From 77184c15165a82223985a8a62022078534604306 Mon Sep 17 00:00:00 2001 From: audrasjb Date: Thu, 13 Jun 2024 08:57:15 +0000 Subject: [PATCH] HTML API: Revert using regex in block bindings HTML replacement logic. This changeset reverts part of the changes made in [58298] to avoid using regex that can cause potential bugs. It is indeed safer to revert these changes for now and do the refactoring once the HTML API supports CSS selectors and provides a way to set inner content. It also adds a unit test to cover the regression experienced in https://github.com/WordPress/gutenberg/issues/62347. Follow-up to [58298]. Props santosguillamot, gziolo. Fixes #61385. See #61351. Built from https://develop.svn.wordpress.org/trunk@58398 git-svn-id: http://core.svn.wordpress.org/trunk@57847 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-block.php | 77 ++++++++++++++++++++++++++-------- wp-includes/version.php | 2 +- 2 files changed, 60 insertions(+), 19 deletions(-) diff --git a/wp-includes/class-wp-block.php b/wp-includes/class-wp-block.php index be73c13070..c6ca8a3bd4 100644 --- a/wp-includes/class-wp-block.php +++ b/wp-includes/class-wp-block.php @@ -333,27 +333,68 @@ class WP_Block { switch ( $block_type->attributes[ $attribute_name ]['source'] ) { case 'html': case 'rich-text': - // Hardcode the selectors and processing until the HTML API is able to read CSS selectors and replace inner HTML. - // TODO: Use the HTML API instead. - if ( 'core/paragraph' === $this->name && 'content' === $attribute_name ) { - $selector = 'p'; - } - if ( 'core/heading' === $this->name && 'content' === $attribute_name ) { - $selector = 'h[1-6]'; - } - if ( 'core/button' === $this->name && 'text' === $attribute_name ) { - // Check if it is a