WordPress.org

Make WordPress Core

Ticket #19500: 19500.5.diff

File 19500.5.diff, 2.6 KB (added by ryan, 6 years ago)

meta delete loop for wpmu_delete_user()

  • wp-includes/user.php

     
    652652 *
    653653 * @param int $user_id User ID
    654654 * @param bool $all Whether to retrieve all blogs, or only blogs that are not marked as deleted, archived, or spam.
    655  * @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.
     655 * @return array A list of the user's blogs. An empty array if the user doesn't exist or belongs to no blogs.
    656656 */
    657657function get_blogs_of_user( $user_id, $all = false ) {
    658658        global $wpdb;
     
    661661
    662662        // Logged out users can't have blogs
    663663        if ( empty( $user_id ) )
    664                 return false;
     664                return array();
    665665
    666666        $keys = get_user_meta( $user_id );
    667667        if ( empty( $keys ) )
    668                 return false;
     668                return array();
    669669
    670670        if ( ! is_multisite() ) {
    671671                $blog_id = get_current_blog_id();
     
    745745                $blog_id = get_current_blog_id();
    746746
    747747        $blogs = get_blogs_of_user( $user_id );
    748         if ( is_array( $blogs ) )
    749                 return array_key_exists( $blog_id, $blogs );
    750         else
    751                 return false;
     748        return array_key_exists( $blog_id, $blogs );
    752749}
    753750
    754751/**
  • wp-admin/includes/user.php

     
    264264        }
    265265
    266266        // FINALLY, delete user
    267         if ( !is_multisite() ) {
    268                 $wpdb->delete( $wpdb->usermeta, array( 'user_id' => $id ) );
     267        if ( is_multisite() ) {
     268                remove_user_from_blog( $id, get_current_blog_id() );
     269        } else {
     270                $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
     271                foreach ( $meta as $mid )
     272                        delete_metadata_by_mid( 'user', $mid );
     273
    269274                $wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
    270         } else {
    271                 $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels
    272                 $wpdb->delete( $wpdb->usermeta, array( 'user_id' => $id , 'meta_key' => $level_key ) );
    273275        }
    274276
    275277        clean_user_cache( $user );
  • wp-admin/includes/ms.php

     
    160160                }
    161161        }
    162162
    163         $wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
     163        $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
     164        foreach ( $meta as $mid )
     165                delete_metadata_by_mid( 'user', $mid );
     166
    164167        $wpdb->delete( $wpdb->usermeta, array( 'user_id' => $id ) );
    165168
    166169        clean_user_cache( $user );