Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/09/2014 01:58:11 PM (11 years ago)
Author:
boonebgorges
Message:

BP_User_Query search_terms should match against user_login and user_nicename in addition to xprofile fields

This changeset changes the search_terms logic in BP_User_Query so that it
matches user_login and user_nicename in the core users table. Then, via filter,
the xprofile component amends the WHERE clause so that search_terms are matched
in the users table OR the xprofile data table.

Clauses have been refactored to subqueries rather than storing the matched
user IDs in PHP, for improved performance.

See #5155

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-classes.php

    r8054 r8087  
    362362        /** Search Terms ******************************************************/
    363363
    364         // 'search_terms' searches the xprofile fields
    365         // To avoid global joins, do a separate query
    366         // @todo remove need for bp_is_active() check
    367         if ( false !== $search_terms && bp_is_active( 'xprofile' ) ) {
     364        // 'search_terms' searches user_login and user_nicename
     365        // xprofile field matches happen in bp_xprofile_bp_user_query_search()
     366        if ( false !== $search_terms ) {
    368367            $search_terms_clean = esc_sql( esc_sql( $search_terms ) );
    369             $search_terms_clean = like_escape( $search_terms_clean );
    370             $found_user_ids_query = "SELECT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE '%" . $search_terms_clean . "%'";
    371             $found_user_ids = $wpdb->get_col( $found_user_ids_query );
    372 
    373             if ( ! empty( $found_user_ids ) ) {
    374                 $sql['where'][] = "u.{$this->uid_name} IN (" . implode( ',', wp_parse_id_list( $found_user_ids ) ) . ")";
    375             } else {
    376                 $sql['where'][] = $this->no_results['where'];
    377             }
     368            $sql['where']['search'] = "u.{$this->uid_name} IN ( SELECT ID FROM {$wpdb->users} WHERE ( user_login LIKE '%{$search_terms_clean}%' OR user_nicename LIKE '%{$search_terms_clean}%' ) )";
    378369        }
    379370
     
    400391            $sql['limit'] = '';
    401392        }
     393
     394        // Allow custom filters
     395        $sql = apply_filters_ref_array( 'bp_user_query_uid_clauses', array( $sql, &$this ) );
    402396
    403397        // Assemble the query chunks
Note: See TracChangeset for help on using the changeset viewer.