PHP Class __WPDKRoles

Inheritance: extends WP_Roles
Show file Open project: wpxtreme/wpdk

Public Properties

Property Type Description
$countRoles integer The total number of roles

Public Methods

Method Description
__construct ( ) The class constructor, that extends in some part the default constructor of parent WP_Roles
add_cap_to_role ( string $sRoleName, string $sCapName, boolean $bCapValue = TRUE ) : mixed Add an existing capability to a specific WordPress role
add_cap_to_user ( integer $iIDUser, string $sCapName, boolean $bCapValue = TRUE ) : mixed Add an existing capability to a specific WordPress user
add_role ( string $sRoleName, string $sRoleLabel, array $aCapabilities = [] ) : mixed Create a brand new role, with its capabilities. The add_role from parent is simply made more secure.
create_cap ( string $sCapName, string $sRole, boolean $bCapValue = TRUE, array $aNewData = [] ) : mixed Create a brand new capability for a role, with some new params that extends normal WordPress handling.
delete_cap_from_role ( string $sRoleName, string $sCapName ) : mixed Delete an existing capability from a specific WordPress role.
delete_cap_from_user ( integer $iIDUser, string $sCapName ) : mixed Delete a capability from a specific WordPress user WARNING: with this method, I can ALSO DELETE A CAPABILITY FROM DEFAULT USERS, LIKE admin. Please use VERY CAREFULLY this facility.
delete_extended_cap_data ( string $sCapName, integer | array $aExtendedKey ) : TRUE | FALSE Delete extended data about a specific capability.
delete_extended_role_data ( string $sRoleName, integer | array $aExtendedKey ) : TRUE | FALSE Delete extended data about a specific role.
delete_role ( string $sRoleName ) : mixed Delete an existing WordPress role.
get_all_caps ( integer $iGroupedBy = self::CAPS_NOT_GROUPED_BY_ROLE ) : array Return a multidimensional array with all actual caps in the whole WordPress system, and all extended data eventually associated to them.
get_all_roles ( integer $iMode ) : array If $iMode param is equal to self::WP_STANDARD, directly returns output of get_names() method of WP_Roles object.
get_cap_data ( string $sCapName ) : mixed Get all data about a specific capability, including extended one.
get_caps_of_role ( string $sRoleName ) : mixed Get all capabilities data about a specific role, including extended one.
get_caps_of_user ( integer $iIDUser ) : mixed Get all capabilities data about a specific user, including extended one.
get_role_data ( string $sRoleName ) : mixed Get all data about a specific role, including extended one.
get_user_role ( integer $iIDUser ) : array | WPDKError Return the main role of a user in the whole WordPress system, with all extended data eventually associated to it.
set_extended_cap_data ( string $sCapName, array $aNewData ) : TRUE | FALSE Set extended data about a specific capability, or update extended data for the same key.
set_extended_role_data ( string $sRoleName, array $aNewData ) : TRUE | FALSE Set extended data about a specific role, or update extended data for the same key.
set_main_role_of_user ( integer $iIDUser, string $sRoleName ) : mixed Set the main role of a WordPress user.

Private Methods

Method Description
_countUsersByRole ( ) Counts the number of users for every role on the site and set this value into the array of roles created by WP_Roles.
delete_extended_data ( string $sKey, integer | array $aExtendedKey ) : TRUE | FALSE Delete options about extended data, with checks.
update_extended_data ( string $sKey, array $aNewData ) : TRUE | FALSE Update options about extended data, with checks.

Method Details

__construct() public method

The class constructor, that extends in some part the default constructor of parent WP_Roles
Since: 0.0.1
public __construct ( )

add_cap_to_role() static public method

Add an existing capability to a specific WordPress role
Since: 1.0.0
static public add_cap_to_role ( string $sRoleName, string $sCapName, boolean $bCapValue = TRUE ) : mixed
$sRoleName string - role name/key that receive the cap
$sCapName string - capability name/key
$bCapValue boolean (optional) boolean value of capability. Default to TRUE.
return mixed TRUE|WPDKError

add_cap_to_user() static public method

