wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_get_state_declarations_with_background_resets › WordPress Function
Since7.1.0
Deprecatedn/a
› wp_get_state_declarations_with_background_resets ( $declarations )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
| Codex: |
Adds background reset declarations to prevent gradient/solid color conflicts.
When a state sets a solid background-color, any gradient applied to the default state (viabackground shorthand or background-image) must be
explicitly cleared. Without this, the gradient image layer remains visible
on top of the solid hover color even when !important is used, because
background-color and background-image are separate CSS properties.Source
function wp_get_state_declarations_with_background_resets( $declarations ) {
if ( ! is_array( $declarations ) ) {
return $declarations;
}
$has_background_color = isset( $declarations['background-color'] ) && '' !== $declarations['background-color'];
$has_background = isset( $declarations['background'] ) && '' !== $declarations['background'];
$has_background_image = isset( $declarations['background-image'] ) && '' !== $declarations['background-image'];
/*
* When the state sets a solid background-color but no gradient of its own,
* emit `background-image: unset !important` to clear any gradient (whether
* stored as the `background` shorthand or as `background-image`) that was
* applied to the default / normal state via an inline style attribute.
*/
if ( $has_background_color && ! $has_background && ! $has_background_image ) {
$declarations['background-image'] = 'unset !important';
}
return $declarations;
}