Ejemplo n.º 1
0
 function find_subcommand(&$args)
 {
     $command = array_shift($args);
     Utils\load_command($command);
     if (!isset($this->subcommands[$command])) {
         return false;
     }
     return $this->subcommands[$command];
 }
Ejemplo n.º 2
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';
     }
 }
Ejemplo n.º 3
0
 public function start()
 {
     $this->init_config();
     $this->init_colorization();
     $this->init_logger();
     WP_CLI::debug($this->_global_config_path_debug);
     WP_CLI::debug($this->_project_config_path_debug);
     $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 (getenv('WP_CLI_PACKAGES_DIR')) {
         $package_autoload = rtrim(getenv('WP_CLI_PACKAGES_DIR'), '/') . '/vendor/autoload.php';
     } else {
         $package_autoload = getenv('HOME') . '/.wp-cli/packages/vendor/autoload.php';
     }
     if (file_exists($package_autoload)) {
         require_once $package_autoload;
     }
     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);
         }
     }
     // 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() || !Utils\locate_wp_config())) {
         $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();
 }