Skip to:
Content

BuddyPress.org

Changeset 2285 for trunk/bp-core.php


Ignore:
Timestamp:
01/10/2010 11:38:25 AM (16 years ago)
Author:
apeatling
Message:

Updating user_domain() fetching and caching and removing any duplication with userurl().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core.php

    r2276 r2285  
    537537    if ( !$user_id ) return;
    538538
    539     if ( $domain = wp_cache_get( 'bp_user_domain_' . $user_id, 'bp' ) )
    540         return apply_filters( 'bp_core_get_user_domain', $domain );
    541 
    542     if ( !$user_nicename && !$user_login ) {
    543         $ud = get_userdata($user_id);
    544         $user_nicename = $ud->user_nicename;
    545         $user_login = $ud->user_login;
    546     }
    547 
    548     if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
    549         $username = $user_login;
    550     else
    551         $username = $user_nicename;
    552 
    553     /* If we are using a members slug, include it. */
    554     if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
    555         $domain = $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/';
    556     else
    557         $domain = $bp->root_domain . '/' . $username . '/';
    558 
    559     /* Cache the link */
    560     wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
     539    if ( !$domain = wp_cache_get( 'bp_user_domain_' . $user_id, 'bp' ) ) {
     540        $username = bp_core_get_username( $user_id, $user_nicename, $user_login );
     541
     542        /* If we are using a members slug, include it. */
     543        if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
     544            $domain = $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/';
     545        else
     546            $domain = $bp->root_domain . '/' . $username . '/';
     547
     548        /* Cache the link */
     549        wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
     550    }
    561551
    562552    return apply_filters( 'bp_core_get_user_domain', $domain );
    563553}
     554/* DEPRECATED */
     555function bp_core_get_userurl( $uid ) { return bp_core_get_user_domain( $uid ); }
    564556
    565557/**
     
    992984 * @return str the username of the matched user.
    993985 */
    994 function bp_core_get_username( $uid ) {
    995     global $userdata;
    996 
    997     if ( $uid == $userdata->ID )
    998         $username =  __( 'You', 'buddypress' );
    999 
    1000     if ( !$ud = get_userdata($uid) )
    1001         return false;
    1002 
    1003     $username = $ud->user_login;
     986function bp_core_get_username( $uid, $user_nicename = false, $user_login = false ) {
     987    global $bp;
     988
     989    if ( !$username = wp_cache_get( 'bp_user_username_' . $uid, 'bp' ) ) {
     990        if ( empty( $user_nicename ) && empty( $user_login ) ) {
     991            $ud = false;
     992
     993            if ( $bp->loggedin_user->id == $uid )
     994                $ud = &$bp->loggedin_user->userdata;
     995
     996            if ( $bp->displayed_user->id == $uid )
     997                $ud = &$bp->displayed_user->userdata;
     998
     999            if ( empty( $ud ) ) {
     1000                if ( !$ud = bp_core_get_core_userdata($uid) )
     1001                    return false;
     1002
     1003                $user_nicename = $ud->user_nicename;
     1004                $user_login = $ud->user_login;
     1005            }
     1006        }
     1007
     1008        if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
     1009            $username = $user_login;
     1010        else
     1011            $username = $user_nicename;
     1012    }
     1013
     1014    /* Add this to cache */
     1015    wp_cache_set( 'bp_user_username_' . $uid, 'bp' );
    10041016
    10051017    return apply_filters( 'bp_core_get_username', $username );
    1006 }
    1007 
    1008 /**
    1009  * bp_core_get_userurl()
    1010  *
    1011  * Returns the URL with no HTML markup for a user based on their user id.
    1012  *
    1013  * @package BuddyPress Core
    1014  * @param $uid int User ID to check.
    1015  * @global $userdata WordPress user data for the current logged in user.
    1016  * @uses get_userdata() WordPress function to fetch the userdata for a user ID
    1017  * @return false on no match
    1018  * @return str The URL for the user with no HTML formatting.
    1019  */
    1020 function bp_core_get_userurl( $uid ) {
    1021     global $bp;
    1022 
    1023     if ( !$url = wp_cache_get( 'bp_user_url_' . $uid, 'bp' ) ) {
    1024         $url = bp_core_get_user_domain( $uid );
    1025     }
    1026 
    1027     return apply_filters( 'bp_core_get_userurl', $url );
    10281018}
    10291019
     
    10821072        return $display_name;
    10831073
    1084     if ( !$url = bp_core_get_userurl($user_id) )
     1074    if ( !$url = bp_core_get_user_domain($user_id) )
    10851075        return false;
    10861076
Note: See TracChangeset for help on using the changeset viewer.