Changeset 50927
- Timestamp:
- 05/19/2021 01:50:09 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r50919 r50927 7 7 * @since 5.0.0 8 8 */ 9 10 /**11 * Registers a block type.12 *13 * @since 5.0.014 *15 * @param string|WP_Block_Type $name Block type name including namespace, or alternatively16 * a complete WP_Block_Type instance. In case a WP_Block_Type17 * is provided, the $args parameter will be ignored.18 * @param array $args Optional. Array of block type arguments. Accepts any public property19 * of `WP_Block_Type`. See WP_Block_Type::__construct() for information20 * on accepted arguments. Default empty array.21 * @return WP_Block_Type|false The registered block type on success, or false on failure.22 */23 function register_block_type( $name, $args = array() ) {24 return WP_Block_Type_Registry::get_instance()->register( $name, $args );25 }26 27 /**28 * Unregisters a block type.29 *30 * @since 5.0.031 *32 * @param string|WP_Block_Type $name Block type name including namespace, or alternatively33 * a complete WP_Block_Type instance.34 * @return WP_Block_Type|false The unregistered block type on success, or false on failure.35 */36 function unregister_block_type( $name ) {37 return WP_Block_Type_Registry::get_instance()->unregister( $name );38 }39 9 40 10 /** … … 205 175 206 176 /** 207 * Registers a block type from metadata stored in the `block.json` file.177 * Registers a block type from the metadata stored in the `block.json` file. 208 178 * 209 179 * @since 5.5.0 … … 349 319 ); 350 320 351 return register_block_type(321 return WP_Block_Type_Registry::get_instance()->register( 352 322 $metadata['name'], 353 323 $settings 354 324 ); 325 } 326 327 /** 328 * Registers a block type. The recommended way is to register a block type using 329 * the metadata stored in the `block.json` file. 330 * 331 * @since 5.0.0 332 * 333 * @param string|WP_Block_Type $block_type Block type name including namespace, or alternatively 334 * a path to the JSON file with metadata definition for the block, 335 * or a path to the folder where the `block.json` file is located, 336 * or a complete WP_Block_Type instance. 337 * In case a WP_Block_Type is provided, the $args parameter will be ignored. 338 * @param array $args Optional. Array of block type arguments. Accepts any public property 339 * of `WP_Block_Type`. See WP_Block_Type::__construct() for information 340 * on accepted arguments. Default empty array. 341 * 342 * @return WP_Block_Type|false The registered block type on success, or false on failure. 343 */ 344 function register_block_type( $block_type, $args = array() ) { 345 if ( is_string( $block_type ) && file_exists( $block_type ) ) { 346 return register_block_type_from_metadata( $block_type, $args ); 347 } 348 349 return WP_Block_Type_Registry::get_instance()->register( $block_type, $args ); 350 } 351 352 /** 353 * Unregisters a block type. 354 * 355 * @since 5.0.0 356 * 357 * @param string|WP_Block_Type $name Block type name including namespace, or alternatively 358 * a complete WP_Block_Type instance. 359 * @return WP_Block_Type|false The unregistered block type on success, or false on failure. 360 */ 361 function unregister_block_type( $name ) { 362 return WP_Block_Type_Registry::get_instance()->unregister( $name ); 355 363 } 356 364 -
trunk/src/wp-includes/blocks/index.php
r50824 r50927 60 60 61 61 foreach ( $block_folders as $block_folder ) { 62 register_block_type _from_metadata(62 register_block_type( 63 63 ABSPATH . WPINC . '/blocks/' . $block_folder 64 64 ); -
trunk/tests/phpunit/tests/blocks/register.php
r50838 r50927 384 384 385 385 /** 386 * @ticket 53233 387 */ 388 function test_block_register_block_type_proxy_for_metadata() { 389 $result = register_block_type( 390 DIR_TESTDATA . '/blocks/notice' 391 ); 392 393 $this->assertInstanceOf( 'WP_Block_Type', $result ); 394 $this->assertSame( 'tests/notice', $result->name ); 395 } 396 397 /** 386 398 * @ticket 52301 387 399 */
Note: See TracChangeset
for help on using the changeset viewer.