Skip to content

Commit

Permalink
Remove to it's own function.
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedmonkey committed Nov 29, 2022
1 parent 9e82a0b commit b0a9764
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
28 changes: 1 addition & 27 deletions lib/experimental/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,40 +65,14 @@ public static function get_theme_data( $deprecated = array(), $settings = array(
if ( ! $settings['with_supports'] ) {
return static::$theme;
}

$editor_settings = array(
'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ),
'disableLayoutStyles' => get_theme_support( 'disable-layout-styles' ),
'enableCustomLineHeight' => get_theme_support( 'custom-line-height' ),
'enableCustomSpacing' => get_theme_support( 'custom-spacing' ),
'enableCustomUnits' => get_theme_support( 'custom-units' ),
);

// Theme settings.
$color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
if ( false !== $color_palette ) {
$editor_settings['colors'] = $color_palette;
}

$font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
if ( false !== $font_sizes ) {
$editor_settings['fontSizes'] = $font_sizes;
}

$gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
if ( false !== $gradient_presets ) {
$editor_settings['gradients'] = $gradient_presets;
}

/*
* We want the presets and settings declared in theme.json
* to override the ones declared via theme supports.
* So we take theme supports, transform it to theme.json shape
* and merge the static::$theme upon that.
*/
$theme_support_data = WP_Theme_JSON_Gutenberg::get_from_editor_settings( $editor_settings );
$theme_support_data = WP_Theme_JSON_Gutenberg::get_from_editor_settings( gutenberg_get_block_theme_supports() );
if ( ! wp_theme_has_theme_json() ) {
if ( ! isset( $theme_support_data['settings']['color'] ) ) {
$theme_support_data['settings']['color'] = array();
Expand Down
38 changes: 38 additions & 0 deletions lib/experimental/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php


/**
* Repeated logic from `get_default_block_editor_settings` function. When implemented into core,
* remove logic from `get_default_block_editor_settings` and simple call this function instead.
*
* @return array
*/
function gutenberg_get_block_theme_supports(){
$theme_settings = array(
'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ),
'disableLayoutStyles' => get_theme_support( 'disable-layout-styles' ),
'enableCustomLineHeight' => get_theme_support( 'custom-line-height' ),
'enableCustomSpacing' => get_theme_support( 'custom-spacing' ),
'enableCustomUnits' => get_theme_support( 'custom-units' ),
);

// Theme settings.
$color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
if ( false !== $color_palette ) {
$theme_settings['colors'] = $color_palette;
}

$font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
if ( false !== $font_sizes ) {
$theme_settings['fontSizes'] = $font_sizes;
}

$gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
if ( false !== $gradient_presets ) {
$theme_settings['gradients'] = $gradient_presets;
}

return $theme_settings;
}
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function gutenberg_is_experiment_enabled( $name ) {
if ( ! class_exists( 'WP_HTML_Tag_Processor' ) ) {
require __DIR__ . '/experimental/html/index.php';
}
require __DIR__ . '/experimental/get-global-styles-and-settings.php';
require __DIR__ . '/experimental/class-wp-theme-json-gutenberg.php';
require __DIR__ . '/experimental/class-wp-theme-json-resolver-gutenberg.php';
require __DIR__ . '/experimental/class-wp-webfonts.php';
Expand Down

0 comments on commit b0a9764

Please sign in to comment.