Skip to content
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

Clarify error message if duotone color values is incorrect #51397

Merged
merged 4 commits into from
Jun 13, 2023
Merged
Changes from 2 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
17 changes: 13 additions & 4 deletions lib/class-wp-duotone-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,19 @@ private static function get_filter_svg( $filter_id, $colors ) {
foreach ( $colors as $color_str ) {
$color = self::colord_parse( $color_str );

$duotone_values['r'][] = $color['r'] / 255;
$duotone_values['g'][] = $color['g'] / 255;
$duotone_values['b'][] = $color['b'] / 255;
$duotone_values['a'][] = $color['a'];
if ( null === $color ) {
$error_message = sprintf(
/* translators: %s: duotone colors */
__( '"%s" is not a hex or rgb string in theme.json settings.', 'gutenberg' ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested well for me. I wonder if for even more clarity we should say `'"%s" in theme.json settings.color.duotone is not a hex or rgb string.'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! Updated with dae5201. Here are the new error messages:

PHP Notice:  Function WP_Duotone_Gutenberg::get_filter_svg was called <strong>incorrectly</strong>. "var(--wp--preset--color--black)" in theme.json settings.color.duotone is not a hex or rgb string. Please see <a href="https://wordpress.org/documentation/article/debugging-in-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 6.3.0.) in /var/www/html/wp-includes/functions.php on line 5896
PHP Notice:  Function WP_Duotone_Gutenberg::get_filter_svg was called <strong>incorrectly</strong>. "var(--wp--preset--color--vivid-red)" in theme.json settings.color.duotone is not a hex or rgb string. Please see <a href="https://wordpress.org/documentation/article/debugging-in-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 6.3.0.) in /var/www/html/wp-includes/functions.php on line 5896
PHP Notice:  Function WP_Duotone_Gutenberg::get_filter_svg was called <strong>incorrectly</strong>. "incorrect-value-1" in theme.json settings.color.duotone is not a hex or rgb string. Please see <a href="https://wordpress.org/documentation/article/debugging-in-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 6.3.0.) in /var/www/html/wp-includes/functions.php on line 5896
PHP Notice:  Function WP_Duotone_Gutenberg::get_filter_svg was called <strong>incorrectly</strong>. "incorrect-value-2" in theme.json settings.color.duotone is not a hex or rgb string. Please see <a href="https://wordpress.org/documentation/article/debugging-in-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 6.3.0.) in /var/www/html/wp-includes/functions.php on line 5896

$color_str
);
_doing_it_wrong( __METHOD__, $error_message, '6.3.0' );
} else {
$duotone_values['r'][] = $color['r'] / 255;
$duotone_values['g'][] = $color['g'] / 255;
$duotone_values['b'][] = $color['b'] / 255;
$duotone_values['a'][] = $color['a'];
}
}

ob_start();
Expand Down