PHP Class WPDKUserRoles

Since: 1.6.0
Author: =undo= ([email protected])
Inheritance: extends WP_Roles
Show file Open project: wpxtreme/wpdk Class Usage Examples

Public Properties

Property Type Description
$activeRoles array An array with all active roles
$all_roles array Array with the list of all roles.
$arrayCapabilitiesByRole array An key value pairs array with key = role and value = list of capabilities.
$arrayCountUsersByRole array List with count role group by user
$count integer Number of roles
$inactiveRoles array An array with all inactive roles
$wordPressRoles array Default WordPress roles

Public Methods

Method Description
__construct ( ) : WPDKUserRoles Create an instance of WPDKUserRoles class
activeRoles ( ) : array
add_role ( string $role, string $display_name, array $capabilities = [], string $description = '', string $owner = '' ) : null | WP_Role Updates the list of roles, if the role doesn't already exist.
arrayCapabilitiesByRole ( ) : array Create An key value pairs array with key = role and value = list of capabilities.
countUsersByRole ( ) : array Set the arrayCountUsersByRole property with the list of user count by role.
getInstance ( ) : WPDKUserRoles Create a singleton instance of WPDKUserRoles class
get_instance ( ) : WPDKUserRoles Create a singleton instance of WPDKUserRoles class
inactiveRoles ( ) : array
init ( ) : WPDKUserRoles Create a singleton instance of WPDKUserRoles class
invalidate ( ) : WPDKUserRoles Used to invalidate static (internal singleton) and refresh all roles list
remove_role ( string $role ) Remove a role
roleExists ( string $role ) : boolean Return TRUE if the role exists
rolesWithCaps ( WPDKCapability | string | array $caps ) : array Return the roles id list with one or more caps
statusRoles ( ) Set the activeRoles and inactiveRoles properties array.
wordPressRoles ( ) : mixed | void Return a key value pairs array with name of role and extends info.

Method Details

__construct() public method

Create an instance of WPDKUserRoles class
public __construct ( ) : WPDKUserRoles
return WPDKUserRoles

activeRoles() public method

Deprecation: since 1.6.0 - Use statusRoles() instead
public activeRoles ( ) : array
return array

add_role() public method

The capabilities are defined in the following format array( 'read' => true ); To explicitly deny a role a capability you set the value for that capability to false. In this overide method you can extends the capapilities array with format array( 'read' => true, 'description' => 'Thsi capability allow access to...' );
public add_role ( string $role, string $display_name, array $capabilities = [], string $description = '', string $owner = '' ) : null | WP_Role
$role string Role name.
$display_name string Role display name.
$capabilities array Optional. List of role capabilities in the above format.
$description string Optional. An extend description for this role.
$owner string Optional. Owner of this role
return null | WP_Role

arrayCapabilitiesByRole() public method

Create An key value pairs array with key = role and value = list of capabilities.
public arrayCapabilitiesByRole ( ) : array
return array

countUsersByRole() public method

Counts the number of users for all roles on the site and returns this as an array.
public countUsersByRole ( ) : array
return array

getInstance() public static method

Create a singleton instance of WPDKUserRoles class
public static getInstance ( ) : WPDKUserRoles
return WPDKUserRoles

get_instance() public static method

Create a singleton instance of WPDKUserRoles class
public static get_instance ( ) : WPDKUserRoles
return WPDKUserRoles

inactiveRoles() public method

Deprecation: since 1.6.0 - Use statusRoles() instead
public inactiveRoles ( ) : array
return array

init() public static method

Create a singleton instance of WPDKUserRoles class
public static init ( ) : WPDKUserRoles
return WPDKUserRoles

invalidate() public static method

Used to invalidate static (internal singleton) and refresh all roles list
public static invalidate ( ) : WPDKUserRoles
return WPDKUserRoles

remove_role() public method

Remove a role
public remove_role ( string $role )
$role string

roleExists() public method

Return TRUE if the role exists
public roleExists ( string $role ) : boolean
$role string Role key name
return boolean

rolesWithCaps() public method

Return the roles id list with one or more caps
Since: 1.5.4
public rolesWithCaps ( WPDKCapability | string | array $caps ) : array
$caps WPDKCapability | string | array Any instance of WPDKCapability class, capability name or array of capability name/instance of WPDKCapability class
return array

statusRoles() public method

Set the activeRoles and inactiveRoles properties array.
Since: 1.6.0
public statusRoles ( )

wordPressRoles() public method

Return a key value pairs array with name of role and extends info.
public wordPressRoles ( ) : mixed | void
return mixed | void

Property Details

$activeRoles public property

An array with all active roles
public array $activeRoles
return array

$all_roles public property

Array with the list of all roles.
public array $all_roles
return array

$arrayCapabilitiesByRole public property

An key value pairs array with key = role and value = list of capabilities.
public array $arrayCapabilitiesByRole
return array

$arrayCountUsersByRole public property

List with count role group by user
public array $arrayCountUsersByRole
return array

$count public property

Number of roles
public int $count
return integer

$inactiveRoles public property

An array with all inactive roles
public array $inactiveRoles
return array

$wordPressRoles public property

Default WordPress roles
public array $wordPressRoles
return array