wp/wp-admin/includes/network.php
changeset 7 cf61fcea0001
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
       
     1 <?php
       
     2 /**
       
     3  * WordPress Network Administration API.
       
     4  *
       
     5  * @package WordPress
       
     6  * @subpackage Administration
       
     7  * @since 4.4.0
       
     8  */
       
     9 
       
    10 /**
       
    11  * Check for an existing network.
       
    12  *
       
    13  * @since 3.0.0
       
    14  *
       
    15  * @global wpdb $wpdb WordPress database abstraction object.
       
    16  *
       
    17  * @return Whether a network exists.
       
    18  */
       
    19 function network_domain_check() {
       
    20 	global $wpdb;
       
    21 
       
    22 	$sql = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->site ) );
       
    23 	if ( $wpdb->get_var( $sql ) ) {
       
    24 		return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" );
       
    25 	}
       
    26 	return false;
       
    27 }
       
    28 
       
    29 /**
       
    30  * Allow subdomain installation
       
    31  *
       
    32  * @since 3.0.0
       
    33  * @return bool Whether subdomain installation is allowed
       
    34  */
       
    35 function allow_subdomain_install() {
       
    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 ) )
       
    38 		return false;
       
    39 
       
    40 	return true;
       
    41 }
       
    42 
       
    43 /**
       
    44  * Allow subdirectory installation.
       
    45  *
       
    46  * @since 3.0.0
       
    47  *
       
    48  * @global wpdb $wpdb WordPress database abstraction object.
       
    49  *
       
    50  * @return bool Whether subdirectory installation is allowed
       
    51  */
       
    52 function allow_subdirectory_install() {
       
    53 	global $wpdb;
       
    54         /**
       
    55          * Filters whether to enable the subdirectory installation feature in Multisite.
       
    56          *
       
    57          * @since 3.0.0
       
    58          *
       
    59          * @param bool $allow Whether to enable the subdirectory installation feature in Multisite. Default is false.
       
    60          */
       
    61 	if ( apply_filters( 'allow_subdirectory_install', false ) )
       
    62 		return true;
       
    63 
       
    64 	if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL )
       
    65 		return true;
       
    66 
       
    67 	$post = $wpdb->get_row( "SELECT ID FROM $wpdb->posts WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND post_status = 'publish'" );
       
    68 	if ( empty( $post ) )
       
    69 		return true;
       
    70 
       
    71 	return false;
       
    72 }
       
    73 
       
    74 /**
       
    75  * Get base domain of network.
       
    76  *
       
    77  * @since 3.0.0
       
    78  * @return string Base domain.
       
    79  */
       
    80 function get_clean_basedomain() {
       
    81 	if ( $existing_domain = network_domain_check() )
       
    82 		return $existing_domain;
       
    83 	$domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
       
    84 	if ( $slash = strpos( $domain, '/' ) )
       
    85 		$domain = substr( $domain, 0, $slash );
       
    86 	return $domain;
       
    87 }
       
    88 
       
    89 /**
       
    90  * Prints step 1 for Network installation process.
       
    91  *
       
    92  * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. Navigating to Tools > Network
       
    93  * 	should not be a sudden "Welcome to a new install process! Fill this out and click here." See also contextual help todo.
       
    94  *
       
    95  * @since 3.0.0
       
    96  *
       
    97  * @global bool $is_apache
       
    98  *
       
    99  * @param WP_Error $errors
       
   100  */
       
   101 function network_step1( $errors = false ) {
       
   102 	global $is_apache;
       
   103 
       
   104 	if ( defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
       
   105 		echo '<div class="error"><p><strong>' . __( 'ERROR:' ) . '</strong> ' . sprintf(
       
   106 			/* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */
       
   107 			__( 'The constant %s cannot be defined when creating a network.' ),
       
   108 			'<code>DO_NOT_UPGRADE_GLOBAL_TABLES</code>'
       
   109 		) . '</p></div>';
       
   110 		echo '</div>';
       
   111 		include( ABSPATH . 'wp-admin/admin-footer.php' );
       
   112 		die();
       
   113 	}
       
   114 
       
   115 	$active_plugins = get_option( 'active_plugins' );
       
   116 	if ( ! empty( $active_plugins ) ) {
       
   117 		echo '<div class="updated"><p><strong>' . __( 'Warning:' ) . '</strong> ' . sprintf(
       
   118 			/* translators: %s: Plugins screen URL */
       
   119 			__( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ),
       
   120 			admin_url( 'plugins.php?plugin_status=active' )
       
   121 		) . '</p></div>';
       
   122 		echo '<p>' . __( 'Once the network is created, you may reactivate your plugins.' ) . '</p>';
       
   123 		echo '</div>';
       
   124 		include( ABSPATH . 'wp-admin/admin-footer.php' );
       
   125 		die();
       
   126 	}
       
   127 
       
   128 	$hostname = get_clean_basedomain();
       
   129 	$has_ports = strstr( $hostname, ':' );
       
   130 	if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
       
   131 		echo '<div class="error"><p><strong>' . __( 'ERROR:' ) . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
       
   132 		echo '<p>' . sprintf(
       
   133 			/* translators: %s: port number */
       
   134 			__( 'You cannot use port numbers such as %s.' ),
       
   135 			'<code>' . $has_ports . '</code>'
       
   136 		) . '</p>';
       
   137 		echo '<a href="' . esc_url( admin_url() ) . '">' . __( 'Return to Dashboard' ) . '</a>';
       
   138 		echo '</div>';
       
   139 		include( ABSPATH . 'wp-admin/admin-footer.php' );
       
   140 		die();
       
   141 	}
       
   142 
       
   143 	echo '<form method="post">';
       
   144 
       
   145 	wp_nonce_field( 'install-network-1' );
       
   146 
       
   147 	$error_codes = array();
       
   148 	if ( is_wp_error( $errors ) ) {
       
   149 		echo '<div class="error"><p><strong>' . __( 'ERROR: The network could not be created.' ) . '</strong></p>';
       
   150 		foreach ( $errors->get_error_messages() as $error )
       
   151 			echo "<p>$error</p>";
       
   152 		echo '</div>';
       
   153 		$error_codes = $errors->get_error_codes();
       
   154 	}
       
   155 
       
   156 	if ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes ) ) {
       
   157 		$site_name = $_POST['sitename'];
       
   158 	} else {
       
   159 		/* translators: %s: Default network name */
       
   160 		$site_name = sprintf( __( '%s Sites' ), get_option( 'blogname' ) );
       
   161 	}
       
   162 
       
   163 	if ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes ) ) {
       
   164 		$admin_email = $_POST['email'];
       
   165 	} else {
       
   166 		$admin_email = get_option( 'admin_email' );
       
   167 	}
       
   168 	?>
       
   169 	<p><?php _e( 'Welcome to the Network installation process!' ); ?></p>
       
   170 	<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>
       
   171 	<?php
       
   172 
       
   173 	if ( isset( $_POST['subdomain_install'] ) ) {
       
   174 		$subdomain_install = (bool) $_POST['subdomain_install'];
       
   175 	} elseif ( apache_mod_loaded('mod_rewrite') ) { // assume nothing
       
   176 		$subdomain_install = true;
       
   177 	} elseif ( !allow_subdirectory_install() ) {
       
   178 		$subdomain_install = true;
       
   179 	} else {
       
   180 		$subdomain_install = false;
       
   181 		if ( $got_mod_rewrite = got_mod_rewrite() ) { // dangerous assumptions
       
   182 			echo '<div class="updated inline"><p><strong>' . __( 'Note:' ) . '</strong> ';
       
   183 			/* translators: %s: mod_rewrite */
       
   184 			printf( __( 'Please make sure the Apache %s module is installed as it will be used at the end of this installation.' ),
       
   185 				'<code>mod_rewrite</code>'
       
   186 			);
       
   187 			echo '</p>';
       
   188 		} elseif ( $is_apache ) {
       
   189 			echo '<div class="error inline"><p><strong>' . __( 'Warning:' ) . '</strong> ';
       
   190 			/* translators: %s: mod_rewrite */
       
   191 			printf( __( 'It looks like the Apache %s module is not installed.' ),
       
   192 				'<code>mod_rewrite</code>'
       
   193 			);
       
   194 			echo '</p>';
       
   195 		}
       
   196 
       
   197 		if ( $got_mod_rewrite || $is_apache ) { // Protect against mod_rewrite mimicry (but ! Apache)
       
   198 			echo '<p>';
       
   199 			/* translators: 1: mod_rewrite, 2: mod_rewrite documentation URL, 3: Google search for mod_rewrite */
       
   200 			printf( __( '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.' ),
       
   201 				'<code>mod_rewrite</code>',
       
   202 				'https://httpd.apache.org/docs/mod/mod_rewrite.html',
       
   203 				'https://www.google.com/search?q=apache+mod_rewrite'
       
   204 			);
       
   205 			echo '</p></div>';
       
   206 		}
       
   207 	}
       
   208 
       
   209 	if ( allow_subdomain_install() && allow_subdirectory_install() ) : ?>
       
   210 		<h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3>
       
   211 		<p><?php _e( 'Please choose whether you would like sites in your WordPress network to use sub-domains or sub-directories.' ); ?>
       
   212 			<strong><?php _e( 'You cannot change this later.' ); ?></strong></p>
       
   213 		<p><?php _e( 'You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality.' ); ?></p>
       
   214 		<?php // @todo: Link to an MS readme? ?>
       
   215 		<table class="form-table">
       
   216 			<tr>
       
   217 				<th><label><input type="radio" name="subdomain_install" value="1"<?php checked( $subdomain_install ); ?> /> <?php _e( 'Sub-domains' ); ?></label></th>
       
   218 				<td><?php printf(
       
   219 					/* translators: 1: hostname */
       
   220 					_x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ),
       
   221 					$hostname
       
   222 				); ?></td>
       
   223 			</tr>
       
   224 			<tr>
       
   225 				<th><label><input type="radio" name="subdomain_install" value="0"<?php checked( ! $subdomain_install ); ?> /> <?php _e( 'Sub-directories' ); ?></label></th>
       
   226 				<td><?php printf(
       
   227 					/* translators: 1: hostname */
       
   228 					_x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ),
       
   229 					$hostname
       
   230 				); ?></td>
       
   231 			</tr>
       
   232 		</table>
       
   233 
       
   234 <?php
       
   235 	endif;
       
   236 
       
   237 		if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) )
       
   238 			echo '<div class="error inline"><p><strong>' . __( 'Warning:' ) . '</strong> ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
       
   239 
       
   240 		$is_www = ( 0 === strpos( $hostname, 'www.' ) );
       
   241 		if ( $is_www ) :
       
   242 		?>
       
   243 		<h3><?php esc_html_e( 'Server Address' ); ?></h3>
       
   244 		<p><?php printf(
       
   245 			/* translators: 1: site url 2: host name 3. www */
       
   246 			__( '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.' ),
       
   247 			'<code>' . substr( $hostname, 4 ) . '</code>',
       
   248 			'<code>' . $hostname . '</code>',
       
   249 			'<code>www</code>'
       
   250 		); ?></p>
       
   251 		<table class="form-table">
       
   252 			<tr>
       
   253 				<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
       
   254 				<td>
       
   255 					<?php printf(
       
   256 						/* translators: %s: host name */
       
   257 						__( 'The internet address of your network will be %s.' ),
       
   258 						'<code>' . $hostname . '</code>'
       
   259 					); ?>
       
   260 				</td>
       
   261 			</tr>
       
   262 		</table>
       
   263 		<?php endif; ?>
       
   264 
       
   265 		<h3><?php esc_html_e( 'Network Details' ); ?></h3>
       
   266 		<table class="form-table">
       
   267 		<?php if ( 'localhost' == $hostname ) : ?>
       
   268 			<tr>
       
   269 				<th scope="row"><?php esc_html_e( 'Sub-directory Installation' ); ?></th>
       
   270 				<td><?php
       
   271 					printf(
       
   272 						/* translators: 1: localhost 2: localhost.localdomain */
       
   273 						__( 'Because you are using %1$s, the sites in your WordPress network must use sub-directories. Consider using %2$s if you wish to use sub-domains.' ),
       
   274 						'<code>localhost</code>',
       
   275 						'<code>localhost.localdomain</code>'
       
   276 					);
       
   277 					// Uh oh:
       
   278 					if ( !allow_subdirectory_install() )
       
   279 						echo ' <strong>' . __( 'Warning:' ) . ' ' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
       
   280 				?></td>
       
   281 			</tr>
       
   282 		<?php elseif ( !allow_subdomain_install() ) : ?>
       
   283 			<tr>
       
   284 				<th scope="row"><?php esc_html_e( 'Sub-directory Installation' ); ?></th>
       
   285 				<td><?php
       
   286 					_e( 'Because your installation is in a directory, the sites in your WordPress network must use sub-directories.' );
       
   287 					// Uh oh:
       
   288 					if ( !allow_subdirectory_install() )
       
   289 						echo ' <strong>' . __( 'Warning:' ) . ' ' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
       
   290 				?></td>
       
   291 			</tr>
       
   292 		<?php elseif ( !allow_subdirectory_install() ) : ?>
       
   293 			<tr>
       
   294 				<th scope="row"><?php esc_html_e( 'Sub-domain Installation' ); ?></th>
       
   295 				<td><?php _e( 'Because your installation is not new, the sites in your WordPress network must use sub-domains.' );
       
   296 					echo ' <strong>' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
       
   297 				?></td>
       
   298 			</tr>
       
   299 		<?php endif; ?>
       
   300 		<?php if ( ! $is_www ) : ?>
       
   301 			<tr>
       
   302 				<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
       
   303 				<td>
       
   304 					<?php printf(
       
   305 						/* translators: %s: host name */
       
   306 						__( 'The internet address of your network will be %s.' ),
       
   307 						'<code>' . $hostname . '</code>'
       
   308 					); ?>
       
   309 				</td>
       
   310 			</tr>
       
   311 		<?php endif; ?>
       
   312 			<tr>
       
   313 				<th scope='row'><?php esc_html_e( 'Network Title' ); ?></th>
       
   314 				<td>
       
   315 					<input name='sitename' type='text' size='45' value='<?php echo esc_attr( $site_name ); ?>' />
       
   316 					<p class="description">
       
   317 						<?php _e( 'What would you like to call your network?' ); ?>
       
   318 					</p>
       
   319 				</td>
       
   320 			</tr>
       
   321 			<tr>
       
   322 				<th scope='row'><?php esc_html_e( 'Network Admin Email' ); ?></th>
       
   323 				<td>
       
   324 					<input name='email' type='text' size='45' value='<?php echo esc_attr( $admin_email ); ?>' />
       
   325 					<p class="description">
       
   326 						<?php _e( 'Your email address.' ); ?>
       
   327 					</p>
       
   328 				</td>
       
   329 			</tr>
       
   330 		</table>
       
   331 		<?php submit_button( __( 'Install' ), 'primary', 'submit' ); ?>
       
   332 	</form>
       
   333 	<?php
       
   334 }
       
   335 
       
   336 /**
       
   337  * Prints step 2 for Network installation process.
       
   338  *
       
   339  * @since 3.0.0
       
   340  *
       
   341  * @global wpdb $wpdb WordPress database abstraction object.
       
   342  *
       
   343  * @param WP_Error $errors
       
   344  */
       
   345 function network_step2( $errors = false ) {
       
   346 	global $wpdb;
       
   347 
       
   348 	$hostname          = get_clean_basedomain();
       
   349 	$slashed_home      = trailingslashit( get_option( 'home' ) );
       
   350 	$base              = parse_url( $slashed_home, PHP_URL_PATH );
       
   351 	$document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
       
   352 	$abspath_fix       = str_replace( '\\', '/', ABSPATH );
       
   353 	$home_path         = 0 === strpos( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path();
       
   354 	$wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix );
       
   355 	$rewrite_base      = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : '';
       
   356 
       
   357 
       
   358 	$location_of_wp_config = $abspath_fix;
       
   359 	if ( ! file_exists( ABSPATH . 'wp-config.php' ) && file_exists( dirname( ABSPATH ) . '/wp-config.php' ) ) {
       
   360 		$location_of_wp_config = dirname( $abspath_fix );
       
   361 	}
       
   362 	$location_of_wp_config = trailingslashit( $location_of_wp_config );
       
   363 
       
   364 	// Wildcard DNS message.
       
   365 	if ( is_wp_error( $errors ) )
       
   366 		echo '<div class="error">' . $errors->get_error_message() . '</div>';
       
   367 
       
   368 	if ( $_POST ) {
       
   369 		if ( allow_subdomain_install() )
       
   370 			$subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
       
   371 		else
       
   372 			$subdomain_install = false;
       
   373 	} else {
       
   374 		if ( is_multisite() ) {
       
   375 			$subdomain_install = is_subdomain_install();
       
   376 ?>
       
   377 	<p><?php _e( 'The original configuration steps are shown here for reference.' ); ?></p>
       
   378 <?php
       
   379 		} else {
       
   380 			$subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
       
   381 ?>
       
   382 	<div class="error"><p><strong><?php _e( 'Warning:' ); ?></strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div>
       
   383 	<p><?php _e( 'Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.' ); ?></p>
       
   384 <?php
       
   385 		}
       
   386 	}
       
   387 
       
   388 	$subdir_match          = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?';
       
   389 	$subdir_replacement_01 = $subdomain_install ? '' : '$1';
       
   390 	$subdir_replacement_12 = $subdomain_install ? '$1' : '$2';
       
   391 
       
   392 	if ( $_POST || ! is_multisite() ) {
       
   393 ?>
       
   394 		<h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
       
   395 		<p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
       
   396 		<div class="updated inline"><p><?php
       
   397 			if ( file_exists( $home_path . '.htaccess' ) ) {
       
   398 				echo '<strong>' . __( 'Caution:' ) . '</strong> ';
       
   399 				printf(
       
   400 					/* translators: 1: wp-config.php 2: .htaccess */
       
   401 					__( 'We recommend you back up your existing %1$s and %2$s files.' ),
       
   402 					'<code>wp-config.php</code>',
       
   403 					'<code>.htaccess</code>'
       
   404 				);
       
   405 			} elseif ( file_exists( $home_path . 'web.config' ) ) {
       
   406 				echo '<strong>' . __( 'Caution:' ) . '</strong> ';
       
   407 				printf(
       
   408 					/* translators: 1: wp-config.php 2: web.config */
       
   409 					__( 'We recommend you back up your existing %1$s and %2$s files.' ),
       
   410 					'<code>wp-config.php</code>',
       
   411 					'<code>web.config</code>'
       
   412 				);
       
   413 			} else {
       
   414 				echo '<strong>' . __( 'Caution:' ) . '</strong> ';
       
   415 				printf(
       
   416 					/* translators: 1: wp-config.php */
       
   417 					__( 'We recommend you back up your existing %s file.' ),
       
   418 					'<code>wp-config.php</code>'
       
   419 				);
       
   420 			}
       
   421 		?></p></div>
       
   422 <?php
       
   423 	}
       
   424 ?>
       
   425 		<ol>
       
   426 			<li><p><?php printf(
       
   427 				/* translators: 1: wp-config.php 2: location of wp-config file, 3: translated version of "That's all, stop editing! Happy blogging." */
       
   428 				__( 'Add the following to your %1$s file in %2$s <strong>above</strong> the line reading %3$s:' ),
       
   429 				'<code>wp-config.php</code>',
       
   430 				'<code>' . $location_of_wp_config . '</code>',
       
   431 				/*
       
   432 				 * translators: This string should only be translated if wp-config-sample.php is localized.
       
   433 				 * You can check the localized release package or
       
   434 				 * https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php
       
   435 				 */
       
   436 				'<code>/* ' . __( 'That&#8217;s all, stop editing! Happy blogging.' ) . ' */</code>'
       
   437 			); ?></p>
       
   438 				<textarea class="code" readonly="readonly" cols="100" rows="7">
       
   439 define('MULTISITE', true);
       
   440 define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>);
       
   441 define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>');
       
   442 define('PATH_CURRENT_SITE', '<?php echo $base; ?>');
       
   443 define('SITE_ID_CURRENT_SITE', 1);
       
   444 define('BLOG_ID_CURRENT_SITE', 1);
       
   445 </textarea>
       
   446 <?php
       
   447 	$keys_salts = array( 'AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' );
       
   448 	foreach ( $keys_salts as $c => $v ) {
       
   449 		if ( defined( $c ) )
       
   450 			unset( $keys_salts[ $c ] );
       
   451 	}
       
   452 
       
   453 	if ( ! empty( $keys_salts ) ) {
       
   454 		$keys_salts_str = '';
       
   455 		$from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
       
   456 		if ( is_wp_error( $from_api ) ) {
       
   457 			foreach ( $keys_salts as $c => $v ) {
       
   458 				$keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
       
   459 			}
       
   460 		} else {
       
   461 			$from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) );
       
   462 			foreach ( $keys_salts as $c => $v ) {
       
   463 				$keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
       
   464 			}
       
   465 		}
       
   466 		$num_keys_salts = count( $keys_salts );
       
   467 ?>
       
   468 	<p>
       
   469 		<?php
       
   470 			if ( 1 == $num_keys_salts ) {
       
   471 				printf(
       
   472 					/* translators: 1: wp-config.php */
       
   473 					__( 'This unique authentication key is also missing from your %s file.' ),
       
   474 					'<code>wp-config.php</code>'
       
   475 				);
       
   476 			} else {
       
   477 				printf(
       
   478 					/* translators: 1: wp-config.php */
       
   479 					__( 'These unique authentication keys are also missing from your %s file.' ),
       
   480 					'<code>wp-config.php</code>'
       
   481 				);
       
   482 			}
       
   483 		?>
       
   484 		<?php _e( 'To make your installation more secure, you should also add:' ); ?>
       
   485 	</p>
       
   486 	<textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>"><?php echo esc_textarea( $keys_salts_str ); ?></textarea>
       
   487 <?php
       
   488 	}
       
   489 ?>
       
   490 </li>
       
   491 <?php
       
   492 	if ( iis7_supports_permalinks() ) :
       
   493 		// IIS doesn't support RewriteBase, all your RewriteBase are belong to us
       
   494 		$iis_subdir_match = ltrim( $base, '/' ) . $subdir_match;
       
   495 		$iis_rewrite_base = ltrim( $base, '/' ) . $rewrite_base;
       
   496 		$iis_subdir_replacement = $subdomain_install ? '' : '{R:1}';
       
   497 
       
   498 		$web_config_file = '<?xml version="1.0" encoding="UTF-8"?>
       
   499 <configuration>
       
   500     <system.webServer>
       
   501         <rewrite>
       
   502             <rules>
       
   503                 <rule name="WordPress Rule 1" stopProcessing="true">
       
   504                     <match url="^index\.php$" ignoreCase="false" />
       
   505                     <action type="None" />
       
   506                 </rule>';
       
   507 				if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
       
   508 					$web_config_file .= '
       
   509                 <rule name="WordPress Rule for Files" stopProcessing="true">
       
   510                     <match url="^' . $iis_subdir_match . 'files/(.+)" ignoreCase="false" />
       
   511                     <action type="Rewrite" url="' . $iis_rewrite_base . WPINC . '/ms-files.php?file={R:1}" appendQueryString="false" />
       
   512                 </rule>';
       
   513                 }
       
   514                 $web_config_file .= '
       
   515                 <rule name="WordPress Rule 2" stopProcessing="true">
       
   516                     <match url="^' . $iis_subdir_match . 'wp-admin$" ignoreCase="false" />
       
   517                     <action type="Redirect" url="' . $iis_subdir_replacement . 'wp-admin/" redirectType="Permanent" />
       
   518                 </rule>
       
   519                 <rule name="WordPress Rule 3" stopProcessing="true">
       
   520                     <match url="^" ignoreCase="false" />
       
   521                     <conditions logicalGrouping="MatchAny">
       
   522                         <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
       
   523                         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
       
   524                     </conditions>
       
   525                     <action type="None" />
       
   526                 </rule>
       
   527                 <rule name="WordPress Rule 4" stopProcessing="true">
       
   528                     <match url="^' . $iis_subdir_match . '(wp-(content|admin|includes).*)" ignoreCase="false" />
       
   529                     <action type="Rewrite" url="' . $iis_rewrite_base . '{R:1}" />
       
   530                 </rule>
       
   531                 <rule name="WordPress Rule 5" stopProcessing="true">
       
   532                     <match url="^' . $iis_subdir_match . '([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
       
   533                     <action type="Rewrite" url="' . $iis_rewrite_base . '{R:2}" />
       
   534                 </rule>
       
   535                 <rule name="WordPress Rule 6" stopProcessing="true">
       
   536                     <match url="." ignoreCase="false" />
       
   537                     <action type="Rewrite" url="index.php" />
       
   538                 </rule>
       
   539             </rules>
       
   540         </rewrite>
       
   541     </system.webServer>
       
   542 </configuration>
       
   543 ';
       
   544 
       
   545 		echo '<li><p>';
       
   546 		printf(
       
   547 			/* translators: 1: a filename like .htaccess. 2: a file path. */
       
   548 			__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
       
   549 			'<code>web.config</code>',
       
   550 			'<code>' . $home_path . '</code>'
       
   551 		);
       
   552 		echo '</p>';
       
   553 		if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
       
   554 			echo '<p><strong>' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
       
   555 		?>
       
   556 		<textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea( $web_config_file ); ?>
       
   557 		</textarea></li>
       
   558 		</ol>
       
   559 
       
   560 	<?php else : // end iis7_supports_permalinks(). construct an htaccess file instead:
       
   561 
       
   562 		$ms_files_rewriting = '';
       
   563 		if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
       
   564 			$ms_files_rewriting = "\n# uploaded files\nRewriteRule ^";
       
   565 			$ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n";
       
   566 		}
       
   567 
       
   568 		$htaccess_file = <<<EOF
       
   569 RewriteEngine On
       
   570 RewriteBase {$base}
       
   571 RewriteRule ^index\.php$ - [L]
       
   572 {$ms_files_rewriting}
       
   573 # add a trailing slash to /wp-admin
       
   574 RewriteRule ^{$subdir_match}wp-admin$ {$subdir_replacement_01}wp-admin/ [R=301,L]
       
   575 
       
   576 RewriteCond %{REQUEST_FILENAME} -f [OR]
       
   577 RewriteCond %{REQUEST_FILENAME} -d
       
   578 RewriteRule ^ - [L]
       
   579 RewriteRule ^{$subdir_match}(wp-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L]
       
   580 RewriteRule ^{$subdir_match}(.*\.php)$ {$rewrite_base}$subdir_replacement_12 [L]
       
   581 RewriteRule . index.php [L]
       
   582 
       
   583 EOF;
       
   584 
       
   585 		echo '<li><p>';
       
   586 		printf(
       
   587 			/* translators: 1: a filename like .htaccess. 2: a file path. */
       
   588 			__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
       
   589 			'<code>.htaccess</code>',
       
   590 			'<code>' . $home_path . '</code>'
       
   591 		);
       
   592 		echo '</p>';
       
   593 		if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
       
   594 			echo '<p><strong>' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
       
   595 		?>
       
   596 		<textarea class="code" readonly="readonly" cols="100" rows="<?php echo substr_count( $htaccess_file, "\n" ) + 1; ?>">
       
   597 <?php echo esc_textarea( $htaccess_file ); ?></textarea></li>
       
   598 		</ol>
       
   599 
       
   600 	<?php endif; // end IIS/Apache code branches.
       
   601 
       
   602 	if ( !is_multisite() ) { ?>
       
   603 		<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>
       
   604 <?php
       
   605 	}
       
   606 }