-
Notifications
You must be signed in to change notification settings - Fork 330
/
Copy pathclass-kirki-output-field-typography.php
69 lines (62 loc) · 2.17 KB
/
class-kirki-output-field-typography.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Handles CSS output for typography fields.
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license http://opensource.org/licenses/https://opensource.org/licenses/MIT
* @since 2.2.0
*/
/**
* Output overrides.
*/
class Kirki_Output_Field_Typography extends Kirki_Output {
/**
* Processes a single item from the `output` array.
*
* @access protected
* @param array $output The `output` item.
* @param array $value The field's value.
*/
protected function process_output( $output, $value ) {
$output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
$output['element'] = ( isset( $output['element'] ) ) ? $output['element'] : 'body';
$output['prefix'] = ( isset( $output['prefix'] ) ) ? $output['prefix'] : '';
$output['suffix'] = ( isset( $output['suffix'] ) ) ? $output['suffix'] : '';
if ( ! isset( $value['variant'] ) || ! isset( $value['font-weight'] ) || ! isset( $value['font-style'] ) ) {
$value = Kirki_Field_Typography::sanitize( $value );
$this->value = $value;
}
$properties = array(
'font-family',
'font-size',
'font-weight',
'font-style',
'letter-spacing',
'word-spacing',
'line-height',
'text-align',
'text-transform',
'color',
);
foreach ( $properties as $property ) {
if ( ! isset( $value[ $property ] ) || '' === $value[ $property ] ) {
continue;
}
if ( isset( $output['choice'] ) && $output['choice'] !== $property ) {
continue;
}
$property_value = $this->process_property_value( $property, $value[ $property ] );
if ( 'font-family' === $property ) {
$value['font-backup'] = ( isset( $value['font-backup'] ) ) ? $value['font-backup'] : '';
$property_value = $this->process_property_value( $property, array(
$value['font-family'],
$value['font-backup'],
) );
}
$property_value = ( is_array( $property_value ) && isset( $property_value[0] ) ) ? $property_value[0] : $property_value;
$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $property_value . $output['suffix'];
}
}
}