Add an existing capability to a specific WordPress user
Since: 1.0.0
static public add_cap_to_user ( integer $iIDUser, string $sCapName, boolean $bCapValue = TRUE ) : mixed
$iIDUser integer - user ID in WordPress environment
$sCapName string - capability name/key
$bCapValue boolean (optional) boolean value of capability. Default to TRUE.
return mixed TRUE|WPDKError

add_role() public method

Create a brand new role, with its capabilities. The add_role from parent is simply made more secure.
Since: 0.0.1
public add_role ( string $sRoleName, string $sRoleLabel, array $aCapabilities = [] ) : mixed
$sRoleName string - role name/key in DB and in the whole system
$sRoleLabel string - label of role in WordPress environment ( i.e. in user settings ).
$aCapabilities array (optional) Array of capabilities for this role. Default to array().
return mixed WP_Role|WPDKError : the new role, or the error occurred.

create_cap() static public method

Create a brand new capability for a role, with some new params that extends normal WordPress handling.
Since: 1.0.0
static public create_cap ( string $sCapName, string $sRole, boolean $bCapValue = TRUE, array $aNewData = [] ) : mixed
$sCapName string - capability name/key in DB and in the whole system
$sRole string - role the capability belongs to.
$bCapValue boolean (optional) boolean value of capability. Default to TRUE.
$aNewData array (optional) array of new extended data related to this cap. Default to array().
return mixed TRUE|WPDKError

delete_cap_from_role() static public method

WARNING: with this method, I can ALSO DELETE A CAPABILITY FROM DEFAULT ROLES, LIKE administrator. Please use VERY CAREFULLY this facility.
Since: 1.0.0
static public delete_cap_from_role ( string $sRoleName, string $sCapName ) : mixed
$sRoleName string - role name/key that will drop the cap
$sCapName string - capability name/key
return mixed TRUE|WPDKError

delete_cap_from_user() static public method

Delete a capability from a specific WordPress user WARNING: with this method, I can ALSO DELETE A CAPABILITY FROM DEFAULT USERS, LIKE admin. Please use VERY CAREFULLY this facility.
Since: 1.0.0
static public delete_cap_from_user ( integer $iIDUser, string $sCapName ) : mixed
$iIDUser integer - user ID in WordPress environment
$sCapName string - capability name/key
return mixed TRUE|WPDKError

delete_extended_cap_data() static public method

Delete extended data about a specific capability.
Since: 1.0.0
static public delete_extended_cap_data ( string $sCapName, integer | array $aExtendedKey ) : TRUE | FALSE
$sCapName string - capability name/key to delete extended data of.
$aExtendedKey integer | array - ALL_EXTENDED_DATA, or an array of extended keys to delete. If this param is equal to ALL_EXTENDED_DATA, then all extended data related to the capability will be deleted.
return TRUE | FALSE : if the capability is in, return TRUE if its extended data has been deleted, FALSE otherwise.

delete_extended_role_data() static public method

Delete extended data about a specific role.
Since: 1.0.0
static public delete_extended_role_data ( string $sRoleName, integer | array $aExtendedKey ) : TRUE | FALSE
$sRoleName string - role name/key to delete extended data of.
$aExtendedKey integer | array - ALL_EXTENDED_DATA, or an array of extended keys to delete. If this param is equal to ALL_EXTENDED_DATA, then all extended data related to the role will be deleted.
return TRUE | FALSE : if the role is in, return TRUE if extended data has been delete, FALSE otherwise.

delete_role() static public method

WARNING: with this method, I can ALSO COMPLETELY DELETE DEFAULT ROLES, LIKE administrator. Please use VERY CAREFULLY this facility.
Since: 1.0.0
static public delete_role ( string $sRoleName ) : mixed
$sRoleName string - role name/key to delete
return mixed TRUE|WPDKError

get_all_caps() static public method

