Skip to content

Commit

Permalink
Support all attributes in bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed Jun 11, 2024
1 parent 8f8c7eb commit f822e21
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/wp-includes/class-wp-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private function process_block_bindings() {
$supported_block_attributes = array(
'core/paragraph' => array( 'content' ),
'core/heading' => array( 'content' ),
'core/image' => array( 'id', 'url', 'title', 'alt' ),
'core/image' => array( 'id', 'url', 'title', 'alt', 'caption', 'href', 'rel', 'linkClass', 'linkTarget' ),
'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ),
);

Expand Down Expand Up @@ -389,6 +389,16 @@ private function replace_html( string $block_content, string $attribute_name, $s
}
return $amended_button->get_updated_html();
}
if ( 'core/image' === $this->name && 'caption' === $attribute_name ) {
// TODO: Don't use regex.
return preg_replace_callback(
'/<figcaption[^>]*>.*?<\/figcaption>/is',
function () use ( $amended_content ) {
return $amended_content->get_updated_html();
},
$block_content
);
}
} else {
$block_reader->seek( 'iterate-selectors' );
}
Expand All @@ -398,10 +408,15 @@ private function replace_html( string $block_content, string $attribute_name, $s

case 'attribute':
$amended_content = new WP_HTML_Tag_Processor( $block_content );
$selector = $block_type->attributes[ $attribute_name ]['selector'];
// TODO: build the query from CSS selector when the HTML API supports it.
if ( 'figure > a' === $selector ) {
$selector = 'a';
}
if ( ! $amended_content->next_tag(
array(
// TODO: build the query from CSS selector.
'tag_name' => $block_type->attributes[ $attribute_name ]['selector'],
'tag_name' => $selector,
)
) ) {
return $block_content;
Expand Down

0 comments on commit f822e21

Please sign in to comment.