Make WordPress Core

Opened 3 months ago

Closed 3 months ago

Last modified 3 weeks ago

#59338 closed enhancement (fixed)

Themes: Inject theme attribute during block serialization

Reported by: bernhard-reiter's profile Bernhard Reiter Owned by: bernhard-reiter's profile Bernhard Reiter
Milestone: 6.4 Priority: normal
Severity: normal Version:
Component: Themes Keywords:
Focuses: Cc:

Description

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 [56557]) 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 #59313).

Change History (4)

#1 @Bernhard Reiter
3 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 56578:

Themes: Inject theme attribute during serialization.

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 called _inject_theme_attribute_in_template_part_block, and use that as second argument to serialize_blocks() (introduced in [56557]) 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.

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 [56562].

Props @gziolo.
Fixes #59338. See #59313.

#2 @Bernhard Reiter
3 months ago

In 56579:

Themes: Fix @covers PHPDoc line for test.

Follow-up to [56578].
Props @mukesh27.
See #59338.

#3 @gziolo
3 months ago

In 56584:

Tests: Split tests for _inject_theme_attribute_in_template_part_block

Follow-up to [56578].
See #59338.

#4 @flixos90
3 months ago

@gziolo @bernhard-reiter Just to double check whether that is correct, looking at https://github.com/WordPress/wordpress-develop/pull/5192#issuecomment-1719000338, it appears this change (plus the underlying function from #59327) is a quite notable performance improvement?

Curious whether that was an intended goal here, and I wonder if you have more context where the benefit could come from? Potentially the removed call to _flatten_blocks() is responsible for that? That function at least seems somewhat expensive to me.

Note: See TracTickets for help on using tickets.