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.



Built from https://develop.svn.wordpress.org/trunk@59813


git-svn-id: http://core.svn.wordpress.org/trunk@59155 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
audrasjb
2025-02-11 21:06:25 +00:00
parent 08c4498647
commit 737185823f
3 changed files with 3 additions and 3 deletions

View File

@@ -288,7 +288,7 @@ class Custom_Background {
$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();

View File

@@ -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 ) . '");';

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.8-alpha-59812';
$wp_version = '6.8-alpha-59813';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.