WordPress at a glance
function is not described

register_rest_field() WP 4.7.0

Registers a new field on an existing WordPress object type.

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

No Hooks.

Return

Nothing (null).

Usage

register_rest_field( $object_type, $attribute, $args );
$object_type(string/array) (required)
Object(s) the field is being registered to, "post"|"term"|"comment" etc.
$attribute(string) (required)
The attribute name.
$args(array)

An array of arguments used to handle the registered field.

  • $get_callback (string/array/null)
    Optional. The callback function used to retrieve the field value.
    Default: 'null', the field will not be returned in the response

  • $update_callback (string/array/null)
    Optional. The callback function used to set and update the field value.
    Default: 'null', the value cannot be set or updated

  • $schema (string/array/null)
    Optional. The callback function used to create the schema for this field.
    Default: 'null', no schema entry will be returned

Default: array()

Code of register rest field: wp-includes/rest-api.php VER 5.1.1

<?php
function register_rest_field( $object_type, $attribute, $args = array() ) {
	$defaults = array(
		'get_callback'    => null,
		'update_callback' => null,
		'schema'          => null,
	);

	$args = wp_parse_args( $args, $defaults );

	global $wp_rest_additional_fields;

	$object_types = (array) $object_type;

	foreach ( $object_types as $object_type ) {
		$wp_rest_additional_fields[ $object_type ][ $attribute ] = $args;
	}
}