Get just the logged in user url for BuddyPress


There are two functions here,

the first one will return the user url for a specified ID

function bp_core_get_justuserlink( $user_id, $no_anchor = false, $just_link = true, $deprecated = false, $with_s = false ) {
 global $userdata;
 $ud = get_userdata($user_id);
 if ( !$ud )
 return false;
 if ( function_exists('bp_fetch_user_fullname') ) {
 $display_name = bp_core_get_user_displayname( $user_id );
 if ( $with_s )
 $display_name = sprintf( __( "%s's", 'buddypress' ), $display_name );
 } else {
 $display_name = $ud->display_name;
 }
 if ( $no_anchor )
 return $display_name;
 if ( !$url = bp_core_get_userurl($user_id) )
 return false;

 if ( $just_link )
 return $url;
 return $url;
}

The second function will use the first, but get the url of the currently logged in user.

function bp_get_loggedinuser_link() {
 global $bp;

 if ( $link = bp_core_get_justuserlink( $bp->loggedin_user->id ) ) {
 return $link;
 }
 }

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *