如何阻止 PHP 通知出现在 wordpress 中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1308379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I stop PHP notices from appearing in wordpress?
提问by Carson Myers
I know about error_reporting(0);, and ini_set('display_errors', false);, but there is a notice appearing in wordpress:
我知道error_reporting(0);, 和ini_set('display_errors', false);,但是wordpress中出现了一条通知:
Notice: Array to string conversion in /var/www/vhosts/treethink.net/subdomains/parkridge/httpdocs/wp-includes/formatting.phpon line 359
注意:第359行/var/www/vhosts/treethink.net/subdomains/parkridge/httpdocs/wp-includes/formatting.php 中的数组到字符串转换
it onlyappears in wordpress, not in any other pages of the site.
它只是出现在WordPress的,而不是在该网站的任何其他页面。
I checked phpinfo(), and everything is set so that errors are not displayed. Why does this one still show up?
我检查了phpinfo(),一切都设置为不显示错误。为什么这个还是出现?
Here is the line that generates the error:
这是生成错误的行:
function wp_check_invalid_utf8( $string, $strip = false ) {
$string = (string) $string;
I didchange 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.
我确实在 wordpress 中改变了一些东西,以改变画廊的工作方式。但不是这个函数,我认为我也没有改变对这个函数的任何调用。除了出现通知之外,一切似乎都运行良好,我只需要隐藏此错误即可。
回答by Jakub
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
否则 Wordpress 会覆盖 PHP.INI 设置的警报
回答by Eric Henry
Jan 2015 with latest Wordpress, none of the above works for me.
2015 年 1 月使用最新的 Wordpress,以上都不适合我。
Creating a php file in mu-plugins folder of Wordpress worked, like :
在 Wordpress 的 mu-plugins 文件夹中创建一个 php 文件,例如:
<?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/
https://wycks.wordpress.com/2013/12/05/how-to-remove-error-notices-using-wordpresss-wp_debug/
回答by Jason
In wp-config.php add this line:
在 wp-config.php 添加这一行:
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:
这将启用或禁用向页面显示通知和警告。这里有关于这个选项和一些相关选项的更完整的描述:
回答by Ankit Agrawal
if you want to hide only errors that comes from this function you can use
如果你只想隐藏来自这个函数的错误,你可以使用
@function wp_check_invalid_utf8( $string, $strip = false )
{
}
回答by OpenWebWar
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.
大多数时候这些都没什么可担心的(尽管插件/主题开发人员应该知道这些,以便他们可以在未来的版本中修复它们)。大多数情况下,在生产站点上无需担心 PHP 警告和通知。其中一些甚至可以生成,因为开发人员必须保持与旧版 WordPress 以及旧版 PHP 的兼容性。
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 falsein your wp-config.php fileyou should be fine. These don't affect your site in any way.
如果您只是在wp-config.php 文件中将 WP_DEBUG 设置为 false,则应该没问题。这些不会以任何方式影响您的网站。
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:
但是,问题是有时上述方法不起作用。大多数情况下,这种情况可能发生在强制显示 PHP 警告和通知的廉价共享主机上。在这种情况下,您可以替换 wp-config.php 文件中的这一行:
回答by adamj
/**
* 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.
我使用的是什么,它适用于最新的 WordPress 版本。

