From 4bebab39b1ba516fb8ae362da4dad6a938a04cb4 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 3 Nov 2010 19:31:11 +0000 Subject: [PATCH] Allow trailing wildcard user searches by appending *. see #15170 git-svn-id: http://svn.automattic.com/wordpress/trunk@16170 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-object-query.php | 6 ++++-- wp-includes/user.php | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-object-query.php b/wp-includes/class-wp-object-query.php index 240d68de1..7798cd00b 100644 --- a/wp-includes/class-wp-object-query.php +++ b/wp-includes/class-wp-object-query.php @@ -227,17 +227,19 @@ class WP_Object_Query { * * @param string $string * @param array $cols + * @param bool $wild Whether to allow trailing wildcard searches. Default is false. * @return string */ - function get_search_sql( $string, $cols ) { + function get_search_sql( $string, $cols, $wild = false ) { $string = esc_sql( $string ); $searches = array(); + $wild_char = ( $wild ) ? '%' : ''; foreach ( $cols as $col ) { if ( 'ID' == $col ) $searches[] = "$col = '$string'"; else - $searches[] = "$col LIKE '$string%'"; + $searches[] = "$col LIKE '$string$wild_char'"; } return ' AND (' . implode(' OR ', $searches) . ')'; diff --git a/wp-includes/user.php b/wp-includes/user.php index 6734f1514..1120143f5 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -446,6 +446,11 @@ class WP_User_Query extends WP_Object_Query { $search = trim( $qv['search'] ); if ( $search ) { + $wild = false; + if ( false !== strpos($search, '*') ) { + $wild = 'true'; + $search = trim($search, '*'); + } if ( false !== strpos( $search, '@') ) $search_columns[] = array('user_email'); elseif ( is_numeric($search) ) @@ -455,7 +460,7 @@ class WP_User_Query extends WP_Object_Query { else $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 );