BP_REST_XProfile_Data_Endpoint::prepare_item_for_response( BP_XProfile_ProfileData $field_data, WP_REST_Request $request )

Prepares XProfile data to return as an object.

Description

Parameters

$field_data

(Required) XProfile field data object.

$request

(Required) Full data about the request.

Return

(WP_REST_Response)

Source

File: bp-xprofile/classes/class-bp-rest-xprofile-data-endpoint.php

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
public function prepare_item_for_response( $field_data, $request ) {
    $data = array(
        'id'           => $field_data->id,
        'field_id'     => $field_data->field_id,
        'user_id'      => $field_data->user_id,
        'value'        => array(
            'raw'          => $field_data->value,
            'unserialized' => $this->fields_endpoint->get_profile_field_unserialized_value( $field_data->value ),
            'rendered'     => $this->fields_endpoint->get_profile_field_rendered_value( $field_data->value, $field_data->field_id ),
        ),
        'last_updated' => bp_rest_prepare_date_response( $field_data->last_updated ),
    );
 
    $context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
    $data     = $this->add_additional_fields_to_object( $data, $request );
    $data     = $this->filter_response_by_context( $data, $context );
    $response = rest_ensure_response( $data );
 
    $response->add_links( $this->prepare_links( $field_data ) );
 
    /**
     * Filter the XProfile data response returned from the API.
     *
     * @param WP_REST_Response $response The response data.
     * @param WP_REST_Request $request Request used to generate the response.
     * @param BP_XProfile_ProfileData $field_data XProfile field data object.
     *
     * @since 0.1.0
     */
    return apply_filters( 'bp_rest_xprofile_data_prepare_value', $response, $request, $field_data );
}

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.