From cf22bbb523b640e003b2fe8a5cd9c5fb1c8b81c1 Mon Sep 17 00:00:00 2001 From: nacin Date: Wed, 8 Feb 2012 21:48:47 +0000 Subject: [PATCH] Add search_columns arg to WP_User_Query to allow for explicit column choices. Without it, the columns will be detected based on the search term. see #19810. git-svn-id: http://svn.automattic.com/wordpress/trunk@19882 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/user.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/wp-includes/user.php b/wp-includes/user.php index 7bb10277f..804a90936 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -378,6 +378,7 @@ class WP_User_Query { 'include' => array(), 'exclude' => array(), 'search' => '', + 'search_columns' => array(), 'orderby' => 'login', 'order' => 'ASC', 'offset' => '', @@ -476,14 +477,19 @@ class WP_User_Query { if ( $wild ) $search = trim($search, '*'); - if ( false !== strpos( $search, '@') ) - $search_columns = array('user_email'); - elseif ( is_numeric($search) ) - $search_columns = array('user_login', 'ID'); - elseif ( preg_match('|^https?://|', $search) ) - $search_columns = array('user_url'); - else - $search_columns = array('user_login', 'user_nicename'); + $search_columns = array(); + if ( $qv['search_columns'] ) + $search_columns = array_intersect( $qv['search_columns'], array( 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename' ) ); + if ( ! $search_columns ) { + if ( false !== strpos( $search, '@') ) + $search_columns = array('user_email'); + elseif ( is_numeric($search) ) + $search_columns = array('user_login', 'ID'); + elseif ( preg_match('|^https?://|', $search) ) + $search_columns = array('user_url'); + else + $search_columns = array('user_login', 'user_nicename'); + } $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild ); }