REST API: Set maximum 'per_page' for embedded REST API requests.

This enhancement refines the REST API server to automatically establish the maximum 'per_page' value for embedded objects, adhering to the endpoint's schema when not explicitly defined in the request. This adjustment elevates the limit from the default of 10 items to 100 items, significantly improving the likelihood of receiving the complete dataset of embedded objects.

Props manyourisms, lpawlik, spacedmonkey, kadamwhite, TimothyBlynJacobs. 
Fixes #43439.
Built from https://develop.svn.wordpress.org/trunk@57623


git-svn-id: http://core.svn.wordpress.org/trunk@57124 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
spacedmonkey 2024-02-13 13:48:08 +00:00
parent 0ab75261f4
commit 9b3acbae25
2 changed files with 8 additions and 1 deletions

View File

@ -743,6 +743,13 @@ class WP_REST_Server {
continue;
}
if ( empty( $request['per_page'] ) ) {
$matched = $this->match_request_to_handler( $request );
if ( ! is_wp_error( $matched ) && isset( $matched[1]['args']['per_page']['maximum'] ) ) {
$request['per_page'] = (int) $matched[1]['args']['per_page']['maximum'];
}
}
// Embedded resources get passed context=embed.
if ( empty( $request['context'] ) ) {
$request['context'] = 'embed';

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.5-alpha-57622';
$wp_version = '6.5-alpha-57623';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.