WP_CLI::launch PHP Method

launch() public static method

# wp core download falls back to the tar binary when PharData isn't available if ( ! class_exists( 'PharData' ) ) { $cmd = "tar xz --strip-components=1 --directory=%s -f $tarball"; WP_CLI::launch( Utils\esc_cmd( $cmd, $dest ) ); return; }
public static launch ( string $command, boolean $exit_on_error = true, boolean $return_detailed = false ) : integer | ProcessRun
$command string External process to launch.
$exit_on_error boolean Whether to exit if the command returns an elevated return code.
$return_detailed boolean Whether to return an exit status (default) or detailed execution results.
return integer | ProcessRun The command exit status, or a ProcessRun object for full details.
    public static function launch($command, $exit_on_error = true, $return_detailed = false)
    {
        $proc = Process::create($command);
        $results = $proc->run();
        if (-1 == $results->return_code) {
            self::warning("Spawned process returned exit code {$results->return_code}, which could be caused by a custom compiled version of PHP that uses the --enable-sigchild option.");
        }
        if ($results->return_code && $exit_on_error) {
            exit($results->return_code);
        }
        if ($return_detailed) {
            return $results;
        } else {
            return $results->return_code;
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * Download the core files from wordpress.org
  */
 public function download($args, $assoc_args)
 {
     if (is_readable(WP_ROOT . 'wp-load.php')) {
         WP_CLI::error('WordPress files seem to already be present here.');
     }
     if (isset($assoc_args['path'])) {
         $docroot = $assoc_args['path'];
     } else {
         $docroot = './';
     }
     if (isset($assoc_args['locale'])) {
         exec('curl -s ' . escapeshellarg('https://api.wordpress.org/core/version-check/1.5/?locale=' . $assoc_args['locale']), $lines, $r);
         if ($r) {
             exit($r);
         }
         $download_url = str_replace('.zip', '.tar.gz', $lines[2]);
         WP_CLI::line(sprintf('Downloading WordPress %s (%s)...', $lines[3], $lines[4]));
     } elseif (isset($assoc_args['version'])) {
         $download_url = 'https://wordpress.org/wordpress-' . $assoc_args['version'] . '.tar.gz';
         WP_CLI::line(sprintf('Downloading WordPress %s (%s)...', $assoc_args['version'], 'en_US'));
     } else {
         $download_url = 'https://wordpress.org/latest.tar.gz';
         WP_CLI::line(sprintf('Downloading latest WordPress (%s)...', 'en_US'));
     }
     WP_CLI::launch('curl -f' . (WP_CLI_QUIET ? ' --silent ' : ' ') . escapeshellarg($download_url) . ' | tar xz');
     WP_CLI::launch('mv wordpress/* . && rm -rf wordpress');
     WP_CLI::success('WordPress downloaded.');
 }
All Usage Examples Of WP_CLI::launch