network.php ➔ network_step2()   F
last analyzed

Complexity

Conditions 36
Paths > 20000

Size

Total Lines 262
Code Lines 161

Duplication

Lines 15
Ratio 5.73 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 36
eloc 161
nc 429496.7295
nop 1
dl 15
loc 262
rs 2
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 install
31
 *
32
 * @since 3.0.0
33
 * @return bool Whether subdomain install 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 install.
45
 *
46
 * @since 3.0.0
47
 *
48
 * @global wpdb $wpdb WordPress database abstraction object.
49
 *
50
 * @return bool Whether subdirectory install is allowed
51
 */
52
function allow_subdirectory_install() {
53
	global $wpdb;
54
        /**
55
         * Filters whether to enable the subdirectory install feature in Multisite.
56
         *
57
         * @since 3.0.0
58
         *
59
         * @param bool $allow Whether to enable the subdirectory install 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> ' . __( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '</p></div>';
106
		echo '</div>';
107
		include( ABSPATH . 'wp-admin/admin-footer.php' );
108
		die();
109
	}
110
111
	$active_plugins = get_option( 'active_plugins' );
112
	if ( ! empty( $active_plugins ) ) {
113
		echo '<div class="updated"><p><strong>' . __('Warning:') . '</strong> ' . sprintf( __( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ), admin_url( 'plugins.php?plugin_status=active' ) ) . '</p></div><p>' . __( 'Once the network is created, you may reactivate your plugins.' ) . '</p>';
114
		echo '</div>';
115
		include( ABSPATH . 'wp-admin/admin-footer.php' );
116
		die();
117
	}
118
119
	$hostname = get_clean_basedomain();
120
	$has_ports = strstr( $hostname, ':' );
121
	if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
122
		echo '<div class="error"><p><strong>' . __( 'ERROR:') . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
123
		echo '<p>' . sprintf(
124
			/* translators: %s: port number */
125
			__( 'You cannot use port numbers such as %s.' ),
126
			'<code>' . $has_ports . '</code>'
127
		) . '</p>';
128
		echo '<a href="' . esc_url( admin_url() ) . '">' . __( 'Return to Dashboard' ) . '</a>';
129
		echo '</div>';
130
		include( ABSPATH . 'wp-admin/admin-footer.php' );
131
		die();
132
	}
133
134
	echo '<form method="post">';
135
136
	wp_nonce_field( 'install-network-1' );
137
138
	$error_codes = array();
139
	if ( is_wp_error( $errors ) ) {
140
		echo '<div class="error"><p><strong>' . __( 'ERROR: The network could not be created.' ) . '</strong></p>';
141
		foreach ( $errors->get_error_messages() as $error )
0 ignored issues
show
Bug introduced by
It seems like $errors is not always an object, but can also be of type false. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
142
			echo "<p>$error</p>";
143
		echo '</div>';
144
		$error_codes = $errors->get_error_codes();
145
	}
146
147
	if ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes ) ) {
148
		$site_name = $_POST['sitename'];
149
	} else {
150
		/* translators: %s: Default network name */
151
		$site_name = sprintf( __( '%s Sites' ), get_option( 'blogname' ) );
152
	}
153
154
	if ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes ) ) {
155
		$admin_email = $_POST['email'];
156
	} else {
157
		$admin_email = get_option( 'admin_email' );
158
	}
159
	?>
160
	<p><?php _e( 'Welcome to the Network installation process!' ); ?></p>
161
	<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>
162
	<?php
163
164
	if ( isset( $_POST['subdomain_install'] ) ) {
165
		$subdomain_install = (bool) $_POST['subdomain_install'];
166
	} elseif ( apache_mod_loaded('mod_rewrite') ) { // assume nothing
167
		$subdomain_install = true;
168
	} elseif ( !allow_subdirectory_install() ) {
169
		$subdomain_install = true;
170
	} else {
171
		$subdomain_install = false;
172
		if ( $got_mod_rewrite = got_mod_rewrite() ) { // dangerous assumptions
173
			echo '<div class="updated inline"><p><strong>' . __( 'Note:' ) . '</strong> ';
174
			/* translators: %s: mod_rewrite */
175
			printf( __( 'Please make sure the Apache %s module is installed as it will be used at the end of this installation.' ),
176
				'<code>mod_rewrite</code>'
177
			);
178
			echo '</p>';
179
		} elseif ( $is_apache ) {
180
			echo '<div class="error inline"><p><strong>' . __( 'Warning!' ) . '</strong> ';
181
			/* translators: %s: mod_rewrite */
182
			printf( __( 'It looks like the Apache %s module is not installed.' ),
183
				'<code>mod_rewrite</code>'
184
			);
185
			echo '</p>';
186
		}
187
188
		if ( $got_mod_rewrite || $is_apache ) { // Protect against mod_rewrite mimicry (but ! Apache)
189
			echo '<p>';
190
			/* translators: 1: mod_rewrite, 2: mod_rewrite documentation URL, 3: Google search for mod_rewrite */
191
			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.' ),
192
				'<code>mod_rewrite</code>',
193
				'https://httpd.apache.org/docs/mod/mod_rewrite.html',
194
				'https://www.google.com/search?q=apache+mod_rewrite'
195
			);
196
			echo '</p></div>';
197
		}
