Changeset 59662 for trunk/src/wp-includes/class-wp-block.php
- Timestamp:
- 01/17/2025 09:35:50 PM (17 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-block.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-block.php
r59361 r59662 57 57 * @access protected 58 58 */ 59 protected $available_context ;59 protected $available_context = array(); 60 60 61 61 /** … … 141 141 $this->available_context = $available_context; 142 142 143 $this->refresh_context_dependents(); 144 } 145 146 /** 147 * Updates the context for the current block and its inner blocks. 148 * 149 * The method updates the context of inner blocks, if any, by passing down 150 * any context values the block provides (`provides_context`). 151 * 152 * If the block has inner blocks, the method recursively processes them by creating new instances of `WP_Block` 153 * for each inner block and updating their context based on the block's `provides_context` property. 154 * 155 * @since 6.8.0 156 */ 157 public function refresh_context_dependents() { 158 /* 159 * Merging the `$context` property here is not ideal, but for now needs to happen because of backward compatibility. 160 * Ideally, the `$context` property itself would not be filterable directly and only the `$available_context` would be filterable. 161 * However, this needs to be separately explored whether it's possible without breakage. 162 */ 163 $this->available_context = array_merge( $this->available_context, $this->context ); 164 143 165 if ( ! empty( $this->block_type->uses_context ) ) { 144 166 foreach ( $this->block_type->uses_context as $context_name ) { … … 149 171 } 150 172 151 if ( ! empty( $block['innerBlocks'] ) ) { 173 $this->refresh_parsed_block_dependents(); 174 } 175 176 /** 177 * Updates the parsed block content for the current block and its inner blocks. 178 * 179 * This method sets the `inner_html` and `inner_content` properties of the block based on the parsed 180 * block content provided during initialization. It ensures that the block instance reflects the 181 * most up-to-date content for both the inner HTML and any string fragments around inner blocks. 182 * 183 * If the block has inner blocks, this method initializes a new `WP_Block_List` for them, ensuring the 184 * correct content and context are updated for each nested block. 185 * 186 * @since 6.8.0 187 */ 188 public function refresh_parsed_block_dependents() { 189 if ( ! empty( $this->parsed_block['innerBlocks'] ) ) { 152 190 $child_context = $this->available_context; 153 191 … … 160 198 } 161 199 162 $this->inner_blocks = new WP_Block_List( $ block['innerBlocks'], $child_context, $registry );163 } 164 165 if ( ! empty( $ block['innerHTML'] ) ) {166 $this->inner_html = $ block['innerHTML'];167 } 168 169 if ( ! empty( $ block['innerContent'] ) ) {170 $this->inner_content = $ block['innerContent'];200 $this->inner_blocks = new WP_Block_List( $this->parsed_block['innerBlocks'], $child_context, $this->registry ); 201 } 202 203 if ( ! empty( $this->parsed_block['innerHTML'] ) ) { 204 $this->inner_html = $this->parsed_block['innerHTML']; 205 } 206 207 if ( ! empty( $this->parsed_block['innerContent'] ) ) { 208 $this->inner_content = $this->parsed_block['innerContent']; 171 209 } 172 210 } … … 507 545 $block_content .= $pre_render; 508 546 } else { 509 $source_block = $inner_block->parsed_block; 547 $source_block = $inner_block->parsed_block; 548 $inner_block_context = $inner_block->context; 510 549 511 550 /** This filter is documented in wp-includes/blocks.php */ … … 514 553 /** This filter is documented in wp-includes/blocks.php */ 515 554 $inner_block->context = apply_filters( 'render_block_context', $inner_block->context, $inner_block->parsed_block, $parent_block ); 555 556 /* 557 * The `refresh_context_dependents()` method already calls `refresh_parsed_block_dependents()`. 558 * Therefore the second condition is irrelevant if the first one is satisfied. 559 */ 560 if ( $inner_block->context !== $inner_block_context ) { 561 $inner_block->refresh_context_dependents(); 562 } elseif ( $inner_block->parsed_block !== $source_block ) { 563 $inner_block->refresh_parsed_block_dependents(); 564 } 516 565 517 566 $block_content .= $inner_block->render();
Note: See TracChangeset
for help on using the changeset viewer.