<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[59970] trunk: REST API: Fix fatal error when making HEAD requests with _fields filter.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/59970">59970</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/59970","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>TimothyBlynJacobs</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2025-03-11 14:17:41 +0000 (Tue, 11 Mar 2025)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>REST API: Fix fatal error when making HEAD requests with _fields filter.

In <a href="https://core.trac.wordpress.org/changeset/59889">[59889]</a> 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 <a href="https://core.trac.wordpress.org/ticket/56481">#56481</a>.
Props antonvlasenko, timothyblynjacobs, mamaduka, wildworks.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestautosavescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestblockpatterncategoriescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-pattern-categories-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestblocktypescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestcommentscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestfontcollectionscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestglobalstylesrevisionscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestpatterndirectorycontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestposttypescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestpostscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestrevisionscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestsearchcontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestsidebarscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswpresttaxonomiescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswpresttemplatescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswpresttermscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestuserscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestwidgettypescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestwidgetscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php</a></li>
<li><a href="#trunktestsphpunittestsfontsfontlibrarywpRestFontCollectionsControllerphp">trunk/tests/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestautosavescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-autosaves-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestblocktypecontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestcategoriescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestcommentscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestglobalstylesrevisionscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestpatterndirectorycontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestposttypescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestpostscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestrevisionscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestsidebarscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapiresttagscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapiresttaxonomiescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestuserscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-users-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestwidgettypescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-widget-types-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestwidgetscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapiwpRestBlockPatternCategoriesControllerphp">trunk/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php</a></li>
<li><a href="#trunktestsphpunittestsrestapiwpRestTemplateAutosavesControllerphp">trunk/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php</a></li>
<li><a href="#trunktestsphpunittestsrestapiwpRestTemplateRevisionsControllerphp">trunk/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php</a></li>
<li><a href="#trunktestsphpunittestsrestapiwpRestTemplatesControllerphp">trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesrestapiendpointsclasswprestautosavescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php   2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php     2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -307,7 +307,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Return early as this handler doesn't add any response headers.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">                $response  = array();
</span><span class="cx" style="display: block; padding: 0 10px">                $parent_id = $parent->ID;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -455,7 +455,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( 'rest_prepare_autosave', new WP_REST_Response(), $post, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( 'rest_prepare_autosave', new WP_REST_Response( array() ), $post, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">                $response = $this->revisions_controller->prepare_item_for_response( $post, $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $fields   = $this->get_fields_for_response( $request );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestblockpatterncategoriescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-pattern-categories-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-pattern-categories-controller.php    2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-pattern-categories-controller.php      2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -83,7 +83,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_items( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Return early as this handler doesn't add any response headers.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response   = array();
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestblocktypescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php 2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php   2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -133,7 +133,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_items( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Return early as this handler doesn't add any response headers.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $data        = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -258,7 +258,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( 'rest_prepare_block_type', new WP_REST_Response(), $block_type, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( 'rest_prepare_block_type', new WP_REST_Response( array() ), $block_type, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $fields = $this->get_fields_for_response( $request );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestcommentscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php    2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php      2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -313,7 +313,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $max_pages      = (int) ceil( $total_comments / $request['per_page'] );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = $is_head_request ? new WP_REST_Response() : rest_ensure_response( $comments );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $comments );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $response->header( 'X-WP-Total', $total_comments );
</span><span class="cx" style="display: block; padding: 0 10px">                $response->header( 'X-WP-TotalPages', $max_pages );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1054,7 +1054,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( 'rest_prepare_comment', new WP_REST_Response(), $comment, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( 'rest_prepare_comment', new WP_REST_Response( array() ), $comment, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $fields = $this->get_fields_for_response( $request );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestfontcollectionscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php    2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php      2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -113,7 +113,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $items[] = $item;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = $is_head_request ? new WP_REST_Response() : rest_ensure_response( $items );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $items );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response->header( 'X-WP-Total', (int) $total_items );
</span><span class="cx" style="display: block; padding: 0 10px">                $response->header( 'X-WP-TotalPages', $max_pages );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -193,7 +193,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         */
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                return apply_filters( 'rest_prepare_font_collection', new WP_REST_Response(), $item, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         return apply_filters( 'rest_prepare_font_collection', new WP_REST_Response( array() ), $item, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        foreach ( $data_fields as $field ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -209,7 +209,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( 'rest_prepare_font_collection', new WP_REST_Response(), $item, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( 'rest_prepare_font_collection', new WP_REST_Response( array() ), $item, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $data );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestglobalstylesrevisionscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php     2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php       2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -248,7 +248,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        $response = rest_ensure_response( $response );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $response = new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $response = new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response->header( 'X-WP-Total', (int) $total_revisions );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -291,7 +291,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function prepare_item_for_response( $post, $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $parent               = $this->get_parent( $request['parent'] );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestpatterndirectorycontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php   2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php     2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -163,7 +163,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Return early as this handler doesn't add any response headers.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = array();
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestposttypescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php  2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php    2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -111,7 +111,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_items( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Return early as this handler doesn't add any response headers.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $data  = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -186,7 +186,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( 'rest_prepare_post_type', new WP_REST_Response(), $post_type, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( 'rest_prepare_post_type', new WP_REST_Response( array() ), $post_type, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $taxonomies = wp_list_filter( get_object_taxonomies( $post_type->name, 'objects' ), array( 'show_in_rest' => true ) );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestpostscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php       2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -499,7 +499,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = $is_head_request ? new WP_REST_Response() : rest_ensure_response( $posts );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $posts );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response->header( 'X-WP-Total', (int) $total_posts );
</span><span class="cx" style="display: block; padding: 0 10px">                $response->header( 'X-WP-TotalPages', (int) $max_pages );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1847,7 +1847,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( "rest_prepare_{$this->post_type}", new WP_REST_Response(), $post, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( "rest_prepare_{$this->post_type}", new WP_REST_Response( array() ), $post, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $fields = $this->get_fields_for_response( $request );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestrevisionscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php   2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php     2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -355,7 +355,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        $response = rest_ensure_response( $response );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $response = new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $response = new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response->header( 'X-WP-Total', (int) $total_revisions );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -591,7 +591,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( 'rest_prepare_revision', new WP_REST_Response(), $post, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( 'rest_prepare_revision', new WP_REST_Response( array() ), $post, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $fields = $this->get_fields_for_response( $request );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestsearchcontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php      2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php        2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -165,7 +165,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = $is_head_request ? new WP_REST_Response() : rest_ensure_response( $results );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $results );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $response->header( 'X-WP-Total', $total );
</span><span class="cx" style="display: block; padding: 0 10px">                $response->header( 'X-WP-TotalPages', $max_pages );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestsidebarscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php    2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php      2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -121,7 +121,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_items( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Return early as this handler doesn't add any response headers.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->retrieve_widgets();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -329,7 +329,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( 'rest_prepare_sidebar', new WP_REST_Response(), $raw_sidebar, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( 'rest_prepare_sidebar', new WP_REST_Response( array() ), $raw_sidebar, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $id      = $raw_sidebar['id'];
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswpresttaxonomiescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php  2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php    2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -115,7 +115,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_items( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Return early as this handler doesn't add any response headers.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Retrieve the list of registered collection query parameters.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -217,7 +217,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( 'rest_prepare_taxonomy', new WP_REST_Response(), $taxonomy, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( 'rest_prepare_taxonomy', new WP_REST_Response( array() ), $taxonomy, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswpresttemplatescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php   2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php     2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -271,7 +271,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_items( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Return early as this handler doesn't add any response headers.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $query = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -675,7 +675,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function prepare_item_for_response( $item, $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /*
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswpresttermscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php       2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php 2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -370,7 +370,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = $is_head_request ? new WP_REST_Response() : rest_ensure_response( $response );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $response );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Store pagination values for headers.
</span><span class="cx" style="display: block; padding: 0 10px">                $per_page = (int) $prepared_args['number'];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -899,7 +899,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( "rest_prepare_{$this->taxonomy}", new WP_REST_Response(), $item, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( "rest_prepare_{$this->taxonomy}", new WP_REST_Response( array() ), $item, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $fields = $this->get_fields_for_response( $request );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestuserscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php       2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php 2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -384,7 +384,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = $is_head_request ? new WP_REST_Response() : rest_ensure_response( $users );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $users );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Store pagination values for headers then unset for count query.
</span><span class="cx" style="display: block; padding: 0 10px">                $per_page = (int) $prepared_args['number'];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1032,7 +1032,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( 'rest_prepare_user', new WP_REST_Response(), $user, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( 'rest_prepare_user', new WP_REST_Response( array() ), $user, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $fields = $this->get_fields_for_response( $request );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestwidgettypescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php        2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php  2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -147,7 +147,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_items( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Return early as this handler doesn't add any response headers.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $data = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -306,7 +306,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( 'rest_prepare_widget_type', new WP_REST_Response(), $widget_type, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( 'rest_prepare_widget_type', new WP_REST_Response( array() ), $widget_type, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $fields = $this->get_fields_for_response( $request );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestwidgetscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php     2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php       2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -138,7 +138,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_items( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Return early as this handler doesn't add any response headers.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_REST_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_REST_Response( array() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->retrieve_widgets();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -686,7 +686,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Don't prepare the response body for HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return apply_filters( 'rest_prepare_widget', new WP_REST_Response(), $widget, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return apply_filters( 'rest_prepare_widget', new WP_REST_Response( array() ), $widget, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $parsed_id = wp_parse_widget_id( $widget_id );
</span></span></pre></div>
<a id="trunktestsphpunittestsfontsfontlibrarywpRestFontCollectionsControllerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php  2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php    2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -108,7 +108,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $content, 'The response should be empty.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $content, 'The response should be empty.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $headers = $response->get_headers();
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'X-WP-Total', $headers, 'The "X-WP-Total" header should be present in the response.' );
</span><span class="cx" style="display: block; padding: 0 10px">                // Includes non-valid collections.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -172,7 +172,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestautosavescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-autosaves-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-autosaves-controller.php  2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-autosaves-controller.php    2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -196,7 +196,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotWPError( $response );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -314,7 +314,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_item_embed_context() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -889,4 +889,35 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status() );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( $autosave['id'], $data['id'], 'Original autosave was not returned' );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               wp_set_current_user( self::$editor_id );
+               $request = new WP_REST_Request( 'HEAD', sprintf( $path, self::$post_id, self::$autosave_post_id ) );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/posts/%d/autosaves/%d' ),
+                       'get_items request' => array( '/wp/v2/posts/%d' ),
+               );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestblocktypecontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php 2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php   2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -636,7 +636,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -659,10 +659,41 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $request  = new WP_REST_Request( 'HEAD', '/wp/v2/block-types' );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'HEAD', $path );
+               $request->set_param( '_fields', 'title' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/block-types/fake/test' ),
+                       'get_items request' => array( '/wp/v2/block-types' ),
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @dataProvider data_readable_http_methods
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 47620
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 56481
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestcategoriescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php 2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php   2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1360,6 +1360,36 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               $request = new WP_REST_Request( 'HEAD', $path );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/categories/1' ),
+                       'get_items request' => array( '/wp/v2/categories' ),
+               );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestcommentscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php   2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php     2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3567,6 +3567,36 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               $request = new WP_REST_Request( 'HEAD', sprintf( $path, self::$approved_id ) );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/comments/%d' ),
+                       'get_items request' => array( '/wp/v2/comments' ),
+               );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestglobalstylesrevisionscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php    2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php      2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -336,10 +336,41 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $request  = new WP_REST_Request( 'HEAD', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'Response status is 200.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'GET', sprintf( $path, self::$global_styles_id, $this->revision_1_id ) );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/global-styles/%d/revisions/%d' ),
+                       'get_items request' => array( '/wp/v2/global-styles/%d/revisions' ),
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @ticket 59810
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @covers WP_REST_Global_Styles_Controller::get_item
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -366,7 +397,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $request  = new WP_REST_Request( 'HEAD', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions/' . $this->revision_1_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'Response status is 200.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestpatterndirectorycontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php  2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php    2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -167,10 +167,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 56481
+        */
+       public function test_get_items_head_request_with_specified_fields_returns_success_response() {
+               wp_set_current_user( self::$contributor_id );
+               self::mock_successful_response( 'browse-all', true );
+               $request = new WP_REST_Request( 'HEAD', '/wp/v2/pattern-directory/patterns' );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @covers WP_REST_Pattern_Directory_Controller::get_items
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.8.0
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestposttypescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php 2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php   2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -111,10 +111,40 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               $request = new WP_REST_Request( 'HEAD', $path );
+               $request->set_param( '_fields', 'slug' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/types/post' ),
+                       'get_items request' => array( '/wp/v2/types' ),
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @ticket 53656
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_item_cpt() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -324,7 +354,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                remove_filter( $hook_name, $callback );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        protected function check_post_type_obj( $context, $post_type_obj, $data, $links ) {
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestpostscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php      2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php        2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -295,7 +295,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $headers = $response->get_headers();
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'Link', $headers, 'The "Link" header should be present in the response.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -320,7 +320,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'HEAD' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertNull( $response->get_data(), 'Failed asserting that response data is null for HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertSame( array(), $response->get_data(), 'Failed asserting that response data is null for HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 } else {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( array(), $response->get_data(), 'Failed asserting that response data is an empty array for GET request.' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -351,7 +351,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertCount( $total_posts, $response->get_data() );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertNull( $response->get_data(), 'Failed asserting that response data is null for HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertSame( array(), $response->get_data(), 'Failed asserting that response data is null for HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $headers = $response->get_headers();
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( $total_posts, $headers['X-WP-Total'] );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -366,7 +366,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertCount( 2, $data );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSameSets( array( self::$editor_id, self::$author_id ), wp_list_pluck( $data, 'author' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertNull( $data, 'Failed asserting that response data is null for HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertSame( array(), $data, 'Failed asserting that response data is null for HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $headers = $response->get_headers();
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( 2, $headers['X-WP-Total'], 'Failed asserting that X-WP-Total header is 2.' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -381,7 +381,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertCount( 1, $data );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( self::$editor_id, $data[0]['author'] );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertNull( $data, 'Failed asserting that response data is null for HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertSame( array(), $data, 'Failed asserting that response data is null for HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $headers = $response->get_headers();
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( 1, $headers['X-WP-Total'], 'Failed asserting that X-WP-Total header is 1.' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -407,7 +407,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->is_method( 'get' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertCount( $total_posts, $response->get_data() );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertNull( $response->get_data(), 'Failed asserting that response data is null for HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertSame( array(), $response->get_data(), 'Failed asserting that response data is null for HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $headers = $response->get_headers();
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( $total_posts, $headers['X-WP-Total'], 'Failed asserting that the number of posts is correct.' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -424,7 +424,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertNotEquals( self::$editor_id, $data[0]['author'] );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertNotEquals( self::$author_id, $data[0]['author'] );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertNull( $response->get_data(), 'Failed asserting that response data is null for HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertSame( array(), $response->get_data(), 'Failed asserting that response data is null for HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $headers = $response->get_headers();
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( $total_posts - 2, $headers['X-WP-Total'], 'Failed asserting that the number of posts is correct.' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -441,7 +441,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertNotEquals( self::$editor_id, $data[0]['author'] );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertNotEquals( self::$editor_id, $data[1]['author'] );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertNull( $response->get_data(), 'Failed asserting that response data is null for HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertSame( array(), $response->get_data(), 'Failed asserting that response data is null for HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $headers = $response->get_headers();
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( $total_posts - 1, $headers['X-WP-Total'], 'Failed asserting that the number of posts is correct.' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -483,7 +483,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertCount( 2, $data );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( $id2, $data[0]['id'] );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertNull( $data, 'Failed asserting that response data is null for HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertSame( array(), $data, 'Failed asserting that response data is null for HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $headers = $response->get_headers();
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( 2, $headers['X-WP-Total'], 'Failed asserting that the number of posts is correct.' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -498,7 +498,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertCount( 2, $data );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( $id1, $data[0]['id'] );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertNull( $data, 'Failed asserting that response data is null for HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertSame( array(), $data, 'Failed asserting that response data is null for HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $headers = $response->get_headers();
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( 2, $headers['X-WP-Total'], 'Failed asserting that the number of posts is correct.' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2193,9 +2193,39 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               $request = new WP_REST_Request( 'HEAD', sprintf( $path, self::$post_id ) );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/posts/%d' ),
+                       'get_items request' => array( '/wp/v2/posts' ),
+               );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_item_links() {
</span><span class="cx" style="display: block; padding: 0 10px">                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_get_server()->dispatch( $request );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestrevisionscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php  2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php    2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -182,7 +182,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -300,9 +300,41 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'GET' === $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               wp_set_current_user( self::$editor_id );
+               $request = new WP_REST_Request( 'HEAD', sprintf( $path, self::$post_id, $this->revision_id1 ) );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+
+                       'get_item request'  => array( '/wp/v2/posts/%d/revisions/%d' ),
+                       'get_items request' => array( '/wp/v2/posts/%d/revisions' ),
+               );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_item_embed_context() {
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( self::$editor_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestsidebarscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php   2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php     2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -171,7 +171,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -567,10 +567,49 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               $this->setup_sidebar(
+                       'sidebar-1',
+                       array(
+                               'name' => 'Test sidebar',
+                       )
+               );
+
+               $request = new WP_REST_Request( 'HEAD', $path );
+               // This endpoint doesn't seem to support _fields param, but we need to set it to reproduce the fatal error.
+               $request->set_param( '_fields', 'name' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+
+                       'get_item request'  => array( '/wp/v2/sidebars/sidebar-1' ),
+                       'get_items request' => array( '/wp/v2/sidebars' ),
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Data provider intended to provide HTTP method names for testing GET and HEAD requests.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapiresttagscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php       2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php 2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1614,6 +1614,37 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               $tag_id  = self::factory()->tag->create();
+               $request = new WP_REST_Request( 'HEAD', sprintf( $path, $tag_id ) );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/tags/%d' ),
+                       'get_items request' => array( '/wp/v2/tags' ),
+               );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapiresttaxonomiescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php 2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php   2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -73,7 +73,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                remove_filter( $hook_name, $callback );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_items_context_edit() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -185,9 +185,39 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               $request = new WP_REST_Request( 'HEAD', $path );
+               $request->set_param( '_fields', 'name' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/taxonomies/category' ),
+                       'get_items request' => array( '/wp/v2/taxonomies' ),
+               );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_item_edit_context() {
</span><span class="cx" style="display: block; padding: 0 10px">                $editor_id = self::factory()->user->create( array( 'role' => 'editor' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( $editor_id );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestuserscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-users-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-users-controller.php      2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-users-controller.php        2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -254,7 +254,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' === $method ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertNull( $response->get_data(), 'Expected null response data for HEAD request, but received non-null data.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertSame( array(), $response->get_data(), 'Expected null response data for HEAD request, but received non-null data.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3251,7 +3251,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3272,7 +3272,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status() );
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $is_head_request ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertNull( $response->get_data() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertSame( array(), $response->get_data() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 } else {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertNotEmpty( $response->get_data() );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3306,6 +3306,39 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertMatchesRegularExpression( $pattern, $query->request, 'The SQL query does not match the expected string.' );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               $user_id = self::factory()->user->create();
+               wp_set_current_user( self::$user );
+
+               $request = new WP_REST_Request( 'HEAD', sprintf( $path, $user_id ) );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/users/%d' ),
+                       'get_items request' => array( '/wp/v2/users' ),
+               );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         protected function check_user_data( $user, $data, $context, $links ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( $user->ID, $data['id'] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( $user->display_name, $data['name'] );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestwidgettypescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-widget-types-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-widget-types-controller.php       2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-widget-types-controller.php 2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -129,7 +129,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $request  = new WP_REST_Request( 'HEAD', '/wp/v2/widget-types' );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -227,7 +227,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -243,6 +243,37 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'HEAD', $path );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/widget-types/calendar' ),
+                       'get_items request' => array( '/wp/v2/widget-types' ),
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @ticket 41683
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_widget_legacy() {
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestwidgetscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php    2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php      2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -472,7 +472,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotWPError( $response );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function mocked_rss_response() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -644,10 +644,71 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'HEAD' !== $method ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               add_filter( 'pre_http_request', array( $this, 'mocked_rss_response' ) );
+               global $wp_widget_factory;
+
+               $wp_widget_factory->widgets['WP_Widget_RSS']->widget_options['show_instance_in_rest'] = false;
+
+               $block_content = '<!-- wp:paragraph --><p>Block test</p><!-- /wp:paragraph -->';
+
+               $this->setup_widget(
+                       'rss',
+                       1,
+                       array(
+                               'title' => 'RSS test',
+                               'url'   => 'https://wordpress.org/news/feed',
+                       )
+               );
+               $this->setup_widget(
+                       'block',
+                       1,
+                       array(
+                               'content' => $block_content,
+                       )
+               );
+               $this->setup_sidebar(
+                       'sidebar-1',
+                       array(
+                               'name' => 'Test sidebar',
+                       ),
+                       array( 'block-1', 'rss-1', 'testwidget' )
+               );
+
+               $request = new WP_REST_Request( 'HEAD', $path );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+               remove_filter( 'pre_http_request', array( $this, 'mocked_rss_response' ) );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/widgets/block-1' ),
+                       'get_items request' => array( '/wp/v2/widgets' ),
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @dataProvider data_readable_http_methods
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 41683
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 56481
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapiwpRestBlockPatternCategoriesControllerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php     2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php       2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -131,10 +131,28 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $request  = new WP_REST_Request( 'HEAD', static::REQUEST_ROUTE );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response() {
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'HEAD', static::REQUEST_ROUTE );
+               $request->set_param( '_fields', 'name' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Verify capability check for unauthorized request (not logged in).
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_items_unauthorized() {
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapiwpRestTemplateAutosavesControllerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php  2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php    2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -316,7 +316,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'Response status is 200.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -470,7 +470,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $request  = new WP_REST_Request( 'HEAD', '/wp/v2/templates/' . self::TEST_THEME . '/' . self::TEMPLATE_NAME . '/autosaves/' . $autosave_post_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'Response status is 200.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -486,6 +486,79 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @dataProvider data_get_item_with_data_provider
+        * @covers       WP_REST_Template_Autosaves_Controller::get_item
+        * @ticket 56922
+        *
+        * @param string $parent_post_property_name A class property name that contains the parent post object.
+        * @param string $rest_base Base part of the REST API endpoint to test.
+        * @param string $template_id Template ID to use in the test.
+        */
+       public function test_get_item_head_request_with_specified_fields_returns_success_response( $parent_post_property_name, $rest_base, $template_id ) {
+               wp_set_current_user( self::$admin_id );
+
+               $parent_post = self::$$parent_post_property_name;
+
+               $autosave_post_id = wp_create_post_autosave(
+                       array(
+                               'post_content' => 'Autosave content.',
+                               'post_ID'      => $parent_post->ID,
+                               'post_type'    => $parent_post->post_type,
+                       )
+               );
+
+               $request = new WP_REST_Request(
+                       'HEAD',
+                       '/wp/v2/' . $rest_base . '/' . $template_id . '/autosaves/' . $autosave_post_id
+               );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * @dataProvider data_get_items_with_data_provider
+        * @covers       WP_REST_Template_Autosaves_Controller::get_items
+        * @ticket 56922
+        *
+        * @param string $parent_post_property_name A class property name that contains the parent post object.
+        * @param string $rest_base Base part of the REST API endpoint to test.
+        * @param string $template_id Template ID to use in the test.
+        */
+       public function test_get_items_head_request_with_specified_fields_returns_success_response( $parent_post_property_name, $rest_base, $template_id ) {
+               wp_set_current_user( self::$admin_id );
+               // Cannot access this property in the data provider because it is not initialized at the time of execution.
+               $parent_post = self::$$parent_post_property_name;
+               wp_create_post_autosave(
+                       array(
+                               'post_content' => 'Autosave content.',
+                               'post_ID'      => $parent_post->ID,
+                               'post_type'    => $parent_post->post_type,
+                       )
+               );
+
+               $request = new WP_REST_Request(
+                       'HEAD',
+                       '/wp/v2/' . $rest_base . '/' . $template_id . '/autosaves'
+               );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @coversNothing
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 56922
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapiwpRestTemplateRevisionsControllerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php  2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php    2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -437,7 +437,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'Response status is 200.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -627,7 +627,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $request     = new WP_REST_Request( 'HEAD', '/wp/v2/templates/' . self::TEST_THEME . '/' . self::TEMPLATE_NAME . '/revisions/' . $revision_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $response    = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'Response status is 200.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -643,6 +643,65 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @dataProvider data_get_item_with_data_provider
+        * @covers       WP_REST_Template_Revisions_Controller::get_item
+        * @ticket 56922
+        *
+        * @param string $parent_post_property_name A class property name that contains the parent post object.
+        * @param string $rest_base Base part of the REST API endpoint to test.
+        * @param string $template_id Template ID to use in the test.
+        */
+       public function test_get_item_head_request_with_specified_fields_returns_success_response( $parent_post_property_name, $rest_base, $template_id ) {
+               wp_set_current_user( self::$admin_id );
+
+               $parent_post = self::$$parent_post_property_name;
+
+               $revisions   = wp_get_post_revisions( $parent_post, array( 'fields' => 'ids' ) );
+               $revision_id = array_shift( $revisions );
+
+               $request = new WP_REST_Request(
+                       'HEAD',
+                       '/wp/v2/' . $rest_base . '/' . $template_id . '/revisions/' . $revision_id
+               );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * @dataProvider data_get_items_with_data_provider
+        * @covers       WP_REST_Template_Revisions_Controller::get_items
+        * @ticket 56922
+        *
+        * @param string $parent_post_property_name A class property name that contains the parent post object.
+        * @param string $rest_base Base part of the REST API endpoint to test.
+        * @param string $template_id Template ID to use in the test.
+        */
+       public function test_get_items_head_request_with_specified_fields_returns_success_response( $parent_post_property_name, $rest_base, $template_id ) {
+               wp_set_current_user( self::$admin_id );
+               $parent_post = self::$$parent_post_property_name;
+
+               $request = new WP_REST_Request(
+                       'HEAD',
+                       '/wp/v2/' . $rest_base . '/' . $template_id . '/revisions'
+               );
+
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @dataProvider data_get_item_not_found
</span><span class="cx" style="display: block; padding: 0 10px">         * @covers WP_REST_Template_Revisions_Controller::get_item
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 56922
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapiwpRestTemplatesControllerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php  2025-03-11 14:05:37 UTC (rev 59969)
+++ trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php    2025-03-11 14:17:41 UTC (rev 59970)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -185,10 +185,41 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $request  = new WP_REST_Request( 'HEAD', '/wp/v2/templates' );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'Response status is 200.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @dataProvider data_head_request_with_specified_fields_returns_success_response
+        * @ticket 56481
+        *
+        * @param string $path The path to test.
+        */
+       public function test_head_request_with_specified_fields_returns_success_response( $path ) {
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'HEAD', $path );
+               $request->set_param( '_fields', 'id' );
+               $server   = rest_get_server();
+               $response = $server->dispatch( $request );
+               add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
+               $response = apply_filters( 'rest_post_dispatch', $response, $server, $request );
+               remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
+
+               $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' );
+       }
+
+       /**
+        * Data provider intended to provide paths for testing HEAD requests.
+        *
+        * @return array
+        */
+       public static function data_head_request_with_specified_fields_returns_success_response() {
+               return array(
+                       'get_item request'  => array( '/wp/v2/templates/default//my_template' ),
+                       'get_items request' => array( '/wp/v2/templates' ),
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @covers WP_REST_Templates_Controller::get_items
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_items_editor() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -291,7 +322,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $request  = new WP_REST_Request( 'HEAD', '/wp/v2/templates/default//my_template' );
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 200, $response->get_status(), 'Response status is 200.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre>
</div>
</div>

</body>
</html>