BP_Core_Nav::delete_nav( string $slug = '', string $parent_slug = '' )

Unset an item or a subitem of the nav.

Description

Parameters

$slug

(Optional) The slug of the main item.

Default value: ''

$parent_slug

(Optional) The slug of the sub item.

Default value: ''

Return

(false|callable|array) False on failure, the screen function(s) on success.

Source

File: bp-core/classes/class-bp-core-nav.php

	public function delete_nav( $slug = '', $parent_slug = '' ) {

		// Bail if slug is empty
		if ( empty( $slug ) ) {
			return false;
		}

		// We're deleting a child
		if ( ! empty( $parent_slug ) ) {

			// Validate the subnav
			$sub_items = $this->get_secondary( array( 'parent_slug' => $parent_slug, 'slug' => $slug ), false );

			if ( ! $sub_items ) {
				return false;
			}

			$sub_item = reset( $sub_items );

			if ( empty( $sub_item->slug ) ) {
				return false;
			}

			// Delete the child
			unset( $this->nav[ $this->object_id ][ $parent_slug . '/' . $slug ] );

			// Return the deleted item's screen function
			return array( $sub_item->screen_function );

		// We're deleting a parent
		} else {
			// Validate the nav
			$nav_items = $this->get_primary( array( 'slug' => $slug ), false );

			if ( ! $nav_items ) {
				return false;
			}

			$nav_item = reset( $nav_items );

			if ( empty( $nav_item->slug ) ) {
				return false;
			}

			$screen_functions = array( $nav_item->screen_function );

			// Life's unfair, children won't survive the parent :(
			$sub_items = $this->get_secondary( array( 'parent_slug' => $nav_item->slug ), false );

			if ( ! empty( $sub_items ) ) {
				foreach ( $sub_items as $sub_item ) {
					$screen_functions[] = $sub_item->screen_function;

					// Delete the child
					unset( $this->nav[ $this->object_id ][ $nav_item->slug . '/' . $sub_item->slug ] );
				}
			}

			// Delete the parent.
			unset( $this->nav[ $this->object_id ][ $nav_item->slug ] );

			// Return the deleted item's screen functions.
			return $screen_functions;
		}
	}

Changelog

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