1616trait CssVariablesTrait
1717{
1818 /**
19- * Get Global Manifest.json and return globalVariables as CSS variables.
19+ * Get Global Manifest.json and return globalVariables as CSS variables. Not wrapped in a style tag.
2020 *
2121 * @param array<string, mixed> $globalSettings Global settings.
2222 *
2323 * @return string
2424 */
25- public static function outputCssVariablesGlobal (array $ globalSettings = []): string
25+ public static function outputCssVariablesGlobalClean (array $ globalSettings = []): string
2626 {
2727 $ output = '' ;
2828
@@ -38,9 +38,7 @@ public static function outputCssVariablesGlobal(array $globalSettings = []): str
3838 }
3939 }
4040
41- $ id = Helpers::getConfigOutputCssSelectorName ();
42-
43- $ output = "<style id=' {$ id }-global'>:root { {$ output }}</style> " ;
41+ $ output = ":root { {$ output }} " ;
4442
4543 if (Helpers::getConfigOutputCssOptimize ()) {
4644 $ output = \str_replace (["\n" , "\r" ], '' , $ output );
@@ -49,6 +47,21 @@ public static function outputCssVariablesGlobal(array $globalSettings = []): str
4947 return $ output ;
5048 }
5149
50+ /**
51+ * Get Global Manifest.json and return globalVariables as CSS variables. Wrapped in a style tag.
52+ *
53+ * @param array<string, mixed> $globalSettings Global settings.
54+ *
55+ * @return string
56+ */
57+ public static function outputCssVariablesGlobal (array $ globalSettings = []): string
58+ {
59+ $ output = self ::outputCssVariablesGlobalClean ($ globalSettings );
60+ $ id = Helpers::getConfigOutputCssSelectorName () . '-global ' ;
61+
62+ return "<style id=' {$ id }'> {$ output }</style> " ;
63+ }
64+
5265 /**
5366 * Get component/block options and process them in CSS variables.
5467 *
@@ -142,13 +155,13 @@ static function ($key) use ($attributes) {
142155 }
143156
144157 /**
145- * Output css variables as a one inline style tag. Used with wp_footer filter.
158+ * Output css variables as a one inline style tag. Used with wp_footer filter. Not wrapped in a style tag.
146159 *
147160 * @param array<string, mixed> $globalSettings Global settings.
148161 *
149162 * @return string
150163 */
151- public static function outputCssVariablesInline (array $ globalSettings = []): string
164+ public static function outputCssVariablesInlineClean (array $ globalSettings = []): string
152165 {
153166 // Load normal styles if server side render is used.
154167 $ context = isset ($ _GET ['context ' ]) ? \sanitize_text_field (\wp_unslash ($ _GET ['context ' ])) : '' ; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
@@ -266,9 +279,22 @@ static function () {
266279 $ additionalStyles = Helpers::getConfigOutputCssGloballyAdditionalStyles ();
267280 $ additionalStylesOutput = $ additionalStyles ? \esc_html (\implode ("; \n" , $ additionalStyles )) : '' ;
268281
282+ return "{$ output } {$ additionalStylesOutput }" ;
283+ }
284+
285+ /**
286+ * Output css variables as a one inline style tag. Used with wp_footer filter. Wrapped in a style tag.
287+ *
288+ * @param array<string, mixed> $globalSettings Global settings.
289+ *
290+ * @return string
291+ */
292+ public static function outputCssVariablesInline (array $ globalSettings = []): string
293+ {
294+ $ output = self ::outputCssVariablesInlineClean ($ globalSettings );
269295 $ selector = Helpers::getConfigOutputCssSelectorName ();
270296
271- return "<style id=' {$ selector }'> {$ output } { $ additionalStylesOutput } </style> " ;
297+ return "<style id=' {$ selector }'> {$ output }</style> " ;
272298 }
273299
274300 /**
@@ -366,9 +392,9 @@ private static function getCssVariablesTypeDefault(string $name, array $data, ar
366392
367393 // Prepare final output for testing.
368394 $ fullOutput = "
369- {$ output }
370- {$ manual }
371- " ;
395+ {$ output }
396+ {$ manual }
397+ " ;
372398
373399 // Check if final output is empty and and remove if it is.
374400 if (empty (\trim ($ fullOutput ))) {
0 commit comments