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

Inject theme attribute during serialization #5192

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Sep 12, 2023

Rather than using _inject_theme_attribute_in_block_template_content to inject the theme attribute into all Template Part blocks found in a given file-based Block Template, introduce a new function tentatively called _inject_theme_attribute_in_template_part_block, and use that as second argument to serialize_blocks() (introduced in #5187) in order to inject said attribute during tree traversal for serialization.

This allows for a more modular approach that will eventually be extended to implement automatic insertion of hooked blocks (see).

Note that we're guarding _build_block_template_result_from_file() (i.e. the callsite of _inject_theme_attribute_in_template_part_block and previously of _inject_theme_attribute_in_block_template_content) against regressions through additional unit test coverage added in #5186.

Trac ticket: https://core.trac.wordpress.org/ticket/59338


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@ockham ockham force-pushed the update/inject-theme-attr-during-serialization branch from 7c952fc to 5a92288 Compare September 13, 2023 12:06
@ockham ockham marked this pull request as ready for review September 13, 2023 14:18
@ockham ockham requested a review from gziolo September 13, 2023 14:18
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Everything works as expected. The refactoring looks like discussed in the linked WordPress trac ticket.

The only thing I’d like to rise is the code practices around unit tests. WordPress core has this guiding principle to put every individual test scenario in a seperate test function to ensure that failing assertion doesn't prevent further code from running. I currently see 3 different test case that even start with a code comment explaining what's being tested. The nice part is that all use cases I can think of are covered.

@gziolo
Copy link
Member

gziolo commented Sep 14, 2023

For visibility, this is the performance impact from this PR included on CI https://github.com/WordPress/wordpress-develop/actions/runs/6173429870/job/16778816255?pr=5192:

Screenshot 2023-09-14 at 10 28 36

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Let's tackle splitting the test case in a follow-up. I volunteer for doing it.

@ockham
Copy link
Contributor Author

ockham commented Sep 14, 2023

Thank you very much!

@ockham
Copy link
Contributor Author

ockham commented Sep 14, 2023

Committted to Core in https://core.trac.wordpress.org/changeset/56578.

@ockham ockham closed this Sep 14, 2023
@ockham ockham deleted the update/inject-theme-attr-during-serialization branch September 14, 2023 08:51
@gziolo
Copy link
Member

gziolo commented Sep 14, 2023

Let's tackle splitting the test case in a follow-up. I volunteer for doing it.

Tests splitted with https://core.trac.wordpress.org/changeset/56584.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants