Passed
Push — main ( 137754...ffd9e1 )
by TARIQ
04:53
created
packages/kirki-framework/field-typography/src/Field/CSS/Typography.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -18,78 +18,78 @@
 block discarded – undo
18 18
  */
19 19
 class Typography extends Output {
20 20
 
21
-	/**
22
-	 * Processes a single item from the `output` array.
23
-	 *
24
-	 * @access protected
25
-	 * @param array $output The `output` item.
26
-	 * @param array $value  The field's value.
27
-	 */
28
-	protected function process_output( $output, $value ) {
29
-
30
-		$output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
31
-		$output['element']     = ( isset( $output['element'] ) ) ? $output['element'] : 'body';
32
-		$output['prefix']      = ( isset( $output['prefix'] ) ) ? $output['prefix'] : '';
33
-		$output['suffix']      = ( isset( $output['suffix'] ) ) ? $output['suffix'] : '';
34
-
35
-		$properties = [
36
-			'font-family',
37
-			'font-size',
38
-			'variant',
39
-			'font-weight',
40
-			'font-style',
41
-			'letter-spacing',
42
-			'word-spacing',
43
-			'line-height',
44
-			'text-align',
45
-			'text-transform',
46
-			'text-decoration',
47
-			'color',
48
-			'margin-top',
49
-			'margin-bottom',
50
-		];
51
-
52
-		foreach ( $properties as $property ) {
53
-
54
-			// Early exit if the value is not in the defaults.
55
-			if ( ! isset( $this->field['default'][ $property ] ) ) {
56
-				continue;
57
-			}
58
-
59
-			// Early exit if the value is not saved in the values.
60
-			if ( ! isset( $value[ $property ] ) || ! $value[ $property ] ) {
61
-				continue;
62
-			}
63
-
64
-			// Early exit if we use "choice" but not for this property.
65
-			if ( isset( $output['choice'] ) && $output['choice'] !== $property ) {
66
-				continue;
67
-			}
68
-
69
-			// Take care of variants.
70
-			if ( 'variant' === $property && isset( $value['variant'] ) && ! empty( $value['variant'] ) ) {
71
-
72
-				// Get the font_weight.
73
-				$font_weight = str_replace( 'italic', '', $value['variant'] );
74
-				$font_weight = ( in_array( $font_weight, [ '', 'regular' ], true ) ) ? '400' : $font_weight;
75
-
76
-				// Is this italic?
77
-				$is_italic = ( false !== strpos( $value['variant'], 'italic' ) );
78
-
79
-				$this->styles[ $output['media_query'] ][ $output['element'] ]['font-weight'] = $font_weight;
80
-
81
-				if ( $is_italic ) {
82
-					$this->styles[ $output['media_query'] ][ $output['element'] ]['font-style'] = 'italic';
83
-				}
84
-
85
-				continue;
86
-			}
87
-
88
-			$property_value = $this->process_property_value( $property, $value[ $property ] );
89
-			$property       = ( isset( $output['choice'] ) && isset( $output['property'] ) ) ? $output['property'] : $property;
90
-			$property_value = ( is_array( $property_value ) && isset( $property_value[0] ) ) ? $property_value[0] : $property_value;
91
-			$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $property_value . $output['suffix'];
92
-		}
93
-
94
-	}
21
+    /**
22
+     * Processes a single item from the `output` array.
23
+     *
24
+     * @access protected
25
+     * @param array $output The `output` item.
26
+     * @param array $value  The field's value.
27
+     */
28
+    protected function process_output( $output, $value ) {
29
+
30
+        $output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
31
+        $output['element']     = ( isset( $output['element'] ) ) ? $output['element'] : 'body';
32
+        $output['prefix']      = ( isset( $output['prefix'] ) ) ? $output['prefix'] : '';
33
+        $output['suffix']      = ( isset( $output['suffix'] ) ) ? $output['suffix'] : '';
34
+
35
+        $properties = [
36
+            'font-family',
37
+            'font-size',
38
+            'variant',
39
+            'font-weight',
40
+            'font-style',
41
+            'letter-spacing',
42
+            'word-spacing',
43
+            'line-height',
44
+            'text-align',
45
+            'text-transform',
46
+            'text-decoration',
47
+            'color',
48
+            'margin-top',
49
+            'margin-bottom',
50
+        ];
51
+
52
+        foreach ( $properties as $property ) {
53
+
54
+            // Early exit if the value is not in the defaults.
55
+            if ( ! isset( $this->field['default'][ $property ] ) ) {
56
+                continue;
57
+            }
58
+
59
+            // Early exit if the value is not saved in the values.
60
+            if ( ! isset( $value[ $property ] ) || ! $value[ $property ] ) {
61
+                continue;
62
+            }
63
+
64
+            // Early exit if we use "choice" but not for this property.
65
+            if ( isset( $output['choice'] ) && $output['choice'] !== $property ) {
66
+                continue;
67
+            }
68
+
69
+            // Take care of variants.
70
+            if ( 'variant' === $property && isset( $value['variant'] ) && ! empty( $value['variant'] ) ) {
71
+
72
+                // Get the font_weight.
73
+                $font_weight = str_replace( 'italic', '', $value['variant'] );
74
+                $font_weight = ( in_array( $font_weight, [ '', 'regular' ], true ) ) ? '400' : $font_weight;
75
+
76
+                // Is this italic?
77
+                $is_italic = ( false !== strpos( $value['variant'], 'italic' ) );
78
+
79
+                $this->styles[ $output['media_query'] ][ $output['element'] ]['font-weight'] = $font_weight;
80
+
81
+                if ( $is_italic ) {
82
+                    $this->styles[ $output['media_query'] ][ $output['element'] ]['font-style'] = 'italic';
83
+                }
84
+
85
+                continue;
86
+            }
87
+
88
+            $property_value = $this->process_property_value( $property, $value[ $property ] );
89
+            $property       = ( isset( $output['choice'] ) && isset( $output['property'] ) ) ? $output['property'] : $property;
90
+            $property_value = ( is_array( $property_value ) && isset( $property_value[0] ) ) ? $property_value[0] : $property_value;
91
+            $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $property_value . $output['suffix'];
92
+        }
93
+
94
+    }
95 95
 }
Please login to merge, or discard this patch.
packages/kirki-framework/field-typography/src/Field/Typography.php 1 patch
Indentation   +990 added lines, -990 removed lines patch added patch discarded remove patch
@@ -22,995 +22,995 @@
 block discarded – undo
22 22
  */
23 23
 class Typography extends Field {
24 24
 
25
-	/**
26
-	 * The field type.
27
-	 *
28
-	 * @access public
29
-	 * @since 1.0
30
-	 * @var string
31
-	 */
32
-	public $type = 'kirki-typography';
33
-
34
-	/**
35
-	 * Has the glogal fonts var been added already?
36
-	 *
37
-	 * @static
38
-	 * @access private
39
-	 * @since 1.0
40
-	 * @var bool
41
-	 */
42
-	private static $fonts_var_added = false;
43
-
44
-	/**
45
-	 * Has the preview related var been added already?
46
-	 *
47
-	 * @static
48
-	 * @access private
49
-	 * @since 1.0
50
-	 * @var bool
51
-	 */
52
-	private static $preview_var_added = false;
53
-
54
-	/**
55
-	 * An array of typography controls.
56
-	 *
57
-	 * This is used by the typography script for any custom logic
58
-	 * that has to be applied to typography controls.
59
-	 *
60
-	 * @static
61
-	 * @access private
62
-	 * @since 1.0
63
-	 * @var array
64
-	 */
65
-	private static $typography_controls = [];
66
-
67
-	/**
68
-	 * An array of standard font variants.
69
-	 *
70
-	 * @access private
71
-	 * @since 1.0.1
72
-	 *
73
-	 * @var array
74
-	 */
75
-	private static $std_variants;
76
-
77
-	/**
78
-	 * An array of complete font variants.
79
-	 *
80
-	 * @access private
81
-	 * @since 1.0.1
82
-	 *
83
-	 * @var array
84
-	 */
85
-	private static $complete_variants;
86
-
87
-	/**
88
-	 * An array of complete font variant labels.
89
-	 *
90
-	 * @access private
91
-	 * @since 1.0.2
92
-	 *
93
-	 * @var array
94
-	 */
95
-	private static $complete_variant_labels = [];
96
-
97
-	/**
98
-	 * Extra logic for the field.
99
-	 *
100
-	 * Adds all sub-fields.
101
-	 *
102
-	 * @access public
103
-	 * @param array $args The arguments of the field.
104
-	 */
105
-	public function init( $args = [] ) {
106
-
107
-		self::$typography_controls[] = $args['settings'];
108
-
109
-		self::$std_variants = [
110
-			[
111
-				'value' => 'regular',
112
-				'label' => __( 'Regular', 'kirki' ),
113
-			],
114
-			[
115
-				'value' => 'italic',
116
-				'label' => __( 'Italic', 'kirki' ),
117
-			],
118
-			[
119
-				'value' => '700',
120
-				'label' => __( '700', 'kirki' ),
121
-			],
122
-			[
123
-				'value' => '700italic',
124
-				'label' => __( '700 Italic', 'kirki' ),
125
-			],
126
-		];
127
-
128
-		self::$complete_variants = [
129
-			[
130
-				'value' => 'regular',
131
-				'label' => __( 'Regular', 'kirki' ),
132
-			],
133
-			[
134
-				'value' => 'italic',
135
-				'label' => __( 'Italic', 'kirki' ),
136
-			],
137
-			[
138
-				'value' => '100',
139
-				'label' => __( '100', 'kirki' ),
140
-			],
141
-			[
142
-				'value' => '100italic',
143
-				'label' => __( '100 Italic', 'kirki' ),
144
-			],
145
-			[
146
-				'value' => '200',
147
-				'label' => __( '200', 'kirki' ),
148
-			],
149
-			[
150
-				'value' => '200italic',
151
-				'label' => __( '200 Italic', 'kirki' ),
152
-			],
153
-			[
154
-				'value' => '300',
155
-				'label' => __( '300', 'kirki' ),
156
-			],
157
-			[
158
-				'value' => '300italic',
159
-				'label' => __( '300 Italic', 'kirki' ),
160
-			],
161
-			[
162
-				'value' => '500',
163
-				'label' => __( '500', 'kirki' ),
164
-			],
165
-			[
166
-				'value' => '500italic',
167
-				'label' => __( '500 Italic', 'kirki' ),
168
-			],
169
-			[
170
-				'value' => '600',
171
-				'label' => __( '600', 'kirki' ),
172
-			],
173
-			[
174
-				'value' => '600italic',
175
-				'label' => __( '600 Italic', 'kirki' ),
176
-			],
177
-			[
178
-				'value' => '700',
179
-				'label' => __( '700', 'kirki' ),
180
-			],
181
-			[
182
-				'value' => '700italic',
183
-				'label' => __( '700 Italic', 'kirki' ),
184
-			],
185
-			[
186
-				'value' => '800',
187
-				'label' => __( '800', 'kirki' ),
188
-			],
189
-			[
190
-				'value' => '800italic',
191
-				'label' => __( '800 Italic', 'kirki' ),
192
-			],
193
-			[
194
-				'value' => '900',
195
-				'label' => __( '900', 'kirki' ),
196
-			],
197
-			[
198
-				'value' => '900italic',
199
-				'label' => __( '900 Italic', 'kirki' ),
200
-			],
201
-		];
202
-
203
-		foreach ( self::$complete_variants as $variants ) {
204
-			self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
205
-		}
206
-
207
-		$this->add_sub_fields( $args );
208
-
209
-		add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
210
-		add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
211
-		add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
212
-	}
213
-
214
-	/**
215
-	 * Add sub-fields.
216
-	 *
217
-	 * @access private
218
-	 * @since 1.0
219
-	 * @param array $args The field arguments.
220
-	 * @return void
221
-	 */
222
-	private function add_sub_fields( $args ) {
223
-
224
-		$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
225
-
226
-		$defaults = isset( $args['default'] ) ? $args['default'] : [];
227
-
228
-		/**
229
-		 * Add a hidden field, the label & description.
230
-		 */
231
-		new \Kirki\Field\Generic(
232
-			wp_parse_args(
233
-				[
234
-					'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
235
-					'wrapper_opts'      => [
236
-						'gap' => 'small',
237
-					],
238
-					'input_attrs'       => '',
239
-					'choices'           => [
240
-						'type'        => 'hidden',
241
-						'parent_type' => 'kirki-typography',
242
-					],
243
-				],
244
-				$args
245
-			)
246
-		);
247
-
248
-		$args['parent_setting'] = $args['settings'];
249
-		$args['output']         = [];
250
-		$args['wrapper_attrs']  = [
251
-			'data-kirki-parent-control-type' => 'kirki-typography',
252
-		];
253
-
254
-		if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
255
-			$args['transport'] = 'postMessage';
256
-		}
257
-
258
-		/**
259
-		 * Add font-family selection controls.
260
-		 * These include font-family and variant.
261
-		 * They are grouped here because all they are required.
262
-		 * in order to get the right googlefont variant.
263
-		 */
264
-		if ( isset( $args['default']['font-family'] ) ) {
265
-
266
-			$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
267
-
268
-			/**
269
-			 * Add font-family control.
270
-			 */
271
-			new \Kirki\Field\ReactSelect(
272
-				wp_parse_args(
273
-					[
274
-						'label'       => esc_html__( 'Font Family', 'kirki' ),
275
-						'description' => '',
276
-						'settings'    => $args['settings'] . '[font-family]',
277
-						'default'     => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
278
-						'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
279
-						'choices'     => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
280
-						'css_vars'    => [],
281
-						'output'      => [],
282
-					],
283
-					$args
284
-				)
285
-			);
286
-
287
-			/**
288
-			 * Add font variant.
289
-			 */
290
-			$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
291
-
292
-			if ( isset( $args['default']['font-weight'] ) ) {
293
-				$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
294
-			}
295
-
296
-			$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
297
-
298
-			new \Kirki\Field\ReactSelect(
299
-				wp_parse_args(
300
-					[
301
-						'label'       => esc_html__( 'Font Variant', 'kirki' ),
302
-						'description' => '',
303
-						'settings'    => $args['settings'] . '[variant]',
304
-						'default'     => $font_variant,
305
-						'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
306
-						'choices'     => [], // The choices will be populated later inside `get_variant_choices` function in this file.
307
-						'css_vars'    => [],
308
-						'output'      => [],
309
-					],
310
-					$args
311
-				)
312
-			);
313
-
314
-		}
315
-
316
-		$font_size_field_specified = isset( $defaults['font-size'] );
317
-		$color_field_specified     = isset( $defaults['color'] );
318
-
319
-		if ( $font_size_field_specified || $color_field_specified ) {
320
-			$group = [
321
-				'font-size' => [
322
-					'type'         => 'dimension',
323
-					'label'        => esc_html__( 'Font Size', 'kirki' ),
324
-					'is_specified' => $font_size_field_specified,
325
-				],
326
-				'color'     => [
327
-					'type'         => 'react-colorful',
328
-					'label'        => esc_html__( 'Font Color', 'kirki' ),
329
-					'is_specified' => $color_field_specified,
330
-					'choices'      => [
331
-						'alpha'       => true,
332
-						'label_style' => 'top',
333
-					],
334
-				],
335
-			];
336
-
337
-			$this->generate_controls_group( $group, $args );
338
-		}
339
-
340
-		$text_align_field_specified     = isset( $defaults['text-align'] );
341
-		$text_transform_field_specified = isset( $defaults['text-transform'] );
342
-
343
-		if ( $text_align_field_specified || $text_transform_field_specified ) {
344
-			$group = [
345
-				'text-align'     => [
346
-					'type'         => 'react-select',
347
-					'label'        => esc_html__( 'Text Align', 'kirki' ),
348
-					'is_specified' => $text_align_field_specified,
349
-					'choices'      => [
350
-						'initial' => esc_html__( 'Initial', 'kirki' ),
351
-						'left'    => esc_html__( 'Left', 'kirki' ),
352
-						'center'  => esc_html__( 'Center', 'kirki' ),
353
-						'right'   => esc_html__( 'Right', 'kirki' ),
354
-						'justify' => esc_html__( 'Justify', 'kirki' ),
355
-					],
356
-				],
357
-				'text-transform' => [
358
-					'type'         => 'react-select',
359
-					'label'        => esc_html__( 'Text Transform', 'kirki' ),
360
-					'is_specified' => $text_transform_field_specified,
361
-					'choices'      => [
362
-						'none'       => esc_html__( 'None', 'kirki' ),
363
-						'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
364
-						'uppercase'  => esc_html__( 'Uppercase', 'kirki' ),
365
-						'lowercase'  => esc_html__( 'Lowercase', 'kirki' ),
366
-					],
367
-				],
368
-			];
369
-
370
-			$this->generate_controls_group( $group, $args );
371
-		}
372
-
373
-		$text_decoration_field_specified = isset( $defaults['text-decoration'] );
374
-
375
-		if ( $text_decoration_field_specified ) {
376
-			$group = [
377
-				'text-decoration' => [
378
-					'type'         => 'react-select',
379
-					'label'        => esc_html__( 'Text Decoration', 'kirki' ),
380
-					'is_specified' => $text_decoration_field_specified,
381
-					'choices'      => [
382
-						'none'         => esc_html__( 'None', 'kirki' ),
383
-						'underline'    => esc_html__( 'Underline', 'kirki' ),
384
-						'line-through' => esc_html__( 'Line Through', 'kirki' ),
385
-						'overline'     => esc_html__( 'Overline', 'kirki' ),
386
-						'solid'        => esc_html__( 'Solid', 'kirki' ),
387
-						'wavy'         => esc_html__( 'Wavy', 'kirki' ),
388
-					],
389
-				],
390
-			];
391
-
392
-			$this->generate_controls_group( $group, $args );
393
-		}
394
-
395
-		$line_height_field_specified    = isset( $defaults['line-height'] );
396
-		$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
397
-
398
-		if ( $line_height_field_specified || $letter_spacing_field_specified ) {
399
-			$group = [
400
-				'line-height'    => [
401
-					'type'         => 'dimension',
402
-					'label'        => esc_html__( 'Line Height', 'kirki' ),
403
-					'is_specified' => $line_height_field_specified,
404
-				],
405
-				'letter-spacing' => [
406
-					'type'         => 'dimension',
407
-					'label'        => esc_html__( 'Letter Spacing', 'kirki' ),
408
-					'is_specified' => $letter_spacing_field_specified,
409
-				],
410
-			];
411
-
412
-			$this->generate_controls_group( $group, $args );
413
-		}
414
-
415
-		$margin_top_field_specified    = isset( $defaults['margin-top'] );
416
-		$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
417
-
418
-		if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
419
-			$group = [
420
-				'margin-top'    => [
421
-					'type'         => 'dimension',
422
-					'label'        => esc_html__( 'Margin Top', 'kirki' ),
423
-					'is_specified' => $margin_top_field_specified,
424
-				],
425
-				'margin-bottom' => [
426
-					'type'         => 'dimension',
427
-					'label'        => esc_html__( 'Margin Bottom', 'kirki' ),
428
-					'is_specified' => $margin_bottom_field_specified,
429
-				],
430
-			];
431
-
432
-			$this->generate_controls_group( $group, $args );
433
-		}
434
-
435
-	}
436
-
437
-	/**
438
-	 * Generate controls group.
439
-	 *
440
-	 * @param array $group The group data.
441
-	 * @param array $args The field args.
442
-	 */
443
-	public function generate_controls_group( $group, $args ) {
444
-
445
-		$total_specified = 0;
446
-		$field_width     = 100;
447
-
448
-		foreach ( $group as $css_prop => $control ) {
449
-			if ( $control['is_specified'] ) {
450
-				$total_specified++;
451
-			}
452
-		}
453
-
454
-		if ( $total_specified > 1 ) {
455
-			$field_width = floor( 100 / $total_specified );
456
-		}
457
-
458
-		$group_count = 0;
459
-
460
-		foreach ( $group as $css_prop => $control ) {
461
-			if ( $control['is_specified'] ) {
462
-				$group_count++;
463
-
464
-				$group_classname  = 'kirki-group-item';
465
-				$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
466
-
467
-				$control_class = str_ireplace( '-', ' ', $control['type'] );
468
-				$control_class = ucwords( $control_class );
469
-				$control_class = str_replace( ' ', '', $control_class );
470
-				$control_class = '\\Kirki\\Field\\' . $control_class;
471
-
472
-				new $control_class(
473
-					wp_parse_args(
474
-						[
475
-							'label'         => isset( $control['label'] ) ? $control['label'] : '',
476
-							'description'   => isset( $control['description'] ) ? $control['description'] : '',
477
-							'settings'      => $args['settings'] . '[' . $css_prop . ']',
478
-							'default'       => $args['default'][ $css_prop ],
479
-							'wrapper_attrs' => wp_parse_args(
480
-								[
481
-									'data-kirki-typography-css-prop' => $css_prop,
482
-									'kirki-typography-subcontrol-type' => $css_prop,
483
-									'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
484
-								],
485
-								$args['wrapper_attrs']
486
-							),
487
-							'input_attrs'   => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
488
-							'choices'       => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
489
-							'css_vars'      => [],
490
-							'output'        => [],
491
-						],
492
-						$args
493
-					)
494
-				);
495
-
496
-			}
497
-		}
498
-
499
-	}
500
-
501
-	/**
502
-	 * Sanitizes typography controls
503
-	 *
504
-	 * @static
505
-	 * @since 1.0
506
-	 * @param array $value The value.
507
-	 * @return array
508
-	 */
509
-	public static function sanitize( $value ) {
510
-
511
-		if ( ! is_array( $value ) ) {
512
-			return [];
513
-		}
514
-
515
-		foreach ( $value as $key => $val ) {
516
-			switch ( $key ) {
517
-				case 'font-family':
518
-					$value['font-family'] = sanitize_text_field( $val );
519
-					break;
520
-
521
-				case 'variant':
522
-					// Use 'regular' instead of 400 for font-variant.
523
-					$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
524
-
525
-					// Get font-weight from variant.
526
-					$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
527
-					$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
528
-
529
-					// Get font-style from variant.
530
-					if ( ! isset( $value['font-style'] ) ) {
531
-						$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
532
-					}
533
-
534
-					break;
535
-
536
-				case 'text-align':
537
-					if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
538
-						$value['text-align'] = '';
539
-					}
540
-
541
-					break;
542
-
543
-				case 'text-transform':
544
-					if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
545
-						$value['text-transform'] = '';
546
-					}
547
-
548
-					break;
549
-
550
-				case 'text-decoration':
551
-					if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
552
-						$value['text-transform'] = '';
553
-					}
554
-
555
-					break;
556
-
557
-				case 'color':
558
-					$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
559
-					break;
560
-
561
-				default:
562
-					$value[ $key ] = sanitize_text_field( $value[ $key ] );
563
-			}
564
-		}
565
-
566
-		return $value;
567
-
568
-	}
569
-
570
-	/**
571
-	 * Enqueue scripts & styles.
572
-	 *
573
-	 * @access public
574
-	 * @since 1.0
575
-	 * @return void
576
-	 */
577
-	public function enqueue_control_scripts() {
578
-
579
-		wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
580
-
581
-		wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
582
-
583
-		wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
584
-
585
-		$args = $this->args;
586
-
587
-		$variants = [];
588
-
589
-		// Add custom variants (for custom fonts) to the $variants.
590
-		if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
591
-
592
-			// If $args['choices']['fonts']['families'] exists, then loop it.
593
-			foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
594
-
595
-				// Then loop the $font_family_value['children].
596
-				foreach ( $font_family_value['children'] as $font_family ) {
597
-
598
-					// Then check if $font_family['id'] exists in variants argument.
599
-					if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
600
-
601
-						// Create new array if $variants[ $font_family['id'] ] doesn't exist.
602
-						if ( ! isset( $variants[ $font_family['id'] ] ) ) {
603
-							$variants[ $font_family['id'] ] = [];
604
-						}
605
-
606
-						// The $custom_variant here can be something like "400italic" or "italic".
607
-						foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
608
-
609
-							// Check if $custom_variant exists in self::$complete_variant_labels.
610
-							if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
611
-
612
-								// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
613
-								array_push(
614
-									$variants[ $font_family['id'] ],
615
-									[
616
-										'value' => $custom_variant,
617
-										'label' => self::$complete_variant_labels[ $custom_variant ],
618
-									]
619
-								);
620
-
621
-							} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
622
-						} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
623
-					}
624
-				} // End of $font_family_value['children'] foreach.
625
-			} // End of $args['choices']['fonts']['families'] foreach.
626
-		} // End of $args['choices']['fonts']['families'] if.
627
-
628
-		if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
629
-			$standard_fonts = Fonts::get_standard_fonts();
630
-
631
-			foreach ( $standard_fonts as $font ) {
632
-				if ( isset( $font['variants'] ) ) {
633
-
634
-					// Create new array if $variants[ $font['stack'] ] doesn't exist.
635
-					if ( ! isset( $variants[ $font['stack'] ] ) ) {
636
-						$variants[ $font['stack'] ] = [];
637
-					}
638
-
639
-					// The $std_variant here can be something like "400italic" or "italic".
640
-					foreach ( $font['variants'] as $std_variant ) {
641
-
642
-						// Check if $std_variant exists in self::$complete_variant_labels.
643
-						if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
644
-
645
-							// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
646
-							array_push(
647
-								$variants[ $font['stack'] ],
648
-								[
649
-									'value' => $std_variant,
650
-									'label' => self::$complete_variant_labels[ $std_variant ],
651
-								]
652
-							);
653
-
654
-						} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
655
-					} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
656
-				}
657
-			}
658
-		} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
659
-			foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
660
-				$key = ( is_int( $key ) ) ? $val : $key;
661
-
662
-				if ( isset( $val['variants'] ) ) {
663
-
664
-					// Create new array if $variants[ $font['stack'] ] doesn't exist.
665
-					if ( ! isset( $variants[ $key ] ) ) {
666
-						$variants[ $key ] = [];
667
-					}
668
-
669
-					// The $std_variant here can be something like "400italic" or "italic".
670
-					foreach ( $val['variants'] as $std_variant ) {
671
-
672
-						// Check if $std_variant exists in self::$complete_variant_labels.
673
-						if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
674
-
675
-							// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
676
-							array_push(
677
-								$variants[ $key ],
678
-								[
679
-									'value' => $std_variant,
680
-									'label' => self::$complete_variant_labels[ $std_variant ],
681
-								]
682
-							);
683
-
684
-						} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
685
-					} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
686
-				}
687
-			}
688
-		}
689
-
690
-		// Scripts inside this block will only be executed once.
691
-		if ( ! self::$fonts_var_added ) {
692
-			wp_localize_script(
693
-				'kirki-control-typography',
694
-				'kirkiFontVariants',
695
-				[
696
-					'standard' => self::$std_variants,
697
-					'complete' => self::$complete_variants,
698
-				]
699
-			);
700
-
701
-			$google = new GoogleFonts();
702
-
703
-			wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
704
-			wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
705
-
706
-			self::$fonts_var_added = true;
707
-		}
708
-
709
-		// This custom variants will be available for each typography control.
710
-		$custom_variant_key   = str_ireplace( ']', '', $args['settings'] );
711
-		$custom_variant_key   = str_ireplace( '[', '_', $custom_variant_key );
712
-		$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
713
-
714
-		wp_add_inline_script(
715
-			'kirki-control-typography',
716
-			'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
717
-			$variants
718
-		);
719
-
720
-	}
721
-
722
-	/**
723
-	 * Enqueue scripts for customize_preview_init.
724
-	 *
725
-	 * @access public
726
-	 * @since 1.0
727
-	 * @return void
728
-	 */
729
-	public function enqueue_preview_scripts() {
730
-
731
-		wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
732
-
733
-		if ( ! self::$preview_var_added ) {
734
-			$google = new GoogleFonts();
735
-
736
-			wp_localize_script(
737
-				'kirki-preview-typography',
738
-				'kirkiGoogleFontNames',
739
-				$google->get_google_font_names()
740
-			);
741
-
742
-			self::$preview_var_added = true;
743
-		}
744
-
745
-	}
746
-
747
-	/**
748
-	 * Prefer control specific value over field value
749
-	 *
750
-	 * @access public
751
-	 * @since 4.0
752
-	 * @param $setting
753
-	 * @param $choice
754
-	 * @param $args
755
-	 *
756
-	 * @return string
757
-	 */
758
-	public function filter_preferred_choice_setting( $setting, $choice, $args ) {
759
-
760
-		// Fail early.
761
-		if ( ! isset( $args[ $setting ] ) ) {
762
-			return '';
763
-		}
764
-
765
-		// If a specific field for the choice is set
766
-		if ( isset( $args[ $setting ][ $choice ] ) ) {
767
-			return $args[ $setting ][ $choice ];
768
-		}
769
-
770
-		// Unset input_attrs of all other choices.
771
-		foreach ( $args['choices'] as $id => $set ) {
772
-			if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
773
-				unset( $args[ $setting ][ $id ] );
774
-			} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
775
-				$args[ $setting ] = '';
776
-			}
777
-		}
778
-
779
-		return $args[ $setting ];
780
-
781
-	}
782
-
783
-	/**
784
-	 * Populate the font family choices.
785
-	 *
786
-	 * It's separated from the `add_sub_field` function to prevent a bug
787
-	 * when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
788
-	 *
789
-	 * When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
790
-	 * But if it's hooked after field registration, then the function won't be available.
791
-	 *
792
-	 * @access private
793
-	 * @since 1.0.1
794
-	 *
795
-	 * @return array
796
-	 */
797
-	private function get_font_family_choices() {
798
-
799
-		$args = $this->args;
800
-
801
-		// Figure out how to sort the fonts.
802
-		$sorting   = 'alpha';
803
-		$max_fonts = 9999;
804
-		$google    = new GoogleFonts();
805
-
806
-		if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
807
-			if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
808
-				$sorting = $args['choices']['fonts']['google'][0];
809
-
810
-				if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
811
-					$max_fonts = (int) $args['choices']['fonts']['google'][1];
812
-				}
813
-
814
-				$g_fonts = $google->get_google_fonts_by_args(
815
-					[
816
-						'sort'  => $sorting,
817
-						'count' => $max_fonts,
818
-					]
819
-				);
820
-			} else {
821
-				$g_fonts = $args['choices']['fonts']['google'];
822
-			}
823
-		} else {
824
-			$g_fonts = $google->get_google_fonts_by_args(
825
-				[
826
-					'sort'  => $sorting,
827
-					'count' => $max_fonts,
828
-				]
829
-			);
830
-		}
831
-
832
-		$std_fonts = [];
833
-
834
-		if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
835
-			$standard_fonts = Fonts::get_standard_fonts();
836
-
837
-			foreach ( $standard_fonts as $font ) {
838
-				$std_fonts[ $font['stack'] ] = $font['label'];
839
-			}
840
-		} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
841
-			foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
842
-				$key               = ( \is_int( $key ) ) ? $val : $key;
843
-				$std_fonts[ $key ] = $val;
844
-			}
845
-		}
846
-
847
-		$choices = [];
848
-
849
-		$choices['default'] = [
850
-			esc_html__( 'Defaults', 'kirki' ),
851
-			[
852
-				'' => esc_html__( 'Default', 'kirki' ),
853
-			],
854
-		];
855
-
856
-		if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
857
-			// Implementing the custom font families.
858
-			foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
859
-				if ( ! isset( $choices[ $font_family_key ] ) ) {
860
-					$choices[ $font_family_key ] = [];
861
-				}
862
-
863
-				$family_opts = [];
864
-
865
-				foreach ( $font_family_value['children'] as $font_family ) {
866
-					$family_opts[ $font_family['id'] ] = $font_family['text'];
867
-				}
868
-
869
-				$choices[ $font_family_key ] = [
870
-					$font_family_value['text'],
871
-					$family_opts,
872
-				];
873
-			}
874
-		}
875
-
876
-		$choices['standard'] = [
877
-			esc_html__( 'Standard Fonts', 'kirki' ),
878
-			$std_fonts,
879
-		];
880
-
881
-		$choices['google'] = [
882
-			esc_html__( 'Google Fonts', 'kirki' ),
883
-			array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
884
-		];
885
-
886
-		if ( empty( $choices['standard'][1] ) ) {
887
-			$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
888
-		} elseif ( empty( $choices['google'][1] ) ) {
889
-			$choices = $std_fonts;
890
-		}
891
-
892
-		return $choices;
893
-
894
-	}
895
-
896
-	/**
897
-	 * Get custom variant choices (for custom fonts).
898
-	 *
899
-	 * It's separated from the `add_sub_field` function to prevent a bug
900
-	 * when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
901
-	 *
902
-	 * When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
903
-	 * But if it's hooked after field registration, then the function won't be available.
904
-	 *
905
-	 * @access private
906
-	 * @since 1.0.2
907
-	 *
908
-	 * @return array
909
-	 */
910
-	private function get_variant_choices() {
911
-
912
-		$args = $this->args;
913
-
914
-		$choices = self::$std_variants;
915
-
916
-		// Implementing the custom variants for custom fonts.
917
-		if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
918
-
919
-			$choices = [];
920
-
921
-			// If $args['choices']['fonts']['families'] exists, then loop it.
922
-			foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
923
-
924
-				// Then loop the $font_family_value['children].
925
-				foreach ( $font_family_value['children'] as $font_family ) {
926
-
927
-					// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
928
-					if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
929
-
930
-						// The $custom_variant here can be something like "400italic" or "italic".
931
-						foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
932
-
933
-							// Check if $custom_variant exists in self::$complete_variant_labels.
934
-							if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
935
-
936
-								// If it exists, assign it to $choices.
937
-								array_push(
938
-									$choices,
939
-									[
940
-										'value' => $custom_variant,
941
-										'label' => self::$complete_variant_labels[ $custom_variant ],
942
-									]
943
-								);
944
-
945
-							} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
946
-						} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
947
-					}
948
-				} // End of $font_family_value['children'] foreach.
949
-			} // End of $args['choices']['fonts']['families'] foreach.
950
-		} // End of $args['choices']['fonts']['families'] if.
951
-
952
-		return $choices;
953
-
954
-	}
955
-
956
-	/**
957
-	 * Filter arguments before creating the control.
958
-	 *
959
-	 * @access public
960
-	 * @since 0.1
961
-	 * @param array                $args         The field arguments.
962
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
963
-	 * @return array
964
-	 */
965
-	public function filter_control_args( $args, $wp_customize ) {
966
-
967
-		if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
968
-			$args            = parent::filter_control_args( $args, $wp_customize );
969
-			$args['choices'] = $this->get_font_family_choices();
970
-		}
971
-
972
-		if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
973
-			$args            = parent::filter_control_args( $args, $wp_customize );
974
-			$args['choices'] = $this->get_variant_choices();
975
-		}
976
-
977
-		return $args;
978
-
979
-	}
980
-
981
-	/**
982
-	 * Adds a custom output class for typography fields.
983
-	 *
984
-	 * @access public
985
-	 * @since 1.0
986
-	 * @param array $classnames The array of classnames.
987
-	 * @return array
988
-	 */
989
-	public function output_control_classnames( $classnames ) {
990
-
991
-		$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
992
-		return $classnames;
993
-
994
-	}
995
-
996
-	/**
997
-	 * Override parent method. No need to register any setting.
998
-	 *
999
-	 * @access public
1000
-	 * @since 0.1
1001
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
1002
-	 * @return void
1003
-	 */
1004
-	public function add_setting( $wp_customize ) {}
1005
-
1006
-	/**
1007
-	 * Override the parent method. No need for a control.
1008
-	 *
1009
-	 * @access public
1010
-	 * @since 0.1
1011
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
1012
-	 * @return void
1013
-	 */
1014
-	public function add_control( $wp_customize ) {}
25
+    /**
26
+     * The field type.
27
+     *
28
+     * @access public
29
+     * @since 1.0
30
+     * @var string
31
+     */
32
+    public $type = 'kirki-typography';
33
+
34
+    /**
35
+     * Has the glogal fonts var been added already?
36
+     *
37
+     * @static
38
+     * @access private
39
+     * @since 1.0
40
+     * @var bool
41
+     */
42
+    private static $fonts_var_added = false;
43
+
44
+    /**
45
+     * Has the preview related var been added already?
46
+     *
47
+     * @static
48
+     * @access private
49
+     * @since 1.0
50
+     * @var bool
51
+     */
52
+    private static $preview_var_added = false;
53
+
54
+    /**
55
+     * An array of typography controls.
56
+     *
57
+     * This is used by the typography script for any custom logic
58
+     * that has to be applied to typography controls.
59
+     *
60
+     * @static
61
+     * @access private
62
+     * @since 1.0
63
+     * @var array
64
+     */
65
+    private static $typography_controls = [];
66
+
67
+    /**
68
+     * An array of standard font variants.
69
+     *
70
+     * @access private
71
+     * @since 1.0.1
72
+     *
73
+     * @var array
74
+     */
75
+    private static $std_variants;
76
+
77
+    /**
78
+     * An array of complete font variants.
79
+     *
80
+     * @access private
81
+     * @since 1.0.1
82
+     *
83
+     * @var array
84
+     */
85
+    private static $complete_variants;
86
+
87
+    /**
88
+     * An array of complete font variant labels.
89
+     *
90
+     * @access private
91
+     * @since 1.0.2
92
+     *
93
+     * @var array
94
+     */
95
+    private static $complete_variant_labels = [];
96
+
97
+    /**
98
+     * Extra logic for the field.
99
+     *
100
+     * Adds all sub-fields.
101
+     *
102
+     * @access public
103
+     * @param array $args The arguments of the field.
104
+     */
105
+    public function init( $args = [] ) {
106
+
107
+        self::$typography_controls[] = $args['settings'];
108
+
109
+        self::$std_variants = [
110
+            [
111
+                'value' => 'regular',
112
+                'label' => __( 'Regular', 'kirki' ),
113
+            ],
114
+            [
115
+                'value' => 'italic',
116
+                'label' => __( 'Italic', 'kirki' ),
117
+            ],
118
+            [
119
+                'value' => '700',
120
+                'label' => __( '700', 'kirki' ),
121
+            ],
122
+            [
123
+                'value' => '700italic',
124
+                'label' => __( '700 Italic', 'kirki' ),
125
+            ],
126
+        ];
127
+
128
+        self::$complete_variants = [
129
+            [
130
+                'value' => 'regular',
131
+                'label' => __( 'Regular', 'kirki' ),
132
+            ],
133
+            [
134
+                'value' => 'italic',
135
+                'label' => __( 'Italic', 'kirki' ),
136
+            ],
137
+            [
138
+                'value' => '100',
139
+                'label' => __( '100', 'kirki' ),
140
+            ],
141
+            [
142
+                'value' => '100italic',
143
+                'label' => __( '100 Italic', 'kirki' ),
144
+            ],
145
+            [
146
+                'value' => '200',
147
+                'label' => __( '200', 'kirki' ),
148
+            ],
149
+            [
150
+                'value' => '200italic',
151
+                'label' => __( '200 Italic', 'kirki' ),
152
+            ],
153
+            [
154
+                'value' => '300',
155
+                'label' => __( '300', 'kirki' ),
156
+            ],
157
+            [
158
+                'value' => '300italic',
159
+                'label' => __( '300 Italic', 'kirki' ),
160
+            ],
161
+            [
162
+                'value' => '500',
163
+                'label' => __( '500', 'kirki' ),
164
+            ],
165
+            [
166
+                'value' => '500italic',
167
+                'label' => __( '500 Italic', 'kirki' ),
168
+            ],
169
+            [
170
+                'value' => '600',
171
+                'label' => __( '600', 'kirki' ),
172
+            ],
173
+            [
174
+                'value' => '600italic',
175
+                'label' => __( '600 Italic', 'kirki' ),
176
+            ],
177
+            [
178
+                'value' => '700',
179
+                'label' => __( '700', 'kirki' ),
180
+            ],
181
+            [
182
+                'value' => '700italic',
183
+                'label' => __( '700 Italic', 'kirki' ),
184
+            ],
185
+            [
186
+                'value' => '800',
187
+                'label' => __( '800', 'kirki' ),
188
+            ],
189
+            [
190
+                'value' => '800italic',
191
+                'label' => __( '800 Italic', 'kirki' ),
192
+            ],
193
+            [
194
+                'value' => '900',
195
+                'label' => __( '900', 'kirki' ),
196
+            ],
197
+            [
198
+                'value' => '900italic',
199
+                'label' => __( '900 Italic', 'kirki' ),
200
+            ],
201
+        ];
202
+
203
+        foreach ( self::$complete_variants as $variants ) {
204
+            self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
205
+        }
206
+
207
+        $this->add_sub_fields( $args );
208
+
209
+        add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
210
+        add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
211
+        add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
212
+    }
213
+
214
+    /**
215
+     * Add sub-fields.
216
+     *
217
+     * @access private
218
+     * @since 1.0
219
+     * @param array $args The field arguments.
220
+     * @return void
221
+     */
222
+    private function add_sub_fields( $args ) {
223
+
224
+        $args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
225
+
226
+        $defaults = isset( $args['default'] ) ? $args['default'] : [];
227
+
228
+        /**
229
+         * Add a hidden field, the label & description.
230
+         */
231
+        new \Kirki\Field\Generic(
232
+            wp_parse_args(
233
+                [
234
+                    'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
235
+                    'wrapper_opts'      => [
236
+                        'gap' => 'small',
237
+                    ],
238
+                    'input_attrs'       => '',
239
+                    'choices'           => [
240
+                        'type'        => 'hidden',
241
+                        'parent_type' => 'kirki-typography',
242
+                    ],
243
+                ],
244
+                $args
245
+            )
246
+        );
247
+
248
+        $args['parent_setting'] = $args['settings'];
249
+        $args['output']         = [];
250
+        $args['wrapper_attrs']  = [
251
+            'data-kirki-parent-control-type' => 'kirki-typography',
252
+        ];
253
+
254
+        if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
255
+            $args['transport'] = 'postMessage';
256
+        }
257
+
258
+        /**
259
+         * Add font-family selection controls.
260
+         * These include font-family and variant.
261
+         * They are grouped here because all they are required.
262
+         * in order to get the right googlefont variant.
263
+         */
264
+        if ( isset( $args['default']['font-family'] ) ) {
265
+
266
+            $args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
267
+
268
+            /**
269
+             * Add font-family control.
270
+             */
271
+            new \Kirki\Field\ReactSelect(
272
+                wp_parse_args(
273
+                    [
274
+                        'label'       => esc_html__( 'Font Family', 'kirki' ),
275
+                        'description' => '',
276
+                        'settings'    => $args['settings'] . '[font-family]',
277
+                        'default'     => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
278
+                        'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
279
+                        'choices'     => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
280
+                        'css_vars'    => [],
281
+                        'output'      => [],
282
+                    ],
283
+                    $args
284
+                )
285
+            );
286
+
287
+            /**
288
+             * Add font variant.
289
+             */
290
+            $font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
291
+
292
+            if ( isset( $args['default']['font-weight'] ) ) {
293
+                $font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
294
+            }
295
+
296
+            $args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
297
+
298
+            new \Kirki\Field\ReactSelect(
299
+                wp_parse_args(
300
+                    [
301
+                        'label'       => esc_html__( 'Font Variant', 'kirki' ),
302
+                        'description' => '',
303
+                        'settings'    => $args['settings'] . '[variant]',
304
+                        'default'     => $font_variant,
305
+                        'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
306
+                        'choices'     => [], // The choices will be populated later inside `get_variant_choices` function in this file.
307
+                        'css_vars'    => [],
308
+                        'output'      => [],
309
+                    ],
310
+                    $args
311
+                )
312
+            );
313
+
314
+        }
315
+
316
+        $font_size_field_specified = isset( $defaults['font-size'] );
317
+        $color_field_specified     = isset( $defaults['color'] );
318
+
319
+        if ( $font_size_field_specified || $color_field_specified ) {
320
+            $group = [
321
+                'font-size' => [
322
+                    'type'         => 'dimension',
323
+                    'label'        => esc_html__( 'Font Size', 'kirki' ),
324
+                    'is_specified' => $font_size_field_specified,
325
+                ],
326
+                'color'     => [
327
+                    'type'         => 'react-colorful',
328
+                    'label'        => esc_html__( 'Font Color', 'kirki' ),
329
+                    'is_specified' => $color_field_specified,
330
+                    'choices'      => [
331
+                        'alpha'       => true,
332
+                        'label_style' => 'top',
333
+                    ],
334
+                ],
335
+            ];
336
+
337
+            $this->generate_controls_group( $group, $args );
338
+        }
339
+
340
+        $text_align_field_specified     = isset( $defaults['text-align'] );
341
+        $text_transform_field_specified = isset( $defaults['text-transform'] );
342
+
343
+        if ( $text_align_field_specified || $text_transform_field_specified ) {
344
+            $group = [
345
+                'text-align'     => [
346
+                    'type'         => 'react-select',
347
+                    'label'        => esc_html__( 'Text Align', 'kirki' ),
348
+                    'is_specified' => $text_align_field_specified,
349
+                    'choices'      => [
350
+                        'initial' => esc_html__( 'Initial', 'kirki' ),
351
+                        'left'    => esc_html__( 'Left', 'kirki' ),
352
+                        'center'  => esc_html__( 'Center', 'kirki' ),
353
+                        'right'   => esc_html__( 'Right', 'kirki' ),
354
+                        'justify' => esc_html__( 'Justify', 'kirki' ),
355
+                    ],
356
+                ],
357
+                'text-transform' => [
358
+                    'type'         => 'react-select',
359
+                    'label'        => esc_html__( 'Text Transform', 'kirki' ),
360
+                    'is_specified' => $text_transform_field_specified,
361
+                    'choices'      => [
362
+                        'none'       => esc_html__( 'None', 'kirki' ),
363
+                        'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
364
+                        'uppercase'  => esc_html__( 'Uppercase', 'kirki' ),
365
+                        'lowercase'  => esc_html__( 'Lowercase', 'kirki' ),
366
+                    ],
367
+                ],
368
+            ];
369
+
370
+            $this->generate_controls_group( $group, $args );
371
+        }
372
+
373
+        $text_decoration_field_specified = isset( $defaults['text-decoration'] );
374
+
375
+        if ( $text_decoration_field_specified ) {
376
+            $group = [
377
+                'text-decoration' => [
378
+                    'type'         => 'react-select',
379
+                    'label'        => esc_html__( 'Text Decoration', 'kirki' ),
380
+                    'is_specified' => $text_decoration_field_specified,
381
+                    'choices'      => [
382
+                        'none'         => esc_html__( 'None', 'kirki' ),
383
+                        'underline'    => esc_html__( 'Underline', 'kirki' ),
384
+                        'line-through' => esc_html__( 'Line Through', 'kirki' ),
385
+                        'overline'     => esc_html__( 'Overline', 'kirki' ),
386
+                        'solid'        => esc_html__( 'Solid', 'kirki' ),
387
+                        'wavy'         => esc_html__( 'Wavy', 'kirki' ),
388
+                    ],
389
+                ],
390
+            ];
391
+
392
+            $this->generate_controls_group( $group, $args );
393
+        }
394
+
395
+        $line_height_field_specified    = isset( $defaults['line-height'] );
396
+        $letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
397
+
398
+        if ( $line_height_field_specified || $letter_spacing_field_specified ) {
399
+            $group = [
400
+                'line-height'    => [
401
+                    'type'         => 'dimension',
402
+                    'label'        => esc_html__( 'Line Height', 'kirki' ),
403
+                    'is_specified' => $line_height_field_specified,
404
+                ],
405
+                'letter-spacing' => [
406
+                    'type'         => 'dimension',
407
+                    'label'        => esc_html__( 'Letter Spacing', 'kirki' ),
408
+                    'is_specified' => $letter_spacing_field_specified,
409
+                ],
410
+            ];
411
+
412
+            $this->generate_controls_group( $group, $args );
413
+        }
414
+
415
+        $margin_top_field_specified    = isset( $defaults['margin-top'] );
416
+        $margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
417
+
418
+        if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
419
+            $group = [
420
+                'margin-top'    => [
421
+                    'type'         => 'dimension',
422
+                    'label'        => esc_html__( 'Margin Top', 'kirki' ),
423
+                    'is_specified' => $margin_top_field_specified,
424
+                ],
425
+                'margin-bottom' => [
426
+                    'type'         => 'dimension',
427
+                    'label'        => esc_html__( 'Margin Bottom', 'kirki' ),
428
+                    'is_specified' => $margin_bottom_field_specified,
429
+                ],
430
+            ];
431
+
432
+            $this->generate_controls_group( $group, $args );
433
+        }
434
+
435
+    }
436
+
437
+    /**
438
+     * Generate controls group.
439
+     *
440
+     * @param array $group The group data.
441
+     * @param array $args The field args.
442
+     */
443
+    public function generate_controls_group( $group, $args ) {
444
+
445
+        $total_specified = 0;
446
+        $field_width     = 100;
447
+
448
+        foreach ( $group as $css_prop => $control ) {
449
+            if ( $control['is_specified'] ) {
450
+                $total_specified++;
451
+            }
452
+        }
453
+
454
+        if ( $total_specified > 1 ) {
455
+            $field_width = floor( 100 / $total_specified );
456
+        }
457
+
458
+        $group_count = 0;
459
+
460
+        foreach ( $group as $css_prop => $control ) {
461
+            if ( $control['is_specified'] ) {
462
+                $group_count++;
463
+
464
+                $group_classname  = 'kirki-group-item';
465
+                $group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
466
+
467
+                $control_class = str_ireplace( '-', ' ', $control['type'] );
468
+                $control_class = ucwords( $control_class );
469
+                $control_class = str_replace( ' ', '', $control_class );
470
+                $control_class = '\\Kirki\\Field\\' . $control_class;
471
+
472
+                new $control_class(
473
+                    wp_parse_args(
474
+                        [
475
+                            'label'         => isset( $control['label'] ) ? $control['label'] : '',
476
+                            'description'   => isset( $control['description'] ) ? $control['description'] : '',
477
+                            'settings'      => $args['settings'] . '[' . $css_prop . ']',
478
+                            'default'       => $args['default'][ $css_prop ],
479
+                            'wrapper_attrs' => wp_parse_args(
480
+                                [
481
+                                    'data-kirki-typography-css-prop' => $css_prop,
482
+                                    'kirki-typography-subcontrol-type' => $css_prop,
483
+                                    'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
484
+                                ],
485
+                                $args['wrapper_attrs']
486
+                            ),
487
+                            'input_attrs'   => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
488
+                            'choices'       => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
489
+                            'css_vars'      => [],
490
+                            'output'        => [],
491
+                        ],
492
+                        $args
493
+                    )
494
+                );
495
+
496
+            }
497
+        }
498
+
499
+    }
500
+
501
+    /**
502
+     * Sanitizes typography controls
503
+     *
504
+     * @static
505
+     * @since 1.0
506
+     * @param array $value The value.
507
+     * @return array
508
+     */
509
+    public static function sanitize( $value ) {
510
+
511
+        if ( ! is_array( $value ) ) {
512
+            return [];
513
+        }
514
+
515
+        foreach ( $value as $key => $val ) {
516
+            switch ( $key ) {
517
+                case 'font-family':
518
+                    $value['font-family'] = sanitize_text_field( $val );
519
+                    break;
520
+
521
+                case 'variant':
522
+                    // Use 'regular' instead of 400 for font-variant.
523
+                    $value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
524
+
525
+                    // Get font-weight from variant.
526
+                    $value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
527
+                    $value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
528
+
529
+                    // Get font-style from variant.
530
+                    if ( ! isset( $value['font-style'] ) ) {
531
+                        $value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
532
+                    }
533
+
534
+                    break;
535
+
536
+                case 'text-align':
537
+                    if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
538
+                        $value['text-align'] = '';
539
+                    }
540
+
541
+                    break;
542
+
543
+                case 'text-transform':
544
+                    if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
545
+                        $value['text-transform'] = '';
546
+                    }
547
+
548
+                    break;
549
+
550
+                case 'text-decoration':
551
+                    if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
552
+                        $value['text-transform'] = '';
553
+                    }
554
+
555
+                    break;
556
+
557
+                case 'color':
558
+                    $value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
559
+                    break;
560
+
561
+                default:
562
+                    $value[ $key ] = sanitize_text_field( $value[ $key ] );
563
+            }
564
+        }
565
+
566
+        return $value;
567
+
568
+    }
569
+
570
+    /**
571
+     * Enqueue scripts & styles.
572
+     *
573
+     * @access public
574
+     * @since 1.0
575
+     * @return void
576
+     */
577
+    public function enqueue_control_scripts() {
578
+
579
+        wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
580
+
581
+        wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
582
+
583
+        wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
584
+
585
+        $args = $this->args;
586
+
587
+        $variants = [];
588
+
589
+        // Add custom variants (for custom fonts) to the $variants.
590
+        if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
591
+
592
+            // If $args['choices']['fonts']['families'] exists, then loop it.
593
+            foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
594
+
595
+                // Then loop the $font_family_value['children].
596
+                foreach ( $font_family_value['children'] as $font_family ) {
597
+
598
+                    // Then check if $font_family['id'] exists in variants argument.
599
+                    if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
600
+
601
+                        // Create new array if $variants[ $font_family['id'] ] doesn't exist.
602
+                        if ( ! isset( $variants[ $font_family['id'] ] ) ) {
603
+                            $variants[ $font_family['id'] ] = [];
604
+                        }
605
+
606
+                        // The $custom_variant here can be something like "400italic" or "italic".
607
+                        foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
608
+
609
+                            // Check if $custom_variant exists in self::$complete_variant_labels.
610
+                            if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
611
+
612
+                                // If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
613
+                                array_push(
614
+                                    $variants[ $font_family['id'] ],
615
+                                    [
616
+                                        'value' => $custom_variant,
617
+                                        'label' => self::$complete_variant_labels[ $custom_variant ],
618
+                                    ]
619
+                                );
620
+
621
+                            } // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
622
+                        } // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
623
+                    }
624
+                } // End of $font_family_value['children'] foreach.
625
+            } // End of $args['choices']['fonts']['families'] foreach.
626
+        } // End of $args['choices']['fonts']['families'] if.
627
+
628
+        if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
629
+            $standard_fonts = Fonts::get_standard_fonts();
630
+
631
+            foreach ( $standard_fonts as $font ) {
632
+                if ( isset( $font['variants'] ) ) {
633
+
634
+                    // Create new array if $variants[ $font['stack'] ] doesn't exist.
635
+                    if ( ! isset( $variants[ $font['stack'] ] ) ) {
636
+                        $variants[ $font['stack'] ] = [];
637
+                    }
638
+
639
+                    // The $std_variant here can be something like "400italic" or "italic".
640
+                    foreach ( $font['variants'] as $std_variant ) {
641
+
642
+                        // Check if $std_variant exists in self::$complete_variant_labels.
643
+                        if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
644
+
645
+                            // If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
646
+                            array_push(
647
+                                $variants[ $font['stack'] ],
648
+                                [
649
+                                    'value' => $std_variant,
650
+                                    'label' => self::$complete_variant_labels[ $std_variant ],
651
+                                ]
652
+                            );
653
+
654
+                        } // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
655
+                    } // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
656
+                }
657
+            }
658
+        } elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
659
+            foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
660
+                $key = ( is_int( $key ) ) ? $val : $key;
661
+
662
+                if ( isset( $val['variants'] ) ) {
663
+
664
+                    // Create new array if $variants[ $font['stack'] ] doesn't exist.
665
+                    if ( ! isset( $variants[ $key ] ) ) {
666
+                        $variants[ $key ] = [];
667
+                    }
668
+
669
+                    // The $std_variant here can be something like "400italic" or "italic".
670
+                    foreach ( $val['variants'] as $std_variant ) {
671
+
672
+                        // Check if $std_variant exists in self::$complete_variant_labels.
673
+                        if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
674
+
675
+                            // If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
676
+                            array_push(
677
+                                $variants[ $key ],
678
+                                [
679
+                                    'value' => $std_variant,
680
+                                    'label' => self::$complete_variant_labels[ $std_variant ],
681
+                                ]
682
+                            );
683
+
684
+                        } // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
685
+                    } // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
686
+                }
687
+            }
688
+        }
689
+
690
+        // Scripts inside this block will only be executed once.
691
+        if ( ! self::$fonts_var_added ) {
692
+            wp_localize_script(
693
+                'kirki-control-typography',
694
+                'kirkiFontVariants',
695
+                [
696
+                    'standard' => self::$std_variants,
697
+                    'complete' => self::$complete_variants,
698
+                ]
699
+            );
700
+
701
+            $google = new GoogleFonts();
702
+
703
+            wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
704
+            wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
705
+
706
+            self::$fonts_var_added = true;
707
+        }
708
+
709
+        // This custom variants will be available for each typography control.
710
+        $custom_variant_key   = str_ireplace( ']', '', $args['settings'] );
711
+        $custom_variant_key   = str_ireplace( '[', '_', $custom_variant_key );
712
+        $custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
713
+
714
+        wp_add_inline_script(
715
+            'kirki-control-typography',
716
+            'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
717
+            $variants
718
+        );
719
+
720
+    }
721
+
722
+    /**
723
+     * Enqueue scripts for customize_preview_init.
724
+     *
725
+     * @access public
726
+     * @since 1.0
727
+     * @return void
728
+     */
729
+    public function enqueue_preview_scripts() {
730
+
731
+        wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
732
+
733
+        if ( ! self::$preview_var_added ) {
734
+            $google = new GoogleFonts();
735
+
736
+            wp_localize_script(
737
+                'kirki-preview-typography',
738
+                'kirkiGoogleFontNames',
739
+                $google->get_google_font_names()
740
+            );
741
+
742
+            self::$preview_var_added = true;
743
+        }
744
+
745
+    }
746
+
747
+    /**
748
+     * Prefer control specific value over field value
749
+     *
750
+     * @access public
751
+     * @since 4.0
752
+     * @param $setting
753
+     * @param $choice
754
+     * @param $args
755
+     *
756
+     * @return string
757
+     */
758
+    public function filter_preferred_choice_setting( $setting, $choice, $args ) {
759
+
760
+        // Fail early.
761
+        if ( ! isset( $args[ $setting ] ) ) {
762
+            return '';
763
+        }
764
+
765
+        // If a specific field for the choice is set
766
+        if ( isset( $args[ $setting ][ $choice ] ) ) {
767
+            return $args[ $setting ][ $choice ];
768
+        }
769
+
770
+        // Unset input_attrs of all other choices.
771
+        foreach ( $args['choices'] as $id => $set ) {
772
+            if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
773
+                unset( $args[ $setting ][ $id ] );
774
+            } elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
775
+                $args[ $setting ] = '';
776
+            }
777
+        }
778
+
779
+        return $args[ $setting ];
780
+
781
+    }
782
+
783
+    /**
784
+     * Populate the font family choices.
785
+     *
786
+     * It's separated from the `add_sub_field` function to prevent a bug
787
+     * when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
788
+     *
789
+     * When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
790
+     * But if it's hooked after field registration, then the function won't be available.
791
+     *
792
+     * @access private
793
+     * @since 1.0.1
794
+     *
795
+     * @return array
796
+     */
797
+    private function get_font_family_choices() {
798
+
799
+        $args = $this->args;
800
+
801
+        // Figure out how to sort the fonts.
802
+        $sorting   = 'alpha';
803
+        $max_fonts = 9999;
804
+        $google    = new GoogleFonts();
805
+
806
+        if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
807
+            if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
808
+                $sorting = $args['choices']['fonts']['google'][0];
809
+
810
+                if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
811
+                    $max_fonts = (int) $args['choices']['fonts']['google'][1];
812
+                }
813
+
814
+                $g_fonts = $google->get_google_fonts_by_args(
815
+                    [
816
+                        'sort'  => $sorting,
817
+                        'count' => $max_fonts,
818
+                    ]
819
+                );
820
+            } else {
821
+                $g_fonts = $args['choices']['fonts']['google'];
822
+            }
823
+        } else {
824
+            $g_fonts = $google->get_google_fonts_by_args(
825
+                [
826
+                    'sort'  => $sorting,
827
+                    'count' => $max_fonts,
828
+                ]
829
+            );
830
+        }
831
+
832
+        $std_fonts = [];
833
+
834
+        if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
835
+            $standard_fonts = Fonts::get_standard_fonts();
836
+
837
+            foreach ( $standard_fonts as $font ) {
838
+                $std_fonts[ $font['stack'] ] = $font['label'];
839
+            }
840
+        } elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
841
+            foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
842
+                $key               = ( \is_int( $key ) ) ? $val : $key;
843
+                $std_fonts[ $key ] = $val;
844
+            }
845
+        }
846
+
847
+        $choices = [];
848
+
849
+        $choices['default'] = [
850
+            esc_html__( 'Defaults', 'kirki' ),
851
+            [
852
+                '' => esc_html__( 'Default', 'kirki' ),
853
+            ],
854
+        ];
855
+
856
+        if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
857
+            // Implementing the custom font families.
858
+            foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
859
+                if ( ! isset( $choices[ $font_family_key ] ) ) {
860
+                    $choices[ $font_family_key ] = [];
861
+                }
862
+
863
+                $family_opts = [];
864
+
865
+                foreach ( $font_family_value['children'] as $font_family ) {
866
+                    $family_opts[ $font_family['id'] ] = $font_family['text'];
867
+                }
868
+
869
+                $choices[ $font_family_key ] = [
870
+                    $font_family_value['text'],
871
+                    $family_opts,
872
+                ];
873
+            }
874
+        }
875
+
876
+        $choices['standard'] = [
877
+            esc_html__( 'Standard Fonts', 'kirki' ),
878
+            $std_fonts,
879
+        ];
880
+
881
+        $choices['google'] = [
882
+            esc_html__( 'Google Fonts', 'kirki' ),
883
+            array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
884
+        ];
885
+
886
+        if ( empty( $choices['standard'][1] ) ) {
887
+            $choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
888
+        } elseif ( empty( $choices['google'][1] ) ) {
889
+            $choices = $std_fonts;
890
+        }
891
+
892
+        return $choices;
893
+
894
+    }
895
+
896
+    /**
897
+     * Get custom variant choices (for custom fonts).
898
+     *
899
+     * It's separated from the `add_sub_field` function to prevent a bug
900
+     * when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
901
+     *
902
+     * When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
903
+     * But if it's hooked after field registration, then the function won't be available.
904
+     *
905
+     * @access private
906
+     * @since 1.0.2
907
+     *
908
+     * @return array
909
+     */
910
+    private function get_variant_choices() {
911
+
912
+        $args = $this->args;
913
+
914
+        $choices = self::$std_variants;
915
+
916
+        // Implementing the custom variants for custom fonts.
917
+        if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
918
+
919
+            $choices = [];
920
+
921
+            // If $args['choices']['fonts']['families'] exists, then loop it.
922
+            foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
923
+
924
+                // Then loop the $font_family_value['children].
925
+                foreach ( $font_family_value['children'] as $font_family ) {
926
+
927
+                    // Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
928
+                    if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
929
+
930
+                        // The $custom_variant here can be something like "400italic" or "italic".
931
+                        foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
932
+
933
+                            // Check if $custom_variant exists in self::$complete_variant_labels.
934
+                            if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
935
+
936
+                                // If it exists, assign it to $choices.
937
+                                array_push(
938
+                                    $choices,
939
+                                    [
940
+                                        'value' => $custom_variant,
941
+                                        'label' => self::$complete_variant_labels[ $custom_variant ],
942
+                                    ]
943
+                                );
944
+
945
+                            } // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
946
+                        } // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
947
+                    }
948
+                } // End of $font_family_value['children'] foreach.
949
+            } // End of $args['choices']['fonts']['families'] foreach.
950
+        } // End of $args['choices']['fonts']['families'] if.
951
+
952
+        return $choices;
953
+
954
+    }
955
+
956
+    /**
957
+     * Filter arguments before creating the control.
958
+     *
959
+     * @access public
960
+     * @since 0.1
961
+     * @param array                $args         The field arguments.
962
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
963
+     * @return array
964
+     */
965
+    public function filter_control_args( $args, $wp_customize ) {
966
+
967
+        if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
968
+            $args            = parent::filter_control_args( $args, $wp_customize );
969
+            $args['choices'] = $this->get_font_family_choices();
970
+        }
971
+
972
+        if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
973
+            $args            = parent::filter_control_args( $args, $wp_customize );
974
+            $args['choices'] = $this->get_variant_choices();
975
+        }
976
+
977
+        return $args;
978
+
979
+    }
980
+
981
+    /**
982
+     * Adds a custom output class for typography fields.
983
+     *
984
+     * @access public
985
+     * @since 1.0
986
+     * @param array $classnames The array of classnames.
987
+     * @return array
988
+     */
989
+    public function output_control_classnames( $classnames ) {
990
+
991
+        $classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
992
+        return $classnames;
993
+
994
+    }
995
+
996
+    /**
997
+     * Override parent method. No need to register any setting.
998
+     *
999
+     * @access public
1000
+     * @since 0.1
1001
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
1002
+     * @return void
1003
+     */
1004
+    public function add_setting( $wp_customize ) {}
1005
+
1006
+    /**
1007
+     * Override the parent method. No need for a control.
1008
+     *
1009
+     * @access public
1010
+     * @since 0.1
1011
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
1012
+     * @return void
1013
+     */
1014
+    public function add_control( $wp_customize ) {}
1015 1015
 
1016 1016
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-radio/src/Field/Radio_Buttonset.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -17,38 +17,38 @@
 block discarded – undo
17 17
  */
18 18
 class Radio_Buttonset extends Radio {
19 19
 
20
-	/**
21
-	 * The field type.
22
-	 *
23
-	 * @access public
24
-	 * @since 1.0
25
-	 * @var string
26
-	 */
27
-	public $type = 'kirki-radio-buttonset';
20
+    /**
21
+     * The field type.
22
+     *
23
+     * @access public
24
+     * @since 1.0
25
+     * @var string
26
+     */
27
+    public $type = 'kirki-radio-buttonset';
28 28
 
29
-	/**
30
-	 * The control class-name.
31
-	 *
32
-	 * @access protected
33
-	 * @since 0.1
34
-	 * @var string
35
-	 */
36
-	protected $control_class = '\Kirki\Control\Radio_Buttonset';
29
+    /**
30
+     * The control class-name.
31
+     *
32
+     * @access protected
33
+     * @since 0.1
34
+     * @var string
35
+     */
36
+    protected $control_class = '\Kirki\Control\Radio_Buttonset';
37 37
 
38
-	/**
39
-	 * Filter arguments before creating the control.
40
-	 *
41
-	 * @access public
42
-	 * @since 0.1
43
-	 * @param array                $args         The field arguments.
44
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
45
-	 * @return array
46
-	 */
47
-	public function filter_control_args( $args, $wp_customize ) {
48
-		if ( $args['settings'] === $this->args['settings'] ) {
49
-			$args         = parent::filter_control_args( $args, $wp_customize );
50
-			$args['type'] = 'kirki-radio-buttonset';
51
-		}
52
-		return $args;
53
-	}
38
+    /**
39
+     * Filter arguments before creating the control.
40
+     *
41
+     * @access public
42
+     * @since 0.1
43
+     * @param array                $args         The field arguments.
44
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
45
+     * @return array
46
+     */
47
+    public function filter_control_args( $args, $wp_customize ) {
48
+        if ( $args['settings'] === $this->args['settings'] ) {
49
+            $args         = parent::filter_control_args( $args, $wp_customize );
50
+            $args['type'] = 'kirki-radio-buttonset';
51
+        }
52
+        return $args;
53
+    }
54 54
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-radio/src/Field/Radio_Image.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -17,38 +17,38 @@
 block discarded – undo
17 17
  */
18 18
 class Radio_Image extends Radio {
19 19
 
20
-	/**
21
-	 * The field type.
22
-	 *
23
-	 * @access public
24
-	 * @since 1.0
25
-	 * @var string
26
-	 */
27
-	public $type = 'kirki-radio-image';
20
+    /**
21
+     * The field type.
22
+     *
23
+     * @access public
24
+     * @since 1.0
25
+     * @var string
26
+     */
27
+    public $type = 'kirki-radio-image';
28 28
 
29
-	/**
30
-	 * The control class-name.
31
-	 *
32
-	 * @access protected
33
-	 * @since 0.1
34
-	 * @var string
35
-	 */
36
-	protected $control_class = '\Kirki\Control\Radio_Image';
29
+    /**
30
+     * The control class-name.
31
+     *
32
+     * @access protected
33
+     * @since 0.1
34
+     * @var string
35
+     */
36
+    protected $control_class = '\Kirki\Control\Radio_Image';
37 37
 
38
-	/**
39
-	 * Filter arguments before creating the control.
40
-	 *
41
-	 * @access public
42
-	 * @since 0.1
43
-	 * @param array                $args         The field arguments.
44
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
45
-	 * @return array
46
-	 */
47
-	public function filter_control_args( $args, $wp_customize ) {
48
-		if ( $args['settings'] === $this->args['settings'] ) {
49
-			$args         = parent::filter_control_args( $args, $wp_customize );
50
-			$args['type'] = 'kirki-radio-image';
51
-		}
52
-		return $args;
53
-	}
38
+    /**
39
+     * Filter arguments before creating the control.
40
+     *
41
+     * @access public
42
+     * @since 0.1
43
+     * @param array                $args         The field arguments.
44
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
45
+     * @return array
46
+     */
47
+    public function filter_control_args( $args, $wp_customize ) {
48
+        if ( $args['settings'] === $this->args['settings'] ) {
49
+            $args         = parent::filter_control_args( $args, $wp_customize );
50
+            $args['type'] = 'kirki-radio-image';
51
+        }
52
+        return $args;
53
+    }
54 54
 }
Please login to merge, or discard this patch.
kirki-4.0.24/packages/kirki-framework/control-radio/src/Field/Radio.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -19,73 +19,73 @@
 block discarded – undo
19 19
  */
20 20
 class Radio extends Field {
21 21
 
22
-	/**
23
-	 * The field type.
24
-	 *
25
-	 * @access public
26
-	 * @since 1.0
27
-	 * @var string
28
-	 */
29
-	public $type = 'kirki-radio';
22
+    /**
23
+     * The field type.
24
+     *
25
+     * @access public
26
+     * @since 1.0
27
+     * @var string
28
+     */
29
+    public $type = 'kirki-radio';
30 30
 
31
-	/**
32
-	 * The control class-name.
33
-	 *
34
-	 * @access protected
35
-	 * @since 0.1
36
-	 * @var string
37
-	 */
38
-	protected $control_class = '\Kirki\Control\Radio';
31
+    /**
32
+     * The control class-name.
33
+     *
34
+     * @access protected
35
+     * @since 0.1
36
+     * @var string
37
+     */
38
+    protected $control_class = '\Kirki\Control\Radio';
39 39
 
40
-	/**
41
-	 * Whether we should register the control class for JS-templating or not.
42
-	 *
43
-	 * @access protected
44
-	 * @since 0.1
45
-	 * @var bool
46
-	 */
47
-	protected $control_has_js_template = true;
40
+    /**
41
+     * Whether we should register the control class for JS-templating or not.
42
+     *
43
+     * @access protected
44
+     * @since 0.1
45
+     * @var bool
46
+     */
47
+    protected $control_has_js_template = true;
48 48
 
49
-	/**
50
-	 * Filter arguments before creating the setting.
51
-	 *
52
-	 * @access public
53
-	 * @since 0.1
54
-	 * @param array                $args         The field arguments.
55
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
56
-	 * @return array
57
-	 */
58
-	public function filter_setting_args( $args, $wp_customize ) {
59
-		if ( $args['settings'] === $this->args['settings'] ) {
60
-			$args = parent::filter_setting_args( $args, $wp_customize );
49
+    /**
50
+     * Filter arguments before creating the setting.
51
+     *
52
+     * @access public
53
+     * @since 0.1
54
+     * @param array                $args         The field arguments.
55
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
56
+     * @return array
57
+     */
58
+    public function filter_setting_args( $args, $wp_customize ) {
59
+        if ( $args['settings'] === $this->args['settings'] ) {
60
+            $args = parent::filter_setting_args( $args, $wp_customize );
61 61
 
62
-			// Set the sanitize-callback if none is defined.
63
-			if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
64
-				$args['sanitize_callback'] = function( $value ) {
65
-					if ( ! isset( $this->args['choices'][ $value ] ) ) {
66
-						return ( isset( $this->args['default'] ) ) ? $this->args['default'] : '';
67
-					}
68
-					return $value;
69
-				};
70
-			}
71
-		}
72
-		return $args;
73
-	}
62
+            // Set the sanitize-callback if none is defined.
63
+            if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
64
+                $args['sanitize_callback'] = function( $value ) {
65
+                    if ( ! isset( $this->args['choices'][ $value ] ) ) {
66
+                        return ( isset( $this->args['default'] ) ) ? $this->args['default'] : '';
67
+                    }
68
+                    return $value;
69
+                };
70
+            }
71
+        }
72
+        return $args;
73
+    }
74 74
 
