- Timestamp:
- 11/05/2013 11:28:07 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php
r26003 r26021 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 … … 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. … … 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 * … … 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 … … 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 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 123 144 /** 124 145 * Output the CSS for the Theme Customizer options. … … 129 150 */ 130 151 function twentyfourteen_customizer_styles() { 131 $accent_color = get_theme_mod( 'accent_color' );152 $accent_color = get_theme_mod( 'accent_color', '#24890d' ); 132 153 133 154 // Don't do anything if the current color is the default. … … 135 156 return; 136 157 137 $accent_ lighter = get_theme_mod( 'accent_lighter' );138 $accent_ much_lighter = get_theme_mod( 'accent_much_lighter' );158 $accent_mid = get_theme_mod( 'accent_mid' ); 159 $accent_light = get_theme_mod( 'accent_light' ); 139 160 140 161 $css = '/* Custom accent color. */ … … 193 214 } 194 215 195 /* Generated variant of custom accent color: slightly lighter. */216 /* Generated "mid" variant of custom accent color. */ 196 217 button:hover, 197 218 button:focus, … … 221 242 .content-sidebar .widget input[type="submit"]:focus, 222 243 .slider-control-paging a:hover:before { 223 background-color: ' . $accent_ lighter. ';244 background-color: ' . $accent_mid . '; 224 245 } 225 246 … … 246 267 .site-info a:hover, 247 268 .featured-content a:hover { 248 color: ' . $accent_ lighter. ';269 color: ' . $accent_mid . '; 249 270 } 250 271 251 272 .page-links a:hover, 252 273 .paging-navigation a:hover { 253 border-color: ' . $accent_ lighter. ';274 border-color: ' . $accent_mid . '; 254 275 } 255 276 256 277 .tag-links a:hover:before { 257 border-right-color: ' . $accent_ lighter. ';278 border-right-color: ' . $accent_mid . '; 258 279 } 259 280 … … 261 282 .primary-navigation ul ul a:hover, 262 283 .primary-navigation ul ul li.focus > a { 263 background-color: ' . $accent_ lighter. ';284 background-color: ' . $accent_mid . '; 264 285 } 265 286 } … … 268 289 .secondary-navigation ul ul a:hover, 269 290 .secondary-navigation ul ul li.focus > a { 270 background-color: ' . $accent_ lighter. ';291 background-color: ' . $accent_mid . '; 271 292 } 272 293 } 273 294 274 /* Generated variant of custom accent color: much lighter. */295 /* Generated "light" variant of custom accent color. */ 275 296 button:active, 276 297 .contributor-posts-link:active, … … 284 305 .content-sidebar .widget input[type="reset"]:active, 285 306 .content-sidebar .widget input[type="submit"]:active { 286 background-color: ' . $accent_ much_lighter. ';307 background-color: ' . $accent_light . '; 287 308 } 288 309 … … 291 312 .site-navigation .current-menu-item > a, 292 313 .site-navigation .current-menu-ancestor > a { 293 color: ' . $accent_ much_lighter. ';314 color: ' . $accent_light . '; 294 315 }'; 295 316
Note: See TracChangeset
for help on using the changeset viewer.