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


Generated : Fri Apr 26 08:20:02 2024 Cross-referenced by PHPXref