Skip to content

Commit

Permalink
Generate duotone styles even with empty block content
Browse files Browse the repository at this point in the history
  • Loading branch information
cbravobernal committed Oct 23, 2023
1 parent 482843a commit d264e88
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-duotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ private static function get_all_global_style_block_names() {
* @return string Filtered block content.
*/
public static function render_duotone_support( $block_content, $block, $wp_block ) {
if ( empty( $block_content ) || ! $block['blockName'] ) {
if ( ! $block['blockName'] ) {
return $block_content;
}
$duotone_selector = self::get_selector( $wp_block->block_type );
Expand Down
23 changes: 23 additions & 0 deletions tests/phpunit/tests/block-supports/duotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@ public function test_get_slug_from_attribute( $data_attr, $expected ) {
$this->assertSame( $expected, $reflection->invoke( null, $data_attr ) );
}

/**
* Tests whether the CSS declarations are generated even if the block content is
* empty. We need this to make the CSS output stable across paginations for
* features like the enhanced pagination of the Query block.
*
* @ticket 59694
*
* @covers ::render_duotone_support
*/
public function test_css_declarations_are_generated_even_with_empty_block_content() {
$block = array(
'blockName' => 'core/image',
'attrs' => array( 'style' => array( 'color' => array( 'duotone' => 'var:preset|duotone|blue-orange' ) ) ),
);
$wp_block = new WP_Block( $block );
$block_css_declarations_property = new ReflectionProperty( 'WP_Duotone', 'block_css_declarations' );
$block_css_declarations_property->setAccessible( true );
$block_css_declarations_property->setValue( array() );
WP_Duotone::render_duotone_support( '', $block, $wp_block );
$this->assertNotEmpty( $block_css_declarations_property->getValue() );
}


/**
* Data provider.
*
Expand Down

0 comments on commit d264e88

Please sign in to comment.