Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#42014 closed defect (bug) (fixed)

Return correct role counts in `count_users()` when passing a different site ID

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

Description

When passing the $site_id parameter to count_users(), users for that site are counted. However, the available roles are still taken from the current site which is unexpected behavior.

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)

42014.diff (1.6 KB ) - added by flixos90 9 years ago.

Download all attachments as: .zip

Change History (3)

@flixos90
9 years ago

#1 @flixos90
9 years ago

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
  • Owner set to flixos90
  • Status newassigned

#2 @flixos90
9 years ago

  • Resolutionfixed
  • Status assignedclosed

In 41653:

Multisite: Fix count_users() possibly querying incorrect roles when passed a different site ID.

The time strategy in count_users() queries users by role. However, the roles queried for were not affected by passing another site than the current one through the $site_id parameter, causing users having roles that were not queried for to appear as users without a role. This changeset fixes the issue by switching the site before retrieving the roles to query for.

Fixes #42014.

Note: See TracTickets for help on using tickets.