198
	}
199
200
	if ( allow_subdomain_install() && allow_subdirectory_install() ) : ?>
201
		<h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3>
202
		<p><?php _e( 'Please choose whether you would like sites in your WordPress network to use sub-domains or sub-directories.' ); ?>
203
			<strong><?php _e( 'You cannot change this later.' ); ?></strong></p>
204
		<p><?php _e( 'You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality.' ); ?></p>
205
		<?php // @todo: Link to an MS readme? ?>
206
		<table class="form-table">
207
			<tr>
208
				<th><label><input type="radio" name="subdomain_install" value="1"<?php checked( $subdomain_install ); ?> /> <?php _e( 'Sub-domains' ); ?></label></th>
209
				<td><?php printf(
210
					/* translators: 1: hostname */
211
					_x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ),
212
					$hostname
213
				); ?></td>
214
			</tr>
215
			<tr>
216
				<th><label><input type="radio" name="subdomain_install" value="0"<?php checked( ! $subdomain_install ); ?> /> <?php _e( 'Sub-directories' ); ?></label></th>
217
				<td><?php printf(
218
					/* translators: 1: hostname */
219
					_x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ),
220
					$hostname
221
				); ?></td>
222
			</tr>
223
		</table>
224
225
<?php
226
	endif;
227
228
		if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) )
229
			echo '<div class="error inline"><p><strong>' . __('Warning!') . '</strong> ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
230
231
		$is_www = ( 0 === strpos( $hostname, 'www.' ) );
232
		if ( $is_www ) :
233
		?>
234
		<h3><?php esc_html_e( 'Server Address' ); ?></h3>
235
		<p><?php printf(
236
			/* translators: 1: site url 2: host name 3. www */
237
			__( '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.' ),
238
			'<code>' . substr( $hostname, 4 ) . '</code>',
239
			'<code>' . $hostname . '</code>',
240
			'<code>www</code>'
241
		); ?></p>
242
		<table class="form-table">
243
			<tr>
244
				<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
245
				<td>
246
					<?php printf(
247
						/* translators: %s: host name */
248
						__( 'The internet address of your network will be %s.' ),
249
						'<code>' . $hostname . '</code>'
250
					); ?>
251
				</td>
252
			</tr>
253
		</table>
254
		<?php endif; ?>
255
256
		<h3><?php esc_html_e( 'Network Details' ); ?></h3>
257
		<table class="form-table">
258
		<?php if ( 'localhost' == $hostname ) : ?>
259
			<tr>
260
				<th scope="row"><?php esc_html_e( 'Sub-directory Install' ); ?></th>
261
				<td><?php
262
					printf(
263
						/* translators: 1: localhost 2: localhost.localdomain */
264
						__( '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.' ),
265
						'<code>localhost</code>',
266
						'<code>localhost.localdomain</code>'
267
					);
268
					// Uh oh:
269 View Code Duplication
					if ( !allow_subdirectory_install() )
270
						echo ' <strong>' . __( 'Warning!' ) . ' ' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
271
				?></td>
272
			</tr>
273
		<?php elseif ( !allow_subdomain_install() ) : ?>
274
			<tr>
275
				<th scope="row"><?php esc_html_e( 'Sub-directory Install' ); ?></th>
276
				<td><?php
277
					_e( 'Because your install is in a directory, the sites in your WordPress network must use sub-directories.' );
278
					// Uh oh:
279 View Code Duplication
					if ( !allow_subdirectory_install() )
280
						echo ' <strong>' . __( 'Warning!' ) . ' ' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
