Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
check for the directory rather than the file
  • Loading branch information
scruffian authored and youknowriad committed Dec 13, 2021
commit 12b017b342c403244e05344d6774635f735161ba
2 changes: 1 addition & 1 deletion lib/compat/wordpress-5.9/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function get_block_theme_folders( $theme_stylesheet = null ) {
$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' ) ) {
if ( is_readable( $theme_dir . '/block-templates/' ) || is_readable( $parent_theme_dir . '/block-templates/' ) ) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I create a child theme with no templates or template parts I see this message:

Screenshot 2021-12-13 at 11 08 48

Copy link
Contributor

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)

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good thanks

return array(
'wp_template' => 'block-templates',
'wp_template_part' => 'block-template-parts',
Expand Down