prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->site ) ); if ( $wpdb->get_var( $sql ) ) { return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" ); } return false; } /** * Allow subdomain installation * * @since 3.0.0 * @return bool Whether subdomain installation is allowed */ function allow_subdomain_install() { $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) ); if ( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' === $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) ) { return false; } return true; } /** * Allow subdirectory installation. * * @since 3.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @return bool Whether subdirectory installation is allowed */ function allow_subdirectory_install() { global $wpdb; /** * Filters whether to enable the subdirectory installation feature in Multisite. * * @since 3.0.0 * * @param bool $allow Whether to enable the subdirectory installation feature in Multisite. * Default false. */ 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() { $existing_domain = network_domain_check(); if ( $existing_domain ) { return $existing_domain; } $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) ); $slash = strpos( $domain, '/' ); if ( $slash ) { $domain = substr( $domain, 0, $slash ); } return $domain; } /** * Prints step 1 for Network installation process. * * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. * Navigating to Tools > 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 * * @global bool $is_apache * * @param false|WP_Error $errors Optional. Error object. Default false. */ function network_step1( $errors = false ) { global $is_apache; if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { $cannot_define_constant_message = '' . __( 'Error:' ) . ' '; $cannot_define_constant_message .= sprintf( /* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */ __( 'The constant %s cannot be defined when creating a network.' ), 'DO_NOT_UPGRADE_GLOBAL_TABLES' ); wp_admin_notice( $cannot_define_constant_message, array( 'additional_classes' => array( 'error' ), ) ); echo ''; require_once ABSPATH . 'wp-admin/admin-footer.php'; die(); } $active_plugins = get_option( 'active_plugins' ); if ( ! empty( $active_plugins ) ) { wp_admin_notice( '' . __( 'Warning:' ) . ' ' . sprintf( /* translators: %s: URL to Plugins screen. */ __( 'Please deactivate your plugins before enabling the Network feature.' ), admin_url( 'plugins.php?plugin_status=active' ) ), array( 'type' => 'warning' ) ); echo '

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

'; echo ''; require_once ABSPATH . 'wp-admin/admin-footer.php'; die(); } // Strip standard port from hostname. $hostname = preg_replace( '/(?::80|:443)$/', '', get_clean_basedomain() ); echo '
'; wp_nonce_field( 'install-network-1' ); $error_codes = array(); if ( is_wp_error( $errors ) ) { $network_created_error_message = '

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

'; foreach ( $errors->get_error_messages() as $error ) { $network_created_error_message .= "

$error

"; } wp_admin_notice( $network_created_error_message, array( 'additional_classes' => array( 'error' ), 'paragraph_wrap' => false, ) ); $error_codes = $errors->get_error_codes(); } if ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes, true ) ) { $site_name = $_POST['sitename']; } else { /* translators: %s: Default network title. */ $site_name = sprintf( __( '%s Sites' ), get_option( 'blogname' ) ); } if ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes, true ) ) { $admin_email = $_POST['email']; } else { $admin_email = get_option( 'admin_email' ); } ?>

' . __( 'Warning:' ) . ' '; $message .= '

' . sprintf( /* translators: %s: mod_rewrite */ __( 'Please make sure the Apache %s module is installed as it will be used at the end of this installation.' ), 'mod_rewrite' ) . '

'; } elseif ( $is_apache ) { $message_class = 'error'; $message = '

' . __( 'Warning:' ) . ' '; $message .= sprintf( /* translators: %s: mod_rewrite */ __( 'It looks like the Apache %s module is not installed.' ), 'mod_rewrite' ) . '

'; } if ( $got_mod_rewrite || $is_apache ) { // Protect against mod_rewrite mimicry (but ! Apache). $message .= '

' . sprintf( /* translators: 1: mod_rewrite, 2: mod_rewrite documentation URL, 3: Google search for mod_rewrite. */ __( 'If %1$s is disabled, ask your administrator to enable that module, or look at the Apache documentation or elsewhere for help setting it up.' ), 'mod_rewrite', 'https://httpd.apache.org/docs/mod/mod_rewrite.html', 'https://www.google.com/search?q=apache+mod_rewrite' ) . '

'; wp_admin_notice( $message, array( 'additional_classes' => array( $message_class, 'inline' ), 'paragraph_wrap' => false, ) ); } } if ( allow_subdomain_install() && allow_subdirectory_install() ) : ?>

' . __( 'Warning:' ) . ' '; $subdirectory_warning_message .= __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ); wp_admin_notice( $subdirectory_warning_message, array( 'additional_classes' => array( 'error', 'inline' ), ) ); } $is_www = str_starts_with( $hostname, 'www.' ); if ( $is_www ) : ?>

' . substr( $hostname, 4 ) . '', '' . $hostname . '', 'www' ); ?>

get_error_message(), array( 'additional_classes' => array( 'error' ), ) ); } if ( $_POST ) { if ( allow_subdomain_install() ) { $subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true; } else { $subdomain_install = 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'" ); wp_admin_notice( '' . __( 'Warning:' ) . ' ' . __( 'An existing WordPress network was detected.' ), array( 'additional_classes' => array( 'error' ), ) ); ?>

' . __( 'Caution:' ) . ' '; $notice_args = array( 'type' => 'warning', 'additional_classes' => array( 'inline' ), ); if ( file_exists( $home_path . '.htaccess' ) ) { $notice_message .= sprintf( /* translators: 1: wp-config.php, 2: .htaccess */ __( 'You should back up your existing %1$s and %2$s files.' ), 'wp-config.php', '.htaccess' ); } elseif ( file_exists( $home_path . 'web.config' ) ) { $notice_message .= sprintf( /* translators: 1: wp-config.php, 2: web.config */ __( 'You should back up your existing %1$s and %2$s files.' ), 'wp-config.php', 'web.config' ); } else { $notice_message .= sprintf( /* translators: %s: wp-config.php */ __( 'You should back up your existing %s file.' ), 'wp-config.php' ); } wp_admin_notice( $notice_message, $notice_args ); } ?>
  1. above the line reading %3$s:' ), 'wp-config.php', '' . $location_of_wp_config . '', /* * translators: This string should only be translated if wp-config-sample.php is localized. * You can check the localized release package or * https://i18n.svn.wordpress.org//branches//dist/wp-config-sample.php */ '/* ' . __( 'That’s all, stop editing! Happy publishing.' ) . ' */' ); ?>

    '', '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 ) ) { $keys_salts_str = ''; $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_str .= "\ndefine( '$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_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );"; } } $num_keys_salts = count( $keys_salts ); ?>

    wp-config.php' ); } else { printf( /* translators: %s: wp-config.php */ __( 'These unique authentication keys are also missing from your %s file.' ), 'wp-config.php' ); } ?>

  2. '; if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) { $web_config_file .= ' '; } $web_config_file .= ' '; echo '
  3. '; printf( /* translators: 1: File name (.htaccess or web.config), 2: File path. */ __( 'Add the following to your %1$s file in %2$s, replacing other WordPress rules:' ), 'web.config', '' . $home_path . '' ); echo '

    '; if ( ! $subdomain_install && WP_CONTENT_DIR !== ABSPATH . 'wp-content' ) { echo '

    ' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '

    '; } ?>

'; printf( /* translators: %s: Documentation URL. */ __( 'It seems your network is running with Nginx web server. Learn more about further configuration.' ), __( 'https://developer.wordpress.org/advanced-administration/server/web-server/nginx/' ) ); echo '

'; else : // End $is_nginx. Construct an .htaccess file instead: $ms_files_rewriting = ''; if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) { $ms_files_rewriting = "\n# uploaded files\nRewriteRule ^"; $ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n"; } $htaccess_file = <<

'; printf( /* translators: 1: File name (.htaccess or web.config), 2: File path. */ __( 'Add the following to your %1$s file in %2$s, replacing other WordPress rules:' ), '.htaccess', '' . $home_path . '' ); echo '

'; if ( ! $subdomain_install && WP_CONTENT_DIR !== ABSPATH . 'wp-content' ) { echo '

' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '

'; } ?>