Allow the new wp_register_block_template
to register both wp_template
and wp_template_part
types
#65861
Labels
[Type] Enhancement
A suggestion for improvement.
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 thetype
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 aMini Cart
block template part. And this can't be done using the newwp_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 thetype
property in the$args
parameter.Currently, the
get_block_templates
function in the core can return eitherwp_template
orwp_template_part
objects based on the specifiedtemplate_type
parameter. And the returned objects for both types have similar structures. So maybe we can use thewp_register_block_template
API to also registerwp_template
orwp_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 ofregister_block_template
?We have similarly named APIs, like
register_block_type
,register_block_style
,register_block_pattern
, etc.The text was updated successfully, but these errors were encountered: