add_role() WordPress Function
The add_role() function is used to create new roles for users in a WordPress site. This function takes two parameters: the role name and a capabilities array. The role name is a string that is used to identify the role, while the capabilities array is used to specify the capabilities that the role will have.
add_role( string $role, string $display_name, bool[] $capabilities = array() ) #
Adds a role, if it does not exist.
Parameters
- $role
(string)(Required)Role name.
- $display_name
(string)(Required)Display name for role.
- $capabilities
(bool[])(Optional)List of capabilities keyed by the capability name, e.g. array( 'edit_posts' => true, 'delete_posts' => false ).
Default value: array()
Return
(WP_Role|null) WP_Role object if role is added, null if already exists.
Source
File: wp-includes/capabilities.php
function add_role( $role, $display_name, $capabilities = array() ) { if ( empty( $role ) ) { return; } return wp_roles()->add_role( $role, $display_name, $capabilities ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |