$bp->bp_options_nav wrong user links
-
Hello there,
I’m trying to make a new user menu (the same one that is in admin bar actually), so I’m using $bp->bp_nav and $bp->bp_options_nav to buid it up.
$bp->bp_nav has the current logged in user links so it’s ok.
But when I’m on someone else profile $bp->bp_options_nav has this profile links instead of the current logged in user links.
I’ve seen this topic whith the same problem has me but there is no solution there.
here is how I do it :
$activity = ''; foreach($bp->bp_nav as $data) { $activity .= '<li><a href="' . $data['link'] . '">' . $data['name'] . '</a>'; if(empty($bp->bp_options_nav[$data['slug']])) continue; $activity .= '<ul>'; foreach($bp->bp_options_nav[$data['slug']] as $subdata) { if(!$subdata['user_has_access']) continue; $activity .= '<li><a href="' . $subdata['link'] . '">' . $subdata['name'] . '</a></li>'; } $activity .= '</ul>'; $activity .= '</li>'; }
-
Thanks a lot for any help I can get !
ps: edit link redirect me to homepage.
try by adding this at the begin of your function
$user_id = bp_get_activity_user_id();
If you’re working on the Toolbar, the correct way to add a menu is like on this example:
/* add links/menus to the admin bar*/ /* more details here: http://wpengineer.com/2113/add-menus-to-the-admin-bar-of-wordpress/ */ function mytheme_admin_bar_render() { global $wp_admin_bar; $wp_admin_bar->add_menu( array( 'parent' => 'new-content', // use 'false' for a root menu, or pass the ID of the parent menu 'id' => 'new_media', // link ID, defaults to a sanitized title value 'title' => __('Media'), // link title 'href' => admin_url( 'media-new.php') // name of file 'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' ); ) ); } add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );
A similar method is used to add a tab. Here on a user profile.
function bpfr_my_setup_nav() { global $bp; $mytab=array( 'name' => 'My Tab', 'link' => 'http://example.com/wp-content/themes/twentythirteen/my_extra_page.php', 'slug' => 'my-tab', 'css_id' => 'my_custom_tab', 'position' => 100, 'user_has_access' => 1, 'screen_function' => 'xprofile_screen_my_tab' ); $bp->bp_options_nav['profile']['my-tab']=$mytab; } add_action('bp_setup_nav', 'bpfr_my_setup_nav');
Thanks for you help !
Actually I hide the admin bar on my pages. That’s the reason why I’m trying to build the exact same menu on another navigation bar.
I feel like it is a bug because here, it says that :
$bp->bp_nav “is the array used to render each component navigation menu item for the logged in user”
and
$bp->bp_options_nav “is the array used to render all of the sub navigation items for the $bp->bp_nav array”.
Actually I feel like I’m having the result of $bp->bp_users_nav.
Because it “is the array used to render each component navigation menu item for the displayed user (when you view a user that is not you).”What do you guys think ?
I’m still having this issue.
Maybee there is another way to generate admin menu ?
Anybody ?
- The topic ‘$bp->bp_options_nav wrong user links’ is closed to new replies.