Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

Creating a link to the member page (5 posts)

Started 2 years, 8 months ago by: carinallc

  • Profile picture of carinallc carinallc said 2 years, 8 months ago:

    I’d like to create a link to the member’s homepage. Does anyone know of a function that would return that link? For example, “www.fubar.com/members/[username]“?

    Thanks

  • Profile picture of Greg Greg said 2 years, 8 months ago:

    Here is what I do (in BP 1.0.3):

    function _profile_url( $login_name=0 ) {
    	global $bp;
    
    	/* if no login name is specified, use logged in user */
    	if ($login_name) {
    		$url = $bp->root_domain . '/members/' . $login_name . '/profile';
    	} else {
    		$url = $bp->loggedin_user->domain . 'profile';
    	}	
    
    	return $url;
    }
  • Profile picture of carinallc carinallc said 2 years, 8 months ago:

    Wow, hey thank you for responding! So, would I add this to the functions.php and then call it as:

    <?php _profile_url(); ?>

  • Profile picture of Greg Greg said 2 years, 8 months ago:

    Yes. That will give you the profile URL for the currently logged in member. But if all you want is a link to the currently logged in user, then you could use the bp_loggedinuser_link() tag. Note that this returns a LINK (i.e. <a href=”… etc.) and not just a URL. Just put…

    <?php bp_loggedinuser_link(); ?>

    …in your template where you want the link.

    If you do call my _profile_url() above to get the URL for a specific user, then note that you must provide the login name. So it depends what you have to begin with. Let’s say you have the user ID, then you need to get the login name as follows:

    $user = get_userdata( $user_id );
    $url =  _profile_url( $user->user_login );

    And while we’re at it, if you want the URL for the displayed user, you can get it using…

    global $bp;
    return $bp->displayed_user->domain;
  • Profile picture of porkchops1987 porkchops1987 said 8 months, 1 week ago:

    @Greg thank you so much. something so simple but so useful when creating our own templates. I dont know if you still participate in these forums but thanks nonetheless.