• So I a bit confused, because WordPress manual does not gives me an answer.

    add_cap() function has the database storage call:

    public function add_cap( $role, $cap, $grant = true ) {
    		if ( ! isset( $this->roles[$role] ) )
    			return;
    
    		$this->roles[$role]['capabilities'][$cap] = $grant;
    		if ( $this->use_db )
    			update_option( $this->role_key, $this->roles );
    	}

    But what if I want to add new capability when creating new role. I.e. the new role should be ‘grandmaster‘ and I want to give him a new ‘can_play_chess‘ capability immediately in plugin activation:

    $result = add_role(
        'grandmaster',
        __( 'Grandmaster' ),
        array(
            'read'         => true,  // true allows this capability
            'can_play_chess' => true,
        )
    );

    Is this is allowed, and is this is a correct way to adding both – new role and new capability.

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can I assign a new capability when creating a role’ is closed to new replies.