- Timestamp:
- 03/02/2025 10:05:08 PM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r59882 r59899 263 263 } 264 264 265 $is_head_request = $request->is_method( 'HEAD' ); 266 if ( $is_head_request ) { 267 // Force the 'fields' argument. For HEAD requests, only post IDs are required to calculate pagination. 268 $prepared_args['fields'] = 'ids'; 269 // Disable priming comment meta for HEAD requests to improve performance. 270 $prepared_args['update_comment_meta_cache'] = false; 271 } 272 265 273 /** 266 274 * Filters WP_Comment_Query arguments when querying comments via the REST API. … … 278 286 $query_result = $query->query( $prepared_args ); 279 287 280 $comments = array(); 281 282 foreach ( $query_result as $comment ) { 283 if ( ! $this->check_read_permission( $comment, $request ) ) { 284 continue; 285 } 286 287 $data = $this->prepare_item_for_response( $comment, $request ); 288 $comments[] = $this->prepare_response_for_collection( $data ); 288 if ( ! $is_head_request ) { 289 $comments = array(); 290 291 foreach ( $query_result as $comment ) { 292 if ( ! $this->check_read_permission( $comment, $request ) ) { 293 continue; 294 } 295 296 $data = $this->prepare_item_for_response( $comment, $request ); 297 $comments[] = $this->prepare_response_for_collection( $data ); 298 } 289 299 } 290 300 … … 304 314 } 305 315 306 $response = rest_ensure_response( $comments );316 $response = $is_head_request ? new WP_REST_Response() : rest_ensure_response( $comments ); 307 317 $response->header( 'X-WP-Total', $total_comments ); 308 318 $response->header( 'X-WP-TotalPages', $max_pages ); … … 1041 1051 // Restores the more descriptive, specific name for use within this method. 1042 1052 $comment = $item; 1053 1054 // Don't prepare the response body for HEAD requests. 1055 if ( $request->is_method( 'HEAD' ) ) { 1056 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php */ 1057 return apply_filters( 'rest_prepare_comment', new WP_REST_Response(), $comment, $request ); 1058 } 1043 1059 1044 1060 $fields = $this->get_fields_for_response( $request );
Note: See TracChangeset
for help on using the changeset viewer.