WpOrg\Requests
Hooks::dispatch()
Dispatch a message
Method of the class: Hooks{}
No Hooks.
Return
true|false
. Successfulness
Usage
$Hooks = new Hooks(); $Hooks->dispatch( $hook, $parameters );
- $hook(string) (required)
- Hook name
- $parameters(array)
- Parameters to pass to callbacks
Default: []
Hooks::dispatch() Hooks::dispatch code WP 6.7.1
public function dispatch($hook, $parameters = []) { if (is_string($hook) === false) { throw InvalidArgument::create(1, '$hook', 'string', gettype($hook)); } // Check strictly against array, as Array* objects don't work in combination with `call_user_func_array()`. if (is_array($parameters) === false) { throw InvalidArgument::create(2, '$parameters', 'array', gettype($parameters)); } if (empty($this->hooks[$hook])) { return false; } if (!empty($parameters)) { // Strip potential keys from the array to prevent them being interpreted as parameter names in PHP 8.0. $parameters = array_values($parameters); } ksort($this->hooks[$hook]); foreach ($this->hooks[$hook] as $priority => $hooked) { foreach ($hooked as $callback) { $callback(...$parameters); } } return true; }