Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#42015 closed defect (bug) (fixed)

Ensure `wp_get_users_with_no_role()` returns the correct users when `$site_id` is passed

Reported by: flixos90's profile flixos90 Owned by: flixos90's profile flixos90
Milestone: 4.9 Priority: normal
Severity: normal Version:
Component: Role/Capability Keywords: has-patch has-unit-tests
Focuses: multisite Cc:


When passing the $site_id parameter to wp_get_users_with_no_role(), it still takes the roles from the current site and creates the regular expression based on those, causing possibly incorrect return values.

With the changes introduced in [41625], it is possible to easily switch the roles object over temporarily with wp_roles->for_site( $site_id ). This can be leveraged here to fix the bug in this function.

Attachments (1)

42015.diff (1.5 KB) - added by flixos90 7 years ago.

Download all attachments as: .zip

Change History (3)

7 years ago

#1 @flixos90
7 years ago

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
  • Owner set to flixos90
  • Status changed from new to assigned

#2 @flixos90
7 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 41654:

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.

Note: See TracTickets for help on using tickets.