Make WordPress Core

Changeset 19882


Ignore:
Timestamp:
02/08/2012 09:48:47 PM (13 years ago)
Author:
nacin
Message:

Add search_columns arg to WP_User_Query to allow for explicit column choices. Without it, the columns will be detected based on the search term. see #19810.

File:
1 edited

Legend:

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

    r19735 r19882  
    379379                'exclude' => array(),
    380380                'search' => '',
     381                'search_columns' => array(),
    381382                'orderby' => 'login',
    382383                'order' => 'ASC',
     
    477478                $search = trim($search, '*');
    478479
    479             if ( false !== strpos( $search, '@') )
    480                 $search_columns = array('user_email');
    481             elseif ( is_numeric($search) )
    482                 $search_columns = array('user_login', 'ID');
    483             elseif ( preg_match('|^https?://|', $search) )
    484                 $search_columns = array('user_url');
    485             else
    486                 $search_columns = array('user_login', 'user_nicename');
     480            $search_columns = array();
     481            if ( $qv['search_columns'] )
     482                $search_columns = array_intersect( $qv['search_columns'], array( 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename' ) );
     483            if ( ! $search_columns ) {
     484                if ( false !== strpos( $search, '@') )
     485                    $search_columns = array('user_email');
     486                elseif ( is_numeric($search) )
     487                    $search_columns = array('user_login', 'ID');
     488                elseif ( preg_match('|^https?://|', $search) )
     489                    $search_columns = array('user_url');
     490                else
     491                    $search_columns = array('user_login', 'user_nicename');
     492            }
    487493
    488494            $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild );
Note: See TracChangeset for help on using the changeset viewer.