private function _multisite_convert($assoc_args)
{
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$domain = self::get_clean_basedomain();
if ('localhost' === $domain && !empty($assoc_args['subdomains'])) {
WP_CLI::error("Multisite with subdomains cannot be configured when domain is 'localhost'.");
}
// need to register the multisite tables manually for some reason
foreach ($wpdb->tables('ms_global') as $table => $prefixed_table) {
$wpdb->{$table} = $prefixed_table;
}
install_network();
$result = populate_network($assoc_args['site_id'], $domain, get_option('admin_email'), $assoc_args['title'], $assoc_args['base'], $assoc_args['subdomains']);
if (true === $result) {
WP_CLI::log('Set up multisite database tables.');
} else {
if (is_wp_error($result)) {
switch ($result->get_error_code()) {
case 'siteid_exists':
WP_CLI::log($result->get_error_message());
return false;
case 'no_wildcard_dns':
WP_CLI::warning(__('Wildcard DNS may not be configured correctly.'));
break;
default:
WP_CLI::error($result);
}
}
}
// delete_site_option() cleans the alloptions cache to prevent dupe option
delete_site_option('upload_space_check_disabled');
update_site_option('upload_space_check_disabled', 1);
if (!is_multisite()) {
$subdomain_export = Utils\get_flag_value($assoc_args, 'subdomains') ? 'true' : 'false';
$ms_config = <<<EOT
define( 'WP_ALLOW_MULTISITE', true );
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', {$subdomain_export} );
\$base = '{$assoc_args['base']}';
define( 'DOMAIN_CURRENT_SITE', '{$domain}' );
define( 'PATH_CURRENT_SITE', '{$assoc_args['base']}' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
EOT;
$wp_config_path = Utils\locate_wp_config();
if (is_writable($wp_config_path) && self::modify_wp_config($ms_config)) {
WP_CLI::log("Added multisite constants to 'wp-config.php'.");
} else {
WP_CLI::warning("Multisite constants could not be written to 'wp-config.php'. You may need to add them manually:" . PHP_EOL . $ms_config);
}
}
return true;
}