Make WordPress Core


Ignore:
Timestamp:
09/30/2017 04:09:11 AM (8 years ago)
Author:
flixos90
Message:

Multisite: Fix wp_get_users_with_no_role() possibly including users with a role on a different site.

Prior to this change, when passing another site than the current one to wp_get_users_with_no_role() through its $site_id parameter, the function still used the roles available on the current site, which would cause users with other roles that possibly exist on the other site to show up as users without a role. Switching the site before retrieving the available rules fixes the issue.

Fixes #42015.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/wpGetUsersWithNoRole.php

    r41138 r41654  
    102102    }
    103103
     104    /**
     105     * @ticket 42015
     106     * @group multisite
     107     * @group ms-required
     108     */
     109    public function test_get_users_with_no_role_matches_on_role_name_different_site() {
     110        $site_id = (int) self::factory()->blog->create();
     111
     112        switch_to_blog( $site_id );
     113        wp_roles()->add_role( 'somerole', 'Some role display name' );
     114        $user_id = self::factory()->user->create( array(
     115            'role' => 'somerole',
     116        ) );
     117        restore_current_blog();
     118
     119        $users = wp_get_users_with_no_role( $site_id );
     120
     121        $this->assertEmpty( $users );
     122    }
     123
    104124}
Note: See TracChangeset for help on using the changeset viewer.