1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WebFont-Loader Module. |
4
|
|
|
* |
5
|
|
|
* @see https://github.com/typekit/webfontloader |
6
|
|
|
* @package Kirki |
7
|
|
|
* @category Modules |
8
|
|
|
* @author Aristeides Stathopoulos |
9
|
|
|
* @copyright Copyright (c) 2017, Aristeides Stathopoulos |
10
|
|
|
* @license https://opensource.org/licenses/MIT |
11
|
|
|
* @since 3.0.26 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
// Exit if accessed directly. |
15
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
16
|
|
|
exit; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Adds script for tooltips. |
21
|
|
|
*/ |
22
|
|
|
class Kirki_Modules_Webfont_Loader { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The object instance. |
26
|
|
|
* |
27
|
|
|
* @static |
28
|
|
|
* @access private |
29
|
|
|
* @since 3.0.26 |
30
|
|
|
* @var object |
31
|
|
|
*/ |
32
|
|
|
private static $instance; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Only load the webfont script if this is true. |
36
|
|
|
* |
37
|
|
|
* @static |
38
|
|
|
* @access public |
39
|
|
|
* @since 3.0.26 |
40
|
|
|
* @var bool |
41
|
|
|
*/ |
42
|
|
|
public static $load = false; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The class constructor |
46
|
|
|
* |
47
|
|
|
* @access protected |
48
|
|
|
* @since 3.0.26 |
49
|
|
|
*/ |
50
|
|
|
protected function __construct() { |
51
|
|
|
add_action( 'wp_head', array( $this, 'enqueue_scripts' ), 20 ); |
52
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 20 ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Gets an instance of this object. |
57
|
|
|
* Prevents duplicate instances which avoid artefacts and improves performance. |
58
|
|
|
* |
59
|
|
|
* @static |
60
|
|
|
* @access public |
61
|
|
|
* @since 3.0.26 |
62
|
|
|
* @return object |
63
|
|
|
*/ |
64
|
|
|
public static function get_instance() { |
65
|
|
|
if ( ! self::$instance ) { |
66
|
|
|
self::$instance = new self(); |
67
|
|
|
} |
68
|
|
|
return self::$instance; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Enqueue scripts. |
73
|
|
|
* |
74
|
|
|
* @access public |
75
|
|
|
* @since 3.0.26 |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
public function enqueue_scripts() { |
79
|
|
|
global $wp_customize; |
80
|
|
|
if ( self::$load || $wp_customize || is_customize_preview() ) { |
81
|
|
|
wp_enqueue_script( 'webfont-loader', trailingslashit( Kirki::$url ) . 'modules/webfont-loader/vendor-typekit/webfontloader.js', array(), '3.0.28', true ); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Set the $load property of this object. |
87
|
|
|
* |
88
|
|
|
* @access public |
89
|
|
|
* @since 3.0.35 |
90
|
|
|
* @param bool $load Set to false to disable loading. |
91
|
|
|
* @return void |
92
|
|
|
*/ |
93
|
|
|
public function set_load( $load ) { |
94
|
|
|
self::$load = $load; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|