From 9b3acbae25d526994fa571dd7f95f71f1cfb93dc Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Tue, 13 Feb 2024 13:48:08 +0000 Subject: [PATCH] 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 --- wp-includes/rest-api/class-wp-rest-server.php | 7 +++++++ wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/wp-includes/rest-api/class-wp-rest-server.php b/wp-includes/rest-api/class-wp-rest-server.php index 861f5115e6..380eea2ca3 100644 --- a/wp-includes/rest-api/class-wp-rest-server.php +++ b/wp-includes/rest-api/class-wp-rest-server.php @@ -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'; diff --git a/wp-includes/version.php b/wp-includes/version.php index 133601e3e3..6581e9cd0a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.