wpcom-editor-colors.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <?php
  2. /*
  3. * Custom Editor Colors
  4. */
  5. // Background Color
  6. // $config-global--color-background-default
  7. add_editor_color_rule(
  8. 'bg',
  9. '#FFFFFF',
  10. array(
  11. // Background-color
  12. array( '#editor .editor-styles-wrapper', 'background-color' ),
  13. // Text-color
  14. array(
  15. '#editor .editor-styles-wrapper .button,
  16. #editor .editor-styles-wrapper .button.has-focus,
  17. #editor .editor-styles-wrapper .button:focus,
  18. #editor .editor-styles-wrapper .button:hover,
  19. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts + .button,
  20. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts + .button:focus,
  21. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts + .button:hover,
  22. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts + .has-focus.button,
  23. #editor .editor-styles-wrapper .wp-block-button__link,
  24. #editor .editor-styles-wrapper .wp-block-button__link.has-focus,
  25. #editor .editor-styles-wrapper .wp-block-button__link:focus,
  26. #editor .editor-styles-wrapper .wp-block-button__link:hover,
  27. #editor .editor-styles-wrapper .wp-block-cover-image,
  28. #editor .editor-styles-wrapper .wp-block-cover-image:not([class*="background-color"]) .block-editor-block-list__block,
  29. #editor .editor-styles-wrapper .wp-block-cover-image:not([class*="background-color"]) .wp-block-cover-image-text,
  30. #editor .editor-styles-wrapper .wp-block-cover-image:not([class*="background-color"]) .wp-block-cover-text,
  31. #editor .editor-styles-wrapper .wp-block-cover-image:not([class*="background-color"]) .wp-block-cover__inner-container,
  32. #editor .editor-styles-wrapper .wp-block-cover-image:not([class*="background-color"]) .block-editor-block-list__block,
  33. #editor .editor-styles-wrapper .wp-block-cover,
  34. #editor .editor-styles-wrapper .wp-block-cover:not([class*="background-color"]) .block-editor-block-list__block,
  35. #editor .editor-styles-wrapper .wp-block-cover:not([class*="background-color"]) .wp-block-cover-image-text,
  36. #editor .editor-styles-wrapper .wp-block-cover:not([class*="background-color"]) .wp-block-cover-text,
  37. #editor .editor-styles-wrapper .wp-block-cover:not([class*="background-color"]) .wp-block-cover__inner-container,
  38. #editor .editor-styles-wrapper .wp-block-cover:not([class*="background-color"]) .block-editor-block-list__block,
  39. #editor .editor-styles-wrapper .wp-block-search .wp-block-search__button,
  40. #editor .editor-styles-wrapper .wp-block-pullquote.is-style-solid-color',
  41. 'color',
  42. ),
  43. // Text-color darkened
  44. array( '#editor .editor-styles-wrapper .wp-block-separator.is-style-dots', 'color', '-1' ),
  45. // Background color darkened
  46. array(
  47. '#editor .editor-styles-wrapper .wp-block-table.is-style-stripes tbody tr:nth-child(odd),
  48. #editor .editor-styles-wrapper table.is-style-stripes tbody tr:nth-child(odd)',
  49. 'background-color',
  50. '-1',
  51. ),
  52. // Border-color darkened
  53. array( '#editor .editor-styles-wrapper .wp-block-code', 'border-color', '-1' ),
  54. // Border-top-color darkened
  55. array( '#editor .editor-styles-wrapper .wp-block-pullquote', 'border-top-color', '-1' ),
  56. // Border-bottom-color darkened
  57. array(
  58. '#editor .editor-styles-wrapper .wp-block-pullquote,
  59. #editor .editor-styles-wrapper .wp-block-separator',
  60. 'border-bottom-color',
  61. '-1',
  62. ),
  63. /**
  64. * Utility Classes
  65. */
  66. // Text-color
  67. array(
  68. '#editor .editor-styles-wrapper .has-primary-background-color[class],
  69. #editor .editor-styles-wrapper .has-secondary-background-color[class],
  70. #editor .editor-styles-wrapper .has-foreground-background-color[class],
  71. #editor .editor-styles-wrapper .has-foreground-dark-background-color[class],
  72. #editor .editor-styles-wrapper .has-foreground-light-background-color[class],
  73. #editor .editor-styles-wrapper .has-background-color[class]',
  74. 'color',
  75. ),
  76. // Background-color
  77. array(
  78. '#editor .editor-styles-wrapper .has-background-background-color[class],
  79. #editor .editor-styles-wrapper .wp-block .has-background-background-color[class]',
  80. 'background-color',
  81. ),
  82. // Text-color darkened
  83. array(
  84. '#editor .editor-styles-wrapper .has-background-dark-color[class],
  85. #editor .editor-styles-wrapper .wp-block .has-background-dark-color[class]',
  86. 'color',
  87. '-1',
  88. ),
  89. // Background-color darkened
  90. array(
  91. '#editor .editor-styles-wrapper .has-background-dark-background-color[class],
  92. #editor .editor-styles-wrapper .wp-block .has-background-dark-background-color[class]',
  93. 'background-color',
  94. '-1',
  95. ),
  96. // Text-color lightened
  97. array(
  98. '#editor .editor-styles-wrapper .has-background-light-color[class],
  99. #editor .editor-styles-wrapper .wp-block .has-background-light-color[class]',
  100. 'color',
  101. '+1',
  102. ),
  103. // Background-color lightened
  104. array(
  105. '#editor .editor-styles-wrapper .has-background-light-background-color[class],
  106. #editor .editor-styles-wrapper .wp-block .has-background-light-background-color[class]',
  107. 'background-color',
  108. '+1',
  109. ),
  110. ),
  111. __( 'Background Color' )
  112. );
  113. // Link Color
  114. // $config-global--color-primary-default
  115. add_editor_color_rule(
  116. 'link',
  117. '#CA2017',
  118. array(
  119. // Text-color
  120. array(
  121. '#editor .editor-styles-wrapper .wp-block-button.is-style-outline .wp-block-button__link:not(.has-text-color),
  122. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .entry-title a,
  123. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .entry-title a:active,
  124. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .entry-title a:focus,
  125. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .entry-title a:hover,
  126. #editor .editor-styles-wrapper .wp-block-button__link.is-style-outline,
  127. #editor .editor-styles-wrapper a',
  128. 'color',
  129. ),
  130. // Background-color
  131. array(
  132. '#editor .editor-styles-wrapper .button,
  133. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts + .button,
  134. #editor .editor-styles-wrapper .wp-block-button:not(.is-style-outline) .wp-block-button__link:not(.has-background),
  135. #editor .editor-styles-wrapper .wp-block-search .wp-block-search__button,
  136. #editor .editor-styles-wrapper .wp-block-search .wp-block-search__button:focus,
  137. #editor .editor-styles-wrapper .wp-block-search .wp-block-search__button:hover,
  138. #editor .editor-styles-wrapper .wp-block-pullquote.is-style-solid-color',
  139. 'background-color',
  140. ),
  141. // Border color left
  142. array( '#editor .editor-styles-wrapper .wp-block-quote', 'border-left-color' ),
  143. // Border color right
  144. array(
  145. '#editor .editor-styles-wrapper .wp-block-quote[style*="text-align: right"],
  146. #editor .editor-styles-wrapper .wp-block-quote[style*="text-align:right"]',
  147. 'border-right-color',
  148. ),
  149. // Border-color (forms)
  150. array(
  151. '#editor .editor-styles-wrapper .wp-block-search .wp-block-search__input:focus,
  152. textarea:focus',
  153. 'border-color',
  154. ),
  155. /**
  156. * Utility Classes
  157. */
  158. // Text-color
  159. array(
  160. '#editor .editor-styles-wrapper .has-primary-color[class],
  161. #editor .editor-styles-wrapper .wp-block .has-primary-color[class]',
  162. 'color',
  163. ),
  164. // Background-color
  165. array(
  166. '#editor .editor-styles-wrapper .has-primary-background-color[class],
  167. #editor .editor-styles-wrapper .wp-block .has-primary-background-color[class]',
  168. 'background-color',
  169. ),
  170. ),
  171. __( 'Link Color' )
  172. );
  173. // Text Color
  174. // $config-global--color-foreground-default
  175. add_editor_color_rule(
  176. 'txt',
  177. '#222222',
  178. array(
  179. // Text-color
  180. array(
  181. '#editor .editor-styles-wrapper .editor-post-title__block .editor-post-title__input,
  182. #editor .editor-styles-wrapper .wp-block-button.is-style-outline .wp-block-button__link.has-focus,
  183. #editor .editor-styles-wrapper .wp-block-button.is-style-outline .wp-block-button__link:focus,
  184. #editor .editor-styles-wrapper .wp-block-button.is-style-outline .wp-block-button__link:hover,
  185. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .cat-links a:active,
  186. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .cat-links a:hover,
  187. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .entry-meta a:active,
  188. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .entry-meta a:hover,
  189. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .entry-title a:hover,
  190. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .more-link:active,
  191. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .more-link:hover,
  192. #editor .editor-styles-wrapper .wp-block-button__link.is-style-outline.has-focus,
  193. #editor .editor-styles-wrapper .wp-block-button__link.is-style-outline:focus,
  194. #editor .editor-styles-wrapper .wp-block-button__link.is-style-outline:hover,
  195. #editor .editor-styles-wrapper .wp-block-pullquote,
  196. #editor .editor-styles-wrapper .wp-block-table.is-style-stripes tbody tr:nth-child(odd),
  197. #editor .editor-styles-wrapper table.is-style-stripes tbody tr:nth-child(odd),
  198. #editor .editor-styles-wrapper a:hover,
  199. #editor .editor-styles-wrapper',
  200. 'color',
  201. ),
  202. // Background-color
  203. array(
  204. '#editor .editor-styles-wrapper .button.has-focus,
  205. #editor .editor-styles-wrapper .button:focus,
  206. #editor .editor-styles-wrapper .button:hover,
  207. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts + .button:focus,
  208. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts + .button:hover,
  209. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts + .has-focus.button,
  210. #editor .editor-styles-wrapper .wp-block-button:not(.is-style-outline) .wp-block-button__link.has-focus,
  211. #editor .editor-styles-wrapper .wp-block-button:not(.is-style-outline) .wp-block-button__link:focus,
  212. #editor .editor-styles-wrapper .wp-block-button:not(.is-style-outline) .wp-block-button__link:hover,
  213. #editor .editor-styles-wrapper .wp-block-cover,
  214. #editor .editor-styles-wrapper .wp-block-cover.has-background-dim,
  215. #editor .editor-styles-wrapper .wp-block-cover-image,
  216. #editor .editor-styles-wrapper .wp-block-cover-image.has-background-dim',
  217. 'background-color',
  218. ),
  219. // Text-color brightened
  220. array(
  221. '#editor .editor-styles-wrapper .a8c-posts-list__item .a8c-posts-list-item__meta,
  222. #editor .editor-styles-wrapper .wp-block-image figcaption,
  223. #editor .editor-styles-wrapper .wp-block-latest-comments .wp-block-latest-comments__comment-date,
  224. #editor .editor-styles-wrapper .wp-block-latest-posts .wp-block-latest-posts__post-date,
  225. #editor .editor-styles-wrapper .wp-block-newspack-blocks-homepage-articles article .cat-links,
  226. #editor .editor-styles-wrapper .wp-block-newspack-blocks-homepage-articles article .entry-meta,
  227. #editor .editor-styles-wrapper .wp-block-pullquote .wp-block-pullquote__citation,
  228. #editor .editor-styles-wrapper .wp-block-pullquote cite,
  229. #editor .editor-styles-wrapper .wp-block-pullquote footer,
  230. #editor .editor-styles-wrapper .wp-block-quote .wp-block-quote__citation,
  231. #editor .editor-styles-wrapper .wp-block-quote cite,
  232. #editor .editor-styles-wrapper .wp-block-quote footer,
  233. #editor .editor-styles-wrapper .wp-block-quote.is-large .wp-block-quote__citation,
  234. #editor .editor-styles-wrapper .wp-block-quote.is-large cite,
  235. #editor .editor-styles-wrapper .wp-block-quote.is-large footer,
  236. #editor .editor-styles-wrapper .wp-block-quote.is-style-large .wp-block-quote__citation,
  237. #editor .editor-styles-wrapper .wp-block-quote.is-style-large cite,
  238. #editor .editor-styles-wrapper .wp-block-quote.is-style-large footer,
  239. #editor .editor-styles-wrapper .wp-block-video figcaption,
  240. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .cat-links,
  241. #editor .editor-styles-wrapper .wp-block-a8c-blog-posts .entry-meta,
  242. #editor .editor-styles-wrapper figcaption',
  243. 'color',
  244. '+2',
  245. ),
  246. /**
  247. * Utility Classes
  248. */
  249. // Text-color
  250. array(
  251. '#editor .editor-styles-wrapper .has-background-background-color[class],
  252. #editor .editor-styles-wrapper .wp-block .has-background-background-color[class],
  253. #editor .editor-styles-wrapper .has-background-dark-background-color[class],
  254. #editor .editor-styles-wrapper .wp-block .has-background-dark-background-color[class],
  255. #editor .editor-styles-wrapper .has-background-light-background-color[class],
  256. #editor .editor-styles-wrapper .wp-block .has-background-light-background-color[class],
  257. #editor .editor-styles-wrapper .has-foreground-color[class],
  258. #editor .editor-styles-wrapper .wp-block .has-foreground-color[class]',
  259. 'color',
  260. ),
  261. // Background-color
  262. array(
  263. '#editor .editor-styles-wrapper .has-foreground-background-color[class],
  264. #editor .editor-styles-wrapper .wp-block .has-foreground-background-color[class]',
  265. 'background-color',
  266. ),
  267. // Text-color darkened
  268. array(
  269. '#editor .editor-styles-wrapper .has-foreground-dark-color[class],
  270. #editor .editor-styles-wrapper .wp-block .has-foreground-dark-color[class]',
  271. 'color',
  272. '-1',
  273. ),
  274. // Background-color darkened
  275. array(
  276. '#editor .editor-styles-wrapper .has-foreground-dark-background-color[class],
  277. #editor .editor-styles-wrapper .wp-block .has-foreground-dark-background-color[class]',
  278. 'background-color',
  279. '-1',
  280. ),
  281. // Text-color brightened
  282. array(
  283. '#editor .editor-styles-wrapper .has-foreground-light-color[class],
  284. #editor .editor-styles-wrapper .wp-block .has-foreground-light-color[class]',
  285. 'color',
  286. '+2',
  287. ),
  288. // Background-color brightened
  289. array(
  290. '#editor .editor-styles-wrapper .has-foreground-light-background-color[class],
  291. #editor .editor-styles-wrapper .wp-block .has-foreground-light-background-color[class]',
  292. 'background-color',
  293. '+2',
  294. ),
  295. // Border-color with less opacity (dim)
  296. array(
  297. '#editor .editor-styles-wrapper .wp-block-code,
  298. #editor .editor-styles-wrapper .wp-block-search .wp-block-search__input',
  299. 'border-color',
  300. 0.8,
  301. ),
  302. ),
  303. __( 'Text Color' )
  304. );
  305. // Accent Color (Red)
  306. // $config-global--color-secondary-default
  307. add_editor_color_rule(
  308. 'fg1',
  309. '#007FDB',
  310. array(
  311. /**
  312. * Utility Classes
  313. */
  314. // Text-color
  315. array(
  316. '#editor .editor-styles-wrapper .has-secondary-color[class],
  317. #editor .editor-styles-wrapper .wp-block .has-secondary-color[class]',
  318. 'color',
  319. ),
  320. // Background-color
  321. array(
  322. '#editor .editor-styles-wrapper .has-secondary-background-color[class],
  323. #editor .editor-styles-wrapper .wp-block .has-secondary-background-color[class]',
  324. 'background-color',
  325. ),
  326. ),
  327. __( 'Secondary Color' )
  328. );
  329. /**
  330. * Custom CSS
  331. */
  332. function redhill_editor_custom_colors_extra_css() {
  333. $colors_array = get_theme_mod( 'colors_manager' );
  334. $bg = $colors_array['colors']['bg'];
  335. $txt = $colors_array['colors']['txt'];
  336. ?>
  337. #editor .editor-styles-wrapper .has-background:not(.has-background-background-color) a:not(.wp-block-button__link),
  338. #editor .editor-styles-wrapper p.has-text-color a {
  339. color: currentColor;
  340. }
  341. <?php
  342. }
  343. add_theme_support( 'custom_colors_extra_css', 'redhill_editor_custom_colors_extra_css' );