[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> ms-settings.php (source)

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


Generated : Fri Jan 24 08:20:01 2025 Cross-referenced by PHPXref