Skip to content

Instantly share code, notes, and snippets.

@markoheijnen
Forked from kurtpayne/mysql_error_catcher.php
Last active December 20, 2015 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markoheijnen/6157779 to your computer and use it in GitHub Desktop.
Save markoheijnen/6157779 to your computer and use it in GitHub Desktop.
Custom error handler for catching MySQL errors
<?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