Editor: Support filtering arguments in block type registration
Adds possibility to filter the settings of a block type during its registration. Props aduth, azaozz. Fixes #49615. git-svn-id: https://develop.svn.wordpress.org/trunk@48263 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f7d617cfb8
commit
a425f15dd7
@ -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;
|
||||
}
|
||||
|
@ -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'] );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user