Widgets
Overview
Manage visibility of registered WordPress widgets. Select the subject with AAM::api()->widgets($access_level, $settings). Omit $access_level to use the current user or visitor.
PHP class: AAM_Framework_Service_Widgets.
Method reference
| Method | Purpose |
|---|---|
deny($widget) |
Store a deny rule. |
allow($widget) |
Store an allow rule. |
reset($widget = null) |
Remove one rule or all rules for this level. |
is_denied($widget) |
Check the effective deny decision. |
is_allowed($widget) |
Check the effective allow decision. |
is_customized($widget = null) |
Check for a direct rule or preference. |
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 a widget slug string such as 'search-2', a descriptor ['slug' => 'search-2'], or a descriptor with a registered callback such as ['callback' => 'my_plugin_render_widget']. AAM derives a slug from a callback descriptor. Prefer a discovered widget ID when available so the rule matches the registered widget.
Example
$widgets = AAM::api()->widgets('role:subscriber');
$widgets->deny('search-2');
$hidden = $widgets->is_denied('search-2');
This hides widget search-2 for Subscribers. $hidden reads the effective visibility decision for that widget.
Developer notes
- Use the widget ID accepted by the service.
reset()without an argument removes all widget rules for the selected access level.- The selected access level determines whose rules are stored or evaluated. See Access levels.
Behavior and parameters
deny($widget)andallow($widget)write visibility rules.is_denied()andis_allowed()check the result.is_customized($widget = null)checks for a direct rule.reset($widget = null)removes one widget rule or all widget rules.