Skip to content

Commit 6d62dc4

Browse files
committed
Editor: Use HTML API class_list() for duotone wrapper classes.
Update `WP_Duotone::restore_image_outer_container()` to iterate `WP_HTML_Tag_Processor::class_list()` instead of splitting the `class` attribute on spaces, matching Gutenberg PR 79531. Developed in WordPress#12324. Follow-up to [58313]. Props jonsurrell, mukesh27, scruffian. Fixes #65576. git-svn-id: https://develop.svn.wordpress.org/trunk@62627 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2161d9b commit 6d62dc4

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/wp-includes/class-wp-duotone.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,8 +1191,7 @@ public static function restore_image_outer_container( $block_content ) {
11911191
$tags->set_bookmark( 'wrapper-div' );
11921192
$tags->next_tag();
11931193

1194-
$inner_classnames = explode( ' ', $tags->get_attribute( 'class' ) );
1195-
foreach ( $inner_classnames as $classname ) {
1194+
foreach ( $tags->class_list() as $classname ) {
11961195
if ( str_starts_with( $classname, 'wp-duotone' ) ) {
11971196
$tags->remove_class( $classname );
11981197
$tags->seek( 'wrapper-div' );

tests/phpunit/tests/block-supports/duotone.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ public function test_render_duotone_support_custom() {
6161
$this->assertMatchesRegularExpression( $expected, WP_Duotone::render_duotone_support( $block_content, $block, $wp_block ) );
6262
}
6363

64+
/**
65+
* @ticket 65576
66+
*
67+
* @covers ::restore_image_outer_container
68+
*/
69+
public function test_restore_image_outer_container_moves_duotone_class_to_wrapper_in_classic_theme() {
70+
switch_theme( 'default' );
71+
72+
$block_content = '<div class="wp-block-image"><figure class="alignright wp-duotone-blue-orange size-full"><img src="/my-image.jpg"></figure></div>';
73+
$expected = '<div class="wp-block-image wp-duotone-blue-orange"><figure class="alignright size-full"><img src="/my-image.jpg"></figure></div>';
74+
75+
$this->assertEqualHTML( $expected, WP_Duotone::restore_image_outer_container( $block_content ) );
76+
}
77+
6478
/**
6579
* Tests whether the slug is extracted from the attribute.
6680
*

0 commit comments

Comments
 (0)