WordPress.org

Make WordPress Core

Ticket #42326: 42326.diff

File 42326.diff, 1009 bytes (added by spacedmonkey, 3 years ago)
  • src/wp-admin/includes/user.php

     
    381381                }
    382382        }
    383383
     384        $delete_user = true;
    384385        // FINALLY, delete user
    385386        if ( is_multisite() ) {
    386387                remove_user_from_blog( $id, get_current_blog_id() );
    387         } else {
     388                $delete_user = false;
     389        }
     390
     391        $blogs = get_blogs_of_user( $id, true );
     392
     393        /**
     394         * Filter to allow for user deletion on multisite
     395         *
     396         * @since 5.0.0
     397         *
     398         * @param boolean $delete_user Weather or not to delete the user data
     399         * @param int $id User ID.
     400         */
     401        $delete_user = apply_filters( 'allow_user_deletion', $delete_user, $id );
     402
     403        // Only allow deletion if user has no sites
     404        if ( $delete_user && count( $blogs ) === 0 ) {
    388405                $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
    389406                foreach ( $meta as $mid )
    390407                        delete_metadata_by_mid( 'user', $mid );