How to remove error notices using WordPress’s WP_DEBUG

A neat trick I learned today to remove or adjust PHP error reporting when using `WP_DEBUG`. It’s often the case that a theme or plugin author has either not written code with debug on or perhaps supporting an older version of PHP so error notices can hinder the output visually or fill up your log file. A theme I was working on that caused me to find a solution was adding 8k lines of debug output to the log file every couple hours!

In your `wp-content` folder create a new folder called `mu-plugins` and in that folder create a php file with the error level you want, for example:

//Turns off notices
error_reporting(E_ALL ^ E_NOTICE);

If you are using PHP 5.5 +, you will get deprecated noticed for WordPress’s mysql_* functions, you can turn them off using:

error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);

Or for something really robust, which happens to be the case a lot.

error_reporting(E_ALL &  ~( E_DEPRECATED | E_USER_DEPRECATED | E_USER_NOTICE | E_STRICT ));

References:

I you develop themes/plugins please turn on debugging and support at the very least PHP 5.4!

Advertisements