diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php --- a/wp/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php Fri Sep 05 18:40:08 2025 +0200 @@ -244,6 +244,8 @@ $prepared_args['no_found_rows'] = false; + $prepared_args['update_comment_post_cache'] = true; + $prepared_args['date_query'] = array(); // Set before into date query. Date query must be specified as an array of an array. @@ -272,7 +274,7 @@ */ $prepared_args = apply_filters( 'rest_comment_query', $prepared_args, $request ); - $query = new WP_Comment_Query; + $query = new WP_Comment_Query(); $query_result = $query->query( $prepared_args ); $comments = array(); @@ -293,11 +295,12 @@ // Out-of-bounds, run the query again without LIMIT for total count. unset( $prepared_args['number'], $prepared_args['offset'] ); - $query = new WP_Comment_Query; - $prepared_args['count'] = true; + $query = new WP_Comment_Query(); + $prepared_args['count'] = true; + $prepared_args['orderby'] = 'none'; $total_comments = $query->query( $prepared_args ); - $max_pages = ceil( $total_comments / $request['per_page'] ); + $max_pages = (int) ceil( $total_comments / $request['per_page'] ); } $response = rest_ensure_response( $comments ); @@ -1037,8 +1040,9 @@ public function prepare_item_for_response( $item, $request ) { // Restores the more descriptive, specific name for use within this method. $comment = $item; - $fields = $this->get_fields_for_response( $request ); - $data = array(); + + $fields = $this->get_fields_for_response( $request ); + $data = array(); if ( in_array( 'id', $fields, true ) ) { $data['id'] = (int) $comment->comment_ID; @@ -1087,7 +1091,7 @@ if ( in_array( 'content', $fields, true ) ) { $data['content'] = array( /** This filter is documented in wp-includes/comment-template.php */ - 'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment ), + 'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment, array() ), 'raw' => $comment->comment_content, ); } @@ -1119,7 +1123,9 @@ // Wrap the data in a response object. $response = rest_ensure_response( $data ); - $response->add_links( $this->prepare_links( $comment ) ); + if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { + $response->add_links( $this->prepare_links( $comment ) ); + } /** * Filters a comment returned from the REST API. @@ -1183,8 +1189,8 @@ // Only grab one comment to verify the comment has children. $comment_children = $comment->get_children( array( - 'number' => 1, - 'count' => true, + 'count' => true, + 'orderby' => 'none', ) ); @@ -1757,8 +1763,10 @@ $posts_controller = $post_type->get_rest_controller(); - // Ensure the posts controller is specifically a WP_REST_Posts_Controller instance - // before using methods specific to that controller. + /* + * Ensure the posts controller is specifically a WP_REST_Posts_Controller instance + * before using methods specific to that controller. + */ if ( ! $posts_controller instanceof WP_REST_Posts_Controller ) { $posts_controller = new WP_REST_Posts_Controller( $post->post_type ); } @@ -1883,11 +1891,11 @@ $prepared_comment, array( 'comment_post_ID' => 0, - 'comment_parent' => 0, - 'user_ID' => 0, 'comment_author' => null, 'comment_author_email' => null, 'comment_author_url' => null, + 'comment_parent' => 0, + 'user_id' => 0, ) );