bp_get_options_nav( string $parent_slug = '' )

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

Description

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.

Parameters

$parent_slug

(Optional) Options nav slug.

Default value: ''

Return

(string)

Source

File: bp-core/bp-core-template.php

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function bp_get_options_nav( $parent_slug = '' ) {
    $bp = buddypress();
 
    // If we are looking at a member profile, then the we can use the current
    // component as an index. Otherwise we need to use the component's root_slug.
    $component_index = !empty( $bp->displayed_user ) ? bp_current_component() : bp_get_root_slug( bp_current_component() );
    $selected_item   = bp_current_action();
 
    // Default to the Members nav.
    if ( ! bp_is_single_item() ) {
        // Set the parent slug, if not provided.
        if ( empty( $parent_slug ) ) {
            $parent_slug = $component_index;
        }
 
        $secondary_nav_items = $bp->members->nav->get_secondary( array( 'parent_slug' => $parent_slug ) );
 
        if ( ! $secondary_nav_items ) {
            return false;
        }
 
    // For a single item, try to use the component's nav.
    } else {
        $current_item = bp_current_item();
        $single_item_component = bp_current_component();
 
        // Adjust the selected nav item for the current single item if needed.
        if ( ! empty( $parent_slug ) ) {
            $current_item  = $parent_slug;
            $selected_item = bp_action_variable( 0 );
        }
 
        // If the nav is not defined by the parent component, look in the Members nav.
        if ( ! isset( $bp->{$single_item_component}->nav ) ) {
            $secondary_nav_items = $bp->members->nav->get_secondary( array( 'parent_slug' => $current_item ) );
        } else {
            $secondary_nav_items = $bp->{$single_item_component}->nav->get_secondary( array( 'parent_slug' => $current_item ) );
        }
 
        if ( ! $secondary_nav_items ) {
            return false;
        }
    }
 
    // Loop through each navigation item.
    foreach ( $secondary_nav_items as $subnav_item ) {
        if ( empty( $subnav_item->user_has_access ) ) {
            continue;
        }
 
        // If the current action or an action variable matches the nav item id, then add a highlight CSS class.
        if ( $subnav_item->slug === $selected_item ) {
            $selected = ' class="current selected"';
        } else {
            $selected = '';
        }
 
        // List type depends on our current component.
        $list_type = bp_is_group() ? 'groups' : 'personal';
 
        /**
         * Filters the "options nav", the secondary-level single item navigation menu.
         *
         * This is a dynamic filter that is dependent on the provided css_id value.
         *
         * @since BuddyPress 1.1.0
         *
         * @param string $value         HTML list item for the submenu item.
         * @param array  $subnav_item   Submenu array item being displayed.
         * @param string $selected_item Current action.
         */
        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 );
    }
}

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.