customizer.php 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. <?php
  2. /**
  3. * Twenty Sixteen Customizer functionality
  4. *
  5. * @package WordPress
  6. * @subpackage Twenty_Sixteen
  7. * @since Twenty Sixteen 1.0
  8. */
  9. /**
  10. * Sets up the WordPress core custom header and custom background features.
  11. *
  12. * @since Twenty Sixteen 1.0
  13. *
  14. * @see twentysixteen_header_style()
  15. */
  16. function twentysixteen_custom_header_and_background() {
  17. $color_scheme = twentysixteen_get_color_scheme();
  18. $default_background_color = trim( $color_scheme[0], '#' );
  19. $default_text_color = trim( $color_scheme[3], '#' );
  20. /**
  21. * Filter the arguments used when adding 'custom-background' support in Twenty Sixteen.
  22. *
  23. * @since Twenty Sixteen 1.0
  24. *
  25. * @param array $args {
  26. * An array of custom-background support arguments.
  27. *
  28. * @type string $default-color Default color of the background.
  29. * }
  30. */
  31. add_theme_support( 'custom-background', apply_filters( 'twentysixteen_custom_background_args', array(
  32. 'default-color' => $default_background_color,
  33. ) ) );
  34. /**
  35. * Filter the arguments used when adding 'custom-header' support in Twenty Sixteen.
  36. *
  37. * @since Twenty Sixteen 1.0
  38. *
  39. * @param array $args {
  40. * An array of custom-header support arguments.
  41. *
  42. * @type string $default-text-color Default color of the header text.
  43. * @type int $width Width in pixels of the custom header image. Default 1200.
  44. * @type int $height Height in pixels of the custom header image. Default 280.
  45. * @type bool $flex-height Whether to allow flexible-height header images. Default true.
  46. * @type callable $wp-head-callback Callback function used to style the header image and text
  47. * displayed on the blog.
  48. * }
  49. */
  50. add_theme_support( 'custom-header', apply_filters( 'twentysixteen_custom_header_args', array(
  51. 'default-text-color' => $default_text_color,
  52. 'width' => 1200,
  53. 'height' => 280,
  54. 'flex-height' => true,
  55. 'wp-head-callback' => 'twentysixteen_header_style',
  56. ) ) );
  57. }
  58. add_action( 'after_setup_theme', 'twentysixteen_custom_header_and_background' );
  59. if ( ! function_exists( 'twentysixteen_header_style' ) ) :
  60. /**
  61. * Styles the header text displayed on the site.
  62. *
  63. * Create your own twentysixteen_header_style() function to override in a child theme.
  64. *
  65. * @since Twenty Sixteen 1.0
  66. *
  67. * @see twentysixteen_custom_header_and_background().
  68. */
  69. function twentysixteen_header_style() {
  70. // If the header text option is untouched, let's bail.
  71. if ( display_header_text() ) {
  72. return;
  73. }
  74. // If the header text has been hidden.
  75. ?>
  76. <style type="text/css" id="twentysixteen-header-css">
  77. .site-branding {
  78. margin: 0 auto 0 0;
  79. }
  80. .site-branding .site-title,
  81. .site-description {
  82. clip: rect(1px, 1px, 1px, 1px);
  83. position: absolute;
  84. }
  85. </style>
  86. <?php
  87. }
  88. endif; // twentysixteen_header_style
  89. /**
  90. * Adds postMessage support for site title and description for the Customizer.
  91. *
  92. * @since Twenty Sixteen 1.0
  93. *
  94. * @param WP_Customize_Manager $wp_customize The Customizer object.
  95. */
  96. function twentysixteen_customize_register( $wp_customize ) {
  97. $color_scheme = twentysixteen_get_color_scheme();
  98. $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
  99. $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
  100. // Add color scheme setting and control.
  101. $wp_customize->add_setting( 'color_scheme', array(
  102. 'default' => 'default',
  103. 'sanitize_callback' => 'twentysixteen_sanitize_color_scheme',
  104. 'transport' => 'postMessage',
  105. ) );
  106. $wp_customize->add_control( 'color_scheme', array(
  107. 'label' => __( 'Base Color Scheme', 'twentysixteen' ),
  108. 'section' => 'colors',
  109. 'type' => 'select',
  110. 'choices' => twentysixteen_get_color_scheme_choices(),
  111. 'priority' => 1,
  112. ) );
  113. // Add page background color setting and control.
  114. $wp_customize->add_setting( 'page_background_color', array(
  115. 'default' => $color_scheme[1],
  116. 'sanitize_callback' => 'sanitize_hex_color',
  117. 'transport' => 'postMessage',
  118. ) );
  119. $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'page_background_color', array(
  120. 'label' => __( 'Page Background Color', 'twentysixteen' ),
  121. 'section' => 'colors',
  122. ) ) );
  123. // Remove the core header textcolor control, as it shares the main text color.
  124. $wp_customize->remove_control( 'header_textcolor' );
  125. // Add link color setting and control.
  126. $wp_customize->add_setting( 'link_color', array(
  127. 'default' => $color_scheme[2],
  128. 'sanitize_callback' => 'sanitize_hex_color',
  129. 'transport' => 'postMessage',
  130. ) );
  131. $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
  132. 'label' => __( 'Link Color', 'twentysixteen' ),
  133. 'section' => 'colors',
  134. ) ) );
  135. // Add main text color setting and control.
  136. $wp_customize->add_setting( 'main_text_color', array(
  137. 'default' => $color_scheme[3],
  138. 'sanitize_callback' => 'sanitize_hex_color',
  139. 'transport' => 'postMessage',
  140. ) );
  141. $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'main_text_color', array(
  142. 'label' => __( 'Main Text Color', 'twentysixteen' ),
  143. 'section' => 'colors',
  144. ) ) );
  145. // Add secondary text color setting and control.
  146. $wp_customize->add_setting( 'secondary_text_color', array(
  147. 'default' => $color_scheme[4],
  148. 'sanitize_callback' => 'sanitize_hex_color',
  149. 'transport' => 'postMessage',
  150. ) );
  151. $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'secondary_text_color', array(
  152. 'label' => __( 'Secondary Text Color', 'twentysixteen' ),
  153. 'section' => 'colors',
  154. ) ) );
  155. }
  156. add_action( 'customize_register', 'twentysixteen_customize_register', 11 );
  157. /**
  158. * Registers color schemes for Twenty Sixteen.
  159. *
  160. * Can be filtered with {@see 'twentysixteen_color_schemes'}.
  161. *
  162. * The order of colors in a colors array:
  163. * 1. Main Background Color.
  164. * 2. Page Background Color.
  165. * 3. Link Color.
  166. * 4. Main Text Color.
  167. * 5. Secondary Text Color.
  168. *
  169. * @since Twenty Sixteen 1.0
  170. *
  171. * @return array An associative array of color scheme options.
  172. */
  173. function twentysixteen_get_color_schemes() {
  174. /**
  175. * Filter the color schemes registered for use with Twenty Sixteen.
  176. *
  177. * The default schemes include 'default', 'dark', 'gray', 'green', and 'yellow'.
  178. *
  179. * @since Twenty Sixteen 1.0
  180. *
  181. * @param array $schemes {
  182. * Associative array of color schemes data.
  183. *
  184. * @type array $slug {
  185. * Associative array of information for setting up the color scheme.
  186. *
  187. * @type string $label Color scheme label.
  188. * @type array $colors HEX codes for default colors prepended with a hash symbol ('#').
  189. * Colors are defined in the following order: Main background, page
  190. * background, link, main text, secondary text.
  191. * }
  192. * }
  193. */
  194. return apply_filters( 'twentysixteen_color_schemes', array(
  195. 'default' => array(
  196. 'label' => __( 'Default', 'twentysixteen' ),
  197. 'colors' => array(
  198. '#1a1a1a',
  199. '#ffffff',
  200. '#007acc',
  201. '#1a1a1a',
  202. '#686868',
  203. ),
  204. ),
  205. 'dark' => array(
  206. 'label' => __( 'Dark', 'twentysixteen' ),
  207. 'colors' => array(
  208. '#262626',
  209. '#1a1a1a',
  210. '#9adffd',
  211. '#e5e5e5',
  212. '#c1c1c1',
  213. ),
  214. ),
  215. 'gray' => array(
  216. 'label' => __( 'Gray', 'twentysixteen' ),
  217. 'colors' => array(
  218. '#616a73',
  219. '#4d545c',
  220. '#aaaaaa',
  221. '#ededed',
  222. '#ededed',
  223. ),
  224. ),
  225. 'green' => array(
  226. 'label' => __( 'Green', 'twentysixteen' ),
  227. 'colors' => array(
  228. '#ffffff',
  229. '#acc1a2',
  230. '#6d8c87',
  231. '#ffffff',
  232. '#efeef4',
  233. ),
  234. ),
  235. 'yellow' => array(
  236. 'label' => __( 'Yellow', 'twentysixteen' ),
  237. 'colors' => array(
  238. '#3b3721',
  239. '#ffef8e',
  240. '#7f7d6f',
  241. '#3b3721',
  242. '#774e24',
  243. ),
  244. ),
  245. ) );
  246. }
  247. if ( ! function_exists( 'twentysixteen_get_color_scheme' ) ) :
  248. /**
  249. * Retrieves the current Twenty Sixteen color scheme.
  250. *
  251. * Create your own twentysixteen_get_color_scheme() function to override in a child theme.
  252. *
  253. * @since Twenty Sixteen 1.0
  254. *
  255. * @return array An associative array of either the current or default color scheme HEX values.
  256. */
  257. function twentysixteen_get_color_scheme() {
  258. $color_scheme_option = get_theme_mod( 'color_scheme', 'default' );
  259. $color_schemes = twentysixteen_get_color_schemes();
  260. if ( array_key_exists( $color_scheme_option, $color_schemes ) ) {
  261. return $color_schemes[ $color_scheme_option ]['colors'];
  262. }
  263. return $color_schemes['default']['colors'];
  264. }
  265. endif; // twentysixteen_get_color_scheme
  266. if ( ! function_exists( 'twentysixteen_get_color_scheme_choices' ) ) :
  267. /**
  268. * Retrieves an array of color scheme choices registered for Twenty Sixteen.
  269. *
  270. * Create your own twentysixteen_get_color_scheme_choices() function to override
  271. * in a child theme.
  272. *
  273. * @since Twenty Sixteen 1.0
  274. *
  275. * @return array Array of color schemes.
  276. */
  277. function twentysixteen_get_color_scheme_choices() {
  278. $color_schemes = twentysixteen_get_color_schemes();
  279. $color_scheme_control_options = array();
  280. foreach ( $color_schemes as $color_scheme => $value ) {
  281. $color_scheme_control_options[ $color_scheme ] = $value['label'];
  282. }
  283. return $color_scheme_control_options;
  284. }
  285. endif; // twentysixteen_get_color_scheme_choices
  286. if ( ! function_exists( 'twentysixteen_sanitize_color_scheme' ) ) :
  287. /**
  288. * Handles sanitization for Twenty Sixteen color schemes.
  289. *
  290. * Create your own twentysixteen_sanitize_color_scheme() function to override
  291. * in a child theme.
  292. *
  293. * @since Twenty Sixteen 1.0
  294. *
  295. * @param string $value Color scheme name value.
  296. * @return string Color scheme name.
  297. */
  298. function twentysixteen_sanitize_color_scheme( $value ) {
  299. $color_schemes = twentysixteen_get_color_scheme_choices();
  300. if ( ! array_key_exists( $value, $color_schemes ) ) {
  301. return 'default';
  302. }
  303. return $value;
  304. }
  305. endif; // twentysixteen_sanitize_color_scheme
  306. /**
  307. * Enqueues front-end CSS for color scheme.
  308. *
  309. * @since Twenty Sixteen 1.0
  310. *
  311. * @see wp_add_inline_style()
  312. */
  313. function twentysixteen_color_scheme_css() {
  314. $color_scheme_option = get_theme_mod( 'color_scheme', 'default' );
  315. // Don't do anything if the default color scheme is selected.
  316. if ( 'default' === $color_scheme_option ) {
  317. return;
  318. }
  319. $color_scheme = twentysixteen_get_color_scheme();
  320. // Convert main text hex color to rgba.
  321. $color_textcolor_rgb = twentysixteen_hex2rgb( $color_scheme[3] );
  322. // If the rgba values are empty return early.
  323. if ( empty( $color_textcolor_rgb ) ) {
  324. return;
  325. }
  326. // If we get this far, we have a custom color scheme.
  327. $colors = array(
  328. 'background_color' => $color_scheme[0],
  329. 'page_background_color' => $color_scheme[1],
  330. 'link_color' => $color_scheme[2],
  331. 'main_text_color' => $color_scheme[3],
  332. 'secondary_text_color' => $color_scheme[4],
  333. 'border_color' => vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.2)', $color_textcolor_rgb ),
  334. );
  335. $color_scheme_css = twentysixteen_get_color_scheme_css( $colors );
  336. wp_add_inline_style( 'twentysixteen-style', $color_scheme_css );
  337. }
  338. add_action( 'wp_enqueue_scripts', 'twentysixteen_color_scheme_css' );
  339. /**
  340. * Binds the JS listener to make Customizer color_scheme control.
  341. *
  342. * Passes color scheme data as colorScheme global.
  343. *
  344. * @since Twenty Sixteen 1.0
  345. */
  346. function twentysixteen_customize_control_js() {
  347. wp_enqueue_script( 'color-scheme-control', get_template_directory_uri() . '/js/color-scheme-control.js', array( 'customize-controls', 'iris', 'underscore', 'wp-util' ), '20151005', true );
  348. wp_localize_script( 'color-scheme-control', 'colorScheme', twentysixteen_get_color_schemes() );
  349. }
  350. add_action( 'customize_controls_enqueue_scripts', 'twentysixteen_customize_control_js' );
  351. /**
  352. * Binds JS handlers to make the Customizer preview reload changes asynchronously.
  353. *
  354. * @since Twenty Sixteen 1.0
  355. */
  356. function twentysixteen_customize_preview_js() {
  357. wp_enqueue_script( 'twentysixteen-customize-preview', get_template_directory_uri() . '/js/customize-preview.js', array( 'customize-preview' ), '20151005', true );
  358. }
  359. add_action( 'customize_preview_init', 'twentysixteen_customize_preview_js' );
  360. /**
  361. * Returns CSS for the color schemes.
  362. *
  363. * @since Twenty Sixteen 1.0
  364. *
  365. * @param array $colors Color scheme colors.
  366. * @return string Color scheme CSS.
  367. */
  368. function twentysixteen_get_color_scheme_css( $colors ) {
  369. $colors = wp_parse_args( $colors, array(
  370. 'background_color' => '',
  371. 'page_background_color' => '',
  372. 'link_color' => '',
  373. 'main_text_color' => '',
  374. 'secondary_text_color' => '',
  375. 'border_color' => '',
  376. ) );
  377. return <<<CSS
  378. /* Color Scheme */
  379. /* Background Color */
  380. body {
  381. background-color: {$colors['background_color']};
  382. }
  383. /* Page Background Color */
  384. .site {
  385. background-color: {$colors['page_background_color']};
  386. }
  387. mark,
  388. ins,
  389. button,
  390. button[disabled]:hover,
  391. button[disabled]:focus,
  392. input[type="button"],
  393. input[type="button"][disabled]:hover,
  394. input[type="button"][disabled]:focus,
  395. input[type="reset"],
  396. input[type="reset"][disabled]:hover,
  397. input[type="reset"][disabled]:focus,
  398. input[type="submit"],
  399. input[type="submit"][disabled]:hover,
  400. input[type="submit"][disabled]:focus,
  401. .menu-toggle.toggled-on,
  402. .menu-toggle.toggled-on:hover,
  403. .menu-toggle.toggled-on:focus,
  404. .pagination .prev,
  405. .pagination .next,
  406. .pagination .prev:hover,
  407. .pagination .prev:focus,
  408. .pagination .next:hover,
  409. .pagination .next:focus,
  410. .pagination .nav-links:before,
  411. .pagination .nav-links:after,
  412. .widget_calendar tbody a,
  413. .widget_calendar tbody a:hover,
  414. .widget_calendar tbody a:focus,
  415. .page-links a,
  416. .page-links a:hover,
  417. .page-links a:focus {
  418. color: {$colors['page_background_color']};
  419. }
  420. /* Link Color */
  421. .menu-toggle:hover,
  422. .menu-toggle:focus,
  423. a,
  424. .main-navigation a:hover,
  425. .main-navigation a:focus,
  426. .dropdown-toggle:hover,
  427. .dropdown-toggle:focus,
  428. .social-navigation a:hover:before,
  429. .social-navigation a:focus:before,
  430. .post-navigation a:hover .post-title,
  431. .post-navigation a:focus .post-title,
  432. .tagcloud a:hover,
  433. .tagcloud a:focus,
  434. .site-branding .site-title a:hover,
  435. .site-branding .site-title a:focus,
  436. .entry-title a:hover,
  437. .entry-title a:focus,
  438. .entry-footer a:hover,
  439. .entry-footer a:focus,
  440. .comment-metadata a:hover,
  441. .comment-metadata a:focus,
  442. .pingback .comment-edit-link:hover,
  443. .pingback .comment-edit-link:focus,
  444. .comment-reply-link,
  445. .comment-reply-link:hover,
  446. .comment-reply-link:focus,
  447. .required,
  448. .site-info a:hover,
  449. .site-info a:focus {
  450. color: {$colors['link_color']};
  451. }
  452. mark,
  453. ins,
  454. button:hover,
  455. button:focus,
  456. input[type="button"]:hover,
  457. input[type="button"]:focus,
  458. input[type="reset"]:hover,
  459. input[type="reset"]:focus,
  460. input[type="submit"]:hover,
  461. input[type="submit"]:focus,
  462. .pagination .prev:hover,
  463. .pagination .prev:focus,
  464. .pagination .next:hover,
  465. .pagination .next:focus,
  466. .widget_calendar tbody a,
  467. .page-links a:hover,
  468. .page-links a:focus {
  469. background-color: {$colors['link_color']};
  470. }
  471. input[type="text"]:focus,
  472. input[type="email"]:focus,
  473. input[type="url"]:focus,
  474. input[type="password"]:focus,
  475. input[type="search"]:focus,
  476. textarea:focus,
  477. .tagcloud a:hover,
  478. .tagcloud a:focus,
  479. .menu-toggle:hover,
  480. .menu-toggle:focus {
  481. border-color: {$colors['link_color']};
  482. }
  483. /* Main Text Color */
  484. body,
  485. select,
  486. blockquote cite,
  487. blockquote small,
  488. .main-navigation a,
  489. .menu-toggle,
  490. .dropdown-toggle,
  491. .social-navigation a,
  492. .post-navigation a,
  493. .pagination a:hover,
  494. .pagination a:focus,
  495. .widget-title a,
  496. .site-branding .site-title a,
  497. .entry-title a,
  498. .page-links > .page-links-title,
  499. .comment-author,
  500. .comment-reply-title small a:hover,
  501. .comment-reply-title small a:focus {
  502. color: {$colors['main_text_color']};
  503. }
  504. blockquote,
  505. .menu-toggle.toggled-on,
  506. .menu-toggle.toggled-on:hover,
  507. .menu-toggle.toggled-on:focus,
  508. .post-navigation,
  509. .post-navigation div + div,
  510. .pagination,
  511. .widget,
  512. .page-header,
  513. .page-links a,
  514. .comments-title,
  515. .comment-reply-title {
  516. border-color: {$colors['main_text_color']};
  517. }
  518. button,
  519. button[disabled]:hover,
  520. button[disabled]:focus,
  521. input[type="button"],
  522. input[type="button"][disabled]:hover,
  523. input[type="button"][disabled]:focus,
  524. input[type="reset"],
  525. input[type="reset"][disabled]:hover,
  526. input[type="reset"][disabled]:focus,
  527. input[type="submit"],
  528. input[type="submit"][disabled]:hover,
  529. input[type="submit"][disabled]:focus,
  530. .menu-toggle.toggled-on,
  531. .menu-toggle.toggled-on:hover,
  532. .menu-toggle.toggled-on:focus,
  533. .pagination:before,
  534. .pagination:after,
  535. .pagination .prev,
  536. .pagination .next,
  537. .page-links a {
  538. background-color: {$colors['main_text_color']};
  539. }
  540. /* Secondary Text Color */
  541. /**
  542. * IE8 and earlier will drop any block with CSS3 selectors.
  543. * Do not combine these styles with the next block.
  544. */
  545. body:not(.search-results) .entry-summary {
  546. color: {$colors['secondary_text_color']};
  547. }
  548. blockquote,
  549. .post-password-form label,
  550. a:hover,
  551. a:focus,
  552. a:active,
  553. .post-navigation .meta-nav,
  554. .image-navigation,
  555. .comment-navigation,
  556. .widget_recent_entries .post-date,
  557. .widget_rss .rss-date,
  558. .widget_rss cite,
  559. .site-description,
  560. .author-bio,
  561. .entry-footer,
  562. .entry-footer a,
  563. .sticky-post,
  564. .taxonomy-description,
  565. .entry-caption,
  566. .comment-metadata,
  567. .pingback .edit-link,
  568. .comment-metadata a,
  569. .pingback .comment-edit-link,
  570. .comment-form label,
  571. .comment-notes,
  572. .comment-awaiting-moderation,
  573. .logged-in-as,
  574. .form-allowed-tags,
  575. .site-info,
  576. .site-info a,
  577. .wp-caption .wp-caption-text,
  578. .gallery-caption,
  579. .widecolumn label,
  580. .widecolumn .mu_register label {
  581. color: {$colors['secondary_text_color']};
  582. }
  583. .widget_calendar tbody a:hover,
  584. .widget_calendar tbody a:focus {
  585. background-color: {$colors['secondary_text_color']};
  586. }
  587. /* Border Color */
  588. fieldset,
  589. pre,
  590. abbr,
  591. acronym,
  592. table,
  593. th,
  594. td,
  595. input[type="text"],
  596. input[type="email"],
  597. input[type="url"],
  598. input[type="password"],
  599. input[type="search"],
  600. textarea,
  601. .main-navigation li,
  602. .main-navigation .primary-menu,
  603. .menu-toggle,
  604. .dropdown-toggle:after,
  605. .social-navigation a,
  606. .image-navigation,
  607. .comment-navigation,
  608. .tagcloud a,
  609. .author-info,
  610. .page-links a,
  611. .page-links > span,
  612. .comment-list article,
  613. .comment-list .pingback,
  614. .comment-list .trackback,
  615. .comment-reply-link,
  616. .no-comments {
  617. border-color: {$colors['main_text_color']}; /* Fallback for IE7 and IE8 */
  618. border-color: {$colors['border_color']};
  619. }
  620. hr,
  621. code {
  622. background-color: {$colors['main_text_color']}; /* Fallback for IE7 and IE8 */
  623. background-color: {$colors['border_color']};
  624. }
  625. @media screen and (min-width: 56.875em) {
  626. .main-navigation li:hover > a,
  627. .main-navigation li.focus > a {
  628. color: {$colors['link_color']};
  629. }
  630. .main-navigation ul ul,
  631. .main-navigation ul ul li {
  632. border-color: {$colors['border_color']};
  633. }
  634. .main-navigation ul ul:before {
  635. border-top-color: {$colors['border_color']};
  636. border-bottom-color: {$colors['border_color']};
  637. }
  638. .main-navigation ul ul li {
  639. background-color: {$colors['page_background_color']};
  640. }
  641. .main-navigation ul ul:after {
  642. border-top-color: {$colors['page_background_color']};
  643. border-bottom-color: {$colors['page_background_color']};
  644. }
  645. }
  646. CSS;
  647. }
  648. /**
  649. * Outputs an Underscore template for generating CSS for the color scheme.
  650. *
  651. * The template generates the css dynamically for instant display in the
  652. * Customizer preview.
  653. *
  654. * @since Twenty Sixteen 1.0
  655. */
  656. function twentysixteen_color_scheme_css_template() {
  657. $colors = array(
  658. 'background_color' => '{{ data.background_color }}',
  659. 'page_background_color' => '{{ data.page_background_color }}',
  660. 'link_color' => '{{ data.link_color }}',
  661. 'main_text_color' => '{{ data.main_text_color }}',
  662. 'secondary_text_color' => '{{ data.secondary_text_color }}',
  663. 'border_color' => '{{ data.border_color }}',
  664. );
  665. ?>
  666. <script type="text/html" id="tmpl-twentysixteen-color-scheme">
  667. <?php echo twentysixteen_get_color_scheme_css( $colors ); ?>
  668. </script>
  669. <?php
  670. }
  671. add_action( 'customize_controls_print_footer_scripts', 'twentysixteen_color_scheme_css_template' );
  672. /**
  673. * Enqueues front-end CSS for the page background color.
  674. *
  675. * @since Twenty Sixteen 1.0
  676. *
  677. * @see wp_add_inline_style()
  678. */
  679. function twentysixteen_page_background_color_css() {
  680. $color_scheme = twentysixteen_get_color_scheme();
  681. $default_color = $color_scheme[1];
  682. $page_background_color = get_theme_mod( 'page_background_color', $default_color );
  683. // Don't do anything if the current color is the default.
  684. if ( $page_background_color === $default_color ) {
  685. return;
  686. }
  687. $css = '
  688. /* Custom Page Background Color */
  689. .site {
  690. background-color: %1$s;
  691. }
  692. mark,
  693. ins,
  694. button,
  695. button[disabled]:hover,
  696. button[disabled]:focus,
  697. input[type="button"],
  698. input[type="button"][disabled]:hover,
  699. input[type="button"][disabled]:focus,
  700. input[type="reset"],
  701. input[type="reset"][disabled]:hover,
  702. input[type="reset"][disabled]:focus,
  703. input[type="submit"],
  704. input[type="submit"][disabled]:hover,
  705. input[type="submit"][disabled]:focus,
  706. .menu-toggle.toggled-on,
  707. .menu-toggle.toggled-on:hover,
  708. .menu-toggle.toggled-on:focus,
  709. .pagination .prev,
  710. .pagination .next,
  711. .pagination .prev:hover,
  712. .pagination .prev:focus,
  713. .pagination .next:hover,
  714. .pagination .next:focus,
  715. .pagination .nav-links:before,
  716. .pagination .nav-links:after,
  717. .widget_calendar tbody a,
  718. .widget_calendar tbody a:hover,
  719. .widget_calendar tbody a:focus,
  720. .page-links a,
  721. .page-links a:hover,
  722. .page-links a:focus {
  723. color: %1$s;
  724. }
  725. @media screen and (min-width: 56.875em) {
  726. .main-navigation ul ul li {
  727. background-color: %1$s;
  728. }
  729. .main-navigation ul ul:after {
  730. border-top-color: %1$s;
  731. border-bottom-color: %1$s;
  732. }
  733. }
  734. ';
  735. wp_add_inline_style( 'twentysixteen-style', sprintf( $css, $page_background_color ) );
  736. }
  737. add_action( 'wp_enqueue_scripts', 'twentysixteen_page_background_color_css', 11 );
  738. /**
  739. * Enqueues front-end CSS for the link color.
  740. *
  741. * @since Twenty Sixteen 1.0
  742. *
  743. * @see wp_add_inline_style()
  744. */
  745. function twentysixteen_link_color_css() {
  746. $color_scheme = twentysixteen_get_color_scheme();
  747. $default_color = $color_scheme[2];
  748. $link_color = get_theme_mod( 'link_color', $default_color );
  749. // Don't do anything if the current color is the default.
  750. if ( $link_color === $default_color ) {
  751. return;
  752. }
  753. $css = '
  754. /* Custom Link Color */
  755. .menu-toggle:hover,
  756. .menu-toggle:focus,
  757. a,
  758. .main-navigation a:hover,
  759. .main-navigation a:focus,
  760. .dropdown-toggle:hover,
  761. .dropdown-toggle:focus,
  762. .social-navigation a:hover:before,
  763. .social-navigation a:focus:before,
  764. .post-navigation a:hover .post-title,
  765. .post-navigation a:focus .post-title,
  766. .tagcloud a:hover,
  767. .tagcloud a:focus,
  768. .site-branding .site-title a:hover,
  769. .site-branding .site-title a:focus,
  770. .entry-title a:hover,
  771. .entry-title a:focus,
  772. .entry-footer a:hover,
  773. .entry-footer a:focus,
  774. .comment-metadata a:hover,
  775. .comment-metadata a:focus,
  776. .pingback .comment-edit-link:hover,
  777. .pingback .comment-edit-link:focus,
  778. .comment-reply-link,
  779. .comment-reply-link:hover,
  780. .comment-reply-link:focus,
  781. .required,
  782. .site-info a:hover,
  783. .site-info a:focus {
  784. color: %1$s;
  785. }
  786. mark,
  787. ins,
  788. button:hover,
  789. button:focus,
  790. input[type="button"]:hover,
  791. input[type="button"]:focus,
  792. input[type="reset"]:hover,
  793. input[type="reset"]:focus,
  794. input[type="submit"]:hover,
  795. input[type="submit"]:focus,
  796. .pagination .prev:hover,
  797. .pagination .prev:focus,
  798. .pagination .next:hover,
  799. .pagination .next:focus,
  800. .widget_calendar tbody a,
  801. .page-links a:hover,
  802. .page-links a:focus {
  803. background-color: %1$s;
  804. }
  805. input[type="text"]:focus,
  806. input[type="email"]:focus,
  807. input[type="url"]:focus,
  808. input[type="password"]:focus,
  809. input[type="search"]:focus,
  810. textarea:focus,
  811. .tagcloud a:hover,
  812. .tagcloud a:focus,
  813. .menu-toggle:hover,
  814. .menu-toggle:focus {
  815. border-color: %1$s;
  816. }
  817. @media screen and (min-width: 56.875em) {
  818. .main-navigation li:hover > a,
  819. .main-navigation li.focus > a {
  820. color: %1$s;
  821. }
  822. }
  823. ';
  824. wp_add_inline_style( 'twentysixteen-style', sprintf( $css, $link_color ) );
  825. }
  826. add_action( 'wp_enqueue_scripts', 'twentysixteen_link_color_css', 11 );
  827. /**
  828. * Enqueues front-end CSS for the main text color.
  829. *
  830. * @since Twenty Sixteen 1.0
  831. *
  832. * @see wp_add_inline_style()
  833. */
  834. function twentysixteen_main_text_color_css() {
  835. $color_scheme = twentysixteen_get_color_scheme();
  836. $default_color = $color_scheme[3];
  837. $main_text_color = get_theme_mod( 'main_text_color', $default_color );
  838. // Don't do anything if the current color is the default.
  839. if ( $main_text_color === $default_color ) {
  840. return;
  841. }
  842. // Convert main text hex color to rgba.
  843. $main_text_color_rgb = twentysixteen_hex2rgb( $main_text_color );
  844. // If the rgba values are empty return early.
  845. if ( empty( $main_text_color_rgb ) ) {
  846. return;
  847. }
  848. // If we get this far, we have a custom color scheme.
  849. $border_color = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.2)', $main_text_color_rgb );
  850. $css = '
  851. /* Custom Main Text Color */
  852. body,
  853. select,
  854. blockquote cite,
  855. blockquote small,
  856. .main-navigation a,
  857. .menu-toggle,
  858. .dropdown-toggle,
  859. .social-navigation a,
  860. .post-navigation a,
  861. .pagination a:hover,
  862. .pagination a:focus,
  863. .widget-title a,
  864. .site-branding .site-title a,
  865. .entry-title a,
  866. .page-links > .page-links-title,
  867. .comment-author,
  868. .comment-reply-title small a:hover,
  869. .comment-reply-title small a:focus {
  870. color: %1$s
  871. }
  872. blockquote,
  873. .menu-toggle.toggled-on,
  874. .menu-toggle.toggled-on:hover,
  875. .menu-toggle.toggled-on:focus,
  876. .post-navigation,
  877. .post-navigation div + div,
  878. .pagination,
  879. .widget,
  880. .page-header,
  881. .page-links a,
  882. .comments-title,
  883. .comment-reply-title {
  884. border-color: %1$s;
  885. }
  886. button,
  887. button[disabled]:hover,
  888. button[disabled]:focus,
  889. input[type="button"],
  890. input[type="button"][disabled]:hover,
  891. input[type="button"][disabled]:focus,
  892. input[type="reset"],
  893. input[type="reset"][disabled]:hover,
  894. input[type="reset"][disabled]:focus,
  895. input[type="submit"],
  896. input[type="submit"][disabled]:hover,
  897. input[type="submit"][disabled]:focus,
  898. .menu-toggle.toggled-on,
  899. .menu-toggle.toggled-on:hover,
  900. .menu-toggle.toggled-on:focus,
  901. .pagination:before,
  902. .pagination:after,
  903. .pagination .prev,
  904. .pagination .next,
  905. .page-links a {
  906. background-color: %1$s;
  907. }
  908. /* Border Color */
  909. fieldset,
  910. pre,
  911. abbr,
  912. acronym,
  913. table,
  914. th,
  915. td,
  916. input[type="text"],
  917. input[type="email"],
  918. input[type="url"],
  919. input[type="password"],
  920. input[type="search"],
  921. textarea,
  922. .main-navigation li,
  923. .main-navigation .primary-menu,
  924. .menu-toggle,
  925. .dropdown-toggle:after,
  926. .social-navigation a,
  927. .image-navigation,
  928. .comment-navigation,
  929. .tagcloud a,
  930. .author-info,
  931. .page-links a,
  932. .page-links > span,
  933. .comment-list article,
  934. .comment-list .pingback,
  935. .comment-list .trackback,
  936. .comment-reply-link,
  937. .no-comments {
  938. border-color: %1$s; /* Fallback for IE7 and IE8 */
  939. border-color: %2$s;
  940. }
  941. hr,
  942. code {
  943. background-color: %1$s; /* Fallback for IE7 and IE8 */
  944. background-color: %2$s;
  945. }
  946. @media screen and (min-width: 56.875em) {
  947. .main-navigation ul ul,
  948. .main-navigation ul ul li {
  949. border-color: %2$s;
  950. }
  951. .main-navigation ul ul:before {
  952. border-top-color: %2$s;
  953. border-bottom-color: %2$s;
  954. }
  955. }
  956. ';
  957. wp_add_inline_style( 'twentysixteen-style', sprintf( $css, $main_text_color, $border_color ) );
  958. }
  959. add_action( 'wp_enqueue_scripts', 'twentysixteen_main_text_color_css', 11 );
  960. /**
  961. * Enqueues front-end CSS for the secondary text color.
  962. *
  963. * @since Twenty Sixteen 1.0
  964. *
  965. * @see wp_add_inline_style()
  966. */
  967. function twentysixteen_secondary_text_color_css() {
  968. $color_scheme = twentysixteen_get_color_scheme();
  969. $default_color = $color_scheme[4];
  970. $secondary_text_color = get_theme_mod( 'secondary_text_color', $default_color );
  971. // Don't do anything if the current color is the default.
  972. if ( $secondary_text_color === $default_color ) {
  973. return;
  974. }
  975. $css = '
  976. /* Custom Secondary Text Color */
  977. /**
  978. * IE8 and earlier will drop any block with CSS3 selectors.
  979. * Do not combine these styles with the next block.
  980. */
  981. body:not(.search-results) .entry-summary {
  982. color: %1$s;
  983. }
  984. blockquote,
  985. .post-password-form label,
  986. a:hover,
  987. a:focus,
  988. a:active,
  989. .post-navigation .meta-nav,
  990. .image-navigation,
  991. .comment-navigation,
  992. .widget_recent_entries .post-date,
  993. .widget_rss .rss-date,
  994. .widget_rss cite,
  995. .site-description,
  996. .author-bio,
  997. .entry-footer,
  998. .entry-footer a,
  999. .sticky-post,
  1000. .taxonomy-description,
  1001. .entry-caption,
  1002. .comment-metadata,
  1003. .pingback .edit-link,
  1004. .comment-metadata a,
  1005. .pingback .comment-edit-link,
  1006. .comment-form label,
  1007. .comment-notes,
  1008. .comment-awaiting-moderation,
  1009. .logged-in-as,
  1010. .form-allowed-tags,
  1011. .site-info,
  1012. .site-info a,
  1013. .wp-caption .wp-caption-text,
  1014. .gallery-caption,
  1015. .widecolumn label,
  1016. .widecolumn .mu_register label {
  1017. color: %1$s;
  1018. }
  1019. .widget_calendar tbody a:hover,
  1020. .widget_calendar tbody a:focus {
  1021. background-color: %1$s;
  1022. }
  1023. ';
  1024. wp_add_inline_style( 'twentysixteen-style', sprintf( $css, $secondary_text_color ) );
  1025. }
  1026. add_action( 'wp_enqueue_scripts', 'twentysixteen_secondary_text_color_css', 11 );