Make WordPress Core

Changeset 58283


Ignore:
Timestamp:
06/02/2024 08:01:44 PM (8 months ago)
Author:
TimothyBlynJacobs
Message:

REST API: Add batch support to the Users API.

Developers can now include /wp/v2/users routes when making a batch API request.

Props alexminza, timothyblynjacobs, mukesh27.
Fixes #60895.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r57648 r58283  
    2424     */
    2525    protected $meta;
     26
     27    /**
     28     * Whether the controller supports batching.
     29     *
     30     * @since 6.6.0
     31     * @var array
     32     */
     33    protected $allow_batch = array( 'v1' => true );
    2634
    2735    /**
     
    6270                    'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
    6371                ),
    64                 'schema' => array( $this, 'get_public_item_schema' ),
     72                'allow_batch' => $this->allow_batch,
     73                'schema'      => array( $this, 'get_public_item_schema' ),
    6574            )
    6675        );
     
    108117                    ),
    109118                ),
    110                 'schema' => array( $this, 'get_public_item_schema' ),
     119                'allow_batch' => $this->allow_batch,
     120                'schema'      => array( $this, 'get_public_item_schema' ),
    111121            )
    112122        );
  • trunk/tests/phpunit/tests/rest-api/rest-users-controller.php

    r57239 r58283  
    181181        $response = rest_get_server()->dispatch( $request );
    182182        $data     = $response->get_data();
     183        $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] );
    183184        $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
    184185        $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
     
    187188        $response = rest_get_server()->dispatch( $request );
    188189        $data     = $response->get_data();
     190        $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] );
    189191        $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
    190192        $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r58232 r58283  
    93729372                        "GET"
    93739373                    ],
     9374                    "allow_batch": {
     9375                        "v1": true
     9376                    },
    93749377                    "args": {
    93759378                        "context": {
     
    95159518                        "POST"
    95169519                    ],
     9520                    "allow_batch": {
     9521                        "v1": true
     9522                    },
    95179523                    "args": {
    95189524                        "username": {
     
    96179623                        "GET"
    96189624                    ],
     9625                    "allow_batch": {
     9626                        "v1": true
     9627                    },
    96199628                    "args": {
    96209629                        "id": {
     
    96429651                        "PATCH"
    96439652                    ],
     9653                    "allow_batch": {
     9654                        "v1": true
     9655                    },
    96449656                    "args": {
    96459657                        "id": {
     
    97349746                        "DELETE"
    97359747                    ],
     9748                    "allow_batch": {
     9749                        "v1": true
     9750                    },
    97369751                    "args": {
    97379752                        "id": {
Note: See TracChangeset for help on using the changeset viewer.