Skip to content

Commit

Permalink
Expose presets declared via add_theme_support in global styles (#22076)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosolosw authored May 6, 2020
1 parent 7da5571 commit 1b649a7
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,56 @@ function gutenberg_experimental_global_styles_get_core() {
}

/**
* Return theme's Global Styles.
* Return theme's Global Styles. It also fetches the editor palettes
* declared via add_theme_support.
*
* @return array Global Styles tree.
*/
function gutenberg_experimental_global_styles_get_theme() {
return gutenberg_experimental_global_styles_get_from_file(
locate_template( 'experimental-theme.json' )
$theme_supports = array();
// Take colors from declared theme support.
$theme_colors = get_theme_support( 'editor-color-palette' )[0];
if ( is_array( $theme_colors ) ) {
foreach ( $theme_colors as $color ) {
$theme_supports['preset']['color'][ $color['slug'] ] = $color['color'];
}
}

// Take gradients from declared theme support.
$theme_gradients = get_theme_support( 'editor-gradient-presets' )[0];
if ( is_array( $theme_gradients ) ) {
foreach ( $theme_gradients as $gradient ) {
$theme_supports['preset']['gradient'][ $gradient['slug'] ] = $gradient['gradient'];
}
}

// Take font-sizes from declared theme support.
$theme_font_sizes = get_theme_support( 'editor-font-sizes' )[0];
if ( is_array( $theme_font_sizes ) ) {
foreach ( $theme_font_sizes as $font_size ) {
$theme_supports['preset']['font-size'][ $font_size['slug'] ] = $font_size['size'];
}
}

/*
* We want the presets declared in theme.json
* to take precedence over the ones declared via add_theme_support.
*
* However, at the moment, it's not clear how we're going to declare them
* in theme.json until we resolve issues related to i18n and
* unfold the proper theme.json hierarchy. See:
*
* https://github.com/wp-cli/i18n-command/pull/210
* https://github.com/WordPress/gutenberg/issues/20588
*
* Hence, for simplicity, we take here the existing presets
* from the add_theme_support, if any.
*/
return array_merge(
gutenberg_experimental_global_styles_get_from_file(
locate_template( 'experimental-theme.json' )
),
$theme_supports
);
}

Expand Down

0 comments on commit 1b649a7

Please sign in to comment.