Open daviedR opened 1 month ago
Hi, I would like to work on this issue.
Ideally, we want to try to make template parts, special block patterns. Read this for more details https://github.com/WordPress/gutenberg/issues/62566#issuecomment-2180749161
In that sense, there's already a registration function for patterns. So solving what that link proposes would be another way to solve this issue.
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, likeregister_block_type
,register_block_style
,register_block_pattern
, etc.