WP_CLI::launch_self()
Run a WP-CLI command in a new process reusing the current runtime arguments.
Use WP_CLI::runcommand() instead, which is easier to use and works better.
Note: While this command does persist a limited set of runtime arguments, it does not persist environment variables. Practically speaking, WP-CLI packages won't be loaded when using WP_CLI::launch_self() because the launched process doesn't have access to the current process $HOME.
Метод класса: WP_CLI{}
Хуков нет.
Возвращает
int|ProcessRun
. The command exit status, or a ProcessRun instance
Использование
$result = WP_CLI::launch_self( $command, $args, $assoc_args, $exit_on_error, $return_detailed, $runtime_args );
- $command(строка) (обязательный)
- WP-CLI command to call.
- $args(массив)
- Positional arguments to include when calling the command.
По умолчанию: [] - $assoc_args(массив)
- Associative arguments to include when calling the command.
По умолчанию: [] - $exit_on_error(true|false)
- Whether to exit if the command returns an elevated return code.
По умолчанию: true - $return_detailed(true|false)
- Whether to return an exit status (default) or detailed execution results.
По умолчанию: false - $runtime_args(массив)
- Override one or more global args (path,url,user,allow-root)
По умолчанию: []
Код WP_CLI::launch_self() WP CLI::launch self WP-CLI 2.8.0-alpha
public static function launch_self( $command, $args = [], $assoc_args = [], $exit_on_error = true, $return_detailed = false, $runtime_args = [] ) { $reused_runtime_args = [ 'path', 'url', 'user', 'allow-root', ]; foreach ( $reused_runtime_args as $key ) { if ( isset( $runtime_args[ $key ] ) ) { $assoc_args[ $key ] = $runtime_args[ $key ]; continue; } $value = self::get_runner()->config[ $key ]; if ( $value ) { $assoc_args[ $key ] = $value; } } $php_bin = escapeshellarg( Utils\get_php_binary() ); $script_path = $GLOBALS['argv'][0]; if ( getenv( 'WP_CLI_CONFIG_PATH' ) ) { $config_path = getenv( 'WP_CLI_CONFIG_PATH' ); } else { $config_path = Utils\get_home_dir() . '/.wp-cli/config.yml'; } $config_path = escapeshellarg( $config_path ); $args = implode( ' ', array_map( 'escapeshellarg', $args ) ); $assoc_args = Utils\assoc_args_to_str( $assoc_args ); $full_command = "WP_CLI_CONFIG_PATH={$config_path} {$php_bin} {$script_path} {$command} {$args} {$assoc_args}"; return self::launch( $full_command, $exit_on_error, $return_detailed ); }