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
Global Styles: absorb editor settings transformation in WP_Theme_JSON #30610
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,107 +5,6 @@ | |
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been moved verbatim to $all_blocks = WP_Theme_JSON::ALL_BLOCKS_NAME;
$theme_settings = array();
$theme_settings['settings'] = array();
$theme_settings['settings'][ $all_blocks ] = array(); that were collapsed into one: $theme_settings = array( 'settings' => array() ); |
||
* Returns the theme presets registered via add_theme_support, if any. | ||
* | ||
* @param array $settings Existing editor settings. | ||
* | ||
* @return array Config that adheres to the theme.json schema. | ||
*/ | ||
function gutenberg_experimental_global_styles_get_theme_support_settings( $settings ) { | ||
$all_blocks = WP_Theme_JSON::ALL_BLOCKS_NAME; | ||
$theme_settings = array(); | ||
$theme_settings['settings'] = array(); | ||
$theme_settings['settings'][ $all_blocks ] = array(); | ||
|
||
// Deprecated theme supports. | ||
if ( isset( $settings['disableCustomColors'] ) ) { | ||
if ( ! isset( $theme_settings['settings'][ $all_blocks ]['color'] ) ) { | ||
$theme_settings['settings'][ $all_blocks ]['color'] = array(); | ||
} | ||
$theme_settings['settings'][ $all_blocks ]['color']['custom'] = ! $settings['disableCustomColors']; | ||
} | ||
|
||
if ( isset( $settings['disableCustomGradients'] ) ) { | ||
if ( ! isset( $theme_settings['settings'][ $all_blocks ]['color'] ) ) { | ||
$theme_settings['settings'][ $all_blocks ]['color'] = array(); | ||
} | ||
$theme_settings['settings'][ $all_blocks ]['color']['customGradient'] = ! $settings['disableCustomGradients']; | ||
} | ||
|
||
if ( isset( $settings['disableCustomFontSizes'] ) ) { | ||
if ( ! isset( $theme_settings['settings'][ $all_blocks ]['typography'] ) ) { | ||
$theme_settings['settings'][ $all_blocks ]['typography'] = array(); | ||
} | ||
$theme_settings['settings'][ $all_blocks ]['typography']['customFontSize'] = ! $settings['disableCustomFontSizes']; | ||
} | ||
|
||
if ( isset( $settings['enableCustomLineHeight'] ) ) { | ||
if ( ! isset( $theme_settings['settings'][ $all_blocks ]['typography'] ) ) { | ||
$theme_settings['settings'][ $all_blocks ]['typography'] = array(); | ||
} | ||
$theme_settings['settings'][ $all_blocks ]['typography']['customLineHeight'] = $settings['enableCustomLineHeight']; | ||
} | ||
|
||
if ( isset( $settings['enableCustomUnits'] ) ) { | ||
if ( ! isset( $theme_settings['settings'][ $all_blocks ]['spacing'] ) ) { | ||
$theme_settings['settings'][ $all_blocks ]['spacing'] = array(); | ||
} | ||
$theme_settings['settings'][ $all_blocks ]['spacing']['units'] = ( true === $settings['enableCustomUnits'] ) ? | ||
array( 'px', 'em', 'rem', 'vh', 'vw' ) : | ||
$settings['enableCustomUnits']; | ||
} | ||
|
||
if ( isset( $settings['colors'] ) ) { | ||
if ( ! isset( $theme_settings['settings'][ $all_blocks ]['color'] ) ) { | ||
$theme_settings['settings'][ $all_blocks ]['color'] = array(); | ||
} | ||
$theme_settings['settings'][ $all_blocks ]['color']['palette'] = $settings['colors']; | ||
} | ||
|
||
if ( isset( $settings['gradients'] ) ) { | ||
if ( ! isset( $theme_settings['settings'][ $all_blocks ]['color'] ) ) { | ||
$theme_settings['settings'][ $all_blocks ]['color'] = array(); | ||
} | ||
$theme_settings['settings'][ $all_blocks ]['color']['gradients'] = $settings['gradients']; | ||
} | ||
|
||
if ( isset( $settings['fontSizes'] ) ) { | ||
$font_sizes = $settings['fontSizes']; | ||
// Back-compatibility for presets without units. | ||
foreach ( $font_sizes as $key => $font_size ) { | ||
if ( is_numeric( $font_size['size'] ) ) { | ||
$font_sizes[ $key ]['size'] = $font_size['size'] . 'px'; | ||
} | ||
} | ||
if ( ! isset( $theme_settings['settings'][ $all_blocks ]['typography'] ) ) { | ||
$theme_settings['settings'][ $all_blocks ]['typography'] = array(); | ||
} | ||
$theme_settings['settings'][ $all_blocks ]['typography']['fontSizes'] = $font_sizes; | ||
} | ||
|
||
// This allows to make the plugin work with WordPress 5.7 beta | ||
// as well as lower versions. The second check can be removed | ||
// as soon as the minimum WordPress version for the plugin | ||
// is bumped to 5.7. | ||
if ( isset( $settings['enableCustomSpacing'] ) ) { | ||
if ( ! isset( $theme_settings['settings'][ $all_blocks ]['spacing'] ) ) { | ||
$theme_settings['settings'][ $all_blocks ]['spacing'] = array(); | ||
} | ||
$theme_settings['settings'][ $all_blocks ]['spacing']['customPadding'] = $settings['enableCustomSpacing']; | ||
} | ||
|
||
// Things that didn't land in core yet, so didn't have a setting assigned. | ||
if ( current( (array) get_theme_support( 'experimental-link-color' ) ) ) { | ||
if ( ! isset( $theme_settings['settings'][ $all_blocks ]['color'] ) ) { | ||
$theme_settings['settings'][ $all_blocks ]['color'] = array(); | ||
} | ||
$theme_settings['settings'][ $all_blocks ]['color']['link'] = true; | ||
} | ||
|
||
return $theme_settings; | ||
} | ||
|
||
/** | ||
* Takes a tree adhering to the theme.json schema and generates | ||
* the corresponding stylesheet. | ||
|
@@ -165,7 +64,7 @@ function gutenberg_experimental_global_styles_enqueue_assets() { | |
} | ||
|
||
$settings = gutenberg_get_common_block_editor_settings(); | ||
$theme_support_data = gutenberg_experimental_global_styles_get_theme_support_settings( $settings ); | ||
$theme_support_data = WP_Theme_JSON::get_from_editor_settings( $settings ); | ||
|
||
$all = WP_Theme_JSON_Resolver::get_merged_data( $theme_support_data ); | ||
|
||
|
@@ -186,7 +85,7 @@ function gutenberg_experimental_global_styles_enqueue_assets() { | |
* @return array New block editor settings | ||
*/ | ||
function gutenberg_experimental_global_styles_settings( $settings ) { | ||
$theme_support_data = gutenberg_experimental_global_styles_get_theme_support_settings( $settings ); | ||
$theme_support_data = WP_Theme_JSON::get_from_editor_settings( $settings ); | ||
unset( $settings['colors'] ); | ||
unset( $settings['disableCustomColors'] ); | ||
unset( $settings['disableCustomFontSizes'] ); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a leftover I found, so I thought I'd remove it here as well.