選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

network.php 23 KiB

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