WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 5 months ago

#53149 new feature request

Plugins: Consider using `block.json` file as an entry point for blocks from Block Directory

Reported by: gziolo Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Plugins Keywords: 2nd-opinion
Focuses: Cc:

Description (last modified by gziolo)

The original discussion sparked by a comment from @jipmoors on GitHub in https://github.com/WordPress/gutenberg/pull/13693#issuecomment-477904539:

WordPress automatically discovers all the block.json files in the plugin/core blocks folder and registers the corresponding block types. These block types are made available through the block registry (https://developer.wordpress.org/reference/classes/wp_block_type_registry/) PHP class, and the blocks scripts and styles are added as dependencies to the wp-block-library script and style handles.

At the moment, it's mandatory to create the PHP file for the plugin that contains only a single block type registration code when developing for Block Directory. Those plugins rarely have PHP code, so we could simplify the flow for developers by making it possible to use block.json to source all required metadata. If the current metadata schema doesn't contain some fields that can be declared only in the PHP comment (some are duplicated in readme.txt, we can always include it in block.json.

In the case when developers would like to use the render_callback, they could use the concept proposed in #53148 - the renderTemplate file reference in block.json. This way, the process of validation of block types submitted to Block Directory would get further simplified.

Change History (3)

#1 @gziolo
5 months ago

  • Description modified (diff)

#2 @desrosj
5 months ago

  • Keywords 2nd-opinion added
  • Milestone Awaiting Review deleted

@gziolo I think that the Meta Trac may be a better place for this initial discussion to be had (it may not be possible with how the directory is set up).

As far as I know, a PHP file is required because Block Directory plugins are just a specific type of plugin and have to adhere to the same requirements around required files. The main PHP file in the plugin is used for the plugin headers so that the plugin can be activated/deactivated.

#3 @gziolo
5 months ago

As far as I know, a PHP file is required because Block Directory plugins are just a specific type of plugin and have to adhere to the same requirements around required files.

Yes, all correct. This is why I'm proposing this ticket. Let's discuss if we could make the system more flexible and allow to skip PHP file when block.json is present.

Last edited 5 months ago by gziolo (previous) (diff)
Note: See TracTickets for help on using tickets.