wpcom-colors.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /*
  3. * Custom Colors: Spearhead
  4. */
  5. // Background Color
  6. // --global--color-background
  7. add_color_rule( 'bg', '#FFFFFF', array(
  8. // This placeholder is needed to make the color annotations work
  9. array( '.global--color-background', 'background-color' ),
  10. ), __( 'Background Color' ) );
  11. // Foreground Color
  12. // --global--color-foreground-light
  13. add_color_rule( 'txt', '#444444', array(
  14. // This placeholder is needed to make the color annotations work
  15. array( '.global--color-foreground-light', 'color' ),
  16. ), __( 'Foreground Color' ) );
  17. // Primary Color
  18. // --global--color-primary
  19. add_color_rule( 'link', '#000000', array(
  20. // This placeholder is needed to make the color annotations work
  21. array( '.global--color-primary', 'color' ),
  22. ), __( 'Primary Color' ) );
  23. // Secondary Color
  24. // --global--color-secondary
  25. add_color_rule( 'fg1', '#3C8067', array(
  26. // Text-color
  27. array( '.global--color-secondary', 'color' ),
  28. ), __( 'Secondary Color' ) );
  29. // Tertiary Color
  30. // --global--color-tertiary
  31. add_color_rule( 'fg2', '#FAFBF6', array(
  32. // Text-color
  33. array( '.global--color-tertiary', 'color' ),
  34. ), __( 'Tertiary Color' ) );
  35. function change_color_luminescence( $hex, $amount ) {
  36. require_lib( 'colorline' );
  37. $colorline = new colorline();
  38. $hex_without_hash = substr( $hex, 1, strlen( $hex ) );
  39. $rgb = $colorline::hex_to_rgb( $hex_without_hash );
  40. $hsvl = $colorline::rgb_to_hsvl( $rgb );
  41. return 'hsl( ' . $hsvl[ 0 ] . ',' . $hsvl[ 1 ] . '%,' . ( $hsvl[ 2 ] + $amount ) . '%)';
  42. }
  43. /**
  44. * Custom CSS.
  45. * The plugin takes the body of this function and applies it in a style tag in the document head.
  46. */
  47. function seedlet_custom_colors_extra_css() {
  48. $colors_array = get_theme_mod( 'colors_manager' );
  49. $background = $colors_array['colors']['bg'];
  50. $foreground = $colors_array['colors']['txt'];
  51. $primary = $colors_array['colors']['link'];
  52. $secondary = $colors_array['colors']['fg1'];
  53. $tertiary = $colors_array['colors']['fg2'];
  54. $foreground_light = change_color_luminescence( $foreground, 10 );
  55. $foreground_dark = change_color_luminescence( $foreground, -10 );
  56. $primary_hover = change_color_luminescence( $primary, 10 );
  57. $secondary_hover = change_color_luminescence( $secondary, 10 );
  58. ?>
  59. :root,
  60. #editor .editor-styles-wrapper {
  61. --global--color-background: <?php echo $background; ?>;
  62. --global--color-foreground: <?php echo $foreground; ?>;
  63. --global--color-foreground-light: <?php echo $foreground_light; ?>;
  64. --global--color-foreground-dark: <?php echo $foreground_dark; ?>;
  65. --global--color-primary: <?php echo $primary; ?>;
  66. --global--color-primary-hover: <?php echo $primary_hover; ?>;
  67. --global--color-secondary: <?php echo $secondary; ?>;
  68. --global--color-secondary-hover: <?php echo $secondary_hover; ?>;
  69. --global--color-tertiary: <?php echo $tertiary; ?>;
  70. }
  71. <?php }
  72. add_theme_support( 'custom_colors_extra_css', 'seedlet_custom_colors_extra_css' );
  73. // Light
  74. add_color_palette( array(
  75. '#EFFCED',
  76. '#DCEEE2',
  77. '#297B27',
  78. '#639182',
  79. '#333333',
  80. ), /* translators: This is the name for a color scheme */ 'Light' );
  81. // Medium
  82. add_color_palette( array(
  83. '#EEF4F7',
  84. '#0F2751',
  85. '#0F6D89',
  86. '#37374C',
  87. '#E7E7F3',
  88. ), /* translators: This is the name for a color scheme */ 'Medium' );
  89. // Dark
  90. add_color_palette( array(
  91. '#2d0f2d',
  92. '#bfadc1',
  93. '#d2cad2',
  94. '#887890',
  95. '#3a1c3a',
  96. ), /* translators: This is the name for a color scheme */ 'Dark' );