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.

Return

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

Usage

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

Code of add_role: wp-includes/capabilities.php VER 5.0.1

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

Related Functions

From tag: Roles capabilities

No comments
    Hello, !     Log In . Register