Skip to content

Commit 43f9563

Browse files
committed
Docs: Cast header values to strings in WP_REST_Comments_Controller::get_items().
Follow-up to [38832]. Props justlevine, johnbillion. See #64238. git-svn-id: https://develop.svn.wordpress.org/trunk@61282 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c9c6518 commit 43f9563

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ public function get_items( $request ) {
357357
}
358358

359359
$response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $comments );
360-
$response->header( 'X-WP-Total', $total_comments );
361-
$response->header( 'X-WP-TotalPages', $max_pages );
360+
$response->header( 'X-WP-Total', (string) $total_comments );
361+
$response->header( 'X-WP-TotalPages', (string) $max_pages );
362362

363363
$base = add_query_arg( urlencode_deep( $request->get_query_params() ), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
364364

tests/phpunit/tests/rest-api/rest-comments-controller.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,8 @@ public function test_get_comments_pagination_headers( $method ) {
868868
$request = new WP_REST_Request( $method, '/wp/v2/comments' );
869869
$response = rest_get_server()->dispatch( $request );
870870
$headers = $response->get_headers();
871-
$this->assertSame( $total_comments, $headers['X-WP-Total'] );
872-
$this->assertSame( $total_pages, $headers['X-WP-TotalPages'] );
871+
$this->assertSame( (string) $total_comments, $headers['X-WP-Total'] );
872+
$this->assertSame( (string) $total_pages, $headers['X-WP-TotalPages'] );
873873
$next_link = add_query_arg(
874874
array(
875875
'page' => 2,
@@ -891,8 +891,8 @@ public function test_get_comments_pagination_headers( $method ) {
891891
$request->set_param( 'page', 3 );
892892
$response = rest_get_server()->dispatch( $request );
893893
$headers = $response->get_headers();
894-
$this->assertSame( $total_comments, $headers['X-WP-Total'] );
895-
$this->assertSame( $total_pages, $headers['X-WP-TotalPages'] );
894+
$this->assertSame( (string) $total_comments, $headers['X-WP-Total'] );
895+
$this->assertSame( (string) $total_pages, $headers['X-WP-TotalPages'] );
896896
$prev_link = add_query_arg(
897897
array(
898898
'page' => 2,
@@ -913,8 +913,8 @@ public function test_get_comments_pagination_headers( $method ) {
913913
$request->set_param( 'page', $total_pages );
914914
$response = rest_get_server()->dispatch( $request );
915915
$headers = $response->get_headers();
916-
$this->assertSame( $total_comments, $headers['X-WP-Total'] );
917-
$this->assertSame( $total_pages, $headers['X-WP-TotalPages'] );
916+
$this->assertSame( (string) $total_comments, $headers['X-WP-Total'] );
917+
$this->assertSame( (string) $total_pages, $headers['X-WP-TotalPages'] );
918918
$prev_link = add_query_arg(
919919
array(
920920
'page' => $total_pages - 1,
@@ -929,8 +929,8 @@ public function test_get_comments_pagination_headers( $method ) {
929929
$request->set_param( 'page', 100 );
930930
$response = rest_get_server()->dispatch( $request );
931931
$headers = $response->get_headers();
932-
$this->assertSame( $total_comments, $headers['X-WP-Total'] );
933-
$this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
932+
$this->assertSame( (string) $total_comments, $headers['X-WP-Total'] );
933+
$this->assertEquals( (string) $total_pages, $headers['X-WP-TotalPages'] );
934934
$prev_link = add_query_arg(
935935
array(
936936
'page' => $total_pages,

0 commit comments

Comments
 (0)