BP_Core_Nav::sort_nav( array $items )
Sorts a list of nav items.
Description
Parameters
- $items
-
(Required) The nav items to sort.
Return
(array)
Source
File: bp-core/classes/class-bp-core-nav.php
public function sort_nav( $items ) {
$sorted = array();
foreach ( $items as $item ) {
// Default position
$position = 99;
if ( isset( $item->position ) ) {
$position = (int) $item->position;
}
// If position is already taken, move to the first next available
if ( isset( $sorted[ $position ] ) ) {
$sorted_keys = array_keys( $sorted );
do {
$position += 1;
} while ( in_array( $position, $sorted_keys ) );
}
$sorted[ $position ] = $item;
}
ksort( $sorted );
return $sorted;
}
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.