From ee8d43548dcd8d195194c1b422bb7ede80a0d511 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Tue, 16 May 2023 11:22:03 -0500 Subject: [PATCH 1/4] Show a more specific error when theme.json styles use a preset not from settings --- lib/class-wp-duotone-gutenberg.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/class-wp-duotone-gutenberg.php b/lib/class-wp-duotone-gutenberg.php index b461e4ba0a64f..005310d9c292b 100644 --- a/lib/class-wp-duotone-gutenberg.php +++ b/lib/class-wp-duotone-gutenberg.php @@ -712,6 +712,15 @@ private static function enqueue_custom_filter( $filter_id, $duotone_selector, $f * @param string $filter_value The filter CSS value. e.g. 'url(#wp-duotone-blue-orange)' or 'unset'. */ private static function enqueue_global_styles_preset( $filter_id, $duotone_selector, $filter_value ) { + if ( ! array_key_exists( $filter_id, self::$global_styles_presets ) ) { + $error_message = sprintf( + /* translators: %s: duotone filter ID */ + __( 'The duotone id "%s" is not registered in theme.json settings.' ), + $filter_id + ); + trigger_error( $error_message ); + return; + } self::$used_global_styles_presets[ $filter_id ] = self::$global_styles_presets[ $filter_id ]; self::enqueue_custom_filter( $filter_id, $duotone_selector, $filter_value, self::$global_styles_presets[ $filter_id ] ); } From f07828decd6ffbadccf81061686fc62b5ce7881f Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 17 May 2023 13:32:36 -0500 Subject: [PATCH 2/4] Remove the period in the error message --- lib/class-wp-duotone-gutenberg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/class-wp-duotone-gutenberg.php b/lib/class-wp-duotone-gutenberg.php index 005310d9c292b..01bf96bf7cac1 100644 --- a/lib/class-wp-duotone-gutenberg.php +++ b/lib/class-wp-duotone-gutenberg.php @@ -715,7 +715,7 @@ private static function enqueue_global_styles_preset( $filter_id, $duotone_selec if ( ! array_key_exists( $filter_id, self::$global_styles_presets ) ) { $error_message = sprintf( /* translators: %s: duotone filter ID */ - __( 'The duotone id "%s" is not registered in theme.json settings.' ), + __( 'The duotone id "%s" is not registered in theme.json settings' ), $filter_id ); trigger_error( $error_message ); From c7f86dbee815a6c9a387bf3653b5777571670a0e Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 17 May 2023 13:35:27 -0500 Subject: [PATCH 3/4] Add gutenberg domain to translation --- lib/class-wp-duotone-gutenberg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/class-wp-duotone-gutenberg.php b/lib/class-wp-duotone-gutenberg.php index 01bf96bf7cac1..a500e0e5e1127 100644 --- a/lib/class-wp-duotone-gutenberg.php +++ b/lib/class-wp-duotone-gutenberg.php @@ -715,7 +715,7 @@ private static function enqueue_global_styles_preset( $filter_id, $duotone_selec if ( ! array_key_exists( $filter_id, self::$global_styles_presets ) ) { $error_message = sprintf( /* translators: %s: duotone filter ID */ - __( 'The duotone id "%s" is not registered in theme.json settings' ), + __( 'The duotone id "%s" is not registered in theme.json settings', 'gutenberg' ), $filter_id ); trigger_error( $error_message ); From ef60cd50de629f12710bb38d3305735c3c6290bd Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Fri, 19 May 2023 14:26:07 -0500 Subject: [PATCH 4/4] Use _doing_it_wrong instead of trigger_error --- lib/class-wp-duotone-gutenberg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/class-wp-duotone-gutenberg.php b/lib/class-wp-duotone-gutenberg.php index a500e0e5e1127..b18121086bae0 100644 --- a/lib/class-wp-duotone-gutenberg.php +++ b/lib/class-wp-duotone-gutenberg.php @@ -718,7 +718,7 @@ private static function enqueue_global_styles_preset( $filter_id, $duotone_selec __( 'The duotone id "%s" is not registered in theme.json settings', 'gutenberg' ), $filter_id ); - trigger_error( $error_message ); + _doing_it_wrong( __METHOD__, $error_message, '6.3.0' ); return; } self::$used_global_styles_presets[ $filter_id ] = self::$global_styles_presets[ $filter_id ];