Passed
Push — develop ( 4e1663...e14823 )
by Aristeides
03:47
created

Kirki_Modules_Webfont_Loader::get_instance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 5
rs 9.4285
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   http://opensource.org/licenses/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
	}
53
54
	/**
55
	 * Gets an instance of this object.
56
	 * Prevents duplicate instances which avoid artefacts and improves performance.
57
	 *
58
	 * @static
59
	 * @access public
60
	 * @since 3.0.26
61
	 * @return object
62
	 */
63
	public static function get_instance() {
64
		if ( ! self::$instance ) {
65
			self::$instance = new self();
66
		}
67
		return self::$instance;
68
	}
69
70
	/**
71
	 * Enqueue scripts.
72
	 *
73
	 * @access public
74
	 * @since 3.0.26
75
	 * @return void
76
	 */
77
	public function enqueue_scripts() {
78
		if ( self::$load ) {
79
			wp_enqueue_script( 'webfont-loader', trailingslashit( Kirki::$url ) . 'modules/webfont-loader/vendor-typekit/webfontloader.js', array(), '3.0.28', true );
80
		}
81
	}
82
}
83