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