wp cap

Adds, removes, and lists capabilities of a user role.

See references for Roles and Capabilities and WP User class.

See olso wp role command.

Commands Description
wp cap list Lists capabilities for a given role.
wp cap add Adds capabilities to a given role.
wp cap remove Removes capabilities from a given role.

Examples

# Add 'spectate' capability to 'author' role.
$ wp cap add 'author' 'spectate'
Success: Added 1 capability to 'author' role.

# Add all caps from 'editor' role to 'author' role.
$ wp cap list 'editor' | xargs wp cap add 'author'
Success: Added 24 capabilities to 'author' role.

# Remove all caps from 'editor' role that also appear in 'author' role.
$ wp cap list 'author' | xargs wp cap remove 'editor'
Success: Removed 34 capabilities from 'editor' role.

Source code of the commands


wp cap list

Lists capabilities for a given role.

Usage

wp cap list {role} [--format={format}] [--show-grant]

You can specify global options and the following:

{role}
Key for the role.
[--format={format}]

Render output in a particular format.
Default: list
Can be:

  • list
  • table
  • csv
  • json
  • count
  • yaml
[--show-grant]
Display all capabilities defined for a role including grant.
Default: false

Examples

# Display alphabetical list of Contributor capabilities.
$ wp cap list 'contributor' | sort
delete_posts
edit_posts
level_0
level_1
read

wp cap add

Adds capabilities to a given role.

Usage

wp cap add {role} {cap}... [--grant]

You can specify global options and the following:

{role}
Key for the role.
{cap}...
One or more capabilities to add.
[--grant]

Adds the capability as an explicit boolean value, instead of implicitly defaulting to true.
Default: true
Can be:

  • true
  • false

Examples

# Add 'spectate' capability to 'author' role.
$ wp cap add author spectate
Success: Added 1 capability to 'author' role.

wp cap remove

Removes capabilities from a given role.

Usage

wp cap remove {role} {cap}...

You can specify global options and the following:

{role}
Key for the role.
{cap}...
One or more capabilities to remove.

Examples

# Remove 'spectate' capability from 'author' role.
$ wp cap remove author spectate
Success: Removed 1 capability from 'author' role.