281
				?></td>
282
			</tr>
283
		<?php elseif ( !allow_subdirectory_install() ) : ?>
284
			<tr>
285
				<th scope="row"><?php esc_html_e( 'Sub-domain Install' ); ?></th>
286
				<td><?php _e( 'Because your install is not new, the sites in your WordPress network must use sub-domains.' );
287
					echo ' <strong>' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
288
				?></td>
289
			</tr>
290
		<?php endif; ?>
291
		<?php if ( ! $is_www ) : ?>
292
			<tr>
293
				<th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
294
				<td>
295
					<?php printf(
296
						/* translators: %s: host name */
297
						__( 'The internet address of your network will be %s.' ),
298
						'<code>' . $hostname . '</code>'
299
					); ?>
300
				</td>
301
			</tr>
302
		<?php endif; ?>
303
			<tr>
304
				<th scope='row'><?php esc_html_e( 'Network Title' ); ?></th>
305
				<td>
306
					<input name='sitename' type='text' size='45' value='<?php echo esc_attr( $site_name ); ?>' />
307
					<p class="description">
308
						<?php _e( 'What would you like to call your network?' ); ?>
309
					</p>
310
				</td>
311
			</tr>
312
			<tr>
313
				<th scope='row'><?php esc_html_e( 'Network Admin Email' ); ?></th>
314
				<td>
315
					<input name='email' type='text' size='45' value='<?php echo esc_attr( $admin_email ); ?>' />
316
					<p class="description">
317
						<?php _e( 'Your email address.' ); ?>
318
					</p>
319
				</td>
320
			</tr>
321
		</table>
322
		<?php submit_button( __( 'Install' ), 'primary', 'submit' ); ?>
323
	</form>
324
	<?php
325
}
326
327
/**
328
 * Prints step 2 for Network installation process.
329
 *
330
 * @since 3.0.0
331
 *
332
 * @global wpdb $wpdb WordPress database abstraction object.
333
 *
334
 * @param WP_Error $errors
335
 */
336
function network_step2( $errors = false ) {
337
	global $wpdb;
338
339
	$hostname          = get_clean_basedomain();
340
	$slashed_home      = trailingslashit( get_option( 'home' ) );
341
	$base              = parse_url( $slashed_home, PHP_URL_PATH );
342
	$document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
343
	$abspath_fix       = str_replace( '\\', '/', ABSPATH );
344
	$home_path         = 0 === strpos( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path();
345
	$wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix );
346
	$rewrite_base      = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : '';
347
348
349
	$location_of_wp_config = $abspath_fix;
350
	if ( ! file_exists( ABSPATH . 'wp-config.php' ) && file_exists( dirname( ABSPATH ) . '/wp-config.php' ) ) {
351
		$location_of_wp_config = dirname( $abspath_fix );
352
	}
353
	$location_of_wp_config = trailingslashit( $location_of_wp_config );
354
355
	// Wildcard DNS message.
356
	if ( is_wp_error( $errors ) )
357
		echo '<div class="error">' . $errors->get_error_message() . '</div>';
0 ignored issues
show
Bug introduced by
It seems like $errors is not always an object, but can also be of type false. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
358
359
	if ( $_POST ) {
360
		if ( allow_subdomain_install() )
361
			$subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
362
		else
363
			$subdomain_install = false;
364
	} else {
365
		if ( is_multisite() ) {
366
			$subdomain_install = is_subdomain_install();
367
?>
368
	<p><?php _e( 'The original configuration steps are shown here for reference.' ); ?></p>
369
<?php
370
		} else {
371
			$subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
372
?>
373
	<div class="error"><p><strong><?php _e('Warning:'); ?></strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div>
374
	<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>
375
<?php
376
		}
377
	}
378
379
	$subdir_match          = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?';
380
	$subdir_replacement_01 = $subdomain_install ? '' : '$1';
381
	$subdir_replacement_12 = $subdomain_install ? '$1' : '$2';
382
383
	if ( $_POST || ! is_multisite() ) {
384
?>
385
		<h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
386
		<p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
387
		<div class="updated inline"><p><?php
388
			if ( file_exists( $home_path . '.htaccess' ) ) {
389
				echo '<strong>' . __( 'Caution:' ) . '</strong> ';
390
				printf(
391
					/* translators: 1: wp-config.php 2: .htaccess */
392
					__( 'We recommend you back up your existing %1$s and %2$s files.' ),
393
					'<code>wp-config.php</code>',
394
					'<code>.htaccess</code>'
395
				);
396
			} elseif ( file_exists( $home_path . 'web.config' ) ) {
397
				echo '<strong>' . __( 'Caution:' ) . '</strong> ';
398
				printf(
399
					/* translators: 1: wp-config.php 2: web.config */
400
					__( 'We recommend you back up your existing %1$s and %2$s files.' ),
401
					'<code>wp-config.php</code>',
402
					'<code>web.config</code>'
403
				);
404
			} else {
405
				echo '<strong>' . __( 'Caution:' ) . '</strong> ';
406
				printf(
407
					/* translators: 1: wp-config.php */
408
					__( 'We recommend you back up your existing %s file.' ),
409
					'<code>wp-config.php</code>'
410
				);
411
			}
412
		?></p></div>
413
<?php
414
	}
415
?>
416
		<ol>
417
			<li><p><?php printf(
418
				/* translators: 1: wp-config.php 2: location of wp-config file, 3: translated version of "That's all, stop editing! Happy blogging." */
419
				__( 'Add the following to your %1$s file in %2$s <strong>above</strong> the line reading %3$s:' ),
420
				'<code>wp-config.php</code>',
421
				'<code>' . $location_of_wp_config . '</code>',
422
				/*
423
				 * translators: This string should only be translated if wp-config-sample.php is localized.
424
				 * You can check the localized release package or
425
				 * https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php
426
				 */
427
				'<code>/* ' . __( 'That&#8217;s all, stop editing! Happy blogging.' ) . ' */</code>'
428
			); ?></p>
429
				<textarea class="code" readonly="readonly" cols="100" rows="7">
430
define('MULTISITE', true);
431
define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>);
432
define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>');
433
define('PATH_CURRENT_SITE', '<?php echo $base; ?>');
434
define('SITE_ID_CURRENT_SITE', 1);
435
define('BLOG_ID_CURRENT_SITE', 1);
436
</textarea>
437
<?php
438
	$keys_salts = array( 'AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' );
