Exemple #1
0
 public function before_wp_load()
 {
     $this->init_config();
     $this->init_colorization();
     $this->init_logger();
     $this->check_root();
     if (empty($this->arguments)) {
         $this->arguments[] = 'help';
     }
     // Protect 'cli info' from most of the runtime
     if ('cli' === $this->arguments[0] && !empty($this->arguments[1]) && 'info' === $this->arguments[1]) {
         $this->_run_command();
         exit;
     }
     // Load bundled commands early, so that they're forced to use the same
     // APIs as non-bundled commands.
     Utils\load_command($this->arguments[0]);
     if (isset($this->config['require'])) {
         foreach ($this->config['require'] as $path) {
             if (!file_exists($path)) {
                 WP_CLI::error(sprintf("Required file '%s' doesn't exist", basename($path)));
             }
             Utils\load_file($path);
         }
     }
     // Show synopsis if it's a composite command.
     $r = $this->find_command_to_run($this->arguments);
     if (is_array($r)) {
         list($command) = $r;
         if ($command->can_have_subcommands()) {
             $command->show_usage();
             exit;
         }
     }
     // Handle --path parameter
     self::set_wp_root($this->find_wp_root());
     // First try at showing man page
     if ('help' === $this->arguments[0] && !$this->wp_exists()) {
         $this->_run_command();
     }
     // Handle --url parameter
     $url = self::guess_url($this->config);
     if ($url) {
         \WP_CLI::set_url($url);
     }
     $this->do_early_invoke('before_wp_load');
     $this->check_wp_version();
     if ($this->cmd_starts_with(array('core', 'config'))) {
         $this->_run_command();
         exit;
     }
     if (!Utils\locate_wp_config()) {
         WP_CLI::error("wp-config.php not found.\n" . "Either create one manually or use `wp core config`.");
     }
     if ($this->cmd_starts_with(array('db')) && !$this->cmd_starts_with(array('db', 'tables'))) {
         eval($this->get_wp_config_code());
         $this->_run_command();
         exit;
     }
     if ($this->cmd_starts_with(array('core', 'is-installed'))) {
         define('WP_INSTALLING', true);
     }
     if (count($this->arguments) >= 2 && $this->arguments[0] == 'core' && in_array($this->arguments[1], array('install', 'multisite-install'))) {
         define('WP_INSTALLING', true);
         // We really need a URL here
         if (!isset($_SERVER['HTTP_HOST'])) {
             $url = 'http://example.com';
             \WP_CLI::set_url($url);
         }
         if ('multisite-install' == $this->arguments[1]) {
             // need to fake some globals to skip the checks in wp-includes/ms-settings.php
             $url_parts = Utils\parse_url($url);
             self::fake_current_site_blog($url_parts);
             if (!defined('COOKIEHASH')) {
                 define('COOKIEHASH', md5($url_parts['host']));
             }
         }
     }
     if ($this->cmd_starts_with(array('import'))) {
         define('WP_LOAD_IMPORTERS', true);
         define('WP_IMPORTING', true);
     }
     if ($this->cmd_starts_with(array('plugin'))) {
         $GLOBALS['pagenow'] = 'plugins.php';
     }
 }
Exemple #2
0
 public function start()
 {
     $this->init_config();
     $this->init_colorization();
     $this->init_logger();
     WP_CLI::debug($this->_global_config_path_debug, 'bootstrap');
     WP_CLI::debug($this->_project_config_path_debug, 'bootstrap');
     $this->check_root();
     if (empty($this->arguments)) {
         $this->arguments[] = 'help';
     }
     // Protect 'cli info' from most of the runtime
     if ('cli' === $this->arguments[0] && !empty($this->arguments[1]) && 'info' === $this->arguments[1]) {
         $this->_run_command();
         exit;
     }
     // Protect 'package' commands from most of the runtime too
     if ('package' === $this->arguments[0]) {
         $this->_run_command();
         exit;
     }
     // Load bundled commands early, so that they're forced to use the same
     // APIs as non-bundled commands.
     Utils\load_all_commands();
     $skip_packages = \WP_CLI::get_runner()->config['skip-packages'];
     if (true === $skip_packages) {
         WP_CLI::debug('Skipped loading packages.', 'bootstrap');
     } else {
         $package_autoload = $this->get_packages_dir_path() . 'vendor/autoload.php';
         if (file_exists($package_autoload)) {
             WP_CLI::debug('Loading packages from: ' . $package_autoload, 'bootstrap');
             require_once $package_autoload;
         } else {
             WP_CLI::debug('No package autoload found to load.', 'bootstrap');
         }
     }
     if (isset($this->config['require'])) {
         foreach ($this->config['require'] as $path) {
             if (!file_exists($path)) {
                 $context = '';
                 foreach (array('global', 'project', 'runtime') as $scope) {
                     if (in_array($path, $this->_required_files[$scope])) {
                         switch ($scope) {
                             case 'global':
                                 $context = ' (from global ' . basename($this->global_config_path) . ')';
                                 break;
                             case 'project':
                                 $context = ' (from project\'s ' . basename($this->project_config_path) . ')';
                                 break;
                             case 'runtime':
                                 $context = ' (from runtime argument)';
                                 break;
                         }
                         break;
                     }
                 }
                 WP_CLI::error(sprintf("Required file '%s' doesn't exist%s.", basename($path), $context));
             }
             Utils\load_file($path);
             WP_CLI::debug('Required file from config: ' . $path, 'bootstrap');
         }
     }
     // Show synopsis if it's a composite command.
     $r = $this->find_command_to_run($this->arguments);
     if (is_array($r)) {
         list($command) = $r;
         if ($command->can_have_subcommands()) {
             $command->show_usage();
             exit;
         }
     }
     // Handle --path parameter
     self::set_wp_root($this->find_wp_root());
     // First try at showing man page
     if (!empty($this->arguments[0]) && 'help' === $this->arguments[0] && (!$this->wp_exists() || !Utils\locate_wp_config() || !empty($this->arguments[1]) && !empty($this->arguments[2]) && 'core' === $this->arguments[1] && in_array($this->arguments[2], array('config', 'install', 'multisite-install', 'verify-checksums', 'version')))) {
         $this->auto_check_update();
         $this->_run_command();
     }
     // Handle --url parameter
     $url = self::guess_url($this->config);
     if ($url) {
         \WP_CLI::set_url($url);
     }
     $this->do_early_invoke('before_wp_load');
     $this->check_wp_version();
     if ($this->cmd_starts_with(array('core', 'config'))) {
         $this->_run_command();
         exit;
     }
     if (!Utils\locate_wp_config()) {
         WP_CLI::error("wp-config.php not found.\n" . "Either create one manually or use `wp core config`.");
     }
     if ($this->cmd_starts_with(array('db')) && !$this->cmd_starts_with(array('db', 'tables'))) {
         eval($this->get_wp_config_code());
         $this->_run_command();
         exit;
     }
     if ($this->cmd_starts_with(array('core', 'is-installed'))) {
         define('WP_INSTALLING', true);
     }
     if (count($this->arguments) >= 2 && $this->arguments[0] == 'core' && in_array($this->arguments[1], array('install', 'multisite-install'))) {
         define('WP_INSTALLING', true);
         // We really need a URL here
         if (!isset($_SERVER['HTTP_HOST'])) {
             $url = 'http://example.com';
             \WP_CLI::set_url($url);
         }
         if ('multisite-install' == $this->arguments[1]) {
             // need to fake some globals to skip the checks in wp-includes/ms-settings.php
             $url_parts = Utils\parse_url($url);
             self::fake_current_site_blog($url_parts);
             if (!defined('COOKIEHASH')) {
                 define('COOKIEHASH', md5($url_parts['host']));
             }
         }
     }
     if ($this->cmd_starts_with(array('import'))) {
         define('WP_LOAD_IMPORTERS', true);
         define('WP_IMPORTING', true);
     }
     if ($this->cmd_starts_with(array('plugin'))) {
         $GLOBALS['pagenow'] = 'plugins.php';
     }
     $this->load_wordpress();
     $this->_run_command();
 }
Exemple #3
0
 /**
  * Set the context in which WP-CLI should be run
  */
 public static function set_url($url)
 {
     $url_parts = Utils\parse_url($url);
     self::set_url_params($url_parts);
 }
Exemple #4
0
 /**
  * Set the context in which WP-CLI should be run
  */
 public static function set_url($url)
 {
     WP_CLI::debug('Set URL: ' . $url);
     $url_parts = Utils\parse_url($url);
     self::set_url_params($url_parts);
 }
