wpcom-colors.php 4.2 KB

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