BP_REST_Members_Details_Endpoint::prepare_item_for_response( array $navigation, WP_REST_Request $request )

Prepares navigation data for return as an object.

Description

Parameters

$navigation

(Required) Navigation data.

$request

(Required) Full details about the request.

Return

(WP_REST_Response)

Source

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

492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
public function prepare_item_for_response( $navigation, $request ) {
    $id     = ( ! empty( $navigation->post_name ) ? $navigation->post_name : $navigation->ID );
    $id_map = array(
        'activity' => 'activities',
        'profile'  => 'xprofile',
    );
 
    if ( isset( $id_map[ $id ] ) ) {
        $id = $id_map[ $id ];
    }
 
    $data = array(
        'id'       => $id,
        'name'     => $navigation->title,
        'url'      => $navigation->url,
        'count'    => isset( $navigation->count ) ? $navigation->count : '',
        'children' => array(),
    );
 
    if ( ! empty( $navigation->children ) ) {
        $data['children'] = $this->prepare_child_navigation( (object) $navigation->children, $request );
    }
 
    $data = $this->add_additional_fields_to_object( $data, $request );
 
    $response = rest_ensure_response( $data );
 
    /**
     * Filter an navigation value returned from the API.
     *
     * @since 0.1.0
     *
     * @param WP_REST_Request  $request    Request used to generate the response.
     * @param object           $navigation The navigation object.
     *
     * @param WP_REST_Response $response   The response data.
     */
    return apply_filters( 'bp_rest_profile_dropdown_prepare_value', $response, $request, $navigation );
}

Changelog

Changelog
Version Description
0.1.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.