439
	foreach ( $keys_salts as $c => $v ) {
440
		if ( defined( $c ) )
441
			unset( $keys_salts[ $c ] );
442
	}
443
444
	if ( ! empty( $keys_salts ) ) {
445
		$keys_salts_str = '';
446
		$from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
447
		if ( is_wp_error( $from_api ) ) {
448
			foreach ( $keys_salts as $c => $v ) {
449
				$keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
450
			}
451
		} else {
452
			$from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) );
0 ignored issues
show
Bug introduced by
It seems like $from_api can also be of type object<WP_Error>; however, wp_remote_retrieve_body() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
453
			foreach ( $keys_salts as $c => $v ) {
454
				$keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
455
			}
456
		}
457
		$num_keys_salts = count( $keys_salts );
458
?>
459
	<p>
460
		<?php
461
			if ( 1 == $num_keys_salts ) {
462
				printf(
463
					/* translators: 1: wp-config.php */
464
					__( 'This unique authentication key is also missing from your %s file.' ),
465
					'<code>wp-config.php</code>'
466
				);
467
			} else {
468
				printf(
469
					/* translators: 1: wp-config.php */
470
					__( 'These unique authentication keys are also missing from your %s file.' ),
471
					'<code>wp-config.php</code>'
472
				);
473
			}
474
		?>
475
		<?php _e( 'To make your installation more secure, you should also add:' ); ?>
476
	</p>
477
	<textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>"><?php echo esc_textarea( $keys_salts_str ); ?></textarea>
478
<?php
479
	}
480
?>
481
</li>
482
<?php
483
	if ( iis7_supports_permalinks() ) :
484
		// IIS doesn't support RewriteBase, all your RewriteBase are belong to us
485
		$iis_subdir_match = ltrim( $base, '/' ) . $subdir_match;
486
		$iis_rewrite_base = ltrim( $base, '/' ) . $rewrite_base;
487
		$iis_subdir_replacement = $subdomain_install ? '' : '{R:1}';
488
489
		$web_config_file = '<?xml version="1.0" encoding="UTF-8"?>
490
<configuration>
491
    <system.webServer>
492
        <rewrite>
493
            <rules>
494
                <rule name="WordPress Rule 1" stopProcessing="true">
495
                    <match url="^index\.php$" ignoreCase="false" />
