tables( 'ms_global' ) as $table => $prefixed_table ) $wpdb->$table = $prefixed_table; /** * Check for an existing network. * * @since 3.0.0 * @return Whether a network exists. */ function network_domain_check() { global $wpdb; if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) ) return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" ); return false; } /** * Allow subdomain install * * @since 3.0.0 * @return bool Whether subdomain install is allowed */ function allow_subdomain_install() { $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'siteurl' ) ); if( false !== strpos( $domain, '/' ) || 'localhost' == $domain || preg_match( '|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|', $domain ) ) return false; return true; } /** * Allow subdirectory install * * @since 3.0.0 * @return bool Whether subdirectory install is allowed */ function allow_subdirectory_install() { global $wpdb; if ( apply_filters( 'allow_subdirectory_install', false ) ) return true; if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL ) return true; $post = $wpdb->get_row( "SELECT ID FROM $wpdb->posts WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND post_status = 'publish'" ); if ( empty( $post ) ) return true; return false; } /** * Get base domain of network. * * @since 3.0.0 * @return string Base domain. */ function get_clean_basedomain() { if ( $existing_domain = network_domain_check() ) return $existing_domain; $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) ); if ( $slash = strpos( $domain, '/' ) ) $domain = substr( $domain, 0, $slash ); return $domain; } if ( ! network_domain_check() && ( ! defined( 'WP_ALLOW_MULTISITE' ) || ! WP_ALLOW_MULTISITE ) ) wp_die( __( 'You must define the WP_ALLOW_MULTISITE constant as true in your wp-config.php file to allow creation of a Network.' ) ); $title = __( 'Create a Network of WordPress Sites' ); $parent_file = 'tools.php'; add_contextual_help($current_screen, '

' . __('This screen allows you to configure a network as having subdomains (site1.example.com) or subdirectories (example.com/site1). Subdomains require wildcard subdomains to be enabled in Apache and DNS records, if your host allows it.') . '

' . '

' . __('Choose subdomains or subdirectories; this can only be switched afterwards by reconfiguring your install. Fill out the network details, and click install. If this does not work, you may have to add a wildcard DNS record (for subdomains) or change to another setting in Permalinks (for subdirectories).') . '

' . '

' . __('The next screen for Network will give you individually-generated lines of code to add to your wp-config.php and .htaccess files. Make sure the settings of your FTP client make files starting with a dot visible, so that you can find .htaccess; you may have to create this file if it really is not there. Make backup copies of those two files.') . '

' . '

' . __('Add a blogs.dir directory under /wp-content and add the designated lines of code to wp-config.php (just before /*...stop editing...*/) and .htaccess (replacing the existing WordPress rules).') . '

' . '

' . __('Refreshing your browser will take you to a screen with an archive of those added lines of code. A set of six links under Super Admin will appear at the top of the main left navigation menu. The multisite network is now enabled.') . '

' . '

' . __('The choice of subdirectory sites is disabled if this setup is more than a month old because of permalink problems with “/blog/” from the main site. This disabling will be addressed soon in a future version.') . '

' . '

' . __('For more information:') . '

' . '

' . __('General Network Creation Documentation') . '

' . '

' . __('Tools > Network Documentation') . '

' . '

' . __('Support Forums') . '

' ); include( './admin-header.php' ); ?>

