WP_Duotone::restore_image_outer_container
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.
Method of the class: WP_Duotone{}
No Hooks.
Returns
String. Filtered block content.
Usage
$result = WP_Duotone::restore_image_outer_container( $block_content );
- $block_content(string) (required)
- Rendered block content.
Changelog
| Since 6.6.0 | Introduced. |
WP_Duotone::restore_image_outer_container() WP Duotone::restore image outer container code WP 6.9.1
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();
}