PluginProbe ʕ •ᴥ•ʔ
Admin Help Docs / 2.0.0.1
Admin Help Docs v2.0.0.1
2.0.1.1 trunk 1.4.3.2 2.0.0 2.0.0.1 2.0.0.2 2.0.1
admin-help-docs / inc / colors.php
admin-help-docs / inc Last commit date
css 3 months ago docs 3 months ago img 3 months ago js 3 months ago tabs 3 months ago api.php 3 months ago cleanup.php 3 months ago colors.php 3 months ago deprecated.php 3 months ago header.php 3 months ago helpers.php 3 months ago index.php 3 months ago menu.php 3 months ago plugins-page.php 3 months ago post-type-help-doc-imports.php 3 months ago post-type-help-docs.php 3 months ago shortcodes.php 3 months ago taxonomy-folders.php 3 months ago
colors.php
423 lines
1 <?php
2 /**
3 * Colors
4 */
5
6 namespace PluginRx\AdminHelpDocs;
7
8 if ( ! defined( 'ABSPATH' ) ) exit;
9
10 class Colors {
11
12 /**
13 * Predefined color themes
14 */
15 public static function themes() : array {
16 $default_colors = [];
17 foreach ( self::defaults() as $key => $data ) {
18 $default_colors[ $key ] = $data[ 'color' ];
19 }
20
21 $themes = [
22 'classic' => [
23 'label' => __( 'Classic', 'admin-help-docs' ),
24 'colors' => $default_colors,
25 ],
26 'corporate' => [
27 'label' => __( 'Corporate', 'admin-help-docs' ),
28 'colors' => [
29 'doc_accent' => '#C99A2C',
30 'doc_bg' => '#DCF3F6',
31 'doc_title' => '#093B60',
32 'doc_font' => '#023260',
33 'doc_link' => '#00BAD2',
34 'header_bg' => '#093B60',
35 'header_font' => '#BEEEF3',
36 'header_tab' => '#C99A2C',
37 'header_tab_link' => '#BEEEF3',
38 'subheader_bg' => '#D8F5F8',
39 'subheader_font' => '#093B60',
40 'button' => '#093B60',
41 'button_font' => '#FFFFFF',
42 'button_hover' => '#006630',
43 ],
44 ],
45 'sunrise' => [
46 'label' => __( 'Sunrise', 'admin-help-docs' ),
47 'colors' => [
48 'doc_accent' => '#FF6B6B',
49 'doc_bg' => '#FFF8F0',
50 'doc_title' => '#4E342E',
51 'doc_font' => '#5D4037',
52 'doc_link' => '#FF8A65',
53 'header_bg' => '#FF7043',
54 'header_font' => '#FFFFFF',
55 'header_tab' => '#FFAB91',
56 'header_tab_link' => '#FFCCBC',
57 'subheader_bg' => '#FF8A65',
58 'subheader_font' => '#4E342E',
59 'button' => '#FF8C42',
60 'button_font' => '#FFFFFF',
61 'button_hover' => '#E76F51',
62 ],
63 ],
64 'ocean' => [
65 'label' => __( 'Ocean', 'admin-help-docs' ),
66 'colors' => [
67 'doc_accent' => '#0288D1',
68 'doc_bg' => '#E3F2FD',
69 'doc_title' => '#01579B',
70 'doc_font' => '#0277BD',
71 'doc_link' => '#039BE5',
72 'header_bg' => '#0277BD',
73 'header_font' => '#FFFFFF',
74 'header_tab' => '#4FC3F7',
75 'header_tab_link' => '#B3E5FC',
76 'subheader_bg' => '#03A9F4',
77 'subheader_font' => '#01579B',
78 'button' => '#0277BD',
79 'button_font' => '#FFFFFF',
80 'button_hover' => '#01579B',
81 ],
82 ],
83 'forest' => [
84 'label' => __( 'Forest', 'admin-help-docs' ),
85 'colors' => [
86 'doc_accent' => '#2E7D32',
87 'doc_bg' => '#E8F5E9',
88 'doc_title' => '#1B5E20',
89 'doc_font' => '#2E7D32',
90 'doc_link' => '#43A047',
91 'header_bg' => '#1B5E20',
92 'header_font' => '#FFFFFF',
93 'header_tab' => '#66BB6A',
94 'header_tab_link' => '#A5D6A7',
95 'subheader_bg' => '#43A047',
96 'subheader_font' => '#1B5E20',
97 'button' => '#388E3C',
98 'button_font' => '#FFFFFF',
99 'button_hover' => '#1B5E20',
100 ],
101 ],
102 'midnight' => [
103 'label' => __( 'Midnight', 'admin-help-docs' ),
104 'colors' => [
105 'doc_accent' => '#8E24AA',
106 'doc_bg' => '#1B1B2F',
107 'doc_title' => '#E0E0E0',
108 'doc_font' => '#C5CAE9',
109 'doc_link' => '#7E57C2',
110 'header_bg' => '#311B92',
111 'header_font' => '#FFFFFF',
112 'header_tab' => '#512DA8',
113 'header_tab_link' => '#B39DDB',
114 'subheader_bg' => '#7E57C2',
115 'subheader_font' => '#E0E0E0',
116 'button' => '#6A1B9A',
117 'button_font' => '#FFFFFF',
118 'button_hover' => '#4A148C',
119 ],
120 ],
121 'sunset' => [
122 'label' => __( 'Sunset', 'admin-help-docs' ),
123 'colors' => [
124 'doc_accent' => '#FF7043',
125 'doc_bg' => '#FFF3E0',
126 'doc_title' => '#BF360C',
127 'doc_font' => '#E64A19',
128 'doc_link' => '#FF5722',
129 'header_bg' => '#F4511E',
130 'header_font' => '#FFFFFF',
131 'header_tab' => '#FF8A65',
132 'header_tab_link' => '#FFCCBC',
133 'subheader_bg' => '#FF7043',
134 'subheader_font' => '#BF360C',
135 'button' => '#F4511E',
136 'button_font' => '#FFFFFF',
137 'button_hover' => '#BF360C',
138 ],
139 ],
140 'sandstone' => [
141 'label' => __( 'Sandstone', 'admin-help-docs' ),
142 'colors' => [
143 'doc_accent' => '#D79F65',
144 'doc_bg' => '#FFF7E6',
145 'doc_title' => '#8D6E63',
146 'doc_font' => '#A1887F',
147 'doc_link' => '#BCAAA4',
148 'header_bg' => '#B8764C',
149 'header_font' => '#FFFFFF',
150 'header_tab' => '#D7B19D',
151 'header_tab_link' => '#FFE0B2',
152 'subheader_bg' => '#D79F65',
153 'subheader_font' => '#8D6E63',
154 'button' => '#B8764C',
155 'button_font' => '#FFFFFF',
156 'button_hover' => '#8C5E3B',
157 ],
158 ],
159 'skyline' => [
160 'label' => __( 'Skyline', 'admin-help-docs' ),
161 'colors' => [
162 'doc_accent' => '#607D8B',
163 'doc_bg' => '#ECEFF1',
164 'doc_title' => '#37474F',
165 'doc_font' => '#455A64',
166 'doc_link' => '#546E7A',
167 'header_bg' => '#455A64',
168 'header_font' => '#FFFFFF',
169 'header_tab' => '#90A4AE',
170 'header_tab_link' => '#CFD8DC',
171 'subheader_bg' => '#607D8B',
172 'subheader_font' => '#37474F',
173 'button' => '#455A64',
174 'button_font' => '#FFFFFF',
175 'button_hover' => '#263238',
176 ],
177 ],
178 'lavender' => [
179 'label' => __( 'Lavender', 'admin-help-docs' ),
180 'colors' => [
181 'doc_accent' => '#7E57C2',
182 'doc_bg' => '#F3E5F5',
183 'doc_title' => '#4A148C',
184 'doc_font' => '#6A1B9A',
185 'doc_link' => '#9575CD',
186 'header_bg' => '#5E35B1',
187 'header_font' => '#FFFFFF',
188 'header_tab' => '#B39DDB',
189 'header_tab_link' => '#E1BEE7',
190 'subheader_bg' => '#7E57C2',
191 'subheader_font' => '#4A148C',
192 'button' => '#5E35B1',
193 'button_font' => '#FFFFFF',
194 'button_hover' => '#4527A0',
195 ],
196 ],
197 'citrus' => [
198 'label' => __( 'Citrus', 'admin-help-docs' ),
199 'colors' => [
200 'doc_accent' => '#FFA000',
201 'doc_bg' => '#FFFDE7',
202 'doc_title' => '#FF6F00',
203 'doc_font' => '#FF8F00',
204 'doc_link' => '#FFC107',
205 'header_bg' => '#FFB300',
206 'header_font' => '#FFFFFF',
207 'header_tab' => '#FFD54F',
208 'header_tab_link' => '#FFF9C4',
209 'subheader_bg' => '#FFA000',
210 'subheader_font' => '#FF6F00',
211 'button' => '#FFB300',
212 'button_font' => '#FFFFFF',
213 'button_hover' => '#FF8F00',
214 ],
215 ],
216 'alabaster' => [
217 'label' => __( 'Alabaster', 'admin-help-docs' ),
218 'colors' => [
219 'doc_accent' => '#D0D0D0',
220 'doc_bg' => '#FFFFFF',
221 'doc_title' => '#1D2327',
222 'doc_font' => '#1F2D5A',
223 'doc_link' => '#2F76DB',
224 'header_bg' => '#F5F5F5',
225 'header_font' => '#1D2327',
226 'header_tab' => '#E0E0E0',
227 'header_tab_link' => '#616161',
228 'subheader_bg' => '#ECECEC',
229 'subheader_font' => '#1D2327',
230 'button' => '#E0E0E0',
231 'button_font' => '#1D2327',
232 'button_hover' => '#C0C0C0',
233 ],
234 ],
235 'marigold' => [
236 'label' => __( 'Marigold', 'admin-help-docs' ),
237 'colors' => [
238 'doc_accent' => '#FFD54F',
239 'doc_bg' => '#FFFDE7',
240 'doc_title' => '#5D4037',
241 'doc_font' => '#6D4C41',
242 'doc_link' => '#FFA000',
243 'header_bg' => '#FFF8E1',
244 'header_font' => '#5D4037',
245 'header_tab' => '#FFECB3',
246 'header_tab_link' => '#8D6E63',
247 'subheader_bg' => '#FFE082',
248 'subheader_font' => '#5D4037',
249 'button' => '#FFD54F',
250 'button_font' => '#5D4037',
251 'button_hover' => '#FFC107',
252 ],
253 ],
254 ];
255
256 return apply_filters( 'helpdocs_color_themes', $themes );
257 } // End themes()
258
259
260 /**
261 * Default colors
262 */
263 public static function defaults( $key = null ) : array {
264 $defaults = [
265 'doc_accent' => [
266 'color' => '#306DC4',
267 'label' => __( 'Doc Accent Color', 'admin-help-docs' ),
268 ],
269 'doc_bg' => [
270 'color' => '#FBFBFB',
271 'label' => __( 'Doc Background Color', 'admin-help-docs' ),
272 ],
273 'doc_title' => [
274 'color' => '#1D2327',
275 'label' => __( 'Doc Title Color', 'admin-help-docs' ),
276 ],
277 'doc_font' => [
278 'color' => '#1F2D5A',
279 'label' => __( 'Doc Font Color', 'admin-help-docs' ),
280 ],
281 'doc_link' => [
282 'color' => '#2F76DB',
283 'label' => __( 'Doc Link Color', 'admin-help-docs' ),
284 ],
285 'header_bg' => [
286 'color' => '#1D2327',
287 'label' => __( 'Header BG Color', 'admin-help-docs' ),
288 ],
289 'header_font' => [
290 'color' => '#FFFFFF',
291 'label' => __( 'Header Font Color', 'admin-help-docs' ),
292 ],
293 'header_tab' => [
294 'color' => '#475467',
295 'label' => __( 'Header Tab Color', 'admin-help-docs' ),
296 ],
297 'header_tab_link' => [
298 'color' => '#98a2b3',
299 'label' => __( 'Header Tab Link Color', 'admin-help-docs' ),
300 ],
301 'subheader_bg' => [
302 'color' => '#0783be',
303 'label' => __( 'Subheader BG Color', 'admin-help-docs' ),
304 ],
305 'subheader_font' => [
306 'color' => '#1D2327',
307 'label' => __( 'Subheader Font Color', 'admin-help-docs' ),
308 ],
309 'button' => [
310 'color' => '#0783be',
311 'label' => __( 'Button Color', 'admin-help-docs' ),
312 ],
313 'button_font' => [
314 'color' => '#FFFFFF',
315 'label' => __( 'Button Font Color', 'admin-help-docs' ),
316 ],
317 'button_hover' => [
318 'color' => '#066998',
319 'label' => __( 'Button Hover Color', 'admin-help-docs' ),
320 ],
321 ];
322
323 $defaults = apply_filters( 'helpdocs_color_defaults', $defaults );
324
325 if ( $key !== null ) {
326 return $defaults[ $key ] ?? [];
327 }
328
329 return $defaults;
330 } // End defaults()
331
332
333 /**
334 * Get a color value
335 *
336 * @param string|null $key The color key
337 * @return string|array|false The color value(s) or false if invalid key
338 */
339 public static function get( $key = null ) : array|string|false {
340 $defaults = self::defaults();
341 $stored = get_option( 'helpdocs_colors', false );
342
343 $option_map = [
344 'doc_accent' => 'helpdocs_color_ac',
345 'doc_bg' => 'helpdocs_color_bg',
346 'doc_title' => 'helpdocs_color_ti',
347 'doc_font' => 'helpdocs_color_fg',
348 'doc_link' => 'helpdocs_color_cl',
349 ];
350
351 if ( $key === null ) {
352
353 $resolved = [];
354 foreach ( $defaults as $color_key => $default ) {
355 $value = false;
356
357 if ( is_array( $stored ) && isset( $stored[ $color_key ] ) && $stored[ $color_key ] !== '' ) {
358 $value = sanitize_text_field( $stored[ $color_key ] );
359 } elseif ( isset( $option_map[ $color_key ] ) ) {
360 $legacy = sanitize_text_field( get_option( $option_map[ $color_key ], '' ) );
361 if ( $legacy !== '' ) {
362 $value = $legacy;
363 }
364 }
365
366 $resolved[ $color_key ] = $value !== false ? $value : $default[ 'color' ];
367 }
368
369 return $resolved;
370 }
371
372 if ( empty( $defaults[ $key ] ) ) {
373 return false;
374 }
375
376 if ( is_array( $stored ) && isset( $stored[ $key ] ) && $stored[ $key ] !== '' ) {
377 return sanitize_text_field( $stored[ $key ] );
378 }
379
380 if ( isset( $option_map[ $key ] ) ) {
381 $legacy = sanitize_text_field( get_option( $option_map[ $key ], '' ) );
382 if ( $legacy !== '' ) {
383 return $legacy;
384 }
385 }
386
387 return $defaults[ $key ][ 'color' ];
388 } // End get()
389
390
391 /**
392 * Convert the old method of storage each color as a separate option into the new method of storing all colors together in a single option as an associative array. This should only be run once during an upgrade routine, and will check if the new option already exists before attempting to convert.
393 */
394 public static function convert_color_storage() : void {
395 if ( get_option( 'helpdocs_colors', false ) !== false ) {
396 return;
397 }
398
399 $option_map = [
400 'doc_accent' => 'helpdocs_color_ac',
401 'doc_bg' => 'helpdocs_color_bg',
402 'doc_title' => 'helpdocs_color_ti',
403 'doc_font' => 'helpdocs_color_fg',
404 'doc_link' => 'helpdocs_color_cl',
405 ];
406
407 $new_colors = [];
408 foreach ( $option_map as $new_key => $old_option_name ) {
409 $old_value = sanitize_text_field( get_option( $old_option_name, '' ) );
410 if ( $old_value !== '' ) {
411 $new_colors[ $new_key ] = $old_value;
412 }
413 }
414
415 if ( ! empty( $new_colors ) ) {
416 update_option( 'helpdocs_colors', $new_colors );
417 foreach ( $option_map as $old_option_name ) {
418 delete_option( $old_option_name );
419 }
420 }
421 } // End convert_color_storage()
422
423 }