Skip to content

Instantly share code, notes, and snippets.

@westonruter
Created January 21, 2016 16:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/49e9c3826667b0071f65 to your computer and use it in GitHub Desktop.
Save westonruter/49e9c3826667b0071f65 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Deprecated admin_notices
* Description: Disable PHP Deprecated notices and display in admin_notices
* Author: Weston Ruter, XWP
*/
call_user_func( function() {
error_reporting( error_reporting() ^ E_DEPRECATED );
$deprecated_notices = array();
set_error_handler(
function( $errno, $errstr, $errfile, $errline, $errcontext ) use ( &$deprecated_notices ) {
$deprecated_notices[] = compact( 'errno', 'errstr', 'errfile', 'errline', 'errcontext' );
},
E_USER_DEPRECATED
);
add_action( 'admin_notices', function() use ( $deprecated_notices ) {
if ( empty( $deprecated_notices ) ) {
return;
}
?>
<div class="error">
<details>
<summary>Alert: There are <?php echo count( $deprecated_notices ) ?> deprecation notices are suppressed.</summary>
<ul>
<?php foreach ( $deprecated_notices as $deprecated_notice ) : ?>
<li><code><?php echo esc_html( wp_json_encode( $deprecated_notice ) ); ?></code></li>
<?php endforeach; ?>
</ul>
</details>
</div>
<?php
} );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment