WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/19/2018 02:09:07 PM (2 years ago)
Author:
danielbachhuber
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php

    r43834 r43908  
    520520        $schema = $this->get_item_schema();
    521521        $fields = isset( $schema['properties'] ) ? array_keys( $schema['properties'] ) : array();
     522
     523        $additional_fields = $this->get_additional_fields();
     524        foreach ( $additional_fields as $field_name => $field_options ) {
     525            // For back-compat, include any field with an empty schema
     526            // because it won't be present in $this->get_item_schema().
     527            if ( is_null( $field_options['schema'] ) ) {
     528                $fields[] = $field_name;
     529            }
     530        }
     531
    522532        if ( ! isset( $request['_fields'] ) ) {
    523533            return $fields;
Note: See TracChangeset for help on using the changeset viewer.