Skip to:
Content
Pages
Categories
Search
Top
Bottom

Move User Details to Custom Sidebar


  • Howdy_McGee
    Participant

    @howdy_mcgee

    Is there a way to unhook the user-details.php and move re-call it in my own custom sidebar? Or is there a function to load the template part in my custom sidebar file?

Viewing 2 replies - 1 through 2 (of 2 total)

  • Howdy_McGee
    Participant

    @howdy_mcgee

    So I found how I can go about loading a specific template, either bbp_get_template_part() or bbp_locate_template() should work.

    The only part of this question I’m not sure of is how to unload a specific template / stop it from loading initially. Any suggestions?


    Howdy_McGee
    Participant

    @howdy_mcgee

    Ok, here’s what I did. If anyone has a better solution post it! What I was ultimately trying to do was combine both the WooCommerce accounts sidebar with the BBPress sidebar. I think the most difficult part / part I’m most unsure about is the bbp user ID which we’ll get to later.

    Unloading a Template

    I used the bbp_get_template_part filter to find and remove the user-details.php template from loading:

    /**
     * Prevent BBPress from loading certain templates
     *
     * @param Array $templates
     *
     * @return Array $templates;
     */
    function prefix_bbp_template_removal( $templates ) {
    
    	if( bbp_is_single_user() && is_array( $templates ) ) {
    		
    		
    		if( false !== ( $key = array_search( 'user-details.php', $templates ) ) ) {
    			unset( $templates[ $key ] );
    		}
    		
    	}
    	
    	return $templates;
    	
    }
    add_filter( 'bbp_get_template_part', 'prefix_bbp_template_removal');

    Loading a Template

    Then I used the bbp_locate_template() function to reload the template where I wanted it.

    bbp_locate_template( array( 'user-details.php' ), true, false );

    User Profile Links

    This is where it gets hairy. For whatever reason, when outside the “User Home”, BBPress doesn’t know which user is displaying so none of the sidebar links would link plus “Edit” and “Subscriptions” were missing. To show the last 2 links I needed to have bbp_is_user_home return true, in my case it was whenever the user was on WooCommerce Accounts pages:

    /**
     * Modify Home Conditional if viewing WooCommerce Account
     *
     * @return Boolean
     */
    function prefix_bbp_user_home( $is_user_home ) {
    	
    	if( function_exists( 'is_account_page' ) && is_account_page() ) {
    		$is_user_home = true;
    	}
    	
    	return $is_user_home;
    	
    }
    add_filter( 'bbp_is_user_home', 'prefix_bbp_user_home' );

    Which now shows the two links at the bottom. The final piece was actually getting the links to work correctly. This is what I’m most unsure about as I’m not sure how BBPress defines which user is displayed. I’m assuming there’s some kind of impersonation feature which makes this more difficult or something I’m not sure so I just return the current user ID:

    /** 
     * Give BBPress a User ID on Woocommerce Accounts
     *
     * @param Integer $bbp_user_id
     *
     * @return Integer $bbp_user_id
     */
    function prefix_bbp_user_id( $bbp_user_id ) {
    	
    	$user_id = get_current_user_id();
    	
    	if( function_exists( 'is_account_page' ) && is_account_page() && empty( $bbp_user_id ) ) {
    		$bbp_user_id = $user_id;
    	}
    	
    	return $bbp_user_id;
    		
    }
    add_filter( 'bbp_get_user_id', 'prefix_bbp_user_id' );

    I’d love to get some clarification on the BBPress user ID, why it doesn’t use the current user outside User Home, and what the best way to go about this is.

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