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
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.