bp_get_nav_menu_items( string $component = 'members' )
Get the items registered in the primary and secondary BuddyPress navigation menus.
Description
Parameters
- $component
-
(Optional) Component whose nav items are being fetched.
Default value: 'members'
Return
(array) A multidimensional array of all navigation items.
Source
File: bp-core/bp-core-template.php
function bp_get_nav_menu_items( $component = 'members' ) { $bp = buddypress(); $menus = array(); if ( ! isset( $bp->{$component}->nav ) ) { return $menus; } // Get the item nav and build the menus. foreach ( $bp->{$component}->nav->get_item_nav() as $nav_menu ) { // Get the correct menu link. See https://buddypress.trac.wordpress.org/ticket/4624. $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 ); // Add this menu. $menu = new stdClass; $menu->class = array( 'menu-parent' ); $menu->css_id = $nav_menu->css_id; $menu->link = $link; $menu->name = $nav_menu->name; $menu->parent = 0; if ( ! empty( $nav_menu->children ) ) { $submenus = array(); foreach( $nav_menu->children as $sub_menu ) { $submenu = new stdClass; $submenu->class = array( 'menu-child' ); $submenu->css_id = $sub_menu->css_id; $submenu->link = $sub_menu->link; $submenu->name = $sub_menu->name; $submenu->parent = $nav_menu->slug; // If we're viewing this item's screen, record that we need to mark its parent menu to be selected. if ( bp_is_current_action( $sub_menu->slug ) && bp_is_current_component( $nav_menu->slug ) ) { $menu->class[] = 'current-menu-parent'; $submenu->class[] = 'current-menu-item'; } $submenus[] = $submenu; } } $menus[] = $menu; if ( ! empty( $submenus ) ) { $menus = array_merge( $menus, $submenus ); } } /** * Filters the items registered in the primary and secondary BuddyPress navigation menus. * * @since BuddyPress 1.7.0 * * @param array $menus Array of items registered in the primary and secondary BuddyPress navigation. */ return apply_filters( 'bp_get_nav_menu_items', $menus ); }
Changelog
Version | Description |
---|---|
BuddyPress 1.7.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.