Adds a role name with capabilities to the list.
Updates the list of roles, if the role doesn’t already exist.
The capabilities are defined in the following format: array( 'read' => true ).
To explicitly deny the role a capability, set the value for that capability to false.
$rolestringrequired
$display_namestringrequired
$capabilitiesbool[]optional
array( 'edit_posts' => true, 'delete_posts' => false ).Default:array()
public function add_role( $role, $display_name, $capabilities = array() ) {
if ( empty( $role ) || isset( $this->roles[ $role ] ) ) {
return;
}
$this->roles[ $role ] = array(
'name' => $display_name,
'capabilities' => $capabilities,
);
if ( $this->use_db ) {
update_option( $this->role_key, $this->roles, true );
}
$this->role_objects[ $role ] = new WP_Role( $role, $capabilities );
$this->role_names[ $role ] = $display_name;
return $this->role_objects[ $role ];
}
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_roles/add_role