Network * should not be a sudden "Welcome to a new install process! Fill this out and click here." See also contextual help todo. * * @since 3.0.0 */ function network_step1( $errors = false ) { global $is_apache; if ( get_option( 'siteurl' ) != get_option( 'home' ) ) { echo '

' . __('Error:') . ' ' . sprintf( __( 'Your WordPress address must match your Site address before creating a Network. See General Settings.' ), esc_url( admin_url( 'options-general.php' ) ) ) . '

'; echo '
'; include ('./admin-footer.php' ); die(); } $active_plugins = get_option( 'active_plugins' ); if ( ! empty( $active_plugins ) ) { echo '

' . __('Warning:') . ' ' . sprintf( __( 'Please deactivate your plugins before enabling the Network feature.' ), admin_url( 'plugins.php?plugin_status=active' ) ) . '

' . __( 'Once the network is created, you may reactivate your plugins.' ) . '

'; echo ''; include( './admin-footer.php' ); die(); } $hostname = get_clean_basedomain(); $has_ports = strstr( $hostname, ':' ); if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) { echo '

' . __( 'Error:') . ' ' . __( 'You cannot install a network of sites with your server address.' ) . '

'; echo '

' . sprintf( __( 'You cannot use port numbers such as %s.' ), $has_ports ) . '

'; echo '' . __( 'Return to Dashboard' ) . ''; echo ''; include( './admin-footer.php' ); die(); } echo '
'; wp_nonce_field( 'install-network-1' ); $error_codes = array(); if ( is_wp_error( $errors ) ) { echo '

' . __( 'ERROR: The network could not be created.' ) . '

'; foreach ( $errors->get_error_messages() as $error ) echo "

$error

"; echo '
'; $error_codes = $errors->get_error_codes(); } if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' ) echo '

' . __('Warning!') . ' ' . __( 'Networks may not be fully compatible with custom wp-content directories.' ) . '

'; $site_name = ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes ) ) ? $_POST['sitename'] : sprintf( _x('%s Sites', 'Default network name' ), get_option( 'blogname' ) ); $admin_email = ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes ) ) ? $_POST['email'] : get_option( 'admin_email' ); ?>

' . __( 'Note:' ) . ' ' . __( 'Please make sure the Apache mod_rewrite module is installed as it will be used at the end of this installation.' ) . '

'; elseif ( $is_apache ) echo '

' . __( 'Warning!' ) . ' ' . __( 'It looks like the Apache mod_rewrite module is not installed.' ) . '

'; if ( $got_mod_rewrite || $is_apache ) // Protect against mod_rewrite mimicry (but ! Apache) echo '

' . __( 'If mod_rewrite is disabled, ask your administrator to enable that module, or look at the Apache documentation or elsewhere for help setting it up.' ) . '

'; } if ( allow_subdomain_install() && allow_subdirectory_install() ) : ?>

You cannot change this later.' ); ?>

site1.%1$s and site2.%1$s', 'subdomain examples' ), $hostname ); ?>
%1$s/site1 and %1$s/site2', 'subdirectory examples' ), $hostname ); ?>

%1$s before enabling the network feature. It will still be possible to visit your site using the www prefix with an address like %2$s but any links will not have the www prefix.' ), substr( $hostname, 4 ), $hostname ); ?>
%s.' ), $hostname ); ?>

localhost, the sites in your WordPress network must use sub-directories. Consider using localhost.localdomain if you wish to use sub-domains.' ); // Uh oh: if ( !allow_subdirectory_install() ) echo ' ' . __( 'Warning!' ) . ' ' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . ''; ?>
' . __( 'Warning!' ) . ' ' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . ''; ?>
' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . ''; ?>
%s.' ), $hostname ); ?>


' . $errors->get_error_message() . ''; if ( $_POST ) { $subdomain_install = allow_subdomain_install() ? ( allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true ) : false; } else { if ( is_multisite() ) { $subdomain_install = is_subdomain_install(); ?>

get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" ); ?>

Caution: We recommend you back up your existing wp-config.php file.' ); else _e( 'Caution: We recommend you back up your existing wp-config.php and .htaccess files.' ); ?>

  1. blogs.dir directory at %s/blogs.dir. This directory is used to store uploaded media for your additional sites and must be writeable by the web server.' ), WP_CONTENT_DIR ); if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' ) echo ' ' . __('Warning:') . ' ' . __( 'Networks may not be fully compatible with custom wp-content directories.' ) . '

  2. wp-config.php file in %s above the line reading /* That’s all, stop editing! Happy blogging. */:' ), ABSPATH ); ?>

    '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' ); foreach ( $keys_salts as $c => $v ) { if ( defined( $c ) ) unset( $keys_salts[ $c ] ); } if ( ! empty( $keys_salts ) ) { $from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' ); if ( is_wp_error( $from_api ) ) { foreach ( $keys_salts as $c => $v ) { $keys_salts[ $c ] = wp_generate_password( 64, true, true ); } } else { $from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) ); foreach ( $keys_salts as $c => $v ) { $keys_salts[ $c ] = substr( array_shift( $from_api ), 28, 64 ); } } $num_keys_salts = count( $keys_salts ); ?>

    wp-config.php file.', 'These unique authentication keys are also missing from your wp-config.php file.', $num_keys_salts ); ?>

  3. '; } else { $web_config_file = ' '; } ?>
  4. web.config file in %s, replacing other WordPress rules:' ), ABSPATH ); ?>

  • .htaccess file in %s, replacing other WordPress rules:' ), ABSPATH ); ?>

  • 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 { network_step1(); } ?>