| | 41 | |
| | 42 | /** |
| | 43 | * Generates two variants of the accent color, returns the original, and saves the others as theme mods. |
| | 44 | * |
| | 45 | */ |
| | 46 | function twentyfourteen_generate_accent_colors( $color ) { |
| | 47 | $color = sanitize_hex_color( $color ); |
| | 48 | |
| | 49 | set_theme_mod( 'accent_1', twentyfourteen_adjust_color( $color, 14 ) ); |
| | 50 | set_theme_mod( 'accent_2', twentyfourteen_adjust_color( $color, 71 ) ); |
| | 51 | |
| | 52 | return $color; |
| | 53 | } |
| | 54 | |
| | 55 | /** |
| | 56 | * Tweaks the brightness of a color by adjusting the r/g/b values by the given interval. |
| | 57 | * |
| | 58 | */ |
| | 59 | function twentyfourteen_adjust_color( $color, $steps ) { |
| | 60 | // convert shorthand to full hex |
| | 61 | if( strlen( $color ) == 3 ) { |
| | 62 | $color = str_repeat( substr( $color, 1, 1 ), 2 ) . str_repeat( substr( $color, 2, 1 ), 2 ) . str_repeat( substr( $color, 3, 1), 2 ); |
| | 63 | } |
| | 64 | |
| | 65 | // convert hex to rgb |
| | 66 | $rgb = array( hexdec( substr( $color, 1, 2 ) ), hexdec( substr( $color, 3, 2 ) ), hexdec( substr( $color, 5, 2 ) ) ); |
| | 67 | |
| | 68 | // adjust color and switch back to hex |
| | 69 | $hex = '#'; |
| | 70 | foreach ( $rgb as $c ) { |
| | 71 | $c += $steps; |
| | 72 | if( $c > 255 ) |
| | 73 | $c = 255; |
| | 74 | elseif( $c < 0 ) |
| | 75 | $c = 0; |
| | 76 | $hex .= str_pad( dechex( $c ), 2, '0', STR_PAD_LEFT); |
| | 77 | } |
| | 78 | |
| | 79 | return $hex; |
| | 80 | } |
| | 81 | |
| | 82 | /** |
| | 83 | * Outputs the css for the Theme Customizer options. |
| | 84 | * |
| | 85 | */ |
| | 86 | function twentyfourteen_customizer_styles() { |
| | 87 | $accent_color = get_theme_mod( 'accent_color' ); |
| | 88 | |
| | 89 | // don't do anything if the current color is the default |
| | 90 | if ( $accent_color == '#24890d' ) |
| | 91 | return; |
| | 92 | |
| | 93 | $accent_1 = get_theme_mod( 'accent_1' ); |
| | 94 | $accent_2 = get_theme_mod( 'accent_2' ); |
| | 95 | |
| | 96 | $css = '<style type="text/css"> |
| | 97 | /* custom accent color */ |
| | 98 | h1 a:hover, |
| | 99 | h2 a:hover, |
| | 100 | h3 a:hover, |
| | 101 | h4 a:hover, |
| | 102 | h5 a:hover, |
| | 103 | h6 a:hover, |
| | 104 | a, |
| | 105 | .primary-navigation ul ul a:hover, |
| | 106 | .entry-title a:hover, |
| | 107 | .cat-links a:hover, |
| | 108 | .site-content .post-navigation a:hover, |
| | 109 | .site-content .image-navigation a:hover, |
| | 110 | .comment-author a:hover, |
| | 111 | .comment-metadata a:hover, |
| | 112 | .comment-list .trackback a:hover, |
| | 113 | .comment-list .pingback a:hover, |
| | 114 | .content-sidebar a:hover, |
| | 115 | .paging-navigation .page-numbers.current { |
| | 116 | color: ' . $accent_color . '; |
| | 117 | } |
| | 118 | |
| | 119 | button:hover, |
| | 120 | html input[type="button"]:hover, |
| | 121 | input[type="reset"]:hover, |
| | 122 | input[type="submit"]:hover, |
| | 123 | button:focus, |
| | 124 | html input[type="button"]:focus, |
| | 125 | input[type="reset"]:focus, |
| | 126 | input[type="submit"]:focus, |
| | 127 | .header-extra, |
| | 128 | .search-toggle, |
| | 129 | .bypostauthor .avatar, |
| | 130 | .widget-area button, |
| | 131 | .widget-area html input[type="button"], |
| | 132 | .widget-area input[type="reset"], |
| | 133 | .widget-area input[type="submit"], |
| | 134 | .widget_calendar a, |
| | 135 | .content-sidebar button:hover, |
| | 136 | .content-sidebar html input[type="button"]:hover, |
| | 137 | .content-sidebar input[type="reset"]:hover, |
| | 138 | .content-sidebar input[type="submit"]:hover, |
| | 139 | .content-sidebar button:focus, |
| | 140 | .content-sidebar html input[type="button"]:focus, |
| | 141 | .content-sidebar input[type="reset"]:focus, |
| | 142 | .content-sidebar input[type="submit"]:focus, |
| | 143 | .page-links a:hover { |
| | 144 | background-color: ' . $accent_color . '; |
| | 145 | } |
| | 146 | |
| | 147 | ::-moz-selection { |
| | 148 | background: ' . $accent_color . '; |
| | 149 | } |
| | 150 | |
| | 151 | ::selection { |
| | 152 | background: ' . $accent_color . '; |
| | 153 | } |
| | 154 | |
| | 155 | .page-links a:hover, |
| | 156 | .paging-navigation .page-numbers.current { |
| | 157 | border-color: ' . $accent_color . '; |
| | 158 | } |
| | 159 | |
| | 160 | /* generated variant of custom accent color: slightly lighter */ |
| | 161 | .search-toggle:hover, |
| | 162 | .search-toggle.active, |
| | 163 | .search-box, |
| | 164 | .widget-area button:hover, |
| | 165 | .widget-area html input[type="button"]:hover, |
| | 166 | .widget-area input[type="reset"]:hover, |
| | 167 | .widget-area input[type="submit"]:hover, |
| | 168 | .widget-area button:focus, |
| | 169 | .widget-area html input[type="button"]:focus, |
| | 170 | .widget-area input[type="reset"]:focus, |
| | 171 | .widget-area input[type="submit"]:focus, |
| | 172 | .widget-area button:active, |
| | 173 | .widget-area html input[type="button"]:active, |
| | 174 | .widget-area input[type="reset"]:active, |
| | 175 | .widget-area input[type="submit"]:active, |
| | 176 | .widget_calendar a:hover { |
| | 177 | background-color: ' . $accent_1 . '; |
| | 178 | } |
| | 179 | |
| | 180 | /* generated variant of custom accent color: lighter */ |
| | 181 | button:active, |
| | 182 | html input[type="button"]:active, |
| | 183 | input[type="reset"]:active, |
| | 184 | input[type="submit"]:active, |
| | 185 | .content-sidebar button:active, |
| | 186 | .content-sidebar html input[type="button"]:active, |
| | 187 | .content-sidebar input[type="reset"]:active, |
| | 188 | .content-sidebar input[type="submit"]:active { |
| | 189 | background-color: ' . $accent_2 . '; |
| | 190 | } |
| | 191 | |
| | 192 | a:hover, |
| | 193 | a:focus, |
| | 194 | a:active, |
| | 195 | .primary-navigation li.current_page_item > a, |
| | 196 | .primary-navigation li.current-menu-item > a, |
| | 197 | .secondary-navigation a:hover, |
| | 198 | #secondary .current_page_item > a, |
| | 199 | #secondary .current-menu-item > a, |
| | 200 | #featured-content .entry-meta a:hover, |
| | 201 | #featured-content .entry-title a:hover, |
| | 202 | #featured-content .more-link, |
| | 203 | .widget-area a:hover { |
| | 204 | color: ' . $accent_2 . '; |
| | 205 | } |
| | 206 | </style>'; |
| | 207 | |
| | 208 | wp_add_inline_style( 'twentyfourteen-style', $css ); |
| | 209 | } |
| | 210 | add_action( 'wp_enqueue_scripts', 'twentyfourteen_customizer_styles' ); |
| | 211 | No newline at end of file |