-
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
[FSE - Templates]: Add info to templates created from wp suggestion #41387
Conversation
Size Change: -9 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
$changes->post_excerpt = $template->description; | ||
} | ||
|
||
if ( 'wp_template' === $this->post_type ) { |
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 is a new addition.
} | ||
|
||
$origin = get_post_meta( $post->ID, 'origin', true ); | ||
$is_wp_suggestion = get_post_meta( $post->ID, 'is_wp_suggestion', true ); |
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 is a new addition.
* @param string $id Template unique identifier (example: theme_slug//template_slug). | ||
* @param array $template_type wp_template or wp_template_part. | ||
*/ | ||
return apply_filters( 'get_block_template', $block_template, $id, $template_type ); |
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.
Unrelated to this PR, but this filter will never apply if we have template object results from DB. See is_wp_error
condition above.
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 noticed that as well, but it might be better to handle this separately. WDYT?
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.
Also it might be intentional, I'm not really sure and would need checking.
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.
Sure. Let's fix this in a follow-up.
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.
Changes test well for me. Thanks, Nik!
✅ I cannot rename templates from the WP hierarchy in Site Editor.
✅ These templates aren't visible in the Post Editor template dropdown (The default template doesn't count).
✅ Suggested template create works as expected, and they're not visible in the post editor.
If not for the issue I mentioned above, I think we could've done most of the changes using get_block_templates
and get_block_template
filters + extending the REST API endpoint.
The number of changes we've to make for simple enhancements like this sure makes things complicated.
…41387) * [FSE - Templates]: Add info to templates created from wp suggestion * remove leftover
Does this commit have something to do with the recent issue when the page templates are no longer displaying? - #41617 |
It seems it does. I'll look into this! |
Added the Needs Dev Note label in case this needs a dev note for the 6.1 release. |
…e content. This commit improves site editor templates by: * Adds a post meta `is_wp_suggestion` to templates created from the site editor. Why? To differentiate the templates created from the post editor in the Template panel in inspector controls and the templates suggested in site editor. See [WordPress/gutenberg#41387 Gutenberg PR 41387] for more details. * Expands the template types that can be added to the site editor to include single custom post type and specific posts templates. See [WordPress/gutenberg#41189 Gutenberg PR 41189] for more details. * Adds fallback template content on creation in site editor: * Introduces `get_template_hierarchy()` to get the template hierarchy for a given template slug to be created. * Adds a `lookup` route to `WP_REST_Templates_Controller` to get the fallback template content. See [WordPress/gutenberg#42520 Gutenberg PR 42520] for more details. * Fixes a typo in default category template's description within `get_default_block_template_types()`. See [WordPress/gutenberg#42586 Gutenberg PR 42586] for more details. * Changes field checks from `in_array()` to `rest_is_field_included()` in `WP_REST_Post_Types_Controller`. * Adds an `icon` field to `WP_REST_Post_Types_Controller` Follow-up to [53129], [52331], [52275], [52062], [51962], [43087]. Props ntsekouras, spacedmonkey, mamaduka, mburridge, jameskoster, bernhard-reiter, mcsf, hellofromTonya. See #56467. git-svn-id: https://develop.svn.wordpress.org/trunk@54269 602fd350-edb4-49c9-b593-d223f7449a82
…e content. This commit improves site editor templates by: * Adds a post meta `is_wp_suggestion` to templates created from the site editor. Why? To differentiate the templates created from the post editor in the Template panel in inspector controls and the templates suggested in site editor. See [WordPress/gutenberg#41387 Gutenberg PR 41387] for more details. * Expands the template types that can be added to the site editor to include single custom post type and specific posts templates. See [WordPress/gutenberg#41189 Gutenberg PR 41189] for more details. * Adds fallback template content on creation in site editor: * Introduces `get_template_hierarchy()` to get the template hierarchy for a given template slug to be created. * Adds a `lookup` route to `WP_REST_Templates_Controller` to get the fallback template content. See [WordPress/gutenberg#42520 Gutenberg PR 42520] for more details. * Fixes a typo in default category template's description within `get_default_block_template_types()`. See [WordPress/gutenberg#42586 Gutenberg PR 42586] for more details. * Changes field checks from `in_array()` to `rest_is_field_included()` in `WP_REST_Post_Types_Controller`. * Adds an `icon` field to `WP_REST_Post_Types_Controller` Follow-up to [53129], [52331], [52275], [52062], [51962], [43087]. Props ntsekouras, spacedmonkey, mamaduka, mburridge, jameskoster, bernhard-reiter, mcsf, hellofromTonya. See #56467. Built from https://develop.svn.wordpress.org/trunk@54269 git-svn-id: http://core.svn.wordpress.org/trunk@53828 1a063a9b-81f0-0310-95a4-ce76da25c4cd
…e content. This commit improves site editor templates by: * Adds a post meta `is_wp_suggestion` to templates created from the site editor. Why? To differentiate the templates created from the post editor in the Template panel in inspector controls and the templates suggested in site editor. See [WordPress/gutenberg#41387 Gutenberg PR 41387] for more details. * Expands the template types that can be added to the site editor to include single custom post type and specific posts templates. See [WordPress/gutenberg#41189 Gutenberg PR 41189] for more details. * Adds fallback template content on creation in site editor: * Introduces `get_template_hierarchy()` to get the template hierarchy for a given template slug to be created. * Adds a `lookup` route to `WP_REST_Templates_Controller` to get the fallback template content. See [WordPress/gutenberg#42520 Gutenberg PR 42520] for more details. * Fixes a typo in default category template's description within `get_default_block_template_types()`. See [WordPress/gutenberg#42586 Gutenberg PR 42586] for more details. * Changes field checks from `in_array()` to `rest_is_field_included()` in `WP_REST_Post_Types_Controller`. * Adds an `icon` field to `WP_REST_Post_Types_Controller` Follow-up to [53129], [52331], [52275], [52062], [51962], [43087]. Props ntsekouras, spacedmonkey, mamaduka, mburridge, jameskoster, bernhard-reiter, mcsf, hellofromTonya. See #56467. Built from https://develop.svn.wordpress.org/trunk@54269 git-svn-id: https://core.svn.wordpress.org/trunk@53828 1a063a9b-81f0-0310-95a4-ce76da25c4cd
…e content. This commit improves site editor templates by: * Adds a post meta `is_wp_suggestion` to templates created from the site editor. Why? To differentiate the templates created from the post editor in the Template panel in inspector controls and the templates suggested in site editor. See [WordPress/gutenberg#41387 Gutenberg PR 41387] for more details. * Expands the template types that can be added to the site editor to include single custom post type and specific posts templates. See [WordPress/gutenberg#41189 Gutenberg PR 41189] for more details. * Adds fallback template content on creation in site editor: * Introduces `get_template_hierarchy()` to get the template hierarchy for a given template slug to be created. * Adds a `lookup` route to `WP_REST_Templates_Controller` to get the fallback template content. See [WordPress/gutenberg#42520 Gutenberg PR 42520] for more details. * Fixes a typo in default category template's description within `get_default_block_template_types()`. See [WordPress/gutenberg#42586 Gutenberg PR 42586] for more details. * Changes field checks from `in_array()` to `rest_is_field_included()` in `WP_REST_Post_Types_Controller`. * Adds an `icon` field to `WP_REST_Post_Types_Controller` Follow-up to [53129], [52331], [52275], [52062], [51962], [43087]. Props ntsekouras, spacedmonkey, mamaduka, mburridge, jameskoster, bernhard-reiter, mcsf, hellofromTonya. See #56467. git-svn-id: https://develop.svn.wordpress.org/trunk@54269 602fd350-edb4-49c9-b593-d223f7449a82
What?
Part of: #37407
Needed for: #41189
This PR adds a post meta(
is_wp_suggestion
) to templates created from the site editor.Why?
Currently we handle some template actions/filtering based on whether the template is part of the template hierarchy. This currently happens through
get_default_block_template_types
results, that are hardcoded and of course are just a few of the possible templates. Many specific templates will need to be dynamically calculated and suggested(see linked PR for single-$post_type, archive-$post_type and post specific templates) and these should be treated as well as part of the template hierarchy.In a few words we need to differentiate the templates created from the post editor in the
Template
panel in inspector controls and the ones suggested in site editor. So in the suggested templates in site editor list(Add new
) from WP we should mark them as suggested.Testing instructions
The two main differences are:
in site editor we should not be able to rename a template from template hierarchy
such a template should not be shown in post editor available templates
Create a new template from post editor
Add the below snippet here(before the return) and create the template
`missingTemplates.push( {
title: 'Suggested',
description: 'test template',
slug: 'single-book',
} );
Test that everything is working as expected and no regression is introduced
Existing templates should rename unaffected.