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'm using BuddyPress and need a certain block of code to show up on user role Store Owner profiles only. I'll be putting it in member_header.php, so it's just a template file.

I've been digging for a long time now and just can't seem to figure this out. I found a way to target current user role, but that makes it show up on everyone's profile for a user in the Store Owner user role.

I understand I need a conditional, but I just can't seem to find the right conditional... Am I missing something, somehow?

Thanks so much!!

Edit:

OK, so I've been fiddling around and moved on to something a little different... I still need similar help, just in a slightly different and less flexible setting.

I've changed my mind and moved this block of code to a separate profile page entirely. I have the page built and linked to in the profile menu. So what I need the conditional for is to show this menu item based on the user role of the profile being viewed.

Here's the code that works and shows up on every single user's page:

// Set up Custom BP navigation
function my_setup_nav() {    
   global $bp;
      bp_core_new_nav_item( array(
            'name' => __( 'Calendar', 'buddypress' ),
            'slug' => 'calendar',
            'position' => 20,
            'screen_function' => 'calendar_template' 
      ) );

      // Change the order of menu items
      $bp->bp_nav['messages']['position'] = 100;
}

add_action( 'bp_setup_nav', 'my_setup_nav' );

Here's the code that I've been playing with, but it causes the menu item to just not show up anywhere.

// Set up Custom BP navigation
function my_setup_nav() {   
   if(user_can($user->ID, "store_owner")) {   
   global $bp;
      bp_core_new_nav_item( array(
            'name' => __( 'Calendar', 'buddypress' ),
            'slug' => 'calendar',
            'position' => 20,
            'screen_function' => 'calendar_template' 
      ) );

      // Change the order of menu items
      $bp->bp_nav['messages']['position'] = 100;
}
}

add_action( 'bp_setup_nav', 'my_setup_nav' );

My site is: http://www.pureplayhaven.com And the user "sample" is a "Store Owner" user.

Thank you so much!!

share|improve this question

closed as off-topic by toscho Aug 2 at 20:55

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

    
Please post the code you are trying to use. –  s_ha_dum Feb 11 '13 at 23:15
    
Currently, I don't have any code I'm using. Nothing has worked so I keep deleting and retrying. I'm just trying to insert <h2>Hi, I'm a Store Owner!</h2 right now. Eventually I think I'm going to have to do an execute_shortcode function for the static info. –  LadyCourage Feb 11 '13 at 23:44

1 Answer 1

up vote 0 down vote accepted

I think you need to check if the displayed user has that role, try replacing $user->ID with bp_displayed_user_id():

function my_setup_nav() {   
   if ( user_can( bp_displayed_user_id(), 'store_owner' ) ) {
       // ... rest of your code
   }
}
share|improve this answer
    
Oh my gosh. THAT'S IT. THANK YOU SO MUCH. YOU ARE SO INCREDIBLY AWESOME. –  LadyCourage Feb 26 '13 at 0:35

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