wppaste
WordPress

add_role( string $role, string $display_name, bool[] $capabilities = array() ): WP_Role|void

Since
2.0.0
Source
wp-includes/capabilities.php:1110
Adds a role, if it does not exist.

Parameters

$rolestring
Role name.
$display_namestring
Display name for role.
$capabilitiesbool[]optional
List of capabilities keyed by the capability name, e.g. array( 'edit_posts' => true, 'delete_posts' => false ).Default: array()

Return

WP_Role|void
WP_Role object, if the role is added.

Uses · 2

  • wp_roles()Retrieves the global WP_Roles instance and instantiates it if necessary.
  • wp_roles()::add_role()

Used by · 1

Source

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

History

Introduced in 2.0.0. 2 changes between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.1.0
Return type changed from WP_Role|void to WP_Role|null.verified against source
6.9.7
Parameter $capabilities retyped from bool[] to array<string,bool>|array<int,string>.verified against source
2.0.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/capabilities.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.