diff --git a/wp-includes/rest-api/class-wp-rest-server.php b/wp-includes/rest-api/class-wp-rest-server.php index 3585aa7656..b7451ffc18 100644 --- a/wp-includes/rest-api/class-wp-rest-server.php +++ b/wp-includes/rest-api/class-wp-rest-server.php @@ -1403,6 +1403,8 @@ class WP_REST_Server { 'endpoints' => array(), ); + $allow_batch = false; + if ( isset( $this->route_options[ $route ] ) ) { $options = $this->route_options[ $route ]; @@ -1410,6 +1412,8 @@ class WP_REST_Server { $data['namespace'] = $options['namespace']; } + $allow_batch = isset( $options['allow_batch'] ) ? $options['allow_batch'] : false; + if ( isset( $options['schema'] ) && 'help' === $context ) { $data['schema'] = call_user_func( $options['schema'] ); } @@ -1430,6 +1434,12 @@ class WP_REST_Server { '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'] ) ) { $endpoint_data['args'] = array(); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php index ad6a89b234..423347a721 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php @@ -16,6 +16,14 @@ */ 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. * diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index ffb4466892..fd7fa22b4c 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -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[\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' ), ) ); } diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index 3a92b774f0..8856609375 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php @@ -48,6 +48,14 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { */ protected $total_terms; + /** + * Whether the controller supports batching. + * + * @since 5.9.0 + * @var array + */ + protected $allow_batch = array( 'v1' => true ); + /** * Constructor. * @@ -89,7 +97,8 @@ class WP_REST_Terms_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' ), ) ); @@ -97,7 +106,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( - 'args' => array( + 'args' => array( 'id' => array( 'description' => __( 'Unique identifier for the term.' ), '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' ), ) ); } diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php index 6385be8ef8..8cf7039d1f 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php @@ -24,6 +24,14 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller { */ protected $widgets_retrieved = false; + /** + * Whether the controller supports batching. + * + * @since 5.9.0 + * @var array + */ + protected $allow_batch = array( 'v1' => true ); + /** * Widgets controller constructor. * @@ -56,7 +64,7 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller { 'permission_callback' => array( $this, 'create_item_permissions_check' ), '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' ), ) ); @@ -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' ), ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 16e6e5fbef..2cf20e019e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @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.