The basic format of this array is like this example (if caps ARE NOT grouped by role): array(n) { ..... ["switch_themes"]=> array(1) { ["grant"]=> bool(true) } ..... ["writiness"]=> array(4) { ["grant"]=> bool(true) ["description"]=> string(24) "Descrizione di writiness" ["label"]=> string(18) "label di writiness" ["input"]=> string(31) "questa e una nuova cap" } } Every single main key is the cap key/name, and indexes a further array, in which all extended data about cap are stored. This array has only one fixed key, 'grant', equal to the default grant related to the cap. All others key are extended and dynamically handled data. If the array of caps is grouped by role, the behaviour is equivalent; the only difference is that the first main key is not the single cap, but the role the cap belongs to.
Since: 1.0.0
static public get_all_caps ( integer $iGroupedBy = self::CAPS_NOT_GROUPED_BY_ROLE ) : array
$iGroupedBy integer - whether or not return the array grouped by role. self::CAPS_NOT_GROUPED_BY_ROLE means the array will be unidimensional; self::CAPS_GROUPED_BY_ROLE means the array will be grouped by single role.
return array All capabilities in WordPress system.

get_all_roles() static public method

Else, return a multidimensional array with all actual roles in the whole WordPress system, and all extended data eventually associated to them. The basic format of this array is: array(n) { ........ ["administrator"]=> array(1) { ["display_label"]=> string(13) "Administrator" } ....... } Every single main key is the role key/name, and indexes a further array, in which all extended data about role are stored. This array has only one fixed key, 'display_label', equal to the label string shown by WordPress related to the role. All others key are extended and dynamically handled data.
Since: 1.0.0
static public get_all_roles ( integer $iMode ) : array
$iMode integer - (optional) return mode. If it is equal to self::WP_STANDARD, the method returns the standard data from WP environment.
return array All roles in WordPress system, standard or extended, according to $iMode.

get_cap_data() static public method

Get all data about a specific capability, including extended one.
Since: 1.0.0
static public get_cap_data ( string $sCapName ) : mixed
$sCapName string - capability name/key to get data of.
return mixed array|FALSE : if the capability is in, return an array with all data about it

get_caps_of_role() static public method

Get all capabilities data about a specific role, including extended one.
Since: 1.0.0
static public get_caps_of_role ( string $sRoleName ) : mixed
$sRoleName string - role to get data of.
return mixed array|FALSE : if the role is in, return an array with all data about its capabilities

get_caps_of_user() static public method

Get all capabilities data about a specific user, including extended one.
Since: 1.0.0
static public get_caps_of_user ( integer $iIDUser ) : mixed
$iIDUser integer - user ID in WordPress environment
return mixed array|FALSE : if the user exists, return an array with all data about its capabilities

get_role_data() static public method

Get all data about a specific role, including extended one.
Since: 1.0.0
static public get_role_data ( string $sRoleName ) : mixed
$sRoleName string - role name/key to get data of.
return mixed array|FALSE : if the role is in, return an array with all data about it

get_user_role() static public method

For some reason, a user can have more roles, but for WordPress the main role is the first element in (WP_User)->roles. This function respects this behaviour.
Since: 1.0.0
static public get_user_role ( integer $iIDUser ) : array | WPDKError
$iIDUser integer - user ID in WordPress environment
return array | WPDKError The main role of the user, or an instance of WPDKError object in case of an error.

set_extended_cap_data() static public method

Set extended data about a specific capability, or update extended data for the same key.
Since: 1.0.0
static public set_extended_cap_data ( string $sCapName, array $aNewData ) : TRUE | FALSE
$sCapName string - capability name/key to get data of.
$aNewData array array of new extended data related to this cap.
return TRUE | FALSE : if the capability is in, return TRUE if extended data has been stored, FALSE otherwise.

set_extended_role_data() static public method

Set extended data about a specific role, or update extended data for the same key.
Since: 1.0.0
static public set_extended_role_data ( string $sRoleName, array $aNewData ) : TRUE | FALSE
$sRoleName string - role name/key to get data of.
$aNewData array array of new extended data related to this role.
return TRUE | FALSE : if the role is in, return TRUE if extended data has been stored, FALSE otherwise.

set_main_role_of_user() static public method

Set the main role of a WordPress user.
Since: 1.0.0
static public set_main_role_of_user ( integer $iIDUser, string $sRoleName ) : mixed
$iIDUser integer - user ID in WordPress environment
$sRoleName string - role name/key
return mixed TRUE|WPDKError

Property Details

$countRoles public property

The total number of roles
public int $countRoles
return integer