REST API: Add batch support for posts and terms controllers.

This also exposes the value of `allow_batch` in `OPTIONS` requests to a route.

A future commit will add batch support to more resources.

Props spacedmonkey, chrisvanpatten.
See #53063.


git-svn-id: https://develop.svn.wordpress.org/trunk@52068 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs
2021-11-09 01:57:48 +00:00
parent 29615a6c70
commit ecf1d6a158
13 changed files with 188 additions and 9 deletions

View File

@@ -39,6 +39,14 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
*/
protected $password_check_passed = array();
/**
* Whether the controller supports batching.
*
* @since 5.9.0
* @var array
*/
protected $allow_batch = array( 'v1' => true );
/**
* Constructor.
*
@@ -80,7 +88,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
),
'schema' => array( $this, 'get_public_item_schema' ),
'allow_batch' => $this->allow_batch,
'schema' => array( $this, 'get_public_item_schema' ),
)
);
@@ -98,7 +107,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
$this->namespace,
'/' . $this->rest_base . '/(?P<id>[\d]+)',
array(
'args' => array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the post.' ),
'type' => 'integer',
@@ -128,7 +137,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
),
),
),
'schema' => array( $this, 'get_public_item_schema' ),
'allow_batch' => $this->allow_batch,
'schema' => array( $this, 'get_public_item_schema' ),
)
);
}