Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/23/2014 05:56:57 PM (11 years ago)
Author:
djpaul
Message:

Core: add new search_wildcard parameter to BP_User_Query.

This new parameter controls where BuddyPress places MySQL wildcard characters around the search term (when it's set).
Prior to this change, BuddyPress added a wildcard character to both ends of the search term, but for some use cases, a more restrictive search pattern is required; you can specify "left", "right", or "both" (the default) to pick where the wildcard is added.

Fixes #5769

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-functions.php

    r8672 r8675  
    596596    $search_terms_clean = esc_sql( esc_sql( $query->query_vars['search_terms'] ) );
    597597
     598    if ( $query->query_vars['search_wildcard'] === 'left' ) {
     599        $search_terms_clean = '%' . $search_terms_clean;
     600    } elseif ( $query->query_vars['search_wildcard'] === 'right' ) {
     601        $search_terms_clean = $search_terms_clean . '%';
     602    } else {
     603        $search_terms_clean = '%' . $search_terms_clean . '%';
     604    }
     605
    598606    // Combine the core search (against wp_users) into a single OR clause
    599607    // with the xprofile_data search
    600608    $search_core     = $sql['where']['search'];
    601     $search_xprofile = "u.{$query->uid_name} IN ( SELECT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE '%{$search_terms_clean}%' )";
     609    $search_xprofile = "u.{$query->uid_name} IN ( SELECT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE '{$search_terms_clean}' )";
    602610    $search_combined = "( {$search_xprofile} OR {$search_core} )";
    603611
Note: See TracChangeset for help on using the changeset viewer.