How to fix _weak_escape() error after upgrading to WordPress 2.8

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 :)

Like this post? Subscribe to my RSS feed or receive updates via email.

Got something to say? Say it below :)

Related posts:

  1. Scheduled Posts on WordPress
  2. How to setup Twitter to promote your WordPress blog
  3. WordPress almost setup for SEO
  4. WordPress Plugins to avoid LIKE THE PLAGUE MOFO!
  5. Good Job There WordPress (and the Page Peel Plugin)

8 Comments »

RSS feed for comments on this post. TrackBack URI

  1. It works, I had the same problem, THANKS!! :]

    Comment by Jan Spacil — June 13, 2009 #

  2. 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 #

  3. 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 #

  4. 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 #

  5. That means I manually replace the code. I replaced the function with the one above.

    Comment by David Whitehouse — August 27, 2009 #

  6. There is definitely a better way. Go to your plug-in folder and find all calls of wpdb::escape and replace it with wpdb::_weak_escape

    I 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 #

  7. Luckily an update to the redirection plug in fixes this problem.

    Comment by Peter V Cook — February 6, 2010 #

  8. However this happens to many other plugins that use deprecated wpdb::escape.

    Comment by Tim — July 17, 2010 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Feedback Form