-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Site Editor: Limit template part slugs to Latin chars #38695
Conversation
Size Change: +40 B (0%) Total Size: 1.14 MB
ℹ️ View Unchanged
|
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.
Are there plans to support non-Latin characters? I'm afraid that this fix could have some side effects when the cleaned slugs collide with each other. For instance hello-世界
and hello-台灣
will both result in the same slug hello-
.
Maybe instead of handling them implicitly, we should throw an error and let the users choose the alternative slug names.
// Currently template parts only allow latin chars. | ||
// Fallback slug will receive suffix by default. | ||
const cleanSlug = | ||
kebabCase( title ).replace( /[^\w-]+/g, '' ) || | ||
'wp-custom-part'; |
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.
Could we extract this into a utility function or hook?
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.
We have the cleanForSlug
method, which supports non-Latin chars; this is the reason I decided to inline it to avoid confusion in the future.
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.
We could still name this getCleanSlugForLatinChars
or something to make it explicit, but I don't feel strongly that we need to do 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.
I will leave inline for now, if that's okay for you.
I'm not 100% sure about this. Currently, slugs are considered 1:1 map to template filenames, which usually use Latin chars.
WP will try to make them unique and suffix one with a number.
Do would be my ideal UX as well. Now modals on have title fields. Do we always want to display the slug field or just when the title contains non-Latin chars? @jameskoster, do you have any suggestions about displaying the slug field? |
Is there any situation in the general UX where the slug has a practical use for template parts? I'm trying to think of something but coming up blank 🤔 Assuming that is the case, I would advocate keeping the slug as invisible as possible. IE auto-generating If there are flows in which the end user needs to interact with the slug, then let's list them and think about where/when it might be best to edit. |
Only case I can think of is this. Where we can't auto-generate slugs because of non-Latin chars. Generally we want the slug field hidden. |
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.
Makes sense 👍 . Thanks!
Description
Resolves #38160.
Currently, templates and template parts don't allow non-Latin characters as a slug.
This PR tries to "clean" up the slug first, and if this isn't possible, use a fallback slug.
Testing Instructions
私のテンプレートパーツのテスト
orქართული ნაწილი
.Types of changes
Bugfix
Checklist:
*.native.js
files for terms that need renaming or removal).