diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 708b1563248f3f..01ad8cae629451 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -44,7 +44,7 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support // Use a unique store to avoid conflicts with other stores and implementations. $store = WP_Style_Engine_CSS_Rules_Store_Gutenberg::get_store( 'block-supports/layout/' . md5( $selector ) ); $processor = new WP_Style_Engine_Processor_Gutenberg( $store ); - return $processor->get_css(); + return $processor->get_css( true ); } /** diff --git a/lib/compat/wordpress-6.1/script-loader.php b/lib/compat/wordpress-6.1/script-loader.php index 11b0382ac38211..c63db102bf243e 100644 --- a/lib/compat/wordpress-6.1/script-loader.php +++ b/lib/compat/wordpress-6.1/script-loader.php @@ -52,7 +52,7 @@ function gutenberg_enqueue_style_engine_store( $store_name ) { static function () use ( $store_name ) { $store = WP_Style_Engine_CSS_Rules_Store_Gutenberg::get_store( $store_name ); $processor = new WP_Style_Engine_Processor_Gutenberg( $store ); - $css = $processor->get_css(); + $css = $processor->get_css( true ); if ( $css ) { echo ''; } diff --git a/packages/style-engine/class-wp-style-engine-processor.php b/packages/style-engine/class-wp-style-engine-processor.php index 2f00635c2b98b8..e23bda25f8b5c7 100644 --- a/packages/style-engine/class-wp-style-engine-processor.php +++ b/packages/style-engine/class-wp-style-engine-processor.php @@ -37,9 +37,11 @@ public function __construct( WP_Style_Engine_CSS_Rules_Store $store ) { /** * Get the CSS rules as a string. * + * @param bool $remove_printed_rules Whether to remove printed rules. + * * @return string The computed CSS. */ - public function get_css() { + public function get_css( $remove_printed_rules = false ) { // Combine CSS selectors that have identical declarations. $this->combine_rules_selectors(); @@ -49,8 +51,10 @@ public function get_css() { foreach ( $rules as $rule ) { // Add the CSS. $css .= $rule->get_css(); - // Remove the rule from the store to avoid double-rendering. - $this->store->remove_rule( $rule->get_selector() ); + if ( $remove_printed_rules ) { + // Remove the rule from the store to avoid double-rendering. + $this->store->remove_rule( $rule->get_selector() ); + } } return $css; }