Skip to:
Content
Pages
Categories
Search
Top
Bottom

Is there any way to get forum root slug field value?


  • fakrulislam
    Participant

    @fakrulislam

    Hi, I am trying to add forum user profile link into wp_nav_menu_items.
    Is there any way to get the forum root slug field value dynamically (just like user nickname, see $user in below code) to making the profile link dynamic? I am thinking to adding a setting option for getting the forum root slug from users in case no way to get the forum root slug fieled value.

    Could anyone help? Thanks in advance.

    /**
    * Add bbp user profile link in WP nav menu
    * Filter wp_nav_menu() to add profile link
    */
    function prefix_bbp_profile_link_nav_menu($menu) {
    	
        if ( !is_user_logged_in() )
            return $menu;
        else
    	$home_url     		= 	home_url( '/' );    
            $current_user 		= 	wp_get_current_user();
            $user         		= 	$current_user->user_nicename ;
            $profilelink  	= 	'<li>
    			            <a href="' . esc_url( $home_url ) . '/forum-slug/users/' . $user . '/edit"> '. __('Edit Profile', 'text-domain' ) .' </a>
    			        </li>';
            $menu         	= 	$menu . $profilelink;
            
            return $menu;
      
    }
    add_filter( 'wp_nav_menu_items', 'prefix_bbp_profile_link_nav_menu' );
Viewing 2 replies - 1 through 2 (of 2 total)

  • Robin W
    Moderator

    @robin-w

    the last set of code in this thread should give you what you want

    https://bbpress.org/forums/topic/adding-user-profile-button/


    fakrulislam
    Participant

    @fakrulislam

    Thanks Robin W, it worked!. The working code is below for others help.

    /**
    * Add bbp user profile link in WP nav menu
    * Filter wp_nav_menu() to add profile link
    */
    function prefix_bbp_profile_link_nav_menu($menu) {
    	
        if ( !is_user_logged_in() )
            return $menu;
        else   
            $current_user 				= 	wp_get_current_user();
            $user					=	$current_user->ID;
            $bbp_profile_url			=       bbp_get_user_profile_url( $user);
            $bbp_profile_menu_link	  	        = 	'<li>
    			        				<a href=" '. esc_url( $bbp_profile_url ) .' "> '. __('Edit Profile', 'text-domain' ) .' </a>
    							</li>';
            $menu         	= 	$menu . $bbp_profile_menu_link;
            
            return $menu;
      
    }
    add_filter( 'wp_nav_menu_items', 'prefix_bbp_profile_link_nav_menu' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar