From 8796373ba51fb9d456d4d1ddd98f3f845aef9a3f Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 27 Dec 2024 19:20:38 +0100 Subject: [PATCH] Short circuit the WP_REST_Sidebars_Controller controller. --- .../endpoints/class-wp-rest-sidebars-controller.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php index 4ff100723757c..afb51a4da98a7 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php @@ -119,6 +119,11 @@ public function get_items_permissions_check( $request ) { * @return WP_REST_Response Response object on success. */ public function get_items( $request ) { + // Don't prepare the response body for HEAD requests. + if ( $request->is_method( 'HEAD' ) ) { + return new WP_REST_Response(); + } + $this->retrieve_widgets(); $data = array(); @@ -321,6 +326,12 @@ public function prepare_item_for_response( $item, $request ) { // Restores the more descriptive, specific name for use within this method. $raw_sidebar = $item; + // Don't prepare the response body for HEAD requests. + if ( $request->is_method( 'HEAD' ) ) { + /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php */ + return apply_filters( 'rest_prepare_sidebar', new WP_REST_Response(), $raw_sidebar, $request ); + } + $id = $raw_sidebar['id']; $sidebar = array( 'id' => $id );