Halloween Sale 15% off Ends in See the plans
PHP

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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.