WP_REST_Controller::add_additional_fields_to_object( array $object, WP_REST_Request $request )

Adds the values from additional fields to a data object.


Description Description


Parameters Parameters

$object

(array) (Required) Data object.

$request

(WP_REST_Request) (Required) Full details about the request.


Top ↑

Return Return

(array) Modified data object with additional fields.


Top ↑

Source Source

File: wp-includes/rest-api/endpoints/class-wp-rest-controller.php

	protected function add_additional_fields_to_object( $object, $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 ( ! in_array( $field_name, $requested_fields, true ) ) {
				continue;
			}

			$object[ $field_name ] = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type() );
		}

		return $object;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
4.7.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.