WP_CLI::runcommand() Edit

Run a WP-CLI command.

Usage Usage

WP_CLI::runcommand( $command, $options = array() )
$command (string) WP-CLI command to run, including arguments.
$options (array) Configuration options for command execution.
@return (mixed)

Top ↑

Notes Notes

Launches a new child process to run a specified WP-CLI command.

  • 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.

    $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.
    $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.

Top ↑