11 | | * Registers a block type. |
12 | | * |
13 | | * @since 5.0.0 |
14 | | * |
15 | | * @param string|WP_Block_Type $name Block type name including namespace, or alternatively |
16 | | * a complete WP_Block_Type instance. In case a WP_Block_Type |
17 | | * is provided, the $args parameter will be ignored. |
18 | | * @param array $args Optional. Array of block type arguments. Accepts any public property |
19 | | * of `WP_Block_Type`. See WP_Block_Type::__construct() for information |
20 | | * 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.0 |
31 | | * |
32 | | * @param string|WP_Block_Type $name Block type name including namespace, or alternatively |
33 | | * 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 | | |
40 | | /** |
| 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 ); |
| 363 | } |
| 364 | |
| 365 | /** |