Ticket #25580: 25580.2.diff
| File 25580.2.diff, 6.3 KB (added by , 13 years ago) |
|---|
-
wp-content/themes/twentyfourteen/inc/customizer.php
22 22 // Add the custom accent color setting and control. 23 23 $wp_customize->add_setting( 'accent_color', array( 24 24 'default' => '#24890d', 25 'sanitize_callback' => ' twentyfourteen_generate_accent_colors',25 'sanitize_callback' => 'sanitize_hex_color', 26 26 ) ); 27 27 28 28 $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'accent_color', array( … … 30 30 'section' => 'colors', 31 31 'settings' => 'accent_color', 32 32 ) ) ); 33 34 add_filter( 'theme_mod_accent_mid', 'twentyfourteen_accent_mid' ); 35 add_filter( 'theme_mod_accent_light', 'twentyfourteen_accent_light' ); 33 36 34 37 // Add the featured content section. 35 38 $wp_customize->add_section( 'featured_content', array( … … 67 70 add_action( 'customize_preview_init', 'twentyfourteen_customize_preview_js' ); 68 71 69 72 /** 70 * Generate two variants of the accent color, return the original, and71 * save the others as theme mods.72 *73 * @since Twenty Fourteen 1.074 *75 * @param string $color The original color.76 * @return string $color The original color, sanitized.77 */78 function twentyfourteen_generate_accent_colors( $color ) {79 $color = sanitize_hex_color( $color );80 81 set_theme_mod( 'accent_lighter', twentyfourteen_adjust_color( $color, 29 ) );82 set_theme_mod( 'accent_much_lighter', twentyfourteen_adjust_color( $color, 49 ) );83 84 return $color;85 }86 87 /**88 73 * Tweak the brightness of a color by adjusting the RGB values by the given interval. 89 74 * 90 75 * Use positive values of $steps to brighten the color and negative values to darken the color. … … (this hunk was shorter than expected) 106 91 // Convert hex to rgb. 107 92 $rgb = array( hexdec( substr( $color, 1, 2 ) ), hexdec( substr( $color, 3, 2 ) ), hexdec( substr( $color, 5, 2 ) ) ); 108 93 109 // Adjust color and switch back to hex.94 // Adjust color and switch back to 6-digit hex. 110 95 $hex = '#'; 111 foreach ( $rgb as $ c) {112 $ c+= $steps;113 if ( $ c> 255 )114 $ c= 255;115 elseif ( $ c< 0 )116 $ c= 0;117 $hex .= str_pad( dechex( $ c), 2, '0', STR_PAD_LEFT);96 foreach ( $rgb as $value ) { 97 $value += $steps; 98 if ( $value > 255 ) 99 $value = 255; 100 elseif ( $value < 0 ) 101 $value = 0; 102 $hex .= str_pad( dechex( $value ), 2, '0', STR_PAD_LEFT); 118 103 } 119 104 120 105 return $hex; 121 106 } 122 107 108 /** 109 * Returns a slightly lighter color than what is set as the theme's 110 * accent color. 111 * 112 * @since Twenty Fourteen 1.0 113 * 114 * @return string 115 */ 116 function twentyfourteen_accent_mid() { 117 return twentyfourteen_adjust_color( get_theme_mod( 'accent_color' ), 29 ); 118 } 119 123 120 /** 121 * Returns a lighter color than what is set as the theme's accent color. 122 * 123 * @since Twenty Fourteen 1.0 124 * 125 * @return string 126 */ 127 function twentyfourteen_accent_light() { 128 return twentyfourteen_adjust_color( get_theme_mod( 'accent_color' ), 49 ); 129 } 130 131 /** 132 * Caches the generated variants of the theme's accent color. 133 * 134 * @since Twenty Fourteen 1.0 135 * 136 * @return void 137 */ 138 function twentyfourteen_rebuild_accent_colors() { 139 set_theme_mod( 'accent_mid', twentyfourteen_accent_mid() ); 140 set_theme_mod( 'accent_light', twentyfourteen_accent_light() ); 141 } 142 add_action( 'update_option_theme_mods_twentyfourteen', 'twentyfourteen_rebuild_accent_colors' ); 143 144 /** 124 145 * Output the CSS for the Theme Customizer options. 125 146 * 126 147 * @since Twenty Fourteen 1.0 … … 128 151 * @return void 129 152 */ 130 153 function twentyfourteen_customizer_styles() { 131 $accent_color = get_theme_mod( 'accent_color' );154 $accent_color = get_theme_mod( 'accent_color', '#24890d' ); 132 155 133 156 // Don't do anything if the current color is the default. 134 157 if ( '#24890d' === $accent_color ) 135 158 return; 136 159 137 $accent_ lighter = get_theme_mod( 'accent_lighter' );138 $accent_ much_lighter = get_theme_mod( 'accent_much_lighter' );160 $accent_mid = get_theme_mod( 'accent_mid' ); 161 $accent_light = get_theme_mod( 'accent_light' ); 139 162 140 163 $css = '/* Custom accent color. */ 141 164 a, … … 192 215 } 193 216 } 194 217 195 /* Generated variant of custom accent color: slightly lighter. */218 /* Generated "mid" variant of custom accent color. */ 196 219 button:hover, 197 220 button:focus, 198 221 .contributor-posts-link:hover, … … 220 243 .content-sidebar .widget input[type="submit"]:hover, 221 244 .content-sidebar .widget input[type="submit"]:focus, 222 245 .slider-control-paging a:hover:before { 223 background-color: ' . $accent_ lighter. ';246 background-color: ' . $accent_mid . '; 224 247 } 225 248 226 249 a:active, … … 245 268 .content-sidebar .widget_twentyfourteen_ephemera .entry-meta a:hover, 246 269 .site-info a:hover, 247 270 .featured-content a:hover { 248 color: ' . $accent_ lighter. ';271 color: ' . $accent_mid . '; 249 272 } 250 273 251 274 .page-links a:hover, 252 275 .paging-navigation a:hover { 253 border-color: ' . $accent_ lighter. ';276 border-color: ' . $accent_mid . '; 254 277 } 255 278 256 279 .tag-links a:hover:before { 257 border-right-color: ' . $accent_ lighter. ';280 border-right-color: ' . $accent_mid . '; 258 281 } 259 282 260 283 @media screen and (min-width: 782px) { 261 284 .primary-navigation ul ul a:hover, 262 285 .primary-navigation ul ul li.focus > a { 263 background-color: ' . $accent_ lighter. ';286 background-color: ' . $accent_mid . '; 264 287 } 265 288 } 266 289 … … 267 290 @media screen and (min-width: 1008px) { 268 291 .secondary-navigation ul ul a:hover, 269 292 .secondary-navigation ul ul li.focus > a { 270 background-color: ' . $accent_ lighter. ';293 background-color: ' . $accent_mid . '; 271 294 } 272 295 } 273 296 274 /* Generated variant of custom accent color: much lighter. */297 /* Generated "light" variant of custom accent color. */ 275 298 button:active, 276 299 .contributor-posts-link:active, 277 300 input[type="button"]:active, … … 283 306 .content-sidebar .widget input[type="button"]:active, 284 307 .content-sidebar .widget input[type="reset"]:active, 285 308 .content-sidebar .widget input[type="submit"]:active { 286 background-color: ' . $accent_ much_lighter. ';309 background-color: ' . $accent_light . '; 287 310 } 288 311 289 312 .site-navigation .current_page_item > a, … … 290 313 .site-navigation .current_page_ancestor > a, 291 314 .site-navigation .current-menu-item > a, 292 315 .site-navigation .current-menu-ancestor > a { 293 color: ' . $accent_ much_lighter. ';316 color: ' . $accent_light . '; 294 317 }'; 295 318 296 319