Last active
December 20, 2015 15:28
-
-
Save kurtpayne/6154006 to your computer and use it in GitHub Desktop.
First pass at catching rogue mysql_* calls in themes and plugins.
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 | |
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; | |
}, E_WARNING ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This may conflict with other plugins that use set_error_handler like https://github.com/tollmanz/ostrichcize.
It should prevent warnings caused by mysql_*, and log them via _doing_it_wrong. It won't magically fix anything, though.