Skip to:
Content

BuddyPress.org

Changeset 7348


Ignore:
Timestamp:
08/12/2013 10:41:46 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Update bp_core_get_username() to check explicit false return on wp_cache_get() per best practices.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-members/bp-members-functions.php

    r7334 r7348  
    216216 * @package BuddyPress Core
    217217 * @param int $uid User ID to check.
    218  * @global $userdata WordPress user data for the current logged in user.
    219  * @uses get_userdata() WordPress function to fetch the userdata for a user ID
     218 * @uses bp_core_get_core_userdata() Fetch the userdata for a user ID
    220219 * @return string|bool The username of the matched user, or false.
    221220 */
    222 function bp_core_get_username( $user_id, $user_nicename = false, $user_login = false ) {
    223         global $bp;
    224 
    225         if ( !$username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' ) ) {
     221function bp_core_get_username( $user_id = 0, $user_nicename = false, $user_login = false ) {
     222        $bp = buddypress();
     223
     224        // Check cache for user nicename
     225        $username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' );
     226        if ( false === $username ) {
    226227
    227228                // Cache not found so prepare to update it
     
    270271
    271272        // Check $username for empty spaces and default to nicename if found
    272         if ( strstr( $username, ' ' ) )
     273        if ( strstr( $username, ' ' ) ) {
    273274                $username = bp_members_get_user_nicename( $user_id );
     275        }
    274276
    275277        // Add this to cache
    276         if ( ( true == $update_cache ) && !empty( $username ) )
     278        if ( ( true === $update_cache ) && !empty( $username ) ) {
    277279                wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );
     280
     281        // @todo bust this cache if no $username found?
     282        //} else {
     283        //      wp_cache_delete( 'bp_user_username_' . $user_id );
     284        }
    278285
    279286        return apply_filters( 'bp_core_get_username', $username );
Note: See TracChangeset for help on using the changeset viewer.