Make WordPress Core

Changeset 17189


Ignore:
Timestamp:
12/30/2010 11:38:21 PM (14 years ago)
Author:
ryan
Message:

Default to leading and trailing wildcards for site user searches. Require explicit trailing wildcard asterisk request for network user searches. Disallow leading wildcards for network user searches. Move wildcard policy up the stake, allowing more flexibility in WP_User_Query. Props SergeyBiryukov. fixes #16014

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-ms-users-list-table.php

    r17013 r17189  
    3131            'fields' => 'all_with_meta'
    3232        );
     33
     34        $args['search'] = ltrim($args['search'], '*');
    3335
    3436        if ( $role == 'super' ) {
  • trunk/wp-admin/includes/class-wp-users-list-table.php

    r17102 r17189  
    5151            'fields' => 'all_with_meta'
    5252        );
     53
     54        $args['search'] = '*' . $args['search'] . '*';
    5355
    5456        if ( $this->is_site_users )
  • trunk/wp-includes/user.php

    r17170 r17189  
    466466        $search = trim( $qv['search'] );
    467467        if ( $search ) {
    468             $wild = false;
    469             if ( false !== strpos($search, '*') ) {
    470                 $wild = true;
     468            $leading_wild = ( ltrim($search, '*') != $search );
     469            $trailing_wild = ( rtrim($search, '*') != $search );
     470            if ( $leading_wild && $trailing_wild )
     471                $wild = 'both';
     472            elseif ( $leading_wild )
     473                $wild = 'leading';
     474            elseif ( $trailing_wild )
     475                $wild = 'trailing';
     476            else
     477                $wild = false;
     478            if ( $wild )
    471479                $search = trim($search, '*');
    472             }
     480
    473481            if ( false !== strpos( $search, '@') )
    474482                $search_columns = array('user_email');
     
    565573     * @param string $string
    566574     * @param array $cols
    567      * @param bool $wild Whether to allow trailing wildcard searches. Default is false.
     575     * @param bool $wild Whether to allow wildcard searches. Default is false for Network Admin, true for
     576     *  single site. Single site allows leading and trailing wildcards, Network Admin only trailing.
    568577     * @return string
    569578     */
     
    572581
    573582        $searches = array();
    574         $wild_char = ( $wild ) ? '%' : '';
     583        $leading_wild = ( 'leading' == $wild || 'both' == $wild ) ? '%' : '';
     584        $trailing_wild = ( 'trailing' == $wild || 'both' == $wild ) ? '%' : '';
    575585        foreach ( $cols as $col ) {
    576586            if ( 'ID' == $col )
    577587                $searches[] = "$col = '$string'";
    578588            else
    579                 $searches[] = "$col LIKE '" . like_escape($string) . "$wild_char'";
     589                $searches[] = "$col LIKE '$leading_wild" . like_escape($string) . "$trailing_wild'";
    580590        }
    581591
Note: See TracChangeset for help on using the changeset viewer.