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!!
1 Answer
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
}
}