Changeset 57574 for trunk/src/wp-includes/class-wp-block.php
- Timestamp:
- 02/09/2024 10:38:38 AM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-block.php
r57565 r57574 193 193 194 194 /** 195 * Processes the block bindings in block's attributes.195 * Processes the block bindings and updates the block attributes with the values from the sources. 196 196 * 197 197 * A block might contain bindings in its attributes. Bindings are mappings … … 200 200 * retrieve a value from outside the block, e.g. from post meta. 201 201 * 202 * This function will process those bindings and replace the HTML with the value of the binding.203 * The value is retrieved from the source of the binding.202 * This function will process those bindings and update the block's attributes 203 * with the values coming from the bindings. 204 204 * 205 205 * ### Example … … 229 229 * @since 6.5.0 230 230 * 231 * @param string $block_content Block content. 232 * @param array $block The full block, including name and attributes. 233 * @return string The modified block content. 234 */ 235 private function process_block_bindings( $block_content ) { 231 * @return array The computed block attributes for the provided block bindings. 232 */ 233 private function process_block_bindings() { 236 234 $parsed_block = $this->parsed_block; 235 236 $computed_attributes = array(); 237 237 238 238 // Allowed blocks that support block bindings. … … 252 252 ! is_array( $parsed_block['attrs']['metadata']['bindings'] ) 253 253 ) { 254 return $block_content; 255 } 256 257 $modified_block_content = $block_content; 254 return $computed_attributes; 255 } 256 258 257 foreach ( $parsed_block['attrs']['metadata']['bindings'] as $attribute_name => $block_binding ) { 259 258 // If the attribute is not in the allowed list, process next attribute. … … 276 275 // If the value is not null, process the HTML based on the block and the attribute. 277 276 if ( ! is_null( $source_value ) ) { 278 $ modified_block_content = $this->replace_html( $modified_block_content, $attribute_name, $source_value );279 } 280 } 281 282 return $ modified_block_content;277 $computed_attributes[ $attribute_name ] = $source_value; 278 } 279 } 280 281 return $computed_attributes; 283 282 } 284 283 … … 392 391 * 393 392 * @since 5.5.0 393 * @since 6.5.0 Added block bindings processing. 394 394 * 395 395 * @global WP_Post $post Global post object. … … 411 411 ); 412 412 413 // Process the block bindings and get attributes updated with the values from the sources. 414 $computed_attributes = $this->process_block_bindings(); 415 if ( ! empty( $computed_attributes ) ) { 416 // Merge the computed attributes with the original attributes 417 $this->attributes = array_merge( $this->attributes, $computed_attributes ); 418 } 419 413 420 $is_dynamic = $options['dynamic'] && $this->name && null !== $this->block_type && $this->block_type->is_dynamic(); 414 421 $block_content = ''; … … 446 453 } 447 454 455 if ( ! empty( $computed_attributes ) && ! empty( $block_content ) ) { 456 foreach ( $computed_attributes as $attribute_name => $source_value ) { 457 $block_content = $this->replace_html( $block_content, $attribute_name, $source_value ); 458 } 459 } 460 448 461 if ( $is_dynamic ) { 449 462 $global_post = $post; … … 488 501 } 489 502 } 490 491 // Process the block bindings for this block, if any are registered. This492 // will replace the block content with the value from a registered binding source.493 $block_content = $this->process_block_bindings( $block_content );494 503 495 504 /**
Note: See TracChangeset
for help on using the changeset viewer.