PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / customizer / packages / fields / typography / src / Field / CSS / Typography.php
kirki / customizer / packages / fields / typography / src / Field / CSS Last commit date
Typography.php 5 months ago
Typography.php
96 lines
1 <?php
2 /**
3 * Handles CSS output for typography fields.
4 *
5 * @package Kirki
6 * @subpackage Controls
7 * @copyright Copyright (c) 2023, Themeum
8 * @license https://opensource.org/licenses/MIT
9 * @since 2.2.0
10 */
11
12 namespace Kirki\Field\CSS;
13
14 use Kirki\Module\CSS\Output;
15
16 /**
17 * Output overrides.
18 */
19 class Typography extends Output {
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 }
95 }
96