network.php 26 KB

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