Skip to content

Commit

Permalink
Fix: allow themes to opt out from core color palette (#36492)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiankaegy committed Nov 15, 2021
1 parent 73e6f60 commit ad47f05
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/how-to-guides/themes/theme-json.md
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lib/class-wp-theme-json-gutenberg.php
Expand Up @@ -89,6 +89,8 @@ class WP_Theme_JSON_Gutenberg {
),
'color' => array(
'background' => null,
'corePalette' => null,
'coreGradients' => null,
'custom' => null,
'customDuotone' => null,
'customGradient' => null,
Expand Down
2 changes: 2 additions & 0 deletions lib/theme.json
Expand Up @@ -170,6 +170,8 @@
}
],
"custom": true,
"corePalette": true,
"coreGradients": true,
"customDuotone": true,
"customGradient": true,
"link": false,
Expand Down
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions schemas/json/theme.json
Expand Up @@ -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",
Expand Down

0 comments on commit ad47f05

Please sign in to comment.