|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* ACF Page Link Field Class |
|
5
|
|
|
* |
|
6
|
|
|
* All the logic for this field type |
|
7
|
|
|
* |
|
8
|
|
|
* @class acf_field_page_link |
|
9
|
|
|
* @extends acf_field |
|
10
|
|
|
* @package ACF |
|
11
|
|
|
* @subpackage Fields |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
if( ! class_exists('acf_field_page_link') ) : |
|
15
|
|
|
|
|
16
|
|
|
class acf_field_page_link 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
|
|
View Code Duplication |
function __construct() { |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
// vars |
|
35
|
|
|
$this->name = 'page_link'; |
|
36
|
|
|
$this->label = __("Page Link",'acf'); |
|
|
|
|
|
|
37
|
|
|
$this->category = 'relational'; |
|
38
|
|
|
$this->defaults = array( |
|
39
|
|
|
'post_type' => array(), |
|
40
|
|
|
'taxonomy' => array(), |
|
41
|
|
|
'allow_null' => 0, |
|
42
|
|
|
'multiple' => 0, |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
// extra |
|
47
|
|
|
add_action('wp_ajax_acf/fields/page_link/query', array($this, 'ajax_query')); |
|
48
|
|
|
add_action('wp_ajax_nopriv_acf/fields/page_link/query', array($this, 'ajax_query')); |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
// do not delete! |
|
52
|
|
|
parent::__construct(); |
|
53
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/* |
|
58
|
|
|
* get_choices |
|
59
|
|
|
* |
|
60
|
|
|
* This function will return an array of data formatted for use in a select2 AJAX response |
|
61
|
|
|
* |
|
62
|
|
|
* @type function |
|
63
|
|
|
* @date 15/10/2014 |
|
64
|
|
|
* @since 5.0.9 |
|
65
|
|
|
* |
|
66
|
|
|
* @param $options (array) |
|
67
|
|
|
* @return (array) |
|
68
|
|
|
*/ |
|
69
|
|
|
|
|
70
|
|
|
function get_choices( $options = array() ) { |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
// defaults |
|
73
|
|
|
$options = acf_parse_args($options, array( |
|
74
|
|
|
'post_id' => 0, |
|
75
|
|
|
's' => '', |
|
76
|
|
|
'lang' => false, |
|
77
|
|
|
'field_key' => '', |
|
78
|
|
|
'paged' => 1 |
|
79
|
|
|
)); |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
// vars |
|
83
|
|
|
$r = array(); |
|
84
|
|
|
$args = array(); |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
// paged |
|
88
|
|
|
$args['posts_per_page'] = 20; |
|
89
|
|
|
$args['paged'] = $options['paged']; |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
// load field |
|
93
|
|
|
$field = acf_get_field( $options['field_key'] ); |
|
94
|
|
|
|
|
95
|
|
|
if( !$field ) { |
|
96
|
|
|
|
|
97
|
|
|
return false; |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
// update $args |
|
103
|
|
View Code Duplication |
if( !empty($field['post_type']) ) { |
|
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
$args['post_type'] = acf_get_array( $field['post_type'] ); |
|
106
|
|
|
|
|
107
|
|
|
} else { |
|
108
|
|
|
|
|
109
|
|
|
$args['post_type'] = acf_get_post_types(); |
|
110
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
// create tax queries |
|
114
|
|
View Code Duplication |
if( !empty($field['taxonomy']) ) { |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
// append to $args |
|
117
|
|
|
$args['tax_query'] = array(); |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
// decode terms |
|
121
|
|
|
$taxonomies = acf_decode_taxonomy_terms( $field['taxonomy'] ); |
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
// now create the tax queries |
|
125
|
|
|
foreach( $taxonomies as $taxonomy => $terms ) { |
|
126
|
|
|
|
|
127
|
|
|
$args['tax_query'][] = array( |
|
128
|
|
|
'taxonomy' => $taxonomy, |
|
129
|
|
|
'field' => 'slug', |
|
130
|
|
|
'terms' => $terms, |
|
131
|
|
|
); |
|
132
|
|
|
|
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
// search |
|
138
|
|
|
if( $options['s'] ) { |
|
139
|
|
|
|
|
140
|
|
|
$args['s'] = $options['s']; |
|
141
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
// filters |
|
146
|
|
|
$args = apply_filters('acf/fields/page_link/query', $args, $field, $options['post_id']); |
|
147
|
|
|
$args = apply_filters('acf/fields/page_link/query/name=' . $field['name'], $args, $field, $options['post_id'] ); |
|
148
|
|
|
$args = apply_filters('acf/fields/page_link/query/key=' . $field['key'], $args, $field, $options['post_id'] ); |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
// add archives to $r |
|
152
|
|
|
if( $args['paged'] == 1 ) { |
|
153
|
|
|
|
|
154
|
|
|
$archives = array(); |
|
155
|
|
|
$archives[] = array( |
|
156
|
|
|
'id' => home_url(), |
|
157
|
|
|
'text' => home_url() |
|
158
|
|
|
); |
|
159
|
|
|
|
|
160
|
|
|
foreach( $args['post_type'] as $post_type ) { |
|
161
|
|
|
|
|
162
|
|
|
$archive_link = get_post_type_archive_link( $post_type ); |
|
163
|
|
|
|
|
164
|
|
|
if( $archive_link ) { |
|
165
|
|
|
|
|
166
|
|
|
$archives[] = array( |
|
167
|
|
|
'id' => $archive_link, |
|
168
|
|
|
'text' => $archive_link |
|
169
|
|
|
); |
|
170
|
|
|
|
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
// search |
|
177
|
|
|
if( !empty($args['s']) ) { |
|
178
|
|
|
|
|
179
|
|
|
foreach( array_keys($archives) as $i ) { |
|
180
|
|
|
|
|
181
|
|
|
if( strpos( $archives[$i]['text'], $args['s'] ) === false ) { |
|
182
|
|
|
|
|
183
|
|
|
unset($archives[$i]); |
|
184
|
|
|
|
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
$archives = array_values($archives); |
|
190
|
|
|
|
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
if( !empty($archives) ) { |
|
195
|
|
|
|
|
196
|
|
|
$r[] = array( |
|
197
|
|
|
'text' => __('Archives', 'acf'), |
|
198
|
|
|
'children' => $archives |
|
199
|
|
|
); |
|
200
|
|
|
|
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
// get posts grouped by post type |
|
207
|
|
|
$groups = acf_get_grouped_posts( $args ); |
|
208
|
|
|
|
|
209
|
|
|
if( !empty($groups) ) { |
|
210
|
|
|
|
|
211
|
|
|
foreach( array_keys($groups) as $group_title ) { |
|
212
|
|
|
|
|
213
|
|
|
// vars |
|
214
|
|
|
$posts = acf_extract_var( $groups, $group_title ); |
|
215
|
|
|
$titles = array(); |
|
|
|
|
|
|
216
|
|
|
|
|
217
|
|
|
|
|
218
|
|
|
// data |
|
219
|
|
|
$data = array( |
|
220
|
|
|
'text' => $group_title, |
|
221
|
|
|
'children' => array() |
|
222
|
|
|
); |
|
223
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
foreach( array_keys($posts) as $post_id ) { |
|
226
|
|
|
|
|
227
|
|
|
// override data |
|
228
|
|
|
$posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'] ); |
|
229
|
|
|
|
|
230
|
|
|
}; |
|
231
|
|
|
|
|
232
|
|
|
|
|
233
|
|
|
// order by search |
|
234
|
|
|
if( !empty($args['s']) ) { |
|
235
|
|
|
|
|
236
|
|
|
$posts = acf_order_by_search( $posts, $args['s'] ); |
|
237
|
|
|
|
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
|
|
241
|
|
|
// append to $data |
|
242
|
|
|
foreach( array_keys($posts) as $post_id ) { |
|
243
|
|
|
|
|
244
|
|
|
$data['children'][] = array( |
|
245
|
|
|
'id' => $post_id, |
|
246
|
|
|
'text' => $posts[ $post_id ] |
|
247
|
|
|
); |
|
248
|
|
|
|
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
|
|
252
|
|
|
// append to $r |
|
253
|
|
|
$r[] = $data; |
|
254
|
|
|
|
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
|
|
260
|
|
|
// return |
|
261
|
|
|
return $r; |
|
262
|
|
|
|
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
|
|
266
|
|
|
/* |
|
267
|
|
|
* ajax_query |
|
268
|
|
|
* |
|
269
|
|
|
* description |
|
270
|
|
|
* |
|
271
|
|
|
* @type function |
|
272
|
|
|
* @date 24/10/13 |
|
273
|
|
|
* @since 5.0.0 |
|
274
|
|
|
* |
|
275
|
|
|
* @param $post_id (int) |
|
276
|
|
|
* @return $post_id (int) |
|
277
|
|
|
*/ |
|
|
|
|
|
|
278
|
|
|
|
|
279
|
|
View Code Duplication |
function ajax_query() { |
|
|
|
|
|
|
280
|
|
|
|
|
281
|
|
|
// validate |
|
282
|
|
|
if( !acf_verify_ajax() ) { |
|
283
|
|
|
|
|
284
|
|
|
die(); |
|
285
|
|
|
|
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
|
|
289
|
|
|
// get choices |
|
290
|
|
|
$choices = $this->get_choices( $_POST ); |
|
291
|
|
|
|
|
292
|
|
|
|
|
293
|
|
|
// validate |
|
294
|
|
|
if( !$choices ) { |
|
295
|
|
|
|
|
296
|
|
|
die(); |
|
297
|
|
|
|
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
|
|
301
|
|
|
// return JSON |
|
302
|
|
|
echo json_encode( $choices ); |
|
303
|
|
|
die(); |
|
304
|
|
|
|
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
|
|
308
|
|
|
/* |
|
309
|
|
|
* get_post_title |
|
310
|
|
|
* |
|
311
|
|
|
* This function returns the HTML for a result |
|
312
|
|
|
* |
|
313
|
|
|
* @type function |
|
314
|
|
|
* @date 1/11/2013 |
|
315
|
|
|
* @since 5.0.0 |
|
316
|
|
|
* |
|
317
|
|
|
* @param $post (object) |
|
318
|
|
|
* @param $field (array) |
|
319
|
|
|
* @param $post_id (int) the post_id to which this value is saved to |
|
320
|
|
|
* @return (string) |
|
321
|
|
|
*/ |
|
322
|
|
|
|
|
323
|
|
View Code Duplication |
function get_post_title( $post, $field, $post_id = 0 ) { |
|
|
|
|
|
|
324
|
|
|
|
|
325
|
|
|
// get post_id |
|
326
|
|
|
if( !$post_id ) { |
|
327
|
|
|
|
|
328
|
|
|
$form_data = acf_get_setting('form_data'); |
|
329
|
|
|
|
|
330
|
|
|
if( !empty($form_data['post_id']) ) { |
|
331
|
|
|
|
|
332
|
|
|
$post_id = $form_data['post_id']; |
|
333
|
|
|
|
|
334
|
|
|
} else { |
|
335
|
|
|
|
|
336
|
|
|
$post_id = get_the_ID(); |
|
337
|
|
|
|
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
|
|
343
|
|
|
// vars |
|
344
|
|
|
$title = acf_get_post_title( $post ); |
|
345
|
|
|
|
|
346
|
|
|
|
|
347
|
|
|
// filters |
|
348
|
|
|
$title = apply_filters('acf/fields/page_link/result', $title, $post, $field, $post_id); |
|
349
|
|
|
$title = apply_filters('acf/fields/page_link/result/name=' . $field['_name'], $title, $post, $field, $post_id); |
|
350
|
|
|
$title = apply_filters('acf/fields/page_link/result/key=' . $field['key'], $title, $post, $field, $post_id); |
|
351
|
|
|
|
|
352
|
|
|
|
|
353
|
|
|
// return |
|
354
|
|
|
return $title; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
|
|
358
|
|
|
/* |
|
359
|
|
|
* get_posts |
|
360
|
|
|
* |
|
361
|
|
|
* This function will return an array of posts for a given field value |
|
362
|
|
|
* |
|
363
|
|
|
* @type function |
|
364
|
|
|
* @date 13/06/2014 |
|
365
|
|
|
* @since 5.0.0 |
|
366
|
|
|
* |
|
367
|
|
|
* @param $value (array) |
|
368
|
|
|
* @return $value |
|
369
|
|
|
*/ |
|
|
|
|
|
|
370
|
|
|
|
|
371
|
|
|
function get_posts( $value, $field ) { |
|
|
|
|
|
|
372
|
|
|
|
|
373
|
|
|
// force value to array |
|
374
|
|
|
$value = acf_get_array( $value ); |
|
375
|
|
|
|
|
376
|
|
|
|
|
377
|
|
|
// get selected post ID's |
|
378
|
|
|
$post__in = array(); |
|
379
|
|
|
|
|
380
|
|
|
foreach( $value as $k => $v ) { |
|
381
|
|
|
|
|
382
|
|
|
if( is_numeric($v) ) { |
|
383
|
|
|
|
|
384
|
|
|
// append to $post__in |
|
385
|
|
|
$post__in[] = (int) $v; |
|
386
|
|
|
|
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
|
|
392
|
|
|
// bail early if no posts |
|
393
|
|
|
if( empty($post__in) ) { |
|
394
|
|
|
|
|
395
|
|
|
return $value; |
|
396
|
|
|
|
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
|
|
400
|
|
|
// get posts |
|
401
|
|
|
$posts = acf_get_posts(array( |
|
402
|
|
|
'post__in' => $post__in, |
|
403
|
|
|
'post_type' => $field['post_type'] |
|
404
|
|
|
)); |
|
405
|
|
|
|
|
406
|
|
|
|
|
407
|
|
|
// override value with post |
|
408
|
|
|
$return = array(); |
|
409
|
|
|
|
|
410
|
|
|
|
|
411
|
|
|
// append to $return |
|
412
|
|
|
foreach( $value as $k => $v ) { |
|
413
|
|
|
|
|
414
|
|
|
if( is_numeric($v) ) { |
|
415
|
|
|
|
|
416
|
|
|
// extract first post |
|
417
|
|
|
$post = array_shift( $posts ); |
|
418
|
|
|
|
|
419
|
|
|
|
|
420
|
|
|
// append |
|
421
|
|
|
if( $post ) { |
|
422
|
|
|
|
|
423
|
|
|
$return[] = $post; |
|
424
|
|
|
|
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
} else { |
|
428
|
|
|
|
|
429
|
|
|
$return[] = $v; |
|
430
|
|
|
|
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
|
|
|
|
436
|
|
|
// return |
|
437
|
|
|
return $return; |
|
438
|
|
|
|
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
|
|
442
|
|
|
/* |
|
443
|
|
|
* render_field() |
|
444
|
|
|
* |
|
445
|
|
|
* Create the HTML interface for your field |
|
446
|
|
|
* |
|
447
|
|
|
* @param $field - an array holding all the field's data |
|
448
|
|
|
* |
|
449
|
|
|
* @type action |
|
450
|
|
|
* @since 3.6 |
|
451
|
|
|
* @date 23/01/13 |
|
452
|
|
|
*/ |
|
453
|
|
|
|
|
454
|
|
|
function render_field( $field ){ |
|
|
|
|
|
|
455
|
|
|
|
|
456
|
|
|
// Change Field into a select |
|
457
|
|
|
$field['type'] = 'select'; |
|
458
|
|
|
$field['ui'] = 1; |
|
459
|
|
|
$field['ajax'] = 1; |
|
460
|
|
|
$field['choices'] = array(); |
|
461
|
|
|
|
|
462
|
|
|
|
|
463
|
|
|
// populate choices if value exists |
|
464
|
|
|
if( !empty($field['value']) ) { |
|
465
|
|
|
|
|
466
|
|
|
// get posts |
|
467
|
|
|
$posts = $this->get_posts( $field['value'], $field ); |
|
468
|
|
|
|
|
469
|
|
|
|
|
470
|
|
|
// set choices |
|
471
|
|
View Code Duplication |
if( !empty($posts) ) { |
|
|
|
|
|
|
472
|
|
|
|
|
473
|
|
|
foreach( array_keys($posts) as $i ) { |
|
474
|
|
|
|
|
475
|
|
|
// vars |
|
476
|
|
|
$post = acf_extract_var( $posts, $i ); |
|
477
|
|
|
|
|
478
|
|
|
|
|
479
|
|
|
if( is_object($post) ) { |
|
480
|
|
|
|
|
481
|
|
|
// append to choices |
|
482
|
|
|
$field['choices'][ $post->ID ] = $this->get_post_title( $post, $field ); |
|
483
|
|
|
|
|
484
|
|
|
} else { |
|
485
|
|
|
|
|
486
|
|
|
// append to choices |
|
487
|
|
|
$field['choices'][ $post ] = $post; |
|
488
|
|
|
|
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
|
|
498
|
|
|
// render |
|
499
|
|
|
acf_render_field( $field ); |
|
|
|
|
|
|
500
|
|
|
} |
|
501
|
|
|
|
|
502
|
|
|
|
|
503
|
|
|
/* |
|
504
|
|
|
* render_field_settings() |
|
505
|
|
|
* |
|
506
|
|
|
* Create extra options for your field. This is rendered when editing a field. |
|
507
|
|
|
* The value of $field['name'] can be used (like bellow) to save extra data to the $field |
|
508
|
|
|
* |
|
509
|
|
|
* @type action |
|
510
|
|
|
* @since 3.6 |
|
511
|
|
|
* @date 23/01/13 |
|
512
|
|
|
* |
|
513
|
|
|
* @param $field - an array holding all the field's data |
|
514
|
|
|
*/ |
|
515
|
|
|
|
|
516
|
|
|
function render_field_settings( $field ) { |
|
|
|
|
|
|
517
|
|
|
|
|
518
|
|
|
// post_type |
|
519
|
|
|
acf_render_field_setting( $field, array( |
|
520
|
|
|
'label' => __('Filter by Post Type','acf'), |
|
521
|
|
|
'instructions' => '', |
|
522
|
|
|
'type' => 'select', |
|
523
|
|
|
'name' => 'post_type', |
|
524
|
|
|
'choices' => acf_get_pretty_post_types(), |
|
525
|
|
|
'multiple' => 1, |
|
526
|
|
|
'ui' => 1, |
|
527
|
|
|
'allow_null' => 1, |
|
528
|
|
|
'placeholder' => __("All post types",'acf'), |
|
529
|
|
|
)); |
|
530
|
|
|
|
|
531
|
|
|
|
|
532
|
|
|
// taxonomy |
|
533
|
|
|
acf_render_field_setting( $field, array( |
|
534
|
|
|
'label' => __('Filter by Taxonomy','acf'), |
|
535
|
|
|
'instructions' => '', |
|
536
|
|
|
'type' => 'select', |
|
537
|
|
|
'name' => 'taxonomy', |
|
538
|
|
|
'choices' => acf_get_taxonomy_terms(), |
|
539
|
|
|
'multiple' => 1, |
|
540
|
|
|
'ui' => 1, |
|
541
|
|
|
'allow_null' => 1, |
|
542
|
|
|
'placeholder' => __("All taxonomies",'acf'), |
|
543
|
|
|
)); |
|
544
|
|
|
|
|
545
|
|
|
|
|
546
|
|
|
// allow_null |
|
547
|
|
|
acf_render_field_setting( $field, array( |
|
548
|
|
|
'label' => __('Allow Null?','acf'), |
|
549
|
|
|
'instructions' => '', |
|
550
|
|
|
'type' => 'radio', |
|
551
|
|
|
'name' => 'allow_null', |
|
552
|
|
|
'choices' => array( |
|
553
|
|
|
1 => __("Yes",'acf'), |
|
554
|
|
|
0 => __("No",'acf'), |
|
555
|
|
|
), |
|
556
|
|
|
'layout' => 'horizontal', |
|
557
|
|
|
)); |
|
558
|
|
|
|
|
559
|
|
|
|
|
560
|
|
|
// multiple |
|
561
|
|
|
acf_render_field_setting( $field, array( |
|
562
|
|
|
'label' => __('Select multiple values?','acf'), |
|
563
|
|
|
'instructions' => '', |
|
564
|
|
|
'type' => 'radio', |
|
565
|
|
|
'name' => 'multiple', |
|
566
|
|
|
'choices' => array( |
|
567
|
|
|
1 => __("Yes",'acf'), |
|
568
|
|
|
0 => __("No",'acf'), |
|
569
|
|
|
), |
|
570
|
|
|
'layout' => 'horizontal', |
|
571
|
|
|
)); |
|
572
|
|
|
|
|
573
|
|
|
} |
|
574
|
|
|
|
|
575
|
|
|
|
|
576
|
|
|
/* |
|
577
|
|
|
* format_value() |
|
578
|
|
|
* |
|
579
|
|
|
* This filter is appied to the $value after it is loaded from the db and before it is returned to the template |
|
580
|
|
|
* |
|
581
|
|
|
* @type filter |
|
582
|
|
|
* @since 3.6 |
|
583
|
|
|
* @date 23/01/13 |
|
584
|
|
|
* |
|
585
|
|
|
* @param $value (mixed) the value which was loaded from the database |
|
586
|
|
|
* @param $post_id (mixed) the $post_id from which the value was loaded |
|
587
|
|
|
* @param $field (array) the field array holding all the field options |
|
588
|
|
|
* |
|
589
|
|
|
* @return $value (mixed) the modified value |
|
590
|
|
|
*/ |
|
|
|
|
|
|
591
|
|
|
|
|
592
|
|
|
function format_value( $value, $post_id, $field ) { |
|
|
|
|
|
|
593
|
|
|
|
|
594
|
|
|
// ACF4 null |
|
595
|
|
|
if( $value === 'null' ) { |
|
596
|
|
|
|
|
597
|
|
|
return false; |
|
598
|
|
|
|
|
599
|
|
|
} |
|
600
|
|
|
|
|
601
|
|
|
|
|
602
|
|
|
// bail early if no value |
|
603
|
|
|
if( empty($value) ) { |
|
604
|
|
|
|
|
605
|
|
|
return $value; |
|
606
|
|
|
|
|
607
|
|
|
} |
|
608
|
|
|
|
|
609
|
|
|
|
|
610
|
|
|
// get posts |
|
611
|
|
|
$value = $this->get_posts( $value, $field ); |
|
612
|
|
|
|
|
613
|
|
|
|
|
614
|
|
|
// set choices |
|
615
|
|
|
foreach( array_keys($value) as $i ) { |
|
616
|
|
|
|
|
617
|
|
|
// vars |
|
618
|
|
|
$post = acf_extract_var( $value, $i ); |
|
619
|
|
|
|
|
620
|
|
|
|
|
621
|
|
|
// convert $post to permalink |
|
622
|
|
|
if( is_object($post) ) { |
|
623
|
|
|
|
|
624
|
|
|
$post = get_permalink( $post ); |
|
625
|
|
|
|
|
626
|
|
|
} |
|
627
|
|
|
|
|
628
|
|
|
|
|
629
|
|
|
// append back to $value |
|
630
|
|
|
$value[ $i ] = $post; |
|
631
|
|
|
|
|
632
|
|
|
} |
|
633
|
|
|
|
|
634
|
|
|
|
|
635
|
|
|
// convert back from array if neccessary |
|
636
|
|
|
if( !$field['multiple'] ) { |
|
637
|
|
|
|
|
638
|
|
|
$value = array_shift($value); |
|
639
|
|
|
|
|
640
|
|
|
} |
|
641
|
|
|
|
|
642
|
|
|
|
|
643
|
|
|
// return value |
|
644
|
|
|
return $value; |
|
645
|
|
|
|
|
646
|
|
|
} |
|
647
|
|
|
|
|
648
|
|
|
|
|
649
|
|
|
/* |
|
650
|
|
|
* update_value() |
|
651
|
|
|
* |
|
652
|
|
|
* This filter is appied to the $value before it is updated in the db |
|
653
|
|
|
* |
|
654
|
|
|
* @type filter |
|
655
|
|
|
* @since 3.6 |
|
656
|
|
|
* @date 23/01/13 |
|
657
|
|
|
* |
|
658
|
|
|
* @param $value - the value which will be saved in the database |
|
659
|
|
|
* @param $post_id - the $post_id of which the value will be saved |
|
660
|
|
|
* @param $field - the field array holding all the field options |
|
661
|
|
|
* |
|
662
|
|
|
* @return $value - the modified value |
|
663
|
|
|
*/ |
|
|
|
|
|
|
664
|
|
|
|
|
665
|
|
View Code Duplication |
function update_value( $value, $post_id, $field ) { |
|
|
|
|
|
|
666
|
|
|
|
|
667
|
|
|
// validate |
|
668
|
|
|
if( empty($value) ) { |
|
669
|
|
|
|
|
670
|
|
|
return $value; |
|
671
|
|
|
|
|
672
|
|
|
} |
|
673
|
|
|
|
|
674
|
|
|
|
|
675
|
|
|
// format |
|
676
|
|
|
if( is_array($value) ) { |
|
677
|
|
|
|
|
678
|
|
|
// array |
|
679
|
|
|
foreach( $value as $k => $v ){ |
|
680
|
|
|
|
|
681
|
|
|
// object? |
|
682
|
|
|
if( is_object($v) && isset($v->ID) ) |
|
683
|
|
|
{ |
|
684
|
|
|
$value[ $k ] = $v->ID; |
|
685
|
|
|
} |
|
686
|
|
|
} |
|
687
|
|
|
|
|
688
|
|
|
|
|
689
|
|
|
// save value as strings, so we can clearly search for them in SQL LIKE statements |
|
690
|
|
|
$value = array_map('strval', $value); |
|
691
|
|
|
|
|
692
|
|
|
} elseif( is_object($value) && isset($value->ID) ) { |
|
693
|
|
|
|
|
694
|
|
|
// object |
|
695
|
|
|
$value = $value->ID; |
|
696
|
|
|
|
|
697
|
|
|
} |
|
698
|
|
|
|
|
699
|
|
|
|
|
700
|
|
|
// return |
|
701
|
|
|
return $value; |
|
702
|
|
|
|
|
703
|
|
|
} |
|
704
|
|
|
|
|
705
|
|
|
} |
|
706
|
|
|
|
|
707
|
|
|
new acf_field_page_link(); |
|
708
|
|
|
|
|
709
|
|
|
endif; |
|
710
|
|
|
|
|
711
|
|
|
?> |
|
|
|
|
|
|
712
|
|
|
|
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.