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. Built from https://develop.svn.wordpress.org/trunk@59080 git-svn-id: http://core.svn.wordpress.org/trunk@58476 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3bb03c7654
commit
71a4092291
|
@ -189,20 +189,6 @@ final class WP_Block_Bindings_Registry {
|
||||||
|
|
||||||
$this->sources[ $source_name ] = $source;
|
$this->sources[ $source_name ] = $source;
|
||||||
|
|
||||||
// Adds `uses_context` defined by block bindings sources.
|
|
||||||
add_filter(
|
|
||||||
'get_block_type_uses_context',
|
|
||||||
function ( $uses_context, $block_type ) use ( $source ) {
|
|
||||||
if ( ! in_array( $block_type->name, $this->supported_blocks, true ) || empty( $source->uses_context ) ) {
|
|
||||||
return $uses_context;
|
|
||||||
}
|
|
||||||
// Use array_values to reset the array keys.
|
|
||||||
return array_values( array_unique( array_merge( $uses_context, $source->uses_context ) ) );
|
|
||||||
},
|
|
||||||
10,
|
|
||||||
2
|
|
||||||
);
|
|
||||||
|
|
||||||
return $source;
|
return $source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -301,6 +301,15 @@ class WP_Block {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adds the necessary context defined by the source.
|
||||||
|
if ( ! empty( $block_binding_source->uses_context ) ) {
|
||||||
|
foreach ( $block_binding_source->uses_context as $context_name ) {
|
||||||
|
if ( array_key_exists( $context_name, $this->available_context ) ) {
|
||||||
|
$this->context[ $context_name ] = $this->available_context[ $context_name ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$source_args = ! empty( $block_binding['args'] ) && is_array( $block_binding['args'] ) ? $block_binding['args'] : array();
|
$source_args = ! empty( $block_binding['args'] ) && is_array( $block_binding['args'] ) ? $block_binding['args'] : array();
|
||||||
$source_value = $block_binding_source->get_value( $source_args, $this, $attribute_name );
|
$source_value = $block_binding_source->get_value( $source_args, $this, $attribute_name );
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.7-alpha-59079';
|
$wp_version = '6.7-alpha-59080';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue