WpOrg\Requests

Hooks::dispatch()publicWP 1.0

Dispatch a message

Метод класса: Hooks{}

Хуков нет.

Возвращает

true|false. Successfulness

Использование

$Hooks = new Hooks();
$Hooks->dispatch( $hook, $parameters );
$hook(строка) (обязательный)
Hook name
$parameters(массив)
Parameters to pass to callbacks
По умолчанию: []

Код Hooks::dispatch() WP 6.6.2

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;
}