Quick fix for the notice "wpdb::escape is deprecated since version 3.6"

Assuming you have set WP_DEBUG to true, upgrading to the latest stable release of WordPress, at the present 3.6, may cause an error message on the top of the page.

Notice: wpdb::escape is deprecated since version 3.6! Use wpdb::prepare() or esc_sql() instead.

The expression $wpdb->escape is still used by some plugins. To narrow down what causes the error, I would deactivate the full set of plugins on the site, and eventually switch back to the default theme (like Twentytwelve), to make sure isn't the them itself.

Then I would reactivate the plugins one by one, to find out which one breaks the layout.

In my case, it was the file sunrise.php, commonly used in WordPress Multisites.

To fix it, I could substitute the expression $wpdb->escape with $wpdb->prepare or to use instead the function esc_sql().

Unfortunately, the file sunrise.php is included via wp-config.php before the function esc_sql() has been even registered. And to further complicate things, the expression $wpdb->prepare can’t be used either in that specific line.

However, there is a third option. Open the file sunrise.php (it should be in wp-content/sunrise.php), and locate the following line:

$dm_domain = $wpdb->escape( $_SERVER[ 'HTTP_HOST' ] );

And change it like shown below with an underscore.

$dm_domain = $wpdb->_escape( $_SERVER[ 'HTTP_HOST' ] );

Refresh the page in your browser and the error should be gone for good.