Saving Objects In WordPress’ User Meta

There’s a hole in the wall at about head level next to my desk.

I’ve spent most of the day trying to track down a bug with some code I’ve been working on to add fields to a user’s profile in WordPress. The problem is that upon trying to save the profile I’d get an error like the following:

Catchable fatal error: Object of class stdClass could not be converted to string in /wp-includes/wp-db.php on line 472

Line 472 in my install is in the wpdb::escape() function. After poking around the wrong side of the problem, I finally broke down and rewrote the function along these lines:

function escape($string) {
 if( !is_object( $string ))
 return( $string );

 echo '<h2>'. $this->get_caller() .'</h2><pre>';
 print_r( $string );
 echo '</pre>';
 die();
}

That’s how I finally learned that wp_update_user() was at fault. I also opened a ticket for add_magic_quotes(), as both probably need independent fixes.

For now, however, I'm just converting the object to an array and avoiding the mess.

No Comments Yet

No comments yet.

Comments RSS TrackBack Identifier URI

Leave a comment

 

User contributed tags for this post:

1