diff --git a/lib/experimental-default-theme.json b/lib/experimental-default-theme.json index 23357d05d29f2..23bf29f058b9c 100644 --- a/lib/experimental-default-theme.json +++ b/lib/experimental-default-theme.json @@ -130,6 +130,9 @@ }, "color": { "custom": true + }, + "gradient": { + "custom": true } } } diff --git a/lib/experiments-page.php b/lib/experiments-page.php index 19352ea578f8e..26cb98036b161 100644 --- a/lib/experiments-page.php +++ b/lib/experiments-page.php @@ -129,8 +129,6 @@ function gutenberg_experiments_editor_settings( $settings ) { $experiments_settings['gradients'] = $gradient_presets; } - $experiments_settings['disableCustomGradients'] = get_theme_support( 'disable-custom-gradients' ); - return array_merge( $settings, $experiments_settings ); } add_filter( 'block_editor_settings', 'gutenberg_experiments_editor_settings' ); diff --git a/lib/global-styles.php b/lib/global-styles.php index b4d916555f172..ec2062d9778bf 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -615,6 +615,12 @@ function gutenberg_experimental_global_styles_get_editor_features( $config ) { } $features['global']['color']['custom'] = false; } + if ( get_theme_support( 'disable-custom-gradients' ) ) { + if ( ! isset( $features['global']['gradient'] ) ) { + $features['global']['gradient'] = array(); + } + $features['global']['gradient']['custom'] = false; + } return $features; } @@ -646,8 +652,10 @@ function gutenberg_experimental_global_styles_settings( $settings ) { $settings['styles'][] = array( 'css' => $stylesheet ); $settings['__experimentalFeatures'] = gutenberg_experimental_global_styles_get_editor_features( $merged ); + // Unsetting deprecated settings defined by Core. unset( $settings['disableCustomColors'] ); + unset( $settings['disableCustomGradients'] ); return $settings; } diff --git a/packages/block-editor/src/components/colors-gradients/control.js b/packages/block-editor/src/components/colors-gradients/control.js index 0ad9c4463d721..9af633ba45eb9 100644 --- a/packages/block-editor/src/components/colors-gradients/control.js +++ b/packages/block-editor/src/components/colors-gradients/control.js @@ -181,6 +181,9 @@ function ColorGradientControlSelect( props ) { colorGradientSettings.disableCustomColors = ! useEditorFeature( 'color.custom' ); + colorGradientSettings.disableCustomGradients = ! useEditorFeature( + 'gradients.custom' + ); return ( { colorGradientSettings.disableCustomColors = ! useEditorFeature( 'color.custom' ); + colorGradientSettings.disableCustomGradients = ! useEditorFeature( + 'gradient.custom' + ); return ( - pick( select( 'core/block-editor' ).getSettings(), [ - 'gradients', - 'disableCustomGradients', - ] ), - [] - ); + const gradients = + useSelect( + ( select ) => select( 'core/block-editor' ).getSettings().gradients, + [] + ) ?? []; + const disableCustomGradients = ! useEditorFeature( 'gradient.custom' ); if ( isEmpty( gradients ) && disableCustomGradients ) { return null; } diff --git a/packages/block-editor/src/components/gradient-picker/index.js b/packages/block-editor/src/components/gradient-picker/index.js index cf1ebac3ed0d9..51e97ba8dac24 100644 --- a/packages/block-editor/src/components/gradient-picker/index.js +++ b/packages/block-editor/src/components/gradient-picker/index.js @@ -1,23 +1,22 @@ -/** - * External dependencies - */ -import { pick } from 'lodash'; - /** * WordPress dependencies */ import { __experimentalGradientPicker as GradientPicker } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; +/** + * Internal dependencies + */ +import useEditorFeature from '../use-editor-feature'; + function GradientPickerWithGradients( props ) { - const { gradients, disableCustomGradients } = useSelect( - ( select ) => - pick( select( 'core/block-editor' ).getSettings(), [ - 'gradients', - 'disableCustomGradients', - ] ), - [] - ); + const gradients = + useSelect( + ( select ) => select( 'core/block-editor' ).getSettings().gradients, + [] + ) ?? []; + const disableCustomGradients = ! useEditorFeature( 'gradient.custom' ); + return ( + settings.disableCustomGradients === undefined + ? undefined + : ! settings.disableCustomGradients, }; /**