diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
index f98d1ad57e..f7954c67d7 100644
a
|
b
|
abstract class WP_REST_Controller { |
388 | 388 | continue; |
389 | 389 | } |
390 | 390 | |
391 | | if ( ! in_array( $field_name, $requested_fields, true ) ) { |
| 391 | if ( isset( $request['_fields'] ) && ! in_array( $field_name, $requested_fields, true ) ) { |
392 | 392 | continue; |
393 | 393 | } |
394 | 394 | |
diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php
index 10f6a6eebc..601cf9ec1d 100644
a
|
b
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
3365 | 3365 | $wp_rest_additional_fields = array(); |
3366 | 3366 | } |
3367 | 3367 | |
| 3368 | /** |
| 3369 | * @ticket 45220 |
| 3370 | */ |
| 3371 | public function test_get_additional_field_registration_null_schema() { |
| 3372 | register_rest_field( 'post', 'my_custom_int', array( |
| 3373 | 'schema' => null, |
| 3374 | 'get_callback' => array( $this, 'additional_field_get_callback' ), |
| 3375 | 'update_callback' => null, |
| 3376 | ) ); |
| 3377 | $post_id = $this->factory->post->create(); |
| 3378 | $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); |
| 3379 | |
| 3380 | $response = $this->server->dispatch( $request ); |
| 3381 | $this->assertArrayHasKey( 'my_custom_int', $response->data ); |
| 3382 | |
| 3383 | global $wp_rest_additional_fields; |
| 3384 | $wp_rest_additional_fields = array(); |
| 3385 | } |
| 3386 | |
3368 | 3387 | public function test_additional_field_update_errors() { |
3369 | 3388 | $schema = array( |
3370 | 3389 | 'type' => 'integer', |