Make WordPress Core

Changeset 47875


Ignore:
Timestamp:
06/01/2020 12:25:34 PM (6 years ago)
Author:
gziolo
Message:

Add fields to WP_Block_Type

As part of #47620 and the RFC for block registeration. Server registered blocks are missing some fields. These changeset includes them.

Props spacedmonkey, aduth.

Fixes #48529.

Location:
trunk
Files:
4 edited

Legend:

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

    r47808 r47875  
    22352235        $block_registry = WP_Block_Type_Registry::get_instance();
    22362236        $blocks         = array();
    2237         $keys_to_pick   = array( 'title', 'description', 'icon', 'category', 'keywords', 'parent', 'supports', 'attributes', 'styles' );
     2237        $keys_to_pick   = array( 'title', 'description', 'icon', 'category', 'keywords', 'parent', 'supports', 'attributes', 'styles', 'textdomain', 'example' );
    22382238
    22392239        foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
  • trunk/src/wp-includes/class-wp-block-type.php

    r46586 r47875  
    1616 */
    1717class WP_Block_Type {
     18
    1819        /**
    1920         * Block type key.
     
    2526
    2627        /**
     28         * @since 5.5.0
     29         * @var string
     30         */
     31        public $title = '';
     32
     33        /**
     34         * @since 5.5.0
     35         * @var string
     36         */
     37        public $category = '';
     38
     39        /**
     40         * @since 5.5.0
     41         * @var array|null
     42         */
     43        public $parent = null;
     44
     45        /**
     46         * @since 5.5.0
     47         * @var string
     48         */
     49        public $icon = '';
     50
     51        /**
     52         * @since 5.5.0
     53         * @var string
     54         */
     55        public $description = '';
     56
     57        /**
     58         * @since 5.5.0
     59         * @var array
     60         */
     61        public $keywords = array();
     62
     63        /**
     64         * @since 5.5.0
     65         * @var string|null
     66         */
     67        public $textdomain = null;
     68
     69        /**
     70         * @since 5.5.0
     71         * @var array
     72         */
     73        public $styles = array();
     74
     75        /**
     76         * @since 5.5.0
     77         * @var array
     78         */
     79        public $supports = array();
     80
     81        /**
     82         * @since 5.5.0
     83         * @var array|null
     84         */
     85        public $example = null;
     86
     87        /**
    2788         * Block type render callback.
    2889         *
     
    3091         * @var callable
    3192         */
    32         public $render_callback;
     93        public $render_callback = null;
    3394
    3495        /**
     
    3697         *
    3798         * @since 5.0.0
    38          * @var array
    39          */
    40         public $attributes;
     99         * @var array|null
     100         */
     101        public $attributes = null;
    41102
    42103        /**
     
    46107         * @var string
    47108         */
    48         public $editor_script;
     109        public $editor_script = '';
    49110
    50111        /**
     
    54115         * @var string
    55116         */
    56         public $script;
     117        public $script = '';
    57118
    58119        /**
     
    62123         * @var string
    63124         */
    64         public $editor_style;
     125        public $editor_style = '';
    65126
    66127        /**
     
    70131         * @var string
    71132         */
    72         public $style;
     133        public $style = '';
    73134
    74135        /**
     
    76137         *
    77138         * Will populate object properties from the provided arguments.
    78          *
    79          * @since 5.0.0
    80          *
    81          * @see register_block_type()
    82139         *
    83140         * @param string       $block_type Block type name including namespace.
    84141         * @param array|string $args       Optional. Array or string of arguments for registering a block type.
    85142         *                                 Default empty array.
     143         *
     144         * @since 5.0.0
     145         *
     146         * @see   register_block_type()
     147         *
    86148         */
    87149        public function __construct( $block_type, $args = array() ) {
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r47122 r47875  
    826826                $name     = 'core/test';
    827827                $settings = array(
     828                        'category'        => 'common',
    828829                        'icon'            => 'text',
    829830                        'render_callback' => 'foo',
     
    837838
    838839                $this->assertArrayHasKey( $name, $blocks );
    839                 $this->assertSame( array( 'icon' => 'text' ), $blocks[ $name ] );
     840                $this->assertEquals( array(
     841                        'title'       => '',
     842                        'description' => '',
     843                        'category'    => 'common',
     844                        'icon'        => 'text',
     845                        'keywords'    => array(),
     846                        'supports'    => array(),
     847                        'styles'      => array(),
     848                ), $blocks[ $name ] );
    840849        }
    841850
  • trunk/tests/phpunit/tests/blocks/block-type.php

    r46896 r47875  
    351351
    352352        /**
     353         * @ticket 48529
     354         */
     355        public function test_register_block() {
     356                $block_type = new WP_Block_Type( 'core/fake', array(
     357                        'title'       => 'Test title',
     358                        'category'    => 'Test category',
     359                        'parent'      => array( 'core/third-party' ),
     360                        'icon'        => 'icon.png',
     361                        'description' => 'test description',
     362                        'keywords'    => array( 'test keyword' ),
     363                        'textdomain'  => 'test_domain',
     364                        'supports'    => array( 'alignment' => true ),
     365                ) );
     366
     367                $this->assertSame( 'Test title', $block_type->title );
     368                $this->assertSame( 'Test category', $block_type->category );
     369                $this->assertEqualSets( array( 'core/third-party' ), $block_type->parent );
     370                $this->assertSame( 'icon.png', $block_type->icon );
     371                $this->assertSame( 'test description', $block_type->description );
     372                $this->assertEqualSets( array( 'test keyword' ), $block_type->keywords );
     373                $this->assertSame( 'test_domain', $block_type->textdomain );
     374                $this->assertEqualSets( array( 'alignment' => true ), $block_type->supports );
     375        }
     376
     377        /**
    353378         * Testing the block version.
    354379         *
Note: See TracChangeset for help on using the changeset viewer.