51
61
list( $path ) = explode( '?', $path );
53
// If the network is defined in wp-config.php, we can simply use that.
54
if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
55
$current_site = new stdClass;
56
$current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
57
$current_site->domain = DOMAIN_CURRENT_SITE;
58
$current_site->path = PATH_CURRENT_SITE;
59
if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
60
$current_site->blog_id = BLOG_ID_CURRENT_SITE;
61
} elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated.
62
$current_site->blog_id = BLOGID_CURRENT_SITE;
65
if ( 0 === strcasecmp( $current_site->domain, $domain ) && 0 === strcasecmp( $current_site->path, $path ) ) {
66
$current_blog = get_site_by_path( $domain, $path );
67
} elseif ( '/' !== $current_site->path && 0 === strcasecmp( $current_site->domain, $domain ) && 0 === stripos( $path, $current_site->path ) ) {
68
// If the current network has a path and also matches the domain and path of the request,
69
// we need to look for a site using the first path segment following the network's path.
70
$current_blog = get_site_by_path( $domain, $path, 1 + count( explode( '/', trim( $current_site->path, '/' ) ) ) );
72
// Otherwise, use the first path segment (as usual).
73
$current_blog = get_site_by_path( $domain, $path, 1 );
76
} elseif ( ! is_subdomain_install() ) {
78
* A "subdomain" install can be re-interpreted to mean "can support any domain".
79
* If we're not dealing with one of these installs, then the important part is determining
80
* the network first, because we need the network's path to identify any sites.
82
if ( ! $current_site = wp_cache_get( 'current_network', 'site-options' ) ) {
83
// Are there even two networks installed?
84
$one_network = $wpdb->get_row( "SELECT * FROM $wpdb->site LIMIT 2" ); // [sic]
85
if ( 1 === $wpdb->num_rows ) {
86
$current_site = new WP_Network( $one_network );
87
wp_cache_add( 'current_network', $current_site, 'site-options' );
88
} elseif ( 0 === $wpdb->num_rows ) {
89
ms_not_installed( $domain, $path );
92
if ( empty( $current_site ) ) {
93
$current_site = WP_Network::get_by_path( $domain, $path, 1 );
96
if ( empty( $current_site ) ) {
98
* Fires when a network cannot be found based on the requested domain and path.
100
* At the time of this action, the only recourse is to redirect somewhere
101
* and exit. If you want to declare a particular network, do so earlier.
105
* @param string $domain The domain used to search for a network.
106
* @param string $path The path used to search for a path.
108
do_action( 'ms_network_not_found', $domain, $path );
110
ms_not_installed( $domain, $path );
111
} elseif ( $path === $current_site->path ) {
112
$current_blog = get_site_by_path( $domain, $path );
114
// Search the network path + one more path segment (on top of the network path).
115
$current_blog = get_site_by_path( $domain, $path, substr_count( $current_site->path, '/' ) );
63
$bootstrap_result = ms_load_current_site_and_network( $domain, $path, is_subdomain_install() );
65
if ( true === $bootstrap_result ) {
66
// `$current_blog` and `$current_site are now populated.
67
} elseif ( false === $bootstrap_result ) {
68
ms_not_installed( $domain, $path );
118
// Find the site by the domain and at most the first path segment.
119
$current_blog = get_site_by_path( $domain, $path, 1 );
120
if ( $current_blog ) {
121
$current_site = WP_Network::get_instance( $current_blog->site_id ? $current_blog->site_id : 1 );
123
// If you don't have a site with the same domain/path as a network, you're pretty screwed, but:
124
$current_site = WP_Network::get_by_path( $domain, $path, 1 );
128
// The network declared by the site trumps any constants.
129
if ( $current_blog && $current_blog->site_id != $current_site->id ) {
130
$current_site = WP_Network::get_instance( $current_blog->site_id );
133
// No network has been found, bail.
134
if ( empty( $current_site ) ) {
135
/** This action is documented in wp-includes/ms-settings.php */
136
do_action( 'ms_network_not_found', $domain, $path );
138
ms_not_installed( $domain, $path );
141
// During activation of a new subdomain, the requested site does not yet exist.
142
if ( empty( $current_blog ) && wp_installing() ) {
143
$current_blog = new stdClass;
144
$current_blog->blog_id = $blog_id = 1;
145
$current_blog->public = 1;
148
// No site has been found, bail.
149
if ( empty( $current_blog ) ) {
150
// We're going to redirect to the network URL, with some possible modifications.
151
$scheme = is_ssl() ? 'https' : 'http';
152
$destination = "$scheme://{$current_site->domain}{$current_site->path}";
155
* Fires when a network can be determined but a site cannot.
157
* At the time of this action, the only recourse is to redirect somewhere
158
* and exit. If you want to declare a particular site, do so earlier.
162
* @param object $current_site The network that had been determined.
163
* @param string $domain The domain used to search for a site.
164
* @param string $path The path used to search for a site.
166
do_action( 'ms_site_not_found', $current_site, $domain, $path );
168
if ( is_subdomain_install() && ! defined( 'NOBLOGREDIRECT' ) ) {
169
// For a "subdomain" install, redirect to the signup form specifically.
170
$destination .= 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
171
} elseif ( is_subdomain_install() ) {
172
// For a "subdomain" install, the NOBLOGREDIRECT constant
173
// can be used to avoid a redirect to the signup form.
174
// Using the ms_site_not_found action is preferred to the constant.
175
if ( '%siteurl%' !== NOBLOGREDIRECT ) {
176
$destination = NOBLOGREDIRECT;
178
} elseif ( 0 === strcasecmp( $current_site->domain, $domain ) ) {
180
* If the domain we were searching for matches the network's domain,
181
* it's no use redirecting back to ourselves -- it'll cause a loop.
182
* As we couldn't find a site, we're simply not installed.
184
ms_not_installed( $domain, $path );
187
header( 'Location: ' . $destination );
70
header( 'Location: ' . $bootstrap_result );
191
// Figure out the current network's main site.
192
if ( empty( $current_site->blog_id ) ) {
193
if ( $current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path ) {
194
$current_site->blog_id = $current_blog->blog_id;
195
} elseif ( ! $current_site->blog_id = wp_cache_get( 'network:' . $current_site->id . ':main_site', 'site-options' ) ) {
196
$current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s",
197
$current_site->domain, $current_site->path ) );
198
wp_cache_add( 'network:' . $current_site->id . ':main_site', $current_site->blog_id, 'site-options' );
73
unset( $bootstrap_result );
202
75
$blog_id = $current_blog->blog_id;
203
76
$public = $current_blog->public;