WP_CLI::do_hook()public staticWP-CLI 1.0

Execute callbacks registered to a given hook.

See WP_CLI::add_hook() for details on WP-CLI's internal hook system. Commands can provide and call their own hooks.

{} Это метод класса: WP_CLI{}

Хуков нет.

Возвращает

null|Разное. Returns the first optional argument if optional arguments were passed, otherwise returns null.

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

$result = WP_CLI::do_hook( $when, ...$args );
$when(строка) (обязательный)
Identifier for the hook.
...$args(разное) (обязательный)
Arguments that will be passed onto the callback provided by WP_CLI::add_hook().

Код WP_CLI::do_hook() WP-CLI 2.7.0-alpha

public static function do_hook( $when, ...$args ) {
	self::$hooks_passed[ $when ] = $args;

	$has_args = count( $args ) > 0;

	if ( ! isset( self::$hooks[ $when ] ) ) {
		if ( $has_args ) {
			return $args[0];
		}

		return null;
	}

	self::debug(
		sprintf(
			'Processing hook "%s" with %d callbacks',
			$when,
			count( self::$hooks[ $when ] )
		),
		'hooks'
	);

	foreach ( self::$hooks[ $when ] as $callback ) {
		self::debug(
			sprintf(
				'On hook "%s": %s',
				$when,
				Utils\describe_callable( $callback )
			),
			'hooks'
		);

		if ( $has_args ) {
			$return_value = $callback( ...$args );
			if ( isset( $return_value ) ) {
				$args[0] = $return_value;
			}
		} else {
			$callback();
		}
	}

	if ( $has_args ) {
		return $args[0];
	}

	return null;
}