Skip to content
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

Template Part Block: Use get_block_file_template for rendering #52892

Merged
merged 1 commit into from
Jul 25, 2023

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Jul 24, 2023

What?

Change the Template Part block's render method (render_block_core_template_part) to use get_block_file_template rather than a number of lower-level functions.

Why?

Higher-level functions such as get_block_file_template apply filters (such as the eponymous get_block_file_template) that otherwise aren't invoked. (This is relevant e.g. for #51449.)

Furthermore, it can be argued that if a high-level function is available to what otherwise requires calling a number of lower-level functions, it's preferable to use the high-level function (unless there are side effects and/or performance issues, of course) 😄

How?

By using get_block_file_template (which returns a WP_Block_Template object) in the code branch that loads a block template from a theme file, thus supplanting calls to the lower-level _get_block_template_file and _inject_theme_attribute_in_block_template_content functions.

Note that get_block_file_template invokes both of them in its function body. (_inject_theme_attribute_in_block_template_content is called via _build_block_template_result_from_file).

Testing Instructions

Verify that Template Parts still work as before:

  • On the frontend, with an unmodified block theme;
  • In the editor -- loading, modifying, and saving;
  • On the frontend, with modifications to the template part.

@ockham ockham self-assigned this Jul 24, 2023
@ockham ockham added the [Block] Template Part Affects the Template Parts Block label Jul 24, 2023
@ockham ockham marked this pull request as ready for review July 24, 2023 14:22
@ockham ockham requested a review from ajitbohra as a code owner July 24, 2023 14:22
@ockham ockham requested a review from ramonjd July 24, 2023 14:24
@ockham ockham changed the title Template Part Block: Use get_block_file_template for rendering Template Part Block: Use get_block_file_template for rendering Jul 24, 2023
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

Thanks @ockham!

@ramonjd ramonjd added [Status] In Progress Tracking issues with work in progress and removed [Status] In Progress Tracking issues with work in progress labels Jul 24, 2023
@spacedmonkey
Copy link
Member

The new function doesn't seem to
Support parent themes. Did you test with a parent theme?

@ramonjd ramonjd added the [Type] Code Quality Issues or PRs that relate to code quality label Jul 24, 2023
@ockham
Copy link
Contributor Author

ockham commented Jul 25, 2023

The new function doesn't seem to Support parent themes. Did you test with a parent theme?

I just did, and it seemed to work fine in my testing. (I made a quick child theme of TT3 locally and verified that it picked up the parent's template parts; I then added a modified header.html template part to the child and verified that it overrode the parent's.)

I don't quite see why get_block_file_template wouldn't support child themes 🤔 -- after all, it's using _get_block_template_file to locate the file, just like we used to do directly in the block's render method. But please LMK if I'm missing something!

@ockham
Copy link
Contributor Author

ockham commented Jul 25, 2023

Since this PR has approval and parent themes seem to be working fine for me, I'll go ahead and merge (in order to unblock #51449).

Happy to tweak or revert in case we find that it's breaking something after all!

@johnbillion
Copy link
Member

This introduced a regression: #56013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants