Completed
Push — master ( 92c15a...901517 )
by
unknown
03:36
created

customizer-colour.php ➔ lsx_customizer_colour__body_get_theme_mods()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 19
nc 2
nop 0
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
1
<?php
2
if ( ! defined( 'ABSPATH' ) ) return; // Exit if accessed directly
3
4
/**
5
 * Transform SCSS to CSS
6
 */
7
function lsx_customizer_colour__scss_to_css( $scss ) {
8
	$css = '';
9
	$scssphp_file = get_template_directory() .'/vendor/leafo/scssphp/scss.inc.php';
10
11
	if ( ! empty( $scss ) && file_exists( $scssphp_file ) ) {
12
		require_once $scssphp_file;
13
14
		$compiler = new \Leafo\ScssPhp\Compiler();
15
		$compiler->setFormatter( 'Leafo\ScssPhp\Formatter\Compact' );
16
17
		try {
18
			$css = $compiler->compile( $scss );
19
		} catch ( Exception $e ) {
20
			$error = $e->getMessage();
21
			return "/*\n\n\$error:\n\n{$error}\n\n\$scss:\n\n{$scss} */";
22
		}
23
	}
24
25
	return $css;
26
}
27
28
/**
29
 * 
30
 */
31
function lsx_customizer_colour__add_footer_styles() {
32
	wp_enqueue_style( 'lsx_customizer_colour', get_stylesheet_uri() );
33
}
34
add_action( 'wp_footer', 'lsx_customizer_colour__add_footer_styles', 11 );
35
36
/**
37
 * Outputs an Underscore template for generating CSS for the color scheme.
38
 */
39
function lsx_customizer_colour__color_scheme_css_template() {
40
	global $customizer_colour_names;
41
	
42
	$colors = array();
43
44
	foreach ( $customizer_colour_names as $key => $value ) {
45
		$colors[$key] = 'unquote("{{ data.'.$key.' }}")';
46
	}
47
	?>
48
	<script type="text/html" id="tmpl-lsx-color-scheme">
49
		<?php echo esc_html( lsx_customizer_colour__top_menu_get_css( $colors ) ) ?>
50
		<?php echo esc_html( lsx_customizer_colour__header_get_css( $colors ) ) ?>
51
		<?php echo esc_html( lsx_customizer_colour__main_menu_get_css( $colors ) ) ?>
52
53
		<?php echo esc_html( lsx_customizer_colour__banner_get_css( $colors ) ) ?>
54
		<?php echo esc_html( lsx_customizer_colour__body_get_css( $colors ) ) ?>
55
56
		<?php echo esc_html( lsx_customizer_colour__footer_cta_get_css( $colors ) ) ?>
57
		<?php echo esc_html( lsx_customizer_colour__footer_widgets_get_css( $colors ) ) ?>
58
		<?php echo esc_html( lsx_customizer_colour__footer_get_css( $colors ) ) ?>
59
60
		<?php echo esc_html( lsx_customizer_colour__button_get_css( $colors ) ) ?>
61
		<?php echo esc_html( lsx_customizer_colour__button_cta_get_css( $colors ) ) ?>
62
	</script>
63
	<?php
64
}
65
add_action( 'customize_controls_print_footer_scripts', 'lsx_customizer_colour__color_scheme_css_template' );
66
67
/**
68
 * Retrieves the current color scheme.
69
 */
70
function lsx_customizer_colour__get_color_scheme() {
71
	global $customizer_colour_choices;
72
73
	$color_scheme_option = get_theme_mod( 'color_scheme', 'default' );
74
	$color_schemes = $customizer_colour_choices;
75
76
	if ( array_key_exists( $color_scheme_option, $color_schemes ) ) {
77
		return $color_schemes[ $color_scheme_option ]['colors'];
78
	}
79
80
	return $color_schemes['default']['colors'];
81
}
82
83
/**
84
 * Converts a HEX value to RGB.
85
 */
86
function lsx_customizer_colour__hex2rgb( $color ) {
87
	$color = trim( $color, '#' );
88
89
	if ( strlen( $color ) === 3 ) {
90
		$r = hexdec( substr( $color, 0, 1 ).substr( $color, 0, 1 ) );
91
		$g = hexdec( substr( $color, 1, 1 ).substr( $color, 1, 1 ) );
92
		$b = hexdec( substr( $color, 2, 1 ).substr( $color, 2, 1 ) );
93
	} else if ( strlen( $color ) === 6 ) {
94
		$r = hexdec( substr( $color, 0, 2 ) );
95
		$g = hexdec( substr( $color, 2, 2 ) );
96
		$b = hexdec( substr( $color, 4, 2 ) );
97
	} else {
98
		return array();
99
	}
100
101
	return array( 'red' => $r, 'green' => $g, 'blue' => $b );
102
}
103
104
/* ################################################################################# */
105
106
107
/**
108
 * Assign CSS to button theme mod.
109
 */
110
function lsx_customizer_colour__button_set_theme_mod() {
111
	$theme_mods = lsx_customizer_colour__button_get_theme_mods();
112
	$styles     = lsx_customizer_colour__button_get_css( $theme_mods );
113
	
114
	set_theme_mod( 'lsx_customizer_colour__button_theme_mod', $styles );
115
}
116
add_action( 'after_switch_theme',   'lsx_customizer_colour__button_set_theme_mod' );
117
add_action( 'customize_save_after', 'lsx_customizer_colour__button_set_theme_mod' );
118
119
/**
120
 * Enqueues front-end CSS for the button.
121
 */
122 View Code Duplication
function lsx_customizer_colour__button_css() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
123
	$styles_from_theme_mod = get_theme_mod( 'lsx_customizer_colour__button_theme_mod' );
124
	
125
	if ( is_customize_preview() || false === $styles_from_theme_mod ) {
126
		$theme_mods = lsx_customizer_colour__button_get_theme_mods();
127
		$styles     = lsx_customizer_colour__button_get_css( $theme_mods );
128
		
129
		if ( false === $styles_from_theme_mod ) {
130
			set_theme_mod( 'lsx_customizer_colour__button_theme_mod', $styles );
131
		}
132
	} else {
133
		$styles = $styles_from_theme_mod;
134
	}
135
136
	wp_add_inline_style( 'lsx_customizer_colour', $styles );
137
}
138
add_action( 'wp_footer', 'lsx_customizer_colour__button_css', 12 );
139
140
/**
141
 * Get button CSS theme mods.
142
 */
143
function lsx_customizer_colour__button_get_theme_mods() {
144
	global $customizer_colour_names;
145
146
	$color_scheme = lsx_customizer_colour__get_color_scheme();
147
	$colors       = array();
148
	$counter      = 0;
149
150
	foreach ( $customizer_colour_names as $key => $value ) {
151
		$colors[$key] = $color_scheme[$counter];
152
		$counter++;
153
	}
154
155
	return array(
156
		'button_background_color' =>       get_theme_mod( 'button_background_color',       $colors['button_background_color'] ),
157
		'button_background_hover_color' => get_theme_mod( 'button_background_hover_color', $colors['button_background_hover_color'] ),
158
		'button_text_color' =>             get_theme_mod( 'button_text_color',             $colors['button_text_color'] ),
159
		'button_text_color_hover' =>       get_theme_mod( 'button_text_color_hover',       $colors['button_text_color_hover'] )
160
	);
161
}
162
163
/**
164
 * Returns CSS for the button.
165
 */
166
function lsx_customizer_colour__button_get_css( $colors ) {
167
	global $customizer_colour_names;
168
	
169
	$colors_template = array();
170
171
	foreach ( $customizer_colour_names as $key => $value ) {
172
		$colors_template[$key] = '';
173
	}
174
175
	$colors = wp_parse_args( $colors, $colors_template );
176
177
	$css = <<<CSS
178
		/*
179
		 *
180
		 * Button
181
		 *
182
		 */
183
184
		.btn,
185
		.button,
186
		input[type="submit"],
187
		#searchform .input-group span.input-group-btn button.search-submit,
188
		#respond #submit {
189
			&,
190
			&:visited {
191
				background-color: {$colors['button_background_color']};
192
				color: {$colors['button_text_color']};
193
			}
194
195
			&:hover,
196
			&:active,
197
			&:focus {
198
				background-color: {$colors['button_background_hover_color']};
199
				color: {$colors['button_text_color_hover']};
200
			}
201
		}
