Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hide Profile Navigation from non-friends


  • dmccuiston
    Participant

    @dmccuiston

    Is it possible to hide the profile navigation links from non-friends?

    Essentially, I would like to only display a member’s profile header to non-connected users. Once users are connected, the navigation bar (and its resulting linked pages) would be available to view.

    Thanks for any assistance here!

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

  • Henry Wright
    Moderator

    @henrywright

    Hi @dmccuiston

    Check out this forum reply


    dmccuiston
    Participant

    @dmccuiston

    @henrywright, Thanks for this.

    So that totally gets me where I need to be, checking for connections status. Any clue where I would apply that logic to hide the Profile navbar? I’m sure I can do it with some CSS trickery, but was wondering where that nav is initiated.


    danbp
    Moderator

    @danbp

    Hi @dmccuiston,

    here is another solution which let you remove easily nav and subnav items to any visitor and users who are not friends.

    If one or all items are removed, a message is displayed.

    Put these 3 functions in bp-custom.php or child-theme functions.php

    function bpfr_view_profile_msg() {
    	// msg in case the nav item is removed
    	if ( bpfr_maybe_hide_friends_nav_etc( $retval ) )  
    	echo'<h3>Sorry, you can only view the profile of your friends !</h3>';	
    }	
    add_action( 'template_notices','bpfr_view_profile_msg' );
    
    function bpfr_maybe_hide_friends_nav_etc() {
    	$retval = false;
    	// condition 
    	if ( bp_is_user() && ! bp_is_my_profile() && ! friends_check_friendship( bp_displayed_user_id(), bp_loggedin_user_id() ) ) {
    		$retval = true;
    	}	
    	return $retval;
    }
    
    function bpfr_hide_friends_nav_to_non_friends() {	
    	// stop if condition is not ok
    	if ( ! bpfr_maybe_hide_friends_nav_etc() ) {
    		return;
    	}
    	// otherwise we remove the nav items
    	// bp topnav items
    	bp_core_remove_nav_item( 'profile' ); 
    	bp_core_remove_nav_item( 'groups' );
    	bp_core_remove_nav_item( 'forums' );
    	
    	//bp subnav items
    	bp_core_remove_subnav_item( 'activity', 'friends' ); 
    	bp_core_remove_subnav_item( 'activity', 'mentions' ); 
    }
    add_action( 'bp_ready', 'bpfr_hide_friends_nav_to_non_friends' );

    dmccuiston
    Participant

    @dmccuiston

    @danbp,
    Thanks for this. I am going to drop this in and let you know what happens. Truly appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hide Profile Navigation from non-friends’ is closed to new replies.
Skip to toolbar