diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php index 26cb2fbeb8..12baf995c8 100644 --- a/wp-admin/includes/ms.php +++ b/wp-admin/includes/ms.php @@ -132,6 +132,7 @@ function wpmu_delete_user( $id ) { global $wpdb; $id = (int) $id; + $user = new WP_User( $id ); do_action( 'wpmu_delete_user', $id ); @@ -162,7 +163,7 @@ function wpmu_delete_user( $id ) { $wpdb->delete( $wpdb->users, array( 'ID' => $id ) ); $wpdb->delete( $wpdb->usermeta, array( 'user_id' => $id ) ); - clean_user_cache( $id ); + clean_user_cache( $user ); // allow for commit transaction do_action( 'deleted_user', $id ); @@ -389,7 +390,8 @@ function update_user_status( $id, $pref, $value, $deprecated = null ) { $wpdb->update( $wpdb->users, array( $pref => $value ), array( 'ID' => $id ) ); - clean_user_cache( $id ); + $user = new WP_User( $id ); + clean_user_cache( $user ); if ( $pref == 'spam' ) { if ( $value == 1 ) @@ -407,7 +409,7 @@ function refresh_user_details( $id ) { if ( !$user = get_userdata( $id ) ) return false; - clean_user_cache( $id ); + clean_user_cache( $user ); return $id; } diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index 63384fbddb..cdff2e40e2 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -237,6 +237,7 @@ function wp_delete_user( $id, $reassign = 'novalue' ) { global $wpdb; $id = (int) $id; + $user = new WP_User( $id ); // allow for transaction statement do_action('delete_user', $id); @@ -262,7 +263,7 @@ function wp_delete_user( $id, $reassign = 'novalue' ) { $wpdb->update( $wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id) ); } - clean_user_cache($id); + clean_user_cache( $user ); // FINALLY, delete user if ( !is_multisite() ) { diff --git a/wp-includes/user.php b/wp-includes/user.php index 463f311765..2a1a294810 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -1143,15 +1143,21 @@ function update_user_caches($user) { * * @since 3.0.0 * - * @param int $id User ID + * @param WP_User $user User object to be cleaned from the cache */ -function clean_user_cache($id) { - $user = WP_User::get_data_by( 'id', $id ); +function clean_user_cache( $user ) { + if ( is_numeric( $user ) ) { + _deprecated_argument( __FUNCTION__, '3.4', 'Pass the full user object instead of the ID.' ); + $user = new WP_User( $user ); + } - wp_cache_delete($id, 'users'); - wp_cache_delete($user->user_login, 'userlogins'); - wp_cache_delete($user->user_email, 'useremail'); - wp_cache_delete($user->user_nicename, 'userslugs'); + if ( ! $user->exists() ) + return; + + wp_cache_delete( $user->ID, 'users' ); + wp_cache_delete( $user->user_login, 'userlogins' ); + wp_cache_delete( $user->user_email, 'useremail' ); + wp_cache_delete( $user->user_nicename, 'userslugs' ); } /**