1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package Pods\Fields |
4
|
|
|
*/ |
5
|
|
|
class PodsField_Pick extends PodsField { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Field Type Group |
9
|
|
|
* |
10
|
|
|
* @var string |
11
|
|
|
* @since 2.0 |
12
|
|
|
*/ |
13
|
|
|
public static $group = 'Relationships / Media'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Field Type Identifier |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
* @since 2.0 |
20
|
|
|
*/ |
21
|
|
|
public static $type = 'pick'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Field Type Label |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
* @since 2.0 |
28
|
|
|
*/ |
29
|
|
|
public static $label = 'Relationship'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Available Related Objects |
33
|
|
|
* |
34
|
|
|
* @var array |
35
|
|
|
* @since 2.3 |
36
|
|
|
*/ |
37
|
|
|
public static $related_objects = array(); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Custom Related Objects |
41
|
|
|
* |
42
|
|
|
* @var array |
43
|
|
|
* @since 2.3 |
44
|
|
|
*/ |
45
|
|
|
public static $custom_related_objects = array(); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Data used during validate / save to avoid extra queries |
49
|
|
|
* |
50
|
|
|
* @var array |
51
|
|
|
* @since 2.3 |
52
|
|
|
*/ |
53
|
|
|
public static $related_data = array(); |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Data used during input method (mainly for autocomplete) |
57
|
|
|
* |
58
|
|
|
* @var array |
59
|
|
|
* @since 2.3 |
60
|
|
|
*/ |
61
|
|
|
public static $field_data = array(); |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* API caching for fields that need it during validate/save |
65
|
|
|
* |
66
|
|
|
* @var \PodsAPI |
67
|
|
|
* @since 2.3 |
68
|
|
|
*/ |
69
|
|
|
protected static $api = false; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Saved array of simple relationship names |
73
|
|
|
* |
74
|
|
|
* @var array |
75
|
|
|
* @since 2.5 |
76
|
|
|
*/ |
77
|
|
|
private static $names_simple = null; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Saved array of relationship names |
81
|
|
|
* |
82
|
|
|
* @var array |
83
|
|
|
* @since 2.5 |
84
|
|
|
*/ |
85
|
|
|
private static $names_related = null; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Saved array of bidirectional relationship names |
89
|
|
|
* |
90
|
|
|
* @var array |
91
|
|
|
* @since 2.5 |
92
|
|
|
*/ |
93
|
|
|
private static $names_bidirectional = null; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Setup related objects list |
97
|
|
|
* |
98
|
|
|
* @since 2.0 |
99
|
|
|
*/ |
100
|
|
|
public function __construct () { |
101
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Add admin_init actions |
106
|
|
|
* |
107
|
|
|
* @since 2.3 |
108
|
|
|
*/ |
109
|
|
|
public function admin_init () { |
110
|
|
|
// AJAX for Relationship lookups |
111
|
|
|
add_action( 'wp_ajax_pods_relationship', array( $this, 'admin_ajax_relationship' ) ); |
112
|
|
|
add_action( 'wp_ajax_nopriv_pods_relationship', array( $this, 'admin_ajax_relationship' ) ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Add options and set defaults to |
117
|
|
|
* |
118
|
|
|
* @return array |
119
|
|
|
* |
120
|
|
|
* @since 2.0 |
121
|
|
|
*/ |
122
|
|
|
public function options () { |
123
|
|
|
$options = array( |
124
|
|
|
self::$type . '_format_type' => array( |
125
|
|
|
'label' => __( 'Selection Type', 'pods' ), |
126
|
|
|
'help' => __( 'help', 'pods' ), |
127
|
|
|
'default' => 'single', |
128
|
|
|
'type' => 'pick', |
129
|
|
|
'data' => array( |
130
|
|
|
'single' => __( 'Single Select', 'pods' ), |
131
|
|
|
'multi' => __( 'Multiple Select', 'pods' ) |
132
|
|
|
), |
133
|
|
|
'dependency' => true |
134
|
|
|
), |
135
|
|
|
self::$type . '_format_single' => array( |
136
|
|
|
'label' => __( 'Format', 'pods' ), |
137
|
|
|
'help' => __( 'help', 'pods' ), |
138
|
|
|
'depends-on' => array( self::$type . '_format_type' => 'single' ), |
139
|
|
|
'default' => 'dropdown', |
140
|
|
|
'type' => 'pick', |
141
|
|
|
'data' => apply_filters( |
142
|
|
|
'pods_form_ui_field_pick_format_single_options', |
143
|
|
|
array( |
144
|
|
|
'dropdown' => __( 'Drop Down', 'pods' ), |
145
|
|
|
'radio' => __( 'Radio Buttons', 'pods' ), |
146
|
|
|
'autocomplete' => __( 'Autocomplete', 'pods' ) |
147
|
|
|
) + ( ( pods_developer() ) ? array( 'flexible' => __( 'Flexible', 'pods' ) ) : array() ) |
148
|
|
|
), |
149
|
|
|
'dependency' => true |
150
|
|
|
), |
151
|
|
|
self::$type . '_format_multi' => array( |
152
|
|
|
'label' => __( 'Format', 'pods' ), |
153
|
|
|
'help' => __( 'help', 'pods' ), |
154
|
|
|
'depends-on' => array( self::$type . '_format_type' => 'multi' ), |
155
|
|
|
'default' => 'checkbox', |
156
|
|
|
'type' => 'pick', |
157
|
|
|
'data' => apply_filters( |
158
|
|
|
'pods_form_ui_field_pick_format_multi_options', |
159
|
|
|
array( |
160
|
|
|
'checkbox' => __( 'Checkboxes', 'pods' ), |
161
|
|
|
'multiselect' => __( 'Multi Select', 'pods' ), |
162
|
|
|
'autocomplete' => __( 'Autocomplete', 'pods' ) |
163
|
|
|
) + ( ( pods_developer() ) ? array( 'flexible' => __( 'Flexible', 'pods' ) ) : array() ) |
164
|
|
|
), |
165
|
|
|
'dependency' => true |
166
|
|
|
), |
167
|
|
|
self::$type . '_taggable' => array( |
168
|
|
|
'label' => __( 'Taggable', 'pods' ), |
169
|
|
|
'help' => __( 'Allow new values to be inserted when using an Autocomplete field', 'pods' ), |
170
|
|
|
'excludes-on' => array( |
171
|
|
|
self::$type . '_format_single' => array( 'dropdown', 'radio' ), |
172
|
|
|
self::$type . '_format_multi' => array( 'checkbox', 'multiselect' ), |
173
|
|
|
self::$type . '_object' => array_merge( |
174
|
|
|
array( 'site', 'network' ), |
175
|
|
|
self::simple_objects() |
176
|
|
|
) |
177
|
|
|
), |
178
|
|
|
'type' => 'boolean', |
179
|
|
|
'default' => 0 |
180
|
|
|
), |
181
|
|
|
self::$type . '_select_text' => array( |
182
|
|
|
'label' => __( 'Default Select Text', 'pods' ), |
183
|
|
|
'help' => __( 'This is the text use for the default "no selection" dropdown item, if empty, it will default to "-- Select One --"', 'pods' ), |
184
|
|
|
'depends-on' => array( |
185
|
|
|
self::$type . '_format_type' => 'single', |
186
|
|
|
self::$type . '_format_single' => 'dropdown' |
187
|
|
|
), |
188
|
|
|
'default' => '', |
189
|
|
|
'type' => 'text' |
190
|
|
|
), |
191
|
|
|
self::$type . '_limit' => array( |
192
|
|
|
'label' => __( 'Selection Limit', 'pods' ), |
193
|
|
|
'help' => __( 'help', 'pods' ), |
194
|
|
|
'depends-on' => array( self::$type . '_format_type' => 'multi' ), |
195
|
|
|
'default' => 0, |
196
|
|
|
'type' => 'number' |
197
|
|
|
), |
198
|
|
|
self::$type . '_allow_html' => array( |
199
|
|
|
'label' => __('Allow HTML','pods'), |
200
|
|
|
'type' => 'boolean', |
201
|
|
|
'default' => 0 |
202
|
|
|
), |
203
|
|
|
self::$type . '_table_id' => array( |
204
|
|
|
'label' => __( 'Table ID Column', 'pods' ), |
205
|
|
|
'help' => __( 'You must provide the ID column name for the table, this will be used to keep track of the relationship', 'pods' ), |
206
|
|
|
'depends-on' => array( self::$type . '_object' => 'table' ), |
207
|
|
|
'required' => 1, |
208
|
|
|
'default' => '', |
209
|
|
|
'type' => 'text' |
210
|
|
|
), |
211
|
|
|
self::$type . '_table_index' => array( |
212
|
|
|
'label' => __( 'Table Index Column', 'pods' ), |
213
|
|
|
'help' => __( 'You must provide the index column name for the table, this may optionally also be the ID column name', 'pods' ), |
214
|
|
|
'depends-on' => array( self::$type . '_object' => 'table' ), |
215
|
|
|
'required' => 1, |
216
|
|
|
'default' => '', |
217
|
|
|
'type' => 'text' |
218
|
|
|
), |
219
|
|
|
self::$type . '_display' => array( |
220
|
|
|
'label' => __( 'Display Field in Selection List', 'pods' ), |
221
|
|
|
'help' => __( 'Provide the name of a field on the related object to reference, example: {@post_title}', 'pods' ), |
222
|
|
|
'excludes-on' => array( |
223
|
|
|
self::$type . '_object' => array_merge( |
224
|
|
|
array( 'site', 'network' ), |
225
|
|
|
self::simple_objects() |
226
|
|
|
) |
227
|
|
|
), |
228
|
|
|
'default' => '', |
229
|
|
|
'type' => 'text' |
230
|
|
|
), |
231
|
|
|
self::$type . '_user_role' => array( |
232
|
|
|
'label' => __( 'Limit list to Role(s)', 'pods' ), |
233
|
|
|
'help' => __( 'help', 'pods' ), |
234
|
|
|
'depends-on' => array( self::$type . '_object' => 'user' ), |
235
|
|
|
'default' => '', |
236
|
|
|
'type' => 'pick', |
237
|
|
|
'pick_object' => 'role', |
238
|
|
|
'pick_format_type' => 'multi' |
239
|
|
|
),/* |
|
|
|
|
240
|
|
|
self::$type . '_user_site' => array( |
241
|
|
|
'label' => __( 'Limit list to Site(s)', 'pods' ), |
242
|
|
|
'help' => __( 'help', 'pods' ), |
243
|
|
|
'depends-on' => array( self::$type . '_object' => 'user' ), |
244
|
|
|
'default' => '', |
245
|
|
|
'type' => 'pick', |
246
|
|
|
'pick_object' => 'site', |
247
|
|
|
'pick_format_type' => 'multi' |
248
|
|
|
),*/ |
249
|
|
|
self::$type . '_where' => array( |
250
|
|
|
'label' => __( 'Customized <em>WHERE</em>', 'pods' ), |
251
|
|
|
'help' => __( 'help', 'pods' ), |
252
|
|
|
'excludes-on' => array( |
253
|
|
|
self::$type . '_object' => array_merge( |
254
|
|
|
array( 'site', 'network' ), |
255
|
|
|
self::simple_objects() |
256
|
|
|
) |
257
|
|
|
), |
258
|
|
|
'default' => '', |
259
|
|
|
'type' => 'text' |
260
|
|
|
), |
261
|
|
|
self::$type . '_orderby' => array( |
262
|
|
|
'label' => __( 'Customized <em>ORDER BY</em>', 'pods' ), |
263
|
|
|
'help' => __( 'help', 'pods' ), |
264
|
|
|
'excludes-on' => array( |
265
|
|
|
self::$type . '_object' => array_merge( |
266
|
|
|
array( 'site', 'network' ), |
267
|
|
|
self::simple_objects() |
268
|
|
|
) |
269
|
|
|
), |
270
|
|
|
'default' => '', |
271
|
|
|
'type' => 'text' |
272
|
|
|
), |
273
|
|
|
self::$type . '_groupby' => array( |
274
|
|
|
'label' => __( 'Customized <em>GROUP BY</em>', 'pods' ), |
275
|
|
|
'help' => __( 'help', 'pods' ), |
276
|
|
|
'excludes-on' => array( |
277
|
|
|
self::$type . '_object' => array_merge( |
278
|
|
|
array( 'site', 'network' ), |
279
|
|
|
self::simple_objects() |
280
|
|
|
) |
281
|
|
|
), |
282
|
|
|
'default' => '', |
283
|
|
|
'type' => 'text' |
284
|
|
|
) |
285
|
|
|
/*, |
|
|
|
|
286
|
|
|
self::$type . '_size' => array( |
287
|
|
|
'label' => __( 'Field Size', 'pods' ), |
288
|
|
|
'default' => 'medium', |
289
|
|
|
'type' => 'pick', |
290
|
|
|
'data' => array( |
291
|
|
|
'small' => __( 'Small', 'pods' ), |
292
|
|
|
'medium' => __( 'Medium', 'pods' ), |
293
|
|
|
'large' => __( 'Large', 'pods' ) |
294
|
|
|
) |
295
|
|
|
)*/ |
296
|
|
|
); |
297
|
|
|
|
298
|
|
|
/*if ( !is_multisite() ) |
|
|
|
|
299
|
|
|
unset( $options[ self::$type . '_user_site' ] );*/ |
300
|
|
|
|
301
|
|
|
return $options; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Register a related object |
306
|
|
|
* |
307
|
|
|
* @param string $name Object name |
308
|
|
|
* @param string $label Object label |
309
|
|
|
* @param array $options Object options |
310
|
|
|
* |
311
|
|
|
* @return array|boolean Object array or false if unsuccessful |
312
|
|
|
* @since 2.3 |
313
|
|
|
*/ |
314
|
|
|
public function register_related_object ( $name, $label, $options = null ) { |
315
|
|
|
if ( empty( $name ) || empty( $label ) ) |
316
|
|
|
return false; |
317
|
|
|
|
318
|
|
|
$related_object = array( |
319
|
|
|
'label' => $label, |
320
|
|
|
'group' => 'Custom Relationships', |
321
|
|
|
'simple' => true, |
322
|
|
|
'bidirectional' => false, |
323
|
|
|
'data' => array(), |
324
|
|
|
'data_callback' => null |
325
|
|
|
); |
326
|
|
|
|
327
|
|
|
$related_object = array_merge( $related_object, $options ); |
328
|
|
|
|
329
|
|
|
self::$custom_related_objects[ $name ] = $related_object; |
330
|
|
|
|
331
|
|
|
return true; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Setup related objects |
336
|
|
|
* |
337
|
|
|
* @param boolean $force Whether to force refresh of related objects |
338
|
|
|
* @return bool True when data has been loaded |
339
|
|
|
* @since 2.3 |
340
|
|
|
*/ |
341
|
|
|
public function setup_related_objects ( $force = false ) { |
342
|
|
|
$new_data_loaded = false; |
343
|
|
|
|
344
|
|
|
if ( ! $force && empty( self::$related_objects ) ) { |
345
|
|
|
// Only load transient if we aren't forcing a refresh |
346
|
|
|
self::$related_objects = pods_transient_get( 'pods_related_objects' ); |
347
|
|
|
if ( false !== self::$related_objects ) { |
348
|
|
|
$new_data_loaded = true; |
349
|
|
|
} |
350
|
|
|
} elseif ( $force ) { |
351
|
|
|
// If we are rebuilding, make sure we start with a clean slate |
352
|
|
|
self::$related_objects = array(); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
if ( empty( self::$related_objects ) ) { |
356
|
|
|
// Do a complete build of related_objects |
357
|
|
|
$new_data_loaded = true; |
358
|
|
|
|
359
|
|
|
// Custom |
360
|
|
|
self::$related_objects[ 'custom-simple' ] = array( |
361
|
|
|
'label' => __( 'Simple (custom defined list)', 'pods' ), |
362
|
|
|
'group' => __( 'Custom', 'pods' ), |
363
|
|
|
'simple' => true |
364
|
|
|
); |
365
|
|
|
|
366
|
|
|
// Pods |
367
|
|
|
$pod_options = array(); |
368
|
|
|
|
369
|
|
|
// Include PodsMeta if not already included |
370
|
|
|
pods_meta(); |
371
|
|
|
|
372
|
|
|
// Advanced Content Types |
373
|
|
|
$_pods = PodsMeta::$advanced_content_types; |
374
|
|
|
|
375
|
|
View Code Duplication |
foreach ( $_pods as $pod ) { |
376
|
|
|
$pod_options[ $pod[ 'name' ] ] = $pod[ 'label' ] . ' (' . $pod[ 'name' ] . ')'; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
// Settings |
380
|
|
|
$_pods = PodsMeta::$settings; |
381
|
|
|
|
382
|
|
View Code Duplication |
foreach ( $_pods as $pod ) { |
383
|
|
|
$pod_options[ $pod[ 'name' ] ] = $pod[ 'label' ] . ' (' . $pod[ 'name' ] . ')'; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
asort( $pod_options ); |
387
|
|
|
|
388
|
|
|
foreach ( $pod_options as $pod => $label ) { |
389
|
|
|
self::$related_objects[ 'pod-' . $pod ] = array( |
390
|
|
|
'label' => $label, |
391
|
|
|
'group' => __( 'Pods', 'pods' ), |
392
|
|
|
'bidirectional' => true |
393
|
|
|
); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
// Post Types |
397
|
|
|
$post_types = get_post_types(); |
398
|
|
|
asort( $post_types ); |
399
|
|
|
|
400
|
|
|
$ignore = array( 'attachment', 'revision', 'nav_menu_item' ); |
401
|
|
|
|
402
|
|
View Code Duplication |
foreach ( $post_types as $post_type => $label ) { |
403
|
|
|
if ( in_array( $post_type, $ignore ) || empty( $post_type ) ) { |
404
|
|
|
unset( $post_types[ $post_type ] ); |
405
|
|
|
|
406
|
|
|
continue; |
407
|
|
|
} |
408
|
|
|
elseif ( 0 === strpos( $post_type, '_pods_' ) && apply_filters( 'pods_pick_ignore_internal', true ) ) { |
409
|
|
|
unset( $post_types[ $post_type ] ); |
410
|
|
|
|
411
|
|
|
continue; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
$post_type = get_post_type_object( $post_type ); |
415
|
|
|
|
416
|
|
|
self::$related_objects[ 'post_type-' . $post_type->name ] = array( |
417
|
|
|
'label' => $post_type->label . ' (' . $post_type->name . ')', |
418
|
|
|
'group' => __( 'Post Types', 'pods' ), |
419
|
|
|
'bidirectional' => true |
420
|
|
|
); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
// Taxonomies |
424
|
|
|
$taxonomies = get_taxonomies(); |
425
|
|
|
asort( $taxonomies ); |
426
|
|
|
|
427
|
|
|
$ignore = array( 'nav_menu', 'post_format' ); |
428
|
|
|
|
429
|
|
View Code Duplication |
foreach ( $taxonomies as $taxonomy => $label ) { |
430
|
|
|
if ( in_array( $taxonomy, $ignore ) || empty( $taxonomy ) ) { |
431
|
|
|
unset( $taxonomies[ $taxonomy ] ); |
432
|
|
|
|
433
|
|
|
continue; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Prevent ability to extend core Pods content types. |
438
|
|
|
* |
439
|
|
|
* @param bool. Default is true, when set to false Pods internal content types can not be extended. |
440
|
|
|
* |
441
|
|
|
* @since 2.3.19 |
442
|
|
|
*/ |
443
|
|
|
elseif ( 0 === strpos( $taxonomy, '_pods_' ) && apply_filters( 'pods_pick_ignore_internal', true ) ) { |
444
|
|
|
unset( $taxonomies[ $taxonomy ] ); |
445
|
|
|
|
446
|
|
|
continue; |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
$taxonomy = get_taxonomy( $taxonomy ); |
450
|
|
|
|
451
|
|
|
self::$related_objects[ 'taxonomy-' . $taxonomy->name ] = array( |
452
|
|
|
'label' => $taxonomy->label . ' (' . $taxonomy->name . ')', |
453
|
|
|
'group' => __( 'Taxonomies', 'pods' ), |
454
|
|
|
'bidirectional' => true |
455
|
|
|
); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
// Other WP Objects |
459
|
|
|
self::$related_objects[ 'user' ] = array( |
460
|
|
|
'label' => __( 'Users', 'pods' ), |
461
|
|
|
'group' => __( 'Other WP Objects', 'pods' ), |
462
|
|
|
'bidirectional' => true |
463
|
|
|
); |
464
|
|
|
|
465
|
|
|
self::$related_objects[ 'role' ] = array( |
466
|
|
|
'label' => __( 'User Roles', 'pods' ), |
467
|
|
|
'group' => __( 'Other WP Objects', 'pods' ), |
468
|
|
|
'simple' => true, |
469
|
|
|
'data_callback' => array( $this, 'data_roles' ) |
470
|
|
|
); |
471
|
|
|
|
472
|
|
|
self::$related_objects[ 'capability' ] = array( |
473
|
|
|
'label' => __( 'User Capabilities', 'pods' ), |
474
|
|
|
'group' => __( 'Other WP Objects', 'pods' ), |
475
|
|
|
'simple' => true, |
476
|
|
|
'data_callback' => array( $this, 'data_capabilities' ) |
477
|
|
|
); |
478
|
|
|
|
479
|
|
|
self::$related_objects[ 'media' ] = array( |
480
|
|
|
'label' => __( 'Media', 'pods' ), |
481
|
|
|
'group' => __( 'Other WP Objects', 'pods' ), |
482
|
|
|
'bidirectional' => true |
483
|
|
|
); |
484
|
|
|
|
485
|
|
|
self::$related_objects[ 'comment' ] = array( |
486
|
|
|
'label' => __( 'Comments', 'pods' ), |
487
|
|
|
'group' => __( 'Other WP Objects', 'pods' ), |
488
|
|
|
'bidirectional' => true |
489
|
|
|
); |
490
|
|
|
|
491
|
|
|
self::$related_objects[ 'image-size' ] = array( |
492
|
|
|
'label' => __( 'Image Sizes', 'pods' ), |
493
|
|
|
'group' => __( 'Other WP Objects', 'pods' ), |
494
|
|
|
'simple' => true, |
495
|
|
|
'data_callback' => array( $this, 'data_image_sizes' ) |
496
|
|
|
); |
497
|
|
|
|
498
|
|
|
self::$related_objects[ 'nav_menu' ] = array( |
499
|
|
|
'label' => __( 'Navigation Menus', 'pods' ), |
500
|
|
|
'group' => __( 'Other WP Objects', 'pods' ) |
501
|
|
|
); |
502
|
|
|
|
503
|
|
|
self::$related_objects[ 'post_format' ] = array( |
504
|
|
|
'label' => __( 'Post Formats', 'pods' ), |
505
|
|
|
'group' => __( 'Other WP Objects', 'pods' ) |
506
|
|
|
); |
507
|
|
|
|
508
|
|
|
self::$related_objects[ 'post-status' ] = array( |
509
|
|
|
'label' => __( 'Post Status', 'pods' ), |
510
|
|
|
'group' => __( 'Other WP Objects', 'pods' ), |
511
|
|
|
'simple' => true, |
512
|
|
|
'data_callback' => array( $this, 'data_post_stati' ) |
513
|
|
|
); |
514
|
|
|
|
515
|
|
|
do_action( 'pods_form_ui_field_pick_related_objects_other' ); |
516
|
|
|
|
517
|
|
|
self::$related_objects[ 'country' ] = array( |
518
|
|
|
'label' => __( 'Countries', 'pods' ), |
519
|
|
|
'group' => __( 'Predefined Lists', 'pods' ), |
520
|
|
|
'simple' => true, |
521
|
|
|
'data_callback' => array( $this, 'data_countries' ) |
522
|
|
|
); |
523
|
|
|
|
524
|
|
|
self::$related_objects[ 'us_state' ] = array( |
525
|
|
|
'label' => __( 'US States', 'pods' ), |
526
|
|
|
'group' => __( 'Predefined Lists', 'pods' ), |
527
|
|
|
'simple' => true, |
528
|
|
|
'data_callback' => array( $this, 'data_us_states' ) |
529
|
|
|
); |
530
|
|
|
|
531
|
|
|
self::$related_objects[ 'days_of_week' ] = array( |
532
|
|
|
'label' => __( 'Calendar - Days of Week', 'pods' ), |
533
|
|
|
'group' => __( 'Predefined Lists', 'pods' ), |
534
|
|
|
'simple' => true, |
535
|
|
|
'data_callback' => array( $this, 'data_days_of_week' ) |
536
|
|
|
); |
537
|
|
|
|
538
|
|
|
self::$related_objects[ 'months_of_year' ] = array( |
539
|
|
|
'label' => __( 'Calendar - Months of Year', 'pods' ), |
540
|
|
|
'group' => __( 'Predefined Lists', 'pods' ), |
541
|
|
|
'simple' => true, |
542
|
|
|
'data_callback' => array( $this, 'data_months_of_year' ) |
543
|
|
|
); |
544
|
|
|
|
545
|
|
|
do_action( 'pods_form_ui_field_pick_related_objects_predefined' ); |
546
|
|
|
|
547
|
|
|
if ( did_action( 'init' ) ) |
548
|
|
|
pods_transient_set( 'pods_related_objects', self::$related_objects ); |
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
foreach ( self::$custom_related_objects as $object => $related_object ) { |
552
|
|
|
if ( ! isset( self::$related_objects[ $object ] ) ) { |
553
|
|
|
$new_data_loaded = true; |
554
|
|
|
self::$related_objects[ $object ] = $related_object; |
555
|
|
|
} |
556
|
|
|
} |
557
|
|
|
return $new_data_loaded; |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* Return available related objects |
562
|
|
|
* |
563
|
|
|
* @param boolean $force Whether to force refresh of related objects |
564
|
|
|
* |
565
|
|
|
* @return array Field selection array |
566
|
|
|
* @since 2.3 |
567
|
|
|
*/ |
568
|
|
|
public function related_objects ( $force = false ) { |
569
|
|
|
if ( $this->setup_related_objects( $force ) || null === self::$names_related ) { |
570
|
|
|
$related_objects = array(); |
571
|
|
|
|
572
|
|
|
foreach ( self::$related_objects as $related_object_name => $related_object ) { |
573
|
|
|
if ( ! isset( $related_objects[ $related_object[ 'group' ] ] ) ) { |
574
|
|
|
$related_objects[ $related_object[ 'group' ] ] = array(); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
$related_objects[ $related_object[ 'group' ] ][ $related_object_name ] = $related_object[ 'label' ]; |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
self::$names_related = (array) apply_filters( 'pods_form_ui_field_pick_related_objects', $related_objects ); |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
return self::$names_related; |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
/** |
587
|
|
|
* Return available simple object names |
588
|
|
|
* |
589
|
|
|
* @return array Simple object names |
590
|
|
|
* @since 2.3 |
591
|
|
|
*/ |
592
|
|
View Code Duplication |
public function simple_objects () { |
|
|
|
|
593
|
|
|
if ( $this->setup_related_objects() || null === self::$names_simple ) { |
594
|
|
|
$simple_objects = array(); |
595
|
|
|
|
596
|
|
|
foreach ( self::$related_objects as $object => $related_object ) { |
597
|
|
|
if ( !isset( $related_object[ 'simple' ] ) || !$related_object[ 'simple' ] ) |
598
|
|
|
continue; |
599
|
|
|
|
600
|
|
|
$simple_objects[] = $object; |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
self::$names_simple = (array) apply_filters( 'pods_form_ui_field_pick_simple_objects', $simple_objects ); |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
return self::$names_simple; |
607
|
|
|
} |
608
|
|
|
|
609
|
|
|
/** |
610
|
|
|
* Return available bidirectional object names |
611
|
|
|
* |
612
|
|
|
* @return array Bidirectional object names |
613
|
|
|
* @since 2.3.4 |
614
|
|
|
*/ |
615
|
|
View Code Duplication |
public function bidirectional_objects () { |
|
|
|
|
616
|
|
|
if ( $this->setup_related_objects() || null === self::$names_bidirectional ) { |
617
|
|
|
$bidirectional_objects = array(); |
618
|
|
|
|
619
|
|
|
foreach ( self::$related_objects as $object => $related_object ) { |
620
|
|
|
if ( !isset( $related_object[ 'bidirectional' ] ) || !$related_object[ 'bidirectional' ] ) |
621
|
|
|
continue; |
622
|
|
|
|
623
|
|
|
$bidirectional_objects[] = $object; |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
self::$names_bidirectional = (array) apply_filters( 'pods_form_ui_field_pick_bidirectional_objects', $bidirectional_objects ); |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
return self::$names_bidirectional; |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
/** |
633
|
|
|
* Define the current field's schema for DB table storage |
634
|
|
|
* |
635
|
|
|
* @param array $options |
636
|
|
|
* |
637
|
|
|
* @return array |
638
|
|
|
* @since 2.0 |
639
|
|
|
*/ |
640
|
|
|
public function schema ( $options = null ) { |
641
|
|
|
$schema = false; |
642
|
|
|
|
643
|
|
|
$simple_tableless_objects = $this->simple_objects(); |
644
|
|
|
|
645
|
|
|
if ( in_array( pods_var( self::$type . '_object', $options ), $simple_tableless_objects ) ) |
646
|
|
|
$schema = 'LONGTEXT'; |
647
|
|
|
|
648
|
|
|
return $schema; |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
/** |
652
|
|
|
* Change the way the value of the field is displayed with Pods::get |
653
|
|
|
* |
654
|
|
|
* @param mixed $value |
655
|
|
|
* @param string $name |
656
|
|
|
* @param array $options |
657
|
|
|
* @param array $fields |
|
|
|
|
658
|
|
|
* @param array $pod |
659
|
|
|
* @param int $id |
660
|
|
|
* |
661
|
|
|
* @since 2.0 |
662
|
|
|
*/ |
663
|
|
|
public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) { |
664
|
|
|
$fields = null; |
665
|
|
|
|
666
|
|
|
if ( is_object( $pod ) && isset( $pod->fields ) ) { |
667
|
|
|
$fields = $pod->fields; |
668
|
|
|
|
669
|
|
|
if ( ! empty( $pod->pod_data[ 'object_fields' ] ) ) { |
670
|
|
|
$fields = array_merge( $fields, $pod->pod_data[ 'object_fields' ] ); |
671
|
|
|
} |
672
|
|
View Code Duplication |
} elseif ( is_array( $pod ) && isset( $pod[ 'fields' ] ) ) { |
673
|
|
|
$fields = $pod[ 'fields' ]; |
674
|
|
|
|
675
|
|
|
if ( ! empty( $pod[ 'object_fields' ] ) ) { |
676
|
|
|
$fields = array_merge( $fields, $pod[ 'object_fields' ] ); |
677
|
|
|
} |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
return pods_serial_comma( $value, array( 'field' => $name, 'fields' => $fields ) ); |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
/** |
684
|
|
|
* Customize output of the form field |
685
|
|
|
* |
686
|
|
|
* @param string $name |
687
|
|
|
* @param mixed $value |
688
|
|
|
* @param array $options |
689
|
|
|
* @param array $pod |
690
|
|
|
* @param int $id |
691
|
|
|
* |
692
|
|
|
* @since 2.0 |
693
|
|
|
*/ |
694
|
|
|
public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) { |
695
|
|
|
global $wpdb; |
|
|
|
|
696
|
|
|
|
697
|
|
|
$options = (array) $options; |
698
|
|
|
$form_field_type = PodsForm::$field_type; |
|
|
|
|
699
|
|
|
|
700
|
|
|
$options[ 'grouped' ] = 1; |
701
|
|
|
|
702
|
|
|
$options[ 'table_info' ] = array(); |
703
|
|
|
|
704
|
|
|
$custom = pods_var_raw( self::$type . '_custom', $options, false ); |
705
|
|
|
|
706
|
|
|
$custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $name, $value, $options, $pod, $id ); |
707
|
|
|
|
708
|
|
|
$ajax = false; |
709
|
|
|
|
710
|
|
|
if ( ( 'custom-simple' != pods_var( self::$type . '_object', $options ) || empty( $custom ) ) && '' != pods_var( self::$type . '_object', $options, '', null, true ) ) |
711
|
|
|
$ajax = true; |
712
|
|
|
|
713
|
|
|
if ( !empty( self::$field_data ) && self::$field_data[ 'id' ] == $options[ 'id' ] ) { |
714
|
|
|
$ajax = (boolean) self::$field_data[ 'autocomplete' ]; |
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
$ajax = apply_filters( 'pods_form_ui_field_pick_ajax', $ajax, $name, $value, $options, $pod, $id ); |
718
|
|
|
|
719
|
|
|
if ( 0 == pods_var( self::$type . '_ajax', $options, 1 ) ) |
720
|
|
|
$ajax = false; |
721
|
|
|
|
722
|
|
|
if ( 'single' == pods_var( self::$type . '_format_type', $options, 'single' ) ) { |
723
|
|
View Code Duplication |
if ( 'dropdown' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) ) |
724
|
|
|
$field_type = 'select'; |
725
|
|
|
elseif ( 'radio' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) ) |
726
|
|
|
$field_type = 'radio'; |
727
|
|
|
elseif ( 'autocomplete' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) ) |
728
|
|
|
$field_type = 'select2'; |
729
|
|
|
elseif ( 'flexible' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) ) |
730
|
|
|
$field_type = 'flexible'; |
731
|
|
|
else { |
732
|
|
|
// Support custom integration |
733
|
|
|
do_action( 'pods_form_ui_field_pick_input_' . pods_var( self::$type . '_format_type', $options, 'single' ) . '_' . pods_var( self::$type . '_format_single', $options, 'dropdown' ), $name, $value, $options, $pod, $id ); |
734
|
|
|
do_action( 'pods_form_ui_field_pick_input', pods_var( self::$type . '_format_type', $options, 'single' ), $name, $value, $options, $pod, $id ); |
735
|
|
|
return; |
736
|
|
|
} |
737
|
|
|
} |
738
|
|
|
elseif ( 'multi' == pods_var( self::$type . '_format_type', $options, 'single' ) ) { |
739
|
|
|
if ( !empty( $value ) && !is_array( $value ) ) |
740
|
|
|
$value = explode( ',', $value ); |
741
|
|
|
|
742
|
|
View Code Duplication |
if ( 'checkbox' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) ) |
743
|
|
|
$field_type = 'checkbox'; |
744
|
|
|
elseif ( 'multiselect' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) ) |
745
|
|
|
$field_type = 'select'; |
746
|
|
|
elseif ( 'autocomplete' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) ) |
747
|
|
|
$field_type = 'select2'; |
748
|
|
|
elseif ( 'flexible' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) ) |
749
|
|
|
$field_type = 'flexible'; |
750
|
|
|
else { |
751
|
|
|
// Support custom integration |
752
|
|
|
do_action( 'pods_form_ui_field_pick_input_' . pods_var( self::$type . '_format_type', $options, 'single' ) . '_' . pods_var( self::$type . '_format_multi', $options, 'checkbox' ), $name, $value, $options, $pod, $id ); |
753
|
|
|
do_action( 'pods_form_ui_field_pick_input', pods_var( self::$type . '_format_type', $options, 'single' ), $name, $value, $options, $pod, $id ); |
754
|
|
|
return; |
755
|
|
|
} |
756
|
|
|
} |
757
|
|
|
else { |
758
|
|
|
// Support custom integration |
759
|
|
|
do_action( 'pods_form_ui_field_pick_input', pods_var( self::$type . '_format_type', $options, 'single' ), $name, $value, $options, $pod, $id ); |
760
|
|
|
return; |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
if ( 'flexible' == $field_type || ( 'select2' == $field_type && 1 == pods_v( self::$type . '_taggable', $options, 0 ) ) ) { |
764
|
|
|
// @todo: Fix location when merging |
765
|
|
|
$field_type = 'pick'; |
766
|
|
|
pods_view( PODS_DIR . 'ui/fields/pick/pick.php', compact( array_keys( get_defined_vars() ) ) ); |
767
|
|
|
return; |
768
|
|
|
} |
769
|
|
|
|
770
|
|
|
pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) ); |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
/** |
774
|
|
|
* Validate a value before it's saved |
775
|
|
|
* |
776
|
|
|
* @param mixed $value |
777
|
|
|
* @param string $name |
778
|
|
|
* @param array $options |
779
|
|
|
* @param array $fields |
780
|
|
|
* @param array $pod |
781
|
|
|
* @param int $id |
782
|
|
|
* |
783
|
|
|
* @param null $params |
784
|
|
|
* @return array|bool |
785
|
|
|
* @since 2.0 |
786
|
|
|
*/ |
787
|
|
|
public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { |
788
|
|
|
if ( empty( self::$api ) ) |
789
|
|
|
self::$api = pods_api(); |
790
|
|
|
|
791
|
|
|
$simple_tableless_objects = $this->simple_objects(); |
792
|
|
|
|
793
|
|
|
$related_pick_limit = 0; |
794
|
|
|
$related_field = $related_pod = $current_related_ids = false; |
795
|
|
|
|
796
|
|
|
// Bidirectional relationship requirement checks |
797
|
|
|
$related_object = pods_var( self::$type . '_object', $options, '' ); // pod, post_type, taxonomy, etc.. |
798
|
|
|
$related_val = pods_var( self::$type . '_val', $options, $related_object, null, true ); // pod name, post type name, taxonomy name, etc.. |
799
|
|
|
if ( empty( $related_val ) ) { |
800
|
|
|
$related_val = $related_object; |
801
|
|
|
} |
802
|
|
|
|
803
|
|
|
$related_sister_id = (int) pods_var( 'sister_id', $options, 0 ); |
804
|
|
|
|
805
|
|
|
$options[ 'id' ] = (int) $options[ 'id' ]; |
806
|
|
|
|
807
|
|
|
if ( !isset( self::$related_data[ $options[ 'id' ] ] ) || empty( self::$related_data[ $options[ 'id' ] ] ) ) |
808
|
|
|
self::$related_data[ $options[ 'id' ] ] = array(); |
809
|
|
|
|
810
|
|
|
if ( !empty( $related_sister_id ) && !in_array( $related_object, $simple_tableless_objects ) ) { |
811
|
|
|
$related_pod = self::$api->load_pod( array( 'name' => $related_val, 'table_info' => false ), false ); |
812
|
|
|
|
813
|
|
|
if ( false !== $related_pod && ( 'pod' == $related_object || $related_object == $related_pod[ 'type' ] ) ) { |
814
|
|
|
$related_field = false; |
815
|
|
|
|
816
|
|
|
// Ensure sister_id exists on related Pod |
817
|
|
View Code Duplication |
foreach ( $related_pod[ 'fields' ] as $related_pod_field ) { |
818
|
|
|
if ( 'pick' == $related_pod_field[ 'type' ] && $related_sister_id == $related_pod_field[ 'id' ] ) { |
819
|
|
|
$related_field = $related_pod_field; |
820
|
|
|
|
821
|
|
|
break; |
822
|
|
|
} |
823
|
|
|
} |
824
|
|
|
|
825
|
|
|
if ( !empty( $related_field ) ) { |
826
|
|
|
$current_ids = self::$api->lookup_related_items( $fields[ $name ][ 'id' ], $pod[ 'id' ], $id, $fields[ $name ], $pod ); |
827
|
|
|
|
828
|
|
|
self::$related_data[ $options[ 'id' ] ][ 'current_ids' ] = $current_ids; |
829
|
|
|
|
830
|
|
|
$value_ids = $value; |
831
|
|
|
|
832
|
|
|
// Convert values from a comma-separated string into an array |
833
|
|
|
if ( !is_array( $value_ids ) ) |
834
|
|
|
$value_ids = explode( ',', $value_ids ); |
835
|
|
|
|
836
|
|
|
$value_ids = array_unique( array_filter( $value_ids ) ); |
837
|
|
|
|
838
|
|
|
// Get ids to remove |
839
|
|
|
$remove_ids = array_diff( $current_ids, $value_ids ); |
840
|
|
|
|
841
|
|
|
$related_required = (boolean) pods_var( 'required', $related_field[ 'options' ], 0 ); |
842
|
|
|
$related_pick_limit = (int) pods_var( self::$type . '_limit', $related_field[ 'options' ], 0 ); |
843
|
|
|
|
844
|
|
|
if ( 'single' == pods_var_raw( self::$type . '_format_type', $related_field[ 'options' ] ) ) |
845
|
|
|
$related_pick_limit = 1; |
846
|
|
|
|
847
|
|
|
// Validate Required |
848
|
|
|
if ( $related_required && !empty( $remove_ids ) ) { |
849
|
|
|
foreach ( $remove_ids as $related_id ) { |
850
|
|
|
$bidirectional_ids = self::$api->lookup_related_items( $related_field[ 'id' ], $related_pod[ 'id' ], $related_id, $related_field, $related_pod ); |
851
|
|
|
|
852
|
|
|
self::$related_data[ $options[ 'id' ] ][ 'related_ids_' . $related_id ] = $bidirectional_ids; |
853
|
|
|
|
854
|
|
|
if ( empty( $bidirectional_ids ) || ( in_array( $id, $bidirectional_ids ) && 1 == count( $bidirectional_ids ) ) ) |
855
|
|
|
return sprintf( __( 'The %s field is required and cannot be removed by the %s field', 'pods' ), $related_field[ 'label' ], $options[ 'label' ] ); |
856
|
|
|
} |
857
|
|
|
} |
858
|
|
|
} |
859
|
|
|
else |
860
|
|
|
$related_pod = false; |
861
|
|
|
} |
862
|
|
|
else |
863
|
|
|
$related_pod = false; |
864
|
|
|
} |
865
|
|
|
|
866
|
|
|
if ( empty( self::$related_data[ $options[ 'id' ] ] ) ) |
867
|
|
|
unset( self::$related_data[ $options[ 'id' ] ] ); |
868
|
|
|
else { |
869
|
|
|
self::$related_data[ $options[ 'id' ] ][ 'related_pod' ] = $related_pod; |
870
|
|
|
self::$related_data[ $options[ 'id' ] ][ 'related_field' ] = $related_field; |
871
|
|
|
self::$related_data[ $options[ 'id' ] ][ 'related_pick_limit' ] = $related_pick_limit; |
872
|
|
|
|
873
|
|
|
$pick_limit = (int) pods_var( self::$type . '_limit', $options[ 'options' ], 0 ); |
874
|
|
|
|
875
|
|
|
if ( 'single' == pods_var_raw( self::$type . '_format_type', $options[ 'options' ] ) ) |
876
|
|
|
$pick_limit = 1; |
877
|
|
|
|
878
|
|
|
$related_field[ 'id' ] = (int) $related_field[ 'id' ]; |
879
|
|
|
|
880
|
|
|
if ( !isset( self::$related_data[ $related_field[ 'id' ] ] ) || empty( self::$related_data[ $related_field[ 'id' ] ] ) ) { |
881
|
|
|
self::$related_data[ $related_field[ 'id' ] ] = array( |
882
|
|
|
'related_pod' => $pod, |
883
|
|
|
'related_field' => $options, |
884
|
|
|
'related_pick_limit' => $pick_limit |
885
|
|
|
); |
886
|
|
|
} |
887
|
|
|
} |
888
|
|
|
|
889
|
|
|
return true; |
890
|
|
|
} |
891
|
|
|
|
892
|
|
|
/** |
893
|
|
|
* Save the value to the DB |
894
|
|
|
* |
895
|
|
|
* @param mixed $value |
896
|
|
|
* @param int $id |
897
|
|
|
* @param string $name |
898
|
|
|
* @param array $options |
899
|
|
|
* @param array $fields |
900
|
|
|
* @param array $pod |
901
|
|
|
* @param object $params |
902
|
|
|
* |
903
|
|
|
* @since 2.3 |
904
|
|
|
*/ |
905
|
|
|
public function save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { |
906
|
|
|
if ( empty( self::$api ) ) |
907
|
|
|
self::$api = pods_api(); |
908
|
|
|
|
909
|
|
|
$options[ 'id' ] = (int) $options[ 'id' ]; |
910
|
|
|
|
911
|
|
|
if ( !isset( self::$related_data[ $options[ 'id' ] ] ) ) |
912
|
|
|
return; |
913
|
|
|
|
914
|
|
|
$related_pod = self::$related_data[ $options[ 'id' ] ][ 'related_pod' ]; |
915
|
|
|
$related_field = self::$related_data[ $options[ 'id' ] ][ 'related_field' ]; |
916
|
|
|
$related_pick_limit = self::$related_data[ $options[ 'id' ] ][ 'related_pick_limit' ]; |
917
|
|
|
|
918
|
|
|
// Bidirectional relationship updates |
919
|
|
|
if ( !empty( $related_field ) ) { |
920
|
|
|
// Don't use no conflict mode unless this isn't the current pod type |
921
|
|
|
$no_conflict = true; |
922
|
|
|
|
923
|
|
|
if ( $related_pod[ 'type' ] != $pod[ 'type' ] ) |
924
|
|
|
$no_conflict = pods_no_conflict_check( $related_pod[ 'type' ] ); |
925
|
|
|
|
926
|
|
|
if ( !$no_conflict ) |
927
|
|
|
pods_no_conflict_on( $related_pod[ 'type' ] ); |
928
|
|
|
|
929
|
|
|
$value = array_filter( $value ); |
930
|
|
|
|
931
|
|
|
foreach ( $value as $related_id ) { |
932
|
|
|
if ( isset( self::$related_data[ $options[ 'id' ] ][ 'related_ids_' . $related_id ] ) && !empty( self::$related_data[ $options[ 'id' ] ][ 'related_ids_' . $related_id ] ) ) |
933
|
|
|
$bidirectional_ids = self::$related_data[ $options[ 'id' ] ][ 'related_ids_' . $related_id ]; |
934
|
|
|
else |
935
|
|
|
$bidirectional_ids = self::$api->lookup_related_items( $related_field[ 'id' ], $related_pod[ 'id' ], $related_id, $related_field, $related_pod ); |
936
|
|
|
|
937
|
|
|
$bidirectional_ids = array_filter( $bidirectional_ids ); |
938
|
|
|
|
939
|
|
|
if ( empty( $bidirectional_ids ) ) |
940
|
|
|
$bidirectional_ids = array(); |
941
|
|
|
|
942
|
|
|
$remove_ids = array(); |
943
|
|
|
|
944
|
|
|
if ( 0 < $related_pick_limit && !empty( $bidirectional_ids ) && !in_array( $id, $bidirectional_ids ) ) { |
945
|
|
|
while ( $related_pick_limit <= count( $bidirectional_ids ) ) { |
946
|
|
|
$remove_ids[] = (int) array_pop( $bidirectional_ids ); |
947
|
|
|
} |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
// Remove this item from related items no longer related to |
951
|
|
|
$remove_ids = array_unique( array_filter( $remove_ids ) ); |
952
|
|
|
|
953
|
|
|
// Add to related items |
954
|
|
|
if ( !in_array( $id, $bidirectional_ids ) ) |
955
|
|
|
$bidirectional_ids[] = $id; |
956
|
|
|
// Nothing to change |
957
|
|
|
elseif ( empty( $remove_ids ) ) |
958
|
|
|
continue; |
959
|
|
|
|
960
|
|
|
self::$api->save_relationships( $related_id, $bidirectional_ids, $related_pod, $related_field ); |
961
|
|
|
|
962
|
|
|
if ( !empty( $remove_ids ) ) |
963
|
|
|
self::$api->delete_relationships( $remove_ids, $related_id, $pod, $options ); |
964
|
|
|
} |
965
|
|
|
|
966
|
|
|
if ( !$no_conflict ) |
967
|
|
|
pods_no_conflict_off( $related_pod[ 'type' ] ); |
968
|
|
|
} |
969
|
|
|
} |
970
|
|
|
|
971
|
|
|
/** |
972
|
|
|
* Delete the value from the DB |
973
|
|
|
* |
974
|
|
|
* @param int $id |
975
|
|
|
* @param string $name |
976
|
|
|
* @param array $options |
977
|
|
|
* @param array $pod |
978
|
|
|
* |
979
|
|
|
* @since 2.3 |
980
|
|
|
*/ |
981
|
|
|
public function delete ( $id = null, $name = null, $options = null, $pod = null ) { |
982
|
|
|
if ( empty( self::$api ) ) |
983
|
|
|
self::$api = pods_api(); |
984
|
|
|
|
985
|
|
|
$simple_tableless_objects = $this->simple_objects(); |
986
|
|
|
|
987
|
|
|
// Bidirectional relationship requirement checks |
988
|
|
|
$related_object = pods_var( self::$type . '_object', $options, '' ); // pod, post_type, taxonomy, etc.. |
989
|
|
|
$related_val = pods_var( self::$type . '_val', $options, $related_object, null, true ); // pod name, post type name, taxonomy name, etc.. |
990
|
|
|
$related_sister_id = (int) pods_var( 'sister_id', $options, 0 ); |
991
|
|
|
|
992
|
|
|
if ( !empty( $related_sister_id ) && !in_array( $related_object, $simple_tableless_objects ) ) { |
993
|
|
|
$related_pod = self::$api->load_pod( array( 'name' => $related_val, 'table_info' => false ), false ); |
994
|
|
|
|
995
|
|
|
if ( false !== $related_pod && ( 'pod' == $related_object || $related_object == $related_pod[ 'type' ] ) ) { |
996
|
|
|
$related_field = false; |
997
|
|
|
|
998
|
|
|
// Ensure sister_id exists on related Pod |
999
|
|
View Code Duplication |
foreach ( $related_pod[ 'fields' ] as $related_pod_field ) { |
1000
|
|
|
if ( 'pick' == $related_pod_field[ 'type' ] && $related_sister_id == $related_pod_field[ 'id' ] ) { |
1001
|
|
|
$related_field = $related_pod_field; |
1002
|
|
|
|
1003
|
|
|
break; |
1004
|
|
|
} |
1005
|
|
|
} |
1006
|
|
|
|
1007
|
|
|
if ( !empty( $related_field ) ) { |
1008
|
|
|
$values = self::$api->lookup_related_items( $options[ 'id' ], $pod[ 'id' ], $id, $options, $pod ); |
1009
|
|
|
|
1010
|
|
|
if ( !empty( $values ) ) { |
1011
|
|
|
$no_conflict = pods_no_conflict_check( $related_pod[ 'type' ] ); |
1012
|
|
|
|
1013
|
|
|
if ( !$no_conflict ) |
1014
|
|
|
pods_no_conflict_on( $related_pod[ 'type' ] ); |
1015
|
|
|
|
1016
|
|
|
self::$api->delete_relationships( $values, $id, $related_pod, $related_field ); |
1017
|
|
|
|
1018
|
|
|
if ( !$no_conflict ) |
1019
|
|
|
pods_no_conflict_off( $related_pod[ 'type' ] ); |
1020
|
|
|
} |
1021
|
|
|
} |
1022
|
|
|
} |
1023
|
|
|
} |
1024
|
|
|
} |
1025
|
|
|
|
1026
|
|
|
/** |
1027
|
|
|
* Customize the Pods UI manage table column output |
1028
|
|
|
* |
1029
|
|
|
* @param int $id |
1030
|
|
|
* @param mixed $value |
1031
|
|
|
* @param string $name |
1032
|
|
|
* @param array $options |
1033
|
|
|
* @param array $fields |
1034
|
|
|
* @param array $pod |
1035
|
|
|
* |
1036
|
|
|
* @since 2.0 |
1037
|
|
|
*/ |
1038
|
|
|
public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) { |
1039
|
|
|
$value = $this->simple_value( $name, $value, $options, $pod, $id ); |
1040
|
|
|
|
1041
|
|
|
return $this->display( $value, $name, $options, $pod, $id ); |
1042
|
|
|
} |
1043
|
|
|
|
1044
|
|
|
/** |
1045
|
|
|
* Get the data from the field |
1046
|
|
|
* |
1047
|
|
|
* @param string $name The name of the field |
1048
|
|
|
* @param string|array $value The value of the field |
1049
|
|
|
* @param array $options Field options |
1050
|
|
|
* @param array $pod Pod data |
1051
|
|
|
* @param int $id Item ID |
1052
|
|
|
* @param boolean $in_form |
1053
|
|
|
* |
1054
|
|
|
* @return array Array of possible field data |
1055
|
|
|
* |
1056
|
|
|
* @since 2.0 |
1057
|
|
|
*/ |
1058
|
|
|
public function data ( $name, $value = null, $options = null, $pod = null, $id = null, $in_form = true ) { |
1059
|
|
View Code Duplication |
if ( isset( $options[ 'options' ] ) ) { |
1060
|
|
|
$options = array_merge( $options, $options[ 'options' ] ); |
1061
|
|
|
|
1062
|
|
|
unset( $options[ 'options' ] ); |
1063
|
|
|
} |
1064
|
|
|
|
1065
|
|
|
$data = pods_var_raw( 'data', $options, null, null, true ); |
1066
|
|
|
|
1067
|
|
|
$object_params = array( |
1068
|
|
|
'name' => $name, // The name of the field |
1069
|
|
|
'value' => $value, // The value of the field |
1070
|
|
|
'options' => $options, // Field options |
1071
|
|
|
'pod' => $pod, // Pod data |
1072
|
|
|
'id' => $id, // Item ID |
1073
|
|
|
'context' => 'data', // Data context |
1074
|
|
|
); |
1075
|
|
|
|
1076
|
|
|
if ( null !== $data ) |
1077
|
|
|
$data = (array) $data; |
1078
|
|
|
else |
1079
|
|
|
$data = $this->get_object_data( $object_params ); |
1080
|
|
|
|
1081
|
|
|
if ( 'single' == pods_var( self::$type . '_format_type', $options, 'single' ) && 'dropdown' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) ) |
1082
|
|
|
$data = array( '' => pods_var_raw( self::$type . '_select_text', $options, __( '-- Select One --', 'pods' ), null, true ) ) + $data; |
1083
|
|
|
|
1084
|
|
|
$data = apply_filters( 'pods_field_pick_data', $data, $name, $value, $options, $pod, $id ); |
1085
|
|
|
|
1086
|
|
|
return $data; |
1087
|
|
|
} |
1088
|
|
|
|
1089
|
|
|
/** |
1090
|
|
|
* Convert a simple value to the correct value |
1091
|
|
|
* |
1092
|
|
|
* @param string $name The name of the field |
1093
|
|
|
* @param string|array $value The value of the field |
1094
|
|
|
* @param array $options Field options |
1095
|
|
|
* @param array $pod Pod data |
1096
|
|
|
* @param int $id Item ID |
1097
|
|
|
* @param boolean $raw Whether to return the raw list of keys (true) or convert to key=>value (false) |
1098
|
|
|
* |
1099
|
|
|
* @return mixed Corrected value |
1100
|
|
|
*/ |
1101
|
|
|
public function simple_value ( $name, $value = null, $options = null, $pod = null, $id = null, $raw = false ) { |
1102
|
|
|
if ( in_array( pods_var( self::$type . '_object', $options ), self::simple_objects() ) ) { |
1103
|
|
View Code Duplication |
if ( isset( $options[ 'options' ] ) ) { |
1104
|
|
|
$options = array_merge( $options, $options[ 'options' ] ); |
1105
|
|
|
|
1106
|
|
|
unset( $options[ 'options' ] ); |
1107
|
|
|
} |
1108
|
|
|
|
1109
|
|
|
if ( !is_array( $value ) && 0 < strlen( $value ) ) { |
1110
|
|
|
$simple = @json_decode( $value, true ); |
1111
|
|
|
|
1112
|
|
|
if ( is_array( $simple ) ) |
1113
|
|
|
$value = $simple; |
1114
|
|
|
} |
1115
|
|
|
|
1116
|
|
|
$data = pods_var_raw( 'data', $options, null, null, true ); |
1117
|
|
|
|
1118
|
|
|
$object_params = array( |
1119
|
|
|
'name' => $name, // The name of the field |
1120
|
|
|
'value' => $value, // The value of the field |
1121
|
|
|
'options' => $options, // Field options |
1122
|
|
|
'pod' => $pod, // Pod data |
1123
|
|
|
'id' => $id, // Item ID |
1124
|
|
|
'context' => 'simple_value', // Data context |
1125
|
|
|
); |
1126
|
|
|
|
1127
|
|
|
if ( null === $data ) |
1128
|
|
|
$data = $this->get_object_data( $object_params ); |
1129
|
|
|
|
1130
|
|
|
$data = (array) $data; |
1131
|
|
|
|
1132
|
|
|
$key = 0; |
1133
|
|
|
|
1134
|
|
|
if ( is_array( $value ) ) { |
1135
|
|
|
if ( !empty( $data ) ) { |
1136
|
|
|
$val = array(); |
1137
|
|
|
|
1138
|
|
|
foreach ( $value as $k => $v ) { |
1139
|
|
|
if ( isset( $data[ $v ] ) ) { |
1140
|
|
|
if ( false === $raw ) { |
1141
|
|
|
$k = $v; |
1142
|
|
|
$v = $data[ $v ]; |
1143
|
|
|
} |
1144
|
|
|
|
1145
|
|
|
$val[ $k ] = $v; |
1146
|
|
|
} |
1147
|
|
|
} |
1148
|
|
|
|
1149
|
|
|
$value = $val; |
1150
|
|
|
} |
1151
|
|
|
} |
1152
|
|
|
elseif ( isset( $data[ $value ] ) && false === $raw ) { |
1153
|
|
|
$key = $value; |
1154
|
|
|
$value = $data[ $value ]; |
1155
|
|
|
} |
1156
|
|
|
|
1157
|
|
|
$single_multi = pods_var( self::$type . '_format_type', $options, 'single' ); |
1158
|
|
|
|
1159
|
|
|
if ( 'multi' == $single_multi ) |
1160
|
|
|
$limit = (int) pods_var( self::$type . '_limit', $options, 0 ); |
1161
|
|
|
else |
1162
|
|
|
$limit = 1; |
1163
|
|
|
|
1164
|
|
|
if ( is_array( $value ) && 0 < $limit ) { |
1165
|
|
|
if ( 1 == $limit ) |
1166
|
|
|
$value = current( $value ); |
1167
|
|
|
else |
1168
|
|
|
$value = array_slice( $value, 0, $limit, true ); |
1169
|
|
|
} |
1170
|
|
|
elseif ( !is_array( $value ) && null !== $value && 0 < strlen( $value ) ) { |
1171
|
|
|
if ( 1 != $limit || ( true === $raw && 'multi' == $single_multi ) ) { |
1172
|
|
|
$value = array( |
1173
|
|
|
$key => $value |
1174
|
|
|
); |
1175
|
|
|
} |
1176
|
|
|
} |
1177
|
|
|
} |
1178
|
|
|
|
1179
|
|
|
return $value; |
1180
|
|
|
} |
1181
|
|
|
|
1182
|
|
|
/** |
1183
|
|
|
* Get the label from a pick value |
1184
|
|
|
* |
1185
|
|
|
* @param string $name The name of the field |
1186
|
|
|
* @param string|array $value The value of the field |
1187
|
|
|
* @param array $options Field options |
1188
|
|
|
* @param array $pod Pod data |
1189
|
|
|
* @param int $id Item ID |
1190
|
|
|
* |
1191
|
|
|
* @return string |
1192
|
|
|
* |
1193
|
|
|
* @since 2.2 |
1194
|
|
|
*/ |
1195
|
|
|
public function value_to_label ( $name, $value = null, $options = null, $pod = null, $id = null ) { |
1196
|
|
View Code Duplication |
if ( isset( $options[ 'options' ] ) ) { |
1197
|
|
|
$options = array_merge( $options, $options[ 'options' ] ); |
1198
|
|
|
|
1199
|
|
|
unset( $options[ 'options' ] ); |
1200
|
|
|
} |
1201
|
|
|
|
1202
|
|
|
$data = pods_var_raw( 'data', $options, null, null, true ); |
1203
|
|
|
|
1204
|
|
|
$object_params = array( |
1205
|
|
|
'name' => $name, // The name of the field |
1206
|
|
|
'value' => $value, // The value of the field |
1207
|
|
|
'options' => $options, // Field options |
1208
|
|
|
'pod' => $pod, // Pod data |
1209
|
|
|
'id' => $id, // Item ID |
1210
|
|
|
'context' => 'value_to_label', // Data context |
1211
|
|
|
); |
1212
|
|
|
|
1213
|
|
|
if ( null !== $data ) |
1214
|
|
|
$data = (array) $data; |
1215
|
|
|
else |
1216
|
|
|
$data = $this->get_object_data( $object_params ); |
1217
|
|
|
|
1218
|
|
|
$labels = array(); |
1219
|
|
|
|
1220
|
|
|
foreach ( $data as $v => $l ) { |
|
|
|
|
1221
|
|
|
if ( !in_array( $l, $labels ) && ( $value == $v || ( is_array( $value ) && in_array( $v, $value ) ) ) ) |
1222
|
|
|
$labels[] = $l; |
1223
|
|
|
} |
1224
|
|
|
|
1225
|
|
|
$labels = apply_filters( 'pods_field_pick_value_to_label', $labels, $name, $value, $options, $pod, $id ); |
1226
|
|
|
|
1227
|
|
|
$labels = pods_serial_comma( $labels ); |
1228
|
|
|
|
1229
|
|
|
return $labels; |
1230
|
|
|
} |
1231
|
|
|
|
1232
|
|
|
/** |
1233
|
|
|
* Get available items from a relationship field |
1234
|
|
|
* |
1235
|
|
|
* @param array|string $field Field array or field name |
1236
|
|
|
* @param array $options [optional] Field options array overrides |
1237
|
|
|
* @param array $object_params [optional] Additional get_object_data options |
1238
|
|
|
* |
1239
|
|
|
* @return array An array of available items from a relationship field |
1240
|
|
|
*/ |
1241
|
|
|
public function get_field_data( $field, $options = array(), $object_params = array() ) { |
1242
|
|
|
|
1243
|
|
|
// Handle field array overrides |
1244
|
|
|
if ( is_array( $field ) ) { |
1245
|
|
|
$options = array_merge( $field, $options ); |
1246
|
|
|
} |
1247
|
|
|
|
1248
|
|
|
// Get field name from array |
1249
|
|
|
$field = pods_var_raw( 'name', $options, $field, null, true ); |
1250
|
|
|
|
1251
|
|
|
// Field name or options not set |
1252
|
|
|
if ( empty( $field ) || empty( $options ) ) { |
1253
|
|
|
return array(); |
1254
|
|
|
} |
1255
|
|
|
|
1256
|
|
|
// Options normalization |
1257
|
|
|
$options = array_merge( $options, pods_var_raw( 'options', $options, array(), null, true ) ); |
1258
|
|
|
|
1259
|
|
|
// Setup object params |
1260
|
|
|
$object_params = array_merge( |
1261
|
|
|
array( |
1262
|
|
|
'name' => $field, // The name of the field |
1263
|
|
|
'options' => $options, // Field options |
1264
|
|
|
), |
1265
|
|
|
$object_params |
1266
|
|
|
); |
1267
|
|
|
|
1268
|
|
|
// Get data override |
1269
|
|
|
$data = pods_var_raw( 'data', $options, null, null, true ); |
1270
|
|
|
|
1271
|
|
|
// Return data override |
1272
|
|
|
if ( null !== $data ) { |
1273
|
|
|
$data = (array) $data; |
1274
|
|
|
} |
1275
|
|
|
// Get object data |
1276
|
|
|
else { |
1277
|
|
|
$data = $this->get_object_data( $object_params ); |
1278
|
|
|
} |
1279
|
|
|
|
1280
|
|
|
return $data; |
1281
|
|
|
|
1282
|
|
|
} |
1283
|
|
|
|
1284
|
|
|
/** |
1285
|
|
|
* Get data from relationship objects |
1286
|
|
|
* |
1287
|
|
|
* @param array $object_params Object data parameters |
1288
|
|
|
* |
1289
|
|
|
* @return array|bool Object data |
1290
|
|
|
*/ |
1291
|
|
|
public function get_object_data ( $object_params = null ) { |
1292
|
|
|
global $wpdb, $polylang, $sitepress, $icl_adjust_id_url_filter_off; |
|
|
|
|
1293
|
|
|
|
1294
|
|
|
$current_language = false; |
1295
|
|
|
|
1296
|
|
|
// WPML support |
1297
|
|
View Code Duplication |
if ( is_object( $sitepress ) && !$icl_adjust_id_url_filter_off ) |
1298
|
|
|
$current_language = pods_sanitize( ICL_LANGUAGE_CODE ); |
1299
|
|
|
// Polylang support |
1300
|
|
|
elseif ( function_exists( 'pll_current_language' ) ) |
1301
|
|
|
$current_language = pll_current_language( 'slug' ); |
1302
|
|
|
|
1303
|
|
|
$object_params = array_merge( |
1304
|
|
|
array( |
1305
|
|
|
'name' => '', // The name of the field |
1306
|
|
|
'value' => '', // The value of the field |
1307
|
|
|
'options' => array(), // Field options |
1308
|
|
|
'pod' => '', // Pod data |
1309
|
|
|
'id' => '', // Item ID |
1310
|
|
|
'context' => '', // Data context |
1311
|
|
|
'data_params' => array( |
1312
|
|
|
'query' => '' // Query being searched |
1313
|
|
|
), |
1314
|
|
|
'page' => 1, // Page number of results to get |
1315
|
|
|
'limit' => 0 // How many data items to limit to (autocomplete defaults to 30, set to -1 or 1+ to override) |
1316
|
|
|
), |
1317
|
|
|
$object_params |
1318
|
|
|
); |
1319
|
|
|
|
1320
|
|
|
$name = $object_params[ 'name' ]; |
1321
|
|
|
$value = $object_params[ 'value' ]; |
1322
|
|
|
$options = $object_params[ 'options' ] = (array) $object_params[ 'options' ]; |
1323
|
|
|
$pod = $object_params[ 'pod' ]; |
1324
|
|
|
$id = $object_params[ 'id' ]; |
1325
|
|
|
$context = $object_params[ 'context' ]; |
1326
|
|
|
$data_params = $object_params[ 'data_params' ] = (array) $object_params[ 'data_params' ]; |
1327
|
|
|
$page = min( 1, (int) $object_params[ 'page' ] ); |
1328
|
|
|
$limit = (int) $object_params[ 'limit' ]; |
1329
|
|
|
|
1330
|
|
View Code Duplication |
if ( isset( $options[ 'options' ] ) ) { |
1331
|
|
|
$options = array_merge( $options, $options[ 'options' ] ); |
1332
|
|
|
|
1333
|
|
|
unset( $options[ 'options' ] ); |
1334
|
|
|
} |
1335
|
|
|
|
1336
|
|
|
$data = apply_filters( 'pods_field_pick_object_data', null, $name, $value, $options, $pod, $id, $object_params ); |
1337
|
|
|
$items = array(); |
1338
|
|
|
|
1339
|
|
|
if ( !isset( $options[ self::$type . '_object' ] ) ) |
1340
|
|
|
$data = pods_var_raw( 'data', $options, array(), null, true ); |
1341
|
|
|
|
1342
|
|
|
$simple = false; |
1343
|
|
|
|
1344
|
|
|
if ( null === $data ) { |
1345
|
|
|
$data = array(); |
1346
|
|
|
|
1347
|
|
|
if ( 'custom-simple' == $options[ self::$type . '_object' ] ) { |
1348
|
|
|
$custom = pods_var_raw( self::$type . '_custom', $options, '' ); |
1349
|
|
|
|
1350
|
|
|
$custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $name, $value, $options, $pod, $id, $object_params ); |
1351
|
|
|
|
1352
|
|
|
if ( !empty( $custom ) ) { |
1353
|
|
|
if ( !is_array( $custom ) ) { |
1354
|
|
|
$data = array(); |
1355
|
|
|
|
1356
|
|
|
$custom = explode( "\n", trim( $custom ) ); |
1357
|
|
|
|
1358
|
|
|
foreach ( $custom as $custom_value ) { |
1359
|
|
|
$custom_label = explode( '|', $custom_value ); |
1360
|
|
|
|
1361
|
|
|
if ( empty( $custom_label ) ) |
1362
|
|
|
continue; |
1363
|
|
|
|
1364
|
|
|
if ( 1 == count( $custom_label ) ) |
1365
|
|
|
$custom_label = $custom_value; |
1366
|
|
|
else { |
1367
|
|
|
$custom_value = $custom_label[ 0 ]; |
1368
|
|
|
$custom_label = $custom_label[ 1 ]; |
1369
|
|
|
} |
1370
|
|
|
|
1371
|
|
|
$custom_value = trim( (string) $custom_value ); |
1372
|
|
|
$custom_label = trim( (string) $custom_label ); |
1373
|
|
|
|
1374
|
|
|
$data[ $custom_value ] = $custom_label; |
1375
|
|
|
} |
1376
|
|
|
} |
1377
|
|
|
else |
1378
|
|
|
$data = $custom; |
1379
|
|
|
|
1380
|
|
|
$simple = true; |
1381
|
|
|
} |
1382
|
|
|
} |
1383
|
|
|
elseif ( isset( self::$related_objects[ $options[ self::$type . '_object' ] ] ) && isset( self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data' ] ) && !empty( self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data' ] ) ) { |
1384
|
|
|
$data = self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data' ]; |
1385
|
|
|
|
1386
|
|
|
$simple = true; |
1387
|
|
|
} |
1388
|
|
|
elseif ( isset( self::$related_objects[ $options[ self::$type . '_object' ] ] ) && isset( self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data_callback' ] ) && is_callable( self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data_callback' ] ) ) { |
1389
|
|
|
$data = call_user_func_array( |
1390
|
|
|
self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data_callback' ], |
1391
|
|
|
array( $name, $value, $options, $pod, $id ) |
1392
|
|
|
); |
1393
|
|
|
|
1394
|
|
|
$simple = true; |
1395
|
|
|
|
1396
|
|
|
// Cache data from callback |
1397
|
|
|
if ( !empty( $data ) ) |
1398
|
|
|
self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data' ] = $data; |
1399
|
|
|
} |
1400
|
|
|
elseif ( 'simple_value' != $context ) { |
1401
|
|
|
$pick_val = pods_var( self::$type . '_val', $options ); |
1402
|
|
|
|
1403
|
|
|
if ( 'table' == pods_var( self::$type . '_object', $options ) ) |
1404
|
|
|
$pick_val = pods_var( self::$type . '_table', $options, $pick_val, null, true ); |
1405
|
|
|
|
1406
|
|
View Code Duplication |
if ( '__current__' == $pick_val ) { |
1407
|
|
|
if ( is_object( $pod ) ) |
1408
|
|
|
$pick_val = $pod->pod; |
1409
|
|
|
elseif ( is_array( $pod ) ) |
1410
|
|
|
$pick_val = $pod[ 'name' ]; |
1411
|
|
|
elseif ( 0 < strlen( $pod ) ) |
1412
|
|
|
$pick_val = $pod; |
1413
|
|
|
} |
1414
|
|
|
|
1415
|
|
|
$options[ 'table_info' ] = pods_api()->get_table_info( pods_var( self::$type . '_object', $options ), $pick_val, null, null, $options ); |
1416
|
|
|
|
1417
|
|
|
$search_data = pods_data(); |
1418
|
|
|
$search_data->table( $options[ 'table_info' ] ); |
1419
|
|
|
|
1420
|
|
|
if ( isset( $options[ 'table_info' ][ 'pod' ] ) && !empty( $options[ 'table_info' ][ 'pod' ] ) && isset( $options[ 'table_info' ][ 'pod' ][ 'name' ] ) ) { |
1421
|
|
|
$search_data->pod = $options[ 'table_info' ][ 'pod' ][ 'name' ]; |
1422
|
|
|
$search_data->fields = $options[ 'table_info' ][ 'pod' ][ 'fields' ]; |
1423
|
|
|
} |
1424
|
|
|
|
1425
|
|
|
$params = array( |
1426
|
|
|
'select' => "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`", |
1427
|
|
|
'table' => $search_data->table, |
1428
|
|
|
'where' => pods_var_raw( self::$type . '_where', $options, (array) $options[ 'table_info' ][ 'where_default' ], null, true ), |
1429
|
|
|
'orderby' => pods_var_raw( self::$type . '_orderby', $options, null, null, true ), |
1430
|
|
|
'groupby' => pods_var_raw( self::$type . '_groupby', $options, null, null, true ), |
1431
|
|
|
//'having' => pods_var_raw( self::$type . '_having', $options, null, null, true ), |
|
|
|
|
1432
|
|
|
'pagination' => false, |
1433
|
|
|
'search' => false |
1434
|
|
|
); |
1435
|
|
|
|
1436
|
|
|
if ( in_array( $options[ self::$type . '_object' ], array( 'site', 'network' ) ) ) |
1437
|
|
|
$params[ 'select' ] .= ', `t`.`path`'; |
1438
|
|
|
|
1439
|
|
|
if ( !empty( $params[ 'where' ] ) && (array) $options[ 'table_info' ][ 'where_default' ] != $params[ 'where' ] ) |
1440
|
|
|
$params[ 'where' ] = pods_evaluate_tags( $params[ 'where' ], true ); |
1441
|
|
|
|
1442
|
|
|
if ( empty( $params[ 'where' ] ) || ( !is_array( $params[ 'where' ] ) && strlen( trim( $params[ 'where' ] ) ) < 1 ) ) |
1443
|
|
|
$params[ 'where' ] = array(); |
1444
|
|
|
elseif ( !is_array( $params[ 'where' ] ) ) |
1445
|
|
|
$params[ 'where' ] = (array) $params[ 'where' ]; |
1446
|
|
|
|
1447
|
|
|
if ( 'value_to_label' == $context ) |
1448
|
|
|
$params[ 'where' ][] = "`t`.`{$search_data->field_id}` = " . number_format( $value, 0, '', '' ); |
1449
|
|
|
|
1450
|
|
|
/* not needed yet |
|
|
|
|
1451
|
|
|
if ( !empty( $params[ 'orderby' ] ) ) |
1452
|
|
|
$params[ 'orderby' ] = pods_evaluate_tags( $params[ 'orderby' ], true ); |
1453
|
|
|
|
1454
|
|
|
if ( !empty( $params[ 'groupby' ] ) ) |
1455
|
|
|
$params[ 'groupby' ] = pods_evaluate_tags( $params[ 'groupby' ], true );*/ |
1456
|
|
|
|
1457
|
|
|
$display = trim( pods_var( self::$type . '_display', $options ), ' {@}' ); |
1458
|
|
|
|
1459
|
|
|
if ( 0 < strlen( $display ) ) { |
1460
|
|
|
if ( isset( $options[ 'table_info' ][ 'pod' ] ) && !empty( $options[ 'table_info' ][ 'pod' ] ) ) { |
1461
|
|
|
if ( isset( $options[ 'table_info' ][ 'pod' ][ 'object_fields' ] ) && isset( $options[ 'table_info' ][ 'pod' ][ 'object_fields' ][ $display ] ) ) { |
1462
|
|
|
$search_data->field_index = $display; |
1463
|
|
|
|
1464
|
|
|
$params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`"; |
1465
|
|
|
} |
1466
|
|
|
elseif ( isset( $options[ 'table_info' ][ 'pod' ][ 'fields' ][ $display ] ) ) { |
1467
|
|
|
$search_data->field_index = $display; |
1468
|
|
|
|
1469
|
|
|
if ( 'table' == $options[ 'table_info' ][ 'pod' ][ 'storage' ] && !in_array( $options[ 'table_info' ][ 'pod' ][ 'type' ], array( 'pod', 'table' ) ) ) |
1470
|
|
|
$params[ 'select' ] = "`t`.`{$search_data->field_id}`, `d`.`{$search_data->field_index}`"; |
1471
|
|
|
elseif ( 'meta' == $options[ 'table_info' ][ 'pod' ][ 'storage' ] ) |
1472
|
|
|
$params[ 'select' ] = "`t`.`{$search_data->field_id}`, `{$search_data->field_index}`.`meta_value` AS {$search_data->field_index}"; |
1473
|
|
|
else |
1474
|
|
|
$params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`"; |
1475
|
|
|
} |
1476
|
|
|
} |
1477
|
|
|
elseif ( isset( $options[ 'table_info' ][ 'object_fields' ] ) && isset( $options[ 'table_info' ][ 'object_fields' ][ $display ] ) ) { |
1478
|
|
|
$search_data->field_index = $display; |
1479
|
|
|
|
1480
|
|
|
$params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`"; |
1481
|
|
|
} |
1482
|
|
|
} |
1483
|
|
|
|
1484
|
|
|
$autocomplete = false; |
1485
|
|
|
|
1486
|
|
|
if ( 'single' == pods_var( self::$type . '_format_type', $options, 'single' ) && 'autocomplete' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) ) |
1487
|
|
|
$autocomplete = true; |
1488
|
|
View Code Duplication |
elseif ( 'multi' == pods_var( self::$type . '_format_type', $options, 'single' ) && 'autocomplete' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) ) |
1489
|
|
|
$autocomplete = true; |
1490
|
|
|
|
1491
|
|
|
$hierarchy = false; |
1492
|
|
|
|
1493
|
|
|
if ( 'data' == $context && !$autocomplete ) { |
1494
|
|
|
if ( 'single' == pods_var( self::$type . '_format_type', $options, 'single' ) && in_array( pods_var( self::$type . '_format_single', $options, 'dropdown' ), array( 'dropdown', 'radio' ) ) ) |
1495
|
|
|
$hierarchy = true; |
1496
|
|
View Code Duplication |
elseif ( 'multi' == pods_var( self::$type . '_format_type', $options, 'single' ) && in_array( pods_var( self::$type . '_format_multi', $options, 'checkbox' ), array( 'multiselect', 'checkbox' ) ) ) |
1497
|
|
|
$hierarchy = true; |
1498
|
|
|
} |
1499
|
|
|
|
1500
|
|
|
if ( $hierarchy && $options[ 'table_info' ][ 'object_hierarchical' ] && !empty( $options[ 'table_info' ][ 'field_parent' ] ) ) |
1501
|
|
|
$params[ 'select' ] .= ', ' . $options[ 'table_info' ][ 'field_parent_select' ]; |
1502
|
|
|
|
1503
|
|
|
if ( $autocomplete ) { |
1504
|
|
|
if ( 0 == $limit ) { |
1505
|
|
|
$limit = 30; |
1506
|
|
|
} |
1507
|
|
|
|
1508
|
|
|
$params[ 'limit' ] = apply_filters( 'pods_form_ui_field_pick_autocomplete_limit', $limit, $name, $value, $options, $pod, $id, $object_params ); |
1509
|
|
|
|
1510
|
|
|
if ( is_array( $value ) && $params[ 'limit' ] < count( $value ) ) { |
1511
|
|
|
$params[ 'limit' ] = count( $value ); |
1512
|
|
|
} |
1513
|
|
|
|
1514
|
|
|
$params[ 'page' ] = $page; |
1515
|
|
|
|
1516
|
|
|
if ( 'admin_ajax_relationship' == $context ) { |
1517
|
|
|
$lookup_where = array( |
1518
|
|
|
$search_data->field_index => "`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'" |
1519
|
|
|
); |
1520
|
|
|
|
1521
|
|
|
// @todo Hook into WPML for each table |
1522
|
|
|
if ( $wpdb->users == $search_data->table ) { |
1523
|
|
|
$lookup_where[ 'display_name' ] = "`t`.`display_name` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; |
1524
|
|
|
$lookup_where[ 'user_login' ] = "`t`.`user_login` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; |
1525
|
|
|
$lookup_where[ 'user_email' ] = "`t`.`user_email` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; |
1526
|
|
|
} |
1527
|
|
|
elseif ( $wpdb->posts == $search_data->table ) { |
1528
|
|
|
$lookup_where[ 'post_title' ] = "`t`.`post_title` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; |
1529
|
|
|
$lookup_where[ 'post_name' ] = "`t`.`post_name` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; |
1530
|
|
|
$lookup_where[ 'post_content' ] = "`t`.`post_content` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; |
1531
|
|
|
$lookup_where[ 'post_excerpt' ] = "`t`.`post_excerpt` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; |
1532
|
|
|
} |
1533
|
|
|
elseif ( $wpdb->terms == $search_data->table ) { |
1534
|
|
|
$lookup_where[ 'name' ] = "`t`.`name` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; |
1535
|
|
|
$lookup_where[ 'slug' ] = "`t`.`slug` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; |
1536
|
|
|
} |
1537
|
|
|
elseif ( $wpdb->comments == $search_data->table ) { |
1538
|
|
|
$lookup_where[ 'comment_content' ] = "`t`.`comment_content` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; |
1539
|
|
|
$lookup_where[ 'comment_author' ] = "`t`.`comment_author` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; |
1540
|
|
|
$lookup_where[ 'comment_author_email' ] = "`t`.`comment_author_email` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"; |
1541
|
|
|
} |
1542
|
|
|
|
1543
|
|
|
$lookup_where = apply_filters( 'pods_form_ui_field_pick_autocomplete_lookup', $lookup_where, $data_params[ 'query' ], $name, $value, $options, $pod, $id, $object_params, $search_data ); |
1544
|
|
|
|
1545
|
|
|
if ( !empty( $lookup_where ) ) |
1546
|
|
|
$params[ 'where' ][] = implode( ' OR ', $lookup_where ); |
1547
|
|
|
|
1548
|
|
|
$orderby = array(); |
1549
|
|
|
$orderby[] = "(`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%' ) DESC"; |
1550
|
|
|
|
1551
|
|
|
$pick_orderby = pods_var_raw( self::$type . '_orderby', $options, null, null, true ); |
1552
|
|
|
|
1553
|
|
|
if ( 0 < strlen( $pick_orderby ) ) |
1554
|
|
|
$orderby[] = $pick_orderby; |
1555
|
|
|
|
1556
|
|
|
$orderby[] = "`t`.`{$search_data->field_index}`"; |
1557
|
|
|
$orderby[] = "`t`.`{$search_data->field_id}`"; |
1558
|
|
|
|
1559
|
|
|
$params[ 'orderby' ] = $orderby; |
1560
|
|
|
} |
1561
|
|
|
} |
1562
|
|
|
elseif ( 0 < $limit ) { |
1563
|
|
|
$params[ 'limit' ] = $limit; |
1564
|
|
|
$params[ 'page' ] = $page; |
1565
|
|
|
} |
1566
|
|
|
|
1567
|
|
|
$extra = ''; |
1568
|
|
|
|
1569
|
|
|
if ( $wpdb->posts == $search_data->table ) |
1570
|
|
|
$extra = ', `t`.`post_type`'; |
1571
|
|
|
elseif ( $wpdb->terms == $search_data->table ) |
1572
|
|
|
$extra = ', `tt`.`taxonomy`'; |
1573
|
|
|
elseif ( $wpdb->comments == $search_data->table ) |
1574
|
|
|
$extra = ', `t`.`comment_type`'; |
1575
|
|
|
|
1576
|
|
|
$params[ 'select' ] .= $extra; |
1577
|
|
|
|
1578
|
|
|
if ( 'user' == pods_var( self::$type . '_object', $options ) ) { |
1579
|
|
|
$roles = pods_var( self::$type . '_user_role', $options ); |
1580
|
|
|
|
1581
|
|
|
if ( !empty( $roles ) ) { |
1582
|
|
|
$where = array(); |
1583
|
|
|
|
1584
|
|
|
foreach ( (array) $roles as $role ) { |
1585
|
|
|
if ( empty( $role ) || ( pods_clean_name( $role ) != $role && sanitize_title( $role ) != $role ) ) |
1586
|
|
|
continue; |
1587
|
|
|
|
1588
|
|
|
$where[] = $wpdb->base_prefix . ( ( is_multisite() && !is_main_site() ) ? get_current_blog_id() . '_' : '' ) . 'capabilities.meta_value LIKE "%\"' . pods_sanitize_like( $role ) . '\"%"'; |
1589
|
|
|
} |
1590
|
|
|
|
1591
|
|
|
if ( !empty( $where ) ) { |
1592
|
|
|
$params[ 'where' ][] = implode( ' OR ', $where ); |
1593
|
|
|
} |
1594
|
|
|
} |
1595
|
|
|
} |
1596
|
|
|
|
1597
|
|
|
$results = $search_data->select( $params ); |
1598
|
|
|
|
1599
|
|
|
if ( $autocomplete && $params[ 'limit' ] < $search_data->total_found() ) { |
1600
|
|
|
if ( !empty( $value ) ) { |
1601
|
|
|
$ids = $value; |
1602
|
|
|
|
1603
|
|
|
if ( is_array( $ids ) && isset( $ids[ 0 ] ) && is_array( $ids[ 0 ] ) ) { |
1604
|
|
|
$ids = wp_list_pluck( $ids, $search_data->field_id ); |
1605
|
|
|
} |
1606
|
|
|
|
1607
|
|
|
if ( is_array( $ids ) ) |
1608
|
|
|
$ids = implode( ', ', $ids ); |
1609
|
|
|
|
1610
|
|
|
if ( is_array( $params[ 'where' ] ) ) |
1611
|
|
|
$params[ 'where' ] = implode( ' AND ', $params[ 'where' ] ); |
1612
|
|
|
if ( !empty( $params[ 'where' ] ) ) |
1613
|
|
|
$params[ 'where' ] .= ' AND '; |
1614
|
|
|
|
1615
|
|
|
$params[ 'where' ] .= "`t`.`{$search_data->field_id}` IN ( " . $ids . " )"; |
1616
|
|
|
|
1617
|
|
|
$results = $search_data->select( $params ); |
1618
|
|
|
} |
1619
|
|
|
} |
1620
|
|
|
else |
1621
|
|
|
$autocomplete = false; |
1622
|
|
|
|
1623
|
|
|
if ( 'data' == $context ) { |
1624
|
|
|
self::$field_data = array( |
1625
|
|
|
'field' => $name, |
1626
|
|
|
'id' => $options[ 'id' ], |
1627
|
|
|
'autocomplete' => $autocomplete |
1628
|
|
|
); |
1629
|
|
|
} |
1630
|
|
|
|
1631
|
|
|
if ( $hierarchy && !$autocomplete && !empty( $results ) && $options[ 'table_info' ][ 'object_hierarchical' ] && !empty( $options[ 'table_info' ][ 'field_parent' ] ) ) { |
1632
|
|
|
$args = array( |
1633
|
|
|
'id' => $options[ 'table_info' ][ 'field_id' ], |
1634
|
|
|
'index' => $options[ 'table_info' ][ 'field_index' ], |
1635
|
|
|
'parent' => $options[ 'table_info' ][ 'field_parent' ], |
1636
|
|
|
); |
1637
|
|
|
|
1638
|
|
|
$results = pods_hierarchical_select( $results, $args ); |
1639
|
|
|
} |
1640
|
|
|
|
1641
|
|
|
$ids = array(); |
1642
|
|
|
|
1643
|
|
|
if ( !empty( $results ) ) { |
1644
|
|
|
$display_filter = pods_var( 'display_filter', pods_var_raw( 'options', pods_var_raw( $search_data->field_index, $search_data->pod_data[ 'object_fields' ] ) ) ); |
1645
|
|
|
|
1646
|
|
|
foreach ( $results as $result ) { |
1647
|
|
|
$result = get_object_vars( $result ); |
1648
|
|
|
|
1649
|
|
|
if ( !isset( $result[ $search_data->field_id ] ) || !isset( $result[ $search_data->field_index ] ) ) |
1650
|
|
|
continue; |
1651
|
|
|
|
1652
|
|
|
$result[ $search_data->field_index ] = trim( $result[ $search_data->field_index ] ); |
1653
|
|
|
|
1654
|
|
|
$object = $object_type = ''; |
1655
|
|
|
|
1656
|
|
|
if ( $wpdb->posts == $search_data->table && isset( $result[ 'post_type' ] ) ) { |
1657
|
|
|
$object = $result[ 'post_type' ]; |
1658
|
|
|
$object_type = 'post_type'; |
1659
|
|
|
} |
1660
|
|
|
elseif ( $wpdb->terms == $search_data->table && isset( $result[ 'taxonomy' ] ) ) { |
1661
|
|
|
$object = $result[ 'taxonomy' ]; |
1662
|
|
|
$object_type = 'taxonomy'; |
1663
|
|
|
} |
1664
|
|
|
|
1665
|
|
|
// WPML integration for Post Types and Taxonomies |
1666
|
|
|
if ( is_object( $sitepress ) && in_array( $object_type, array( 'post_type', 'taxonomy' ) ) ) { |
1667
|
|
|
$translated = false; |
1668
|
|
|
|
1669
|
|
|
if ( 'post_type' == $object_type && $sitepress->is_translated_post_type( $object ) ) |
1670
|
|
|
$translated = true; |
1671
|
|
|
elseif ( 'taxonomy' == $object_type && $sitepress->is_translated_taxonomy( $object ) ) |
1672
|
|
|
$translated = true; |
1673
|
|
|
|
1674
|
|
View Code Duplication |
if ( $translated ) { |
1675
|
|
|
$object_id = icl_object_id( $result[ $search_data->field_id ], $object, false, $current_language ); |
1676
|
|
|
|
1677
|
|
|
if ( 0 < $object_id && !in_array( $object_id, $ids ) ) { |
1678
|
|
|
$text = $result[ $search_data->field_index ]; |
1679
|
|
|
|
1680
|
|
|
if ( $result[ $search_data->field_id ] != $object_id ) { |
1681
|
|
|
if ( $wpdb->posts == $search_data->table ) |
1682
|
|
|
$text = trim( get_the_title( $object_id ) ); |
1683
|
|
|
elseif ( $wpdb->terms == $search_data->table ) |
1684
|
|
|
$text = trim( get_term( $object_id, $object )->name ); |
1685
|
|
|
} |
1686
|
|
|
|
1687
|
|
|
$result[ $search_data->field_id ] = $object_id; |
1688
|
|
|
$result[ $search_data->field_index ] = $text; |
1689
|
|
|
} |
1690
|
|
|
else |
1691
|
|
|
continue; |
1692
|
|
|
} |
1693
|
|
|
} |
1694
|
|
|
// Polylang integration for Post Types and Taxonomies |
1695
|
|
|
elseif ( is_object( $polylang ) && in_array( $object_type, array( 'post_type', 'taxonomy' ) ) && method_exists( $polylang, 'get_translation' ) ) { |
1696
|
|
|
$translated = false; |
1697
|
|
|
|
1698
|
|
|
if ( 'post_type' == $object_type && pll_is_translated_post_type( $object ) ) |
1699
|
|
|
$translated = true; |
1700
|
|
|
elseif ( 'taxonomy' == $object_type && pll_is_translated_taxonomy( $object ) ) |
1701
|
|
|
$translated = true; |
1702
|
|
|
|
1703
|
|
View Code Duplication |
if ( $translated ) { |
1704
|
|
|
$object_id = $polylang->get_translation( $object, $result[ $search_data->field_id ], $current_language ); |
1705
|
|
|
|
1706
|
|
|
if ( 0 < $object_id && !in_array( $object_id, $ids ) ) { |
1707
|
|
|
$text = $result[ $search_data->field_index ]; |
1708
|
|
|
|
1709
|
|
|
if ( $result[ $search_data->field_id ] != $object_id ) { |
1710
|
|
|
if ( $wpdb->posts == $search_data->table ) |
1711
|
|
|
$text = trim( get_the_title( $object_id ) ); |
1712
|
|
|
elseif ( $wpdb->terms == $search_data->table ) |
1713
|
|
|
$text = trim( get_term( $object_id, $object )->name ); |
1714
|
|
|
} |
1715
|
|
|
|
1716
|
|
|
$result[ $search_data->field_id ] = $object_id; |
1717
|
|
|
$result[ $search_data->field_index ] = $text; |
1718
|
|
|
} |
1719
|
|
|
else |
1720
|
|
|
continue; |
1721
|
|
|
} |
1722
|
|
|
} |
1723
|
|
|
|
1724
|
|
|
if ( 0 < strlen( $display_filter ) ) { |
1725
|
|
|
$display_filter_args = pods_var( 'display_filter_args', pods_var_raw( 'options', pods_var_raw( $search_data->field_index, $search_data->pod_data[ 'object_fields' ] ) ) ); |
1726
|
|
|
|
1727
|
|
|
$args = array( |
1728
|
|
|
$display_filter, |
1729
|
|
|
$result[ $search_data->field_index ] |
1730
|
|
|
); |
1731
|
|
|
|
1732
|
|
|
if ( !empty( $display_filter_args ) ) { |
1733
|
|
|
foreach ( (array) $display_filter_args as $display_filter_arg ) { |
1734
|
|
|
if ( isset( $result[ $display_filter_arg ] ) ) |
1735
|
|
|
$args[] = $result[ $display_filter_arg ]; |
1736
|
|
|
} |
1737
|
|
|
} |
1738
|
|
|
|
1739
|
|
|
$result[ $search_data->field_index ] = call_user_func_array( 'apply_filters', $args ); |
1740
|
|
|
} |
1741
|
|
|
|
1742
|
|
|
if ( in_array( $options[ self::$type . '_object' ], array( 'site', 'network' ) ) ) |
1743
|
|
|
$result[ $search_data->field_index ] = $result[ $search_data->field_index ] . $result[ 'path' ]; |
1744
|
|
|
elseif ( strlen( $result[ $search_data->field_index ] ) < 1 ) |
1745
|
|
|
$result[ $search_data->field_index ] = '(No Title)'; |
1746
|
|
|
|
1747
|
|
|
if ( 'admin_ajax_relationship' == $context ) { |
1748
|
|
|
$items[] = array( |
1749
|
|
|
'id' => $result[ $search_data->field_id ], |
1750
|
|
|
'text' => $result[ $search_data->field_index ], |
1751
|
|
|
'image' => '' |
1752
|
|
|
); |
1753
|
|
|
} |
1754
|
|
|
else |
1755
|
|
|
$data[ $result[ $search_data->field_id ] ] = $result[ $search_data->field_index ]; |
1756
|
|
|
|
1757
|
|
|
$ids[] = $result[ $search_data->field_id ]; |
1758
|
|
|
} |
1759
|
|
|
} |
1760
|
|
|
} |
1761
|
|
|
|
1762
|
|
|
if ( $simple && 'admin_ajax_relationship' == $context ) { |
1763
|
|
|
$found_data = array(); |
1764
|
|
|
|
1765
|
|
|
foreach ( $data as $k => $v ) { |
1766
|
|
|
if ( false !== stripos( $v, $data_params[ 'query' ] ) || false !== stripos( $k, $data_params[ 'query' ] ) ) { |
1767
|
|
|
$found_data[ $k ] = $v; |
1768
|
|
|
} |
1769
|
|
|
} |
1770
|
|
|
|
1771
|
|
|
$data = $found_data; |
1772
|
|
|
} |
1773
|
|
|
} |
1774
|
|
|
|
1775
|
|
|
if ( 'admin_ajax_relationship' == $context ) { |
1776
|
|
|
if ( empty( $items ) && !empty( $data ) ) { |
1777
|
|
|
foreach ( $data as $k => $v ) { |
1778
|
|
|
$items[] = array( |
1779
|
|
|
'id' => $k, |
1780
|
|
|
'text' => $v, |
1781
|
|
|
'image' => '' |
1782
|
|
|
); |
1783
|
|
|
} |
1784
|
|
|
} |
1785
|
|
|
|
1786
|
|
|
return $items; |
1787
|
|
|
} |
1788
|
|
|
|
1789
|
|
|
return $data; |
1790
|
|
|
} |
1791
|
|
|
|
1792
|
|
|
/** |
1793
|
|
|
* Handle autocomplete AJAX |
1794
|
|
|
* |
1795
|
|
|
* @since 2.3 |
1796
|
|
|
*/ |
1797
|
|
|
public function admin_ajax_relationship () { |
1798
|
|
|
pods_session_start(); |
1799
|
|
|
|
1800
|
|
|
// Sanitize input |
1801
|
|
|
$params = pods_unslash( (array) $_POST ); |
1802
|
|
|
|
1803
|
|
View Code Duplication |
foreach ( $params as $key => $value ) { |
1804
|
|
|
if ( 'action' == $key ) |
1805
|
|
|
continue; |
1806
|
|
|
|
1807
|
|
|
unset( $params[ $key ] ); |
1808
|
|
|
|
1809
|
|
|
$params[ str_replace( '_podsfix_', '', $key ) ] = $value; |
1810
|
|
|
} |
1811
|
|
|
|
1812
|
|
|
$params = (object) $params; |
1813
|
|
|
|
1814
|
|
|
$uid = @session_id(); |
1815
|
|
|
|
1816
|
|
|
if ( is_user_logged_in() ) |
1817
|
|
|
$uid = 'user_' . get_current_user_id(); |
1818
|
|
|
|
1819
|
|
|
$nonce_check = 'pods_relationship_' . (int) $params->pod . '_' . $uid . '_' . $params->uri . '_' . (int) $params->field; |
1820
|
|
|
|
1821
|
|
View Code Duplication |
if ( !isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, $nonce_check ) ) |
1822
|
|
|
pods_error( __( 'Unauthorized request', 'pods' ), PodsInit::$admin ); |
|
|
|
|
1823
|
|
|
|
1824
|
|
|
$api = pods_api(); |
1825
|
|
|
|
1826
|
|
|
$pod = $api->load_pod( array( 'id' => (int) $params->pod ) ); |
1827
|
|
|
$field = $api->load_field( array( 'id' => (int) $params->field, 'table_info' => true ) ); |
1828
|
|
|
$id = (int) $params->id; |
1829
|
|
|
|
1830
|
|
|
$limit = 15; |
1831
|
|
|
|
1832
|
|
|
if ( isset( $params->limit ) ) |
1833
|
|
|
$limit = (int) $params->limit; |
1834
|
|
|
|
1835
|
|
|
$page = 1; |
1836
|
|
|
|
1837
|
|
|
if ( isset( $params->page ) ) |
1838
|
|
|
$page = (int) $params->page; |
1839
|
|
|
|
1840
|
|
|
if ( !isset( $params->query ) || strlen( trim( $params->query ) ) < 1 ) |
1841
|
|
|
pods_error( __( 'Invalid field request', 'pods' ), PodsInit::$admin ); |
|
|
|
|
1842
|
|
View Code Duplication |
elseif ( empty( $pod ) || empty( $field ) || $pod[ 'id' ] != $field[ 'pod_id' ] || !isset( $pod[ 'fields' ][ $field[ 'name' ] ] ) ) |
1843
|
|
|
pods_error( __( 'Invalid field request', 'pods' ), PodsInit::$admin ); |
|
|
|
|
1844
|
|
|
elseif ( 'pick' != $field[ 'type' ] || empty( $field[ 'table_info' ] ) ) |
1845
|
|
|
pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin ); |
|
|
|
|
1846
|
|
View Code Duplication |
elseif ( 'single' == pods_var( self::$type . '_format_type', $field ) && 'autocomplete' == pods_var( self::$type . '_format_single', $field ) ) |
1847
|
|
|
pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin ); |
|
|
|
|
1848
|
|
View Code Duplication |
elseif ( 'multi' == pods_var( self::$type . '_format_type', $field ) && 'autocomplete' == pods_var( self::$type . '_format_multi', $field ) ) |
1849
|
|
|
pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin ); |
|
|
|
|
1850
|
|
|
|
1851
|
|
|
$object_params = array( |
1852
|
|
|
'name' => $field[ 'name' ], // The name of the field |
1853
|
|
|
'value' => null, // The value of the field |
1854
|
|
|
'options' => array_merge( $field, $field[ 'options' ] ), // Field options |
1855
|
|
|
'pod' => $pod, // Pod data |
1856
|
|
|
'id' => $id, // Item ID |
1857
|
|
|
'context' => 'admin_ajax_relationship', // Data context |
1858
|
|
|
'data_params' => $params, |
1859
|
|
|
'page' => $page, |
1860
|
|
|
'limit' => $limit |
1861
|
|
|
); |
1862
|
|
|
|
1863
|
|
|
$pick_data = apply_filters( 'pods_field_pick_data_ajax', null, $field[ 'name' ], null, $field, $pod, $id ); |
1864
|
|
|
|
1865
|
|
|
if ( null !== $pick_data ) |
1866
|
|
|
$items = $pick_data; |
1867
|
|
|
else |
1868
|
|
|
$items = $this->get_object_data( $object_params ); |
1869
|
|
|
|
1870
|
|
|
if ( !empty( $items ) && isset( $items[ 0 ] ) && !is_array( $items[ 0 ] ) ) { |
1871
|
|
|
$new_items = array(); |
1872
|
|
|
|
1873
|
|
|
foreach ( $items as $id => $text ) { |
1874
|
|
|
$new_items[] = array( |
1875
|
|
|
'id' => $id, |
1876
|
|
|
'text' => $text, |
1877
|
|
|
'image' => '' |
1878
|
|
|
); |
1879
|
|
|
} |
1880
|
|
|
|
1881
|
|
|
$items = $new_items; |
1882
|
|
|
} |
1883
|
|
|
|
1884
|
|
|
$items = apply_filters( 'pods_field_pick_data_ajax_items', $items, $field[ 'name' ], null, $field, $pod, $id ); |
1885
|
|
|
|
1886
|
|
|
$items = array( |
1887
|
|
|
'results' => $items |
1888
|
|
|
); |
1889
|
|
|
|
1890
|
|
|
wp_send_json( $items ); |
1891
|
|
|
|
1892
|
|
|
die(); // KBAI! |
|
|
|
|
1893
|
|
|
} |
1894
|
|
|
|
1895
|
|
|
/** |
1896
|
|
|
* Data callback for Post Stati |
1897
|
|
|
* |
1898
|
|
|
* @param string $name The name of the field |
1899
|
|
|
* @param string|array $value The value of the field |
1900
|
|
|
* @param array $options Field options |
1901
|
|
|
* @param array $pod Pod data |
1902
|
|
|
* @param int $id Item ID |
1903
|
|
|
* |
1904
|
|
|
* @return array |
1905
|
|
|
* |
1906
|
|
|
* @since 2.3 |
1907
|
|
|
*/ |
1908
|
|
|
public function data_post_stati ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { |
1909
|
|
|
$data = array(); |
1910
|
|
|
|
1911
|
|
|
$post_stati = get_post_stati( array(), 'objects' ); |
1912
|
|
|
|
1913
|
|
|
foreach ( $post_stati as $post_status ) { |
1914
|
|
|
$data[ $post_status->name ] = $post_status->label; |
1915
|
|
|
} |
1916
|
|
|
|
1917
|
|
|
return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); |
1918
|
|
|
} |
1919
|
|
|
|
1920
|
|
|
/** |
1921
|
|
|
* Data callback for User Roles |
1922
|
|
|
* |
1923
|
|
|
* @param string $name The name of the field |
1924
|
|
|
* @param string|array $value The value of the field |
1925
|
|
|
* @param array $options Field options |
1926
|
|
|
* @param array $pod Pod data |
1927
|
|
|
* @param int $id Item ID |
1928
|
|
|
* |
1929
|
|
|
* @return array |
1930
|
|
|
* |
1931
|
|
|
* @since 2.3 |
1932
|
|
|
*/ |
1933
|
|
|
public function data_roles ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { |
1934
|
|
|
$data = array(); |
1935
|
|
|
|
1936
|
|
|
global $wp_roles; |
|
|
|
|
1937
|
|
|
|
1938
|
|
|
foreach ( $wp_roles->role_objects as $key => $role ) { |
1939
|
|
|
$data[ $key ] = $wp_roles->role_names[ $key ]; |
1940
|
|
|
} |
1941
|
|
|
|
1942
|
|
|
return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); |
1943
|
|
|
} |
1944
|
|
|
|
1945
|
|
|
/** |
1946
|
|
|
* Data callback for User Capabilities |
1947
|
|
|
* |
1948
|
|
|
* @param string $name The name of the field |
1949
|
|
|
* @param string|array $value The value of the field |
1950
|
|
|
* @param array $options Field options |
1951
|
|
|
* @param array $pod Pod data |
1952
|
|
|
* @param int $id Item ID |
1953
|
|
|
* |
1954
|
|
|
* @return array |
1955
|
|
|
* |
1956
|
|
|
* @since 2.3 |
1957
|
|
|
*/ |
1958
|
|
|
public function data_capabilities ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { |
1959
|
|
|
$data = array(); |
1960
|
|
|
|
1961
|
|
|
global $wp_roles; |
|
|
|
|
1962
|
|
|
|
1963
|
|
|
$default_caps = array( |
1964
|
|
|
'activate_plugins', |
1965
|
|
|
'add_users', |
1966
|
|
|
'create_users', |
1967
|
|
|
'delete_others_pages', |
1968
|
|
|
'delete_others_posts', |
1969
|
|
|
'delete_pages', |
1970
|
|
|
'delete_plugins', |
1971
|
|
|
'delete_posts', |
1972
|
|
|
'delete_private_pages', |
1973
|
|
|
'delete_private_posts', |
1974
|
|
|
'delete_published_pages', |
1975
|
|
|
'delete_published_posts', |
1976
|
|
|
'delete_users', |
1977
|
|
|
'edit_dashboard', |
1978
|
|
|
'edit_files', |
1979
|
|
|
'edit_others_pages', |
1980
|
|
|
'edit_others_posts', |
1981
|
|
|
'edit_pages', |
1982
|
|
|
'edit_plugins', |
1983
|
|
|
'edit_posts', |
1984
|
|
|
'edit_private_pages', |
1985
|
|
|
'edit_private_posts', |
1986
|
|
|
'edit_published_pages', |
1987
|
|
|
'edit_published_posts', |
1988
|
|
|
'edit_theme_options', |
1989
|
|
|
'edit_themes', |
1990
|
|
|
'edit_users', |
1991
|
|
|
'import', |
1992
|
|
|
'install_plugins', |
1993
|
|
|
'install_themes', |
1994
|
|
|
'list_users', |
1995
|
|
|
'manage_categories', |
1996
|
|
|
'manage_links', |
1997
|
|
|
'manage_options', |
1998
|
|
|
'moderate_comments', |
1999
|
|
|
'promote_users', |
2000
|
|
|
'publish_pages', |
2001
|
|
|
'publish_posts', |
2002
|
|
|
'read', |
2003
|
|
|
'read_private_pages', |
2004
|
|
|
'read_private_posts', |
2005
|
|
|
'remove_users', |
2006
|
|
|
'switch_themes', |
2007
|
|
|
'unfiltered_html', |
2008
|
|
|
'unfiltered_upload', |
2009
|
|
|
'update_core', |
2010
|
|
|
'update_plugins', |
2011
|
|
|
'update_themes', |
2012
|
|
|
'upload_files' |
2013
|
|
|
); |
2014
|
|
|
|
2015
|
|
|
$role_caps = array(); |
2016
|
|
|
|
2017
|
|
View Code Duplication |
foreach ( $wp_roles->role_objects as $key => $role ) { |
2018
|
|
|
if ( is_array( $role->capabilities ) ) { |
2019
|
|
|
foreach ( $role->capabilities as $cap => $grant ) { |
2020
|
|
|
$role_caps[ $cap ] = $cap; |
2021
|
|
|
} |
2022
|
|
|
} |
2023
|
|
|
} |
2024
|
|
|
|
2025
|
|
|
$role_caps = array_unique( $role_caps ); |
2026
|
|
|
|
2027
|
|
|
$capabilities = array_merge( $default_caps, $role_caps ); |
2028
|
|
|
|
2029
|
|
|
// To support Members filters |
2030
|
|
|
$capabilities = apply_filters( 'members_get_capabilities', $capabilities ); |
2031
|
|
|
|
2032
|
|
|
$capabilities = apply_filters( 'pods_roles_get_capabilities', $capabilities ); |
2033
|
|
|
|
2034
|
|
|
sort( $capabilities ); |
2035
|
|
|
|
2036
|
|
|
$capabilities = array_unique( $capabilities ); |
2037
|
|
|
|
2038
|
|
|
global $wp_roles; |
|
|
|
|
2039
|
|
|
|
2040
|
|
|
foreach ( $capabilities as $capability ) { |
2041
|
|
|
$data[ $capability ] = $capability; |
2042
|
|
|
} |
2043
|
|
|
|
2044
|
|
|
return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); |
2045
|
|
|
} |
2046
|
|
|
|
2047
|
|
|
/** |
2048
|
|
|
* Data callback for Image Sizes |
2049
|
|
|
* |
2050
|
|
|
* @param string $name The name of the field |
2051
|
|
|
* @param string|array $value The value of the field |
2052
|
|
|
* @param array $options Field options |
2053
|
|
|
* @param array $pod Pod data |
2054
|
|
|
* @param int $id Item ID |
2055
|
|
|
* |
2056
|
|
|
* @return array |
2057
|
|
|
* |
2058
|
|
|
* @since 2.3 |
2059
|
|
|
*/ |
2060
|
|
|
public function data_image_sizes ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { |
2061
|
|
|
$data = array(); |
2062
|
|
|
|
2063
|
|
|
$image_sizes = get_intermediate_image_sizes(); |
2064
|
|
|
|
2065
|
|
|
foreach ( $image_sizes as $image_size ) { |
2066
|
|
|
$data[ $image_size ] = ucwords( str_replace( '-', ' ', $image_size ) ); |
2067
|
|
|
} |
2068
|
|
|
|
2069
|
|
|
return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); |
2070
|
|
|
} |
2071
|
|
|
|
2072
|
|
|
/** |
2073
|
|
|
* Data callback for Countries |
2074
|
|
|
* |
2075
|
|
|
* @param string $name The name of the field |
2076
|
|
|
* @param string|array $value The value of the field |
2077
|
|
|
* @param array $options Field options |
2078
|
|
|
* @param array $pod Pod data |
2079
|
|
|
* @param int $id Item ID |
2080
|
|
|
* |
2081
|
|
|
* @return array |
2082
|
|
|
* |
2083
|
|
|
* @since 2.3 |
2084
|
|
|
*/ |
2085
|
|
|
public function data_countries ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { |
2086
|
|
|
$data = array( |
2087
|
|
|
'AF' => __( 'Afghanistan' ), |
2088
|
|
|
'AL' => __( 'Albania' ), |
2089
|
|
|
'DZ' => __( 'Algeria' ), |
2090
|
|
|
'AS' => __( 'American Samoa' ), |
2091
|
|
|
'AD' => __( 'Andorra' ), |
2092
|
|
|
'AO' => __( 'Angola' ), |
2093
|
|
|
'AI' => __( 'Anguilla' ), |
2094
|
|
|
'AQ' => __( 'Antarctica' ), |
2095
|
|
|
'AG' => __( 'Antigua and Barbuda' ), |
2096
|
|
|
'AR' => __( 'Argentina' ), |
2097
|
|
|
'AM' => __( 'Armenia' ), |
2098
|
|
|
'AW' => __( 'Aruba' ), |
2099
|
|
|
'AU' => __( 'Australia' ), |
2100
|
|
|
'AT' => __( 'Austria' ), |
2101
|
|
|
'AZ' => __( 'Azerbaijan' ), |
2102
|
|
|
'BS' => __( 'Bahamas' ), |
2103
|
|
|
'BH' => __( 'Bahrain' ), |
2104
|
|
|
'BD' => __( 'Bangladesh' ), |
2105
|
|
|
'BB' => __( 'Barbados' ), |
2106
|
|
|
'BY' => __( 'Belarus' ), |
2107
|
|
|
'BE' => __( 'Belgium' ), |
2108
|
|
|
'BZ' => __( 'Belize' ), |
2109
|
|
|
'BJ' => __( 'Benin' ), |
2110
|
|
|
'BM' => __( 'Bermuda' ), |
2111
|
|
|
'BT' => __( 'Bhutan' ), |
2112
|
|
|
'BO' => __( 'Bolivia' ), |
2113
|
|
|
'BA' => __( 'Bosnia and Herzegovina' ), |
2114
|
|
|
'BW' => __( 'Botswana' ), |
2115
|
|
|
'BV' => __( 'Bouvet Island' ), |
2116
|
|
|
'BR' => __( 'Brazil' ), |
2117
|
|
|
'BQ' => __( 'British Antarctic Territory' ), |
2118
|
|
|
'IO' => __( 'British Indian Ocean Territory' ), |
2119
|
|
|
'VG' => __( 'British Virgin Islands' ), |
2120
|
|
|
'BN' => __( 'Brunei' ), |
2121
|
|
|
'BG' => __( 'Bulgaria' ), |
2122
|
|
|
'BF' => __( 'Burkina Faso' ), |
2123
|
|
|
'BI' => __( 'Burundi' ), |
2124
|
|
|
'KH' => __( 'Cambodia' ), |
2125
|
|
|
'CM' => __( 'Cameroon' ), |
2126
|
|
|
'CA' => __( 'Canada' ), |
2127
|
|
|
'CT' => __( 'Canton and Enderbury Islands' ), |
2128
|
|
|
'CV' => __( 'Cape Verde' ), |
2129
|
|
|
'KY' => __( 'Cayman Islands' ), |
2130
|
|
|
'CF' => __( 'Central African Republic' ), |
2131
|
|
|
'TD' => __( 'Chad' ), |
2132
|
|
|
'CL' => __( 'Chile' ), |
2133
|
|
|
'CN' => __( 'China' ), |
2134
|
|
|
'CX' => __( 'Christmas Island' ), |
2135
|
|
|
'CC' => __( 'Cocos [Keeling] Islands' ), |
2136
|
|
|
'CO' => __( 'Colombia' ), |
2137
|
|
|
'KM' => __( 'Comoros' ), |
2138
|
|
|
'CG' => __( 'Congo - Brazzaville' ), |
2139
|
|
|
'CD' => __( 'Congo - Kinshasa' ), |
2140
|
|
|
'CK' => __( 'Cook Islands' ), |
2141
|
|
|
'CR' => __( 'Costa Rica' ), |
2142
|
|
|
'HR' => __( 'Croatia' ), |
2143
|
|
|
'CU' => __( 'Cuba' ), |
2144
|
|
|
'CY' => __( 'Cyprus' ), |
2145
|
|
|
'CZ' => __( 'Czech Republic' ), |
2146
|
|
|
'CI' => __( 'Côte d’Ivoire' ), |
2147
|
|
|
'DK' => __( 'Denmark' ), |
2148
|
|
|
'DJ' => __( 'Djibouti' ), |
2149
|
|
|
'DM' => __( 'Dominica' ), |
2150
|
|
|
'DO' => __( 'Dominican Republic' ), |
2151
|
|
|
'NQ' => __( 'Dronning Maud Land' ), |
2152
|
|
|
'DD' => __( 'East Germany' ), |
2153
|
|
|
'EC' => __( 'Ecuador' ), |
2154
|
|
|
'EG' => __( 'Egypt' ), |
2155
|
|
|
'SV' => __( 'El Salvador' ), |
2156
|
|
|
'GQ' => __( 'Equatorial Guinea' ), |
2157
|
|
|
'ER' => __( 'Eritrea' ), |
2158
|
|
|
'EE' => __( 'Estonia' ), |
2159
|
|
|
'ET' => __( 'Ethiopia' ), |
2160
|
|
|
'FK' => __( 'Falkland Islands' ), |
2161
|
|
|
'FO' => __( 'Faroe Islands' ), |
2162
|
|
|
'FJ' => __( 'Fiji' ), |
2163
|
|
|
'FI' => __( 'Finland' ), |
2164
|
|
|
'FR' => __( 'France' ), |
2165
|
|
|
'GF' => __( 'French Guiana' ), |
2166
|
|
|
'PF' => __( 'French Polynesia' ), |
2167
|
|
|
'TF' => __( 'French Southern Territories' ), |
2168
|
|
|
'FQ' => __( 'French Southern and Antarctic Territories' ), |
2169
|
|
|
'GA' => __( 'Gabon' ), |
2170
|
|
|
'GM' => __( 'Gambia' ), |
2171
|
|
|
'GE' => __( 'Georgia' ), |
2172
|
|
|
'DE' => __( 'Germany' ), |
2173
|
|
|
'GH' => __( 'Ghana' ), |
2174
|
|
|
'GI' => __( 'Gibraltar' ), |
2175
|
|
|
'GR' => __( 'Greece' ), |
2176
|
|
|
'GL' => __( 'Greenland' ), |
2177
|
|
|
'GD' => __( 'Grenada' ), |
2178
|
|
|
'GP' => __( 'Guadeloupe' ), |
2179
|
|
|
'GU' => __( 'Guam' ), |
2180
|
|
|
'GT' => __( 'Guatemala' ), |
2181
|
|
|
'GG' => __( 'Guernsey' ), |
2182
|
|
|
'GN' => __( 'Guinea' ), |
2183
|
|
|
'GW' => __( 'Guinea-Bissau' ), |
2184
|
|
|
'GY' => __( 'Guyana' ), |
2185
|
|
|
'HT' => __( 'Haiti' ), |
2186
|
|
|
'HM' => __( 'Heard Island and McDonald Islands' ), |
2187
|
|
|
'HN' => __( 'Honduras' ), |
2188
|
|
|
'HK' => __( 'Hong Kong SAR China' ), |
2189
|
|
|
'HU' => __( 'Hungary' ), |
2190
|
|
|
'IS' => __( 'Iceland' ), |
2191
|
|
|
'IN' => __( 'India' ), |
2192
|
|
|
'ID' => __( 'Indonesia' ), |
2193
|
|
|
'IR' => __( 'Iran' ), |
2194
|
|
|
'IQ' => __( 'Iraq' ), |
2195
|
|
|
'IE' => __( 'Ireland' ), |
2196
|
|
|
'IM' => __( 'Isle of Man' ), |
2197
|
|
|
'IL' => __( 'Israel' ), |
2198
|
|
|
'IT' => __( 'Italy' ), |
2199
|
|
|
'JM' => __( 'Jamaica' ), |
2200
|
|
|
'JP' => __( 'Japan' ), |
2201
|
|
|
'JE' => __( 'Jersey' ), |
2202
|
|
|
'JT' => __( 'Johnston Island' ), |
2203
|
|
|
'JO' => __( 'Jordan' ), |
2204
|
|
|
'KZ' => __( 'Kazakhstan' ), |
2205
|
|
|
'KE' => __( 'Kenya' ), |
2206
|
|
|
'KI' => __( 'Kiribati' ), |
2207
|
|
|
'KW' => __( 'Kuwait' ), |
2208
|
|
|
'KG' => __( 'Kyrgyzstan' ), |
2209
|
|
|
'LA' => __( 'Laos' ), |
2210
|
|
|
'LV' => __( 'Latvia' ), |
2211
|
|
|
'LB' => __( 'Lebanon' ), |
2212
|
|
|
'LS' => __( 'Lesotho' ), |
2213
|
|
|
'LR' => __( 'Liberia' ), |
2214
|
|
|
'LY' => __( 'Libya' ), |
2215
|
|
|
'LI' => __( 'Liechtenstein' ), |
2216
|
|
|
'LT' => __( 'Lithuania' ), |
2217
|
|
|
'LU' => __( 'Luxembourg' ), |
2218
|
|
|
'MO' => __( 'Macau SAR China' ), |
2219
|
|
|
'MK' => __( 'Macedonia' ), |
2220
|
|
|
'MG' => __( 'Madagascar' ), |
2221
|
|
|
'MW' => __( 'Malawi' ), |
2222
|
|
|
'MY' => __( 'Malaysia' ), |
2223
|
|
|
'MV' => __( 'Maldives' ), |
2224
|
|
|
'ML' => __( 'Mali' ), |
2225
|
|
|
'MT' => __( 'Malta' ), |
2226
|
|
|
'MH' => __( 'Marshall Islands' ), |
2227
|
|
|
'MQ' => __( 'Martinique' ), |
2228
|
|
|
'MR' => __( 'Mauritania' ), |
2229
|
|
|
'MU' => __( 'Mauritius' ), |
2230
|
|
|
'YT' => __( 'Mayotte' ), |
2231
|
|
|
'FX' => __( 'Metropolitan France' ), |
2232
|
|
|
'MX' => __( 'Mexico' ), |
2233
|
|
|
'FM' => __( 'Micronesia' ), |
2234
|
|
|
'MI' => __( 'Midway Islands' ), |
2235
|
|
|
'MD' => __( 'Moldova' ), |
2236
|
|
|
'MC' => __( 'Monaco' ), |
2237
|
|
|
'MN' => __( 'Mongolia' ), |
2238
|
|
|
'ME' => __( 'Montenegro' ), |
2239
|
|
|
'MS' => __( 'Montserrat' ), |
2240
|
|
|
'MA' => __( 'Morocco' ), |
2241
|
|
|
'MZ' => __( 'Mozambique' ), |
2242
|
|
|
'MM' => __( 'Myanmar [Burma]' ), |
2243
|
|
|
'NA' => __( 'Namibia' ), |
2244
|
|
|
'NR' => __( 'Nauru' ), |
2245
|
|
|
'NP' => __( 'Nepal' ), |
2246
|
|
|
'NL' => __( 'Netherlands' ), |
2247
|
|
|
'AN' => __( 'Netherlands Antilles' ), |
2248
|
|
|
'NT' => __( 'Neutral Zone' ), |
2249
|
|
|
'NC' => __( 'New Caledonia' ), |
2250
|
|
|
'NZ' => __( 'New Zealand' ), |
2251
|
|
|
'NI' => __( 'Nicaragua' ), |
2252
|
|
|
'NE' => __( 'Niger' ), |
2253
|
|
|
'NG' => __( 'Nigeria' ), |
2254
|
|
|
'NU' => __( 'Niue' ), |
2255
|
|
|
'NF' => __( 'Norfolk Island' ), |
2256
|
|
|
'KP' => __( 'North Korea' ), |
2257
|
|
|
'VD' => __( 'North Vietnam' ), |
2258
|
|
|
'MP' => __( 'Northern Mariana Islands' ), |
2259
|
|
|
'NO' => __( 'Norway' ), |
2260
|
|
|
'OM' => __( 'Oman' ), |
2261
|
|
|
'PC' => __( 'Pacific Islands Trust Territory' ), |
2262
|
|
|
'PK' => __( 'Pakistan' ), |
2263
|
|
|
'PW' => __( 'Palau' ), |
2264
|
|
|
'PS' => __( 'Palestinian Territories' ), |
2265
|
|
|
'PA' => __( 'Panama' ), |
2266
|
|
|
'PZ' => __( 'Panama Canal Zone' ), |
2267
|
|
|
'PG' => __( 'Papua New Guinea' ), |
2268
|
|
|
'PY' => __( 'Paraguay' ), |
2269
|
|
|
'YD' => __( "People's Democratic Republic of Yemen" ), |
2270
|
|
|
'PE' => __( 'Peru' ), |
2271
|
|
|
'PH' => __( 'Philippines' ), |
2272
|
|
|
'PN' => __( 'Pitcairn Islands' ), |
2273
|
|
|
'PL' => __( 'Poland' ), |
2274
|
|
|
'PT' => __( 'Portugal' ), |
2275
|
|
|
'PR' => __( 'Puerto Rico' ), |
2276
|
|
|
'QA' => __( 'Qatar' ), |
2277
|
|
|
'RO' => __( 'Romania' ), |
2278
|
|
|
'RU' => __( 'Russia' ), |
2279
|
|
|
'RW' => __( 'Rwanda' ), |
2280
|
|
|
'RE' => __( 'Réunion' ), |
2281
|
|
|
'BL' => __( 'Saint Barthélemy' ), |
2282
|
|
|
'SH' => __( 'Saint Helena' ), |
2283
|
|
|
'KN' => __( 'Saint Kitts and Nevis' ), |
2284
|
|
|
'LC' => __( 'Saint Lucia' ), |
2285
|
|
|
'MF' => __( 'Saint Martin' ), |
2286
|
|
|
'PM' => __( 'Saint Pierre and Miquelon' ), |
2287
|
|
|
'VC' => __( 'Saint Vincent and the Grenadines' ), |
2288
|
|
|
'WS' => __( 'Samoa' ), |
2289
|
|
|
'SM' => __( 'San Marino' ), |
2290
|
|
|
'SA' => __( 'Saudi Arabia' ), |
2291
|
|
|
'SN' => __( 'Senegal' ), |
2292
|
|
|
'RS' => __( 'Serbia' ), |
2293
|
|
|
'CS' => __( 'Serbia and Montenegro' ), |
2294
|
|
|
'SC' => __( 'Seychelles' ), |
2295
|
|
|
'SL' => __( 'Sierra Leone' ), |
2296
|
|
|
'SG' => __( 'Singapore' ), |
2297
|
|
|
'SK' => __( 'Slovakia' ), |
2298
|
|
|
'SI' => __( 'Slovenia' ), |
2299
|
|
|
'SB' => __( 'Solomon Islands' ), |
2300
|
|
|
'SO' => __( 'Somalia' ), |
2301
|
|
|
'ZA' => __( 'South Africa' ), |
2302
|
|
|
'GS' => __( 'South Georgia and the South Sandwich Islands' ), |
2303
|
|
|
'KR' => __( 'South Korea' ), |
2304
|
|
|
'ES' => __( 'Spain' ), |
2305
|
|
|
'LK' => __( 'Sri Lanka' ), |
2306
|
|
|
'SD' => __( 'Sudan' ), |
2307
|
|
|
'SR' => __( 'Suriname' ), |
2308
|
|
|
'SJ' => __( 'Svalbard and Jan Mayen' ), |
2309
|
|
|
'SZ' => __( 'Swaziland' ), |
2310
|
|
|
'SE' => __( 'Sweden' ), |
2311
|
|
|
'CH' => __( 'Switzerland' ), |
2312
|
|
|
'SY' => __( 'Syria' ), |
2313
|
|
|
'ST' => __( 'São Tomé and Príncipe' ), |
2314
|
|
|
'TW' => __( 'Taiwan' ), |
2315
|
|
|
'TJ' => __( 'Tajikistan' ), |
2316
|
|
|
'TZ' => __( 'Tanzania' ), |
2317
|
|
|
'TH' => __( 'Thailand' ), |
2318
|
|
|
'TL' => __( 'Timor-Leste' ), |
2319
|
|
|
'TG' => __( 'Togo' ), |
2320
|
|
|
'TK' => __( 'Tokelau' ), |
2321
|
|
|
'TO' => __( 'Tonga' ), |
2322
|
|
|
'TT' => __( 'Trinidad and Tobago' ), |
2323
|
|
|
'TN' => __( 'Tunisia' ), |
2324
|
|
|
'TR' => __( 'Turkey' ), |
2325
|
|
|
'TM' => __( 'Turkmenistan' ), |
2326
|
|
|
'TC' => __( 'Turks and Caicos Islands' ), |
2327
|
|
|
'TV' => __( 'Tuvalu' ), |
2328
|
|
|
'UM' => __( 'U.S. Minor Outlying Islands' ), |
2329
|
|
|
'PU' => __( 'U.S. Miscellaneous Pacific Islands' ), |
2330
|
|
|
'VI' => __( 'U.S. Virgin Islands' ), |
2331
|
|
|
'UG' => __( 'Uganda' ), |
2332
|
|
|
'UA' => __( 'Ukraine' ), |
2333
|
|
|
'SU' => __( 'Union of Soviet Socialist Republics' ), |
2334
|
|
|
'AE' => __( 'United Arab Emirates' ), |
2335
|
|
|
'GB' => __( 'United Kingdom' ), |
2336
|
|
|
'US' => __( 'United States' ), |
2337
|
|
|
'ZZ' => __( 'Unknown or Invalid Region' ), |
2338
|
|
|
'UY' => __( 'Uruguay' ), |
2339
|
|
|
'UZ' => __( 'Uzbekistan' ), |
2340
|
|
|
'VU' => __( 'Vanuatu' ), |
2341
|
|
|
'VA' => __( 'Vatican City' ), |
2342
|
|
|
'VE' => __( 'Venezuela' ), |
2343
|
|
|
'VN' => __( 'Vietnam' ), |
2344
|
|
|
'WK' => __( 'Wake Island' ), |
2345
|
|
|
'WF' => __( 'Wallis and Futuna' ), |
2346
|
|
|
'EH' => __( 'Western Sahara' ), |
2347
|
|
|
'YE' => __( 'Yemen' ), |
2348
|
|
|
'ZM' => __( 'Zambia' ), |
2349
|
|
|
'ZW' => __( 'Zimbabwe' ), |
2350
|
|
|
'AX' => __( 'Åland Islands' ) |
2351
|
|
|
); |
2352
|
|
|
|
2353
|
|
|
return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); |
2354
|
|
|
} |
2355
|
|
|
|
2356
|
|
|
/** |
2357
|
|
|
* Data callback for US States |
2358
|
|
|
* |
2359
|
|
|
* @param string $name The name of the field |
2360
|
|
|
* @param string|array $value The value of the field |
2361
|
|
|
* @param array $options Field options |
2362
|
|
|
* @param array $pod Pod data |
2363
|
|
|
* @param int $id Item ID |
2364
|
|
|
* |
2365
|
|
|
* @return array |
2366
|
|
|
* |
2367
|
|
|
* @since 2.3 |
2368
|
|
|
*/ |
2369
|
|
|
public function data_us_states ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { |
2370
|
|
|
$data = array( |
2371
|
|
|
'AL' => __( 'Alabama' ), |
2372
|
|
|
'AK' => __( 'Alaska' ), |
2373
|
|
|
'AZ' => __( 'Arizona' ), |
2374
|
|
|
'AR' => __( 'Arkansas' ), |
2375
|
|
|
'CA' => __( 'California' ), |
2376
|
|
|
'CO' => __( 'Colorado' ), |
2377
|
|
|
'CT' => __( 'Connecticut' ), |
2378
|
|
|
'DE' => __( 'Delaware' ), |
2379
|
|
|
'DC' => __( 'District Of Columbia' ), |
2380
|
|
|
'FL' => __( 'Florida' ), |
2381
|
|
|
'GA' => __( 'Georgia' ), |
2382
|
|
|
'HI' => __( 'Hawaii' ), |
2383
|
|
|
'ID' => __( 'Idaho' ), |
2384
|
|
|
'IL' => __( 'Illinois' ), |
2385
|
|
|
'IN' => __( 'Indiana' ), |
2386
|
|
|
'IA' => __( 'Iowa' ), |
2387
|
|
|
'KS' => __( 'Kansas' ), |
2388
|
|
|
'KY' => __( 'Kentucky' ), |
2389
|
|
|
'LA' => __( 'Louisiana' ), |
2390
|
|
|
'ME' => __( 'Maine' ), |
2391
|
|
|
'MD' => __( 'Maryland' ), |
2392
|
|
|
'MA' => __( 'Massachusetts' ), |
2393
|
|
|
'MI' => __( 'Michigan' ), |
2394
|
|
|
'MN' => __( 'Minnesota' ), |
2395
|
|
|
'MS' => __( 'Mississippi' ), |
2396
|
|
|
'MO' => __( 'Missouri' ), |
2397
|
|
|
'MT' => __( 'Montana' ), |
2398
|
|
|
'NE' => __( 'Nebraska' ), |
2399
|
|
|
'NV' => __( 'Nevada' ), |
2400
|
|
|
'NH' => __( 'New Hampshire' ), |
2401
|
|
|
'NJ' => __( 'New Jersey' ), |
2402
|
|
|
'NM' => __( 'New Mexico' ), |
2403
|
|
|
'NY' => __( 'New York' ), |
2404
|
|
|
'NC' => __( 'North Carolina' ), |
2405
|
|
|
'ND' => __( 'North Dakota' ), |
2406
|
|
|
'OH' => __( 'Ohio' ), |
2407
|
|
|
'OK' => __( 'Oklahoma' ), |
2408
|
|
|
'OR' => __( 'Oregon' ), |
2409
|
|
|
'PA' => __( 'Pennsylvania' ), |
2410
|
|
|
'RI' => __( 'Rhode Island' ), |
2411
|
|
|
'SC' => __( 'South Carolina' ), |
2412
|
|
|
'SD' => __( 'South Dakota' ), |
2413
|
|
|
'TN' => __( 'Tennessee' ), |
2414
|
|
|
'TX' => __( 'Texas' ), |
2415
|
|
|
'UT' => __( 'Utah' ), |
2416
|
|
|
'VT' => __( 'Vermont' ), |
2417
|
|
|
'VA' => __( 'Virginia' ), |
2418
|
|
|
'WA' => __( 'Washington' ), |
2419
|
|
|
'WV' => __( 'West Virginia' ), |
2420
|
|
|
'WI' => __( 'Wisconsin' ), |
2421
|
|
|
'WY' => __( 'Wyoming' ) |
2422
|
|
|
); |
2423
|
|
|
|
2424
|
|
|
return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); |
2425
|
|
|
} |
2426
|
|
|
|
2427
|
|
|
/** |
2428
|
|
|
* Data callback for US States |
2429
|
|
|
* |
2430
|
|
|
* @param string $name The name of the field |
2431
|
|
|
* @param string|array $value The value of the field |
2432
|
|
|
* @param array $options Field options |
2433
|
|
|
* @param array $pod Pod data |
2434
|
|
|
* @param int $id Item ID |
2435
|
|
|
* |
2436
|
|
|
* @return array |
2437
|
|
|
* |
2438
|
|
|
* @since 2.3 |
2439
|
|
|
*/ |
2440
|
|
|
public function data_days_of_week ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { |
|
|
|
|
2441
|
|
|
|
2442
|
|
|
/** |
2443
|
|
|
* @var WP_Locale |
2444
|
|
|
*/ |
2445
|
|
|
global $wp_locale; |
|
|
|
|
2446
|
|
|
|
2447
|
|
|
return $wp_locale->weekday; |
2448
|
|
|
|
2449
|
|
|
} |
2450
|
|
|
|
2451
|
|
|
/** |
2452
|
|
|
* Data callback for US States |
2453
|
|
|
* |
2454
|
|
|
* @param string $name The name of the field |
2455
|
|
|
* @param string|array $value The value of the field |
2456
|
|
|
* @param array $options Field options |
2457
|
|
|
* @param array $pod Pod data |
2458
|
|
|
* @param int $id Item ID |
2459
|
|
|
* |
2460
|
|
|
* @return array |
2461
|
|
|
* |
2462
|
|
|
* @since 2.3 |
2463
|
|
|
*/ |
2464
|
|
|
public function data_months_of_year ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { |
|
|
|
|
2465
|
|
|
|
2466
|
|
|
/** |
2467
|
|
|
* @var WP_Locale |
2468
|
|
|
*/ |
2469
|
|
|
global $wp_locale; |
|
|
|
|
2470
|
|
|
|
2471
|
|
|
return $wp_locale->month; |
2472
|
|
|
|
2473
|
|
|
} |
2474
|
|
|
} |
2475
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.