496
                    <action type="None" />
497
                </rule>';
498 View Code Duplication
				if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
499
					$web_config_file .= '
500
                <rule name="WordPress Rule for Files" stopProcessing="true">
501
                    <match url="^' . $iis_subdir_match . 'files/(.+)" ignoreCase="false" />
502
                    <action type="Rewrite" url="' . $iis_rewrite_base . WPINC . '/ms-files.php?file={R:1}" appendQueryString="false" />
503
                </rule>';
504
                }
505
                $web_config_file .= '
506
                <rule name="WordPress Rule 2" stopProcessing="true">
507
                    <match url="^' . $iis_subdir_match . 'wp-admin$" ignoreCase="false" />
508
                    <action type="Redirect" url="' . $iis_subdir_replacement . 'wp-admin/" redirectType="Permanent" />
509
                </rule>
510
                <rule name="WordPress Rule 3" stopProcessing="true">
511
                    <match url="^" ignoreCase="false" />
512
                    <conditions logicalGrouping="MatchAny">
513
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
514
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
515
                    </conditions>
516
                    <action type="None" />
517
                </rule>
518
                <rule name="WordPress Rule 4" stopProcessing="true">
519
                    <match url="^' . $iis_subdir_match . '(wp-(content|admin|includes).*)" ignoreCase="false" />
520
                    <action type="Rewrite" url="' . $iis_rewrite_base . '{R:1}" />
521
                </rule>
522
                <rule name="WordPress Rule 5" stopProcessing="true">
523
                    <match url="^' . $iis_subdir_match . '([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
524
                    <action type="Rewrite" url="' . $iis_rewrite_base . '{R:2}" />
525
                </rule>
526
                <rule name="WordPress Rule 6" stopProcessing="true">
527
                    <match url="." ignoreCase="false" />
528
                    <action type="Rewrite" url="index.php" />
529
                </rule>
530
            </rules>
531
        </rewrite>
532
    </system.webServer>
533
</configuration>
534
';
535
536
		echo '<li><p>';
537
		printf(
538
			/* translators: 1: a filename like .htaccess. 2: a file path. */
539
			__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
540
			'<code>web.config</code>',
541
			'<code>' . $home_path . '</code>'
542
		);
543
		echo '</p>';
544 View Code Duplication
		if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
545
			echo '<p><strong>' . __('Warning:') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
546
		?>
547
		<textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea( $web_config_file ); ?>
548
		</textarea></li>
549
		</ol>
550
551
	<?php else : // end iis7_supports_permalinks(). construct an htaccess file instead:
552
553
		$ms_files_rewriting = '';
554 View Code Duplication
		if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
555
			$ms_files_rewriting = "\n# uploaded files\nRewriteRule ^";
556
			$ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n";
557
		}
558
559
		$htaccess_file = <<<EOF
560
RewriteEngine On
561
RewriteBase {$base}
562
RewriteRule ^index\.php$ - [L]
563
{$ms_files_rewriting}
564
# add a trailing slash to /wp-admin
565
RewriteRule ^{$subdir_match}wp-admin$ {$subdir_replacement_01}wp-admin/ [R=301,L]
566
567
RewriteCond %{REQUEST_FILENAME} -f [OR]
568
RewriteCond %{REQUEST_FILENAME} -d
569
RewriteRule ^ - [L]
570
RewriteRule ^{$subdir_match}(wp-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L]
571
RewriteRule ^{$subdir_match}(.*\.php)$ {$rewrite_base}$subdir_replacement_12 [L]
572
RewriteRule . index.php [L]
573
574
EOF;
575
576
		echo '<li><p>';
577
		printf(
578
			/* translators: 1: a filename like .htaccess. 2: a file path. */
579
			__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
580
			'<code>.htaccess</code>',
581
			'<code>' . $home_path . '</code>'
582
		);
583
		echo '</p>';
584 View Code Duplication
		if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
585
			echo '<p><strong>' . __('Warning:') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
586
		?>
587
		<textarea class="code" readonly="readonly" cols="100" rows="<?php echo substr_count( $htaccess_file, "\n" ) + 1; ?>">
588
<?php echo esc_textarea( $htaccess_file ); ?></textarea></li>
589
		</ol>
590
591
	<?php endif; // end IIS/Apache code branches.
592
593
	if ( !is_multisite() ) { ?>
594
		<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>
595
<?php
596
	}
597
}
598