PHP Класс WPDKRolesCaps

Устаревший: Since 1.0.0.b4 - Nveere used WPDKRolesCaps class extends features of roles and capabilities in a WordPress environment. ## Overview [draft]
Автор: yuma - ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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
cap_exists ( string $sCapName ) : boolean Check if a capability exists in the whole WordPress system.
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.
create_role ( string $sRoleName, string $sRoleLabel, array $aNewData = [] ) : mixed Create a brand new 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.
init ( ) : boolean Initialize static instance of this class.
role_exists ( string $sRoleName ) : boolean Check if a role exists in the whole WordPress system.
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.

Приватные методы

Метод Описание
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.

Описание методов

add_cap_to_role() статический публичный Метод

Add an existing capability to a specific WordPress role
С версии: 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.
Результат mixed TRUE|WPDKError

add_cap_to_user() статический публичный Метод

Add an existing capability to a specific WordPress user
С версии: 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.
Результат mixed TRUE|WPDKError

cap_exists() статический публичный Метод

Check if a capability exists in the whole WordPress system.
С версии: 1.0.0
static public cap_exists ( string $sCapName ) : boolean
$sCapName string The capability name.
Результат boolean

create_cap() статический публичный Метод

Create a brand new capability for a role, with some new params that extends normal WordPress handling.
С версии: 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().
Результат mixed TRUE|WPDKError

create_role() статический публичный Метод

Create a brand new role, with some new params that extends normal WordPress handling.
С версии: 1.0.0
static public create_role ( string $sRoleName, string $sRoleLabel, array $aNewData = [] ) : 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 ).
$aNewData array (optional) array of new extended data related to this role. Default to array().
Результат mixed TRUE|WPDKError

delete_cap_from_role() статический публичный Метод

WARNING: with this method, I can ALSO DELETE A CAPABILITY FROM DEFAULT ROLES, LIKE administrator. Please use VERY CAREFULLY this facility.
С версии: 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
Результат mixed TRUE|WPDKError

delete_cap_from_user() статический публичный Метод

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.
С версии: 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
Результат mixed TRUE|WPDKError

delete_extended_cap_data() статический публичный Метод

Delete extended data about a specific capability.
С версии: 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.
Результат TRUE | FALSE : if the capability is in, return TRUE if its extended data has been deleted, FALSE otherwise.

delete_extended_role_data() статический публичный Метод

Delete extended data about a specific role.
С версии: 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.
Результат TRUE | FALSE : if the role is in, return TRUE if extended data has been delete, FALSE otherwise.

delete_role() статический публичный Метод

WARNING: with this method, I can ALSO COMPLETELY DELETE DEFAULT ROLES, LIKE administrator. Please use VERY CAREFULLY this facility.
С версии: 1.0.0
static public delete_role ( string $sRoleName ) : mixed
$sRoleName string - role name/key to delete
Результат mixed TRUE|WPDKError

get_all_caps() статический публичный Метод

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.
С версии: 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.
Результат array All capabilities in WordPress system.

get_all_roles() статический публичный Метод

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.
С версии: 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.
Результат array All roles in WordPress system, standard or extended, according to $iMode.

get_cap_data() статический публичный Метод

Get all data about a specific capability, including extended one.
С версии: 1.0.0
static public get_cap_data ( string $sCapName ) : mixed
$sCapName string - capability name/key to get data of.
Результат mixed array|FALSE : if the capability is in, return an array with all data about it

get_caps_of_role() статический публичный Метод

Get all capabilities data about a specific role, including extended one.
С версии: 1.0.0
static public get_caps_of_role ( string $sRoleName ) : mixed
$sRoleName string - role to get data of.
Результат mixed array|FALSE : if the role is in, return an array with all data about its capabilities

get_caps_of_user() статический публичный Метод

Get all capabilities data about a specific user, including extended one.
С версии: 1.0.0
static public get_caps_of_user ( integer $iIDUser ) : mixed
$iIDUser integer - user ID in WordPress environment
Результат mixed array|FALSE : if the user exists, return an array with all data about its capabilities

get_role_data() статический публичный Метод

Get all data about a specific role, including extended one.
С версии: 1.0.0
static public get_role_data ( string $sRoleName ) : mixed
$sRoleName string - role name/key to get data of.
Результат mixed array|FALSE : if the role is in, return an array with all data about it

get_user_role() статический публичный Метод

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.
С версии: 1.0.0
static public get_user_role ( integer $iIDUser ) : array | WPDKError
$iIDUser integer - user ID in WordPress environment
Результат array | WPDKError The main role of the user, or an instance of WPDKError object in case of an error.

init() статический публичный Метод

Initialize static instance of this class.
С версии: 1.0.0
static public init ( ) : boolean
Результат boolean TRUE if init operations are OK, FALSE otherwise

role_exists() статический публичный Метод

Check if a role exists in the whole WordPress system.
С версии: 1.0.0
static public role_exists ( string $sRoleName ) : boolean
$sRoleName string The role name.
Результат boolean

set_extended_cap_data() статический публичный Метод

Set extended data about a specific capability, or update extended data for the same key.
С версии: 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.
Результат TRUE | FALSE : if the capability is in, return TRUE if extended data has been stored, FALSE otherwise.

set_extended_role_data() статический публичный Метод

Set extended data about a specific role, or update extended data for the same key.
С версии: 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.
Результат TRUE | FALSE : if the role is in, return TRUE if extended data has been stored, FALSE otherwise.

set_main_role_of_user() статический публичный Метод

Set the main role of a WordPress user.
С версии: 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
Результат mixed TRUE|WPDKError