Assign role a capability.
Parameters
$cap
stringrequired- Capability name.
$grant
booloptional- Whether role has capability privilege.
Default:
true
Source
public function add_cap( $cap, $grant = true ) {
$this->capabilities[ $cap ] = $grant;
wp_roles()->add_cap( $this->name, $cap, $grant );
}
Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |
Example
NB: This setting is saved to the database, so it might be better to run this on theme/plugin activation
To add capability to specific user :
Note that add_cap only accept one string; you cannot add multiple using a single add_cap call; you need to make multiple add_cap calls like the following:
$your_var -> add_cap( 'edit_others_posts' );
$your_var -> add_cap( 'upload_files' );