bp_get_options_nav

Output the "options nav", the secondary-level single item navigation menu.

Description

(string) bp_get_options_nav( (string) $parent_slug = '' ); 

Uses the component's nav global to render out the sub navigation for the current component. Each component adds to its sub navigation array within its own setup_nav() function.

This sub navigation array is the secondary level navigation, so for profile it contains: [Public, Edit Profile, Change Avatar]

The function will also analyze the current action for the current component to determine whether or not to highlight a particular sub nav item.

Returns (string)

Parameters (1)

0. $parent_slug — Optional. (string) => ''
Options nav slug.

Usage

  1. if ( !function_exists( 'bp_get_options_nav' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-template.php'; 
  3.  
  4. // Options nav slug. 
  5. $parent_slug = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_get_options_nav($parent_slug); 
  9.  

Defined (1)

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

/bp-core/bp-core-template.php  
  1. function bp_get_options_nav( $parent_slug = '' ) { 
  2. $bp =buddypress); 
  3.  
  4. // If we are looking at a member profile, then the we can use the current 
  5. // component as an index. Otherwise we need to use the component's root_slug. 
  6. $component_index = !empty( $bp->displayed_user ) ? bp_current_component() : bp_get_root_slug( bp_current_component() ); 
  7. $selected_item = bp_current_action(); 
  8.  
  9. // Default to the Members nav. 
  10. if ( ! bp_is_single_item() ) { 
  11. // Set the parent slug, if not provided. 
  12. if ( empty( $parent_slug ) ) { 
  13. $parent_slug = $component_index; 
  14.  
  15. $secondary_nav_items = $bp->members->nav->get_secondary( array( 'parent_slug' => $parent_slug ) ); 
  16.  
  17. if ( ! $secondary_nav_items ) { 
  18. return false; 
  19.  
  20. // For a single item, try to use the component's nav. 
  21. } else { 
  22. $current_item = bp_current_item(); 
  23. $single_item_component = bp_current_component(); 
  24.  
  25. // Adjust the selected nav item for the current single item if needed. 
  26. if ( ! empty( $parent_slug ) ) { 
  27. $current_item = $parent_slug; 
  28. $selected_item = bp_action_variable( 0 ); 
  29.  
  30. // If the nav is not defined by the parent component, look in the Members nav. 
  31. if ( ! isset( $bp->{$single_item_component}->nav ) ) { 
  32. $secondary_nav_items = $bp->members->nav->get_secondary( array( 'parent_slug' => $current_item ) ); 
  33. } else { 
  34. $secondary_nav_items = $bp->{$single_item_component}->nav->get_secondary( array( 'parent_slug' => $current_item ) ); 
  35.  
  36. if ( ! $secondary_nav_items ) { 
  37. return false; 
  38.  
  39. // Loop through each navigation item. 
  40. foreach ( $secondary_nav_items as $subnav_item ) { 
  41. if ( empty( $subnav_item->user_has_access ) ) { 
  42. continue; 
  43.  
  44. // If the current action or an action variable matches the nav item id, then add a highlight CSS class. 
  45. if ( $subnav_item->slug === $selected_item ) { 
  46. $selected = ' class="current selected"'; 
  47. } else { 
  48. $selected = ''; 
  49.  
  50. // List type depends on our current component. 
  51. $list_type = bp_is_group() ? 'groups' : 'personal'; 
  52.  
  53. /** 
  54. * Filters the "options nav", the secondary-level single item navigation menu. 
  55. * This is a dynamic filter that is dependent on the provided css_id value. 
  56. * @since 1.1.0 
  57. * @param string $value HTML list item for the submenu item. 
  58. * @param array $subnav_item Submenu array item being displayed. 
  59. * @param string $selected_item Current action. 
  60. */ 
  61. echo apply_filters( 'bp_get_options_nav_' . $subnav_item->css_id, '<li id="' . esc_attr( $subnav_item->css_id . '-' . $list_type . '-li' ) . '" ' . $selected . '><a id="' . esc_attr( $subnav_item->css_id ) . '" href="' . esc_url( $subnav_item->link ) . '">' . $subnav_item->name . '</a></li>', $subnav_item, $selected_item );