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

Paul paul at codehooligans.com
Mon Feb 2 18:06:25 GMT 2009


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



More information about the wp-hackers mailing list