BP_Core_Nav::edit_nav( array $args = array(), string $slug = '', string $parent_slug = '' )

Edits a nav item.

Description

Parameters

$args

(Optional) The nav item's arguments.

Default value: array()

$slug

(Optional) The slug of the nav item.

Default value: ''

$parent_slug

(Optional) The slug of the parent nav item (required to edit a child).

Default value: ''

Return

(BP_Core_Nav_Item)

Source

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

	public function edit_nav( $args = array(), $slug = '', $parent_slug = '' ) {
		if ( empty( $slug ) ) {
			return false;
		}

		// We're editing a parent!
		if ( empty( $parent_slug ) ) {
			$nav_items = $this->get_primary( array( 'slug' => $slug ), false );

			if ( ! $nav_items ) {
				return false;
			}

			$nav_item = reset( $nav_items );
			$this->nav[ $this->object_id ][ $slug ] = new BP_Core_Nav_Item( wp_parse_args( $args, (array) $nav_item ) );

			// Return the edited object.
			return $this->nav[ $this->object_id ][ $slug ];

		// We're editing a child.
		} else {
			$sub_items = $this->get_secondary( array( 'parent_slug' => $parent_slug, 'slug' => $slug ), false );

			if ( ! $sub_items ) {
				return false;
			}

			$sub_item = reset( $sub_items );

			$params = wp_parse_args( $args, (array) $sub_item );

			// When we have parents, it's for life, we can't change them!
			if ( empty( $params['parent_slug'] ) || $parent_slug !== $params['parent_slug'] ) {
				return false;
			}

			$this->nav[ $this->object_id ][ $parent_slug . '/' . $slug ] = new BP_Core_Nav_Item( $params );

			// Return the edited object.
			return $this->nav[ $this->object_id ][ $parent_slug . '/' . $slug ];
		}
	}

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.