From ad47f0505f2791c5b6804cba3ccf5a29f66ef1e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20K=C3=A4gy?= Date: Mon, 15 Nov 2021 19:24:47 +0100 Subject: [PATCH] Fix: allow themes to opt out from core color palette (#36492) --- docs/how-to-guides/themes/theme-json.md | 4 ++++ lib/class-wp-theme-json-gutenberg.php | 2 ++ lib/theme.json | 2 ++ .../colors-gradients/panel-color-gradient-settings.js | 11 +++++++++-- schemas/json/theme.json | 10 ++++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/docs/how-to-guides/themes/theme-json.md b/docs/how-to-guides/themes/theme-json.md index 3f3da4c9f4a75..24095cf2dd709 100644 --- a/docs/how-to-guides/themes/theme-json.md +++ b/docs/how-to-guides/themes/theme-json.md @@ -226,9 +226,13 @@ The settings section has the following structure: }, "color": { "background": true, + "corePalette": true, + "coreGradients": true, "custom": true, "customDuotone": true, "customGradient": true, + "corePalette": true, + "coreGradients": true, "duotone": [], "gradients": [], "link": false, diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index 52d1cbbb643aa..2c1df8b309e79 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -89,6 +89,8 @@ class WP_Theme_JSON_Gutenberg { ), 'color' => array( 'background' => null, + 'corePalette' => null, + 'coreGradients' => null, 'custom' => null, 'customDuotone' => null, 'customGradient' => null, diff --git a/lib/theme.json b/lib/theme.json index 7629089219f8e..82e3b4fec9ee0 100644 --- a/lib/theme.json +++ b/lib/theme.json @@ -170,6 +170,8 @@ } ], "custom": true, + "corePalette": true, + "coreGradients": true, "customDuotone": true, "customGradient": true, "link": false, diff --git a/packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js b/packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js index f3f0a9a68859b..d77447f9b726e 100644 --- a/packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js +++ b/packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js @@ -175,9 +175,11 @@ const PanelColorGradientSettingsMultipleSelect = ( props ) => { const userColors = useSetting( 'color.palette.user' ); const themeColors = useSetting( 'color.palette.theme' ); const coreColors = useSetting( 'color.palette.core' ); + const shouldDisplayCoreColors = useSetting( 'color.corePalette' ); + colorGradientSettings.colors = useMemo( () => { const result = []; - if ( coreColors && coreColors.length ) { + if ( shouldDisplayCoreColors && coreColors && coreColors.length ) { result.push( { name: __( 'Core' ), colors: coreColors, @@ -201,9 +203,14 @@ const PanelColorGradientSettingsMultipleSelect = ( props ) => { const userGradients = useSetting( 'color.gradients.user' ); const themeGradients = useSetting( 'color.gradients.theme' ); const coreGradients = useSetting( 'color.gradients.core' ); + const shouldDisplayCoreGradients = useSetting( 'color.coreGradients' ); colorGradientSettings.gradients = useMemo( () => { const result = []; - if ( coreGradients && coreGradients.length ) { + if ( + shouldDisplayCoreGradients && + coreGradients && + coreGradients.length + ) { result.push( { name: __( 'Core' ), gradients: coreGradients, diff --git a/schemas/json/theme.json b/schemas/json/theme.json index 20b4950eb2bf6..982703a8b5332 100644 --- a/schemas/json/theme.json +++ b/schemas/json/theme.json @@ -45,6 +45,16 @@ "type": "boolean", "default": true }, + "corePalette": { + "description": "Allow users to choose colors from the Core palette. \nGutenberg plugin required.", + "type": "boolean", + "default": true + }, + "coreGradients": { + "description": "Allow users to choose colors from the Core gradients. \nGutenberg plugin required.", + "type": "boolean", + "default": true + }, "custom": { "description": "Allow users to select custom colors.\nSince 5.8.", "type": "boolean",