Changeset 59101 for trunk/src/wp-includes/block-template-utils.php
- Timestamp:
- 09/27/2024 09:18:46 AM (20 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/block-template-utils.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template-utils.php
r59073 r59101 616 616 } 617 617 618 $hooked_blocks = get_hooked_blocks(); 619 $has_hooked_blocks = ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ); 620 $before_block_visitor = '_inject_theme_attribute_in_template_part_block'; 621 $after_block_visitor = null; 622 623 if ( $has_hooked_blocks ) { 624 $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' ); 625 $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' ); 626 } 627 628 if ( 'wp_template_part' === $template->type && $has_hooked_blocks ) { 618 if ( 'wp_template_part' === $template->type ) { 629 619 /* 630 620 * In order for hooked blocks to be inserted at positions first_child and last_child in a template part, … … 636 626 $template->content 637 627 ); 638 $content = traverse_and_serialize_blocks( parse_blocks( $content ), $before_block_visitor, $after_block_visitor ); 628 $content = apply_block_hooks_to_content( 629 $content, 630 $template, 631 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' 632 ); 639 633 $template->content = remove_serialized_parent_block( $content ); 640 634 } else { 641 $template->content = traverse_and_serialize_blocks(642 parse_blocks( $template->content ),643 $ before_block_visitor,644 $after_block_visitor635 $template->content = apply_block_hooks_to_content( 636 $template->content, 637 $template, 638 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' 645 639 ); 646 640 } … … 1037 1031 } 1038 1032 1039 $hooked_blocks = get_hooked_blocks(); 1040 if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { 1041 $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' ); 1042 $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' ); 1043 if ( 'wp_template_part' === $template->type ) { 1044 $existing_ignored_hooked_blocks = get_post_meta( $post->ID, '_wp_ignored_hooked_blocks', true ); 1045 $attributes = ! empty( $existing_ignored_hooked_blocks ) ? array( 'metadata' => array( 'ignoredHookedBlocks' => json_decode( $existing_ignored_hooked_blocks, true ) ) ) : array(); 1046 1047 /* 1048 * In order for hooked blocks to be inserted at positions first_child and last_child in a template part, 1049 * we need to wrap its content a mock template part block and traverse it. 1050 */ 1051 $content = get_comment_delimited_block_content( 1052 'core/template-part', 1053 $attributes, 1054 $template->content 1055 ); 1056 $content = traverse_and_serialize_blocks( parse_blocks( $content ), $before_block_visitor, $after_block_visitor ); 1057 $template->content = remove_serialized_parent_block( $content ); 1058 } else { 1059 $template->content = traverse_and_serialize_blocks( 1060 parse_blocks( $template->content ), 1061 $before_block_visitor, 1062 $after_block_visitor 1063 ); 1064 } 1033 if ( 'wp_template_part' === $template->type ) { 1034 $existing_ignored_hooked_blocks = get_post_meta( $post->ID, '_wp_ignored_hooked_blocks', true ); 1035 $attributes = ! empty( $existing_ignored_hooked_blocks ) ? array( 'metadata' => array( 'ignoredHookedBlocks' => json_decode( $existing_ignored_hooked_blocks, true ) ) ) : array(); 1036 1037 /* 1038 * In order for hooked blocks to be inserted at positions first_child and last_child in a template part, 1039 * we need to wrap its content a mock template part block and traverse it. 1040 */ 1041 $content = get_comment_delimited_block_content( 1042 'core/template-part', 1043 $attributes, 1044 $template->content 1045 ); 1046 $content = apply_block_hooks_to_content( 1047 $content, 1048 $template, 1049 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' 1050 ); 1051 $template->content = remove_serialized_parent_block( $content ); 1052 } else { 1053 $template->content = apply_block_hooks_to_content( 1054 $template->content, 1055 $template, 1056 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' 1057 ); 1065 1058 } 1066 1059
Note: See TracChangeset
for help on using the changeset viewer.