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.12 |
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
|
|
|
return array(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Enqueue control related scripts/styles. |
55
|
|
|
* |
56
|
|
|
* @access public |
57
|
|
|
*/ |
58
|
|
|
public function enqueue() { |
59
|
|
|
|
60
|
|
|
// Build the suffix for the script. |
61
|
|
|
$suffix = ''; |
62
|
|
|
$suffix .= ( Kirki_Util::get_wp_version() >= 4.9 ) ? '' : '-legacy'; |
63
|
|
|
$suffix .= ( ! defined( 'SCRIPT_DEBUG' ) || true !== SCRIPT_DEBUG ) ? '.min' : ''; |
64
|
|
|
|
65
|
|
|
// The Kirki plugin URL. |
66
|
|
|
$kirki_url = trailingslashit( Kirki::$url ); |
67
|
|
|
|
68
|
|
|
// Enqueue ColorPicker. |
69
|
|
|
$script_filename = 'wp-color-picker-alpha-legacy.js'; |
70
|
|
|
if ( Kirki_Util::get_wp_version() >= 4.9 ) { |
71
|
|
|
$script_filename = 'wp-color-picker-alpha.js'; |
72
|
|
|
wp_enqueue_style( 'wp-color-picker-alpha', trailingslashit( Kirki::$url ) . 'assets/vendor/wp-color-picker-alpha/wp-color-picker-alpha.css', null ); |
73
|
|
|
} |
74
|
|
|
wp_enqueue_script( 'wp-color-picker-alpha', trailingslashit( Kirki::$url ) . 'assets/vendor/wp-color-picker-alpha/' . $script_filename, array( 'wp-color-picker' ), false, true ); |
75
|
|
|
wp_enqueue_style( 'wp-color-picker' ); |
76
|
|
|
|
77
|
|
|
// Enqueue selectWoo. |
78
|
|
|
wp_enqueue_script( 'selectWoo', trailingslashit( Kirki::$url ) . 'assets/vendor/selectWoo/js/selectWoo.full.js', array( 'jquery' ), '1.0.1', true ); |
79
|
|
|
wp_enqueue_style( 'selectWoo', trailingslashit( Kirki::$url ) . 'assets/vendor/selectWoo/css/selectWoo.css', array(), '1.0.1' ); |
80
|
|
|
wp_enqueue_style( 'kirki-selectWoo', trailingslashit( Kirki::$url ) . 'assets/vendor/selectWoo/kirki.css', null ); |
81
|
|
|
|
82
|
|
|
// Enqueue the script. |
83
|
|
|
wp_enqueue_script( |
84
|
|
|
'kirki-script', |
85
|
|
|
"{$kirki_url}controls/js/dist/script{$suffix}.js", |
86
|
|
|
array( |
87
|
|
|
'jquery', |
88
|
|
|
'customize-base', |
89
|
|
|
'wp-color-picker-alpha', |
90
|
|
|
'selectWoo', |
91
|
|
|
'jquery-ui-button', |
92
|
|
|
'jquery-ui-spinner' |
|
|
|
|
93
|
|
|
) |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
// Build the suffix for the style. |
97
|
|
|
$suffix = ''; |
98
|
|
|
$suffix .= ( Kirki_Util::get_wp_version() >= 4.9 ) ? '' : '-legacy'; |
99
|
|
|
|
100
|
|
|
// Enqueue the style. |
101
|
|
|
wp_enqueue_style( |
102
|
|
|
'kirki-styles', |
103
|
|
|
"{$kirki_url}controls/css/styles{$suffix}.css", |
104
|
|
|
null |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Refresh the parameters passed to the JavaScript via JSON. |
110
|
|
|
* |
111
|
|
|
* @see WP_Customize_Control::to_json() |
112
|
|
|
*/ |
113
|
|
|
public function to_json() { |
114
|
|
|
// Get the basics from the parent class. |
115
|
|
|
parent::to_json(); |
116
|
|
|
// Default. |
117
|
|
|
$this->json['default'] = $this->setting->default; |
118
|
|
|
if ( isset( $this->default ) ) { |
119
|
|
|
$this->json['default'] = $this->default; |
120
|
|
|
} |
121
|
|
|
// Output. |
122
|
|
|
$this->json['output'] = $this->output; |
123
|
|
|
// Value. |
124
|
|
|
$this->json['value'] = $this->value(); |
125
|
|
|
// Choices. |
126
|
|
|
$this->json['choices'] = $this->choices; |
127
|
|
|
// The link. |
128
|
|
|
$this->json['link'] = $this->get_link(); |
129
|
|
|
// The ID. |
130
|
|
|
$this->json['id'] = $this->id; |
131
|
|
|
// Translation strings. |
132
|
|
|
$this->json['l10n'] = $this->l10n(); |
133
|
|
|
// The ajaxurl in case we need it. |
134
|
|
|
$this->json['ajaxurl'] = admin_url( 'admin-ajax.php' ); |
135
|
|
|
// Input attributes. |
136
|
|
|
$this->json['inputAttrs'] = ''; |
137
|
|
|
foreach ( $this->input_attrs as $attr => $value ) { |
138
|
|
|
$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" '; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Render the control's content. |
144
|
|
|
* |
145
|
|
|
* Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`. |
146
|
|
|
* |
147
|
|
|
* Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`. |
148
|
|
|
* Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly. |
149
|
|
|
* |
150
|
|
|
* Control content can alternately be rendered in JS. See WP_Customize_Control::print_template(). |
151
|
|
|
* |
152
|
|
|
* @since 3.4.0 |
153
|
|
|
*/ |
154
|
|
|
protected function render_content() {} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* An Underscore (JS) template for this control's content (but not its container). |
158
|
|
|
* |
159
|
|
|
* Class variables for this control class are available in the `data` JS object; |
160
|
|
|
* export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
161
|
|
|
* |
162
|
|
|
* @see WP_Customize_Control::print_template() |
163
|
|
|
* |
164
|
|
|
* @access protected |
165
|
|
|
*/ |
166
|
|
|
protected function content_template() {} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Returns an array of translation strings. |
170
|
|
|
* |
171
|
|
|
* @access protected |
172
|
|
|
* @since 3.0.0 |
173
|
|
|
* @return array |
174
|
|
|
*/ |
175
|
|
|
protected function l10n() { |
176
|
|
|
return array(); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|