function wp_update_user($userdata) {}

Update an user in the database.
It is possible to update a user’s password by specifying the ‘user_pass’ value in the $userdata parameter array.


  • array $userdata: An array of user data.

Return values

returns:The updated user’s ID.

Source code

function wp_update_user($userdata) {

	$ID = (int) $userdata['ID'];

	// First, get all of the original fields

	$user = get_userdata($ID);

	// Escape data pulled from DB.

	$user = add_magic_quotes(get_object_vars($user));

	// If password is changing, hash it now.

	if ( ! empty($userdata['user_pass']) ) {

		$plaintext_pass = $userdata['user_pass'];

		$userdata['user_pass'] = wp_hash_password($userdata['user_pass']);


	wp_cache_delete($user[ 'user_email' ], 'useremail');

	// Merge old and new fields with new fields overwriting old ones.

	$userdata = array_merge($user, $userdata);

	$user_id = wp_insert_user($userdata);

	// Update the cookies if the password changed.

	$current_user = wp_get_current_user();

	if ( $current_user->id == $ID ) {

		if ( isset($plaintext_pass) ) {





	return $user_id;



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: