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


Generated : Sat Jun 6 08:20:01 2020 Cross-referenced by PHPXref