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

Check whether a given nav item has subnav items.


Parameters 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'


Top ↑

Return Return

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


Source 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 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 );
}


Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced the $component parameter.
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.