wp_update_user [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| See: | |
| Returns: |
|
| Defined at: |
|
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.
If $userdata does not contain an 'ID' key, then a new user will be created and the new user's ID will be returned.
If current user's password is being updated, then the cookies will be cleared.
Source
<?php
function wp_update_user($userdata) {
$ID = (int) $userdata['ID'];
// First, get all of the original fields
$user_obj = get_userdata( $ID );
$user = get_object_vars( $user_obj->data );
// Add additional custom fields
foreach ( _get_additional_user_keys( $user_obj ) as $key ) {
$user[ $key ] = get_user_meta( $ID, $key, true );
}
// Escape data pulled from DB.
$user = add_magic_quotes( $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) ) {
wp_clear_auth_cookie();
wp_set_auth_cookie($ID);
}
}
return $user_id;
}
?>
Examples [ wp-snippets.com ]
Top Google Search Results
- Function Reference/wp update user « WordPress Codex
Description. Update a user in the database. It is possible to update a user's password by specifying the 'user_pass' value in the $userdata parameter array.
codex.wordpress.org - wp_update_user and user_login | Occasional Coder
Sep 27, 2010 ... I attempted to change the user_login of a user using the standard wp_update_user function. The following code is simplified for clarity.
radiok.info - wp_update_user | A HitchHackers guide through WordPress
Feb 24, 2011 ... Definition: function wp_update_user($userdata) {}. Update an user in the database. It is possible to update a user's password by specifying the ...
hitchhackerguide.com - wp_update_user (WordPress Function) - WPSeek.com
WordPress lookup for wp_update_user, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme authors.
wpseek.com
User discussions [ wordpress.org ]
- happynuclear on "What function updates user_status, spam and deleted column?"
- gilzow on "wp_update_user vs wp_insert_user"
- Tim Moore on "wp_update_user vs wp_insert_user"
- gilzow on "wp_update_user vs wp_insert_user"
- jnorion on "wp_update_user password change error"
- jnorion on "wp_update_user password change error"
- jhong on "Bug in wp_update_user?"
- jhong on "Bug in wp_update_user?"
- mom2twinz on "Fatal Error: wp_update_user() Any advice?"
- MichaelH on "Fatal Error: wp_update_user() Any advice?"