Make WordPress Core

Ticket #49615: 49615-filter-register-block-type.diff

File 49615-filter-register-block-type.diff, 1.8 KB (added by aduth, 5 years ago)
  • src/wp-includes/class-wp-block-type.php

    diff --git a/src/wp-includes/class-wp-block-type.php b/src/wp-includes/class-wp-block-type.php
    index 6ffda95b4e..219feb0388 100644
    a b class WP_Block_Type { 
    185185
    186186                $args['name'] = $this->name;
    187187
     188                /**
     189                 * Filters the arguments for registering a block type.
     190                 *
     191                 * @since 5.5.0
     192                 *
     193                 * @param array  $args       Array of arguments for for registering a
     194                 *                           block type.
     195                 * @param string $block_type Block type name including namespace.
     196                 */
     197                $args = apply_filters( 'register_block_type_args', $args, $this->name );
     198
    188199                foreach ( $args as $property_name => $property_value ) {
    189200                        $this->$property_name = $property_value;
    190201                }
  • tests/phpunit/tests/blocks/register.php

    diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php
    index 8271c9babd..93128136fe 100644
    a b class WP_Test_Block_Register extends WP_UnitTestCase { 
    138138                $content = file_get_contents( DIR_TESTDATA . '/blocks/do-blocks-expected.html' );
    139139                $this->assertFalse( has_blocks( $content ) );
    140140        }
     141
     142        /**
     143         * @ticket 49615
     144         */
     145        public function test_filter_block_registration() {
     146                $filter_registration = function( $args, $name ) {
     147                        $args['attributes'] = array( $name => array( 'type' => 'boolean' ) );
     148                        return $args;
     149                };
     150
     151                add_filter( 'register_block_type_args', $filter_registration, 10, 2 );
     152                register_block_type( 'core/test-filtered', array() );
     153                remove_filter( 'register_block_type_args', $filter_registration );
     154
     155                $registry   = WP_Block_Type_Registry::get_instance();
     156                $block_type = $registry->get_registered( 'core/test-filtered' );
     157                $this->assertEquals( 'boolean', $block_type->attributes['core/test-filtered']['type'] );
     158        }
    141159}