From aa5eab2531d4322f86cbc814deaba2a05c7de4af Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 22 Sep 2025 11:40:24 +0200 Subject: [PATCH 1/8] Block Bindings: Add new get_block_bindings_supported_attributes() fn --- src/wp-includes/block-bindings.php | 50 ++++++++++++++++++++++++++++++ src/wp-includes/class-wp-block.php | 49 +---------------------------- 2 files changed, 51 insertions(+), 48 deletions(-) diff --git a/src/wp-includes/block-bindings.php b/src/wp-includes/block-bindings.php index ff8db5f5dd4e9..31e8098b709b8 100644 --- a/src/wp-includes/block-bindings.php +++ b/src/wp-includes/block-bindings.php @@ -129,3 +129,53 @@ function get_all_registered_block_bindings_sources() { function get_block_bindings_source( string $source_name ) { return WP_Block_Bindings_Registry::get_instance()->get_registered( $source_name ); } + +/** + * Retrieves the list of block attributes supported by block bindings. + * + * @since 6.9.0 + * + * @return array The list of block attributes that are supported by block bindings.gi + */ +function get_block_bindings_supported_attributes() { + $block_bindings_supported_attributes = array( + 'core/paragraph' => array( 'content' ), + 'core/heading' => array( 'content' ), + 'core/image' => array( 'id', 'url', 'title', 'alt', 'caption' ), + 'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ), + 'core/post-date' => array( 'datetime' ), + ); + + $supported_block_attributes = + $block_bindings_supported_attributes[ $block_type ] ?? + array(); + + /** + * Filters the supported block attributes for block bindings. + * + * @since 6.9.0 + * + * @param string[] $supported_block_attributes The block's attributes that are supported by block bindings. + * @param string $block_type The block type whose attributes are being filtered. + */ + $supported_block_attributes = apply_filters( + 'block_bindings_supported_attributes', + $supported_block_attributes, + $block_type + ); + + /** + * Filters the supported block attributes for block bindings. + * + * The dynamic portion of the hook name, `$block_type`, refers to the block type + * whose attributes are being filtered. + * + * @since 6.9.0 + * + * @param string[] $supported_block_attributes The block's attributes that are supported by block bindings. + */ + $supported_block_attributes = apply_filters( + "block_bindings_supported_attributes_{$block_type}", + $supported_block_attributes + ); +} \ No newline at end of file diff --git a/src/wp-includes/class-wp-block.php b/src/wp-includes/class-wp-block.php index e2ebcf35711ad..b498c1189700e 100644 --- a/src/wp-includes/class-wp-block.php +++ b/src/wp-includes/class-wp-block.php @@ -98,22 +98,6 @@ class WP_Block { */ public $inner_content = array(); - /** - * List of supported block attributes for block bindings. - * - * @since 6.9.0 - * @var array - * - * @see WP_Block::process_block_bindings() - */ - private const BLOCK_BINDINGS_SUPPORTED_ATTRIBUTES = array( - 'core/paragraph' => array( 'content' ), - 'core/heading' => array( 'content' ), - 'core/image' => array( 'id', 'url', 'title', 'alt', 'caption' ), - 'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ), - 'core/post-date' => array( 'datetime' ), - ); - /** * Constructor. * @@ -297,38 +281,7 @@ private function process_block_bindings() { $block_type = $this->name; $parsed_block = $this->parsed_block; $computed_attributes = array(); - $supported_block_attributes = - self::BLOCK_BINDINGS_SUPPORTED_ATTRIBUTES[ $block_type ] ?? - array(); - - /** - * Filters the supported block attributes for block bindings. - * - * @since 6.9.0 - * - * @param string[] $supported_block_attributes The block's attributes that are supported by block bindings. - * @param string $block_type The block type whose attributes are being filtered. - */ - $supported_block_attributes = apply_filters( - 'block_bindings_supported_attributes', - $supported_block_attributes, - $block_type - ); - - /** - * Filters the supported block attributes for block bindings. - * - * The dynamic portion of the hook name, `$block_type`, refers to the block type - * whose attributes are being filtered. - * - * @since 6.9.0 - * - * @param string[] $supported_block_attributes The block's attributes that are supported by block bindings. - */ - $supported_block_attributes = apply_filters( - "block_bindings_supported_attributes_{$block_type}", - $supported_block_attributes - ); + $supported_block_attributes = get_block_bindings_supported_attributes( $block_type ); // If the block doesn't have the bindings property, isn't one of the supported // block types, or the bindings property is not an array, return the block content. From cb89c3cb0c73bfd2f0fa9c6994fc04f3137301c4 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 22 Sep 2025 11:43:17 +0200 Subject: [PATCH 2/8] Forgot to add param --- src/wp-includes/block-bindings.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/block-bindings.php b/src/wp-includes/block-bindings.php index 31e8098b709b8..581fdde69dbf2 100644 --- a/src/wp-includes/block-bindings.php +++ b/src/wp-includes/block-bindings.php @@ -135,9 +135,10 @@ function get_block_bindings_source( string $source_name ) { * * @since 6.9.0 * + * @param string $block_type The block type whose supported attributes are being retrieved. * @return array The list of block attributes that are supported by block bindings.gi */ -function get_block_bindings_supported_attributes() { +function get_block_bindings_supported_attributes( $block_type) { $block_bindings_supported_attributes = array( 'core/paragraph' => array( 'content' ), 'core/heading' => array( 'content' ), From 57ae3e01a334acac99e97e743e72c07eff73c48b Mon Sep 17 00:00:00 2001 From: Bernie Reiter <96308+ockham@users.noreply.github.com> Date: Mon, 22 Sep 2025 14:18:09 +0200 Subject: [PATCH 3/8] Add missing whitespace before closing paren Co-authored-by: Mukesh Panchal --- src/wp-includes/block-bindings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/block-bindings.php b/src/wp-includes/block-bindings.php index 581fdde69dbf2..6650247a915ec 100644 --- a/src/wp-includes/block-bindings.php +++ b/src/wp-includes/block-bindings.php @@ -138,7 +138,7 @@ function get_block_bindings_source( string $source_name ) { * @param string $block_type The block type whose supported attributes are being retrieved. * @return array The list of block attributes that are supported by block bindings.gi */ -function get_block_bindings_supported_attributes( $block_type) { +function get_block_bindings_supported_attributes( $block_type ) { $block_bindings_supported_attributes = array( 'core/paragraph' => array( 'content' ), 'core/heading' => array( 'content' ), From 997495f135fd3f01adb1bc62eb3c6bbe7bb4442a Mon Sep 17 00:00:00 2001 From: Bernie Reiter <96308+ockham@users.noreply.github.com> Date: Mon, 22 Sep 2025 14:18:21 +0200 Subject: [PATCH 4/8] Whitespace fix Co-authored-by: Mukesh Panchal --- src/wp-includes/block-bindings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/block-bindings.php b/src/wp-includes/block-bindings.php index 6650247a915ec..94c5fc35e3969 100644 --- a/src/wp-includes/block-bindings.php +++ b/src/wp-includes/block-bindings.php @@ -179,4 +179,4 @@ function get_block_bindings_supported_attributes( $block_type ) { "block_bindings_supported_attributes_{$block_type}", $supported_block_attributes ); -} \ No newline at end of file +} From 784c041713f53c3a3130f989b4d6c27802a3a15c Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 22 Sep 2025 14:38:26 +0200 Subject: [PATCH 5/8] Forgot to add return statement :grimacing: --- src/wp-includes/block-bindings.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wp-includes/block-bindings.php b/src/wp-includes/block-bindings.php index 94c5fc35e3969..2b6b86a83c46b 100644 --- a/src/wp-includes/block-bindings.php +++ b/src/wp-includes/block-bindings.php @@ -179,4 +179,6 @@ function get_block_bindings_supported_attributes( $block_type ) { "block_bindings_supported_attributes_{$block_type}", $supported_block_attributes ); + + return $supported_block_attributes; } From 99ebd43698b157dcc2acafe4b08f0262b1bebfec Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 22 Sep 2025 15:53:29 +0200 Subject: [PATCH 6/8] Typo in PHPDoc --- src/wp-includes/block-bindings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/block-bindings.php b/src/wp-includes/block-bindings.php index 2b6b86a83c46b..0b5cee3dab412 100644 --- a/src/wp-includes/block-bindings.php +++ b/src/wp-includes/block-bindings.php @@ -136,7 +136,7 @@ function get_block_bindings_source( string $source_name ) { * @since 6.9.0 * * @param string $block_type The block type whose supported attributes are being retrieved. - * @return array The list of block attributes that are supported by block bindings.gi + * @return array The list of block attributes that are supported by block bindings. */ function get_block_bindings_supported_attributes( $block_type ) { $block_bindings_supported_attributes = array( From 205df2cd65a9922fe7c04c60bbd65c6a49a5b0d4 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 23 Sep 2025 15:43:18 +0200 Subject: [PATCH 7/8] Expose in editor settings --- src/wp-includes/block-editor.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 3c0ccdaa4b587..2a639f9781087 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -496,6 +496,14 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex $custom_settings ); + $editor_settings['blockBindingsSupportedAttributes'] = array(); + foreach ( array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ) as $block_type ) { + $supported_block_attributes = get_block_bindings_supported_attributes( $block_type ); + if ( ! empty( $supported_block_attributes ) ) { + $editor_settings['blockBindingsSupportedAttributes'][ $block_type ] = $supported_block_attributes; + } + } + $global_styles = array(); $presets = array( array( From af99215ca51b5ef22e959816a188f20829dbd7af Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 24 Sep 2025 13:29:38 +0200 Subject: [PATCH 8/8] Prefix var with __experimental --- src/wp-includes/block-editor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 2a639f9781087..6f5720ec21c9d 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -496,11 +496,11 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex $custom_settings ); - $editor_settings['blockBindingsSupportedAttributes'] = array(); + $editor_settings['__experimentalBlockBindingsSupportedAttributes'] = array(); foreach ( array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ) as $block_type ) { $supported_block_attributes = get_block_bindings_supported_attributes( $block_type ); if ( ! empty( $supported_block_attributes ) ) { - $editor_settings['blockBindingsSupportedAttributes'][ $block_type ] = $supported_block_attributes; + $editor_settings['__experimentalBlockBindingsSupportedAttributes'][ $block_type ] = $supported_block_attributes; } }