-
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
Add auto-drafting for theme supplied template parts. #23254
Conversation
Size Change: +593 B (0%) Total Size: 1.12 MB
ℹ️ View Unchanged
|
lib/template-parts.php
Outdated
$template_part_files = array_merge( $template_part_files, $child_template_part_files ); | ||
} | ||
foreach ( $template_part_files as $template_part ) { | ||
create_auto_draft_for_template_part_block( $template_part ); |
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 function takes a block, not a 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.
Ahh yeah. And it looks like the template part files only contain the inner content. That is, the template files contain the template part definitions that have the slug/theme name, but the template part files do not contain that information inside themselves.
So im getting the content from the template part file, and wrapping it with a template-part block string and parsing it into a block. Im filling in that missing info by assuming the slug attribute will always correspond to the file name and the theme attr will always correspond to the currently applied theme in this case. I think thats fair?
Does this approach make more sense? (pushed these changes noted above)
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.
After stepping away and thinking about it more, would it make more sense to do the query and create post here? As opposed to building a string to parse it into a block to give to a function that is going to go back to the stylesheet directory again anyways?
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.
It'd be nice to extract the logic for creating the post so that it can be referenced in both places.
This works! I updated the template part placeholder query to use this, so that can be used to help test. But for testing, I created a new template part in my current theme's directory that has a slug not used in any of the templates. It shows up in the placeholder previews! 🎉 I do wonder if #23254 (comment) might be a better approach though? 🤔 |
Description
A follow up to #22760 - to prevent the potential issue of losing access to theme supplied template parts as discussed in #22760 (comment)
How has this been tested?
Local docker environment using twentynineteen-blocks theme.
Using the site editor experiment and a block based theme, add a new template part .html file to the themes /block-template-parts/ directory. (you can copy the contents of one that already exists thre, just give it a new unique file name for the slug). Then run this PR and verify the new template part loads in the template part placeholder's preview list.
Screenshots
Types of changes
Checklist: