Function: add_role

add_role( string $role, string $display_name, array $capabilities )

Add role, if it does not exist.

Parameters

Name Type(s) Default Value Description
$role string

Role name.

$display_name string

Display name for role.

$capabilities array array()

List of capabilities, e.g. array( 'edit_posts' => true, 'delete_posts' => false );

Returns

WP_Role | null

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

WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.