Skip to content

Commit

Permalink
Short circuit the WP_REST_Autosaves_Controller controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
janusqa authored and anton-vlasenko committed Dec 30, 2024
1 parent d67ea1d commit 23e5b16
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ public function get_items( $request ) {
return $parent;
}

if ( $request->is_method( 'HEAD' ) ) {
// Return early as this handler doesn't add any response headers.
return new WP_REST_Response();
}
$response = array();
$parent_id = $parent->ID;
$revisions = wp_get_post_revisions( $parent_id, array( 'check_enabled' => false ) );
Expand Down Expand Up @@ -448,6 +452,11 @@ public function prepare_item_for_response( $item, $request ) {
// Restores the more descriptive, specific name for use within this method.
$post = $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-autosaves-controller.php */
return apply_filters( 'rest_prepare_autosave', new WP_REST_Response(), $post, $request );
}
$response = $this->revisions_controller->prepare_item_for_response( $post, $request );
$fields = $this->get_fields_for_response( $request );

Expand Down

0 comments on commit 23e5b16

Please sign in to comment.