-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix template part theme identifier #25995
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
|
Size Change: +2 B (0%) Total Size: 1.19 MB
ℹ️ View Unchanged
|
noahtallen
left a 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.
This seems to be working well for me! ![]()
|
Thanks! |
|
|
||
| // Ensure auto-drafts of all theme supplied template parts are created. | ||
| if ( wp_get_theme()->get( 'TextDomain' ) === $request['theme'] ) { | ||
| if ( wp_get_theme()->stylesheet === $request['theme'] ) { |
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.
should we use wp_get_theme()->get_stylesheet() instead? cc @mcsf
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.
@nosolosw dug into this just yesterday (and himself used get_stylesheet()), so I'll defer to him.
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.
👋 TLDR: if you look for a theme identifier, stylesheet is the best option. Here's what I know:
- Despite its name,
stylesheetrefers to the name of the theme directory within the theme root (see https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/class-wp-theme.php#L206). - For child themes, its value is the child theme directory name, not the parent's. This means that, effectively,
stylesheetcan function as the unique identifier of a theme, unlike other potential candidates such astextdomain(can be empty) ortemplate(points to the parent in a child theme). - If the theme is stored within another directory (eg:
themes/some-dir/my-themeinstead ofthemes/my-theme) it'll returnsome-dir/my-theme, so need to cover for this case if it's problematic. - The
stylesheetname can contain any character that is allowed in the filesystem (eg: spaces, somy themeis a validstylesheetvalue), need to cover for this as well.
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.
Nice, thanks for that overview! I guess I was curious about the difference between:
$theme_identifier = wp_get_theme()->stylesheet;
// alternatively:
$theme_identifier = wp_get_theme()->get_stylesheet();is there any reason to use one over the other?
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, what a misunderstanding, I'm so embarrassed 😅
Probably the WordPress standards or PHP idioms have some strong opinions on how this should be done, but I don't know if it really matters in this case.
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 wp_get_theme()->get_stylesheet(); is preferred.
Description
Update to use the themes
stylesheetproperty instead oftextdomain. It was pointed out (#25923 (comment)) that whiletextdomainshould generally be the same asstylesheet,textdomaincould technically be omitted andstylesheetwill be a more robust solution.How has this been tested?
Smoke test template part seleection:
Screenshots
Types of changes
Checklist: