Skip to content

Improve wp user remove-role docs and output when no role argument is given#580

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-remove-role-display
Draft

Improve wp user remove-role docs and output when no role argument is given#580
Copilot wants to merge 3 commits intomainfrom
copilot/fix-remove-role-display

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

When wp user remove-role <id> is called without a role argument, it silently removes all roles from the user (or removes the user from the blog on multisite). The behavior was undocumented and the success message—Removed {user} ({id}) from {site_url}.—sounded like the user account was deleted.

Changes

  • Success message: "Removed {user} ({id}) from {site_url}.""Removed all roles from {user} ({id}) on {site_url}." — clearly signals role removal, not account deletion, while retaining the site URL context
  • Docblock: Documents the no-argument behavior on [<role>...] and adds a corresponding example
$ wp user remove-role 12
Success: Removed all roles from johndoe (12) on http://example.com.
Original prompt

This section details on the original issue you should resolve

<issue_title>2.4.0: wp user remove-role <id> with no role arguments could produce a less scary display result</issue_title>
<issue_description>## Bug Report

Describe the current, buggy behavior

wp user set-role with no [role] argument is documented as "adds the default role".

But matching remove-role synopsis is undocumented and also produces a scary display result:

[cxl ~/www]# wp user remove-role 293
Success: Removed leho (293) from <site>.

This looks like my user just got wiped. Fortunately it's not the case, as wp user get confirmed.

Describe how other contributors can replicate this bug

See commands above.

Describe what you would expect as the correct outcome

a) user remove-role should not proceed without a [role] parameter
b) match set-role strategy and remove default role + add documentation

Let us know what environment you are running this on

# wp cli info
OS:     Linux 2.6.32-754.17.1.el6.x86_64 wp-cli/entity-command#1 SMP Tue Jul 2 12:42:48 UTC 2019 x86_64
Shell:  /bin/bash
PHP binary:     /opt/cpanel/ea-php73/root/usr/bin/php
PHP version:    7.3.16
php.ini used:   /opt/cpanel/ea-php73/root/etc/php.ini
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /home/convers/public_html
WP-CLI packages dir:    /home/convers/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.4.0
```</issue_description>

<agent_instructions>Improve command documentation and output to clarify what's going on.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@danielbachhuber</author><body>
From the code, it looks like the user is meant to be removed from the site if no role is specified:

https://github.com/wp-cli/entity-command/blob/ab523042d163875e8011d1fe3a8f715522798a21/src/User_Command.php#L749-L756

When I tested, it seems like the role is removed as expected:

$ wp user remove-role danieltesting
Success: Removed danieltesting (2) from https://vanilla.test.
$ wp user list
+----+---------------+---------------+-----------------------------+---------------------+---------------+
| ID | user_login | display_name | user_email | user_registered | roles |
+----+---------------+---------------+-----------------------------+---------------------+---------------+
| 1 | daniel | daniel | daniel@handbuilt.co | 2023-05-17 12:02:14 | administrator |
| 2 | danieltesting | danieltesting | daniel+testing@bachhuber.co | 2023-07-13 16:16:05 | |
+----+---------------+---------------+-----------------------------+---------------------+---------------+


Maybe we could improve the documentation?</body></comment_new>
</comments>


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix display message for wp user remove-role without role argument Improve wp user remove-role docs and output when no role argument is given Feb 26, 2026
@swissspidy swissspidy added the command:user-remove-role Related to 'user remove-role' command label Feb 26, 2026
@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy swissspidy added this to the 2.9.0 milestone Feb 26, 2026
@swissspidy swissspidy requested a review from Copilot February 26, 2026 10:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Clarifies wp user remove-role <id> behavior when no role is provided by improving both the documentation and the success output message.

Changes:

  • Documented the “no role args” behavior for wp user remove-role.
  • Added an example for invoking the command without specifying roles.
  • Updated the success message to explicitly state that roles were removed (not the user account).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/User_Command.php Updates command docs and refines the success message for the no-role-argument path.
features/user.feature Updates the acceptance test to assert the new success output text.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

WP_CLI::success( "Removed {$user->user_login} ({$user->ID}) from " . site_url() . '.' );
WP_CLI::success( "Removed all roles from {$user->user_login} ({$user->ID}) on " . site_url() . '.' );
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new message is clearer for single-site, but it may be inaccurate on multisite where the no-role path can remove the user from the site/blog (not just strip roles). Consider branching the message for multisite (e.g., explicitly “Removed user from site …” or “Removed all roles (user removed from site on multisite) …”) so the output reflects what actually happened.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Comment on lines +811 to 812
* removed from the user.
*
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc update still omits the multisite nuance called out in the issue context (no role args may remove the user from the site/blog). Please update the synopsis description to mention the multisite behavior explicitly, so users aren’t surprised by being removed from a site when running the command on multisite.

Suggested change
* removed from the user.
*
* removed from the user; on multisite, this removes the user from the current
* site/blog.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:user-remove-role Related to 'user remove-role' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wp user remove-role <id> with no role arguments could produce a less scary display result

3 participants