WP_CLI::defer_command_addition()private staticWP-CLI 1.0

Defer command addition for a sub-command if the parent command is not yet registered.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$result = WP_CLI::defer_command_addition( $name, $parent, $callable, $args );
$name(строка) (обязательный)
Name for the sub-command.
$parent(строка) (обязательный)
Name for the parent command.
$callable(строка) (обязательный)
Command implementation as a class, function or closure.
$args(массив)
See WP_CLI::add_command() for details.
По умолчанию: []

Код WP_CLI::defer_command_addition() WP-CLI 2.8.0-alpha

private static function defer_command_addition( $name, $parent, $callable, $args = [] ) {
	$args['is_deferred']               = true;
	self::$deferred_additions[ $name ] = [
		'parent'   => $parent,
		'callable' => $callable,
		'args'     => $args,
	];
	self::add_hook(
		"after_add_command:$parent",
		function () use ( $name ) {
			$deferred_additions = WP_CLI::get_deferred_additions();

			if ( ! array_key_exists( $name, $deferred_additions ) ) {
				return;
			}

			$callable = $deferred_additions[ $name ]['callable'];
			$args     = $deferred_additions[ $name ]['args'];
			WP_CLI::remove_deferred_addition( $name );

			WP_CLI::add_command( $name, $callable, $args );
		}
	);
}