Admin toolbar
Overview
Manage access to WordPress admin toolbar nodes. Select the subject with AAM::api()->admin_toolbar($access_level, $settings). Omit $access_level to use the current user or visitor.
PHP class: AAM_Framework_Service_AdminToolbar.
Method reference
| Method | Purpose |
|---|---|
get_items() |
List discovered items. |
items() |
Alias of get_items(). |
get_item($slug) |
Get one discovered item. |
item($item_id) |
Alias of get_item(). |
deny($item_id) |
Store a deny rule. |
allow($item_id) |
Store an allow rule. |
reset($item_id = null) |
Reset toolbar rules for this level. |
is_denied($slug) |
Check the effective deny decision. |
is_allowed($item_id) |
Check the effective allow decision. |
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 toolbar node ID as a string, for example 'wp-logo' or 'my-account'. Use get_items() to discover IDs after WordPress populates the toolbar. A node’s visible title or URL is not its identifier.
Example
$toolbar = AAM::api()->admin_toolbar('role:subscriber');
$toolbar->deny('wp-logo');
$hidden = $toolbar->is_denied('wp-logo');
This hides the wp-logo toolbar node for Subscribers. $hidden reads the role’s effective decision for that node.
Developer notes
- Use the toolbar node ID, including the parent ID where appropriate.
- The toolbar must be populated before item discovery methods can return its nodes.
- The selected access level determines whose rules are stored or evaluated. See Access levels.
Behavior and parameters
deny($item_id)andallow($item_id)write a toolbar rule. In the current implementation,reset()clears all toolbar rules even when an ID is passed.is_denied()andis_allowed()resolve the effective decision.get_items()returns discovered nodes andget_item($id)returns one node.items()anditem()are aliases.- A child node can inherit a parent decision. Use WordPress toolbar node IDs, then test the result after toolbar registration.