Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FSE: Allow themes to opt in to wp-block-styles using theme.json #40097

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,54 @@
*/
class WP_Theme_JSON_Gutenberg extends WP_Theme_JSON_5_9 {

const VALID_SETTINGS = array(
'appearanceTools' => null,
'border' => array(
'color' => null,
'radius' => null,
'style' => null,
'width' => null,
),
'color' => array(
'background' => null,
'custom' => null,
'customDuotone' => null,
'customGradient' => null,
'defaultDuotone' => null,
'defaultGradients' => null,
'defaultPalette' => null,
'duotone' => null,
'gradients' => null,
'link' => null,
'palette' => null,
'text' => null,
),
'custom' => null,
'defaultBlockStyles' => null,
Copy link
Contributor Author

@scruffian scruffian Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change. Should I just add this to the array in the construct?

'layout' => array(
'contentSize' => null,
'wideSize' => null,
),
'spacing' => array(
'blockGap' => null,
'margin' => null,
'padding' => null,
'units' => null,
),
'typography' => array(
'customFontSize' => null,
'dropCap' => null,
'fontFamilies' => null,
'fontSizes' => null,
'fontStyle' => null,
'fontWeight' => null,
'letterSpacing' => null,
'lineHeight' => null,
'textDecoration' => null,
'textTransform' => null,
),
);

/**
* The top-level keys a theme.json can have.
*
Expand All @@ -31,6 +79,34 @@ class WP_Theme_JSON_Gutenberg extends WP_Theme_JSON_5_9 {
'title',
);

/**
* Constructor.
*
* @param array $theme_json A structure that follows the theme.json schema.
* @param string $origin Optional. What source of data this object represents.
* One of 'default', 'theme', or 'custom'. Default 'theme'.
*/
public function __construct( $theme_json = array(), $origin = 'theme' ) {
parent::__construct( $theme_json, $origin );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we don't do this more?


static::maybe_opt_in_into_theme_supports( $theme_json );
}

/**
* Enables some theme_supports if the theme.json declares support.
*
* @param array $theme_json A theme.json structure to modify.
* @return null
*/
protected static function maybe_opt_in_into_theme_supports( $theme_json ) {
if (
isset( $theme_json['settings']['defaultBlockStyles'] ) &&
true === $theme_json['settings']['defaultBlockStyles']
) {
add_theme_support( 'wp-block-styles' );
}
}

/**
* Returns the current theme's wanted patterns(slugs) to be
* registered from Pattern Directory.
Expand Down
9 changes: 9 additions & 0 deletions schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@
}
}
},
"settingsPropertiesDefaultBlockStyles": {
"properties": {
"defaultBlockStyles": {
"description": "Setting that adds theme support for 'wp-block-styles', which loads the theme.css file for each block.",
"type": "boolean",
"default": false
}
}
},
"settingsPropertiesLayout": {
"properties": {
"layout": {
Expand Down