Make WordPress Core

Changeset 49224


Ignore:
Timestamp:
10/20/2020 07:52:06 AM (4 years ago)
Author:
youknowriad
Message:

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.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r49120 r49224  
    208208        'styles'          => 'styles',
    209209        'example'         => 'example',
     210        'apiVersion'      => 'api_version',
    210211    );
    211212
  • trunk/src/wp-includes/class-wp-block-type.php

    r49120 r49224  
    1616 */
    1717class WP_Block_Type {
     18
     19    /**
     20     * Block API version.
     21     *
     22     * @since 5.6.0
     23     * @var int
     24     */
     25    public $api_version = 1;
    1826
    1927    /**
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php

    r48982 r49224  
    257257        $schema       = $this->get_item_schema();
    258258        $extra_fields = array(
     259            'api_version',
    259260            'name',
    260261            'title',
     
    366367            'type'       => 'object',
    367368            'properties' => array(
     369                'api_version'            => array(
     370                    'description' => __( 'Version of block API.' ),
     371                    'type'        => 'integer',
     372                    'default'     => 1,
     373                    'context'     => array( 'embed', 'view', 'edit' ),
     374                    'readonly'    => true,
     375                ),
    368376                'title'            => array(
    369377                    'description' => __( 'Title of block type.' ),
  • trunk/tests/phpunit/tests/blocks/fixtures/block.json

    r48845 r49224  
    11{
     2    "apiVersion": 2,
    23    "name": "my-plugin/notice",
    34    "title": "Notice",
  • trunk/tests/phpunit/tests/blocks/register.php

    r48939 r49224  
    286286
    287287        $this->assertInstanceOf( 'WP_Block_Type', $result );
     288        $this->assertSame( 2, $result->api_version );
    288289        $this->assertSame( 'my-plugin/notice', $result->name );
    289290        $this->assertSame( 'Notice', $result->title );
  • trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php

    r48939 r49224  
    313313        $data       = $response->get_data();
    314314        $properties = $data['schema']['properties'];
    315         $this->assertCount( 19, $properties );
     315        $this->assertCount( 20, $properties );
     316        $this->assertArrayHasKey( 'api_version', $properties );
    316317        $this->assertArrayHasKey( 'title', $properties );
    317318        $this->assertArrayHasKey( 'icon', $properties );
     
    432433
    433434        $extra_fields = array(
     435            'api_version',
    434436            'name',
    435437            'category',
Note: See TracChangeset for help on using the changeset viewer.