BP_REST_Members_Details_Endpoint::bp_rest_build_tree( array $elements, int $parent_id )

Recursive function to create child level elements.

Description

Parameters

$elements

(Required) Array elements.

$parent_id

(Required) Parent element id.

Return

(array)

Source

File: bp-members/classes/class-bp-rest-members-details-endpoint.php

1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
protected function bp_rest_build_tree( array &$elements, $parent_id = 0 ) {
    $branch = array();
    foreach ( $elements as &$element ) {
        if ( (int) $element->menu_item_parent === (int) $parent_id ) {
            $children = $this->bp_rest_build_tree( $elements, $element->ID );
            if ( $children ) {
                $element->children = $children;
            }
 
            $branch[ $element->ID ] = $element;
            unset( $element );
        }
    }
 
    return $branch;
}

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.