src/Role_Command.php
public function create( $args, $assoc_args ) {
		global $wp_roles;

		self::persistence_check();

		$role_key  = array_shift( $args );
		$role_name = array_shift( $args );

		if ( empty( $role_key ) || empty( $role_name ) ) {
			WP_CLI::error( "Can't create role, insufficient information provided." );
		}

		$capabilities = false;
		if ( ! empty( $assoc_args['clone'] ) ) {
			$role_obj = $wp_roles->get_role( $assoc_args['clone'] );
			if ( ! $role_obj ) {
				WP_CLI::error( "'{$assoc_args['clone']}' role not found." );
			}
			$capabilities = array_keys( $role_obj->capabilities );
		}

		if ( add_role( $role_key, $role_name ) ) {
			if ( ! empty( $capabilities ) ) {
				$role_obj = $wp_roles->get_role( $role_key );
				foreach ( $capabilities as $cap ) {
					$role_obj->add_cap( $cap );
				}
				WP_CLI::success( "Role with key '{$role_key}' created. Cloned capabilities from '{$assoc_args['clone']}'." );
			} else {
				WP_CLI::success( "Role with key '{$role_key}' created." );
			}
		} else {
			WP_CLI::error( "Role couldn't be created." );
		}
	}
public function create( $args, $assoc_args ) {
		global $wp_roles;

		self::persistence_check();

		$role_key  = array_shift( $args );
		$role_name = array_shift( $args );

		if ( empty( $role_key ) || empty( $role_name ) ) {
			WP_CLI::error( "Can't create role, insufficient information provided." );
		}

		$capabilities = false;
		if ( ! empty( $assoc_args['clone'] ) ) {
			$role_obj = $wp_roles->get_role( $assoc_args['clone'] );
			if ( ! $role_obj ) {
				WP_CLI::error( "'{$assoc_args['clone']}' role not found." );
			}
			$capabilities = array_keys( $role_obj->capabilities );
		}

		if ( add_role( $role_key, $role_name ) ) {
			if ( ! empty( $capabilities ) ) {
				$role_obj = $wp_roles->get_role( $role_key );
				foreach ( $capabilities as $cap ) {
					$role_obj->add_cap( $cap );
				}
				WP_CLI::success( "Role with key '{$role_key}' created. Cloned capabilities from '{$assoc_args['clone']}'." );
			} else {
				WP_CLI::success( "Role with key '{$role_key}' created." );
			}
		} else {
			WP_CLI::error( "Role couldn't be created." );
		}
	}
public function create ( $ args , $ assoc_args ) { global $ wp_roles ; self :: persistence_check ( ) ; $ role_key = array_shift ( $ args ) ; $ role_name = array_shift ( $ args ) ; if ( empty ( $ role_key ) || empty ( $ role_name ) ) { WP_CLI :: error ( "Can't create role, insufficient information provided." ) ; } $ capabilities = false ; if ( ! empty ( $ assoc_args [ 'clone' ] ) ) { $ role_obj = $ wp_roles -> get_role ( $ assoc_args [ 'clone' ] ) ; if ( ! $ role_obj ) { WP_CLI :: error ( "'{$assoc_args['clone']}' role not found." ) ; } $ capabilities = array_keys ( $ role_obj -> capabilities ) ; } if ( add_role ( $ role_key , $ role_name ) ) { if ( ! empty ( $ capabilities ) ) { $ role_obj = $ wp_roles -> get_role ( $ role_key ) ; foreach ( $ capabilities as $ cap ) { $ role_obj -> add_cap ( $ cap ) ; } WP_CLI :: success ( "Role with key '{$role_key}' created. Cloned capabilities from '{$assoc_args['clone']}'." ) ; } else { WP_CLI :: success ( "Role with key '{$role_key}' created." ) ; } } else { WP_CLI :: error ( "Role couldn't be created." ) ; } }
Creates a new role.

## OPTIONS

<role-key>
: The internal name of the role.

<role-name>
: The publicly visible name of the role.

[--clone=<role>]
: Clone capabilities from an existing role.

## EXAMPLES

# Create role for Approver.
$ wp role create approver Approver
Success: Role with key 'approver' created.

# Create role for Product Administrator.
$ wp role create productadmin "Product Administrator"
Success: Role with key 'productadmin' created.
Creates a new role .