Completed
Pull Request — master (#1653)
by Aristeides
05:59 queued 03:27
created

Kirki_Controls   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 54
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A underscore_templates() 0 9 3
1
<?php
2
/**
3
 * Customizer Controls Init.
4
 *
5
 * @package     Kirki
6
 * @subpackage  Controls
7
 * @copyright   Copyright (c) 2017, Aristeides Stathopoulos
8
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
9
 * @since       3.0.17
10
 */
11
12
/**
13
 * Controls.
14
 */
15
class Kirki_Controls {
16
17
	/**
18
	 * An array of templates to load.
19
	 *
20
	 * @access private
21
	 * @since 3.0.17
22
	 * @var array
23
	 */
24
	private $templates = array(
25
		'input-color',
26
		'input-radio',
27
	);
28
29
	/**
30
	 * Path to controls views.
31
	 *
32
	 * @access private
33
	 * @since 3.0.17
34
	 * @var string
35
	 */
36
	private $views_path;
37
38
	/**
39
	 * Constructor.
40
	 *
41
	 * @access public
42
	 * @since 3.0.17
43
	 */
44
	public function __construct() {
45
46
		if ( ! $this->views_path ) {
47
			$this->views_path = wp_normalize_path( dirname( KIRKI_PLUGIN_FILE ) . '/controls/views/' );
48
		}
49
		add_action( 'customize_controls_print_footer_scripts', array( $this, 'underscore_templates' ) );
50
	}
51
52
	/**
53
	 * Adds underscore.js templates to the footer.
54
	 *
55
	 * @access public
56
	 * @since 3.0.17
57
	 * @return void
58
	 */
59
	public function underscore_templates() {
60
		foreach ( $this->templates as $template ) {
61
			if ( file_exists( $this->views_path . $template . '.php' ) ) {
62
				echo '<script type="text/html" id="tmpl-kirki-' . esc_attr( $template ) . '">';
63
				include $this->views_path . $template . '.php';
64
				echo '</script>';
65
			}
66
		}
67
	}
68
}
69