API / Minn\Runtime / Hooks

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.

Uses 1

Constants and properties

privatearray $hooks
privatearray $actionsDone
privatearray $filtersDone
privatearray $stack
privatearray $running
private?Closure $onNew

Public

methodonNew(Closure $observer): void#

Called with each hook name the first time a callback registers under it.

methodstorage(): array#

The live registry, for a hook object to share by reference.

methodactionCounters(): array#

How often each action, or each filter, has run, by hook.

methodfilterCounters(): array#

How often each filter has run, by hook, by reference for the facade's global.

methodstackRef(): array#

The hooks running now, outermost first, by reference for the facade\'s globals.

methodcurrentPriority(string $hook): int|false#

The priority a running hook is at, or false when it is idle.

methodadd(string $hook, callable|array|string $callback, string|int $priority = 10, int $accepted = 1): bool#

Adds a callback to a hook at a priority.

methodremove(string $hook, callable|array|string $callback, string|int $priority = 10): bool#

Removes a callback from a hook.

methodremoveAll(string $hook, string|int|false $priority = false): bool#

Every callback of a hook, or only those at one priority. Always true, as observed.

methodhas(string $hook, callable|array|string|false $callback = false): int|bool#

With a callback: its lowest priority, or false; without: whether anything is registered.

methodhasBeyond(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.

$donearray<string, int>
methodfilter(string $hook, array $args): mixed#

Runs a filter and returns the value.

$argslist<mixed>the value first
methodfilterWithout(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.

$argslist<mixed>the value first
$donearray<string, int|array{0: int, 1: string}>
methodaction(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).

$argslist<mixed>
methodactionRef(string $hook, array $args): void#

Runs an action with exactly the arguments given, none included (do_action_ref_array).

$argslist<mixed>
methodactionRefArray(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.

$argslist<mixed>
methodfilterRefArray(string $hook, array $args): mixed#

apply_filters_ref_array: as filter(), with an 'all' callback handed the arguments as one array.

$argslist<mixed>
methodfilterDeprecated(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.

$argsarray<array-key, mixed>the value first
methodactionDeprecated(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.

$argsarray<array-key, mixed>
methodactionsDone(string $hook): int#

How often an action has run.

methodfiltersDone(string $hook): int#

How often a filter has run.

methodcurrent(): string|false#

The hook running now, or false.

methoddoing(?string $hook): bool#

Whether a hook, or any hook, is running.

methodregistered(): array#

Every hook with callbacks, by name.

@return array<string, array<int, list<callable>>> a read-only view for diagnostics
methodcallAll(array $args): void#

The 'all' callbacks run with the arguments given, the hook's name first (_wp_call_all_hook). @param list<mixed> $args

$argslist<mixed>

Internals 4

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privaterun(string $hook, array $args, bool $isFilter, array $skip = array ( ), ?array $allArgs = NULL): mixed#
$argslist<mixed>
$skiparray<string, int>function name => priority, passed over
$allArgslist<mixed>|nullwhat an 'all' callback gets after the hook's name; the arguments when null
privatenextPriority(string $hook, ?int $after): ?int#
privatefireAll(string $hook, array $args): void#
privateid(callable|array|string $callback): string#

One identity per callable: closures and objects by instance, static methods in either spelling as one.