Skip to content

Commit ef3da33

Browse files
committed
Block Editor: Add Global Settings support using theme.json file.
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. git-svn-id: https://develop.svn.wordpress.org/trunk@50959 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c0084bc commit ef3da33

File tree

11 files changed

+1730
-0
lines changed

11 files changed

+1730
-0
lines changed

src/wp-includes/block-editor.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,50 @@ function get_block_editor_settings( $editor_name, $custom_settings = array() ) {
243243
$custom_settings
244244
);
245245

246+
$editor_settings['__experimentalFeatures'] = WP_Theme_JSON_Resolver::get_merged_data( $editor_settings )->get_settings();
247+
248+
// These settings may need to be updated based on data coming from theme.json sources.
249+
if ( isset( $editor_settings['__experimentalFeatures']['color']['palette'] ) ) {
250+
$editor_settings['colors'] = $editor_settings['__experimentalFeatures']['color']['palette'];
251+
unset( $editor_settings['__experimentalFeatures']['color']['palette'] );
252+
}
253+
if ( isset( $editor_settings['__experimentalFeatures']['color']['gradients'] ) ) {
254+
$editor_settings['gradients'] = $editor_settings['__experimentalFeatures']['color']['gradients'];
255+
unset( $editor_settings['__experimentalFeatures']['color']['gradients'] );
256+
}
257+
if ( isset( $editor_settings['__experimentalFeatures']['color']['custom'] ) ) {
258+
$editor_settings['disableCustomColors'] = $editor_settings['__experimentalFeatures']['color']['custom'];
259+
unset( $editor_settings['__experimentalFeatures']['color']['custom'] );
260+
}
261+
if ( isset( $editor_settings['__experimentalFeatures']['color']['customGradient'] ) ) {
262+
$editor_settings['disableCustomGradients'] = $editor_settings['__experimentalFeatures']['color']['customGradient'];
263+
unset( $editor_settings['__experimentalFeatures']['color']['customGradient'] );
264+
}
265+
if ( isset( $editor_settings['__experimentalFeatures']['typography']['fontSizes'] ) ) {
266+
$editor_settings['fontSizes'] = $editor_settings['__experimentalFeatures']['typography']['fontSizes'];
267+
unset( $editor_settings['__experimentalFeatures']['typography']['fontSizes'] );
268+
}
269+
if ( isset( $editor_settings['__experimentalFeatures']['typography']['customFontSize'] ) ) {
270+
$editor_settings['disableCustomFontSizes'] = $editor_settings['__experimentalFeatures']['typography']['customFontSize'];
271+
unset( $editor_settings['__experimentalFeatures']['typography']['customFontSize'] );
272+
}
273+
if ( isset( $editor_settings['__experimentalFeatures']['typography']['customLineHeight'] ) ) {
274+
$editor_settings['enableCustomLineHeight'] = $editor_settings['__experimentalFeatures']['typography']['customLineHeight'];
275+
unset( $editor_settings['__experimentalFeatures']['typography']['customLineHeight'] );
276+
}
277+
if ( isset( $editor_settings['__experimentalFeatures']['spacing']['units'] ) ) {
278+
if ( ! is_array( $editor_settings['__experimentalFeatures']['spacing']['units'] ) ) {
279+
$editor_settings['enableCustomUnits'] = false;
280+
} else {
281+
$editor_settings['enableCustomUnits'] = count( $editor_settings['__experimentalFeatures']['spacing']['units'] ) > 0;
282+
}
283+
unset( $editor_settings['__experimentalFeatures']['spacing']['units'] );
284+
}
285+
if ( isset( $editor_settings['__experimentalFeatures']['spacing']['customPadding'] ) ) {
286+
$editor_settings['enableCustomSpacing'] = $editor_settings['__experimentalFeatures']['spacing']['customPadding'];
287+
unset( $editor_settings['__experimentalFeatures']['spacing']['customPadding'] );
288+
}
289+
246290
/**
247291
* Filters the settings to pass to the block editor for all editor type.
248292
*

0 commit comments

Comments
 (0)