Repository navigation
Fix Template Part auto-drafting to support sub-directories. - #25063
Conversation
|
Size Change: 0 B Total Size: 1.2 MB ℹ️ View Unchanged
|
noahtallen
left a comment
There was a problem hiding this comment.
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?
| $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.
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.
Yeah, that makes sense. As in b86514f?
This runs on the |
aristath
left a comment
There was a problem hiding this comment.
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.
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 🙂 |
jeyip
left a comment
There was a problem hiding this comment.
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: