add_role( string $role, string $display_name, bool[] $capabilities = array() )
Add 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 ); }
Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/add_role