1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
<?php
/**
* Astra Theme Customizer Configuration Base.
*
* @package Astra
* @author Astra
* @copyright Copyright (c) 2020, Astra
* @link https://wpastra.com/
* @since Astra 1.4.3
*/
// No direct access, please.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Base Class for Registering Customizer Controls.
*
* @since 1.4.3
*/
if ( ! class_exists( 'Astra_Customizer_Control_Base' ) ) {
/**
* Customizer Sanitizes Initial setup
*/
class Astra_Customizer_Control_Base {
/**
* Registered Controls.
*
* @since 1.4.3
* @var Array
*/
private static $controls;
/**
* Constructor
*/
public function __construct() {
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}
/**
* Enqueue Admin Scripts
*
* @since 1.4.3
*/
public function enqueue_scripts() {
$dir_name = ( SCRIPT_DEBUG ) ? 'unminified' : 'minified';
$file_prefix = ( SCRIPT_DEBUG ) ? '' : '.min';
$file_rtl = ( is_rtl() ) ? '-rtl' : '';
$css_uri = ASTRA_THEME_URI . 'inc/customizer/custom-controls/assets/css/' . $dir_name . '/';
$js_uri = ASTRA_THEME_URI . 'inc/customizer/custom-controls/assets/js/' . $dir_name . '/';
wp_enqueue_style( 'astra-custom-control-style' . $file_rtl, $css_uri . 'custom-controls' . $file_prefix . $file_rtl . '.css', null, ASTRA_THEME_VERSION );
if ( ! SCRIPT_DEBUG ) {
// Enqueue Customizer script.
$custom_controls_deps = array(
'jquery',
'customize-base',
'jquery-ui-tabs',
'jquery-ui-sortable',
'wp-i18n',
'wp-components',
'wp-element',
'wp-media-utils',
'wp-block-editor',
);
wp_enqueue_script( 'astra-custom-control-script', $js_uri . 'custom-controls' . $file_prefix . '.js', $custom_controls_deps, ASTRA_THEME_VERSION, true );
$css_uri = ASTRA_THEME_URI . 'inc/customizer/custom-controls/typography/';
wp_enqueue_style( 'astra-select-woo-style', $css_uri . 'selectWoo.css', null, ASTRA_THEME_VERSION );
$astra_typo_localize = array(
'100' => __( 'Thin 100', 'astra' ),
'100italic' => __( '100 Italic', 'astra' ),
'200' => __( 'Extra-Light 200', 'astra' ),
'200italic' => __( '200 Italic', 'astra' ),
'300' => __( 'Light 300', 'astra' ),
'300italic' => __( '300 Italic', 'astra' ),
'400' => __( 'Normal 400', 'astra' ),
'italic' => __( '400 Italic', 'astra' ),
'500' => __( 'Medium 500', 'astra' ),
'500italic' => __( '500 Italic', 'astra' ),
'600' => __( 'Semi-Bold 600', 'astra' ),
'600italic' => __( '600 Italic', 'astra' ),
'700' => __( 'Bold 700', 'astra' ),
'700italic' => __( '700 Italic', 'astra' ),
'800' => __( 'Extra-Bold 800', 'astra' ),
'800italic' => __( '800 Italic', 'astra' ),
'900' => __( 'Ultra-Bold 900', 'astra' ),
'900italic' => __( '900 Italic', 'astra' ),
);
wp_localize_script( 'astra-custom-control-script', 'astraTypo', $astra_typo_localize );
$localize_array = array(
'colors' => astra_color_palette(),
);
wp_localize_script( 'astra-custom-control-script', 'astColorPalette', $localize_array );
} else {
// Enqueue Customizer Plain script.
$custom_controls_plain_deps = array(
'jquery',
'customize-base',
'jquery-ui-tabs',
'jquery-ui-sortable',
);
wp_enqueue_script( 'astra-custom-control-plain-script', $js_uri . 'custom-controls-plain' . $file_prefix . '.js', $custom_controls_plain_deps, ASTRA_THEME_VERSION, true );
// Enqueue Customizer React.JS script.
$custom_controls_react_deps = array(
'astra-custom-control-plain-script',
'wp-i18n',
'wp-components',
'wp-element',
'wp-media-utils',
'wp-block-editor',
);
$css_uri = ASTRA_THEME_URI . 'inc/customizer/custom-controls/typography/';
wp_enqueue_style( 'astra-select-woo-style', $css_uri . 'selectWoo.css', null, ASTRA_THEME_VERSION );
wp_enqueue_script( 'astra-custom-control-react-script', ASTRA_THEME_URI . 'inc/customizer/extend-custom-controls/build/index.js', $custom_controls_react_deps, ASTRA_THEME_VERSION, true );
$localize_array = array(
'colors' => astra_color_palette(),
);
$astra_typo_localize = array(
'100' => __( 'Thin 100', 'astra' ),
'100italic' => __( '100 Italic', 'astra' ),
'200' => __( 'Extra-Light 200', 'astra' ),
'200italic' => __( '200 Italic', 'astra' ),
'300' => __( 'Light 300', 'astra' ),
'300italic' => __( '300 Italic', 'astra' ),
'400' => __( 'Normal 400', 'astra' ),
'italic' => __( '400 Italic', 'astra' ),
'500' => __( 'Medium 500', 'astra' ),
'500italic' => __( '500 Italic', 'astra' ),
'600' => __( 'Semi-Bold 600', 'astra' ),
'600italic' => __( '600 Italic', 'astra' ),
'700' => __( 'Bold 700', 'astra' ),
'700italic' => __( '700 Italic', 'astra' ),
'800' => __( 'Extra-Bold 800', 'astra' ),
'800italic' => __( '800 Italic', 'astra' ),
'900' => __( 'Ultra-Bold 900', 'astra' ),
'900italic' => __( '900 Italic', 'astra' ),
);
wp_localize_script( 'astra-custom-control-react-script', 'astColorPalette', $localize_array );
wp_localize_script( 'astra-custom-control-react-script', 'astraTypo', $astra_typo_localize );
}
}
/**
* Add Control to self::$controls and Register control to WordPress Customizer.
*
* @param String $name Slug for the control.
* @param Array $atts Control Attributes.
* @return void
*/
public static function add_control( $name, $atts ) {
global $wp_customize;
self::$controls[ $name ] = $atts;
if ( isset( $atts['callback'] ) ) {
/**
* Register controls
*/
$wp_customize->register_control_type( $atts['callback'] );
}
}
/**
* Returns control instance
*
* @param string $control_type control type.
* @since 1.4.3
* @return string
*/
public static function get_control_instance( $control_type ) {
$control_class = self::get_control( $control_type );
if ( isset( $control_class['callback'] ) ) {
return class_exists( $control_class['callback'] ) ? $control_class['callback'] : false;
}
return false;
}
/**
* Returns control and its attributes
*
* @param string $control_type control type.
* @since 1.4.3
* @return array
*/
public static function get_control( $control_type ) {
if ( isset( self::$controls[ $control_type ] ) ) {
return self::$controls[ $control_type ];
}
return array();
}
/**
* Returns Santize callback for control
*
* @param string $control control.
* @since 1.4.3
* @return string
*/
public static function get_sanitize_call( $control ) {
if ( isset( self::$controls[ $control ]['sanitize_callback'] ) ) {
return self::$controls[ $control ]['sanitize_callback'];
}
return false;
}
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
new Astra_Customizer_Control_Base();
|