src/Capabilities_Command.php
public function add( $args, $assoc_args ) {
		self::persistence_check();

		$role = array_shift( $args );

		$role_obj = self::get_role( $role );

		$grant = ! isset( $assoc_args['grant'] ) || ! empty( $assoc_args['grant'] );

		$count = 0;

		foreach ( $args as $cap ) {
			if ( true === $grant && $role_obj->has_cap( $cap ) ) {
				continue;
			}

			if ( false === $grant && isset( $role_obj->capabilities[ $cap ] ) && false === $role_obj->capabilities[ $cap ] ) {
				continue;
			}

			$role_obj->add_cap( $cap, $grant );

			$count++;
		}

		$capability          = WP_CLI\Utils\pluralize( 'capability', $count );
		$grant_qualification = $grant ? '' : ' as false';

		WP_CLI::success( "Added {$count} {$capability} to '{$role}' role{$grant_qualification}." );
	}
public function add( $args, $assoc_args ) {
		self::persistence_check();

		$role = array_shift( $args );

		$role_obj = self::get_role( $role );

		$grant = ! isset( $assoc_args['grant'] ) || ! empty( $assoc_args['grant'] );

		$count = 0;

		foreach ( $args as $cap ) {
			if ( true === $grant && $role_obj->has_cap( $cap ) ) {
				continue;
			}

			if ( false === $grant && isset( $role_obj->capabilities[ $cap ] ) && false === $role_obj->capabilities[ $cap ] ) {
				continue;
			}

			$role_obj->add_cap( $cap, $grant );

			$count++;
		}

		$capability          = WP_CLI\Utils\pluralize( 'capability', $count );
		$grant_qualification = $grant ? '' : ' as false';

		WP_CLI::success( "Added {$count} {$capability} to '{$role}' role{$grant_qualification}." );
	}
public function add ( $ args , $ assoc_args ) { self :: persistence_check ( ) ; $ role = array_shift ( $ args ) ; $ role_obj = self :: get_role ( $ role ) ; $ grant = ! isset ( $ assoc_args [ 'grant' ] ) || ! empty ( $ assoc_args [ 'grant' ] ) ; $ count = 0 ; foreach ( $ args as $ cap ) { if ( true === $ grant && $ role_obj -> has_cap ( $ cap ) ) { continue ; } if ( false === $ grant && isset ( $ role_obj -> capabilities [ $ cap ] ) && false === $ role_obj -> capabilities [ $ cap ] ) { continue ; } $ role_obj -> add_cap ( $ cap , $ grant ) ; $ count ++ ; } $ capability = WP_CLI \ Utils \ pluralize ( 'capability' , $ count ) ; $ grant_qualification = $ grant ? '' : ' as false' ; WP_CLI :: success ( "Added {$count} {$capability} to '{$role}' role{$grant_qualification}." ) ; }
Adds capabilities to a given role.

## OPTIONS

<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
options:
- true
- false
---

## EXAMPLES

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