[wp-trac] [WordPress Trac] #49399: wp_get_users_with_no_role() does not handle user roles which contain numbers

WordPress Trac noreply at wordpress.org
Tue Feb 11 00:42:25 UTC 2020


#49399: wp_get_users_with_no_role() does not handle user roles which contain
numbers
--------------------------+-----------------------------
 Reporter:  chillbram     |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.3.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The function
 [https://developer.wordpress.org/reference/functions/wp_get_users_with_no_role/
 wp_get_users_with_no_role()] does not correctly ascertain which roles it
 needs to search for. Before it queries the database it changes the names
 for roles which contain numbers (and special characters for that matter).
 It uses the following regex to adapt the list of roles it gets from
 [https://developer.wordpress.org/reference/classes/wp_roles/get_names/
 wp_roles()->get_names()]:

 {{{#!php
 <?php
 $regex = implode( '|', array_keys( $role_names ) );
 $regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex );
 }}}

 This results in roles with names like "Year1" and "Group1Admins" to be
 truncated to "Year" and "GroupAdmins" respectively before querying.

 This could be easily solved by extending the regex pattern to also accept
 numbers:

 {{{#!php
 <?php
 $regex = preg_replace( '/[^0-9a-zA-Z_\|-]/', '', $regex );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49399>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list