Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to hide profile menu items from other users


  • iwishiknew
    Participant

    @iwishiknew

    Say I want to make it so that no one can view a certain menu item in a users profile EXCEPT FOR the user whos profile it is, how do I do that.

    So say I am user1 and I go to my profile, I should be able to see the Friends tab; now if I as user1 goes to user2 profile page, their Friends menu item should not be visible.

    Any way to do this? All help GREATLY appreciated! 😀

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

  • Hastig
    Participant

    @hastig

    Could you wrap the area you want seen by only the logged in user with bp_is_my_profile()

    Something like this..

    <?php if (bp_is_my_profile()) : ?>
        show this
    <?php endif; ?>

    bp_is_my_profile on hookr
    asked in a past buddypress forum post


    iwishiknew
    Participant

    @iwishiknew

    Thank you that works


    marcono
    Participant

    @marcono

    First of all this seems not working for me! Nothing happens at all!
    Secondly, I don’t want to just hide, rather completely restrict other users to see the menu items of other users when they visit their profile except some of the items.
    Exactly like the ‘Messages’ and ‘Setting’ items; as they are only accessible for profile owner not for the other visitors.
    Could someone help me with this?


    danbp
    Moderator

    @danbp

    Add this snippet to bp-custom.php and give it a try.

    function bpex_hide_profile_menu_tabs() {
    
    	if( bp_is_active( 'xprofile' ) ) :
    
    	if ( bp_is_user() && !is_super_admin() && !bp_is_my_profile() ) {
    	//	BP's profile main menu items. Comment those to show.
    	//	bp_core_remove_nav_item( 'activity' );
    		bp_core_remove_nav_item( 'profile' );
    		bp_core_remove_nav_item( 'friends' );
    		bp_core_remove_nav_item( 'groups' );
    	//	exist only if you use bbPress
    		bp_core_remove_nav_item( 'forums' ); 
    
    	//	BP's profile main menu items. Comment those to show.
    	//	bp_core_remove_subnav_item( 'activity', 'personnal' );
    		bp_core_remove_subnav_item( 'activity', 'mentions' );
    		bp_core_remove_subnav_item( 'activity', 'favorites' );
    		bp_core_remove_subnav_item( 'activity', 'friends' );
    		bp_core_remove_subnav_item( 'activity', 'groups' );
    	}
    	endif;
    }
    add_action( 'bp_setup_nav', 'bpex_hide_profile_menu_tabs', 15 );

    marcono
    Participant

    @marcono

    ***danbp***, THANK YOU SO MUCH! It worked.

    If I want to remove a sub menu, but this time globally for all the users, I should add the command right after above function before any of the conditions!? For instance:

    function bpex_hide_profile_menu_tabs() {
    bp_core_remove_subnav_item( ‘groups’, ‘Invitation’ );

    But it does not work obviously in this manner?


    danbp
    Moderator

    @danbp

    It’s the same principle, but not the same syntax since 2.6

    To hide tabs on groups, you need to specify the component. Note that all menu items (nav and subnav items) are considered as sub-nav, they have not the same distinction as on member or activity menus.

    Use another function for groups. Try this.

    function bpex_remove_group_tabs() {  
    
    	if ( ! bp_is_group() ) {
    		return;
    	}
    
    	$slug = bp_get_current_group_slug();
    
    		// hide items to all users except site admin
    	if ( !is_super_admin() ) {
    
    	//	bp_core_remove_subnav_item( $slug, 'members' );
    		bp_core_remove_subnav_item( $slug, 'send-invites' );
    	//	bp_core_remove_subnav_item( $slug, 'admin' );
    	//	bp_core_remove_subnav_item( $slug, 'forum' );
    	}
    
    }
    add_action( 'bp_actions', 'bpex_remove_group_tabs' );

    To get more usage examples, see here:

    Navigation API


    marcono
    Participant

    @marcono

    Thx again danbp!
    But please note, I do not want to change the group menu.
    I am still talking about the user menu. I want to delete some sub-folders from user menu not just to be hidden from the visitors.


    marcono
    Participant

    @marcono

    I exactly aimed to remove (setting-profile visibility) from user menu for all users.


    danbp
    Moderator

    @danbp

    bp_core_remove_subnav_item( 'settings', 'profile' );


    marcono
    Participant

    @marcono

    danbp, I learned from you a lot today! THANK YOU FOR YOUR TIME HELPING ME!
    I know it is not related to topic directly, but could you give a hint about changing the name of ‘Forum’ and ‘Group’ in user profile and ‘Forum’ on the group page!?


    socialc
    Participant

    @socialc

    @marcono you might want to read this page and consider making a translation file of your own.


    danbp
    Moderator

    @danbp

    @socialc, since 2.6 and the new Nav API, there is a much simplier possibility as the translation file to change nav item names.


    @marcono
    , try this; not sure you learned, below snippet is on Nav API examples i indicated previously. 😉

    function bpcodex_rename_group_tabs() {
    
        if ( ! bp_is_group() ) {
            return;
        }
       
        buddypress()->groups->nav->edit_nav( array( 'name' => __( 'Group Discussion', 'buddypress' ) ), 'forum', bp_current_item() );
    }
    add_action( 'bp_actions', 'bpcodex_rename_group_tabs' );
    
    function bpcodex_rename_profile_tabs() {
     
          buddypress()->members->nav->edit_nav( array( 'name' => __( 'My Buddy Forums', 'textdomain' ) ), 'forums' );
          buddypress()->members->nav->edit_nav( array( 'name' => __( 'My Buddy Groups', 'textdomain' ) ), 'groups' );
     
    }
    add_action( 'bp_actions', 'bpcodex_rename_profile_tabs' );

    socialc
    Participant

    @socialc

    @danbp Ah yeah no doubt, although surely if it’s changed in one place it should be changed in all occurrences? “Create [group]” for example would also need changed.


    danbp
    Moderator

    @danbp

    No, not for the moment. We’re handling here about profile and group nav, not about Group or Member Directory nav.

    If you have a snippet who works for the Directory, feel free to add it to the Nav Api examples. Codex Contributors are always welcome.


    marcono
    Participant

    @marcono

    ‘danbp’ your codes work great!
    One thing, though, since I removed the ‘home’ item in groups, now if I create a private group or click on a public group icon, the group page will not be available!
    I think it is because the ‘home’ item has remained as the default page for the group pages!? I changed my profile default page with ‘define(‘BP_DEFAULT_COMPONENT’, ‘profile’ );’ but it seems for changing group default tab story is different, so I used code suggested here: https://buddypress.org/support/topic/changing-group-tab-display-defaults/

    But still no success!?


    danbp
    Moderator

    @danbp

    The Home tab is the default one. If you remove that tab, BP has no way to know where to output the other group tabs content. If you remove Home(aka activity) you should define another landing tab.

    But when you want to modify groups, you shouldn’t define ‘profile’, but ‘groups’. (read what you wrote!)
    For the profile landing tab, see this codex page.

    For groups, you can try this snippet. This let you define a different landing tab for each of your groups (not profile, ok ?). 😉

    function bpfr_custom_group_default_tab($default_tab){
    	/**
    	 * class_exists() is recommanded to avoid problems during updates 
    	 * or when Groups Component is deactivated
    	 */
    	if ( class_exists( 'BP_Group_Extension' ) ) : // 
    	
    	$group=groups_get_current_group();//get the current group
    	
    	if(empty($group))
    	return $default_tab;
    	
    	switch($group->slug){
    		
    		case 'kill-bill': // group name (use slug format)
    		$default_tab='forum';
    		break;
    		
    		case 'groupe-2014':
    		$default_tab='members';
    		break;
    		
    		default:		
    		$default_tab='home';// the original default landing tab
    		break;
    		
    	}
    	
    	return $default_tab;
    	
    	endif; // end if ( class_exists( 'BP_Group_Extension' ) )
    }
    add_filter('bp_groups_default_extension','bpfr_custom_group_default_tab');

    marcono
    Participant

    @marcono

    Thx *danbp* I REALLY appreciate your help.
    I’m a mech. eng. and started 1 week with wordpress, so u can guess how much I know about wordpress! Yet, of course when I used the code ‘define(‘BP_DEFAULT_COMPONENT’, ‘profile’ )’ for group default, I changed ‘profile’ to something else 🙂
    btw, this code ‘define(‘BP_DEFAULT_COMPONENT’, ‘profile’ )’ worked for me and my default tab in user profile is ‘Profile’ now.

    But concerning the code above (your post above) for changing the group’s default tab, it does not work obviously, and still I see the page is not available?
    Not to mention, I used the function above (ur post above) before functions which change the name of Forum, etc. Exactly at the top of ‘bp-custom.php’.


    danbp
    Moderator

    @danbp

    I use that function bpfr_custom_group_default_tab and it works.
    Have you replaced the group slug to yours in ‘case’ ? This must fit the exact slug, the one you see by mouse over the group name in the bottom left corner of your brower (and normally in the browser’s address bar).

    Please ask one question at a time. Make an effort to be clear. It’s difficult to follow your post !

    – I want to do this on profile: details, item names…

    – I want to do this on groups: details, item names…

    NB 1: if you want to change the landing tab for ALL groups, you can use:

    
    define( 'BP_GROUPS_DEFAULT_EXTENSION', 'members' );

    With this, all groups will use the group members directory as landing tab instead the group activity.
    If you want a different landing tab for each group, use the snippet and don’t use define.

    Changing Internal Configuration Settings

    NB 2: the tab name has no influence on the landing tab. The name and the slug are handled separately, precisely because of that

    NB 3: where you put functions in bp-custom has no importance.


    marcono
    Participant

    @marcono

    Thank you *danbp*, a lot!

    Yes I wanted to do it for all group. define( 'BP_GROUPS_DEFAULT_EXTENSION', 'members' ); works perfectly. But, not for private groups, i.e. if you click on the group which is private, it will not be available.


    jaishreejai
    Participant

    @jaishreejai

    Could you wrap the area you want seen by only the logged in user with bp_is_my_profile()

    Something like this..

    <?php if (bp_is_my_profile()) : ?>
    show this
    <?php endif; ?>

    Thanks! it works for me.


    danbp
    Moderator

    @danbp

    @marcono,

    of course that define works also for private groups ! Has nothing to do with group status.

    If it really dosn’t work for you, you have an error somewhere, but current home tab is not related to group privacy. Members access is restricted, not the output.

    define( 'BP_GROUPS_DEFAULT_EXTENSION', 'members' );


    marcono
    Participant

    @marcono

    Thx *danbp*
    With define( ‘BP_GROUPS_DEFAULT_EXTENSION’, ‘members’ ); the default tab for all groups (private and public) DOES change.
    But if the user is not a member of a private group, he cannot see the group’s page to request a membership. However, if the user is already a member of private group, of course everything is OK and the default tab is changed as the same as the public groups.
    If I don’t remove ‘home’ tab in the group pages, then everything is fine though!


    marcono
    Participant

    @marcono

    Just to clarify, with define( ‘BP_GROUPS_DEFAULT_EXTENSION’, ‘members’ ) the landing tab of the groups actually will not be changed (at least for me). What changes is the tab u will be directed to when u click on the group’s icon!?


    danbp
    Moderator

    @danbp

    Stop ! Please, i allreay answered to this. Now it is time to learn and experiment by yourself.

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