Make WordPress Core

Changeset 56991


Ignore:
Timestamp:
10/23/2023 11:37:55 PM (15 months ago)
Author:
hellofromTonya
Message:

Editor: Fix render_duotone_support() to be compatible with enhanced pagination.

Some blocks do not have content. For duotone support, blocks without content still need to run through the render_duotone_support() to render their duotone CSS.

This fix makes the duotone compatible with the enhanced pagination (introduced in 6.4.0) by making sure that the CSS is always on the page, even when the posts have no featured image. It also prevents the duotone from interfering with other blocks using wp_unique_id().

References:

Follow-up to [56226].

Props cbravobernal, luisherranz, hellofromTonya, isabel_brison, jorbin.
Fixes #59694.

Location:
trunk
Files:
2 edited

Legend:

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

    r56709 r56991  
    10751075     */
    10761076    public static function render_duotone_support( $block_content, $block, $wp_block ) {
    1077         if ( empty( $block_content ) || ! $block['blockName'] ) {
     1077        if ( ! $block['blockName'] ) {
    10781078            return $block_content;
    10791079        }
  • trunk/tests/phpunit/tests/block-supports/duotone.php

    r56981 r56991  
    104104
    105105    /**
     106     * Tests whether the CSS declarations are generated even if the block content is
     107     * empty. This is needed to make the CSS output stable across paginations for
     108     * features like the enhanced pagination of the Query block.
     109     *
     110     * @ticket 59694
     111     *
     112     * @covers ::render_duotone_support
     113     */
     114    public function test_css_declarations_are_generated_even_with_empty_block_content() {
     115        $block                           = array(
     116            'blockName' => 'core/image',
     117            'attrs'     => array( 'style' => array( 'color' => array( 'duotone' => 'var:preset|duotone|blue-orange' ) ) ),
     118        );
     119        $wp_block                        = new WP_Block( $block );
     120        $block_css_declarations_property = new ReflectionProperty( 'WP_Duotone', 'block_css_declarations' );
     121        $block_css_declarations_property->setAccessible( true );
     122        $block_css_declarations_property->setValue( $wp_block, array() );
     123
     124        WP_Duotone::render_duotone_support( '', $block, $wp_block );
     125        $actual = $block_css_declarations_property->getValue();
     126        // Reset the property's visibility.
     127        $block_css_declarations_property->setAccessible( false );
     128
     129        $this->assertNotEmpty( $actual );
     130    }
     131
     132    /**
    106133     * @dataProvider data_is_preset
    107134     */
Note: See TracChangeset for help on using the changeset viewer.