From 646cb4e2cefbd11f3f7b1e5bdfa0c9ee89fc57c3 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 24 Apr 2012 22:13:47 +0000 Subject: [PATCH] * Return empty arrays instead of false for all conditions in get_blogs_of_user(). * When deleting a user, use a delete_metadata_by_mid() loop over the meta so that the meta cache is cleared. * Use remove_user_from_blog() for DRYness. Props nacin, duck_ Fixes #19500 git-svn-id: http://svn.automattic.com/wordpress/trunk@20581 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/ms.php | 5 ++++- wp-admin/includes/user.php | 12 +++++++----- wp-includes/user.php | 11 ++++------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php index 12baf995c..cfd2bb8c6 100644 --- a/wp-admin/includes/ms.php +++ b/wp-admin/includes/ms.php @@ -160,7 +160,10 @@ function wpmu_delete_user( $id ) { } } - $wpdb->delete( $wpdb->users, array( 'ID' => $id ) ); + $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) ); + foreach ( $meta as $mid ) + delete_metadata_by_mid( 'user', $mid ); + $wpdb->delete( $wpdb->usermeta, array( 'user_id' => $id ) ); clean_user_cache( $user ); diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index 0fa1a9793..edc0c2abb 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -264,12 +264,14 @@ function wp_delete_user( $id, $reassign = 'novalue' ) { } // FINALLY, delete user - if ( !is_multisite() ) { - $wpdb->delete( $wpdb->usermeta, array( 'user_id' => $id ) ); - $wpdb->delete( $wpdb->users, array( 'ID' => $id ) ); + if ( is_multisite() ) { + remove_user_from_blog( $id, get_current_blog_id() ); } else { - $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels - $wpdb->delete( $wpdb->usermeta, array( 'user_id' => $id , 'meta_key' => $level_key ) ); + $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) ); + foreach ( $meta as $mid ) + delete_metadata_by_mid( 'user', $mid ); + + $wpdb->delete( $wpdb->users, array( 'ID' => $id ) ); } clean_user_cache( $user ); diff --git a/wp-includes/user.php b/wp-includes/user.php index 2b6947254..11ea2b277 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -652,7 +652,7 @@ function get_users( $args = array() ) { * * @param int $user_id User ID * @param bool $all Whether to retrieve all blogs, or only blogs that are not marked as deleted, archived, or spam. - * @return array A list of the user's blogs. False if the user was not found or an empty array if the user has no blogs. + * @return array A list of the user's blogs. An empty array if the user doesn't exist or belongs to no blogs. */ function get_blogs_of_user( $user_id, $all = false ) { global $wpdb; @@ -661,11 +661,11 @@ function get_blogs_of_user( $user_id, $all = false ) { // Logged out users can't have blogs if ( empty( $user_id ) ) - return false; + return array(); $keys = get_user_meta( $user_id ); if ( empty( $keys ) ) - return false; + return array(); if ( ! is_multisite() ) { $blog_id = get_current_blog_id(); @@ -745,10 +745,7 @@ function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) { $blog_id = get_current_blog_id(); $blogs = get_blogs_of_user( $user_id ); - if ( is_array( $blogs ) ) - return array_key_exists( $blog_id, $blogs ); - else - return false; + return array_key_exists( $blog_id, $blogs ); } /**