bp_get_nav_menu_items

Get the items registered in the primary and secondary BuddyPress navigation menus.

Description

(array) bp_get_nav_menu_items( (string) $component = 'members' ); 

Returns (array)

A multidimensional array of all navigation items.

Parameters (1)

0. $component — Optional. (string) => 'members'
Component whose nav items are being fetched.

Usage

  1. if ( !function_exists( 'bp_get_nav_menu_items' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-template.php'; 
  3.  
  4. // Optional. Component whose nav items are being fetched. 
  5. $component = 'members'; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_get_nav_menu_items($component); 
  9.  

Defined (1)

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

/bp-core/bp-core-template.php  
  1. function bp_get_nav_menu_items( $component = 'members' ) { 
  2. $bp =buddypress); 
  3. $menus = array(); 
  4.  
  5. if ( ! isset( $bp->{$component}->nav ) ) { 
  6. return $menus; 
  7.  
  8. // Get the item nav and build the menus. 
  9. foreach ( $bp->{$component}->nav->get_item_nav() as $nav_menu ) { 
  10. // Get the correct menu link. See https://buddypress.trac.wordpress.org/ticket/4624. 
  11. $link = bp_loggedin_user_domain() ? str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $nav_menu->link ) : trailingslashit( bp_displayed_user_domain() . $nav_menu->link ); 
  12.  
  13. // Add this menu. 
  14. $menu = new stdClass; 
  15. $menu->class = array( 'menu-parent' ); 
  16. $menu->css_id = $nav_menu->css_id; 
  17. $menu->link = $link; 
  18. $menu->name = $nav_menu->name; 
  19. $menu->parent = 0; 
  20.  
  21. if ( ! empty( $nav_menu->children ) ) { 
  22. $submenus = array(); 
  23.  
  24. foreach( $nav_menu->children as $sub_menu ) { 
  25. $submenu = new stdClass; 
  26. $submenu->class = array( 'menu-child' ); 
  27. $submenu->css_id = $sub_menu->css_id; 
  28. $submenu->link = $sub_menu->link; 
  29. $submenu->name = $sub_menu->name; 
  30. $submenu->parent = $nav_menu->slug; 
  31.  
  32. // If we're viewing this item's screen, record that we need to mark its parent menu to be selected. 
  33. if ( $sub_menu->slug == bp_current_action() ) { 
  34. $menu->class[] = 'current-menu-parent'; 
  35. $submenu->class[] = 'current-menu-item'; 
  36.  
  37. $submenus[] = $submenu; 
  38.  
  39. $menus[] = $menu; 
  40.  
  41. if ( ! empty( $submenus ) ) { 
  42. $menus = array_merge( $menus, $submenus ); 
  43.  
  44. /** 
  45. * Filters the items registered in the primary and secondary BuddyPress navigation menus. 
  46. * @since 1.7.0 
  47. * @param array $menus Array of items registered in the primary and secondary BuddyPress navigation. 
  48. */