202
203
		#infinite-handle span {
204
			&,
205
			&:visited {
206
				background-color: {$colors['button_background_color']} !important;
207
				color: {$colors['button_text_color']} !important;
208
			}
209
210
			&:hover,
211
			&:active,
212
			&:focus {
213
				background-color: {$colors['button_background_hover_color']} !important;
214
				color: {$colors['button_text_color_hover']} !important;
215
			}
216
		}
217
218
		.caldera-grid,
219
		.caldera-clarity-grid,
220
		#footer-widgets .widget form {
221
			.btn,
222
			.button-primary {
223
				&,
224
				&:visited {
225
					background-color: {$colors['button_background_color']};
226
					color: {$colors['button_text_color']};
227
				}
228
229
				&:hover,
230
				&:active,
231
				&:focus {
232
					background-color: {$colors['button_background_hover_color']};
233
					color: {$colors['button_text_color_hover']};
234
				}
235
			}
236
		}
237
238
		.field-wrap {
239
			input[type="submit"],
240
			input[type="button"],
241
			button {
242
				&,
243
				&:visited {
244
					background-color: {$colors['button_background_color']} !important;
245
					color: {$colors['button_text_color']} !important;
246
				}
247
248
				&:hover,
249
				&:active,
250
				&:focus {
251
					background-color: {$colors['button_background_hover_color']} !important;
252
					color: {$colors['button_text_color_hover']} !important;
253
				}
254
			}
255
		}
256
257
		article {
258
			header.entry-header {
259
				h1.entry-title {
260
					a.format-link {
261
						&,
262
						&:visited {
263
							background-color: {$colors['button_background_color']};
264
							color: {$colors['button_text_color']} !important;
265
						}
266
					}
267
				}
268
			}
269
		}
270
271
		.button-primary.border-btn,
272
		.btn.border-btn,
273
		button.border-btn,
274
		.wp-pagenavi a,
275
		.lsx-postnav > a {
276
			&,
277
			&:visited {
278
				border-color: {$colors['button_background_color']} !important;
279
				color: {$colors['button_background_color']} !important;
280
			}
281
282
			&:hover,
283
			&:active,
284
			&:focus {
285
				background-color: {$colors['button_background_hover_color']} !important;
286
				border-color: {$colors['button_background_hover_color']} !important;
287
				color: {$colors['button_text_color_hover']} !important;
288
			}
289
		}
290
291
		.wp-pagenavi span.current,
292
		.lsx-postnav > span {
293
			background-color: {$colors['button_background_color']} !important;
294
			border-color: {$colors['button_background_color']} !important;
295
			color: {$colors['button_text_color']} !important;
296
		}
297
298
		input[type="text"],
299
		input[type="search"],
300
		input[type="email"],
301
		input[type="number"],
302
		input[type="password"],
303
		textarea,
304
		select {
305
			&:focus {
306
				border-color: {$colors['button_background_color']} !important;
307
			}
308
		}
309
310
		/*
311
		 *
312
		 * Button WooCommerce
313
		 *
314
		 */
315
316
		.woocommerce {
317
			a.button,
318
			button.button,
319
			input.button,
320
			input[type="submit"],
321
			#respond input#submit {
322
				&,
323
				&:visited {
324
					background-color: {$colors['button_background_color']} !important;
325
					color: {$colors['button_text_color']} !important;
326
				}
327
328
				&:hover,
329
				&:active,
330
				&:focus {
331
					background-color: {$colors['button_background_hover_color']} !important;
332
					color: {$colors['button_text_color_hover']} !important;
333
				}
334
			}
335
336
			table.cart {
337
				td.actions {
338
					.coupon {
339
						.input-text {
340
							&:focus {
341
								border-color: {$colors['button_background_color']} !important;
342
							}
343
						}
344
					}
345
				}
346
			}
347
348
			nav.woocommerce-pagination a {
349
				&,
350
				&:visited {
351
					border-color: {$colors['button_background_color']} !important;
352
					color: {$colors['button_background_color']} !important;
353
				}
354
355
				&:hover,
356
				&:active,
357
				&:focus {
358
					background-color: {$colors['button_background_hover_color']} !important;
359
					border-color: {$colors['button_background_hover_color']} !important;
360
					color: {$colors['button_text_color_hover']} !important;
361
				}
362
			}
363
364
			nav.woocommerce-pagination span.current {
365
				background-color: {$colors['button_background_color']} !important;
366
				border-color: {$colors['button_background_color']} !important;
367
				color: {$colors['button_text_color']} !important;
368
			}
369
		}
370
CSS;
371
372
	$css = apply_filters( 'lsx_customizer_colour_selectors_button', $css, $colors );
373
	$css = lsx_customizer_colour__scss_to_css( $css );
374
	return $css;
375
}
376
377
378
/* ################################################################################# */
379
380
381
/**
382
 * Assign CSS to button cta theme mod.
383
 */
384
function lsx_customizer_colour__button_cta_set_theme_mod() {
385
	$theme_mods = lsx_customizer_colour__button_cta_get_theme_mods();
386
	$styles     = lsx_customizer_colour__button_cta_get_css( $theme_mods );
387
	
388
	set_theme_mod( 'lsx_customizer_colour__button_cta_theme_mod', $styles );
389
}
390
add_action( 'after_switch_theme',   'lsx_customizer_colour__button_cta_set_theme_mod' );
391
add_action( 'customize_save_after', 'lsx_customizer_colour__button_cta_set_theme_mod' );
392
393
/**
394
 * Enqueues front-end CSS for the button cta.
395
 */
396 View Code Duplication
function lsx_customizer_colour__button_cta_css() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
397
	$styles_from_theme_mod = get_theme_mod( 'lsx_customizer_colour__button_cta_theme_mod' );
398
	
399
	if ( is_customize_preview() || false === $styles_from_theme_mod ) {
400
		$theme_mods = lsx_customizer_colour__button_cta_get_theme_mods();
401
		$styles     = lsx_customizer_colour__button_cta_get_css( $theme_mods );
402
		
403
		if ( false === $styles_from_theme_mod ) {
404
			set_theme_mod( 'lsx_customizer_colour__button_cta_theme_mod', $styles );
405
		}
406
	} else {
407
		$styles = $styles_from_theme_mod;
408
	}
409
410
	wp_add_inline_style( 'lsx_customizer_colour', $styles );
411
}
412
add_action( 'wp_footer', 'lsx_customizer_colour__button_cta_css', 12 );
413
414
/**
415
 * Get button cta CSS theme mods.
416
 */
417
function lsx_customizer_colour__button_cta_get_theme_mods() {
418
	global $customizer_colour_names;
419
420
	$color_scheme = lsx_customizer_colour__get_color_scheme();
421
	$colors       = array();
422
	$counter      = 0;
423
424
	foreach ( $customizer_colour_names as $key => $value ) {
425
		$colors[$key] = $color_scheme[$counter];
426
		$counter++;
427
	}
428
429
	return array(
430
		'button_cta_background_color' =>       get_theme_mod( 'button_cta_background_color',       $colors['button_cta_background_color'] ),
431
		'button_cta_background_hover_color' => get_theme_mod( 'button_cta_background_hover_color', $colors['button_cta_background_hover_color'] ),
432
		'button_cta_text_color' =>             get_theme_mod( 'button_cta_text_color',             $colors['button_cta_text_color'] ),
433
		'button_cta_text_color_hover' =>       get_theme_mod( 'button_cta_text_color_hover',       $colors['button_cta_text_color_hover'] )
434
	);
435
}
436
437
/**
438
 * Returns CSS for the button cta.
439
 */
440
function lsx_customizer_colour__button_cta_get_css( $colors ) {
441
	global $customizer_colour_names;
442
	
443
	$colors_template = array();
444
445
	foreach ( $customizer_colour_names as $key => $value ) {
446
		$colors_template[$key] = '';
447
	}
448
449
	$colors = wp_parse_args( $colors, $colors_template );
450
451
	$css = <<<CSS
452
		/*
453
		 *
454
		 * Button CTA
455
		 *
456
		 */
457
458
		.btn {
459
			&.cta-btn {
460
				&,
461
				&:visited {
462
					background-color: {$colors['button_cta_background_color']} !important;
463
					color: {$colors['button_cta_text_color']} !important;
464
				}
465
466
				&:hover,
467
				&:active,
468
				&:focus {
469
					background-color: {$colors['button_cta_background_hover_color']} !important;
470
					color: {$colors['button_cta_text_color_hover']} !important;
471
				}
472
			}
473
474
			&.cta-border-btn {
475
				&,
476
				&:visited {
477
					border-color: {$colors['button_cta_background_color']} !important;
478
					color: {$colors['button_cta_background_color']} !important;
479
				}
480
481
				&:hover,
482
				&:active,
483
				&:focus {
484
					background-color: {$colors['button_cta_background_hover_color']} !important;
485
					border-color: {$colors['button_cta_background_hover_color']} !important;
486
					color: {$colors['button_cta_text_color_hover']} !important;
487
				}
488
			}
489
		}
490
491
		#top-menu {
492
			nav.top-menu {
493
				ul {
494
					li.cta {
495
						a {
496
							&,
497
							&:visited {
498
								background-color: {$colors['button_cta_background_color']} !important;
499
								color: {$colors['button_cta_text_color']} !important;
500
							}
501
502
							&:hover,
503
							&:active,
504
							&:focus {
505
								background-color: {$colors['button_cta_background_hover_color']} !important;
506
								color: {$colors['button_cta_text_color_hover']} !important;
507
							}
508
						}
509
					}
510
				}
511
			}
512
		}
513
514
		/*
515
		 *
516
		 * Button CTA WooCommerce
517
		 *
518
		 */
519
520
		.woocommerce {
521
			a.button,
522
			button.button,
523
			input.button,
524
			input[type="submit"],
525
			#respond input#submit {
526
				&.alt {
527
					&,
528
					&:visited {
529
						background-color: {$colors['button_cta_background_color']} !important;
530
						color: {$colors['button_cta_text_color']} !important;
531
					}
532
533
					&:hover,
534
					&:active,
535
					&:focus {
536
						background-color: {$colors['button_cta_background_hover_color']} !important;
537
						color: {$colors['button_cta_text_color_hover']} !important;
538
					}
539
				}
540
			}
541
		}
542
CSS;
543
544
	$css = apply_filters( 'lsx_customizer_colour_selectors_button_cta', $css, $colors );
545
	$css = lsx_customizer_colour__scss_to_css( $css );
546
	return $css;
547
}
548
549
550
/* ################################################################################# */
551
552
553
/**
554
 * Assign CSS to top menu theme mod.
555
 */
556
function lsx_customizer_colour__top_menu_set_theme_mod() {
557
	$theme_mods = lsx_customizer_colour__top_menu_get_theme_mods();
558
	$styles     = lsx_customizer_colour__top_menu_get_css( $theme_mods );
559
	
560
	set_theme_mod( 'lsx_customizer_colour__top_menu_theme_mod', $styles );
561
}
562
add_action( 'after_switch_theme',   'lsx_customizer_colour__top_menu_set_theme_mod' );
563
add_action( 'customize_save_after', 'lsx_customizer_colour__top_menu_set_theme_mod' );
564
565
/**
566
 * Enqueues front-end CSS for the top menu.
567
 */
568 View Code Duplication
function lsx_customizer_colour__top_menu_css() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
569
	$styles_from_theme_mod = get_theme_mod( 'lsx_customizer_colour__top_menu_theme_mod' );
570
	
571
	if ( is_customize_preview() || false === $styles_from_theme_mod ) {
572
		$theme_mods = lsx_customizer_colour__top_menu_get_theme_mods();
573
		$styles     = lsx_customizer_colour__top_menu_get_css( $theme_mods );
574
		
575
		if ( false === $styles_from_theme_mod ) {
576
			set_theme_mod( 'lsx_customizer_colour__top_menu_theme_mod', $styles );
577
		}
578
	} else {
579
		$styles = $styles_from_theme_mod;
580
	}
581
582
	wp_add_inline_style( 'lsx_customizer_colour', $styles );
583
}
584
add_action( 'wp_footer', 'lsx_customizer_colour__top_menu_css', 12 );
585
586
/**
587
 * Get top menu CSS theme mods.
588
 */
589
function lsx_customizer_colour__top_menu_get_theme_mods() {
590
	global $customizer_colour_names;
591
592
	$color_scheme = lsx_customizer_colour__get_color_scheme();
593
	$colors       = array();
594
	$counter      = 0;
595
596
	foreach ( $customizer_colour_names as $key => $value ) {
597
		$colors[$key] = $color_scheme[$counter];
598
		$counter++;
599
	}
600
601
	return array(
602
		'top_menu_background_color' => get_theme_mod( 'top_menu_background_color', $colors['top_menu_background_color'] ),
603
		'top_menu_text_color' =>       get_theme_mod( 'top_menu_text_color',       $colors['top_menu_text_color'] ),
604
		'top_menu_text_hover_color' => get_theme_mod( 'top_menu_text_hover_color', $colors['top_menu_text_hover_color'] )
605
	);
606
}
607
608
/**
609
 * Returns CSS for the top menu.
610
 */
611
function lsx_customizer_colour__top_menu_get_css( $colors ) {
612
	global $customizer_colour_names;
613
	
614
	$colors_template = array();
615
616
	foreach ( $customizer_colour_names as $key => $value ) {
617
		$colors_template[$key] = '';
618
	}
619
620
	$colors = wp_parse_args( $colors, $colors_template );
621
622
	$css = <<<CSS
623
		/*
624
		 *
625
		 * Top Menu
626
		 *
627
		 */
628
629
		#top-menu {
630
			background-color: {$colors['top_menu_background_color']};
631
632
			nav.top-menu {
633
				ul {
634
					li {
635
						a {
636
							&,
637
							&:visited {
638
								color: {$colors['top_menu_text_color']};
639
							}
640
641
							&:before {
642
								color: {$colors['top_menu_text_hover_color']};
643
							}
644
645
							&:hover,
646
							&:active,
647
							&:focus {
648
								&,
649
								&:before {
650
									color: {$colors['top_menu_text_hover_color']};
651
								}
652
							}
653
						}
654
					}
655
				}
656
			}
657
		}
658
CSS;
659
660
	$css = apply_filters( 'lsx_customizer_colour_selectors_top_menu', $css, $colors );
661
	$css = lsx_customizer_colour__scss_to_css( $css );
662
	return $css;
663
}
664
665
666
/* ################################################################################# */
667
668
669
/**
670
 * Assign CSS to header theme mod.
671
 */
672
function lsx_customizer_colour__header_set_theme_mod() {
673
	$theme_mods = lsx_customizer_colour__header_get_theme_mods();
674
	$styles     = lsx_customizer_colour__header_get_css( $theme_mods );
675
	
676
	set_theme_mod( 'lsx_customizer_colour__header_theme_mod', $styles );
677
}
678
add_action( 'after_switch_theme',   'lsx_customizer_colour__header_set_theme_mod' );
679
add_action( 'customize_save_after', 'lsx_customizer_colour__header_set_theme_mod' );
680
681
/**
682
 * Enqueues front-end CSS for the header.
683
 */
684 View Code Duplication
function lsx_customizer_colour__header_css() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
685
	$styles_from_theme_mod = get_theme_mod( 'lsx_customizer_colour__header_theme_mod' );
686
	
