Skip to content

Commit

Permalink
Fix theme & user specificity
Browse files Browse the repository at this point in the history
Some properties can be styled by the user
and will end up having preset classes attached to the block
such as `.has-text-color .has-red-color`, etc.

In those cases, we want the user preferences
to overrule the theme's, hence we prevent the theme styles
from being used when the users have set styles themselves.
  • Loading branch information
oandregal committed Mar 3, 2021
1 parent ee1b70d commit cd3fd8e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,39 @@ private function get_block_styles() {
);
}

// Some properties can be styled by the user
// and will end up having preset classes attached to the block
// such as `.has-text-color .has-red-color`, etc.
//
// In those cases, we want the user preferences
// to overrule the theme's, hence this negations.
foreach ( $declarations as $index => $property ) {
if ( 'color' === $property['name'] ) {
$block_rules .= self::to_ruleset(
$selector . ':not([class*=has-text-color])',
array( $property )
);
unset( $declarations[ $index ] );
}

if ( in_array( $property['name'], array( 'background', 'background-color' ) ) ) {
$block_rules .= self::to_ruleset(
$selector . ':not([class*=has-background-color])',
array( $property )
);
unset( $declarations[ $index ] );
}

if ( 'font-size' === $property['name'] ) {
$block_rules .= self::to_ruleset(
$selector . ':not([class*=-font-size])',
array( $property )
);
unset( $declarations[ $index ] );
}
}

// Attach the style rules left in one single ruleset.
$block_rules .= self::to_ruleset( $selector, $declarations );

// Attach the rulesets for the classes.
Expand Down

0 comments on commit cd3fd8e

Please sign in to comment.