Skip to:
Content

BuddyPress.org

Changeset 2285


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

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

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2282 r2285  
    249249        if ( $activity->component_name == $bp->groups->id ) {
    250250                if ( $activity->user_id )
    251                         $redirect = bp_core_get_userurl( $activity->user_id ) . $bp->activity->slug . '/' . $activity->id;
     251                        $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
    252252                else {
    253253                        if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
     
    255255                }
    256256        } else
    257                 $redirect = bp_core_get_userurl( $activity->user_id ) . $bp->activity->slug . '/' . $activity->id;
     257                $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
    258258
    259259        if ( !$redirect )
  • 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
  • trunk/bp-core/bp-core-classes.php

    r2284 r2285  
    6565                        $this->email = attribute_escape( $this->profile_data['user_email'] );
    6666                } else {
    67                         $this->user_url = bp_core_get_userurl( $this->id );
     67                        $this->user_url = bp_core_get_user_domain( $this->id );
    6868                        $this->user_link = bp_core_get_userlink( $this->id );
    6969                        $this->fullname = attribute_escape( bp_core_get_user_displayname( $this->id ) );
  • trunk/bp-core/bp-core-templatetags.php

    r2284 r2285  
    13111311        }
    13121312
     1313function bp_displayed_user_username() {
     1314        echo bp_get_displayed_user_username();
     1315}
     1316        function bp_get_displayed_user_username() {
     1317                global $bp;
     1318                return apply_filters( 'bp_get_displayed_user_username', bp_core_get_username( $bp->displayed_user->id, $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login ) );
     1319        }
     1320
     1321function bp_loggedin_user_username() {
     1322        echo bp_get_loggedin_user_username();
     1323}
     1324        function bp_get_loggedin_user_username() {
     1325                global $bp;
     1326                return apply_filters( 'bp_get_loggedin_user_username', bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ) );
     1327        }
     1328
    13131329function bp_current_component() {
    13141330        global $bp;
  • trunk/bp-friends.php

    r2276 r2285  
    313313                        } else {
    314314                                $user_fullname = bp_core_get_user_displayname( $item_id );
    315                                 $user_url = bp_core_get_userurl( $item_id );
     315                                $user_url = bp_core_get_domain( $item_id );
    316316                                return apply_filters( 'bp_friends_single_friendship_accepted_notification', '<a href="' . $user_url . '?new" title="' . $user_fullname .'\'s profile">' . sprintf( __( '%s accepted your friendship request', 'buddypress' ), $user_fullname ) . '</a>', $user_fullname );
    317317                        }
     
    323323                        } else {
    324324                                $user_fullname = bp_core_get_user_displayname( $item_id );
    325                                 $user_url = bp_core_get_userurl( $item_id );
     325                                $user_url = bp_core_get_user_domain( $item_id );
    326326                                return apply_filters( 'bp_friends_single_friendship_request_notification', '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/requests" title="' . __( 'Friendship requests', 'buddypress' ) . '">' . sprintf( __('You have a friendship request from %s', 'buddypress' ), $user_fullname ) . '</a>', $user_fullname );
    327327                        }
     
    419419                $friend_link = bp_core_get_userlink( $friendship->friend_user_id );
    420420
    421                 $primary_link = apply_filters( 'friends_activity_friendship_accepted_primary_link', bp_core_get_userurl( $friendship->initiator_user_id ), &$friendship );
     421                $primary_link = apply_filters( 'friends_activity_friendship_accepted_primary_link', bp_core_get_user_domain( $friendship->initiator_user_id ), &$friendship );
    422422
    423423                /* Record in activity streams for the initiator */
  • trunk/bp-friends/bp-friends-templatetags.php

    r2277 r2285  
    4444                        <?php for ( $i = 0; $i < count( $friend_ids ); $i++ ) { ?>
    4545                                <li>
    46                                         <a href="<?php echo bp_core_get_userurl( $friend_ids[$i] ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $friend_ids[$i], 'type' => 'thumb' ) ) ?></a>
     46                                        <a href="<?php echo bp_core_get_domain( $friend_ids[$i] ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $friend_ids[$i], 'type' => 'thumb' ) ) ?></a>
    4747                                        <h5><?php echo bp_core_get_userlink($friend_ids[$i]) ?></h5>
    4848                                </li>
     
    7171                <?php for ( $i = 0; $i < count( $user_ids['users'] ); $i++ ) { ?>
    7272                        <li>
    73                                 <a href="<?php echo bp_core_get_userurl( $user_ids['users'][$i]->user_id ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $user_ids['users'][$i]->user_id, 'type' => 'thumb' ) ) ?></a>
     73                                <a href="<?php echo bp_core_get_user_domain( $user_ids['users'][$i]->user_id ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $user_ids['users'][$i]->user_id, 'type' => 'thumb' ) ) ?></a>
    7474                                <h5><?php echo bp_core_get_userlink($user_ids['users'][$i]->user_id) ?></h5>
    7575                                <?php if ( function_exists( 'xprofile_get_random_profile_data' ) ) { ?>
  • trunk/bp-groups.php

    r2270 r2285  
    15111511
    15121512                        $group = new BP_Groups_Group( $group_id, false, false );
    1513                         $user_url = bp_core_get_userurl( $user_id );
     1513                        $user_url = bp_core_get_domain( $user_id );
    15141514
    15151515                        if ( (int)$total_items > 1 ) {
Note: See TracChangeset for help on using the changeset viewer.