687
	if ( is_customize_preview() || false === $styles_from_theme_mod ) {
688
		$theme_mods = lsx_customizer_colour__header_get_theme_mods();
689
		$styles     = lsx_customizer_colour__header_get_css( $theme_mods );
690
		
691
		if ( false === $styles_from_theme_mod ) {
692
			set_theme_mod( 'lsx_customizer_colour__header_theme_mod', $styles );
693
		}
694
	} else {
695
		$styles = $styles_from_theme_mod;
696
	}
697
698
	wp_add_inline_style( 'lsx_customizer_colour', $styles );
699
}
700
add_action( 'wp_footer', 'lsx_customizer_colour__header_css', 12 );
701
702
/**
703
 * Get header CSS theme mods.
704
 */
705
function lsx_customizer_colour__header_get_theme_mods() {
706
	global $customizer_colour_names;
707
708
	$color_scheme = lsx_customizer_colour__get_color_scheme();
709
	$colors       = array();
710
	$counter      = 0;
711
712
	foreach ( $customizer_colour_names as $key => $value ) {
713
		$colors[$key] = $color_scheme[$counter];
714
		$counter++;
715
	}
716
717
	return array(
718
		'header_background_color'  => get_theme_mod( 'header_background_color',  $colors['header_background_color'] ),
719
		'header_title_color'       => get_theme_mod( 'header_title_color',       $colors['header_title_color'] ),
720
		'header_title_hover_color' => get_theme_mod( 'header_title_hover_color', $colors['header_title_hover_color'] ),
721
		'header_description_color' => get_theme_mod( 'header_description_color', $colors['header_description_color'] )
722
	);
723
}
724
725
/**
726
 * Returns CSS for the header.
727
 */
728
function lsx_customizer_colour__header_get_css( $colors ) {
729
	global $customizer_colour_names;
730
	
731
	$colors_template = array();
732
733
	foreach ( $customizer_colour_names as $key => $value ) {
734
		$colors_template[$key] = '';
735
	}
736
737
	$colors = wp_parse_args( $colors, $colors_template );
738
739
	$css = <<<CSS
740
		/*
741
		 *
742
		 * Header
743
		 *
744
		 */
745
746
		header.banner {
747
			background-color: {$colors['header_background_color']};
748
749
			.site-branding {
750
				.site-title {
751
					color: {$colors['header_title_color']};
752
753
					a {
754
						&,
755
						&:visited {
756
							color: {$colors['header_title_color']};
757
						}
758
759
						&:hover,
760
						&:active,
761
						&:focus {
762
							color: {$colors['header_title_hover_color']};
763
						}
764
					}
765
				}
766
767
				.site-description {
768
					color: {$colors['header_description_color']};
769
				}
770
			}
771
		}
772
CSS;
773
774
	$css = apply_filters( 'lsx_customizer_colour_selectors_header', $css, $colors );
775
	$css = lsx_customizer_colour__scss_to_css( $css );
776
	return $css;
777
}
778
779
780
/* ################################################################################# */
781
782
783
/**
784
 * Assign CSS to main menu theme mod.
785
 */
786
function lsx_customizer_colour__main_menu_set_theme_mod() {
787
	$theme_mods = lsx_customizer_colour__main_menu_get_theme_mods();
788
	$styles     = lsx_customizer_colour__main_menu_get_css( $theme_mods );
789
	
790
	set_theme_mod( 'lsx_customizer_colour__main_menu_theme_mod', $styles );
791
}
792
add_action( 'after_switch_theme',   'lsx_customizer_colour__main_menu_set_theme_mod' );
793
add_action( 'customize_save_after', 'lsx_customizer_colour__main_menu_set_theme_mod' );
794
795
/**
796
 * Enqueues front-end CSS for the main menu.
797
 */
798 View Code Duplication
function lsx_customizer_colour__main_menu_css() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
799
	$styles_from_theme_mod = get_theme_mod( 'lsx_customizer_colour__main_menu_theme_mod' );
800
	
801
	if ( is_customize_preview() || false === $styles_from_theme_mod ) {
802
		$theme_mods = lsx_customizer_colour__main_menu_get_theme_mods();
803
		$styles     = lsx_customizer_colour__main_menu_get_css( $theme_mods );
804
		
805
		if ( false === $styles_from_theme_mod ) {
806
			set_theme_mod( 'lsx_customizer_colour__main_menu_theme_mod', $styles );
807
		}
808
	} else {
809
		$styles = $styles_from_theme_mod;
810
	}
811
812
	wp_add_inline_style( 'lsx_customizer_colour', $styles );
813
}
814
add_action( 'wp_footer', 'lsx_customizer_colour__main_menu_css', 12 );
815
816
/**
817
 * Get main menu CSS theme mods.
818
 */
819
function lsx_customizer_colour__main_menu_get_theme_mods() {
820
	global $customizer_colour_names;
821
822
	$color_scheme = lsx_customizer_colour__get_color_scheme();
823
	$colors       = array();
824
	$counter      = 0;
825
826
	foreach ( $customizer_colour_names as $key => $value ) {
827
		$colors[$key] = $color_scheme[$counter];
828
		$counter++;
829
	}
830
831
	return array(
832
		'main_menu_background_hover1_color' => get_theme_mod( 'main_menu_background_hover1_color', $colors['main_menu_background_hover1_color'] ),
833
		'main_menu_background_hover2_color' => get_theme_mod( 'main_menu_background_hover2_color', $colors['main_menu_background_hover2_color'] ),
834
		'main_menu_text_color' =>              get_theme_mod( 'main_menu_text_color',              $colors['main_menu_text_color'] ),
835
		'main_menu_text_hover1_color' =>       get_theme_mod( 'main_menu_text_hover1_color',       $colors['main_menu_text_hover1_color'] ),
836
		'main_menu_text_hover2_color' =>       get_theme_mod( 'main_menu_text_hover2_color',       $colors['main_menu_text_hover2_color'] )
837
	);
838
}
839
840
/**
841
 * Returns CSS for the main menu.
842
 */
843
function lsx_customizer_colour__main_menu_get_css( $colors ) {
844
	global $customizer_colour_names;
845
	
846
	$colors_template = array();
847
848
	foreach ( $customizer_colour_names as $key => $value ) {
849
		$colors_template[$key] = '';
850
	}
851
852
	$colors = wp_parse_args( $colors, $colors_template );
853
854
	$css = <<<CSS
855
		/*
856
		 *
857
		 * Main Menu
858
		 *
859
		 */
860
861
		nav.primary-navbar {
862
			.nav.navbar-nav {
863
				& > li,
864
				ul.dropdown-menu > li {
865
					& > a,
866
					ul.dropdown-menu > li > a {
867
						color: {$colors['main_menu_text_color']};
868
					}
869
					
870
					&:hover,
871
					&.open,
872
					&.active {
873
						& > a {
874
							background-color: {$colors['main_menu_background_hover1_color']};
875
							color: {$colors['main_menu_text_hover1_color']};
876
877
							.caret {
878
								border-top-color: {$colors['main_menu_text_hover1_color']};
879
								border-bottom-color: {$colors['main_menu_text_hover1_color']};
880
							}
881
						}
882
					}
883
884
					ul.dropdown-menu {
885
						background-color: {$colors['main_menu_background_hover1_color']};
886
887
						& > li {
888
							& > a {
889
								color: {$colors['main_menu_text_hover1_color']};
890
891
								&:hover {
892
									color: {$colors['main_menu_text_hover1_color']};
893
								}
894
							}
895
						}
896
					}
897
898
					&.active {
899
						& li.active a {
900
							background-color: {$colors['main_menu_background_hover2_color']} !important;
901
							color: {$colors['main_menu_text_hover2_color']};
902
						}
903
					}
904
905
					&.menu-highlight {
906
						a {
907
							background-color: {$colors['main_menu_background_hover1_color']} !important;
908
							color: {$colors['main_menu_text_hover1_color']} !important;
909
910
							.caret {
911
								border-top-color: {$colors['main_menu_text_hover1_color']} !important;
912
								border-bottom-color: {$colors['main_menu_text_hover1_color']} !important;
913
							}
914
						}
915
916
						&:hover {
917
							& > a {
918
								background-color: {$colors['main_menu_background_hover1_color']} !important;
919
								color: {$colors['main_menu_text_hover1_color']} !important;
920
							}
921
						}
922
						
923
						& li.menu-highlight a {
924
							background-color: {$colors['main_menu_background_hover2_color']} !important;
925
							color: {$colors['main_menu_text_hover2_color']} !important;
926
						}
927
					}
928
				}
929
			}
930
		}
931
932
		.navbar-default {
933
			.navbar-toggle {
934
				&,
935
				&:visited,
936
				&:focus,
937
				&:hover,
938
				&:active {
939
					border-color: {$colors['main_menu_background_hover1_color']};
940
					background-color: {$colors['main_menu_background_hover1_color']};
941
				}
942
943
				.icon-bar {
944
					background-color: {$colors['main_menu_text_hover1_color']};
945
				}
946
			}
947
		}
948
949
		header.banner {
950
			.search-submit {
951
				&,
952
				&:visited {
953
					color: {$colors['main_menu_text_color']} !important;
954
				}
955
956
				&:hover,
957
				&:active,
958
				&:focus {
959
					color: #333 !important; /* @TODO */
960
				}
961
			}
962
		}
963
CSS;
964
965
	$css = apply_filters( 'lsx_customizer_colour_selectors_main_menu', $css, $colors );
966
	$css = lsx_customizer_colour__scss_to_css( $css );
967
	return $css;
968
}
969
970
971
/* ################################################################################# */
972
973
974
/**
975
 * Assign CSS to banner theme mod.
976
 */
