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

Add role, if it does not exist.


Parameters

$role

(Required) Role name.

$display_name

(Required) Display name for role.

$capabilities

(Optional) List of capabilities, 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

Changelog
Version Description
WP-2.0.0 Introduced.