if (!is_readable(WP_ROOT . 'wp-load.php')) { WP_CLI::error('This does not seem to be a WordPress install. Pass --path=`path/to/wordpress` or run `wp core download`.'); } if (array('core', 'config') == $arguments) { WP_CLI::run_command($arguments, $assoc_args); exit; } // The db commands don't need any WP files if (array('db') == array_slice($arguments, 0, 1)) { WP_CLI::load_wp_config(); WP_CLI::run_command($arguments, $assoc_args); exit; } // Set installer flag before loading any WP files if (array('core', 'install') == $arguments) { WP_CLI::check_required_args(array('url', 'title', 'admin_email', 'admin_password'), $assoc_args); define('WP_INSTALLING', true); } // Load WordPress require WP_ROOT . 'wp-load.php'; // Fix memory limit. See http://core.trac.wordpress.org/ticket/14889 @ini_set('memory_limit', -1); require ABSPATH . 'wp-admin/includes/admin.php'; // Load the right info into the global wp_query if (!defined('WP_INSTALLING') && isset($assoc_args['url'])) { if (isset($GLOBALS['wp_query']) && isset($GLOBALS['wp'])) { $GLOBALS['wp']->parse_request(); $GLOBALS['wp_query']->query($GLOBALS['wp']->query_vars); } } // Set filesystem method
public function install_network($args, $assoc_args) { if (is_multisite()) { WP_CLI::error('This already is a multisite install.'); } global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; // need to register the multisite tables manually for some reason foreach ($wpdb->tables('ms_global') as $table => $prefixed_table) { $wpdb->{$table} = $prefixed_table; } WP_CLI::check_required_args(array('title'), $assoc_args); extract(wp_parse_args($assoc_args, array('base' => '/'))); $hostname = self::get_clean_basedomain(); $subdomain_install = isset($assoc_args['subdomains']); install_network(); $result = populate_network(1, $hostname, get_option('admin_email'), $assoc_args['title'], $base, $subdomain_install); if (is_wp_error($result)) { WP_CLI::error($result); } ob_start(); ?> define('MULTISITE', true); define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?> ); $base = '<?php echo $base; ?> '; define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?> '); define('PATH_CURRENT_SITE', '<?php echo $base; ?> '); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1); <?php $ms_config = ob_get_clean(); $wp_config_path = WP_CLI::locate_wp_config(); $token = "/* That's all, stop editing!"; list($before, $after) = explode($token, file_get_contents($wp_config_path)); file_put_contents($wp_config_path, $before . $ms_config . $token . $after); wp_mkdir_p(WP_CONTENT_DIR . '/blogs.dir'); WP_CLI::success("Network installed. Don't forget to set up rewrite rules."); }