977
function lsx_customizer_colour__banner_set_theme_mod() {
978
	$theme_mods = lsx_customizer_colour__banner_get_theme_mods();
979
	$styles     = lsx_customizer_colour__banner_get_css( $theme_mods );
980
	
981
	set_theme_mod( 'lsx_customizer_colour__banner_theme_mod', $styles );
982
}
983
add_action( 'after_switch_theme',   'lsx_customizer_colour__banner_set_theme_mod' );
984
add_action( 'customize_save_after', 'lsx_customizer_colour__banner_set_theme_mod' );
985
986
/**
987
 * Enqueues front-end CSS for the banner.
988
 */
989 View Code Duplication
function lsx_customizer_colour__banner_css() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
990
	$styles_from_theme_mod = get_theme_mod( 'lsx_customizer_colour__banner_theme_mod' );
991
	
992
	if ( is_customize_preview() || false === $styles_from_theme_mod ) {
993
		$theme_mods = lsx_customizer_colour__banner_get_theme_mods();
994
		$styles     = lsx_customizer_colour__banner_get_css( $theme_mods );
995
		
996
		if ( false === $styles_from_theme_mod ) {
997
			set_theme_mod( 'lsx_customizer_colour__banner_theme_mod', $styles );
998
		}
999
	} else {
1000
		$styles = $styles_from_theme_mod;
1001
	}
1002
1003
	wp_add_inline_style( 'lsx_customizer_colour', $styles );
1004
}
1005
add_action( 'wp_footer', 'lsx_customizer_colour__banner_css', 12 );
1006
1007
/**
1008
 * Get banner CSS theme mods.
1009
 */
1010
function lsx_customizer_colour__banner_get_theme_mods() {
1011
	global $customizer_colour_names;
1012
1013
	$color_scheme = lsx_customizer_colour__get_color_scheme();
1014
	$colors       = array();
1015
	$counter      = 0;
1016
1017
	foreach ( $customizer_colour_names as $key => $value ) {
1018
		$colors[$key] = $color_scheme[$counter];
1019
		$counter++;
1020
	}
1021
1022
	return array(
1023
		'banner_background_color' => get_theme_mod( 'banner_background_color', $colors['banner_background_color'] ),
1024
		'banner_text_color' =>       get_theme_mod( 'banner_text_color',       $colors['banner_text_color'] ),
1025
		'banner_text_image_color' => get_theme_mod( 'banner_text_image_color', $colors['banner_text_image_color'] )
1026
	);
1027
}
1028
1029
/**
1030
 * Returns CSS for the banner.
1031
 */
1032
function lsx_customizer_colour__banner_get_css( $colors ) {
1033
	global $customizer_colour_names;
1034
	
1035
	$colors_template = array();
1036
1037
	foreach ( $customizer_colour_names as $key => $value ) {
1038
		$colors_template[$key] = '';
1039
	}
1040
1041
	$colors = wp_parse_args( $colors, $colors_template );
1042
1043
	$css = <<<CSS
1044
		/*
1045
		 *
1046
		 * Banner
1047
		 *
1048
		 */
1049
1050
		.wrap {
1051
			.archive-header {
1052
				background-color: {$colors['banner_background_color']} !important;
1053
1054
				.archive-title,
1055
				h1 {
1056
					color: {$colors['banner_text_color']} !important;
1057
				}
1058
			}
1059
		}
1060
1061
		body.page-has-banner {
1062
			.page-banner {
1063
				h1.page-title {
1064
					color: {$colors['banner_text_image_color']} !important;
1065
				}
1066
			}
1067
		}
1068
CSS;
1069
1070
	$css = apply_filters( 'lsx_customizer_colour_selectors_banner', $css, $colors );
1071
	$css = lsx_customizer_colour__scss_to_css( $css );
1072
	return $css;
1073
}
1074
1075
1076
/* ################################################################################# */
1077
1078
1079
/**
1080
 * Assign CSS to body theme mod.
1081
 */
1082
function lsx_customizer_colour__body_set_theme_mod() {
1083
	$theme_mods = lsx_customizer_colour__body_get_theme_mods();
1084
	$styles     = lsx_customizer_colour__body_get_css( $theme_mods );
1085
	
1086
	set_theme_mod( 'lsx_customizer_colour__body_theme_mod', $styles );
1087
}
1088
add_action( 'after_switch_theme',   'lsx_customizer_colour__body_set_theme_mod' );
1089
add_action( 'customize_save_after', 'lsx_customizer_colour__body_set_theme_mod' );
1090
1091
/**
1092
 * Enqueues front-end CSS for the body.
1093
 */
1094 View Code Duplication
function lsx_customizer_colour__body_css() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1095
	$styles_from_theme_mod = get_theme_mod( 'lsx_customizer_colour__body_theme_mod' );
1096
	
1097
	if ( is_customize_preview() || false === $styles_from_theme_mod ) {
1098
		$theme_mods = lsx_customizer_colour__body_get_theme_mods();
1099
		$styles     = lsx_customizer_colour__body_get_css( $theme_mods );
1100
		
1101
		if ( false === $styles_from_theme_mod ) {
1102
			set_theme_mod( 'lsx_customizer_colour__body_theme_mod', $styles );
1103
		}
1104
	} else {
1105
		$styles = $styles_from_theme_mod;
1106
	}
1107
1108
	wp_add_inline_style( 'lsx_customizer_colour', $styles );
1109
}
1110
add_action( 'wp_footer', 'lsx_customizer_colour__body_css', 12 );
1111
1112
/**
1113
 * Get body CSS theme mods.
1114
 */
1115
function lsx_customizer_colour__body_get_theme_mods() {
1116
	global $customizer_colour_names;
1117
1118
	$color_scheme = lsx_customizer_colour__get_color_scheme();
1119
	$colors       = array();
1120
	$counter      = 0;
1121
1122
	foreach ( $customizer_colour_names as $key => $value ) {
1123
		$colors[$key] = $color_scheme[$counter];
1124
		$counter++;
1125
	}
1126
1127
	return array(
1128
		'body_background_color' =>   get_theme_mod( 'body_background_color',   $colors['body_background_color'] ),
1129
		'body_line_color' =>         get_theme_mod( 'body_line_color',         $colors['body_line_color'] ),
1130
		'body_text_heading_color' => get_theme_mod( 'body_text_heading_color', $colors['body_text_heading_color'] ),
1131
		'body_text_color' =>         get_theme_mod( 'body_text_color',         $colors['body_text_color'] ),
1132
		'body_link_color' =>         get_theme_mod( 'body_link_color',         $colors['body_link_color'] ),
1133
		'body_link_hover_color' =>   get_theme_mod( 'body_link_hover_color',   $colors['body_link_hover_color'] ),
1134
1135
		'body_section_full_background_color' =>     get_theme_mod( 'body_section_full_background_color',     $colors['body_section_full_background_color'] ),
1136
		'body_section_full_text_color' =>           get_theme_mod( 'body_section_full_text_color',           $colors['body_section_full_text_color'] ),
1137
		'body_section_full_cta_background_color' => get_theme_mod( 'body_section_full_cta_background_color', $colors['body_section_full_cta_background_color'] ),
1138
		'body_section_full_cta_text_color' =>       get_theme_mod( 'body_section_full_cta_text_color',       $colors['body_section_full_cta_text_color'] )
1139
	);
1140
}
1141
1142
/**
1143
 * Returns CSS for the body.
1144
 */
