-
-
Save markoheijnen/6157779 to your computer and use it in GitHub Desktop.
Custom error handler for catching MySQL errors
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
<?php | |
function wp_set_error_handler() { | |
if ( defined( 'E_DEPRECATED' ) ) | |
$errcontext = E_WARNING | E_DEPRECATED; | |
else | |
$errcontext = E_WARNING; | |
set_error_handler( function( $errno, $errstr, $errfile ) { | |
if ( 'wp-db.php' !== basename( $errfile ) ) { | |
if ( preg_match( '/^(mysql_[a-zA-Z0-9_]+)/', $errstr, $matches ) ) { | |
_doing_it_wrong( $matches[1], __('Please talk to the database using $wpdb' ), '3.7' ); | |
return apply_filters( 'wpdb_drivers_raw_mysql_call_trigger_error', true ); | |
} | |
} | |
return apply_filters( 'wp_error_handler', false, $errno, $errstr, $errfile ); | |
}, $errcontext ); | |
} | |
wp_set_error_handler(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment