Adds the values from additional fields to a data object.
Parameters
$response_data
arrayrequired- Prepared response array.
$request
WP_REST_Requestrequired- Full details about the request.
Source
protected function add_additional_fields_to_object( $response_data, $request ) {
$additional_fields = $this->get_additional_fields();
$requested_fields = $this->get_fields_for_response( $request );
foreach ( $additional_fields as $field_name => $field_options ) {
if ( ! $field_options['get_callback'] ) {
continue;
}
if ( ! rest_is_field_included( $field_name, $requested_fields ) ) {
continue;
}
$response_data[ $field_name ] = call_user_func(
$field_options['get_callback'],
$response_data,
$field_name,
$request,
$this->get_object_type()
);
}
return $response_data;
}
Changelog
Version | Description |
---|---|
4.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.