@@ -24,6 +24,21 @@ function ( $attributes, $block_type ) {
2424 2
2525);
2626
27+ // The following filter can be removed once the minimum required WordPress version is 6.9 or newer.
28+ add_filter (
29+ 'block_editor_settings_all ' ,
30+ function ( $ editor_settings ) {
31+ $ editor_settings ['__experimentalBlockBindingsSupportedAttributes ' ] = array ();
32+ foreach ( array_keys ( WP_Block_Type_Registry::get_instance ()->get_all_registered () ) as $ block_type ) {
33+ $ supported_block_attributes = gutenberg_get_block_bindings_supported_attributes ( $ block_type );
34+ if ( ! empty ( $ supported_block_attributes ) ) {
35+ $ editor_settings ['__experimentalBlockBindingsSupportedAttributes ' ][ $ block_type ] = $ supported_block_attributes ;
36+ }
37+ }
38+ return $ editor_settings ;
39+ }
40+ );
41+
2742/**
2843 * Callback function for the render_block filter.
2944 *
@@ -86,6 +101,59 @@ function gutenberg_block_bindings_render_block( $block_content, $block, $instanc
86101}
87102add_filter ( 'render_block ' , 'gutenberg_block_bindings_render_block ' , 10 , 3 );
88103
104+ /**
105+ * Retrieves the list of block attributes supported by block bindings.
106+ *
107+ * @since 6.9.0
108+ *
109+ * @param string $block_type The block type whose supported attributes are being retrieved.
110+ * @return array The list of block attributes that are supported by block bindings.
111+ */
112+ function gutenberg_get_block_bindings_supported_attributes ( $ block_type ) {
113+ // List of block attributes supported by Block Bindings in WP 6.8.
114+ $ block_bindings_supported_attributes_6_8 = array (
115+ 'core/paragraph ' => array ( 'content ' ),
116+ 'core/heading ' => array ( 'content ' ),
117+ 'core/image ' => array ( 'id ' , 'url ' , 'title ' , 'alt ' ),
118+ 'core/button ' => array ( 'url ' , 'text ' , 'linkTarget ' , 'rel ' ),
119+ );
120+
121+ $ supported_block_attributes =
122+ $ block_bindings_supported_attributes_6_8 [ $ block_type ] ??
123+ array ();
124+
125+ /**
126+ * Filters the supported block attributes for block bindings.
127+ *
128+ * @since 6.9.0
129+ *
130+ * @param string[] $supported_block_attributes The block's attributes that are supported by block bindings.
131+ * @param string $block_type The block type whose attributes are being filtered.
132+ */
133+ $ supported_block_attributes = apply_filters (
134+ 'block_bindings_supported_attributes ' ,
135+ $ supported_block_attributes ,
136+ $ block_type
137+ );
138+
139+ /**
140+ * Filters the supported block attributes for block bindings.
141+ *
142+ * The dynamic portion of the hook name, `$block_type`, refers to the block type
143+ * whose attributes are being filtered.
144+ *
145+ * @since 6.9.0
146+ *
147+ * @param string[] $supported_block_attributes The block's attributes that are supported by block bindings.
148+ */
149+ $ supported_block_attributes = apply_filters (
150+ "block_bindings_supported_attributes_ {$ block_type }" ,
151+ $ supported_block_attributes
152+ );
153+
154+ return $ supported_block_attributes ;
155+ }
156+
89157/**
90158 * Processes the block bindings and updates the block attributes with the values from the sources.
91159 *
@@ -138,38 +206,8 @@ function gutenberg_process_block_bindings( $instance ) {
138206 'core/image ' => array ( 'id ' , 'url ' , 'title ' , 'alt ' ),
139207 'core/button ' => array ( 'url ' , 'text ' , 'linkTarget ' , 'rel ' ),
140208 );
141- $ supported_block_attributes =
142- $ block_bindings_supported_attributes_6_8 [ $ block_type ] ??
143- array ();
144-
145- /**
146- * Filters the supported block attributes for block bindings.
147- *
148- * @since 6.9.0
149- *
150- * @param string[] $supported_block_attributes The block's attributes that are supported by block bindings.
151- * @param string $block_type The block type whose attributes are being filtered.
152- */
153- $ supported_block_attributes = apply_filters (
154- 'block_bindings_supported_attributes ' ,
155- $ supported_block_attributes ,
156- $ block_type
157- );
158209
159- /**
160- * Filters the supported block attributes for block bindings.
161- *
162- * The dynamic portion of the hook name, `$block_type`, refers to the block type
163- * whose attributes are being filtered.
164- *
165- * @since 6.9.0
166- *
167- * @param string[] $supported_block_attributes The block's attributes that are supported by block bindings.
168- */
169- $ supported_block_attributes = apply_filters (
170- "block_bindings_supported_attributes_ {$ block_type }" ,
171- $ supported_block_attributes
172- );
210+ $ supported_block_attributes = gutenberg_get_block_bindings_supported_attributes ( $ block_type );
173211
174212 /*
175213 * Remove attributes that we know are processed by WP 6.8 from the list,
0 commit comments