Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/17/2015 07:16:58 PM (11 years ago)
Author:
boonebgorges
Message:

Fix BP_UnitTestCase::go_to() for WP_Network.

See ​[WP34097].

Fixes #6626.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r9984 r10125  
    166166                        // (strip -src, -alpha, etc which may trip up version_compare())
    167167                        $wp_version = (float) $GLOBALS['wp_version'];
    168                         if ( version_compare( $wp_version, '3.9', '>=' ) ) {
     168                        if ( version_compare( $wp_version, '4.4', '>=' ) ) {
     169                                if ( ! $current_site = wp_cache_get( 'current_network', 'site-options' ) ) {
     170                                        // Are there even two networks installed?
     171                                        $one_network = $wpdb->get_row( "SELECT * FROM $wpdb->site LIMIT 2" ); // [sic]
     172                                        if ( 1 === $wpdb->num_rows ) {
     173                                                $current_site = new WP_Network( $one_network );
     174                                                wp_cache_add( 'current_network', $current_site, 'site-options' );
     175                                        } elseif ( 0 === $wpdb->num_rows ) {
     176                                                ms_not_installed( $domain, $path );
     177                                        }
     178                                }
     179                                if ( empty( $current_site ) ) {
     180                                        $current_site = WP_Network::get_by_path( $domain, $path, 1 );
     181                                }
     182
     183                                // The network declared by the site trumps any constants.
     184                                if ( $current_blog && $current_blog->site_id != $current_site->id ) {
     185                                        $current_site = WP_Network::get_instance( $current_blog->site_id );
     186                                }
     187
     188                                if ( empty( $current_site ) ) {
     189                                        do_action( 'ms_network_not_found', $domain, $path );
     190
     191                                        ms_not_installed( $domain, $path );
     192                                } elseif ( $path === $current_site->path ) {
     193                                        $current_blog = get_site_by_path( $domain, $path );
     194                                } else {
     195                                        // Search the network path + one more path segment (on top of the network path).
     196                                        $current_blog = get_site_by_path( $domain, $path, substr_count( $current_site->path, '/' ) );
     197                                }
     198
     199                                // Figure out the current network's main site.
     200                                if ( empty( $current_site->blog_id ) ) {
     201                                        if ( $current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path ) {
     202                                                $current_site->blog_id = $current_blog->blog_id;
     203                                        } elseif ( ! $current_site->blog_id = wp_cache_get( 'network:' . $current_site->id . ':main_site', 'site-options' ) ) {
     204                                                $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s",
     205                                                        $current_site->domain, $current_site->path ) );
     206                                                wp_cache_add( 'network:' . $current_site->id . ':main_site', $current_site->blog_id, 'site-options' );
     207                                        }
     208                                }
     209
     210                                $blog_id = $current_blog->blog_id;
     211                                $public  = $current_blog->public;
     212
     213                                if ( empty( $current_blog->site_id ) ) {
     214                                        // This dates to [MU134] and shouldn't be relevant anymore,
     215                                        // but it could be possible for arguments passed to insert_blog() etc.
     216                                        $current_blog->site_id = 1;
     217                                }
     218
     219                                $site_id = $current_blog->site_id;
     220                                wp_load_core_site_options( $site_id );
     221
     222                        } elseif ( version_compare( $wp_version, '3.9', '>=' ) ) {
    169223
    170224                                if ( is_admin() ) {
Note: See TracChangeset for help on using the changeset viewer.