diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php index 66a2e7adad..a523764dc5 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php @@ -36,4 +36,57 @@ class WP_REST_Blocks_Controller extends WP_REST_Posts_Controller { return parent::check_read_permission( $post ); } + + /** + * Filters a response based on the context defined in the schema. + * + * @since 5.0.0 + * + * @param array $data Response data to fiter. + * @param string $context Context defined in the schema. + * @return array Filtered response. + */ + public function filter_response_by_context( $data, $context ) { + $data = parent::filter_response_by_context( $data, $context ); + + /* + * Remove `title.rendered` and `content.rendered` from the response. It + * doesn't make sense for a reusable block to have rendered content on its + * own, since rendering a block requires it to be inside a post or a page. + */ + unset( $data['title']['rendered'] ); + unset( $data['content']['rendered'] ); + + return $data; + } + + /** + * Retrieves the block's schema, conforming to JSON Schema. + * + * @since 5.0.0 + * + * @return array Item schema data. + */ + public function get_item_schema() { + $schema = parent::get_item_schema(); + + /* + * Allow all contexts to access `title.raw` and `content.raw`. Clients always + * need the raw markup of a reusable block to do anything useful, e.g. parse + * it or display it in an editor. + */ + $schema['properties']['title']['properties']['raw']['context'] = array( 'view', 'edit' ); + $schema['properties']['content']['properties']['raw']['context'] = array( 'view', 'edit' ); + + /* + * Remove `title.rendered` and `content.rendered` from the schema. It doesn’t + * make sense for a reusable block to have rendered content on its own, since + * rendering a block requires it to be inside a post or a page. + */ + unset( $schema['properties']['title']['properties']['rendered'] ); + unset( $schema['properties']['content']['properties']['rendered'] ); + + return $schema; + } + } diff --git a/wp-includes/version.php b/wp-includes/version.php index 553b78415d..8ee222666c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-alpha-44267'; +$wp_version = '5.1-alpha-44268'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.