Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print minified css for global styles #24924

Merged
21 changes: 16 additions & 5 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ function gutenberg_experimental_global_styles_resolver( $tree ) {
// so that existing link colors themes used didn't break.
// We add this here to make it work for themes that opt-in to theme.json
// In the future, we may do this differently.
$stylesheet .= 'a { color: var(--wp--style--color--link, #00e); }';
$stylesheet .= 'a{color:var(--wp--style--color--link, #00e);}';
}

return $stylesheet;
Expand All @@ -479,13 +479,24 @@ function gutenberg_experimental_global_styles_resolver_styles( $block_selector,
// 1) The style attributes the block has declared support for.
// 2) Any CSS custom property attached to the node.
if ( in_array( $property, $block_supports, true ) || strstr( $property, '--' ) ) {
$css_declarations .= "\t" . $property . ': ' . $value . ";\n";

// Add whitespace if SCRIPT_DEBUG is defined and set to true.
$css_declarations .= ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
? "\t" . $property . ': ' . $value . ";\n"
: $property . ':' . $value . ';';
}
}

if ( '' !== $css_declarations ) {
$css_rule .= $block_selector . " {\n";
$css_rule .= $css_declarations;
$css_rule .= "}\n";

// Add whitespace if SCRIPT_DEBUG is defined and set to true.
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
$css_rule .= $block_selector . " {\n";
$css_rule .= $css_declarations;
$css_rule .= "}\n";
} else {
$css_rule .= $block_selector . '{' . $css_declarations . '}';
}
}

return $css_rule;
Expand Down