Make WordPress Core

Opened 10 years ago

Closed 10 years 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
Priority: normal Milestone: 4.7
Component: Users Version: 4.4
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

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

Download all attachments as: .zip

Change History (8)

#1 @ocean90
10 years ago

  • Keywords good-first-bug needs-patch needs-unit-tests added
  • Milestone Awaiting ReviewFuture Release
  • Version 4.6.14.4

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

@procodewp
10 years ago

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

#2 @procodewp
10 years ago

  • Keywords has-patch added; needs-patch removed

#3 @procodewp
10 years 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
10 years 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
10 years ago

  • Keywords good-first-bug removed
  • Milestone Future Release4.7
  • Owner set to johnbillion
  • Status newreviewing

#6 @johnbillion
10 years ago

  • Resolutionfixed
  • Status reviewingclosed

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.