Make WordPress Core


Ignore:
Timestamp:
02/13/2024 01:46:45 PM (8 months ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/class-wp-rest-server.php

    r57312 r57623  
    744744                    }
    745745
     746                    if ( empty( $request['per_page'] ) ) {
     747                        $matched = $this->match_request_to_handler( $request );
     748                        if ( ! is_wp_error( $matched ) && isset( $matched[1]['args']['per_page']['maximum'] ) ) {
     749                            $request['per_page'] = (int) $matched[1]['args']['per_page']['maximum'];
     750                        }
     751                    }
     752
    746753                    // Embedded resources get passed context=embed.
    747754                    if ( empty( $request['context'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.