Skip to content

Commit

Permalink
Add get_item_schema function to WP_REST_Widget_Areas_Controller (#15981)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored Aug 26, 2019
1 parent 8eb5007 commit 2e45a8b
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions lib/class-wp-rest-widget-areas-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 2e45a8b

Please sign in to comment.