WP_Role::add_cap( string $cap, bool $grant = true )
Assign role a capability.
Description Description
Parameters Parameters
- $cap
-
(string) (Required) Capability name.
- $grant
-
(bool) (Optional) Whether role has capability privilege.
Default value: true
Source Source
File: wp-includes/class-wp-role.php
public function add_cap( $cap, $grant = true ) { $this->capabilities[ $cap ] = $grant; wp_roles()->add_cap( $this->name, $cap, $grant ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Example
NB: This setting is saved to the database, so it might be better to run this on theme/plugin activation
Expand full source codeCollapse full source code
To add capability to specific user :