Issues (1724)

classes/class-lsx-customizer-colour-main-menu.php (6 issues)

1
<?php
2
if ( ! class_exists( 'LSX_Customizer_Colour_Main_Menu' ) ) {
3
4
	/**
5
	 * LSX Customizer Colour Main Menu Class
6
	 *
7
	 * @package   LSX Customizer
8
	 * @author    LightSpeed
9
	 * @license   GPL3
10
	 * @link
11
	 * @copyright 2016 LightSpeed
12
	 */
13
	class LSX_Customizer_Colour_Main_Menu extends LSX_Customizer_Colour {
14
15
		/**
16
		 * Constructor.
17
		 *
18
		 * @since 1.0.0
19
		 */
20
		public function __construct() {
21
			add_action( 'after_switch_theme',   array( $this, 'set_theme_mod' ) );
22
			add_action( 'customize_save_after', array( $this, 'set_theme_mod' ) );
23
24
			add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_css' ), 2999 );
25
		}
26
27
		/**
28
		 * Assign CSS to theme mod.
29
		 *
30
		 * @since 1.0.0
31
		 */
32
		public function set_theme_mod() {
33
			$theme_mods = $this->get_theme_mods();
34
			$styles     = $this->get_css( $theme_mods );
35
36
			set_theme_mod( 'lsx_customizer_colour__main_menu_theme_mod', $styles );
37
		}
38
39
		/**
40
		 * Enqueues front-end CSS.
41
		 *
42
		 * @since 1.0.0
43
		 */
44
		public function enqueue_css() {
45
			$styles_from_theme_mod = get_theme_mod( 'lsx_customizer_colour__main_menu_theme_mod' );
46
47
			if ( is_customize_preview() || false === $styles_from_theme_mod ) {
48
				$theme_mods = $this->get_theme_mods();
49
				$styles     = $this->get_css( $theme_mods );
50
51
				if ( false === $styles_from_theme_mod ) {
52
					set_theme_mod( 'lsx_customizer_colour__main_menu_theme_mod', $styles );
53
				}
54
			} else {
55
				$styles = $styles_from_theme_mod;
56
			}
57
58
			wp_add_inline_style( 'lsx-customizer', $styles );
59
		}
60
61
		/**
62
		 * Get CSS theme mods.
63
		 *
64
		 * @since 1.0.0
65
		 */
66
		public function get_theme_mods() {
67
			$colors = parent::get_color_scheme();
68
69
			return apply_filters( 'lsx_customizer_colours_main_menu', array(
70
				'main_menu_background_color'                => get_theme_mod( 'main_menu_background_color',                $colors['main_menu_background_color'] ),
0 ignored issues
show
Array double arrow not aligned correctly; expected 10 space(s) between "'main_menu_background_color'" and double arrow, but found 16.
Loading history...
71
				'main_menu_link_color'                      => get_theme_mod( 'main_menu_link_color',                      $colors['main_menu_link_color'] ),
0 ignored issues
show
Array double arrow not aligned correctly; expected 16 space(s) between "'main_menu_link_color'" and double arrow, but found 22.
Loading history...
72
				'main_menu_link_hover_color'                => get_theme_mod( 'main_menu_link_hover_color',                $colors['main_menu_link_hover_color'] ),
0 ignored issues
show
Array double arrow not aligned correctly; expected 10 space(s) between "'main_menu_link_hover_color'" and double arrow, but found 16.
Loading history...
73
				'main_menu_dropdown_background_color'       => get_theme_mod( 'main_menu_dropdown_background_color',       $colors['main_menu_dropdown_background_color'] ),
0 ignored issues
show
Array double arrow not aligned correctly; expected 1 space(s) between "'main_menu_dropdown_background_color'" and double arrow, but found 7.
Loading history...
74
				'main_menu_dropdown_background_hover_color' => get_theme_mod( 'main_menu_dropdown_background_hover_color', $colors['main_menu_dropdown_background_hover_color'] ),
75
				'main_menu_dropdown_link_color'             => get_theme_mod( 'main_menu_dropdown_link_color',             $colors['main_menu_dropdown_link_color'] ),
0 ignored issues
show
Array double arrow not aligned correctly; expected 7 space(s) between "'main_menu_dropdown_link_color'" and double arrow, but found 13.
Loading history...
76
				'main_menu_dropdown_link_hover_color'       => get_theme_mod( 'main_menu_dropdown_link_hover_color',       $colors['main_menu_dropdown_link_hover_color'] ),
0 ignored issues
show
Array double arrow not aligned correctly; expected 1 space(s) between "'main_menu_dropdown_link_hover_color'" and double arrow, but found 7.
Loading history...
77
			) );
78
		}
79
80
		/**
81
		 * Returns CSS.
82
		 *
83
		 * @since 1.0.0
84
		 */
85
		function get_css( $colors ) {
86
			global $customizer_colour_names;
87
88
			$colors_template = array();
89
90
			foreach ( $customizer_colour_names as $key => $value ) {
91
				$colors_template[ $key ] = '';
92
			}
93
94
			$colors = wp_parse_args( $colors, $colors_template );
95
96
			if ( empty( $colors['main_menu_background_color'] )
97
				|| empty( $colors['main_menu_link_color'] )
98
				|| empty( $colors['main_menu_link_hover_color'] )
99
				|| empty( $colors['main_menu_dropdown_background_color'] )
100
				|| empty( $colors['main_menu_dropdown_background_hover_color'] )
101
				|| empty( $colors['main_menu_dropdown_link_color'] )
102
				|| empty( $colors['main_menu_dropdown_link_hover_color'] ) ) {
103
				return '';
104
			}
105
106
			$css = '
107
				@import "' . get_template_directory() . '/assets/css/scss/global/mixins/nav";
108
109
				/**
110
				 * LSX Customizer - Main Menu
111
				 */
112
				@include nav-colours (
113
					$bg:                  ' . $colors['main_menu_background_color'] . ',
114
					$link:                ' . $colors['main_menu_link_color'] . ',
115
					$hover:               ' . $colors['main_menu_link_hover_color'] . ',
116
					$dropdown:            ' . $colors['main_menu_dropdown_background_color'] . ',
117
					$dropdown-hover:      ' . $colors['main_menu_dropdown_background_hover_color'] . ',
118
					$dropdown-link:       ' . $colors['main_menu_dropdown_link_color'] . ',
119
					$dropdown-link-hover: ' . $colors['main_menu_dropdown_link_hover_color'] . '
120
				);
121
			';
122
123
			$css = apply_filters( 'lsx_customizer_colour_selectors_main_menu', $css, $colors );
124
			$css = parent::scss_to_css( $css );
125
126
			return $css;
127
		}
128
129
	}
130
131
}
132