bp_nouveau_set_nav_item_order( object $nav = null, array $order = array(), string $parent_slug = '' )

Reorder a BuddyPress item nav according to a given list of nav item slugs


Parameters Parameters

$nav

(object) (Optional) The BuddyPress Item Nav object to reorder

Default value: null

$order

(array) (Optional) A list of slugs ordered (eg: array( 'profile', 'activity', etc..) )

Default value: array()

$parent_slug

(string) (Optional) A parent slug if it's a secondary nav we are reordering (case of the Groups single item)

Default value: ''


Top ↑

Return Return

(bool) True on success. False otherwise.


Source Source

File: bp-templates/bp-nouveau/includes/functions.php

function bp_nouveau_set_nav_item_order( $nav = null, $order = array(), $parent_slug = '' ) {
	if ( ! is_object( $nav ) || empty( $order ) || ! is_array( $order ) ) {
		return false;
	}

	$position = 0;

	foreach ( $order as $slug ) {
		$position += 10;

		$key = $slug;
		if ( ! empty( $parent_slug ) ) {
			$key = $parent_slug . '/' . $key;
		}

		$item_nav = $nav->get( $key );

		if ( ! $item_nav ) {
			continue;
		}

		if ( (int) $item_nav->position !== (int) $position ) {
			$nav->edit_nav( array( 'position' => $position ), $slug, $parent_slug );
		}
	}

	return true;
}


Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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