Last active
August 17, 2023 11:46
-
-
Save r-a-y/bab85fc47fa0357a8100 to your computer and use it in GitHub Desktop.
Suppress warnings created by certain plugins and themes in WordPress.
This file contains 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
/** | |
* Suppress errors generated by specified WordPress plugins. | |
* | |
* Put this in /wp-content/mu-plugins/ | |
* | |
* @param string $errno The error number. | |
* @param string $errstr The error message. | |
* @param string $errfile Path to the file that caused the error. | |
* @param int $errline Line number of the error. | |
* @return bool True to suppress error reporting; false to use default error handler. | |
*/ | |
function my_error_handler( $errno, $errstr, $errfile, $errline ) { | |
if ( E_STRICT == $errno ) { | |
// Return true to disable all strict notices. | |
//return true; | |
} | |
// Do not display these notices: | |
$patterns = array( | |
'themes/cbox-theme', | |
'Group_Extension::display', // older BP group extensions | |
'bp_setup_current_user was called', // annoying bp_setup_current_user notices | |
); | |
foreach ( $patterns as $pattern ) { | |
$pattern = str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, $pattern ); | |
if ( false !== strpos( $errstr, $pattern ) ) { | |
return true; | |
} | |
if ( false !== strpos( $errfile, $pattern ) ) { | |
return true; | |
} | |
} | |
// The path was not found, so report the error. | |
return false; | |
} | |
set_error_handler( 'my_error_handler' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment