Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_item_schema function to WP_REST_Widget_Areas_Controller #15981

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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