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.

git-svn-id: https://develop.svn.wordpress.org/trunk@57623 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2024-02-13 13:46:45 +00:00
parent 1d4eff1303
commit 2480e16d99
3 changed files with 58 additions and 0 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';