diff --git a/lib/class-wp-rest-widget-areas-controller.php b/lib/class-wp-rest-widget-areas-controller.php index e191a50305c13..b31ca37a83ddf 100644 --- a/lib/class-wp-rest-widget-areas-controller.php +++ b/lib/class-wp-rest-widget-areas-controller.php @@ -74,16 +74,66 @@ public function register_routes() { 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_item' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), - 'args' => array( - 'id' => $id_argument, - 'content' => $content_argument, - ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); } + /** + * Retrieves the comment's schema, conforming to JSON Schema. + * + * @since 6.1.0 + * + * @return array + */ + public function get_item_schema() { + $schema = array( + '$schema' => 'http://json-schema.org/draft-04/schema#', + 'title' => 'widget-area', + 'type' => 'object', + 'properties' => array( + 'id' => array( + 'description' => __( 'Unique identifier for the object.', 'gutenberg' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, + ), + 'content' => array( + 'description' => __( 'The content for the object.', 'gutenberg' ), + 'type' => 'object', + 'context' => array( 'view', 'edit', 'embed' ), + 'arg_options' => array( + 'sanitize_callback' => null, + 'validate_callback' => null, + ), + 'properties' => array( + 'raw' => array( + 'description' => __( 'Content for the object, as it exists in the database.', 'gutenberg' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + ), + 'rendered' => array( + 'description' => __( 'HTML content for the object, transformed for display.', 'gutenberg' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, + ), + 'block_version' => array( + 'description' => __( 'Version of the content block format used by the object.', 'gutenberg' ), + 'type' => 'integer', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, + ), + ), + ), + ), + ); + + return $schema; + } + /** * Checks whether a given request has permission to read widget areas. * @@ -166,6 +216,10 @@ public function update_item( $request ) { $sidebar_id = $request->get_param( 'id' ); $sidebar_content = $request->get_param( 'content' ); + if ( ! is_string( $sidebar_content ) && isset( $sidebar_content['raw'] ) ) { + $sidebar_content = $sidebar_content['raw']; + } + $id_referenced_in_sidebar = Experimental_WP_Widget_Blocks_Manager::get_post_id_referenced_in_sidebar( $sidebar_id ); $post_id = wp_insert_post(