Roles
Overview
Manage which WordPress roles an access level may see or assume. Select the subject with AAM::api()->roles($access_level, $settings). Omit $access_level to use the current user or visitor.
PHP class: AAM_Framework_Service_Roles.
Method reference
| Method | Purpose |
|---|---|
get_list() |
List explicitly configured entries. |
list() |
Alias of get_list(). |
deny($role_identifier, $permission) |
Store a deny rule. |
allow($role_identifier, $permission) |
Store an allow rule. |
is_denied_to($role_identifier, $permission) |
Check whether an action is denied. |
is_allowed_to($role_identifier, $permission) |
Check whether an action is allowed. |
is_hidden($role_identifier) |
Check whether listing is hidden. |
hide($role_identifier) |
Deny listing. |
show($role_identifier) |
Allow listing. |
reset($role_identifier = null) |
Remove one rule or all rules for this level. |
aggregate() |
Get effective permissions for this resource type. |
Return values vary by method. Rule updates usually return bool; reads can return a value, null, or an array. Errors follow the service’s error_handling setting and may produce WP_Error.
Accepted identifiers
Pass the target role as a registered role slug string, a WP_Role object, or an AAM role proxy. For example, deny('editor', 'list_role') and deny(get_role('editor'), 'list_role') target the same role. Obtain an AAM proxy with AAM::api()->role('editor')->get_proxy_instance(). The argument to roles() is the subject access level.
Example
$roles = AAM::api()->roles('role:editor');
$roles->deny('administrator', 'assume_role');
$blocked = $roles->is_denied_to('administrator', 'assume_role');
The service subject is the Editor role; administrator is the role it may try to assume. $blocked checks the assume_role decision for that target role.
Developer notes
- The first argument names the target WordPress role; the access level passed to
roles()is the subject. hide()andshow()write thelist_rolepermission.get_list()returns dynamic assumed-role rules, not the WordPress role registry.- The selected access level determines whose rules are stored or evaluated. See Access levels.
Behavior and parameters
deny($target_role, $permission)andallow()accept one permission string or an array. Useassume_rolefor role assumption andlist_rolefor listing.get_list()returns dynamically assumed roles and their decisions;aggregate()returns the effective permission map.reset($role = null)removes rules for one target or all targets.