-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
What problem does this address?
Hi, I just checked the new wp_register_block_template
API (WP 6.7 beta) that allows custom plugins (and themes) to register block templates in PHP.
I noticed that the API only supports creating block templates (wp_template
) as the type
property is hardcoded in the registry (WP_Block_Templates_Registry
).
In some cases, plugins might want to add block template parts (wp_template_part
) in PHP. For example, the WooCommerce plugin adds a Mini Cart
block template part. And this can't be done using the new wp_register_block_template
API.
What is your proposed solution?
Allow the wp_register_block_template
API to also register a block template part. Perhaps by defining the type
property in the $args
parameter.
Currently, the get_block_templates
function in the core can return either wp_template
or wp_template_part
objects based on the specified template_type
parameter. And the returned objects for both types have similar structures. So maybe we can use the wp_register_block_template
API to also register wp_template
or wp_template_part
type, instead of creating a separate API for template parts (e.g. wp_register_block_template_part
).
Also, I am curious why is it named wp_register_block_template
instead of register_block_template
?
We have similarly named APIs, like register_block_type
, register_block_style
, register_block_pattern
, etc.