|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* ACF Gallery Field Class |
|
5
|
|
|
* |
|
6
|
|
|
* All the logic for this field type |
|
7
|
|
|
* |
|
8
|
|
|
* @class acf_field_gallery |
|
9
|
|
|
* @extends acf_field |
|
10
|
|
|
* @package ACF |
|
11
|
|
|
* @subpackage Fields |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
if( ! class_exists('acf_field_gallery') ) : |
|
15
|
|
|
|
|
16
|
|
|
class acf_field_gallery extends acf_field { |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/* |
|
20
|
|
|
* __construct |
|
21
|
|
|
* |
|
22
|
|
|
* This function will setup the field type data |
|
23
|
|
|
* |
|
24
|
|
|
* @type function |
|
25
|
|
|
* @date 5/03/2014 |
|
26
|
|
|
* @since 5.0.0 |
|
27
|
|
|
* |
|
28
|
|
|
* @param n/a |
|
29
|
|
|
* @return n/a |
|
30
|
|
|
*/ |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
function __construct() { |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
// vars |
|
35
|
|
|
$this->name = 'gallery'; |
|
36
|
|
|
$this->label = __("Gallery",'acf'); |
|
|
|
|
|
|
37
|
|
|
$this->category = 'content'; |
|
38
|
|
|
$this->defaults = array( |
|
39
|
|
|
'preview_size' => 'thumbnail', |
|
40
|
|
|
'library' => 'all', |
|
41
|
|
|
'min' => 0, |
|
42
|
|
|
'max' => 0, |
|
43
|
|
|
'min_width' => 0, |
|
44
|
|
|
'min_height' => 0, |
|
45
|
|
|
'min_size' => 0, |
|
46
|
|
|
'max_width' => 0, |
|
47
|
|
|
'max_height' => 0, |
|
48
|
|
|
'max_size' => 0, |
|
49
|
|
|
'mime_types' => '' |
|
50
|
|
|
); |
|
51
|
|
|
$this->l10n = array( |
|
52
|
|
|
'select' => __("Add Image to Gallery",'acf'), |
|
53
|
|
|
'edit' => __("Edit Image",'acf'), |
|
54
|
|
|
'update' => __("Update Image",'acf'), |
|
55
|
|
|
'uploadedTo' => __("uploaded to this post",'acf'), |
|
56
|
|
|
'max' => __("Maximum selection reached",'acf') |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
// actions |
|
61
|
|
|
add_action('wp_ajax_acf/fields/gallery/get_attachment', array($this, 'ajax_get_attachment')); |
|
62
|
|
|
add_action('wp_ajax_nopriv_acf/fields/gallery/get_attachment', array($this, 'ajax_get_attachment')); |
|
63
|
|
|
|
|
64
|
|
|
add_action('wp_ajax_acf/fields/gallery/update_attachment', array($this, 'ajax_update_attachment')); |
|
65
|
|
|
add_action('wp_ajax_nopriv_acf/fields/gallery/update_attachment', array($this, 'ajax_update_attachment')); |
|
66
|
|
|
|
|
67
|
|
|
add_action('wp_ajax_acf/fields/gallery/get_sort_order', array($this, 'ajax_get_sort_order')); |
|
68
|
|
|
add_action('wp_ajax_nopriv_acf/fields/gallery/get_sort_order', array($this, 'ajax_get_sort_order')); |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
// do not delete! |
|
73
|
|
|
parent::__construct(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
/* |
|
78
|
|
|
* ajax_get_attachment |
|
79
|
|
|
* |
|
80
|
|
|
* description |
|
81
|
|
|
* |
|
82
|
|
|
* @type function |
|
83
|
|
|
* @date 13/12/2013 |
|
84
|
|
|
* @since 5.0.0 |
|
85
|
|
|
* |
|
86
|
|
|
* @param $post_id (int) |
|
87
|
|
|
* @return $post_id (int) |
|
88
|
|
|
*/ |
|
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
function ajax_get_attachment() { |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
// options |
|
93
|
|
|
$options = acf_parse_args( $_POST, array( |
|
94
|
|
|
'post_id' => 0, |
|
95
|
|
|
'id' => 0, |
|
96
|
|
|
'field_key' => '', |
|
97
|
|
|
'nonce' => '', |
|
98
|
|
|
)); |
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
// validate |
|
102
|
|
|
if( ! wp_verify_nonce($options['nonce'], 'acf_nonce') ) { |
|
103
|
|
|
|
|
104
|
|
|
die(); |
|
105
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if( empty($options['id']) ) { |
|
109
|
|
|
|
|
110
|
|
|
die(); |
|
111
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
// load field |
|
116
|
|
|
$field = acf_get_field( $options['field_key'] ); |
|
117
|
|
|
|
|
118
|
|
|
if( !$field ) { |
|
119
|
|
|
|
|
120
|
|
|
die(); |
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
// render |
|
126
|
|
|
$this->render_attachment( $options['id'], $field ); |
|
127
|
|
|
die; |
|
128
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
/* |
|
133
|
|
|
* ajax_update_attachment |
|
134
|
|
|
* |
|
135
|
|
|
* description |
|
136
|
|
|
* |
|
137
|
|
|
* @type function |
|
138
|
|
|
* @date 13/12/2013 |
|
139
|
|
|
* @since 5.0.0 |
|
140
|
|
|
* |
|
141
|
|
|
* @param $post_id (int) |
|
142
|
|
|
* @return $post_id (int) |
|
143
|
|
|
*/ |
|
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
function ajax_update_attachment() { |
|
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
// validate nonce |
|
148
|
|
|
if( !wp_verify_nonce($_POST['nonce'], 'acf_nonce') ) { |
|
149
|
|
|
|
|
150
|
|
|
wp_send_json_error(); |
|
151
|
|
|
|
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
// bail early if no attachments |
|
156
|
|
|
if( empty($_POST['attachments']) ) { |
|
157
|
|
|
|
|
158
|
|
|
wp_send_json_error(); |
|
159
|
|
|
|
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
|
|
163
|
|
|
// loop over attachments |
|
164
|
|
|
foreach( $_POST['attachments'] as $id => $changes ) { |
|
165
|
|
|
|
|
166
|
|
|
if ( !current_user_can( 'edit_post', $id ) ) |
|
167
|
|
|
wp_send_json_error(); |
|
168
|
|
|
|
|
169
|
|
|
$post = get_post( $id, ARRAY_A ); |
|
170
|
|
|
|
|
171
|
|
|
if ( 'attachment' != $post['post_type'] ) |
|
172
|
|
|
wp_send_json_error(); |
|
173
|
|
|
|
|
174
|
|
|
if ( isset( $changes['title'] ) ) |
|
175
|
|
|
$post['post_title'] = $changes['title']; |
|
176
|
|
|
|
|
177
|
|
|
if ( isset( $changes['caption'] ) ) |
|
178
|
|
|
$post['post_excerpt'] = $changes['caption']; |
|
179
|
|
|
|
|
180
|
|
|
if ( isset( $changes['description'] ) ) |
|
181
|
|
|
$post['post_content'] = $changes['description']; |
|
182
|
|
|
|
|
183
|
|
|
if ( isset( $changes['alt'] ) ) { |
|
184
|
|
|
$alt = wp_unslash( $changes['alt'] ); |
|
185
|
|
|
if ( $alt != get_post_meta( $id, '_wp_attachment_image_alt', true ) ) { |
|
186
|
|
|
$alt = wp_strip_all_tags( $alt, true ); |
|
187
|
|
|
update_post_meta( $id, '_wp_attachment_image_alt', wp_slash( $alt ) ); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
|
|
192
|
|
|
// save post |
|
193
|
|
|
wp_update_post( $post ); |
|
194
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
/** This filter is documented in wp-admin/includes/media.php */ |
|
197
|
|
|
// - seems off to run this filter AFTER the update_post function, but there is a reason |
|
198
|
|
|
// - when placed BEFORE, an empty post_title will be populated by WP |
|
199
|
|
|
// - this filter will still allow 3rd party to save extra image data! |
|
200
|
|
|
$post = apply_filters( 'attachment_fields_to_save', $post, $changes ); |
|
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
|
|
203
|
|
|
// save meta |
|
204
|
|
|
acf_save_post( $id ); |
|
205
|
|
|
|
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
|
|
209
|
|
|
// return |
|
210
|
|
|
wp_send_json_success(); |
|
211
|
|
|
|
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
|
|
215
|
|
|
/* |
|
216
|
|
|
* ajax_get_sort_order |
|
217
|
|
|
* |
|
218
|
|
|
* description |
|
219
|
|
|
* |
|
220
|
|
|
* @type function |
|
221
|
|
|
* @date 13/12/2013 |
|
222
|
|
|
* @since 5.0.0 |
|
223
|
|
|
* |
|
224
|
|
|
* @param $post_id (int) |
|
225
|
|
|
* @return $post_id (int) |
|
226
|
|
|
*/ |
|
|
|
|
|
|
227
|
|
|
|
|
228
|
|
|
function ajax_get_sort_order() { |
|
|
|
|
|
|
229
|
|
|
|
|
230
|
|
|
// vars |
|
231
|
|
|
$r = array(); |
|
|
|
|
|
|
232
|
|
|
$order = 'DESC'; |
|
233
|
|
|
$args = acf_parse_args( $_POST, array( |
|
234
|
|
|
'ids' => 0, |
|
235
|
|
|
'sort' => 'date', |
|
236
|
|
|
'field_key' => '', |
|
237
|
|
|
'nonce' => '', |
|
238
|
|
|
)); |
|
239
|
|
|
|
|
240
|
|
|
|
|
241
|
|
|
// validate |
|
242
|
|
|
if( ! wp_verify_nonce($args['nonce'], 'acf_nonce') ) { |
|
243
|
|
|
|
|
244
|
|
|
wp_send_json_error(); |
|
245
|
|
|
|
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
|
|
249
|
|
|
// reverse |
|
250
|
|
|
if( $args['sort'] == 'reverse' ) { |
|
251
|
|
|
|
|
252
|
|
|
$ids = array_reverse($args['ids']); |
|
253
|
|
|
|
|
254
|
|
|
wp_send_json_success($ids); |
|
255
|
|
|
|
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
|
|
259
|
|
|
if( $args['sort'] == 'title' ) { |
|
260
|
|
|
|
|
261
|
|
|
$order = 'ASC'; |
|
262
|
|
|
|
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
|
|
266
|
|
|
// find attachments (DISTINCT POSTS) |
|
267
|
|
|
$ids = get_posts(array( |
|
268
|
|
|
'post_type' => 'attachment', |
|
269
|
|
|
'numberposts' => -1, |
|
270
|
|
|
'post_status' => 'any', |
|
271
|
|
|
'post__in' => $args['ids'], |
|
272
|
|
|
'order' => $order, |
|
273
|
|
|
'orderby' => $args['sort'], |
|
274
|
|
|
'fields' => 'ids' |
|
275
|
|
|
)); |
|
276
|
|
|
|
|
277
|
|
|
|
|
278
|
|
|
// success |
|
279
|
|
|
if( !empty($ids) ) { |
|
280
|
|
|
|
|
281
|
|
|
wp_send_json_success($ids); |
|
282
|
|
|
|
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
|
|
286
|
|
|
// failure |
|
287
|
|
|
wp_send_json_error(); |
|
288
|
|
|
|
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
|
|
292
|
|
|
/* |
|
293
|
|
|
* render_attachment |
|
294
|
|
|
* |
|
295
|
|
|
* description |
|
296
|
|
|
* |
|
297
|
|
|
* @type function |
|
298
|
|
|
* @date 13/12/2013 |
|
299
|
|
|
* @since 5.0.0 |
|
300
|
|
|
* |
|
301
|
|
|
* @param $post_id (int) |
|
302
|
|
|
* @return $post_id (int) |
|
303
|
|
|
*/ |
|
|
|
|
|
|
304
|
|
|
|
|
305
|
|
|
function render_attachment( $id = 0, $field ) { |
|
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
// vars |
|
308
|
|
|
$attachment = wp_prepare_attachment_for_js( $id ); |
|
309
|
|
|
$thumb = ''; |
|
|
|
|
|
|
310
|
|
|
$prefix = "attachments[{$id}]"; |
|
311
|
|
|
$compat = get_compat_media_markup( $id ); |
|
312
|
|
|
$dimentions = ''; |
|
313
|
|
|
|
|
314
|
|
|
|
|
315
|
|
|
// thumb |
|
316
|
|
|
if( isset($attachment['thumb']['src']) ) { |
|
317
|
|
|
|
|
318
|
|
|
// video |
|
319
|
|
|
$thumb = $attachment['thumb']['src']; |
|
320
|
|
|
|
|
321
|
|
|
} elseif( isset($attachment['sizes']['thumbnail']['url']) ) { |
|
322
|
|
|
|
|
323
|
|
|
// image |
|
324
|
|
|
$thumb = $attachment['sizes']['thumbnail']['url']; |
|
325
|
|
|
|
|
326
|
|
|
} elseif( $attachment['type'] === 'image' ) { |
|
327
|
|
|
|
|
328
|
|
|
// svg |
|
329
|
|
|
$thumb = $attachment['url']; |
|
330
|
|
|
|
|
331
|
|
|
} else { |
|
332
|
|
|
|
|
333
|
|
|
// fallback (perhaps attachment does not exist) |
|
334
|
|
|
$thumb = $attachment['icon']; |
|
335
|
|
|
|
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
|
|
339
|
|
|
|
|
340
|
|
|
// dimentions |
|
341
|
|
|
if( $attachment['type'] === 'audio' ) { |
|
342
|
|
|
|
|
343
|
|
|
$dimentions = __('Length', 'acf') . ': ' . $attachment['fileLength']; |
|
344
|
|
|
|
|
345
|
|
|
} elseif( !empty($attachment['width']) ) { |
|
346
|
|
|
|
|
347
|
|
|
$dimentions = $attachment['width'] . ' x ' . $attachment['height']; |
|
348
|
|
|
|
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
if( $attachment['filesizeHumanReadable'] ) { |
|
352
|
|
|
|
|
353
|
|
|
$dimentions .= ' (' . $attachment['filesizeHumanReadable'] . ')'; |
|
354
|
|
|
|
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
?> |
|
358
|
|
|
<div class="acf-gallery-side-info acf-cf"> |
|
359
|
|
|
<img src="<?php echo $thumb; ?>" alt="<?php echo $attachment['alt']; ?>" /> |
|
360
|
|
|
<p class="filename"><strong><?php echo $attachment['filename']; ?></strong></p> |
|
361
|
|
|
<p class="uploaded"><?php echo $attachment['dateFormatted']; ?></p> |
|
362
|
|
|
<p class="dimensions"><?php echo $dimentions; ?></p> |
|
363
|
|
|
<p class="actions"><a href="#" class="edit-attachment" data-id="<?php echo $id; ?>"><?php _e('Edit', 'acf'); ?></a> <a href="#" class="remove-attachment" data-id="<?php echo $id; ?>"><?php _e('Remove', 'acf'); ?></a></p> |
|
364
|
|
|
</div> |
|
365
|
|
|
<table class="form-table"> |
|
366
|
|
|
<tbody> |
|
367
|
|
|
<?php |
|
368
|
|
|
|
|
369
|
|
|
acf_render_field_wrap(array( |
|
370
|
|
|
//'key' => "{$field['key']}-title", |
|
371
|
|
|
'name' => 'title', |
|
372
|
|
|
'prefix' => $prefix, |
|
373
|
|
|
'type' => 'text', |
|
374
|
|
|
'label' => 'Title', |
|
375
|
|
|
'value' => $attachment['title'] |
|
376
|
|
|
), 'tr'); |
|
377
|
|
|
|
|
378
|
|
|
acf_render_field_wrap(array( |
|
379
|
|
|
//'key' => "{$field['key']}-caption", |
|
380
|
|
|
'name' => 'caption', |
|
381
|
|
|
'prefix' => $prefix, |
|
382
|
|
|
'type' => 'textarea', |
|
383
|
|
|
'label' => 'Caption', |
|
384
|
|
|
'value' => $attachment['caption'] |
|
385
|
|
|
), 'tr'); |
|
386
|
|
|
|
|
387
|
|
|
acf_render_field_wrap(array( |
|
388
|
|
|
//'key' => "{$field['key']}-alt", |
|
389
|
|
|
'name' => 'alt', |
|
390
|
|
|
'prefix' => $prefix, |
|
391
|
|
|
'type' => 'text', |
|
392
|
|
|
'label' => 'Alt Text', |
|
393
|
|
|
'value' => $attachment['alt'] |
|
394
|
|
|
), 'tr'); |
|
395
|
|
|
|
|
396
|
|
|
acf_render_field_wrap(array( |
|
397
|
|
|
//'key' => "{$field['key']}-description", |
|
398
|
|
|
'name' => 'description', |
|
399
|
|
|
'prefix' => $prefix, |
|
400
|
|
|
'type' => 'textarea', |
|
401
|
|
|
'label' => 'Description', |
|
402
|
|
|
'value' => $attachment['description'] |
|
403
|
|
|
), 'tr'); |
|
404
|
|
|
|
|
405
|
|
|
?> |
|
406
|
|
|
</tbody> |
|
407
|
|
|
</table> |
|
408
|
|
|
<?php echo $compat['item']; ?> |
|
409
|
|
|
|
|
410
|
|
|
<?php |
|
411
|
|
|
|
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
|
|
415
|
|
|
/* |
|
416
|
|
|
* render_field() |
|
417
|
|
|
* |
|
418
|
|
|
* Create the HTML interface for your field |
|
419
|
|
|
* |
|
420
|
|
|
* @param $field - an array holding all the field's data |
|
421
|
|
|
* |
|
422
|
|
|
* @type action |
|
423
|
|
|
* @since 3.6 |
|
424
|
|
|
* @date 23/01/13 |
|
425
|
|
|
*/ |
|
426
|
|
|
|
|
427
|
|
|
function render_field( $field ) { |
|
|
|
|
|
|
428
|
|
|
|
|
429
|
|
|
// enqueue |
|
430
|
|
|
acf_enqueue_uploader(); |
|
431
|
|
|
|
|
432
|
|
|
|
|
433
|
|
|
// vars |
|
434
|
|
|
$posts = array(); |
|
435
|
|
|
$atts = array( |
|
436
|
|
|
'id' => $field['id'], |
|
437
|
|
|
'class' => "acf-gallery {$field['class']}", |
|
438
|
|
|
'data-preview_size' => $field['preview_size'], |
|
439
|
|
|
'data-library' => $field['library'], |
|
440
|
|
|
'data-min' => $field['min'], |
|
441
|
|
|
'data-max' => $field['max'], |
|
442
|
|
|
'data-mime_types' => $field['mime_types'], |
|
443
|
|
|
); |
|
444
|
|
|
|
|
445
|
|
|
|
|
446
|
|
|
// set gallery height |
|
447
|
|
|
$height = acf_get_user_setting('gallery_height', 400); |
|
|
|
|
|
|
448
|
|
|
$height = max( $height, 200 ); // minimum height is 200 |
|
449
|
|
|
$atts['style'] = "height:{$height}px"; |
|
450
|
|
|
|
|
451
|
|
|
|
|
452
|
|
|
// load posts |
|
453
|
|
|
if( !empty($field['value']) ) { |
|
454
|
|
|
|
|
455
|
|
|
$posts = acf_get_posts(array( |
|
456
|
|
|
'post_type' => 'attachment', |
|
457
|
|
|
'post__in' => $field['value'] |
|
458
|
|
|
)); |
|
459
|
|
|
|
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
|
|
463
|
|
|
?> |
|
464
|
|
|
<div <?php acf_esc_attr_e($atts); ?>> |
|
465
|
|
|
|
|
466
|
|
|
<div class="acf-hidden"> |
|
467
|
|
|
<input type="hidden" <?php acf_esc_attr_e(array( 'name' => $field['name'], 'value' => '', 'data-name' => 'ids' )); ?> /> |
|
468
|
|
|
</div> |
|
469
|
|
|
|
|
470
|
|
|
<div class="acf-gallery-main"> |
|
471
|
|
|
|
|
472
|
|
|
<div class="acf-gallery-attachments"> |
|
473
|
|
|
|
|
474
|
|
|
<?php if( !empty($posts) ): ?> |
|
475
|
|
|
|
|
476
|
|
|
<?php foreach( $posts as $post ): |
|
477
|
|
|
|
|
478
|
|
|
// vars |
|
479
|
|
|
$type = acf_maybe_get(explode('/', $post->post_mime_type), 0); |
|
480
|
|
|
$thumb_id = $post->ID; |
|
481
|
|
|
$thumb_url = ''; |
|
482
|
|
|
$thumb_class = 'acf-gallery-attachment acf-soh'; |
|
483
|
|
|
$filename = wp_basename($post->guid); |
|
484
|
|
|
|
|
485
|
|
|
|
|
486
|
|
|
// thumb |
|
487
|
|
|
if( $type === 'image' || $type === 'audio' || $type === 'video' ) { |
|
488
|
|
|
|
|
489
|
|
|
// change $thumb_id |
|
490
|
|
|
if( $type === 'audio' || $type === 'video' ) { |
|
491
|
|
|
|
|
492
|
|
|
$thumb_id = get_post_thumbnail_id( $post->ID ); |
|
493
|
|
|
|
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
|
|
497
|
|
|
// get attachment |
|
498
|
|
|
if( $thumb_id ) { |
|
499
|
|
|
|
|
500
|
|
|
$thumb_url = wp_get_attachment_image_src( $thumb_id, $field['preview_size'] ); |
|
501
|
|
|
$thumb_url = acf_maybe_get( $thumb_url, 0 ); |
|
502
|
|
|
|
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
} |
|
506
|
|
|
|
|
507
|
|
|
|
|
508
|
|
|
// fallback |
|
509
|
|
|
if( !$thumb_url ) { |
|
510
|
|
|
|
|
511
|
|
|
$thumb_url = wp_mime_type_icon( $post->ID ); |
|
512
|
|
|
$thumb_class .= ' is-mime-icon'; |
|
513
|
|
|
|
|
514
|
|
|
} |
|
515
|
|
|
|
|
516
|
|
|
?> |
|
517
|
|
|
<div class="<?php echo $thumb_class; ?>" data-id="<?php echo $post->ID; ?>"> |
|
518
|
|
|
<input type="hidden" name="<?php echo $field['name']; ?>[]" value="<?php echo $post->ID; ?>" /> |
|
519
|
|
|
<div class="margin" title="<?php echo $filename; ?>"> |
|
520
|
|
|
<div class="thumbnail"> |
|
521
|
|
|
<img src="<?php echo $thumb_url; ?>"/> |
|
522
|
|
|
</div> |
|
523
|
|
|
<?php if( $type !== 'image' ): ?> |
|
524
|
|
|
<div class="filename"><?php echo acf_get_truncated($filename, 18); ?></div> |
|
525
|
|
|
<?php endif; ?> |
|
526
|
|
|
</div> |
|
527
|
|
|
<div class="actions acf-soh-target"> |
|
528
|
|
|
<a class="acf-icon -cancel dark remove-attachment" data-id="<?php echo $post->ID; ?>" href="#"></a> |
|
529
|
|
|
</div> |
|
530
|
|
|
</div> |
|
531
|
|
|
|
|
532
|
|
|
<?php endforeach; ?> |
|
533
|
|
|
|
|
534
|
|
|
<?php endif; ?> |
|
535
|
|
|
|
|
536
|
|
|
|
|
537
|
|
|
</div> |
|
538
|
|
|
|
|
539
|
|
|
<div class="acf-gallery-toolbar"> |
|
540
|
|
|
|
|
541
|
|
|
<ul class="acf-hl"> |
|
542
|
|
|
<li> |
|
543
|
|
|
<a href="#" class="acf-button blue add-attachment"><?php _e('Add to gallery', 'acf'); ?></a> |
|
544
|
|
|
</li> |
|
545
|
|
|
<li class="acf-fr"> |
|
546
|
|
|
<select class="bulk-actions"> |
|
547
|
|
|
<option value=""><?php _e('Bulk actions', 'acf'); ?></option> |
|
548
|
|
|
<option value="date"><?php _e('Sort by date uploaded', 'acf'); ?></option> |
|
549
|
|
|
<option value="modified"><?php _e('Sort by date modified', 'acf'); ?></option> |
|
550
|
|
|
<option value="title"><?php _e('Sort by title', 'acf'); ?></option> |
|
551
|
|
|
<option value="reverse"><?php _e('Reverse current order', 'acf'); ?></option> |
|
552
|
|
|
</select> |
|
553
|
|
|
</li> |
|
554
|
|
|
</ul> |
|
555
|
|
|
|
|
556
|
|
|
</div> |
|
557
|
|
|
|
|
558
|
|
|
</div> |
|
559
|
|
|
|
|
560
|
|
|
<div class="acf-gallery-side"> |
|
561
|
|
|
<div class="acf-gallery-side-inner"> |
|
562
|
|
|
|
|
563
|
|
|
<div class="acf-gallery-side-data"></div> |
|
564
|
|
|
|
|
565
|
|
|
<div class="acf-gallery-toolbar"> |
|
566
|
|
|
|
|
567
|
|
|
<ul class="acf-hl"> |
|
568
|
|
|
<li> |
|
569
|
|
|
<a href="#" class="acf-button close-sidebar"><?php _e('Close', 'acf'); ?></a> |
|
570
|
|
|
</li> |
|
571
|
|
|
<li class="acf-fr"> |
|
572
|
|
|
<a class="acf-button blue update-attachment"><?php _e('Update', 'acf'); ?></a> |
|
573
|
|
|
</li> |
|
574
|
|
|
</ul> |
|
575
|
|
|
|
|
576
|
|
|
</div> |
|
577
|
|
|
|
|
578
|
|
|
</div> |
|
579
|
|
|
</div> |
|
580
|
|
|
|
|
581
|
|
|
</div> |
|
582
|
|
|
<?php |
|
583
|
|
|
|
|
584
|
|
|
} |
|
585
|
|
|
|
|
586
|
|
|
|
|
587
|
|
|
/* |
|
588
|
|
|
* render_field_settings() |
|
589
|
|
|
* |
|
590
|
|
|
* Create extra options for your field. This is rendered when editing a field. |
|
591
|
|
|
* The value of $field['name'] can be used (like bellow) to save extra data to the $field |
|
592
|
|
|
* |
|
593
|
|
|
* @type action |
|
594
|
|
|
* @since 3.6 |
|
595
|
|
|
* @date 23/01/13 |
|
596
|
|
|
* |
|
597
|
|
|
* @param $field - an array holding all the field's data |
|
598
|
|
|
*/ |
|
599
|
|
|
|
|
600
|
|
|
function render_field_settings( $field ) { |
|
|
|
|
|
|
601
|
|
|
|
|
602
|
|
|
// clear numeric settings |
|
603
|
|
|
$clear = array( |
|
604
|
|
|
'min', |
|
605
|
|
|
'max', |
|
606
|
|
|
'min_width', |
|
607
|
|
|
'min_height', |
|
608
|
|
|
'min_size', |
|
609
|
|
|
'max_width', |
|
610
|
|
|
'max_height', |
|
611
|
|
|
'max_size' |
|
612
|
|
|
); |
|
613
|
|
|
|
|
614
|
|
|
foreach( $clear as $k ) { |
|
615
|
|
|
|
|
616
|
|
|
if( empty($field[$k]) ) { |
|
617
|
|
|
|
|
618
|
|
|
$field[$k] = ''; |
|
619
|
|
|
|
|
620
|
|
|
} |
|
621
|
|
|
|
|
622
|
|
|
} |
|
623
|
|
|
|
|
624
|
|
|
|
|
625
|
|
|
// min |
|
626
|
|
|
acf_render_field_setting( $field, array( |
|
627
|
|
|
'label' => __('Minimum Selection','acf'), |
|
628
|
|
|
'instructions' => '', |
|
629
|
|
|
'type' => 'number', |
|
630
|
|
|
'name' => 'min' |
|
631
|
|
|
)); |
|
632
|
|
|
|
|
633
|
|
|
|
|
634
|
|
|
// max |
|
635
|
|
|
acf_render_field_setting( $field, array( |
|
636
|
|
|
'label' => __('Maximum Selection','acf'), |
|
637
|
|
|
'instructions' => '', |
|
638
|
|
|
'type' => 'number', |
|
639
|
|
|
'name' => 'max' |
|
640
|
|
|
)); |
|
641
|
|
|
|
|
642
|
|
|
|
|
643
|
|
|
// preview_size |
|
644
|
|
|
acf_render_field_setting( $field, array( |
|
645
|
|
|
'label' => __('Preview Size','acf'), |
|
646
|
|
|
'instructions' => __('Shown when entering data','acf'), |
|
647
|
|
|
'type' => 'select', |
|
648
|
|
|
'name' => 'preview_size', |
|
649
|
|
|
'choices' => acf_get_image_sizes() |
|
650
|
|
|
)); |
|
651
|
|
|
|
|
652
|
|
|
|
|
653
|
|
|
// library |
|
654
|
|
|
acf_render_field_setting( $field, array( |
|
655
|
|
|
'label' => __('Library','acf'), |
|
656
|
|
|
'instructions' => __('Limit the media library choice','acf'), |
|
657
|
|
|
'type' => 'radio', |
|
658
|
|
|
'name' => 'library', |
|
659
|
|
|
'layout' => 'horizontal', |
|
660
|
|
|
'choices' => array( |
|
661
|
|
|
'all' => __('All', 'acf'), |
|
662
|
|
|
'uploadedTo' => __('Uploaded to post', 'acf') |
|
663
|
|
|
) |
|
664
|
|
|
)); |
|
665
|
|
|
|
|
666
|
|
|
|
|
667
|
|
|
// min |
|
668
|
|
|
acf_render_field_setting( $field, array( |
|
669
|
|
|
'label' => __('Minimum','acf'), |
|
670
|
|
|
'instructions' => __('Restrict which images can be uploaded','acf'), |
|
671
|
|
|
'type' => 'text', |
|
672
|
|
|
'name' => 'min_width', |
|
673
|
|
|
'prepend' => __('Width', 'acf'), |
|
674
|
|
|
'append' => 'px', |
|
675
|
|
|
)); |
|
676
|
|
|
|
|
677
|
|
|
acf_render_field_setting( $field, array( |
|
678
|
|
|
'label' => '', |
|
679
|
|
|
'type' => 'text', |
|
680
|
|
|
'name' => 'min_height', |
|
681
|
|
|
'prepend' => __('Height', 'acf'), |
|
682
|
|
|
'append' => 'px', |
|
683
|
|
|
'wrapper' => array( |
|
684
|
|
|
'data-append' => 'min_width' |
|
685
|
|
|
) |
|
686
|
|
|
)); |
|
687
|
|
|
|
|
688
|
|
|
acf_render_field_setting( $field, array( |
|
689
|
|
|
'label' => '', |
|
690
|
|
|
'type' => 'text', |
|
691
|
|
|
'name' => 'min_size', |
|
692
|
|
|
'prepend' => __('File size', 'acf'), |
|
693
|
|
|
'append' => 'MB', |
|
694
|
|
|
'wrapper' => array( |
|
695
|
|
|
'data-append' => 'min_width' |
|
696
|
|
|
) |
|
697
|
|
|
)); |
|
698
|
|
|
|
|
699
|
|
|
|
|
700
|
|
|
// max |
|
701
|
|
|
acf_render_field_setting( $field, array( |
|
702
|
|
|
'label' => __('Maximum','acf'), |
|
703
|
|
|
'instructions' => __('Restrict which images can be uploaded','acf'), |
|
704
|
|
|
'type' => 'text', |
|
705
|
|
|
'name' => 'max_width', |
|
706
|
|
|
'prepend' => __('Width', 'acf'), |
|
707
|
|
|
'append' => 'px', |
|
708
|
|
|
)); |
|
709
|
|
|
|
|
710
|
|
|
acf_render_field_setting( $field, array( |
|
711
|
|
|
'label' => '', |
|
712
|
|
|
'type' => 'text', |
|
713
|
|
|
'name' => 'max_height', |
|
714
|
|
|
'prepend' => __('Height', 'acf'), |
|
715
|
|
|
'append' => 'px', |
|
716
|
|
|
'wrapper' => array( |
|
717
|
|
|
'data-append' => 'max_width' |
|
718
|
|
|
) |
|
719
|
|
|
)); |
|
720
|
|
|
|
|
721
|
|
|
acf_render_field_setting( $field, array( |
|
722
|
|
|
'label' => '', |
|
723
|
|
|
'type' => 'text', |
|
724
|
|
|
'name' => 'max_size', |
|
725
|
|
|
'prepend' => __('File size', 'acf'), |
|
726
|
|
|
'append' => 'MB', |
|
727
|
|
|
'wrapper' => array( |
|
728
|
|
|
'data-append' => 'max_width' |
|
729
|
|
|
) |
|
730
|
|
|
)); |
|
731
|
|
|
|
|
732
|
|
|
|
|
733
|
|
|
// allowed type |
|
734
|
|
|
acf_render_field_setting( $field, array( |
|
735
|
|
|
'label' => __('Allowed file types','acf'), |
|
736
|
|
|
'instructions' => __('Comma separated list. Leave blank for all types','acf'), |
|
737
|
|
|
'type' => 'text', |
|
738
|
|
|
'name' => 'mime_types', |
|
739
|
|
|
)); |
|
740
|
|
|
|
|
741
|
|
|
} |
|
742
|
|
|
|
|
743
|
|
|
|
|
744
|
|
|
/* |
|
745
|
|
|
* format_value() |
|
746
|
|
|
* |
|
747
|
|
|
* This filter is appied to the $value after it is loaded from the db and before it is returned to the template |
|
748
|
|
|
* |
|
749
|
|
|
* @type filter |
|
750
|
|
|
* @since 3.6 |
|
751
|
|
|
* @date 23/01/13 |
|
752
|
|
|
* |
|
753
|
|
|
* @param $value (mixed) the value which was loaded from the database |
|
754
|
|
|
* @param $post_id (mixed) the $post_id from which the value was loaded |
|
755
|
|
|
* @param $field (array) the field array holding all the field options |
|
756
|
|
|
* |
|
757
|
|
|
* @return $value (mixed) the modified value |
|
758
|
|
|
*/ |
|
|
|
|
|
|
759
|
|
|
|
|
760
|
|
|
function format_value( $value, $post_id, $field ) { |
|
|
|
|
|
|
761
|
|
|
|
|
762
|
|
|
// bail early if no value |
|
763
|
|
|
if( empty($value) ) { |
|
764
|
|
|
|
|
765
|
|
|
// return false as $value may be '' (from DB) which doesn't make much sense |
|
766
|
|
|
return false; |
|
767
|
|
|
|
|
768
|
|
|
} |
|
769
|
|
|
|
|
770
|
|
|
|
|
771
|
|
|
// get posts |
|
772
|
|
|
$posts = acf_get_posts(array( |
|
773
|
|
|
'post_type' => 'attachment', |
|
774
|
|
|
'post__in' => $value, |
|
775
|
|
|
)); |
|
776
|
|
|
|
|
777
|
|
|
|
|
778
|
|
|
|
|
779
|
|
|
// update value to include $post |
|
780
|
|
|
foreach( array_keys($posts) as $i ) { |
|
781
|
|
|
|
|
782
|
|
|
$posts[ $i ] = acf_get_attachment( $posts[ $i ] ); |
|
783
|
|
|
|
|
784
|
|
|
} |
|
785
|
|
|
|
|
786
|
|
|
|
|
787
|
|
|
// return |
|
788
|
|
|
return $posts; |
|
789
|
|
|
|
|
790
|
|
|
} |
|
791
|
|
|
|
|
792
|
|
|
|
|
793
|
|
|
/* |
|
794
|
|
|
* validate_value |
|
795
|
|
|
* |
|
796
|
|
|
* description |
|
797
|
|
|
* |
|
798
|
|
|
* @type function |
|
799
|
|
|
* @date 11/02/2014 |
|
800
|
|
|
* @since 5.0.0 |
|
801
|
|
|
* |
|
802
|
|
|
* @param $post_id (int) |
|
803
|
|
|
* @return $post_id (int) |
|
804
|
|
|
*/ |
|
|
|
|
|
|
805
|
|
|
|
|
806
|
|
View Code Duplication |
function validate_value( $valid, $value, $field, $input ){ |
|
|
|
|
|
|
807
|
|
|
|
|
808
|
|
|
if( empty($value) || !is_array($value) ) { |
|
809
|
|
|
|
|
810
|
|
|
$value = array(); |
|
811
|
|
|
|
|
812
|
|
|
} |
|
813
|
|
|
|
|
814
|
|
|
|
|
815
|
|
|
if( count($value) < $field['min'] ) { |
|
816
|
|
|
|
|
817
|
|
|
$valid = _n( '%s requires at least %s selection', '%s requires at least %s selections', $field['min'], 'acf' ); |
|
818
|
|
|
$valid = sprintf( $valid, $field['label'], $field['min'] ); |
|
819
|
|
|
|
|
820
|
|
|
} |
|
821
|
|
|
|
|
822
|
|
|
|
|
823
|
|
|
return $valid; |
|
824
|
|
|
|
|
825
|
|
|
} |
|
826
|
|
|
|
|
827
|
|
|
|
|
828
|
|
|
} |
|
829
|
|
|
|
|
830
|
|
|
new acf_field_gallery(); |
|
831
|
|
|
|
|
832
|
|
|
endif; |
|
833
|
|
|
|
|
834
|
|
|
?> |
|
835
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.