Make WordPress Core


Ignore:
Timestamp:
09/23/2024 12:33:14 PM (2 years ago)
Author:
gziolo
Message:

Block Bindings: Adds context needed by sources during its processing

Extends block context during block bindings processing. This implies that the context is extended ONLY for the blocks where bindings are defined and only when rendered on the page.

Props santosguillamot, gziolo, artemiosans, cbravobernal.
Fixes #61642.

File:
1 edited

Legend:

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

    r58395 r59080  
    190190                $this->sources[ $source_name ] = $source;
    191191
    192                 // Adds `uses_context` defined by block bindings sources.
    193                 add_filter(
    194                         'get_block_type_uses_context',
    195                         function ( $uses_context, $block_type ) use ( $source ) {
    196                                 if ( ! in_array( $block_type->name, $this->supported_blocks, true ) || empty( $source->uses_context ) ) {
    197                                         return $uses_context;
    198                                 }
    199                                 // Use array_values to reset the array keys.
    200                                 return array_values( array_unique( array_merge( $uses_context, $source->uses_context ) ) );
    201                         },
    202                         10,
    203                         2
    204                 );
    205 
    206192                return $source;
    207193        }
Note: See TracChangeset for help on using the changeset viewer.