Skip to:
Content

BuddyPress.org


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

Introduce bp_core_user_displaynames(), for quick, bulk displayname lookup

The technique BP uses for determining a user's displayname takes into
consideration whether the xprofile component is active, whether the user has a
WP display_name, and a number of other factors. Because the values are used so
often throughout BP, they are then cached in WP's object cache. However, there
are a number of places throughout BuddyPress where displaynames are fetched
in a way that is inconsistent with the "canonical" workflow (ie, by querying
the xprofile tables correctly). This causes inconsistent results, and also can
result in performance degradation when the persistent cache is skipped.
Moreover, the singular nature of bp_core_get_user_displayname() meant that
doing it the "right" way meant introducing large numbers of queries to a given
page load.

This changeset introduces bp_core_get_user_displaynames(), which contains all
the critical logic of bp_core_get_user_displayname() - including fallbacks for
various setups and support for the object cache - but allows for fetching large
numbers of displaynames without multiple queries. bp_core_get_user_displayname()
is now a wrapper for the more general function.

The function has been swapped in throughout BuddyPress as appropriate.

See #5445

File:
1 edited

Legend:

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

    r7862 r8027  
    216216
    217217    // Pull up the xprofile fullname of each commenter
    218     if ( $fullnames = BP_XProfile_ProfileData::get_value_byid( 1, $user_ids ) ) {
    219         foreach( (array) $fullnames as $user ) {
    220             $users[ $user->user_id ] = trim( stripslashes( $user->value ) );
     218    if ( $fullnames = bp_core_get_user_displaynames( $user_ids ) ) {
     219        foreach( (array) $fullnames as $user_id => $user_fullname ) {
     220            $users[ $user_id ] = trim( stripslashes( $user_fullname ) );
    221221        }
    222222    }
     
    252252    }
    253253
    254     $user_id_names = BP_XProfile_ProfileData::get_value_byid( bp_xprofile_fullname_field_id(), $user_query->user_ids );
     254    $user_id_names = bp_core_get_user_displaynames( $user_query->user_ids );
    255255
    256256    // Loop through names and override each user's fullname
    257     foreach ( $user_id_names as $user ) {
    258         if ( isset( $user_query->results[ $user->user_id ] ) ) {
    259             $user_query->results[ $user->user_id ]->fullname = $user->value;
     257    foreach ( $user_id_names as $user_id => $user_fullname ) {
     258        if ( isset( $user_query->results[ $user_id ] ) ) {
     259            $user_query->results[ $user_id ]->fullname = $user_fullname;
    260260        }
    261261    }
Note: See TracChangeset for help on using the changeset viewer.