set_bookmark( 'here' );
$opener = $this->bookmarks['here'];
// Allow comments within the definition of “empty.”
while ( $this->next_token() && '#comment' === $this->get_token_name() ) {
continue;
}
if ( 'FIGCAPTION' !== $this->get_tag() || ! $this->is_tag_closer() ) {
return false;
}
$this->set_bookmark( 'here' );
$closer = $this->bookmarks['here'];
return new WP_HTML_Span( $opener->start, $closer->start + $closer->length - $opener->start );
}
};
if ( ! $processor->next_tag( 'img' ) || ! $processor->get_attribute( 'src' ) ) {
return '';
}
$has_id_binding = isset( $attributes['metadata']['bindings']['id'] ) && isset( $attributes['id'] );
// Ensure the `wp-image-id` classname on the image block supports block bindings.
if ( $has_id_binding ) {
// If there's a mismatch with the 'wp-image-' class and the actual id, the id was
// probably overridden by block bindings. Update it to the correct value.
// See https://github.com/WordPress/gutenberg/issues/62886 for why this is needed.
$id = $attributes['id'];
$image_classnames = $processor->get_attribute( 'class' );
$class_with_binding_value = "wp-image-$id";
if ( is_string( $image_classnames ) && ! str_contains( $image_classnames, $class_with_binding_value ) ) {
$image_classnames = preg_replace( '/wp-image-(\d+)/', $class_with_binding_value, $image_classnames );
$processor->set_attribute( 'class', $image_classnames );
}
}
// For backwards compatibility, the data-id html attribute is only set for
// image blocks nested in a gallery. Detect if the image is in a gallery by
// checking the data-id attribute.
// See the `block_core_gallery_data_id_backcompatibility` function.
if ( isset( $attributes['data-id'] ) ) {
// If there's a binding for the `id`, the `id` attribute is used for the
// value, since `data-id` does not support block bindings.
// Else the `data-id` is used for backwards compatibility, since
// third parties may be filtering its value.
$data_id = $has_id_binding ? $attributes['id'] : $attributes['data-id'];
$processor->set_attribute( 'data-id', $data_id );
}
/*
* If the `caption` attribute is empty and we encounter a `