Changeset 61009 for trunk/src/wp-includes/blocks/block.php
- Timestamp:
- 10/21/2025 07:11:53 AM (3 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/blocks/block.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/block.php
r59906 r61009 1 <?php 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName // Needed for WP_Block_Cloner helper class. 2 2 /** 3 3 * Server-side rendering of the `core/block` block. … … 17 17 * @return string Rendered HTML of the referenced block. 18 18 */ 19 function render_block_core_block( $attributes ) {19 function render_block_core_block( $attributes, $content, $block_instance ) { 20 20 static $seen_refs = array(); 21 21 … … 74 74 } 75 75 76 /**77 * We set the `pattern/overrides` context through the `render_block_context`78 * filter so that it is available when a pattern's inner blocks are79 * rendering via do_blocks given it only receives the inner content.80 */81 $has_pattern_overrides = isset( $attributes['content'] ) && null !== get_block_bindings_source( 'core/pattern-overrides' );82 if ( $has_pattern_overrides ) {83 $filter_block_context = static function ( $context ) use ( $attributes ) {84 $context['pattern/overrides'] = $attributes['content'];85 return $context;86 };87 add_filter( 'render_block_context', $filter_block_context, 1 );88 }89 90 76 // Apply Block Hooks. 91 77 $content = apply_block_hooks_to_content_from_post_object( $content, $reusable_block ); 92 78 93 $content = do_blocks( $content ); 79 /** 80 * We attach the blocks from $content as inner blocks to the Synced Pattern block instance. 81 * This ensures that block context available to the Synced Pattern block instance is provided to 82 * those blocks. 83 */ 84 $block_instance->parsed_block['innerBlocks'] = parse_blocks( $content ); 85 $block_instance->parsed_block['innerContent'] = array_fill( 0, count( $block_instance->parsed_block['innerBlocks'] ), null ); 86 if ( method_exists( $block_instance, 'refresh_context_dependents' ) ) { 87 // WP_Block::refresh_context_dependents() was introduced in WordPress 6.8. 88 $block_instance->refresh_context_dependents(); 89 } else { 90 // This branch can be removed once Gutenberg requires WordPress 6.8 or later. 91 if ( ! class_exists( 'WP_Block_Cloner' ) ) { 92 // phpcs:ignore Gutenberg.Commenting.SinceTag.MissingClassSinceTag 93 class WP_Block_Cloner extends WP_Block { 94 /** 95 * Static methods of subclasses have access to protected properties 96 * of instances of the parent class. 97 * In this case, this gives us access to `available_context` and `registry`. 98 */ 99 // phpcs:ignore Gutenberg.Commenting.SinceTag.MissingMethodSinceTag 100 public static function clone_instance( $instance ) { 101 return new WP_Block( 102 $instance->parsed_block, 103 $instance->available_context, 104 $instance->registry 105 ); 106 } 107 } 108 } 109 $block_instance = WP_Block_Cloner::clone_instance( $block_instance ); 110 } 111 112 $content = $block_instance->render( array( 'dynamic' => false ) ); 94 113 unset( $seen_refs[ $attributes['ref'] ] ); 95 96 if ( $has_pattern_overrides ) {97 remove_filter( 'render_block_context', $filter_block_context, 1 );98 }99 114 100 115 return $content;
Note: See TracChangeset
for help on using the changeset viewer.