|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Customizer Control: repeater. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Kirki |
|
6
|
|
|
* @subpackage Controls |
|
7
|
|
|
* @copyright Copyright (c) 2016, Aristeides Stathopoulos |
|
8
|
|
|
* @license http://opensource.org/licenses/https://opensource.org/licenses/MIT |
|
9
|
|
|
* @since 2.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// Exit if accessed directly. |
|
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
14
|
|
|
exit; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Repeater control |
|
19
|
|
|
*/ |
|
20
|
|
|
class Kirki_Control_Repeater extends WP_Customize_Control { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The control type. |
|
24
|
|
|
* |
|
25
|
|
|
* @access public |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $type = 'repeater'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Used to automatically generate all CSS output. |
|
32
|
|
|
* |
|
33
|
|
|
* @access public |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
public $output = array(); |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Data type |
|
40
|
|
|
* |
|
41
|
|
|
* @access public |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
public $option_type = 'theme_mod'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The kirki_config we're using for this control |
|
48
|
|
|
* |
|
49
|
|
|
* @access public |
|
50
|
|
|
* @var string |
|
51
|
|
|
*/ |
|
52
|
|
|
public $kirki_config = 'global'; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* The fields that each container row will contain. |
|
56
|
|
|
* |
|
57
|
|
|
* @access public |
|
58
|
|
|
* @var array |
|
59
|
|
|
*/ |
|
60
|
|
|
public $fields = array(); |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Will store a filtered version of value for advenced fields (like images). |
|
64
|
|
|
* |
|
65
|
|
|
* @access protected |
|
66
|
|
|
* @var array |
|
67
|
|
|
*/ |
|
68
|
|
|
protected $filtered_value = array(); |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* The row label |
|
72
|
|
|
* |
|
73
|
|
|
* @access public |
|
74
|
|
|
* @var array |
|
75
|
|
|
*/ |
|
76
|
|
|
public $row_label = array(); |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Constructor. |
|
80
|
|
|
* Supplied `$args` override class property defaults. |
|
81
|
|
|
* If `$args['settings']` is not defined, use the $id as the setting ID. |
|
82
|
|
|
* |
|
83
|
|
|
* @param WP_Customize_Manager $manager Customizer bootstrap instance. |
|
84
|
|
|
* @param string $id Control ID. |
|
85
|
|
|
* @param array $args {@see WP_Customize_Control::__construct}. |
|
86
|
|
|
*/ |
|
87
|
|
|
public function __construct( $manager, $id, $args = array() ) { |
|
88
|
|
|
|
|
89
|
|
|
parent::__construct( $manager, $id, $args ); |
|
90
|
|
|
|
|
91
|
|
|
// Set up defaults for row labels. |
|
92
|
|
|
$this->row_label = array( |
|
93
|
|
|
'type' => 'text', |
|
94
|
|
|
'value' => $this->l10n( 'row' ), |
|
95
|
|
|
'field' => false, |
|
96
|
|
|
); |
|
97
|
|
|
|
|
98
|
|
|
// Validate row-labels. |
|
99
|
|
|
$this->row_label( $args ); |
|
100
|
|
|
|
|
101
|
|
|
if ( empty( $this->button_label ) ) { |
|
102
|
|
|
$this->button_label = $this->l10n( 'add-new' ) . ' ' . $this->row_label['value']; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
if ( empty( $args['fields'] ) || ! is_array( $args['fields'] ) ) { |
|
106
|
|
|
$args['fields'] = array(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
// An array to store keys of fields that need to be filtered. |
|
110
|
|
|
$media_fields_to_filter = array(); |
|
111
|
|
|
|
|
112
|
|
|
foreach ( $args['fields'] as $key => $value ) { |
|
113
|
|
|
if ( ! isset( $value['default'] ) ) { |
|
114
|
|
|
$args['fields'][ $key ]['default'] = ''; |
|
115
|
|
|
} |
|
116
|
|
|
if ( ! isset( $value['label'] ) ) { |
|
117
|
|
|
$args['fields'][ $key ]['label'] = ''; |
|
118
|
|
|
} |
|
119
|
|
|
$args['fields'][ $key ]['id'] = $key; |
|
120
|
|
|
|
|
121
|
|
|
// We check if the filed is an uploaded media ( image , file, video, etc.. ). |
|
122
|
|
|
if ( isset( $value['type'] ) ) { |
|
123
|
|
|
switch ( $value['type'] ) { |
|
124
|
|
|
case 'image': |
|
125
|
|
|
case 'cropped_image': |
|
126
|
|
|
case 'upload': |
|
127
|
|
|
// We add it to the list of fields that need some extra filtering/processing. |
|
128
|
|
|
$media_fields_to_filter[ $key ] = true; |
|
129
|
|
|
break; |
|
130
|
|
|
|
|
131
|
|
|
case 'dropdown-pages': |
|
132
|
|
|
// If the field is a dropdown-pages field then add it to args. |
|
133
|
|
|
$dropdown = wp_dropdown_pages( |
|
134
|
|
|
array( |
|
135
|
|
|
'name' => '', |
|
136
|
|
|
'echo' => 0, |
|
137
|
|
|
'show_option_none' => esc_attr( $this->l10n( 'select-page' ) ), |
|
138
|
|
|
'option_none_value' => '0', |
|
139
|
|
|
'selected' => '', |
|
140
|
|
|
) |
|
141
|
|
|
); |
|
142
|
|
|
// Hackily add in the data link parameter. |
|
143
|
|
|
$dropdown = str_replace( '<select', '<select data-field="' . esc_attr( $args['fields'][ $key ]['id'] ) . '"' . $this->get_link(), $dropdown ); |
|
144
|
|
|
$args['fields'][ $key ]['dropdown'] = $dropdown; |
|
145
|
|
|
break; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
} // End foreach(). |
|
149
|
|
|
|
|
150
|
|
|
$this->fields = $args['fields']; |
|
151
|
|
|
|
|
152
|
|
|
// Now we are going to filter the fields. |
|
153
|
|
|
// First we create a copy of the value that would be used otherwise. |
|
154
|
|
|
$this->filtered_value = $this->value(); |
|
155
|
|
|
|
|
156
|
|
|
if ( is_array( $this->filtered_value ) && ! empty( $this->filtered_value ) ) { |
|
157
|
|
|
|
|
158
|
|
|
// We iterate over the list of fields. |
|
159
|
|
|
foreach ( $this->filtered_value as &$filtered_value_field ) { |
|
160
|
|
|
|
|
161
|
|
|
if ( is_array( $filtered_value_field ) && ! empty( $filtered_value_field ) ) { |
|
162
|
|
|
|
|
163
|
|
|
// We iterate over the list of properties for this field. |
|
164
|
|
|
foreach ( $filtered_value_field as $key => &$value ) { |
|
165
|
|
|
|
|
166
|
|
|
// We check if this field was marked as requiring extra filtering (in this case image, cropped_images, upload). |
|
167
|
|
|
if ( array_key_exists( $key, $media_fields_to_filter ) ) { |
|
168
|
|
|
|
|
169
|
|
|
// What follows was made this way to preserve backward compatibility. |
|
170
|
|
|
// The repeater control use to store the URL for images instead of the attachment ID. |
|
171
|
|
|
// We check if the value look like an ID (otherwise it's probably a URL so don't filter it). |
|
172
|
|
|
if ( is_numeric( $value ) ) { |
|
173
|
|
|
|
|
174
|
|
|
// "sanitize" the value. |
|
175
|
|
|
$attachment_id = (int) $value; |
|
176
|
|
|
|
|
177
|
|
|
// Try to get the attachment_url. |
|
178
|
|
|
$url = wp_get_attachment_url( $attachment_id ); |
|
179
|
|
|
|
|
180
|
|
|
$filename = basename( get_attached_file( $attachment_id ) ); |
|
181
|
|
|
|
|
182
|
|
|
// If we got a URL. |
|
183
|
|
|
if ( $url ) { |
|
184
|
|
|
|
|
185
|
|
|
// 'id' is needed for form hidden value, URL is needed to display the image. |
|
186
|
|
|
$value = array( |
|
187
|
|
|
'id' => $attachment_id, |
|
188
|
|
|
'url' => $url, |
|
189
|
|
|
'filename' => $filename, |
|
190
|
|
|
); |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
} // End foreach(). |
|
197
|
|
|
} // End if(). |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Refresh the parameters passed to the JavaScript via JSON. |
|
202
|
|
|
* |
|
203
|
|
|
* @access public |
|
204
|
|
|
*/ |
|
205
|
|
|
public function to_json() { |
|
206
|
|
|
parent::to_json(); |
|
207
|
|
|
|
|
208
|
|
|
$this->json['default'] = ( isset( $this->default ) ) ? $this->default : $this->setting->default; |
|
209
|
|
|
$this->json['output'] = $this->output; |
|
210
|
|
|
$this->json['value'] = $this->value(); |
|
211
|
|
|
$this->json['choices'] = $this->choices; |
|
212
|
|
|
$this->json['link'] = $this->get_link(); |
|
213
|
|
|
$this->json['id'] = $this->id; |
|
214
|
|
|
|
|
215
|
|
|
if ( 'user_meta' === $this->option_type ) { |
|
216
|
|
|
// @codingStandardsIgnoreLine |
|
217
|
|
|
$this->json['value'] = get_user_meta( get_current_user_id(), $this->id, true ); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
$this->json['inputAttrs'] = ''; |
|
221
|
|
|
foreach ( $this->input_attrs as $attr => $value ) { |
|
222
|
|
|
$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" '; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
$fields = $this->fields; |
|
226
|
|
|
|
|
227
|
|
|
$this->json['fields'] = $fields; |
|
228
|
|
|
$this->json['row_label'] = $this->row_label; |
|
229
|
|
|
|
|
230
|
|
|
// If filtered_value has been set and is not empty we use it instead of the actual value. |
|
231
|
|
|
if ( is_array( $this->filtered_value ) && ! empty( $this->filtered_value ) ) { |
|
232
|
|
|
$this->json['value'] = $this->filtered_value; |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* Enqueue control related scripts/styles. |
|
238
|
|
|
* |
|
239
|
|
|
* @access public |
|
240
|
|
|
*/ |
|
241
|
|
|
public function enqueue() { |
|
242
|
|
|
|
|
243
|
|
|
// If we have a color picker field we need to enqueue the Wordpress Color Picker style and script. |
|
244
|
|
|
if ( is_array( $this->fields ) && ! empty( $this->fields ) ) { |
|
245
|
|
|
foreach ( $this->fields as $field ) { |
|
246
|
|
|
if ( isset( $field['type'] ) ) { |
|
247
|
|
|
|
|
248
|
|
|
// Some field-types require extra scripts. |
|
249
|
|
|
switch ( $field['type'] ) { |
|
250
|
|
|
case 'color': |
|
251
|
|
|
wp_enqueue_script( 'wp-color-picker' ); |
|
252
|
|
|
wp_enqueue_style( 'wp-color-picker' ); |
|
253
|
|
|
break; |
|
254
|
|
|
case 'select': |
|
255
|
|
|
case 'dropdown-pages': |
|
256
|
|
|
wp_enqueue_script( 'select2', trailingslashit( Kirki::$url ) . 'assets/vendor/select2/js/select2.full.js', array( 'jquery' ), false, true ); |
|
257
|
|
|
wp_enqueue_style( 'select2', trailingslashit( Kirki::$url ) . 'assets/vendor/select2/css/select2.min.css', null ); |
|
258
|
|
|
break; |
|
259
|
|
|
} |
|
260
|
|
|
} |
|
261
|
|
|
} |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
wp_enqueue_script( 'kirki-repeater', trailingslashit( Kirki::$url ) . 'controls/repeater/repeater.js', array( 'jquery', 'customize-base', 'jquery-ui-core', 'jquery-ui-sortable' ), false, true ); |
|
265
|
|
|
wp_enqueue_style( 'kirki-repeater-css', trailingslashit( Kirki::$url ) . 'controls/repeater/repeater.css', null ); |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* Render the control's content. |
|
270
|
|
|
* Allows the content to be overriden without having to rewrite the wrapper in $this->render(). |
|
271
|
|
|
* |
|
272
|
|
|
* @access protected |
|
273
|
|
|
*/ |
|
274
|
|
|
protected function render_content() { |
|
275
|
|
|
?> |
|
276
|
|
|
<label> |
|
277
|
|
|
<?php if ( ! empty( $this->label ) ) : ?> |
|
278
|
|
|
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
|
279
|
|
|
<?php endif; ?> |
|
280
|
|
|
<?php if ( ! empty( $this->description ) ) : ?> |
|
281
|
|
|
<span class="description customize-control-description"><?php echo wp_kses_post( $this->description ); ?></span> |
|
282
|
|
|
<?php endif; ?> |
|
283
|
|
|
<input type="hidden" {{{ data.inputAttrs }}} value="" <?php echo wp_kses_post( $this->get_link() ); ?> /> |
|
284
|
|
|
</label> |
|
285
|
|
|
|
|
286
|
|
|
<ul class="repeater-fields"></ul> |
|
287
|
|
|
|
|
288
|
|
|
<?php if ( isset( $this->choices['limit'] ) ) : ?> |
|
289
|
|
|
<p class="limit"><?php printf( esc_html( $this->l10n( 'limit-rows' ) ), esc_html( $this->choices['limit'] ) ); ?></p> |
|
290
|
|
|
<?php endif; ?> |
|
291
|
|
|
<button class="button-secondary repeater-add"><?php echo esc_html( $this->button_label ); ?></button> |
|
292
|
|
|
|
|
293
|
|
|
<?php |
|
294
|
|
|
|
|
295
|
|
|
$this->repeater_js_template(); |
|
296
|
|
|
|
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* An Underscore (JS) template for this control's content (but not its container). |
|
301
|
|
|
* Class variables for this control class are available in the `data` JS object. |
|
302
|
|
|
* |
|
303
|
|
|
* @access public |
|
304
|
|
|
*/ |
|
305
|
|
|
public function repeater_js_template() { |
|
306
|
|
|
?> |
|
307
|
|
|
<script type="text/html" class="customize-control-repeater-content"> |
|
308
|
|
|
<# var field; var index = data.index; #> |
|
309
|
|
|
|
|
310
|
|
|
<li class="repeater-row minimized" data-row="{{{ index }}}"> |
|
311
|
|
|
|
|
312
|
|
|
<div class="repeater-row-header"> |
|
313
|
|
|
<span class="repeater-row-label"></span> |
|
314
|
|
|
<i class="dashicons dashicons-arrow-down repeater-minimize"></i> |
|
315
|
|
|
</div> |
|
316
|
|
|
<div class="repeater-row-content"> |
|
317
|
|
|
<# _.each( data, function( field, i ) { #> |
|
318
|
|
|
|
|
319
|
|
|
<div class="repeater-field repeater-field-{{{ field.type }}}"> |
|
320
|
|
|
|
|
321
|
|
|
<# if ( 'text' === field.type || 'url' === field.type || 'link' === field.type || 'email' === field.type || 'tel' === field.type || 'date' === field.type || 'number' === field.type ) { #> |
|
322
|
|
|
<# var fieldExtras = ''; #> |
|
323
|
|
|
<# if ( 'link' === field.type ) { #> |
|
324
|
|
|
<# field.type = 'url' #> |
|
325
|
|
|
<# } #> |
|
326
|
|
|
|
|
327
|
|
|
<# if ( 'number' === field.type ) { #> |
|
328
|
|
|
<# if ( ! _.isUndefined( field.choices ) && ! _.isUndefined( field.choices.min ) ) { #> |
|
329
|
|
|
<# fieldExtras += ' min="' + field.choices.min + '"'; #> |
|
330
|
|
|
<# } #> |
|
331
|
|
|
<# if ( ! _.isUndefined( field.choices ) && ! _.isUndefined( field.choices.max ) ) { #> |
|
332
|
|
|
<# fieldExtras += ' max="' + field.choices.max + '"'; #> |
|
333
|
|
|
<# } #> |
|
334
|
|
|
<# if ( ! _.isUndefined( field.choices ) && ! _.isUndefined( field.choices.step ) ) { #> |
|
335
|
|
|
<# fieldExtras += ' step="' + field.choices.step + '"'; #> |
|
336
|
|
|
<# } #> |
|
337
|
|
|
<# } #> |
|
338
|
|
|
|
|
339
|
|
|
<label> |
|
340
|
|
|
<# if ( field.label ) { #> |
|
341
|
|
|
<span class="customize-control-title">{{ field.label }}</span> |
|
342
|
|
|
<# } #> |
|
343
|
|
|
<# if ( field.description ) { #> |
|
344
|
|
|
<span class="description customize-control-description">{{ field.description }}</span> |
|
345
|
|
|
<# } #> |
|
346
|
|
|
<input type="{{field.type}}" name="" value="{{{ field.default }}}" data-field="{{{ field.id }}}"{{ fieldExtras }}> |
|
347
|
|
|
</label> |
|
348
|
|
|
|
|
349
|
|
|
<# } else if ( 'number' === field.type ) { #> |
|
350
|
|
|
|
|
351
|
|
|
<label> |
|
352
|
|
|
<# if ( field.label ) { #> |
|
353
|
|
|
<span class="customize-control-title">{{ field.label }}</span> |
|
354
|
|
|
<# } #> |
|
355
|
|
|
<# if ( field.description ) { #> |
|
356
|
|
|
<span class="description customize-control-description">{{ field.description }}</span> |
|
357
|
|
|
<# } #> |
|
358
|
|
|
<input type="{{ field.type }}" name="" value="{{{ field.default }}}" data-field="{{{ field.id }}}"{{ numberFieldExtras }}> |
|
359
|
|
|
</label> |
|
360
|
|
|
|
|
361
|
|
|
<# } else if ( 'hidden' === field.type ) { #> |
|
362
|
|
|
|
|
363
|
|
|
<input type="hidden" data-field="{{{ field.id }}}" <# if ( field.default ) { #> value="{{{ field.default }}}" <# } #> /> |
|
364
|
|
|
|
|
365
|
|
|
<# } else if ( 'checkbox' === field.type ) { #> |
|
366
|
|
|
|
|
367
|
|
|
<label> |
|
368
|
|
|
<input type="checkbox" value="true" data-field="{{{ field.id }}}" <# if ( field.default ) { #> checked="checked" <# } #> /> {{ field.label }} |
|
369
|
|
|
<# if ( field.description ) { #> |
|
370
|
|
|
{{ field.description }} |
|
371
|
|
|
<# } #> |
|
372
|
|
|
</label> |
|
373
|
|
|
|
|
374
|
|
|
<# } else if ( 'select' === field.type ) { #> |
|
375
|
|
|
|
|
376
|
|
|
<label> |
|
377
|
|
|
<# if ( field.label ) { #> |
|
378
|
|
|
<span class="customize-control-title">{{ field.label }}</span> |
|
379
|
|
|
<# } #> |
|
380
|
|
|
<# if ( field.description ) { #> |
|
381
|
|
|
<span class="description customize-control-description">{{ field.description }}</span> |
|
382
|
|
|
<# } #> |
|
383
|
|
|
<select data-field="{{{ field.id }}}"<# if ( ! _.isUndefined( field.multiple ) && false !== field.multiple ) { #> multiple="multiple" data-multiple="{{ field.multiple }}"<# } #>> |
|
384
|
|
|
<# _.each( field.choices, function( choice, i ) { #> |
|
385
|
|
|
<option value="{{{ i }}}" <# if ( field.default == i ) { #> selected="selected" <# } #>>{{ choice }}</option> |
|
386
|
|
|
<# }); #> |
|
387
|
|
|
</select> |
|
388
|
|
|
</label> |
|
389
|
|
|
|
|
390
|
|
|
<# } else if ( 'dropdown-pages' === field.type ) { #> |
|
391
|
|
|
|
|
392
|
|
|
<label> |
|
393
|
|
|
<# if ( field.label ) { #> |
|
394
|
|
|
<span class="customize-control-title">{{{ data.label }}}</span> |
|
395
|
|
|
<# } #> |
|
396
|
|
|
<# if ( field.description ) { #> |
|
397
|
|
|
<span class="description customize-control-description">{{{ field.description }}}</span> |
|
398
|
|
|
<# } #> |
|
399
|
|
|
<div class="customize-control-content repeater-dropdown-pages">{{{ field.dropdown }}}</div> |
|
400
|
|
|
</label> |
|
401
|
|
|
|
|
402
|
|
|
<# } else if ( 'radio' === field.type ) { #> |
|
403
|
|
|
|
|
404
|
|
|
<label> |
|
405
|
|
|
<# if ( field.label ) { #> |
|
406
|
|
|
<span class="customize-control-title">{{ field.label }}</span> |
|
407
|
|
|
<# } #> |
|
408
|
|
|
<# if ( field.description ) { #> |
|
409
|
|
|
<span class="description customize-control-description">{{ field.description }}</span> |
|
410
|
|
|
<# } #> |
|
411
|
|
|
|
|
412
|
|
|
<# _.each( field.choices, function( choice, i ) { #> |
|
413
|
|
|
<label> |
|
414
|
|
|
<input type="radio" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> {{ choice }} <br/> |
|
415
|
|
|
</label> |
|
416
|
|
|
<# }); #> |
|
417
|
|
|
</label> |
|
418
|
|
|
|
|
419
|
|
|
<# } else if ( 'radio-image' === field.type ) { #> |
|
420
|
|
|
|
|
421
|
|
|
<label> |
|
422
|
|
|
<# if ( field.label ) { #> |
|
423
|
|
|
<span class="customize-control-title">{{ field.label }}</span> |
|
424
|
|
|
<# } #> |
|
425
|
|
|
<# if ( field.description ) { #> |
|
426
|
|
|
<span class="description customize-control-description">{{ field.description }}</span> |
|
427
|
|
|
<# } #> |
|
428
|
|
|
|
|
429
|
|
|
<# _.each( field.choices, function( choice, i ) { #> |
|
430
|
|
|
<input type="radio" id="{{{ field.id }}}_{{ index }}_{{{ i }}}" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> |
|
431
|
|
|
<label for="{{{ field.id }}}_{{ index }}_{{{ i }}}"> |
|
432
|
|
|
<img src="{{ choice }}"> |
|
433
|
|
|
</label> |
|
434
|
|
|
</input> |
|
435
|
|
|
<# }); #> |
|
436
|
|
|
</label> |
|
437
|
|
|
|
|
438
|
|
|
<# } else if ( 'color' === field.type ) { #> |
|
439
|
|
|
|
|
440
|
|
|
<# var defaultValue = ''; |
|
441
|
|
|
if ( field.default ) { |
|
442
|
|
|
if ( '#' !== field.default.substring( 0, 1 ) ) { |
|
443
|
|
|
defaultValue = '#' + field.default; |
|
444
|
|
|
} else { |
|
445
|
|
|
defaultValue = field.default; |
|
446
|
|
|
} |
|
447
|
|
|
defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically. |
|
448
|
|
|
} #> |
|
449
|
|
|
<label> |
|
450
|
|
|
<# if ( field.label ) { #> |
|
451
|
|
|
<span class="customize-control-title">{{{ field.label }}}</span> |
|
452
|
|
|
<# } #> |
|
453
|
|
|
<# if ( field.description ) { #> |
|
454
|
|
|
<span class="description customize-control-description">{{{ field.description }}}</span> |
|
455
|
|
|
<# } #> |
|
456
|
|
|
<input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php echo esc_attr( $this->l10n( 'hex-value' ) ); ?>" value="{{{ field.default }}}" data-field="{{{ field.id }}}" {{ defaultValue }} /> |
|
457
|
|
|
|
|
458
|
|
|
</label> |
|
459
|
|
|
|
|
460
|
|
|
<# } else if ( 'textarea' === field.type ) { #> |
|
461
|
|
|
|
|
462
|
|
|
<# if ( field.label ) { #> |
|
463
|
|
|
<span class="customize-control-title">{{ field.label }}</span> |
|
464
|
|
|
<# } #> |
|
465
|
|
|
<# if ( field.description ) { #> |
|
466
|
|
|
<span class="description customize-control-description">{{ field.description }}</span> |
|
467
|
|
|
<# } #> |
|
468
|
|
|
<textarea rows="5" data-field="{{{ field.id }}}">{{ field.default }}</textarea> |
|
469
|
|
|
|
|
470
|
|
|
<# } else if ( field.type === 'image' || field.type === 'cropped_image' ) { #> |
|
471
|
|
|
|
|
472
|
|
|
<label> |
|
473
|
|
|
<# if ( field.label ) { #> |
|
474
|
|
|
<span class="customize-control-title">{{ field.label }}</span> |
|
475
|
|
|
<# } #> |
|
476
|
|
|
<# if ( field.description ) { #> |
|
477
|
|
|
<span class="description customize-control-description">{{ field.description }}</span> |
|
478
|
|
|
<# } #> |
|
479
|
|
|
</label> |
|
480
|
|
|
|
|
481
|
|
|
<figure class="kirki-image-attachment" data-placeholder="<?php echo esc_attr( $this->l10n( 'no-image-selected' ) ); ?>" > |
|
482
|
|
|
<# if ( field.default ) { #> |
|
483
|
|
|
<# var defaultImageURL = ( field.default.url ) ? field.default.url : field.default; #> |
|
484
|
|
|
<img src="{{{ defaultImageURL }}}"> |
|
485
|
|
|
<# } else { #> |
|
486
|
|
|
<?php echo esc_attr( $this->l10n( 'no-image-selected' ) ); ?> |
|
487
|
|
|
<# } #> |
|
488
|
|
|
</figure> |
|
489
|
|
|
|
|
490
|
|
|
<div class="actions"> |
|
491
|
|
|
<button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"><?php echo esc_attr( $this->l10n( 'remove' ) ); ?></button> |
|
492
|
|
|
<button type="button" class="button upload-button" data-label=" <?php echo esc_attr( $this->l10n( 'add-image' ) ); ?>" data-alt-label="<?php echo esc_attr( $this->l10n( 'change-image' ) ); ?>" > |
|
493
|
|
|
<# if ( field.default ) { #> |
|
494
|
|
|
<?php echo esc_attr( $this->l10n( 'change-image' ) ); ?> |
|
495
|
|
|
<# } else { #> |
|
496
|
|
|
<?php echo esc_attr( $this->l10n( 'add-image' ) ); ?> |
|
497
|
|
|
<# } #> |
|
498
|
|
|
</button> |
|
499
|
|
|
<# if ( field.default.id ) { #> |
|
500
|
|
|
<input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
|
501
|
|
|
<# } else { #> |
|
502
|
|
|
<input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
|
503
|
|
|
<# } #> |
|
504
|
|
|
</div> |
|
505
|
|
|
|
|
506
|
|
|
<# } else if ( field.type === 'upload' ) { #> |
|
507
|
|
|
|
|
508
|
|
|
<label> |
|
509
|
|
|
<# if ( field.label ) { #> |
|
510
|
|
|
<span class="customize-control-title">{{ field.label }}</span> |
|
511
|
|
|
<# } #> |
|
512
|
|
|
<# if ( field.description ) { #> |
|
513
|
|
|
<span class="description customize-control-description">{{ field.description }}</span> |
|
514
|
|
|
<# } #> |
|
515
|
|
|
</label> |
|
516
|
|
|
|
|
517
|
|
|
<figure class="kirki-file-attachment" data-placeholder="<?php echo esc_attr( $this->l10n( 'no-file-selected' ) ); ?>" > |
|
518
|
|
|
<# if ( field.default ) { #> |
|
519
|
|
|
<# var defaultFilename = ( field.default.filename ) ? field.default.filename : field.default; #> |
|
520
|
|
|
<span class="file"><span class="dashicons dashicons-media-default"></span> {{ defaultFilename }}</span> |
|
521
|
|
|
<# } else { #> |
|
522
|
|
|
<?php echo esc_attr( $this->l10n( 'no-file-selected' ) ); ?> |
|
523
|
|
|
<# } #> |
|
524
|
|
|
</figure> |
|
525
|
|
|
|
|
526
|
|
|
<div class="actions"> |
|
527
|
|
|
<button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"></button> |
|
528
|
|
|
<button type="button" class="button upload-button" data-label="<?php echo esc_attr( $this->l10n( 'add-file' ) ); ?>" data-alt-label="<?php echo esc_attr( $this->l10n( 'change-file' ) ); ?>" > |
|
529
|
|
|
<# if ( field.default ) { #> |
|
530
|
|
|
<?php echo esc_attr( $this->l10n( 'change-file' ) ); ?> |
|
531
|
|
|
<# } else { #> |
|
532
|
|
|
<?php echo esc_attr( $this->l10n( 'add-file' ) ); ?> |
|
533
|
|
|
<# } #> |
|
534
|
|
|
</button> |
|
535
|
|
|
<# if ( field.default.id ) { #> |
|
536
|
|
|
<input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
|
537
|
|
|
<# } else { #> |
|
538
|
|
|
<input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
|
539
|
|
|
<# } #> |
|
540
|
|
|
</div> |
|
541
|
|
|
|
|
542
|
|
|
<# } else if ( 'custom' === field.type ) { #> |
|
543
|
|
|
|
|
544
|
|
|
<# if ( field.label ) { #> |
|
545
|
|
|
<span class="customize-control-title">{{ field.label }}</span> |
|
546
|
|
|
<# } #> |
|
547
|
|
|
<# if ( field.description ) { #> |
|
548
|
|
|
<span class="description customize-control-description">{{ field.description }}</span> |
|
549
|
|
|
<# } #> |
|
550
|
|
|
<div data-field="{{{ field.id }}}">{{{ field.default }}}</div> |
|
551
|
|
|
|
|
552
|
|
|
<# } #> |
|
553
|
|
|
|
|
554
|
|
|
</div> |
|
555
|
|
|
<# }); #> |
|
556
|
|
|
<button type="button" class="button-link repeater-row-remove"><?php echo esc_attr( $this->l10n( 'remove' ) ); ?></button> |
|
557
|
|
|
</div> |
|
558
|
|
|
</li> |
|
559
|
|
|
</script> |
|
560
|
|
|
<?php |
|
561
|
|
|
} |
|
562
|
|
|
|
|
563
|
|
|
/** |
|
564
|
|
|
* Validate row-labels. |
|
565
|
|
|
* |
|
566
|
|
|
* @access protected |
|
567
|
|
|
* @since 3.0.0 |
|
568
|
|
|
* @param array $args {@see WP_Customize_Control::__construct}. |
|
569
|
|
|
*/ |
|
570
|
|
|
protected function row_label( $args ) { |
|
571
|
|
|
|
|
572
|
|
|
// Validating args for row labels. |
|
573
|
|
|
if ( isset( $args['row_label'] ) && is_array( $args['row_label'] ) && ! empty( $args['row_label'] ) ) { |
|
574
|
|
|
|
|
575
|
|
|
// Validating row label type. |
|
576
|
|
|
if ( isset( $args['row_label']['type'] ) && ( 'text' === $args['row_label']['type'] || 'field' === $args['row_label']['type'] ) ) { |
|
577
|
|
|
$this->row_label['type'] = $args['row_label']['type']; |
|
578
|
|
|
} |
|
579
|
|
|
|
|
580
|
|
|
// Validating row label type. |
|
581
|
|
|
if ( isset( $args['row_label']['value'] ) && ! empty( $args['row_label']['value'] ) ) { |
|
582
|
|
|
$this->row_label['value'] = esc_attr( $args['row_label']['value'] ); |
|
583
|
|
|
} |
|
584
|
|
|
|
|
585
|
|
|
// Validating row label field. |
|
586
|
|
|
if ( isset( $args['row_label']['field'] ) && ! empty( $args['row_label']['field'] ) && isset( $args['fields'][ esc_attr( $args['row_label']['field'] ) ] ) ) { |
|
587
|
|
|
$this->row_label['field'] = esc_attr( $args['row_label']['field'] ); |
|
588
|
|
|
} else { |
|
589
|
|
|
// If from field is not set correctly, making sure standard is set as the type. |
|
590
|
|
|
$this->row_label['type'] = 'text'; |
|
591
|
|
|
} |
|
592
|
|
|
} |
|
593
|
|
|
} |
|
594
|
|
|
|
|
595
|
|
|
/** |
|
596
|
|
|
* Returns an array of translation strings. |
|
597
|
|
|
* |
|
598
|
|
|
* @access protected |
|
599
|
|
|
* @since 3.0.0 |
|
600
|
|
|
* @param string|false $id The string-ID. |
|
601
|
|
|
* @return string |
|
602
|
|
|
*/ |
|
603
|
|
|
protected function l10n( $id = false ) { |
|
604
|
|
|
$translation_strings = array( |
|
605
|
|
|
'row' => esc_attr__( 'row', 'kirki' ), |
|
606
|
|
|
'add-new' => esc_attr__( 'Add new', 'kirki' ), |
|
607
|
|
|
'select-page' => esc_attr__( 'Select a Page', 'kirki' ), |
|
608
|
|
|
/* translators: %s represents the number of rows we're limiting the repeater to allow. */ |
|
609
|
|
|
'limit-rows' => esc_attr__( 'Limit: %s rows', 'kirki' ), |
|
610
|
|
|
'hex-value' => esc_attr__( 'Hex Value', 'kirki' ), |
|
611
|
|
|
'no-image-selected' => esc_attr__( 'No Image Selected', 'kirki' ), |
|
612
|
|
|
'remove' => esc_attr__( 'Remove', 'kirki' ), |
|
613
|
|
|
'add-image' => esc_attr__( 'Add Image', 'kirki' ), |
|
614
|
|
|
'change-image' => esc_attr__( 'Change Image', 'kirki' ), |
|
615
|
|
|
'no-file-selected' => esc_attr__( 'No File Selected', 'kirki' ), |
|
616
|
|
|
'add-file' => esc_attr__( 'Add File', 'kirki' ), |
|
617
|
|
|
'change-file' => esc_attr__( 'Change File', 'kirki' ), |
|
618
|
|
|
); |
|
619
|
|
|
$translation_strings = apply_filters( "kirki/{$this->kirki_config}/l10n", $translation_strings ); |
|
620
|
|
|
if ( false === $id ) { |
|
621
|
|
|
return $translation_strings; |
|
622
|
|
|
} |
|
623
|
|
|
return $translation_strings[ $id ]; |
|
624
|
|
|
} |
|
625
|
|
|
} |
|
626
|
|
|
|