The list of capabilities can be passed either as a numerically indexed array of capability names, or an associative array of boolean values keyed by the capability name. To explicitly deny the role a capability, set the value for that capability to false. Examples: // Add a role that can edit posts.
add_role( 'custom_role', 'Custom Role', array(
'read',
'edit_posts',
) ); Or, using an associative array: // Add a role that can edit posts but explicitly cannot not delete them.
add_role( 'custom_role', 'Custom Role', array(
'read' => true,
'edit_posts' => true,
'delete_posts' => false,
) );
Signature, return type and hooks compared across 5 parsed releases.
7.1.0
Return type changed from WP_Role|void to WP_Role|null.verified against source
6.9.7
Parameter $capabilities retyped from bool[] to array<string,bool>|array<int,string>.verified against source
6.9.0
Support was added for a numerically indexed array of strings for the capabilities array.from the docblock
2.0.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/capabilities.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.