1145
function lsx_customizer_colour__body_get_css( $colors ) {
1146
	global $customizer_colour_names;
1147
	
1148
	$colors_template = array();
1149
1150
	foreach ( $customizer_colour_names as $key => $value ) {
1151
		$colors_template[$key] = '';
1152
	}
1153
1154
	$colors = wp_parse_args( $colors, $colors_template );
1155
1156
	$rgb = lsx_customizer_colour__hex2rgb( $colors['body_line_color'] );
1157
	$colors['body_line_color_rgba'] = "rgba({$rgb['red']}, {$rgb['green']}, {$rgb['blue']}, 0.5)";
1158
1159
	$css = <<<CSS
1160
		/*
1161
		 *
1162
		 * Body
1163
		 *
1164
		 */
1165
1166
		body {
1167
			background-color: {$colors['body_background_color']};
1168
			color: {$colors['body_text_color']};
1169
			
1170
			&.archive.author,
1171
			&.archive.category,
1172
			&.archive.date,
1173
			&.archive.tag,
1174
			&.archive.tax-post_format,
1175
			&.blog,
1176
			&.search {
1177
				.wrap {
1178
					#primary {
1179
						#main {
1180
							& > article {
1181
								-webkit-box-shadow: 1px 1px 3px 0 {$colors['body_line_color_rgba']};
1182
								box-shadow: 1px 1px 3px 0 {$colors['body_line_color_rgba']};
1183
								border-color: {$colors['body_line_color']};
1184
							}
1185
						}
1186
					}
1187
				}
1188
			}
1189
1190
			&.single-post {
1191
				.wrap {
1192
					#primary {
1193
						#main {
1194
							& > article {
1195
								.post-tags-wrapper {
1196
									border-top-color: {$colors['body_line_color']};
1197
									border-bottom-color: {$colors['body_line_color']};
1198
								}
1199
							}
1200
						}
1201
1202
						.post-navigation {
1203
							.pager {
1204
								a {
1205
									&,
1206
									&:visited {
1207
										div {
1208
											h3 {
1209
												color: {$colors['body_text_heading_color']};
1210
											}
1211
										}
1212
									}
1213
1214
									&:hover,
1215
									&:active,
1216
									&:focus {
1217
										div {
1218
											h3 {
1219
												color: {$colors['body_link_hover_color']};
1220
											}
1221
										}
1222
									}
1223
								}
1224
							}
1225
						}
1226
					}
1227
				}
1228
			}
1229
		}
1230
1231
		.wrap {
1232
			background-color: {$colors['body_background_color']};
1233
		}
1234
1235
		h1, h2, h3, h4, h5, h6 {
1236
			color: {$colors['body_text_heading_color']};
1237
1238
			a {
1239
				&,
1240
				&:visited {
1241
					color: {$colors['body_text_heading_color']};
1242
				}
1243
1244
				&:hover,
1245
				&:active,
1246
				&:focus {
1247
					color: {$colors['body_link_hover_color']};
1248
				}
1249
			}
1250
		}
1251
1252
		article {
1253
			header.entry-header {
1254
				h1.entry-title {
1255
					a {
1256
						&,
1257
						&:visited {
1258
							color: {$colors['body_text_heading_color']} !important;
1259
						}
1260
1261
						&:hover,
1262
						&:active,
1263
						&:focus {
1264
							color: {$colors['body_link_hover_color']} !important;
1265
						}
1266
					}
1267
				}
1268
			}
1269
1270
			.entry-content,
1271
			.entry-summary {
1272
				color: {$colors['body_text_color']} !important;
1273
			}
1274
		}
1275
1276
		.sharedaddy {
1277
			.sd-sharing {
1278
				border-top-color: {$colors['body_line_color']};
1279
1280
				.sd-title {
1281
					&,
1282
					&:before {
1283
						color: {$colors['body_text_color']} !important;
1284
					}
1285
				}
1286
			}
1287
		}
1288
1289
		.entry-meta {
1290
			.post-meta {
1291
				color: {$colors['body_text_color']} !important;
1292
			}
1293
		}
1294
1295
		.nav-links-description {
1296
			color: {$colors['body_text_color']} !important;
1297
			
1298
			&:after,
1299
			&:before {
1300
				color: {$colors['body_text_color']} !important;
1301
			}
1302
		}
1303
1304
		.post-meta-author,
1305
		.post-meta-categories,
1306
		.post-meta-time,
1307
		.post-comments {
1308
			&:before {
1309
				color: {$colors['body_text_color']} !important;
1310
			}
1311
1312
			a {
1313
				&,
1314
				&:visited {
1315
					color: {$colors['body_link_color']} !important;
1316
				}
1317
1318
				&:hover,
1319
				&:active,
1320
				&:focus {
1321
					color: {$colors['body_link_hover_color']} !important;
1322
				}
1323
			}
1324
		}
1325
1326
		.post-meta-link {
1327
			&:before {
1328
				color: {$colors['body_text_color']} !important;
1329
			}
1330
1331
			&,
1332
			&:visited {
1333
				color: {$colors['body_link_color']} !important;
1334
			}
1335
1336
			&:hover,
1337
			&:active,
1338
			&:focus {
1339
				color: {$colors['body_link_hover_color']} !important;
1340
			}
1341
		}
1342
		
1343
		.post-tags,
1344
		#reply-title {
1345
			&:before {
1346
				color: {$colors['body_text_color']} !important;
1347
			}
1348
		}
1349
1350
		a {
1351
			&,
1352
			.entry-content &:not(.btn),
1353
			.entry-summary &:not(.btn) {
1354
				&,
1355
				&:visited {
1356
					color: {$colors['body_link_color']};
1357
				}
1358
1359
				&:hover,
1360
				&:active,
1361
				&:focus {
1362
					color: {$colors['body_link_hover_color']};
1363
				}
1364
			}
1365
		}
1366
1367
		.facetwp-alpha {
1368
			&.available,
1369
			&.selected {
1370
				color: {$colors['body_link_color']} !important;
1371
1372
				&:hover {
1373
					color: {$colors['body_link_hover_color']} !important;
1374
				}
1375
			}
1376
		}
1377
1378
		figure.wp-caption {
1379
			border-color: {$colors['body_line_color']};
1380
1381
			figcaption.wp-caption-text {
1382
				border-top-color: {$colors['body_line_color']};
1383
			}
1384
		}
1385
1386
		.page-header {
1387
			border-bottom-color: {$colors['body_line_color']};
1388
		}
1389
1390
		#main {
1391
			.lsx-full-width {
1392
				background-color: {$colors['body_section_full_background_color']};
1393
				color: {$colors['body_section_full_text_color']};
1394
1395
				h1, h2, h3, h4, h5, h6,
1396
				a, .lsx-hero-unit {
1397
					color: {$colors['body_section_full_text_color']};
1398
				}
1399
1400
				.lsx-border-button {
1401
					border-color: {$colors['body_section_full_text_color']} !important;
1402
				}
1403
			}
