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

Apply ! important to user preset styles for theme.json themes only #39660

Closed
Closed
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,44 @@ public function get_data() {
return $flattened_theme_json;
}

/**
* Given a settings array, it returns the generated rulesets
* for the preset classes.
*
* @param array $settings Settings to process.
* @param string $selector Selector wrapping the classes.
* @param array $origins List of origins to process.
* @return string The result of processing the presets.
*/
protected static function compute_preset_classes( $settings, $selector, $origins ) {
if ( static::ROOT_BLOCK_SELECTOR === $selector ) {
// Classes at the global level do not need any CSS prefixed,
// and we don't want to increase its specificity.
$selector = '';
}

$stylesheet = '';
foreach ( static::PRESETS_METADATA as $preset_metadata ) {
$slugs = static::get_settings_slugs( $settings, $preset_metadata, $origins );
foreach ( $preset_metadata['classes'] as $class => $property ) {
foreach ( $slugs as $slug ) {
$css_var = static::replace_slug_in_string( $preset_metadata['css_vars'], $slug );
$class_name = static::replace_slug_in_string( $class, $slug );
$prioritise_user_presets = ( WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) ? '!important' : '';

$stylesheet .= static::to_ruleset(
static::append_to_selector( $selector, $class_name ),
array(
array(
'name' => $property,
'value' => 'var(' . $css_var . ')' . $prioritise_user_presets,
),
)
);
}
}
}

return $stylesheet;
}
}