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. Built from https://develop.svn.wordpress.org/trunk@52068 git-svn-id: http://core.svn.wordpress.org/trunk@51660 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5c47273f06
commit
84dae82fd3
|
@ -1403,6 +1403,8 @@ class WP_REST_Server {
|
||||||
'endpoints' => array(),
|
'endpoints' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$allow_batch = false;
|
||||||
|
|
||||||
if ( isset( $this->route_options[ $route ] ) ) {
|
if ( isset( $this->route_options[ $route ] ) ) {
|
||||||
$options = $this->route_options[ $route ];
|
$options = $this->route_options[ $route ];
|
||||||
|
|
||||||
|
@ -1410,6 +1412,8 @@ class WP_REST_Server {
|
||||||
$data['namespace'] = $options['namespace'];
|
$data['namespace'] = $options['namespace'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$allow_batch = isset( $options['allow_batch'] ) ? $options['allow_batch'] : false;
|
||||||
|
|
||||||
if ( isset( $options['schema'] ) && 'help' === $context ) {
|
if ( isset( $options['schema'] ) && 'help' === $context ) {
|
||||||
$data['schema'] = call_user_func( $options['schema'] );
|
$data['schema'] = call_user_func( $options['schema'] );
|
||||||
}
|
}
|
||||||
|
@ -1430,6 +1434,12 @@ class WP_REST_Server {
|
||||||
'methods' => array_keys( $callback['methods'] ),
|
'methods' => array_keys( $callback['methods'] ),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$callback_batch = isset( $callback['allow_batch'] ) ? $callback['allow_batch'] : $allow_batch;
|
||||||
|
|
||||||
|
if ( $callback_batch ) {
|
||||||
|
$endpoint_data['allow_batch'] = $callback_batch;
|
||||||
|
}
|
||||||
|
|
||||||
if ( isset( $callback['args'] ) ) {
|
if ( isset( $callback['args'] ) ) {
|
||||||
$endpoint_data['args'] = array();
|
$endpoint_data['args'] = array();
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,14 @@
|
||||||
*/
|
*/
|
||||||
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the controller supports batching.
|
||||||
|
*
|
||||||
|
* @since 5.9.0
|
||||||
|
* @var false
|
||||||
|
*/
|
||||||
|
protected $allow_batch = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the routes for attachments.
|
* Registers the routes for attachments.
|
||||||
*
|
*
|
||||||
|
|
|
@ -39,6 +39,14 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||||
*/
|
*/
|
||||||
protected $password_check_passed = array();
|
protected $password_check_passed = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the controller supports batching.
|
||||||
|
*
|
||||||
|
* @since 5.9.0
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $allow_batch = array( 'v1' => true );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
@ -80,7 +88,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
|
'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->namespace,
|
||||||
'/' . $this->rest_base . '/(?P<id>[\d]+)',
|
'/' . $this->rest_base . '/(?P<id>[\d]+)',
|
||||||
array(
|
array(
|
||||||
'args' => array(
|
'args' => array(
|
||||||
'id' => array(
|
'id' => array(
|
||||||
'description' => __( 'Unique identifier for the post.' ),
|
'description' => __( 'Unique identifier for the post.' ),
|
||||||
'type' => 'integer',
|
'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' ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,14 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
||||||
*/
|
*/
|
||||||
protected $total_terms;
|
protected $total_terms;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the controller supports batching.
|
||||||
|
*
|
||||||
|
* @since 5.9.0
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $allow_batch = array( 'v1' => true );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
@ -89,7 +97,8 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
||||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
|
'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' ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -97,7 +106,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
||||||
$this->namespace,
|
$this->namespace,
|
||||||
'/' . $this->rest_base . '/(?P<id>[\d]+)',
|
'/' . $this->rest_base . '/(?P<id>[\d]+)',
|
||||||
array(
|
array(
|
||||||
'args' => array(
|
'args' => array(
|
||||||
'id' => array(
|
'id' => array(
|
||||||
'description' => __( 'Unique identifier for the term.' ),
|
'description' => __( 'Unique identifier for the term.' ),
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
|
@ -129,7 +138,8 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'schema' => array( $this, 'get_public_item_schema' ),
|
'allow_batch' => $this->allow_batch,
|
||||||
|
'schema' => array( $this, 'get_public_item_schema' ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,14 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
|
||||||
*/
|
*/
|
||||||
protected $widgets_retrieved = false;
|
protected $widgets_retrieved = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the controller supports batching.
|
||||||
|
*
|
||||||
|
* @since 5.9.0
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $allow_batch = array( 'v1' => true );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Widgets controller constructor.
|
* Widgets controller constructor.
|
||||||
*
|
*
|
||||||
|
@ -56,7 +64,7 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
|
||||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||||
'args' => $this->get_endpoint_args_for_item_schema(),
|
'args' => $this->get_endpoint_args_for_item_schema(),
|
||||||
),
|
),
|
||||||
'allow_batch' => array( 'v1' => true ),
|
'allow_batch' => $this->allow_batch,
|
||||||
'schema' => array( $this, 'get_public_item_schema' ),
|
'schema' => array( $this, 'get_public_item_schema' ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -90,7 +98,7 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'allow_batch' => array( 'v1' => true ),
|
'allow_batch' => $this->allow_batch,
|
||||||
'schema' => array( $this, 'get_public_item_schema' ),
|
'schema' => array( $this, 'get_public_item_schema' ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.9-alpha-52067';
|
$wp_version = '5.9-alpha-52068';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue