~canonical-sysadmins/wordpress/4.9.1

« back to all changes in this revision

Viewing changes to wp-includes/ms-load.php

  • Committer: Barry Price
  • Date: 2017-11-17 04:49:02 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: barry.price@canonical.com-20171117044902-5frux4ycbq6g9fyf
Merge WP4.9 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
135
135
 
136
136
/**
137
137
 * Retrieves the closest matching site object by its domain and path.
138
 
 * 
 
138
 *
139
139
 * This will not necessarily return an exact match for a domain and path. Instead, it
140
140
 * breaks the domain and path into pieces that are then used to match the closest
141
141
 * possibility from a query.
268
268
 * @since 4.6.0
269
269
 * @access private
270
270
 *
271
 
 * @global wpdb       $wpdb         WordPress database abstraction object.
272
271
 * @global WP_Network $current_site The current network.
273
272
 * @global WP_Site    $current_blog The current site.
274
273
 *
281
280
 *                     Redirect URL if parts exist, but the request as a whole can not be fulfilled.
282
281
 */
283
282
function ms_load_current_site_and_network( $domain, $path, $subdomain = false ) {
284
 
        global $wpdb, $current_site, $current_blog;
 
283
        global $current_site, $current_blog;
285
284
 
286
285
        // If the network is defined in wp-config.php, we can simply use that.
287
286
        if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
308
307
 
309
308
        } elseif ( ! $subdomain ) {
310
309
                /*
311
 
                 * A "subdomain" install can be re-interpreted to mean "can support any domain".
312
 
                 * If we're not dealing with one of these installs, then the important part is determining
 
310
                 * A "subdomain" installation can be re-interpreted to mean "can support any domain".
 
311
                 * If we're not dealing with one of these installations, then the important part is determining
313
312
                 * the network first, because we need the network's path to identify any sites.
314
313
                 */
315
314
                if ( ! $current_site = wp_cache_get( 'current_network', 'site-options' ) ) {
316
315
                        // Are there even two networks installed?
317
 
                        $one_network = $wpdb->get_row( "SELECT * FROM $wpdb->site LIMIT 2" ); // [sic]
318
 
                        if ( 1 === $wpdb->num_rows ) {
319
 
                                $current_site = new WP_Network( $one_network );
 
316
                        $networks = get_networks( array( 'number' => 2 ) );
 
317
                        if ( count( $networks ) === 1 ) {
 
318
                                $current_site = array_shift( $networks );
320
319
                                wp_cache_add( 'current_network', $current_site, 'site-options' );
321
 
                        } elseif ( 0 === $wpdb->num_rows ) {
 
320
                        } elseif ( empty( $networks ) ) {
322
321
                                // A network not found hook should fire here.
323
322
                                return false;
324
323
                        }
401
400
                do_action( 'ms_site_not_found', $current_site, $domain, $path );
402
401
 
403
402
                if ( $subdomain && ! defined( 'NOBLOGREDIRECT' ) ) {
404
 
                        // For a "subdomain" install, redirect to the signup form specifically.
 
403
                        // For a "subdomain" installation, redirect to the signup form specifically.
405
404
                        $destination .= 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
406
405
                } elseif ( $subdomain ) {
407
 
                        // For a "subdomain" install, the NOBLOGREDIRECT constant
 
406
                        // For a "subdomain" installation, the NOBLOGREDIRECT constant
408
407
                        // can be used to avoid a redirect to the signup form.
409
408
                        // Using the ms_site_not_found action is preferred to the constant.
410
409
                        if ( '%siteurl%' !== NOBLOGREDIRECT ) {
424
423
 
425
424
        // Figure out the current network's main site.
426
425
        if ( empty( $current_site->blog_id ) ) {
427
 
                if ( $current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path ) {
428
 
                        $current_site->blog_id = $current_blog->blog_id;
429
 
                } elseif ( ! $current_site->blog_id = wp_cache_get( 'network:' . $current_site->id . ':main_site', 'site-options' ) ) {
430
 
                        $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s",
431
 
                                $current_site->domain, $current_site->path ) );
432
 
                        wp_cache_add( 'network:' . $current_site->id . ':main_site', $current_site->blog_id, 'site-options' );
433
 
                }
 
426
                $current_site->blog_id = get_main_site_id( $current_site->id );
434
427
        }
435
428
 
436
429
        return true;