wpcom-colors-utils.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // Custom Colors: Seedlet
  3. function seedlet_define_color_annotations( $colors ) {
  4. // Background Color
  5. // --global--color-background
  6. add_color_rule( 'bg', $colors[ 'background' ], array(
  7. // This placeholder is needed to make the color annotations work
  8. array( '.global--color-background', 'background-color' ),
  9. ), __( 'Background Color' ) );
  10. // Foreground Color
  11. // --global--color-foreground-light
  12. add_color_rule( 'txt', $colors[ 'foreground' ], array(
  13. // This placeholder is needed to make the color annotations work
  14. array( '.global--color-foreground-light', 'color' ),
  15. ), __( 'Foreground Color' ) );
  16. // Primary Color
  17. // --global--color-primary
  18. add_color_rule( 'link', $colors[ 'primary' ], array(
  19. // This placeholder is needed to make the color annotations work
  20. array( '.global--color-primary', 'color' ),
  21. ), __( 'Primary Color' ) );
  22. // Secondary Color
  23. // --global--color-secondary
  24. add_color_rule( 'fg1', $colors[ 'secondary' ], array(
  25. // Text-color
  26. array( '.global--color-secondary', 'color' ),
  27. ), __( 'Secondary Color' ) );
  28. // Tertiary Color
  29. // --global--color-tertiary
  30. add_color_rule( 'fg2', $colors[ 'tertiary' ], array(
  31. // Text-color
  32. array( '.global--color-tertiary', 'color' ),
  33. ), __( 'Tertiary Color' ) );
  34. }
  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. /**
  74. * Featured Varia/Seedlet Palettes
  75. */
  76. // Light
  77. add_color_palette( array(
  78. '#FFFFFF',
  79. '#1D1E1E',
  80. '#C8133E',
  81. '#4E2F4B',
  82. '#F9F9F9',
  83. ), /* translators: This is the name for a color scheme */ 'Light' );
  84. // Medium
  85. add_color_palette( array(
  86. '#EEF4F7',
  87. '#242527',
  88. '#35845D',
  89. '#233252',
  90. '#F9F9F9',
  91. ), /* translators: This is the name for a color scheme */ 'Medium' );
  92. // Dark
  93. add_color_palette( array(
  94. '#1F2527',
  95. '#FFFFFF',
  96. '#9FD3E8',
  97. '#FBE6AA',
  98. '#364043',
  99. ), /* translators: This is the name for a color scheme */ 'Dark' );