Make WordPress Core

Ticket #45220: 45220.1.diff

File 45220.1.diff, 1.7 KB (added by danielbachhuber, 6 years ago)
  • src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php

    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 { 
    388388                                continue;
    389389                        }
    390390
    391                         if ( ! in_array( $field_name, $requested_fields, true ) ) {
     391                        if ( isset( $request['_fields'] ) && ! in_array( $field_name, $requested_fields, true ) ) {
    392392                                continue;
    393393                        }
    394394
  • tests/phpunit/tests/rest-api/rest-posts-controller.php

    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 
    33653365                $wp_rest_additional_fields = array();
    33663366        }
    33673367
     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
    33683387        public function test_additional_field_update_errors() {
    33693388                $schema = array(
    33703389                        'type'        => 'integer',