diff --git a/src/wp-includes/class-wp-duotone.php b/src/wp-includes/class-wp-duotone.php index 482ddc6c133ba..08beac3cd4923 100644 --- a/src/wp-includes/class-wp-duotone.php +++ b/src/wp-includes/class-wp-duotone.php @@ -1116,9 +1116,12 @@ public static function render_duotone_support( $block_content, $block, $wp_block */ $duotone_attr = $block['attrs']['style']['color']['duotone']; - $is_preset = is_string( $duotone_attr ) && self::is_preset( $duotone_attr ); - $is_css = is_string( $duotone_attr ) && ! $is_preset; - $is_custom = is_array( $duotone_attr ); + if ( ! is_string( $duotone_attr ) && ! is_array( $duotone_attr ) ) { + return $block_content; + } + + $is_preset = is_string( $duotone_attr ) && self::is_preset( $duotone_attr ); + $is_css = is_string( $duotone_attr ) && ! $is_preset; if ( $is_preset ) { @@ -1136,7 +1139,7 @@ public static function render_duotone_support( $block_content, $block, $wp_block // Just block CSS. self::enqueue_block_css( $filter_id, $duotone_selector, $filter_value ); - } elseif ( $is_custom ) { + } else { $slug = wp_unique_id( sanitize_key( implode( '-', $duotone_attr ) . '-' ) ); // e.g. '000000-ffffff-2'. $filter_id = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-000000-ffffff-2'. $filter_value = self::get_filter_url( $filter_id ); // e.g. 'url(#wp-duotone-filter-000000-ffffff-2)'. @@ -1148,7 +1151,7 @@ public static function render_duotone_support( $block_content, $block, $wp_block // SVG filter and block CSS. self::enqueue_custom_filter( $filter_id, $duotone_selector, $filter_value, $filter_data ); } - } elseif ( $has_global_styles_duotone ) { + } else { $slug = $global_styles_block_names[ $block['blockName'] ]; // e.g. 'blue-orange'. $filter_id = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-blue-orange'. $filter_value = self::get_css_var( $slug ); // e.g. 'var(--wp--preset--duotone--blue-orange)'. diff --git a/tests/phpstan/baselines/variable.undefined.neon b/tests/phpstan/baselines/variable.undefined.neon index f82fe31a16504..8a2f2a9d8df31 100644 --- a/tests/phpstan/baselines/variable.undefined.neon +++ b/tests/phpstan/baselines/variable.undefined.neon @@ -703,11 +703,6 @@ parameters: identifier: variable.undefined count: 5 path: ../../../src/wp-includes/class-wp-block-processor.php - - - message: '#^Variable \$filter_id might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../src/wp-includes/class-wp-duotone.php - message: '#^Variable \$processed_response might not be defined\.$#' identifier: variable.undefined diff --git a/tests/phpunit/tests/block-supports/duotone.php b/tests/phpunit/tests/block-supports/duotone.php index f4eaa63faec99..7877254d554da 100644 --- a/tests/phpunit/tests/block-supports/duotone.php +++ b/tests/phpunit/tests/block-supports/duotone.php @@ -9,6 +9,38 @@ */ class Tests_Block_Supports_Duotone extends WP_UnitTestCase { + /** + * Tests that unsupported duotone attribute types leave the block unchanged. + * + * @ticket 65817 + * @dataProvider data_render_duotone_support_invalid_attribute + * @covers ::render_duotone_support + * + * @param mixed $duotone Invalid duotone attribute value. + */ + public function test_render_duotone_support_invalid_attribute( $duotone ) { + $block = array( + 'blockName' => 'core/image', + 'attrs' => array( 'style' => array( 'color' => array( 'duotone' => $duotone ) ) ), + ); + $wp_block = new WP_Block( $block ); + $block_content = '
'; + + $this->assertSame( $block_content, WP_Duotone::render_duotone_support( $block_content, $block, $wp_block ) ); + } + + /** + * @return array + */ + public function data_render_duotone_support_invalid_attribute() { + return array( + 'false' => array( false ), + 'true' => array( true ), + 'integer' => array( 1 ), + 'float' => array( 1.5 ), + ); + } + /** * Tests whether the duotone preset class is added to the block. *