Block Editor: Expose api_version in the block type and the REST endpoint.

The new block editor included in 5.6 introduces an api_version property
that indicates which block API version the block is using. 
This commits makes this property available on the block type and the endpoint.

Props TimothyBlynJacobs, gziolo.
Fixes #51529.


Built from https://develop.svn.wordpress.org/trunk@49224


git-svn-id: http://core.svn.wordpress.org/trunk@48986 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
youknowriad 2020-10-20 07:54:10 +00:00
parent edb64a3d8e
commit 8fbbd54c40
4 changed files with 18 additions and 1 deletions

View File

@ -207,6 +207,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
'supports' => 'supports', 'supports' => 'supports',
'styles' => 'styles', 'styles' => 'styles',
'example' => 'example', 'example' => 'example',
'apiVersion' => 'api_version',
); );
foreach ( $property_mappings as $key => $mapped_key ) { foreach ( $property_mappings as $key => $mapped_key ) {

View File

@ -16,6 +16,14 @@
*/ */
class WP_Block_Type { class WP_Block_Type {
/**
* Block API version.
*
* @since 5.6.0
* @var int
*/
public $api_version = 1;
/** /**
* Block type key. * Block type key.
* *

View File

@ -256,6 +256,7 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
$schema = $this->get_item_schema(); $schema = $this->get_item_schema();
$extra_fields = array( $extra_fields = array(
'api_version',
'name', 'name',
'title', 'title',
'description', 'description',
@ -365,6 +366,13 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
'title' => 'block-type', 'title' => 'block-type',
'type' => 'object', 'type' => 'object',
'properties' => array( 'properties' => array(
'api_version' => array(
'description' => __( 'Version of block API.' ),
'type' => 'integer',
'default' => 1,
'context' => array( 'embed', 'view', 'edit' ),
'readonly' => true,
),
'title' => array( 'title' => array(
'description' => __( 'Title of block type.' ), 'description' => __( 'Title of block type.' ),
'type' => 'string', 'type' => 'string',

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.6-alpha-49223'; $wp_version = '5.6-alpha-49224';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.