block_bindings_supported_attributesfilter-hookWP 6.9.0

Allows you to change or extend the list of block attributes that support Block Bindings.

The hook applies to any block.

It is useful when controlling which block attributes can be populated dynamically, for example, from post meta-fields, a custom data source, or another Block Bindings source.

Usage

add_filter( 'block_bindings_supported_attributes', 'wp_kama_block_bindings_supported_attributes_filter', 10, 2 );

/**
 * Function for `block_bindings_supported_attributes` filter-hook.
 * 
 * @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.
 *
 * @return string[]
 */
function wp_kama_block_bindings_supported_attributes_filter( $supported_block_attributes, $block_type ){

	// filter...
	return $supported_block_attributes;
}
$supported_block_attributes(string[])
An array of block attributes that support Block Bindings.
$block_type(string)

The name of the block whose attribute list is being filtered.

For example: core/paragraph, core/image, my-plugin/card.

Examples

#1 Add support for an attribute of a custom block

In the example, the subtitle attribute is added to the list of attributes that can be bound to a data source.

add_filter( 'block_bindings_supported_attributes', 'my_card_binding_attributes', 10, 2 );

function my_card_binding_attributes( $attributes, $block_name ) {
	if (
		'my-plugin/card' !== $block_name
		&& ! in_array( 'subtitle', $attributes, true )
	) {
		$attributes[] = 'subtitle';
	}

	return $attributes;
}

#2 Remove title support from the image block

In the example, the title attribute is removed from the supported attributes of the core/image block.

add_filter( 'block_bindings_supported_attributes', 'my_remove_image_binding_attributes', 10, 2 );

function my_remove_image_binding_attributes( $attributes, $block_name ) {
	if ( 'core/image' !== $block_name ) {
		return $attributes;
	}

	return array_values(
		array_diff( $attributes, [ 'title' ] )
	);
}

Changelog

Since 6.9.0 Introduced.

Where the hook is called

get_block_bindings_supported_attributes()
block_bindings_supported_attributes
wp-includes/block-bindings.php 167-171
$supported_block_attributes = apply_filters(
	'block_bindings_supported_attributes',
	$supported_block_attributes,
	$block_type
);

Where the hook is used in WordPress

Usage not found.