diff --git a/src/wp-includes/class-wp-duotone.php b/src/wp-includes/class-wp-duotone.php index 69b56e090c5d4..8666f85a0f8e4 100644 --- a/src/wp-includes/class-wp-duotone.php +++ b/src/wp-includes/class-wp-duotone.php @@ -546,10 +546,14 @@ private static function colord_parse( $input ) { * * @since 6.3.0 * - * @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 ) ) { + return ''; + } + // Uses Branch Reset Groups `(?|…)` to return one capture group. preg_match( '/(?|var:preset\|duotone\|(\S+)|var\(--wp--preset--duotone--(\S+)\))/', $duotone_attr, $matches ); @@ -566,9 +570,13 @@ private static function get_slug_from_attribute( $duotone_attr ) { * @since 6.3.0 * * @param string $duotone_attr The duotone attribute from a block. - * @return bool True if the duotone preset present and valid. + * @param string|string[] $duotone_attr The duotone attribute from a block. */ 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 ); @@ -1050,6 +1058,11 @@ private static function get_all_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/tests/phpunit/tests/block-supports/duotone.php b/tests/phpunit/tests/block-supports/duotone.php index 1f60a8247d4c4..808903a072452 100644 --- a/tests/phpunit/tests/block-supports/duotone.php +++ b/tests/phpunit/tests/block-supports/duotone.php @@ -93,6 +93,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(), '' ), ); } @@ -164,6 +166,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 ), ); }