CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Template activation: reduce templates listed as options for post/page #72141
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
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +52 B (0%) Total Size: 1.96 MB
ℹ️ View Unchanged
|
07d31b4
to
4f23323
Compare
Flaky tests detected in 4f23323. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18323374394
|
return [ | ||
...registeredTemplates, | ||
...userTemplates.filter( | ||
( template ) => | ||
// Only give "custom" templates as an option, which | ||
// means the is_wp_suggestion meta field is not set and | ||
// the slug is not found in the default template types. | ||
// https://github.com/WordPress/wordpress-develop/blob/97382397b2bd7c85aef6d4cd1c10bafd397957fc/src/wp-includes/block-template-utils.php#L858-L867 | ||
! template.meta.is_wp_suggestion && | ||
! defaultTemplateTypes.find( | ||
( type ) => type.slug === template.slug | ||
) | ||
), | ||
}; | ||
]; |
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 practice we're trying to discourage and use rarely. It's probably better to do this merging and filtering in useMemo
, no?
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.
Oh that's news to me, why is it discouraged?
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 know it's not the case here, but it's easy to "break" shallow equality checks if you're not careful and manipulate objects/arrays inside the useSelect
callback, IMO.
We even introduced a dev warning to catch those early and help third-party developers.
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.
Hm, but the same can be said of returning an object breaking shallow equality if you nest them. I get your argument, but I think there are valid cases like being able avoid passing values to the render function and avoid re-renders due to value changes. Not super applicable here, but I like avoiding the useMemo
call if it's possible like this.
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.
Restored in 532f4b1
Merging because this is blocking GB stable. Let me know if there's concerns and I'll follow up. |
…#72141) Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
I just cherry-picked this PR to the release/21.8 branch to get it included in the next release: e266b75 |
…WordPress#72141) Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
What?
Restores the behaviour from WP 6.8: only actual custom templates should be listed in the template modal for specific posts/pages.
Why?
This is the current WP behavior: when you make edits to a theme template file, the old template or the edit is not visible as an option. Only templates that are "custom" according to the hierarchy can be picked. This is not ideal, but it's a currently limitation because the template property of a post has to be a slug instead of the template ID.
How?
There's actually an error in the changes I made before: the new templates endpoint doesn't have a
post_type
query option because it's a normal post endpoint. That's why I have to expose theis_wp_suggestion
meta (which was not correctly set anymore after the rewrite), which seems to be used currently to determine if a template is custom.A template is custom if
is_wp_suggestion
is not set and if the template slug does not appear in the default template types.Testing Instructions
Create a specific template for a certain post, this template should not appear in the template options for other posts.
Duplicate the page template for the theme (or any other template). These user templates should also not appear in the options in the post/page editors.
Now create a "custom" templates (last option) after clicking "Add template". This one should appear in the options!
Testing Instructions for Keyboard
Screenshots or screencast