1404
1405
			.lsx-full-width-alt {
1406
				background-color: {$colors['body_section_full_cta_background_color']};
1407
				color: {$colors['body_section_full_cta_text_color']};
1408
1409
				h1, h2, h3, h4, h5, h6,
1410
				a, .lsx-hero-unit {
1411
					color: {$colors['body_section_full_cta_text_color']};
1412
				}
1413
1414
				.lsx-border-button {
1415
					border-color: {$colors['body_section_full_text_color']} !important;
1416
				}
1417
			}
1418
		}
1419
CSS;
1420
1421
	$css = apply_filters( 'lsx_customizer_colour_selectors_body', $css, $colors );
1422
	$css = lsx_customizer_colour__scss_to_css( $css );
1423
	return $css;
1424
}
1425
1426
1427
/* ################################################################################# */
1428
1429
1430
/**
1431
 * Assign CSS to footer cta theme mod.
1432
 */
1433
function lsx_customizer_colour__footer_cta_set_theme_mod() {
1434
	$theme_mods = lsx_customizer_colour__footer_cta_get_theme_mods();
1435
	$styles     = lsx_customizer_colour__footer_cta_get_css( $theme_mods );
1436
	
1437
	set_theme_mod( 'lsx_customizer_colour__footer_cta_theme_mod', $styles );
1438
}
1439
add_action( 'after_switch_theme',   'lsx_customizer_colour__footer_cta_set_theme_mod' );
1440
add_action( 'customize_save_after', 'lsx_customizer_colour__footer_cta_set_theme_mod' );
1441
1442
/**
1443
 * Enqueues front-end CSS for the footer cta.
1444
 */
1445 View Code Duplication
function lsx_customizer_colour__footer_cta_css() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1446
	$styles_from_theme_mod = get_theme_mod( 'lsx_customizer_colour__footer_cta_theme_mod' );
1447
	
1448
	if ( is_customize_preview() || false === $styles_from_theme_mod ) {
1449
		$theme_mods = lsx_customizer_colour__footer_cta_get_theme_mods();
1450
		$styles     = lsx_customizer_colour__footer_cta_get_css( $theme_mods );
1451
		
1452
		if ( false === $styles_from_theme_mod ) {
1453
			set_theme_mod( 'lsx_customizer_colour__footer_cta_theme_mod', $styles );
1454
		}
1455
	} else {
1456
		$styles = $styles_from_theme_mod;
1457
	}
1458
1459
	wp_add_inline_style( 'lsx_customizer_colour', $styles );
1460
}
1461
add_action( 'wp_footer', 'lsx_customizer_colour__footer_cta_css', 12 );
1462
1463
/**
1464
 * Get footer cta CSS theme mods.
1465
 */
1466
function lsx_customizer_colour__footer_cta_get_theme_mods() {
1467
	global $customizer_colour_names;
1468
1469
	$color_scheme = lsx_customizer_colour__get_color_scheme();
1470
	$colors       = array();
1471
	$counter      = 0;
1472
1473
	foreach ( $customizer_colour_names as $key => $value ) {
1474
		$colors[$key] = $color_scheme[$counter];
1475
		$counter++;
1476
	}
1477
1478
	return array(
1479
		'footer_cta_background_color' => get_theme_mod( 'footer_cta_background_color', $colors['footer_cta_background_color'] ),
1480
		'footer_cta_text_color'       => get_theme_mod( 'footer_cta_text_color',       $colors['footer_cta_text_color'] ),
1481
		'footer_cta_link_color'       => get_theme_mod( 'footer_cta_link_color',       $colors['footer_cta_link_color'] ),
1482
		'footer_cta_link_hover_color' => get_theme_mod( 'footer_cta_link_hover_color', $colors['footer_cta_link_hover_color'] )
1483
	);
1484
}
1485
1486
/**
1487
 * Returns CSS for the footer cta.
1488
 */
1489
function lsx_customizer_colour__footer_cta_get_css( $colors ) {
1490
	global $customizer_colour_names;
1491
	
1492
	$colors_template = array();
1493
1494
	foreach ( $customizer_colour_names as $key => $value ) {
1495
		$colors_template[$key] = '';
1496
	}
1497
1498
	$colors = wp_parse_args( $colors, $colors_template );
1499
1500
	$css = <<<CSS
1501
		/*
1502
		 *
1503
		 * Footer CTA
1504
		 *
1505
		 */
1506
1507
		#footer-cta {
1508
			&,
1509
			.lsx-full-width {
1510
				background-color: {$colors['footer_cta_background_color']};
1511
			}
1512
1513
			h1, h2, h3, h4, h5, h6,
1514
			.textwidget {
1515
				color: {$colors['footer_cta_text_color']};
1516
1517
				a {
1518
					&,
1519
					&:visited {
1520
						color: {$colors['footer_cta_link_color']};
1521
					}
1522
1523
					&:hover,
1524
					&:active,
1525
					&:focus {
1526
						color: {$colors['footer_cta_link_hover_color']};
1527
					}
1528
				}
1529
			}
1530
		}
1531
CSS;
1532
1533
	$css = apply_filters( 'lsx_customizer_colour_selectors_footer_cta', $css, $colors );
1534
	$css = lsx_customizer_colour__scss_to_css( $css );
1535
	return $css;
1536
}
1537
1538
1539
/* ################################################################################# */
1540
1541
/**
1542
 * Assign CSS to footer widgets theme mod.
1543
 */
1544
function lsx_customizer_colour__footer_widgets_set_theme_mod() {
1545
	$theme_mods = lsx_customizer_colour__footer_widgets_get_theme_mods();
1546
	$styles     = lsx_customizer_colour__footer_widgets_get_css( $theme_mods );
1547
	
1548
	set_theme_mod( 'lsx_customizer_colour__footer_widgets_theme_mod', $styles );
1549
}
1550
add_action( 'after_switch_theme',   'lsx_customizer_colour__footer_widgets_set_theme_mod' );
1551
add_action( 'customize_save_after', 'lsx_customizer_colour__footer_widgets_set_theme_mod' );
1552
1553
/**
1554
 * Enqueues front-end CSS for the footer widgets.
1555
 */
1556 View Code Duplication
function lsx_customizer_colour__footer_widgets_css() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1557
	$styles_from_theme_mod = get_theme_mod( 'lsx_customizer_colour__footer_widgets_theme_mod' );
1558
	
1559
	if ( is_customize_preview() || false === $styles_from_theme_mod ) {
1560
		$theme_mods = lsx_customizer_colour__footer_widgets_get_theme_mods();
1561
		$styles     = lsx_customizer_colour__footer_widgets_get_css( $theme_mods );
1562
		
1563
		if ( false === $styles_from_theme_mod ) {
1564
			set_theme_mod( 'lsx_customizer_colour__footer_widgets_theme_mod', $styles );
1565
		}
1566
	} else {
1567
		$styles = $styles_from_theme_mod;
1568
	}
1569
1570
	wp_add_inline_style( 'lsx_customizer_colour', $styles );
1571
}
1572
add_action( 'wp_footer', 'lsx_customizer_colour__footer_widgets_css', 12 );
1573
1574
/**
1575
 * Get footer widgets CSS theme mods.
1576
 */
1577
function lsx_customizer_colour__footer_widgets_get_theme_mods() {
1578
	global $customizer_colour_names;
1579
1580
	$color_scheme = lsx_customizer_colour__get_color_scheme();
1581
	$colors       = array();
1582
	$counter      = 0;
1583
1584
	foreach ( $customizer_colour_names as $key => $value ) {
1585
		$colors[$key] = $color_scheme[$counter];
1586
		$counter++;
1587
	}
1588
1589
	return array(
1590
		'footer_widgets_background_color' => get_theme_mod( 'footer_widgets_background_color', $colors['footer_widgets_background_color'] ),
1591
		'footer_widgets_text_color'       => get_theme_mod( 'footer_widgets_text_color',       $colors['footer_widgets_text_color'] ),
1592
		'footer_widgets_link_color'       => get_theme_mod( 'footer_widgets_link_color',       $colors['footer_widgets_link_color'] ),
1593
		'footer_widgets_link_hover_color' => get_theme_mod( 'footer_widgets_link_hover_color', $colors['footer_widgets_link_hover_color'] )
1594
	);
1595
}
1596
1597
/**
1598
 * Returns CSS for the footer widgets.
1599
 */
