From bcfb6d34f2f2b0fb513710e90565871c15dffe71 Mon Sep 17 00:00:00 2001 From: danielbachhuber Date: Mon, 19 Nov 2018 14:10:50 +0000 Subject: [PATCH] REST API: Include fields with null schema in `get_fields_for_response()`. In [43736], we prevented rendering fields when not present in `?_fields=`. However, because `get_fields_for_response()` is dependent on `get_item_schema()`, any custom fields registered with a null schema would be incorrectly excluded from the response. Because the REST API permits a null schema for `register_rest_field()`, those fields should be included in the available fields for a response. Fixes #45220. Built from https://develop.svn.wordpress.org/branches/5.0@43908 git-svn-id: http://core.svn.wordpress.org/branches/5.0@43740 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../rest-api/endpoints/class-wp-rest-controller.php | 10 ++++++++++ wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-controller.php index f98d1ad57e..caee7204ea 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-controller.php @@ -519,6 +519,16 @@ abstract class WP_REST_Controller { public function get_fields_for_response( $request ) { $schema = $this->get_item_schema(); $fields = isset( $schema['properties'] ) ? array_keys( $schema['properties'] ) : array(); + + $additional_fields = $this->get_additional_fields(); + foreach ( $additional_fields as $field_name => $field_options ) { + // For back-compat, include any field with an empty schema + // because it won't be present in $this->get_item_schema(). + if ( is_null( $field_options['schema'] ) ) { + $fields[] = $field_name; + } + } + if ( ! isset( $request['_fields'] ) ) { return $fields; } diff --git a/wp-includes/version.php b/wp-includes/version.php index d6ea670880..22ca5d3164 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-beta5-43907'; +$wp_version = '5.0-beta5-43908'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.