Hooks
Overview
Apply conditional changes to WordPress actions and filters. Select the subject with AAM::api()->hooks($access_level, $settings). Omit $access_level to use the current user or visitor.
PHP class: AAM_Framework_Service_Hooks.
Method reference
| Method | Purpose |
|---|---|
get_hooks() |
List configured hook rules. |
deny($hook, $priority = 10) |
Store a deny rule. |
allow($hook, $priority = 10) |
Store an allow rule. |
alter($hook, $return, $priority = 10) |
Set a replacement filter value. |
merge($hook, array $data, $priority = 10) |
Merge data into a filter value. |
replace($hook, $value, $priority = 10) |
Replace a capability or hook value. |
reset() |
Remove one rule or all rules for this level. |
listen($hook = null) |
Attach listeners for hook rules. |
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 WordPress action or filter name string, for example 'the_content', and optionally its priority: deny('the_content', 20). The priority distinguishes rules for the same hook. listen() can take a runtime hook descriptor; it does not use a post or user identifier.
Example
$hooks = AAM::api()->hooks('role:subscriber');
$hooks->deny('my_plugin_sensitive_action');
// Attach listeners for the current user or visitor.
AAM::api()->hooks()->listen();
The rule is stored for Subscribers. listen() attaches listeners for the current user or visitor; call it during a Subscriber request before this action fires.
Developer notes
listen()works only for a user or visitor access level. Call it after defining rules and before the target hook fires.- Use
deny(),alter(),merge(), orreplace()for the needed action or filter behavior. - The selected access level determines whose rules are stored or evaluated. See Access levels.
Behavior and parameters
deny($hook)disables a configured hook;allow($hook)removes that denial.alter(),merge(), andreplace()set effects for filter values.reset()removes a stored rule.listen()attaches all stored hook rules, or accepts an array with anamekey for a runtime listener. Connect it early enough for the relevant action or filter.- Hook effects change code execution or filter data. Test the exact hook and argument shape; avoid broad rules on hooks shared by unrelated plugins.