Class: WP_Role

Core class used to extend the user roles API.

Properties


Properties

Name Type(s) Default Value Summary
name string Role name.
capabilities array List of capabilities the role contains.

Methods

WP_Role:: __construct( string $role, array $capabilities )

Constructor - Set up object properties. Since 2.0.0.

The list of capabilities, must have the key as the name of the capability and the value a boolean of whether it is granted to the role.

Arguments

Name Type(s) Default Value Description
$role string

Role name.

$capabilities array

List of capabilities.


WP_Role:: add_cap( string $cap, boolean $grant = true )

Assign role a capability. Since 2.0.0.

Arguments

Name Type(s) Default Value Description
$cap string

Capability name.

$grant boolean

Whether role has capability privilege.


WP_Role:: has_cap( string $cap )

Determines whether the role has the given capability. Since 2.0.0.

The capabilities is passed through the \'role_has_cap' filter. The first parameter for the hook is the list of capabilities the class has assigned. The second parameter is the capability name to look for. The third and final parameter for the hook is the role name.

Arguments

Name Type(s) Default Value Description
$cap string

Capability name.

Returns

boolean

True if the role has the given capability. False otherwise.


WP_Role:: remove_cap( string $cap )

Removes a capability from a role. Since 2.0.0.

This is a container for WP_Roles::remove_cap() to remove the capability from the role. That is to say, that WP_Roles::remove_cap() implements the functionality, but it also makes sense to use this class, because you don't need to enter the role name.

Arguments

Name Type(s) Default Value Description
$cap string

Capability name.


WordPress Developer Newsletter

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