Skip to:
Content

BuddyPress.org

Changeset 6249


Ignore:
Timestamp:
08/08/2012 05:13:00 PM (14 years ago)
Author:
boonebgorges
Message:

Moves bp_displayed_user_id() and bp_loggedin_user_id() to Core component

The function bp_displayed_user_id() and bp_loggedin_user_id() are referenced
throughout BuddyPress's Core component when doing things like checking page
type. In certain circumstances, these checks might happen after the Core
component is loaded, but before the Members component is loaded. For this
reason, it's important that the functions live in Core rather than Members,
to avoid fatal errors.

Fixes #4403

Props steve7777

Location:
trunk
Files:
2 edited

Legend:

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

    r6198 r6249  
    752752        }
    753753
     754/**
     755 * Get the id of the currently displayed user
     756 *
     757 * @uses apply_filters() Filter 'bp_displayed_user_id' to change this value
     758 * @return int
     759 */
     760function bp_displayed_user_id() {
     761
     762        static $id = 0;
     763
     764        if ( empty( $id ) ) {
     765                global $bp;
     766                $id = !empty( $bp->displayed_user->id ) ? $bp->displayed_user->id : 0;
     767        }
     768
     769        return apply_filters( 'bp_displayed_user_id', $id );
     770}
     771
     772/**
     773 * Get the id of the currently logged-in user
     774 *
     775 * @uses apply_filters() Filter 'bp_loggedin_user_id' to change this value
     776 * @return int
     777 */
     778function bp_loggedin_user_id() {
     779
     780        static $id = 0;
     781
     782        if ( empty( $id ) ) {
     783                global $bp;
     784                $id = !empty( $bp->loggedin_user->id ) ? $bp->loggedin_user->id : 0;
     785        }
     786
     787        return apply_filters( 'bp_loggedin_user_id', $id );
     788}
     789
    754790/** is_() functions to determine the current page *****************************/
    755791
  • trunk/bp-members/bp-members-template.php

    r6152 r6249  
    863863        }
    864864        function bp_user_link() { bp_displayed_user_domain(); } // Deprecated.
    865 
    866 function bp_displayed_user_id() {
    867 
    868         static $id = 0;
    869 
    870         if ( empty( $id ) ) {
    871                 global $bp;
    872                 $id = !empty( $bp->displayed_user->id ) ? $bp->displayed_user->id : 0;
    873         }
    874 
    875         return apply_filters( 'bp_displayed_user_id', $id );
    876 }
    877 
    878 function bp_loggedin_user_id() {
    879 
    880         static $id = 0;
    881 
    882         if ( empty( $id ) ) {
    883                 global $bp;
    884                 $id = !empty( $bp->loggedin_user->id ) ? $bp->loggedin_user->id : 0;
    885         }
    886 
    887         return apply_filters( 'bp_loggedin_user_id', $id );
    888 }
    889865
    890866function bp_current_user_id() { return bp_displayed_user_id(); }
Note: See TracChangeset for help on using the changeset viewer.