75
-	/**
76
-	 * Filter arguments before creating the control.
77
-	 *
78
-	 * @access public
79
-	 * @since 0.1
80
-	 * @param array                $args         The field arguments.
81
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
82
-	 * @return array
83
-	 */
84
-	public function filter_control_args( $args, $wp_customize ) {
85
-		if ( $args['settings'] === $this->args['settings'] ) {
86
-			$args         = parent::filter_control_args( $args, $wp_customize );
87
-			$args['type'] = 'kirki-radio';
88
-		}
89
-		return $args;
90
-	}
75
+    /**
76
+     * Filter arguments before creating the control.
77
+     *
78
+     * @access public
79
+     * @since 0.1
80
+     * @param array                $args         The field arguments.
81
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
82
+     * @return array
83
+     */
84
+    public function filter_control_args( $args, $wp_customize ) {
85
+        if ( $args['settings'] === $this->args['settings'] ) {
86
+            $args         = parent::filter_control_args( $args, $wp_customize );
87
+            $args['type'] = 'kirki-radio';
88
+        }
89
+        return $args;
90
+    }
91 91
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-radio/src/Control/Radio_Buttonset.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -21,46 +21,46 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Radio_Buttonset extends Base {
23 23
 
24
-	/**
25
-	 * The control type.
26
-	 *
27
-	 * @access public
28
-	 * @since 1.0
29
-	 * @var string
30
-	 */
31
-	public $type = 'kirki-radio-buttonset';
24
+    /**
25
+     * The control type.
26
+     *
27
+     * @access public
28
+     * @since 1.0
29
+     * @var string
30
+     */
31
+    public $type = 'kirki-radio-buttonset';
32 32
 
33
-	/**
34
-	 * Enqueue control related scripts/styles.
35
-	 *
36
-	 * @access public
37
-	 * @since 1.0
38
-	 * @return void
39
-	 */
40
-	public function enqueue() {
41
-		parent::enqueue();
33
+    /**
34
+     * Enqueue control related scripts/styles.
35
+     *
36
+     * @access public
37
+     * @since 1.0
38
+     * @return void
39
+     */
40
+    public function enqueue() {
41
+        parent::enqueue();
42 42
 
43
-		// Enqueue the script.
44
-		wp_enqueue_script( 'kirki-control-radio', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], Radio::$control_ver, false );
43
+        // Enqueue the script.
44
+        wp_enqueue_script( 'kirki-control-radio', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], Radio::$control_ver, false );
45 45
 
46
-		// Enqueue the style.
47
-		wp_enqueue_style( 'kirki-control-radio-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], Radio::$control_ver );
48
-	}
46
+        // Enqueue the style.
47
+        wp_enqueue_style( 'kirki-control-radio-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], Radio::$control_ver );
48
+    }
49 49
 
50
-	/**
51
-	 * An Underscore (JS) template for this control's content (but not its container).
52
-	 *
53
-	 * Class variables for this control class are available in the `data` JS object;
54
-	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
55
-	 *
56
-	 * @see WP_Customize_Control::print_template()
57
-	 *
58
-	 * @access protected
59
-	 * @since 1.0
60
-	 * @return void
61
-	 */
62
-	protected function content_template() {
63
-		?>
50
+    /**
51
+     * An Underscore (JS) template for this control's content (but not its container).
52
+     *
53
+     * Class variables for this control class are available in the `data` JS object;
54
+     * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
55
+     *
56
+     * @see WP_Customize_Control::print_template()
57
+     *
58
+     * @access protected
59
+     * @since 1.0
60
+     * @return void
61
+     */
62
+    protected function content_template() {
63
+        ?>
64 64
 		<# if ( data.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #>
65 65
 		<# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #>
66 66
 		<div id="input_{{ data.id }}" class="buttonset">
@@ -71,5 +71,5 @@  discard block
 block discarded – undo
71 71
 			<# } #>
72 72
 		</div>
73 73
 		<?php
74
-	}
74
+    }
75 75
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-radio/src/Control/Radio_Image.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 // Exit if accessed directly.
17 17
 if ( ! defined( 'ABSPATH' ) ) {
18
-	exit;
18
+    exit;
19 19
 }
20 20
 
21 21
 /**
@@ -23,63 +23,63 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class Radio_Image extends Base {
25 25
 
26
-	/**
27
-	 * The control type.
28
-	 *
29
-	 * @access public
30
-	 * @var string
31
-	 */
32
-	public $type = 'kirki-radio-image';
26
+    /**
27
+     * The control type.
28
+     *
29
+     * @access public
30
+     * @var string
31
+     */
32
+    public $type = 'kirki-radio-image';
33 33
 
34
-	/**
35
-	 * Enqueue control related scripts/styles.
36
-	 *
37
-	 * @access public
38
-	 */
39
-	public function enqueue() {
40
-		parent::enqueue();
34
+    /**
35
+     * Enqueue control related scripts/styles.
36
+     *
37
+     * @access public
38
+     */
39
+    public function enqueue() {
40
+        parent::enqueue();
41 41
 
42
-		// Enqueue the script.
43
-		wp_enqueue_script( 'kirki-control-radio', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], Radio::$control_ver, false );
42
+        // Enqueue the script.
43
+        wp_enqueue_script( 'kirki-control-radio', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], Radio::$control_ver, false );
44 44
 
45
-		// Enqueue the style.
46
-		wp_enqueue_style( 'kirki-control-radio-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], Radio::$control_ver );
47
-	}
45
+        // Enqueue the style.
46
+        wp_enqueue_style( 'kirki-control-radio-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], Radio::$control_ver );
47
+    }
48 48
 
49
-	/**
50
-	 * Refresh the parameters passed to the JavaScript via JSON.
51
-	 *
52
-	 * @see WP_Customize_Control::to_json()
53
-	 *
54
-	 * @access public
55
-	 * @since 1.0
56
-	 * @return void
57
-	 */
58
-	public function to_json() {
59
-		parent::to_json();
60
-		foreach ( $this->input_attrs as $attr => $value ) {
61
-			if ( 'style' !== $attr ) {
62
-				$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';
63
-				continue;
64
-			}
65
-			$this->json['labelStyle'] = 'style="' . esc_attr( $value ) . '" ';
66
-		}
67
-	}
49
+    /**
50
+     * Refresh the parameters passed to the JavaScript via JSON.
51
+     *
52
+     * @see WP_Customize_Control::to_json()
53
+     *
54
+     * @access public
55
+     * @since 1.0
56
+     * @return void
57
+     */
58
+    public function to_json() {
59
+        parent::to_json();
60
+        foreach ( $this->input_attrs as $attr => $value ) {
61
+            if ( 'style' !== $attr ) {
62
+                $this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';
63
+                continue;
64
+            }
65
+            $this->json['labelStyle'] = 'style="' . esc_attr( $value ) . '" ';
66
+        }
67
+    }
68 68
 
69
-	/**
70
-	 * An Underscore (JS) template for this control's content (but not its container).
71
-	 *
72
-	 * Class variables for this control class are available in the `data` JS object;
73
-	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
74
-	 *
75
-	 * @see WP_Customize_Control::print_template()
76
-	 *
77
-	 * @access protected
78
-	 * @since 1.0
79
-	 * @return void
80
-	 */
81
-	protected function content_template() {
82
-		?>
69
+    /**
70
+     * An Underscore (JS) template for this control's content (but not its container).
71
+     *
72
+     * Class variables for this control class are available in the `data` JS object;
73
+     * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
74
+     *
75
+     * @see WP_Customize_Control::print_template()
76
+     *
77
+     * @access protected
78
+     * @since 1.0
79
+     * @return void
80
+     */
81
+    protected function content_template() {
82
+        ?>
83 83
 		<label class="customizer-text">
84 84
 			<# if ( data.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #>
85 85
 			<# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #>
@@ -101,5 +101,5 @@  discard block
 block discarded – undo
101 101
 			<# } #>
102 102
 		</div>
103 103
 		<?php
104
-	}
104
+    }
105 105
 }
