WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 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
Milestone: 4.9 Priority: normal
Severity: normal Version:
Component: Role/Capability Keywords: has-patch has-unit-tests
Focuses: multisite Cc:

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 3 years ago.

Download all attachments as: .zip

Change History (3)

@flixos90
3 years ago

#1 @flixos90
3 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
3 years ago

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

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.