Tracking Down Deprecated Functions

You may be seeing warnings like this if you have WordPress Debug mode enabled:

“Notice: wpdb::escape is deprecated since version 3.6! Use wpdb::prepare() or esc_sql() instead. in /home/USERNAME/public_html/wp-includes/functions.php on line 2913”

I am getting this with WordPress version 3.8.1, and the Domain Mapping plugin wordpress-mu-domain-mapping version 0.5.4.3 but “deprecated” messages happen with many, many plugins.

The wp-includes/functions.php is a WordPress core file. The function at the line mentioned is reporting the error, not the line with the error. To fix the error, you need to know where the error originates. I’m going to show you how to find that.

To see the back-trace (which program line is causing the ‘deprecated’ error), modify functions.php, about line 2900 (_deprecated_function begins a few lines above what the original error message says).

Add this line before the closing } of the “if (WP_DEBUG”, before two }’s from the end of that function. (I know, modifying a WP Core file??? but this is a temporary debugging fix, and you don’t care if a WordPress update undoes it) :
/* Added by GL 2014-06-23 */ echo '<pre>';trigger_error(print_r(debug_backtrace(), TRUE)); echo '</pre>';
so the function looks like this:

function _deprecated_function( $function, $version, $replacement = null ) {

	do_action( 'deprecated_function_run', $function, $replacement, $version );

	// Allow plugin to filter the output error trigger
	if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
		if ( function_exists( '__' ) ) {
			if ( ! is_null( $replacement ) )
				trigger_error( sprintf( __('%1$s is deprecated since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
			else
				trigger_error( sprintf( __('%1$s is deprecated since version %2$s with no alternative available.'), $function, $version ) );
		} else {
			if ( ! is_null( $replacement ) )
				trigger_error( sprintf( '%1$s is deprecated since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
			else
				trigger_error( sprintf( '%1$s is deprecated since version %2$s with no alternative available.', $function, $version ) );
		}
/* Added by GL 2014-06-23 */ echo '<pre>'; trigger_error(print_r(debug_backtrace(), TRUE)); echo '</pre>';
	}
}

Thanks to vicchi.org for the technique.

Your PHP error log will have all this information, and it will display on screen. (You may have to select from the bottom of the messages, use shift-uparrow to select all the way to the start of the messages, underneath the WordPress bar, Ctrl-C to copy to clipboard):

Notice: wpdb::escape is deprecated since version 3.6! Use wpdb::prepare() or esc_sql() instead. in /home/USERNAME/public_html/wp-includes/functions.php on line 3083

Notice:  Array
(
[0] => Array
(
[file] => /home/USERNAME/public_html/wp-includes/wp-db.php
[line] => 1082
[function] => _deprecated_function
[args] => Array
(
[0] => wpdb::escape
[1] => 3.6
[2] => wpdb::prepare() or esc_sql()
)

)

[1] => Array
(
[file] => /home/USERNAME/public_html/wp-content/sunrise.php
[line] => 11
[function] => escape
[class] => wpdb
[object] => wpdb Object
(
[show_errors] => 1
[suppress_errors] =>
[last_error] =>
[num_queries] => 0
[num_rows] => 0
[rows_affected] => 0
[insert_id] => 0
[last_query] =>
[last_result] =>
[result:protected] =>
in /home/USERNAME/public_html/wp-includes/functions.php on line 3087

Notice: get_current_site_name is deprecated since version 3.9 with no alternative available. in /home/USERNAME/public_html/wp-includes/functions.php on line 3085

Notice:  Array
(
[0] => Array
(
[file] => /home/USERNAME/public_html/wp-includes/ms-load.php
[line] => 435
[function] => _deprecated_function
[args] => Array
(
[0] => get_current_site_name
[1] => 3.9
)

)

[1] => Array
(
[file] => /home/USERNAME/public_html/wp-content/sunrise.php
[line] => 33
[function] => get_current_site_name
[args] => Array
(
[0] => stdClass Object
(
[id] => 1
[domain] => YOURDOMAIN.COM
[path] => /
[blog_id] => 1
)

)

)

[2] => Array
(
[file] => /home/USERNAME/public_html/wp-includes/ms-settings.php
[line] => 18
[args] => Array
in /home/USERNAME/public_html/wp-includes/functions.php on line 3087

See the “/wp-content/sunrise.php” and line 11, in “[1] => Array”, [file] and [line]? That’s the plugin file that generated the error. If you look in that file, at the line specified, there’s the deprecated function. Contact the plugin author to get it fixed, giving them the entire error message and backtrace.


by

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.