1600
function lsx_customizer_colour__footer_widgets_get_css( $colors ) {
1601
	global $customizer_colour_names;
1602
	
1603
	$colors_template = array();
1604
1605
	foreach ( $customizer_colour_names as $key => $value ) {
1606
		$colors_template[$key] = '';
1607
	}
1608
1609
	$colors = wp_parse_args( $colors, $colors_template );
1610
1611
	$css = <<<CSS
1612
		/*
1613
		 *
1614
		 * Footer Widgets
1615
		 *
1616
		 */
1617
1618
		#footer-widgets {
1619
			background-color: {$colors['footer_widgets_background_color']};
1620
1621
			&,
1622
			.widget,
1623
			.widget h3.widget-title {
1624
				color: {$colors['footer_widgets_text_color']};
1625
1626
				a {
1627
					&,
1628
					&:visited {
1629
						color: {$colors['footer_widgets_link_color']};
1630
					}
1631
1632
					&:hover,
1633
					&:active,
1634
					&:focus {
1635
						color: {$colors['footer_widgets_link_hover_color']};
1636
					}
1637
				}
1638
			}
1639
1640
			.widget {
1641
				h3.widget-title {
1642
					border-bottom-color: {$colors['footer_widgets_text_color']};
1643
				}
1644
			}
1645
		}
1646
CSS;
1647
1648
	$css = apply_filters( 'lsx_customizer_colour_selectors_footer_widgets', $css, $colors );
1649
	$css = lsx_customizer_colour__scss_to_css( $css );
1650
	return $css;
1651
}
1652
1653
1654
/* ################################################################################# */
1655
1656
/**
1657
 * Assign CSS to footer theme mod.
1658
 */
1659
function lsx_customizer_colour__footer_set_theme_mod() {
1660
	$theme_mods = lsx_customizer_colour__footer_get_theme_mods();
1661
	$styles     = lsx_customizer_colour__footer_get_css( $theme_mods );
1662
	
1663
	set_theme_mod( 'lsx_customizer_colour__footer_theme_mod', $styles );
1664
}
1665
add_action( 'after_switch_theme',   'lsx_customizer_colour__footer_set_theme_mod' );
1666
add_action( 'customize_save_after', 'lsx_customizer_colour__footer_set_theme_mod' );
1667
1668
/**
1669
 * Enqueues front-end CSS for the footer.
1670
 */
1671 View Code Duplication
function lsx_customizer_colour__footer_css() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1672
	$styles_from_theme_mod = get_theme_mod( 'lsx_customizer_colour__footer_theme_mod' );
1673
1674
	if ( is_customize_preview() || false === $styles_from_theme_mod ) {
1675
		$theme_mods = lsx_customizer_colour__footer_get_theme_mods();
1676
		$styles     = lsx_customizer_colour__footer_get_css( $theme_mods );
1677
		
1678
		if ( false === $styles_from_theme_mod ) {
1679
			set_theme_mod( 'lsx_customizer_colour__footer_theme_mod', $styles );
1680
		}
1681
	} else {
1682
		$styles = $styles_from_theme_mod;
1683
	}
1684
1685
	wp_add_inline_style( 'lsx_customizer_colour', $styles );
1686
}
1687
add_action( 'wp_footer', 'lsx_customizer_colour__footer_css', 12 );
1688
1689
/**
1690
 * Get footer CSS theme mods.
1691
 */
1692
function lsx_customizer_colour__footer_get_theme_mods() {
1693
	global $customizer_colour_names;
1694
1695
	$color_scheme = lsx_customizer_colour__get_color_scheme();
1696
	$colors       = array();
1697
	$counter      = 0;
1698
1699
	foreach ( $customizer_colour_names as $key => $value ) {
1700
		$colors[$key] = $color_scheme[$counter];
1701
		$counter++;
1702
	}
1703
1704
	return array(
1705
		'footer_background_color' => get_theme_mod( 'footer_background_color', $colors['footer_background_color'] ),
1706
		'footer_text_color'       => get_theme_mod( 'footer_text_color',       $colors['footer_text_color'] ),
1707
		'footer_link_color'       => get_theme_mod( 'footer_link_color',       $colors['footer_link_color'] ),
1708
		'footer_link_hover_color' => get_theme_mod( 'footer_link_hover_color', $colors['footer_link_hover_color'] )
1709
	);
1710
}
1711
1712
/**
1713
 * Returns CSS for the footer.
1714
 */
1715
function lsx_customizer_colour__footer_get_css( $colors ) {
1716
	global $customizer_colour_names;
1717
	
1718
	$colors_template = array();
1719
1720
	foreach ( $customizer_colour_names as $key => $value ) {
1721
		$colors_template[$key] = '';
1722
	}
1723
1724
	$colors = wp_parse_args( $colors, $colors_template );
1725
1726
	$css = <<<CSS
1727
		/*
1728
		 *
1729
		 * Footer
1730
		 *
1731
		 */
1732
1733
		footer.content-info {
1734
			background-color: {$colors['footer_background_color']};
1735
1736
			&,
1737
			& .credit {
1738
				color: {$colors['footer_text_color']};
1739
			}
1740
1741
			a {
1742
				&,
1743
				&:visited {
1744
					color: {$colors['footer_link_color']};
1745
				}
1746
1747
				&:hover,
1748
				&:active,
1749
				&:focus {
1750
					color: {$colors['footer_link_hover_color']};
1751
				}
1752
			}
1753
		}
1754
1755
		nav#footer-navigation {
1756
			ul {
1757
				li {
1758
					border-right-color: {$colors['footer_link_color']};
1759
				}
1760
			}
1761
		}
1762
CSS;
1763
1764
	$css = apply_filters( 'lsx_customizer_colour_selectors_footer', $css, $colors );
1765
	$css = lsx_customizer_colour__scss_to_css( $css );
1766
	return $css;
1767
}
1768
1769
1770
/* ################################################################################# */
1771
1772
1773
/**
1774
 * Customize Colour Control Class
1775
 */
1776
1777
if ( ! class_exists( 'WP_Customize_Control' ) ) {
1778
	return;
1779
}
1780
1781
class LSX_Customize_Colour_Control extends WP_Customize_Control {
1782
	
1783
	/**
1784
	 * Enqueue control related scripts/styles.
1785
	 */
1786
	public function enqueue() {
1787
		wp_enqueue_script( 'lsx-colour-control', get_template_directory_uri() .'/js/customizer-colour.js', array( 'customize-controls', 'iris', 'underscore', 'wp-util' ), null, true );
1788
		wp_localize_script( 'lsx-colour-control', 'colorScheme', $this->choices );
1789
1790
		global $customizer_colour_names;
1791
		$colors = array();
1792
		foreach ( $customizer_colour_names as $key => $value ) {
1793
			$colors[] = $key;
1794
		}
1795
		wp_localize_script( 'lsx-colour-control', 'colorSchemeKeys', $colors );
1796
	}
1797
1798
	/**
1799
	 * Render the control's content.
1800
	 */
1801
	public function render_content() {
1802
		if ( empty( $this->choices ) ) {
1803
			return;
1804
		}
1805
1806
		?> 
1807
		<label>
1808
			<?php if ( ! empty( $this->label ) ) { ?>
1809
				<span class="customize-control-title"><?php echo esc_html( $this->label ) ?></span>
1810
			<?php }
1811
			if ( ! empty( $this->description ) ) { ?>
1812
				<span class="description customize-control-description"><?php echo esc_html( $this->description ) ?></span>
1813
			<?php } ?>
1814
			<select <?php $this->link() ?>>
1815
				<?php
1816
					foreach ( $this->choices as $value => $label ) {
1817
						echo '<option value="'. esc_attr( $value ) .'"'. selected( $this->value(), $value, false ) .'>'. esc_html( $label['label'] ) .'</option>';
1818
					}
1819
				?>
1820
			</select>
1821
		</label>
1822
	<?php
1823
	}
1824
1825
}
1826
1827
?>