Anchor user search queries to the front. Limit columns searched based on what the search string looks like. see #15170

git-svn-id: http://svn.automattic.com/wordpress/trunk@16168 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-11-03 19:02:42 +00:00
parent b713a76272
commit 6291fa9dc6
2 changed files with 16 additions and 3 deletions

View File

@ -233,8 +233,12 @@ class WP_Object_Query {
$string = esc_sql( $string );
$searches = array();
foreach ( $cols as $col )
$searches[] = "$col LIKE '%$string%'";
foreach ( $cols as $col ) {
if ( 'ID' == $col )
$searches[] = "$col = '$string'";
else
$searches[] = "$col LIKE '$string%'";
}
return ' AND (' . implode(' OR ', $searches) . ')';
}

View File

@ -446,7 +446,16 @@ class WP_User_Query extends WP_Object_Query {
$search = trim( $qv['search'] );
if ( $search ) {
$this->query_where .= $this->get_search_sql( $search, array( 'user_login', 'user_nicename', 'user_email', 'user_url', 'display_name' ) );
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', 'display_name');
$this->query_where .= $this->get_search_sql( $search, $search_columns );
}
$this->parse_meta_query( $qv );