-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix Template Part auto-drafting to support sub-directories. #25063
Fix Template Part auto-drafting to support sub-directories. #25063
Conversation
Size Change: 0 B Total Size: 1.2 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.
This works for me locally 👍
I'm curious, do you know when this is run? Curious if it happens every page load (which would probably be bad performance wise), but I'm guessing it's only at a different time?
lib/template-parts.php
Outdated
$child_template_part_files = glob( get_template_directory() . '/block-template-parts/*.html' ); | ||
$child_template_part_files = is_array( $child_template_part_files ) ? $child_template_part_files : array(); | ||
$template_part_files = array_merge( $template_part_files, $child_template_part_files ); | ||
$template_part_files = get_template_part_paths( get_template_directory(), $template_part_files ); |
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 concatenate the arrays outside of the function instead of passing it in to modify? I like how that would make the function "more pure," if that makes sense
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 makes sense. As in b86514f?
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.
yep thanks!
This runs on the |
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.
Code looks good. Great addition and finally gets rid of those glob()
calls, they were never pretty 😆
Tested locally and it works 👍
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.
Hmmm 🤔
I was trying to test this locally and there are duplicate template part previews for the new template part .html file I've created. Any hunch as to why?
- I'm creating files in the seedlet blocks theme
- I have distinct names for each new html file (nested within a subdirectory)
- I've tried cleaning up all the data in the WordPress instance
npx wp-env clean all
- I double-checked the template parts view in wp-admin to make sure these are auto-drafted. The view is empty, so it seems like these are auto drafts.
If the duplicates are showing up for the TP in the subdirectory, it is probably because I didn't rebase since @noahtallen's fix for that in #25030 😁 . |
5d4e0eb
to
21c803b
Compare
Just rebased so that should be fixed here as well. |
Beat me to the punch! I was about to rebase as well. Thanks, I'll test the PR again 🙂 |
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 rebase does it! 🎉 The code looks good to me as well.
Description
Currently, template part auto-drafting is only done for template parts directly in the block-template-parts directory of a theme. This change updates this to handle template parts included in subdirectories of block-template-parts.
How has this been tested?
In your themes block-template-parts folder, create a new template part .html file in a sub-directory. Load the editor, and verify the auto draft for this new template part is found in the template part placeholder's selection/preview popover.
Screenshots
Types of changes
Checklist: