Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/08/2011 01:14:31 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Use bp_displayed_user_id() rather than reference the $bp->displayed_user->id global var directly. First step at consolidating user ID checks to use WP_User class later. See #3738.

File:
1 edited

Legend:

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

    r5271 r5301  
    282282
    283283    // User filtering
    284     if ( !empty( $bp->displayed_user->id ) )
    285         $user_id = $bp->displayed_user->id;
     284    if ( bp_displayed_user_id() )
     285        $user_id = bp_displayed_user_id();
    286286
    287287    // type: active ( default ) | random | newest | popular | online | alphabetical
     
    610610        if ( !empty( $members_template->member->id ) )
    611611            $user_id = $members_template->member->id;
    612         elseif ( !empty( $bp->displayed_user->id ) )
    613             $user_id = $bp->displayed_user->id;
     612        elseif ( bp_displayed_user_id() )
     613            $user_id = bp_displayed_user_id();
    614614
    615615        $defaults = array(
     
    716716           then check to see if the two users are friends. if they are, add a highlight CSS class
    717717           to the friends nav item if it exists. */
    718         if ( !bp_is_my_profile() && $bp->displayed_user->id ) {
     718        if ( !bp_is_my_profile() && bp_displayed_user_id() ) {
    719719            $selected = '';
    720720
    721721            if ( bp_is_active( 'friends' ) ) {
    722722                if ( $nav_item['css_id'] == $bp->friends->id ) {
    723                     if ( friends_check_friendship( $bp->loggedin_user->id, $bp->displayed_user->id ) )
     723                    if ( friends_check_friendship( $bp->loggedin_user->id, bp_displayed_user_id() ) )
    724724                        $selected = ' class="current selected"';
    725725                }
     
    804804        extract( $r, EXTR_SKIP );
    805805
    806         return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html, 'alt' => $alt ) ) );
     806        return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( array( 'item_id' => bp_displayed_user_id(), 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html, 'alt' => $alt ) ) );
    807807    }
    808808
     
    829829
    830830        if ( empty( $user_id ) )
    831             $user_id = $bp->displayed_user->id;
     831            $user_id = bp_displayed_user_id();
    832832
    833833        $last_activity = bp_core_get_last_activity( bp_get_user_meta( $user_id, 'last_activity', true ), __('active %s', 'buddypress') );
     
    871871
    872872function bp_displayed_user_id() {
    873     global $bp;
    874     return apply_filters( 'bp_displayed_user_id', !empty( $bp->displayed_user->id ) ? $bp->displayed_user->id : 0 );
     873   
     874    static $id = 0;
     875   
     876    if ( empty( $id ) ) {
     877        global $bp;
     878        $id = !empty( $bp->displayed_user->id ) ? $bp->displayed_user->id : 0;
     879    }
     880
     881    return apply_filters( 'bp_displayed_user_id', $id );
    875882}
    876883    function bp_current_user_id() { return bp_displayed_user_id(); }
    877884
    878885function bp_loggedin_user_id() {
    879     global $bp;
    880     return apply_filters( 'bp_loggedin_user_id', !empty( $bp->loggedin_user->id ) ? $bp->loggedin_user->id : 0 );
     886
     887    static $id = 0;
     888   
     889    if ( empty( $id ) ) {
     890        global $bp;
     891        $id = !empty( $bp->loggedin_user->id ) ? $bp->loggedin_user->id : 0;
     892    }
     893
     894    return apply_filters( 'bp_loggedin_user_id', $id );
    881895}
    882896
     
    915929        global $bp;
    916930
    917         if ( !empty( $bp->displayed_user->id ) ) {
    918             $username = bp_core_get_username( $bp->displayed_user->id, $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login );
     931        if ( bp_displayed_user_id() ) {
     932            $username = bp_core_get_username( bp_displayed_user_id(), $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login );
    919933        } else {
    920934            $username = '';
     
    11711185
    11721186        // Must be displayed user
    1173         if ( empty( $bp->displayed_user->id ) )
     1187        if ( !bp_displayed_user_id() )
    11741188            return;
    11751189
Note: See TracChangeset for help on using the changeset viewer.