Skip to content

Commit

Permalink
Block Editor: Add Global Settings support using theme.json file.
Browse files Browse the repository at this point in the history
This is the first piece of landing the theme.json processing in WordPress core. 
It allows themes to configure the different editor settings, allow cusomizations and define presets in theme.json file.
 
Props jorgefilipecosta, nosolosw.
See #53175.

Built from https://develop.svn.wordpress.org/trunk@50959


git-svn-id: http://core.svn.wordpress.org/trunk@50568 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
youknowriad committed May 24, 2021
1 parent 6c05780 commit 4e1dc7a
Show file tree
Hide file tree
Showing 7 changed files with 1,062 additions and 1 deletion.
44 changes: 44 additions & 0 deletions wp-includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,50 @@ function get_block_editor_settings( $editor_name, $custom_settings = array() ) {
$custom_settings
);

$editor_settings['__experimentalFeatures'] = WP_Theme_JSON_Resolver::get_merged_data( $editor_settings )->get_settings();

// These settings may need to be updated based on data coming from theme.json sources.
if ( isset( $editor_settings['__experimentalFeatures']['color']['palette'] ) ) {
$editor_settings['colors'] = $editor_settings['__experimentalFeatures']['color']['palette'];
unset( $editor_settings['__experimentalFeatures']['color']['palette'] );
}
if ( isset( $editor_settings['__experimentalFeatures']['color']['gradients'] ) ) {
$editor_settings['gradients'] = $editor_settings['__experimentalFeatures']['color']['gradients'];
unset( $editor_settings['__experimentalFeatures']['color']['gradients'] );
}
if ( isset( $editor_settings['__experimentalFeatures']['color']['custom'] ) ) {
$editor_settings['disableCustomColors'] = $editor_settings['__experimentalFeatures']['color']['custom'];
unset( $editor_settings['__experimentalFeatures']['color']['custom'] );
}
if ( isset( $editor_settings['__experimentalFeatures']['color']['customGradient'] ) ) {
$editor_settings['disableCustomGradients'] = $editor_settings['__experimentalFeatures']['color']['customGradient'];
unset( $editor_settings['__experimentalFeatures']['color']['customGradient'] );
}
if ( isset( $editor_settings['__experimentalFeatures']['typography']['fontSizes'] ) ) {
$editor_settings['fontSizes'] = $editor_settings['__experimentalFeatures']['typography']['fontSizes'];
unset( $editor_settings['__experimentalFeatures']['typography']['fontSizes'] );
}
if ( isset( $editor_settings['__experimentalFeatures']['typography']['customFontSize'] ) ) {
$editor_settings['disableCustomFontSizes'] = $editor_settings['__experimentalFeatures']['typography']['customFontSize'];
unset( $editor_settings['__experimentalFeatures']['typography']['customFontSize'] );
}
if ( isset( $editor_settings['__experimentalFeatures']['typography']['customLineHeight'] ) ) {
$editor_settings['enableCustomLineHeight'] = $editor_settings['__experimentalFeatures']['typography']['customLineHeight'];
unset( $editor_settings['__experimentalFeatures']['typography']['customLineHeight'] );
}
if ( isset( $editor_settings['__experimentalFeatures']['spacing']['units'] ) ) {
if ( ! is_array( $editor_settings['__experimentalFeatures']['spacing']['units'] ) ) {
$editor_settings['enableCustomUnits'] = false;
} else {
$editor_settings['enableCustomUnits'] = count( $editor_settings['__experimentalFeatures']['spacing']['units'] ) > 0;
}
unset( $editor_settings['__experimentalFeatures']['spacing']['units'] );
}
if ( isset( $editor_settings['__experimentalFeatures']['spacing']['customPadding'] ) ) {
$editor_settings['enableCustomSpacing'] = $editor_settings['__experimentalFeatures']['spacing']['customPadding'];
unset( $editor_settings['__experimentalFeatures']['spacing']['customPadding'] );
}

/**
* Filters the settings to pass to the block editor for all editor type.
*
Expand Down
Loading

0 comments on commit 4e1dc7a

Please sign in to comment.