Exemple #5
0
 public function start()
 {
     $this->init_config();
     $this->init_colorization();
     $this->init_logger();
     WP_CLI::debug($this->_global_config_path_debug, 'bootstrap');
     WP_CLI::debug($this->_project_config_path_debug, 'bootstrap');
     $this->check_root();
     if ($this->alias) {
         if ('@all' === $this->alias && !isset($this->aliases['@all'])) {
             WP_CLI::error("Cannot use '@all' when no aliases are registered.");
         }
         if ('@all' === $this->alias && is_string($this->aliases['@all'])) {
             $aliases = array_keys($this->aliases);
             $k = array_search('@all', $aliases);
             unset($aliases[$k]);
             $this->run_alias_group($aliases);
             exit;
         }
         if (!array_key_exists($this->alias, $this->aliases)) {
             WP_CLI::error("Alias '{$this->alias}' not found.");
         }
         // Numerically indexed means a group of aliases
         if (isset($this->aliases[$this->alias][0])) {
             $group_aliases = $this->aliases[$this->alias];
             $all_aliases = array_keys($this->aliases);
             if ($diff = array_diff($group_aliases, $all_aliases)) {
                 WP_CLI::error("Group '{$this->alias}' contains one or more invalid aliases: " . implode(', ', $diff));
             }
             $this->run_alias_group($group_aliases);
             exit;
         } else {
             $this->set_alias($this->alias);
         }
     }
     if (empty($this->arguments)) {
         $this->arguments[] = 'help';
     }
     // Protect 'cli info' from most of the runtime,
     // except when the command will be run over SSH
     if ('cli' === $this->arguments[0] && !empty($this->arguments[1]) && 'info' === $this->arguments[1] && !$this->config['ssh']) {
         $this->_run_command();
         exit;
     }
     // Protect 'package' commands from most of the runtime too,
     // except when the command will be run over SSH
     if ('package' === $this->arguments[0] && !$this->config['ssh']) {
         $this->_run_command();
         exit;
     }
     // Load bundled commands early, so that they're forced to use the same
     // APIs as non-bundled commands.
     Utils\load_all_commands();
     $skip_packages = \WP_CLI::get_runner()->config['skip-packages'];
     if (true === $skip_packages) {
         WP_CLI::debug('Skipped loading packages.', 'bootstrap');
     } else {
         $package_autoload = $this->get_packages_dir_path() . 'vendor/autoload.php';
         if (file_exists($package_autoload)) {
             WP_CLI::debug('Loading packages from: ' . $package_autoload, 'bootstrap');
             require_once $package_autoload;
         } else {
             WP_CLI::debug('No package autoload found to load.', 'bootstrap');
         }
     }
     if (isset($this->config['http']) && !class_exists('\\WP_REST_CLI\\Runner')) {
         WP_CLI::error("RESTful WP-CLI needs to be installed. Try 'wp package install wp-cli/restful'.");
     }
     if (isset($this->config['require'])) {
         foreach ($this->config['require'] as $path) {
             if (!file_exists($path)) {
                 $context = '';
                 foreach (array('global', 'project', 'runtime') as $scope) {
                     if (in_array($path, $this->_required_files[$scope])) {
                         switch ($scope) {
                             case 'global':
                                 $context = ' (from global ' . basename($this->global_config_path) . ')';
                                 break;
                             case 'project':
                                 $context = ' (from project\'s ' . basename($this->project_config_path) . ')';
                                 break;
                             case 'runtime':
                                 $context = ' (from runtime argument)';
                                 break;
                         }
                         break;
                     }
                 }
                 WP_CLI::error(sprintf("Required file '%s' doesn't exist%s.", basename($path), $context));
             }
             Utils\load_file($path);
             WP_CLI::debug('Required file from config: ' . $path, 'bootstrap');
         }
     }
     if ($this->config['ssh']) {
         $this->run_ssh_command($this->config['ssh']);
         return;
     }
     // Show synopsis if it's a composite command.
     $r = $this->find_command_to_run($this->arguments);
     if (is_array($r)) {
         list($command) = $r;
         if ($command->can_have_subcommands()) {
             $command->show_usage();
             exit;
         }
     }
     // Handle --path parameter
     self::set_wp_root($this->find_wp_root());
     // First try at showing man page
     if (!empty($this->arguments[0]) && 'help' === $this->arguments[0] && (!$this->wp_exists() || !Utils\locate_wp_config() || !empty($this->arguments[1]) && !empty($this->arguments[2]) && 'core' === $this->arguments[1] && in_array($this->arguments[2], array('config', 'install', 'multisite-install', 'verify-checksums', 'version')))) {
         $this->auto_check_update();
         $this->_run_command();
     }
     // Handle --url parameter
     $url = self::guess_url($this->config);
     if ($url) {
         \WP_CLI::set_url($url);
     }
     $this->do_early_invoke('before_wp_load');
     $this->check_wp_version();
     if ($this->cmd_starts_with(array('core', 'config'))) {
         $this->_run_command();
         exit;
     }
     if (!Utils\locate_wp_config()) {
         WP_CLI::error("'wp-config.php' not found.\n" . "Either create one manually or use `wp core config`.");
     }
     if ($this->cmd_starts_with(array('db')) && !$this->cmd_starts_with(array('db', 'tables'))) {
         eval($this->get_wp_config_code());
         $this->_run_command();
         exit;
     }
     if ($this->cmd_starts_with(array('core', 'is-installed')) || $this->cmd_starts_with(array('core', 'update-db'))) {
         define('WP_INSTALLING', true);
     }
     if (count($this->arguments) >= 2 && $this->arguments[0] == 'core' && in_array($this->arguments[1], array('install', 'multisite-install'))) {
         define('WP_INSTALLING', true);
         // We really need a URL here
         if (!isset($_SERVER['HTTP_HOST'])) {
             $url = 'http://example.com';
             \WP_CLI::set_url($url);
         }
         if ('multisite-install' == $this->arguments[1]) {
             // need to fake some globals to skip the checks in wp-includes/ms-settings.php
             $url_parts = Utils\parse_url($url);
             self::fake_current_site_blog($url_parts);
             if (!defined('COOKIEHASH')) {
                 define('COOKIEHASH', md5($url_parts['host']));
             }
         }
     }
     if ($this->cmd_starts_with(array('import'))) {
         define('WP_LOAD_IMPORTERS', true);
         define('WP_IMPORTING', true);
     }
     if ($this->cmd_starts_with(array('cron', 'event', 'run'))) {
         define('DOING_CRON', true);
     }
     $this->load_wordpress();
     $this->_run_command();
 }