Make WordPress Core


Ignore:
Timestamp:
02/12/2024 01:13:38 PM (12 months ago)
Author:
Bernhard Reiter
Message:

Block Hooks: Inject hooked blocks into modified templates and parts.

Using the new technique introduced in [57157] of using a metadata.ignoredHookedBlocks attribute in the anchor block to store information about whether or not a hooked block should be considered for injection, extend said injection to encompass modified templates and parts.

Fixes #59646.
Props gziolo, matveb.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-template-utils.php

    r57349 r57594  
    902902    }
    903903
     904    $hooked_blocks = get_hooked_blocks();
     905    if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
     906        $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template );
     907        $after_block_visitor  = make_after_block_visitor( $hooked_blocks, $template );
     908        $blocks               = parse_blocks( $template->content );
     909        $template->content    = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
     910    }
     911
    904912    return $template;
    905913}
Note: See TracChangeset for help on using the changeset viewer.