WP_REST_Controller::get_additional_fields() WordPress Method

The WP_REST_Controller::get_additional_fields() method allows developers to register additional fields for a REST API request. This is useful for adding extra data to an existing request, or for adding new data to a request.

WP_REST_Controller::get_additional_fields( string $object_type = null ) #

Retrieves all of the registered additional fields for a given object-type.


Parameters

$object_type

(string)(Optional) The object type.

Default value: null


Top ↑

Return

(array) Registered additional fields (if any), empty array if none or if the object type could not be inferred.


Top ↑

Source

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

	protected function get_additional_fields( $object_type = null ) {
		global $wp_rest_additional_fields;

		if ( ! $object_type ) {
			$object_type = $this->get_object_type();
		}

		if ( ! $object_type ) {
			return array();
		}

		if ( ! $wp_rest_additional_fields || ! isset( $wp_rest_additional_fields[ $object_type ] ) ) {
			return array();
		}

		return $wp_rest_additional_fields[ $object_type ];
	}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.