Make WordPress Core


Ignore:
Timestamp:
02/16/2024 12:53:16 PM (2 years ago)
Author:
gziolo
Message:

Editor: Merge uses_context defined by block bindings sources with block types

Adds logic that fixes the limitation for souces by allowing merging the uses_context defined by block bindings sources into supported block types. Each source defines the context it needs and it is added to the block types that are using the block bindings API.

Fixes #60525.
Props santosguillamot, gziolo, czapla, thekt12.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block.php

    r57576 r57641  
    232232     */
    233233    private function process_block_bindings() {
    234         $parsed_block = $this->parsed_block;
    235 
    236         $computed_attributes = array();
    237 
    238         // Allowed blocks that support block bindings.
    239         // TODO: Look for a mechanism to opt-in for this. Maybe adding a property to block attributes?
    240         $allowed_blocks = array(
     234        $parsed_block               = $this->parsed_block;
     235        $computed_attributes        = array();
     236        $supported_block_attributes = array(
    241237            'core/paragraph' => array( 'content' ),
    242238            'core/heading'   => array( 'content' ),
     
    245241        );
    246242
    247         // If the block doesn't have the bindings property, isn't one of the allowed
     243        // If the block doesn't have the bindings property, isn't one of the supported
    248244        // block types, or the bindings property is not an array, return the block content.
    249245        if (
    250             ! isset( $allowed_blocks[ $this->name ] ) ||
     246            ! isset( $supported_block_attributes[ $this->name ] ) ||
    251247            empty( $parsed_block['attrs']['metadata']['bindings'] ) ||
    252248            ! is_array( $parsed_block['attrs']['metadata']['bindings'] )
     
    256252
    257253        foreach ( $parsed_block['attrs']['metadata']['bindings'] as $attribute_name => $block_binding ) {
    258             // If the attribute is not in the allowed list, process next attribute.
    259             if ( ! in_array( $attribute_name, $allowed_blocks[ $this->name ], true ) ) {
     254            // If the attribute is not in the supported list, process next attribute.
     255            if ( ! in_array( $attribute_name, $supported_block_attributes[ $this->name ], true ) ) {
    260256                continue;
    261257            }
Note: See TracChangeset for help on using the changeset viewer.