- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentysixteen/inc/customizer.php
r40851 r42343 31 31 * } 32 32 */ 33 add_theme_support( 'custom-background', apply_filters( 'twentysixteen_custom_background_args', array( 34 'default-color' => $default_background_color, 35 ) ) ); 33 add_theme_support( 34 'custom-background', apply_filters( 35 'twentysixteen_custom_background_args', array( 36 'default-color' => $default_background_color, 37 ) 38 ) 39 ); 36 40 37 41 /** … … 51 55 * } 52 56 */ 53 add_theme_support( 'custom-header', apply_filters( 'twentysixteen_custom_header_args', array( 54 'default-text-color' => $default_text_color, 55 'width' => 1200, 56 'height' => 280, 57 'flex-height' => true, 58 'wp-head-callback' => 'twentysixteen_header_style', 59 ) ) ); 57 add_theme_support( 58 'custom-header', apply_filters( 59 'twentysixteen_custom_header_args', array( 60 'default-text-color' => $default_text_color, 61 'width' => 1200, 62 'height' => 280, 63 'flex-height' => true, 64 'wp-head-callback' => 'twentysixteen_header_style', 65 ) 66 ) 67 ); 60 68 } 61 69 add_action( 'after_setup_theme', 'twentysixteen_custom_header_and_background' ); 62 70 63 71 if ( ! function_exists( 'twentysixteen_header_style' ) ) : 64 /**65 * Styles the header text displayed on the site.66 *67 * Create your own twentysixteen_header_style() function to override in a child theme.68 *69 * @since Twenty Sixteen 1.070 *71 * @see twentysixteen_custom_header_and_background().72 */73 function twentysixteen_header_style() {74 // If the header text option is untouched, let's bail.75 if ( display_header_text() ) {76 return;77 }78 79 // If the header text has been hidden.80 ?>81 <style type="text/css" id="twentysixteen-header-css">72 /** 73 * Styles the header text displayed on the site. 74 * 75 * Create your own twentysixteen_header_style() function to override in a child theme. 76 * 77 * @since Twenty Sixteen 1.0 78 * 79 * @see twentysixteen_custom_header_and_background(). 80 */ 81 function twentysixteen_header_style() { 82 // If the header text option is untouched, let's bail. 83 if ( display_header_text() ) { 84 return; 85 } 86 87 // If the header text has been hidden. 88 ?> 89 <style type="text/css" id="twentysixteen-header-css"> 82 90 .site-branding { 83 91 margin: 0 auto 0 0; … … 89 97 position: absolute; 90 98 } 91 </style>92 <?php93 }99 </style> 100 <?php 101 } 94 102 endif; // twentysixteen_header_style 95 103 … … 104 112 $color_scheme = twentysixteen_get_color_scheme(); 105 113 106 $wp_customize->get_setting( 'blogname' )->transport 107 $wp_customize->get_setting( 'blogdescription' )->transport 114 $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; 115 $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; 108 116 109 117 if ( isset( $wp_customize->selective_refresh ) ) { 110 $wp_customize->selective_refresh->add_partial( 'blogname', array( 111 'selector' => '.site-title a', 112 'container_inclusive' => false, 113 'render_callback' => 'twentysixteen_customize_partial_blogname', 114 ) ); 115 $wp_customize->selective_refresh->add_partial( 'blogdescription', array( 116 'selector' => '.site-description', 117 'container_inclusive' => false, 118 'render_callback' => 'twentysixteen_customize_partial_blogdescription', 119 ) ); 118 $wp_customize->selective_refresh->add_partial( 119 'blogname', array( 120 'selector' => '.site-title a', 121 'container_inclusive' => false, 122 'render_callback' => 'twentysixteen_customize_partial_blogname', 123 ) 124 ); 125 $wp_customize->selective_refresh->add_partial( 126 'blogdescription', array( 127 'selector' => '.site-description', 128 'container_inclusive' => false, 129 'render_callback' => 'twentysixteen_customize_partial_blogdescription', 130 ) 131 ); 120 132 } 121 133 122 134 // Add color scheme setting and control. 123 $wp_customize->add_setting( 'color_scheme', array( 124 'default' => 'default', 125 'sanitize_callback' => 'twentysixteen_sanitize_color_scheme', 126 'transport' => 'postMessage', 127 ) ); 128 129 $wp_customize->add_control( 'color_scheme', array( 130 'label' => __( 'Base Color Scheme', 'twentysixteen' ), 131 'section' => 'colors', 132 'type' => 'select', 133 'choices' => twentysixteen_get_color_scheme_choices(), 134 'priority' => 1, 135 ) ); 135 $wp_customize->add_setting( 136 'color_scheme', array( 137 'default' => 'default', 138 'sanitize_callback' => 'twentysixteen_sanitize_color_scheme', 139 'transport' => 'postMessage', 140 ) 141 ); 142 143 $wp_customize->add_control( 144 'color_scheme', array( 145 'label' => __( 'Base Color Scheme', 'twentysixteen' ), 146 'section' => 'colors', 147 'type' => 'select', 148 'choices' => twentysixteen_get_color_scheme_choices(), 149 'priority' => 1, 150 ) 151 ); 136 152 137 153 // Add page background color setting and control. 138 $wp_customize->add_setting( 'page_background_color', array( 139 'default' => $color_scheme[1], 140 'sanitize_callback' => 'sanitize_hex_color', 141 'transport' => 'postMessage', 142 ) ); 143 144 $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'page_background_color', array( 145 'label' => __( 'Page Background Color', 'twentysixteen' ), 146 'section' => 'colors', 147 ) ) ); 154 $wp_customize->add_setting( 155 'page_background_color', array( 156 'default' => $color_scheme[1], 157 'sanitize_callback' => 'sanitize_hex_color', 158 'transport' => 'postMessage', 159 ) 160 ); 161 162 $wp_customize->add_control( 163 new WP_Customize_Color_Control( 164 $wp_customize, 'page_background_color', array( 165 'label' => __( 'Page Background Color', 'twentysixteen' ), 166 'section' => 'colors', 167 ) 168 ) 169 ); 148 170 149 171 // Remove the core header textcolor control, as it shares the main text color. … … 151 173 152 174 // Add link color setting and control. 153 $wp_customize->add_setting( 'link_color', array( 154 'default' => $color_scheme[2], 155 'sanitize_callback' => 'sanitize_hex_color', 156 'transport' => 'postMessage', 157 ) ); 158 159 $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array( 160 'label' => __( 'Link Color', 'twentysixteen' ), 161 'section' => 'colors', 162 ) ) ); 175 $wp_customize->add_setting( 176 'link_color', array( 177 'default' => $color_scheme[2], 178 'sanitize_callback' => 'sanitize_hex_color', 179 'transport' => 'postMessage', 180 ) 181 ); 182 183 $wp_customize->add_control( 184 new WP_Customize_Color_Control( 185 $wp_customize, 'link_color', array( 186 'label' => __( 'Link Color', 'twentysixteen' ), 187 'section' => 'colors', 188 ) 189 ) 190 ); 163 191 164 192 // Add main text color setting and control. 165 $wp_customize->add_setting( 'main_text_color', array( 166 'default' => $color_scheme[3], 167 'sanitize_callback' => 'sanitize_hex_color', 168 'transport' => 'postMessage', 169 ) ); 170 171 $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'main_text_color', array( 172 'label' => __( 'Main Text Color', 'twentysixteen' ), 173 'section' => 'colors', 174 ) ) ); 193 $wp_customize->add_setting( 194 'main_text_color', array( 195 'default' => $color_scheme[3], 196 'sanitize_callback' => 'sanitize_hex_color', 197 'transport' => 'postMessage', 198 ) 199 ); 200 201 $wp_customize->add_control( 202 new WP_Customize_Color_Control( 203 $wp_customize, 'main_text_color', array( 204 'label' => __( 'Main Text Color', 'twentysixteen' ), 205 'section' => 'colors', 206 ) 207 ) 208 ); 175 209 176 210 // Add secondary text color setting and control. 177 $wp_customize->add_setting( 'secondary_text_color', array( 178 'default' => $color_scheme[4], 179 'sanitize_callback' => 'sanitize_hex_color', 180 'transport' => 'postMessage', 181 ) ); 182 183 $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'secondary_text_color', array( 184 'label' => __( 'Secondary Text Color', 'twentysixteen' ), 185 'section' => 'colors', 186 ) ) ); 211 $wp_customize->add_setting( 212 'secondary_text_color', array( 213 'default' => $color_scheme[4], 214 'sanitize_callback' => 'sanitize_hex_color', 215 'transport' => 'postMessage', 216 ) 217 ); 218 219 $wp_customize->add_control( 220 new WP_Customize_Color_Control( 221 $wp_customize, 'secondary_text_color', array( 222 'label' => __( 'Secondary Text Color', 'twentysixteen' ), 223 'section' => 'colors', 224 ) 225 ) 226 ); 187 227 } 188 228 add_action( 'customize_register', 'twentysixteen_customize_register', 11 ); … … 249 289 * } 250 290 */ 251 return apply_filters( 'twentysixteen_color_schemes', array( 252 'default' => array( 253 'label' => __( 'Default', 'twentysixteen' ), 254 'colors' => array( 255 '#1a1a1a', 256 '#ffffff', 257 '#007acc', 258 '#1a1a1a', 259 '#686868', 291 return apply_filters( 292 'twentysixteen_color_schemes', array( 293 'default' => array( 294 'label' => __( 'Default', 'twentysixteen' ), 295 'colors' => array( 296 '#1a1a1a', 297 '#ffffff', 298 '#007acc', 299 '#1a1a1a', 300 '#686868', 301 ), 260 302 ), 261 ),262 'dark' => array(263 'label' => __( 'Dark', 'twentysixteen' ),264 'colors' => array(265 '#262626',266 '#1a1a1a',267 '#9adffd',268 '#e5e5e5',269 '#c1c1c1',303 'dark' => array( 304 'label' => __( 'Dark', 'twentysixteen' ), 305 'colors' => array( 306 '#262626', 307 '#1a1a1a', 308 '#9adffd', 309 '#e5e5e5', 310 '#c1c1c1', 311 ), 270 312 ), 271 ),272 'gray' => array(273 'label' => __( 'Gray', 'twentysixteen' ),274 'colors' => array(275 '#616a73',276 '#4d545c',277 '#c7c7c7',278 '#f2f2f2',279 '#f2f2f2',313 'gray' => array( 314 'label' => __( 'Gray', 'twentysixteen' ), 315 'colors' => array( 316 '#616a73', 317 '#4d545c', 318 '#c7c7c7', 319 '#f2f2f2', 320 '#f2f2f2', 321 ), 280 322 ), 281 ),282 'red' => array(283 'label' => __( 'Red', 'twentysixteen' ),284 'colors' => array(285 '#ffffff',286 '#ff675f',287 '#640c1f',288 '#402b30',289 '#402b30',323 'red' => array( 324 'label' => __( 'Red', 'twentysixteen' ), 325 'colors' => array( 326 '#ffffff', 327 '#ff675f', 328 '#640c1f', 329 '#402b30', 330 '#402b30', 331 ), 290 332 ), 291 ),292 'yellow' => array(293 'label' => __( 'Yellow', 'twentysixteen' ),294 'colors' => array(295 '#3b3721',296 '#ffef8e',297 '#774e24',298 '#3b3721',299 '#5b4d3e',333 'yellow' => array( 334 'label' => __( 'Yellow', 'twentysixteen' ), 335 'colors' => array( 336 '#3b3721', 337 '#ffef8e', 338 '#774e24', 339 '#3b3721', 340 '#5b4d3e', 341 ), 300 342 ), 301 ) ,302 ) );343 ) 344 ); 303 345 } 304 346 305 347 if ( ! function_exists( 'twentysixteen_get_color_scheme' ) ) : 306 /**307 * Retrieves the current Twenty Sixteen color scheme.308 *309 * Create your own twentysixteen_get_color_scheme() function to override in a child theme.310 *311 * @since Twenty Sixteen 1.0312 *313 * @return array An associative array of either the current or default color scheme HEX values.314 */315 function twentysixteen_get_color_scheme() {316 $color_scheme_option = get_theme_mod( 'color_scheme', 'default' );317 $color_schemes = twentysixteen_get_color_schemes();318 319 if ( array_key_exists( $color_scheme_option, $color_schemes ) ) {320 return $color_schemes[ $color_scheme_option ]['colors'];321 }322 323 return $color_schemes['default']['colors'];324 }348 /** 349 * Retrieves the current Twenty Sixteen color scheme. 350 * 351 * Create your own twentysixteen_get_color_scheme() function to override in a child theme. 352 * 353 * @since Twenty Sixteen 1.0 354 * 355 * @return array An associative array of either the current or default color scheme HEX values. 356 */ 357 function twentysixteen_get_color_scheme() { 358 $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); 359 $color_schemes = twentysixteen_get_color_schemes(); 360 361 if ( array_key_exists( $color_scheme_option, $color_schemes ) ) { 362 return $color_schemes[ $color_scheme_option ]['colors']; 363 } 364 365 return $color_schemes['default']['colors']; 366 } 325 367 endif; // twentysixteen_get_color_scheme 326 368 327 369 if ( ! function_exists( 'twentysixteen_get_color_scheme_choices' ) ) : 328 /**329 * Retrieves an array of color scheme choices registered for Twenty Sixteen.330 *331 * Create your own twentysixteen_get_color_scheme_choices() function to override332 * in a child theme.333 *334 * @since Twenty Sixteen 1.0335 *336 * @return array Array of color schemes.337 */338 function twentysixteen_get_color_scheme_choices() {339 $color_schemes = twentysixteen_get_color_schemes();340 $color_scheme_control_options = array();341 342 foreach ( $color_schemes as $color_scheme => $value ) {343 $color_scheme_control_options[ $color_scheme ] = $value['label'];344 }345 346 return $color_scheme_control_options;347 }370 /** 371 * Retrieves an array of color scheme choices registered for Twenty Sixteen. 372 * 373 * Create your own twentysixteen_get_color_scheme_choices() function to override 374 * in a child theme. 375 * 376 * @since Twenty Sixteen 1.0 377 * 378 * @return array Array of color schemes. 379 */ 380 function twentysixteen_get_color_scheme_choices() { 381 $color_schemes = twentysixteen_get_color_schemes(); 382 $color_scheme_control_options = array(); 383 384 foreach ( $color_schemes as $color_scheme => $value ) { 385 $color_scheme_control_options[ $color_scheme ] = $value['label']; 386 } 387 388 return $color_scheme_control_options; 389 } 348 390 endif; // twentysixteen_get_color_scheme_choices 349 391 350 392 351 393 if ( ! function_exists( 'twentysixteen_sanitize_color_scheme' ) ) : 352 /**353 * Handles sanitization for Twenty Sixteen color schemes.354 *355 * Create your own twentysixteen_sanitize_color_scheme() function to override356 * in a child theme.357 *358 * @since Twenty Sixteen 1.0359 *360 * @param string $value Color scheme name value.361 * @return string Color scheme name.362 */363 function twentysixteen_sanitize_color_scheme( $value ) {364 $color_schemes = twentysixteen_get_color_scheme_choices();365 366 if ( ! array_key_exists( $value, $color_schemes ) ) {367 return 'default';368 }369 370 return $value;371 }394 /** 395 * Handles sanitization for Twenty Sixteen color schemes. 396 * 397 * Create your own twentysixteen_sanitize_color_scheme() function to override 398 * in a child theme. 399 * 400 * @since Twenty Sixteen 1.0 401 * 402 * @param string $value Color scheme name value. 403 * @return string Color scheme name. 404 */ 405 function twentysixteen_sanitize_color_scheme( $value ) { 406 $color_schemes = twentysixteen_get_color_scheme_choices(); 407 408 if ( ! array_key_exists( $value, $color_schemes ) ) { 409 return 'default'; 410 } 411 412 return $value; 413 } 372 414 endif; // twentysixteen_sanitize_color_scheme 373 415 … … 446 488 */ 447 489 function twentysixteen_get_color_scheme_css( $colors ) { 448 $colors = wp_parse_args( $colors, array( 449 'background_color' => '', 450 'page_background_color' => '', 451 'link_color' => '', 452 'main_text_color' => '', 453 'secondary_text_color' => '', 454 'border_color' => '', 455 ) ); 490 $colors = wp_parse_args( 491 $colors, array( 492 'background_color' => '', 493 'page_background_color' => '', 494 'link_color' => '', 495 'main_text_color' => '', 496 'secondary_text_color' => '', 497 'border_color' => '', 498 ) 499 ); 456 500 457 501 return <<<CSS … … 870 914 */ 871 915 function twentysixteen_link_color_css() { 872 $color_scheme 873 $default_color 874 $link_color = get_theme_mod( 'link_color', $default_color );916 $color_scheme = twentysixteen_get_color_scheme(); 917 $default_color = $color_scheme[2]; 918 $link_color = get_theme_mod( 'link_color', $default_color ); 875 919 876 920 // Don't do anything if the current color is the default. … … 1127 1171 */ 1128 1172 function twentysixteen_secondary_text_color_css() { 1129 $color_scheme = twentysixteen_get_color_scheme();1130 $default_color = $color_scheme[4];1173 $color_scheme = twentysixteen_get_color_scheme(); 1174 $default_color = $color_scheme[4]; 1131 1175 $secondary_text_color = get_theme_mod( 'secondary_text_color', $default_color ); 1132 1176
Note: See TracChangeset
for help on using the changeset viewer.