Please login to merge, or discard this patch.
kirki-4.0.24/packages/kirki-framework/control-radio/src/Control/Radio.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 // Exit if accessed directly.
17 17
 if ( ! defined( 'ABSPATH' ) ) {
18
-	exit;
18
+    exit;
19 19
 }
20 20
 
21 21
 /**
@@ -23,53 +23,53 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class Radio extends Base {
25 25
 
26
-	/**
27
-	 * The control type.
28
-	 *
29
-	 * @access public
30
-	 * @var string
31
-	 */
32
-	public $type = 'kirki-radio';
26
+    /**
27
+     * The control type.
28
+     *
29
+     * @access public
30
+     * @var string
31
+     */
32
+    public $type = 'kirki-radio';
33 33
 
34
-	/**
35
-	 * The version. Used in scripts & styles for cache-busting.
36
-	 *
37
-	 * @static
38
-	 * @access public
39
-	 * @since 1.0
40
-	 * @var string
41
-	 */
42
-	public static $control_ver = '1.1';
34
+    /**
35
+     * The version. Used in scripts & styles for cache-busting.
36
+     *
37
+     * @static
38
+     * @access public
39
+     * @since 1.0
40
+     * @var string
41
+     */
42
+    public static $control_ver = '1.1';
43 43
 
