Make WordPress Core


Ignore:
Timestamp:
06/04/2024 01:46:03 AM (3 months ago)
Author:
isabel_brison
Message:

Editor: fix duotone filter for aligned images on classic themes.

Adds a filter to move the duotone classname to the outer wrapper on aligned images.

Props scruffian, isabel_brison, ajlende.
Fixes #61271.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-duotone.php

    r58123 r58313  
    11561156
    11571157    /**
     1158     * Fixes the issue with our generated class name not being added to the block's outer container
     1159     * in classic themes due to gutenberg_restore_image_outer_container from layout block supports.
     1160     *
     1161     * @since 6.6.0
     1162     *
     1163     * @param  string $block_content Rendered block content.
     1164     * @return string                Filtered block content.
     1165     */
     1166    public static function restore_image_outer_container( $block_content ) {
     1167        if ( wp_theme_has_theme_json() ) {
     1168            return $block_content;
     1169        }
     1170
     1171        $tags          = new WP_HTML_Tag_Processor( $block_content );
     1172        $wrapper_query = array(
     1173            'tag_name'   => 'div',
     1174            'class_name' => 'wp-block-image',
     1175        );
     1176        if ( ! $tags->next_tag( $wrapper_query ) ) {
     1177            return $block_content;
     1178        }
     1179
     1180        $tags->set_bookmark( 'wrapper-div' );
     1181        $tags->next_tag();
     1182
     1183        $inner_classnames = explode( ' ', $tags->get_attribute( 'class' ) );
     1184        foreach ( $inner_classnames as $classname ) {
     1185            if ( 0 === strpos( $classname, 'wp-duotone' ) ) {
     1186                $tags->remove_class( $classname );
     1187                $tags->seek( 'wrapper-div' );
     1188                $tags->add_class( $classname );
     1189                break;
     1190            }
     1191        }
     1192
     1193        return $tags->get_updated_html();
     1194    }
     1195
     1196    /**
    11581197     * Appends the used block duotone filter declarations to the inline block supports CSS.
    11591198     *
Note: See TracChangeset for help on using the changeset viewer.