mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-03 04:04:35 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@39967 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user