How to hide profile menu items from other users
-
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!
-
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 postThank you that works
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?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 );
***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?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:
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.I exactly aimed to remove (setting-profile visibility) from user menu for all users.
bp_core_remove_subnav_item( 'settings', 'profile' );
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, 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' );
@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.
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.
‘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!?
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');
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’.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.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.
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.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.
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' );
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!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!?Stop ! Please, i allreay answered to this. Now it is time to learn and experiment by yourself.
- You must be logged in to reply to this topic.