Make WordPress Core

Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#50263 closed enhancement (fixed)

Editor: Introduce new API method that register block from `block.json` metadata file

Reported by: gziolo's profile gziolo Owned by: gziolo's profile 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 gziolo)

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)

50263-init.diff (2.3 KB) - added by gziolo 4 years ago.
Move core blocks registration to init hook

Download all attachments as: .zip

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

#2 @gziolo
5 years ago

  • Description modified (diff)

#3 @gziolo
5 years ago

The patch added on GitHub includes changes added to Gutenberg in:

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.

Last edited 5 years ago by gziolo (previous) (diff)

#4 @gziolo
5 years ago

  • Keywords needs-dev-note dev-feedback added

gziolo commented on PR #346:


5 years ago
#5

@ocean90, is it good to go now?

#6 @gziolo
5 years ago

  • Owner set to gziolo
  • Resolution set to fixed
  • Status changed from new to closed

In 48141:

Editor: Introduce new API method that register block from block.json metadata file

Backports changes added to Gutenberg in:

register_block_type_from_metadata function is going to be used to register all blocks on the server using block.json metadata files.

Props ocean90, azaozz, aduth, mcsf, jorgefilipecosta, spacedmonkey, nosolosw, swissspidy and noahtallen.
Fixes #50263.

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)

#8 @gziolo
4 years ago

In 48262:

Editor: Register core blocks on the server

Exposes all core blocks (excluding embeds) on the server to be used with the REST API block types endpoint.

Props spacedmonkey, timothyblynjacobs.
Fixes #50263.

#9 @gziolo
4 years ago

  • Keywords dev-feedback removed

#10 @gziolo
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.

@gziolo
4 years ago

Move core blocks registration to init hook

#11 @gziolo
4 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 48279:

Editor: Move core blocks registration to init hook

After working on support for register_block_type_args filter in #49615, it became clear that we need to use init action for core blocks to make it possible to use this filter.

Fixes #50263.

This ticket was mentioned in Slack in #core by justinahinon. View the logs.


4 years ago

This ticket was mentioned in Slack in #core-editor by justinahinon. View the logs.


4 years ago

#14 @justinahinon
4 years ago

  • Keywords has-dev-note added; needs-dev-note removed
Note: See TracTickets for help on using tickets.