bp_get_loggedin_user_nav

Render the navigation markup for the logged-in user.

Description

bp_get_loggedin_user_nav(); 

Each component adds to this navigation array within its own [component_name]setup_nav() function.

This navigation array is the top level navigation, so it contains items such as: [Blog, Profile, Messages, Groups, Friends] ...

The function will also analyze the current component the user is in, to determine whether or not to highlight a particular nav item.


Usage

  1. if ( !function_exists( 'bp_get_loggedin_user_nav' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-template.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_get_loggedin_user_nav(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-members/bp-members-template.php  
  1. function bp_get_loggedin_user_nav() { 
  2. $bp =buddypress); 
  3.  
  4. // Loop through each navigation item. 
  5. foreach ( (array) $bp->members->nav->get_primary() as $nav_item ) { 
  6.  
  7. $selected = ''; 
  8.  
  9. // If the current component matches the nav item id, then add a highlight CSS class. 
  10. if ( ! bp_is_directory() && ! empty( $bp->active_components[ bp_current_component() ] ) && $bp->active_components[ bp_current_component() ] == $nav_item->css_id ) { 
  11. $selected = ' class="current selected"'; 
  12.  
  13. // If we are viewing another person (current_userid does not equal 
  14. // loggedin_user->id then check to see if the two users are friends. 
  15. // if they are, add a highlight CSS class to the friends nav item 
  16. // if it exists. 
  17. if ( !bp_is_my_profile() && bp_displayed_user_id() ) { 
  18. $selected = ''; 
  19.  
  20. if ( bp_is_active( 'friends' ) ) { 
  21. if ( $nav_item->css_id == $bp->friends->id ) { 
  22. $selected = ' class="current selected"'; 
  23.  
  24. // Echo out the final list item. 
  25. echo apply_filters_ref_array( 'bp_get_loggedin_user_nav_' . $nav_item->css_id, array( '<li id="li-nav-' . $nav_item->css_id . '" ' . $selected . '><a id="my-' . $nav_item->css_id . '" href="' . $nav_item->link . '">' . $nav_item->name . '</a></li>', &$nav_item ) ); 
  26.  
  27. // Always add a log out list item to the end of the navigation. 
  28. $logout_link = '<li><a id="wp-logout" href="' . wp_logout_url( bp_get_root_domain() ) . '">' . __( 'Log Out', buddypress ) . '</a></li>'; 
  29.  
  30. echo apply_filters( 'bp_logout_nav_link', $logout_link );