Make WordPress Core

Ticket #38355: 38355.2.diff

File 38355.2.diff, 3.4 KB (added by flixos90, 9 years ago)
  • src/wp-includes/ms-functions.php

     
    5353        if ( false !== $primary_blog ) {
    5454                if ( ! isset( $blogs[ $primary_blog ] ) ) {
    5555                        update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );
    56                         $primary = get_blog_details( $first_blog->userblog_id );
     56                        $primary = get_site( $first_blog->userblog_id );
    5757                } else {
    58                         $primary = get_blog_details( $primary_blog );
     58                        $primary = get_site( $primary_blog );
    5959                }
    6060        } else {
    6161                //TODO Review this call to add_user_to_blog too - to get here the user must have a role on this blog?
     
    7171                        foreach ( (array) $blogs as $blog_id => $blog ) {
    7272                                if ( $blog->site_id != $wpdb->siteid )
    7373                                        continue;
    74                                 $details = get_blog_details( $blog_id );
     74                                $details = get_site( $blog_id );
    7575                                if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) {
    7676                                        $ret = $blog;
    7777                                        if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id )
  • tests/phpunit/tests/user/multisite.php

     
    365365                $this->assertFalse( wpmu_delete_user( $u_obj ) );
    366366                $this->assertEquals( $u_obj->ID, username_exists( $u_obj->user_login ) );
    367367        }
     368
     369        /**
     370         * @ticket 38355
     371         */
     372        public function test_get_active_blog_for_user_with_no_sites() {
     373                $current_site_id = get_current_blog_id();
     374                $user_id = self::factory()->user->create();
     375                remove_user_from_blog( $user_id, $current_site_id );
     376
     377                $result = get_active_blog_for_user( $user_id );
     378                $this->assertNull( $result );
     379        }
     380
     381        /**
     382         * @ticket 38355
     383         */
     384        public function test_get_active_blog_for_user_with_primary_site() {
     385                $user_id = self::factory()->user->create();
     386                self::factory()->blog->create( array( 'user_id' => $user_id ) );
     387                self::factory()->blog->create( array( 'user_id' => $user_id ) );
     388
     389                $sites = get_blogs_of_user( $user_id );
     390                $site_ids = array_keys( $sites );
     391                $primary_site_id = $site_ids[1];
     392
     393                update_user_meta( $user_id, 'primary_blog', $primary_site_id );
     394
     395                $result = get_active_blog_for_user( $user_id );
     396                $this->assertEquals( $primary_site_id, $result->id );
     397        }
     398
     399        /**
     400         * @ticket 38355
     401         */
     402        public function test_get_active_blog_for_user_without_primary_site() {
     403                $user_id = self::factory()->user->create();
     404                self::factory()->blog->create( array( 'user_id' => $user_id ) );
     405
     406                $sites = get_blogs_of_user( $user_id );
     407                $site_ids = array_keys( $sites );
     408                $primary_site_id = $site_ids[0];
     409
     410                delete_user_meta( $user_id, 'primary_blog' );
     411
     412                $result = get_active_blog_for_user( $user_id );
     413                $this->assertEquals( $primary_site_id, $result->id );
     414        }
     415
     416        /**
     417         * @ticket 38355
     418         */
     419        public function test_get_active_blog_for_user_with_spam_site() {
     420                $current_site_id = get_current_blog_id();
     421                $user_id = self::factory()->user->create();
     422
     423                $site_id = self::factory()->blog->create( array(
     424                        'user_id' => $user_id,
     425                        'meta'    => array( 'spam' => 1 ),
     426                ) );
     427
     428                add_user_to_blog( $user_id, $site_id, 'subscriber' );
     429                update_user_meta( $user_id, 'primary_blog', $site_id );
     430
     431                $result = get_active_blog_for_user( $user_id );
     432                $this->assertEquals( $current_site_id, $result->id );
     433        }
    368434}
    369435
    370436endif ;