Repository navigation
Editor: Ignore unsupported duotone attribute types #14286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 ) ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello! I think we'd need to sync Gutenberg's copy as well lib/class-wp-duotone-gutenberg.php
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing out the Gutenberg copy! I have opened WordPress/gutenberg#84801 to sync the early type guard and exhaustive branches, with coverage for the four unsupported attribute values. The existing isset( $filter_id ) guard in Gutenberg is preserved. Validation: all 27 duotone tests (27 assertions), Gutenberg PHPCS for both changed PHP files, and the production build pass. PHP syntax checks also pass on PHP 7.4 and 8.3. The Gutenberg PR includes a backport-changelog entry linking it to this Core PR. |
||
| 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)'. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good. I can see that
$filter_idis now assigned in all branches of the conditional.Before this change, PhpStorm also flags an error:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking this in PhpStorm as well! With the early type guard, unsupported attribute values return unchanged and every remaining branch assigns $filter_id.