Skip to content

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

Merged
swissspidy merged 6 commits intomainfrom
copilot/fix-remove-role-display
Mar 2, 2026
Merged

Improve wp user remove-role docs and output when no role argument is given#580
swissspidy merged 6 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: Now branches based on context:
    • Single-site: "Removed all roles from {user} ({id}) on {site_url}." — clearly signals role removal, not account deletion
    • Multisite: "Removed {user} ({id}) from {site_url}." — accurately reflects that the user was removed from the site/blog
  • Docblock: Documents the no-argument behavior on [<role>...] (including the multisite nuance) and adds separate examples for single-site and multisite
# 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.
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

This comment was marked as resolved.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review March 1, 2026 08:46
@swissspidy swissspidy requested a review from a team as a code owner March 1, 2026 08:46
@swissspidy swissspidy merged commit 07eeaf7 into main Mar 2, 2026
68 checks passed
@swissspidy swissspidy deleted the copilot/fix-remove-role-display branch March 2, 2026 09:16
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