mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-05 10:22:23 +01:00
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
This commit is contained in:
parent
b8906e5e95
commit
bcfb6d34f2
@ -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;
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user