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
Update 'Add template' screen to prefer template_name label instead of singular_name #60367
base: trunk
Are you sure you want to change the base?
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: +110 B (0%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
@@ -98,33 +98,31 @@ const usePublicTaxonomies = () => { | |||
}, [ taxonomies ] ); | |||
}; | |||
|
|||
function usePostTypeNeedsUniqueIdentifier( publicPostTypes ) { |
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.
Why not adjust the logic here?
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.
Until now, the same could be reused in usePostTypeArchiveMenuItems()
and usePostTypeMenuItems()
, I guess that's why this function existed, instead of having it inline like in useTaxonomiesMenuItems()
.
With the changes in this PR, though, the same code can no longer be shared between usePostTypeArchiveMenuItems()
and usePostTypeMenuItems()
and because of that I removed the function and inlined the code in each respective place.
I don't have a strong opinion, so I'm happy to create functions for each one of them if you think that will keep the code cleaner.
); | ||
const needsUniqueIdentifier = useCallback( | ||
( { labels, slug } ) => { | ||
if ( [ 'post', 'page' ].includes( 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.
Why do we need this extra check?
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.
Hmm, good catch! I don't think it's necessary because templateName !== slug
will always resolve to false for post
and page
. I guess it was a leftover from when I was coding, I removed it in 71d5748.
48f049c
to
71d5748
Compare
Fixes #60283.
Related PR on WordPress: WordPress/wordpress-develop#6344.
What?
This PR makes it so the Add template screen displays the
template_name
label for CPT and custom taxonomy templates, instead of relying onsingular_name
.Why?
This way, we allow plugins to add user-friendly names to templates related to their CPT/custom taxonomies.
How?
This PR makes it so
template_name
takes priority oversingular_name
when possible. It also accounts for the cases of:template_name
being missing, in which case we fall back tosingular_name
, as it used to work.template_name
being duplicate, in which case the CPT/custom taxonomy slug is displayed.Testing Instructions
template_name
to the post type and taxonomy: