Make WordPress Core

Changeset 57623

Timestamp:
02/13/2024 01:46:45 PM (6 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.

Location:
trunk
Files:
3 edited

Legend:

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

    r57312 r57623  
    744744                    }
    745745
     746
     747
     748
     749
     750
     751
     752
    746753                    // Embedded resources get passed context=embed.
    747754                    if ( empty( $request['context'] ) ) {
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r57108 r57623  
    1919    protected static $supported_formats;
    2020    protected static $post_ids    = array();
     21
    2122    protected static $total_posts = 30;
    2223    protected static $per_page    = 50;
     
    2930    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    3031        self::$post_id = $factory->post->create();
     32
     33
    3134
    3235        self::$superadmin_id  = $factory->user->create(
     
    222225        sort( $keys );
    223226        $this->assertSame( array( 'context', 'id', 'password' ), $keys );
     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
     237
     238
     239
     240
     241
    224242    }
    225243
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r57147 r57623  
    930930        $this->assertArrayNotHasKey( '_embedded', $result );
    931931        $this->assertSame( 'data', $result['untouched'] );
     932
     933
     934
     935
     936
     937
     938
     939
     940
     941
     942
     943
     944
     945
     946
     947
     948
     949
     950
     951
     952
     953
     954
     955
     956
     957
     958
     959
     960
     961
     962
     963
     964
    932965    }
    933966
Note: See TracChangeset for help on using the changeset viewer.