From 71a4092291774e2633fdc9fceb179d6fa353a645 Mon Sep 17 00:00:00 2001 From: gziolo Date: Mon, 23 Sep 2024 12:35:15 +0000 Subject: [PATCH] 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 --- wp-includes/class-wp-block-bindings-registry.php | 14 -------------- wp-includes/class-wp-block.php | 9 +++++++++ wp-includes/version.php | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/wp-includes/class-wp-block-bindings-registry.php b/wp-includes/class-wp-block-bindings-registry.php index 14c1b89229..dc065356c5 100644 --- a/wp-includes/class-wp-block-bindings-registry.php +++ b/wp-includes/class-wp-block-bindings-registry.php @@ -189,20 +189,6 @@ final class WP_Block_Bindings_Registry { $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; } diff --git a/wp-includes/class-wp-block.php b/wp-includes/class-wp-block.php index f7fd53dfc9..d4481a68a7 100644 --- a/wp-includes/class-wp-block.php +++ b/wp-includes/class-wp-block.php @@ -301,6 +301,15 @@ class WP_Block { 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_value = $block_binding_source->get_value( $source_args, $this, $attribute_name ); diff --git a/wp-includes/version.php b/wp-includes/version.php index f5926906b4..c971a64761 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @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.