Codex

Function Reference/add cap

Contents

Description

Adds a capability to a role.

Usage

 <?php add_cap$role$cap$grant ); ?> 

Parameters

role
(string) (Required) role name
Default: None
cap
(string) (Required) capability name
Default: None
grant
(boolean) (optional) Whether the role is capable of performing this capability.
Default: true

Example

function add_theme_caps() {
$role = get_role( 'author' ); // gets the author role
 
$role->add_cap( 'edit_others_posts' ); // would allow the author to edit others' posts for current theme only
}
add_action( 'admin_init', 'add_theme_caps');

Notes

Changelog

Source File

add_cap is located in wp-includes/capabilities.php.

Resources

Related

Roles and Capabilities: add_role(), remove_role(), get_role(), add_cap(), remove_cap()

See also index of Function Reference and index of Template Tags.