Make WordPress Core

Changeset 61282


Ignore:
Timestamp:
11/23/2025 05:48:01 AM (5 weeks ago)
Author:
westonruter
Message:

Docs: Cast header values to strings in WP_REST_Comments_Controller::get_items().

Follow-up to [38832].

Props justlevine, johnbillion.
See #64238.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    r61276 r61282  
    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 ) ) );
  • trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php

    r61276 r61282  
    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(
     
    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(
     
    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(
     
    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(
Note: See TracChangeset for help on using the changeset viewer.