Make WordPress Core

Changeset 56997 for branches/6.4


Ignore:
Timestamp:
10/24/2023 11:06:59 AM (2 years 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.
Reviewed by costdev.
Merges [56991] and [56996] to the 6.4 branch.
Fixes #59694.

Location:
branches/6.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/6.4

  • branches/6.4/src/wp-includes/class-wp-duotone.php

    r56709 r56997  
    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        }
  • branches/6.4/tests/phpunit/tests/block-supports/duotone.php

    r56226 r56997  
    102102
    103103    /**
     104     * Tests whether the CSS declarations are generated even if the block content is
     105     * empty. This is needed to make the CSS output stable across paginations for
     106     * features like the enhanced pagination of the Query block.
     107     *
     108     * @ticket 59694
     109     *
     110     * @covers ::render_duotone_support
     111     */
     112    public function test_css_declarations_are_generated_even_with_empty_block_content() {
     113        $block    = array(
     114            'blockName' => 'core/image',
     115            'attrs'     => array( 'style' => array( 'color' => array( 'duotone' => 'var:preset|duotone|blue-orange' ) ) ),
     116        );
     117        $wp_block = new WP_Block( $block );
     118
     119        /*
     120         * Handling to access the static WP_Duotone::$block_css_declarations property.
     121         *
     122         * Why is an instance needed?
     123         * WP_Duotone is a static class by design, meaning it only contains static properties and methods.
     124         * In production, it should not be instantiated. However, as of PHP 8.3, ReflectionProperty::setValue()
     125         * needs an object.
     126         */
     127        $wp_duotone                      = new WP_Duotone();
     128        $block_css_declarations_property = new ReflectionProperty( 'WP_Duotone', 'block_css_declarations' );
     129        $block_css_declarations_property->setAccessible( true );
     130        $previous_value = $block_css_declarations_property->getValue();
     131        $block_css_declarations_property->setValue( $wp_duotone, array() );
     132
     133        WP_Duotone::render_duotone_support( '', $block, $wp_block );
     134        $actual = $block_css_declarations_property->getValue();
     135
     136        // Reset the property.
     137        $block_css_declarations_property->setValue( $wp_duotone, $previous_value );
     138        $block_css_declarations_property->setAccessible( false );
     139
     140        $this->assertNotEmpty( $actual );
     141    }
     142
     143    /**
    104144     * @dataProvider data_is_preset
    105145     */
Note: See TracChangeset for help on using the changeset viewer.