set_url_params() private static method

private static set_url_params ( $url_parts )
Example #1
0
 /**
  * Run wp_install. Assumes that wp-config.php is already in place.
  */
 public function install($args, $assoc_args)
 {
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     if (is_blog_installed()) {
         WP_CLI::error('WordPress is already installed.');
     }
     extract(wp_parse_args($assoc_args, array('site_url' => defined('WP_SITEURL') ? WP_SITEURL : '', 'site_title' => '', 'admin_name' => 'admin', 'admin_email' => '', 'admin_password' => '')), EXTR_SKIP);
     $missing = false;
     foreach (array('site_url', 'site_title', 'admin_email', 'admin_password') as $required_arg) {
         if (empty(${$required_arg})) {
             WP_CLI::warning("missing --{$required_arg} parameter");
             $missing = true;
         }
     }
     if ($site_url) {
         WP_CLI::set_url_params($site_url);
     }
     if ($missing) {
         exit(1);
     }
     $public = true;
     $result = wp_install($site_title, $admin_name, $admin_email, $public, '', $admin_password);
     if (is_wp_error($result)) {
         WP_CLI::error('Installation failed (' . WP_CLI::errorToString($result) . ').');
     } else {
         WP_CLI::success('WordPress installed successfully.');
     }
 }
Example #2
0
 static function _set_url(&$assoc_args)
 {
     if (isset($assoc_args['url'])) {
         $blog = $assoc_args['url'];
         unset($assoc_args['url']);
     } elseif (isset($assoc_args['blog'])) {
         $blog = $assoc_args['blog'];
         unset($assoc_args['blog']);
         if (true === $blog) {
             WP_CLI::line('usage: wp --blog=example.com');
         }
     } elseif (is_readable(WP_ROOT . 'wp-cli-blog')) {
         $blog = trim(file_get_contents(WP_ROOT . 'wp-cli-blog'));
     } else {
         // Try to find the blog parameter in the wp-config file
         if (file_exists(WP_ROOT . '/wp-config.php')) {
             $wp_config_file = file_get_contents(WP_ROOT . '/wp-config.php');
             $hit = array();
             if (preg_match_all("#.*define\\s*\\(\\s*(['|\"]{1})(.+)(['|\"]{1})\\s*,\\s*(['|\"]{1})(.+)(['|\"]{1})\\s*\\)\\s*;#iU", $wp_config_file, $matches)) {
                 foreach ($matches[2] as $def_key => $def_name) {
                     if ('DOMAIN_CURRENT_SITE' == $def_name) {
                         $hit['domain'] = $matches[5][$def_key];
                     }
                     if ('PATH_CURRENT_SITE' == $def_name) {
                         $hit['path'] = $matches[5][$def_key];
                     }
                 }
             }
             if (!empty($hit) && isset($hit['domain'])) {
                 $blog = $hit['domain'];
             }
             if (!empty($hit) && isset($hit['path'])) {
                 $blog .= $hit['path'];
             }
         }
     }
     if (isset($blog)) {
         WP_CLI::set_url_params($blog);
     }
 }