Skip to content

Commit

Permalink
Added a param to the get_css() method
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Jul 19, 2022
1 parent b760d78 commit 7aa60b5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.1/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<style id="wp-style-engine-' . esc_attr( str_replace( '/', '-', $store_name ) ) . '">' . $css . '</style>';
}
Expand Down
10 changes: 7 additions & 3 deletions packages/style-engine/class-wp-style-engine-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
}
Expand Down

0 comments on commit 7aa60b5

Please sign in to comment.