Completed
Pull Request — master (#1653)
by Aristeides
05:02 queued 02:34
created

Kirki_Controls   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 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-radio',
26
	);
27
28
	/**
29
	 * Path to controls views.
30
	 *
31
	 * @access private
32
	 * @since 3.0.17
33
	 * @var string
34
	 */
35
	private $views_path;
36
37
	/**
38
	 * Constructor.
39
	 *
40
	 * @access public
41
	 * @since 3.0.17
42
	 */
43
	public function __construct() {
44
45
		if ( ! $this->views_path ) {
46
			$this->views_path = wp_normalize_path( dirname( KIRKI_PLUGIN_FILE ) . '/controls/views/' );
47
		}
48
		add_action( 'customize_controls_print_footer_scripts', array( $this, 'underscore_templates' ) );
49
	}
50
51
	/**
52
	 * Adds underscore.js templates to the footer.
53
	 *
54
	 * @access public
55
	 * @since 3.0.17
56
	 * @return void
57
	 */
58
	public function underscore_templates() {
59
		foreach ( $this->templates as $template ) {
60
			if ( file_exists( $this->views_path . $template . '.php' ) ) {
61
				echo '<script type="text/html" id="tmpl-kirki-' . esc_attr( $template ) . '">';
62
				include $this->views_path . $template . '.php';
63
				echo '</script>';
64
			}
65
		}
66
	}
67
}
68