WordPress.org

Make WordPress Core

Changeset 16170


Ignore:
Timestamp:
11/03/2010 07:31:11 PM (10 years ago)
Author:
ryan
Message:

Allow trailing wildcard user searches by appending *. see #15170

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-object-query.php

    r16168 r16170  
    228228     * @param string $string
    229229     * @param array $cols
     230     * @param bool $wild Whether to allow trailing wildcard searches. Default is false.
    230231     * @return string
    231232     */
    232     function get_search_sql( $string, $cols ) {
     233    function get_search_sql( $string, $cols, $wild = false ) {
    233234        $string = esc_sql( $string );
    234235
    235236        $searches = array();
     237        $wild_char = ( $wild ) ? '%' : '';
    236238        foreach ( $cols as $col ) {
    237239            if ( 'ID' == $col )
    238240                $searches[] = "$col = '$string'";
    239241            else
    240                 $searches[] = "$col LIKE '$string%'";
     242                $searches[] = "$col LIKE '$string$wild_char'";
    241243        }
    242244
  • trunk/wp-includes/user.php

    r16168 r16170  
    447447        $search = trim( $qv['search'] );
    448448        if ( $search ) {
     449            $wild = false;
     450            if ( false !== strpos($search, '*') ) {
     451                $wild = 'true';
     452                $search = trim($search, '*');
     453            }
    449454            if ( false !== strpos( $search, '@') )
    450455                $search_columns[] = array('user_email');
     
    456461                $search_columns = array('user_login', 'user_nicename', 'display_name');
    457462
    458             $this->query_where .= $this->get_search_sql( $search, $search_columns );
     463            $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild );
    459464        }
    460465
Note: See TracChangeset for help on using the changeset viewer.