Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/wp-includes/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,56 @@ 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
*
* @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.
*/
function get_block_bindings_supported_attributes( $block_type ) {
$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
);

return $supported_block_attributes;
}
8 changes: 8 additions & 0 deletions src/wp-includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,14 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex
$custom_settings
);

$editor_settings['__experimentalBlockBindingsSupportedAttributes'] = array();
foreach ( array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ) as $block_type ) {
Comment thread
gziolo marked this conversation as resolved.
$supported_block_attributes = get_block_bindings_supported_attributes( $block_type );
if ( ! empty( $supported_block_attributes ) ) {
$editor_settings['__experimentalBlockBindingsSupportedAttributes'][ $block_type ] = $supported_block_attributes;
}
}

$global_styles = array();
$presets = array(
array(
Expand Down
49 changes: 1 addition & 48 deletions src/wp-includes/class-wp-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 );
Comment thread
ockham marked this conversation as resolved.

// 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.
Expand Down
Loading