Make WordPress Core


Ignore:
Timestamp:
03/11/2025 02:17:41 PM (12 months ago)
Author:
TimothyBlynJacobs
Message:

REST API: Fix fatal error when making HEAD requests with _fields filter.

In [59889] the REST API controllers were adjusted to perform less work when responding to HEAD requests. The WP_REST_Response body would now be null, which caused issues with filters that expected the response body to be an array.

This commit sets the response body to be an empty array when preparing the response instead. The body will still be discarded, but this provides better backward comppatibility with code that assumes an array will be used.

See #56481.
Props antonvlasenko, timothyblynjacobs, mamaduka, wildworks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php

    r59899 r59970  
    109109        }
    110110
    111         $this->assertNull( $content, 'The response should be empty.' );
     111        $this->assertSame( array(), $content, 'The response should be empty.' );
    112112        $headers = $response->get_headers();
    113113        $this->assertArrayHasKey( 'X-WP-Total', $headers, 'The "X-WP-Total" header should be present in the response.' );
     
    173173            return null;
    174174        }
    175         $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
     175        $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
    176176    }
    177177
Note: See TracChangeset for help on using the changeset viewer.