From 2c8da49588dd046626c4fb3cdd1457936afc322b Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 4 Feb 2020 19:34:27 +0000 Subject: [PATCH] Users: In `remove_user_from_blog()`: * Change default value of the `$blog_id` parameter to match the documented type. * Change the type of the `$reassign` parameter for consistency with `$user_id` and `$blog_id`. * Add documentation for the return value. See #49361. git-svn-id: https://develop.svn.wordpress.org/trunk@47173 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/network/users.php | 2 +- src/wp-includes/ms-functions.php | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/wp-admin/network/users.php b/src/wp-admin/network/users.php index cd39bf1465..1db14e295d 100644 --- a/src/wp-admin/network/users.php +++ b/src/wp-admin/network/users.php @@ -158,7 +158,7 @@ if ( isset( $_GET['action'] ) ) { } if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][ $blogid ][ $id ] ) { - remove_user_from_blog( $id, $blogid, $user_id ); + remove_user_from_blog( $id, $blogid, (int) $user_id ); } else { remove_user_from_blog( $id, $blogid ); } diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index 9479ace08b..5dd1891201 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -234,15 +234,17 @@ function add_user_to_blog( $blog_id, $user_id, $role ) { * * @global wpdb $wpdb WordPress database abstraction object. * - * @param int $user_id ID of the user you're removing. - * @param int $blog_id ID of the blog you're removing the user from. - * @param string $reassign Optional. A user to whom to reassign posts. - * @return true|WP_Error + * @param int $user_id ID of the user you're removing. + * @param int $blog_id Optional. ID of the blog you're removing the user from. Default 0. + * @param int $reassign Optional. ID of the user to whom to reassign posts. Default 0. + * @return true|WP_Error True on success or a WP_Error object if the user doesn't exist. */ -function remove_user_from_blog( $user_id, $blog_id = '', $reassign = '' ) { +function remove_user_from_blog( $user_id, $blog_id = 0, $reassign = 0 ) { global $wpdb; + switch_to_blog( $blog_id ); $user_id = (int) $user_id; + /** * Fires before a user is removed from a site. * @@ -253,8 +255,8 @@ function remove_user_from_blog( $user_id, $blog_id = '', $reassign = '' ) { */ do_action( 'remove_user_from_blog', $user_id, $blog_id ); - // If being removed from the primary blog, set a new primary if the user is assigned - // to multiple blogs. + // If being removed from the primary blog, set a new primary + // if the user is assigned to multiple blogs. $primary_blog = get_user_meta( $user_id, 'primary_blog', true ); if ( $primary_blog == $blog_id ) { $new_id = ''; @@ -288,7 +290,7 @@ function remove_user_from_blog( $user_id, $blog_id = '', $reassign = '' ) { update_user_meta( $user_id, 'source_domain', '' ); } - if ( $reassign != '' ) { + if ( $reassign ) { $reassign = (int) $reassign; $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $user_id ) ); $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $user_id ) );