Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding User Profile Button

  • @vivnt

    Participant

    I want to add a button that takes the user to their profile, similar to the login widget. However, I want to place it near the search bar on the “all forums” section or next to the subscribe button. I don’t want to place a widget on the sidebar because I want the forum to be full width. Can anyone help?

Viewing 12 replies - 1 through 12 (of 12 total)
  • @robin-w

    Moderator

    This should do what you want

    //add profile link to forums
    add_action ( 'bbp_template_before_single_forum', 'rew_profile_link' ) ;
    add_action ( 'bbp_template_before_forums_index', 'rew_profile_link' ) ;
    
    function rew_profile_link () {
    	if (!is_user_logged_in())
    		return ;
    	$current_user = wp_get_current_user();
    		$user=$current_user->user_nicename  ;
    		$user_slug =  get_option( '_bbp_user_slug' ) ;
    			if (get_option( '_bbp_include_root' ) == true  ) {	
    			$forum_slug = get_option( '_bbp_root_slug' ) ;
    			$slug = $forum_slug.'/'.$user_slug.'/' ;
    			}
    			else {
    			$slug=$user_slug . '/' ;
    			}
    			$edit_profile = __('Edit Profile', 'bbp-style-pack') ;
    			//get url
    			$url = get_site_url(); 
    			$profilelink = '<a href="'. $url .'/' .$slug. $user . '/edit">'.$edit_profile.'</a>';
    			echo '<div style="text-align: center;">'.$profilelink ;
    }

    add it to your functions file

    https://codex.bbpress.org/functions-files-and-child-themes-explained/

    @robkk

    Moderator

    Robin there is a few functions already in bbPress that might be useful to use, and it might cut some of your code some.

    http://hookr.io/plugins/bbpress/2.5.8/#index=u&search=bbp_user_profile

    @robin-w

    Moderator

    @robkk – I’m just trying to help someone, not trying to get the most efficient code 🙂

    @vivnt

    Participant

    @robin-w Thank you so much! I was wondering if you could help me just a bit more. I want to change the link to main profile page & add the avatar to the left of the link.

    @robin-w

    Moderator

    This code will do that

    //add profile link to forums
    add_action ( 'bbp_template_before_single_forum', 'rew_profile_link' ) ;
    add_action ( 'bbp_template_before_forums_index', 'rew_profile_link' ) ;
    
    function rew_profile_link () {
    	if (!is_user_logged_in())
    		return ;
    	$current_user = wp_get_current_user();
    	$user=$current_user->ID  ;
    	$profile = 'Profile' ;
    	$user_link = '<a href="' . esc_url( bbp_get_user_profile_url( $user) ) . '">' . $profile . '</a>';
    	echo '<div style="text-align: center;">'.$user_link.'</div>';
    }

    @indigoo

    Participant

    Where would this code be added? I’m trying to do the same by adding it to my child theme’s bbpress.php file, but is just showing the raw code on the page. I may be in the wrong file, or else have something else missing. Thanks if you can direct.

    @robin-w

    Moderator

    yes it goes in the functions file of your child theme

    Functions files and child themes – explained !

    @paul899

    Participant

    Thanks for advice. I’ve been looking for it, but nowhere can find it, hopefully here come across:) thanks

    @indigoo

    Participant

    EDITED: I first added the second code snippet you provided, then realized I needed to other one, so I deleted that second snippet and used the first at the end of the functions.php file in my child theme. It does not place a small “edit profile” link centered at the top of my forum main page, which is a help (thanks), but it also places the following text at the bottom of my members home page when logged in: “Click edit button to change this code.”

    That is not a clickable link and it is also not in the right location. Also, I can’t see where that specific text is being defined to edit the wording, which I’d want if it was a working link. It would be great to also have the edit link on the members home page, not just the forum main page, or even better to be able to add it to the sidebar that shows on all member area pages, but at least I’d like to remove this text from the non-forum page.

    Thanks in advance if you can sort this.

    @indigoo

    Participant

    I was trying to say, “It does NOW place a small edit link.” It is working on that page, just also putting that stray text on another page too.

    I did manage to change the placement of the “edit profile” link on the forum page to get it to be right align. I guess this only shows on the main forums page and individual forum pages, not on topic pages.

    All I really need to do now is to get the extra text removed from the other members area page it was added to.

    @indigoo

    Participant

    Oh, wait. I got that one too! LOL

    I found that a code block had been added to my member home page by the second code snippet. I deleted that block and all good now.

    Thanks for your help!

    @robin-w

    Moderator

    great – glad you’re fixed !

Viewing 12 replies - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.
Skip to toolbar