Keep Plugin Deprecation Notices Out of debug.log
Stops PHP deprecation notices coming from plugins and themes from filling debug.log, so the real warnings and errors you are looking for stand out while debugging.
Opens WPIDE on
Code
// Folders whose deprecation notices are silenced.
$wpide_quiet_paths = array( WP_PLUGIN_DIR, get_theme_root() );
$wpide_previous_handler = set_error_handler( function ( $errno, $errstr, $errfile = '', $errline = 0 ) use ( $wpide_quiet_paths, &$wpide_previous_handler ) {
if ( in_array( $errno, array( E_DEPRECATED, E_USER_DEPRECATED ), true ) ) {
foreach ( $wpide_quiet_paths as $path ) {
if ( 0 === strpos( (string) $errfile, $path ) ) {
return true; // Handled: do not log.
}
}
}
// Hand everything else to the previous handler, or to PHP itself.
return $wpide_previous_handler ? call_user_func( $wpide_previous_handler, $errno, $errstr, $errfile, $errline ) : false;
} );
Notes
Only E_DEPRECATED and E_USER_DEPRECATED from wp-content are silenced; WordPress core notices and all other errors are logged as before.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.