Fix color modifications on shorthand hex colors

This commit is contained in:
Geert De Deckere 2012-06-14 10:14:45 +02:00
parent ff82bb3a26
commit 18af1823ae
1 changed files with 6 additions and 2 deletions

View File

@ -495,6 +495,8 @@ function woocommerce_get_formatted_variation( $variation = '', $flat = false ) {
if (!function_exists('woocommerce_hex_darker')) {
function woocommerce_hex_darker( $color, $factor = 30 ) {
$color = str_replace('#', '', $color);
// Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
$color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
$base['R'] = hexdec($color{0}.$color{1});
$base['G'] = hexdec($color{2}.$color{3});
@ -520,6 +522,8 @@ if (!function_exists('woocommerce_hex_darker')) {
if (!function_exists('woocommerce_hex_lighter')) {
function woocommerce_hex_lighter( $color, $factor = 30 ) {
$color = str_replace('#', '', $color);
// Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
$color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
$base['R'] = hexdec($color{0}.$color{1});
$base['G'] = hexdec($color{2}.$color{3});