-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Allow plugins to add new items to the "Add new" menu on the Site Editor #46362
Conversation
9b446d9
to
e5a0aae
Compare
e5a0aae
to
4c12c66
Compare
packages/edit-site/src/components/add-new-template/new-template.js
Outdated
Show resolved
Hide resolved
1ce8c71
to
102d4c8
Compare
102d4c8
to
224e96b
Compare
packages/edit-site/src/components/add-new-template/new-template.js
Outdated
Show resolved
Hide resolved
packages/edit-site/src/components/add-new-template/new-template.js
Outdated
Show resolved
Hide resolved
Rather than plugins having to do this manually, could core handle it for them? IE if a custom post type or taxonomy is The same functionality could theoretically drive #40941. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work! In general I think this is the time that @WordPress/gutenberg-core should chime in and maybe the @WordPress/gutenberg-design , since adding this is a commitment and there are some new designs about adding new templates. --cc @jorgefilipecosta
I'm also wondering this. It would be nice if we could use existing WordPress APIs. |
This is already handled for CPTs and custom taxonomies. It might be just specialized custom templates although I'm not sure what these should be and if it makes sense, as their content can't know the used headers/footers etc.. @albarin can you explain a bit more about the use case of yours and if the CPTs and taxonomies can be leveraged there? --edit There is also this issue about the addition of such templates: #41401 |
Sure, via the WooCommerce plugin, we added support for the |
@ntsekouras anything else we can do to get more feedback or move this forward? Thanks! 🙌 |
I think you could bring it up in the weekly
Have you explored the possibility of making them public? If that part is done, what would be the remaining problem? Would it be that you don't want to expose the |
@ntsekouras Yes, I've tried that and this is what happens: because every product attribute is a separate taxonomy itself we get an item in the menu for each one of them 👇 But what we want is a general template that will be applied to all product attributes. |
I think there are always cases that don't make sense to be supported by core. For example, the Product by Attribute has been discussed above. Besides, @albarin also linked an exploration PR about templates for each Product Type which is a private taxonomy under the hood. The Product Type template is for displaying individual products. We can make that taxonomy public but it's super confusing to add a new template for taxonomy but that template is used for the single item (instead of the loop). We're just taking WooCommerce examples, I believe there is so much more special and creative usage of WordPress data objects in the broader ecosystem. And I think it'd be a great developer experience to support those custom/creative usages. |
Thank you for clarifying some of the needed use cases. What becomes more obvious to me is that we should consider an API that could be more flexible in terms of the current generic template handling. This could mean an API that explicitly declares some things - for example if has a I think some of the use cases here are worth being mentioned to the scaling Sorry for delaying to response, but I'm mostly working for WP |
I don't understand why this is an issue. You might want to create a template that is applied to all product attributes. It would be extremely tedious to have to repeat this process for every single attribute if you want the same display for all of them.
Private entities shouldn't be displayed here. Similar to how we do not offer template creation for private post types (like orders). Edit: That said, it seems reasonable that folks might want different templates for different product types. |
I just want to clarify my point more. Continuing on the Product Type, it's a special entity of WooCommerce that is only used internally. WC uses that taxonomy to determine the type of product. There isn't an archive page for product types. Now we want to create templates for product types, we can't do that because Gutenberg only supports default entities that are used in the intended way (post type for a single item, taxonomy term for a list of items), we want to create the template for each product type which displays a single product but the entity powering it is a taxonomy, which for list of items. Plugins should try to use the core entity as much as they can. But to me, using core entities in an unintended way like this makes total sense. Plugins can even create their own type of entity. So having a way to register custom templates will save plugin developers a lot of effort. |
What?
This PR adds the new
extraTemplateTypes
custom setting and theextra_template_types
filter which will allow plugins to add new items to theAdd new
dropdown menu on theSite Editor
.Why?
Currently, other plugins cannot add new menu items to the
Add new
menu.For example, via the WooCommerce plugin, we want to make a block template available in the
Add menu
user interface that will apply to all product attributes pages, which wouldn't be possible right now.How?
This PRs is introducing a new filter
extra_template_types
which plugins can use to add their custom templates and that is passed to the Site Editor via a new custom setting calledextraTemplateTypes
.Testing Instructions
extra_template_types
hook:Site Editor
>Browse all templates
(/wp-admin/site-editor.php?postType=wp_template
)Add new
button and make sure you see an item in the dropdown for theMy new template
template.Screenshots