#50263 closed enhancement (fixed)
Editor: Introduce new API method that register block from `block.json` metadata file
Reported by: | gziolo | Owned by: | gziolo |
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | 5.5 |
Component: | Editor | Keywords: | has-patch has-unit-tests has-dev-note |
Focuses: | Cc: |
Description (last modified by )
Now that we are close to be able to expose all block with the new REST API endpoint as proposed in https://github.com/WordPress/gutenberg/pull/21065 (#47620), the next step is to make it easier to register blocks on the server.
The initial implementation was proposed in https://github.com/WordPress/gutenberg/pull/20794.
It's still being worked on in https://github.com/WordPress/gutenberg/pull/22519 where Extend register_block_type_from_metadata
to handle assets.
There is also a related task #49615 that proposes register_block_type_args
filter and might help improve the general experience when registering a block.
This is how the interface looks like:
<?php /** * Registers a block type from metadata stored in the `block.json` file. * * @since 5.5.0 * * @param string $file_or_folder Path to the JSON file with metadata definition for * the block or path to the folder where the `block.json` file is located. * @param array $args { * Optional. Array of block type arguments. Any arguments may be defined, however the * ones described below are supported by default. Default empty array. * * @type callable $render_callback Callback used to render blocks of this block type. * } * @return WP_Block_Type|false The registered block type on success, or false on failure. */ function register_block_type_from_metadata( $file_or_folder, $args = array() );
Attachments (1)
Change History (15)
This ticket was mentioned in PR #346 on WordPress/wordpress-develop by gziolo.
5 years ago
#1
- Keywords has-patch has-unit-tests added
#3
@
5 years ago
The patch added on GitHub includes changes added to Gutenberg in:
- https://github.com/WordPress/gutenberg/pull/20794
- https://github.com/WordPress/gutenberg/pull/22519
register_block_type_from_metadata
function is going to be used to register all blocks on the server when backporting the block editor changes in https://core.trac.wordpress.org/ticket/50420.
#6
@
5 years ago
- Owner set to gziolo
- Resolution set to fixed
- Status changed from new to closed
In 48141:
This ticket was mentioned in PR #373 on WordPress/wordpress-develop by gziolo.
4 years ago
#7
Trac ticket: https://core.trac.wordpress.org/ticket/50263
This PR exposes all core blocks on the server to be used with the REST API block types endpoint.
Note: Embeds blocks aren't registered on the server. It's a more complex task for post WordPress 5.5.
## Testing
It can be tested using the temporary approach where blocks are exposed from the server using wp.blocks.unstable__bootstrapServerSideBlockDefinitions
function call:
![Screen Shot 2020-06-30 at 20 05 28](https://user-images.githubusercontent.com/699132/86161506-a37bf400-bb0d-11ea-8dd6-40347391e805.png)
#10
@
4 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
After working on support for register_block_type_args
filter in #49615, I realized that we need to use init
action for core blocks to make it possible to use it.
Trac ticket: https://core.trac.wordpress.org/ticket/50263