WordPress at a glance

add_role() WP 1.0

Add role, if it does not exist.

Works based on: wp_roles(), WP_Roles()

No Hooks.


WP_Role/null. WP_Role object if role is added, null if already exists.


add_role( $role, $display_name, $capabilities );
$role(string) (required)
Role name.
$display_name(string) (required)
Display name for role.
List of capabilities, e.g. array( 'edit_posts' => true, 'delete_posts' => false );
Default: array()

Code of add role: wp-includes/capabilities.php VER 5.1

function add_role( $role, $display_name, $capabilities = array() ) {
	if ( empty( $role ) ) {
	return wp_roles()->add_role( $role, $display_name, $capabilities );

Related Functions

From tag: Roles capabilities

No comments
    Hello, !     Log In . Register