Allow trailing wildcard user searches by appending *. see #15170
git-svn-id: https://develop.svn.wordpress.org/trunk@16170 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0ab95195d0
commit
85e4a4a434
@ -227,17 +227,19 @@ class WP_Object_Query {
|
|||||||
*
|
*
|
||||||
* @param string $string
|
* @param string $string
|
||||||
* @param array $cols
|
* @param array $cols
|
||||||
|
* @param bool $wild Whether to allow trailing wildcard searches. Default is false.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function get_search_sql( $string, $cols ) {
|
function get_search_sql( $string, $cols, $wild = false ) {
|
||||||
$string = esc_sql( $string );
|
$string = esc_sql( $string );
|
||||||
|
|
||||||
$searches = array();
|
$searches = array();
|
||||||
|
$wild_char = ( $wild ) ? '%' : '';
|
||||||
foreach ( $cols as $col ) {
|
foreach ( $cols as $col ) {
|
||||||
if ( 'ID' == $col )
|
if ( 'ID' == $col )
|
||||||
$searches[] = "$col = '$string'";
|
$searches[] = "$col = '$string'";
|
||||||
else
|
else
|
||||||
$searches[] = "$col LIKE '$string%'";
|
$searches[] = "$col LIKE '$string$wild_char'";
|
||||||
}
|
}
|
||||||
|
|
||||||
return ' AND (' . implode(' OR ', $searches) . ')';
|
return ' AND (' . implode(' OR ', $searches) . ')';
|
||||||
|
@ -446,6 +446,11 @@ class WP_User_Query extends WP_Object_Query {
|
|||||||
|
|
||||||
$search = trim( $qv['search'] );
|
$search = trim( $qv['search'] );
|
||||||
if ( $search ) {
|
if ( $search ) {
|
||||||
|
$wild = false;
|
||||||
|
if ( false !== strpos($search, '*') ) {
|
||||||
|
$wild = 'true';
|
||||||
|
$search = trim($search, '*');
|
||||||
|
}
|
||||||
if ( false !== strpos( $search, '@') )
|
if ( false !== strpos( $search, '@') )
|
||||||
$search_columns[] = array('user_email');
|
$search_columns[] = array('user_email');
|
||||||
elseif ( is_numeric($search) )
|
elseif ( is_numeric($search) )
|
||||||
@ -455,7 +460,7 @@ class WP_User_Query extends WP_Object_Query {
|
|||||||
else
|
else
|
||||||
$search_columns = array('user_login', 'user_nicename', 'display_name');
|
$search_columns = array('user_login', 'user_nicename', 'display_name');
|
||||||
|
|
||||||
$this->query_where .= $this->get_search_sql( $search, $search_columns );
|
$this->query_where .= $this->get_search_sql( $search, $search_columns, $wild );
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->parse_meta_query( $qv );
|
$this->parse_meta_query( $qv );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user