function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '') { global $wpdb; $base = '/'; $domain = JQUERY_STAGING_PREFIX . 'jquery.com'; wp_check_mysql_version(); wp_cache_flush(); make_db_current_silent(); populate_options(); populate_roles(); $user_id = wp_create_user($user_name, trim($user_password), $user_email); $user = new WP_User($user_id); $user->set_role('administrator'); $guess_url = wp_guess_url(); foreach ($wpdb->tables('ms_global') as $table => $prefixed_table) { $wpdb->{$table} = $prefixed_table; } install_network(); populate_network(1, $domain, $user_email, 'jQuery Network', $base, false); update_site_option('site_admins', array($user->user_login)); update_site_option('allowedthemes', array()); $wpdb->insert($wpdb->blogs, array('site_id' => 1, 'domain' => $domain, 'path' => $base, 'registered' => current_time('mysql'))); $blog_id = $wpdb->insert_id; update_user_meta($user_id, 'source_domain', $domain); update_user_meta($user_id, 'primary_blog', $blog_id); if (!($upload_path = get_option('upload_path'))) { $upload_path = substr(WP_CONTENT_DIR, strlen(ABSPATH)) . '/uploads'; update_option('upload_path', $upload_path); } update_option('fileupload_url', get_option('siteurl') . '/' . $upload_path); jquery_install_remaining_sites($user); wp_new_blog_notification($blog_title, $guess_url, $user_id, $message = __('The password you chose during the install.')); wp_cache_flush(); return array('url' => $guess_url, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message); }
function create_object($args) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; if (!isset($args['user'])) { $email = WP_TESTS_EMAIL; } else { $email = get_userdata($args['user'])->user_email; } populate_network($args['network_id'], $args['domain'], $email, $args['title'], $args['path'], $args['subdomain_install']); return $args['network_id']; }
/** * Generates a new network. * * @since 1.0.0 * * @access protected * @param array $args The array of arguments to use during a new object creation. * @return int The newly created network's ID. */ protected function _createObject($args) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $faker = \Faker\Factory::create(); $test_email = defined('WP_TESTS_EMAIL') ? WP_TESTS_EMAIL : $faker->email; $email = isset($args['user']) ? get_userdata($args['user'])->user_email : $test_email; $network = populate_network($args['network_id'], $args['domain'], $email, $args['title'], $args['path'], $args['subdomain_install']); if ($network && !is_wp_error($network)) { $this->_debug('Generated network ID: ' . $args['network_id']); } elseif (is_wp_error($network)) { $this->_debug('Network generation failed with message [%s] %s', $network->get_error_code(), $network->get_error_messages()); } else { $this->_debug('Network generation failed'); } return $args['network_id']; }
"><?php _e('Log In'); ?> </a></p> <?php } } if ($_POST) { check_admin_referer('install-network-1'); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; // create network tables install_network(); $base = parse_url(trailingslashit(get_option('home')), PHP_URL_PATH); $subdomain_install = allow_subdomain_install() ? !empty($_POST['subdomain_install']) : false; if (!network_domain_check()) { $result = populate_network(1, get_clean_basedomain(), sanitize_email($_POST['email']), wp_unslash($_POST['sitename']), $base, $subdomain_install); if (is_wp_error($result)) { if (1 == count($result->get_error_codes()) && 'no_wildcard_dns' == $result->get_error_code()) { network_step2($result); } else { network_step1($result); } } else { network_step2(); } } else { network_step2(); } } elseif (is_multisite() || network_domain_check()) { network_step2(); } else {
private function _multisite_convert($assoc_args) { 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; } install_network(); $domain = self::get_clean_basedomain(); $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); } } } if (!is_multisite()) { ob_start(); ?> define('MULTISITE', true); define('SUBDOMAIN_INSTALL', <?php var_export($assoc_args['subdomains']); ?> ); $base = '<?php echo $assoc_args['base']; ?> '; define('DOMAIN_CURRENT_SITE', '<?php echo $domain; ?> '); define('PATH_CURRENT_SITE', '<?php echo $assoc_args['base']; ?> '); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1); <?php $ms_config = ob_get_clean(); self::modify_wp_config($ms_config); WP_CLI::log('Added multisite constants to wp-config.php.'); } return true; }
$wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" ); // We need to create references to ms global tables. if ( $multisite ) $wpdb->$table = $prefixed_table; } // Prefill a permalink structure so that WP doesn't try to determine one itself. add_action( 'populate_options', '_set_default_permalink_structure_for_tests' ); wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' ); // Delete dummy permalink structure, as prefilled above. if ( ! is_multisite() ) { delete_option( 'permalink_structure' ); } remove_action( 'populate_options', '_set_default_permalink_structure_for_tests' ); if ( $multisite ) { echo "Installing network..." . PHP_EOL; define( 'WP_INSTALLING_NETWORK', true ); $title = WP_TESTS_TITLE . ' Network'; $subdomain_install = false; install_network(); populate_network( 1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install ); $wp_rewrite->set_permalink_structure( '' ); }
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:'); WP_CLI::log($ms_config); } } return true; }
require_once ABSPATH . '/wp-admin/includes/upgrade.php'; require_once ABSPATH . '/wp-includes/wp-db.php'; define('WP_TESTS_VERSION_FILE', ABSPATH . '.wp-tests-version'); $wpdb->suppress_errors(); $wpdb->hide_errors(); $installed = $wpdb->get_var("SELECT option_value FROM {$wpdb->options} WHERE option_name = 'siteurl'"); if ($installed && file_exists(WP_TESTS_VERSION_FILE)) { $installed_version_hash = file_get_contents(WP_TESTS_VERSION_FILE); if ($installed_version_hash == test_version_check_hash()) { return; } } $wpdb->query('SET storage_engine = INNODB;'); $wpdb->query('DROP DATABASE IF EXISTS ' . DB_NAME . ";"); $wpdb->query('CREATE DATABASE ' . DB_NAME . ";"); $wpdb->select(DB_NAME, $wpdb->dbh); echo "Installing Awesome Support…" . PHP_EOL; wp_install(WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, '', 'a'); if (defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE) { echo "Installing network…" . PHP_EOL; define('WP_INSTALLING_NETWORK', true); //wp_set_wpdb_vars(); // We need to create references to ms global tables to enable Network. foreach ($wpdb->tables('ms_global') as $table => $prefixed_table) { $wpdb->{$table} = $prefixed_table; } install_network(); $result = populate_network(1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, WP_TESTS_NETWORK_TITLE, '/', WP_TESTS_SUBDOMAIN_INSTALL); system(WP_PHP_BINARY . ' ' . escapeshellarg(dirname(__FILE__) . '/ms-install.php') . ' ' . escapeshellarg($config_file_path)); } file_put_contents(WP_TESTS_VERSION_FILE, test_version_check_hash());
public function install() { global $table_prefix; error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT); define('WP_INSTALLING', true); $this->startHeadlessRequest(); if ($this->isMultisite) { echo "Running as multisite..." . PHP_EOL; define('MULTISITE', true); define('SUBDOMAIN_INSTALL', false); define('DOMAIN_CURRENT_SITE', WP_TESTS_DOMAIN); define('PATH_CURRENT_SITE', '/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1); $GLOBALS['base'] = '/'; } else { echo "Running as single site..." . PHP_EOL; } // Preset WordPress options defined in bootstrap file. // Used to activate themes, plugins, as well as other settings. if (isset($GLOBALS['wp_tests_options'])) { function wp_tests_options($value) { $key = substr(current_filter(), strlen('pre_option_')); return $GLOBALS['wp_tests_options'][$key]; } foreach (array_keys($GLOBALS['wp_tests_options']) as $key) { tests_add_filter('pre_option_' . $key, 'wp_tests_options'); } } // Load WordPress require_once ABSPATH . 'wp-settings.php'; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; require_once ABSPATH . 'wp-includes/wp-db.php'; define('WP_TESTS_VERSION_FILE', ABSPATH . '.wp-tests-version'); $wpdb->suppress_errors(); $installed = $wpdb->get_var("SELECT option_value FROM {$wpdb->options} WHERE option_name = 'siteurl'"); $wpdb->suppress_errors(false); $hash = get_option('db_version') . ' ' . (int) $multisite . ' ' . sha1(json_encode($this->settings)); if (!$this->alwaysReinstall && $installed && file_exists(WP_TESTS_VERSION_FILE) && file_get_contents(WP_TESTS_VERSION_FILE) == $hash) { return; } $wpdb->query('SET storage_engine = INNODB'); $wpdb->select(DB_NAME, $wpdb->dbh); echo "Installing..." . PHP_EOL; // Drop all tables foreach ($wpdb->get_col($wpdb->prepare("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA='%s'", DB_NAME)) as $table) { $wpdb->query("DROP TABLE IF EXISTS {$table}"); } wp_install(WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, $this->adminPassword); if ($multisite) { echo "Installing network..." . PHP_EOL; define('WP_INSTALLING_NETWORK', true); $title = WP_TESTS_TITLE . ' Network'; $subdomain_install = false; install_network(); populate_network(1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install); } file_put_contents(WP_TESTS_VERSION_FILE, $hash); if ($this->events['after-install'] !== null) { $this->events['after-install'](); } }
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."); }
<?php /***** * Wordpress automated setup * install_network.php * * Setup a WordPress network. * *****/ define('WP_INSTALLING', true); require_once 'tools/cli-load.php'; # Are we making a network today? if (empty($settings['network'])) { die("Skipping network setup\n"); } # Load WordPress Administration Upgrade API require_once ABSPATH . 'wp-admin/includes/upgrade.php'; # We need to create references to ms global tables to enable Network. foreach ($wpdb->tables('ms_global') as $table => $prefixed_table) { $wpdb->{$table} = $prefixed_table; } install_network(); $ms_install_result = populate_network($settings['install']['network_id'], $settings['install']['hostname'], $settings['install']['admin_email'], $settings['install']['network_title'], $settings['install']['base'], $settings['install']['subdomain_install']); if (is_wp_error($ms_install_result) && $ms_install_result->get_error_code() != 'no_wildcard_dns') { print $ms_install_result->get_error_message() . "\n"; die("Network setup failed\n"); } print "Network setup finished\n";
$wp_install_result = wp_install($weblog_title, $user_name, $admin_email, $public, '', $admin_password); if (is_wp_error($wp_install_result)) { var_dump($wp_install_result); die("Wordpress install failed"); } // Delete the first post wp_delete_post(1, true); // Delete the default about page wp_delete_post(2, true); print "Wordpress install finished\n"; // We need to create references to ms global tables to enable Network. foreach ($wpdb->tables('ms_global') as $table => $prefixed_table) { $wpdb->{$table} = $prefixed_table; } install_network(); $ms_install_result = populate_network($network_id, $hostname, $admin_email, $network_title, $base, $subdomain_install); if (is_wp_error($ms_install_result) && $ms_install_result->get_error_code() != 'no_wildcard_dns') { print $ms_install_result->get_error_message() . "\n"; die("Network setup failed"); } print "Network setup finished\n"; // lets write some files // Write the .htaccess file $htaccess_file = 'RewriteEngine On RewriteBase ' . $base . ' RewriteRule ^index\\.php$ - [L] # uploaded files RewriteRule ^' . ($subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?') . 'files/(.+) wp-includes/ms-files.php?file=$' . ($subdomain_install ? 1 : 2) . ' [L]' . "\n\nRewriteCond %{REQUEST_FILENAME} -f [OR]\nRewriteCond %{REQUEST_FILENAME} -d\nRewriteRule ^ - [L]\nRewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) \$2 [L]\nRewriteRule ^(.*/)?sitemap.xml wp-content/sitemap.php [L]\nRewriteRule ^([_0-9a-zA-Z-]+/)?(.*\\.php)\$ \$2 [L]\nRewriteRule . index.php [L]"; fwrite(fopen("../.htaccess", 'w'), $htaccess_file); // Update the wp-config file
protected function createSite($domain, $path, $subdomain_install, $sitename, $email) { $result = populate_network(1, $domain, $email, $sitename, $path, $subdomain_install); if (is_wp_error($result)) { if ($result->get_error_code() !== 'no_wildcard_dns') { // Error! foreach ($result->get_error_codes() as $error_code) { $this->error($error_code); } return; } $this->line('Warning: no_wildcard_dns'); } }