rest_is_field_included

Advertisement

Summery Summery

Given an array of fields to include in a response, some of which may be nested.fields, determine whether the provided field should be included in the response body.

Syntax Syntax

rest_is_field_included( string $field, array $fields )

Description Description

If a parent field is passed in, the presence of any nested field within that parent will cause the method to return true. For example "title" will return true if any of title, title.raw or title.rendered is provided.

Parameters Parameters

$field

(string) (Required) A field to test for inclusion in the response body.

$fields

(array) (Required) An array of string fields supported by the endpoint.

Return Return

(bool) Whether to include the field or not.

Source Source

File: wp-includes/rest-api.php

 * @since 4.8.0
 *
 * @param WP_REST_Response $response Current response being served.
 * @param WP_REST_Server   $server   ResponseHandler instance (usually WP_REST_Server).
 * @param WP_REST_Request  $request  The request that was used to make current response.
 * @return WP_REST_Response Response to be served, trimmed down to contain a subset of fields.
 */
function rest_filter_response_fields( $response, $server, $request ) {
	if ( ! isset( $request['_fields'] ) || $response->is_error() ) {
		return $response;
	}

	$data = $response->get_data();

	$fields = wp_parse_list( $request['_fields'] );

	if ( 0 === count( $fields ) ) {
		return $response;
	}

Advertisement

Changelog Changelog

Changelog
Version Description
5.3.0 Introduced.

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.