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
Description
Parameters
- $nav
-
(Optional) The BuddyPress Item Nav object to reorder
Default value: null
- $order
-
(Optional) A list of slugs ordered (eg: array( 'profile', 'activity', etc..) )
Default value: array()
- $parent_slug
-
(Optional) A parent slug if it's a secondary nav we are reordering (case of the Groups single item)
Default value: ''
Return
(bool) True on success. False otherwise.
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;
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 3.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.