diff --git a/wp-includes/block-supports/duotone.php b/wp-includes/block-supports/duotone.php index a90eb762ba..df328c317d 100644 --- a/wp-includes/block-supports/duotone.php +++ b/wp-includes/block-supports/duotone.php @@ -42,6 +42,7 @@ WP_Block_Supports::get_instance()->register( // Add classnames to blocks using duotone support. add_filter( 'render_block', array( 'WP_Duotone', 'render_duotone_support' ), 10, 3 ); +add_filter( 'render_block_core/image', array( 'WP_Duotone', 'restore_image_outer_container' ), 10, 1 ); // Enqueue styles. // Block styles (core-block-supports-inline-css) before the style engine (wp_enqueue_stored_styles). diff --git a/wp-includes/class-wp-duotone.php b/wp-includes/class-wp-duotone.php index e8b7735457..77afdce970 100644 --- a/wp-includes/class-wp-duotone.php +++ b/wp-includes/class-wp-duotone.php @@ -1154,6 +1154,45 @@ class WP_Duotone { return $tags->get_updated_html(); } + /** + * Fixes the issue with our generated class name not being added to the block's outer container + * in classic themes due to gutenberg_restore_image_outer_container from layout block supports. + * + * @since 6.6.0 + * + * @param string $block_content Rendered block content. + * @return string Filtered block content. + */ + public static function restore_image_outer_container( $block_content ) { + if ( wp_theme_has_theme_json() ) { + return $block_content; + } + + $tags = new WP_HTML_Tag_Processor( $block_content ); + $wrapper_query = array( + 'tag_name' => 'div', + 'class_name' => 'wp-block-image', + ); + if ( ! $tags->next_tag( $wrapper_query ) ) { + return $block_content; + } + + $tags->set_bookmark( 'wrapper-div' ); + $tags->next_tag(); + + $inner_classnames = explode( ' ', $tags->get_attribute( 'class' ) ); + foreach ( $inner_classnames as $classname ) { + if ( 0 === strpos( $classname, 'wp-duotone' ) ) { + $tags->remove_class( $classname ); + $tags->seek( 'wrapper-div' ); + $tags->add_class( $classname ); + break; + } + } + + return $tags->get_updated_html(); + } + /** * Appends the used block duotone filter declarations to the inline block supports CSS. * diff --git a/wp-includes/version.php b/wp-includes/version.php index f31c73bc1c..be12ad8058 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-alpha-58312'; +$wp_version = '6.6-alpha-58313'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-settings.php b/wp-settings.php index b9d417e422..a682c2a503 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -367,21 +367,21 @@ require ABSPATH . WPINC . '/block-patterns.php'; require ABSPATH . WPINC . '/class-wp-block-supports.php'; require ABSPATH . WPINC . '/block-supports/utils.php'; require ABSPATH . WPINC . '/block-supports/align.php'; -require ABSPATH . WPINC . '/block-supports/background.php'; -require ABSPATH . WPINC . '/block-supports/block-style-variations.php'; -require ABSPATH . WPINC . '/block-supports/border.php'; -require ABSPATH . WPINC . '/block-supports/colors.php'; require ABSPATH . WPINC . '/block-supports/custom-classname.php'; -require ABSPATH . WPINC . '/block-supports/dimensions.php'; -require ABSPATH . WPINC . '/block-supports/duotone.php'; -require ABSPATH . WPINC . '/block-supports/shadow.php'; -require ABSPATH . WPINC . '/block-supports/elements.php'; require ABSPATH . WPINC . '/block-supports/generated-classname.php'; +require ABSPATH . WPINC . '/block-supports/settings.php'; +require ABSPATH . WPINC . '/block-supports/elements.php'; +require ABSPATH . WPINC . '/block-supports/colors.php'; +require ABSPATH . WPINC . '/block-supports/typography.php'; +require ABSPATH . WPINC . '/block-supports/border.php'; require ABSPATH . WPINC . '/block-supports/layout.php'; require ABSPATH . WPINC . '/block-supports/position.php'; require ABSPATH . WPINC . '/block-supports/spacing.php'; -require ABSPATH . WPINC . '/block-supports/typography.php'; -require ABSPATH . WPINC . '/block-supports/settings.php'; +require ABSPATH . WPINC . '/block-supports/dimensions.php'; +require ABSPATH . WPINC . '/block-supports/duotone.php'; +require ABSPATH . WPINC . '/block-supports/shadow.php'; +require ABSPATH . WPINC . '/block-supports/background.php'; +require ABSPATH . WPINC . '/block-supports/block-style-variations.php'; require ABSPATH . WPINC . '/style-engine.php'; require ABSPATH . WPINC . '/style-engine/class-wp-style-engine.php'; require ABSPATH . WPINC . '/style-engine/class-wp-style-engine-css-declarations.php';