wp-cli / role-command

Adds, removes, lists, and resets roles and capabilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wp cap list output does not reflect grant

kshaner opened this issue · comments

Listing a role's capabilities does not show whether the capability has been granted or not.

Example code from a plugin/theme:

get_role('contributor')->add_cap('custom_capability', false)

wp cli output for wp cap list contributor:

edit_posts
read
level_1
level_0
delete_posts
custom_capability

Whether the adding of false for a capability is correct instead of removing it is another discussion, but the grant status should be shown in the output since it is a valid argument for add_cap.

I would propose the output using the table formatter by default and adding a second column for grant.

+1 for addressing this issue. I don't feel like this command is useful without the distinction.

In the docs, wp cap list is described as:

Lists capabilities for a given role.

To me, that means capabilities a given role is granted. As an alternative to showing grant in a different column, I propose hiding all capabilities with grant = false since user_can( $user, $cap ) === false

Yes, I agree, this distinction is important and mustn't get lost.

To keep from breaking existing scripts, I think we should go with @dougaxe1 's proposal. Additionally, we can provide a more detailed list representation under a separate flag, like --show-grants or so.

Fixed via #19

Thanks for taking care of this, @kshaner ! 🙂