Make WordPress Core

Ticket #53233: 53233.patch

File 53233.patch, 4.9 KB (added by gziolo, 4 years ago)
  • src/wp-includes/blocks/index.php

     
    5959        );
    6060
    6161        foreach ( $block_folders as $block_folder ) {
    62                 register_block_type_from_metadata(
     62                register_block_type(
    6363                        ABSPATH . WPINC . '/blocks/' . $block_folder
    6464                );
    6565        }
  • src/wp-includes/blocks.php

     
    88 */
    99
    1010/**
    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 /**
    4111 * Removes the block asset's path prefix if provided.
    4212 *
    4313 * @since 5.5.0
     
    204174}
    205175
    206176/**
    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.
    208178 *
    209179 * @since 5.5.0
    210180 *
     
    348318                $metadata
    349319        );
    350320
    351         return register_block_type(
     321        return WP_Block_Type_Registry::get_instance()->register(
    352322                $metadata['name'],
    353323                $settings
    354324        );
     
    355325}
    356326
    357327/**
     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 */
     344function 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 */
     361function unregister_block_type( $name ) {
     362        return WP_Block_Type_Registry::get_instance()->unregister( $name );
     363}
     364
     365/**
    358366 * Determine whether a post or content string has blocks.
    359367 *
    360368 * This test optimizes for performance rather than strict accuracy, detecting
  • tests/phpunit/tests/blocks/register.php

     
    383383        }
    384384
    385385        /**
     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        /**
    386398         * @ticket 52301
    387399         */
    388400        function test_block_registers_with_metadata_i18n_support() {