Make WordPress Core

Ticket #25580: 25580.diff

File 25580.diff, 4.3 KB (added by obenland, 13 years ago)
  • wp-content/themes/twentyfourteen/inc/customizer.php

     
    2020
    2121        $wp_customize->add_setting( 'accent_color', array(
    2222                'default'           => '#24890d',
    23                 'sanitize_callback' => 'twentyfourteen_generate_accent_colors',
     23                'sanitize_callback' => 'sanitize_hex_color',
    2424        ) );
    2525
    2626        $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'accent_color', array(
     
    2828                'section'  => 'colors',
    2929                'settings' => 'accent_color',
    3030        ) ) );
     31
     32        add_filter( 'theme_mod_accent_hover',  'twentyfourteen_accent_hover'  );
     33        add_filter( 'theme_mod_accent_active', 'twentyfourteen_accent_active' );
    3134}
    3235add_action( 'customize_register', 'twentyfourteen_customize_register' );
    3336
     
    4245add_action( 'customize_preview_init', 'twentyfourteen_customize_preview_js' );
    4346
    4447/**
    45  * Generate two variants of the accent color, return the original, and
    46  * save the others as theme mods.
    47  *
    48  * @since Twenty Fourteen 1.0
    49  *
    50  * @param string $color The original color.
    51  * @return string $color The original color, sanitized.
    52  */
    53 function twentyfourteen_generate_accent_colors( $color ) {
    54         $color = sanitize_hex_color( $color );
    55 
    56         set_theme_mod( 'accent_lighter', twentyfourteen_adjust_color( $color, 14 ) );
    57         set_theme_mod( 'accent_much_lighter', twentyfourteen_adjust_color( $color, 71 ) );
    58 
    59         return $color;
    60 }
    61 
    62 /**
    6348 * Tweak the brightness of a color by adjusting the RGB values by the given interval.
    6449 *
    6550 * Use positive values of $steps to brighten the color and negative values to darken the color.
     
    9681}
    9782
    9883/**
     84 * Returns a slightly lighter color than what is set as the theme's
     85 * accent color.
     86 *
     87 * @since Twenty Fourteen 1.0
     88 *
     89 * @return string
     90 */
     91function twentyfourteen_accent_hover() {
     92        return twentyfourteen_adjust_color( get_theme_mod( 'accent_color' ), 14 );
     93}
     94
     95/**
     96 * Returns a lighter color than what is set as the theme's accent color.
     97 *
     98 * @since Twenty Fourteen 1.0
     99 *
     100 * @return string
     101 */
     102function twentyfourteen_accent_active() {
     103        return twentyfourteen_adjust_color( get_theme_mod( 'accent_color' ), 71 );
     104}
     105
     106/**
     107 * Caches the secondary colors for the theme's accent color.
     108 *
     109 * @since Twenty Fourteen 1.0
     110 *
     111 * @return void
     112 */
     113function twentyfourteen_rebuild_accent_colors() {
     114        set_theme_mod( 'accent_hover',  twentyfourteen_accent_hover()  );
     115        set_theme_mod( 'accent_active', twentyfourteen_accent_active() );
     116}
     117add_action( 'update_option_theme_mods_twentyfourteen', 'twentyfourteen_rebuild_accent_colors' );
     118
     119/**
    99120 * Output the CSS for the Theme Customizer options.
    100121 *
    101122 * @since Twenty Fourteen 1.0
     
    103124 * @return void
    104125 */
    105126function twentyfourteen_customizer_styles() {
    106         $accent_color = get_theme_mod( 'accent_color' );
     127        $accent_color = get_theme_mod( 'accent_color', '#24890d' );
    107128
    108129        // Don't do anything if the current color is the default.
    109130        if ( '#24890d' === $accent_color )
    110131                return;
    111132
    112         $accent_lighter = get_theme_mod( 'accent_lighter' );
    113         $accent_much_lighter = get_theme_mod( 'accent_much_lighter' );
     133        $accent_hover  = get_theme_mod( 'accent_hover' );
     134        $accent_active = get_theme_mod( 'accent_active' );
    114135
    115136        $css = '<style type="text/css" id="twentyfourteen-accent-color">
    116137                /* Custom accent color. */
     
    175196                input[type="reset"]:focus,
    176197                input[type="submit"]:focus,
    177198                .widget_calendar tbody a:hover {
    178                         background-color: ' . $accent_lighter . ';
     199                        background-color: ' . $accent_hover . ';
    179200                }
    180201
    181202                /* Generated variant of custom accent color: much lighter. */
     
    183204                html input[type="button"]:active,
    184205                input[type="reset"]:active,
    185206                input[type="submit"]:active {
    186                         background-color: ' . $accent_much_lighter . ';
     207                        background-color: ' . $accent_active . ';
    187208                }
    188209
    189210                a:hover,
     
    196217                #secondary .current-menu-item > a,
    197218                .featured-content a:hover,
    198219                .featured-content .more-link,
    199                 .widget-area a:hover {
    200                         color: ' . $accent_much_lighter . ';
     220                .widget-area a:hover,
     221                .content-sidebar .widget_twentyfourteen_ephemera .post-format-archive-link:hover {
     222                        color: ' . $accent_active . ';
    201223                }
    202224                </style>';
    203225