Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I feel bad that I haven't been able to figure this out myself. I've looked on the web but haven't been able to hit on quite what I need.

I have a buddypress install here http://bananalust.com/maggie/activity/ As you can see there is a tab called 'Blog' well I would like to hide it on certain profiles

When my users sign up they have to choose between 'Expert' or 'Community-member' for the xprofile field called Membership

so is there a way to check a profile page and hide the 'blog' tab if the owner of that page is not an expert? So we would hide the blog tab when someone visits Maggie's profile because she is just a community-member but the tab would be shown on Paula's profile in buddypress because she is an expert.

I found some code that sort of got close to what I want but I'm struggling here. Would someone please give me a suggestion or example on how to get through this? Thanks much! Leah

add_action('bp_friends_setup_nav','bpdev_custom_hide_friends_if_not_self');

function bpdev_custom_hide_friends_if_not_self(){
   if(bp_is_my_profile()|| is_super_admin())
       return ;

   bp_core_remove_nav_item('buddyblog');

}


function hide_courseware_from_aliens() {
   global $bp; $user_id = $bp->is_author->id;
   $role = xprofile_get_field_data( __('Membership'), $user_id );
   if( !$role )
       remove_action( ‘bp_init’,‘bpsp_init’ );
}

add_action( ‘bp_loaded’, ‘hide_courseware_from_aliens’ );
share|improve this question
add comment

5 Answers

Rather than create the tab and then hide it for non-experts, find out where the tab is being created and don't create it if the displayed member is not an expert.

Or you could use the filter hook in function bp_get_displayed_user_nav() ~Line 800 in \bp-members\bp-members-template.php

share|improve this answer
    
First of all - Shane thank you for replying. I am having a lot of difficulty with this because I am still learning things. Here is what I came up with to place in my bp-custom.php file function hide_tab_from_community() { global $bp; $user_id = $bp->bp_displayed_user_domain->id; $role = xprofile_get_field_data( __( 'Expert'), $user_id ); if( !$role ) bp_core_remove_nav_item('friends'); } add_action( 'bp_loaded', 'hide_tab_from_community' ); <br ><br /> This is not working though. I have an xprofile field called Members the option is either community-member or expert <br /> Can you help –  Leah Nov 18 '13 at 16:44
    
if the field is called Members, then don't ask for Experts. $role = xprofile_get_field_data( 'Members' ); if ( $role != 'Expert' ) etc. –  shanebp Nov 18 '13 at 16:52
add comment

Oh wow - thanks so much to ShaneBP for his help, I finally got this working :) I'm sooooo happy

placed the following code in my bp-custom.php file inside my plugins folder

function hide_tab_from_community() {
global $bp;
$user_id = $bp->bp_displayed_user_domain->id;
$role = xprofile_get_field_data( __( 'members'), $user_id );
if( $role !='expert' )
bp_core_remove_nav_item('friends');
}
add_action( 'bp_friends_setup_nav', 'hide_tab_from_community' );
share|improve this answer
add comment

Well I'm back. I'm hugely bummed because I just am not getting this to work.

function hide_blog_tab() {
global $bp;
$user_id = $bp->bp_displayed_user_domain->id;
$role = xprofile_get_field_data( __( 'membership'), $user_id );
if( $role !='expert' )
bp_core_remove_nav_item('expert-blog');
}
add_action( 'bp_setup_nav', 'hide_blog_tab' );

This code results in the buddypress blog nav item being removed for all users. It's like the if statement is not firing. I am getting exactly the same result with

function hide_tab_from_community() {
global $bp;
$user_id = $bp->bp_displayed_user_domain->id;
$role = xprofile_get_field_data( __( 'Membership'), $user_id );
if( $role !='Expert' )
bp_core_remove_nav_item('friends');
}
add_action( 'bp_friends_setup_nav', 'hide_tab_from_community' );

Can someone help me ... Thanks very much!

share|improve this answer
add comment

You need to find out the value of $role. Once you get that right, you can use an 'if'. Otherwise, you're just guessing.

function hide_tab_from_community() {
  $role = xprofile_get_field_data( 'members' );
  echo 'role: ' . $role . '<br>';
  //if( $role !='expert' )
   // bp_core_remove_nav_item('friends');
}
add_action( 'bp_setup_nav', 'hide_tab_from_community', 99 );
share|improve this answer
add comment

Thank you @shanebp for your follow up. I spent so much time getting this right...such a newb. This has been a great learning experience for me though!

I realized a couple things: 1. the xprofile field is case sensitive...so putting membership doesn't work since in wordpress I list it as Membership 2. Same thing for the types of membership - I had to put Expert and not expert to get it to work 3. the final surprise was that you have to target the tab in terms of its URL so even though the tab reads Blog...it leads to bananalust.com/maggie/expert-blog/ so I had to target expert-blog

The code finally works hoorrah! I was wondering what the 99 relates to down in the add_action line. Is there some documentation on that? Thanks very much. Leah

function hide_tab_from_community() {
$role = xprofile_get_field_data( 'Membership' );
if( $role !='Expert' )
bp_core_remove_nav_item('expert-blog');
}
add_action( 'bp_setup_nav', 'hide_tab_from_community', 99 );
share|improve this answer
    
The 99 refers to the priority. Google add_action. –  shanebp Nov 19 '13 at 21:35
    
If you were helped by responses to your question, please accept an answer. More info on how stackexchange works: wordpress.stackexchange.com/help/accepted-answer –  shanebp Nov 19 '13 at 21:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.