function milky_way_generate_custom_styles($setting, $default) { $value = $color = ''; if ($setting == 'primary-menu') { $get_setting = 'menu'; } else { $get_setting = $setting; } $theme_mod = get_theme_mod('milky_way_' . $get_setting . '_bg'); if ($setting == 'primary-menu') { $value = $theme_mod && $theme_mod != $default ? ".{$setting}, .{$setting} a { background-color: " . esc_attr($theme_mod) . "; }\n" : ".{$setting}, .{$setting} a { background-color: " . $default . "; }\n"; } else { $value = $theme_mod && $theme_mod != $default ? ".{$setting} { background-color: " . esc_attr($theme_mod) . "; }\n" : ".{$setting} { background-color: " . $default . "; }\n"; } if ($value) { $default_link_color = $setting == 'header' ? '#111111' : apply_filters('milky_way_custom_link_color', '#2929EC'); $test_color = $theme_mod != '' ? esc_attr($theme_mod) : $default; $viable = milky_way_compare_contrast($test_color, $default_link_color); if ($viable) { $color = ".{$setting} { color: " . milky_way_inverse_color($test_color) . "; }\n.{$setting} a { color: {$default_link_color} }\n"; } else { $color = ".{$setting}, .{$setting} a { color: " . milky_way_inverse_color($test_color) . "; }\n"; } } return $value . $color; }
function milky_way_shift_color($color, $increment = 'medium') { $color = str_replace('#', '', $color); $rgb = ''; // Empty variable switch ($increment) { case 'small': $percent = 10; break; case 'large': $percent = 30; break; case is_numeric($increment): $percent = $increment; break; default: $percent = 20; } $percent = milky_way_inverse_color($color) == '#ffffff' ? -$percent : $percent; $per = $percent / 100 * 255; // Creates a percentage to work with. Change the middle figure to control colour temperature if ($per < 0) { // DARKER $per = abs($per); // Turns Neg Number to Pos Number for ($x = 0; $x < 3; $x++) { $c = hexdec(substr($color, 2 * $x, 2)) - $per; $c = $c < 0 ? 0 : dechex($c); $rgb .= strlen($c) < 2 ? '0' . $c : $c; } } else { // LIGHTER for ($x = 0; $x < 3; $x++) { $c = hexdec(substr($color, 2 * $x, 2)) + $per; $c = $c > 255 ? 'ff' : dechex($c); $rgb .= strlen($c) < 2 ? '0' . $c : $c; } } return '#' . $rgb; }