From 2e79fd97f719f6ede46e651aeae51eb8279d4dd0 Mon Sep 17 00:00:00 2001 From: Xavier Lozano Carreras Date: Fri, 6 Feb 2026 11:03:38 +0100 Subject: [PATCH 1/3] Prevent fatal error when the inline CSS duotone variable is an array --- lib/class-wp-duotone-gutenberg.php | 13 +++++++++++++ phpunit/class-wp-duotone-test.php | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/lib/class-wp-duotone-gutenberg.php b/lib/class-wp-duotone-gutenberg.php index df18bd84fc63e1..a7dfe00c4609a3 100644 --- a/lib/class-wp-duotone-gutenberg.php +++ b/lib/class-wp-duotone-gutenberg.php @@ -452,6 +452,10 @@ private static function colord_parse( $input ) { * @return string The slug of the duotone preset or an empty string if no slug is found. */ private static function get_slug_from_attribute( $duotone_attr ) { + if ( ! is_string( $duotone_attr ) ) { + return ''; + } + // Uses Branch Reset Groups `(?|…)` to return one capture group. preg_match( '/(?|var:preset\|duotone\|(\S+)|var\(--wp--preset--duotone--(\S+)\))/', $duotone_attr, $matches ); @@ -465,6 +469,10 @@ private static function get_slug_from_attribute( $duotone_attr ) { * @return bool True if the duotone preset present and valid. */ private static function is_preset( $duotone_attr ) { + if ( ! is_string( $duotone_attr ) ) { + return false; + } + $slug = self::get_slug_from_attribute( $duotone_attr ); $filter_id = self::get_filter_id( $slug ); @@ -809,6 +817,11 @@ public static function set_global_style_block_names() { continue; } // If it has a duotone filter preset, save the block name and the preset slug. + // Only process if it's a string (preset reference), not an array (custom colors). + if ( ! is_string( $duotone_attr ) ) { + continue; + } + $slug = self::get_slug_from_attribute( $duotone_attr ); if ( $slug && $slug !== $duotone_attr ) { diff --git a/phpunit/class-wp-duotone-test.php b/phpunit/class-wp-duotone-test.php index cebaddff61360c..bb7355d68af16a 100644 --- a/phpunit/class-wp-duotone-test.php +++ b/phpunit/class-wp-duotone-test.php @@ -94,6 +94,8 @@ public function data_get_slug_from_attribute() { 'pipe-slug-no-value' => array( 'var:preset|duotone|', '' ), 'css-var-spaces' => array( 'var(--wp--preset--duotone-- ', '' ), 'pipe-slug-spaces' => array( 'var:preset|duotone| ', '' ), + 'array-of-colors' => array( array( '#000000', '#ffffff' ), '' ), + 'empty-array' => array( array(), '' ), ); } @@ -115,6 +117,8 @@ public function data_is_preset() { 'css-var-invalid-slug-chars' => array( 'var(--wp--preset--duotone--.)', false ), 'css-var-missing-end-parenthesis' => array( 'var(--wp--preset--duotone--blue-orange', false ), 'invalid' => array( 'not a valid attribute', false ), + 'array-of-colors' => array( array( '#000000', '#ffffff' ), false ), + 'empty-array' => array( array(), false ), ); } From 3084d1944d2f1bc8eaf86ee1746f11b71c06882b Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Sat, 7 Feb 2026 11:57:59 +0000 Subject: [PATCH 2/3] add change log entry --- backport-changelog/7.0/10883.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 backport-changelog/7.0/10883.md diff --git a/backport-changelog/7.0/10883.md b/backport-changelog/7.0/10883.md new file mode 100644 index 00000000000000..83a4d9e3c0cda1 --- /dev/null +++ b/backport-changelog/7.0/10883.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/10883 + +* https://github.com/WordPress/gutenberg/pull/75283 From 55103786f47b6bcb9f0c4c0ce6682acafc228ff6 Mon Sep 17 00:00:00 2001 From: Xavier Lozano Carreras Date: Mon, 9 Feb 2026 10:03:46 +0100 Subject: [PATCH 3/3] Address PR feedback --- lib/class-wp-duotone-gutenberg.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/class-wp-duotone-gutenberg.php b/lib/class-wp-duotone-gutenberg.php index a7dfe00c4609a3..d9e20836397b4c 100644 --- a/lib/class-wp-duotone-gutenberg.php +++ b/lib/class-wp-duotone-gutenberg.php @@ -448,8 +448,8 @@ private static function colord_parse( $input ) { * var:preset|duotone|blue-orange * var(--wp--preset--duotone--blue-orange) * - * @param string $duotone_attr The duotone attribute from a block. - * @return string The slug of the duotone preset or an empty string if no slug is found. + * @param string|string[] $duotone_attr The duotone attribute from a block. + * @return string The slug of the duotone preset or an empty string if no slug is found (including when an array was passed). */ private static function get_slug_from_attribute( $duotone_attr ) { if ( ! is_string( $duotone_attr ) ) { @@ -465,7 +465,7 @@ private static function get_slug_from_attribute( $duotone_attr ) { /** * Check if we have a valid duotone preset. * - * @param string $duotone_attr The duotone attribute from a block. + * @param string|string[] $duotone_attr The duotone attribute from a block. * @return bool True if the duotone preset present and valid. */ private static function is_preset( $duotone_attr ) {