WordPress.org

Make WordPress Core

Opened 7 months ago

Closed 7 months ago

#38234 closed defect (bug) (fixed)

wp_get_users_with_no_role() generates query based on role display names not role name

Reported by: szaqal21 Owned by: johnbillion
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.4
Component: Users Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

This is a follow-up to #22993.

wp_get_users_with_no_role() doesn't work properly when there is and custom role eg. role name is "admin_www" and display name is "Admin WWW", function generates query:

SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_capabilities' AND meta_value NOT REGEXP 'Author|Contributor|Subscriber|Redaktor|Administrator|AdminWWW'

query should be build based on role name not display name.

Attachments (2)

38234.patch (504 bytes) - added by procodewp 7 months ago.
Patch to use role name instead of role display name in wp_get_users_with_no_role()
38234.2.patch (1.5 KB) - added by choongsavvii 7 months ago.

Download all attachments as: .zip

Change History (8)

#1 @ocean90
7 months ago

  • Keywords good-first-bug needs-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 4.6.1 to 4.4

Thanks for the report, it should indeed use the role name.

@procodewp
7 months ago

Patch to use role name instead of role display name in wp_get_users_with_no_role()

#2 @procodewp
7 months ago

  • Keywords has-patch added; needs-patch removed

#3 @procodewp
7 months ago

Explanation for the patch:

wp_roles()->get_names() returns an array in the format:

role_name => display_role_name

wp_get_users_with_no_role() uses the array value (display name) to build the regex, when it should use the array key (role name).

#4 @choongsavvii
7 months ago

  • Keywords has-unit-tests added; needs-unit-tests removed

38234.2.patch contains both @procodewp 's original fix, and the accompanying unit test.

#5 @johnbillion
7 months ago

  • Keywords good-first-bug removed
  • Milestone changed from Future Release to 4.7
  • Owner set to johnbillion
  • Status changed from new to reviewing

#6 @johnbillion
7 months ago

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

In 38787:

Users: Use the role name instead of the role display name when fetching the list of users with no role. This avoids false positives when dealing with user roles that, for example, contain spaces in the display name.

Props procodewp, choongsavvii
Fixes #38234

Note: See TracTickets for help on using tickets.