bp_core_remove_nav_item( string $slug, string|null $component = null )

Deletes an item from the primary navigation of the specified component.

Description

Parameters

$slug

(string) (Required) The slug of the primary navigation item.

$component

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

Default value: null

Return

(bool) Returns false on failure, True on success.

Source

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

function bp_core_remove_nav_item( $slug, $component = null ) {
	$bp = buddypress();

	// Backward compatibility for removing group nav items using the group slug as `$parent_slug`.
	if ( ! $component && bp_is_active( 'groups' ) && isset( $bp->groups->nav ) ) {
		if ( $bp->groups->nav->get_primary( array( 'slug' => $slug ) ) ) {
			$component = 'groups';
		}
	}

	if ( ! $component ) {
		$component = 'members';
	}

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

	$screen_functions = $bp->{$component}->nav->delete_nav( $slug );

	// Reset backcompat nav items so that subsequent references will be correct.
	$bp->bp_nav->reset();
	$bp->bp_options_nav->reset();

	if ( ! is_array( $screen_functions ) ) {
		return false;
	}

	foreach ( $screen_functions as $screen_function ) {
		// Remove our screen hook if screen function is callable.
		if ( is_callable( $screen_function ) ) {
			remove_action( 'bp_screens', $screen_function, 3 );
		}
	}

	return true;
}

Changelog

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