Completed
Push — develop ( e61151...e9af13 )
by Aristeides
06:39 queued 03:34
created

Kirki_Custom_Build::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Handles enqueueing scripts & styles for custom builds.
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.0
11
 */
12
13
/**
14
 * Our main Kirki_Control object
15
 */
16
class Kirki_Custom_Build {
17
18
	/**
19
	 * Is this a custom build?
20
	 *
21
	 * @static
22
	 * @access private
23
	 * @since 3.0.0
24
	 * @var bool|null
25
	 */
26
	private static $is_custom_build = null;
27
28
	/**
29
	 * An array of dependencies for the script.
30
	 *
31
	 * @static
32
	 * @access private
33
	 * @since 3.0.0
34
	 * @var array
35
	 */
36
	private static $dependencies = array();
37
38
	/**
39
	 * Constructor.
40
	 *
41
	 * @access public
42
	 * @since 3.0.0
43
	 */
44
	public function __construct() {
45
		if ( ! self::is_custom_build() ) {
46
			return;
47
		}
48
		add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_controls_enqueue_scripts' ), 999 );
49
	}
50
51
	/**
52
	 * Figure out if this is a custom build or not.
53
	 *
54
	 * @static
55
	 * @access public
56
	 * @since 3.0.0
57
	 * @return bool
58
	 */
59
	public static function is_custom_build() {
60
		if ( null === self::$is_custom_build ) {
61
			if ( file_exists( Kirki::$path . '/build.min.js' ) && file_exists( Kirki::$path . '/build.min.css' ) ) {
62
				self::$is_custom_build = true;
63
				return true;
64
			}
65
			self::$is_custom_build = false;
66
			return false;
67
		}
68
		return self::$is_custom_build;
69
	}
70
71
	/**
72
	 * Registers a dependency for the custom build JS.
73
	 *
74
	 * @static
75
	 * @access public
76
	 * @since 3.0.0
77
	 * @param string $dependency The script's identifier.
78
	 */
79
	public static function register_dependency( $dependency ) {
80
		if ( in_array( $dependency, self::$dependencies ) ) {
81
			return;
82
		}
83
		self::$dependencies[] = $dependency;
84
	}
85
86
	/**
87
	 * Enqueues the scripts and styles we need.
88
	 *
89
	 * @access public
90
	 * @since 3.0.0
91
	 */
92
	public function customize_controls_enqueue_scripts() {
93
94
		wp_enqueue_script( 'kirki-build', trailingslashit( Kirki::$url ) . 'build.min.js', self::$dependencies );
95
		wp_enqueue_style( 'kirki-build', trailingslashit( Kirki::$url ) . 'build.min.css', null );
96
97
	}
98
}
99