How can I stop PHP notices from appearing in wordpress?

廉价感情. 提交于 2019-12-17 17:55:31

问题


I know about error_reporting(0);, and ini_set('display_errors', false);, but there is a notice appearing in wordpress:

Notice: Array to string conversion in /var/www/vhosts/treethink.net/subdomains/parkridge/httpdocs/wp-includes/formatting.php on line 359

it only appears in wordpress, not in any other pages of the site.

I checked phpinfo(), and everything is set so that errors are not displayed. Why does this one still show up?

Here is the line that generates the error:

function wp_check_invalid_utf8( $string, $strip = false ) {
    $string = (string) $string;

I did change some thing in wordpress, to change how the gallery worked. But not this function, and I don't think I changed any calls to this function either. Aside from the notice appearing, everything seems to operate perfectly fine, I just need to get this error to hide.


回答1:


You need to edit your:

wp-config.php

file and modify the following here:

error_reporting(0);
@ini_set('display_errors', 0);

otherwise Wordpress overwrites the ALERTS set by PHP.INI




回答2:


In wp-config.php add this line:

define('WP_DEBUG_DISPLAY', false);

That will enable or disable the display of notices and warnings to the page. There is a fuller description of this option, and some related options, here:

http://codex.wordpress.org/Debugging_in_WordPress




回答3:


Jan 2015 with latest Wordpress, none of the above works for me.

Creating a php file in mu-plugins folder of Wordpress worked, like :

<?php
error_reporting(E_ALL &  ~( E_NOTICE | E_USER_NOTICE | E_STRICT | 
E_DEPRECATED | E_USER_DEPRECATED | E_WARNING | E_CORE_WARNING | 
E_USER_WARNING | E_COMPILE_WARNING | E_PARSE )); 

Just name it anything you want ...

i got the answer from here :

https://wycks.wordpress.com/2013/12/05/how-to-remove-error-notices-using-wordpresss-wp_debug/




回答4:


if you want to hide only errors that comes from this function you can use

@function wp_check_invalid_utf8( $string, $strip = false )
{

}



回答5:


Most of the time these are nothing to worry about (though the plugin/theme developer should know about these so that they may fix them in a future release). PHP warnings and notices are nothing to worry about on a production site most of the time. Some of these can even be generated because the developer has to keep compatibility with older versions of WordPress as well as older PHP versions.

define('WP_DEBUG', false);

with this

ini_set('log_errors','On');
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

If you simply set WP_DEBUG to false in your wp-config.php file you should be fine. These don’t affect your site in any way.

However, the problem is that some times the above does not work. That can happen most times on cheap shared hosts that force displaying PHP warnings and notices. In that case, you can replace this line from your wp-config.php file:




回答6:


/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 */
define('WP_DEBUG', false);

// Enable Debug logging to the /wp-content/debug.log file
define('WP_DEBUG_LOG', false);

// Disable display of errors and warnings 
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors', 0);

What I use and it works with the latest WordPress version.



来源:https://stackoverflow.com/questions/1308379/how-can-i-stop-php-notices-from-appearing-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!