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. Built from https://develop.svn.wordpress.org/trunk@58313 git-svn-id: http://core.svn.wordpress.org/trunk@57770 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
357904a871
commit
d546ce74ab
|
@ -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).
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue