From 108af60dafd3cd15d7533a59fa485eca6de63fad Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Tue, 11 Feb 2025 21:05:00 +0000 Subject: [PATCH] Themes: Avoid double hashed value for `background-color` in custom backgrounds. This changeset replaces the hardcoded hash symbol with running `maybe_hash_hex_color()` on the full `background-color` value provided via the custom background feature, so the hash is only added if it is needed. By doing so, if a theme developer sets a background color value that uses a hash (#), WordPress won't add an additional hash anymore when outputting the relevant CSS. Duplicate hash symbols (##) can break CSS background color declarations. Props hovhanneshovakimyan, joyously, poena, Fixes #40057. git-svn-id: https://develop.svn.wordpress.org/trunk@59813 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-custom-background.php | 2 +- src/wp-includes/theme.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/class-custom-background.php b/src/wp-admin/includes/class-custom-background.php index d8500d8570405..8027c6a2ce95e 100644 --- a/src/wp-admin/includes/class-custom-background.php +++ b/src/wp-admin/includes/class-custom-background.php @@ -288,7 +288,7 @@ public function admin_page() { $background_styles = ''; $bgcolor = get_background_color(); if ( $bgcolor ) { - $background_styles .= 'background-color: #' . $bgcolor . ';'; + $background_styles .= 'background-color: ' . maybe_hash_hex_color( $bgcolor ) . ';'; } $background_image_thumb = get_background_image(); diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index 1a9b2479ad7e2..5b6824b4a1073 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -1893,7 +1893,7 @@ function _custom_background_cb() { return; } - $style = $color ? "background-color: #$color;" : ''; + $style = $color ? 'background-color: ' . maybe_hash_hex_color( $color ) . ';' : ''; if ( $background ) { $image = ' background-image: url("' . sanitize_url( $background ) . '");';