I 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







By Jan Spacil, June 13, 2009 at 5:50 pm
It works, I had the same problem, THANKS!! :]
By David Whitehouse, June 15, 2009 at 10:06 am
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
By Dennis, June 22, 2009 at 9:44 am
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 …
By frank, August 27, 2009 at 11:33 am
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
By David Whitehouse, August 27, 2009 at 12:20 pm
That means I manually replace the code. I replaced the function with the one above.
By Tim, September 28, 2009 at 12:06 pm
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.
By Peter V Cook, February 6, 2010 at 7:39 pm
Luckily an update to the redirection plug in fixes this problem.
By Tim, July 17, 2010 at 11:56 am
However this happens to many other plugins that use deprecated wpdb::escape.
By Ana, January 28, 2011 at 5:02 pm
Thank you sooo much! I recently updated WP to 3.0.4 and I couldn’t publish my entries because of that error. I replaced the code as you said and it went well, it let me publish the entry but without tags because the tagging box wasn’t working, what the hell? So I updated my plugins, Google Analytics for WordPress and HeadSpace2, and now everything is fine! Back to publish (tagged) entries! Thanks again!