diff --git a/features/user.feature b/features/user.feature index 4f8640e14..cd22acdd6 100644 --- a/features/user.feature +++ b/features/user.feature @@ -352,7 +352,10 @@ Feature: Manage WordPress users | roles | author | When I run `wp user remove-role 1` - Then STDOUT should not be empty + Then STDOUT should contain: + """ + Success: Removed all roles from admin (1) on + """ When I run `wp user get 1` Then STDOUT should be a table containing rows: diff --git a/src/User_Command.php b/src/User_Command.php index 7d7c68959..e0c8654be 100644 --- a/src/User_Command.php +++ b/src/User_Command.php @@ -807,15 +807,25 @@ public function add_role( $args, $assoc_args ) { * : User ID, user email, or user login. * * [...] - * : Remove the specified role(s) from the user. + * : Remove the specified role(s) from the user. If not passed, all roles are + * removed from the user; on multisite, this removes the user from the current + * site/blog. * * ## EXAMPLES * * $ wp user remove-role 12 author - * Success: Removed 'author' role for johndoe (12). + * Success: Removed 'author' role from johndoe (12). * * $ wp user remove-role 12 author editor - * Success: Removed 'author', 'editor' roles for johndoe (12). + * Success: Removed 'author', 'editor' roles from johndoe (12). + * + * # On single-site: removes all roles from the user + * $ wp user remove-role 12 + * Success: Removed all roles from johndoe (12) on http://example.com. + * + * # On multisite: removes the user from the current site/blog + * $ wp user remove-role 12 + * Success: Removed johndoe (12) from http://example.com. * * @subcommand remove-role */ @@ -837,14 +847,14 @@ public function remove_role( $args, $assoc_args ) { $label = count( $roles ) > 1 ? 'roles' : 'role'; WP_CLI::success( "Removed '{$message}' {$label} from {$user->user_login} ({$user->ID})." ); } else { - // Multisite + $site_url = site_url(); if ( function_exists( 'remove_user_from_blog' ) ) { remove_user_from_blog( $user->ID, get_current_blog_id() ); + WP_CLI::success( "Removed {$user->user_login} ({$user->ID}) from {$site_url}." ); } else { $user->remove_all_caps(); + WP_CLI::success( "Removed all roles from {$user->user_login} ({$user->ID}) on {$site_url}." ); } - - WP_CLI::success( "Removed {$user->user_login} ({$user->ID}) from " . site_url() . '.' ); } }