1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Adds the Webfont Loader to load fonts asyncronously. |
4
|
|
|
* |
5
|
|
|
* @package Kirki |
6
|
|
|
* @category Core |
7
|
|
|
* @author Aristeides Stathopoulos |
8
|
|
|
* @copyright Copyright (c) 2017, Aristeides Stathopoulos |
9
|
|
|
* @license http://opensource.org/licenses/https://opensource.org/licenses/MIT |
10
|
|
|
* @since 3.0 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Manages the way Google Fonts are enqueued. |
15
|
|
|
*/ |
16
|
|
|
final class Kirki_Modules_Webfonts_Async { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The config ID. |
20
|
|
|
* |
21
|
|
|
* @access protected |
22
|
|
|
* @since 3.0.0 |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $config_id; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The Kirki_Modules_Webfonts object. |
29
|
|
|
* |
30
|
|
|
* @access protected |
31
|
|
|
* @since 3.0.0 |
32
|
|
|
* @var object |
33
|
|
|
*/ |
34
|
|
|
protected $webfonts; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The Kirki_Fonts_Google object. |
38
|
|
|
* |
39
|
|
|
* @access protected |
40
|
|
|
* @since 3.0.0 |
41
|
|
|
* @var object |
42
|
|
|
*/ |
43
|
|
|
protected $googlefonts; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Constructor. |
47
|
|
|
* |
48
|
|
|
* @access public |
49
|
|
|
* @since 3.0 |
50
|
|
|
*/ |
51
|
|
|
public function __construct( $config_id, $webfonts, $googlefonts, $args = array() ) { |
|
|
|
|
52
|
|
|
|
53
|
|
|
$this->config_id = $config_id; |
54
|
|
|
$this->webfonts = $webfonts; |
55
|
|
|
$this->googlefonts = $googlefonts; |
56
|
|
|
|
57
|
|
|
add_action( 'wp_head', array( $this, 'webfont_loader' ) ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Webfont Loader for Google Fonts. |
62
|
|
|
* |
63
|
|
|
* @access public |
64
|
|
|
* @since 3.0.0 |
65
|
|
|
*/ |
66
|
|
|
public function webfont_loader() { |
67
|
|
|
|
68
|
|
|
// Go through our fields and populate $this->fonts. |
69
|
|
|
$this->webfonts->loop_fields(); |
70
|
|
|
|
71
|
|
|
$this->googlefonts->fonts = apply_filters( 'kirki/enqueue_google_fonts', $this->googlefonts->fonts ); |
72
|
|
|
|
73
|
|
|
// Goes through $this->fonts and adds or removes things as needed. |
74
|
|
|
$this->googlefonts->process_fonts(); |
75
|
|
|
|
76
|
|
|
$fonts_to_load = array(); |
77
|
|
|
foreach ( $this->googlefonts->fonts as $font => $weights ) { |
78
|
|
|
$fonts_to_load[] = esc_attr( $font ) . ':' . esc_attr( join( ',', $weights ) ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
?> |
82
|
|
|
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script> |
|
|
|
|
83
|
|
|
<script id="kirki-webfont-loader"> |
84
|
|
|
window.kirkiWebontsLoaderFonts = '<?php echo esc_attr( join( '\', \'', $fonts_to_load ) ); ?>'; |
85
|
|
|
WebFont.load({ |
86
|
|
|
google: { |
87
|
|
|
families: [ window.kirkiWebontsLoaderFonts ] |
88
|
|
|
} |
89
|
|
|
}); |
90
|
|
|
</script> |
91
|
|
|
<?php |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.