diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php index bb8b856f08..d218c41920 100644 --- a/wp-admin/includes/ms.php +++ b/wp-admin/includes/ms.php @@ -101,6 +101,7 @@ function wpmu_delete_blog($blog_id, $drop = false) { restore_current_blog(); } +// @todo Merge with wp_delete_user() ? function wpmu_delete_user($id) { global $wpdb; @@ -131,8 +132,10 @@ function wpmu_delete_user($id) { $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->users WHERE ID = %d", $id) ); $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id) ); - wp_cache_delete($id, 'users'); - wp_cache_delete($user->user_login, 'userlogins'); + clean_user_cache($id); + + // allow for commit transaction + do_action('deleted_user', $id); return true; } @@ -449,8 +452,8 @@ function refresh_user_details($id) { if ( !$user = get_userdata( $id ) ) return false; - wp_cache_delete($id, 'users'); - wp_cache_delete($user->user_login, 'userlogins'); + clean_user_cache($id); + return $id; } diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index 448efee657..f99cdfe8a2 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -419,7 +419,7 @@ function get_users_drafts( $user_id ) { * @param int $reassign Optional. Reassign posts and links to new User ID. * @return bool True when finished. */ -function wp_delete_user($id, $reassign = 'novalue') { +function wp_delete_user( $id, $reassign = 'novalue' ) { global $wpdb; $id = (int) $id; @@ -428,11 +428,11 @@ function wp_delete_user($id, $reassign = 'novalue') { // allow for transaction statement do_action('delete_user', $id); - if ($reassign == 'novalue') { + if ( 'novalue' === $reassign || null === $reassign ) { $post_ids = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id) ); - if ($post_ids) { - foreach ($post_ids as $post_id) + if ( $post_ids ) { + foreach ( $post_ids as $post_id ) wp_delete_post($post_id); } @@ -443,7 +443,6 @@ function wp_delete_user($id, $reassign = 'novalue') { foreach ( $link_ids as $link_id ) wp_delete_link($link_id); } - } else { $reassign = (int) $reassign; $wpdb->update( $wpdb->posts, array('post_author' => $reassign), array('post_author' => $id) ); @@ -459,10 +458,7 @@ function wp_delete_user($id, $reassign = 'novalue') { $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = $id AND meta_key = '{$level_key}'"); } - 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'); + clean_user_cache($id); // allow for commit transaction do_action('deleted_user', $id); diff --git a/wp-includes/user.php b/wp-includes/user.php index 7bff9f25c7..9bdf216d61 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -735,4 +735,21 @@ function sanitize_user_field($field, $value, $user_id, $context) { return $value; } +/** + * Clean all user caches + * + * @since 3.0 + * + * @param int $id User ID + * @return void + */ +function clean_user_cache($id) { + $user = new WP_User($id); + + 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'); +} + ?>