diff --git a/src/wp-includes/class-wp-block-type.php b/src/wp-includes/class-wp-block-type.php index 4758e172ba..3052affdc1 100644 --- a/src/wp-includes/class-wp-block-type.php +++ b/src/wp-includes/class-wp-block-type.php @@ -262,6 +262,17 @@ class WP_Block_Type { $args['name'] = $this->name; + /** + * Filters the arguments for registering a block type. + * + * @since 5.5.0 + * + * @param array $args Array of arguments for registering a + * block type. + * @param string $block_type Block type name including namespace. + */ + $args = apply_filters( 'register_block_type_args', $args, $this->name ); + foreach ( $args as $property_name => $property_value ) { $this->$property_name = $property_value; } diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 514fa80750..d0387f0148 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -380,4 +380,22 @@ class WP_Test_Block_Register extends WP_UnitTestCase { $content = file_get_contents( DIR_TESTDATA . '/blocks/do-blocks-expected.html' ); $this->assertFalse( has_blocks( $content ) ); } + + /** + * @ticket 49615 + */ + public function test_filter_block_registration() { + $filter_registration = function( $args, $name ) { + $args['attributes'] = array( $name => array( 'type' => 'boolean' ) ); + return $args; + }; + + add_filter( 'register_block_type_args', $filter_registration, 10, 2 ); + register_block_type( 'core/test-filtered', array() ); + remove_filter( 'register_block_type_args', $filter_registration ); + + $registry = WP_Block_Type_Registry::get_instance(); + $block_type = $registry->get_registered( 'core/test-filtered' ); + $this->assertEquals( 'boolean', $block_type->attributes['core/test-filtered']['type'] ); + } }