mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-30 20:21:37 +01:00
* 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
This commit is contained in:
parent
b6b321a203
commit
646cb4e2ce
@ -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 );
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user