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. Built from https://develop.svn.wordpress.org/trunk@39967 git-svn-id: http://core.svn.wordpress.org/trunk@39904 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4482f92070
commit
99cf07d882
|
@ -327,6 +327,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
$max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] );
|
||||
|
||||
if ( $page > $max_pages && $total_posts > 0 ) {
|
||||
return new WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
$response = rest_ensure_response( $posts );
|
||||
|
||||
$response->header( 'X-WP-Total', (int) $total_posts );
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.8-alpha-39956';
|
||||
$wp_version = '4.8-alpha-39967';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue