Make WordPress Core


Ignore:
Timestamp:
11/13/2010 06:18:45 PM (14 years ago)
Author:
scribu
Message:

Split get_search_sql(). See #15170. See #15032

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/user.php

    r16286 r16351  
    527527    }
    528528
     529    /*
     530     * Used internally to generate an SQL string for searching across multiple columns
     531     *
     532     * @access protected
     533     * @since 3.1.0
     534     *
     535     * @param string $string
     536     * @param array $cols
     537     * @param bool $wild Whether to allow trailing wildcard searches. Default is false.
     538     * @return string
     539     */
     540    function get_search_sql( $string, $cols, $wild = false ) {
     541        $string = esc_sql( $string );
     542
     543        $searches = array();
     544        $wild_char = ( $wild ) ? '%' : '';
     545        foreach ( $cols as $col ) {
     546            if ( 'ID' == $col )
     547                $searches[] = "$col = '$string'";
     548            else
     549                $searches[] = "$col LIKE '$string$wild_char'";
     550        }
     551
     552        return ' AND (' . implode(' OR ', $searches) . ')';
     553    }
     554
    529555    /**
    530556     * Return the list of users
Note: See TracChangeset for help on using the changeset viewer.