Created
January 21, 2016 16:10
-
-
Save westonruter/49e9c3826667b0071f65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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