Skip to content

Commit

Permalink
Short circuit the WP_REST_Sidebars_Controller controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-vlasenko committed Dec 27, 2024
1 parent 46a34f9 commit 8796373
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 );

Expand Down

0 comments on commit 8796373

Please sign in to comment.