wp/wp-admin/includes/network.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    32  * @since 3.0.0
    32  * @since 3.0.0
    33  * @return bool Whether subdomain installation is allowed
    33  * @return bool Whether subdomain installation is allowed
    34  */
    34  */
    35 function allow_subdomain_install() {
    35 function allow_subdomain_install() {
    36 	$domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
    36 	$domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
    37 	if ( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) ) {
    37 	if ( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' === $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) ) {
    38 		return false;
    38 		return false;
    39 	}
    39 	}
    40 
    40 
    41 	return true;
    41 	return true;
    42 }
    42 }
    50  *
    50  *
    51  * @return bool Whether subdirectory installation is allowed
    51  * @return bool Whether subdirectory installation is allowed
    52  */
    52  */
    53 function allow_subdirectory_install() {
    53 function allow_subdirectory_install() {
    54 	global $wpdb;
    54 	global $wpdb;
    55 		/**
    55 
    56 		 * Filters whether to enable the subdirectory installation feature in Multisite.
    56 	/**
    57 		 *
    57 	 * Filters whether to enable the subdirectory installation feature in Multisite.
    58 		 * @since 3.0.0
    58 	 *
    59 		 *
    59 	 * @since 3.0.0
    60 		 * @param bool $allow Whether to enable the subdirectory installation feature in Multisite. Default is false.
    60 	 *
    61 		 */
    61 	 * @param bool $allow Whether to enable the subdirectory installation feature in Multisite.
       
    62 	 *                    Default false.
       
    63 	 */
    62 	if ( apply_filters( 'allow_subdirectory_install', false ) ) {
    64 	if ( apply_filters( 'allow_subdirectory_install', false ) ) {
    63 		return true;
    65 		return true;
    64 	}
    66 	}
    65 
    67 
    66 	if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL ) {
    68 	if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL ) {
    80  *
    82  *
    81  * @since 3.0.0
    83  * @since 3.0.0
    82  * @return string Base domain.
    84  * @return string Base domain.
    83  */
    85  */
    84 function get_clean_basedomain() {
    86 function get_clean_basedomain() {
    85 	if ( $existing_domain = network_domain_check() ) {
    87 	$existing_domain = network_domain_check();
       
    88 	if ( $existing_domain ) {
    86 		return $existing_domain;
    89 		return $existing_domain;
    87 	}
    90 	}
    88 	$domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
    91 	$domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
    89 	if ( $slash = strpos( $domain, '/' ) ) {
    92 	$slash  = strpos( $domain, '/' );
       
    93 	if ( $slash ) {
    90 		$domain = substr( $domain, 0, $slash );
    94 		$domain = substr( $domain, 0, $slash );
    91 	}
    95 	}
    92 	return $domain;
    96 	return $domain;
    93 }
    97 }
    94 
    98 
    95 /**
    99 /**
    96  * Prints step 1 for Network installation process.
   100  * Prints step 1 for Network installation process.
    97  *
   101  *
    98  * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. Navigating to Tools > Network
   102  * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such.
    99  *  should not be a sudden "Welcome to a new install process! Fill this out and click here." See also contextual help todo.
   103  *       Navigating to Tools > Network should not be a sudden "Welcome to a new install process!
       
   104  *       Fill this out and click here." See also contextual help todo.
   100  *
   105  *
   101  * @since 3.0.0
   106  * @since 3.0.0
   102  *
   107  *
   103  * @global bool $is_apache
   108  * @global bool $is_apache
   104  *
   109  *
   106  */
   111  */
   107 function network_step1( $errors = false ) {
   112 function network_step1( $errors = false ) {
   108 	global $is_apache;
   113 	global $is_apache;
   109 
   114 
   110 	if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
   115 	if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
   111 		echo '<div class="error"><p><strong>' . __( 'ERROR:' ) . '</strong> ' . sprintf(
   116 		echo '<div class="error"><p><strong>' . __( 'Error:' ) . '</strong> ' . sprintf(
   112 			/* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */
   117 			/* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */
   113 			__( 'The constant %s cannot be defined when creating a network.' ),
   118 			__( 'The constant %s cannot be defined when creating a network.' ),
   114 			'<code>DO_NOT_UPGRADE_GLOBAL_TABLES</code>'
   119 			'<code>DO_NOT_UPGRADE_GLOBAL_TABLES</code>'
   115 		) . '</p></div>';
   120 		) . '</p></div>';
   116 		echo '</div>';
   121 		echo '</div>';
   117 		include( ABSPATH . 'wp-admin/admin-footer.php' );
   122 		require_once ABSPATH . 'wp-admin/admin-footer.php';
   118 		die();
   123 		die();
   119 	}
   124 	}
   120 
   125 
   121 	$active_plugins = get_option( 'active_plugins' );
   126 	$active_plugins = get_option( 'active_plugins' );
   122 	if ( ! empty( $active_plugins ) ) {
   127 	if ( ! empty( $active_plugins ) ) {
   123 		echo '<div class="updated"><p><strong>' . __( 'Warning:' ) . '</strong> ' . sprintf(
   128 		echo '<div class="notice notice-warning"><p><strong>' . __( 'Warning:' ) . '</strong> ' . sprintf(
   124 			/* translators: %s: Plugins screen URL */
   129 			/* translators: %s: URL to Plugins screen. */
   125 			__( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ),
   130 			__( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ),
   126 			admin_url( 'plugins.php?plugin_status=active' )
   131 			admin_url( 'plugins.php?plugin_status=active' )
   127 		) . '</p></div>';
   132 		) . '</p></div>';
   128 		echo '<p>' . __( 'Once the network is created, you may reactivate your plugins.' ) . '</p>';
   133 		echo '<p>' . __( 'Once the network is created, you may reactivate your plugins.' ) . '</p>';
   129 		echo '</div>';
   134 		echo '</div>';
   130 		include( ABSPATH . 'wp-admin/admin-footer.php' );
   135 		require_once ABSPATH . 'wp-admin/admin-footer.php';
   131 		die();
   136 		die();
   132 	}
   137 	}
   133 
   138 
   134 	$hostname  = get_clean_basedomain();
   139 	$hostname  = get_clean_basedomain();
   135 	$has_ports = strstr( $hostname, ':' );
   140 	$has_ports = strstr( $hostname, ':' );
   136 	if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
   141 	if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ), true ) ) ) {
   137 		echo '<div class="error"><p><strong>' . __( 'ERROR:' ) . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
   142 		echo '<div class="error"><p><strong>' . __( 'Error:' ) . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
   138 		echo '<p>' . sprintf(
   143 		echo '<p>' . sprintf(
   139 			/* translators: %s: port number */
   144 			/* translators: %s: Port number. */
   140 			__( 'You cannot use port numbers such as %s.' ),
   145 			__( 'You cannot use port numbers such as %s.' ),
   141 			'<code>' . $has_ports . '</code>'
   146 			'<code>' . $has_ports . '</code>'
   142 		) . '</p>';
   147 		) . '</p>';
   143 		echo '<a href="' . esc_url( admin_url() ) . '">' . __( 'Return to Dashboard' ) . '</a>';
   148 		echo '<a href="' . esc_url( admin_url() ) . '">' . __( 'Return to Dashboard' ) . '</a>';
   144 		echo '</div>';
   149 		echo '</div>';
   145 		include( ABSPATH . 'wp-admin/admin-footer.php' );
   150 		require_once ABSPATH . 'wp-admin/admin-footer.php';
   146 		die();
   151 		die();
   147 	}
   152 	}
   148 
   153 
   149 	echo '<form method="post">';
   154 	echo '<form method="post">';
   150 
   155 
   151 	wp_nonce_field( 'install-network-1' );
   156 	wp_nonce_field( 'install-network-1' );
   152 
   157 
   153 	$error_codes = array();
   158 	$error_codes = array();
   154 	if ( is_wp_error( $errors ) ) {
   159 	if ( is_wp_error( $errors ) ) {
   155 		echo '<div class="error"><p><strong>' . __( 'ERROR: The network could not be created.' ) . '</strong></p>';
   160 		echo '<div class="error"><p><strong>' . __( 'Error: The network could not be created.' ) . '</strong></p>';
   156 		foreach ( $errors->get_error_messages() as $error ) {
   161 		foreach ( $errors->get_error_messages() as $error ) {
   157 			echo "<p>$error</p>";
   162 			echo "<p>$error</p>";
   158 		}
   163 		}
   159 		echo '</div>';
   164 		echo '</div>';
   160 		$error_codes = $errors->get_error_codes();
   165 		$error_codes = $errors->get_error_codes();
   161 	}
   166 	}
   162 
   167 
   163 	if ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes ) ) {
   168 	if ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes, true ) ) {
   164 		$site_name = $_POST['sitename'];
   169 		$site_name = $_POST['sitename'];
   165 	} else {
   170 	} else {
   166 		/* translators: %s: Default network name */
   171 		/* translators: %s: Default network title. */
   167 		$site_name = sprintf( __( '%s Sites' ), get_option( 'blogname' ) );
   172 		$site_name = sprintf( __( '%s Sites' ), get_option( 'blogname' ) );
   168 	}
   173 	}
   169 
   174 
   170 	if ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes ) ) {
   175 	if ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes, true ) ) {
   171 		$admin_email = $_POST['email'];
   176 		$admin_email = $_POST['email'];
   172 	} else {
   177 	} else {
   173 		$admin_email = get_option( 'admin_email' );
   178 		$admin_email = get_option( 'admin_email' );
   174 	}
   179 	}
   175 	?>
   180 	?>
   177 	<p><?php _e( 'Fill in the information below and you&#8217;ll be on your way to creating a network of WordPress sites. We will create configuration files in the next step.' ); ?></p>
   182 	<p><?php _e( 'Fill in the information below and you&#8217;ll be on your way to creating a network of WordPress sites. We will create configuration files in the next step.' ); ?></p>
   178 	<?php
   183 	<?php
   179 
   184 
   180 	if ( isset( $_POST['subdomain_install'] ) ) {
   185 	if ( isset( $_POST['subdomain_install'] ) ) {
   181 		$subdomain_install = (bool) $_POST['subdomain_install'];
   186 		$subdomain_install = (bool) $_POST['subdomain_install'];
   182 	} elseif ( apache_mod_loaded( 'mod_rewrite' ) ) { // assume nothing
   187 	} elseif ( apache_mod_loaded( 'mod_rewrite' ) ) { // Assume nothing.
   183 		$subdomain_install = true;
   188 		$subdomain_install = true;
   184 	} elseif ( ! allow_subdirectory_install() ) {
   189 	} elseif ( ! allow_subdirectory_install() ) {
   185 		$subdomain_install = true;
   190 		$subdomain_install = true;
   186 	} else {
   191 	} else {
   187 		$subdomain_install = false;
   192 		$subdomain_install = false;
   188 		if ( $got_mod_rewrite = got_mod_rewrite() ) { // dangerous assumptions
   193 		$got_mod_rewrite   = got_mod_rewrite();
       
   194 		if ( $got_mod_rewrite ) { // Dangerous assumptions.
   189 			echo '<div class="updated inline"><p><strong>' . __( 'Note:' ) . '</strong> ';
   195 			echo '<div class="updated inline"><p><strong>' . __( 'Note:' ) . '</strong> ';
   190 			/* translators: %s: mod_rewrite */
       
   191 			printf(
   196 			printf(
       
   197 				/* translators: %s: mod_rewrite */
   192 				__( 'Please make sure the Apache %s module is installed as it will be used at the end of this installation.' ),
   198 				__( 'Please make sure the Apache %s module is installed as it will be used at the end of this installation.' ),
   193 				'<code>mod_rewrite</code>'
   199 				'<code>mod_rewrite</code>'
   194 			);
   200 			);
   195 			echo '</p>';
   201 			echo '</p>';
   196 		} elseif ( $is_apache ) {
   202 		} elseif ( $is_apache ) {
   197 			echo '<div class="error inline"><p><strong>' . __( 'Warning:' ) . '</strong> ';
   203 			echo '<div class="error inline"><p><strong>' . __( 'Warning:' ) . '</strong> ';
   198 			/* translators: %s: mod_rewrite */
       
   199 			printf(
   204 			printf(
       
   205 				/* translators: %s: mod_rewrite */
   200 				__( 'It looks like the Apache %s module is not installed.' ),
   206 				__( 'It looks like the Apache %s module is not installed.' ),
   201 				'<code>mod_rewrite</code>'
   207 				'<code>mod_rewrite</code>'
   202 			);
   208 			);
   203 			echo '</p>';
   209 			echo '</p>';
   204 		}
   210 		}
   205 
   211 
   206 		if ( $got_mod_rewrite || $is_apache ) { // Protect against mod_rewrite mimicry (but ! Apache)
   212 		if ( $got_mod_rewrite || $is_apache ) { // Protect against mod_rewrite mimicry (but ! Apache).
   207 			echo '<p>';
   213 			echo '<p>';
   208 			/* translators: 1: mod_rewrite, 2: mod_rewrite documentation URL, 3: Google search for mod_rewrite */
       
   209 			printf(
   214 			printf(
       
   215 				/* translators: 1: mod_rewrite, 2: mod_rewrite documentation URL, 3: Google search for mod_rewrite. */
   210 				__( 'If %1$s is disabled, ask your administrator to enable that module, or look at the <a href="%2$s">Apache documentation</a> or <a href="%3$s">elsewhere</a> for help setting it up.' ),
   216 				__( 'If %1$s is disabled, ask your administrator to enable that module, or look at the <a href="%2$s">Apache documentation</a> or <a href="%3$s">elsewhere</a> for help setting it up.' ),
   211 				'<code>mod_rewrite</code>',
   217 				'<code>mod_rewrite</code>',
   212 				'https://httpd.apache.org/docs/mod/mod_rewrite.html',
   218 				'https://httpd.apache.org/docs/mod/mod_rewrite.html',
   213 				'https://www.google.com/search?q=apache+mod_rewrite'
   219 				'https://www.google.com/search?q=apache+mod_rewrite'
   214 			);
   220 			);
   220 		?>
   226 		?>
   221 		<h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3>
   227 		<h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3>
   222 		<p><?php _e( 'Please choose whether you would like sites in your WordPress network to use sub-domains or sub-directories.' ); ?>
   228 		<p><?php _e( 'Please choose whether you would like sites in your WordPress network to use sub-domains or sub-directories.' ); ?>
   223 			<strong><?php _e( 'You cannot change this later.' ); ?></strong></p>
   229 			<strong><?php _e( 'You cannot change this later.' ); ?></strong></p>
   224 		<p><?php _e( 'You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality.' ); ?></p>
   230 		<p><?php _e( 'You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality.' ); ?></p>
   225 		<?php // @todo: Link to an MS readme? ?>
   231 		<?php // @todo Link to an MS readme? ?>
   226 		<table class="form-table" role="presentation">
   232 		<table class="form-table" role="presentation">
   227 			<tr>
   233 			<tr>
   228 				<th><label><input type="radio" name="subdomain_install" value="1"<?php checked( $subdomain_install ); ?> /> <?php _e( 'Sub-domains' ); ?></label></th>
   234 				<th><label><input type="radio" name="subdomain_install" value="1"<?php checked( $subdomain_install ); ?> /> <?php _e( 'Sub-domains' ); ?></label></th>
   229 				<td>
   235 				<td>
   230 				<?php
   236 				<?php
   231 				printf(
   237 				printf(
   232 					/* translators: 1: hostname */
   238 					/* translators: 1: Host name. */
   233 					_x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ),
   239 					_x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ),
   234 					$hostname
   240 					$hostname
   235 				);
   241 				);
   236 				?>
   242 				?>
   237 				</td>
   243 				</td>
   239 			<tr>
   245 			<tr>
   240 				<th><label><input type="radio" name="subdomain_install" value="0"<?php checked( ! $subdomain_install ); ?> /> <?php _e( 'Sub-directories' ); ?></label></th>
   246 				<th><label><input type="radio" name="subdomain_install" value="0"<?php checked( ! $subdomain_install ); ?> /> <?php _e( 'Sub-directories' ); ?></label></th>
   241 				<td>
   247 				<td>
   242 				<?php
   248 				<?php
   243 				printf(
   249 				printf(
   244 					/* translators: 1: hostname */
   250 					/* translators: 1: Host name. */
   245 					_x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ),
   251 					_x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ),
   246 					$hostname
   252 					$hostname
   247 				);
   253 				);
   248 				?>
   254 				?>
   249 				</td>
   255 				</td>
   251 		</table>
   257 		</table>
   252 
   258 
   253 		<?php
   259 		<?php
   254 	endif;
   260 	endif;
   255 
   261 
   256 	if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) ) {
   262 	if ( WP_CONTENT_DIR !== ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) ) {
   257 		echo '<div class="error inline"><p><strong>' . __( 'Warning:' ) . '</strong> ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
   263 		echo '<div class="error inline"><p><strong>' . __( 'Warning:' ) . '</strong> ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
   258 	}
   264 	}
   259 
   265 
   260 		$is_www = ( 0 === strpos( $hostname, 'www.' ) );
   266 	$is_www = ( 0 === strpos( $hostname, 'www.' ) );
   261 	if ( $is_www ) :
   267 	if ( $is_www ) :
   262 		?>
   268 		?>
   263 		<h3><?php esc_html_e( 'Server Address' ); ?></h3>
   269 		<h3><?php esc_html_e( 'Server Address' ); ?></h3>
   264 		<p>
   270 		<p>
   265 		<?php
   271 		<?php
   266 		printf(
   272 		printf(
   267 			/* translators: 1: site url, 2: host name, 3: www */
   273 			/* translators: 1: Site URL, 2: Host name, 3: www. */
   268 			__( 'We recommend you change your siteurl to %1$s before enabling the network feature. It will still be possible to visit your site using the %3$s prefix with an address like %2$s but any links will not have the %3$s prefix.' ),
   274 			__( 'We recommend you change your site domain to %1$s before enabling the network feature. It will still be possible to visit your site using the %3$s prefix with an address like %2$s but any links will not have the %3$s prefix.' ),
   269 			'<code>' . substr( $hostname, 4 ) . '</code>',
   275 			'<code>' . substr( $hostname, 4 ) . '</code>',
   270 			'<code>' . $hostname . '</code>',
   276 			'<code>' . $hostname . '</code>',
   271 			'<code>www</code>'
   277 			'<code>www</code>'
   272 		);
   278 		);
   273 		?>
   279 		?>
   276 			<tr>
   282 			<tr>
   277 			<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
   283 			<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
   278 			<td>
   284 			<td>
   279 				<?php
   285 				<?php
   280 					printf(
   286 					printf(
   281 						/* translators: %s: host name */
   287 						/* translators: %s: Host name. */
   282 						__( 'The internet address of your network will be %s.' ),
   288 						__( 'The internet address of your network will be %s.' ),
   283 						'<code>' . $hostname . '</code>'
   289 						'<code>' . $hostname . '</code>'
   284 					);
   290 					);
   285 				?>
   291 				?>
   286 				</td>
   292 				</td>
   288 		</table>
   294 		</table>
   289 		<?php endif; ?>
   295 		<?php endif; ?>
   290 
   296 
   291 		<h3><?php esc_html_e( 'Network Details' ); ?></h3>
   297 		<h3><?php esc_html_e( 'Network Details' ); ?></h3>
   292 		<table class="form-table" role="presentation">
   298 		<table class="form-table" role="presentation">
   293 		<?php if ( 'localhost' == $hostname ) : ?>
   299 		<?php if ( 'localhost' === $hostname ) : ?>
   294 			<tr>
   300 			<tr>
   295 				<th scope="row"><?php esc_html_e( 'Sub-directory Installation' ); ?></th>
   301 				<th scope="row"><?php esc_html_e( 'Sub-directory Installation' ); ?></th>
   296 				<td>
   302 				<td>
   297 				<?php
   303 				<?php
   298 					printf(
   304 					printf(
   336 			<tr>
   342 			<tr>
   337 				<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
   343 				<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
   338 				<td>
   344 				<td>
   339 					<?php
   345 					<?php
   340 					printf(
   346 					printf(
   341 						/* translators: %s: host name */
   347 						/* translators: %s: Host name. */
   342 						__( 'The internet address of your network will be %s.' ),
   348 						__( 'The internet address of your network will be %s.' ),
   343 						'<code>' . $hostname . '</code>'
   349 						'<code>' . $hostname . '</code>'
   344 					);
   350 					);
   345 					?>
   351 					?>
   346 				</td>
   352 				</td>
   373 /**
   379 /**
   374  * Prints step 2 for Network installation process.
   380  * Prints step 2 for Network installation process.
   375  *
   381  *
   376  * @since 3.0.0
   382  * @since 3.0.0
   377  *
   383  *
   378  * @global wpdb $wpdb WordPress database abstraction object.
   384  * @global wpdb $wpdb     WordPress database abstraction object.
       
   385  * @global bool $is_nginx Whether the server software is Nginx or something else.
   379  *
   386  *
   380  * @param WP_Error $errors
   387  * @param WP_Error $errors
   381  */
   388  */
   382 function network_step2( $errors = false ) {
   389 function network_step2( $errors = false ) {
   383 	global $wpdb;
   390 	global $wpdb, $is_nginx;
   384 
   391 
   385 	$hostname          = get_clean_basedomain();
   392 	$hostname          = get_clean_basedomain();
   386 	$slashed_home      = trailingslashit( get_option( 'home' ) );
   393 	$slashed_home      = trailingslashit( get_option( 'home' ) );
   387 	$base              = parse_url( $slashed_home, PHP_URL_PATH );
   394 	$base              = parse_url( $slashed_home, PHP_URL_PATH );
   388 	$document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
   395 	$document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
   429 
   436 
   430 	if ( $_POST || ! is_multisite() ) {
   437 	if ( $_POST || ! is_multisite() ) {
   431 		?>
   438 		?>
   432 		<h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
   439 		<h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
   433 		<p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
   440 		<p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
   434 		<div class="updated inline"><p>
   441 		<div class="notice notice-warning inline"><p>
   435 		<?php
   442 		<?php
   436 		if ( file_exists( $home_path . '.htaccess' ) ) {
   443 		if ( file_exists( $home_path . '.htaccess' ) ) {
   437 			echo '<strong>' . __( 'Caution:' ) . '</strong> ';
   444 			echo '<strong>' . __( 'Caution:' ) . '</strong> ';
   438 			printf(
   445 			printf(
   439 				/* translators: 1: wp-config.php, 2: .htaccess */
   446 				/* translators: 1: wp-config.php, 2: .htaccess */
   460 		?>
   467 		?>
   461 		</p></div>
   468 		</p></div>
   462 		<?php
   469 		<?php
   463 	}
   470 	}
   464 	?>
   471 	?>
   465 		<ol>
   472 	<ol>
   466 			<li><p>
   473 		<li><p>
   467 			<?php
   474 		<?php
   468 			printf(
   475 		printf(
   469 				/* translators: 1: wp-config.php, 2: location of wp-config file, 3: translated version of "That's all, stop editing! Happy publishing." */
   476 			/* translators: 1: wp-config.php, 2: Location of wp-config file, 3: Translated version of "That's all, stop editing! Happy publishing." */
   470 				__( 'Add the following to your %1$s file in %2$s <strong>above</strong> the line reading %3$s:' ),
   477 			__( 'Add the following to your %1$s file in %2$s <strong>above</strong> the line reading %3$s:' ),
   471 				'<code>wp-config.php</code>',
   478 			'<code>wp-config.php</code>',
   472 				'<code>' . $location_of_wp_config . '</code>',
   479 			'<code>' . $location_of_wp_config . '</code>',
   473 				/*
   480 			/*
   474 				 * translators: This string should only be translated if wp-config-sample.php is localized.
   481 			 * translators: This string should only be translated if wp-config-sample.php is localized.
   475 				 * You can check the localized release package or
   482 			 * You can check the localized release package or
   476 				 * https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php
   483 			 * https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php
   477 				 */
   484 			 */
   478 				'<code>/* ' . __( 'That&#8217;s all, stop editing! Happy publishing.' ) . ' */</code>'
   485 			'<code>/* ' . __( 'That&#8217;s all, stop editing! Happy publishing.' ) . ' */</code>'
   479 			);
   486 		);
   480 			?>
   487 		?>
   481 			</p>
   488 		</p>
   482 				<textarea class="code" readonly="readonly" cols="100" rows="7">
   489 		<textarea class="code" readonly="readonly" cols="100" rows="7">
   483 define('MULTISITE', true);
   490 define('MULTISITE', true);
   484 define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>);
   491 define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>);
   485 define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>');
   492 define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>');
   486 define('PATH_CURRENT_SITE', '<?php echo $base; ?>');
   493 define('PATH_CURRENT_SITE', '<?php echo $base; ?>');
   487 define('SITE_ID_CURRENT_SITE', 1);
   494 define('SITE_ID_CURRENT_SITE', 1);
   488 define('BLOG_ID_CURRENT_SITE', 1);
   495 define('BLOG_ID_CURRENT_SITE', 1);
   489 </textarea>
   496 </textarea>
   490 	<?php
   497 		<?php
   491 	$keys_salts = array(
   498 		$keys_salts = array(
   492 		'AUTH_KEY'         => '',
   499 			'AUTH_KEY'         => '',
   493 		'SECURE_AUTH_KEY'  => '',
   500 			'SECURE_AUTH_KEY'  => '',
   494 		'LOGGED_IN_KEY'    => '',
   501 			'LOGGED_IN_KEY'    => '',
   495 		'NONCE_KEY'        => '',
   502 			'NONCE_KEY'        => '',
   496 		'AUTH_SALT'        => '',
   503 			'AUTH_SALT'        => '',
   497 		'SECURE_AUTH_SALT' => '',
   504 			'SECURE_AUTH_SALT' => '',
   498 		'LOGGED_IN_SALT'   => '',
   505 			'LOGGED_IN_SALT'   => '',
   499 		'NONCE_SALT'       => '',
   506 			'NONCE_SALT'       => '',
   500 	);
   507 		);
   501 	foreach ( $keys_salts as $c => $v ) {
   508 		foreach ( $keys_salts as $c => $v ) {
   502 		if ( defined( $c ) ) {
   509 			if ( defined( $c ) ) {
   503 			unset( $keys_salts[ $c ] );
   510 				unset( $keys_salts[ $c ] );
   504 		}
       
   505 	}
       
   506 
       
   507 	if ( ! empty( $keys_salts ) ) {
       
   508 		$keys_salts_str = '';
       
   509 		$from_api       = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
       
   510 		if ( is_wp_error( $from_api ) ) {
       
   511 			foreach ( $keys_salts as $c => $v ) {
       
   512 				$keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
       
   513 			}
   511 			}
   514 		} else {
   512 		}
   515 			$from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) );
   513 
   516 			foreach ( $keys_salts as $c => $v ) {
   514 		if ( ! empty( $keys_salts ) ) {
   517 				$keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
   515 			$keys_salts_str = '';
       
   516 			$from_api       = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
       
   517 			if ( is_wp_error( $from_api ) ) {
       
   518 				foreach ( $keys_salts as $c => $v ) {
       
   519 					$keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
       
   520 				}
       
   521 			} else {
       
   522 				$from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) );
       
   523 				foreach ( $keys_salts as $c => $v ) {
       
   524 					$keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
       
   525 				}
   518 			}
   526 			}
   519 		}
   527 			$num_keys_salts = count( $keys_salts );
   520 		$num_keys_salts = count( $keys_salts );
   528 			?>
   521 		?>
   529 		<p>
   522 <p>
   530 			<?php
   523 		<?php
   531 			if ( 1 === $num_keys_salts ) {
   524 		if ( 1 == $num_keys_salts ) {
   532 				printf(
   525 			printf(
   533 					/* translators: %s: wp-config.php */
   526 				/* translators: %s: wp-config.php */
   534 					__( 'This unique authentication key is also missing from your %s file.' ),
   527 				__( 'This unique authentication key is also missing from your %s file.' ),
   535 					'<code>wp-config.php</code>'
   528 				'<code>wp-config.php</code>'
   536 				);
   529 			);
   537 			} else {
   530 		} else {
   538 				printf(
   531 			printf(
   539 					/* translators: %s: wp-config.php */
   532 				/* translators: %s: wp-config.php */
   540 					__( 'These unique authentication keys are also missing from your %s file.' ),
   533 				__( 'These unique authentication keys are also missing from your %s file.' ),
   541 					'<code>wp-config.php</code>'
   534 				'<code>wp-config.php</code>'
   542 				);
   535 			);
   543 			}
   536 		}
   544 			?>
   537 		?>
   545 			<?php _e( 'To make your installation more secure, you should also add:' ); ?>
   538 		<?php _e( 'To make your installation more secure, you should also add:' ); ?>
   546 		</p>
   539 	</p>
   547 		<textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>"><?php echo esc_textarea( $keys_salts_str ); ?></textarea>
   540 	<textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>"><?php echo esc_textarea( $keys_salts_str ); ?></textarea>
   548 			<?php
   541 		<?php
   549 		}
   542 	}
   550 		?>
   543 	?>
   551 		</li>
   544 </li>
       
   545 	<?php
   552 	<?php
   546 	if ( iis7_supports_permalinks() ) :
   553 	if ( iis7_supports_permalinks() ) :
   547 		// IIS doesn't support RewriteBase, all your RewriteBase are belong to us
   554 		// IIS doesn't support RewriteBase, all your RewriteBase are belong to us.
   548 		$iis_subdir_match       = ltrim( $base, '/' ) . $subdir_match;
   555 		$iis_subdir_match       = ltrim( $base, '/' ) . $subdir_match;
   549 		$iis_rewrite_base       = ltrim( $base, '/' ) . $rewrite_base;
   556 		$iis_rewrite_base       = ltrim( $base, '/' ) . $rewrite_base;
   550 		$iis_subdir_replacement = $subdomain_install ? '' : '{R:1}';
   557 		$iis_subdir_replacement = $subdomain_install ? '' : '{R:1}';
   551 
   558 
   552 		$web_config_file = '<?xml version="1.0" encoding="UTF-8"?>
   559 		$web_config_file = '<?xml version="1.0" encoding="UTF-8"?>
   596 </configuration>
   603 </configuration>
   597 ';
   604 ';
   598 
   605 
   599 			echo '<li><p>';
   606 			echo '<li><p>';
   600 			printf(
   607 			printf(
   601 				/* translators: 1: a filename like .htaccess, 2: a file path */
   608 				/* translators: 1: File name (.htaccess or web.config), 2: File path. */
   602 				__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
   609 				__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
   603 				'<code>web.config</code>',
   610 				'<code>web.config</code>',
   604 				'<code>' . $home_path . '</code>'
   611 				'<code>' . $home_path . '</code>'
   605 			);
   612 			);
   606 		echo '</p>';
   613 		echo '</p>';
   607 		if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' ) {
   614 		if ( ! $subdomain_install && WP_CONTENT_DIR !== ABSPATH . 'wp-content' ) {
   608 			echo '<p><strong>' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
   615 			echo '<p><strong>' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
   609 		}
   616 		}
   610 		?>
   617 		?>
   611 	<textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea( $web_config_file ); ?>
   618 		<textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea( $web_config_file ); ?></textarea>
   612 		</textarea></li>
   619 		</li>
   613 		</ol>
   620 	</ol>
   614 
   621 
   615 		<?php
   622 		<?php
   616 	else : // end iis7_supports_permalinks(). construct an htaccess file instead:
   623 	elseif ( $is_nginx ) : // End iis7_supports_permalinks(). Link to Nginx documentation instead:
       
   624 
       
   625 		echo '<li><p>';
       
   626 		printf(
       
   627 			/* translators: %s: Documentation URL. */
       
   628 			__( 'It seems your network is running with Nginx web server. <a href="%s">Learn more about further configuration</a>.' ),
       
   629 			__( 'https://wordpress.org/support/article/nginx/' )
       
   630 		);
       
   631 		echo '</p></li>';
       
   632 
       
   633 	else : // End $is_nginx. Construct an .htaccess file instead:
   617 
   634 
   618 		$ms_files_rewriting = '';
   635 		$ms_files_rewriting = '';
   619 		if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
   636 		if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
   620 			$ms_files_rewriting  = "\n# uploaded files\nRewriteRule ^";
   637 			$ms_files_rewriting  = "\n# uploaded files\nRewriteRule ^";
   621 			$ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n";
   638 			$ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n";
   638 
   655 
   639 EOF;
   656 EOF;
   640 
   657 
   641 		echo '<li><p>';
   658 		echo '<li><p>';
   642 		printf(
   659 		printf(
   643 			/* translators: 1: a filename like .htaccess, 2: a file path */
   660 			/* translators: 1: File name (.htaccess or web.config), 2: File path. */
   644 			__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
   661 			__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
   645 			'<code>.htaccess</code>',
   662 			'<code>.htaccess</code>',
   646 			'<code>' . $home_path . '</code>'
   663 			'<code>' . $home_path . '</code>'
   647 		);
   664 		);
   648 		echo '</p>';
   665 		echo '</p>';
   649 		if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' ) {
   666 		if ( ! $subdomain_install && WP_CONTENT_DIR !== ABSPATH . 'wp-content' ) {
   650 			echo '<p><strong>' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
   667 			echo '<p><strong>' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
   651 		}
   668 		}
   652 		?>
   669 		?>
   653 		<textarea class="code" readonly="readonly" cols="100" rows="<?php echo substr_count( $htaccess_file, "\n" ) + 1; ?>">
   670 		<textarea class="code" readonly="readonly" cols="100" rows="<?php echo substr_count( $htaccess_file, "\n" ) + 1; ?>"><?php echo esc_textarea( $htaccess_file ); ?></textarea>
   654 		<?php echo esc_textarea( $htaccess_file ); ?></textarea></li>
   671 		</li>
   655 		</ol>
   672 	</ol>
   656 
   673 
   657 		<?php
   674 		<?php
   658 	endif; // end IIS/Apache code branches.
   675 	endif; // End IIS/Nginx/Apache code branches.
   659 
   676 
   660 	if ( ! is_multisite() ) {
   677 	if ( ! is_multisite() ) {
   661 		?>
   678 		?>
   662 		<p><?php _e( 'Once you complete these steps, your network is enabled and configured. You will have to log in again.' ); ?> <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log In' ); ?></a></p>
   679 		<p><?php _e( 'Once you complete these steps, your network is enabled and configured. You will have to log in again.' ); ?> <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log In' ); ?></a></p>
   663 		<?php
   680 		<?php