[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/includes/ -> network.php (source)

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


Generated : Thu May 14 08:20:03 2026 Cross-referenced by PHPXref