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
[WIP] Add plugin template registration API #61577
base: trunk
Are you sure you want to change the base?
Conversation
Size Change: -6.61 kB (-0.38%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
f3d4e5a
to
03c90ff
Compare
2fa0a91
to
1390923
Compare
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/block-templates.php ❔ lib/class-wp-block-templates-registry.php ❔ lib/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php ❔ lib/compat/wordpress-6.6/compat.php ❔ lib/load.php |
37cec51
to
da50079
Compare
da50079
to
b244dc9
Compare
Flaky tests detected in 97578ce. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9205169741
|
b244dc9
to
1c13545
Compare
1c13545
to
54d2199
Compare
@youknowriad @ntsekouras this PR is still missing tests and documentation, but feature-wise everything should be working, so I would really appreciate it if you could take a look and tell me whether this approach looks good or not. 🙏 In #41401, there were some proposals of next steps, but for now I'm keeping the PR small, only introducing the basic API. This way we can iterate on it in the future. |
Looking at the shape of the API. The first thing that comes to my mind is whether we should keep the "path" argument or replace it with a "content" argument instead that could be more flexible? I didn't give it too much thoughts though, and would appreciate opinions. |
It would be great to get a lot of eyes on this PR, specially from folks familiar with Core and PHP @WordPress/gutenberg-core |
I would love if we can think of a declarative way to actually absorb the |
Thanks for taking a look, @youknowriad!
Good point! I initially started with the
You mean doing it as part of the template registration API or as a follow-up? I'm a bit wary of having a big scope for the first version of the API. Even though in the testing steps I added a |
I guess it's fine as a follow-up, so you're saying that by default these registered templates will serve as "custom templates" you can assign to posts/pages... right? |
Is this meant to be a GB only experimental API for now? |
@ellatrix For me at least, this shouldn't land in 6.6, we need a bit of time to iron things out properly. |
Yes, exactly. With the example code defining |
What?
This WIP PR introduces a new API so plugins can easily register templates and template parts.
Closes #41401.
Why?
Currently, it's not easy for plugins to register templates and template parts, as they need to hook into several filters.
How?
This PR creates two new functions:
gutenberg_register_block_template()
andgutenberg_register_block_template_part()
as well as aWP_Block_Templates_Registry
class. They are based onregister_block_type()
andWP_Block_Type_Registry
.You can read more about the API shape in this comment: #41401 (comment).
Status
This is a WIP PR and there are still several tasks pending. This is not an exhaustive list, as more things might appear in the future.
gutenberg_register_block_template()
,gutenberg_register_block_template_part()
andWP_Block_Templates_Registry
.@core-merge
comments to ease PR merge.Testing Instructions
Testing a template:
/category/test-category/
) and verify therecipe-index.html
template is rendered.Recipe index
template appears with the correct title and description./templates/recipe-index.html
template to your active theme and repeat steps 2-5.Testing a template part:
/parts/recipe-ingredients.html
template part to your active theme and repeat steps 2-4.Testing Instructions for Keyboard
Screenshots or screencast