bp_nav_item_has_subnav( string $nav_item = '', string $component = 'members' )

Check whether a given nav item has subnav items.

Description

Parameters

$nav_item

(string) (Optional) The slug of the top-level nav item whose subnav items you're checking. Default: the current component slug.

Default value: ''

$component

(string) (Optional) The component the navigation is attached to. Defaults to 'members'.

Default value: 'members'

Return

(bool) $has_subnav True if the nav item is found and has subnav items; false otherwise.

Source

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

function bp_nav_item_has_subnav( $nav_item = '', $component = 'members' ) {
	$bp = buddypress();

	if ( ! isset( $bp->{$component}->nav ) ) {
		return false;
	}

	if ( ! $nav_item ) {
		$nav_item = bp_current_component();

		if ( bp_is_group() ) {
			$nav_item = bp_current_item();
		}
	}

	$has_subnav = (bool) $bp->{$component}->nav->get_secondary( array( 'parent_slug' => $nav_item ), false );

	/**
	 * Filters whether or not a given nav item has subnav items.
	 *
	 * @since BuddyPress 1.5.0
	 *
	 * @param bool   $has_subnav Whether or not there is any subnav items.
	 * @param string $nav_item   The slug of the top-level nav item whose subnav items you're checking.
	 */
	return apply_filters( 'bp_nav_item_has_subnav', $has_subnav, $nav_item );
}

Changelog

Changelog
Version Description
BuddyPress 1.5.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.