wpcom-colors-css-variables.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. // Custom Colors:
  3. function varia_define_color_annotations( $colors ) {
  4. // Background Color
  5. if ( isset( $colors['background'] ) ) {
  6. // --wp--preset--color--background
  7. add_color_rule(
  8. 'bg',
  9. $colors['background'],
  10. array(
  11. // This placeholder is needed to make the color annotations work
  12. array( '.wp--preset--color--background', 'background-color' ),
  13. ),
  14. __( 'Background Color' )
  15. );
  16. }
  17. // Foreground Color
  18. if ( isset( $colors['foreground'] ) ) {
  19. // --wp--preset--color--foreground
  20. add_color_rule(
  21. 'txt',
  22. $colors['foreground'],
  23. array(
  24. // This placeholder is needed to make the color annotations work
  25. array( '.wp--preset--color--foreground', 'color' ),
  26. ),
  27. __( 'Foreground Color' )
  28. );
  29. }
  30. // Primary Color
  31. if ( isset( $colors['primary'] ) ) {
  32. // --wp--preset--color--primary
  33. add_color_rule(
  34. 'link',
  35. $colors['primary'],
  36. array(
  37. // This placeholder is needed to make the color annotations work
  38. array( '.wp--preset--color--primary', 'color' ),
  39. ),
  40. __( 'Primary Color' )
  41. );
  42. }
  43. // Secondary Color
  44. if ( isset( $colors['secondary'] ) ) {
  45. // --wp--preset--color--secondary
  46. add_color_rule(
  47. 'fg1',
  48. $colors['secondary'],
  49. array(
  50. // Text-color
  51. array( '.wp--preset--color--secondary', 'color' ),
  52. ),
  53. __( 'Secondary Color' )
  54. );
  55. }
  56. // Tertiary Color
  57. if ( isset( $colors['tertiary'] ) ) {
  58. // --wp--preset--color--tertiary
  59. add_color_rule(
  60. 'fg2',
  61. $colors['tertiary'],
  62. array(
  63. // Text-color
  64. array( '.wp--preset--color--tertiary', 'color' ),
  65. ),
  66. __( 'Tertiary Color' )
  67. );
  68. }
  69. }
  70. /**
  71. * Custom CSS.
  72. * The plugin takes the body of this function and applies it in a style tag in the document head.
  73. */
  74. function varia_custom_colors_extra_css() {
  75. $colors_array = get_theme_mod( 'colors_manager' );
  76. if ( isset( $colors_array['colors']['bg'] ) ) {
  77. $background = $colors_array['colors']['bg'];
  78. $background_low_contrast = change_color_luminescence( $background, -10 );
  79. $background_high_contrast = change_color_luminescence( $background, 10 );
  80. }
  81. if ( isset( $colors_array['colors']['txt'] ) ) {
  82. $foreground = $colors_array['colors']['txt'];
  83. $foreground_low_contrast = change_color_luminescence( $foreground, 10 );
  84. $foreground_high_contrast = change_color_luminescence( $foreground, -10 );
  85. }
  86. if ( isset( $colors_array['colors']['link'] ) ) {
  87. $primary = $colors_array['colors']['link'];
  88. $primary_hover = change_color_luminescence( $primary, 10 );
  89. }
  90. if ( isset( $colors_array['colors']['fg1'] ) ) {
  91. $secondary = $colors_array['colors']['fg1'];
  92. $secondary_hover = change_color_luminescence( $secondary, 10 );
  93. }
  94. if ( isset( $colors_array['colors']['fg2'] ) ) {
  95. $border = $colors_array['colors']['fg2'];
  96. $border_low_contrast = change_color_luminescence( $border, 10 );
  97. $border_high_contrast = change_color_luminescence( $border, -10 );
  98. }
  99. ?>
  100. :root,
  101. #editor .editor-styles-wrapper {
  102. <?php if ( isset( $colors_array['colors']['bg'] ) ) { ?>
  103. --wp--preset--color--background: <?php echo $background; ?>;
  104. --wp--preset--color--background-low-contrast: <?php echo $background_low_contrast; ?>;
  105. --wp--preset--color--background-high-contrast: <?php echo $background_high_contrast; ?>;
  106. <?php
  107. }
  108. if ( isset( $colors_array['colors']['txt'] ) ) {
  109. ?>
  110. --wp--preset--color--foreground: <?php echo $foreground; ?>;
  111. --wp--preset--color--foreground-low-contrast: <?php echo $foreground_low_contrast; ?>;
  112. --wp--preset--color--foreground-high-contrast: <?php echo $foreground_high_contrast; ?>;
  113. <?php
  114. }
  115. if ( isset( $colors_array['colors']['link'] ) ) {
  116. ?>
  117. --wp--preset--color--primary: <?php echo $primary; ?>;
  118. --wp--preset--color--primary-hover: <?php echo $primary_hover; ?>;
  119. <?php
  120. }
  121. if ( isset( $colors_array['colors']['fg1'] ) ) {
  122. ?>
  123. --wp--preset--color--secondary: <?php echo $secondary; ?>;
  124. --wp--preset--color--secondary-hover: <?php echo $secondary_hover; ?>;
  125. <?php
  126. }
  127. if ( isset( $colors_array['colors']['fg2'] ) ) {
  128. ?>
  129. --wp--preset--color--border: <?php echo $border; ?>;
  130. --wp--preset--color--border-low-contrast: <?php echo $border_low_contrast; ?>;
  131. --wp--preset--color--border-high-contrast: <?php echo $border_high_contrast; ?>;
  132. <?php } ?>
  133. }
  134. <?php
  135. }
  136. add_theme_support( 'custom_colors_extra_css', 'varia_custom_colors_extra_css' );
  137. /**
  138. * Featured Palettes
  139. */
  140. $has_tertiary_color = false;
  141. if ( function_exists( 'varia_default_colors' ) ) {
  142. $default_colors = varia_default_colors();
  143. varia_define_color_annotations( $default_colors );
  144. if( $default_colors['tertiary'] ) {
  145. $has_tertiary_color = true;
  146. }
  147. }
  148. $light = array(
  149. '#FFFFFF',
  150. '#1D1E1E',
  151. '#C8133E',
  152. '#4E2F4B',
  153. );
  154. $medium = array(
  155. '#EEF4F7',
  156. '#242527',
  157. '#35845D',
  158. '#233252',
  159. );
  160. $dark = array(
  161. '#1F2527',
  162. '#FFFFFF',
  163. '#9FD3E8',
  164. '#FBE6AA',
  165. );
  166. if($has_tertiary_color) {
  167. $light[] = '#F9F9F9';
  168. $medium[] = '#F9F9F9';
  169. $dark[] = '#364043';
  170. }
  171. add_color_palette(
  172. $light,
  173. /* translators: This is the name for a color scheme */
  174. 'Light'
  175. );
  176. add_color_palette(
  177. $medium,
  178. /* translators: This is the name for a color scheme */
  179. 'Medium'
  180. );
  181. add_color_palette(
  182. $dark,
  183. /* translators: This is the name for a color scheme */
  184. 'Dark'
  185. );