Completed
Pull Request — master (#1653)
by Aristeides
04:25 queued 02:17
created

Kirki_Controls::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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