@@ -98,6 +98,22 @@ class WP_Block {
98
98
*/
99
99
public $ inner_content = array ();
100
100
101
+ /**
102
+ * List of supported block attributes for block bindings.
103
+ *
104
+ * @since 6.9.0
105
+ * @var array
106
+ *
107
+ * @see WP_Block::process_block_bindings()
108
+ */
109
+ private const BLOCK_BINDINGS_SUPPORTED_ATTRIBUTES = array (
110
+ 'core/paragraph ' => array ( 'content ' ),
111
+ 'core/heading ' => array ( 'content ' ),
112
+ 'core/image ' => array ( 'id ' , 'url ' , 'title ' , 'alt ' ),
113
+ 'core/button ' => array ( 'url ' , 'text ' , 'linkTarget ' , 'rel ' ),
114
+ 'core/post-date ' => array ( 'datetime ' ),
115
+ );
116
+
101
117
/**
102
118
* Constructor.
103
119
*
@@ -278,20 +294,33 @@ public function __get( $name ) {
278
294
* @return array The computed block attributes for the provided block bindings.
279
295
*/
280
296
private function process_block_bindings () {
297
+ $ block_type = $ this ->name ;
281
298
$ parsed_block = $ this ->parsed_block ;
282
299
$ computed_attributes = array ();
283
- $ supported_block_attributes = array (
284
- 'core/paragraph ' => array ( 'content ' ),
285
- 'core/heading ' => array ( 'content ' ),
286
- 'core/image ' => array ( 'id ' , 'url ' , 'title ' , 'alt ' ),
287
- 'core/button ' => array ( 'url ' , 'text ' , 'linkTarget ' , 'rel ' ),
288
- 'core/post-date ' => array ( 'datetime ' ),
300
+
301
+ $ supported_block_attributes =
302
+ self ::BLOCK_BINDINGS_SUPPORTED_ATTRIBUTES [ $ block_type ] ??
303
+ array ();
304
+
305
+ /**
306
+ * Filters the supported block attributes for block bindings.
307
+ *
308
+ * The dynamic portion of the hook name, `$block_type`, refers to the block type
309
+ * whose attributes are being filtered.
310
+ *
311
+ * @since 6.9.0
312
+ *
313
+ * @param string[] $supported_block_attributes The block's attributes that are supported by block bindings.
314
+ */
315
+ $ supported_block_attributes = apply_filters (
316
+ "block_bindings_supported_attributes_ {$ block_type }" ,
317
+ $ supported_block_attributes
289
318
);
290
319
291
320
// If the block doesn't have the bindings property, isn't one of the supported
292
321
// block types, or the bindings property is not an array, return the block content.
293
322
if (
294
- ! isset ( $ supported_block_attributes[ $ this -> name ] ) ||
323
+ empty ( $ supported_block_attributes ) ||
295
324
empty ( $ parsed_block ['attrs ' ]['metadata ' ]['bindings ' ] ) ||
296
325
! is_array ( $ parsed_block ['attrs ' ]['metadata ' ]['bindings ' ] )
297
326
) {
@@ -315,7 +344,7 @@ private function process_block_bindings() {
315
344
* Note that this also omits the `__default` attribute from the
316
345
* resulting array.
317
346
*/
318
- foreach ( $ supported_block_attributes[ $ parsed_block [ ' blockName ' ] ] as $ attribute_name ) {
347
+ foreach ( $ supported_block_attributes as $ attribute_name ) {
319
348
// Retain any non-pattern override bindings that might be present.
320
349
$ updated_bindings [ $ attribute_name ] = isset ( $ bindings [ $ attribute_name ] )
321
350
? $ bindings [ $ attribute_name ]
@@ -334,7 +363,7 @@ private function process_block_bindings() {
334
363
335
364
foreach ( $ bindings as $ attribute_name => $ block_binding ) {
336
365
// If the attribute is not in the supported list, process next attribute.
337
- if ( ! in_array ( $ attribute_name , $ supported_block_attributes[ $ this -> name ] , true ) ) {
366
+ if ( ! in_array ( $ attribute_name , $ supported_block_attributes , true ) ) {
338
367
continue ;
339
368
}
340
369
// If no source is provided, or that source is not registered, process next attribute.
0 commit comments