Hooks final class
Minn\Runtime\Hooks · public/minn/src/Minn/Runtime/Hooks.php · 385 lines
The hook registry plugin code registers into and the engine fires. Semantics come from contracts/fixtures/api/hooks.json: callbacks run by ascending priority then insertion order; a callback added at a higher priority during a run takes part in that run, one added at the current or a lower priority waits for the next; a callback removed before its turn is skipped; the "all" hook sees every firing with the hook name first and every argument regardless of its accepted count.
Constants and properties
| private | array $hooks | |
| private | array $actionsDone | |
| private | array $filtersDone | |
| private | array $stack | |
| private | array $running | |
| private | ?Closure $onNew |
Public
| method | onNew(Closure $observer): void# | Called with each hook name the first time a callback registers under it. | ||||||
| method | storage(): array# | The live registry, for a hook object to share by reference. | ||||||
| method | actionCounters(): array# | How often each action, or each filter, has run, by hook. | ||||||
| method | filterCounters(): array# | How often each filter has run, by hook, by reference for the facade's global. | ||||||
| method | stackRef(): array# | The hooks running now, outermost first, by reference for the facade\'s globals. | ||||||
| method | currentPriority(string $hook): int|false# | The priority a running hook is at, or false when it is idle. | ||||||
| method | add(string $hook, callable|array|string $callback, string|int $priority = 10, int $accepted = 1): bool# | Adds a callback to a hook at a priority. | ||||||
| method | remove(string $hook, callable|array|string $callback, string|int $priority = 10): bool# | Removes a callback from a hook. | ||||||
| method | removeAll(string $hook, string|int|false $priority = false): bool# | Every callback of a hook, or only those at one priority. Always true, as observed. | ||||||
| method | has(string $hook, callable|array|string|false $callback = false): int|bool# | With a callback: its lowest priority, or false; without: whether anything is registered. | ||||||
| method | hasBeyond(string $hook, array $done): bool# | Whether anything is hooked besides the callbacks the engine does the work of itself (named function => priority), as filterWithout skips them.
| ||||||
| method | filter(string $hook, array $args): mixed# | Runs a filter and returns the value.
| ||||||
| method | filterWithout(string $hook, array $args, array $done): mixed# | Runs a filter without the callbacks a caller has already done the work of, named function => priority: the engine renders post content through its own pipeline, then runs the_content for everything else hooked there. A callback a plugin removed is simply not there to skip. A skipped callback can name a stand-in, [priority, function], that runs in its place: what of its work the engine has left to do.
| ||||||
| method | action(string $hook, array $args): void# | Runs an action. With no arguments its callbacks still get one, an empty string, as do_action() gives them in the reference (a callback that requires a parameter is not short of one).
| ||||||
| method | actionRef(string $hook, array $args): void# | Runs an action with exactly the arguments given, none included (do_action_ref_array).
| ||||||
| method | actionRefArray(string $hook, array $args): void# | do_action_ref_array: the action's callbacks get the arguments, and an 'all' callback gets them as the one array they were passed in, as the reference hands them on.
| ||||||
| method | filterRefArray(string $hook, array $args): mixed# | apply_filters_ref_array: as filter(), with an 'all' callback handed the arguments as one array.
| ||||||
| method | filterDeprecated(string $hook, array $args, mixed $version, mixed $replacement = '', mixed $message = ''): mixed# | apply_filters_deprecated: the value as given while nothing is hooked; otherwise the deprecation notice, then the filter as filterRefArray runs it.
| ||||||
| method | actionDeprecated(string $hook, array $args, mixed $version, mixed $replacement = '', mixed $message = ''): void# | do_action_deprecated: nothing while nothing is hooked; otherwise the deprecation notice, then the action as actionRefArray runs it.
| ||||||
| method | actionsDone(string $hook): int# | How often an action has run. | ||||||
| method | filtersDone(string $hook): int# | How often a filter has run. | ||||||
| method | current(): string|false# | The hook running now, or false. | ||||||
| method | doing(?string $hook): bool# | Whether a hook, or any hook, is running. | ||||||
| method | registered(): array# | Every hook with callbacks, by name. @return array<string, array<int, list<callable>>> a read-only view for diagnostics | ||||||
| method | callAll(array $args): void# | The 'all' callbacks run with the arguments given, the hook's name first (_wp_call_all_hook). @param list<mixed> $args
|
Internals 4
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | run(string $hook, array $args, bool $isFilter, array $skip = array ( ), ?array $allArgs = NULL): mixed# |
| |||||||||
| private | nextPriority(string $hook, ?int $after): ?int# | ||||||||||
| private | fireAll(string $hook, array $args): void# | ||||||||||
| private | id(callable|array|string $callback): string# | One identity per callable: closures and objects by instance, static methods in either spelling as one. |
Nothing matches.