Skip to content

Commit 07eeaf7

Browse files
CopilotswissspidyCopilot
authored
Improve wp user remove-role docs and output when no role argument is given (#580)
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com>
1 parent defb5ea commit 07eeaf7

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

features/user.feature

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ Feature: Manage WordPress users
352352
| roles | author |
353353
354354
When I run `wp user remove-role 1`
355-
Then STDOUT should not be empty
355+
Then STDOUT should contain:
356+
"""
357+
Success: Removed all roles from admin (1) on
358+
"""
356359
357360
When I run `wp user get 1`
358361
Then STDOUT should be a table containing rows:

src/User_Command.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -807,15 +807,25 @@ public function add_role( $args, $assoc_args ) {
807807
* : User ID, user email, or user login.
808808
*
809809
* [<role>...]
810-
* : Remove the specified role(s) from the user.
810+
* : Remove the specified role(s) from the user. If not passed, all roles are
811+
* removed from the user; on multisite, this removes the user from the current
812+
* site/blog.
811813
*
812814
* ## EXAMPLES
813815
*
814816
* $ wp user remove-role 12 author
815-
* Success: Removed 'author' role for johndoe (12).
817+
* Success: Removed 'author' role from johndoe (12).
816818
*
817819
* $ wp user remove-role 12 author editor
818-
* Success: Removed 'author', 'editor' roles for johndoe (12).
820+
* Success: Removed 'author', 'editor' roles from johndoe (12).
821+
*
822+
* # On single-site: removes all roles from the user
823+
* $ wp user remove-role 12
824+
* Success: Removed all roles from johndoe (12) on http://example.com.
825+
*
826+
* # On multisite: removes the user from the current site/blog
827+
* $ wp user remove-role 12
828+
* Success: Removed johndoe (12) from http://example.com.
819829
*
820830
* @subcommand remove-role
821831
*/
@@ -837,14 +847,14 @@ public function remove_role( $args, $assoc_args ) {
837847
$label = count( $roles ) > 1 ? 'roles' : 'role';
838848
WP_CLI::success( "Removed '{$message}' {$label} from {$user->user_login} ({$user->ID})." );
839849
} else {
840-
// Multisite
850+
$site_url = site_url();
841851
if ( function_exists( 'remove_user_from_blog' ) ) {
842852
remove_user_from_blog( $user->ID, get_current_blog_id() );
853+
WP_CLI::success( "Removed {$user->user_login} ({$user->ID}) from {$site_url}." );
843854
} else {
844855
$user->remove_all_caps();
856+
WP_CLI::success( "Removed all roles from {$user->user_login} ({$user->ID}) on {$site_url}." );
845857
}
846-
847-
WP_CLI::success( "Removed {$user->user_login} ({$user->ID}) from " . site_url() . '.' );
848858
}
849859
}
850860

0 commit comments

Comments
 (0)