|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Kirki_GoogleFonts_Field_Processor extends Kirki_Fonts { |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* The one true instance of this object |
|
7
|
|
|
*/ |
|
8
|
|
|
private static $instance = null; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* iterate all our fields and find the ones that need are typography-related. |
|
12
|
|
|
* Typography fields will be processed |
|
13
|
|
|
* and call the Kirki_GoogleFonts_Manager class to add their fonts. |
|
14
|
|
|
* Other typography fields will add their values globally |
|
15
|
|
|
* to the Kirki_GoogleFonts_Manager class. |
|
16
|
|
|
* |
|
17
|
|
|
* @return void |
|
18
|
|
|
*/ |
|
19
|
|
|
public static function generate_google_fonts( $field ) { |
|
20
|
|
|
/** |
|
21
|
|
|
* Process typography fields |
|
22
|
|
|
*/ |
|
23
|
|
|
if ( isset( $field['type'] ) && 'typography' == $field['type'] ) { |
|
24
|
|
|
// Get the value |
|
25
|
|
|
$value = Kirki_Values::get_sanitized_field_value( $field ); |
|
26
|
|
|
// If we don't have a font-family then we can skip this. |
|
27
|
|
|
if ( ! isset( $value['font-family'] ) ) { |
|
28
|
|
|
return; |
|
29
|
|
|
} |
|
30
|
|
|
// Set a default value for font-weight |
|
31
|
|
|
if ( ! isset( $value['font-weight'] ) ) { |
|
32
|
|
|
$value['font-weight'] = 400; |
|
33
|
|
|
} |
|
34
|
|
|
if ( isset( $value['subset'] ) ) { |
|
35
|
|
|
// Add the subset directly to the array of subsets |
|
36
|
|
|
// in the Kirki_GoogleFonts_Manager object. |
|
37
|
|
|
if ( ! is_array( $value['subset'] ) ) { |
|
38
|
|
|
Kirki_GoogleFonts_Manager::$subsets[] = $value['subset']; |
|
39
|
|
|
} else { |
|
40
|
|
|
foreach ( $value['subset'] as $subset ) { |
|
41
|
|
|
Kirki_GoogleFonts_Manager::$subsets[] = $subset; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
// Get the font-style |
|
46
|
|
|
if ( ! isset( $value['font-style'] ) ) { |
|
47
|
|
|
$value['font-style'] = 'regular'; |
|
48
|
|
|
} |
|
49
|
|
|
// Add the requested google-font |
|
50
|
|
|
Kirki_GoogleFonts_Manager::add_font( $value['font-family'], $value['font-weight'], $value['font-style'] ); |
|
51
|
|
|
// Add font-weight 700 so that bold works for all fonts |
|
52
|
|
|
Kirki_GoogleFonts_Manager::add_font( $value['font-family'], 700, $value['font-style'] ); |
|
53
|
|
|
// Any additional font-weights we may need |
|
54
|
|
|
foreach ( Kirki_GoogleFonts_Manager::$font_weights as $font_weight ) { |
|
55
|
|
|
Kirki_GoogleFonts_Manager::add_font( $value['font-family'], 700, $value['font-style'] ); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Process non-typography fields |
|
61
|
|
|
*/ |
|
62
|
|
|
else { |
|
63
|
|
|
if ( isset( $field['output'] ) && is_array( $field['output'] ) ) { |
|
64
|
|
|
foreach ( $field['output'] as $output ) { |
|
65
|
|
|
// If we don't have a typography-related output argument we can skip this. |
|
66
|
|
|
if ( ! isset( $output['property'] ) || ! in_array( $output['property'], array( 'font-family', 'font-weight', 'font-subset', 'subset', 'font-style' ) ) ) { |
|
|
|
|
|
|
67
|
|
|
continue; |
|
68
|
|
|
} |
|
69
|
|
|
// Get the value |
|
70
|
|
|
$value = Kirki_Values::get_sanitized_field_value( $field ); |
|
71
|
|
|
|
|
72
|
|
|
// font-family |
|
73
|
|
|
if ( 'font-family' == $output['property'] ) { |
|
74
|
|
|
Kirki_GoogleFonts_Manager::add_font( $value ); |
|
75
|
|
|
} |
|
76
|
|
|
// font-weight |
|
77
|
|
|
elseif ( 'font-weight' == $output['property'] ) { |
|
78
|
|
|
Kirki_GoogleFonts_Manager::$font_weights[] = $value; |
|
79
|
|
|
} |
|
80
|
|
|
// subsets |
|
81
|
|
|
elseif ( 'font-subset' == $output['property'] || 'subset' == $output['property'] ) { |
|
82
|
|
|
if ( ! is_array( $value ) ) { |
|
83
|
|
|
Kirki_GoogleFonts_Manager::$subsets[] = $value; |
|
84
|
|
|
} else { |
|
85
|
|
|
foreach ( $value as $subset ) { |
|
86
|
|
|
Kirki_GoogleFonts_Manager::$subsets[] = $subset; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|