Skip to content

Commit 53d116d

Browse files
committed
Block Bindings: Communicate supported block attributes from server.
Instead of requiring the client side to keep a separate list of block attributes that are supported by Block Bindings, communicate that list from the server -- including block attributes that were added there via the `block_bindings_supported_attributes` filter. Props bernhard-reiter, mukesh27, gziolo. Fixes #64030. git-svn-id: https://develop.svn.wordpress.org/trunk@60807 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2446d39 commit 53d116d

File tree

3 files changed

+62
-48
lines changed

3 files changed

+62
-48
lines changed

src/wp-includes/block-bindings.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,56 @@ function get_all_registered_block_bindings_sources() {
129129
function get_block_bindings_source( string $source_name ) {
130130
return WP_Block_Bindings_Registry::get_instance()->get_registered( $source_name );
131131
}
132+
133+
/**
134+
* Retrieves the list of block attributes supported by block bindings.
135+
*
136+
* @since 6.9.0
137+
*
138+
* @param string $block_type The block type whose supported attributes are being retrieved.
139+
* @return array The list of block attributes that are supported by block bindings.
140+
*/
141+
function get_block_bindings_supported_attributes( $block_type ) {
142+
$block_bindings_supported_attributes = array(
143+
'core/paragraph' => array( 'content' ),
144+
'core/heading' => array( 'content' ),
145+
'core/image' => array( 'id', 'url', 'title', 'alt', 'caption' ),
146+
'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ),
147+
'core/post-date' => array( 'datetime' ),
148+
);
149+
150+
$supported_block_attributes =
151+
$block_bindings_supported_attributes[ $block_type ] ??
152+
array();
153+
154+
/**
155+
* Filters the supported block attributes for block bindings.
156+
*
157+
* @since 6.9.0
158+
*
159+
* @param string[] $supported_block_attributes The block's attributes that are supported by block bindings.
160+
* @param string $block_type The block type whose attributes are being filtered.
161+
*/
162+
$supported_block_attributes = apply_filters(
163+
'block_bindings_supported_attributes',
164+
$supported_block_attributes,
165+
$block_type
166+
);
167+
168+
/**
169+
* Filters the supported block attributes for block bindings.
170+
*
171+
* The dynamic portion of the hook name, `$block_type`, refers to the block type
172+
* whose attributes are being filtered.
173+
*
174+
* @since 6.9.0
175+
*
176+
* @param string[] $supported_block_attributes The block's attributes that are supported by block bindings.
177+
*/
178+
$supported_block_attributes = apply_filters(
179+
"block_bindings_supported_attributes_{$block_type}",
180+
$supported_block_attributes
181+
);
182+
183+
return $supported_block_attributes;
184+
}

src/wp-includes/block-editor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,14 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex
496496
$custom_settings
497497
);
498498

499+
$editor_settings['__experimentalBlockBindingsSupportedAttributes'] = array();
500+
foreach ( array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ) as $block_type ) {
501+
$supported_block_attributes = get_block_bindings_supported_attributes( $block_type );
502+
if ( ! empty( $supported_block_attributes ) ) {
503+
$editor_settings['__experimentalBlockBindingsSupportedAttributes'][ $block_type ] = $supported_block_attributes;
504+
}
505+
}
506+
499507
$global_styles = array();
500508
$presets = array(
501509
array(

src/wp-includes/class-wp-block.php

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,6 @@ class WP_Block {
9898
*/
9999
public $inner_content = array();
100100

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', 'caption' ),
113-
'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ),
114-
'core/post-date' => array( 'datetime' ),
115-
);
116-
117101
/**
118102
* Constructor.
119103
*
@@ -297,38 +281,7 @@ private function process_block_bindings() {
297281
$block_type = $this->name;
298282
$parsed_block = $this->parsed_block;
299283
$computed_attributes = array();
300-
$supported_block_attributes =
301-
self::BLOCK_BINDINGS_SUPPORTED_ATTRIBUTES[ $block_type ] ??
302-
array();
303-
304-
/**
305-
* Filters the supported block attributes for block bindings.
306-
*
307-
* @since 6.9.0
308-
*
309-
* @param string[] $supported_block_attributes The block's attributes that are supported by block bindings.
310-
* @param string $block_type The block type whose attributes are being filtered.
311-
*/
312-
$supported_block_attributes = apply_filters(
313-
'block_bindings_supported_attributes',
314-
$supported_block_attributes,
315-
$block_type
316-
);
317-
318-
/**
319-
* Filters the supported block attributes for block bindings.
320-
*
321-
* The dynamic portion of the hook name, `$block_type`, refers to the block type
322-
* whose attributes are being filtered.
323-
*
324-
* @since 6.9.0
325-
*
326-
* @param string[] $supported_block_attributes The block's attributes that are supported by block bindings.
327-
*/
328-
$supported_block_attributes = apply_filters(
329-
"block_bindings_supported_attributes_{$block_type}",
330-
$supported_block_attributes
331-
);
284+
$supported_block_attributes = get_block_bindings_supported_attributes( $block_type );
332285

333286
// If the block doesn't have the bindings property, isn't one of the supported
334287
// block types, or the bindings property is not an array, return the block content.

0 commit comments

Comments
 (0)