Make WordPress Core


Ignore:
Timestamp:
09/27/2024 09:18:46 AM (20 months ago)
Author:
Bernhard Reiter
Message:

Block Hooks: apply_block_hooks_to_content in Patterns, Templates.

In the Patterns registry, use apply_block_hooks_to_content (introduced in [58291]) instead of the WP_Block_Patterns_Registry class's private get_content method. (The latter is removed as part of this changeset.)

In a similar vein, use apply_block_hooks_to_content in the _build_block_template_result_from_file and _build_block_template_result_from_post functions, respectively.

For that to work, apply_block_hooks_to_content is amended to inject the theme attribute into Template Part blocks, even if no hooked blocks are present.

This kind of centralization is required as a preparation for #61902.

Props bernhard-reiter, jonsurrell.
See #61902.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r59081 r59101  
    10361036 *
    10371037 * @since 6.6.0
     1038 * @since 6.7.0 Injects the `theme` attribute into Template Part blocks, even if no hooked blocks are registered.
    10381039 * @access private
    10391040 *
     
    10481049function apply_block_hooks_to_content( $content, $context, $callback = 'insert_hooked_blocks' ) {
    10491050    $hooked_blocks = get_hooked_blocks();
    1050     if ( empty( $hooked_blocks ) && ! has_filter( 'hooked_block_types' ) ) {
    1051         return $content;
     1051
     1052    $before_block_visitor = '_inject_theme_attribute_in_template_part_block';
     1053    $after_block_visitor  = null;
     1054    if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
     1055        $before_block_visitor = make_before_block_visitor( $hooked_blocks, $context, $callback );
     1056        $after_block_visitor  = make_after_block_visitor( $hooked_blocks, $context, $callback );
    10521057    }
    10531058
    10541059    $blocks = parse_blocks( $content );
    1055 
    1056     $before_block_visitor = make_before_block_visitor( $hooked_blocks, $context, $callback );
    1057     $after_block_visitor  = make_after_block_visitor( $hooked_blocks, $context, $callback );
    10581060
    10591061    return traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
Note: See TracChangeset for help on using the changeset viewer.