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

1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
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

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.