Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Block Bindings Processor: Base implementation on WP_HTML_Text_Replace…
…ment to fix broken test
  • Loading branch information
ockham committed Aug 20, 2025
commit 1a61046ed49aef907df42af6ebf06d30e745932a
19 changes: 11 additions & 8 deletions src/wp-includes/class-wp-block-bindings-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
* @since 6.9.0
*/
class WP_Block_Bindings_Processor extends WP_HTML_Processor {
private $output = '';
private $end_of_flushed = 0;

public function build() {
return $this->output . substr( $this->get_updated_html(), $this->end_of_flushed );
return $this->get_updated_html();
}

/**
Expand All @@ -51,20 +49,25 @@ public function replace_rich_text( $rich_text ) {

$this->set_bookmark( '_wp_block_bindings_tag_opener' );
// The bookmark names are prefixed with `_` so the key below has an extra `_`.
$bm = $this->bookmarks['__wp_block_bindings_tag_opener'];
$this->output .= substr( $this->get_updated_html(), $this->end_of_flushed, $bm->start + $bm->length );
$this->output .= $rich_text;
$bm = $this->bookmarks['__wp_block_bindings_tag_opener'];
$start = $bm->start + $bm->length;
$this->release_bookmark( '_wp_block_bindings_tag_opener' );

// Find matching tag closer.
while ( $this->next_token() && $this->get_current_depth() >= $depth ) {
}

$this->set_bookmark( '_wp_block_bindings_tag_closer' );
$bm = $this->bookmarks['__wp_block_bindings_tag_closer'];
$this->end_of_flushed = $bm->start;
$bm = $this->bookmarks['__wp_block_bindings_tag_closer'];
$end = $bm->start;
$this->release_bookmark( '_wp_block_bindings_tag_closer' );

$this->lexical_updates[] = new WP_HTML_Text_Replacement(
$start,
$end - $start,
$rich_text
);

return true;
}
}