Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gutenberg_Block_Template 'theme' property is confusing, because templates might be added by plugins instead of themes #37401

Closed
Aljullu opened this issue Dec 15, 2021 · 2 comments
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Feature] Templates API Related to API powering block template functionality in the Site Editor

Comments

@Aljullu
Copy link
Contributor

Aljullu commented Dec 15, 2021

Description

Currently, the Gutenberg_Block_Template has a theme property that is used to indicate which theme the template belongs to. That works great for themes, but it's confusing when plugins add templates: should plugin devs set the plugin name in the theme property? Currently, the answer is yes, but it's confusing!

I wonder if theme property could be renamed to something that encompasses themes and plugins. So a template added by a plugin, instead of being defined like this:

...
$template->origin      = 'plugin';
$template->theme       = 'woocommerce//woocommerce';
...

would be defined like something along these lines:

...
$template->origin      = 'plugin';
$template->origin_slug = 'woocommerce//woocommerce';
...

I know we are late in the WP 5.9 release cycle so we might not be able to make a change like that at this point. In that case, I would like to clarify if the recommended way for plugins to add templates is to use the theme property.

Any thoughts on this @carolinan @talldan @kevin940726?

Step-by-step reproduction instructions

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@Aljullu Aljullu added [Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Templates API Related to API powering block template functionality in the Site Editor [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") labels Dec 15, 2021
@talldan
Copy link
Contributor

talldan commented Dec 16, 2021

Thanks for creating the issue. I've been meaning to create one along the same lines.

It's probably a bit too late to change this in the release cycle for WordPress 5.9, and the REST API for templates has been available since WordPress 5.8, so there will be backward compatibility concerns with any change.

I think what we do need is some documentation outlining exactly how plugins can add templates before the release of 5.9.

At the moment I think the agreed settings are for source to be set to 'plugin' and theme to be set to the slug of the plugin. origin is derived from source when a template is customized.

@Aljullu
Copy link
Contributor Author

Aljullu commented Dec 16, 2021

Makes sense, thanks for clarifying this part, @talldan:

At the moment I think the agreed settings are for source to be set to 'plugin' and theme to be set to the slug of the plugin. origin is derived from source when a template is customized.

Based on that I will close this issue assuming it works as expected. Looking forward to the documentation. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Feature] Templates API Related to API powering block template functionality in the Site Editor
Projects
None yet
Development

No branches or pull requests

2 participants