-
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
Templates: Search for old template names in the parent theme too #36910
Conversation
$parent_root_dir = get_theme_root( $parent_theme_name ); | ||
$parent_theme_dir = "$parent_root_dir/$parent_theme_name"; | ||
|
||
if ( is_readable( $theme_dir . '/block-templates/index.html' ) || is_readable( $parent_theme_dir . '/block-templates/index.html' ) ) { |
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.
The function here is supposed to be called with a theme stylesheet, so there shouldn't be a need for this added check. Maybe there's an issue elsewhere where we call this and we're not calling it with the parent theme 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.
Forget the first comment, I understand the issue better now and I have separate thoughts :)
What happens if the child theme has been migrated but not the parent, it seems this PR will break that behavior.
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.
Maybe the fix is to actually check the presence of the folder and not the index file.
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.
Yeah that would work I think, although I guess its possible that a child theme could not have the folder at all and just supply a theme.json.
If the child has been migrated before the parent then I would expect things to break to be honest!
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.
Yeah that would work I think, although I guess its possible that a child theme could not have the folder at all and just supply a theme.json.
In that case, it doesn't matter since this function is about returning the folders.
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.
Good point :)
f5cf1d2
to
91bff04
Compare
$parent_root_dir = get_theme_root( $parent_theme_name ); | ||
$parent_theme_dir = "$parent_root_dir/$parent_theme_name"; | ||
|
||
if ( is_readable( $theme_dir . '/block-templates/' ) || is_readable( $parent_theme_dir . '/block-templates/' ) ) { |
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.
Can't we just remove || is_readable( $parent_theme_dir . '/block-templates/' )
, since we're calling the function for both themes (parent and child), this should work right?
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 don't think so. If we did that then we'd be back to the changes that are already in trunk, since the other lines don't actually do anything except assign variables.
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 thought the issue was about themes that are child themes, override some templates but not "index.html" so it's different than trunk? Are there any other use-cases 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.
They might not override any templates at all.
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.
They might not override any templates at all.
In that case that function is useless and doesn't matter what it returns.
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 don't think so. Child themes can simply provide a different theme.json file and no other changes.
In that case it doesn't matter what this function returns.
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.
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.
Indeed, I think we had an issue with the template part block's code where the child theme was not handled properly and it should be fixed in 004cba5
The root issue is that get_theme_file_path
function tries to fallback to the parent theme automatically but it doesn't account with the fact that the path could change slightly between parent and child themes (folder names)
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.
Feel free to ship this if the fix in that commit is good enough for you.
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.
Looks good thanks
71852ba
to
84ef2a2
Compare
84ef2a2
to
004cba5
Compare
Description
In #36647 we added a fallback for themes that don't have templates in the new directory structure. However the checks only looked in the child theme, not the parent. This adds the same check to the parent theme, so that templates in child themes continue to load as before
How has this been tested?
This is quite hard to test as most child themes specify their own index.html.
This PR is an example of theme that doesn't: Automattic/themes#5094
Screenshots
Before:
After:
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.js
files for terms that need renaming or removal).