You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

115 lines
3.3 KiB

  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. * @since 3.0.0
  21. */
  22. global $current_site, $current_blog;
  23. /** WP_Network class */
  24. require_once( ABSPATH . WPINC . '/class-wp-network.php' );
  25. /** WP_Site class */
  26. require_once( ABSPATH . WPINC . '/class-wp-site.php' );
  27. /** Multisite loader */
  28. require_once( ABSPATH . WPINC . '/ms-load.php' );
  29. /** Default Multisite constants */
  30. require_once( ABSPATH . WPINC . '/ms-default-constants.php' );
  31. if ( defined( 'SUNRISE' ) ) {
  32. include_once( WP_CONTENT_DIR . '/sunrise.php' );
  33. }
  34. /** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */
  35. ms_subdomain_constants();
  36. // This block will process a request if the current network or current site objects
  37. // have not been populated in the global scope through something like `sunrise.php`.
  38. if ( !isset( $current_site ) || !isset( $current_blog ) ) {
  39. $domain = strtolower( stripslashes( $_SERVER['HTTP_HOST'] ) );
  40. if ( substr( $domain, -3 ) == ':80' ) {
  41. $domain = substr( $domain, 0, -3 );
  42. $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
  43. } elseif ( substr( $domain, -4 ) == ':443' ) {
  44. $domain = substr( $domain, 0, -4 );
  45. $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
  46. }
  47. $path = stripslashes( $_SERVER['REQUEST_URI'] );
  48. if ( is_admin() ) {
  49. $path = preg_replace( '#(.*)/wp-admin/.*#', '$1/', $path );
  50. }
  51. list( $path ) = explode( '?', $path );
  52. $bootstrap_result = ms_load_current_site_and_network( $domain, $path, is_subdomain_install() );
  53. if ( true === $bootstrap_result ) {
  54. // `$current_blog` and `$current_site are now populated.
  55. } elseif ( false === $bootstrap_result ) {
  56. ms_not_installed( $domain, $path );
  57. } else {
  58. header( 'Location: ' . $bootstrap_result );
  59. exit;
  60. }
  61. unset( $bootstrap_result );
  62. $blog_id = $current_blog->blog_id;
  63. $public = $current_blog->public;
  64. if ( empty( $current_blog->site_id ) ) {
  65. // This dates to [MU134] and shouldn't be relevant anymore,
  66. // but it could be possible for arguments passed to insert_blog() etc.
  67. $current_blog->site_id = 1;
  68. }
  69. $site_id = $current_blog->site_id;
  70. wp_load_core_site_options( $site_id );
  71. }
  72. $wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php
  73. $wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id );
  74. $table_prefix = $wpdb->get_blog_prefix();
  75. $_wp_switched_stack = array();
  76. $switched = false;
  77. // need to init cache again after blog_id is set
  78. wp_start_object_cache();
  79. if ( ! $current_site instanceof WP_Network ) {
  80. $current_site = new WP_Network( $current_site );
  81. }
  82. if ( ! $current_blog instanceof WP_Site ) {
  83. $current_blog = new WP_Site( $current_blog );
  84. }
  85. // Define upload directory constants
  86. ms_upload_constants();
  87. /**
  88. * Fires after the current site and network have been detected and loaded
  89. * in multisite's bootstrap.
  90. *
  91. * @since 4.6.0
  92. */
  93. do_action( 'ms_loaded' );