mirror of
https://gh.wpcy.net/https://github.com/wp-cli/handbook.git
synced 2026-05-01 07:09:06 +08:00
2 KiB
2 KiB
WP_CLI::runcommand()
Run a WP-CLI command.
Usage
WP_CLI::runcommand( $command, $options = [] )
$command (string) WP-CLI command to run, including arguments.
$options (array) Configuration options for command execution.
@return (mixed)
$options (array) Configuration options for command execution.
@return (mixed)
Notes
Launches a new child process to run a specified WP-CLI command. Optionally:
- Run the command in an existing process.
- Prevent halting script execution on error.
- Capture and return STDOUT, or full details about command execution.
- Parse JSON output if the command rendered it.
- Include additional arguments that are passed to the command.
$options = array(
'return' => true, // Return 'STDOUT'; use 'all' for full object.
'parse' => 'json', // Parse captured STDOUT to JSON array.
'launch' => false, // Reuse the current process.
'exit_error' => true, // Halt script execution on error.
'command_args' => [ '--skip-themes' ], // Additional arguments to be passed to the $command.
);
$plugins = WP_CLI::runcommand( 'plugin list --format=json', $options );
Internal API documentation is generated from the WP-CLI codebase on every release. To suggest improvements, please submit a pull request.
Related
- WP_CLI::launch() - Launch an arbitrary external process that takes over I/O.
- WP_CLI::launch_self() - Run a WP-CLI command in a new process reusing the current runtime arguments.
- WP_CLI::run_command() - Run a given command within the current process using the same global parameters.