Changeset 49948
- Timestamp:
- 01/08/2021 04:43:29 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r49927 r49948 201 201 } 202 202 $metadata['file'] = $metadata_file; 203 204 /** 205 * Filters the metadata provided for registering a block type. 206 * 207 * @since 5.7.0 208 * 209 * @param array $metadata Metadata for registering a block type. 210 */ 211 $metadata = apply_filters( 'block_type_metadata', $metadata ); 203 212 204 213 $settings = array(); … … 253 262 } 254 263 255 return register_block_type( 256 $metadata['name'], 264 /** 265 * Filters the settings determined from the block type metadata. 266 * 267 * @since 5.7.0 268 * 269 * @param array $settings Array of determined settings for registering a block type. 270 * @param array $metadata Metadata provided for registering a block type. 271 */ 272 $settings = apply_filters( 273 'block_type_metadata_settings', 257 274 array_merge( 258 275 $settings, 259 276 $args 260 ) 277 ), 278 $metadata 279 ); 280 281 return register_block_type( 282 $metadata['name'], 283 $settings 261 284 ); 262 285 } -
trunk/tests/phpunit/tests/blocks/register.php
r49850 r49948 63 63 $registry = WP_Block_Type_Registry::get_instance(); 64 64 65 foreach ( array( 'test-static', 'test-dynamic' ) as $block_name ) { 66 $block_name = 'core/' . $block_name; 67 65 foreach ( array( 'core/test-static', 'core/test-dynamic', 'my-plugin/notice' ) as $block_name ) { 68 66 if ( $registry->is_registered( $block_name ) ) { 69 67 $registry->unregister( $block_name ); … … 424 422 $this->assertSame( 'boolean', $block_type->attributes['core/test-filtered']['type'] ); 425 423 } 424 425 /** 426 * @ticket 52138 427 */ 428 public function test_filter_block_registration_metadata() { 429 $filter_metadata_registration = function( $metadata ) { 430 $metadata['apiVersion'] = 3; 431 return $metadata; 432 }; 433 434 add_filter( 'block_type_metadata', $filter_metadata_registration, 10, 2 ); 435 $result = register_block_type_from_metadata( 436 __DIR__ . '/fixtures' 437 ); 438 remove_filter( 'block_type_metadata', $filter_metadata_registration ); 439 440 $this->assertSame( 3, $result->api_version ); 441 } 442 443 /** 444 * @ticket 52138 445 */ 446 public function test_filter_block_registration_metadata_settings() { 447 $filter_metadata_registration = function( $settings, $metadata ) { 448 $settings['api_version'] = $metadata['apiVersion'] + 1; 449 return $settings; 450 }; 451 452 add_filter( 'block_type_metadata_settings', $filter_metadata_registration, 10, 2 ); 453 $result = register_block_type_from_metadata( 454 __DIR__ . '/fixtures' 455 ); 456 remove_filter( 'block_type_metadata_settings', $filter_metadata_registration ); 457 458 $this->assertSame( 3, $result->api_version ); 459 } 426 460 }
Note: See TracChangeset
for help on using the changeset viewer.