From 87e05df9fef2c08596cee29748e57e920db97eb0 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 20 Mar 2023 14:06:23 -0500 Subject: [PATCH 1/2] Replace regex with tag processor for duotone class render --- lib/class-wp-duotone-gutenberg.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/class-wp-duotone-gutenberg.php b/lib/class-wp-duotone-gutenberg.php index 3544f580367101..c3cad8c6de06ef 100644 --- a/lib/class-wp-duotone-gutenberg.php +++ b/lib/class-wp-duotone-gutenberg.php @@ -360,11 +360,11 @@ public static function render_duotone_support( $block_content, $block ) { ); // Like the layout hook, this assumes the hook only applies to blocks with a single wrapper. - return preg_replace( - '/' . preg_quote( 'class="', '/' ) . '/', - 'class="' . $filter_id . ' ', - $block_content, - 1 - ); + $tags = new WP_HTML_Tag_Processor( $block_content ); + if ( $tags->next_tag() ) { + $tags->add_class( $filter_id ); + } + + return $tags->get_updated_html(); } } From 9c30a2cc68908ba5cfa10177588465c99997acbe Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 20 Mar 2023 15:58:29 -0500 Subject: [PATCH 2/2] Change the order of classes in duotone tests --- phpunit/class-wp-duotone-test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpunit/class-wp-duotone-test.php b/phpunit/class-wp-duotone-test.php index 21df35847fac50..49ef631e65f022 100644 --- a/phpunit/class-wp-duotone-test.php +++ b/phpunit/class-wp-duotone-test.php @@ -21,7 +21,7 @@ public function test_gutenberg_render_duotone_support_preset() { 'attrs' => array( 'style' => array( 'color' => array( 'duotone' => 'var:preset|duotone|blue-orange' ) ) ), ); $block_content = '
'; - $expected = '
'; + $expected = '
'; $this->assertSame( $expected, WP_Duotone_Gutenberg::render_duotone_support( $block_content, $block ) ); } @@ -31,7 +31,7 @@ public function test_gutenberg_render_duotone_support_css() { 'attrs' => array( 'style' => array( 'color' => array( 'duotone' => 'unset' ) ) ), ); $block_content = '
'; - $expected = '/
<\\/figure>/'; + $expected = '/
<\\/figure>/'; $this->assertMatchesRegularExpression( $expected, WP_Duotone_Gutenberg::render_duotone_support( $block_content, $block ) ); } @@ -41,7 +41,7 @@ public function test_gutenberg_render_duotone_support_custom() { 'attrs' => array( 'style' => array( 'color' => array( 'duotone' => array( '#FFFFFF', '#000000' ) ) ) ), ); $block_content = '
'; - $expected = '/
<\\/figure>/'; + $expected = '/
<\\/figure>/'; $this->assertMatchesRegularExpression( $expected, WP_Duotone_Gutenberg::render_duotone_support( $block_content, $block ) ); }