Completed
Pull Request — develop (#1554)
by Aristeides
02:18
created

Kirki_Control_Base::render_content()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Customizer Controls Base.
4
 *
5
 * Extend this in other controls.
6
 *
7
 * @package     Kirki
8
 * @subpackage  Controls
9
 * @copyright   Copyright (c) 2017, Aristeides Stathopoulos
10
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
11
 * @since       3.0.10
12
 */
13
14
/**
15
 * A base for controls.
16
 */
17
class Kirki_Control_Base extends WP_Customize_Control {
18
19
	/**
20
	 * Used to automatically generate all CSS output.
21
	 *
22
	 * @access public
23
	 * @var array
24
	 */
25
	public $output = array();
26
27
	/**
28
	 * Data type
29
	 *
30
	 * @access public
31
	 * @var string
32
	 */
33
	public $option_type = 'theme_mod';
34
35
	/**
36
	 * The kirki_config we're using for this control
37
	 *
38
	 * @access public
39
	 * @var string
40
	 */
41
	public $kirki_config = 'global';
42
43
	/**
44
	 * Extra script dependencies.
45
	 *
46
	 * @since 3.1.0
47
	 * @return array
48
	 */
49
	public function kirki_script_dependencies() {
50
51
		return array(
52
			'wp-color-picker-alpha',
53
		);
54
	}
55
56
	/**
57
	 * Enqueue control related scripts/styles.
58
	 *
59
	 * @access public
60
	 */
61
	public function enqueue() {
62
63
		$dependencies = array_merge( array( 'jquery', 'customize-base' ), $this->kirki_script_dependencies() );
64
		wp_enqueue_script( 'kirki-control', trailingslashit( Kirki::$url ) . 'controls/js/kirki.control.js', $dependencies, false, true );
65
		wp_enqueue_script( 'kirki-input', trailingslashit( Kirki::$url ) . 'controls/js/kirki.input.js', $dependencies, false, true );
66
		wp_enqueue_script( 'kirki-setting', trailingslashit( Kirki::$url ) . 'controls/js/kirki.setting.js', $dependencies, false, true );
67
		wp_enqueue_script( 'kirki-util', trailingslashit( Kirki::$url ) . 'controls/js/kirki.util.js', $dependencies, false, true );
68
		wp_enqueue_script( 'kirki-value', trailingslashit( Kirki::$url ) . 'controls/js/kirki.value.js', $dependencies, false, true );
69
		wp_enqueue_script( 'kirki-dynamic-control', trailingslashit( Kirki::$url ) . 'controls/js/dynamic-control.js', array( 'jquery', 'customize-base', 'kirki-control', 'kirki-input', 'kirki-setting', 'kirki-util', 'kirki-value' ), false, true );
70
71
		wp_enqueue_script( 'kirki-controls', trailingslashit( Kirki::$url ) . 'controls/js/controls.js', array( 'jquery', 'kirki-dynamic-control', 'customize-base' ), false, true );
72
		wp_enqueue_style( 'kirki-controls-css', trailingslashit( Kirki::$url ) . 'controls/css/controls.css', null );
73
	}
74
75
	/**
76
	 * Refresh the parameters passed to the JavaScript via JSON.
77
	 *
78
	 * @see WP_Customize_Control::to_json()
79
	 */
80
	public function to_json() {
81
		// Get the basics from the parent class.
82
		parent::to_json();
83
		// Default.
84
		$this->json['default'] = $this->setting->default;
85
		if ( isset( $this->default ) ) {
86
			$this->json['default'] = $this->default;
87
		}
88
		// Output.
89
		$this->json['output'] = $this->output;
90
		// Value.
91
		$this->json['value'] = $this->value();
92
		// Choices.
93
		$this->json['choices'] = $this->choices;
94
		// The link.
95
		$this->json['link'] = $this->get_link();
96
		// The ID.
97
		$this->json['id'] = $this->id;
98
		// Translation strings.
99
		$this->json['l10n'] = $this->l10n();
100
		// The ajaxurl in case we need it.
101
		$this->json['ajaxurl'] = admin_url( 'admin-ajax.php' );
102
		// Input attributes.
103
		$this->json['inputAttrs'] = '';
104
		foreach ( $this->input_attrs as $attr => $value ) {
105
			$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';
106
		}
107
	}
108
109
	/**
110
	 * Render the control's content.
111
	 *
112
	 * Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`.
113
	 *
114
	 * Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`.
115
	 * Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly.
116
	 *
117
	 * Control content can alternately be rendered in JS. See WP_Customize_Control::print_template().
118
	 *
119
	 * @since 3.4.0
120
	 */
121
	protected function render_content() {}
122
123
	/**
124
	 * An Underscore (JS) template for this control's content (but not its container).
125
	 *
126
	 * Class variables for this control class are available in the `data` JS object;
127
	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
128
	 *
129
	 * @see WP_Customize_Control::print_template()
130
	 *
131
	 * @access protected
132
	 */
133
	protected function content_template() {
134
		// This HTML will be replaced when the control is loaded.
135
		echo '<h4>' . esc_attr__( 'Please wait while we load the control', 'kirki' ) . '</h4>';
136
	}
137
138
	/**
139
	 * Returns an array of translation strings.
140
	 *
141
	 * @access protected
142
	 * @since 3.0.0
143
	 * @return array
144
	 */
145
	protected function l10n() {
146
		return array();
147
	}
148
}
149