wp-cli / entity-command

Manage WordPress comments, menus, options, posts, sites, terms, and users.
MIT License
100 stars 90 forks source link

2.4.0: `wp user remove-role <id>` with no role arguments could produce a less scary display result #291

Open lkraav opened 4 years ago

lkraav commented 4 years ago

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 #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
lkraav commented 4 years ago

PS looking at user set-role output, I'm not sure it fully makes sense either:

# wp user set-role 293 administrator
Success: Added leho (293) to <site> as administrator.

This reads like a user object was created, instead of a role change.

Your thoughts?

elenachavdarova commented 1 year ago

Hi, actually when there is no role listed, the user is being "deactivated" meanting they will no longer have access to the backend of the site, but their posts will still be visible at the website.

This is actually a good option to have in wp-cli on my opinion. Maybe the message can be edited only as it is a bit missleading.

danielbachhuber commented 1 year ago

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?