From 01d593e1a6451936d79118c69831db5d4c65b211 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 9 Feb 2022 13:43:24 -0600 Subject: [PATCH 01/22] Fix spacing --- lib/compat/wordpress-5.9/theme.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/compat/wordpress-5.9/theme.json b/lib/compat/wordpress-5.9/theme.json index ec29439d7f13f2..9c5d38e1fdd259 100644 --- a/lib/compat/wordpress-5.9/theme.json +++ b/lib/compat/wordpress-5.9/theme.json @@ -17,42 +17,42 @@ "defaultPalette": true, "duotone": [ { - "name": "Dark grayscale" , + "name": "Dark grayscale", "colors": [ "#000000", "#7f7f7f" ], "slug": "dark-grayscale" }, { - "name": "Grayscale" , + "name": "Grayscale", "colors": [ "#000000", "#ffffff" ], "slug": "grayscale" }, { - "name": "Purple and yellow" , + "name": "Purple and yellow", "colors": [ "#8c00b7", "#fcff41" ], "slug": "purple-yellow" }, { - "name": "Blue and red" , + "name": "Blue and red", "colors": [ "#000097", "#ff4747" ], "slug": "blue-red" }, { - "name": "Midnight" , + "name": "Midnight", "colors": [ "#000000", "#00a5ff" ], "slug": "midnight" }, { - "name": "Magenta and yellow" , + "name": "Magenta and yellow", "colors": [ "#c7005a", "#fff278" ], "slug": "magenta-yellow" }, { - "name": "Purple and green" , + "name": "Purple and green", "colors": [ "#a60072", "#67ff66" ], "slug": "purple-green" }, { - "name": "Blue and orange" , + "name": "Blue and orange", "colors": [ "#1900d8", "#ffa96b" ], "slug": "blue-orange" } From 51d2bc539c995662cdff0635a350b253324ac262 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 9 Feb 2022 13:44:03 -0600 Subject: [PATCH 02/22] Add defaultDuotone to disable default SVGs --- lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php | 6 +++++- .../wordpress-5.9/class-wp-theme-json-resolver-5-9.php | 2 ++ lib/compat/wordpress-5.9/theme.json | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index 76bc1c8b4077ad..2981f09281dd06 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -229,6 +229,7 @@ class WP_Theme_JSON_5_9 { 'custom' => null, 'customDuotone' => null, 'customGradient' => null, + 'defaultDuotone' => null, 'defaultGradients' => null, 'defaultPalette' => null, 'duotone' => null, @@ -1527,7 +1528,10 @@ public function get_svg_filters( $origins ) { $filters = ''; foreach ( $origins as $origin ) { - if ( ! isset( $duotone_presets[ $origin ] ) ) { + if ( + ! isset( $duotone_presets[ $origin ] ) || + ( 'default' === $origin && false === $node['color']['defaultDuotone'] ) + ) { continue; } foreach ( $duotone_presets[ $origin ] as $duotone_preset ) { diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php index c16f64f46cee6d..466ca2903e7f0f 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php @@ -190,6 +190,8 @@ public static function get_theme_data( $deprecated = array() ) { $default_gradients = true; } $theme_support_data['settings']['color']['defaultGradients'] = $default_gradients; + + $theme_support_data['settings']['color']['defaultDuotone'] = false; } $with_theme_supports = new WP_Theme_JSON_Gutenberg( $theme_support_data ); $with_theme_supports->merge( static::$theme ); diff --git a/lib/compat/wordpress-5.9/theme.json b/lib/compat/wordpress-5.9/theme.json index 9c5d38e1fdd259..7691aa4a64e6a9 100644 --- a/lib/compat/wordpress-5.9/theme.json +++ b/lib/compat/wordpress-5.9/theme.json @@ -13,6 +13,7 @@ "custom": true, "customDuotone": true, "customGradient": true, + "defaultDuotone": true, "defaultGradients": true, "defaultPalette": true, "duotone": [ From 90723484f409f45708bd2e004754d20b39a9c20e Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 9 Feb 2022 14:54:04 -0600 Subject: [PATCH 03/22] Disable duotone css vars too --- lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index 2981f09281dd06..3f2bfe07266aa5 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -1021,10 +1021,16 @@ protected static function scope_selector( $scope, $selector ) { */ protected static function get_settings_values_by_slug( $settings, $preset_metadata, $origins ) { $preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() ); + $skip_default_presets = + $preset_metadata['path'] == array( 'color', 'duotone' ) && + ! _wp_array_get( $settings, array( 'color', 'defaultDuotone' ), true ); $result = array(); foreach ( $origins as $origin ) { - if ( ! isset( $preset_per_origin[ $origin ] ) ) { + if ( + ! isset( $preset_per_origin[ $origin ] ) || + ( 'default' === $origin && $skip_default_presets ) + ) { continue; } foreach ( $preset_per_origin[ $origin ] as $preset ) { From ccb65acd4d7e93d45e779f6b4f71f8f63b40e9a0 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 9 Feb 2022 15:34:06 -0600 Subject: [PATCH 04/22] Add defaultDuotone to JSON schema --- schemas/json/theme.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/schemas/json/theme.json b/schemas/json/theme.json index a21710fe4626b5..aeb6fa5446459e 100644 --- a/schemas/json/theme.json +++ b/schemas/json/theme.json @@ -73,6 +73,11 @@ "type": "boolean", "default": true }, + "defaultDuotone": { + "description": "Allow users to choose colors from the default duotone presets.", + "type": "boolean", + "default": true + }, "defaultGradients": { "description": "Allow users to choose colors from the default gradients.", "type": "boolean", From 93f23af72fa77e8c51018091f43906aab8fc5837 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 9 Feb 2022 15:46:34 -0600 Subject: [PATCH 05/22] Fix phpcs --- lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index 3f2bfe07266aa5..de266725f02197 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -1021,8 +1021,9 @@ protected static function scope_selector( $scope, $selector ) { */ protected static function get_settings_values_by_slug( $settings, $preset_metadata, $origins ) { $preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() ); + $skip_default_presets = - $preset_metadata['path'] == array( 'color', 'duotone' ) && + array( 'color', 'duotone' ) === $preset_metadata['path'] && ! _wp_array_get( $settings, array( 'color', 'defaultDuotone' ), true ); $result = array(); From 7b4e11c51ef2f98523809b30a94a2fc78c543c2d Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 9 Feb 2022 15:55:18 -0600 Subject: [PATCH 06/22] Update docs --- docs/reference-guides/theme-json-reference/theme-json-living.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/reference-guides/theme-json-reference/theme-json-living.md b/docs/reference-guides/theme-json-reference/theme-json-living.md index ac2d059a1aa0f7..fd4c9c7113900b 100644 --- a/docs/reference-guides/theme-json-reference/theme-json-living.md +++ b/docs/reference-guides/theme-json-reference/theme-json-living.md @@ -45,6 +45,7 @@ Settings related to colors. | custom | boolean | true | | | customDuotone | boolean | true | | | customGradient | boolean | true | | +| defaultDuotone | boolean | true | | | defaultGradients | boolean | true | | | defaultPalette | boolean | true | | | duotone | array | | colors, name, slug | From 795de030f6d7e7294fd115c91273e265a4fa21cd Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Thu, 10 Feb 2022 10:41:19 -0600 Subject: [PATCH 07/22] Add defaultDuotone to prevent override --- lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index de266725f02197..5c14b2ba98a10e 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -71,7 +71,8 @@ class WP_Theme_JSON_5_9 { * * - path => where to find the preset within the settings section * - override => whether a theme preset with the same slug as a default preset - * can override it + * can override it or the path to a setting that _prevents_ + * presets from being overridden * - value_key => the key that represents the value * - value_func => optionally, instead of value_key, a function to generate * the value that takes a preset as an argument @@ -118,7 +119,7 @@ class WP_Theme_JSON_5_9 { ), array( 'path' => array( 'color', 'duotone' ), - 'override' => true, + 'override' => array( 'color', 'defaultDuotone' ), 'use_default_names' => false, 'value_func' => 'gutenberg_get_duotone_filter_property', 'css_vars' => '--wp--preset--duotone--$slug', From 3cda90b17c5ab48192b27bf253e7b272360a363d Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Thu, 10 Feb 2022 10:54:49 -0600 Subject: [PATCH 08/22] Try refactoring override path and bool to not be inverse --- .../wordpress-5.9/class-wp-theme-json-5-9.php | 96 +++++++++---------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index 5c14b2ba98a10e..e85af1a5260e42 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -69,35 +69,43 @@ class WP_Theme_JSON_5_9 { * * This contains the necessary metadata to process them: * - * - path => where to find the preset within the settings section - * - override => whether a theme preset with the same slug as a default preset - * can override it or the path to a setting that _prevents_ - * presets from being overridden - * - value_key => the key that represents the value - * - value_func => optionally, instead of value_key, a function to generate - * the value that takes a preset as an argument - * (either value_key or value_func should be present) - * - css_vars => template string to use in generating the CSS Custom Property. - * Example output: "--wp--preset--duotone--blue: " will generate as many CSS Custom Properties as presets defined - * substituting the $slug for the slug's value for each preset value. - * - classes => array containing a structure with the classes to - * generate for the presets, where for each array item - * the key is the class name and the value the property name. - * The "$slug" substring will be replaced by the slug of each preset. - * For example: - * 'classes' => array( - * '.has-$slug-color' => 'color', - * '.has-$slug-background-color' => 'background-color', - * '.has-$slug-border-color' => 'border-color', - * ) - * - properties => array of CSS properties to be used by kses to - * validate the content of each preset - * by means of the remove_insecure_properties method. + * - path => Where to find the preset within the settings section. + * - prevent_override => Whether a theme preset with the same slug as a default preset + * should not override it or the path to a setting for the same + * When defaults. + * The relationship between whether to override the defaults + * and whether the defaults are enabled is inverse: + * - If defaults are enabled => theme presets should not be overriden + * - If defaults are disabled => theme presets should be overriden + * For example, a theme sets defaultPalette to false, + * making the default palette hidden from the user. + * In that case, we want all the theme presets to be present, + * so they should override the defaults by setting this false. + * - value_key => the key that represents the value + * - value_func => optionally, instead of value_key, a function to generate + * the value that takes a preset as an argument + * (either value_key or value_func should be present) + * - css_vars => template string to use in generating the CSS Custom Property. + * Example output: "--wp--preset--duotone--blue: " will generate as many CSS Custom Properties as presets defined + * substituting the $slug for the slug's value for each preset value. + * - classes => array containing a structure with the classes to + * generate for the presets, where for each array item + * the key is the class name and the value the property name. + * The "$slug" substring will be replaced by the slug of each preset. + * For example: + * 'classes' => array( + * '.has-$slug-color' => 'color', + * '.has-$slug-background-color' => 'background-color', + * '.has-$slug-border-color' => 'border-color', + * ) + * - properties => array of CSS properties to be used by kses to + * validate the content of each preset + * by means of the remove_insecure_properties method. */ const PRESETS_METADATA = array( array( 'path' => array( 'color', 'palette' ), - 'override' => array( 'color', 'defaultPalette' ), + 'prevent_override' => array( 'color', 'defaultPalette' ), 'use_default_names' => false, 'value_key' => 'color', 'css_vars' => '--wp--preset--color--$slug', @@ -110,7 +118,7 @@ class WP_Theme_JSON_5_9 { ), array( 'path' => array( 'color', 'gradients' ), - 'override' => array( 'color', 'defaultGradients' ), + 'prevent_override' => array( 'color', 'defaultGradients' ), 'use_default_names' => false, 'value_key' => 'gradient', 'css_vars' => '--wp--preset--gradient--$slug', @@ -119,7 +127,7 @@ class WP_Theme_JSON_5_9 { ), array( 'path' => array( 'color', 'duotone' ), - 'override' => array( 'color', 'defaultDuotone' ), + 'prevent_override' => array( 'color', 'defaultDuotone' ), 'use_default_names' => false, 'value_func' => 'gutenberg_get_duotone_filter_property', 'css_vars' => '--wp--preset--duotone--$slug', @@ -128,7 +136,7 @@ class WP_Theme_JSON_5_9 { ), array( 'path' => array( 'typography', 'fontSizes' ), - 'override' => true, + 'prevent_override' => false, 'use_default_names' => true, 'value_key' => 'size', 'css_vars' => '--wp--preset--font-size--$slug', @@ -137,7 +145,7 @@ class WP_Theme_JSON_5_9 { ), array( 'path' => array( 'typography', 'fontFamilies' ), - 'override' => true, + 'prevent_override' => false, 'use_default_names' => false, 'value_key' => 'fontFamily', 'css_vars' => '--wp--preset--font-family--$slug', @@ -1479,7 +1487,7 @@ public function merge( $incoming ) { // Replace the presets. foreach ( static::PRESETS_METADATA as $preset ) { - $override_preset = static::should_override_preset( $this->theme_json, $node['path'], $preset['override'] ); + $override_preset = static::should_override_preset( $this->theme_json, $node['path'], $preset['prevent_override'] ); foreach ( static::VALID_ORIGINS as $origin ) { $base_path = array_merge( $node['path'], $preset['path'] ); @@ -1552,41 +1560,31 @@ public function get_svg_filters( $origins ) { } /** - * Returns whether a presets should be overriden or not. + * Returns whether a presets should be overridden or not. * * @param array $theme_json The theme.json like structure to inspect. * @param array $path Path to inspect. - * @param bool|array $override Data to compute whether to override the preset. + * @param bool|array $prevent_override Data to compute whether to prevent override of the preset. * @return boolean */ - protected static function should_override_preset( $theme_json, $path, $override ) { - if ( is_bool( $override ) ) { - return $override; + protected static function should_override_preset( $theme_json, $path, $prevent_override ) { + if ( is_bool( $prevent_override ) ) { + return ! $prevent_override; } - // The relationship between whether to override the defaults - // and whether the defaults are enabled is inverse: - // - // - If defaults are enabled => theme presets should not be overriden - // - If defaults are disabled => theme presets should be overriden - // - // For example, a theme sets defaultPalette to false, - // making the default palette hidden from the user. - // In that case, we want all the theme presets to be present, - // so they should override the defaults. - if ( is_array( $override ) ) { - $value = _wp_array_get( $theme_json, array_merge( $path, $override ) ); + if ( is_array( $prevent_override ) ) { + $value = _wp_array_get( $theme_json, array_merge( $path, $prevent_override ) ); if ( isset( $value ) ) { return ! $value; } // Search the top-level key if none was found for this node. - $value = _wp_array_get( $theme_json, array_merge( array( 'settings' ), $override ) ); + $value = _wp_array_get( $theme_json, array_merge( array( 'settings' ), $prevent_override ) ); if ( isset( $value ) ) { return ! $value; } - return true; + return false; } } From 68cdf4e684ccd1fb8bcd607bbf364095dcbbcb1d Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Thu, 10 Feb 2022 11:24:17 -0600 Subject: [PATCH 09/22] Use multi-origin duotone presets --- packages/block-editor/src/hooks/duotone.js | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/hooks/duotone.js b/packages/block-editor/src/hooks/duotone.js index 13de8f2a4d79ac..f3be0d5cf0b555 100644 --- a/packages/block-editor/src/hooks/duotone.js +++ b/packages/block-editor/src/hooks/duotone.js @@ -12,7 +12,7 @@ import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks'; import { SVG } from '@wordpress/components'; import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose'; import { addFilter } from '@wordpress/hooks'; -import { useContext, createPortal } from '@wordpress/element'; +import { useMemo, useContext, createPortal } from '@wordpress/element'; /** * Internal dependencies @@ -140,12 +140,33 @@ ${ selector } { ); } +function useMultiOriginPresets( { presetSetting, defaultSetting } ) { + const disableDefault = ! useSetting( defaultSetting ); + const userPresets = + useSetting( `${ presetSetting }.custom` ) || EMPTY_ARRAY; + const themePresets = + useSetting( `${ presetSetting }.theme` ) || EMPTY_ARRAY; + const defaultPresets = disableDefault + ? EMPTY_ARRAY + : useSetting( `${ presetSetting }.default` ) || EMPTY_ARRAY; + return useMemo( + () => [ ...userPresets, ...themePresets, ...defaultPresets ], + [ disableDefault, userPresets, themePresets, defaultPresets ] + ); +} + function DuotonePanel( { attributes, setAttributes } ) { const style = attributes?.style; const duotone = style?.color?.duotone; - const duotonePalette = useSetting( 'color.duotone' ) || EMPTY_ARRAY; - const colorPalette = useSetting( 'color.palette' ) || EMPTY_ARRAY; + const duotonePalette = useMultiOriginPresets( { + presetSetting: 'color.duotone', + defaultSetting: 'color.defaultDuotone', + } ); + const colorPalette = useMultiOriginPresets( { + presetSetting: 'color.palette', + defaultSetting: 'color.defaultPalette', + } ); const disableCustomColors = ! useSetting( 'color.custom' ); const disableCustomDuotone = ! useSetting( 'color.customDuotone' ) || From fe1c37a97b5b15312db6ea6fcca9ece1025a0c3c Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Thu, 10 Feb 2022 12:28:41 -0600 Subject: [PATCH 10/22] Try refactor should_override_preset --- .../wordpress-5.9/class-wp-theme-json-5-9.php | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index e85af1a5260e42..0e70762044afef 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -1487,7 +1487,7 @@ public function merge( $incoming ) { // Replace the presets. foreach ( static::PRESETS_METADATA as $preset ) { - $override_preset = static::should_override_preset( $this->theme_json, $node['path'], $preset['prevent_override'] ); + $override_preset = ! static::get_metadata_boolean( $this->theme_json['settings'], $preset['prevent_override'], true ); foreach ( static::VALID_ORIGINS as $origin ) { $base_path = array_merge( $node['path'], $preset['path'] ); @@ -1560,32 +1560,25 @@ public function get_svg_filters( $origins ) { } /** - * Returns whether a presets should be overridden or not. + * For metadata values that can either be booleans or paths to booleans, gets the value. * - * @param array $theme_json The theme.json like structure to inspect. - * @param array $path Path to inspect. - * @param bool|array $prevent_override Data to compute whether to prevent override of the preset. + * @param array $data The data to inspect. + * @param bool|array $path Boolean or path to a boolean. * @return boolean */ - protected static function should_override_preset( $theme_json, $path, $prevent_override ) { - if ( is_bool( $prevent_override ) ) { - return ! $prevent_override; + protected static function get_metadata_boolean( $data, $path, $default = false ) { + if ( is_bool( $path ) ) { + return $path; } - if ( is_array( $prevent_override ) ) { - $value = _wp_array_get( $theme_json, array_merge( $path, $prevent_override ) ); + if ( is_array( $path ) ) { + $value = _wp_array_get( $data, $path ); if ( isset( $value ) ) { - return ! $value; + return $value; } - - // Search the top-level key if none was found for this node. - $value = _wp_array_get( $theme_json, array_merge( array( 'settings' ), $prevent_override ) ); - if ( isset( $value ) ) { - return ! $value; - } - - return false; } + + return $default; } /** From 6b65616270537b4319fa717e9cfe101ba1189f7b Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Thu, 10 Feb 2022 12:58:44 -0600 Subject: [PATCH 11/22] Prevent generating other default presets --- .../wordpress-5.9/class-wp-theme-json-5-9.php | 86 ++++++++++--------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index 0e70762044afef..f2ca169fcc8964 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -104,53 +104,58 @@ class WP_Theme_JSON_5_9 { */ const PRESETS_METADATA = array( array( - 'path' => array( 'color', 'palette' ), - 'prevent_override' => array( 'color', 'defaultPalette' ), - 'use_default_names' => false, - 'value_key' => 'color', - 'css_vars' => '--wp--preset--color--$slug', - 'classes' => array( + 'path' => array( 'color', 'palette' ), + 'prevent_override' => array( 'color', 'defaultPalette' ), + 'use_default_presets' => array( 'color', 'defaultPalette' ), + 'use_default_names' => false, + 'value_key' => 'color', + 'css_vars' => '--wp--preset--color--$slug', + 'classes' => array( '.has-$slug-color' => 'color', '.has-$slug-background-color' => 'background-color', '.has-$slug-border-color' => 'border-color', ), - 'properties' => array( 'color', 'background-color', 'border-color' ), + 'properties' => array( 'color', 'background-color', 'border-color' ), ), array( - 'path' => array( 'color', 'gradients' ), - 'prevent_override' => array( 'color', 'defaultGradients' ), - 'use_default_names' => false, - 'value_key' => 'gradient', - 'css_vars' => '--wp--preset--gradient--$slug', - 'classes' => array( '.has-$slug-gradient-background' => 'background' ), - 'properties' => array( 'background' ), + 'path' => array( 'color', 'gradients' ), + 'prevent_override' => array( 'color', 'defaultGradients' ), + 'use_default_presets' => array( 'color', 'defaultGradients' ), + 'use_default_names' => false, + 'value_key' => 'gradient', + 'css_vars' => '--wp--preset--gradient--$slug', + 'classes' => array( '.has-$slug-gradient-background' => 'background' ), + 'properties' => array( 'background' ), ), array( - 'path' => array( 'color', 'duotone' ), - 'prevent_override' => array( 'color', 'defaultDuotone' ), - 'use_default_names' => false, - 'value_func' => 'gutenberg_get_duotone_filter_property', - 'css_vars' => '--wp--preset--duotone--$slug', - 'classes' => array(), - 'properties' => array( 'filter' ), + 'path' => array( 'color', 'duotone' ), + 'prevent_override' => array( 'color', 'defaultDuotone' ), + 'use_default_presets' => array( 'color', 'defaultDuotone' ), + 'use_default_names' => false, + 'value_func' => 'gutenberg_get_duotone_filter_property', + 'css_vars' => '--wp--preset--duotone--$slug', + 'classes' => array(), + 'properties' => array( 'filter' ), ), array( - 'path' => array( 'typography', 'fontSizes' ), - 'prevent_override' => false, - 'use_default_names' => true, - 'value_key' => 'size', - 'css_vars' => '--wp--preset--font-size--$slug', - 'classes' => array( '.has-$slug-font-size' => 'font-size' ), - 'properties' => array( 'font-size' ), + 'path' => array( 'typography', 'fontSizes' ), + 'prevent_override' => false, + 'use_default_presets' => true, + 'use_default_names' => true, + 'value_key' => 'size', + 'css_vars' => '--wp--preset--font-size--$slug', + 'classes' => array( '.has-$slug-font-size' => 'font-size' ), + 'properties' => array( 'font-size' ), ), array( - 'path' => array( 'typography', 'fontFamilies' ), - 'prevent_override' => false, - 'use_default_names' => false, - 'value_key' => 'fontFamily', - 'css_vars' => '--wp--preset--font-family--$slug', - 'classes' => array( '.has-$slug-font-family' => 'font-family' ), - 'properties' => array( 'font-family' ), + 'path' => array( 'typography', 'fontFamilies' ), + 'prevent_override' => false, + 'use_default_presets' => true, + 'use_default_names' => false, + 'value_key' => 'fontFamily', + 'css_vars' => '--wp--preset--font-family--$slug', + 'classes' => array( '.has-$slug-font-family' => 'font-family' ), + 'properties' => array( 'font-family' ), ), ); @@ -1031,9 +1036,7 @@ protected static function scope_selector( $scope, $selector ) { protected static function get_settings_values_by_slug( $settings, $preset_metadata, $origins ) { $preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() ); - $skip_default_presets = - array( 'color', 'duotone' ) === $preset_metadata['path'] && - ! _wp_array_get( $settings, array( 'color', 'defaultDuotone' ), true ); + $skip_default_presets = ! self::get_metadata_boolean( $settings, $preset_metadata['use_default_presets'], true ); $result = array(); foreach ( $origins as $origin ) { @@ -1082,9 +1085,14 @@ protected static function get_settings_slugs( $settings, $preset_metadata, $orig $preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() ); + $skip_default_presets = ! self::get_metadata_boolean( $settings, $preset_metadata['use_default_presets'], true ); + $result = array(); foreach ( $origins as $origin ) { - if ( ! isset( $preset_per_origin[ $origin ] ) ) { + if ( + ! isset( $preset_per_origin[ $origin ] ) || + ( 'default' === $origin && $skip_default_presets ) + ) { continue; } foreach ( $preset_per_origin[ $origin ] as $preset ) { From ece841daed3b32588594c95c3ced3fb1754201db Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 16 Feb 2022 14:04:49 -0600 Subject: [PATCH 12/22] Fix conditional hook --- packages/block-editor/src/hooks/duotone.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/hooks/duotone.js b/packages/block-editor/src/hooks/duotone.js index f3be0d5cf0b555..2fe20b0da75ff3 100644 --- a/packages/block-editor/src/hooks/duotone.js +++ b/packages/block-editor/src/hooks/duotone.js @@ -146,11 +146,14 @@ function useMultiOriginPresets( { presetSetting, defaultSetting } ) { useSetting( `${ presetSetting }.custom` ) || EMPTY_ARRAY; const themePresets = useSetting( `${ presetSetting }.theme` ) || EMPTY_ARRAY; - const defaultPresets = disableDefault - ? EMPTY_ARRAY - : useSetting( `${ presetSetting }.default` ) || EMPTY_ARRAY; + const defaultPresets = + useSetting( `${ presetSetting }.default` ) || EMPTY_ARRAY; return useMemo( - () => [ ...userPresets, ...themePresets, ...defaultPresets ], + () => [ + ...userPresets, + ...themePresets, + ...( disableDefault ? defaultPresets : EMPTY_ARRAY ), + ], [ disableDefault, userPresets, themePresets, defaultPresets ] ); } From d47041e316c0766b649ddbe22f01e3f4a06ded26 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 16 Feb 2022 14:14:39 -0600 Subject: [PATCH 13/22] Add example for get_metadata_boolean --- .../wordpress-5.9/class-wp-theme-json-5-9.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index f2ca169fcc8964..d9a5312de07fc6 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -1570,6 +1570,20 @@ public function get_svg_filters( $origins ) { /** * For metadata values that can either be booleans or paths to booleans, gets the value. * + * ```php + * $data = array( + * 'color' => array( + * 'defaultPalette' => true + * ) + * ); + * + * self::get_metadata_boolean( $data, false ); + * // => false + * + * self::get_metadata_boolean( $data, array( 'color', 'defaultPalette' ) ); + * // => true + * ``` + * * @param array $data The data to inspect. * @param bool|array $path Boolean or path to a boolean. * @return boolean From bb55054b988d94c7a31164ec10827be5833e9efc Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 16 Feb 2022 17:46:14 -0600 Subject: [PATCH 14/22] Fix phpcs --- lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index d9a5312de07fc6..c39128f3202421 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -1586,6 +1586,7 @@ public function get_svg_filters( $origins ) { * * @param array $data The data to inspect. * @param bool|array $path Boolean or path to a boolean. + * @param bool $default Default value if the referenced path is missing. * @return boolean */ protected static function get_metadata_boolean( $data, $path, $default = false ) { From e6ceb4b59edf12258c554fcdb9dd1843b45fd68e Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 21 Feb 2022 13:00:00 -0600 Subject: [PATCH 15/22] Override core duotone rendering in plugin --- .../wordpress-5.9/render-svg-filters.php | 61 +++++++---------- .../get-global-styles-and-settings.php | 66 +++++++++---------- 2 files changed, 57 insertions(+), 70 deletions(-) diff --git a/lib/compat/wordpress-5.9/render-svg-filters.php b/lib/compat/wordpress-5.9/render-svg-filters.php index 8d842c7e79fcc0..e01cd29c16002c 100644 --- a/lib/compat/wordpress-5.9/render-svg-filters.php +++ b/lib/compat/wordpress-5.9/render-svg-filters.php @@ -5,44 +5,33 @@ * @package gutenberg */ -/* - * If wp_global_styles_render_svg_filters is defined, it means the plugin - * is running on WordPress 5.9.1, so don't need to render the global styles - * SVG filters as it was already done by WordPress core. +/** + * Render the SVG filters supplied by theme.json. + * + * Note that this doesn't render the per-block user-defined + * filters which are handled by wp_render_duotone_support, + * but it should be rendered before the filtered content + * in the body to satisfy Safari's rendering quirks. */ -if ( ! function_exists( 'wp_global_styles_render_svg_filters' ) ) { - /** - * Render the SVG filters supplied by theme.json. - * - * Note that this doesn't render the per-block user-defined - * filters which are handled by wp_render_duotone_support, - * but it should be rendered before the filtered content - * in the body to satisfy Safari's rendering quirks. +function gutenberg_global_styles_render_svg_filters() { + /* + * When calling via the in_admin_header action, we only want to render the + * SVGs on block editor pages. */ - function wp_global_styles_render_svg_filters() { - /* - * When calling via the in_admin_header action, we only want to render the - * SVGs on block editor pages. - */ - if ( - is_admin() && - ! get_current_screen()->is_block_editor() - ) { - return; - } - - $filters = wp_get_global_styles_svg_filters(); - if ( ! empty( $filters ) ) { - echo $filters; - } + if ( + is_admin() && + ! get_current_screen()->is_block_editor() + ) { + return; } - add_action( - 'wp_body_open', - 'wp_global_styles_render_svg_filters' - ); - add_action( - 'in_admin_header', - 'wp_global_styles_render_svg_filters' - ); + $filters = gutenberg_get_global_styles_svg_filters(); + if ( ! empty( $filters ) ) { + echo $filters; + } } + +remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' ); +remove_action( 'in_admin_header', 'wp_global_styles_render_svg_filters' ); +add_action( 'wp_body_open', 'gutenberg_global_styles_render_svg_filters' ); +add_action( 'in_admin_header', 'gutenberg_global_styles_render_svg_filters' ); diff --git a/lib/compat/wordpress-6.0/get-global-styles-and-settings.php b/lib/compat/wordpress-6.0/get-global-styles-and-settings.php index 5e78029d0d1915..bb8819ec2ef257 100644 --- a/lib/compat/wordpress-6.0/get-global-styles-and-settings.php +++ b/lib/compat/wordpress-6.0/get-global-styles-and-settings.php @@ -134,44 +134,42 @@ function gutenberg_get_global_stylesheet( $types = array() ) { return $stylesheet; } -if ( ! function_exists( 'wp_get_global_styles_svg_filters' ) ) { - /** - * Returns a string containing the SVGs to be referenced as filters (duotone). - * - * @return string - */ - function wp_get_global_styles_svg_filters() { - // Return cached value if it can be used and exists. - // It's cached by theme to make sure that theme switching clears the cache. - $transient_name = 'gutenberg_global_styles_svg_filters_' . get_stylesheet(); - $can_use_cached = ( - ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) && - ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) && - ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) && - ! is_admin() - ); - if ( $can_use_cached ) { - $cached = get_transient( $transient_name ); - if ( $cached ) { - return $cached; - } +/** + * Returns a string containing the SVGs to be referenced as filters (duotone). + * + * @return string + */ +function gutenberg_get_global_styles_svg_filters() { + // Return cached value if it can be used and exists. + // It's cached by theme to make sure that theme switching clears the cache. + $transient_name = 'gutenberg_global_styles_svg_filters_' . get_stylesheet(); + $can_use_cached = ( + ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) && + ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) && + ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) && + ! is_admin() + ); + if ( $can_use_cached ) { + $cached = get_transient( $transient_name ); + if ( $cached ) { + return $cached; } + } - $supports_theme_json = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support(); - - $origins = array( 'default', 'theme', 'custom' ); - if ( ! $supports_theme_json ) { - $origins = array( 'default' ); - } + $supports_theme_json = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support(); - $tree = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data(); - $svgs = $tree->get_svg_filters( $origins ); + $origins = array( 'default', 'theme', 'custom' ); + if ( ! $supports_theme_json ) { + $origins = array( 'default' ); + } - if ( $can_use_cached ) { - // Cache for a minute, same as gutenberg_get_global_stylesheet. - set_transient( $transient_name, $svgs, MINUTE_IN_SECONDS ); - } + $tree = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data(); + $svgs = $tree->get_svg_filters( $origins ); - return $svgs; + if ( $can_use_cached ) { + // Cache for a minute, same as gutenberg_get_global_stylesheet. + set_transient( $transient_name, $svgs, MINUTE_IN_SECONDS ); } + + return $svgs; } From 67dbd4be2a555a09f5dfc1992943b09ccccf8333 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 21 Feb 2022 13:52:13 -0600 Subject: [PATCH 16/22] Use protected/static instead of private/self --- lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index c39128f3202421..3c0d69a9631bb3 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -1036,7 +1036,7 @@ protected static function scope_selector( $scope, $selector ) { protected static function get_settings_values_by_slug( $settings, $preset_metadata, $origins ) { $preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() ); - $skip_default_presets = ! self::get_metadata_boolean( $settings, $preset_metadata['use_default_presets'], true ); + $skip_default_presets = ! static::get_metadata_boolean( $settings, $preset_metadata['use_default_presets'], true ); $result = array(); foreach ( $origins as $origin ) { @@ -1085,7 +1085,7 @@ protected static function get_settings_slugs( $settings, $preset_metadata, $orig $preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() ); - $skip_default_presets = ! self::get_metadata_boolean( $settings, $preset_metadata['use_default_presets'], true ); + $skip_default_presets = ! static::get_metadata_boolean( $settings, $preset_metadata['use_default_presets'], true ); $result = array(); foreach ( $origins as $origin ) { @@ -1577,10 +1577,10 @@ public function get_svg_filters( $origins ) { * ) * ); * - * self::get_metadata_boolean( $data, false ); + * static::get_metadata_boolean( $data, false ); * // => false * - * self::get_metadata_boolean( $data, array( 'color', 'defaultPalette' ) ); + * static::get_metadata_boolean( $data, array( 'color', 'defaultPalette' ) ); * // => true * ``` * From 10e3e268a1e81685dcca7b7cd5588003dac1e51b Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 21 Feb 2022 14:04:58 -0600 Subject: [PATCH 17/22] Fix toolbar items for duotone --- packages/block-editor/src/hooks/duotone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/hooks/duotone.js b/packages/block-editor/src/hooks/duotone.js index 2fe20b0da75ff3..163846d52e415a 100644 --- a/packages/block-editor/src/hooks/duotone.js +++ b/packages/block-editor/src/hooks/duotone.js @@ -152,7 +152,7 @@ function useMultiOriginPresets( { presetSetting, defaultSetting } ) { () => [ ...userPresets, ...themePresets, - ...( disableDefault ? defaultPresets : EMPTY_ARRAY ), + ...( disableDefault ? EMPTY_ARRAY : defaultPresets ), ], [ disableDefault, userPresets, themePresets, defaultPresets ] ); From 159afc32f4062918c2de48ab2ccde17751e3fa63 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 21 Feb 2022 16:28:10 -0600 Subject: [PATCH 18/22] Disable duotone generation in classic themes while keeping the default duotone UI for per-block filters --- lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php | 11 ++++++++++- .../class-wp-theme-json-resolver-5-9.php | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index 3c0d69a9631bb3..495d83797e1b54 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -1542,6 +1542,16 @@ public function get_svg_filters( $origins ) { $blocks_metadata = static::get_blocks_metadata(); $setting_nodes = static::get_setting_nodes( $this->theme_json, $blocks_metadata ); + /* + * Filters generated by blocks include their own stylesheet instead of + * having a class name, so we can skip generating the theme filters in + * classic themes which only support per-block filters. + */ + if ( ! wp_is_block_theme() ) { + return ''; + } + + $filters = ''; foreach ( $setting_nodes as $metadata ) { $node = _wp_array_get( $this->theme_json, $metadata['path'], array() ); if ( empty( $node['color']['duotone'] ) ) { @@ -1550,7 +1560,6 @@ public function get_svg_filters( $origins ) { $duotone_presets = $node['color']['duotone']; - $filters = ''; foreach ( $origins as $origin ) { if ( ! isset( $duotone_presets[ $origin ] ) || diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php index 466ca2903e7f0f..5068bed9ca1492 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php @@ -191,7 +191,12 @@ public static function get_theme_data( $deprecated = array() ) { } $theme_support_data['settings']['color']['defaultGradients'] = $default_gradients; - $theme_support_data['settings']['color']['defaultDuotone'] = false; + $default_duotone = false; + if ( ! isset( $theme_support_data['settings']['color']['duotone'] ) ) { + // If the theme does not have any duotone filters, we still want to show the core ones. + $default_duotone = true; + } + $theme_support_data['settings']['color']['defaultDuotone'] = $default_duotone; } $with_theme_supports = new WP_Theme_JSON_Gutenberg( $theme_support_data ); $with_theme_supports->merge( static::$theme ); From 9de2494b499bfab831b1798719aee3fcf11bb4ad Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 21 Feb 2022 16:36:27 -0600 Subject: [PATCH 19/22] Update schema description for defaultDuotone --- schemas/json/theme.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schemas/json/theme.json b/schemas/json/theme.json index aeb6fa5446459e..f2d8419f281db2 100644 --- a/schemas/json/theme.json +++ b/schemas/json/theme.json @@ -74,7 +74,7 @@ "default": true }, "defaultDuotone": { - "description": "Allow users to choose colors from the default duotone presets.", + "description": "Allow users to choose filters from the default duotone filter presets.", "type": "boolean", "default": true }, @@ -647,7 +647,7 @@ } }, "patternProperties": { - "^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$": { + "^[a-z][a-z0-9-]*/[a-z][a-z0-9-]*$": { "$ref": "#/definitions/settingsPropertiesComplete" } }, From 1410ae15e85059e0502b92acf12cec34ba32690f Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 21 Feb 2022 16:39:32 -0600 Subject: [PATCH 20/22] Add comment about overriding --- lib/compat/wordpress-5.9/render-svg-filters.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/compat/wordpress-5.9/render-svg-filters.php b/lib/compat/wordpress-5.9/render-svg-filters.php index e01cd29c16002c..40637900cc35e5 100644 --- a/lib/compat/wordpress-5.9/render-svg-filters.php +++ b/lib/compat/wordpress-5.9/render-svg-filters.php @@ -31,6 +31,7 @@ function gutenberg_global_styles_render_svg_filters() { } } +// Override actions introduced in 5.9.1 remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' ); remove_action( 'in_admin_header', 'wp_global_styles_render_svg_filters' ); add_action( 'wp_body_open', 'gutenberg_global_styles_render_svg_filters' ); From 6bdf5d0f5da9bb2960ec2e5a6bda88e7f88135f1 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 21 Feb 2022 16:40:37 -0600 Subject: [PATCH 21/22] Fix comment style --- lib/compat/wordpress-5.9/render-svg-filters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-5.9/render-svg-filters.php b/lib/compat/wordpress-5.9/render-svg-filters.php index 40637900cc35e5..f13502b867fe95 100644 --- a/lib/compat/wordpress-5.9/render-svg-filters.php +++ b/lib/compat/wordpress-5.9/render-svg-filters.php @@ -31,7 +31,7 @@ function gutenberg_global_styles_render_svg_filters() { } } -// Override actions introduced in 5.9.1 +// Override actions introduced in 5.9.1 if they exist. remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' ); remove_action( 'in_admin_header', 'wp_global_styles_render_svg_filters' ); add_action( 'wp_body_open', 'gutenberg_global_styles_render_svg_filters' ); From 77b04c7d5ffe8bb4a98ab9590c0da4a7fabe69cc Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Thu, 24 Feb 2022 02:20:45 -0600 Subject: [PATCH 22/22] Revert extra check in theme.json resolver --- lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php | 9 --------- .../wordpress-5.9/class-wp-theme-json-resolver-5-9.php | 8 ++------ 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index 495d83797e1b54..5ad476b7d13bbf 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -1542,15 +1542,6 @@ public function get_svg_filters( $origins ) { $blocks_metadata = static::get_blocks_metadata(); $setting_nodes = static::get_setting_nodes( $this->theme_json, $blocks_metadata ); - /* - * Filters generated by blocks include their own stylesheet instead of - * having a class name, so we can skip generating the theme filters in - * classic themes which only support per-block filters. - */ - if ( ! wp_is_block_theme() ) { - return ''; - } - $filters = ''; foreach ( $setting_nodes as $metadata ) { $node = _wp_array_get( $this->theme_json, $metadata['path'], array() ); diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php index 5068bed9ca1492..7973810d33f65f 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php @@ -191,12 +191,8 @@ public static function get_theme_data( $deprecated = array() ) { } $theme_support_data['settings']['color']['defaultGradients'] = $default_gradients; - $default_duotone = false; - if ( ! isset( $theme_support_data['settings']['color']['duotone'] ) ) { - // If the theme does not have any duotone filters, we still want to show the core ones. - $default_duotone = true; - } - $theme_support_data['settings']['color']['defaultDuotone'] = $default_duotone; + // Classic themes without a theme.json don't support global duotone. + $theme_support_data['settings']['color']['defaultDuotone'] = false; } $with_theme_supports = new WP_Theme_JSON_Gutenberg( $theme_support_data ); $with_theme_supports->merge( static::$theme );