/wp-admin/includes/network.php

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