[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Custom Header functionality for Twenty Fifteen 4 * 5 * @package WordPress 6 * @subpackage Twenty_Fifteen 7 * @since Twenty Fifteen 1.0 8 */ 9 10 /** 11 * Set up the WordPress core custom header feature. 12 * 13 * @uses twentyfifteen_header_style() 14 */ 15 function twentyfifteen_custom_header_setup() { 16 $color_scheme = twentyfifteen_get_color_scheme(); 17 $default_text_color = trim( $color_scheme[4], '#' ); 18 19 add_theme_support( 20 'custom-header', 21 /** 22 * Filters Twenty Fifteen custom-header support arguments. 23 * 24 * @since Twenty Fifteen 1.0 25 * 26 * @param array $args { 27 * An array of custom-header support arguments. 28 * 29 * @type string $default_text_color Default color of the header text. 30 * @type int $width Width in pixels of the custom header image. Default 954. 31 * @type int $height Height in pixels of the custom header image. Default 1300. 32 * @type string $wp-head-callback Callback function used to styles the header image and text 33 * displayed on the blog. 34 * } 35 */ 36 apply_filters( 37 'twentyfifteen_custom_header_args', 38 array( 39 'default-text-color' => $default_text_color, 40 'width' => 954, 41 'height' => 1300, 42 'wp-head-callback' => 'twentyfifteen_header_style', 43 ) 44 ) 45 ); 46 } 47 add_action( 'after_setup_theme', 'twentyfifteen_custom_header_setup' ); 48 49 /** 50 * Convert HEX to RGB. 51 * 52 * @since Twenty Fifteen 1.0 53 * 54 * @param string $color The original color, in 3- or 6-digit hexadecimal form. 55 * @return array Array containing RGB (red, green, and blue) values for the given 56 * HEX code, empty array otherwise. 57 */ 58 function twentyfifteen_hex2rgb( $color ) { 59 $color = trim( $color, '#' ); 60 61 if ( strlen( $color ) === 3 ) { 62 $r = hexdec( substr( $color, 0, 1 ) . substr( $color, 0, 1 ) ); 63 $g = hexdec( substr( $color, 1, 1 ) . substr( $color, 1, 1 ) ); 64 $b = hexdec( substr( $color, 2, 1 ) . substr( $color, 2, 1 ) ); 65 } elseif ( strlen( $color ) === 6 ) { 66 $r = hexdec( substr( $color, 0, 2 ) ); 67 $g = hexdec( substr( $color, 2, 2 ) ); 68 $b = hexdec( substr( $color, 4, 2 ) ); 69 } else { 70 return array(); 71 } 72 73 return array( 74 'red' => $r, 75 'green' => $g, 76 'blue' => $b, 77 ); 78 } 79 80 if ( ! function_exists( 'twentyfifteen_header_style' ) ) : 81 /** 82 * Styles the header image and text displayed on the blog. 83 * 84 * @since Twenty Fifteen 1.0 85 * 86 * @see twentyfifteen_custom_header_setup() 87 */ 88 function twentyfifteen_header_style() { 89 $header_image = get_header_image(); 90 91 // If no custom options for text are set, let's bail. 92 if ( empty( $header_image ) && display_header_text() ) { 93 return; 94 } 95 96 // If we get this far, we have custom styles. Let's do this. 97 ?> 98 <style type="text/css" id="twentyfifteen-header-css"> 99 <?php 100 // Short header for when there is no Custom Header and Header Text is hidden. 101 if ( empty( $header_image ) && ! display_header_text() ) : 102 ?> 103 .site-header { 104 padding-top: 14px; 105 padding-bottom: 14px; 106 } 107 108 .site-branding { 109 min-height: 42px; 110 } 111 112 @media screen and (min-width: 46.25em) { 113 .site-header { 114 padding-top: 21px; 115 padding-bottom: 21px; 116 } 117 .site-branding { 118 min-height: 56px; 119 } 120 } 121 @media screen and (min-width: 55em) { 122 .site-header { 123 padding-top: 25px; 124 padding-bottom: 25px; 125 } 126 .site-branding { 127 min-height: 62px; 128 } 129 } 130 @media screen and (min-width: 59.6875em) { 131 .site-header { 132 padding-top: 0; 133 padding-bottom: 0; 134 } 135 .site-branding { 136 min-height: 0; 137 } 138 } 139 <?php 140 endif; 141 142 // Has a Custom Header been added? 143 if ( ! empty( $header_image ) ) : 144 ?> 145 .site-header { 146 147 /* 148 * No shorthand so the Customizer can override individual properties. 149 * @see https://core.trac.wordpress.org/ticket/31460 150 */ 151 background-image: url(<?php header_image(); ?>); 152 background-repeat: no-repeat; 153 background-position: 50% 50%; 154 -webkit-background-size: cover; 155 -moz-background-size: cover; 156 -o-background-size: cover; 157 background-size: cover; 158 } 159 160 @media screen and (min-width: 59.6875em) { 161 body:before { 162 163 /* 164 * No shorthand so the Customizer can override individual properties. 165 * @see https://core.trac.wordpress.org/ticket/31460 166 */ 167 background-image: url(<?php header_image(); ?>); 168 background-repeat: no-repeat; 169 background-position: 100% 50%; 170 -webkit-background-size: cover; 171 -moz-background-size: cover; 172 -o-background-size: cover; 173 background-size: cover; 174 border-right: 0; 175 } 176 177 .site-header { 178 background: transparent; 179 } 180 } 181 <?php 182 endif; 183 184 // Has the text been hidden? 185 if ( ! display_header_text() ) : 186 ?> 187 .site-title, 188 .site-description { 189 clip: rect(1px, 1px, 1px, 1px); 190 position: absolute; 191 } 192 <?php endif; ?> 193 </style> 194 <?php 195 } 196 endif; // twentyfifteen_header_style() 197 198 /** 199 * Enqueues front-end CSS for the header background color. 200 * 201 * @since Twenty Fifteen 1.0 202 * 203 * @see wp_add_inline_style() 204 */ 205 function twentyfifteen_header_background_color_css() { 206 $color_scheme = twentyfifteen_get_color_scheme(); 207 $default_color = $color_scheme[1]; 208 $header_background_color = get_theme_mod( 'header_background_color', $default_color ); 209 210 // Don't do anything if the current color is the default. 211 if ( $header_background_color === $default_color ) { 212 return; 213 } 214 215 $css = ' 216 /* Custom Header Background Color */ 217 body:before, 218 .site-header { 219 background-color: %1$s; 220 } 221 222 @media screen and (min-width: 59.6875em) { 223 .site-header, 224 .secondary { 225 background-color: transparent; 226 } 227 228 .widget button, 229 .widget input[type="button"], 230 .widget input[type="reset"], 231 .widget input[type="submit"], 232 .widget_calendar tbody a, 233 .widget_calendar tbody a:hover, 234 .widget_calendar tbody a:focus { 235 color: %1$s; 236 } 237 } 238 '; 239 240 wp_add_inline_style( 'twentyfifteen-style', sprintf( $css, $header_background_color ) ); 241 } 242 add_action( 'wp_enqueue_scripts', 'twentyfifteen_header_background_color_css', 11 ); 243 244 /** 245 * Enqueues front-end CSS for the sidebar text color. 246 * 247 * @since Twenty Fifteen 1.0 248 */ 249 function twentyfifteen_sidebar_text_color_css() { 250 $color_scheme = twentyfifteen_get_color_scheme(); 251 $default_color = $color_scheme[4]; 252 $sidebar_link_color = get_theme_mod( 'sidebar_textcolor', $default_color ); 253 254 // Don't do anything if the current color is the default. 255 if ( $sidebar_link_color === $default_color ) { 256 return; 257 } 258 259 // If we get this far, we have custom styles. Let's do this. 260 $sidebar_link_color_rgb = twentyfifteen_hex2rgb( $sidebar_link_color ); 261 $sidebar_text_color = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.7)', $sidebar_link_color_rgb ); 262 $sidebar_border_color = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.1)', $sidebar_link_color_rgb ); 263 $sidebar_border_focus_color = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.3)', $sidebar_link_color_rgb ); 264 265 $css = ' 266 /* Custom Sidebar Text Color */ 267 .site-title a, 268 .site-description, 269 .secondary-toggle:before { 270 color: %1$s; 271 } 272 273 .site-title a:hover, 274 .site-title a:focus { 275 color: %2$s; 276 } 277 278 .secondary-toggle { 279 border-color: %3$s; 280 } 281 282 .secondary-toggle:hover, 283 .secondary-toggle:focus { 284 border-color: %4$s; 285 } 286 287 .site-title a { 288 outline-color: %4$s; 289 } 290 291 @media screen and (min-width: 59.6875em) { 292 .secondary a, 293 .dropdown-toggle:after, 294 .widget-title, 295 .widget blockquote cite, 296 .widget blockquote small { 297 color: %1$s; 298 } 299 300 .widget button, 301 .widget input[type="button"], 302 .widget input[type="reset"], 303 .widget input[type="submit"], 304 .widget_calendar tbody a { 305 background-color: %1$s; 306 } 307 308 .textwidget a { 309 border-color: %1$s; 310 } 311 312 .secondary a:hover, 313 .secondary a:focus, 314 .main-navigation .menu-item-description, 315 .widget, 316 .widget blockquote, 317 .widget .wp-caption-text, 318 .widget .gallery-caption { 319 color: %2$s; 320 } 321 322 .widget button:hover, 323 .widget button:focus, 324 .widget input[type="button"]:hover, 325 .widget input[type="button"]:focus, 326 .widget input[type="reset"]:hover, 327 .widget input[type="reset"]:focus, 328 .widget input[type="submit"]:hover, 329 .widget input[type="submit"]:focus, 330 .widget_calendar tbody a:hover, 331 .widget_calendar tbody a:focus { 332 background-color: %2$s; 333 } 334 335 .widget blockquote { 336 border-color: %2$s; 337 } 338 339 .main-navigation ul, 340 .main-navigation li, 341 .secondary-toggle, 342 .widget input, 343 .widget textarea, 344 .widget table, 345 .widget th, 346 .widget td, 347 .widget pre, 348 .widget li, 349 .widget_categories .children, 350 .widget_nav_menu .sub-menu, 351 .widget_pages .children, 352 .widget abbr[title] { 353 border-color: %3$s; 354 } 355 356 .dropdown-toggle:hover, 357 .dropdown-toggle:focus, 358 .widget hr { 359 background-color: %3$s; 360 } 361 362 .widget input:focus, 363 .widget textarea:focus { 364 border-color: %4$s; 365 } 366 367 .sidebar a:focus, 368 .dropdown-toggle:focus { 369 outline-color: %4$s; 370 } 371 } 372 '; 373 374 wp_add_inline_style( 'twentyfifteen-style', sprintf( $css, $sidebar_link_color, $sidebar_text_color, $sidebar_border_color, $sidebar_border_focus_color ) ); 375 } 376 add_action( 'wp_enqueue_scripts', 'twentyfifteen_sidebar_text_color_css', 11 );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Dec 21 08:20:01 2024 | Cross-referenced by PHPXref |