-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add plugin template registration API #61577
Conversation
Size Change: +45 B (0%) Total Size: 1.77 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.7/class-gutenberg-rest-templates-controller-6-7.php ❔ lib/compat/wordpress-6.7/compat.php ❔ lib/compat/wordpress-6.7/rest-api.php ❔ lib/load.php |
da50079
to
b244dc9
Compare
Flaky tests detected in ae59c2c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9682409402
|
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 |
lib/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Timothy Jacobs <timothy@ironbounddesigns.com>
Co-authored-by: Timothy Jacobs <timothy@ironbounddesigns.com>
…after a wrong rebase
3772fa9
to
7eb235c
Compare
Let's land this and have a follow up if needed for the small change discussed here. Great work! |
Co-authored-by: Aljullu <aljullu@git.wordpress.org> Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org> Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org> Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org> Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: mtias <matveb@git.wordpress.org> Co-authored-by: gziolo <gziolo@git.wordpress.org> Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org> Co-authored-by: TimothyBJacobs <timothyblynjacobs@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: ndiego <ndiego@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: nerrad <nerrad@git.wordpress.org> Co-authored-by: annezazu <annezazu@git.wordpress.org>
await expect( | ||
page.getByText( 'This is a plugin-registered page template.' ) | ||
).toBeVisible(); | ||
} ); |
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.
This new test is failing on my freshly rebased branch. Any idea why? #64479
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.
I left a comment on #64479 (comment).
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.
I think this line await page.goto( '?page_id=2' );
might cause the issue. The test assumes that a page with ID = 2 will exist when it's run. The test that ran before in the same shard can remove all pages. Usually, the test file is responsible for setting up all required data.
The same probably applies to the await page.goto( '/?cat=1' );
calls above.
Related discussion about DB snapshots: #61719
…des for plugin-registered templates This commit introduces a new API to allow plugins to easily register block templates with `wp_register_block_template()` and the `WP_Block_Templates_Registry` class, addressing the complexity of hooking into multiple filters. It also ensures plugin-registered templates overridden by themes fall back to the plugin-provided title and description when the theme doesn't define them. See WordPress/gutenberg#61577. See WordPress/gutenberg#64610. Fixes #61804. Props aljullu, peterwilsoncc, antonvlasenko, azaozz, youknowriad, noisysocks. git-svn-id: https://develop.svn.wordpress.org/trunk@59073 602fd350-edb4-49c9-b593-d223f7449a82
…des for plugin-registered templates This commit introduces a new API to allow plugins to easily register block templates with `wp_register_block_template()` and the `WP_Block_Templates_Registry` class, addressing the complexity of hooking into multiple filters. It also ensures plugin-registered templates overridden by themes fall back to the plugin-provided title and description when the theme doesn't define them. See WordPress/gutenberg#61577. See WordPress/gutenberg#64610. Fixes #61804. Props aljullu, peterwilsoncc, antonvlasenko, azaozz, youknowriad, noisysocks. Built from https://develop.svn.wordpress.org/trunk@59073 git-svn-id: http://core.svn.wordpress.org/trunk@58469 1a063a9b-81f0-0310-95a4-ce76da25c4cd
…des for plugin-registered templates This commit introduces a new API to allow plugins to easily register block templates with `wp_register_block_template()` and the `WP_Block_Templates_Registry` class, addressing the complexity of hooking into multiple filters. It also ensures plugin-registered templates overridden by themes fall back to the plugin-provided title and description when the theme doesn't define them. See WordPress/gutenberg#61577. See WordPress/gutenberg#64610. Fixes #61804. Props aljullu, peterwilsoncc, antonvlasenko, azaozz, youknowriad, noisysocks. Built from https://develop.svn.wordpress.org/trunk@59073 git-svn-id: https://core.svn.wordpress.org/trunk@58469 1a063a9b-81f0-0310-95a4-ce76da25c4cd
What?
This PR introduces a new API so plugins can easily register templates.
Closes #41401.
Backport PR in core: WordPress/wordpress-develop#7125.
Why?
Currently, it's not easy for plugins to register templates, as they need to hook into several filters.
How?
This PR creates a new function:
wp_register_block_template()
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).
Testing Instructions
Basic template customization:
/category/test-category/
) and verify the Plugin Template contents are rendered.Plugin Template
appears with the correct title and description.With theme customization:
/templates/plugin-template.html
template to your active theme and repeat steps 2-5./templates/plugin-template.html
from your theme before proceeding with the next steps.Using the template in a post type:
Deactivating the plugin:
Unregistering templates:
Registering WP default templates:
/category/test-category/
).category.html
template to your theme.Registering templates already customized by the user:
/author/admin/
).Devnote