Make WordPress Core


Ignore:
Timestamp:
10/10/2023 01:19:42 PM (14 months ago)
Author:
Bernhard Reiter
Message:

Patterns: Inject theme attribute into Template Part blocks.

[56805] introduced a regression: The theme attribute was no longer injected into Template Part blocks inside of patterns. This caused errors on the frontend, where instead of a given template part, an error message such as Template part has been deleted or is unavailable: header was seen.

This changeset rectifies that problem, and adds unit test coverage to guard against future regressions.

Follow-up to [56805].
Props scruffian, gziolo.
Fixes #59583.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-patterns-registry.php

    r56805 r56818  
    165165    private function prepare_content( $pattern, $hooked_blocks ) {
    166166        $content = $pattern['content'];
     167
     168        $before_block_visitor = '_inject_theme_attribute_in_template_part_block';
     169        $after_block_visitor  = null;
    167170        if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
    168             $blocks               = parse_blocks( $content );
    169171            $before_block_visitor = make_before_block_visitor( $hooked_blocks, $pattern );
    170172            $after_block_visitor  = make_after_block_visitor( $hooked_blocks, $pattern );
    171             $content              = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
    172         }
     173        }
     174        $blocks  = parse_blocks( $content );
     175        $content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
    173176
    174177        return $content;
Note: See TracChangeset for help on using the changeset viewer.