Skip to content

Allow the new wp_register_block_template to register both wp_template and wp_template_part types #65861

Description

@daviedR

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions