[wp-trac] [WordPress Trac] #39643: WP_User_Query does not allow search_fields to use display_name

WordPress Trac noreply at wordpress.org
Thu Jan 19 22:34:32 UTC 2017

#39643: WP_User_Query does not allow search_fields to use display_name
 Reporter:  bcole808      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
 '''Expected Behavior:'''

 The following query:

 new WP_User_Query(array(
         'search' => '*Ben*',
         'search_columns' => 'display_name',

 should search the users table and ONLY look at the column 'display_name'.

 '''Observed problematic behavior:'''

 During the prepare_query method, the search column parameter gets reset to
 the default value because of this line (around line 526) which appears to
 be filtering the allowed values for safety:

 $search_columns = array_intersect( $qv['search_columns'], array( 'ID',
 'user_login', 'user_email', 'user_url', 'user_nicename' ) );

 You can see in the lines of code following this, by default it will
 include all fields (including display_name) like this:

 $search_columns = array('user_login', 'user_url', 'user_email',
 'user_nicename', 'display_name');

 It looks like display_name is just missing from the whitelist of allowed
 custom query fields. I will attach a patch which should fix this problem.

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

More information about the wp-trac mailing list