WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/26/2017 01:52:06 PM (17 months ago)
Author:
joehoyle
Message:

REST API: Return an error if the page number is out of bounds.

Return an error from the REST API if a page number larger than the total pages count is requested.

Props morganestes.
Fixes #39061.

File:
1 edited

Legend:

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

    r39954 r39967  
    328328
    329329        $max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] );
     330
     331        if ( $page > $max_pages && $total_posts > 0 ) {
     332            return new WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) );
     333        }
     334
    330335        $response  = rest_ensure_response( $posts );
    331336
Note: See TracChangeset for help on using the changeset viewer.