最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

debug - How do you change error reporting to only show errors in WordPress?

programmeradmin0浏览0评论

I'm working on a development site that has some plugins that produce notices. It's a bit annoying during development when you only want to see the errors your own code produces.

How can you turn off notices in WordPress but keep reporting of errors enabled?

I thought this should work, but it doesn't:

define( 'WP_DEBUG', true );
error_reporting(E_ALL & ~E_NOTICE);

Edit: I should point out that I added this code to the wp-config.php, just to be clear.

I'm working on a development site that has some plugins that produce notices. It's a bit annoying during development when you only want to see the errors your own code produces.

How can you turn off notices in WordPress but keep reporting of errors enabled?

I thought this should work, but it doesn't:

define( 'WP_DEBUG', true );
error_reporting(E_ALL & ~E_NOTICE);

Edit: I should point out that I added this code to the wp-config.php, just to be clear.

Share Improve this question edited Feb 8, 2022 at 16:54 TheKidsWantDjent asked Feb 8, 2022 at 16:24 TheKidsWantDjentTheKidsWantDjent 3154 silver badges19 bronze badges 2
  • That's a PHP-wide setting, plugins don't get loaded into a neat sandbox that you can tweak on a per-sandbox basis, it's all loaded into the same communal codespace, otherwise filters etc wouldn't work. Instead you're better off investigating better debugging tools than printing things straight to the browser, such as query monitor, debuggers such as xdebug, or at least logging messages to an error log. Printing notices or errors to the frontend can expose information and should be considered a security problem – Tom J Nowell Commented Feb 8, 2022 at 16:41
  • This question is similar: wordpress.stackexchange.com/questions/239501/… – Flimm Commented Apr 29, 2024 at 14:03
Add a comment  | 

1 Answer 1

Reset to default 1

Alternatively you can create a debug logging file for where you can read the errors. Source: http://codex.wordpress.org/Editing_wp-config.php#Configure_Error_Log

/**
 * This will log all errors notices and warnings to a file called debug.log in
 * wp-content (if Apache does not have write permission, you may need to create
 * the file first and set the appropriate permissions (i.e. use 666) ) 
 */

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors',0);
发布评论

评论列表(0)

  1. 暂无评论