Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/wp-includes/class-wp-duotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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 );

Expand Down Expand Up @@ -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 ) {
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/tests/block-supports/duotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(), '' ),
);
}

Expand Down Expand Up @@ -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 ),
);
}

Expand Down
Loading