Changeset 59101
- Timestamp:
- 09/27/2024 09:18:46 AM (less than one hour ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
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 -
trunk/src/wp-includes/blocks.php
r59081 r59101 1036 1036 * 1037 1037 * @since 6.6.0 1038 * @since 6.7.0 Injects the `theme` attribute into Template Part blocks, even if no hooked blocks are registered. 1038 1039 * @access private 1039 1040 * … … 1048 1049 function apply_block_hooks_to_content( $content, $context, $callback = 'insert_hooked_blocks' ) { 1049 1050 $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 ); 1052 1057 } 1053 1058 1054 1059 $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 );1058 1060 1059 1061 return traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); -
trunk/src/wp-includes/class-wp-block-patterns-registry.php
r58186 r59101 160 160 161 161 /** 162 * Prepares the content of a block pattern. If hooked blocks are registered, they get injected into the pattern,163 * when they met the defined criteria.164 *165 * @since 6.4.0166 *167 * @param array $pattern Registered pattern properties.168 * @param array $hooked_blocks The list of hooked blocks.169 * @return string The content of the block pattern.170 */171 private function prepare_content( $pattern, $hooked_blocks ) {172 $content = $pattern['content'];173 174 $before_block_visitor = '_inject_theme_attribute_in_template_part_block';175 $after_block_visitor = null;176 if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {177 $before_block_visitor = make_before_block_visitor( $hooked_blocks, $pattern, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );178 $after_block_visitor = make_after_block_visitor( $hooked_blocks, $pattern, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );179 }180 $blocks = parse_blocks( $content );181 $content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );182 183 return $content;184 }185 186 /**187 162 * Retrieves the content of a registered block pattern. 188 163 * … … 222 197 223 198 $pattern = $this->registered_patterns[ $pattern_name ]; 224 $pattern['content'] = $this->get_content( $pattern_name ); 225 $pattern['content'] = $this->prepare_content( $pattern, get_hooked_blocks() ); 199 $content = $this->get_content( $pattern_name ); 200 $pattern['content'] = apply_block_hooks_to_content( 201 $content, 202 $pattern, 203 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' 204 ); 226 205 227 206 return $pattern; … … 244 223 245 224 foreach ( $patterns as $index => $pattern ) { 246 $pattern['content'] = $this->get_content( $pattern['name'], $outside_init_only ); 247 $patterns[ $index ]['content'] = $this->prepare_content( $pattern, $hooked_blocks ); 225 $content = $this->get_content( $pattern['name'], $outside_init_only ); 226 $patterns[ $index ]['content'] = apply_block_hooks_to_content( 227 $content, 228 $pattern, 229 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' 230 ); 248 231 } 249 232
Note: See TracChangeset
for help on using the changeset viewer.