Skip to content

Commit

Permalink
Update token
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Feb 11, 2020
1 parent 876492b commit 7efa53e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ function gutenberg_experimental_global_styles_has_theme_support() {
* and its values the CSS custom properties' values.
*
* @param array $global_styles Global Styles object to process.
* @param string $prefix Prefix to append to each variable.
* @param string $prefix Prefix to prepend to each variable.
* @param string $token Token to use between levels.
*
* @return array The flattened tree.
*/
function gutenberg_experimental_global_styles_get_css_vars( $global_styles, $prefix = '' ) {
function gutenberg_experimental_global_styles_get_css_vars( $global_styles, $prefix = '', $token = '--' ) {
$result = array();
foreach ( $global_styles as $key => $value ) {
$new_key = $prefix . str_replace( '/', '-', $key );

if ( is_array( $value ) ) {
$result = array_merge(
$new_prefix = $new_key . $token;
$result = array_merge(
$result,
gutenberg_experimental_global_styles_get_css_vars( $value, $new_key . '-' )
gutenberg_experimental_global_styles_get_css_vars( $value, $new_prefix, $token )
);
} else {
$result[ $new_key ] = $value;
Expand Down Expand Up @@ -170,7 +173,9 @@ function gutenberg_experimental_global_styles_get_theme() {
function gutenberg_experimental_global_styles_resolver( $global_styles ) {
$css_rule = '';

$css_vars = gutenberg_experimental_global_styles_get_css_vars( $global_styles, '--wp-' );
$token = '--';
$prefix = '--wp' . $token;
$css_vars = gutenberg_experimental_global_styles_get_css_vars( $global_styles, $prefix, $token );
if ( empty( $css_vars ) ) {
return $css_rule;
}
Expand Down

0 comments on commit 7efa53e

Please sign in to comment.