44
-	/**
45
-	 * Enqueue control related scripts/styles.
46
-	 *
47
-	 * @access public
48
-	 */
49
-	public function enqueue() {
50
-		parent::enqueue();
44
+    /**
45
+     * Enqueue control related scripts/styles.
46
+     *
47
+     * @access public
48
+     */
49
+    public function enqueue() {
50
+        parent::enqueue();
51 51
 
52
-		// Enqueue the script.
53
-		wp_enqueue_script( 'kirki-control-radio', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false );
52
+        // Enqueue the script.
53
+        wp_enqueue_script( 'kirki-control-radio', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false );
54 54
 
55
-		// Enqueue the style.
56
-		wp_enqueue_style( 'kirki-control-radio-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver );
57
-	}
55
+        // Enqueue the style.
56
+        wp_enqueue_style( 'kirki-control-radio-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver );
57
+    }
58 58
 
59
-	/**
60
-	 * An Underscore (JS) template for this control's content (but not its container).
61
-	 *
62
-	 * Class variables for this control class are available in the `data` JS object;
63
-	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
64
-	 *
65
-	 * @see WP_Customize_Control::print_template()
66
-	 *
67
-	 * @access protected
68
-	 * @since 1.1
69
-	 * @return void
70
-	 */
71
-	protected function content_template() {
72
-		?>
59
+    /**
60
+     * An Underscore (JS) template for this control's content (but not its container).
61
+     *
62
+     * Class variables for this control class are available in the `data` JS object;
63
+     * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
64
+     *
65
+     * @see WP_Customize_Control::print_template()
66
+     *
67
+     * @access protected
68
+     * @since 1.1
69
+     * @return void
70
+     */
71
+    protected function content_template() {
72
+        ?>
73 73
 		<span class="customize-control-title">{{{ data.label }}}</span>
74 74
 		<# if ( data.description ) { #>
75 75
 			<span class="description customize-control-description">{{{ data.description }}}</span>
@@ -93,5 +93,5 @@  discard block
 block discarded – undo
93 93
 			</label>
94 94
 		<# } ); #>
95 95
 		<?php
96
-	}
96
+    }
97 97
 }
Please login to merge, or discard this patch.
kirki-4.0.24/packages/kirki-framework/control-palette/src/Field/Palette.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -17,38 +17,38 @@
 block discarded – undo
17 17
  */
18 18
 class Palette extends Radio {
19 19
 
20
-	/**
21
-	 * The field type.
22
-	 *
23
-	 * @access public
24
-	 * @since 1.0
25
-	 * @var string
26
-	 */
27
-	public $type = 'kirki-palette';
20
+    /**
21
+     * The field type.
22
+     *
23
+     * @access public
24
+     * @since 1.0
25
+     * @var string
26
+     */
27
+    public $type = 'kirki-palette';
28 28
 
29
-	/**
30
-	 * The control class-name.
31
-	 *
32
-	 * @access protected
33
-	 * @since 0.1
34
-	 * @var string
35
-	 */
36
-	protected $control_class = '\Kirki\Control\Palette';
29
+    /**
30
+     * The control class-name.
31
+     *
32
+     * @access protected
33
+     * @since 0.1
34
+     * @var string
35
+     */
36
+    protected $control_class = '\Kirki\Control\Palette';
37 37
 
38
-	/**
39
-	 * Filter arguments before creating the control.
40
-	 *
41
-	 * @access public
42
-	 * @since 0.1
43
-	 * @param array                $args         The field arguments.
44
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
45
-	 * @return array
46
-	 */
47
-	public function filter_control_args( $args, $wp_customize ) {
48
-		if ( $args['settings'] === $this->args['settings'] ) {
49
-			$args         = parent::filter_control_args( $args, $wp_customize );
50
-			$args['type'] = 'kirki-palette';
51
-		}
52
-		return $args;
53
-	}
38
+    /**
39
+     * Filter arguments before creating the control.
40
+     *
41
+     * @access public
42
+     * @since 0.1
43
+     * @param array                $args         The field arguments.
44
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
45
+     * @return array
46
+     */
47
+    public function filter_control_args( $args, $wp_customize ) {
48
+        if ( $args['settings'] === $this->args['settings'] ) {
49
+            $args         = parent::filter_control_args( $args, $wp_customize );
50
+            $args['type'] = 'kirki-palette';
51
+        }
52
+        return $args;
53
+    }
54 54
 }
Please login to merge, or discard this patch.