hook_manager_interface
Contract for the Hook Manager.
Provides a WordPress-style system of "filters" and "actions".
Filters: Modify a value and return it. Actions: Execute side effects, no return value.
Table of Contents
Methods
- add_action() : void
- Register a new action callback.
- add_filter() : void
- Register a new filter callback.
- apply_filters() : mixed
- Apply all registered filters to a value.
- do_action() : void
- Execute all callbacks registered for a given action.
- has_action() : bool
- Check whether any callback is registered for the given action.
- reset() : void
- Clear all registered hooks. Essential for unit testing isolation.
Methods
add_action()
Register a new action callback.
public
static add_action(string $tag, callable $function[, int $priority = 10 ][, int $args = 1 ]) : void
Parameters
- $tag : string
-
Action identifier
- $function : callable
-
Callback to execute
- $priority : int = 10
-
Lower = run earlier
- $args : int = 1
-
Number of accepted arguments
add_filter()
Register a new filter callback.
public
static add_filter(string $tag, callable $function[, int $priority = 10 ][, int $args = 1 ]) : void
Parameters
- $tag : string
-
Filter identifier
- $function : callable
-
Callback to execute
- $priority : int = 10
-
Lower = run earlier
- $args : int = 1
-
Number of accepted arguments
apply_filters()
Apply all registered filters to a value.
public
static apply_filters(string $tag, mixed $value, mixed ...$args) : mixed
Parameters
- $tag : string
-
Filter identifier
- $value : mixed
-
Initial value
- $args : mixed
-
Additional parameters passed to callbacks
Return values
mixed —Filtered value
do_action()
Execute all callbacks registered for a given action.
public
static do_action(string $tag, mixed ...$args) : void
Parameters
- $tag : string
-
Action identifier
- $args : mixed
-
Parameters passed to callbacks
has_action()
Check whether any callback is registered for the given action.
public
static has_action(string $tag) : bool
Parameters
- $tag : string
Return values
boolreset()
Clear all registered hooks. Essential for unit testing isolation.
public
static reset() : void