diff options
Diffstat (limited to 'wp-includes/class-wp-duotone.php')
-rw-r--r-- | wp-includes/class-wp-duotone.php | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/wp-includes/class-wp-duotone.php b/wp-includes/class-wp-duotone.php index 40e9f75..a22745d 100644 --- a/wp-includes/class-wp-duotone.php +++ b/wp-includes/class-wp-duotone.php @@ -215,7 +215,7 @@ class WP_Duotone { } /** - * Parses any valid Hex3, Hex4, Hex6 or Hex8 string and converts it to an RGBA object + * Parses any valid Hex3, Hex4, Hex6 or Hex8 string and converts it to an RGBA object. * * Direct port of colord's parseHex function. * @@ -286,7 +286,7 @@ class WP_Duotone { } /** - * Parses a valid RGB[A] CSS color function/string + * Parses a valid RGB[A] CSS color function/string. * * Direct port of colord's parseRgbaString function. * @@ -809,12 +809,13 @@ class WP_Duotone { * @internal * * @since 6.3.0 + * @since 6.6.0 Replaced body selector with `WP_Theme_JSON::ROOT_CSS_PROPERTIES_SELECTOR`. * * @param array $sources The duotone presets. * @return string The CSS for global styles. */ private static function get_global_styles_presets( $sources ) { - $css = 'body{'; + $css = WP_Theme_JSON::ROOT_CSS_PROPERTIES_SELECTOR . '{'; foreach ( $sources as $filter_id => $filter_data ) { $slug = $filter_data['slug']; $colors = $filter_data['colors']; @@ -1154,6 +1155,45 @@ class WP_Duotone { } /** + * 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. * * Uses the declarations saved in earlier calls to self::enqueue_block_css. |