How can I stop PHP notices from appearing in wordp

2019-01-17 10:53发布

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.

6条回答
家丑人穷心不美
2楼-- · 2019-01-17 11:08

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楼-- · 2019-01-17 11:09

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:

查看更多
甜甜的少女心
4楼-- · 2019-01-17 11:17

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

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

}
查看更多
手持菜刀,她持情操
5楼-- · 2019-01-17 11:20

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

查看更多
Lonely孤独者°
6楼-- · 2019-01-17 11:20

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/

查看更多
神经病院院长
7楼-- · 2019-01-17 11:21
/**
 * 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.

查看更多
登录 后发表回答