[wp-hackers] Updating a User Record via PHP?

Mike Schinkel mikeschinkel at newclarity.net
Mon Feb 2 19:08:04 GMT 2009


Paul:

Thanks. Yeah I've reviewed (and actually single-step debugged though) that code but haven't been able to isolate why it is inserting rather than adding.  Wishing the update function didn't overload insert so that it would fail rather than insert.  

Based on your comments it's probably a missing ID somehow.  I'll dive in a try to tackle it again. Thanks.

-Mike Schinkel
http://mikeschinkel.com/

----- Original Message -----
From: "Paul" <paul at codehooligans.com>
To: wp-hackers at lists.automattic.com
Sent: Monday, February 2, 2009 1:06:25 PM GMT -05:00 US/Canada Eastern
Subject: Re: [wp-hackers] Updating a User Record via PHP?

Mike,

Pretty simple. Look at the function 'wp_insert_user' in wp-includes/ 
registrations.php
The code checks id the ID is present from the structure passed into  
the function.

function wp_insert_user($userdata) {
	global $wpdb;

	extract($userdata, EXTR_SKIP);

	// Are we updating or creating?
	if ( !empty($ID) ) {
		$ID = (int) $ID;
		$update = true;
	} else {
		$update = false;
	}

Further down in the same function:

	if ( $update ) {
		$wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
		$user_id = (int) $ID;
	} else {
		$wpdb->insert( $wpdb->users, $data + compact( 'user_login' ) );
		$user_id = (int) $wpdb->insert_id;
	}




On Feb 2, 2009, at 11:59 AM, Mike Schinkel wrote:

> Hi all:
>
> I'm running into trouble using wp_update_user() where it is adding  
> new users instead of simply updating them. When I trace it I find  
> that it calls wp_insert_user(). Does anyone here know anything about  
> this? Does anyone know how to ensure that a request to update a user  
> actually updates instead of inserting a duplicate (w/o simply  
> reverting to SQL?)
>
> -Mike Schinkel
> http://mikeschinkel.com/
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list