Skip to content

Instantly share code, notes, and snippets.

@kurtpayne
Last active December 20, 2015 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kurtpayne/6154006 to your computer and use it in GitHub Desktop.
Save kurtpayne/6154006 to your computer and use it in GitHub Desktop.
First pass at catching rogue mysql_* calls in themes and plugins.
<?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 );
@kurtpayne
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment