From 95d018331536b315a3cc754bd6811f8af9c08661 Mon Sep 17 00:00:00 2001 From: Marie Comet Date: Wed, 22 Dec 2021 15:26:03 +0100 Subject: [PATCH] Allow developers to opt out of !important CSS rules generated from theme.json Proposed solution for https://github.com/WordPress/gutenberg/issues/37590 --- lib/compat/wordpress-5.9/class-wp-theme-json-gutenberg.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-gutenberg.php b/lib/compat/wordpress-5.9/class-wp-theme-json-gutenberg.php index c223b9ac96f414..c57cb5a6a1505a 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-gutenberg.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-gutenberg.php @@ -917,6 +917,11 @@ private static function compute_preset_classes( $settings, $selector, $origins ) } $stylesheet = ''; + + // Allow third party developers to opt out of !important CSS rules. + $important_rule = apply_filters( 'compute_preset_classes_important', true ); + $important = $important_rule ? ' !important' : ''; + foreach ( self::PRESETS_METADATA as $preset_metadata ) { $slugs = self::get_settings_slugs( $settings, $preset_metadata, $origins ); foreach ( $preset_metadata['classes'] as $class => $property ) { @@ -928,7 +933,7 @@ private static function compute_preset_classes( $settings, $selector, $origins ) array( array( 'name' => $property, - 'value' => 'var(' . $css_var . ') !important', + 'value' => 'var(' . $css_var . ')' . $important, ), ) );