Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/07/2012 02:14:42 AM (12 years ago)
Author:
boonebgorges
Message:

Introduces BP_User_Query for improved member query performance

  • Introduces BP_User_Query class
  • Deprecates use of BP_Core_User::get_users() in bp_core_get_users(), the main member query function in BuddyPress
  • Introduces bp_use_legacy_user_query filter, to allow plugins to use legacy query method during transition
  • Expands user query functionality to support 'user_ids' parameter, which can be used to skip the user_id query altogether, for maximum flexibility in plugins and themes

Props boonebgorges, johnjamesjacoby.

See #4060

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-filters.php

    r6224 r6314  
    220220add_filter( 'comments_array', 'xprofile_filter_comments', 10, 2 );
    221221
    222 
     222/**
     223 * Filter BP_User_Query::populate_extras to override each queries users fullname
     224 *
     225 * @since BuddyPress (1.7)
     226 *
     227 * @global BuddyPress $bp
     228 * @global WPDB $wpdb
     229 * @param BP_User_Query $user_query
     230 * @param string $user_ids_sql
     231 */
     232function bp_xprofile_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql ) {
     233    global $bp, $wpdb;
     234
     235    if ( bp_is_active( 'xprofile' ) ) {
     236        $fullname_field_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", bp_xprofile_fullname_field_name() ) );
     237        $user_id_names     = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value as fullname FROM {$bp->profile->table_name_data} WHERE user_id IN ({$user_ids_sql}) AND field_id = {$fullname_field_id}" ) );
     238
     239        // Loop through names and override each user's fullname
     240        foreach ( $user_id_names as $user ) {
     241            if ( isset( $user_query->results[ $user->user_id ] ) ) {
     242                $user_query->results[ $user->user_id ]->fullname = $user->fullname;
     243            }
     244        }
     245    }
     246}
     247add_filter( 'bp_user_query_populate_extras', 'bp_xprofile_filter_user_query_populate_extras', 2, 2 );
    223248
    224249?>
Note: See TracChangeset for help on using the changeset viewer.