network.php 24 KB

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