ms-settings.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * Used to set up and fix common variables and include
  4. * the Multisite procedural and class library.
  5. *
  6. * Allows for some configuration in wp-config.php (see ms-default-constants.php)
  7. *
  8. * @package WordPress
  9. * @subpackage Multisite
  10. * @since 3.0.0
  11. */
  12. /**
  13. * Objects representing the current network and current site.
  14. *
  15. * These may be populated through a custom `sunrise.php`. If not, then this
  16. * file will attempt to populate them based on the current request.
  17. *
  18. * @global WP_Network $current_site The current network.
  19. * @global object $current_blog The current site.
  20. * @global string $domain Deprecated. The domain of the site found on load.
  21. * Use `get_site()->domain` instead.
  22. * @global string $path Deprecated. The path of the site found on load.
  23. * Use `get_site()->path` instead.
  24. * @global int $site_id Deprecated. The ID of the network found on load.
  25. * Use `get_current_network_id()` instead.
  26. * @global bool $public Deprecated. Whether the site found on load is public.
  27. * Use `get_site()->public` instead.
  28. *
  29. * @since 3.0.0
  30. */
  31. global $current_site, $current_blog, $domain, $path, $site_id, $public;
  32. /** WP_Network class */
  33. require_once ABSPATH . WPINC . '/class-wp-network.php';
  34. /** WP_Site class */
  35. require_once ABSPATH . WPINC . '/class-wp-site.php';
  36. /** Multisite loader */
  37. require_once ABSPATH . WPINC . '/ms-load.php';
  38. /** Default Multisite constants */
  39. require_once ABSPATH . WPINC . '/ms-default-constants.php';
  40. if ( defined( 'SUNRISE' ) ) {
  41. include_once WP_CONTENT_DIR . '/sunrise.php';
  42. }
  43. /** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */
  44. ms_subdomain_constants();
  45. // This block will process a request if the current network or current site objects
  46. // have not been populated in the global scope through something like `sunrise.php`.
  47. if ( ! isset( $current_site ) || ! isset( $current_blog ) ) {
  48. $domain = strtolower( stripslashes( $_SERVER['HTTP_HOST'] ) );
  49. if ( ':80' === substr( $domain, -3 ) ) {
  50. $domain = substr( $domain, 0, -3 );
  51. $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
  52. } elseif ( ':443' === substr( $domain, -4 ) ) {
  53. $domain = substr( $domain, 0, -4 );
  54. $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
  55. }
  56. $path = stripslashes( $_SERVER['REQUEST_URI'] );
  57. if ( is_admin() ) {
  58. $path = preg_replace( '#(.*)/wp-admin/.*#', '$1/', $path );
  59. }
  60. list( $path ) = explode( '?', $path );
  61. $bootstrap_result = ms_load_current_site_and_network( $domain, $path, is_subdomain_install() );
  62. if ( true === $bootstrap_result ) {
  63. // `$current_blog` and `$current_site are now populated.
  64. } elseif ( false === $bootstrap_result ) {
  65. ms_not_installed( $domain, $path );
  66. } else {
  67. header( 'Location: ' . $bootstrap_result );
  68. exit;
  69. }
  70. unset( $bootstrap_result );
  71. $blog_id = $current_blog->blog_id;
  72. $public = $current_blog->public;
  73. if ( empty( $current_blog->site_id ) ) {
  74. // This dates to [MU134] and shouldn't be relevant anymore,
  75. // but it could be possible for arguments passed to insert_blog() etc.
  76. $current_blog->site_id = 1;
  77. }
  78. $site_id = $current_blog->site_id;
  79. wp_load_core_site_options( $site_id );
  80. }
  81. $wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php.
  82. $wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id );
  83. $table_prefix = $wpdb->get_blog_prefix();
  84. $_wp_switched_stack = array();
  85. $switched = false;
  86. // Need to init cache again after blog_id is set.
  87. wp_start_object_cache();
  88. if ( ! $current_site instanceof WP_Network ) {
  89. $current_site = new WP_Network( $current_site );
  90. }
  91. if ( ! $current_blog instanceof WP_Site ) {
  92. $current_blog = new WP_Site( $current_blog );
  93. }
  94. // Define upload directory constants.
  95. ms_upload_constants();
  96. /**
  97. * Fires after the current site and network have been detected and loaded
  98. * in multisite's bootstrap.
  99. *
  100. * @since 4.6.0
  101. */
  102. do_action( 'ms_loaded' );