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

Behavior and parameters