WP_Duotone::restore_image_outer_container( string $block_content ): string

In this article

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.

Parameters

$block_contentstringrequired
Rendered block content.

Return

string Filtered block content.

Source

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();
}

Changelog

VersionDescription
6.6.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.