How to fix _weak_escape() error after upgrading to WordPress 2.8
Posted by David WhitehouseI just got the WordPress error: Call to undefined function: _weak_escape() when trying to login to WordPress admin after upgrading to WordPress 2.8.
I looked it up and someone mentioned it was a problem to do with the redirection plugin – but to hell with disabling that, I love that plugin!!! So instead I looked into the file causing the problem:
wp-includes/wp-db.php
At a further look it didn’t seem to like the function _weak_escape, so I simply found what this function did, all it does is addslashes, so I embedded this into the code which was calling _weak_escape and hey presto! It works!
Here is the full code I used:
function escape($data) {
if ( is_array($data) ) {
foreach ( (array) $data as $k => $v ) {
if ( is_array($v) )
$data[$k] = $this->escape( $v );
else
$data[$k] = addslashes($v);
}
} else {
$data = addslashes($data);
}
return $data;
}
Hope that helps some of you out there!
I realise this isn’t the best fix for it – ideally you want to get it so it doesn’t believe _weak_escape is an undefined function – but I’m not sure what the cause of this is, I imagine I could try removing the underscore or searching at php.net – but it’s late and I want to go to bed! If you find the solution please let me know in the comments and I’ll give you a link
Like this post? Subscribe to my RSS feed or receive updates via email.
Got something to say? Say it below
Related posts:
- Scheduled Posts on WordPress
- How to setup Twitter to promote your WordPress blog
- WordPress almost setup for SEO
- WordPress Plugins to avoid LIKE THE PLAGUE MOFO!
- Good Job There WordPress (and the Page Peel Plugin)
8 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment

It works, I had the same problem, THANKS!! :]
Comment by Jan Spacil — June 13, 2009 #
Jan, were you using the redirection plugin?
My only worry is mine looks a bit funny, so I might have to make some changes, if so I’ll comment here and you can check back for the updated solution
Comment by David Whitehouse — June 15, 2009 #
Great fix. I had the same problem and I love the redirection plugin, too! Another fix would be to replace the “new” wp-db.php with the wp-db.php out of wordpress 2.7.1. This also works …
Comment by Dennis — June 22, 2009 #
hi thanks for the fix,
but what do you mean by
“so I embedded this into the code which was calling _weak_escape”
did you just add this code in the wp-includes/wp-db.php
file, or did you remove the function???
thanks
Comment by frank — August 27, 2009 #
That means I manually replace the code. I replaced the function with the one above.
Comment by David Whitehouse — August 27, 2009 #
There is definitely a better way. Go to your plug-in folder and find all calls of
wpdb::escapeand replace it withwpdb::_weak_escapeI know it is a bit longer but it will preserve you from getting this error back one your WordPress version is updated.
Comment by Tim — September 28, 2009 #
Luckily an update to the redirection plug in fixes this problem.
Comment by Peter V Cook — February 6, 2010 #
However this happens to many other plugins that use deprecated wpdb::escape.
Comment by Tim — July 17, 2010 #