WP_REST_Controller::get_additional_fields()protectedWP 4.7.0

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

Method of the class: WP_REST_Controller{}

No Hooks.

Return

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

Usage

// protected - for code of main (parent) or child class
$result = $this->get_additional_fields( $object_type );
$object_type(string)
The object type.
Default: null

Notes

  • Global. Array. $wp_rest_additional_fields Holds registered fields, organized by object type.

Changelog

Since 4.7.0 Introduced.

WP_REST_Controller::get_additional_fields() code WP 6.6.2

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 ];
}