Pods – Custom Content Types and Fields - Version 2.6.11.1

Version Description

  • June 4th, 2020 =
  • Security: Remove deprecated usage of escapeMarkup in Select2 (@sc0ttkclark, @miha.jirov)
Download this release

Release Info

Developer sc0ttkclark
Plugin Icon 128x128 Pods – Custom Content Types and Fields
Version 2.6.11.1
Comparing to
See all releases

Code changes from version 2.7.23 to 2.6.11.1

Files changed (3) hide show
  1. classes/Pods.php +1612 -2269
  2. classes/PodsAPI.php +7979 -8726
  3. classes/PodsAdmin.php +2507 -3164
classes/Pods.php CHANGED
@@ -1,393 +1,285 @@
1
  <?php
2
-
3
  /**
4
- * Pods class.
5
- *
6
  * @package Pods
7
  */
8
  class Pods implements Iterator {
9
 
10
  /**
11
- * Whether the Pods object is in a PHP Iterator call.
12
- *
13
  * @var bool
14
  */
15
  private $iterator = false;
16
 
17
  /**
18
- * PodsAPI object.
19
- *
20
  * @var PodsAPI
21
  */
22
  public $api;
23
 
24
  /**
25
- * PodsData object.
26
- *
27
  * @var PodsData
28
  */
29
  public $data;
30
 
31
  /**
32
- * PodsData object for additional calls.
33
- *
34
  * @var PodsData
35
  */
36
  public $alt_data;
37
 
38
  /**
39
- * Array of pod item arrays.
40
- *
41
- * @var array
42
  */
43
- public $rows;
44
 
45
  /**
46
- * Current pod item array.
47
- *
48
- * @var array
49
  */
50
- public $row;
51
 
52
  /**
53
- * Row number.
54
- *
55
  * @var int
56
  */
57
- private $row_number;
58
 
59
  /**
60
- * Override pod item array.
61
- *
62
- * @var array
63
  */
64
  public $row_override = array();
65
 
66
  /**
67
- * Whether to display errors on the screen.
68
- *
69
  * @var bool
70
  */
71
  public $display_errors = true;
72
 
73
  /**
74
- * Current pod information.
75
- *
76
  * @var array|bool|mixed|null|void
77
  */
78
  public $pod_data;
79
 
80
  /**
81
- * Last used Pods::find() parameters.
82
- *
83
  * @var array
84
  */
85
  public $params = array();
86
 
87
  /**
88
- * Current Pod name.
89
- *
90
  * @var string
91
  */
92
- public $pod;
93
 
94
  /**
95
- * Current Pod ID.
96
- *
97
  * @var int
98
  */
99
- public $pod_id;
100
 
101
  /**
102
- * Pod fields information.
103
- *
104
  * @var array
105
  */
106
- public $fields;
107
 
108
  /**
109
- * Last used filters() parameters.
110
- *
111
  * @var array
112
  */
113
  public $filters = array();
114
 
115
  /**
116
- * Detail page URL used for Advanced Content Types.
117
- *
118
  * @var string
119
  */
120
  public $detail_page;
121
 
122
  /**
123
- * Current Item ID.
124
- *
125
  * @var int
126
  */
127
- public $id;
128
 
129
  /**
130
- * Last used limit from find() lookup.
131
- *
132
  * @var int
133
  */
134
  public $limit = 15;
135
 
136
  /**
137
- * Last used offset from find() lookup.
138
- *
139
  * @var int
140
  */
141
  public $offset = 0;
142
 
143
  /**
144
- * Query variable used for pagination number.
145
- *
146
  * @var string
147
  */
148
  public $page_var = 'pg';
149
 
150
  /**
151
- * Last used page from find() lookup.
152
- *
153
  * @var int|mixed
154
  */
155
  public $page = 1;
156
 
157
  /**
158
- * Last used state of whether pagination was enabled from find() lookup.
159
- *
160
  * @var bool
161
  */
162
  public $pagination = true;
163
 
164
  /**
165
- * Last used state of whether search was enabled from find() lookup.
166
- *
167
  * @var bool
168
  */
169
  public $search = true;
170
 
171
  /**
172
- * Query variable used for search string.
173
- *
174
  * @var string
175
  */
176
  public $search_var = 'search';
177
 
178
  /**
179
- * Search mode (int | text | text_like).
180
- *
181
  * @var string
182
  */
183
- public $search_mode = 'int';
184
 
185
  /**
186
- * Total number of records returned from find() lookup.
187
- *
188
  * @var int
189
  */
190
  public $total = 0;
191
 
192
  /**
193
- * Total number of records found from find() lookup.
194
- *
195
  * @var int
196
  */
197
  public $total_found = 0;
198
 
199
  /**
200
- * Last used ui options for ui() call.
201
- *
202
  * @var array
203
  */
204
  public $ui = array();
205
 
206
  /**
207
- * Page template to use for SEO feature in Pods Pages.
208
- *
209
- * @var string
210
  */
211
  public $page_template;
212
-
213
- /**
214
- * Body classes to use for SEO feature in Pods Pages.
215
- *
216
- * @var array
217
- */
218
  public $body_classes;
219
-
220
- /**
221
- * Meta tags to use for SEO feature in Pods Pages.
222
- *
223
- * @var array
224
- */
225
  public $meta = array();
226
-
227
- /**
228
- * Meta properties to use for SEO feature in Pods Pages.
229
- *
230
- * @var array
231
- */
232
  public $meta_properties = array();
233
-
234
- /**
235
- * Meta custom HTML to use for SEO feature in Pods Pages.
236
- *
237
- * @var string
238
- */
239
  public $meta_extra = '';
240
 
241
  /**
242
- * Last SQL query used by a find() lookup.
243
- *
244
- * @var string
245
  */
246
  public $sql;
247
 
248
  /**
249
- * Pods_Deprecated object.
250
- *
251
- * @var Pods_Deprecated
252
  */
253
  public $deprecated;
254
 
255
- /**
256
- * Old Pod name variable.
257
- *
258
- * @var string
259
- *
260
- * @deprecated 2.0.0
261
- */
262
  public $datatype;
263
 
264
- /**
265
- * Old Pod ID variable.
266
- *
267
- * @var int
268
- *
269
- * @deprecated 2.0.0
270
- */
271
  public $datatype_id;
272
 
273
  /**
274
- * Constructor - Pods Framework core.
 
 
 
275
  *
276
- * @param string $pod The pod name.
277
- * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'.
278
  *
279
  * @license http://www.gnu.org/licenses/gpl-2.0.html
280
- * @since 1.0.0
281
- * @link https://pods.io/docs/pods/
282
  */
283
- public function __construct( $pod = null, $id = null ) {
284
-
285
  if ( null === $pod ) {
286
- $pod = get_queried_object();
287
- }
288
 
289
- if ( $pod && ! is_string( $pod ) ) {
290
- if ( $pod instanceof WP_Post ) {
291
- // Post Type Singular.
292
- $pod = $pod->post_type;
293
  $id_lookup = true;
294
- } elseif ( $pod instanceof WP_Term ) {
295
- // Term Archive.
296
- $pod = $pod->taxonomy;
297
- $id_lookup = true;
298
- } elseif ( $pod instanceof WP_User ) {
299
- // Author Archive.
300
- $pod = 'user';
301
- $id_lookup = true;
302
- } elseif ( $pod instanceof WP_Post_Type ) {
303
- // Post Type Archive.
304
- $pod = $pod->name;
305
- $id_lookup = false;
306
- } else {
307
- // Unsupported pod object.
308
- $pod = null;
309
- $id_lookup = false;
310
- }
311
 
312
- if ( null === $id && $id_lookup ) {
313
- $id = get_queried_object_id();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
  }
315
- }//end if
316
 
317
- $this->api = pods_api( $pod );
318
  $this->api->display_errors =& $this->display_errors;
319
 
320
- $this->data = pods_data( $this->api, $id, false );
321
  PodsData::$display_errors =& $this->display_errors;
322
 
323
- // Set up page variable.
324
  if ( pods_strict( false ) ) {
325
- $this->page = 1;
326
  $this->pagination = false;
327
- $this->search = false;
328
- } else {
329
- // Get the page variable.
330
- $this->page = pods_v( $this->page_var, 'get', 1, true );
331
-
332
- if ( ! empty( $this->page ) ) {
333
- $this->page = max( 1, pods_absint( $this->page ) );
334
- }
335
  }
336
 
337
- // Set default pagination handling to on/off.
338
  if ( defined( 'PODS_GLOBAL_POD_PAGINATION' ) ) {
339
- if ( ! PODS_GLOBAL_POD_PAGINATION ) {
340
- $this->page = 1;
341
  $this->pagination = false;
342
- } else {
343
- $this->pagination = true;
344
  }
 
 
345
  }
346
 
347
- // Set default search to on/off.
348
  if ( defined( 'PODS_GLOBAL_POD_SEARCH' ) ) {
349
- if ( PODS_GLOBAL_POD_SEARCH ) {
350
  $this->search = true;
351
- } else {
352
  $this->search = false;
353
- }
354
  }
355
 
356
- // Set default search mode.
357
  $allowed_search_modes = array( 'int', 'text', 'text_like' );
358
 
359
- if ( defined( 'PODS_GLOBAL_POD_SEARCH_MODE' ) && in_array( PODS_GLOBAL_POD_SEARCH_MODE, $allowed_search_modes, true ) ) {
360
  $this->search_mode = PODS_GLOBAL_POD_SEARCH_MODE;
361
- }
362
 
363
- // Sync Settings.
364
- $this->data->page =& $this->page;
365
- $this->data->limit =& $this->limit;
366
- $this->data->pagination =& $this->pagination;
367
- $this->data->search =& $this->search;
368
  $this->data->search_mode =& $this->search_mode;
369
 
370
- // Sync Pod Data.
371
  $this->api->pod_data =& $this->data->pod_data;
372
- $this->pod_data =& $this->api->pod_data;
373
- $this->api->pod_id =& $this->data->pod_id;
374
- $this->pod_id =& $this->api->pod_id;
375
- $this->datatype_id =& $this->pod_id;
376
- $this->api->pod =& $this->data->pod;
377
- $this->pod =& $this->api->pod;
378
- $this->datatype =& $this->pod;
379
- $this->api->fields =& $this->data->fields;
380
- $this->fields =& $this->api->fields;
381
- $this->detail_page =& $this->data->detail_page;
382
- $this->id =& $this->data->id;
383
- $this->row =& $this->data->row;
384
- $this->rows =& $this->data->data;
385
- $this->row_number =& $this->data->row_number;
386
- $this->sql =& $this->data->sql;
387
-
388
- if ( is_array( $id ) || is_object( $id ) ) {
389
  $this->find( $id );
390
- }
391
  }
392
 
393
  /**
@@ -395,17 +287,14 @@ class Pods implements Iterator {
395
  *
396
  * @return bool
397
  *
398
- * @since 2.0.0
399
  */
400
- public function valid() {
401
-
402
- if ( empty( $this->pod_id ) ) {
403
  return false;
404
- }
405
 
406
- if ( $this->iterator ) {
407
  return isset( $this->rows[ $this->row_number ] );
408
- }
409
 
410
  return true;
411
  }
@@ -417,10 +306,9 @@ class Pods implements Iterator {
417
  *
418
  * @since 2.3.4
419
  *
420
- * @link http://www.php.net/manual/en/class.iterator.php
421
  */
422
- public function is_iterator() {
423
-
424
  return $this->iterator;
425
  }
426
 
@@ -431,28 +319,31 @@ class Pods implements Iterator {
431
  *
432
  * @since 2.3.4
433
  *
434
- * @link http://www.php.net/manual/en/class.iterator.php
435
  */
436
- public function stop_iterator() {
437
-
438
  $this->iterator = false;
439
 
 
440
  }
441
 
442
  /**
443
  * Rewind Iterator
444
  *
 
 
445
  * @since 2.3.4
446
  *
447
- * @link http://www.php.net/manual/en/class.iterator.php
448
  */
449
- public function rewind() {
450
-
451
- if ( ! $this->iterator ) {
452
- $this->iterator = true;
453
-
454
  $this->row_number = 0;
 
 
455
  }
 
 
456
  }
457
 
458
  /**
@@ -462,13 +353,11 @@ class Pods implements Iterator {
462
  *
463
  * @since 2.3.4
464
  *
465
- * @link http://www.php.net/manual/en/class.iterator.php
466
  */
467
- public function current() {
468
-
469
- if ( $this->iterator && $this->fetch() ) {
470
  return $this;
471
- }
472
 
473
  return false;
474
  }
@@ -476,29 +365,36 @@ class Pods implements Iterator {
476
  /**
477
  * Get current Iterator key
478
  *
479
- * @return int
480
  *
481
  * @since 2.3.4
482
  *
483
- * @link http://www.php.net/manual/en/class.iterator.php
484
  */
485
- public function key() {
 
 
486
 
487
- return $this->row_number;
488
  }
489
 
490
  /**
491
  * Move onto the next Iterator row
492
  *
493
- * @return void
494
  *
495
  * @since 2.3.4
496
  *
497
- * @link http://www.php.net/manual/en/class.iterator.php
498
  */
499
- public function next() {
 
 
 
 
 
500
 
501
- $this->row_number ++;
502
  }
503
 
504
  /**
@@ -506,13 +402,11 @@ class Pods implements Iterator {
506
  *
507
  * @return bool
508
  *
509
- * @since 2.0.0
510
  */
511
- public function exists() {
512
-
513
- if ( empty( $this->row ) ) {
514
  return false;
515
- }
516
 
517
  return true;
518
  }
@@ -525,16 +419,14 @@ class Pods implements Iterator {
525
  *
526
  * @return array|bool An array of all rows returned from a find() call, or false if no items returned
527
  *
528
- * @since 2.0.0
529
- * @link https://pods.io/docs/data/
530
  */
531
- public function data() {
532
-
533
  do_action( 'pods_pods_data', $this );
534
 
535
- if ( empty( $this->rows ) ) {
536
  return false;
537
- }
538
 
539
  return (array) $this->rows;
540
  }
@@ -542,9 +434,9 @@ class Pods implements Iterator {
542
  /**
543
  * Return a field input for a specific field
544
  *
545
- * @param string|array $field Field name or Field data array.
546
- * @param string|array|null $input_name Input field name to use (overrides default name).
547
- * @param mixed $value Current value to use.
548
  *
549
  * @return string Field Input HTML
550
  *
@@ -552,28 +444,25 @@ class Pods implements Iterator {
552
  */
553
  public function input( $field, $input_name = null, $value = '__null' ) {
554
 
 
555
  if ( is_array( $field ) ) {
556
- // Field data override.
557
  $field_data = $field;
558
-
559
- $field = pods_v( 'name', $field );
560
- } else {
561
- // Get field data from field name.
562
  $field_data = $this->fields( $field );
563
  }
564
 
565
- if ( ! empty( $field_data ) ) {
566
- $field_type = pods_v( 'type', $field_data );
567
 
568
  if ( empty( $input_name ) ) {
569
  $input_name = $field;
570
  }
571
 
572
- if ( '__null' === $value ) {
573
- $value = $this->field( array(
574
- 'name' => $field,
575
- 'in_form' => true,
576
- ) );
577
  }
578
 
579
  return PodsForm::field( $input_name, $value, $field_type, $field_data, $this, $this->id() );
@@ -586,61 +475,59 @@ class Pods implements Iterator {
586
  /**
587
  * Return field array from a Pod, a field's data, or a field option
588
  *
589
- * @param null $field Field name.
590
- * @param null $option Option name.
591
  *
592
  * @return bool|mixed
593
  *
594
- * @since 2.0.0
595
  */
596
- public function fields( $field = null, $option = null ) {
597
 
598
  $field_data = null;
599
 
600
  if ( empty( $this->fields ) ) {
601
- // No fields found.
602
  $field_data = array();
603
  } elseif ( empty( $field ) ) {
604
- // Return all fields.
605
  $field_data = (array) $this->fields;
606
  } elseif ( ! isset( $this->fields[ $field ] ) && ! isset( $this->pod_data['object_fields'][ $field ] ) ) {
607
- // Field not found.
608
  $field_data = array();
609
  } elseif ( empty( $option ) ) {
610
- // Return all field data.
611
  if ( isset( $this->fields[ $field ] ) ) {
612
  $field_data = $this->fields[ $field ];
613
  } elseif ( isset( $this->pod_data['object_fields'] ) ) {
614
  $field_data = $this->pod_data['object_fields'][ $field ];
615
  }
616
  } else {
617
- $options = array();
618
-
619
- // Merge options.
620
  if ( isset( $this->fields[ $field ] ) ) {
621
  $options = array_merge( $this->fields[ $field ], $this->fields[ $field ]['options'] );
622
  } elseif ( isset( $this->pod_data['object_fields'] ) ) {
623
  $options = array_merge( $this->pod_data['object_fields'][ $field ], $this->pod_data['object_fields'][ $field ]['options'] );
624
  }
625
 
626
- if ( 'data' === $option && in_array( pods_v( 'type', $options ), PodsForm::tableless_field_types(), true ) ) {
627
- // Get a list of available items from a relationship field.
628
  $field_data = PodsForm::field_method( 'pick', 'get_field_data', $options );
629
- } elseif ( isset( $options[ $option ] ) ) {
630
- // Return option.
631
  $field_data = $options[ $option ];
632
  }
633
- }//end if
634
 
635
  /**
636
  * Modify the field data before returning
637
  *
638
  * @since unknown
639
  *
640
- * @param array $field_data The data for the field.
641
- * @param string|null $field The specific field that data is being return for, if set when method is called or null.
642
- * @param string|null $option Value of option param when method was called. Can be used to get a list of available items from a relationship field.
643
- * @param Pods|object $this The current Pods class instance.
644
  */
645
  return apply_filters( 'pods_pods_fields', $field_data, $field, $option, $this );
646
 
@@ -649,17 +536,15 @@ class Pods implements Iterator {
649
  /**
650
  * Return row array for an item
651
  *
652
- * @return array|false
653
  *
654
- * @since 2.0.0
655
  */
656
- public function row() {
657
-
658
  do_action( 'pods_pods_row', $this );
659
 
660
- if ( ! is_array( $this->row ) ) {
661
  return false;
662
- }
663
 
664
  return (array) $this->row;
665
  }
@@ -669,34 +554,31 @@ class Pods implements Iterator {
669
  * you will want to use field() instead. This function will automatically convert arrays into a
670
  * list of text such as "Rick, John, and Gary"
671
  *
672
- * @param string|array|object $name The field name, or an associative array of parameters.
673
- * @param boolean|array|object $single (optional) For tableless fields, to return an array or the first.
674
  *
675
- * @return string|null|false The output from the field, null if the field doesn't exist, false if no value returned
676
- * for tableless fields
677
- * @since 2.0.0
678
- * @link https://pods.io/docs/display/
679
  */
680
- public function display( $name, $single = null ) {
681
-
682
  $defaults = array(
683
- 'name' => $name,
684
- 'single' => $single,
685
- 'display' => true,
686
- 'serial_params' => null,
687
  );
688
 
689
  if ( is_array( $name ) || is_object( $name ) ) {
690
- $defaults['name'] = null;
691
-
692
  $params = (object) array_merge( $defaults, (array) $name );
693
- } elseif ( is_array( $single ) || is_object( $single ) ) {
694
- $defaults['single'] = null;
695
-
696
  $params = (object) array_merge( $defaults, (array) $single );
697
- } else {
698
- $params = $defaults;
699
  }
 
 
700
 
701
  $params = (object) $params;
702
 
@@ -705,18 +587,17 @@ class Pods implements Iterator {
705
  if ( is_array( $value ) ) {
706
  $fields = $this->fields;
707
 
708
- if ( isset( $this->pod_data['object_fields'] ) ) {
709
- $fields = array_merge( $fields, $this->pod_data['object_fields'] );
710
- }
711
 
712
  $serial_params = array(
713
- 'field' => $params->name,
714
- 'fields' => $fields,
715
  );
716
 
717
- if ( ! empty( $params->serial_params ) && is_array( $params->serial_params ) ) {
718
  $serial_params = array_merge( $serial_params, $params->serial_params );
719
- }
720
 
721
  $value = pods_serial_comma( $value, $serial_params );
722
  }
@@ -729,35 +610,34 @@ class Pods implements Iterator {
729
  * you will want to use field() instead. This function will automatically convert arrays into a
730
  * list of text such as "Rick, John, and Gary"
731
  *
732
- * @param string|array|object $name The field name, or an associative array of parameters.
733
- * @param boolean|array|object $single (optional) For tableless fields, to return an array or the first.
734
  *
735
- * @return string|null|false The output from the field, null if the field doesn't exist, false if no value returned
736
- * for tableless fields
737
- * @since 2.0.0
738
- * @link https://pods.io/docs/display/
739
  */
740
- public function raw( $name, $single = null ) {
741
-
742
  $defaults = array(
743
- 'name' => $name,
744
  'single' => $single,
745
- 'raw' => true,
746
  );
747
 
748
  if ( is_array( $name ) || is_object( $name ) ) {
749
- $defaults['name'] = null;
750
-
751
  $params = (object) array_merge( $defaults, (array) $name );
752
- } elseif ( is_array( $single ) || is_object( $single ) ) {
753
- $defaults['single'] = null;
754
-
755
  $params = (object) array_merge( $defaults, (array) $single );
756
- } else {
757
- $params = (object) $defaults;
758
  }
 
 
 
 
759
 
760
- return $this->field( $params );
761
  }
762
 
763
  /**
@@ -767,515 +647,416 @@ class Pods implements Iterator {
767
  *
768
  * This function will return arrays for relationship and file fields.
769
  *
770
- * @param string|array|object $name The field name, or an associative array of parameters.
771
- * @param boolean|array|object $single For tableless fields, to return the whole array or the just the first item,
772
- * or an associative array of parameters.
773
- * @param boolean|array|object $raw Whether to return the raw value, or to run through the field type's display
774
- * method, or an associative array of parameters.
775
  *
776
- * @return mixed|null Value returned depends on the field type, null if the field doesn't exist, false if no value
777
- * returned for tableless fields.
778
- * @since 2.0.0
779
- * @link https://pods.io/docs/field/
780
  */
781
- public function field( $name, $single = null, $raw = false ) {
782
 
783
  $defaults = array(
784
- 'name' => $name,
785
- 'orderby' => null,
786
- 'single' => $single,
787
- 'params' => null,
788
- 'in_form' => false,
789
- 'raw' => $raw,
790
  'raw_display' => false,
791
- 'display' => false,
792
- 'get_meta' => false,
793
- 'output' => null,
794
- 'deprecated' => false,
795
- 'keyed' => false,
796
- // extra data to send to field handlers.
797
- 'args' => array(),
798
  );
799
 
800
- if ( is_object( $name ) ) {
801
- $name = get_object_vars( $name );
802
- }
803
-
804
- if ( is_object( $single ) ) {
805
- $single = get_object_vars( $single );
806
- }
807
-
808
- if ( is_object( $raw ) ) {
809
- $raw = get_object_vars( $raw );
810
- }
811
-
812
- if ( is_array( $name ) ) {
813
- $defaults['name'] = null;
814
-
815
  $params = (object) array_merge( $defaults, (array) $name );
816
- } elseif ( is_array( $single ) ) {
817
- $defaults['single'] = null;
818
-
819
  $params = (object) array_merge( $defaults, (array) $single );
820
- } elseif ( is_array( $raw ) ) {
821
- $defaults['raw'] = false;
822
-
823
  $params = (object) array_merge( $defaults, (array) $raw );
824
- } else {
 
825
  $params = (object) $defaults;
826
- }//end if
827
 
828
  if ( $params->in_form ) {
829
  $params->output = 'ids';
830
- } elseif ( null === $params->output ) {
 
831
  /**
832
- * Override the way related fields are output
833
  *
834
- * @param string $output How to output related fields. Default is 'arrays'. Options: ids|names|objects|arrays|pods|find
835
- * @param array|object $row Current row being outputted.
836
- * @param array $params Params array passed to field().
837
- * @param Pods $this Current Pods object.
838
  */
839
  $params->output = apply_filters( 'pods_pods_field_related_output_type', 'arrays', $this->row, $params, $this );
840
  }
841
 
842
- if ( in_array( $params->output, array( 'id', 'name', 'object', 'array', 'pod' ), true ) ) {
843
  $params->output .= 's';
844
- }
845
 
846
- // Support old $orderby variable.
847
  if ( null !== $params->single && is_string( $params->single ) && empty( $params->orderby ) ) {
848
  if ( ! class_exists( 'Pod' ) || Pod::$deprecated_notice ) {
849
  pods_deprecated( 'Pods::field', '2.0', 'Use $params[ \'orderby\' ] instead' );
850
  }
851
 
852
  $params->orderby = $params->single;
853
- $params->single = false;
854
  }
855
 
856
- if ( null !== $params->single ) {
857
  $params->single = (boolean) $params->single;
858
- }
859
 
860
  $params->name = trim( $params->name );
861
- if ( is_array( $params->name ) || '' === $params->name ) {
862
  return null;
863
- }
864
 
865
  $params->full_name = $params->name;
866
 
867
  $value = null;
868
 
869
- if ( isset( $this->row_override[ $params->name ] ) ) {
870
  $value = $this->row_override[ $params->name ];
871
- }
872
 
873
  if ( false === $this->row() ) {
874
- if ( false !== $this->data() ) {
875
  $this->fetch();
876
- } else {
877
  return $value;
878
- }
879
  }
880
 
881
- if ( $this->data->field_id === $params->name ) {
882
- if ( isset( $this->row[ $params->name ] ) ) {
883
  return $this->row[ $params->name ];
884
- // @codingStandardsIgnoreLine.
885
- } elseif ( null !== $value ) {
886
  return $value;
887
- }
888
 
889
  return 0;
890
  }
891
 
892
- $tableless_field_types = PodsForm::tableless_field_types();
893
  $simple_tableless_objects = PodsForm::simple_tableless_objects();
894
 
895
  $params->traverse = array();
896
 
897
- $permalink_fields = array(
898
- '_link',
899
- 'detail_url',
900
- 'permalink',
901
- 'the_permalink',
902
- );
903
-
904
- $wp_object_types = array(
905
- 'post_type',
906
- 'taxonomy',
907
- 'media',
908
- 'user',
909
- 'comment',
910
- );
911
-
912
- /** @var string $pod_type The pod object type. */
913
- $pod_type = pods_v( 'type', $this->pod_data, '' );
914
-
915
- $is_wp_object = in_array( $pod_type, $wp_object_types, true );
916
-
917
- if ( in_array( $params->name, $permalink_fields, true ) ) {
918
- if ( 0 < strlen( $this->detail_page ) && false === strpos( $params->name, 'permalink' ) ) {
919
- // ACT Pods. Prevent tag loop by not parsing `permalink`.
920
  $value = get_home_url() . '/' . $this->do_magic_tags( $this->detail_page );
921
- } else {
922
- switch ( $pod_type ) {
923
- case 'post_type':
924
- case 'media':
925
- $value = get_permalink( $this->id() );
926
- break;
927
- case 'taxonomy':
928
- $value = get_term_link( $this->id(), $this->pod_data['name'] );
929
- break;
930
- case 'user':
931
- $value = get_author_posts_url( $this->id() );
932
- break;
933
- case 'comment':
934
- $value = get_comment_link( $this->id() );
935
- break;
936
- }
937
- }
938
- }
939
-
940
- /**
941
- * @var bool $is_field_set Is the field found.
942
- * @var bool $is_tableless_field Is it a tableless field.
943
- * @var string $field_source Regular field or object field.
944
- * @var array $field_data The field data.
945
- * @var string $field_type The field type.
946
- * @var array $field_options The field options.
947
- * @var array $traverse_fields All the traversal field names.
948
- * @var bool $is_traversal Is it a traversal field request.
949
- * @var string $first_field The name of the fieds without the traversal names from $params->name.
950
- * @var array $last_field_data The field data used in traversal loop.
951
- */
952
-
953
- $is_field_set = false;
954
- $is_tableless_field = false;
955
- $field_source = '';
956
- $field_data = array();
957
- $field_type = '';
958
- $field_options = array();
959
- $traverse_fields = explode( '.', $params->name );
960
- $is_traversal = 1 < count( $traverse_fields );
961
- $first_field = $traverse_fields[0];
962
- $last_field_data = null;
963
-
964
- if ( isset( $this->fields[ $params->name ] ) ) {
965
- // Get the full field name data.
966
- $field_data = $this->fields[ $params->name ];
967
- $field_source = 'field';
968
- $is_field_set = true;
969
- } elseif ( isset( $this->fields[ $first_field ] ) ) {
970
- // Get the first field name data.
971
- $field_data = $this->fields[ $first_field ];
972
- $field_source = 'field';
973
- $is_field_set = true;
974
- } elseif ( ! empty( $this->pod_data['object_fields'] ) ) {
975
- // Get the object field data.
976
- if ( isset( $this->pod_data['object_fields'][ $first_field ] ) ) {
977
- $field_data = $this->pod_data['object_fields'][ $first_field ];
978
- $field_source = 'object_field';
979
- $is_field_set = true;
980
- } else {
981
- $object_fields = (array) $this->pod_data['object_fields'];
982
-
983
- // Search through field aliases.
984
- foreach ( $object_fields as $object_field => $object_field_opt ) {
985
- if ( in_array( $first_field, $object_field_opt['alias'], true ) ) {
986
- if ( $first_field === $params->name ) {
987
  $params->name = $object_field;
988
- }
989
 
990
- $first_field = $object_field;
991
- $field_data = $object_field_opt;
992
- $field_source = 'object_field';
993
- $is_field_set = true;
994
 
995
  break;
996
  }
997
  }
998
  }
999
- }//end if
1000
-
1001
- // Store field info.
1002
- $field_type = pods_v( 'type', $field_data, '' );
1003
- $field_options = pods_v( 'options', $field_data, array() );
1004
- $is_tableless_field = in_array( $field_type, $tableless_field_types, true );
1005
 
1006
- // Simple fields have no other output options.
1007
- if ( 'pick' === $field_type && in_array( $field_data['pick_object'], $simple_tableless_objects, true ) ) {
1008
  $params->output = 'arrays';
1009
  }
1010
 
1011
- // Enforce output type for tableless fields in forms.
1012
- if ( empty( $value ) && $is_tableless_field ) {
1013
  $params->raw = true;
1014
 
1015
  $value = false;
1016
 
1017
- $row_key = '_' . $params->output . '_' . $params->name;
1018
-
1019
- if ( 'arrays' !== $params->output && isset( $this->row[ $row_key ] ) ) {
1020
- $value = $this->row[ $row_key ];
1021
- } elseif ( 'arrays' === $params->output && isset( $this->row[ $params->name ] ) ) {
1022
  $value = $this->row[ $params->name ];
1023
  }
1024
 
1025
- if (
1026
- false !== $value &&
1027
- ! is_array( $value ) &&
1028
- 'pick' === $field_type &&
1029
- in_array( $field_data['pick_object'], $simple_tableless_objects, true )
1030
- ) {
1031
  $value = PodsForm::field_method( 'pick', 'simple_value', $params->name, $value, $field_data, $this->pod_data, $this->id(), true );
1032
- }
1033
  }
1034
 
1035
- if (
1036
- empty( $value ) &&
1037
- isset( $this->row[ $params->name ] ) &&
1038
- ( ! $is_tableless_field || 'arrays' === $params->output )
1039
- ) {
1040
- if ( empty( $field_data ) || in_array( $field_type, array( 'boolean', 'number', 'currency' ), true ) ) {
1041
  $params->raw = true;
1042
- }
1043
 
1044
  if ( null === $params->single ) {
1045
- if ( ! $is_tableless_field ) {
1046
  $params->single = true;
1047
- } else {
1048
  $params->single = false;
1049
- }
1050
  }
1051
 
1052
  $value = $this->row[ $params->name ];
1053
- } elseif ( empty( $value ) ) {
 
1054
  $object_field_found = false;
1055
 
1056
- if ( 'object_field' === $field_source ) {
1057
  $object_field_found = true;
1058
 
1059
- if ( isset( $this->row[ $first_field ] ) ) {
1060
  $value = $this->row[ $first_field ];
1061
- } elseif ( $is_tableless_field ) {
1062
- // Overwrite existing field data.
1063
  $this->fields[ $first_field ] = $field_data;
1064
 
1065
  $object_field_found = false;
1066
- } else {
1067
- return null;
1068
  }
 
 
 
1069
 
1070
- } elseif ( 'avatar' === $first_field && 'user' === $pod_type ) {
1071
- // User avatar.
1072
- $size = null;
1073
- $get_avatar = true;
1074
-
1075
- if ( $is_traversal ) {
1076
- if ( $is_field_set ) {
1077
- // This is a registered field.
1078
- if ( isset( $traverse_fields[1] ) && is_numeric( $traverse_fields[1] ) ) {
1079
- $size = (int) $traverse_fields[1];
1080
- } else {
1081
- // Traverse through attachment post.
1082
- $get_avatar = false;
1083
- }
1084
- } else {
1085
- if ( isset( $traverse_fields[1] ) ) {
1086
- $size = (int) $traverse_fields[1];
1087
- }
1088
  }
1089
- }
1090
 
1091
- if ( $get_avatar ) {
 
 
1092
  $object_field_found = true;
1093
- if ( 0 < $size ) {
1094
- $value = get_avatar( $this->id(), $size );
1095
- } else {
1096
- $value = get_avatar( $this->id() );
 
 
 
 
 
1097
  }
 
 
 
 
 
1098
  }
 
 
1099
 
1100
- } elseif ( ! $is_field_set ) {
1101
 
1102
- $image_fields = array(
1103
- 'image_attachment',
1104
- 'image_attachment_url',
1105
- );
 
 
 
 
 
 
1106
 
1107
- if ( 'post_type' === $pod_type ) {
1108
- $image_fields[] = 'post_thumbnail';
1109
- $image_fields[] = 'post_thumbnail_url';
1110
  }
 
 
1111
 
1112
- // Handle special field tags.
1113
- if ( in_array( $first_field, $image_fields, true ) ) {
1114
- // Default image field handlers.
1115
- $object_field_found = true;
 
 
1116
 
1117
- $image_field = $first_field;
1118
- // Is it a URL request?
1119
- $url = '_url' === substr( $image_field, - 4 );
1120
- if ( $url ) {
1121
- $image_field = substr( $image_field, 0, - 4 );
 
 
 
1122
  }
 
 
 
 
 
1123
 
1124
- // Copy traversal parameters.
1125
- $traverse_params = $traverse_fields;
1126
- // Results in an empty array if no traversal params are passed.
1127
- array_shift( $traverse_params );
1128
 
1129
- $attachment_id = 0;
1130
- switch ( $image_field ) {
1131
- case 'post_thumbnail':
1132
- $attachment_id = get_post_thumbnail_id( $this->id() );
1133
- break;
1134
- case 'image_attachment':
1135
- if ( isset( $traverse_params[0] ) ) {
1136
- $attachment_id = $traverse_params[0];
1137
- array_shift( $traverse_params );
1138
- }
1139
- break;
1140
  }
1141
 
1142
- if ( $attachment_id ) {
1143
- $is_image = wp_attachment_is_image( $attachment_id );
 
 
 
 
 
 
 
 
 
 
1144
 
1145
- $size = 'thumbnail';
1146
- if ( isset( $traverse_params[0] ) ) {
1147
- $size = $traverse_params[0];
1148
 
1149
- if ( pods_is_image_size( $size ) ) {
1150
- // Force image request since a valid size parameter is passed.
1151
- $is_image = true;
1152
- } else {
1153
- // No valid image size found.
1154
- $size = false;
1155
- }
1156
- }
1157
 
1158
- if ( $url ) {
1159
- if ( $is_image ) {
1160
- $value = pods_image_url( $attachment_id, $size, 0, true );
1161
- } else {
1162
- $value = wp_get_attachment_url( $attachment_id );
1163
- }
1164
- } elseif ( $size ) {
1165
- // Pods will auto-get the thumbnail ID if this isn't an attachment.
1166
- $value = pods_image( $attachment_id, $size, 0, null, true );
1167
- } else {
1168
- // Fallback to attachment Post object to look for other image properties.
1169
- $media = pods( 'media', $attachment_id );
1170
-
1171
- if ( $media && $media->valid() && $media->exists() ) {
1172
- $value = $media->field( implode( '.', $traverse_params ) );
1173
- } else {
1174
- // Fallback to default attachment object.
1175
- $attachment = get_post( $attachment_id );
1176
- $value = pods_v( implode( '.', $traverse_params ), $attachment, null );
1177
-
1178
- if ( null === $value ) {
1179
- // Start traversal though object property or metadata.
1180
- $name_key = array_shift( $traverse_params );
1181
- $value = pods_v( $name_key, $attachment, null );
1182
-
1183
- if ( null === $value ) {
1184
- $value = get_post_meta( $attachment_id, $name_key, true );
1185
- }
1186
 
1187
- $value = pods_traverse( $traverse_params, $value );
1188
- }
1189
- }
1190
- }
1191
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1192
  }
1193
  }
1194
 
1195
- // Continue regular field parsing.
1196
  if ( false === $object_field_found ) {
1197
  $params->traverse = array( $params->name );
1198
 
1199
  if ( false !== strpos( $params->name, '.' ) ) {
1200
  $params->traverse = explode( '.', $params->name );
1201
 
1202
- $params->name = $params->traverse[0];
1203
  }
1204
 
1205
- if ( $field_type ) {
1206
-
1207
  /**
1208
  * Modify value returned by field() after its retrieved, but before its validated or formatted
1209
  *
1210
- * Filter name is set dynamically with name of field: "pods_pods_field_{field_type}"
1211
  *
1212
  * @since unknown
1213
  *
1214
- * @param array|string|null $value Value retrieved.
1215
- * @param array|object $row Current row being outputted.
1216
- * @param array $params Params array passed to field().
1217
- * @param object|Pods $this Current Pods object.
 
1218
  */
1219
- $v = apply_filters( "pods_pods_field_{$field_type}", null, $this->fields[ $params->name ], $this->row, $params, $this );
1220
 
1221
- if ( null !== $v ) {
1222
  return $v;
1223
- }
1224
  }
1225
 
1226
  $simple = false;
 
1227
 
1228
- if ( $is_field_set ) {
1229
-
1230
- if ( 'meta' === $this->pod_data['storage'] && ! $is_tableless_field ) {
1231
- $simple = true;
1232
  }
1233
 
1234
- if ( $is_tableless_field ) {
1235
  $params->raw = true;
1236
 
1237
- if ( 'pick' === $field_type && in_array( $field_data['pick_object'], $simple_tableless_objects, true ) ) {
1238
- $simple = true;
1239
  $params->single = true;
1240
  }
1241
- } elseif ( in_array( $field_type, array( 'boolean', 'number', 'currency' ), true ) ) {
1242
- $params->raw = true;
1243
  }
 
 
1244
  }
1245
 
1246
- if ( ! $is_traversal && ( $simple || ! $is_field_set || ! $is_tableless_field ) ) {
1247
  if ( null === $params->single ) {
1248
- if ( $is_field_set && ! $is_tableless_field ) {
1249
  $params->single = true;
1250
- } else {
1251
  $params->single = false;
1252
- }
1253
  }
1254
 
1255
- $no_conflict = pods_no_conflict_check( $pod_type );
1256
 
1257
- if ( ! $no_conflict ) {
1258
- // Temporarily enable no conflict.
1259
- pods_no_conflict_on( $pod_type );
1260
- }
1261
 
1262
- if ( $is_wp_object ) {
1263
  $id = $this->id();
1264
 
1265
- $metadata_type = $pod_type;
1266
 
1267
- if ( in_array( $metadata_type, array( 'post_type', 'media' ), true ) ) {
1268
  $metadata_type = 'post';
1269
 
1270
- // Support for WPML 'duplicated' translation handling.
1271
- if ( did_action( 'wpml_loaded' ) && apply_filters( 'wpml_is_translated_post_type', false, $this->pod_data['name'] ) ) {
 
1272
  $master_post_id = (int) apply_filters( 'wpml_master_post_from_duplicate', $id );
1273
 
1274
- if ( $master_post_id ) {
1275
  $id = $master_post_id;
1276
- }
1277
  }
1278
- } elseif ( 'taxonomy' === $metadata_type ) {
1279
  $metadata_type = 'term';
1280
  }
1281
 
@@ -1283,377 +1064,321 @@ class Pods implements Iterator {
1283
 
1284
  $single_multi = 'single';
1285
 
1286
- if ( $is_field_set && $field_type ) {
1287
- $single_multi = pods_v( $field_type . '_format_type', $field_options, $single_multi );
1288
  }
1289
 
1290
- if ( $simple && ! is_array( $value ) && 'single' !== $single_multi ) {
1291
  $value = get_metadata( $metadata_type, $id, $params->name );
1292
  }
1293
- } elseif ( 'settings' === $pod_type ) {
1294
- $value = get_option( $this->pod_data['name'] . '_' . $params->name, null );
1295
- }//end if
1296
 
1297
- // Handle Simple Relationships.
1298
  if ( $simple ) {
1299
- if ( null === $params->single ) {
1300
  $params->single = false;
1301
- }
1302
 
1303
  $value = PodsForm::field_method( 'pick', 'simple_value', $params->name, $value, $this->fields[ $params->name ], $this->pod_data, $this->id(), true );
1304
  }
1305
 
1306
- if ( ! $no_conflict ) {
1307
- // Revert temporarily no conflict mode.
1308
- pods_no_conflict_off( $pod_type );
1309
- }
1310
- } else {
1311
- // Dot-traversal.
1312
- $pod = $this->pod;
1313
- $ids = array( $this->id() );
1314
  $all_fields = array();
1315
 
1316
  $lookup = $params->traverse;
1317
 
1318
- // Get fields matching traversal names.
1319
- if ( ! empty( $lookup ) ) {
1320
  $fields = $this->api->load_fields( array(
1321
- 'name' => $lookup,
1322
- 'type' => $tableless_field_types,
1323
- 'object_fields' => true,
1324
- // @todo support object fields too.
1325
  ) );
1326
 
1327
- if ( ! empty( $fields ) ) {
1328
  foreach ( $fields as $field ) {
1329
- if ( ! empty( $field ) ) {
1330
- if ( ! isset( $all_fields[ $field['pod'] ] ) ) {
1331
- $all_fields[ $field['pod'] ] = array();
1332
- }
1333
 
1334
- $all_fields[ $field['pod'] ][ $field['name'] ] = $field;
1335
  }
1336
  }
1337
  }
1338
 
1339
- if ( ! empty( $this->pod_data['object_fields'] ) ) {
1340
- $object_fields = (array) $this->pod_data['object_fields'];
1341
-
1342
- foreach ( $object_fields as $object_field => $object_field_opt ) {
1343
- if ( in_array( $object_field_opt['type'], $tableless_field_types, true ) ) {
1344
  $all_fields[ $this->pod ][ $object_field ] = $object_field_opt;
1345
  }
1346
  }
1347
  }
1348
- }//end if
1349
 
1350
- $last_type = '';
1351
- $last_object = '';
1352
- $last_pick_val = '';
1353
 
1354
- $single_multi = pods_v( $field_type . '_format_type', $field_options, 'single' );
1355
 
1356
- if ( 'multi' === $single_multi ) {
1357
- $limit = (int) pods_v( $field_type . '_limit', $field_options, 0 );
1358
- } else {
1359
  $limit = 1;
1360
- }
1361
 
1362
- // Loop through each traversal level.
 
 
1363
  foreach ( $params->traverse as $key => $field ) {
1364
  $last_loop = false;
1365
 
1366
- if ( count( $params->traverse ) <= ( $key + 1 ) ) {
1367
  $last_loop = true;
1368
- }
1369
 
1370
  $field_exists = isset( $all_fields[ $pod ][ $field ] );
1371
 
1372
- $simple = false;
1373
  $last_options = array();
1374
 
1375
- if (
1376
- $field_exists &&
1377
- 'pick' === $all_fields[ $pod ][ $field ]['type'] &&
1378
- in_array( $all_fields[ $pod ][ $field ]['pick_object'], $simple_tableless_objects, true )
1379
- ) {
1380
- $simple = true;
1381
  $last_options = $all_fields[ $pod ][ $field ];
1382
  }
1383
 
1384
- // Tableless handler.
1385
- if ( $field_exists && ( ! $simple || ! in_array( $all_fields[ $pod ][ $field ]['type'], array(
1386
- 'pick',
1387
- 'taxonomy',
1388
- 'comment',
1389
- ), true ) ) ) {
1390
- $type = $all_fields[ $pod ][ $field ]['type'];
1391
- $pick_object = $all_fields[ $pod ][ $field ]['pick_object'];
1392
- $pick_val = $all_fields[ $pod ][ $field ]['pick_val'];
1393
-
1394
- if ( 'table' === $pick_object ) {
1395
- $pick_val = pods_v( 'pick_table', $all_fields[ $pod ][ $field ]['options'], $pick_val, true );
1396
- } elseif ( '__current__' === $pick_val ) {
1397
  $pick_val = $pod;
1398
  }
1399
 
1400
  $last_limit = 0;
1401
 
1402
- if ( in_array( $type, $tableless_field_types, true ) ) {
1403
- $single_multi = pods_v( "{$type}_format_type", $all_fields[ $pod ][ $field ]['options'], 'single' );
1404
 
1405
- if ( 'multi' === $single_multi ) {
1406
- $last_limit = (int) pods_v( "{$type}_limit", $all_fields[ $pod ][ $field ]['options'], 0 );
1407
- } else {
 
1408
  $last_limit = 1;
1409
  }
1410
  }
1411
 
1412
- $last_type = $type;
1413
- $last_object = $pick_object;
1414
  $last_pick_val = $pick_val;
1415
- $last_options = $all_fields[ $pod ][ $field ];
1416
 
1417
- // Temporary hack until there's some better handling here.
1418
- $last_limit *= count( $ids );
1419
 
1420
- // Get related IDs.
1421
- if ( ! isset( $all_fields[ $pod ][ $field ]['pod_id'] ) ) {
1422
- $all_fields[ $pod ][ $field ]['pod_id'] = 0;
1423
  }
1424
 
1425
- if ( isset( $all_fields[ $pod ][ $field ]['id'] ) ) {
1426
- $ids = $this->api->lookup_related_items( $all_fields[ $pod ][ $field ]['id'], $all_fields[ $pod ][ $field ]['pod_id'], $ids, $all_fields[ $pod ][ $field ] );
 
 
 
 
 
1427
  }
1428
 
1429
- // No items found.
1430
  if ( empty( $ids ) ) {
1431
  return false;
1432
- } elseif ( 0 < $last_limit ) {
1433
- // @todo This should return array() if not $params->single.
1434
  $ids = array_slice( $ids, 0, $last_limit );
1435
  }
1436
 
1437
- // Get $pod if related to a Pod.
1438
- if ( ! empty( $pick_object ) && ( ! empty( $pick_val ) || in_array( $pick_object, array(
1439
- 'user',
1440
- 'media',
1441
- 'comment',
1442
- ), true ) ) ) {
1443
- if ( 'pod' === $pick_object ) {
1444
  $pod = $pick_val;
1445
- } else {
 
1446
  $check = $this->api->get_table_info( $pick_object, $pick_val );
1447
 
1448
- if ( ! empty( $check ) && ! empty( $check['pod'] ) ) {
1449
- $pod = $check['pod']['name'];
1450
  }
1451
  }
1452
  }
1453
- } else {
1454
- // Assume last iteration.
1455
- $last_loop = true;
1456
-
1457
- if ( 0 === $key ) {
1458
- // This is also the first loop. Assume metadata or options to traverse into.
1459
- $last_object = $this->pod_data['object_type'];
1460
- $last_pick_val = $this->pod_data['name'];
1461
  }
1462
- }//end if
 
 
1463
 
1464
  if ( $last_loop ) {
1465
  $object_type = $last_object;
1466
- $object = $last_pick_val;
1467
 
1468
- if ( in_array( $last_type, PodsForm::file_field_types(), true ) ) {
1469
  $object_type = 'media';
1470
- $object = 'attachment';
1471
  }
1472
 
1473
  $data = array();
1474
 
1475
  $table = $this->api->get_table_info( $object_type, $object, null, null, $last_options );
1476
 
1477
- $join = array();
1478
- $where = array();
1479
 
1480
- if ( ! empty( $table['join'] ) ) {
1481
- $join = (array) $table['join'];
1482
- }
1483
 
1484
- if ( ! empty( $ids ) || ! empty( $table['where'] ) ) {
1485
  foreach ( $ids as $id ) {
1486
- $where[ $id ] = '`t`.`' . $table['field_id'] . '` = ' . (int) $id;
1487
  }
1488
 
1489
- if ( ! empty( $where ) ) {
1490
  $where = array( implode( ' OR ', $where ) );
1491
  }
1492
 
1493
- if ( ! empty( $table['where'] ) ) {
1494
- // @codingStandardsIgnoreLine.
1495
- $where = array_merge( $where, array_values( (array) $table['where'] ) );
1496
  }
1497
  }
1498
 
1499
  /**
1500
- * Related object.
1501
- *
1502
- * @var $related_obj Pods|false
1503
  */
1504
  $related_obj = false;
1505
 
1506
- // Check if we can return the full object/array or if we need to traverse into it.
1507
- $is_field_output_full = false;
1508
-
1509
- if ( false !== $field_exists && ( in_array( $last_type, $tableless_field_types, true ) && ! $simple ) ) {
1510
- $is_field_output_full = true;
1511
- }
1512
-
1513
- if ( 'pod' === $object_type ) {
1514
  $related_obj = pods( $object, null, false );
1515
- } elseif ( ! empty( $table['pod'] ) ) {
1516
- $related_obj = pods( $table['pod']['name'], null, false );
1517
- }
1518
 
1519
- if ( $related_obj || ! empty( $table['table'] ) ) {
1520
  $sql = array(
1521
- 'select' => '*, `t`.`' . $table['field_id'] . '` AS `pod_item_id`',
1522
- 'table' => $table['table'],
1523
- 'join' => $join,
1524
- 'where' => $where,
1525
- 'orderby' => $params->orderby,
1526
  'pagination' => false,
1527
- 'search' => false,
1528
- 'limit' => - 1,
1529
- 'expires' => 180,
1530
- // @todo This could potentially cause issues if someone changes the data within this time and persistent storage is used.
1531
  );
1532
 
1533
- if ( ! empty( $table['where_default'] ) ) {
1534
- $sql['where_default'] = $table['where_default'];
1535
- }
1536
-
1537
- // Output types.
1538
- if ( in_array( $params->output, array( 'ids', 'objects', 'pods' ), true ) ) {
1539
- $sql['select'] = '`t`.`' . $table['field_id'] . '` AS `pod_item_id`';
1540
- } elseif ( 'names' === $params->output && ! empty( $table['field_index'] ) ) {
1541
- $sql['select'] = '`t`.`' . $table['field_index'] . '` AS `pod_item_index`, `t`.`' . $table['field_id'] . '` AS `pod_item_id`';
1542
- }
1543
 
1544
- if ( ! empty( $params->params ) && is_array( $params->params ) ) {
1545
- $where = $sql['where'];
1546
 
1547
- // @codingStandardsIgnoreLine.
1548
  $sql = array_merge( $sql, $params->params );
1549
 
1550
- if ( isset( $params->params['where'] ) ) {
1551
- // @codingStandardsIgnoreLine.
1552
- $sql['where'] = array_merge( (array) $where, (array) $params->params['where'] );
1553
- }
1554
  }
1555
 
1556
- $item_data = array();
1557
-
1558
- if ( ! $related_obj || ! $related_obj->valid() ) {
1559
- if ( ! is_object( $this->alt_data ) ) {
1560
  $this->alt_data = pods_data( null, 0, true, true );
1561
- }
1562
 
1563
  $item_data = $this->alt_data->select( $sql );
1564
- } else {
1565
- // Support 'find' output ordering.
1566
- if ( $ids && 'find' === $params->output && $is_field_output_full && empty( $sql['orderby'] ) ) {
1567
- // Handle default orderby for ordering by the IDs.
1568
- $order_ids = implode( ', ', array_map( 'absint', $ids ) );
1569
-
1570
- $sql['orderby'] = 'FIELD( `t`.`' . $table['field_id'] . '`, ' . $order_ids . ' )';
1571
- }
1572
-
1573
- $related_obj->find( $sql );
1574
-
1575
- // Support 'find' output.
1576
- if ( 'find' === $params->output && $is_field_output_full ) {
1577
- $data = $related_obj;
1578
-
1579
- $is_field_output_full = true;
1580
- } else {
1581
- $item_data = $related_obj->data();
1582
- }
1583
- }//end if
1584
 
1585
  $items = array();
1586
 
1587
- if ( ! empty( $item_data ) ) {
1588
  foreach ( $item_data as $item ) {
1589
- if ( is_array( $item ) ) {
1590
  $item = (object) $item;
1591
- }
1592
 
1593
- if ( empty( $item->pod_item_id ) ) {
1594
  continue;
1595
- }
1596
 
1597
- // Bypass pass field.
1598
- if ( isset( $item->user_pass ) ) {
1599
  unset( $item->user_pass );
1600
- }
1601
 
1602
- // Get Item ID.
1603
  $item_id = $item->pod_item_id;
1604
 
1605
- // Output types.
1606
- if ( 'ids' === $params->output ) {
1607
  $item = (int) $item_id;
1608
- } elseif ( 'names' === $params->output && ! empty( $table['field_index'] ) ) {
1609
  $item = $item->pod_item_index;
1610
- } elseif ( 'objects' === $params->output ) {
1611
- if ( in_array( $object_type, array( 'post_type', 'media' ), true ) ) {
1612
  $item = get_post( $item_id );
1613
- } elseif ( 'taxonomy' === $object_type ) {
1614
  $item = get_term( $item_id, $object );
1615
- } elseif ( 'user' === $object_type ) {
1616
  $item = get_userdata( $item_id );
1617
 
1618
- if ( ! empty( $item ) ) {
1619
- // Get other vars.
1620
- $roles = $item->roles;
1621
- $caps = $item->caps;
1622
  $allcaps = $item->allcaps;
1623
 
1624
  $item = $item->data;
1625
 
1626
- // Set other vars.
1627
- $item->roles = $roles;
1628
- $item->caps = $caps;
1629
  $item->allcaps = $allcaps;
1630
 
1631
  unset( $item->user_pass );
1632
  }
1633
- } elseif ( 'comment' === $object_type ) {
 
1634
  $item = get_comment( $item_id );
1635
- } else {
1636
  $item = (object) $item;
1637
- }//end if
1638
- } elseif ( 'pods' === $params->output ) {
1639
- if ( in_array( $object_type, array( 'user', 'media' ), true ) ) {
1640
  $item = pods( $object_type, (int) $item_id );
1641
  } else {
1642
  $item = pods( $object, (int) $item_id );
1643
  }
1644
- } else {
1645
- // arrays.
1646
  $item = get_object_vars( (object) $item );
1647
- }//end if
1648
 
1649
- // Pass item data into $data.
1650
  $items[ $item_id ] = $item;
1651
- }//end foreach
1652
 
1653
- // Cleanup.
1654
  unset( $item_data );
1655
 
1656
- // Return all of the data in the order expected.
1657
  if ( empty( $params->orderby ) ) {
1658
  foreach ( $ids as $id ) {
1659
  if ( isset( $items[ $id ] ) ) {
@@ -1661,298 +1386,259 @@ class Pods implements Iterator {
1661
  }
1662
  }
1663
  } else {
1664
- // Use order set by orderby.
1665
  foreach ( $items as $id => $v ) {
1666
- // @codingStandardsIgnoreLine.
1667
  if ( in_array( $id, $ids ) ) {
1668
  $data[ $id ] = $v;
1669
  }
1670
  }
1671
  }
1672
- }//end if
1673
- }//end if
1674
-
1675
- if ( in_array( $last_type, $tableless_field_types, true ) || in_array( $last_type, array(
1676
- 'boolean',
1677
- 'number',
1678
- 'currency',
1679
- ), true ) ) {
1680
- $params->raw = true;
1681
  }
1682
 
1683
- if ( empty( $data ) ) {
 
 
 
1684
  $value = false;
1685
- } else {
1686
- $object_type = $table['type'];
1687
 
1688
- if ( in_array( $table['type'], array( 'post_type', 'attachment', 'media' ), true ) ) {
1689
  $object_type = 'post';
1690
- }
1691
 
 
1692
 
1693
- $object_no_conflict = in_array( $object_type, array( 'post', 'taxonomy', 'user', 'comment', 'settings' ), true );
 
1694
 
1695
- $no_conflict = pods_no_conflict_check( $object_type );
1696
-
1697
- if ( $object_no_conflict && ! $no_conflict ) {
1698
- // Temporarily enable no conflict.
1699
- pods_no_conflict_on( $object_type );
1700
  }
1701
 
1702
- if ( $is_field_output_full ) {
1703
- // Return entire array.
1704
  $value = $data;
1705
- } else {
1706
- // Return an array of single column values.
1707
  $value = array();
1708
 
1709
  foreach ( $data as $item_id => $item ) {
1710
  // $field is 123x123, needs to be _src.123x123
1711
- $traverse_fields = array_splice( $params->traverse, $key );
1712
- $full_field = implode( '.', $traverse_fields );
1713
- array_shift( $traverse_fields );
1714
 
1715
  if ( is_array( $item ) && isset( $item[ $field ] ) ) {
1716
- if ( $table['field_id'] === $field ) {
1717
  $value[] = (int) $item[ $field ];
1718
- } else {
1719
  $value[] = $item[ $field ];
1720
- }
1721
- } elseif ( is_object( $item ) && isset( $item->{$field} ) ) {
1722
- if ( $table['field_id'] === $field ) {
1723
  $value[] = (int) $item->{$field};
1724
- } else {
1725
  $value[] = $item->{$field};
1726
- }
1727
- } elseif ( ! empty( $related_obj ) && 0 === strpos( $full_field, 'post_thumbnail' ) ) {
1728
- // We want to catch post_thumbnail and post_thumbnail_url here
1729
- $value[] = $related_obj->field( $full_field );
1730
- } elseif (
1731
- (
1732
- ( false !== strpos( $full_field, '_src' ) || 'guid' === $field )
1733
- && (
1734
- in_array( $table['type'], array( 'attachment', 'media' ), true )
1735
- || in_array( $last_type, PodsForm::file_field_types(), true )
1736
- )
1737
- )
1738
- || ( in_array( $field, $permalink_fields, true ) && in_array( $last_type, PodsForm::file_field_types(), true ) )
1739
- ) {
1740
- // @todo Refactor the above condition statement.
1741
  $size = 'full';
1742
 
1743
- if ( ! wp_attachment_is_image( $item_id ) ) {
1744
- // No default sizes for non-images.
1745
- // When a size is defined this will be overwritten.
1746
  $size = null;
1747
  }
1748
 
1749
- if ( false !== strpos( $full_field, '_src.' ) && 5 < strlen( $full_field ) ) {
1750
  $size = substr( $full_field, 5 );
1751
- } elseif ( false !== strpos( $full_field, '_src_relative.' ) && 14 < strlen( $full_field ) ) {
1752
  $size = substr( $full_field, 14 );
1753
- } elseif ( false !== strpos( $full_field, '_src_schemeless.' ) && 16 < strlen( $full_field ) ) {
1754
  $size = substr( $full_field, 16 );
1755
- }
1756
 
1757
  if ( $size ) {
1758
- $value_url = pods_image_url( $item_id, $size, 0, true );
1759
  } else {
1760
  $value_url = wp_get_attachment_url( $item_id );
1761
  }
1762
 
1763
- if ( ! empty( $value_url ) ) {
1764
- if ( false !== strpos( $full_field, '_src_relative' ) ) {
1765
- $value_url_parsed = wp_parse_url( $value_url );
1766
- $value_url = $value_url_parsed['path'];
1767
- } elseif ( false !== strpos( $full_field, '_src_schemeless' ) ) {
1768
- $value_url = str_replace( array(
1769
- 'http://',
1770
- 'https://',
1771
- ), '//', $value_url );
1772
- }
1773
  }
 
 
1774
 
1775
- if ( ! empty( $value_url ) ) {
1776
  $value[] = $value_url;
1777
- }
1778
 
1779
  $params->raw_display = true;
1780
- } elseif ( false !== strpos( $full_field, '_img' ) && ( in_array( $table['type'], array(
1781
- 'attachment',
1782
- 'media',
1783
- ), true ) || in_array( $last_type, PodsForm::file_field_types(), true ) ) ) {
1784
  $size = 'full';
1785
 
1786
- if ( false !== strpos( $full_field, '_img.' ) && 5 < strlen( $full_field ) ) {
1787
  $size = substr( $full_field, 5 );
1788
- }
1789
 
1790
- $value[] = pods_image( $item_id, $size, 0, array(), true );
1791
 
1792
  $params->raw_display = true;
1793
- } elseif ( in_array( $field, array(
1794
- '_link',
1795
- 'detail_url',
1796
- ), true ) || in_array( $field, array( 'permalink', 'the_permalink' ), true ) ) {
1797
- if ( 'pod' === $object_type ) {
1798
  if ( is_object( $related_obj ) ) {
1799
  $related_obj->fetch( $item_id );
1800
 
1801
  $value[] = $related_obj->field( 'detail_url' );
1802
- } else {
1803
- $value[] = '';
1804
  }
1805
- } elseif ( 'post' === $object_type ) {
 
 
 
1806
  $value[] = get_permalink( $item_id );
1807
- } elseif ( 'taxonomy' === $object_type ) {
1808
  $value[] = get_term_link( $item_id, $object );
1809
- } elseif ( 'user' === $object_type ) {
1810
  $value[] = get_author_posts_url( $item_id );
1811
- } elseif ( 'comment' === $object_type ) {
1812
  $value[] = get_comment_link( $item_id );
1813
- } else {
1814
  $value[] = '';
1815
- }
1816
 
1817
  $params->raw_display = true;
1818
- } elseif ( in_array( $object_type, array(
1819
- 'post',
1820
- 'taxonomy',
1821
- 'user',
1822
- 'comment',
1823
- ), true ) ) {
1824
  $metadata_object_id = $item_id;
1825
 
1826
  $metadata_type = $object_type;
1827
 
1828
- if ( 'post' === $object_type ) {
1829
- // Support for WPML 'duplicated' translation handling.
1830
- if ( did_action( 'wpml_loaded' ) && apply_filters( 'wpml_is_translated_post_type', false, $object ) ) {
 
1831
  $master_post_id = (int) apply_filters( 'wpml_master_post_from_duplicate', $metadata_object_id );
1832
 
1833
- if ( 0 < $master_post_id ) {
1834
  $metadata_object_id = $master_post_id;
1835
- }
1836
  }
1837
- } elseif ( 'taxonomy' === $object_type ) {
1838
  $metadata_type = 'term';
1839
  }
1840
 
1841
- $meta_value = get_metadata( $metadata_type, $metadata_object_id, $field, true );
1842
- $value[] = pods_traverse( $traverse_fields, $meta_value );
1843
- } elseif ( 'settings' === $object_type ) {
1844
- $option_value = get_option( $object . '_' . $field );
1845
- $value[] = pods_traverse( $traverse_fields, $option_value );
1846
- }//end if
1847
- }//end foreach
1848
- }//end if
1849
-
1850
- if ( $object_no_conflict && ! $no_conflict ) {
1851
- // Revert temporarily no conflict mode.
1852
- pods_no_conflict_off( $object_type );
1853
  }
1854
 
1855
- // Handle Simple Relationships.
 
 
 
1856
  if ( $simple ) {
1857
- if ( null === $params->single ) {
1858
  $params->single = false;
1859
- }
1860
 
1861
  $value = PodsForm::field_method( 'pick', 'simple_value', $field, $value, $last_options, $all_fields[ $pod ], 0, true );
1862
- } elseif ( false === $params->in_form && ! empty( $value ) && is_array( $value ) && false === $params->keyed ) {
1863
- $value = array_values( $value );
1864
  }
 
 
1865
 
1866
- // Return a single column value.
1867
- if ( false === $params->in_form && 1 === $limit && ! empty( $value ) && is_array( $value ) && 1 === count( $value ) ) {
1868
  $value = current( $value );
1869
- }
1870
- }//end if
1871
 
1872
  if ( $last_options ) {
1873
  $last_field_data = $last_options;
1874
- } elseif ( isset( $related_obj, $related_obj->fields, $related_obj->fields[ $field ] ) ) {
1875
- // Save related field data for later to be used for display formatting
1876
- $last_field_data = $related_obj->fields[ $field ];
1877
  }
1878
 
1879
  break;
1880
- }//end if
1881
- }//end foreach
1882
- }//end if
1883
- }//end if
1884
- }//end if
1885
 
1886
- if ( ! empty( $params->traverse ) && 1 < count( $params->traverse ) ) {
1887
  $field_names = implode( '.', $params->traverse );
1888
 
1889
  $this->row[ $field_names ] = $value;
1890
- } elseif ( 'arrays' !== $params->output && in_array( $field_data['type'], $tableless_field_types, true ) ) {
 
1891
  $this->row[ '_' . $params->output . '_' . $params->full_name ] = $value;
1892
- } elseif ( 'arrays' === $params->output || ! in_array( $field_data['type'], $tableless_field_types, true ) ) {
 
1893
  $this->row[ $params->full_name ] = $value;
1894
  }
1895
 
1896
- if ( true === $params->single && is_array( $value ) && 1 === count( $value ) ) {
1897
  $value = current( $value );
1898
- }
1899
 
1900
  if ( ! empty( $last_field_data ) ) {
1901
  $field_data = $last_field_data;
1902
  }
1903
 
1904
- if ( ! empty( $field_data ) && ( $params->display || ! $params->raw ) && ! $params->in_form && ! $params->raw_display ) {
1905
- if ( $params->display || ( ( $params->get_meta || $params->deprecated ) && ! in_array( $field_data['type'], $tableless_field_types, true ) ) ) {
1906
- $field_data['options'] = pods_v( 'options', $field_data, array(), true );
 
1907
 
1908
- $post_temp = false;
1909
- $old_post = null;
1910
- $old_post_id = null;
1911
- $post_ID = null;
1912
 
1913
- if ( empty( $GLOBALS['post'] ) && 'post_type' === pods_v( 'type', $this->pod_data ) && 0 < $this->id() ) {
1914
  global $post_ID, $post;
1915
 
1916
  $post_temp = true;
1917
 
1918
- $old_post = $post;
1919
- $old_post_id = $post_ID;
1920
 
1921
- // @codingStandardsIgnoreLine.
1922
- $post = get_post( $this->id() );
1923
- // @codingStandardsIgnoreLine.
1924
  $post_ID = $this->id();
1925
  }
1926
 
1927
- $filter = pods_v( 'display_filter', $field_data['options'] );
1928
 
1929
  if ( 0 < strlen( $filter ) ) {
1930
  $args = array(
1931
  $filter,
1932
- $value,
1933
  );
1934
 
1935
- $filter_args = pods_v( 'display_filter_args', $field_data['options'] );
1936
 
1937
- if ( ! empty( $filter_args ) ) {
1938
  $args = array_merge( $args, compact( $filter_args ) );
1939
- }
1940
 
1941
  $value = call_user_func_array( 'apply_filters', $args );
1942
- } elseif ( 1 === (int) pods_v( 'display_process', $field_data['options'], 1 ) ) {
1943
- $value = PodsForm::display( $field_data['type'], $value, $params->name, array_merge( $field_data, $field_data['options'] ), $this->pod_data, $this->id() );
 
 
 
 
 
 
 
 
1944
  }
1945
 
1946
  if ( $post_temp ) {
1947
- // @codingStandardsIgnoreLine.
1948
- $post = $old_post;
1949
- // @codingStandardsIgnoreLine.
1950
- $post_ID = $old_post_id;
1951
  }
1952
- } else {
1953
- $value = PodsForm::value( $field_data['type'], $value, $params->name, array_merge( $field_data, $field_data['options'] ), $this->pod_data, $this->id() );
1954
- }//end if
1955
- }//end if
 
 
 
 
 
 
 
 
1956
 
1957
  /**
1958
  * Modify value returned by field() directly before output.
@@ -1961,10 +1647,11 @@ class Pods implements Iterator {
1961
  *
1962
  * @since unknown
1963
  *
1964
- * @param array|string|null $value Value to be returned.
1965
- * @param array|object $row Current row being outputted.
1966
- * @param array $params Params array passed to field().
1967
- * @param object|Pods $this Current Pods object.
 
1968
  */
1969
  $value = apply_filters( 'pods_pods_field', $value, $this->row, $params, $this );
1970
 
@@ -1974,79 +1661,71 @@ class Pods implements Iterator {
1974
  /**
1975
  * Check if an item field has a specific value in it
1976
  *
1977
- * @param string $field Field name.
1978
- * @param mixed $value Value to check.
1979
- * @param int $id (optional) ID of the pod item to check.
1980
  *
1981
  * @return bool Whether the value was found
1982
  *
1983
  * @since 2.3.3
1984
  */
1985
- public function has( $field, $value, $id = null ) {
1986
-
1987
  $pod =& $this;
1988
 
1989
- if ( null === $id ) {
1990
  $id = $this->id();
1991
- // @codingStandardsIgnoreLine.
1992
- } elseif ( $id != $this->id() ) {
1993
  $pod = pods( $this->pod, $id );
1994
- }
1995
 
1996
  $this->do_hook( 'has', $field, $value, $id );
1997
 
1998
- if ( ! isset( $this->fields[ $field ] ) ) {
1999
  return false;
2000
- }
2001
 
2002
- // Tableless fields.
2003
- if ( in_array( $this->fields[ $field ]['type'], PodsForm::tableless_field_types(), true ) ) {
2004
- if ( ! is_array( $value ) ) {
2005
  $value = explode( ',', $value );
2006
- }
2007
 
2008
- if ( 'pick' === $this->fields[ $field ]['type'] && in_array( $this->fields[ $field ]['pick_object'], PodsForm::simple_tableless_objects(), true ) ) {
2009
  $current_value = $pod->raw( $field );
2010
 
2011
- if ( ! empty( $current_value ) ) {
2012
  $current_value = (array) $current_value;
2013
- }
2014
 
2015
  foreach ( $current_value as $v ) {
2016
- // @codingStandardsIgnoreLine.
2017
- if ( in_array( $v, $value ) ) {
2018
  return true;
2019
- }
2020
  }
2021
- } else {
2022
- $related_ids = $this->api->lookup_related_items( $this->fields[ $field ]['id'], $this->pod_data['id'], $id, $this->fields[ $field ], $this->pod_data );
 
2023
 
2024
  foreach ( $value as $k => $v ) {
2025
- if ( ! preg_match( '/[^\D]/', $v ) ) {
2026
  $value[ $k ] = (int) $v;
2027
- }
 
2028
 
2029
- // @todo Convert slugs into IDs.
2030
  }
2031
 
2032
  foreach ( $related_ids as $v ) {
2033
- // @codingStandardsIgnoreLine.
2034
- if ( in_array( $v, $value ) ) {
2035
  return true;
2036
- }
2037
  }
2038
- }//end if
2039
- } elseif ( in_array( $this->fields[ $field ]['type'], PodsForm::text_field_types(), true ) ) {
2040
- // Text fields.
 
2041
  $current_value = $pod->raw( $field );
2042
 
2043
- if ( 0 < strlen( $current_value ) ) {
2044
  return stripos( $current_value, $value );
2045
- }
2046
- } else {
2047
- // All other fields.
2048
  return $this->is( $field, $value, $id );
2049
- }//end if
2050
 
2051
  return false;
2052
  }
@@ -2054,122 +1733,111 @@ class Pods implements Iterator {
2054
  /**
2055
  * Check if an item field is a specific value
2056
  *
2057
- * @param string $field Field name.
2058
- * @param mixed $value Value to check.
2059
- * @param int $id (optional) ID of the pod item to check.
2060
  *
2061
  * @return bool Whether the value was found
2062
  *
2063
  * @since 2.3.3
2064
  */
2065
- public function is( $field, $value, $id = null ) {
2066
-
2067
  $pod =& $this;
2068
 
2069
- if ( null === $id ) {
2070
  $id = $this->id();
2071
- // @codingStandardsIgnoreLine.
2072
- } elseif ( $id != $this->id() ) {
2073
  $pod = pods( $this->pod, $id );
2074
- }
2075
 
2076
  $this->do_hook( 'is', $field, $value, $id );
2077
 
2078
- if ( ! isset( $this->fields[ $field ] ) ) {
2079
  return false;
2080
- }
2081
 
2082
- // Tableless fields.
2083
- if ( in_array( $this->fields[ $field ]['type'], PodsForm::tableless_field_types(), true ) ) {
2084
- if ( ! is_array( $value ) ) {
2085
  $value = explode( ',', $value );
2086
- }
2087
 
2088
  $current_value = array();
2089
 
2090
- if ( 'pick' === $this->fields[ $field ]['type'] && in_array( $this->fields[ $field ]['pick_object'], PodsForm::simple_tableless_objects(), true ) ) {
2091
  $current_value = $pod->raw( $field );
2092
 
2093
- if ( ! empty( $current_value ) ) {
2094
  $current_value = (array) $current_value;
2095
- }
2096
 
2097
  foreach ( $current_value as $v ) {
2098
- // @codingStandardsIgnoreLine.
2099
- if ( in_array( $v, $value ) ) {
2100
  return true;
2101
- }
2102
  }
2103
- } else {
2104
- $related_ids = $this->api->lookup_related_items( $this->fields[ $field ]['id'], $this->pod_data['id'], $id, $this->fields[ $field ], $this->pod_data );
 
2105
 
2106
  foreach ( $value as $k => $v ) {
2107
- if ( ! preg_match( '/[^\D]/', $v ) ) {
2108
  $value[ $k ] = (int) $v;
2109
- }
 
2110
 
2111
- // @todo Convert slugs into IDs.
2112
  }
2113
 
2114
  foreach ( $related_ids as $v ) {
2115
- // @codingStandardsIgnoreLine.
2116
- if ( in_array( $v, $value ) ) {
2117
  return true;
2118
- }
2119
  }
2120
- }//end if
2121
 
2122
- if ( ! empty( $current_value ) ) {
2123
  $current_value = array_filter( array_unique( $current_value ) );
2124
- } else {
2125
  $current_value = array();
2126
- }
2127
 
2128
- if ( ! empty( $value ) ) {
2129
  $value = array_filter( array_unique( $value ) );
2130
- } else {
2131
  $value = array();
2132
- }
2133
 
2134
  sort( $current_value );
2135
  sort( $value );
2136
 
2137
- if ( $value === $current_value ) {
2138
  return true;
2139
- }
2140
- } elseif ( in_array( $this->fields[ $field ]['type'], PodsForm::number_field_types(), true ) ) {
2141
- // Number fields.
2142
  $current_value = $pod->raw( $field );
2143
 
2144
- if ( (float) $current_value === (float) $value ) {
2145
  return true;
2146
- }
2147
- } elseif ( in_array( $this->fields[ $field ]['type'], PodsForm::date_field_types(), true ) ) {
2148
- // Date fields.
2149
  $current_value = $pod->raw( $field );
2150
 
2151
  if ( 0 < strlen( $current_value ) ) {
2152
- if ( strtotime( $current_value ) === strtotime( $value ) ) {
2153
  return true;
2154
- }
2155
- } elseif ( empty( $value ) ) {
2156
- return true;
2157
  }
2158
- } elseif ( in_array( $this->fields[ $field ]['type'], PodsForm::text_field_types(), true ) ) {
2159
- // Text fields.
 
 
 
2160
  $current_value = $pod->raw( $field );
2161
 
2162
- if ( (string) $current_value === (string) $value ) {
2163
  return true;
2164
- }
2165
- } else {
2166
- // All other fields.
2167
  $current_value = $pod->raw( $field );
2168
 
2169
- if ( $current_value === $value ) {
2170
  return true;
2171
- }
2172
- }//end if
2173
 
2174
  return false;
2175
  }
@@ -2178,101 +1846,98 @@ class Pods implements Iterator {
2178
  * Return the item ID
2179
  *
2180
  * @return int
2181
- * @since 2.0.0
2182
  */
2183
- public function id() {
2184
-
2185
- if ( isset( $this->data->row, $this->data->row['id'] ) ) {
2186
- // If we already have data loaded return that ID.
2187
- return $this->data->row['id'];
2188
  }
2189
-
2190
  return $this->field( $this->data->field_id );
2191
  }
2192
 
2193
  /**
2194
  * Return the previous item ID, loops at the last id to return the first
2195
  *
2196
- * @param int|null $id ID to start from.
2197
- * @param array|object|null $params_override Override the find() parameters.
2198
  *
2199
  * @return int
2200
- * @since 2.0.0
2201
  */
2202
- public function prev_id( $id = null, $params_override = null ) {
2203
-
2204
- if ( null === $id ) {
2205
  $id = $this->id();
2206
- }
2207
 
2208
  $id = (int) $id;
2209
 
2210
  $params = array(
2211
- 'select' => "`t`.`{$this->data->field_id}`",
2212
- 'where' => "`t`.`{$this->data->field_id}` < {$id}",
2213
  'orderby' => "`t`.`{$this->data->field_id}` DESC",
2214
- 'limit' => 1,
2215
  );
2216
 
2217
- if ( ! empty( $params_override ) || ! empty( $this->params ) ) {
2218
- if ( ! empty( $params_override ) ) {
2219
  $params = $params_override;
2220
- } elseif ( ! empty( $this->params ) ) {
2221
  $params = $this->params;
2222
- }
2223
 
2224
  if ( is_object( $params ) ) {
2225
  $params = get_object_vars( $params );
2226
  }
2227
 
2228
  if ( 0 < $id ) {
2229
- if ( isset( $params['where'] ) && ! empty( $params['where'] ) ) {
2230
- $params['where'] = (array) $params['where'];
2231
- $params['where'][] = "`t`.`{$this->data->field_id}` < {$id}";
2232
- } else {
2233
- $params['where'] = "`t`.`{$this->data->field_id}` < {$id}";
 
2234
  }
2235
- } elseif ( isset( $params['offset'] ) && 0 < $params['offset'] ) {
2236
- $params['offset'] --;
2237
- } elseif ( 0 < $this->row_number && ! isset( $params['offset'] ) && ! empty( $this->params ) ) {
2238
- $params['offset'] = $this->row_number - 1;
2239
- } else {
2240
- return 0;
2241
  }
 
 
 
 
 
 
2242
 
2243
- if ( isset( $params['orderby'] ) && ! empty( $params['orderby'] ) ) {
2244
- if ( is_array( $params['orderby'] ) ) {
2245
- foreach ( $params['orderby'] as $orderby => $dir ) {
2246
  $dir = strtoupper( $dir );
2247
 
2248
- if ( ! in_array( $dir, array( 'ASC', 'DESC' ), true ) ) {
2249
  continue;
2250
  }
2251
 
2252
- if ( 'ASC' === $dir ) {
2253
- $params['orderby'][ $orderby ] = 'DESC';
2254
- } else {
2255
- $params['orderby'][ $orderby ] = 'ASC';
 
2256
  }
2257
  }
2258
 
2259
- $params['orderby'][ $this->data->field_id ] = 'DESC';
2260
- } elseif ( "`t`.`{$this->data->field_id}` DESC" !== $params['orderby'] ) {
2261
- $params['orderby'] .= ", `t`.`{$this->data->field_id}` DESC";
 
2262
  }
2263
- }//end if
2264
 
2265
- $params['select'] = "`t`.`{$this->data->field_id}`";
2266
- $params['limit'] = 1;
2267
- }//end if
2268
 
2269
  $pod = pods( $this->pod, $params );
2270
 
2271
  $new_id = 0;
2272
 
2273
- if ( $pod->fetch() ) {
2274
  $new_id = $pod->id();
2275
- }
2276
 
2277
  $new_id = $this->do_hook( 'prev_id', $new_id, $id, $pod, $params_override );
2278
 
@@ -2282,66 +1947,63 @@ class Pods implements Iterator {
2282
  /**
2283
  * Return the next item ID, loops at the first id to return the last
2284
  *
2285
- * @param int|null $id ID to start from.
2286
- * @param array|object|null $params_override Override the find() parameters.
2287
  *
2288
  * @return int
2289
- * @since 2.0.0
2290
  */
2291
- public function next_id( $id = null, $params_override = null ) {
2292
-
2293
- if ( null === $id ) {
2294
  $id = $this->id();
2295
- }
2296
 
2297
  $id = (int) $id;
2298
 
2299
  $params = array(
2300
- 'select' => "`t`.`{$this->data->field_id}`",
2301
- 'where' => "{$id} < `t`.`{$this->data->field_id}`",
2302
  'orderby' => "`t`.`{$this->data->field_id}` ASC",
2303
- 'limit' => 1,
2304
  );
2305
 
2306
- if ( ! empty( $params_override ) || ! empty( $this->params ) ) {
2307
- if ( ! empty( $params_override ) ) {
2308
  $params = $params_override;
2309
- } elseif ( ! empty( $this->params ) ) {
2310
  $params = $this->params;
2311
- }
2312
 
2313
  if ( is_object( $params ) ) {
2314
  $params = get_object_vars( $params );
2315
  }
2316
 
2317
  if ( 0 < $id ) {
2318
- if ( isset( $params['where'] ) && ! empty( $params['where'] ) ) {
2319
- $params['where'] = (array) $params['where'];
2320
- $params['where'][] = "{$id} < `t`.`{$this->data->field_id}`";
2321
- } else {
2322
- $params['where'] = "{$id} < `t`.`{$this->data->field_id}`";
2323
  }
2324
- } elseif ( ! isset( $params['offset'] ) ) {
2325
- if ( ! empty( $this->params ) && - 1 < $this->row_number ) {
2326
- $params['offset'] = $this->row_number + 1;
2327
- } else {
2328
- $params['offset'] = 1;
2329
  }
2330
- } else {
2331
- $params['offset'] ++;
2332
  }
 
 
 
 
 
 
 
 
2333
 
2334
- $params['select'] = "`t`.`{$this->data->field_id}`";
2335
- $params['limit'] = 1;
2336
- }//end if
2337
 
2338
  $pod = pods( $this->pod, $params );
2339
 
2340
  $new_id = 0;
2341
 
2342
- if ( $pod->fetch() ) {
2343
  $new_id = $pod->id();
2344
- }
2345
 
2346
  $new_id = $this->do_hook( 'next_id', $new_id, $id, $pod, $params_override );
2347
 
@@ -2351,42 +2013,39 @@ class Pods implements Iterator {
2351
  /**
2352
  * Return the first item ID
2353
  *
2354
- * @param array|object|null $params_override Override the find() parameters.
2355
  *
2356
  * @return int
2357
- * @since 2.3.0
2358
  */
2359
- public function first_id( $params_override = null ) {
2360
-
2361
  $params = array(
2362
- 'select' => "`t`.`{$this->data->field_id}`",
2363
  'orderby' => "`t`.`{$this->data->field_id}` ASC",
2364
- 'limit' => 1,
2365
  );
2366
 
2367
- if ( ! empty( $params_override ) || ! empty( $this->params ) ) {
2368
- if ( ! empty( $params_override ) ) {
2369
  $params = $params_override;
2370
- } elseif ( ! empty( $this->params ) ) {
2371
  $params = $this->params;
2372
- }
2373
 
2374
  if ( is_object( $params ) ) {
2375
  $params = get_object_vars( $params );
2376
  }
2377
 
2378
- $params['select'] = "`t`.`{$this->data->field_id}`";
2379
- $params['offset'] = 0;
2380
- $params['limit'] = 1;
2381
  }
2382
 
2383
  $pod = pods( $this->pod, $params );
2384
 
2385
  $new_id = 0;
2386
 
2387
- if ( $pod->fetch() ) {
2388
  $new_id = $pod->id();
2389
- }
2390
 
2391
  $new_id = $this->do_hook( 'first_id', $new_id, $pod, $params_override );
2392
 
@@ -2396,72 +2055,69 @@ class Pods implements Iterator {
2396
  /**
2397
  * Return the last item ID
2398
  *
2399
- * @param array|object|null $params_override Override the find() parameters.
2400
  *
2401
  * @return int
2402
- * @since 2.3.0
2403
  */
2404
- public function last_id( $params_override = null ) {
2405
-
2406
  $params = array(
2407
- 'select' => "`t`.`{$this->data->field_id}`",
2408
  'orderby' => "`t`.`{$this->data->field_id}` DESC",
2409
- 'limit' => 1,
2410
  );
2411
 
2412
- if ( ! empty( $params_override ) || ! empty( $this->params ) ) {
2413
- if ( ! empty( $params_override ) ) {
2414
  $params = $params_override;
2415
- } elseif ( ! empty( $this->params ) ) {
2416
  $params = $this->params;
2417
- }
2418
 
2419
  if ( is_object( $params ) ) {
2420
  $params = get_object_vars( $params );
2421
  }
2422
 
2423
- if ( isset( $params['total_found'] ) ) {
2424
- $params['offset'] = $params['total_found'] - 1;
2425
- } else {
2426
- $params['offset'] = $this->total_found() - 1;
2427
- }
2428
 
2429
- if ( isset( $params['orderby'] ) && ! empty( $params['orderby'] ) ) {
2430
- if ( is_array( $params['orderby'] ) ) {
2431
- foreach ( $params['orderby'] as $orderby => $dir ) {
2432
  $dir = strtoupper( $dir );
2433
 
2434
- if ( ! in_array( $dir, array( 'ASC', 'DESC' ), true ) ) {
2435
  continue;
2436
  }
2437
 
2438
- if ( 'ASC' === $dir ) {
2439
- $params['orderby'][ $orderby ] = 'DESC';
2440
- } else {
2441
- $params['orderby'][ $orderby ] = 'ASC';
 
2442
  }
2443
  }
2444
 
2445
- $params['orderby'][ $this->data->field_id ] = 'DESC';
2446
- } elseif ( "`t`.`{$this->data->field_id}` DESC" !== $params['orderby'] ) {
2447
- $params['orderby'] .= ", `t`.`{$this->data->field_id}` DESC";
2448
  }
2449
- }//end if
 
 
 
2450
 
2451
- $params['select'] = "`t`.`{$this->data->field_id}`";
2452
- $params['limit'] = 1;
2453
- }//end if
2454
 
2455
  $pod = pods( $this->pod, $params );
2456
 
2457
  $new_id = 0;
2458
 
2459
- if ( $pod->fetch() ) {
2460
  $new_id = $pod->id();
2461
- }
2462
 
2463
  $new_id = $this->do_hook( 'last_id', $new_id, $pod, $params_override );
2464
-
2465
  return $new_id;
2466
  }
2467
 
@@ -2469,248 +2125,219 @@ class Pods implements Iterator {
2469
  * Return the item name
2470
  *
2471
  * @return string
2472
- * @since 2.0.0
2473
  */
2474
- public function index() {
2475
-
2476
  return $this->field( $this->data->field_index );
2477
  }
2478
 
2479
  /**
2480
  * Find items of a pod, much like WP_Query, but with advanced table handling.
2481
  *
2482
- * @param array|object $params An associative array of parameters.
2483
- * @param int $limit (deprecated) Limit the number of items to find, -1 to return all items with no limit.
2484
- * @param string $where (deprecated) SQL WHERE declaration to use.
2485
- * @param string $sql (deprecated) For advanced use, a custom SQL query to run.
2486
  *
2487
  * @return \Pods The pod object
2488
- * @since 2.0.0
2489
- * @link https://pods.io/docs/find/
2490
  */
2491
- public function find( $params = null, $limit = 15, $where = null, $sql = null ) {
2492
 
2493
- $tableless_field_types = PodsForm::tableless_field_types();
2494
  $simple_tableless_objects = PodsForm::simple_tableless_objects();
2495
 
 
2496
  $this->params = $params;
2497
 
2498
  $select = '`t`.*';
2499
 
2500
- if ( 'table' === $this->pod_data['storage'] && ! in_array( $this->pod_data['type'], array(
2501
- 'pod',
2502
- 'table',
2503
- ), true ) ) {
2504
  $select .= ', `d`.*';
2505
- }
2506
 
2507
- if ( empty( $this->data->table ) ) {
2508
  return $this;
2509
- }
2510
 
2511
  $defaults = array(
2512
- // Optimization parameters.
2513
- 'table' => $this->data->table,
2514
- 'select' => $select,
2515
- 'join' => null,
2516
- // Main query parameters.
2517
- 'where' => $where,
2518
- 'groupby' => null,
2519
- 'having' => null,
2520
- 'orderby' => null,
2521
- // Pagination parameters.
2522
- 'limit' => (int) $limit,
2523
- 'offset' => null,
2524
- 'page' => (int) $this->page,
2525
- 'page_var' => $this->page_var,
2526
- 'pagination' => (boolean) $this->pagination,
2527
- // Search parameters.
2528
- 'search' => (boolean) $this->search,
2529
- 'search_var' => $this->search_var,
2530
- 'search_query' => null,
2531
- 'search_mode' => $this->search_mode,
2532
- 'search_across' => false,
2533
  'search_across_picks' => false,
2534
  'search_across_files' => false,
2535
- // Advanced parameters.
2536
- 'filters' => $this->filters,
2537
- 'sql' => $sql,
2538
- // Caching parameters.
2539
- 'expires' => null,
2540
- 'cache_mode' => 'cache',
2541
  );
2542
 
2543
- if ( is_array( $params ) ) {
2544
  $params = (object) array_merge( $defaults, $params );
2545
- } elseif ( is_object( $params ) ) {
2546
  $params = (object) array_merge( $defaults, get_object_vars( $params ) );
2547
- } else {
2548
- $defaults['orderby'] = $params;
2549
-
2550
  $params = (object) $defaults;
2551
  }
2552
 
2553
- /**
2554
- * Filter the Pods::find() parameters.
2555
- *
2556
- * @param object $params Parameters to make lookup with.
2557
- */
2558
  $params = apply_filters( 'pods_pods_find', $params );
2559
 
2560
  $params->limit = (int) $params->limit;
2561
 
2562
- if ( 0 === $params->limit ) {
2563
- $params->limit = - 1;
2564
- }
2565
 
2566
- $this->limit = (int) $params->limit;
2567
- $this->offset = (int) $params->offset;
2568
- $this->page = (int) $params->page;
2569
- $this->page_var = $params->page_var;
2570
  $this->pagination = (boolean) $params->pagination;
2571
- $this->search = (boolean) $params->search;
2572
  $this->search_var = $params->search_var;
2573
- $params->join = (array) $params->join;
2574
 
2575
- if ( empty( $params->search_query ) ) {
2576
- $params->search_query = pods_v_sanitized( $this->search_var, 'get', '' );
2577
- }
2578
 
2579
- // Allow orderby array ( 'field' => 'asc|desc' ).
2580
- if ( ! empty( $params->orderby ) && is_array( $params->orderby ) ) {
2581
- foreach ( $params->orderby as $k => $orderby ) {
2582
- if ( ! is_numeric( $k ) ) {
2583
  $key = '';
2584
 
2585
  $order = 'ASC';
2586
 
2587
- if ( 'DESC' === strtoupper( $orderby ) ) {
2588
  $order = 'DESC';
2589
- }
2590
 
2591
- if ( isset( $this->fields[ $k ] ) && in_array( $this->fields[ $k ]['type'], $tableless_field_types, true ) ) {
2592
- if ( in_array( $this->fields[ $k ]['pick_object'], $simple_tableless_objects, true ) ) {
2593
- if ( 'table' === $this->pod_data['storage'] ) {
2594
- if ( ! in_array( $this->pod_data['type'], array( 'pod', 'table' ), true ) ) {
2595
  $key = "`d`.`{$k}`";
2596
- } else {
2597
  $key = "`t`.`{$k}`";
2598
- }
2599
- } else {
2600
- $key = "`{$k}`.`meta_value`";
2601
  }
2602
- } else {
2603
- $pick_val = $this->fields[ $k ]['pick_val'];
 
 
 
2604
 
2605
- if ( '__current__' === $pick_val ) {
2606
  $pick_val = $this->pod;
2607
- }
2608
 
2609
- $table = $this->api->get_table_info( $this->fields[ $k ]['pick_object'], $pick_val );
2610
 
2611
- if ( ! empty( $table ) ) {
2612
- $key = "`{$k}`.`" . $table['field_index'] . '`';
2613
- }
2614
- }//end if
2615
- }//end if
2616
 
2617
  if ( empty( $key ) ) {
2618
- if ( ! in_array( $this->pod_data['type'], array( 'pod', 'table' ), true ) ) {
2619
- if ( isset( $this->pod_data['object_fields'][ $k ] ) ) {
2620
  $key = "`t`.`{$k}`";
2621
- } elseif ( isset( $this->fields[ $k ] ) ) {
2622
- if ( 'table' === $this->pod_data['storage'] ) {
2623
  $key = "`d`.`{$k}`";
2624
- } else {
2625
  $key = "`{$k}`.`meta_value`";
2626
- }
2627
- } else {
2628
- $object_fields = (array) $this->pod_data['object_fields'];
2629
-
2630
- foreach ( $object_fields as $object_field => $object_field_opt ) {
2631
- if ( $object_field === $k || in_array( $k, $object_field_opt['alias'], true ) ) {
2632
  $key = "`t`.`{$object_field}`";
2633
- }
2634
  }
2635
  }
2636
- } elseif ( isset( $this->fields[ $k ] ) ) {
2637
- if ( 'table' === $this->pod_data['storage'] ) {
 
2638
  $key = "`t`.`{$k}`";
2639
- } else {
2640
  $key = "`{$k}`.`meta_value`";
2641
- }
2642
- }//end if
2643
 
2644
  if ( empty( $key ) ) {
2645
  $key = $k;
2646
 
2647
- if ( false === strpos( $key, ' ' ) && false === strpos( $key, '`' ) ) {
2648
  $key = '`' . str_replace( '.', '`.`', $key ) . '`';
2649
- }
2650
  }
2651
- }//end if
2652
 
2653
  $orderby = $key;
2654
 
2655
- if ( false === strpos( $orderby, ' ' ) ) {
2656
  $orderby .= ' ' . $order;
2657
- }
2658
-
2659
- $params->orderby[ $k ] = $orderby;
2660
- }//end if
2661
- }//end foreach
2662
- }//end if
2663
 
2664
- // Add prefix to $params->orderby if needed.
2665
- if ( ! empty( $params->orderby ) ) {
2666
- if ( ! is_array( $params->orderby ) ) {
2667
  $params->orderby = array( $params->orderby );
2668
- }
2669
 
2670
- foreach ( $params->orderby as $ok => $prefix_orderby ) {
2671
  if ( false === strpos( $prefix_orderby, ',' ) && false === strpos( $prefix_orderby, '(' ) && false === stripos( $prefix_orderby, ' AS ' ) && false === strpos( $prefix_orderby, '`' ) && false === strpos( $prefix_orderby, '.' ) ) {
2672
  if ( false !== stripos( $prefix_orderby, ' DESC' ) ) {
2673
- $k = trim( str_ireplace( array( '`', ' DESC' ), '', $prefix_orderby ) );
2674
  $dir = 'DESC';
2675
- } else {
2676
- $k = trim( str_ireplace( array( '`', ' ASC' ), '', $prefix_orderby ) );
 
2677
  $dir = 'ASC';
2678
  }
2679
 
2680
  $key = $k;
2681
 
2682
- if ( ! in_array( $this->pod_data['type'], array( 'pod', 'table' ), true ) ) {
2683
- if ( isset( $this->pod_data['object_fields'][ $k ] ) ) {
2684
  $key = "`t`.`{$k}`";
2685
- } elseif ( isset( $this->fields[ $k ] ) ) {
2686
- if ( 'table' === $this->pod_data['storage'] ) {
2687
  $key = "`d`.`{$k}`";
2688
- } else {
2689
  $key = "`{$k}`.`meta_value`";
2690
- }
2691
- } else {
2692
- $object_fields = (array) $this->pod_data['object_fields'];
2693
-
2694
- foreach ( $object_fields as $object_field => $object_field_opt ) {
2695
- if ( $object_field === $k || in_array( $k, $object_field_opt['alias'], true ) ) {
2696
  $key = "`t`.`{$object_field}`";
2697
- }
2698
  }
2699
  }
2700
- } elseif ( isset( $this->fields[ $k ] ) ) {
2701
- if ( 'table' === $this->pod_data['storage'] ) {
 
2702
  $key = "`t`.`{$k}`";
2703
- } else {
2704
  $key = "`{$k}`.`meta_value`";
2705
- }
2706
- }//end if
2707
 
2708
  $prefix_orderby = "{$key} {$dir}";
2709
-
2710
- $params->orderby[ $ok ] = $prefix_orderby;
2711
- }//end if
2712
- }//end foreach
2713
- }//end if
2714
 
2715
  $this->data->select( $params );
2716
 
@@ -2721,34 +2348,31 @@ class Pods implements Iterator {
2721
  * Fetch an item from a Pod. If $id is null, it will return the next item in the list after running find().
2722
  * You can rewind the list back to the start by using reset().
2723
  *
2724
- * Providing an $id will fetch a specific item from a Pod, much like a call to pods(), and can handle either an id
2725
- * or slug.
2726
  *
2727
- * @see PodsData::fetch
2728
  *
2729
- * @param int $id ID or slug of the item to fetch.
2730
- * @param bool $explicit_set Whether to set explicitly (use false when in loop).
2731
  *
2732
  * @return array An array of fields from the row
2733
  *
2734
- * @since 2.0.0
2735
- * @link https://pods.io/docs/fetch/
2736
  */
2737
- public function fetch( $id = null, $explicit_set = true ) {
2738
-
2739
  /**
2740
- * Runs directly before an item is fetched by fetch().
2741
  *
2742
  * @since unknown
2743
  *
2744
- * @param int|string|null $id Item ID being fetched or null.
2745
- * @param object|Pods $this Current Pods object.
2746
  */
2747
  do_action( 'pods_pods_fetch', $id, $this );
2748
 
2749
- if ( ! empty( $id ) ) {
2750
  $this->params = array();
2751
- }
2752
 
2753
  $this->data->fetch( $id, $explicit_set );
2754
 
@@ -2758,23 +2382,22 @@ class Pods implements Iterator {
2758
  /**
2759
  * (Re)set the MySQL result pointer
2760
  *
2761
- * @see PodsData::reset
2762
  *
2763
- * @param int $row ID of the row to reset to.
2764
  *
2765
  * @return \Pods The pod object
2766
  *
2767
- * @since 2.0.0
2768
- * @link https://pods.io/docs/reset/
2769
  */
2770
- public function reset( $row = null ) {
2771
-
2772
  /**
2773
  * Runs directly before the Pods object is reset by reset()
2774
  *
2775
  * @since unknown
2776
  *
2777
- * @param int|string|null The ID of the row being reset to or null if being reset to the beginning.
2778
  * @param object|Pods $this Current Pods object.
2779
  */
2780
  do_action( 'pods_pods_reset', $row, $this );
@@ -2789,14 +2412,13 @@ class Pods implements Iterator {
2789
  *
2790
  * This is different than the total number of rows found in the database, which you can get with total_found().
2791
  *
2792
- * @see PodsData::total
2793
  *
2794
  * @return int Number of rows returned by find(), based on the 'limit' parameter set
2795
- * @since 2.0.0
2796
- * @link https://pods.io/docs/total/
2797
  */
2798
- public function total() {
2799
-
2800
  do_action( 'pods_pods_total', $this );
2801
 
2802
  $this->data->total();
@@ -2811,20 +2433,20 @@ class Pods implements Iterator {
2811
  *
2812
  * This is different than the total number of rows limited by the current call, which you can get with total().
2813
  *
2814
- * @see PodsData::total_found
2815
  *
2816
  * @return int Number of rows returned by find(), regardless of the 'limit' parameter
2817
- * @since 2.0.0
2818
- * @link https://pods.io/docs/total-found/
2819
  */
2820
- public function total_found() {
2821
-
2822
  /**
2823
  * Runs directly before the value of total_found() is determined and returned.
2824
  *
2825
  * @since unknown
2826
  *
2827
  * @param object|Pods $this Current Pods object.
 
2828
  */
2829
  do_action( 'pods_pods_total_found', $this );
2830
 
@@ -2838,9 +2460,9 @@ class Pods implements Iterator {
2838
  /**
2839
  * Fetch the total number of pages, based on total rows found and the last find() limit
2840
  *
2841
- * @param null|int $limit Rows per page.
2842
- * @param null|int $offset Offset of rows.
2843
- * @param null|int $total Total rows.
2844
  *
2845
  * @return int Number of pages
2846
  * @since 2.3.10
@@ -2861,20 +2483,21 @@ class Pods implements Iterator {
2861
  $total = $this->total_found();
2862
  }
2863
 
2864
- return ceil( ( $total - $offset ) / $limit );
 
 
2865
 
2866
  }
2867
 
2868
  /**
2869
  * Fetch the zebra switch
2870
  *
2871
- * @see PodsData::zebra
2872
  *
2873
  * @return bool Zebra state
2874
  * @since 1.12
2875
  */
2876
- public function zebra() {
2877
-
2878
  $this->do_hook( 'zebra' );
2879
 
2880
  return $this->data->zebra();
@@ -2883,15 +2506,14 @@ class Pods implements Iterator {
2883
  /**
2884
  * Fetch the nth state
2885
  *
2886
- * @see PodsData::nth
2887
  *
2888
- * @param int|string $nth The $nth to match on the PodsData::row_number.
2889
  *
2890
  * @return bool Whether $nth matches
2891
- * @since 2.3.0
2892
  */
2893
- public function nth( $nth = null ) {
2894
-
2895
  $this->do_hook( 'nth', $nth );
2896
 
2897
  return $this->data->nth( $nth );
@@ -2900,13 +2522,12 @@ class Pods implements Iterator {
2900
  /**
2901
  * Fetch the current position in the loop (starting at 1)
2902
  *
2903
- * @see PodsData::position
2904
  *
2905
  * @return int Current row number (+1)
2906
- * @since 2.3.0
2907
  */
2908
- public function position() {
2909
-
2910
  $this->do_hook( 'position' );
2911
 
2912
  return $this->data->position();
@@ -2918,53 +2539,48 @@ class Pods implements Iterator {
2918
  *
2919
  * You may be looking for save() in most cases where you're setting a specific field.
2920
  *
2921
- * @see PodsAPI::save_pod_item
2922
  *
2923
- * @param array|string $data Either an associative array of field information or a field name.
2924
- * @param mixed $value (optional) Value of the field, if $data is a field name.
2925
  *
2926
  * @return int The item ID
2927
  *
2928
- * @since 2.0.0
2929
- * @link https://pods.io/docs/add/
2930
  */
2931
- public function add( $data = null, $value = null ) {
2932
-
2933
- if ( null !== $value ) {
2934
  $data = array( $data => $value );
2935
- }
2936
 
2937
  $data = (array) $this->do_hook( 'add', $data );
2938
 
2939
- if ( empty( $data ) ) {
2940
  return 0;
2941
- }
2942
 
2943
  $params = array(
2944
- 'pod' => $this->pod,
2945
- 'data' => $data,
2946
- 'allow_custom_fields' => true,
2947
  );
2948
 
2949
  return $this->api->save_pod_item( $params );
2950
  }
2951
 
2952
  /**
2953
- * Add an item to the values of a relationship field, add a value to a number field (field+1), add time to a date
2954
- * field, or add text to a text field
2955
  *
2956
- * @see PodsAPI::save_pod_item
2957
  *
2958
- * @param string $field Field name.
2959
- * @param mixed $value IDs to add, int|float to add to number field, string for dates (+1 day), or string for text.
2960
- * @param int $id (optional) ID of the pod item to update.
2961
  *
2962
  * @return int The item ID
2963
  *
2964
- * @since 2.3.0
2965
  */
2966
- public function add_to( $field, $value, $id = null ) {
2967
-
2968
  $pod =& $this;
2969
 
2970
  $fetch = false;
@@ -2973,90 +2589,87 @@ class Pods implements Iterator {
2973
  $fetch = true;
2974
 
2975
  $id = $pod->id();
2976
- // @codingStandardsIgnoreLine
2977
- } elseif ( $id != $this->id() ) {
2978
  $pod = pods( $this->pod, $id );
2979
  }
2980
 
2981
  $this->do_hook( 'add_to', $field, $value, $id );
2982
 
2983
- if ( ! isset( $this->fields[ $field ] ) ) {
2984
  return $id;
2985
- }
2986
 
2987
- // Tableless fields.
2988
- if ( in_array( $this->fields[ $field ]['type'], PodsForm::tableless_field_types(), true ) ) {
2989
- if ( ! is_array( $value ) ) {
2990
  $value = explode( ',', $value );
2991
- }
2992
 
2993
- if ( 'pick' === $this->fields[ $field ]['type'] && in_array( $this->fields[ $field ]['pick_object'], PodsForm::simple_tableless_objects(), true ) ) {
2994
  $current_value = $pod->raw( $field );
2995
 
2996
- if ( ! empty( $current_value ) || ( ! is_array( $current_value ) && 0 < strlen( $current_value ) ) ) {
2997
  $current_value = (array) $current_value;
2998
- } else {
2999
  $current_value = array();
3000
- }
3001
 
3002
  $value = array_merge( $current_value, $value );
3003
- } else {
3004
- $related_ids = $this->api->lookup_related_items( $this->fields[ $field ]['id'], $this->pod_data['id'], $id, $this->fields[ $field ], $this->pod_data );
 
3005
 
3006
  foreach ( $value as $k => $v ) {
3007
- if ( ! preg_match( '/[^\D]/', $v ) ) {
3008
  $value[ $k ] = (int) $v;
3009
- }
3010
  }
3011
 
3012
  $value = array_merge( $related_ids, $value );
3013
- }//end if
3014
 
3015
- if ( ! empty( $value ) ) {
3016
  $value = array_filter( array_unique( $value ) );
3017
- } else {
3018
  $value = array();
3019
- }
3020
 
3021
- if ( empty( $value ) ) {
3022
  return $id;
3023
- }
3024
- } elseif ( in_array( $this->fields[ $field ]['type'], PodsForm::number_field_types(), true ) ) {
3025
- // Number fields.
3026
  $current_value = (float) $pod->raw( $field );
3027
 
3028
  $value = ( $current_value + (float) $value );
3029
- } elseif ( in_array( $this->fields[ $field ]['type'], PodsForm::date_field_types(), true ) ) {
3030
- // Date fields.
 
3031
  $current_value = $pod->raw( $field );
3032
 
3033
- if ( 0 < strlen( $current_value ) ) {
3034
  $value = strtotime( $value, strtotime( $current_value ) );
3035
- } else {
3036
  $value = strtotime( $value );
3037
- }
3038
- } elseif ( in_array( $this->fields[ $field ]['type'], PodsForm::text_field_types(), true ) ) {
3039
- // Text fields.
3040
  $current_value = $pod->raw( $field );
3041
 
3042
- if ( 0 < strlen( $current_value ) ) {
3043
  $value = $current_value . $value;
3044
- }
3045
- }//end if
 
3046
 
3047
- // @todo handle object fields and taxonomies.
3048
  $params = array(
3049
- 'pod' => $this->pod,
3050
- 'id' => $id,
3051
  'data' => array(
3052
- $field => $value,
3053
- ),
3054
  );
3055
 
3056
  $id = $this->api->save_pod_item( $params );
3057
 
3058
  if ( 0 < $id && $fetch ) {
3059
- // Clear local var cache of field values.
3060
  $pod->data->row = array();
3061
 
3062
  $pod->fetch( $id, false );
@@ -3066,21 +2679,19 @@ class Pods implements Iterator {
3066
  }
3067
 
3068
  /**
3069
- * Remove an item from the values of a relationship field, remove a value from a number field (field-1), remove
3070
- * time to a date field
3071
  *
3072
- * @see PodsAPI::save_pod_item
3073
  *
3074
- * @param string $field Field name.
3075
- * @param mixed $value IDs to add, int|float to add to number field, string for dates (-1 day), or string for text.
3076
- * @param int $id (optional) ID of the pod item to update.
3077
  *
3078
  * @return int The item ID
3079
  *
3080
  * @since 2.3.3
3081
  */
3082
  public function remove_from( $field, $value = null, $id = null ) {
3083
-
3084
  $pod =& $this;
3085
 
3086
  $fetch = false;
@@ -3089,73 +2700,76 @@ class Pods implements Iterator {
3089
  $fetch = true;
3090
 
3091
  $id = $this->id();
3092
- // @codingStandardsIgnoreLine
3093
- } elseif ( $id != $this->id() ) {
3094
  $pod = pods( $this->pod, $id );
3095
  }
3096
 
3097
  $this->do_hook( 'remove_from', $field, $value, $id );
3098
 
3099
- if ( ! isset( $this->fields[ $field ] ) ) {
3100
  return $id;
3101
  }
3102
 
3103
- // Tableless fields.
3104
- if ( in_array( $this->fields[ $field ]['type'], PodsForm::tableless_field_types(), true ) ) {
3105
  if ( empty( $value ) ) {
3106
  $value = array();
3107
  }
3108
 
3109
- if ( ! empty( $value ) ) {
3110
- if ( ! is_array( $value ) ) {
3111
  $value = explode( ',', $value );
3112
  }
3113
 
3114
- if ( 'pick' === $this->fields[ $field ]['type'] && in_array( $this->fields[ $field ]['pick_object'], PodsForm::simple_tableless_objects(), true ) ) {
3115
  $current_value = $pod->raw( $field );
3116
 
3117
- if ( ! empty( $current_value ) ) {
3118
  $current_value = (array) $current_value;
3119
  }
3120
 
3121
  foreach ( $current_value as $k => $v ) {
3122
- // @codingStandardsIgnoreLine.
3123
  if ( in_array( $v, $value ) ) {
3124
  unset( $current_value[ $k ] );
3125
  }
3126
  }
3127
 
3128
  $value = $current_value;
3129
- } else {
3130
- $related_ids = $this->api->lookup_related_items( $this->fields[ $field ]['id'], $this->pod_data['id'], $id, $this->fields[ $field ], $this->pod_data );
 
3131
 
3132
  foreach ( $value as $k => $v ) {
3133
- if ( ! preg_match( '/[^\D]/', $v ) ) {
3134
  $value[ $k ] = (int) $v;
3135
  }
 
 
3136
 
3137
- // @todo Convert slugs into IDs.
3138
  }
3139
 
3140
  foreach ( $related_ids as $k => $v ) {
3141
- // @codingStandardsIgnoreLine.
3142
  if ( in_array( $v, $value ) ) {
3143
  unset( $related_ids[ $k ] );
3144
  }
3145
  }
3146
 
3147
  $value = $related_ids;
3148
- }//end if
3149
 
3150
- if ( ! empty( $value ) ) {
3151
  $value = array_filter( array_unique( $value ) );
3152
- } else {
 
3153
  $value = array();
3154
  }
3155
- }//end if
3156
- } elseif ( in_array( $this->fields[ $field ]['type'], PodsForm::number_field_types(), true ) ) {
3157
- // Number fields.
3158
- // Date fields don't support empty for removing.
 
3159
  if ( empty( $value ) ) {
3160
  return $id;
3161
  }
@@ -3163,9 +2777,10 @@ class Pods implements Iterator {
3163
  $current_value = (float) $pod->raw( $field );
3164
 
3165
  $value = ( $current_value - (float) $value );
3166
- } elseif ( in_array( $this->fields[ $field ]['type'], PodsForm::date_field_types(), true ) ) {
3167
- // Date fields.
3168
- // Date fields don't support empty for removing.
 
3169
  if ( empty( $value ) ) {
3170
  return $id;
3171
  }
@@ -3174,26 +2789,28 @@ class Pods implements Iterator {
3174
 
3175
  if ( 0 < strlen( $current_value ) ) {
3176
  $value = strtotime( $value, strtotime( $current_value ) );
3177
- } else {
 
3178
  $value = strtotime( $value );
3179
  }
3180
 
3181
  $value = date_i18n( 'Y-m-d h:i:s', $value );
3182
- }//end if
 
 
3183
 
3184
- // @todo handle object fields and taxonomies.
3185
  $params = array(
3186
- 'pod' => $this->pod,
3187
- 'id' => $id,
3188
  'data' => array(
3189
- $field => $value,
3190
- ),
3191
  );
3192
 
3193
  $id = $this->api->save_pod_item( $params );
3194
 
3195
  if ( 0 < $id && $fetch ) {
3196
- // Clear local var cache of field values.
3197
  $pod->data->row = array();
3198
 
3199
  $pod->fetch( $id, false );
@@ -3209,27 +2826,24 @@ class Pods implements Iterator {
3209
  * Though this function has the capacity to add new items, best practice should direct you
3210
  * to use add() for that instead.
3211
  *
3212
- * @see PodsAPI::save_pod_item
3213
  *
3214
- * @param array|string $data Either an associative array of field information or a field name.
3215
- * @param mixed $value (optional) Value of the field, if $data is a field name.
3216
- * @param int $id (optional) ID of the pod item to update.
3217
- * @param array $params (optional) Additional params to send to save_pod_item.
3218
  *
3219
  * @return int The item ID
3220
  *
3221
- * @since 2.0.0
3222
- * @link https://pods.io/docs/save/
3223
  */
3224
- public function save( $data = null, $value = null, $id = null, $params = null ) {
3225
-
3226
- if ( null !== $data && ! is_array( $data ) ) {
3227
  $data = array( $data => $value );
3228
- }
3229
 
3230
  $fetch = false;
3231
 
3232
- // @codingStandardsIgnoreLine
3233
  if ( null === $id || ( $this->row && $id == $this->id() ) ) {
3234
  $fetch = true;
3235
 
@@ -3240,42 +2854,40 @@ class Pods implements Iterator {
3240
 
3241
  $data = (array) $this->do_hook( 'save', $data, $id );
3242
 
3243
- if ( empty( $data ) && empty( $params['is_new_item'] ) ) {
3244
  return $id;
3245
- }
3246
 
3247
  $default = array();
3248
 
3249
- if ( ! empty( $params ) && is_array( $params ) ) {
3250
  $default = $params;
3251
- }
3252
 
3253
  $params = array(
3254
- 'pod' => $this->pod,
3255
- 'id' => $id,
3256
- 'data' => $data,
3257
  'allow_custom_fields' => true,
3258
- 'clear_slug_cache' => false,
3259
  );
3260
 
3261
- if ( ! empty( $default ) ) {
3262
  $params = array_merge( $params, $default );
3263
- }
3264
 
3265
  $id = $this->api->save_pod_item( $params );
3266
 
3267
  if ( 0 < $id && $fetch ) {
3268
- // Clear local var cache of field values.
3269
  $this->data->row = array();
3270
 
3271
  $this->fetch( $id, false );
3272
  }
3273
 
3274
- if ( ! empty( $this->pod_data['field_slug'] ) ) {
3275
  if ( 0 < $id && $fetch ) {
3276
- $slug = $this->field( $this->pod_data['field_slug'] );
3277
- } else {
3278
- $slug = pods( $this->pod, $id )->field( $this->pod_data['field_slug'] );
 
3279
  }
3280
 
3281
  if ( 0 < strlen( $slug ) ) {
@@ -3289,30 +2901,27 @@ class Pods implements Iterator {
3289
  /**
3290
  * Delete an item
3291
  *
3292
- * @see PodsAPI::delete_pod_item
3293
  *
3294
- * @param int $id ID of the Pod item to delete.
3295
  *
3296
  * @return bool Whether the item was successfully deleted
3297
  *
3298
- * @since 2.0.0
3299
- * @link https://pods.io/docs/delete/
3300
  */
3301
- public function delete( $id = null ) {
3302
-
3303
- if ( null === $id ) {
3304
  $id = $this->id();
3305
- }
3306
 
3307
  $id = (int) $this->do_hook( 'delete', $id );
3308
 
3309
- if ( empty( $id ) ) {
3310
  return false;
3311
- }
3312
 
3313
  $params = array(
3314
  'pod' => $this->pod,
3315
- 'id' => $id,
3316
  );
3317
 
3318
  return $this->api->delete_pod_item( $params );
@@ -3321,21 +2930,20 @@ class Pods implements Iterator {
3321
  /**
3322
  * Reset Pod
3323
  *
3324
- * @see PodsAPI::reset_pod
3325
  *
3326
  * @return bool Whether the Pod was successfully reset
3327
  *
3328
  * @since 2.1.1
3329
  */
3330
- public function reset_pod() {
3331
-
3332
  $params = array( 'id' => $this->pod_id );
3333
 
3334
- $this->data->id = null;
3335
- $this->data->row = array();
3336
  $this->data->data = array();
3337
 
3338
- $this->data->total = 0;
3339
  $this->data->total_found = 0;
3340
 
3341
  return $this->api->reset_pod( $params );
@@ -3344,30 +2952,27 @@ class Pods implements Iterator {
3344
  /**
3345
  * Duplicate an item
3346
  *
3347
- * @see PodsAPI::duplicate_pod_item
3348
  *
3349
- * @param int $id ID of the pod item to duplicate.
3350
  *
3351
  * @return int|bool ID of the new pod item
3352
  *
3353
- * @since 2.0.0
3354
- * @link https://pods.io/docs/duplicate/
3355
  */
3356
- public function duplicate( $id = null ) {
3357
-
3358
- if ( null === $id ) {
3359
  $id = $this->id();
3360
- }
3361
 
3362
  $id = (int) $this->do_hook( 'duplicate', $id );
3363
 
3364
- if ( empty( $id ) ) {
3365
  return false;
3366
- }
3367
 
3368
  $params = array(
3369
  'pod' => $this->pod,
3370
- 'id' => $id,
3371
  );
3372
 
3373
  return $this->api->duplicate_pod_item( $params );
@@ -3376,71 +2981,64 @@ class Pods implements Iterator {
3376
  /**
3377
  * Import data / Save multiple rows of data at once
3378
  *
3379
- * @see PodsAPI::import
3380
  *
3381
- * @param mixed $import_data PHP associative array or CSV input.
3382
- * @param bool $numeric_mode Use IDs instead of the name field when matching.
3383
- * @param string $format Format of import data, options are php or csv.
3384
  *
3385
  * @return array IDs of imported items
3386
  *
3387
- * @since 2.3.0
3388
  */
3389
- public function import( $import_data, $numeric_mode = false, $format = null ) {
3390
-
3391
  return $this->api->import( $import_data, $numeric_mode, $format );
3392
  }
3393
 
3394
  /**
3395
  * Export an item's data
3396
  *
3397
- * @see PodsAPI::export_pod_item
3398
  *
3399
- * @param array $fields (optional) Fields to export.
3400
- * @param int $id (optional) ID of the pod item to export.
3401
- * @param null|string $format (optional) The format of the export (php | json).
3402
  *
3403
  * @return array|bool Data array of the exported pod item
3404
  *
3405
- * @since 2.0.0
3406
- * @link https://pods.io/docs/export/
3407
  */
3408
- public function export( $fields = null, $id = null, $format = null ) {
3409
-
3410
  $params = array(
3411
- 'pod' => $this->pod,
3412
- 'id' => $id,
3413
- 'fields' => null,
3414
- 'depth' => 2,
3415
- 'flatten' => false,
3416
- 'context' => null,
3417
- 'format' => $format,
3418
  );
3419
 
3420
- if ( is_array( $fields ) && ( isset( $fields['fields'] ) || isset( $fields['depth'] ) ) ) {
3421
  $params = array_merge( $params, $fields );
3422
- } else {
3423
- $params['fields'] = $fields;
3424
- }
3425
 
3426
- if ( isset( $params['fields'] ) && is_array( $params['fields'] ) && ! in_array( $this->pod_data['field_id'], $params['fields'], true ) ) {
3427
- $params['fields'] = array_merge( array( $this->pod_data['field_id'] ), $params['fields'] );
3428
- }
3429
 
3430
- if ( null === $params['id'] ) {
3431
- $params['id'] = $this->id();
3432
- }
3433
 
3434
  $params = (array) $this->do_hook( 'export', $params );
3435
 
3436
- if ( empty( $params['id'] ) ) {
3437
  return false;
3438
- }
3439
 
3440
  $data = $this->api->export_pod_item( $params );
3441
 
3442
- if ( ! empty( $params['format'] ) && 'json' === $params['format'] ) {
3443
- $data = wp_json_encode( (array) $data );
 
 
3444
  }
3445
 
3446
  return $data;
@@ -3449,27 +3047,25 @@ class Pods implements Iterator {
3449
  /**
3450
  * Export data from all items
3451
  *
3452
- * @see PodsAPI::export
3453
  *
3454
- * @param array $params An associative array of parameters.
3455
  *
3456
  * @return array Data arrays of all exported pod items
3457
  *
3458
- * @since 2.3.0
3459
  */
3460
- public function export_data( $params = null ) {
3461
-
3462
  $defaults = array(
3463
  'fields' => null,
3464
- 'depth' => 2,
3465
- 'params' => null,
3466
  );
3467
 
3468
- if ( empty( $params ) ) {
3469
  $params = $defaults;
3470
- } else {
3471
  $params = array_merge( $defaults, (array) $params );
3472
- }
3473
 
3474
  return $this->api->export( $this, $params );
3475
  }
@@ -3479,21 +3075,22 @@ class Pods implements Iterator {
3479
  * are simple, paginate and advanced. The base and format parameters
3480
  * are used only for the paginate view.
3481
  *
3482
- * @param array|object $params Associative array of parameters.
3483
  *
3484
  * @return string Pagination HTML
3485
- * @since 2.0.0
3486
- * @link https://pods.io/docs/pagination/
3487
  */
3488
  public function pagination( $params = null ) {
3489
 
3490
  if ( empty( $params ) ) {
3491
  $params = array();
3492
- } elseif ( ! is_array( $params ) ) {
 
3493
  $params = array( 'label' => $params );
3494
  }
3495
 
3496
- $this->page_var = pods_v( 'page_var', $params, $this->page_var );
3497
 
3498
  $url = pods_query_arg( null, null, $this->page_var );
3499
 
@@ -3504,43 +3101,39 @@ class Pods implements Iterator {
3504
  }
3505
 
3506
  $defaults = array(
3507
- 'type' => 'advanced',
3508
- 'label' => __( 'Go to page:', 'pods' ),
3509
- 'show_label' => true,
3510
- 'first_text' => __( '&laquo; First', 'pods' ),
3511
- 'prev_text' => __( '&lsaquo; Previous', 'pods' ),
3512
- 'next_text' => __( 'Next &rsaquo;', 'pods' ),
3513
- 'last_text' => __( 'Last &raquo;', 'pods' ),
3514
- 'prev_next' => true,
3515
- 'first_last' => true,
3516
- 'limit' => (int) $this->limit,
3517
- 'offset' => (int) $this->offset,
3518
- 'page' => max( 1, (int) $this->page ),
3519
- 'mid_size' => 2,
3520
- 'end_size' => 1,
3521
  'total_found' => $this->total_found(),
3522
- 'page_var' => $this->page_var,
3523
- 'base' => "{$url}{$append}%_%",
3524
- 'format' => "{$this->page_var}=%#%",
3525
- 'class' => '',
3526
- 'link_class' => '',
3527
  );
3528
 
3529
- if ( is_object( $params ) ) {
3530
- $params = get_object_vars( $params );
3531
- }
3532
-
3533
- $params = (object) array_merge( $defaults, (array) $params );
3534
 
3535
  $params->total = $this->total_pages( $params->limit, $params->offset, $params->total_found );
3536
 
3537
- if ( $params->limit < 1 || $params->total_found < 1 || 1 === $params->total || $params->total_found <= $params->offset ) {
3538
  return $this->do_hook( 'pagination', $this->do_hook( 'pagination_' . $params->type, '', $params ), $params );
3539
  }
3540
 
3541
  $pagination = $params->type;
3542
 
3543
- if ( ! in_array( $params->type, array( 'simple', 'advanced', 'paginate', 'list' ), true ) ) {
3544
  $pagination = 'advanced';
3545
  }
3546
 
@@ -3557,52 +3150,42 @@ class Pods implements Iterator {
3557
  /**
3558
  * Return a filter form for searching a Pod
3559
  *
3560
- * @param array|string $params Comma-separated list of fields or array of parameters.
3561
  *
3562
  * @return string Filters HTML
3563
  *
3564
- * @since 2.0.0
3565
- * @link https://pods.io/docs/filters/
3566
  */
3567
- public function filters( $params = null ) {
3568
-
3569
  $defaults = array(
3570
  'fields' => $params,
3571
- 'label' => '',
3572
  'action' => '',
3573
- 'search' => '',
3574
  );
3575
 
3576
- if ( is_array( $params ) ) {
3577
  $params = array_merge( $defaults, $params );
3578
- } else {
3579
  $params = $defaults;
3580
- }
3581
 
3582
  $pod =& $this;
3583
 
3584
- /**
3585
- * Filter the Pods::filters() parameters.
3586
- *
3587
- * @param array $params Parameters to filter with.
3588
- * @param Pods $pod Pods object.
3589
- */
3590
  $params = apply_filters( 'pods_filters_params', $params, $pod );
3591
 
3592
- $fields = $params['fields'];
3593
 
3594
- if ( null !== $fields && ! is_array( $fields ) && 0 < strlen( $fields ) ) {
3595
  $fields = explode( ',', $fields );
3596
- }
3597
 
3598
- $object_fields = (array) pods_v( 'object_fields', $this->pod_data, array(), true );
3599
 
3600
- // Force array.
3601
- if ( empty( $fields ) ) {
3602
  $fields = array();
3603
- } else {
3604
- // Temporary.
3605
- $filter_fields = $fields;
3606
 
3607
  $fields = array();
3608
 
@@ -3610,54 +3193,46 @@ class Pods implements Iterator {
3610
  $name = $k;
3611
 
3612
  $defaults = array(
3613
- 'name' => $name,
3614
  );
3615
 
3616
- if ( ! is_array( $field ) ) {
3617
  $name = $field;
3618
 
3619
  $field = array(
3620
- 'name' => $name,
3621
  );
3622
  }
3623
 
3624
- // @codingStandardsIgnoreLine.
3625
  $field = array_merge( $defaults, $field );
3626
 
3627
- $field['name'] = trim( $field['name'] );
3628
 
3629
- if ( pods_v( 'hidden', $field, false, true ) ) {
3630
- $field['type'] = 'hidden';
3631
- }
3632
 
3633
- if ( isset( $object_fields[ $field['name'] ] ) ) {
3634
- // @codingStandardsIgnoreLine.
3635
- $fields[ $field['name'] ] = array_merge( $object_fields[ $field['name'] ], $field );
3636
- } elseif ( isset( $this->fields[ $field['name'] ] ) ) {
3637
- // @codingStandardsIgnoreLine.
3638
- $fields[ $field['name'] ] = array_merge( $this->fields[ $field['name'] ], $field );
3639
- }
3640
- }//end foreach
3641
 
3642
- // Cleanup.
3643
- unset( $filter_fields );
3644
- }//end if
3645
 
3646
  $this->filters = array_keys( $fields );
3647
 
3648
- $label = $params['label'];
3649
 
3650
- if ( '' === $label ) {
3651
  $label = __( 'Search', 'pods' );
3652
- }
3653
 
3654
- $action = $params['action'];
3655
 
3656
- $search = trim( $params['search'] );
3657
 
3658
- if ( '' === $search ) {
3659
- $search = pods_v_sanitized( $pod->search_var, 'get', '' );
3660
- }
3661
 
3662
  ob_start();
3663
 
@@ -3670,9 +3245,9 @@ class Pods implements Iterator {
3670
  *
3671
  * @since unknown
3672
  *
3673
- * @param string $output Filter output.
3674
- * @param array $params Params array passed to filters().
3675
- * @param object|Pods $this Current Pods object.
3676
  */
3677
  return apply_filters( 'pods_pods_filters', $output, $params, $this );
3678
  }
@@ -3680,91 +3255,35 @@ class Pods implements Iterator {
3680
  /**
3681
  * Run a helper within a Pod Page or WP Template
3682
  *
3683
- * @see Pods_Helpers::helper
3684
  *
3685
- * @param string|array $helper Helper name.
3686
- * @param string $value Value to run the helper on.
3687
- * @param string $name Field name.
3688
  *
3689
  * @return mixed Anything returned by the helper
3690
- * @since 2.0.0
3691
  */
3692
- public function helper( $helper, $value = null, $name = null ) {
3693
-
3694
  $params = array(
3695
- 'helper' => $helper,
3696
- 'value' => $value,
3697
- 'name' => $name,
3698
- 'deprecated' => false,
3699
  );
3700
 
3701
- if ( class_exists( 'Pods_Templates' ) ) {
3702
- $params['deprecated'] = Pods_Templates::$deprecated;
3703
- }
3704
 
3705
- if ( is_array( $helper ) ) {
3706
  $params = array_merge( $params, $helper );
3707
- }
3708
 
3709
- if ( class_exists( 'Pods_Helpers' ) ) {
3710
  $value = Pods_Helpers::helper( $params, $this );
3711
- } elseif ( is_callable( $params['helper'] ) ) {
3712
- $disallowed = array(
3713
- 'system',
3714
- 'exec',
3715
- 'popen',
3716
- 'eval',
3717
- 'preg_replace',
3718
- 'create_function',
3719
- 'include',
3720
- 'include_once',
3721
- 'require',
3722
- 'require_once',
3723
- );
3724
-
3725
- $allowed = array();
3726
-
3727
- /**
3728
- * Allows adjusting the disallowed callbacks as needed.
3729
- *
3730
- * @param array $disallowed List of callbacks not allowed.
3731
- * @param array $params Parameters used by Pods::helper() method.
3732
- *
3733
- * @since 2.7.0
3734
- */
3735
- $disallowed = apply_filters( 'pods_helper_disallowed_callbacks', $disallowed, $params );
3736
-
3737
- /**
3738
- * Allows adjusting the allowed allowed callbacks as needed.
3739
- *
3740
- * @param array $allowed List of callbacks explicitly allowed.
3741
- * @param array $params Parameters used by Pods::helper() method.
3742
- *
3743
- * @since 2.7.0
3744
- */
3745
- $allowed = apply_filters( 'pods_helper_allowed_callbacks', $allowed, $params );
3746
-
3747
- // Clean up helper callback (if string).
3748
- if ( is_string( $params['helper'] ) ) {
3749
- $params['helper'] = strip_tags( str_replace( array( '`', chr( 96 ) ), "'", $params['helper'] ) );
3750
- }
3751
-
3752
- $is_allowed = false;
3753
-
3754
- if ( ! empty( $allowed ) ) {
3755
- if ( in_array( $params['helper'], $allowed, true ) ) {
3756
- $is_allowed = true;
3757
- }
3758
- } elseif ( ! in_array( $params['helper'], $disallowed, true ) ) {
3759
- $is_allowed = true;
3760
- }
3761
-
3762
- if ( $is_allowed ) {
3763
- $value = call_user_func( $params['helper'], $value );
3764
- }
3765
- } else {
3766
- $value = apply_filters( $params['helper'], $value );
3767
- }//end if
3768
 
3769
  return $value;
3770
  }
@@ -3772,130 +3291,73 @@ class Pods implements Iterator {
3772
  /**
3773
  * Display the page template
3774
  *
3775
- * @see Pods_Templates::template
3776
  *
3777
- * @param string $template_name The template name.
3778
- * @param string|null $code Custom template code to use instead.
3779
- * @param bool $deprecated Whether to use deprecated functionality based on old function usage.
3780
  *
3781
  * @return mixed Template output
3782
  *
3783
- * @since 2.0.0
3784
- * @link https://pods.io/docs/template/
3785
  */
3786
- public function template( $template_name, $code = null, $deprecated = false ) {
3787
-
3788
  $out = null;
3789
 
3790
  $obj =& $this;
3791
 
3792
- if ( ! empty( $code ) ) {
3793
- // backwards compatibility.
3794
- $code = str_replace( '$this->', '$obj->', $code );
3795
 
3796
- /**
3797
- * Filter the template code before running it.
3798
- *
3799
- * @param string $code Template code.
3800
- * @param string $template_name Template name.
3801
- * @param Pods $pod Pods object.
3802
- */
3803
  $code = apply_filters( 'pods_templates_pre_template', $code, $template_name, $this );
3804
-
3805
- /**
3806
- * Filter the template code before running it.
3807
- *
3808
- * @param string $code Template code.
3809
- * @param string $template_name Template name.
3810
- * @param Pods $pod Pods object.
3811
- */
3812
  $code = apply_filters( "pods_templates_pre_template_{$template_name}", $code, $template_name, $this );
3813
 
3814
  ob_start();
3815
 
3816
- if ( ! empty( $code ) ) {
3817
- // Only detail templates need $this->id.
3818
  if ( empty( $this->id ) ) {
3819
  while ( $this->fetch() ) {
3820
- // @codingStandardsIgnoreLine
3821
  echo $this->do_magic_tags( $code );
3822
  }
3823
- } else {
3824
- // @codingStandardsIgnoreLine
3825
- echo $this->do_magic_tags( $code );
3826
  }
 
 
3827
  }
3828
 
3829
  $out = ob_get_clean();
3830
 
3831
- /**
3832
- * Filter the template output.
3833
- *
3834
- * @param string $out Template output.
3835
- * @param string $code Template code.
3836
- * @param string $template_name Template name.
3837
- * @param Pods $pod Pods object.
3838
- */
3839
  $out = apply_filters( 'pods_templates_post_template', $out, $code, $template_name, $this );
3840
-
3841
- /**
3842
- * Filter the template output.
3843
- *
3844
- * @param string $out Template output.
3845
- * @param string $code Template code.
3846
- * @param string $template_name Template name.
3847
- * @param Pods $pod Pods object.
3848
- */
3849
  $out = apply_filters( "pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this );
3850
- } elseif ( class_exists( 'Pods_Templates' ) ) {
 
3851
  $out = Pods_Templates::template( $template_name, $code, $this, $deprecated );
3852
- } elseif ( trim( preg_replace( '/[^a-zA-Z0-9_\-\/]/', '', $template_name ), ' /-' ) === $template_name ) {
3853
  ob_start();
3854
 
3855
  $default_templates = array(
3856
  'pods/' . $template_name,
3857
  'pods-' . $template_name,
3858
- $template_name,
3859
  );
3860
 
3861
- /**
3862
- * Filter the default Pods Template files.
3863
- *
3864
- * @param array $default_templates Default Pods Template files.
3865
- */
3866
  $default_templates = apply_filters( 'pods_template_default_templates', $default_templates );
3867
 
3868
- // Only detail templates need $this->id.
3869
  if ( empty( $this->id ) ) {
3870
  while ( $this->fetch() ) {
3871
  pods_template_part( $default_templates, compact( array_keys( get_defined_vars() ) ) );
3872
  }
3873
- } else {
3874
- pods_template_part( $default_templates, compact( array_keys( get_defined_vars() ) ) );
3875
  }
 
 
3876
 
3877
  $out = ob_get_clean();
3878
 
3879
- /**
3880
- * Filter the template output.
3881
- *
3882
- * @param string $out Template output.
3883
- * @param string $code Template code.
3884
- * @param string $template_name Template name.
3885
- * @param Pods $pod Pods object.
3886
- */
3887
  $out = apply_filters( 'pods_templates_post_template', $out, $code, $template_name, $this );
3888
-
3889
- /**
3890
- * Filter the template output.
3891
- *
3892
- * @param string $out Template output.
3893
- * @param string $code Template code.
3894
- * @param string $template_name Template name.
3895
- * @param Pods $pod Pods object.
3896
- */
3897
  $out = apply_filters( "pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this );
3898
- }//end if
3899
 
3900
  return $out;
3901
  }
@@ -3905,48 +3367,44 @@ class Pods implements Iterator {
3905
  * and override options where needed. For WP object based Pods, you can pass through the WP object
3906
  * field names too, such as "post_title" or "post_content" for example.
3907
  *
3908
- * @param array $params (optional) Fields to show on the form, defaults to all fields.
3909
- * @param string $label (optional) Save button label, defaults to "Save Changes".
3910
- * @param string $thank_you (optional) Thank you URL to send to upon success.
3911
  *
3912
  * @return bool|mixed
3913
- * @since 2.0.0
3914
- * @link https://pods.io/docs/form/
3915
  */
3916
- public function form( $params = null, $label = null, $thank_you = null ) {
3917
-
3918
  $defaults = array(
3919
- 'fields' => $params,
3920
- 'label' => $label,
3921
- 'thank_you' => $thank_you,
3922
- 'fields_only' => false,
3923
  );
3924
 
3925
- if ( is_array( $params ) ) {
3926
  $params = array_merge( $defaults, $params );
3927
- } else {
3928
  $params = $defaults;
3929
- }
3930
 
3931
  $pod =& $this;
3932
 
3933
  $params = $this->do_hook( 'form_params', $params );
3934
 
3935
- $fields = $params['fields'];
3936
 
3937
- if ( null !== $fields && ! is_array( $fields ) && 0 < strlen( $fields ) ) {
3938
  $fields = explode( ',', $fields );
3939
- }
3940
 
3941
- $object_fields = (array) pods_v( 'object_fields', $this->pod_data, array(), true );
3942
 
3943
  if ( empty( $fields ) ) {
3944
- // Add core object fields if $fields is empty.
3945
  $fields = array_merge( $object_fields, $this->fields );
3946
  }
3947
 
3948
- // Temporary.
3949
- $form_fields = $fields;
3950
 
3951
  $fields = array();
3952
 
@@ -3954,111 +3412,100 @@ class Pods implements Iterator {
3954
  $name = $k;
3955
 
3956
  $defaults = array(
3957
- 'name' => $name,
3958
  );
3959
 
3960
- if ( ! is_array( $field ) ) {
3961
  $name = $field;
3962
 
3963
  $field = array(
3964
- 'name' => $name,
3965
  );
3966
  }
3967
 
3968
- // @codingStandardsIgnoreLine.
3969
  $field = array_merge( $defaults, $field );
3970
 
3971
- $field['name'] = trim( $field['name'] );
3972
 
3973
- $default_value = pods_v( 'default', $field );
3974
- $value = pods_v( 'value', $field );
3975
 
3976
- if ( empty( $field['name'] ) ) {
3977
- $field['name'] = trim( $name );
3978
- }
3979
 
3980
- if ( isset( $object_fields[ $field['name'] ] ) ) {
3981
- // @codingStandardsIgnoreLine.
3982
- $field = array_merge( $object_fields[ $field['name'] ], $field );
3983
- } elseif ( isset( $this->fields[ $field['name'] ] ) ) {
3984
- // @codingStandardsIgnoreLine.
3985
- $field = array_merge( $this->fields[ $field['name'] ], $field );
3986
  }
3987
-
3988
- if ( pods_v( 'hidden', $field, false, true ) ) {
3989
- $field['type'] = 'hidden';
3990
  }
3991
 
3992
- $fields[ $field['name'] ] = $field;
 
 
 
3993
 
3994
  if ( empty( $this->id ) && null !== $default_value ) {
3995
- $this->row_override[ $field['name'] ] = $default_value;
3996
- } elseif ( ! empty( $this->id ) && null !== $value ) {
3997
- $this->row[ $field['name'] ] = $value;
3998
  }
3999
- }//end foreach
 
 
 
4000
 
4001
- // Cleanup.
4002
- unset( $form_fields );
4003
 
4004
  $fields = $this->do_hook( 'form_fields', $fields, $params );
4005
 
4006
- $label = $params['label'];
4007
 
4008
- if ( empty( $label ) ) {
4009
  $label = __( 'Save Changes', 'pods' );
4010
- }
4011
 
4012
- $thank_you = $params['thank_you'];
4013
- $fields_only = $params['fields_only'];
4014
 
4015
- PodsForm::$form_counter ++;
4016
 
4017
  ob_start();
4018
 
4019
  if ( empty( $thank_you ) ) {
4020
  $success = 'success';
4021
 
4022
- if ( 1 < PodsForm::$form_counter ) {
4023
  $success .= PodsForm::$form_counter;
4024
- }
4025
 
4026
- $thank_you = pods_query_arg( array(
4027
- 'success*' => null,
4028
- $success => 1,
4029
- ) );
4030
 
4031
- if ( 1 === (int) pods_v( $success, 'get', 0 ) ) {
4032
  $message = __( 'Form submitted successfully', 'pods' );
4033
-
4034
  /**
4035
- * Change the text of the message that appears on successful form submission.
 
 
4036
  *
4037
- * @param string $message Success message.
4038
  *
4039
- * @since 2.7.0
4040
  */
4041
  $message = apply_filters( 'pods_pod_form_success_message', $message );
4042
 
4043
- echo '<div id="message" class="pods-form-front-success">' . wp_kses_post( $message ) . '</div>';
4044
  }
4045
- }//end if
4046
 
4047
  pods_view( PODS_DIR . 'ui/front/form.php', compact( array_keys( get_defined_vars() ) ) );
4048
 
4049
  $output = ob_get_clean();
4050
 
4051
- if ( empty( $this->id ) ) {
4052
  $this->row_override = array();
4053
- }
4054
 
4055
  return $this->do_hook( 'form', $output, $fields, $label, $thank_you, $this, $this->id() );
4056
  }
4057
 
4058
  /**
4059
- * Render a singular view for the Pod item content.
4060
- *
4061
- * @param array|string|null $fields (optional) Fields to show in the view, defaults to all fields.
4062
  *
4063
  * @return mixed
4064
  * @since 2.3.10
@@ -4067,64 +3514,60 @@ class Pods implements Iterator {
4067
 
4068
  $pod =& $this;
4069
 
4070
- // Convert comma separated list of fields to an array.
4071
- if ( null !== $fields && ! is_array( $fields ) && 0 < strlen( $fields ) ) {
4072
  $fields = explode( ',', $fields );
4073
  }
4074
 
4075
  $object_fields = (array) pods_v( 'object_fields', $this->pod_data, array(), true );
4076
 
4077
  if ( empty( $fields ) ) {
4078
- // Add core object fields if $fields is empty.
4079
  $fields = array_merge( $object_fields, $this->fields );
4080
  }
4081
 
4082
- // Temporary.
4083
- $view_fields = $fields;
4084
 
4085
  $fields = array();
4086
 
4087
  foreach ( $view_fields as $name => $field ) {
 
4088
  $defaults = array(
4089
- 'name' => $name,
4090
  );
4091
 
4092
- if ( ! is_array( $field ) ) {
4093
  $name = $field;
4094
 
4095
  $field = array(
4096
- 'name' => $name,
4097
  );
4098
  }
4099
 
4100
- // @codingStandardsIgnoreLine.
4101
  $field = array_merge( $defaults, $field );
4102
 
4103
- $field['name'] = trim( $field['name'] );
4104
 
4105
- if ( empty( $field['name'] ) ) {
4106
- $field['name'] = trim( $name );
4107
  }
4108
 
4109
- if ( isset( $object_fields[ $field['name'] ] ) ) {
4110
- // @codingStandardsIgnoreLine.
4111
- $field = array_merge( $field, $object_fields[ $field['name'] ] );
4112
- } elseif ( isset( $this->fields[ $field['name'] ] ) ) {
4113
- // @codingStandardsIgnoreLine.
4114
- $field = array_merge( $this->fields[ $field['name'] ], $field );
4115
- }
4116
 
4117
- if ( pods_v( 'hidden', $field, false, true ) || 'hidden' === $field['type'] ) {
4118
  continue;
4119
- } elseif ( ! PodsForm::permission( $field['type'], $field['name'], $field['options'], $fields, $pod, $pod->id() ) ) {
 
4120
  continue;
4121
  }
4122
 
4123
- $fields[ $field['name'] ] = $field;
4124
- }//end foreach
4125
 
4126
- // Cleanup.
4127
- unset( $view_fields );
4128
 
4129
  $output = pods_view( PODS_DIR . 'ui/front/view.php', compact( array_keys( get_defined_vars() ) ), false, 'cache', true );
4130
 
@@ -4135,115 +3578,73 @@ class Pods implements Iterator {
4135
  /**
4136
  * Replace magic tags with their values
4137
  *
4138
- * @param string $code The content to evaluate.
 
4139
  *
4140
  * @return string Code with Magic Tags evaluated
4141
  *
4142
- * @since 2.0.0
4143
  */
4144
- public function do_magic_tags( $code ) {
4145
-
4146
- /**
4147
- * Filters the Pods magic tags content before the default function.
4148
- * Allows complete replacement of the Pods magic tag engine.
4149
- *
4150
- * @param null $pre Default is null which processes magic tags normally. Return any other value to override.
4151
- * @param string $code The content to evaluate.
4152
- * @param Pods $pods The Pods Object.
4153
- *
4154
- * @since 2.7.0
4155
- */
4156
- $pre = apply_filters( 'pods_pre_do_magic_tags', null, $code, $this );
4157
- if ( null !== $pre ) {
4158
- return $pre;
4159
- }
4160
-
4161
  return preg_replace_callback( '/({@(.*?)})/m', array( $this, 'process_magic_tags' ), $code );
4162
  }
4163
 
4164
  /**
4165
  * Replace magic tags with their values
4166
  *
4167
- * @param string|array $tag The magic tag to process.
 
4168
  *
4169
  * @return string Code with Magic Tags evaluated
4170
  *
4171
  * @since 2.0.2
4172
  */
4173
- private function process_magic_tags( $tag ) {
4174
 
4175
  if ( is_array( $tag ) ) {
4176
- if ( ! isset( $tag[2] ) && '' === trim( $tag[2] ) ) {
4177
  return '';
4178
- }
4179
 
4180
- $tag = $tag[2];
4181
  }
4182
 
4183
  $tag = trim( $tag, ' {@}' );
4184
  $tag = explode( ',', $tag );
4185
 
4186
- if ( empty( $tag ) || ! isset( $tag[0] ) || '' === trim( $tag[0] ) ) {
4187
  return '';
4188
- }
4189
 
4190
- $tag = pods_trim( $tag );
 
 
4191
 
4192
- $field_name = $tag[0];
4193
 
4194
- $helper_name = '';
4195
- $before = '';
4196
- $after = '';
4197
 
4198
- if ( ! empty( $tag[1] ) ) {
4199
  $value = $this->field( $field_name );
4200
 
4201
- $helper_name = $tag[1];
4202
 
4203
  $value = $this->helper( $helper_name, $value, $field_name );
4204
- } else {
4205
- $value = $this->display( $field_name );
4206
- }
4207
-
4208
- // Process special magic tags but allow "empty" values for numbers.
4209
- if (
4210
- ! $value
4211
- && ! is_numeric( $value )
4212
- && pods_shortcode_allow_evaluate_tags()
4213
- && ! $this->fields( $field_name )
4214
- ) {
4215
- // Do not pass before and after tags (key 2 and 3) or these get processed twice.
4216
- $value = pods_evaluate_tag( implode( ',', array_slice( $tag, 0, 2 ) ) );
4217
  }
 
 
4218
 
4219
- if ( ! empty( $tag[2] ) ) {
4220
- $before = $tag[2];
4221
- }
4222
 
4223
- if ( ! empty( $tag[3] ) ) {
4224
- $after = $tag[3];
4225
- }
4226
 
4227
- /**
4228
- * Filter the magic tag output for a value.
4229
- *
4230
- * @param string $value Magic tag output for value.
4231
- * @param string $field_name Magic tag field name.
4232
- * @param string $before Before content.
4233
- * @param string $after After content.
4234
- */
4235
  $value = apply_filters( 'pods_do_magic_tags', $value, $field_name, $helper_name, $before, $after );
4236
 
4237
- if ( is_array( $value ) ) {
4238
- $value = pods_serial_comma( $value, array(
4239
- 'field' => $field_name,
4240
- 'fields' => $this->fields,
4241
- ) );
4242
- }
4243
 
4244
- if ( null !== $value && false !== $value ) {
4245
  return $before . $value . $after;
4246
- }
4247
 
4248
  return '';
4249
  }
@@ -4252,46 +3653,41 @@ class Pods implements Iterator {
4252
  *
4253
  * Generate UI for Data Management
4254
  *
4255
- * @param mixed $options Array or String containing Pod or Options to be used.
4256
- * @param bool $amend Whether to amend the default UI options or replace entirely.
4257
  *
4258
- * @return PodsUI|null UI object or null if custom UI used
4259
  *
4260
  * @since 2.3.10
4261
  */
4262
- public function ui( $options = null, $amend = false ) {
4263
-
4264
  $num = '';
4265
 
4266
- if ( empty( $options ) ) {
4267
  $options = array();
4268
- } else {
4269
- $num = pods_v_sanitized( 'num', $options, '' );
4270
 
4271
  if ( empty( $num ) ) {
4272
  $num = '';
4273
  }
4274
  }
4275
 
4276
- $check_id = pods_v( 'id' . $num, 'get', null, true );
4277
-
4278
- // @codingStandardsIgnoreLine
4279
- if ( $this->id() != $check_id ) {
4280
- $this->fetch( $check_id );
4281
- }
4282
 
4283
- if ( ! empty( $options ) && ! $amend ) {
4284
  $this->ui = $options;
4285
 
4286
  return pods_ui( $this );
4287
- } elseif ( ! empty( $options ) || 'custom' !== pods_v( 'ui_style', $this->pod_data['options'], 'post_type', true ) ) {
4288
- $actions_enabled = pods_v( 'ui_actions_enabled', $this->pod_data['options'] );
 
4289
 
4290
- if ( ! empty( $actions_enabled ) ) {
4291
  $actions_enabled = (array) $actions_enabled;
4292
- } else {
4293
  $actions_enabled = array();
4294
- }
4295
 
4296
  $available_actions = array(
4297
  'add',
@@ -4299,197 +3695,178 @@ class Pods implements Iterator {
4299
  'duplicate',
4300
  'delete',
4301
  'reorder',
4302
- 'export',
4303
  );
4304
 
4305
- if ( ! empty( $actions_enabled ) ) {
4306
  $actions_disabled = array(
4307
- 'view' => 'view',
4308
  );
4309
 
4310
  foreach ( $available_actions as $action ) {
4311
- if ( ! in_array( $action, $actions_enabled, true ) ) {
4312
  $actions_disabled[ $action ] = $action;
4313
- }
4314
  }
4315
- } else {
 
4316
  $actions_disabled = array(
4317
  'duplicate' => 'duplicate',
4318
- 'view' => 'view',
4319
- 'export' => 'export',
4320
  );
4321
 
4322
- if ( 1 === pods_v( 'ui_export', $this->pod_data['options'], 0 ) ) {
4323
- unset( $actions_disabled['export'] );
4324
- }
4325
- }//end if
4326
 
4327
  if ( empty( $options ) ) {
4328
  $author_restrict = false;
4329
 
4330
- if ( isset( $this->fields['author'] ) && 'pick' === $this->fields['author']['type'] && 'user' === $this->fields['author']['pick_object'] ) {
4331
  $author_restrict = 'author.ID';
4332
- }
4333
 
4334
- if ( ! pods_is_admin( array( 'pods', 'pods_content' ) ) ) {
4335
- if ( ! current_user_can( 'pods_add_' . $this->pod ) ) {
4336
- $actions_disabled['add'] = 'add';
4337
 
4338
- if ( 'add' === pods_v( 'action' . $num ) ) {
4339
  $_GET[ 'action' . $num ] = 'manage';
4340
- }
4341
  }
4342
 
4343
- if ( ! $author_restrict && ! current_user_can( 'pods_edit_' . $this->pod ) && ! current_user_can( 'pods_edit_others_' . $this->pod ) ) {
4344
- $actions_disabled['edit'] = 'edit';
4345
- }
4346
 
4347
- if ( ! $author_restrict && ! current_user_can( 'pods_delete_' . $this->pod ) && ! current_user_can( 'pods_delete_others_' . $this->pod ) ) {
4348
- $actions_disabled['delete'] = 'delete';
4349
- }
4350
 
4351
- if ( ! current_user_can( 'pods_reorder_' . $this->pod ) ) {
4352
- $actions_disabled['reorder'] = 'reorder';
4353
- }
4354
 
4355
- if ( ! current_user_can( 'pods_export_' . $this->pod ) ) {
4356
- $actions_disabled['export'] = 'export';
4357
- }
4358
- }//end if
4359
- }//end if
4360
 
4361
- $_GET[ 'action' . $num ] = pods_v_sanitized( 'action' . $num, 'get', pods_v( 'action', $options, 'manage' ), true );
4362
 
4363
- $index = $this->pod_data['field_id'];
4364
  $label = __( 'ID', 'pods' );
4365
 
4366
- if ( isset( $this->pod_data['fields'][ $this->pod_data['field_index'] ] ) ) {
4367
- $index = $this->pod_data['field_index'];
4368
- $label = $this->pod_data['fields'][ $this->pod_data['field_index'] ];
4369
  }
4370
 
4371
  $manage = array(
4372
- $index => $label,
4373
  );
4374
 
4375
- if ( isset( $this->pod_data['fields']['modified'] ) ) {
4376
- $manage['modified'] = $this->pod_data['fields']['modified']['label'];
4377
- }
4378
 
4379
- $manage_fields = (array) pods_v( 'ui_fields_manage', $this->pod_data['options'] );
4380
 
4381
- if ( ! empty( $manage_fields ) ) {
4382
  $manage_new = array();
4383
 
4384
  foreach ( $manage_fields as $manage_field ) {
4385
- if ( isset( $this->pod_data['fields'][ $manage_field ] ) ) {
4386
- $manage_new[ $manage_field ] = $this->pod_data['fields'][ $manage_field ];
4387
- } elseif ( isset( $this->pod_data['object_fields'][ $manage_field ] ) ) {
4388
- $manage_new[ $manage_field ] = $this->pod_data['object_fields'][ $manage_field ];
4389
- } elseif ( $manage_field === $this->pod_data['field_id'] ) {
4390
  $field = array(
4391
- 'name' => $manage_field,
4392
  'label' => 'ID',
4393
- 'type' => 'number',
4394
- 'width' => '8%',
4395
  );
4396
 
4397
- $manage_new[ $manage_field ] = PodsForm::field_setup( $field, null, $field['type'] );
4398
  }
4399
  }
4400
 
4401
- if ( ! empty( $manage_new ) ) {
4402
  $manage = $manage_new;
4403
- }
4404
- }//end if
4405
 
4406
- $pod_name = $this->pod;
4407
- $manage = apply_filters( "pods_admin_ui_fields_{$pod_name}", apply_filters( 'pods_admin_ui_fields', $manage, $this->pod, $this ), $this->pod, $this );
4408
 
4409
- $icon = pods_v( 'ui_icon', $this->pod_data['options'] );
4410
 
4411
- if ( ! empty( $icon ) ) {
4412
  $icon = pods_image_url( $icon, '32x32' );
4413
- }
4414
 
4415
- $filters = pods_v( 'ui_filters', $this->pod_data['options'] );
4416
 
4417
- if ( ! empty( $filters ) ) {
4418
  $filters_new = array();
4419
 
4420
  $filters = (array) $filters;
4421
 
4422
  foreach ( $filters as $filter_field ) {
4423
- if ( isset( $this->pod_data['fields'][ $filter_field ] ) ) {
4424
- $filters_new[ $filter_field ] = $this->pod_data['fields'][ $filter_field ];
4425
- } elseif ( isset( $this->pod_data['object_fields'][ $filter_field ] ) ) {
4426
- $filters_new[ $filter_field ] = $this->pod_data['object_fields'][ $filter_field ];
4427
- }
4428
  }
4429
 
4430
  $filters = $filters_new;
4431
  }
4432
 
4433
  $ui = array(
4434
- 'fields' => array(
4435
- 'manage' => $manage,
4436
- 'add' => $this->pod_data['fields'],
4437
- 'edit' => $this->pod_data['fields'],
4438
- 'duplicate' => $this->pod_data['fields'],
4439
  ),
4440
- 'icon' => $icon,
4441
- 'actions_disabled' => $actions_disabled,
4442
- 'actions_bulk' => array(),
4443
  );
4444
 
4445
- if ( ! empty( $filters ) ) {
4446
- $ui['fields']['search'] = $filters;
4447
- $ui['filters'] = array_keys( $filters );
4448
- $ui['filters_enhanced'] = true;
4449
  }
4450
 
4451
- $reorder_field = pods_v( 'ui_reorder_field', $this->pod_data['options'] );
4452
-
4453
- if ( ! empty( $reorder_field ) && in_array( 'reorder', $actions_enabled, true ) && ! in_array( 'reorder', $actions_disabled, true ) && ( ( ! empty( $this->pod_data['object_fields'] ) && isset( $this->pod_data['object_fields'][ $reorder_field ] ) ) || isset( $this->pod_data['fields'][ $reorder_field ] ) ) ) {
4454
- $ui['reorder'] = array( 'on' => $reorder_field );
4455
- $ui['orderby'] = $reorder_field;
4456
- $ui['orderby_dir'] = 'ASC';
4457
- }
4458
 
4459
- if ( ! empty( $author_restrict ) ) {
4460
- $ui['restrict'] = array( 'author_restrict' => $author_restrict );
 
 
4461
  }
4462
 
4463
- if ( ! in_array( 'export', $ui['actions_disabled'], true ) ) {
4464
- $ui['actions_bulk']['export'] = array(
4465
- 'label' => __( 'Export', 'pods' ),
4466
- // callback not needed, Pods has this built-in for export.
4467
- );
4468
- }
4469
 
4470
- if ( ! in_array( 'delete', $ui['actions_disabled'], true ) ) {
4471
- $ui['actions_bulk']['delete'] = array(
4472
- 'label' => __( 'Delete', 'pods' ),
4473
- // callback not needed, Pods has this built-in for delete.
 
 
4474
  );
4475
  }
4476
 
4477
- $detail_url = pods_v( 'detail_url', $this->pod_data['options'] );
4478
 
4479
  if ( 0 < strlen( $detail_url ) ) {
4480
- $ui['actions_custom'] = array(
4481
  'view_url' => array(
4482
  'label' => 'View',
4483
- 'link' => get_site_url() . '/' . $detail_url,
4484
- ),
4485
  );
4486
  }
4487
 
4488
- // @todo Customize the Add New / Manage links to point to their correct menu items.
4489
- $pod_name = $this->pod;
4490
- $ui = apply_filters( "pods_admin_ui_{$pod_name}", apply_filters( 'pods_admin_ui', $ui, $this->pod, $this ), $this->pod, $this );
4491
 
4492
- // Override UI options.
4493
  foreach ( $options as $option => $value ) {
4494
  $ui[ $option ] = $value;
4495
  }
@@ -4497,36 +3874,28 @@ class Pods implements Iterator {
4497
  $this->ui = $ui;
4498
 
4499
  return pods_ui( $this );
4500
- }//end if
4501
 
4502
- $pod_name = $this->pod;
4503
  do_action( 'pods_admin_ui_custom', $this );
4504
- do_action( "pods_admin_ui_custom_{$pod_name}", $this );
4505
-
4506
- return null;
4507
  }
4508
 
4509
  /**
4510
  * Handle filters / actions for the class
4511
  *
4512
- * @see pods_do_hook
4513
- *
4514
- * @param string $name Hook name.
4515
  *
4516
  * @return mixed Value filtered
4517
  *
4518
- * @since 2.0.0
4519
  */
4520
- private function do_hook( $name ) {
4521
-
4522
  $args = func_get_args();
4523
 
4524
- if ( empty( $args ) ) {
4525
  return false;
4526
- }
4527
 
4528
- // Remove first argument.
4529
- array_shift( $args );
4530
 
4531
  return pods_do_hook( 'pods', $name, $args, $this );
4532
  }
@@ -4534,38 +3903,35 @@ class Pods implements Iterator {
4534
  /**
4535
  * Handle variables that have been deprecated and PodsData vars
4536
  *
4537
- * @param string $name Property name.
4538
  *
4539
  * @return mixed
4540
  *
4541
- * @since 2.0.0
4542
  */
4543
- public function __get( $name ) {
4544
-
4545
  $name = (string) $name;
4546
 
4547
- // PodsData vars.
4548
- if ( isset( $this->data->{$name} ) && 0 === strpos( $name, 'field_' ) ) {
4549
  return $this->data->{$name};
4550
  }
4551
 
4552
- if ( ! $this->deprecated ) {
4553
- require_once PODS_DIR . 'deprecated/classes/Pods.php';
4554
-
4555
  $this->deprecated = new Pods_Deprecated( $this );
4556
  }
4557
 
4558
  $var = null;
4559
 
4560
- $pod_class_exists = class_exists( 'Pod' );
4561
-
4562
  if ( isset( $this->deprecated->{$name} ) ) {
4563
- if ( ! $pod_class_exists || Pod::$deprecated_notice ) {
4564
  pods_deprecated( "Pods->{$name}", '2.0' );
4565
  }
4566
 
4567
  $var = $this->deprecated->{$name};
4568
- } elseif ( ! $pod_class_exists || Pod::$deprecated_notice ) {
 
4569
  pods_deprecated( "Pods->{$name}", '2.0' );
4570
  }
4571
 
@@ -4573,56 +3939,33 @@ class Pods implements Iterator {
4573
  }
4574
 
4575
  /**
4576
- * Handle methods that have been deprecated and any aliasing.
4577
  *
4578
- * @param string $name Function name.
4579
- * @param array $args Arguments passed to function.
4580
  *
4581
- * @return mixed|null
4582
  *
4583
- * @since 2.0.0
4584
  */
4585
- public function __call( $name, $args ) {
4586
-
4587
  $name = (string) $name;
4588
 
4589
- // select > find alias.
4590
- if ( 'select' === $name ) {
4591
  return call_user_func_array( array( $this, 'find' ), $args );
4592
  }
4593
 
4594
- if ( ! $this->deprecated ) {
4595
- require_once PODS_DIR . 'deprecated/classes/Pods.php';
4596
-
4597
  $this->deprecated = new Pods_Deprecated( $this );
4598
  }
4599
 
4600
- $pod_class_exists = class_exists( 'Pod' );
4601
-
4602
  if ( method_exists( $this->deprecated, $name ) ) {
4603
  return call_user_func_array( array( $this->deprecated, $name ), $args );
4604
- // @codingStandardsIgnoreLine
4605
- } elseif ( ! $pod_class_exists || Pod::$deprecated_notice ) {
4606
- pods_deprecated( "Pods::{$name}", '2.0' );
4607
  }
4608
-
4609
- return null;
4610
- }
4611
-
4612
- /**
4613
- * Handle casting a Pods() object to string
4614
- *
4615
- * @return string Pod type and name in CURIE notation
4616
- */
4617
- public function __toString() {
4618
-
4619
- $string = '';
4620
-
4621
- if ( ! empty( $this->pod_data ) ) {
4622
- $string = sprintf( '%s:%s', $this->pod_data['type'], $this->pod_data['name'] );
4623
  }
4624
-
4625
- return $string;
4626
-
4627
  }
4628
  }
1
  <?php
 
2
  /**
 
 
3
  * @package Pods
4
  */
5
  class Pods implements Iterator {
6
 
7
  /**
 
 
8
  * @var bool
9
  */
10
  private $iterator = false;
11
 
12
  /**
 
 
13
  * @var PodsAPI
14
  */
15
  public $api;
16
 
17
  /**
 
 
18
  * @var PodsData
19
  */
20
  public $data;
21
 
22
  /**
 
 
23
  * @var PodsData
24
  */
25
  public $alt_data;
26
 
27
  /**
28
+ * @var array Array of pod item arrays
 
 
29
  */
30
+ public $rows = array();
31
 
32
  /**
33
+ * @var array Current pod item array
 
 
34
  */
35
+ public $row = array();
36
 
37
  /**
 
 
38
  * @var int
39
  */
40
+ private $row_number = -1;
41
 
42
  /**
43
+ * @var array Override pod item array
 
 
44
  */
45
  public $row_override = array();
46
 
47
  /**
 
 
48
  * @var bool
49
  */
50
  public $display_errors = true;
51
 
52
  /**
 
 
53
  * @var array|bool|mixed|null|void
54
  */
55
  public $pod_data;
56
 
57
  /**
 
 
58
  * @var array
59
  */
60
  public $params = array();
61
 
62
  /**
 
 
63
  * @var string
64
  */
65
+ public $pod = '';
66
 
67
  /**
 
 
68
  * @var int
69
  */
70
+ public $pod_id = 0;
71
 
72
  /**
 
 
73
  * @var array
74
  */
75
+ public $fields = array();
76
 
77
  /**
 
 
78
  * @var array
79
  */
80
  public $filters = array();
81
 
82
  /**
 
 
83
  * @var string
84
  */
85
  public $detail_page;
86
 
87
  /**
 
 
88
  * @var int
89
  */
90
+ public $id = 0;
91
 
92
  /**
 
 
93
  * @var int
94
  */
95
  public $limit = 15;
96
 
97
  /**
 
 
98
  * @var int
99
  */
100
  public $offset = 0;
101
 
102
  /**
 
 
103
  * @var string
104
  */
105
  public $page_var = 'pg';
106
 
107
  /**
 
 
108
  * @var int|mixed
109
  */
110
  public $page = 1;
111
 
112
  /**
 
 
113
  * @var bool
114
  */
115
  public $pagination = true;
116
 
117
  /**
 
 
118
  * @var bool
119
  */
120
  public $search = true;
121
 
122
  /**
 
 
123
  * @var string
124
  */
125
  public $search_var = 'search';
126
 
127
  /**
 
 
128
  * @var string
129
  */
130
+ public $search_mode = 'int'; // int | text | text_like
131
 
132
  /**
 
 
133
  * @var int
134
  */
135
  public $total = 0;
136
 
137
  /**
 
 
138
  * @var int
139
  */
140
  public $total_found = 0;
141
 
142
  /**
 
 
143
  * @var array
144
  */
145
  public $ui = array();
146
 
147
  /**
148
+ * @var mixed SEO related vars for Pod Pages
 
 
149
  */
150
  public $page_template;
 
 
 
 
 
 
151
  public $body_classes;
 
 
 
 
 
 
152
  public $meta = array();
 
 
 
 
 
 
153
  public $meta_properties = array();
 
 
 
 
 
 
154
  public $meta_extra = '';
155
 
156
  /**
157
+ * @var string Last SQL query used by a find()
 
 
158
  */
159
  public $sql;
160
 
161
  /**
162
+ * @var
 
 
163
  */
164
  public $deprecated;
165
 
 
 
 
 
 
 
 
166
  public $datatype;
167
 
 
 
 
 
 
 
 
168
  public $datatype_id;
169
 
170
  /**
171
+ * Constructor - Pods Framework core
172
+ *
173
+ * @param string $pod The pod name
174
+ * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
175
  *
176
+ * @return \Pods
 
177
  *
178
  * @license http://www.gnu.org/licenses/gpl-2.0.html
179
+ * @since 1.0.0
180
+ * @link http://pods.io/docs/pods/
181
  */
182
+ public function __construct ( $pod = null, $id = null ) {
 
183
  if ( null === $pod ) {
184
+ $queried_object = get_queried_object();
 
185
 
186
+ if ( $queried_object ) {
 
 
 
187
  $id_lookup = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
 
189
+ // Post Type Singular
190
+ if ( isset( $queried_object->post_type ) ) {
191
+ $pod = $queried_object->post_type;
192
+ }
193
+ // Term Archive
194
+ elseif ( isset( $queried_object->taxonomy ) ) {
195
+ $pod = $queried_object->taxonomy;
196
+ }
197
+ // Author Archive
198
+ elseif ( isset( $queried_object->user_login ) ) {
199
+ $pod = 'user';
200
+ }
201
+ // Post Type Archive
202
+ elseif ( isset( $queried_object->public ) && isset( $queried_object->name ) ) {
203
+ $pod = $queried_object->name;
204
+
205
+ $id_lookup = false;
206
+ }
207
+
208
+ if ( null === $id && $id_lookup ) {
209
+ $id = get_queried_object_id();
210
+ }
211
  }
212
+ }
213
 
214
+ $this->api = pods_api( $pod );
215
  $this->api->display_errors =& $this->display_errors;
216
 
217
+ $this->data = pods_data( $this->api, $id, false );
218
  PodsData::$display_errors =& $this->display_errors;
219
 
220
+ // Set up page variable
221
  if ( pods_strict( false ) ) {
222
+ $this->page = 1;
223
  $this->pagination = false;
224
+ $this->search = false;
225
+ }
226
+ else {
227
+ // Get the page variable
228
+ $this->page = pods_var( $this->page_var, 'get' );
229
+ $this->page = ( empty( $this->page ) ? 1 : max( pods_absint( $this->page ), 1 ) );
 
 
230
  }
231
 
232
+ // Set default pagination handling to on/off
233
  if ( defined( 'PODS_GLOBAL_POD_PAGINATION' ) ) {
234
+ if ( !PODS_GLOBAL_POD_PAGINATION ) {
235
+ $this->page = 1;
236
  $this->pagination = false;
 
 
237
  }
238
+ else
239
+ $this->pagination = true;
240
  }
241
 
242
+ // Set default search to on/off
243
  if ( defined( 'PODS_GLOBAL_POD_SEARCH' ) ) {
244
+ if ( PODS_GLOBAL_POD_SEARCH )
245
  $this->search = true;
246
+ else
247
  $this->search = false;
 
248
  }
249
 
250
+ // Set default search mode
251
  $allowed_search_modes = array( 'int', 'text', 'text_like' );
252
 
253
+ if ( defined( 'PODS_GLOBAL_POD_SEARCH_MODE' ) && in_array( PODS_GLOBAL_POD_SEARCH_MODE, $allowed_search_modes ) )
254
  $this->search_mode = PODS_GLOBAL_POD_SEARCH_MODE;
 
255
 
256
+ // Sync Settings
257
+ $this->data->page =& $this->page;
258
+ $this->data->limit =& $this->limit;
259
+ $this->data->pagination =& $this->pagination;
260
+ $this->data->search =& $this->search;
261
  $this->data->search_mode =& $this->search_mode;
262
 
263
+ // Sync Pod Data
264
  $this->api->pod_data =& $this->data->pod_data;
265
+ $this->pod_data =& $this->api->pod_data;
266
+ $this->api->pod_id =& $this->data->pod_id;
267
+ $this->pod_id =& $this->api->pod_id;
268
+ $this->datatype_id =& $this->pod_id;
269
+ $this->api->pod =& $this->data->pod;
270
+ $this->pod =& $this->api->pod;
271
+ $this->datatype =& $this->pod;
272
+ $this->api->fields =& $this->data->fields;
273
+ $this->fields =& $this->api->fields;
274
+ $this->detail_page =& $this->data->detail_page;
275
+ $this->id =& $this->data->id;
276
+ $this->row =& $this->data->row;
277
+ $this->rows =& $this->data->data;
278
+ $this->row_number =& $this->data->row_number;
279
+ $this->sql =& $this->data->sql;
280
+
281
+ if ( is_array( $id ) || is_object( $id ) )
282
  $this->find( $id );
 
283
  }
284
 
285
  /**
287
  *
288
  * @return bool
289
  *
290
+ * @since 2.0
291
  */
292
+ public function valid () {
293
+ if ( empty( $this->pod_id ) )
 
294
  return false;
 
295
 
296
+ if ( $this->iterator )
297
  return isset( $this->rows[ $this->row_number ] );
 
298
 
299
  return true;
300
  }
306
  *
307
  * @since 2.3.4
308
  *
309
+ * @link http://www.php.net/manual/en/class.iterator.php
310
  */
311
+ public function is_iterator () {
 
312
  return $this->iterator;
313
  }
314
 
319
  *
320
  * @since 2.3.4
321
  *
322
+ * @link http://www.php.net/manual/en/class.iterator.php
323
  */
324
+ public function stop_iterator () {
 
325
  $this->iterator = false;
326
 
327
+ return;
328
  }
329
 
330
  /**
331
  * Rewind Iterator
332
  *
333
+ * @return void|boolean
334
+ *
335
  * @since 2.3.4
336
  *
337
+ * @link http://www.php.net/manual/en/class.iterator.php
338
  */
339
+ public function rewind () {
340
+ if ( $this->iterator ) {
 
 
 
341
  $this->row_number = 0;
342
+
343
+ return;
344
  }
345
+
346
+ return false;
347
  }
348
 
349
  /**
353
  *
354
  * @since 2.3.4
355
  *
356
+ * @link http://www.php.net/manual/en/class.iterator.php
357
  */
358
+ public function current () {
359
+ if ( $this->iterator && $this->fetch() )
 
360
  return $this;
 
361
 
362
  return false;
363
  }
365
  /**
366
  * Get current Iterator key
367
  *
368
+ * @return int|boolean
369
  *
370
  * @since 2.3.4
371
  *
372
+ * @link http://www.php.net/manual/en/class.iterator.php
373
  */
374
+ public function key () {
375
+ if ( $this->iterator )
376
+ return $this->row_number;
377
 
378
+ return false;
379
  }
380
 
381
  /**
382
  * Move onto the next Iterator row
383
  *
384
+ * @return void|boolean
385
  *
386
  * @since 2.3.4
387
  *
388
+ * @link http://www.php.net/manual/en/class.iterator.php
389
  */
390
+ public function next () {
391
+ if ( $this->iterator ) {
392
+ $this->row_number++;
393
+
394
+ return;
395
+ }
396
 
397
+ return false;
398
  }
399
 
400
  /**
402
  *
403
  * @return bool
404
  *
405
+ * @since 2.0
406
  */
407
+ public function exists () {
408
+ if ( empty( $this->row ) )
 
409
  return false;
 
410
 
411
  return true;
412
  }
419
  *
420
  * @return array|bool An array of all rows returned from a find() call, or false if no items returned
421
  *
422
+ * @since 2.0
423
+ * @link http://pods.io/docs/data/
424
  */
425
+ public function data () {
 
426
  do_action( 'pods_pods_data', $this );
427
 
428
+ if ( empty( $this->rows ) )
429
  return false;
 
430
 
431
  return (array) $this->rows;
432
  }
434
  /**
435
  * Return a field input for a specific field
436
  *
437
+ * @param string|array $field Field name or Field data array
438
+ * @param string $field Input field name to use (overrides default name)
439
+ * @param mixed $value Current value to use
440
  *
441
  * @return string Field Input HTML
442
  *
444
  */
445
  public function input( $field, $input_name = null, $value = '__null' ) {
446
 
447
+ // Field data override
448
  if ( is_array( $field ) ) {
 
449
  $field_data = $field;
450
+ $field = pods_var_raw( 'name', $field );
451
+ }
452
+ // Get field data from field name
453
+ else {
454
  $field_data = $this->fields( $field );
455
  }
456
 
457
+ if ( !empty( $field_data ) ) {
458
+ $field_type = pods_var_raw( 'type', $field_data );
459
 
460
  if ( empty( $input_name ) ) {
461
  $input_name = $field;
462
  }
463
 
464
+ if ( '__null' == $value ) {
465
+ $value = $this->field( array( 'name' => $field, 'in_form' => true ) );
 
 
 
466
  }
467
 
468
  return PodsForm::field( $input_name, $value, $field_type, $field_data, $this, $this->id() );
475
  /**
476
  * Return field array from a Pod, a field's data, or a field option
477
  *
478
+ * @param null $field
479
+ * @param null $option
480
  *
481
  * @return bool|mixed
482
  *
483
+ * @since 2.0
484
  */
485
+ public function fields ( $field = null, $option = null ) {
486
 
487
  $field_data = null;
488
 
489
  if ( empty( $this->fields ) ) {
490
+ // No fields found
491
  $field_data = array();
492
  } elseif ( empty( $field ) ) {
493
+ // Return all fields
494
  $field_data = (array) $this->fields;
495
  } elseif ( ! isset( $this->fields[ $field ] ) && ! isset( $this->pod_data['object_fields'][ $field ] ) ) {
496
+ // Field not found
497
  $field_data = array();
498
  } elseif ( empty( $option ) ) {
499
+ // Return all field data
500
  if ( isset( $this->fields[ $field ] ) ) {
501
  $field_data = $this->fields[ $field ];
502
  } elseif ( isset( $this->pod_data['object_fields'] ) ) {
503
  $field_data = $this->pod_data['object_fields'][ $field ];
504
  }
505
  } else {
506
+ // Merge options
 
 
507
  if ( isset( $this->fields[ $field ] ) ) {
508
  $options = array_merge( $this->fields[ $field ], $this->fields[ $field ]['options'] );
509
  } elseif ( isset( $this->pod_data['object_fields'] ) ) {
510
  $options = array_merge( $this->pod_data['object_fields'][ $field ], $this->pod_data['object_fields'][ $field ]['options'] );
511
  }
512
 
513
+ // Get a list of available items from a relationship field
514
+ if ( 'data' == $option && in_array( pods_var_raw( 'type', $options ), PodsForm::tableless_field_types() ) ) {
515
  $field_data = PodsForm::field_method( 'pick', 'get_field_data', $options );
516
+ } // Return option
517
+ elseif ( isset( $options[ $option ] ) ) {
518
  $field_data = $options[ $option ];
519
  }
520
+ }
521
 
522
  /**
523
  * Modify the field data before returning
524
  *
525
  * @since unknown
526
  *
527
+ * @param array $field_data The data for the field.
528
+ * @param string|null $field The specific field that data is being return for, if set when method is called or null.
529
+ * @param string|null $option Value of option param when method was called. Can be used to get a list of available items from a relationship field.
530
+ * @param Pods|object $this The current Pods class instance.
531
  */
532
  return apply_filters( 'pods_pods_fields', $field_data, $field, $option, $this );
533
 
536
  /**
537
  * Return row array for an item
538
  *
539
+ * @return array
540
  *
541
+ * @since 2.0
542
  */
543
+ public function row () {
 
544
  do_action( 'pods_pods_row', $this );
545
 
546
+ if ( !is_array( $this->row ) )
547
  return false;
 
548
 
549
  return (array) $this->row;
550
  }
554
  * you will want to use field() instead. This function will automatically convert arrays into a
555
  * list of text such as "Rick, John, and Gary"
556
  *
557
+ * @param string|array $name The field name, or an associative array of parameters
558
+ * @param boolean $single (optional) For tableless fields, to return an array or the first
559
  *
560
+ * @return string|null|false The output from the field, null if the field doesn't exist, false if no value returned for tableless fields
561
+ * @since 2.0
562
+ * @link http://pods.io/docs/display/
 
563
  */
564
+ public function display ( $name, $single = null ) {
 
565
  $defaults = array(
566
+ 'name' => $name,
567
+ 'single' => $single,
568
+ 'display' => true,
569
+ 'serial_params' => null
570
  );
571
 
572
  if ( is_array( $name ) || is_object( $name ) ) {
573
+ $defaults[ 'name' ] = null;
 
574
  $params = (object) array_merge( $defaults, (array) $name );
575
+ }
576
+ elseif ( is_array( $single ) || is_object( $single ) ) {
577
+ $defaults[ 'single' ] = null;
578
  $params = (object) array_merge( $defaults, (array) $single );
 
 
579
  }
580
+ else
581
+ $params = $defaults;
582
 
583
  $params = (object) $params;
584
 
587
  if ( is_array( $value ) ) {
588
  $fields = $this->fields;
589
 
590
+ if ( isset( $this->pod_data[ 'object_fields' ] ) ) {
591
+ $fields = array_merge( $fields, $this->pod_data[ 'object_fields' ] );
592
+ }
593
 
594
  $serial_params = array(
595
+ 'field' => $params->name,
596
+ 'fields' => $fields
597
  );
598
 
599
+ if ( !empty( $params->serial_params ) && is_array( $params->serial_params ) )
600
  $serial_params = array_merge( $serial_params, $params->serial_params );
 
601
 
602
  $value = pods_serial_comma( $value, $serial_params );
603
  }
610
  * you will want to use field() instead. This function will automatically convert arrays into a
611
  * list of text such as "Rick, John, and Gary"
612
  *
613
+ * @param string|array $name The field name, or an associative array of parameters
614
+ * @param boolean $single (optional) For tableless fields, to return an array or the first
615
  *
616
+ * @return string|null|false The output from the field, null if the field doesn't exist, false if no value returned for tableless fields
617
+ * @since 2.0
618
+ * @link http://pods.io/docs/display/
 
619
  */
620
+ public function raw ( $name, $single = null ) {
 
621
  $defaults = array(
622
+ 'name' => $name,
623
  'single' => $single,
624
+ 'raw' => true
625
  );
626
 
627
  if ( is_array( $name ) || is_object( $name ) ) {
628
+ $defaults[ 'name' ] = null;
 
629
  $params = (object) array_merge( $defaults, (array) $name );
630
+ }
631
+ elseif ( is_array( $single ) || is_object( $single ) ) {
632
+ $defaults[ 'single' ] = null;
633
  $params = (object) array_merge( $defaults, (array) $single );
 
 
634
  }
635
+ else
636
+ $params = (object) $defaults;
637
+
638
+ $value = $this->field( $params );
639
 
640
+ return $value;
641
  }
642
 
643
  /**
647
  *
648
  * This function will return arrays for relationship and file fields.
649
  *
650
+ * @param string|array $name The field name, or an associative array of parameters
651
+ * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item, or an associative array of parameters
652
+ * @param boolean $raw (optional) Whether to return the raw value, or to run through the field type's display method, or an associative array of parameters
 
 
653
  *
654
+ * @return mixed|null Value returned depends on the field type, null if the field doesn't exist, false if no value returned for tableless fields
655
+ * @since 2.0
656
+ * @link http://pods.io/docs/field/
 
657
  */
658
+ public function field ( $name, $single = null, $raw = false ) {
659
 
660
  $defaults = array(
661
+ 'name' => $name,
662
+ 'orderby' => null,
663
+ 'single' => $single,
664
+ 'params' => null,
665
+ 'in_form' => false,
666
+ 'raw' => $raw,
667
  'raw_display' => false,
668
+ 'display' => false,
669
+ 'get_meta' => false,
670
+ 'output' => null,
671
+ 'deprecated' => false,
672
+ 'args' => array() // extra data to send to field handlers
 
 
673
  );
674
 
675
+ if ( is_array( $name ) || is_object( $name ) ) {
676
+ $defaults[ 'name' ] = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
677
  $params = (object) array_merge( $defaults, (array) $name );
678
+ }
679
+ elseif ( is_array( $single ) || is_object( $single ) ) {
680
+ $defaults[ 'single' ] = null;
681
  $params = (object) array_merge( $defaults, (array) $single );
682
+ }
683
+ elseif ( is_array( $raw ) || is_object( $raw ) ) {
684
+ $defaults[ 'raw' ] = false;
685
  $params = (object) array_merge( $defaults, (array) $raw );
686
+ }
687
+ else
688
  $params = (object) $defaults;
 
689
 
690
  if ( $params->in_form ) {
691
  $params->output = 'ids';
692
+ }
693
+ elseif ( null === $params->output ) {
694
  /**
695
+ * Override the way realted fields are output
696
  *
697
+ * @param string $output How to output related fields. Default is 'arrays'. Options: id|name|object|array|pod
698
+ * @param array|object $row Current row being outputted.
699
+ * @param array $params Params array passed to field().
700
+ * @param object|Pods $this Current Pods object.
701
  */
702
  $params->output = apply_filters( 'pods_pods_field_related_output_type', 'arrays', $this->row, $params, $this );
703
  }
704
 
705
+ if ( in_array( $params->output, array( 'id', 'name', 'object', 'array', 'pod' ) ) )
706
  $params->output .= 's';
 
707
 
708
+ // Support old $orderby variable
709
  if ( null !== $params->single && is_string( $params->single ) && empty( $params->orderby ) ) {
710
  if ( ! class_exists( 'Pod' ) || Pod::$deprecated_notice ) {
711
  pods_deprecated( 'Pods::field', '2.0', 'Use $params[ \'orderby\' ] instead' );
712
  }
713
 
714
  $params->orderby = $params->single;
715
+ $params->single = false;
716
  }
717
 
718
+ if ( null !== $params->single )
719
  $params->single = (boolean) $params->single;
 
720
 
721
  $params->name = trim( $params->name );
722
+ if ( is_array( $params->name ) || strlen( $params->name ) < 1 )
723
  return null;
 
724
 
725
  $params->full_name = $params->name;
726
 
727
  $value = null;
728
 
729
+ if ( isset( $this->row_override[ $params->name ] ) )
730
  $value = $this->row_override[ $params->name ];
 
731
 
732
  if ( false === $this->row() ) {
733
+ if ( false !== $this->data() )
734
  $this->fetch();
735
+ else
736
  return $value;
 
737
  }
738
 
739
+ if ( $this->data->field_id == $params->name ) {
740
+ if ( isset( $this->row[ $params->name ] ) )
741
  return $this->row[ $params->name ];
742
+ elseif ( null !== $value )
 
743
  return $value;
 
744
 
745
  return 0;
746
  }
747
 
748
+ $tableless_field_types = PodsForm::tableless_field_types();
749
  $simple_tableless_objects = PodsForm::simple_tableless_objects();
750
 
751
  $params->traverse = array();
752
 
753
+ if ( in_array( $params->name, array( '_link', 'detail_url' ) ) || ( in_array( $params->name, array( 'permalink', 'the_permalink' ) ) && in_array( $this->pod_data[ 'type' ], array( 'post_type', 'taxonomy', 'media', 'user', 'comment' ) ) ) ) {
754
+ if ( 0 < strlen( $this->detail_page ) )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
755
  $value = get_home_url() . '/' . $this->do_magic_tags( $this->detail_page );
756
+ elseif ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) )
757
+ $value = get_permalink( $this->id() );
758
+ elseif ( 'taxonomy' == $this->pod_data[ 'type' ] )
759
+ $value = get_term_link( $this->id(), $this->pod_data[ 'name' ] );
760
+ elseif ( 'user' == $this->pod_data[ 'type' ] )
761
+ $value = get_author_posts_url( $this->id() );
762
+ elseif ( 'comment' == $this->pod_data[ 'type' ] )
763
+ $value = get_comment_link( $this->id() );
764
+ }
765
+
766
+ $field_data = $last_field_data = false;
767
+ $field_type = false;
768
+
769
+ $first_field = explode( '.', $params->name );
770
+ $first_field = $first_field[ 0 ];
771
+
772
+ if ( isset( $this->fields[ $first_field ] ) ) {
773
+ $field_data = $this->fields[ $first_field ];
774
+ $field_type = 'field';
775
+ }
776
+ elseif ( !empty( $this->pod_data[ 'object_fields' ] ) ) {
777
+ if ( isset( $this->pod_data[ 'object_fields' ][ $first_field ] ) ) {
778
+ $field_data = $this->pod_data[ 'object_fields' ][ $first_field ];
779
+ $field_type = 'object_field';
780
+ }
781
+ else {
782
+ foreach ( $this->pod_data[ 'object_fields' ] as $object_field => $object_field_opt ) {
783
+ if ( in_array( $first_field, $object_field_opt[ 'alias' ] ) ) {
784
+ if ( $first_field == $params->name )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
785
  $params->name = $object_field;
 
786
 
787
+ $first_field = $object_field;
788
+ $field_data = $object_field_opt;
789
+ $field_type = 'object_field';
 
790
 
791
  break;
792
  }
793
  }
794
  }
795
+ }
 
 
 
 
 
796
 
797
+ // Simple fields have no other output options
798
+ if ( 'pick' == $field_data[ 'type' ] && in_array( $field_data[ 'pick_object' ], $simple_tableless_objects ) ) {
799
  $params->output = 'arrays';
800
  }
801
 
802
+ if ( empty( $value ) && in_array( $field_data[ 'type' ], $tableless_field_types ) ) {
 
803
  $params->raw = true;
804
 
805
  $value = false;
806
 
807
+ if ( 'arrays' != $params->output && isset( $this->row[ '_' . $params->output . '_' . $params->name ] ) ) {
808
+ $value = $this->row[ '_' . $params->output . '_' . $params->name ];
809
+ }
810
+ elseif ( 'arrays' == $params->output && isset( $this->row[ $params->name ] ) ) {
 
811
  $value = $this->row[ $params->name ];
812
  }
813
 
814
+ if ( false !== $value && !is_array( $value ) && 'pick' == $field_data[ 'type' ] && in_array( $field_data[ 'pick_object' ], $simple_tableless_objects ) )
 
 
 
 
 
815
  $value = PodsForm::field_method( 'pick', 'simple_value', $params->name, $value, $field_data, $this->pod_data, $this->id(), true );
 
816
  }
817
 
818
+ if ( empty( $value ) && isset( $this->row[ $params->name ] ) && ( !in_array( $field_data[ 'type' ], $tableless_field_types ) || 'arrays' == $params->output ) ) {
819
+ if ( empty( $field_data ) || in_array( $field_data[ 'type' ], array( 'boolean', 'number', 'currency' ) ) )
 
 
 
 
820
  $params->raw = true;
 
821
 
822
  if ( null === $params->single ) {
823
+ if ( isset( $this->fields[ $params->name ] ) && !in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) )
824
  $params->single = true;
825
+ else
826
  $params->single = false;
 
827
  }
828
 
829
  $value = $this->row[ $params->name ];
830
+ }
831
+ elseif ( empty( $value ) ) {
832
  $object_field_found = false;
833
 
834
+ if ( 'object_field' == $field_type ) {
835
  $object_field_found = true;
836
 
837
+ if ( isset( $this->row[ $first_field ] ) )
838
  $value = $this->row[ $first_field ];
839
+ elseif ( in_array( $field_data[ 'type' ], $tableless_field_types ) ) {
 
840
  $this->fields[ $first_field ] = $field_data;
841
 
842
  $object_field_found = false;
 
 
843
  }
844
+ else
845
+ return null;
846
+ }
847
 
848
+ if ( 'post_type' == $this->pod_data[ 'type' ] && !isset( $this->fields[ $params->name ] ) ) {
849
+ if ( !isset( $this->fields[ 'post_thumbnail' ] ) && ( 'post_thumbnail' == $params->name || 0 === strpos( $params->name, 'post_thumbnail.' ) ) ) {
850
+ $size = 'thumbnail';
851
+
852
+ if ( 0 === strpos( $params->name, 'post_thumbnail.' ) ) {
853
+ $field_names = explode( '.', $params->name );
854
+
855
+ if ( isset( $field_names[ 1 ] ) )
856
+ $size = $field_names[ 1 ];
 
 
 
 
 
 
 
 
 
857
  }
 
858
 
859
+ // Pods will auto-get the thumbnail ID if this isn't an attachment
860
+ $value = pods_image( $this->id(), $size, 0, null, true );
861
+
862
  $object_field_found = true;
863
+ }
864
+ elseif ( !isset( $this->fields[ 'post_thumbnail_url' ] ) && ( 'post_thumbnail_url' == $params->name || 0 === strpos( $params->name, 'post_thumbnail_url.' ) ) ) {
865
+ $size = 'thumbnail';
866
+
867
+ if ( 0 === strpos( $params->name, 'post_thumbnail_url.' ) ) {
868
+ $field_names = explode( '.', $params->name );
869
+
870
+ if ( isset( $field_names[ 1 ] ) )
871
+ $size = $field_names[ 1 ];
872
  }
873
+
874
+ // Pods will auto-get the thumbnail ID if this isn't an attachment
875
+ $value = pods_image_url( $this->id(), $size, 0, true );
876
+
877
+ $object_field_found = true;
878
  }
879
+ elseif ( 0 === strpos( $params->name, 'image_attachment.' ) ) {
880
+ $size = 'thumbnail';
881
 
882
+ $image_id = 0;
883
 
884
+ $field_names = explode( '.', $params->name );
885
+
886
+ if ( isset( $field_names[ 1 ] ) )
887
+ $image_id = $field_names[ 1 ];
888
+
889
+ if ( isset( $field_names[ 2 ] ) )
890
+ $size = $field_names[ 2 ];
891
+
892
+ if ( !empty( $image_id ) ) {
893
+ $value = pods_image( $image_id, $size, 0, null, true );
894
 
895
+ if ( !empty( $value ) )
896
+ $object_field_found = true;
897
+ }
898
  }
899
+ elseif ( 0 === strpos( $params->name, 'image_attachment_url.' ) ) {
900
+ $size = 'thumbnail';
901
 
902
+ $image_id = 0;
903
+
904
+ $field_names = explode( '.', $params->name );
905
+
906
+ if ( isset( $field_names[ 1 ] ) )
907
+ $image_id = $field_names[ 1 ];
908
 
909
+ if ( isset( $field_names[ 2 ] ) )
910
+ $size = $field_names[ 2 ];
911
+
912
+ if ( !empty( $image_id ) ) {
913
+ $value = pods_image_url( $image_id, $size, 0, true );
914
+
915
+ if ( !empty( $value ) )
916
+ $object_field_found = true;
917
  }
918
+ }
919
+ }
920
+ elseif ( 'user' == $this->pod_data[ 'type' ] && !isset( $this->fields[ $params->name ] ) ) {
921
+ if ( !isset( $this->fields[ 'avatar' ] ) && ( 'avatar' == $params->name || 0 === strpos( $params->name, 'avatar.' ) ) ) {
922
+ $size = null;
923
 
924
+ if ( 0 === strpos( $params->name, 'avatar.' ) ) {
925
+ $field_names = explode( '.', $params->name );
 
 
926
 
927
+ if ( isset( $field_names[ 1 ] ) )
928
+ $size = (int) $field_names[ 1 ];
 
 
 
 
 
 
 
 
 
929
  }
930
 
931
+ if ( !empty( $size ) )
932
+ $value = get_avatar( $this->id(), $size );
933
+ else
934
+ $value = get_avatar( $this->id() );
935
+
936
+ $object_field_found = true;
937
+ }
938
+ }
939
+ elseif ( 0 === strpos( $params->name, 'image_attachment.' ) ) {
940
+ $size = 'thumbnail';
941
+
942
+ $image_id = 0;
943
 
944
+ $field_names = explode( '.', $params->name );
 
 
945
 
946
+ if ( isset( $field_names[ 1 ] ) )
947
+ $image_id = $field_names[ 1 ];
 
 
 
 
 
 
948
 
949
+ if ( isset( $field_names[ 2 ] ) )
950
+ $size = $field_names[ 2 ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
951
 
952
+ if ( !empty( $image_id ) ) {
953
+ $value = pods_image( $image_id, $size, 0, null, true );
954
+
955
+ if ( !empty( $value ) )
956
+ $object_field_found = true;
957
+ }
958
+ }
959
+ elseif ( 0 === strpos( $params->name, 'image_attachment_url.' ) ) {
960
+ $size = 'thumbnail';
961
+
962
+ $image_id = 0;
963
+
964
+ $field_names = explode( '.', $params->name );
965
+
966
+ if ( isset( $field_names[ 1 ] ) )
967
+ $image_id = $field_names[ 1 ];
968
+
969
+ if ( isset( $field_names[ 2 ] ) )
970
+ $size = $field_names[ 2 ];
971
+
972
+ if ( !empty( $image_id ) ) {
973
+ $value = pods_image_url( $image_id, $size, 0, true );
974
+
975
+ if ( !empty( $value ) )
976
+ $object_field_found = true;
977
  }
978
  }
979
 
 
980
  if ( false === $object_field_found ) {
981
  $params->traverse = array( $params->name );
982
 
983
  if ( false !== strpos( $params->name, '.' ) ) {
984
  $params->traverse = explode( '.', $params->name );
985
 
986
+ $params->name = $params->traverse[ 0 ];
987
  }
988
 
989
+ if ( isset( $this->fields[ $params->name ] ) && isset( $this->fields[ $params->name ][ 'type' ] ) ) {
 
990
  /**
991
  * Modify value returned by field() after its retrieved, but before its validated or formatted
992
  *
993
+ * Filter name is set dynamically with name of field: "pods_pods_field_{field_name}"
994
  *
995
  * @since unknown
996
  *
997
+ * @param array|string|null $value Value retrieved.
998
+ * @param array|object $row Current row being outputted.
999
+ * @param array $params Params array passed to field().
1000
+ * @param object|Pods $this Current Pods object.
1001
+ *
1002
  */
1003
+ $v = apply_filters( 'pods_pods_field_' . $this->fields[ $params->name ][ 'type' ], null, $this->fields[ $params->name ], $this->row, $params, $this );
1004
 
1005
+ if ( null !== $v )
1006
  return $v;
 
1007
  }
1008
 
1009
  $simple = false;
1010
+ $simple_data = array();
1011
 
1012
+ if ( isset( $this->fields[ $params->name ] ) ) {
1013
+ if ( 'meta' == $this->pod_data[ 'storage' ] ) {
1014
+ if ( !in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) )
1015
+ $simple = true;
1016
  }
1017
 
1018
+ if ( in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) ) {
1019
  $params->raw = true;
1020
 
1021
+ if ( 'pick' == $this->fields[ $params->name ][ 'type' ] && in_array( $this->fields[ $params->name ][ 'pick_object' ], $simple_tableless_objects ) ) {
1022
+ $simple = true;
1023
  $params->single = true;
1024
  }
 
 
1025
  }
1026
+ elseif ( in_array( $this->fields[ $params->name ][ 'type' ], array( 'boolean', 'number', 'currency' ) ) )
1027
+ $params->raw = true;
1028
  }
1029
 
1030
+ if ( !isset( $this->fields[ $params->name ] ) || !in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) || $simple ) {
1031
  if ( null === $params->single ) {
1032
+ if ( isset( $this->fields[ $params->name ] ) && !in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) )
1033
  $params->single = true;
1034
+ else
1035
  $params->single = false;
 
1036
  }
1037
 
1038
+ $no_conflict = pods_no_conflict_check( $this->pod_data[ 'type' ] );
1039
 
1040
+ if ( !$no_conflict )
1041
+ pods_no_conflict_on( $this->pod_data[ 'type' ] );
 
 
1042
 
1043
+ if ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media', 'taxonomy', 'user', 'comment' ) ) ) {
1044
  $id = $this->id();
1045
 
1046
+ $metadata_type = $this->pod_data['type'];
1047
 
1048
+ if ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) ) {
1049
  $metadata_type = 'post';
1050
 
1051
+ // Support for WPML 'duplicated' translation handling
1052
+ if ( did_action( 'wpml_loaded' )
1053
+ && apply_filters( 'wpml_is_translated_post_type', false, $this->pod_data[ 'name' ] ) ) {
1054
  $master_post_id = (int) apply_filters( 'wpml_master_post_from_duplicate', $id );
1055
 
1056
+ if ( 0 < $master_post_id )
1057
  $id = $master_post_id;
 
1058
  }
1059
+ } elseif ( 'taxonomy' == $this->pod_data[ 'type' ] ) {
1060
  $metadata_type = 'term';
1061
  }
1062
 
1064
 
1065
  $single_multi = 'single';
1066
 
1067
+ if ( isset( $this->fields[ $params->name ] ) ) {
1068
+ $single_multi = pods_v( $this->fields[ $params->name ][ 'type' ] . '_format_type', $this->fields[ $params->name ][ 'options' ], 'single' );
1069
  }
1070
 
1071
+ if ( $simple && !is_array( $value ) && 'single' != $single_multi ) {
1072
  $value = get_metadata( $metadata_type, $id, $params->name );
1073
  }
1074
+ }
1075
+ elseif ( 'settings' == $this->pod_data[ 'type' ] )
1076
+ $value = get_option( $this->pod_data[ 'name' ] . '_' . $params->name, null );
1077
 
1078
+ // Handle Simple Relationships
1079
  if ( $simple ) {
1080
+ if ( null === $params->single )
1081
  $params->single = false;
1082
+
1083
 
1084
  $value = PodsForm::field_method( 'pick', 'simple_value', $params->name, $value, $this->fields[ $params->name ], $this->pod_data, $this->id(), true );
1085
  }
1086
 
1087
+ if ( !$no_conflict )
1088
+ pods_no_conflict_off( $this->pod_data[ 'type' ] );
1089
+ }
1090
+ else {
1091
+ // Dot-traversal
1092
+ $pod = $this->pod;
1093
+ $ids = array( $this->id() );
 
1094
  $all_fields = array();
1095
 
1096
  $lookup = $params->traverse;
1097
 
1098
+ // Get fields matching traversal names
1099
+ if ( !empty( $lookup ) ) {
1100
  $fields = $this->api->load_fields( array(
1101
+ 'name' => $lookup,
1102
+ 'type' => $tableless_field_types,
1103
+ 'object_fields' => true // @todo support object fields too
 
1104
  ) );
1105
 
1106
+ if ( !empty( $fields ) ) {
1107
  foreach ( $fields as $field ) {
1108
+ if ( !empty( $field ) ) {
1109
+ if ( !isset( $all_fields[ $field[ 'pod' ] ] ) )
1110
+ $all_fields[ $field[ 'pod' ] ] = array();
 
1111
 
1112
+ $all_fields[ $field[ 'pod' ] ][ $field[ 'name' ] ] = $field;
1113
  }
1114
  }
1115
  }
1116
 
1117
+ if ( !empty( $this->pod_data[ 'object_fields' ] ) ) {
1118
+ foreach ( $this->pod_data[ 'object_fields' ] as $object_field => $object_field_opt ) {
1119
+ if ( in_array( $object_field_opt[ 'type' ], $tableless_field_types ) ) {
 
 
1120
  $all_fields[ $this->pod ][ $object_field ] = $object_field_opt;
1121
  }
1122
  }
1123
  }
1124
+ }
1125
 
1126
+ $last_type = $last_object = $last_pick_val = '';
1127
+ $last_options = array();
 
1128
 
1129
+ $single_multi = pods_v( $this->fields[ $params->name ][ 'type' ] . '_format_type', $this->fields[ $params->name ][ 'options' ], 'single' );
1130
 
1131
+ if ( 'multi' == $single_multi )
1132
+ $limit = (int) pods_v( $this->fields[ $params->name ][ 'type' ] . '_limit', $this->fields[ $params->name ][ 'options' ], 0 );
1133
+ else
1134
  $limit = 1;
 
1135
 
1136
+ $last_limit = 0;
1137
+
1138
+ // Loop through each traversal level
1139
  foreach ( $params->traverse as $key => $field ) {
1140
  $last_loop = false;
1141
 
1142
+ if ( count( $params->traverse ) <= ( $key + 1 ) )
1143
  $last_loop = true;
 
1144
 
1145
  $field_exists = isset( $all_fields[ $pod ][ $field ] );
1146
 
1147
+ $simple = false;
1148
  $last_options = array();
1149
 
1150
+ if ( $field_exists && 'pick' == $all_fields[ $pod ][ $field ][ 'type' ] && in_array( $all_fields[ $pod ][ $field ][ 'pick_object' ], $simple_tableless_objects ) ) {
1151
+ $simple = true;
 
 
 
 
1152
  $last_options = $all_fields[ $pod ][ $field ];
1153
  }
1154
 
1155
+ // Tableless handler
1156
+ if ( $field_exists && ( !in_array( $all_fields[ $pod ][ $field ][ 'type' ], array( 'pick', 'taxonomy' ) ) || !$simple ) ) {
1157
+ $type = $all_fields[ $pod ][ $field ][ 'type' ];
1158
+ $pick_object = $all_fields[ $pod ][ $field ][ 'pick_object' ];
1159
+ $pick_val = $all_fields[ $pod ][ $field ][ 'pick_val' ];
1160
+
1161
+ if ( 'table' == $pick_object ) {
1162
+ $pick_val = pods_v( 'pick_table', $all_fields[ $pod ][ $field ][ 'options' ], $pick_val, true );
1163
+ }
1164
+ elseif ( '__current__' == $pick_val ) {
 
 
 
1165
  $pick_val = $pod;
1166
  }
1167
 
1168
  $last_limit = 0;
1169
 
1170
+ if ( in_array( $type, $tableless_field_types ) ) {
1171
+ $single_multi = pods_v( "{$type}_format_type", $all_fields[ $pod ][ $field ][ 'options' ], 'single' );
1172
 
1173
+ if ( 'multi' == $single_multi ) {
1174
+ $last_limit = (int) pods_v( "{$type}_limit", $all_fields[ $pod ][ $field ][ 'options' ], 0 );
1175
+ }
1176
+ else {
1177
  $last_limit = 1;
1178
  }
1179
  }
1180
 
1181
+ $last_type = $type;
1182
+ $last_object = $pick_object;
1183
  $last_pick_val = $pick_val;
1184
+ $last_options = $all_fields[ $pod ][ $field ];
1185
 
1186
+ // Temporary hack until there's some better handling here
1187
+ $last_limit = $last_limit * count( $ids );
1188
 
1189
+ // Get related IDs
1190
+ if ( !isset( $all_fields[ $pod ][ $field ][ 'pod_id' ] ) ) {
1191
+ $all_fields[ $pod ][ $field ][ 'pod_id' ] = 0;
1192
  }
1193
 
1194
+ if ( isset( $all_fields[ $pod ][ $field ][ 'id' ] ) ) {
1195
+ $ids = $this->api->lookup_related_items(
1196
+ $all_fields[ $pod ][ $field ][ 'id' ],
1197
+ $all_fields[ $pod ][ $field ][ 'pod_id' ],
1198
+ $ids,
1199
+ $all_fields[ $pod ][ $field ]
1200
+ );
1201
  }
1202
 
1203
+ // No items found
1204
  if ( empty( $ids ) ) {
1205
  return false;
1206
+ } // @todo This should return array() if not $params->single
1207
+ elseif ( 0 < $last_limit ) {
1208
  $ids = array_slice( $ids, 0, $last_limit );
1209
  }
1210
 
1211
+ // Get $pod if related to a Pod
1212
+ if ( !empty( $pick_object ) && ( !empty( $pick_val ) || in_array( $pick_object, array( 'user', 'media', 'comment' ) ) ) ) {
1213
+ if ( 'pod' == $pick_object ) {
 
 
 
 
1214
  $pod = $pick_val;
1215
+ }
1216
+ else {
1217
  $check = $this->api->get_table_info( $pick_object, $pick_val );
1218
 
1219
+ if ( !empty( $check ) && !empty( $check[ 'pod' ] ) ) {
1220
+ $pod = $check[ 'pod' ][ 'name' ];
1221
  }
1222
  }
1223
  }
1224
+ }
1225
+ // Assume last iteration
1226
+ else {
1227
+ // Invalid field
1228
+ if ( 0 == $key ) {
1229
+ return false;
 
 
1230
  }
1231
+
1232
+ $last_loop = true;
1233
+ }
1234
 
1235
  if ( $last_loop ) {
1236
  $object_type = $last_object;
1237
+ $object = $last_pick_val;
1238
 
1239
+ if ( in_array( $last_type, PodsForm::file_field_types() ) ) {
1240
  $object_type = 'media';
1241
+ $object = 'attachment';
1242
  }
1243
 
1244
  $data = array();
1245
 
1246
  $table = $this->api->get_table_info( $object_type, $object, null, null, $last_options );
1247
 
1248
+ $join = $where = array();
 
1249
 
1250
+ if ( !empty( $table[ 'join' ] ) )
1251
+ $join = (array) $table[ 'join' ];
 
1252
 
1253
+ if ( !empty( $table[ 'where' ] ) || !empty( $ids ) ) {
1254
  foreach ( $ids as $id ) {
1255
+ $where[ $id ] = '`t`.`' . $table[ 'field_id' ] . '` = ' . (int) $id;
1256
  }
1257
 
1258
+ if ( !empty( $where ) ) {
1259
  $where = array( implode( ' OR ', $where ) );
1260
  }
1261
 
1262
+ if ( !empty( $table[ 'where' ] ) ) {
1263
+ $where = array_merge( $where, array_values( (array) $table[ 'where' ] ) );
 
1264
  }
1265
  }
1266
 
1267
  /**
1268
+ * @var $related_obj Pods
 
 
1269
  */
1270
  $related_obj = false;
1271
 
1272
+ if ( 'pod' == $object_type )
 
 
 
 
 
 
 
1273
  $related_obj = pods( $object, null, false );
1274
+ elseif ( !empty( $table[ 'pod' ] ) )
1275
+ $related_obj = pods( $table[ 'pod' ][ 'name' ], null, false );
 
1276
 
1277
+ if ( !empty( $table[ 'table' ] ) || !empty( $related_obj ) ) {
1278
  $sql = array(
1279
+ 'select' => '*, `t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`',
1280
+ 'table' => $table[ 'table' ],
1281
+ 'join' => $join,
1282
+ 'where' => $where,
1283
+ 'orderby' => $params->orderby,
1284
  'pagination' => false,
1285
+ 'search' => false,
1286
+ 'limit' => -1,
1287
+ 'expires' => 180 // @todo This could potentially cause issues if someone changes the data within this time and persistent storage is used
 
1288
  );
1289
 
1290
+ // Output types
1291
+ if ( in_array( $params->output, array( 'ids', 'objects', 'pods' ) ) )
1292
+ $sql[ 'select' ] = '`t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`';
1293
+ elseif ( 'names' == $params->output && !empty( $table[ 'field_index' ] ) )
1294
+ $sql[ 'select' ] = '`t`.`' . $table[ 'field_index' ] . '` AS `pod_item_index`, `t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`';
 
 
 
 
 
1295
 
1296
+ if ( !empty( $params->params ) && is_array( $params->params ) ) {
1297
+ $where = $sql[ 'where' ];
1298
 
 
1299
  $sql = array_merge( $sql, $params->params );
1300
 
1301
+ if ( isset( $params->params[ 'where' ] ) )
1302
+ $sql[ 'where' ] = array_merge( (array) $where, (array) $params->params['where' ] );
 
 
1303
  }
1304
 
1305
+ if ( empty( $related_obj ) ) {
1306
+ if ( !is_object( $this->alt_data ) )
 
 
1307
  $this->alt_data = pods_data( null, 0, true, true );
 
1308
 
1309
  $item_data = $this->alt_data->select( $sql );
1310
+ }
1311
+ else
1312
+ $item_data = $related_obj->find( $sql )->data();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1313
 
1314
  $items = array();
1315
 
1316
+ if ( !empty( $item_data ) ) {
1317
  foreach ( $item_data as $item ) {
1318
+ if ( is_array( $item ) )
1319
  $item = (object) $item;
 
1320
 
1321
+ if ( empty( $item->pod_item_id ) )
1322
  continue;
 
1323
 
1324
+ // Bypass pass field
1325
+ if ( isset( $item->user_pass ) )
1326
  unset( $item->user_pass );
 
1327
 
1328
+ // Get Item ID
1329
  $item_id = $item->pod_item_id;
1330
 
1331
+ // Output types
1332
+ if ( 'ids' == $params->output )
1333
  $item = (int) $item_id;
1334
+ elseif ( 'names' == $params->output && !empty( $table[ 'field_index' ] ) )
1335
  $item = $item->pod_item_index;
1336
+ elseif ( 'objects' == $params->output ) {
1337
+ if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
1338
  $item = get_post( $item_id );
1339
+ elseif ( 'taxonomy' == $object_type )
1340
  $item = get_term( $item_id, $object );
1341
+ elseif ( 'user' == $object_type ) {
1342
  $item = get_userdata( $item_id );
1343
 
1344
+ if ( !empty( $item ) ) {
1345
+ // Get other vars
1346
+ $roles = $item->roles;
1347
+ $caps = $item->caps;
1348
  $allcaps = $item->allcaps;
1349
 
1350
  $item = $item->data;
1351
 
1352
+ // Set other vars
1353
+ $item->roles = $roles;
1354
+ $item->caps = $caps;
1355
  $item->allcaps = $allcaps;
1356
 
1357
  unset( $item->user_pass );
1358
  }
1359
+ }
1360
+ elseif ( 'comment' == $object_type )
1361
  $item = get_comment( $item_id );
1362
+ else
1363
  $item = (object) $item;
1364
+ } elseif ( 'pods' == $params->output ) {
1365
+ if ( in_array( $object_type, array( 'user', 'media' ) ) ) {
 
1366
  $item = pods( $object_type, (int) $item_id );
1367
  } else {
1368
  $item = pods( $object, (int) $item_id );
1369
  }
1370
+ }
1371
+ else // arrays
1372
  $item = get_object_vars( (object) $item );
 
1373
 
1374
+ // Pass item data into $data
1375
  $items[ $item_id ] = $item;
1376
+ }
1377
 
1378
+ // Cleanup
1379
  unset( $item_data );
1380
 
1381
+ // Return all of the data in the order expected
1382
  if ( empty( $params->orderby ) ) {
1383
  foreach ( $ids as $id ) {
1384
  if ( isset( $items[ $id ] ) ) {
1386
  }
1387
  }
1388
  } else {
1389
+ // Use order set by orderby
1390
  foreach ( $items as $id => $v ) {
 
1391
  if ( in_array( $id, $ids ) ) {
1392
  $data[ $id ] = $v;
1393
  }
1394
  }
1395
  }
1396
+ }
 
 
 
 
 
 
 
 
1397
  }
1398
 
1399
+ if ( in_array( $last_type, $tableless_field_types ) || in_array( $last_type, array( 'boolean', 'number', 'currency' ) ) )
1400
+ $params->raw = true;
1401
+
1402
+ if ( empty( $data ) )
1403
  $value = false;
1404
+ else {
1405
+ $object_type = $table[ 'type' ];
1406
 
1407
+ if ( in_array( $table[ 'type' ], array( 'post_type', 'attachment', 'media' ) ) )
1408
  $object_type = 'post';
 
1409
 
1410
+ $no_conflict = true;
1411
 
1412
+ if ( in_array( $object_type, array( 'post', 'taxonomy', 'user', 'comment', 'settings' ) ) ) {
1413
+ $no_conflict = pods_no_conflict_check( $object_type );
1414
 
1415
+ if ( !$no_conflict )
1416
+ pods_no_conflict_on( $object_type );
 
 
 
1417
  }
1418
 
1419
+ // Return entire array
1420
+ if ( false !== $field_exists && ( in_array( $last_type, $tableless_field_types ) && !$simple ) )
1421
  $value = $data;
1422
+ // Return an array of single column values
1423
+ else {
1424
  $value = array();
1425
 
1426
  foreach ( $data as $item_id => $item ) {
1427
  // $field is 123x123, needs to be _src.123x123
1428
+ $full_field = implode( '.', array_splice( $params->traverse, $key ) );
 
 
1429
 
1430
  if ( is_array( $item ) && isset( $item[ $field ] ) ) {
1431
+ if ( $table[ 'field_id' ] == $field )
1432
  $value[] = (int) $item[ $field ];
1433
+ else
1434
  $value[] = $item[ $field ];
1435
+ }
1436
+ elseif ( is_object( $item ) && isset( $item->{$field} ) ) {
1437
+ if ( $table[ 'field_id' ] == $field )
1438
  $value[] = (int) $item->{$field};
1439
+ else
1440
  $value[] = $item->{$field};
1441
+ }
1442
+ elseif ( ( ( false !== strpos( $full_field, '_src' ) || 'guid' == $field ) && ( in_array( $table[ 'type' ], array( 'attachment', 'media' ) ) || in_array( $last_type, PodsForm::file_field_types() ) ) ) || ( in_array( $field, array( '_link', 'detail_url' ) ) || in_array( $field, array( 'permalink', 'the_permalink' ) ) && in_array( $last_type, PodsForm::file_field_types() ) ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
1443
  $size = 'full';
1444
 
1445
+ if ( false === strpos( 'image', get_post_mime_type( $item_id ) ) ) {
1446
+ // No default sizes for non-images. When a size is defined this will be overwritten.
 
1447
  $size = null;
1448
  }
1449
 
1450
+ if ( false !== strpos( $full_field, '_src.' ) && 5 < strlen( $full_field ) )
1451
  $size = substr( $full_field, 5 );
1452
+ elseif ( false !== strpos( $full_field, '_src_relative.' ) && 14 < strlen( $full_field ) )
1453
  $size = substr( $full_field, 14 );
1454
+ elseif ( false !== strpos( $full_field, '_src_schemeless.' ) && 16 < strlen( $full_field ) )
1455
  $size = substr( $full_field, 16 );
 
1456
 
1457
  if ( $size ) {
1458
+ $value_url = pods_image_url( $item_id, $size );
1459
  } else {
1460
  $value_url = wp_get_attachment_url( $item_id );
1461
  }
1462
 
1463
+ if ( false !== strpos( $full_field, '_src_relative' ) && !empty( $value_url ) ) {
1464
+ $value_url_parsed = parse_url( $value_url );
1465
+ $value_url = $value_url_parsed[ 'path' ];
 
 
 
 
 
 
 
1466
  }
1467
+ elseif ( false !== strpos( $full_field, '_src_schemeless' ) && !empty( $value_url ) )
1468
+ $value_url = str_replace( array( 'http://', 'https://' ), '//', $value_url );
1469
 
1470
+ if ( !empty( $value_url ) )
1471
  $value[] = $value_url;
 
1472
 
1473
  $params->raw_display = true;
1474
+ }
1475
+ elseif ( false !== strpos( $full_field, '_img' ) && ( in_array( $table[ 'type' ], array( 'attachment', 'media' ) ) || in_array( $last_type, PodsForm::file_field_types() ) ) ) {
 
 
1476
  $size = 'full';
1477
 
1478
+ if ( false !== strpos( $full_field, '_img.' ) && 5 < strlen( $full_field ) )
1479
  $size = substr( $full_field, 5 );
 
1480
 
1481
+ $value[] = pods_image( $item_id, $size );
1482
 
1483
  $params->raw_display = true;
1484
+ }
1485
+ elseif ( in_array( $field, array( '_link', 'detail_url' ) ) || in_array( $field, array( 'permalink', 'the_permalink' ) ) ) {
1486
+ if ( 'pod' == $object_type ) {
 
 
1487
  if ( is_object( $related_obj ) ) {
1488
  $related_obj->fetch( $item_id );
1489
 
1490
  $value[] = $related_obj->field( 'detail_url' );
 
 
1491
  }
1492
+ else
1493
+ $value[] = '';
1494
+ }
1495
+ elseif ( 'post' == $object_type )
1496
  $value[] = get_permalink( $item_id );
1497
+ elseif ( 'taxonomy' == $object_type )
1498
  $value[] = get_term_link( $item_id, $object );
1499
+ elseif ( 'user' == $object_type )
1500
  $value[] = get_author_posts_url( $item_id );
1501
+ elseif ( 'comment' == $object_type )
1502
  $value[] = get_comment_link( $item_id );
1503
+ else
1504
  $value[] = '';
 
1505
 
1506
  $params->raw_display = true;
1507
+ }
1508
+ elseif ( in_array( $object_type, array( 'post', 'taxonomy', 'user', 'comment' ) ) ) {
 
 
 
 
1509
  $metadata_object_id = $item_id;
1510
 
1511
  $metadata_type = $object_type;
1512
 
1513
+ if ( 'post' == $object_type ) {
1514
+ // Support for WPML 'duplicated' translation handling
1515
+ if ( did_action( 'wpml_loaded' )
1516
+ && apply_filters( 'wpml_is_translated_post_type', false, $object ) ) {
1517
  $master_post_id = (int) apply_filters( 'wpml_master_post_from_duplicate', $metadata_object_id );
1518
 
1519
+ if ( 0 < $master_post_id )
1520
  $metadata_object_id = $master_post_id;
 
1521
  }
1522
+ } elseif ( 'taxonomy' == $object_type ) {
1523
  $metadata_type = 'term';
1524
  }
1525
 
1526
+ $value[] = get_metadata( $metadata_type, $metadata_object_id, $field, true );
1527
+ }
1528
+ elseif ( 'settings' == $object_type )
1529
+ $value[] = get_option( $object . '_' . $field );
1530
+ }
 
 
 
 
 
 
 
1531
  }
1532
 
1533
+ if ( in_array( $object_type, array( 'post', 'taxonomy', 'user', 'comment', 'settings' ) ) && !$no_conflict )
1534
+ pods_no_conflict_off( $object_type );
1535
+
1536
+ // Handle Simple Relationships
1537
  if ( $simple ) {
1538
+ if ( null === $params->single )
1539
  $params->single = false;
 
1540
 
1541
  $value = PodsForm::field_method( 'pick', 'simple_value', $field, $value, $last_options, $all_fields[ $pod ], 0, true );
 
 
1542
  }
1543
+ elseif ( false === $params->in_form && !empty( $value ) )
1544
+ $value = array_values( $value );
1545
 
1546
+ // Return a single column value
1547
+ if ( false === $params->in_form && 1 == $limit && !empty( $value ) && is_array( $value ) && 1 == count( $value ) )
1548
  $value = current( $value );
1549
+ }
 
1550
 
1551
  if ( $last_options ) {
1552
  $last_field_data = $last_options;
 
 
 
1553
  }
1554
 
1555
  break;
1556
+ }
1557
+ }
1558
+ }
1559
+ }
1560
+ }
1561
 
1562
+ if ( !empty( $params->traverse ) && 1 < count( $params->traverse ) ) {
1563
  $field_names = implode( '.', $params->traverse );
1564
 
1565
  $this->row[ $field_names ] = $value;
1566
+ }
1567
+ elseif ( 'arrays' != $params->output && in_array( $field_data[ 'type' ], $tableless_field_types ) ) {
1568
  $this->row[ '_' . $params->output . '_' . $params->full_name ] = $value;
1569
+ }
1570
+ elseif ( 'arrays' == $params->output || !in_array( $field_data[ 'type' ], $tableless_field_types ) ) {
1571
  $this->row[ $params->full_name ] = $value;
1572
  }
1573
 
1574
+ if ( $params->single && is_array( $value ) && 1 == count( $value ) )
1575
  $value = current( $value );
 
1576
 
1577
  if ( ! empty( $last_field_data ) ) {
1578
  $field_data = $last_field_data;
1579
  }
1580
 
1581
+ // @todo Expand this into traversed fields too
1582
+ if ( !empty( $field_data ) && ( $params->display || !$params->raw ) && !$params->in_form && !$params->raw_display ) {
1583
+ if ( $params->display || ( ( $params->get_meta || $params->deprecated ) && !in_array( $field_data[ 'type' ], $tableless_field_types ) ) ) {
1584
+ $field_data[ 'options' ] = pods_var_raw( 'options', $field_data, array(), null, true );
1585
 
1586
+ $post_temp = false;
 
 
 
1587
 
1588
+ if ( 'post_type' == pods_v( 'type', $this->pod_data ) && 0 < $this->id() && ( !isset( $GLOBALS[ 'post' ] ) || empty( $GLOBALS[ 'post' ] ) ) ) {
1589
  global $post_ID, $post;
1590
 
1591
  $post_temp = true;
1592
 
1593
+ $old_post = $GLOBALS[ 'post' ];
1594
+ $old_ID = $GLOBALS[ 'post_ID' ];
1595
 
1596
+ $post = get_post( $this->id() );
 
 
1597
  $post_ID = $this->id();
1598
  }
1599
 
1600
+ $filter = pods_var_raw( 'display_filter', $field_data[ 'options' ] );
1601
 
1602
  if ( 0 < strlen( $filter ) ) {
1603
  $args = array(
1604
  $filter,
1605
+ $value
1606
  );
1607
 
1608
+ $filter_args = pods_var_raw( 'display_filter_args', $field_data[ 'options' ] );
1609
 
1610
+ if ( !empty( $filter_args ) )
1611
  $args = array_merge( $args, compact( $filter_args ) );
 
1612
 
1613
  $value = call_user_func_array( 'apply_filters', $args );
1614
+ }
1615
+ elseif ( 1 == pods_v( 'display_process', $field_data[ 'options' ], 1 ) ) {
1616
+ $value = PodsForm::display(
1617
+ $field_data[ 'type' ],
1618
+ $value,
1619
+ $params->name,
1620
+ array_merge( $field_data, $field_data[ 'options' ] ),
1621
+ $this->pod_data,
1622
+ $this->id()
1623
+ );
1624
  }
1625
 
1626
  if ( $post_temp ) {
1627
+ $post = $old_post;
1628
+ $post_ID = $old_ID;
 
 
1629
  }
1630
+ }
1631
+ else {
1632
+ $value = PodsForm::value(
1633
+ $field_data[ 'type' ],
1634
+ $value,
1635
+ $params->name,
1636
+ array_merge( $field_data, $field_data[ 'options' ] ),
1637
+ $this->pod_data,
1638
+ $this->id()
1639
+ );
1640
+ }
1641
+ }
1642
 
1643
  /**
1644
  * Modify value returned by field() directly before output.
1647
  *
1648
  * @since unknown
1649
  *
1650
+ * @param array|string|null $value Value to be returned.
1651
+ * @param array|object $row Current row being outputted.
1652
+ * @param array $params Params array passed to field().
1653
+ * @param object|Pods $this Current Pods object.
1654
+ *
1655
  */
1656
  $value = apply_filters( 'pods_pods_field', $value, $this->row, $params, $this );
1657
 
1661
  /**
1662
  * Check if an item field has a specific value in it
1663
  *
1664
+ * @param string $field Field name
1665
+ * @param mixed $value Value to check
1666
+ * @param int $id (optional) ID of the pod item to check
1667
  *
1668
  * @return bool Whether the value was found
1669
  *
1670
  * @since 2.3.3
1671
  */
1672
+ public function has ( $field, $value, $id = null ) {
 
1673
  $pod =& $this;
1674
 
1675
+ if ( null === $id )
1676
  $id = $this->id();
1677
+ elseif ( $id != $this->id() )
 
1678
  $pod = pods( $this->pod, $id );
 
1679
 
1680
  $this->do_hook( 'has', $field, $value, $id );
1681
 
1682
+ if ( !isset( $this->fields[ $field ] ) )
1683
  return false;
 
1684
 
1685
+ // Tableless fields
1686
+ if ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::tableless_field_types() ) ) {
1687
+ if ( !is_array( $value ) )
1688
  $value = explode( ',', $value );
 
1689
 
1690
+ if ( 'pick' == $this->fields[ $field ][ 'type' ] && in_array( $this->fields[ $field ][ 'pick_object' ], PodsForm::simple_tableless_objects() ) ) {
1691
  $current_value = $pod->raw( $field );
1692
 
1693
+ if ( !empty( $current_value ) )
1694
  $current_value = (array) $current_value;
 
1695
 
1696
  foreach ( $current_value as $v ) {
1697
+ if ( in_array( $v, $value ) )
 
1698
  return true;
 
1699
  }
1700
+ }
1701
+ else {
1702
+ $related_ids = $this->api->lookup_related_items( $this->fields[ $field ][ 'id' ], $this->pod_data[ 'id' ], $id, $this->fields[ $field ], $this->pod_data );
1703
 
1704
  foreach ( $value as $k => $v ) {
1705
+ if ( !preg_match( '/[^0-9]/', $v ) )
1706
  $value[ $k ] = (int) $v;
1707
+ // @todo Convert slugs into IDs
1708
+ else {
1709
 
1710
+ }
1711
  }
1712
 
1713
  foreach ( $related_ids as $v ) {
1714
+ if ( in_array( $v, $value ) )
 
1715
  return true;
 
1716
  }
1717
+ }
1718
+ }
1719
+ // Text fields
1720
+ elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::text_field_types() ) ) {
1721
  $current_value = $pod->raw( $field );
1722
 
1723
+ if ( 0 < strlen( $current_value ) )
1724
  return stripos( $current_value, $value );
1725
+ }
1726
+ // All other fields
1727
+ else
1728
  return $this->is( $field, $value, $id );
 
1729
 
1730
  return false;
1731
  }
1733
  /**
1734
  * Check if an item field is a specific value
1735
  *
1736
+ * @param string $field Field name
1737
+ * @param mixed $value Value to check
1738
+ * @param int $id (optional) ID of the pod item to check
1739
  *
1740
  * @return bool Whether the value was found
1741
  *
1742
  * @since 2.3.3
1743
  */
1744
+ public function is ( $field, $value, $id = null ) {
 
1745
  $pod =& $this;
1746
 
1747
+ if ( null === $id )
1748
  $id = $this->id();
1749
+ elseif ( $id != $this->id() )
 
1750
  $pod = pods( $this->pod, $id );
 
1751
 
1752
  $this->do_hook( 'is', $field, $value, $id );
1753
 
1754
+ if ( !isset( $this->fields[ $field ] ) )
1755
  return false;
 
1756
 
1757
+ // Tableless fields
1758
+ if ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::tableless_field_types() ) ) {
1759
+ if ( !is_array( $value ) )
1760
  $value = explode( ',', $value );
 
1761
 
1762
  $current_value = array();
1763
 
1764
+ if ( 'pick' == $this->fields[ $field ][ 'type' ] && in_array( $this->fields[ $field ][ 'pick_object' ], PodsForm::simple_tableless_objects() ) ) {
1765
  $current_value = $pod->raw( $field );
1766
 
1767
+ if ( !empty( $current_value ) )
1768
  $current_value = (array) $current_value;
 
1769
 
1770
  foreach ( $current_value as $v ) {
1771
+ if ( in_array( $v, $value ) )
 
1772
  return true;
 
1773
  }
1774
+ }
1775
+ else {
1776
+ $related_ids = $this->api->lookup_related_items( $this->fields[ $field ][ 'id' ], $this->pod_data[ 'id' ], $id, $this->fields[ $field ], $this->pod_data );
1777
 
1778
  foreach ( $value as $k => $v ) {
1779
+ if ( !preg_match( '/[^0-9]/', $v ) )
1780
  $value[ $k ] = (int) $v;
1781
+ // @todo Convert slugs into IDs
1782
+ else {
1783
 
1784
+ }
1785
  }
1786
 
1787
  foreach ( $related_ids as $v ) {
1788
+ if ( in_array( $v, $value ) )
 
1789
  return true;
 
1790
  }
1791
+ }
1792
 
1793
+ if ( !empty( $current_value ) )
1794
  $current_value = array_filter( array_unique( $current_value ) );
1795
+ else
1796
  $current_value = array();
 
1797
 
1798
+ if ( !empty( $value ) )
1799
  $value = array_filter( array_unique( $value ) );
1800
+ else
1801
  $value = array();
 
1802
 
1803
  sort( $current_value );
1804
  sort( $value );
1805
 
1806
+ if ( $value === $current_value )
1807
  return true;
1808
+ }
1809
+ // Number fields
1810
+ elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::number_field_types() ) ) {
1811
  $current_value = $pod->raw( $field );
1812
 
1813
+ if ( (float) $current_value === (float) $value )
1814
  return true;
1815
+ }
1816
+ // Date fields
1817
+ elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::date_field_types() ) ) {
1818
  $current_value = $pod->raw( $field );
1819
 
1820
  if ( 0 < strlen( $current_value ) ) {
1821
+ if ( strtotime( $current_value ) == strtotime( $value ) )
1822
  return true;
 
 
 
1823
  }
1824
+ elseif ( empty( $value ) )
1825
+ return true;
1826
+ }
1827
+ // Text fields
1828
+ elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::text_field_types() ) ) {
1829
  $current_value = $pod->raw( $field );
1830
 
1831
+ if ( (string) $current_value === (string) $value )
1832
  return true;
1833
+ }
1834
+ // All other fields
1835
+ else {
1836
  $current_value = $pod->raw( $field );
1837
 
1838
+ if ( $current_value === $value )
1839
  return true;
1840
+ }
 
1841
 
1842
  return false;
1843
  }
1846
  * Return the item ID
1847
  *
1848
  * @return int
1849
+ * @since 2.0
1850
  */
1851
+ public function id () {
1852
+ if ( isset( $this->data->row ) && isset( $this->data->row[ 'id' ] ) ) {
1853
+ // If we already have data loaded return that ID
1854
+ return $this->data->row[ 'id' ];
 
1855
  }
 
1856
  return $this->field( $this->data->field_id );
1857
  }
1858
 
1859
  /**
1860
  * Return the previous item ID, loops at the last id to return the first
1861
  *
1862
+ * @param int $id
1863
+ * @param array $params_override
1864
  *
1865
  * @return int
1866
+ * @since 2.0
1867
  */
1868
+ public function prev_id ( $id = null, $params_override = null ) {
1869
+ if ( null === $id )
 
1870
  $id = $this->id();
 
1871
 
1872
  $id = (int) $id;
1873
 
1874
  $params = array(
1875
+ 'select' => "`t`.`{$this->data->field_id}`",
1876
+ 'where' => "`t`.`{$this->data->field_id}` < {$id}",
1877
  'orderby' => "`t`.`{$this->data->field_id}` DESC",
1878
+ 'limit' => 1
1879
  );
1880
 
1881
+ if ( !empty( $params_override ) || !empty( $this->params ) ) {
1882
+ if ( !empty( $params_override ) )
1883
  $params = $params_override;
1884
+ elseif ( !empty( $this->params ) )
1885
  $params = $this->params;
 
1886
 
1887
  if ( is_object( $params ) ) {
1888
  $params = get_object_vars( $params );
1889
  }
1890
 
1891
  if ( 0 < $id ) {
1892
+ if ( isset( $params[ 'where' ] ) && !empty( $params[ 'where' ] ) ) {
1893
+ $params[ 'where' ] = (array) $params[ 'where' ];
1894
+ $params[ 'where' ][] = "`t`.`{$this->data->field_id}` < {$id}";
1895
+ }
1896
+ else {
1897
+ $params[ 'where' ] = "`t`.`{$this->data->field_id}` < {$id}";
1898
  }
 
 
 
 
 
 
1899
  }
1900
+ elseif ( isset( $params[ 'offset' ] ) && 0 < $params[ 'offset' ] )
1901
+ $params[ 'offset' ] -= 1;
1902
+ elseif ( !isset( $params[ 'offset' ] ) && !empty( $this->params ) && 0 < $this->row_number )
1903
+ $params[ 'offset' ] = $this->row_number - 1;
1904
+ else
1905
+ return 0;
1906
 
1907
+ if ( isset( $params[ 'orderby' ] ) && !empty( $params[ 'orderby' ] ) ) {
1908
+ if ( is_array( $params[ 'orderby' ] ) ) {
1909
+ foreach ( $params[ 'orderby' ] as $orderby => $dir ) {
1910
  $dir = strtoupper( $dir );
1911
 
1912
+ if ( !in_array( $dir, array( 'ASC', 'DESC' ) ) ) {
1913
  continue;
1914
  }
1915
 
1916
+ if ( 'ASC' == $dir ) {
1917
+ $params[ 'orderby' ][ $orderby ] = 'DESC';
1918
+ }
1919
+ else {
1920
+ $params[ 'orderby' ][ $orderby ] = 'ASC';
1921
  }
1922
  }
1923
 
1924
+ $params[ 'orderby' ][ $this->data->field_id ] = 'DESC';
1925
+ }
1926
+ elseif ( "`t`.`{$this->data->field_id}` DESC" != $params[ 'orderby' ] ) {
1927
+ $params[ 'orderby' ] .= ", `t`.`{$this->data->field_id}` DESC";
1928
  }
1929
+ }
1930
 
1931
+ $params[ 'select' ] = "`t`.`{$this->data->field_id}`";
1932
+ $params[ 'limit' ] = 1;
1933
+ }
1934
 
1935
  $pod = pods( $this->pod, $params );
1936
 
1937
  $new_id = 0;
1938
 
1939
+ if ( $pod->fetch() )
1940
  $new_id = $pod->id();
 
1941
 
1942
  $new_id = $this->do_hook( 'prev_id', $new_id, $id, $pod, $params_override );
1943
 
1947
  /**
1948
  * Return the next item ID, loops at the first id to return the last
1949
  *
1950
+ * @param int $id
1951
+ * @param array $find_params
1952
  *
1953
  * @return int
1954
+ * @since 2.0
1955
  */
1956
+ public function next_id ( $id = null, $params_override = null ) {
1957
+ if ( null === $id )
 
1958
  $id = $this->id();
 
1959
 
1960
  $id = (int) $id;
1961
 
1962
  $params = array(
1963
+ 'select' => "`t`.`{$this->data->field_id}`",
1964
+ 'where' => "{$id} < `t`.`{$this->data->field_id}`",
1965
  'orderby' => "`t`.`{$this->data->field_id}` ASC",
1966
+ 'limit' => 1
1967
  );
1968
 
1969
+ if ( !empty( $params_override ) || !empty( $this->params ) ) {
1970
+ if ( !empty( $params_override ) )
1971
  $params = $params_override;
1972
+ elseif ( !empty( $this->params ) )
1973
  $params = $this->params;
 
1974
 
1975
  if ( is_object( $params ) ) {
1976
  $params = get_object_vars( $params );
1977
  }
1978
 
1979
  if ( 0 < $id ) {
1980
+ if ( isset( $params[ 'where' ] ) && !empty( $params[ 'where' ] ) ) {
1981
+ $params[ 'where' ] = (array) $params[ 'where' ];
1982
+ $params[ 'where' ][] = "{$id} < `t`.`{$this->data->field_id}`";
 
 
1983
  }
1984
+ else {
1985
+ $params[ 'where' ] = "{$id} < `t`.`{$this->data->field_id}`";
 
 
 
1986
  }
 
 
1987
  }
1988
+ elseif ( !isset( $params[ 'offset' ] ) ) {
1989
+ if ( !empty( $this->params ) && -1 < $this->row_number )
1990
+ $params[ 'offset' ] = $this->row_number + 1;
1991
+ else
1992
+ $params[ 'offset' ] = 1;
1993
+ }
1994
+ else
1995
+ $params[ 'offset' ] += 1;
1996
 
1997
+ $params[ 'select' ] = "`t`.`{$this->data->field_id}`";
1998
+ $params[ 'limit' ] = 1;
1999
+ }
2000
 
2001
  $pod = pods( $this->pod, $params );
2002
 
2003
  $new_id = 0;
2004
 
2005
+ if ( $pod->fetch() )
2006
  $new_id = $pod->id();
 
2007
 
2008
  $new_id = $this->do_hook( 'next_id', $new_id, $id, $pod, $params_override );
2009
 
2013
  /**
2014
  * Return the first item ID
2015
  *
2016
+ * @param array $params_override
2017
  *
2018
  * @return int
2019
+ * @since 2.3
2020
  */
2021
+ public function first_id ( $params_override = null ) {
 
2022
  $params = array(
2023
+ 'select' => "`t`.`{$this->data->field_id}`",
2024
  'orderby' => "`t`.`{$this->data->field_id}` ASC",
2025
+ 'limit' => 1
2026
  );
2027
 
2028
+ if ( !empty( $params_override ) || !empty( $this->params ) ) {
2029
+ if ( !empty( $params_override ) )
2030
  $params = $params_override;
2031
+ elseif ( !empty( $this->params ) )
2032
  $params = $this->params;
 
2033
 
2034
  if ( is_object( $params ) ) {
2035
  $params = get_object_vars( $params );
2036
  }
2037
 
2038
+ $params[ 'select' ] = "`t`.`{$this->data->field_id}`";
2039
+ $params[ 'offset' ] = 0;
2040
+ $params[ 'limit' ] = 1;
2041
  }
2042
 
2043
  $pod = pods( $this->pod, $params );
2044
 
2045
  $new_id = 0;
2046
 
2047
+ if ( $pod->fetch() )
2048
  $new_id = $pod->id();
 
2049
 
2050
  $new_id = $this->do_hook( 'first_id', $new_id, $pod, $params_override );
2051
 
2055
  /**
2056
  * Return the last item ID
2057
  *
2058
+ * @param array $params_override
2059
  *
2060
  * @return int
2061
+ * @since 2.3
2062
  */
2063
+ public function last_id ( $params_override = null ) {
 
2064
  $params = array(
2065
+ 'select' => "`t`.`{$this->data->field_id}`",
2066
  'orderby' => "`t`.`{$this->data->field_id}` DESC",
2067
+ 'limit' => 1
2068
  );
2069
 
2070
+ if ( !empty( $params_override ) || !empty( $this->params ) ) {
2071
+ if ( !empty( $params_override ) )
2072
  $params = $params_override;
2073
+ elseif ( !empty( $this->params ) )
2074
  $params = $this->params;
 
2075
 
2076
  if ( is_object( $params ) ) {
2077
  $params = get_object_vars( $params );
2078
  }
2079
 
2080
+ if ( isset( $params[ 'total_found' ] ) )
2081
+ $params[ 'offset' ] = $params[ 'total_found' ] - 1;
2082
+ else
2083
+ $params[ 'offset' ] = $this->total_found() - 1;
 
2084
 
2085
+ if ( isset( $params[ 'orderby' ] ) && !empty( $params[ 'orderby' ] ) ) {
2086
+ if ( is_array( $params[ 'orderby' ] ) ) {
2087
+ foreach ( $params[ 'orderby' ] as $orderby => $dir ) {
2088
  $dir = strtoupper( $dir );
2089
 
2090
+ if ( !in_array( $dir, array( 'ASC', 'DESC' ) ) ) {
2091
  continue;
2092
  }
2093
 
2094
+ if ( 'ASC' == $dir ) {
2095
+ $params[ 'orderby' ][ $orderby ] = 'DESC';
2096
+ }
2097
+ else {
2098
+ $params[ 'orderby' ][ $orderby ] = 'ASC';
2099
  }
2100
  }
2101
 
2102
+ $params[ 'orderby' ][ $this->data->field_id ] = 'DESC';
 
 
2103
  }
2104
+ elseif ( "`t`.`{$this->data->field_id}` DESC" != $params[ 'orderby' ] ) {
2105
+ $params[ 'orderby' ] .= ", `t`.`{$this->data->field_id}` DESC";
2106
+ }
2107
+ }
2108
 
2109
+ $params[ 'select' ] = "`t`.`{$this->data->field_id}`";
2110
+ $params[ 'limit' ] = 1;
2111
+ }
2112
 
2113
  $pod = pods( $this->pod, $params );
2114
 
2115
  $new_id = 0;
2116
 
2117
+ if ( $pod->fetch() )
2118
  $new_id = $pod->id();
 
2119
 
2120
  $new_id = $this->do_hook( 'last_id', $new_id, $pod, $params_override );
 
2121
  return $new_id;
2122
  }
2123
 
2125
  * Return the item name
2126
  *
2127
  * @return string
2128
+ * @since 2.0
2129
  */
2130
+ public function index () {
 
2131
  return $this->field( $this->data->field_index );
2132
  }
2133
 
2134
  /**
2135
  * Find items of a pod, much like WP_Query, but with advanced table handling.
2136
  *
2137
+ * @param array $params An associative array of parameters
2138
+ * @param int $limit (optional) (deprecated) Limit the number of items to find, use -1 to return all items with no limit
2139
+ * @param string $where (optional) (deprecated) SQL WHERE declaration to use
2140
+ * @param string $sql (optional) (deprecated) For advanced use, a custom SQL query to run
2141
  *
2142
  * @return \Pods The pod object
2143
+ * @since 2.0
2144
+ * @link http://pods.io/docs/find/
2145
  */
2146
+ public function find ( $params = null, $limit = 15, $where = null, $sql = null ) {
2147
 
2148
+ $tableless_field_types = PodsForm::tableless_field_types();
2149
  $simple_tableless_objects = PodsForm::simple_tableless_objects();
2150
 
2151
+
2152
  $this->params = $params;
2153
 
2154
  $select = '`t`.*';
2155
 
2156
+ if ( !in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) && 'table' == $this->pod_data[ 'storage' ] )
 
 
 
2157
  $select .= ', `d`.*';
 
2158
 
2159
+ if ( empty( $this->data->table ) )
2160
  return $this;
 
2161
 
2162
  $defaults = array(
2163
+ 'table' => $this->data->table,
2164
+ 'select' => $select,
2165
+ 'join' => null,
2166
+
2167
+ 'where' => $where,
2168
+ 'groupby' => null,
2169
+ 'having' => null,
2170
+ 'orderby' => null,
2171
+
2172
+ 'limit' => (int) $limit,
2173
+ 'offset' => null,
2174
+ 'page' => (int) $this->page,
2175
+ 'page_var' => $this->page_var,
2176
+ 'pagination' => (boolean) $this->pagination,
2177
+
2178
+ 'search' => (boolean) $this->search,
2179
+ 'search_var' => $this->search_var,
2180
+ 'search_query' => null,
2181
+ 'search_mode' => $this->search_mode,
2182
+ 'search_across' => false,
 
2183
  'search_across_picks' => false,
2184
  'search_across_files' => false,
2185
+
2186
+ 'filters' => $this->filters,
2187
+ 'sql' => $sql,
2188
+
2189
+ 'expires' => null,
2190
+ 'cache_mode' => 'cache'
2191
  );
2192
 
2193
+ if ( is_array( $params ) )
2194
  $params = (object) array_merge( $defaults, $params );
2195
+ if ( is_object( $params ) )
2196
  $params = (object) array_merge( $defaults, get_object_vars( $params ) );
2197
+ else {
2198
+ $defaults[ 'orderby' ] = $params;
 
2199
  $params = (object) $defaults;
2200
  }
2201
 
 
 
 
 
 
2202
  $params = apply_filters( 'pods_pods_find', $params );
2203
 
2204
  $params->limit = (int) $params->limit;
2205
 
2206
+ if ( 0 == $params->limit )
2207
+ $params->limit = -1;
 
2208
 
2209
+ $this->limit = (int) $params->limit;
2210
+ $this->offset = (int) $params->offset;
2211
+ $this->page = (int) $params->page;
2212
+ $this->page_var = $params->page_var;
2213
  $this->pagination = (boolean) $params->pagination;
2214
+ $this->search = (boolean) $params->search;
2215
  $this->search_var = $params->search_var;
2216
+ $params->join = (array) $params->join;
2217
 
2218
+ if ( empty( $params->search_query ) )
2219
+ $params->search_query = pods_var( $this->search_var, 'get', '' );
 
2220
 
2221
+ // Allow orderby array ( 'field' => 'asc|desc' )
2222
+ if ( !empty( $params->orderby ) && is_array( $params->orderby ) ) {
2223
+ foreach ( $params->orderby as $k => &$orderby ) {
2224
+ if ( !is_numeric( $k ) ) {
2225
  $key = '';
2226
 
2227
  $order = 'ASC';
2228
 
2229
+ if ( 'DESC' == strtoupper( $orderby ) )
2230
  $order = 'DESC';
 
2231
 
2232
+ if ( isset( $this->fields[ $k ] ) && in_array( $this->fields[ $k ][ 'type' ], $tableless_field_types ) ) {
2233
+ if ( in_array( $this->fields[ $k ][ 'pick_object' ], $simple_tableless_objects ) ) {
2234
+ if ( 'table' == $this->pod_data[ 'storage' ] ) {
2235
+ if ( !in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) )
2236
  $key = "`d`.`{$k}`";
2237
+ else
2238
  $key = "`t`.`{$k}`";
 
 
 
2239
  }
2240
+ else
2241
+ $key = "`{$k}`.`meta_value`";
2242
+ }
2243
+ else {
2244
+ $pick_val = $this->fields[ $k ][ 'pick_val' ];
2245
 
2246
+ if ( '__current__' == $pick_val )
2247
  $pick_val = $this->pod;
 
2248
 
2249
+ $table = $this->api->get_table_info( $this->fields[ $k ][ 'pick_object' ], $pick_val );
2250
 
2251
+ if ( !empty( $table ) )
2252
+ $key = "`{$k}`.`" . $table[ 'field_index' ] . '`';
2253
+ }
2254
+ }
 
2255
 
2256
  if ( empty( $key ) ) {
2257
+ if ( !in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) ) {
2258
+ if ( isset( $this->pod_data[ 'object_fields' ][ $k ] ) )
2259
  $key = "`t`.`{$k}`";
2260
+ elseif ( isset( $this->fields[ $k ] ) ) {
2261
+ if ( 'table' == $this->pod_data[ 'storage' ] )
2262
  $key = "`d`.`{$k}`";
2263
+ else
2264
  $key = "`{$k}`.`meta_value`";
2265
+ }
2266
+ else {
2267
+ foreach ( $this->pod_data[ 'object_fields' ] as $object_field => $object_field_opt ) {
2268
+ if ( $object_field == $k || in_array( $k, $object_field_opt[ 'alias' ] ) )
 
 
2269
  $key = "`t`.`{$object_field}`";
 
2270
  }
2271
  }
2272
+ }
2273
+ elseif ( isset( $this->fields[ $k ] ) ) {
2274
+ if ( 'table' == $this->pod_data[ 'storage' ] )
2275
  $key = "`t`.`{$k}`";
2276
+ else
2277
  $key = "`{$k}`.`meta_value`";
2278
+ }
 
2279
 
2280
  if ( empty( $key ) ) {
2281
  $key = $k;
2282
 
2283
+ if ( false === strpos( $key, ' ' ) && false === strpos( $key, '`' ) )
2284
  $key = '`' . str_replace( '.', '`.`', $key ) . '`';
 
2285
  }
2286
+ }
2287
 
2288
  $orderby = $key;
2289
 
2290
+ if ( false === strpos( $orderby, ' ' ) )
2291
  $orderby .= ' ' . $order;
2292
+ }
2293
+ }
2294
+ }
 
 
 
2295
 
2296
+ // Add prefix to $params->orderby if needed
2297
+ if ( !empty( $params->orderby ) ) {
2298
+ if ( !is_array( $params->orderby ) )
2299
  $params->orderby = array( $params->orderby );
 
2300
 
2301
+ foreach ( $params->orderby as &$prefix_orderby ) {
2302
  if ( false === strpos( $prefix_orderby, ',' ) && false === strpos( $prefix_orderby, '(' ) && false === stripos( $prefix_orderby, ' AS ' ) && false === strpos( $prefix_orderby, '`' ) && false === strpos( $prefix_orderby, '.' ) ) {
2303
  if ( false !== stripos( $prefix_orderby, ' DESC' ) ) {
2304
+ $k = trim( str_ireplace( array( '`', ' DESC' ), '', $prefix_orderby ) );
2305
  $dir = 'DESC';
2306
+ }
2307
+ else {
2308
+ $k = trim( str_ireplace( array( '`', ' ASC' ), '', $prefix_orderby ) );
2309
  $dir = 'ASC';
2310
  }
2311
 
2312
  $key = $k;
2313
 
2314
+ if ( !in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) ) {
2315
+ if ( isset( $this->pod_data[ 'object_fields' ][ $k ] ) )
2316
  $key = "`t`.`{$k}`";
2317
+ elseif ( isset( $this->fields[ $k ] ) ) {
2318
+ if ( 'table' == $this->pod_data[ 'storage' ] )
2319
  $key = "`d`.`{$k}`";
2320
+ else
2321
  $key = "`{$k}`.`meta_value`";
2322
+ }
2323
+ else {
2324
+ foreach ( $this->pod_data[ 'object_fields' ] as $object_field => $object_field_opt ) {
2325
+ if ( $object_field == $k || in_array( $k, $object_field_opt[ 'alias' ] ) )
 
 
2326
  $key = "`t`.`{$object_field}`";
 
2327
  }
2328
  }
2329
+ }
2330
+ elseif ( isset( $this->fields[ $k ] ) ) {
2331
+ if ( 'table' == $this->pod_data[ 'storage' ] )
2332
  $key = "`t`.`{$k}`";
2333
+ else
2334
  $key = "`{$k}`.`meta_value`";
2335
+ }
 
2336
 
2337
  $prefix_orderby = "{$key} {$dir}";
2338
+ }
2339
+ }
2340
+ }
 
 
2341
 
2342
  $this->data->select( $params );
2343
 
2348
  * Fetch an item from a Pod. If $id is null, it will return the next item in the list after running find().
2349
  * You can rewind the list back to the start by using reset().
2350
  *
2351
+ * Providing an $id will fetch a specific item from a Pod, much like a call to pods(), and can handle either an id or slug.
 
2352
  *
2353
+ * @see PodsData::fetch
2354
  *
2355
+ * @param int $id ID or slug of the item to fetch
2356
+ * @param bool $explicit_set Whether to set explicitly (use false when in loop)
2357
  *
2358
  * @return array An array of fields from the row
2359
  *
2360
+ * @since 2.0
2361
+ * @link http://pods.io/docs/fetch/
2362
  */
2363
+ public function fetch ( $id = null, $explicit_set = true ) {
 
2364
  /**
2365
+ * Runs directly before an item is fetched by fetch()
2366
  *
2367
  * @since unknown
2368
  *
2369
+ * @param int|string|null $id Item ID being fetched or null.
2370
+ * @param object|Pods $this Current Pods object.
2371
  */
2372
  do_action( 'pods_pods_fetch', $id, $this );
2373
 
2374
+ if ( !empty( $id ) )
2375
  $this->params = array();
 
2376
 
2377
  $this->data->fetch( $id, $explicit_set );
2378
 
2382
  /**
2383
  * (Re)set the MySQL result pointer
2384
  *
2385
+ * @see PodsData::reset
2386
  *
2387
+ * @param int $row ID of the row to reset to
2388
  *
2389
  * @return \Pods The pod object
2390
  *
2391
+ * @since 2.0
2392
+ * @link http://pods.io/docs/reset/
2393
  */
2394
+ public function reset ( $row = null ) {
 
2395
  /**
2396
  * Runs directly before the Pods object is reset by reset()
2397
  *
2398
  * @since unknown
2399
  *
2400
+ * @param int|string|null The ID of the row being reset to or null if being reset to the beginningg.
2401
  * @param object|Pods $this Current Pods object.
2402
  */
2403
  do_action( 'pods_pods_reset', $row, $this );
2412
  *
2413
  * This is different than the total number of rows found in the database, which you can get with total_found().
2414
  *
2415
+ * @see PodsData::total
2416
  *
2417
  * @return int Number of rows returned by find(), based on the 'limit' parameter set
2418
+ * @since 2.0
2419
+ * @link http://pods.io/docs/total/
2420
  */
2421
+ public function total () {
 
2422
  do_action( 'pods_pods_total', $this );
2423
 
2424
  $this->data->total();
2433
  *
2434
  * This is different than the total number of rows limited by the current call, which you can get with total().
2435
  *
2436
+ * @see PodsData::total_found
2437
  *
2438
  * @return int Number of rows returned by find(), regardless of the 'limit' parameter
2439
+ * @since 2.0
2440
+ * @link http://pods.io/docs/total-found/
2441
  */
2442
+ public function total_found () {
 
2443
  /**
2444
  * Runs directly before the value of total_found() is determined and returned.
2445
  *
2446
  * @since unknown
2447
  *
2448
  * @param object|Pods $this Current Pods object.
2449
+ *
2450
  */
2451
  do_action( 'pods_pods_total_found', $this );
2452
 
2460
  /**
2461
  * Fetch the total number of pages, based on total rows found and the last find() limit
2462
  *
2463
+ * @param null|int $limit Rows per page
2464
+ * @param null|int $offset Offset of rows
2465
+ * @param null|int $total Total rows
2466
  *
2467
  * @return int Number of pages
2468
  * @since 2.3.10
2483
  $total = $this->total_found();
2484
  }
2485
 
2486
+ $total_pages = ceil( ( $total - $offset ) / $limit );
2487
+
2488
+ return $total_pages;
2489
 
2490
  }
2491
 
2492
  /**
2493
  * Fetch the zebra switch
2494
  *
2495
+ * @see PodsData::zebra
2496
  *
2497
  * @return bool Zebra state
2498
  * @since 1.12
2499
  */
2500
+ public function zebra () {
 
2501
  $this->do_hook( 'zebra' );
2502
 
2503
  return $this->data->zebra();
2506
  /**
2507
  * Fetch the nth state
2508
  *
2509
+ * @see PodsData::nth
2510
  *
2511
+ * @param int|string $nth The $nth to match on the PodsData::row_number
2512
  *
2513
  * @return bool Whether $nth matches
2514
+ * @since 2.3
2515
  */
2516
+ public function nth ( $nth = null ) {
 
2517
  $this->do_hook( 'nth', $nth );
2518
 
2519
  return $this->data->nth( $nth );
2522
  /**
2523
  * Fetch the current position in the loop (starting at 1)
2524
  *
2525
+ * @see PodsData::position
2526
  *
2527
  * @return int Current row number (+1)
2528
+ * @since 2.3
2529
  */
2530
+ public function position () {
 
2531
  $this->do_hook( 'position' );
2532
 
2533
  return $this->data->position();
2539
  *
2540
  * You may be looking for save() in most cases where you're setting a specific field.
2541
  *
2542
+ * @see PodsAPI::save_pod_item
2543
  *
2544
+ * @param array|string $data Either an associative array of field information or a field name
2545
+ * @param mixed $value (optional) Value of the field, if $data is a field name
2546
  *
2547
  * @return int The item ID
2548
  *
2549
+ * @since 2.0
2550
+ * @link http://pods.io/docs/add/
2551
  */
2552
+ public function add ( $data = null, $value = null ) {
2553
+ if ( null !== $value )
 
2554
  $data = array( $data => $value );
 
2555
 
2556
  $data = (array) $this->do_hook( 'add', $data );
2557
 
2558
+ if ( empty( $data ) )
2559
  return 0;
 
2560
 
2561
  $params = array(
2562
+ 'pod' => $this->pod,
2563
+ 'data' => $data,
2564
+ 'allow_custom_fields' => true
2565
  );
2566
 
2567
  return $this->api->save_pod_item( $params );
2568
  }
2569
 
2570
  /**
2571
+ * Add an item to the values of a relationship field, add a value to a number field (field+1), add time to a date field, or add text to a text field
 
2572
  *
2573
+ * @see PodsAPI::save_pod_item
2574
  *
2575
+ * @param string $field Field name
2576
+ * @param mixed $value ID(s) to add, int|float to add to number field, string for dates (+1 week), or string for text
2577
+ * @param int $id (optional) ID of the pod item to update
2578
  *
2579
  * @return int The item ID
2580
  *
2581
+ * @since 2.3
2582
  */
2583
+ public function add_to ( $field, $value, $id = null ) {
 
2584
  $pod =& $this;
2585
 
2586
  $fetch = false;
2589
  $fetch = true;
2590
 
2591
  $id = $pod->id();
2592
+ }
2593
+ elseif ( $id != $this->id() ) {
2594
  $pod = pods( $this->pod, $id );
2595
  }
2596
 
2597
  $this->do_hook( 'add_to', $field, $value, $id );
2598
 
2599
+ if ( !isset( $this->fields[ $field ] ) )
2600
  return $id;
 
2601
 
2602
+ // Tableless fields
2603
+ if ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::tableless_field_types() ) ) {
2604
+ if ( !is_array( $value ) )
2605
  $value = explode( ',', $value );
 
2606
 
2607
+ if ( 'pick' == $this->fields[ $field ][ 'type' ] && in_array( $this->fields[ $field ][ 'pick_object' ], PodsForm::simple_tableless_objects() ) ) {
2608
  $current_value = $pod->raw( $field );
2609
 
2610
+ if ( !empty( $current_value ) || ( !is_array( $current_value ) && 0 < strlen( $current_value ) ) )
2611
  $current_value = (array) $current_value;
2612
+ else
2613
  $current_value = array();
 
2614
 
2615
  $value = array_merge( $current_value, $value );
2616
+ }
2617
+ else {
2618
+ $related_ids = $this->api->lookup_related_items( $this->fields[ $field ][ 'id' ], $this->pod_data[ 'id' ], $id, $this->fields[ $field ], $this->pod_data );
2619
 
2620
  foreach ( $value as $k => $v ) {
2621
+ if ( !preg_match( '/[^0-9]/', $v ) )
2622
  $value[ $k ] = (int) $v;
 
2623
  }
2624
 
2625
  $value = array_merge( $related_ids, $value );
2626
+ }
2627
 
2628
+ if ( !empty( $value ) )
2629
  $value = array_filter( array_unique( $value ) );
2630
+ else
2631
  $value = array();
 
2632
 
2633
+ if ( empty( $value ) )
2634
  return $id;
2635
+ }
2636
+ // Number fields
2637
+ elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::number_field_types() ) ) {
2638
  $current_value = (float) $pod->raw( $field );
2639
 
2640
  $value = ( $current_value + (float) $value );
2641
+ }
2642
+ // Date fields
2643
+ elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::date_field_types() ) ) {
2644
  $current_value = $pod->raw( $field );
2645
 
2646
+ if ( 0 < strlen( $current_value ) )
2647
  $value = strtotime( $value, strtotime( $current_value ) );
2648
+ else
2649
  $value = strtotime( $value );
2650
+ }
2651
+ // Text fields
2652
+ elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::text_field_types() ) ) {
2653
  $current_value = $pod->raw( $field );
2654
 
2655
+ if ( 0 < strlen( $current_value ) )
2656
  $value = $current_value . $value;
2657
+ }
2658
+
2659
+ // @todo handle object fields and taxonomies
2660
 
 
2661
  $params = array(
2662
+ 'pod' => $this->pod,
2663
+ 'id' => $id,
2664
  'data' => array(
2665
+ $field => $value
2666
+ )
2667
  );
2668
 
2669
  $id = $this->api->save_pod_item( $params );
2670
 
2671
  if ( 0 < $id && $fetch ) {
2672
+ // Clear local var cache of field values
2673
  $pod->data->row = array();
2674
 
2675
  $pod->fetch( $id, false );
2679
  }
2680
 
2681
  /**
2682
+ * Remove an item from the values of a relationship field, remove a value from a number field (field-1), remove time to a date field
 
2683
  *
2684
+ * @see PodsAPI::save_pod_item
2685
  *
2686
+ * @param string $field Field name
2687
+ * @param mixed $value ID(s) to add, int|float to add to number field, string for dates (-1 week), or string for text
2688
+ * @param int $id (optional) ID of the pod item to update
2689
  *
2690
  * @return int The item ID
2691
  *
2692
  * @since 2.3.3
2693
  */
2694
  public function remove_from( $field, $value = null, $id = null ) {
 
2695
  $pod =& $this;
2696
 
2697
  $fetch = false;
2700
  $fetch = true;
2701
 
2702
  $id = $this->id();
2703
+ }
2704
+ elseif ( $id != $this->id() ) {
2705
  $pod = pods( $this->pod, $id );
2706
  }
2707
 
2708
  $this->do_hook( 'remove_from', $field, $value, $id );
2709
 
2710
+ if ( !isset( $this->fields[ $field ] ) ) {
2711
  return $id;
2712
  }
2713
 
2714
+ // Tableless fields
2715
+ if ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::tableless_field_types() ) ) {
2716
  if ( empty( $value ) ) {
2717
  $value = array();
2718
  }
2719
 
2720
+ if ( !empty( $value ) ) {
2721
+ if ( !is_array( $value ) ) {
2722
  $value = explode( ',', $value );
2723
  }
2724
 
2725
+ if ( 'pick' == $this->fields[ $field ][ 'type' ] && in_array( $this->fields[ $field ][ 'pick_object' ], PodsForm::simple_tableless_objects() ) ) {
2726
  $current_value = $pod->raw( $field );
2727
 
2728
+ if ( !empty( $current_value ) ) {
2729
  $current_value = (array) $current_value;
2730
  }
2731
 
2732
  foreach ( $current_value as $k => $v ) {
 
2733
  if ( in_array( $v, $value ) ) {
2734
  unset( $current_value[ $k ] );
2735
  }
2736
  }
2737
 
2738
  $value = $current_value;
2739
+ }
2740
+ else {
2741
+ $related_ids = $this->api->lookup_related_items( $this->fields[ $field ][ 'id' ], $this->pod_data[ 'id' ], $id, $this->fields[ $field ], $this->pod_data );
2742
 
2743
  foreach ( $value as $k => $v ) {
2744
+ if ( !preg_match( '/[^0-9]/', $v ) ) {
2745
  $value[ $k ] = (int) $v;
2746
  }
2747
+ // @todo Convert slugs into IDs
2748
+ else {
2749
 
2750
+ }
2751
  }
2752
 
2753
  foreach ( $related_ids as $k => $v ) {
 
2754
  if ( in_array( $v, $value ) ) {
2755
  unset( $related_ids[ $k ] );
2756
  }
2757
  }
2758
 
2759
  $value = $related_ids;
2760
+ }
2761
 
2762
+ if ( !empty( $value ) ) {
2763
  $value = array_filter( array_unique( $value ) );
2764
+ }
2765
+ else {
2766
  $value = array();
2767
  }
2768
+ }
2769
+ }
2770
+ // Number fields
2771
+ elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::number_field_types() ) ) {
2772
+ // Date fields don't support empty for removing
2773
  if ( empty( $value ) ) {
2774
  return $id;
2775
  }
2777
  $current_value = (float) $pod->raw( $field );
2778
 
2779
  $value = ( $current_value - (float) $value );
2780
+ }
2781
+ // Date fields
2782
+ elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::date_field_types() ) ) {
2783
+ // Date fields don't support empty for removing
2784
  if ( empty( $value ) ) {
2785
  return $id;
2786
  }
2789
 
2790
  if ( 0 < strlen( $current_value ) ) {
2791
  $value = strtotime( $value, strtotime( $current_value ) );
2792
+ }
2793
+ else {
2794
  $value = strtotime( $value );
2795
  }
2796
 
2797
  $value = date_i18n( 'Y-m-d h:i:s', $value );
2798
+ }
2799
+
2800
+ // @todo handle object fields and taxonomies
2801
 
 
2802
  $params = array(
2803
+ 'pod' => $this->pod,
2804
+ 'id' => $id,
2805
  'data' => array(
2806
+ $field => $value
2807
+ )
2808
  );
2809
 
2810
  $id = $this->api->save_pod_item( $params );
2811
 
2812
  if ( 0 < $id && $fetch ) {
2813
+ // Clear local var cache of field values
2814
  $pod->data->row = array();
2815
 
2816
  $pod->fetch( $id, false );
2826
  * Though this function has the capacity to add new items, best practice should direct you
2827
  * to use add() for that instead.
2828
  *
2829
+ * @see PodsAPI::save_pod_item
2830
  *
2831
+ * @param array|string $data Either an associative array of field information or a field name
2832
+ * @param mixed $value (optional) Value of the field, if $data is a field name
2833
+ * @param int $id (optional) ID of the pod item to update
2834
+ * @param array $params (optional) Additional params to send to save_pod_item
2835
  *
2836
  * @return int The item ID
2837
  *
2838
+ * @since 2.0
2839
+ * @link http://pods.io/docs/save/
2840
  */
2841
+ public function save ( $data = null, $value = null, $id = null, $params = null ) {
2842
+ if ( null !== $value )
 
2843
  $data = array( $data => $value );
 
2844
 
2845
  $fetch = false;
2846
 
 
2847
  if ( null === $id || ( $this->row && $id == $this->id() ) ) {
2848
  $fetch = true;
2849
 
2854
 
2855
  $data = (array) $this->do_hook( 'save', $data, $id );
2856
 
2857
+ if ( empty( $data ) && empty( $params['is_new_item'] ) )
2858
  return $id;
 
2859
 
2860
  $default = array();
2861
 
2862
+ if ( !empty( $params ) && is_array( $params ) )
2863
  $default = $params;
 
2864
 
2865
  $params = array(
2866
+ 'pod' => $this->pod,
2867
+ 'id' => $id,
2868
+ 'data' => $data,
2869
  'allow_custom_fields' => true,
2870
+ 'clear_slug_cache' => false
2871
  );
2872
 
2873
+ if ( !empty( $default ) )
2874
  $params = array_merge( $params, $default );
 
2875
 
2876
  $id = $this->api->save_pod_item( $params );
2877
 
2878
  if ( 0 < $id && $fetch ) {
2879
+ // Clear local var cache of field values
2880
  $this->data->row = array();
2881
 
2882
  $this->fetch( $id, false );
2883
  }
2884
 
2885
+ if ( !empty( $this->pod_data[ 'field_slug' ] ) ) {
2886
  if ( 0 < $id && $fetch ) {
2887
+ $slug = $this->field( $this->pod_data[ 'field_slug' ] );
2888
+ }
2889
+ else {
2890
+ $slug = pods( $this->pod, $id )->field( $this->pod_data[ 'field_slug' ] );
2891
  }
2892
 
2893
  if ( 0 < strlen( $slug ) ) {
2901
  /**
2902
  * Delete an item
2903
  *
2904
+ * @see PodsAPI::delete_pod_item
2905
  *
2906
+ * @param int $id ID of the Pod item to delete
2907
  *
2908
  * @return bool Whether the item was successfully deleted
2909
  *
2910
+ * @since 2.0
2911
+ * @link http://pods.io/docs/delete/
2912
  */
2913
+ public function delete ( $id = null ) {
2914
+ if ( null === $id )
 
2915
  $id = $this->id();
 
2916
 
2917
  $id = (int) $this->do_hook( 'delete', $id );
2918
 
2919
+ if ( empty( $id ) )
2920
  return false;
 
2921
 
2922
  $params = array(
2923
  'pod' => $this->pod,
2924
+ 'id' => $id
2925
  );
2926
 
2927
  return $this->api->delete_pod_item( $params );
2930
  /**
2931
  * Reset Pod
2932
  *
2933
+ * @see PodsAPI::reset_pod
2934
  *
2935
  * @return bool Whether the Pod was successfully reset
2936
  *
2937
  * @since 2.1.1
2938
  */
2939
+ public function reset_pod () {
 
2940
  $params = array( 'id' => $this->pod_id );
2941
 
2942
+ $this->data->id = null;
2943
+ $this->data->row = array();
2944
  $this->data->data = array();
2945
 
2946
+ $this->data->total = 0;
2947
  $this->data->total_found = 0;
2948
 
2949
  return $this->api->reset_pod( $params );
2952
  /**
2953
  * Duplicate an item
2954
  *
2955
+ * @see PodsAPI::duplicate_pod_item
2956
  *
2957
+ * @param int $id ID of the pod item to duplicate
2958
  *
2959
  * @return int|bool ID of the new pod item
2960
  *
2961
+ * @since 2.0
2962
+ * @link http://pods.io/docs/duplicate/
2963
  */
2964
+ public function duplicate ( $id = null ) {
2965
+ if ( null === $id )
 
2966
  $id = $this->id();
 
2967
 
2968
  $id = (int) $this->do_hook( 'duplicate', $id );
2969
 
2970
+ if ( empty( $id ) )
2971
  return false;
 
2972
 
2973
  $params = array(
2974
  'pod' => $this->pod,
2975
+ 'id' => $id
2976
  );
2977
 
2978
  return $this->api->duplicate_pod_item( $params );
2981
  /**
2982
  * Import data / Save multiple rows of data at once
2983
  *
2984
+ * @see PodsAPI::import
2985
  *
2986
+ * @param mixed $import_data PHP associative array or CSV input
2987
+ * @param bool $numeric_mode Use IDs instead of the name field when matching
2988
+ * @param string $format Format of import data, options are php or csv
2989
  *
2990
  * @return array IDs of imported items
2991
  *
2992
+ * @since 2.3
2993
  */
2994
+ public function import ( $import_data, $numeric_mode = false, $format = null ) {
 
2995
  return $this->api->import( $import_data, $numeric_mode, $format );
2996
  }
2997
 
2998
  /**
2999
  * Export an item's data
3000
  *
3001
+ * @see PodsAPI::export_pod_item
3002
  *
3003
+ * @param array $fields (optional) Fields to export
3004
+ * @param int $id (optional) ID of the pod item to export
 
3005
  *
3006
  * @return array|bool Data array of the exported pod item
3007
  *
3008
+ * @since 2.0
3009
+ * @link http://pods.io/docs/export/
3010
  */
3011
+ public function export ( $fields = null, $id = null, $format = null ) {
 
3012
  $params = array(
3013
+ 'pod' => $this->pod,
3014
+ 'id' => $id,
3015
+ 'fields' => null,
3016
+ 'depth' => 2,
3017
+ 'flatten' => false
 
 
3018
  );
3019
 
3020
+ if ( is_array( $fields ) && ( isset( $fields[ 'fields' ] ) || isset( $fields[ 'depth' ] ) ) )
3021
  $params = array_merge( $params, $fields );
3022
+ else
3023
+ $params[ 'fields' ] = $fields;
 
3024
 
3025
+ if ( isset( $params[ 'fields' ] ) && is_array( $params[ 'fields' ] ) && !in_array( $this->pod_data[ 'field_id' ], $params[ 'fields' ] ) )
3026
+ $params[ 'fields' ] = array_merge( array( $this->pod_data[ 'field_id' ] ), $params[ 'fields' ] );
 
3027
 
3028
+ if ( null === $params[ 'id' ] )
3029
+ $params[ 'id' ] = $this->id();
 
3030
 
3031
  $params = (array) $this->do_hook( 'export', $params );
3032
 
3033
+ if ( empty( $params[ 'id' ] ) )
3034
  return false;
 
3035
 
3036
  $data = $this->api->export_pod_item( $params );
3037
 
3038
+ if ( !empty( $format ) ) {
3039
+ if ( 'json' == $format )
3040
+ $data = json_encode( (array) $data );
3041
+ // @todo more formats
3042
  }
3043
 
3044
  return $data;
3047
  /**
3048
  * Export data from all items
3049
  *
3050
+ * @see PodsAPI::export
3051
  *
3052
+ * @param array $params An associative array of parameters
3053
  *
3054
  * @return array Data arrays of all exported pod items
3055
  *
3056
+ * @since 2.3
3057
  */
3058
+ public function export_data ( $params = null ) {
 
3059
  $defaults = array(
3060
  'fields' => null,
3061
+ 'depth' => 2,
3062
+ 'params' => null
3063
  );
3064
 
3065
+ if ( empty( $params ) )
3066
  $params = $defaults;
3067
+ else
3068
  $params = array_merge( $defaults, (array) $params );
 
3069
 
3070
  return $this->api->export( $this, $params );
3071
  }
3075
  * are simple, paginate and advanced. The base and format parameters
3076
  * are used only for the paginate view.
3077
  *
3078
+ * @var array $params Associative array of parameters
3079
  *
3080
  * @return string Pagination HTML
3081
+ * @since 2.0
3082
+ * @link http://pods.io/docs/pagination/
3083
  */
3084
  public function pagination( $params = null ) {
3085
 
3086
  if ( empty( $params ) ) {
3087
  $params = array();
3088
+ }
3089
+ elseif ( !is_array( $params ) ) {
3090
  $params = array( 'label' => $params );
3091
  }
3092
 
3093
+ $this->page_var = pods_var_raw( 'page_var', $params, $this->page_var );
3094
 
3095
  $url = pods_query_arg( null, null, $this->page_var );
3096
 
3101
  }
3102
 
3103
  $defaults = array(
3104
+ 'type' => 'advanced',
3105
+ 'label' => __( 'Go to page:', 'pods' ),
3106
+ 'show_label' => true,
3107
+ 'first_text' => __( '&laquo; First', 'pods' ),
3108
+ 'prev_text' => __( '&lsaquo; Previous', 'pods' ),
3109
+ 'next_text' => __( 'Next &rsaquo;', 'pods' ),
3110
+ 'last_text' => __( 'Last &raquo;', 'pods' ),
3111
+ 'prev_next' => true,
3112
+ 'first_last' => true,
3113
+ 'limit' => (int) $this->limit,
3114
+ 'offset' => (int) $this->offset,
3115
+ 'page' => max( 1, (int) $this->page ),
3116
+ 'mid_size' => 2,
3117
+ 'end_size' => 1,
3118
  'total_found' => $this->total_found(),
3119
+ 'page_var' => $this->page_var,
3120
+ 'base' => "{$url}{$append}%_%",
3121
+ 'format' => "{$this->page_var}=%#%",
3122
+ 'class' => '',
3123
+ 'link_class' => ''
3124
  );
3125
 
3126
+ $params = (object) array_merge( $defaults, $params );
 
 
 
 
3127
 
3128
  $params->total = $this->total_pages( $params->limit, $params->offset, $params->total_found );
3129
 
3130
+ if ( $params->limit < 1 || $params->total_found < 1 || 1 == $params->total || $params->total_found <= $params->offset ) {
3131
  return $this->do_hook( 'pagination', $this->do_hook( 'pagination_' . $params->type, '', $params ), $params );
3132
  }
3133
 
3134
  $pagination = $params->type;
3135
 
3136
+ if ( !in_array( $params->type, array( 'simple', 'advanced', 'paginate', 'list' ) ) ) {
3137
  $pagination = 'advanced';
3138
  }
3139
 
3150
  /**
3151
  * Return a filter form for searching a Pod
3152
  *
3153
+ * @var array|string $params Comma-separated list of fields or array of parameters
3154
  *
3155
  * @return string Filters HTML
3156
  *
3157
+ * @since 2.0
3158
+ * @link http://pods.io/docs/filters/
3159
  */
3160
+ public function filters ( $params = null ) {
 
3161
  $defaults = array(
3162
  'fields' => $params,
3163
+ 'label' => '',
3164
  'action' => '',
3165
+ 'search' => ''
3166
  );
3167
 
3168
+ if ( is_array( $params ) )
3169
  $params = array_merge( $defaults, $params );
3170
+ else
3171
  $params = $defaults;
 
3172
 
3173
  $pod =& $this;
3174
 
 
 
 
 
 
 
3175
  $params = apply_filters( 'pods_filters_params', $params, $pod );
3176
 
3177
+ $fields = $params[ 'fields' ];
3178
 
3179
+ if ( null !== $fields && !is_array( $fields ) && 0 < strlen( $fields ) )
3180
  $fields = explode( ',', $fields );
 
3181
 
3182
+ $object_fields = (array) pods_var_raw( 'object_fields', $this->pod_data, array(), null, true );
3183
 
3184
+ // Force array
3185
+ if ( empty( $fields ) )
3186
  $fields = array();
3187
+ else {
3188
+ $filter_fields = $fields; // Temporary
 
3189
 
3190
  $fields = array();
3191
 
3193
  $name = $k;
3194
 
3195
  $defaults = array(
3196
+ 'name' => $name
3197
  );
3198
 
3199
+ if ( !is_array( $field ) ) {
3200
  $name = $field;
3201
 
3202
  $field = array(
3203
+ 'name' => $name
3204
  );
3205
  }
3206
 
 
3207
  $field = array_merge( $defaults, $field );
3208
 
3209
+ $field[ 'name' ] = trim( $field[ 'name' ] );
3210
 
3211
+ if ( pods_var_raw( 'hidden', $field, false, null, true ) )
3212
+ $field[ 'type' ] = 'hidden';
 
3213
 
3214
+ if ( isset( $object_fields[ $field[ 'name' ] ] ) )
3215
+ $fields[ $field[ 'name' ] ] = array_merge( $object_fields[ $field[ 'name' ] ], $field );
3216
+ elseif ( isset( $this->fields[ $field[ 'name' ] ] ) )
3217
+ $fields[ $field[ 'name' ] ] = array_merge( $this->fields[ $field[ 'name' ] ], $field );
3218
+ }
 
 
 
3219
 
3220
+ unset( $filter_fields ); // Cleanup
3221
+ }
 
3222
 
3223
  $this->filters = array_keys( $fields );
3224
 
3225
+ $label = $params[ 'label' ];
3226
 
3227
+ if ( strlen( $label ) < 1 )
3228
  $label = __( 'Search', 'pods' );
 
3229
 
3230
+ $action = $params[ 'action' ];
3231
 
3232
+ $search = trim( $params[ 'search' ] );
3233
 
3234
+ if ( strlen( $search ) < 1 )
3235
+ $search = pods_var_raw( $pod->search_var, 'get', '' );
 
3236
 
3237
  ob_start();
3238
 
3245
  *
3246
  * @since unknown
3247
  *
3248
+ * @param string $output
3249
+ * @param array $params Params array passed to filters().
3250
+ * @param object|Pods $this Current Pods object.
3251
  */
3252
  return apply_filters( 'pods_pods_filters', $output, $params, $this );
3253
  }
3255
  /**
3256
  * Run a helper within a Pod Page or WP Template
3257
  *
3258
+ * @see Pods_Helpers::helper
3259
  *
3260
+ * @param string $helper Helper name
3261
+ * @param string $value Value to run the helper on
3262
+ * @param string $name Field name
3263
  *
3264
  * @return mixed Anything returned by the helper
3265
+ * @since 2.0
3266
  */
3267
+ public function helper ( $helper, $value = null, $name = null ) {
 
3268
  $params = array(
3269
+ 'helper' => $helper,
3270
+ 'value' => $value,
3271
+ 'name' => $name,
3272
+ 'deprecated' => false
3273
  );
3274
 
3275
+ if ( class_exists( 'Pods_Templates' ) )
3276
+ $params[ 'deprecated' ] = Pods_Templates::$deprecated;
 
3277
 
3278
+ if ( is_array( $helper ) )
3279
  $params = array_merge( $params, $helper );
 
3280
 
3281
+ if ( class_exists( 'Pods_Helpers' ) )
3282
  $value = Pods_Helpers::helper( $params, $this );
3283
+ elseif ( function_exists( $params[ 'helper' ] ) )
3284
+ $value = call_user_func( $params[ 'helper' ], $value );
3285
+ else
3286
+ $value = apply_filters( $params[ 'helper' ], $value );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3287
 
3288
  return $value;
3289
  }
3291
  /**
3292
  * Display the page template
3293
  *
3294
+ * @see Pods_Templates::template
3295
  *
3296
+ * @param string $template The template name
3297
+ * @param string $code Custom template code to use instead
3298
+ * @param bool $deprecated Whether to use deprecated functionality based on old function usage
3299
  *
3300
  * @return mixed Template output
3301
  *
3302
+ * @since 2.0
3303
+ * @link http://pods.io/docs/template/
3304
  */
3305
+ public function template ( $template_name, $code = null, $deprecated = false ) {
 
3306
  $out = null;
3307
 
3308
  $obj =& $this;
3309
 
3310
+ if ( !empty( $code ) ) {
3311
+ $code = str_replace( '$this->', '$obj->', $code ); // backwards compatibility
 
3312
 
 
 
 
 
 
 
 
3313
  $code = apply_filters( 'pods_templates_pre_template', $code, $template_name, $this );
 
 
 
 
 
 
 
 
3314
  $code = apply_filters( "pods_templates_pre_template_{$template_name}", $code, $template_name, $this );
3315
 
3316
  ob_start();
3317
 
3318
+ if ( !empty( $code ) ) {
3319
+ // Only detail templates need $this->id
3320
  if ( empty( $this->id ) ) {
3321
  while ( $this->fetch() ) {
 
3322
  echo $this->do_magic_tags( $code );
3323
  }
 
 
 
3324
  }
3325
+ else
3326
+ echo $this->do_magic_tags( $code );
3327
  }
3328
 
3329
  $out = ob_get_clean();
3330
 
 
 
 
 
 
 
 
 
3331
  $out = apply_filters( 'pods_templates_post_template', $out, $code, $template_name, $this );
 
 
 
 
 
 
 
 
 
3332
  $out = apply_filters( "pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this );
3333
+ }
3334
+ elseif ( class_exists( 'Pods_Templates' ) )
3335
  $out = Pods_Templates::template( $template_name, $code, $this, $deprecated );
3336
+ elseif ( $template_name == trim( preg_replace( '/[^a-zA-Z0-9_\-\/]/', '', $template_name ), ' /-' ) ) {
3337
  ob_start();
3338
 
3339
  $default_templates = array(
3340
  'pods/' . $template_name,
3341
  'pods-' . $template_name,
3342
+ $template_name
3343
  );
3344
 
 
 
 
 
 
3345
  $default_templates = apply_filters( 'pods_template_default_templates', $default_templates );
3346
 
3347
+ // Only detail templates need $this->id
3348
  if ( empty( $this->id ) ) {
3349
  while ( $this->fetch() ) {
3350
  pods_template_part( $default_templates, compact( array_keys( get_defined_vars() ) ) );
3351
  }
 
 
3352
  }
3353
+ else
3354
+ pods_template_part( $default_templates, compact( array_keys( get_defined_vars() ) ) );
3355
 
3356
  $out = ob_get_clean();
3357
 
 
 
 
 
 
 
 
 
3358
  $out = apply_filters( 'pods_templates_post_template', $out, $code, $template_name, $this );
 
 
 
 
 
 
 
 
 
3359
  $out = apply_filters( "pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this );
3360
+ }
3361
 
3362
  return $out;
3363
  }
3367
  * and override options where needed. For WP object based Pods, you can pass through the WP object
3368
  * field names too, such as "post_title" or "post_content" for example.
3369
  *
3370
+ * @param array $params (optional) Fields to show on the form, defaults to all fields
3371
+ * @param string $label (optional) Save button label, defaults to "Save Changes"
3372
+ * @param string $thank_you (optional) Thank you URL to send to upon success
3373
  *
3374
  * @return bool|mixed
3375
+ * @since 2.0
3376
+ * @link http://pods.io/docs/form/
3377
  */
3378
+ public function form ( $params = null, $label = null, $thank_you = null ) {
 
3379
  $defaults = array(
3380
+ 'fields' => $params,
3381
+ 'label' => $label,
3382
+ 'thank_you' => $thank_you,
3383
+ 'fields_only' => false
3384
  );
3385
 
3386
+ if ( is_array( $params ) )
3387
  $params = array_merge( $defaults, $params );
3388
+ else
3389
  $params = $defaults;
 
3390
 
3391
  $pod =& $this;
3392
 
3393
  $params = $this->do_hook( 'form_params', $params );
3394
 
3395
+ $fields = $params[ 'fields' ];
3396
 
3397
+ if ( null !== $fields && !is_array( $fields ) && 0 < strlen( $fields ) )
3398
  $fields = explode( ',', $fields );
 
3399
 
3400
+ $object_fields = (array) pods_var_raw( 'object_fields', $this->pod_data, array(), null, true );
3401
 
3402
  if ( empty( $fields ) ) {
3403
+ // Add core object fields if $fields is empty
3404
  $fields = array_merge( $object_fields, $this->fields );
3405
  }
3406
 
3407
+ $form_fields = $fields; // Temporary
 
3408
 
3409
  $fields = array();
3410
 
3412
  $name = $k;
3413
 
3414
  $defaults = array(
3415
+ 'name' => $name
3416
  );
3417
 
3418
+ if ( !is_array( $field ) ) {
3419
  $name = $field;
3420
 
3421
  $field = array(
3422
+ 'name' => $name
3423
  );
3424
  }
3425
 
 
3426
  $field = array_merge( $defaults, $field );
3427
 
3428
+ $field[ 'name' ] = trim( $field[ 'name' ] );
3429
 
3430
+ $default_value = pods_var_raw( 'default', $field );
3431
+ $value = pods_var_raw( 'value', $field );
3432
 
3433
+ if ( empty( $field[ 'name' ] ) )
3434
+ $field[ 'name' ] = trim( $name );
 
3435
 
3436
+ if ( isset( $object_fields[ $field[ 'name' ] ] ) ) {
3437
+ $field = array_merge( $object_fields[ $field[ 'name' ] ], $field );
 
 
 
 
3438
  }
3439
+ elseif ( isset( $this->fields[ $field[ 'name' ] ] ) ) {
3440
+ $field = array_merge( $this->fields[ $field[ 'name' ] ], $field );
 
3441
  }
3442
 
3443
+ if ( pods_var_raw( 'hidden', $field, false, null, true ) )
3444
+ $field[ 'type' ] = 'hidden';
3445
+
3446
+ $fields[ $field[ 'name' ] ] = $field;
3447
 
3448
  if ( empty( $this->id ) && null !== $default_value ) {
3449
+ $this->row_override[ $field[ 'name' ] ] = $default_value;
 
 
3450
  }
3451
+ elseif ( !empty( $this->id ) && null !== $value ) {
3452
+ $this->row[ $field[ 'name' ] ] = $value;
3453
+ }
3454
+ }
3455
 
3456
+ unset( $form_fields ); // Cleanup
 
3457
 
3458
  $fields = $this->do_hook( 'form_fields', $fields, $params );
3459
 
3460
+ $label = $params[ 'label' ];
3461
 
3462
+ if ( empty( $label ) )
3463
  $label = __( 'Save Changes', 'pods' );
 
3464
 
3465
+ $thank_you = $params[ 'thank_you' ];
3466
+ $fields_only = $params[ 'fields_only' ];
3467
 
3468
+ PodsForm::$form_counter++;
3469
 
3470
  ob_start();
3471
 
3472
  if ( empty( $thank_you ) ) {
3473
  $success = 'success';
3474
 
3475
+ if ( 1 < PodsForm::$form_counter )
3476
  $success .= PodsForm::$form_counter;
 
3477
 
3478
+ $thank_you = pods_query_arg( array( 'success*' => null, $success => 1 ) );
 
 
 
3479
 
3480
+ if ( 1 == pods_v( $success, 'get', 0 ) ) {
3481
  $message = __( 'Form submitted successfully', 'pods' );
 
3482
  /**
3483
+ * Change the text of the message that appears on succesful form submission.
3484
+ *
3485
+ * @param string $message
3486
  *
3487
+ * @returns string the message
3488
  *
3489
+ * @since 3.0.0
3490
  */
3491
  $message = apply_filters( 'pods_pod_form_success_message', $message );
3492
 
3493
+ echo '<div id="message" class="pods-form-front-success">' . $message . '</div>';
3494
  }
3495
+ }
3496
 
3497
  pods_view( PODS_DIR . 'ui/front/form.php', compact( array_keys( get_defined_vars() ) ) );
3498
 
3499
  $output = ob_get_clean();
3500
 
3501
+ if ( empty( $this->id ) )
3502
  $this->row_override = array();
 
3503
 
3504
  return $this->do_hook( 'form', $output, $fields, $label, $thank_you, $this, $this->id() );
3505
  }
3506
 
3507
  /**
3508
+ * @param array $fields (optional) Fields to show in the view, defaults to all fields
 
 
3509
  *
3510
  * @return mixed
3511
  * @since 2.3.10
3514
 
3515
  $pod =& $this;
3516
 
3517
+ // Convert comma separated list of fields to an array
3518
+ if ( null !== $fields && !is_array( $fields ) && 0 < strlen( $fields ) ) {
3519
  $fields = explode( ',', $fields );
3520
  }
3521
 
3522
  $object_fields = (array) pods_v( 'object_fields', $this->pod_data, array(), true );
3523
 
3524
  if ( empty( $fields ) ) {
3525
+ // Add core object fields if $fields is empty
3526
  $fields = array_merge( $object_fields, $this->fields );
3527
  }
3528
 
3529
+ $view_fields = $fields; // Temporary
 
3530
 
3531
  $fields = array();
3532
 
3533
  foreach ( $view_fields as $name => $field ) {
3534
+
3535
  $defaults = array(
3536
+ 'name' => $name
3537
  );
3538
 
3539
+ if ( !is_array( $field ) ) {
3540
  $name = $field;
3541
 
3542
  $field = array(
3543
+ 'name' => $name
3544
  );
3545
  }
3546
 
 
3547
  $field = array_merge( $defaults, $field );
3548
 
3549
+ $field[ 'name' ] = trim( $field[ 'name' ] );
3550
 
3551
+ if ( empty( $field[ 'name' ] ) ) {
3552
+ $field[ 'name' ] = trim( $name );
3553
  }
3554
 
3555
+ if ( isset( $object_fields[ $field[ 'name' ] ] ) )
3556
+ $field = array_merge( $field, $object_fields[ $field[ 'name' ] ] );
3557
+ elseif ( isset( $this->fields[ $field[ 'name' ] ] ) )
3558
+ $field = array_merge( $this->fields[ $field[ 'name' ] ], $field );
 
 
 
3559
 
3560
+ if ( pods_v( 'hidden', $field, false, null, true ) || 'hidden' == $field[ 'type' ] ) {
3561
  continue;
3562
+ }
3563
+ elseif ( !PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $fields, $pod, $pod->id() ) ) {
3564
  continue;
3565
  }
3566
 
3567
+ $fields[ $field[ 'name' ] ] = $field;
3568
+ }
3569
 
3570
+ unset( $view_fields ); // Cleanup
 
3571
 
3572
  $output = pods_view( PODS_DIR . 'ui/front/view.php', compact( array_keys( get_defined_vars() ) ), false, 'cache', true );
3573
 
3578
  /**
3579
  * Replace magic tags with their values
3580
  *
3581
+ * @param string $code The content to evaluate
3582
+ * @param object $obj The Pods object
3583
  *
3584
  * @return string Code with Magic Tags evaluated
3585
  *
3586
+ * @since 2.0
3587
  */
3588
+ public function do_magic_tags ( $code ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3589
  return preg_replace_callback( '/({@(.*?)})/m', array( $this, 'process_magic_tags' ), $code );
3590
  }
3591
 
3592
  /**
3593
  * Replace magic tags with their values
3594
  *
3595
+ * @param string $tag The magic tag to process
3596
+ * @param object $obj The Pods object
3597
  *
3598
  * @return string Code with Magic Tags evaluated
3599
  *
3600
  * @since 2.0.2
3601
  */
3602
+ private function process_magic_tags ( $tag ) {
3603
 
3604
  if ( is_array( $tag ) ) {
3605
+ if ( !isset( $tag[ 2 ] ) && strlen( trim( $tag[ 2 ] ) ) < 1 )
3606
  return '';
 
3607
 
3608
+ $tag = $tag[ 2 ];
3609
  }
3610
 
3611
  $tag = trim( $tag, ' {@}' );
3612
  $tag = explode( ',', $tag );
3613
 
3614
+ if ( empty( $tag ) || !isset( $tag[ 0 ] ) || strlen( trim( $tag[ 0 ] ) ) < 1 )
3615
  return '';
 
3616
 
3617
+ foreach ( $tag as $k => $v ) {
3618
+ $tag[ $k ] = trim( $v );
3619
+ }
3620
 
3621
+ $field_name = $tag[ 0 ];
3622
 
3623
+ $helper_name = $before = $after = '';
 
 
3624
 
3625
+ if ( isset( $tag[ 1 ] ) && !empty( $tag[ 1 ] ) ) {
3626
  $value = $this->field( $field_name );
3627
 
3628
+ $helper_name = $tag[ 1 ];
3629
 
3630
  $value = $this->helper( $helper_name, $value, $field_name );
 
 
 
 
 
 
 
 
 
 
 
 
 
3631
  }
3632
+ else
3633
+ $value = $this->display( $field_name );
3634
 
3635
+ if ( isset( $tag[ 2 ] ) && !empty( $tag[ 2 ] ) )
3636
+ $before = $tag[ 2 ];
 
3637
 
3638
+ if ( isset( $tag[ 3 ] ) && !empty( $tag[ 3 ] ) )
3639
+ $after = $tag[ 3 ];
 
3640
 
 
 
 
 
 
 
 
 
3641
  $value = apply_filters( 'pods_do_magic_tags', $value, $field_name, $helper_name, $before, $after );
3642
 
3643
+ if ( is_array( $value ) )
3644
+ $value = pods_serial_comma( $value, array( 'field' => $field_name, 'fields' => $this->fields ) );
 
 
 
 
3645
 
3646
+ if ( null !== $value && false !== $value )
3647
  return $before . $value . $after;
 
3648
 
3649
  return '';
3650
  }
3653
  *
3654
  * Generate UI for Data Management
3655
  *
3656
+ * @param mixed $options Array or String containing Pod or Options to be used
3657
+ * @param bool $amend Whether to amend the default UI options or replace entirely
3658
  *
3659
+ * @return PodsUI|void UI object or void if custom UI used
3660
  *
3661
  * @since 2.3.10
3662
  */
3663
+ public function ui ( $options = null, $amend = false ) {
 
3664
  $num = '';
3665
 
3666
+ if ( empty( $options ) )
3667
  $options = array();
3668
+ else {
3669
+ $num = pods_var( 'num', $options, '' );
3670
 
3671
  if ( empty( $num ) ) {
3672
  $num = '';
3673
  }
3674
  }
3675
 
3676
+ if ( $this->id() != pods_var( 'id' . $num, 'get', null, null, true ) )
3677
+ $this->fetch( pods_var( 'id' . $num, 'get', null, null, true ) );
 
 
 
 
3678
 
3679
+ if ( !empty( $options ) && !$amend ) {
3680
  $this->ui = $options;
3681
 
3682
  return pods_ui( $this );
3683
+ }
3684
+ elseif ( !empty( $options ) || 'custom' != pods_var( 'ui_style', $this->pod_data[ 'options' ], 'post_type', null, true ) ) {
3685
+ $actions_enabled = pods_var_raw( 'ui_actions_enabled', $this->pod_data[ 'options' ] );
3686
 
3687
+ if ( !empty( $actions_enabled ) )
3688
  $actions_enabled = (array) $actions_enabled;
3689
+ else
3690
  $actions_enabled = array();
 
3691
 
3692
  $available_actions = array(
3693
  'add',
3695
  'duplicate',
3696
  'delete',
3697
  'reorder',
3698
+ 'export'
3699
  );
3700
 
3701
+ if ( !empty( $actions_enabled ) ) {
3702
  $actions_disabled = array(
3703
+ 'view' => 'view'
3704
  );
3705
 
3706
  foreach ( $available_actions as $action ) {
3707
+ if ( !in_array( $action, $actions_enabled ) )
3708
  $actions_disabled[ $action ] = $action;
 
3709
  }
3710
+ }
3711
+ else {
3712
  $actions_disabled = array(
3713
  'duplicate' => 'duplicate',
3714
+ 'view' => 'view',
3715
+ 'export' => 'export'
3716
  );
3717
 
3718
+ if ( 1 == pods_var( 'ui_export', $this->pod_data[ 'options' ], 0 ) )
3719
+ unset( $actions_disabled[ 'export' ] );
3720
+ }
 
3721
 
3722
  if ( empty( $options ) ) {
3723
  $author_restrict = false;
3724
 
3725
+ if ( isset( $this->fields[ 'author' ] ) && 'pick' == $this->fields[ 'author' ][ 'type' ] && 'user' == $this->fields[ 'author' ][ 'pick_object' ] )
3726
  $author_restrict = 'author.ID';
 
3727
 
3728
+ if ( !pods_is_admin( array( 'pods', 'pods_content' ) ) ) {
3729
+ if ( !current_user_can( 'pods_add_' . $this->pod ) ) {
3730
+ $actions_disabled[ 'add' ] = 'add';
3731
 
3732
+ if ( 'add' == pods_var( 'action' . $num, 'get' ) )
3733
  $_GET[ 'action' . $num ] = 'manage';
 
3734
  }
3735
 
3736
+ if ( !$author_restrict && !current_user_can( 'pods_edit_' . $this->pod ) && !current_user_can( 'pods_edit_others_' . $this->pod ) )
3737
+ $actions_disabled[ 'edit' ] = 'edit';
 
3738
 
3739
+ if ( !$author_restrict && !current_user_can( 'pods_delete_' . $this->pod ) && !current_user_can( 'pods_delete_others_' . $this->pod ) )
3740
+ $actions_disabled[ 'delete' ] = 'delete';
 
3741
 
3742
+ if ( !current_user_can( 'pods_reorder_' . $this->pod ) )
3743
+ $actions_disabled[ 'reorder' ] = 'reorder';
 
3744
 
3745
+ if ( !current_user_can( 'pods_export_' . $this->pod ) )
3746
+ $actions_disabled[ 'export' ] = 'export';
3747
+ }
3748
+ }
 
3749
 
3750
+ $_GET[ 'action' . $num ] = pods_var( 'action' . $num, 'get', pods_var( 'action', $options, 'manage' ) );
3751
 
3752
+ $index = $this->pod_data[ 'field_id' ];
3753
  $label = __( 'ID', 'pods' );
3754
 
3755
+ if ( isset( $this->pod_data[ 'fields' ][ $this->pod_data[ 'field_index' ] ] ) ) {
3756
+ $index = $this->pod_data[ 'field_index' ];
3757
+ $label = $this->pod_data[ 'fields' ][ $this->pod_data[ 'field_index' ] ];
3758
  }
3759
 
3760
  $manage = array(
3761
+ $index => $label
3762
  );
3763
 
3764
+ if ( isset( $this->pod_data[ 'fields' ][ 'modified' ] ) )
3765
+ $manage[ 'modified' ] = $this->pod_data[ 'fields' ][ 'modified' ][ 'label' ];
 
3766
 
3767
+ $manage_fields = pods_var_raw( 'ui_fields_manage', $this->pod_data[ 'options' ] );
3768
 
3769
+ if ( !empty( $manage_fields ) ) {
3770
  $manage_new = array();
3771
 
3772
  foreach ( $manage_fields as $manage_field ) {
3773
+ if ( isset( $this->pod_data[ 'fields' ][ $manage_field ] ) )
3774
+ $manage_new[ $manage_field ] = $this->pod_data[ 'fields' ][ $manage_field ];
3775
+ elseif ( isset( $this->pod_data[ 'object_fields' ][ $manage_field ] ) )
3776
+ $manage_new[ $manage_field ] = $this->pod_data[ 'object_fields' ][ $manage_field ];
3777
+ elseif ( $manage_field == $this->pod_data[ 'field_id' ] ) {
3778
  $field = array(
3779
+ 'name' => $manage_field,
3780
  'label' => 'ID',
3781
+ 'type' => 'number',
3782
+ 'width' => '8%'
3783
  );
3784
 
3785
+ $manage_new[ $manage_field ] = PodsForm::field_setup( $field, null, $field[ 'type' ] );
3786
  }
3787
  }
3788
 
3789
+ if ( !empty( $manage_new ) )
3790
  $manage = $manage_new;
3791
+ }
 
3792
 
3793
+ $manage = apply_filters( 'pods_admin_ui_fields_' . $this->pod, apply_filters( 'pods_admin_ui_fields', $manage, $this->pod, $this ), $this->pod, $this );
 
3794
 
3795
+ $icon = pods_var_raw( 'ui_icon', $this->pod_data[ 'options' ] );
3796
 
3797
+ if ( !empty( $icon ) )
3798
  $icon = pods_image_url( $icon, '32x32' );
 
3799
 
3800
+ $filters = pods_var_raw( 'ui_filters', $this->pod_data[ 'options' ] );
3801
 
3802
+ if ( !empty( $filters ) ) {
3803
  $filters_new = array();
3804
 
3805
  $filters = (array) $filters;
3806
 
3807
  foreach ( $filters as $filter_field ) {
3808
+ if ( isset( $this->pod_data[ 'fields' ][ $filter_field ] ) )
3809
+ $filters_new[ $filter_field ] = $this->pod_data[ 'fields' ][ $filter_field ];
3810
+ elseif ( isset( $this->pod_data[ 'object_fields' ][ $filter_field ] ) )
3811
+ $filters_new[ $filter_field ] = $this->pod_data[ 'object_fields' ][ $filter_field ];
 
3812
  }
3813
 
3814
  $filters = $filters_new;
3815
  }
3816
 
3817
  $ui = array(
3818
+ 'fields' => array(
3819
+ 'manage' => $manage,
3820
+ 'add' => $this->pod_data[ 'fields' ],
3821
+ 'edit' => $this->pod_data[ 'fields' ],
3822
+ 'duplicate' => $this->pod_data[ 'fields' ]
3823
  ),
3824
+ 'icon' => $icon,
3825
+ 'actions_disabled' => $actions_disabled
 
3826
  );
3827
 
3828
+ if ( !empty( $filters ) ) {
3829
+ $ui[ 'fields' ][ 'search' ] = $filters;
3830
+ $ui[ 'filters' ] = array_keys( $filters );
3831
+ $ui[ 'filters_enhanced' ] = true;
3832
  }
3833
 
3834
+ $reorder_field = pods_var_raw( 'ui_reorder_field', $this->pod_data[ 'options' ] );
 
 
 
 
 
 
3835
 
3836
+ if ( in_array( 'reorder', $actions_enabled ) && !in_array( 'reorder', $actions_disabled ) && !empty( $reorder_field ) && ( ( !empty( $this->pod_data[ 'object_fields' ] ) && isset( $this->pod_data[ 'object_fields' ][ $reorder_field ] ) ) || isset( $this->pod_data[ 'fields' ][ $reorder_field ] ) ) ) {
3837
+ $ui[ 'reorder' ] = array( 'on' => $reorder_field );
3838
+ $ui[ 'orderby' ] = $reorder_field;
3839
+ $ui[ 'orderby_dir' ] = 'ASC';
3840
  }
3841
 
3842
+ if ( !empty( $author_restrict ) )
3843
+ $ui[ 'restrict' ] = array( 'author_restrict' => $author_restrict );
 
 
 
 
3844
 
3845
+ if ( !in_array( 'delete', $ui[ 'actions_disabled' ] ) ) {
3846
+ $ui[ 'actions_bulk' ] = array(
3847
+ 'delete' => array(
3848
+ 'label' => __( 'Delete', 'pods' )
3849
+ // callback not needed, Pods has this built-in for delete
3850
+ )
3851
  );
3852
  }
3853
 
3854
+ $detail_url = pods_var( 'detail_url', $this->pod_data[ 'options' ] );
3855
 
3856
  if ( 0 < strlen( $detail_url ) ) {
3857
+ $ui[ 'actions_custom' ] = array(
3858
  'view_url' => array(
3859
  'label' => 'View',
3860
+ 'link' => get_site_url() . '/' . $detail_url
3861
+ )
3862
  );
3863
  }
3864
 
3865
+ // @todo Customize the Add New / Manage links to point to their correct menu items
3866
+
3867
+ $ui = apply_filters( 'pods_admin_ui_' . $this->pod, apply_filters( 'pods_admin_ui', $ui, $this->pod, $this ), $this->pod, $this );
3868
 
3869
+ // Override UI options
3870
  foreach ( $options as $option => $value ) {
3871
  $ui[ $option ] = $value;
3872
  }
3874
  $this->ui = $ui;
3875
 
3876
  return pods_ui( $this );
3877
+ }
3878
 
 
3879
  do_action( 'pods_admin_ui_custom', $this );
3880
+ do_action( 'pods_admin_ui_custom_' . $this->pod, $this );
 
 
3881
  }
3882
 
3883
  /**
3884
  * Handle filters / actions for the class
3885
  *
3886
+ * @see pods_do_hook
 
 
3887
  *
3888
  * @return mixed Value filtered
3889
  *
3890
+ * @since 2.0
3891
  */
3892
+ private function do_hook () {
 
3893
  $args = func_get_args();
3894
 
3895
+ if ( empty( $args ) )
3896
  return false;
 
3897
 
3898
+ $name = array_shift( $args );
 
3899
 
3900
  return pods_do_hook( 'pods', $name, $args, $this );
3901
  }
3903
  /**
3904
  * Handle variables that have been deprecated and PodsData vars
3905
  *
3906
+ * @var $name
3907
  *
3908
  * @return mixed
3909
  *
3910
+ * @since 2.0
3911
  */
3912
+ public function __get ( $name ) {
 
3913
  $name = (string) $name;
3914
 
3915
+ // PodsData vars
3916
+ if ( 0 === strpos( $name, 'field_' ) && isset( $this->data->{$name} ) ) {
3917
  return $this->data->{$name};
3918
  }
3919
 
3920
+ if ( !isset( $this->deprecated ) ) {
3921
+ require_once( PODS_DIR . 'deprecated/classes/Pods.php' );
 
3922
  $this->deprecated = new Pods_Deprecated( $this );
3923
  }
3924
 
3925
  $var = null;
3926
 
 
 
3927
  if ( isset( $this->deprecated->{$name} ) ) {
3928
+ if ( ! class_exists( 'Pod' ) || Pod::$deprecated_notice ) {
3929
  pods_deprecated( "Pods->{$name}", '2.0' );
3930
  }
3931
 
3932
  $var = $this->deprecated->{$name};
3933
+ }
3934
+ elseif ( ! class_exists( 'Pod' ) || Pod::$deprecated_notice ) {
3935
  pods_deprecated( "Pods->{$name}", '2.0' );
3936
  }
3937
 
3939
  }
3940
 
3941
  /**
3942
+ * Handle methods that have been deprecated and any aliasing
3943
  *
3944
+ * @var $name
3945
+ * @var $args
3946
  *
3947
+ * @return mixed
3948
  *
3949
+ * @since 2.0
3950
  */
3951
+ public function __call ( $name, $args ) {
 
3952
  $name = (string) $name;
3953
 
3954
+ // select > find alias
3955
+ if ( 'select' == $name ) {
3956
  return call_user_func_array( array( $this, 'find' ), $args );
3957
  }
3958
 
3959
+ if ( !isset( $this->deprecated ) ) {
3960
+ require_once( PODS_DIR . 'deprecated/classes/Pods.php' );
 
3961
  $this->deprecated = new Pods_Deprecated( $this );
3962
  }
3963
 
 
 
3964
  if ( method_exists( $this->deprecated, $name ) ) {
3965
  return call_user_func_array( array( $this->deprecated, $name ), $args );
 
 
 
3966
  }
3967
+ elseif ( ! class_exists( 'Pod' ) || Pod::$deprecated_notice ) {
3968
+ pods_deprecated( "Pods::{$name}", '2.0' );
 
 
 
 
 
 
 
 
 
 
 
 
 
3969
  }
 
 
 
3970
  }
3971
  }
classes/PodsAPI.php CHANGED
@@ -1,9378 +1,8631 @@
1
  <?php
2
-
3
  /**
4
  * @package Pods
5
  */
6
  class PodsAPI {
7
 
8
- /**
9
- * @var PodsAPI
10
- */
11
- static $instance = null;
12
 
13
  /**
14
  * @var array PodsAPI
15
  */
16
  static $instances = array();
17
 
18
- /**
19
- * @var bool
20
- */
21
- public $display_errors = false;
22
 
23
- /**
24
- * @var array|bool|mixed|null|void
25
- */
26
- public $pod_data;
27
 
28
- /**
29
- * @var
30
- */
31
- public $pod;
32
 
33
- /**
34
- * @var
35
- */
36
- public $pod_id;
37
 
38
- /**
39
- * @var
40
- */
41
- public $fields;
42
 
43
- /**
44
- * @var
45
- * @deprecated 2.0.0
46
- */
47
- public $format = null;
48
 
49
- /**
50
- * @var
51
- */
52
- private $deprecated;
 
 
 
 
 
 
53
 
54
  /**
55
  * @var array
56
- * @since 2.5.0
57
  */
58
  private $fields_cache = array();
59
 
60
  /**
61
  * @var array
62
- * @since 2.5.0
63
  *
64
  */
65
  private static $table_info_cache = array();
66
 
67
  /**
68
  * @var array
69
- * @since 2.5.0
70
  *
71
  */
72
  private static $related_item_cache = array();
73
 
74
  /**
75
- * Singleton-ish handling for a basic pods_api() request
76
- *
77
- * @param string $pod (optional) The pod name
78
- * @param string $format (deprecated) Format for import/export, "php" or "csv"
79
- *
80
- * @return \PodsAPI
81
- *
82
- * @since 2.3.5
83
- */
84
- public static function init( $pod = null, $format = null ) {
85
-
86
  if ( null !== $pod || null !== $format ) {
87
  if ( ! isset( self::$instances[ $pod ] ) ) {
88
  // Cache API singleton per Pod
89
  self::$instances[ $pod ] = new PodsAPI( $pod, $format );
90
  }
91
-
92
  return self::$instances[ $pod ];
93
- } elseif ( ! is_object( self::$instance ) ) {
 
94
  self::$instance = new PodsAPI();
95
  }
96
 
97
  return self::$instance;
98
  }
99
 
100
- /**
101
- * Store and retrieve data programatically
102
- *
103
- * @param string $pod (optional) The pod name
104
- * @param string $format (deprecated) Format for import/export, "php" or "csv"
105
- *
106
- * @return \PodsAPI
107
- *
108
- * @license http://www.gnu.org/licenses/gpl-2.0.html
109
- * @since 1.7.1
110
- */
111
- public function __construct( $pod = null, $format = null ) {
112
-
113
- if ( null !== $pod && 0 < strlen( (string) $pod ) ) {
114
- if ( null !== $format ) {
115
- $this->format = $format;
116
-
117
- pods_deprecated( 'pods_api( $pod, $format )', '2.0', 'pods_api( $pod )' );
118
- }
119
-
120
- $pod = pods_clean_name( $pod );
121
 
122
- $pod = $this->load_pod( array( 'name' => $pod, 'table_info' => true ), false );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
- if ( ! empty( $pod ) ) {
125
- $this->pod_data = $pod;
126
- $this->pod = $pod['name'];
127
- $this->pod_id = $pod['id'];
128
- $this->fields = $pod['fields'];
129
- }
130
- }
131
- }
132
 
133
- /**
134
- * Save a WP object and its meta
135
- *
136
- * @param string $object_type Object type: post|taxonomy|user|comment|setting
137
- * @param array $data All post data to be saved
138
- * @param array $meta (optional) Associative array of meta keys and values
139
- * @param bool $strict (optional) Decides whether the previous saved meta should be deleted or not
140
- * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before
141
- * sending.
142
- * @param array $fields (optional) The array of fields and their options, for further processing with
143
- *
144
- * @return bool|mixed
145
- *
146
- * @since 2.0.0
147
- */
148
- public function save_wp_object( $object_type, $data, $meta = array(), $strict = false, $sanitized = false, $fields = array() ) {
149
 
150
- if ( in_array( $object_type, array( 'post_type', 'media' ) ) ) {
151
- $object_type = 'post';
152
- }
153
 
154
- if ( 'taxonomy' === $object_type ) {
155
- $object_type = 'term';
156
- }
157
 
158
- if ( $sanitized ) {
159
- $data = pods_unsanitize( $data );
160
- $meta = pods_unsanitize( $meta );
161
- }
162
 
163
- if ( in_array( $object_type, array( 'post', 'term', 'user', 'comment' ) ) ) {
164
- return call_user_func( array( $this, 'save_' . $object_type ), $data, $meta, $strict, false, $fields );
165
- } elseif ( 'settings' === $object_type ) {
166
- // Nothing to save
167
- if ( empty( $meta ) ) {
168
- return true;
 
169
  }
 
170
 
171
- return $this->save_setting( pods_var( 'option_id', $data ), $meta, false );
172
- }
173
-
174
- return false;
175
- }
176
-
177
- /**
178
- * Delete a WP object
179
- *
180
- * @param string $object_type Object type: post|user|comment
181
- * @param int $id Object ID
182
- * @param bool $force_delete (optional) Force deletion instead of trashing (post types only)
183
- *
184
- * @return bool|mixed
185
- *
186
- * @since 2.0.0
187
- */
188
- public function delete_wp_object( $object_type, $id, $force_delete = true ) {
189
 
190
- if ( in_array( $object_type, array( 'post_type', 'media' ) ) ) {
191
- $object_type = 'post';
192
- }
193
 
194
- if ( 'taxonomy' === $object_type ) {
195
- $object_type = 'term';
196
- }
197
 
198
- if ( empty( $id ) ) {
199
- return false;
200
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
201
 
202
- if ( in_array( $object_type, array( 'post' ) ) ) {
203
- return wp_delete_post( $id, $force_delete );
204
- }
205
 
206
- if ( function_exists( 'wp_delete_' . $object_type ) ) {
207
- return call_user_func( 'wp_delete_' . $object_type, $id );
208
- }
209
 
210
- return false;
211
- }
212
 
213
- /**
214
- * Save a post and it's meta
215
- *
216
- * @param array $post_data All post data to be saved (using wp_insert_post / wp_update_post)
217
- * @param array $post_meta (optional) All meta to be saved (set value to null to delete)
218
- * @param bool $strict (optional) Whether to delete previously saved meta not in $post_meta
219
- * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before
220
- * sending.
221
- * @param array $fields (optional) The array of fields and their options, for further processing with
222
- *
223
- * @return mixed|void
224
- *
225
- * @since 2.0.0
226
- */
227
- public function save_post( $post_data, $post_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
228
 
229
- $conflicted = pods_no_conflict_check( 'post' );
 
 
230
 
231
- if ( ! $conflicted ) {
232
- pods_no_conflict_on( 'post' );
233
  }
234
 
235
- if ( ! is_array( $post_data ) || empty( $post_data ) ) {
236
- $post_data = array( 'post_title' => '' );
237
- }
 
238
 
239
- if ( ! is_array( $post_meta ) ) {
240
- $post_meta = array();
241
- }
242
 
243
- if ( $sanitized ) {
244
- $post_data = pods_unsanitize( $post_data );
245
- $post_meta = pods_unsanitize( $post_meta );
246
- }
247
 
248
- if ( ! isset( $post_data['ID'] ) || empty( $post_data['ID'] ) ) {
249
- $post_data['ID'] = wp_insert_post( $post_data, true );
250
- } elseif ( 2 < count( $post_data ) || ! isset( $post_data['post_type'] ) ) {
251
- $post_data['ID'] = wp_update_post( $post_data, true );
252
- }
253
 
254
- if ( is_wp_error( $post_data['ID'] ) ) {
255
- if ( ! $conflicted ) {
256
- pods_no_conflict_off( 'post' );
257
- }
258
 
259
- /**
260
- * @var $post_error WP_Error
261
- */
262
- $post_error = $post_data['ID'];
263
 
264
- return pods_error( $post_error->get_error_message(), $this );
265
- }
266
 
267
- $this->save_post_meta( $post_data['ID'], $post_meta, $strict, $fields );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
 
269
- if ( ! $conflicted ) {
270
- pods_no_conflict_off( 'post' );
271
- }
272
 
273
- return $post_data['ID'];
274
- }
275
 
276
- /**
277
- * Save a post's meta
278
- *
279
- * @param int $id Post ID
280
- * @param array $post_meta All meta to be saved (set value to null to delete)
281
- * @param bool $strict Whether to delete previously saved meta not in $post_meta
282
- * @param array $fields (optional) The array of fields and their options, for further processing with
283
- *
284
- * @return int Id of the post with the meta
285
- *
286
- * @since 2.0.0
287
- */
288
- public function save_post_meta( $id, $post_meta = null, $strict = false, $fields = array() ) {
289
 
290
- $simple_tableless_objects = PodsForm::simple_tableless_objects();
291
 
292
- $conflicted = pods_no_conflict_check( 'post' );
293
 
294
- if ( ! $conflicted ) {
295
- pods_no_conflict_on( 'post' );
296
- }
297
 
298
- if ( ! is_array( $post_meta ) ) {
299
- $post_meta = array();
300
- }
301
 
302
- $id = (int) $id;
 
 
 
303
 
304
- $meta = get_post_meta( $id );
 
305
 
306
- foreach ( $meta as $k => $value ) {
307
- if ( is_array( $value ) && 1 == count( $value ) ) {
308
- $meta[ $k ] = current( $value );
309
- }
310
- }
311
 
312
- foreach ( $post_meta as $meta_key => $meta_value ) {
313
- if ( null === $meta_value || ( $strict && '' === $post_meta[ $meta_key ] ) ) {
314
- $old_meta_value = '';
315
 
316
- if ( isset( $meta[ $meta_key ] ) ) {
317
- $old_meta_value = $meta[ $meta_key ];
 
318
  }
 
 
 
 
 
319
 
320
- delete_post_meta( $id, $meta_key, $old_meta_value );
321
- } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  $simple = false;
323
 
324
  if ( isset( $fields[ $meta_key ] ) ) {
325
  $field_data = $fields[ $meta_key ];
326
 
327
- $simple = ( 'pick' === pods_v( 'type', $field_data ) && in_array( pods_v( 'pick_object', $field_data ), $simple_tableless_objects ) );
328
  }
329
 
330
  if ( $simple ) {
331
- delete_post_meta( $id, $meta_key );
332
-
333
- update_post_meta( $id, '_pods_' . $meta_key, $meta_value );
334
 
335
  if ( ! is_array( $meta_value ) ) {
336
  $meta_value = array( $meta_value );
337
  }
338
 
339
  foreach ( $meta_value as $value ) {
340
- add_post_meta( $id, $meta_key, $value );
341
  }
342
- } else {
343
- update_post_meta( $id, $meta_key, $meta_value );
344
- }
345
- }
346
- }
347
-
348
- if ( $strict ) {
349
- foreach ( $meta as $meta_key => $meta_value ) {
350
- if ( ! isset( $post_meta[ $meta_key ] ) ) {
351
- delete_post_meta( $id, $meta_key, $meta_value );
352
  }
353
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  }
355
 
356
- if ( ! $conflicted ) {
357
- pods_no_conflict_off( 'post' );
358
- }
359
 
360
- return $id;
361
- }
362
 
363
- /**
364
- * Save a user and it's meta
365
- *
366
- * @param array $user_data All user data to be saved (using wp_insert_user / wp_update_user)
367
- * @param array $user_meta (optional) All meta to be saved (set value to null to delete)
368
- * @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
369
- * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before
370
- * sending.
371
- * @param array $fields (optional) The array of fields and their options, for further processing with
372
- *
373
- * @return int Returns user id on success
374
- *
375
- * @since 2.0.0
376
- */
377
- public function save_user( $user_data, $user_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
378
 
379
- if ( ! is_array( $user_data ) || empty( $user_data ) ) {
380
- return pods_error( __( 'User data is required but is either invalid or empty', 'pods' ), $this );
381
- }
382
 
383
- $conflicted = pods_no_conflict_check( 'user' );
 
 
 
384
 
385
- if ( ! $conflicted ) {
386
- pods_no_conflict_on( 'user' );
387
- }
388
 
389
- if ( ! is_array( $user_meta ) ) {
390
- $user_meta = array();
391
- }
392
 
393
- if ( $sanitized ) {
394
- $user_data = pods_unsanitize( $user_data );
395
- $user_meta = pods_unsanitize( $user_meta );
396
- }
397
 
398
- // Set role
399
- if ( isset( $user_meta['role'] ) ) {
400
- $user_data['role'] = $user_meta['role'];
401
 
402
- unset( $user_meta['role'] );
403
- }
 
 
404
 
405
- if ( ! isset( $user_data['ID'] ) || empty( $user_data['ID'] ) ) {
406
- $user_data['ID'] = wp_insert_user( $user_data );
407
- } elseif ( 1 < count( $user_data ) ) {
408
- wp_update_user( $user_data );
409
- }
410
 
411
- if ( is_wp_error( $user_data['ID'] ) ) {
412
- if ( ! $conflicted ) {
413
- pods_no_conflict_off( 'user' );
414
- }
415
 
416
- /**
417
- * @var $user_error WP_Error
418
- */
419
- $user_error = $user_data['ID'];
420
 
421
- return pods_error( $user_error->get_error_message(), $this );
422
- }
423
 
424
- $this->save_user_meta( $user_data['ID'], $user_meta, $strict, $fields );
 
425
 
426
- if ( ! $conflicted ) {
427
- pods_no_conflict_off( 'user' );
428
- }
429
 
430
- return $user_data['ID'];
431
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
 
433
- /**
434
- * Save a user meta
435
- *
436
- * @param int $id User ID
437
- * @param array $user_meta (optional) All meta to be saved (set value to null to delete)
438
- * @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
439
- * @param array $fields (optional) The array of fields and their options, for further processing with
440
- *
441
- * @return int User ID
442
- *
443
- * @since 2.0.0
444
- *
445
- */
446
- public function save_user_meta( $id, $user_meta = null, $strict = false, $fields = array() ) {
447
 
448
- $simple_tableless_objects = PodsForm::simple_tableless_objects();
449
 
450
- $conflicted = pods_no_conflict_check( 'user' );
 
451
 
452
- if ( ! $conflicted ) {
453
- pods_no_conflict_on( 'user' );
454
- }
455
 
456
- if ( ! is_array( $user_meta ) ) {
457
- $user_meta = array();
458
- }
459
 
460
- $id = (int) $id;
461
 
462
- $meta = get_user_meta( $id );
 
 
 
463
 
464
- foreach ( $user_meta as $meta_key => $meta_value ) {
465
- if ( null === $meta_value ) {
466
- $old_meta_value = '';
467
 
468
- if ( isset( $meta[ $meta_key ] ) ) {
469
- $old_meta_value = $meta[ $meta_key ];
470
- }
471
 
472
- delete_user_meta( $id, $meta_key, $old_meta_value );
473
- } else {
 
474
  $simple = false;
475
 
476
  if ( isset( $fields[ $meta_key ] ) ) {
477
  $field_data = $fields[ $meta_key ];
478
 
479
- $simple = ( 'pick' === $field_data['type'] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
480
  }
481
 
482
  if ( $simple ) {
483
- delete_user_meta( $id, $meta_key );
 
 
484
 
485
  if ( ! is_array( $meta_value ) ) {
486
  $meta_value = array( $meta_value );
487
  }
488
 
489
  foreach ( $meta_value as $value ) {
490
- add_user_meta( $id, $meta_key, $value );
491
  }
492
- } else {
493
- update_user_meta( $id, $meta_key, $meta_value );
494
- }
495
- }
496
- }
497
-
498
- if ( $strict ) {
499
- foreach ( $meta as $meta_key => $meta_value ) {
500
- if ( ! isset( $user_meta[ $meta_key ] ) ) {
501
- delete_user_meta( $id, $meta_key, $user_meta[ $meta_key ] );
502
  }
503
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504
  }
505
 
506
- if ( ! $conflicted ) {
507
- pods_no_conflict_off( 'user' );
508
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
 
510
- return $id;
511
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
 
513
- /**
514
- * Save a comment and it's meta
515
- *
516
- * @param array $comment_data All comment data to be saved (using wp_insert_comment / wp_update_comment)
517
- * @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
518
- * @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
519
- * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before
520
- * sending.
521
- * @param array $fields (optional) The array of fields and their options, for further processing with
522
- *
523
- * @return int Comment ID
524
- *
525
- * @since 2.0.0
526
- */
527
- public function save_comment( $comment_data, $comment_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
528
 
529
- if ( ! is_array( $comment_data ) || empty( $comment_data ) ) {
530
- return pods_error( __( 'Comment data is required but is either invalid or empty', 'pods' ), $this );
531
  }
532
 
533
- $conflicted = pods_no_conflict_check( 'comment' );
534
-
535
- if ( ! $conflicted ) {
536
- pods_no_conflict_on( 'comment' );
537
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
538
 
539
- if ( ! is_array( $comment_meta ) ) {
540
- $comment_meta = array();
541
- }
 
542
 
543
- if ( $sanitized ) {
544
- $comment_data = pods_unsanitize( $comment_data );
545
- $comment_meta = pods_unsanitize( $comment_meta );
546
- }
 
547
 
548
- if ( ! isset( $comment_data['comment_ID'] ) || empty( $comment_data['comment_ID'] ) ) {
549
- $comment_data['comment_ID'] = wp_insert_comment( pods_slash( $comment_data ) );
550
- } elseif ( 1 < count( $comment_data ) ) {
551
- // Expects slashed
552
- wp_update_comment( $comment_data );
553
  }
554
 
555
- if ( is_wp_error( $comment_data['comment_ID'] ) ) {
556
- if ( ! $conflicted ) {
557
- pods_no_conflict_off( 'comment' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558
  }
559
 
560
- /**
561
- * @var $comment_error WP_Error
562
- */
563
- $comment_error = $comment_data['comment_ID'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
564
 
565
- return pods_error( $comment_error->get_error_message(), $this );
566
- }
 
 
 
 
 
567
 
568
- $this->save_comment_meta( $comment_data['comment_ID'], $comment_meta, $strict, $fields );
 
 
 
569
 
570
- if ( ! $conflicted ) {
571
- pods_no_conflict_off( 'comment' );
572
- }
 
 
 
 
 
 
573
 
574
- return $comment_data['comment_ID'];
575
- }
576
 
577
- /**
578
- * Save a comment meta
579
- *
580
- * @param int $id Comment ID
581
- * @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
582
- * @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
583
- * @param array $fields (optional) The array of fields and their options, for further processing with
584
- *
585
- * @return int Comment ID
586
- *
587
- * @since 2.0.0
588
- */
589
- public function save_comment_meta( $id, $comment_meta = null, $strict = false, $fields = array() ) {
590
 
591
- $simple_tableless_objects = PodsForm::simple_tableless_objects();
592
 
593
- $conflicted = pods_no_conflict_check( 'comment' );
 
594
 
595
- if ( ! $conflicted ) {
596
- pods_no_conflict_on( 'comment' );
597
- }
598
 
599
- if ( ! is_array( $comment_meta ) ) {
600
- $comment_meta = array();
601
- }
602
 
603
- $id = (int) $id;
 
 
 
 
 
 
 
604
 
605
- $meta = get_comment_meta( $id );
 
 
606
 
607
- foreach ( $comment_meta as $meta_key => $meta_value ) {
608
- if ( null === $meta_value ) {
609
- $old_meta_value = '';
610
 
611
- if ( isset( $meta[ $meta_key ] ) ) {
612
- $old_meta_value = $meta[ $meta_key ];
613
- }
 
 
 
 
614
 
615
- delete_comment_meta( $id, $meta_key, $old_meta_value );
616
- } else {
617
- $simple = false;
618
 
619
- if ( isset( $fields[ $meta_key ] ) ) {
620
- $field_data = $fields[ $meta_key ];
 
621
 
622
- $simple = ( 'pick' === pods_v( 'type', $field_data ) && in_array( pods_v( 'pick_object', $field_data ), $simple_tableless_objects ) );
623
- }
 
 
 
 
624
 
625
- if ( $simple ) {
626
- delete_comment_meta( $id, $meta_key );
627
 
628
- if ( ! is_array( $meta_value ) ) {
629
- $meta_value = array( $meta_value );
630
- }
631
 
632
- foreach ( $meta_value as $value ) {
633
- add_comment_meta( $id, $meta_key, $value );
634
- }
635
- } else {
636
- update_comment_meta( $id, $meta_key, $meta_value );
637
- }
638
- }
639
- }
640
 
641
- if ( $strict ) {
642
- foreach ( $meta as $meta_key => $meta_value ) {
643
- if ( ! isset( $comment_meta[ $meta_key ] ) ) {
644
- delete_comment_meta( (int) $id, $meta_key, $comment_meta[ $meta_key ] );
645
- }
646
- }
647
- }
648
 
649
- if ( ! $conflicted ) {
650
- pods_no_conflict_off( 'comment' );
651
- }
652
 
653
- return $id;
654
- }
655
 
656
- /**
657
- * Save a taxonomy's term
658
- *
659
- * @param array $term_data All term data to be saved (using wp_insert_term / wp_update_term)
660
- * @param array $term_meta All meta to be saved (set value to null to delete)
661
- * @param bool $strict (optional) Whether to delete previously saved meta not in $post_meta
662
- * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before
663
- * sending.
664
- * @param array $fields (optional) The array of fields and their options, for further processing with
665
- *
666
- * @return int Term ID
667
- *
668
- * @since 2.0.0
669
- */
670
- public function save_term( $term_data, $term_meta, $strict = false, $sanitized = false, $fields = array() ) {
671
 
672
- if ( empty( $term_data['taxonomy'] ) ) {
673
- return 0;
674
- }
675
 
676
- $conflicted = pods_no_conflict_check( 'taxonomy' );
 
 
677
 
678
- if ( ! is_array( $term_data ) || empty( $term_data ) ) {
679
- $term_data = array( 'name' => '' );
680
- }
681
 
682
- if ( ! $conflicted ) {
683
- pods_no_conflict_on( 'taxonomy' );
684
- }
685
 
686
- if ( ! is_array( $term_meta ) ) {
687
- $term_meta = array();
688
- }
689
 
690
- if ( $sanitized ) {
691
- $term_data = pods_unsanitize( $term_data );
692
- $term_meta = pods_unsanitize( $term_meta );
693
- }
694
 
695
- $taxonomy = $term_data['taxonomy'];
696
 
697
- unset( $term_data['taxonomy'] );
 
 
 
 
698
 
699
- if ( empty( $term_data['term_id'] ) ) {
700
- $term_name = $term_data['name'];
701
 
702
- unset( $term_data['name'] );
 
703
 
704
- $term_data['term_id'] = wp_insert_term( $term_name, $taxonomy, $term_data );
705
- } elseif ( 1 < count( $term_data ) ) {
706
- $term_data['term_id'] = wp_update_term( $term_data['term_id'], $taxonomy, $term_data );
707
- }
708
 
709
- if ( is_wp_error( $term_data['term_id'] ) ) {
710
- if ( ! $conflicted ) {
711
- pods_no_conflict_off( 'taxonomy' );
712
- }
713
 
714
- /**
715
- * @var $term_error WP_Error
716
- */
717
- $term_error = $term_data['term_id'];
718
 
719
- return pods_error( $term_error->get_error_message(), $this );
720
- } elseif ( is_array( $term_data['term_id'] ) ) {
721
- $term_data['term_id'] = $term_data['term_id']['term_id'];
722
- }
723
 
724
- $this->save_term_meta( $term_data['term_id'], $term_meta, $strict, $fields );
 
725
 
726
- if ( ! $conflicted ) {
727
- pods_no_conflict_off( 'taxonomy' );
728
- }
729
 
730
- return $term_data['term_id'];
731
- }
732
 
733
- /**
734
- * Save a term's meta
735
- *
736
- * @param int $id Term ID
737
- * @param array $term_meta All meta to be saved (set value to null to delete)
738
- * @param bool $strict Whether to delete previously saved meta not in $term_meta
739
- * @param array $fields (optional) The array of fields and their options, for further processing with
740
- *
741
- * @return int Id of the term with the meta
742
- *
743
- * @since 2.0.0
744
- */
745
- public function save_term_meta( $id, $term_meta = null, $strict = false, $fields = array() ) {
746
 
747
- if ( ! function_exists( 'get_term_meta' ) ) {
748
- return $id;
749
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
750
 
751
- $simple_tableless_objects = PodsForm::simple_tableless_objects();
 
752
 
753
- $conflicted = pods_no_conflict_check( 'taxonomy' );
754
 
755
- if ( ! $conflicted ) {
756
- pods_no_conflict_on( 'taxonomy' );
 
 
757
  }
758
 
759
- if ( ! is_array( $term_meta ) ) {
760
- $term_meta = array();
 
 
 
 
 
 
 
 
761
  }
762
 
763
- $id = (int) $id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
764
 
765
- $meta = get_term_meta( $id );
766
 
767
- foreach ( $meta as $k => $value ) {
768
- if ( is_array( $value ) && 1 == count( $value ) ) {
769
- $meta[ $k ] = current( $value );
770
- }
771
- }
772
 
773
- foreach ( $term_meta as $meta_key => $meta_value ) {
774
- if ( null === $meta_value || ( $strict && '' === $term_meta[ $meta_key ] ) ) {
775
- $old_meta_value = '';
776
 
777
- if ( isset( $meta[ $meta_key ] ) ) {
778
- $old_meta_value = $meta[ $meta_key ];
779
- }
780
 
781
- delete_term_meta( $id, $meta_key, $old_meta_value );
782
- } else {
783
- $simple = false;
784
 
785
- if ( isset( $fields[ $meta_key ] ) ) {
786
- $field_data = $fields[ $meta_key ];
 
787
 
788
- $simple = ( 'pick' === pods_v( 'type', $field_data ) && in_array( pods_v( 'pick_object', $field_data ), $simple_tableless_objects ) );
789
- }
790
 
791
- if ( $simple ) {
792
- delete_term_meta( $id, $meta_key );
793
 
794
- update_term_meta( $id, '_pods_' . $meta_key, $meta_value );
 
795
 
796
- if ( ! is_array( $meta_value ) ) {
797
- $meta_value = array( $meta_value );
798
- }
799
 
800
- foreach ( $meta_value as $value ) {
801
- add_term_meta( $id, $meta_key, $value );
802
- }
803
- } else {
804
- update_term_meta( $id, $meta_key, $meta_value );
805
- }
806
- }
807
- }
808
 
809
- if ( $strict ) {
810
- foreach ( $meta as $meta_key => $meta_value ) {
811
- if ( ! isset( $term_meta[ $meta_key ] ) ) {
812
- delete_term_meta( $id, $meta_key, $meta_value );
813
- }
814
- }
815
- }
816
 
817
- if ( ! $conflicted ) {
818
- pods_no_conflict_off( 'taxonomy' );
819
- }
820
 
821
- return $id;
822
- }
 
 
823
 
824
- /**
825
- * Save a set of options
826
- *
827
- * @param string $setting Setting group name
828
- * @param array $option_data All option data to be saved
829
- * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before
830
- * sending.
831
- *
832
- * @return bool
833
- *
834
- * @since 2.3.0
835
- */
836
- public function save_setting( $setting, $option_data, $sanitized = false ) {
837
 
838
- if ( ! is_array( $option_data ) || empty( $option_data ) ) {
839
- return pods_error( __( 'Setting data is required but is either invalid or empty', 'pods' ), $this );
840
- }
841
 
842
- $conflicted = pods_no_conflict_check( 'settings' );
 
843
 
844
- if ( ! $conflicted ) {
845
- pods_no_conflict_on( 'settings' );
846
- }
847
 
848
- if ( $sanitized ) {
849
- $option_data = pods_unsanitize( $option_data );
850
- }
851
 
852
- foreach ( $option_data as $option => $value ) {
853
- if ( ! empty( $setting ) ) {
854
- $option = $setting . '_' . $option;
855
- }
856
 
857
- update_option( $option, $value );
858
- }
 
 
 
 
859
 
860
- if ( ! $conflicted ) {
861
- pods_no_conflict_off( 'settings' );
862
- }
 
863
 
864
- return true;
865
- }
866
 
867
- /**
868
- * Rename a WP object's type
869
- *
870
- * @param string $object_type Object type: post|taxonomy|comment|setting
871
- * @param string $old_name The old name
872
- * @param string $new_name The new name
873
- *
874
- * @return bool
875
- *
876
- * @since 2.0.0
877
- */
878
- public function rename_wp_object_type( $object_type, $old_name, $new_name ) {
879
 
880
  /**
881
- * @var $wpdb wpdb
 
 
 
 
 
 
882
  */
883
- global $wpdb;
884
 
885
- if ( 'post_type' === $object_type ) {
886
- $object_type = 'post';
887
- }
888
 
889
- if ( 'post' === $object_type ) {
890
- pods_query( "UPDATE `{$wpdb->posts}` SET `post_type` = %s WHERE `post_type` = %s", array(
891
- $new_name,
892
- $old_name
893
- ) );
894
- } elseif ( 'taxonomy' === $object_type ) {
895
- pods_query( "UPDATE `{$wpdb->term_taxonomy}` SET `taxonomy` = %s WHERE `taxonomy` = %s", array(
896
- $new_name,
897
- $old_name
898
- ) );
899
- } elseif ( 'comment' === $object_type ) {
900
- pods_query( "UPDATE `{$wpdb->comments}` SET `comment_type` = %s WHERE `comment_type` = %s", array(
901
- $new_name,
902
- $old_name
903
- ) );
904
- } elseif ( 'settings' === $object_type ) {
905
- pods_query( "UPDATE `{$wpdb->options}` SET `option_name` = REPLACE( `option_name`, %s, %s ) WHERE `option_name` LIKE '" . pods_sanitize_like( $old_name ) . "_%'", array(
906
- $new_name . '_',
907
- $old_name . '_'
908
- ) );
909
  }
910
 
911
- return true;
912
- }
 
 
913
 
914
- /**
915
- * Get a list of core WP object fields for a specific object
916
- *
917
- * @param string $object The pod type to look for, possible values: post_type, user, comment, taxonomy
918
- * @param array $pod Array of Pod data
919
- * @param boolean $refresh Whether to force refresh the information
920
- *
921
- * @return array Array of fields
922
- *
923
- * @since 2.0.0
924
- */
925
- public function get_wp_object_fields( $object = 'post_type', $pod = null, $refresh = false ) {
926
 
927
- $pod_name = pods_var_raw( 'name', $pod, $object, null, true );
 
928
 
929
- if ( 'media' === $pod_name ) {
930
- $object = 'post_type';
931
- $pod_name = 'attachment';
932
- }
933
 
934
- $fields = false;
 
935
 
936
- if ( pods_api_cache() ) {
937
- $fields = pods_transient_get( trim( 'pods_api_object_fields_' . $object . $pod_name . '_', '_' ) );
938
- }
939
 
940
- if ( false !== $fields && ! $refresh ) {
941
- return $this->do_hook( 'get_wp_object_fields', $fields, $object, $pod );
942
- }
943
 
944
- $fields = array();
945
-
946
- if ( 'post_type' === $object ) {
947
- $fields = array(
948
- 'ID' => array(
949
- 'name' => 'ID',
950
- 'label' => 'ID',
951
- 'type' => 'number',
952
- 'alias' => array( 'id' ),
953
- 'options' => array(
954
- 'number_format' => '9999.99'
955
- )
956
- ),
957
- 'post_title' => array(
958
- 'name' => 'post_title',
959
- 'label' => 'Title',
960
- 'type' => 'text',
961
- 'alias' => array( 'title', 'name' ),
962
- 'options' => array(
963
- 'display_filter' => 'the_title',
964
- 'display_filter_args' => array( 'post_ID' )
965
- )
966
- ),
967
- 'post_content' => array(
968
- 'name' => 'post_content',
969
- 'label' => 'Content',
970
- 'type' => 'wysiwyg',
971
- 'alias' => array( 'content' ),
972
- 'options' => array(
973
- 'wysiwyg_allowed_html_tags' => '',
974
- 'display_filter' => 'the_content',
975
- 'pre_save' => 0
976
- )
977
- ),
978
- 'post_excerpt' => array(
979
- 'name' => 'post_excerpt',
980
- 'label' => 'Excerpt',
981
- 'type' => 'paragraph',
982
- 'alias' => array( 'excerpt' ),
983
- 'options' => array(
984
- 'paragraph_allow_html' => 1,
985
- 'paragraph_allowed_html_tags' => '',
986
- 'display_filter' => 'the_excerpt',
987
- 'pre_save' => 0
988
- )
989
- ),
990
- 'post_author' => array(
991
- 'name' => 'post_author',
992
- 'label' => 'Author',
993
- 'type' => 'pick',
994
- 'alias' => array( 'author' ),
995
- 'pick_object' => 'user',
996
- 'options' => array(
997
- 'pick_format_type' => 'single',
998
- 'pick_format_single' => 'autocomplete',
999
- 'default_value' => '{@user.ID}'
1000
- )
1001
- ),
1002
- 'post_date' => array(
1003
- 'name' => 'post_date',
1004
- 'label' => 'Publish Date',
1005
- 'type' => 'datetime',
1006
- 'alias' => array( 'created', 'date' )
1007
- ),
1008
- 'post_date_gmt' => array(
1009
- 'name' => 'post_date_gmt',
1010
- 'label' => 'Publish Date (GMT)',
1011
- 'type' => 'datetime',
1012
- 'alias' => array(),
1013
- 'hidden' => true
1014
- ),
1015
- 'post_status' => array(
1016
- 'name' => 'post_status',
1017
- 'label' => 'Status',
1018
- 'type' => 'pick',
1019
- 'pick_object' => 'post-status',
1020
- 'default' => $this->do_hook( 'default_status_' . $pod_name, pods_var( 'default_status', pods_var_raw( 'options', $pod ), 'draft', null, true ), $pod ),
1021
- 'alias' => array( 'status' )
1022
- ),
1023
- 'comment_status' => array(
1024
- 'name' => 'comment_status',
1025
- 'label' => 'Comment Status',
1026
- 'type' => 'text',
1027
- 'default' => get_option( 'default_comment_status', 'open' ),
1028
- 'alias' => array(),
1029
- 'data' => array(
1030
- 'open' => __( 'Open', 'pods' ),
1031
- 'closed' => __( 'Closed', 'pods' )
1032
- )
1033
- ),
1034
- 'ping_status' => array(
1035
- 'name' => 'ping_status',
1036
- 'label' => 'Ping Status',
1037
- 'default' => get_option( 'default_ping_status', 'open' ),
1038
- 'type' => 'text',
1039
- 'alias' => array(),
1040
- 'data' => array(
1041
- 'open' => __( 'Open', 'pods' ),
1042
- 'closed' => __( 'Closed', 'pods' )
1043
- )
1044
- ),
1045
- 'post_password' => array(
1046
- 'name' => 'post_password',
1047
- 'label' => 'Password',
1048
- 'type' => 'text',
1049
- 'alias' => array()
1050
- ),
1051
- 'post_name' => array(
1052
- 'name' => 'post_name',
1053
- 'label' => 'Permalink',
1054
- 'type' => 'slug',
1055
- 'alias' => array( 'slug', 'permalink' )
1056
- ),
1057
- 'to_ping' => array(
1058
- 'name' => 'to_ping',
1059
- 'label' => 'To Ping',
1060
- 'type' => 'text',
1061
- 'alias' => array(),
1062
- 'hidden' => true
1063
- ),
1064
- 'pinged' => array(
1065
- 'name' => 'pinged',
1066
- 'label' => 'Pinged',
1067
- 'type' => 'text',
1068
- 'alias' => array(),
1069
- 'hidden' => true
1070
- ),
1071
- 'post_modified' => array(
1072
- 'name' => 'post_modified',
1073
- 'label' => 'Last Modified Date',
1074
- 'type' => 'datetime',
1075
- 'alias' => array( 'modified' ),
1076
- 'hidden' => true
1077
- ),
1078
- 'post_modified_gmt' => array(
1079
- 'name' => 'post_modified_gmt',
1080
- 'label' => 'Last Modified Date (GMT)',
1081
- 'type' => 'datetime',
1082
- 'alias' => array(),
1083
- 'hidden' => true
1084
- ),
1085
- 'post_content_filtered' => array(
1086
- 'name' => 'post_content_filtered',
1087
- 'label' => 'Content (filtered)',
1088
- 'type' => 'paragraph',
1089
- 'alias' => array(),
1090
- 'hidden' => true,
1091
- 'options' => array(
1092
- 'paragraph_allow_html' => 1,
1093
- 'paragraph_oembed' => 1,
1094
- 'paragraph_wptexturize' => 1,
1095
- 'paragraph_convert_chars' => 1,
1096
- 'paragraph_wpautop' => 1,
1097
- 'paragraph_allow_shortcode' => 1,
1098
- 'paragraph_allowed_html_tags' => ''
1099
- )
1100
- ),
1101
- 'post_parent' => array(
1102
- 'name' => 'post_parent',
1103
- 'label' => 'Parent',
1104
- 'type' => 'pick',
1105
- 'pick_object' => 'post_type',
1106
- 'pick_val' => '__current__',
1107
- 'alias' => array( 'parent' ),
1108
- 'data' => array(),
1109
- 'hidden' => true
1110
- ),
1111
- 'guid' => array(
1112
- 'name' => 'guid',
1113
- 'label' => 'GUID',
1114
- 'type' => 'text',
1115
- 'alias' => array(),
1116
- 'hidden' => true
1117
- ),
1118
- 'menu_order' => array(
1119
- 'name' => 'menu_order',
1120
- 'label' => 'Menu Order',
1121
- 'type' => 'number',
1122
- 'alias' => array(),
1123
- 'options' => array(
1124
- 'number_format' => '9999.99'
1125
- )
1126
- ),
1127
- 'post_type' => array(
1128
- 'name' => 'post_type',
1129
- 'label' => 'Type',
1130
- 'type' => 'text',
1131
- 'alias' => array( 'type' ),
1132
- 'hidden' => true
1133
- ),
1134
- 'post_mime_type' => array(
1135
- 'name' => 'post_mime_type',
1136
- 'label' => 'Mime Type',
1137
- 'type' => 'text',
1138
- 'alias' => array(),
1139
- 'hidden' => true
1140
- ),
1141
- 'comment_count' => array(
1142
- 'name' => 'comment_count',
1143
- 'label' => 'Comment Count',
1144
- 'type' => 'number',
1145
- 'alias' => array(),
1146
- 'hidden' => true
1147
- ),
1148
- 'comments' => array(
1149
- 'name' => 'comments',
1150
- 'label' => 'Comments',
1151
- 'type' => 'comment',
1152
- 'pick_object' => 'comment',
1153
- 'pick_val' => 'comment',
1154
- 'alias' => array(),
1155
- 'hidden' => true,
1156
- 'options' => array(
1157
- 'comment_format_type' => 'multi'
1158
- )
1159
- )
1160
- );
1161
 
1162
- if ( ! empty( $pod ) ) {
1163
- $taxonomies = get_object_taxonomies( $pod_name, 'objects' );
1164
 
1165
- foreach ( $taxonomies as $taxonomy ) {
1166
- $fields[ $taxonomy->name ] = array(
1167
- 'name' => $taxonomy->name,
1168
- 'label' => $taxonomy->labels->name,
1169
- 'type' => 'taxonomy',
1170
- 'pick_object' => 'taxonomy',
1171
- 'pick_val' => $taxonomy->name,
1172
- 'alias' => array(),
1173
- 'hidden' => true,
1174
- 'options' => array(
1175
- 'taxonomy_format_type' => 'multi'
1176
- )
1177
- );
1178
- }
1179
- }
1180
- } elseif ( 'user' === $object ) {
1181
- $fields = array(
1182
- 'ID' => array(
1183
- 'name' => 'ID',
1184
- 'label' => 'ID',
1185
- 'type' => 'number',
1186
- 'alias' => array( 'id' ),
1187
- 'options' => array(
1188
- 'number_format' => '9999.99'
1189
- )
1190
- ),
1191
- 'user_login' => array(
1192
- 'name' => 'user_login',
1193
- 'label' => 'Title',
1194
- 'type' => 'text',
1195
- 'alias' => array( 'login' ),
1196
- 'options' => array(
1197
- 'required' => 1
1198
- )
1199
- ),
1200
- 'user_nicename' => array(
1201
- 'name' => 'user_nicename',
1202
- 'label' => 'Permalink',
1203
- 'type' => 'slug',
1204
- 'alias' => array( 'nicename', 'slug', 'permalink' )
1205
- ),
1206
- 'display_name' => array(
1207
- 'name' => 'display_name',
1208
- 'label' => 'Display Name',
1209
- 'type' => 'text',
1210
- 'alias' => array( 'title', 'name' )
1211
- ),
1212
- 'user_pass' => array(
1213
- 'name' => 'user_pass',
1214
- 'label' => 'Password',
1215
- 'type' => 'text',
1216
- 'alias' => array( 'password', 'pass' ),
1217
- 'options' => array(
1218
- 'required' => 1,
1219
- 'text_format_type' => 'password'
1220
- )
1221
- ),
1222
- 'user_email' => array(
1223
- 'name' => 'user_email',
1224
- 'label' => 'E-mail',
1225
- 'type' => 'text',
1226
- 'alias' => array( 'email' ),
1227
- 'options' => array(
1228
- 'required' => 1,
1229
- 'text_format_type' => 'email'
1230
- )
1231
- ),
1232
- 'user_url' => array(
1233
- 'name' => 'user_url',
1234
- 'label' => 'URL',
1235
- 'type' => 'text',
1236
- 'alias' => array( 'url', 'website' ),
1237
- 'options' => array(
1238
- 'required' => 0,
1239
- 'text_format_type' => 'website',
1240
- 'text_format_website' => 'normal'
1241
- )
1242
- ),
1243
- 'user_registered' => array(
1244
- 'name' => 'user_registered',
1245
- 'label' => 'Registration Date',
1246
- 'type' => 'date',
1247
- 'alias' => array( 'created', 'date', 'registered' ),
1248
- 'options' => array(
1249
- 'date_format_type' => 'datetime'
1250
- )
1251
- )
1252
- );
1253
- } elseif ( 'comment' === $object ) {
1254
- $fields = array(
1255
- 'comment_ID' => array(
1256
- 'name' => 'comment_ID',
1257
- 'label' => 'ID',
1258
- 'type' => 'number',
1259
- 'alias' => array( 'id', 'ID', 'comment_id' ),
1260
- 'options' => array(
1261
- 'number_format' => '9999.99'
1262
- )
1263
- ),
1264
- 'comment_content' => array(
1265
- 'name' => 'comment_content',
1266
- 'label' => 'Content',
1267
- 'type' => 'wysiwyg',
1268
- 'alias' => array( 'content' )
1269
- ),
1270
- 'comment_approved' => array(
1271
- 'name' => 'comment_approved',
1272
- 'label' => 'Approved',
1273
- 'type' => 'number',
1274
- 'alias' => array( 'approved' ),
1275
- 'options' => array(
1276
- 'number_format' => '9999.99'
1277
- )
1278
- ),
1279
- 'comment_post_ID' => array(
1280
- 'name' => 'comment_post_ID',
1281
- 'label' => 'Post',
1282
- 'type' => 'pick',
1283
- 'alias' => array( 'post', 'post_id' ),
1284
- 'data' => array()
1285
- ),
1286
- 'user_id' => array(
1287
- 'name' => 'user_id',
1288
- 'label' => 'Author',
1289
- 'type' => 'pick',
1290
- 'alias' => array( 'author' ),
1291
- 'pick_object' => 'user',
1292
- 'data' => array()
1293
- ),
1294
- 'comment_date' => array(
1295
- 'name' => 'comment_date',
1296
- 'label' => 'Date',
1297
- 'type' => 'date',
1298
- 'alias' => array( 'created', 'date' ),
1299
- 'options' => array(
1300
- 'date_format_type' => 'datetime'
1301
- )
1302
- ),
1303
- 'comment_author' => array(
1304
- 'name' => 'comment_author',
1305
- 'label' => 'Author',
1306
- 'type' => 'text',
1307
- 'alias' => array( 'author' )
1308
- ),
1309
- 'comment_author_email' => array(
1310
- 'name' => 'comment_author_email',
1311
- 'label' => 'Author E-mail',
1312
- 'type' => 'email',
1313
- 'alias' => array( 'author_email' )
1314
- ),
1315
- 'comment_author_url' => array(
1316
- 'name' => 'comment_author_url',
1317
- 'label' => 'Author URL',
1318
- 'type' => 'text',
1319
- 'alias' => array( 'author_url' )
1320
- ),
1321
- 'comment_author_IP' => array(
1322
- 'name' => 'comment_author_IP',
1323
- 'label' => 'Author IP',
1324
- 'type' => 'text',
1325
- 'alias' => array( 'author_IP' )
1326
- ),
1327
- 'comment_type' => array(
1328
- 'name' => 'comment_type',
1329
- 'label' => 'Type',
1330
- 'type' => 'text',
1331
- 'alias' => array( 'type' ),
1332
- 'hidden' => true
1333
- ),
1334
- 'comment_parent' => array(
1335
- 'name' => 'comment_parent',
1336
- 'label' => 'Parent',
1337
- 'type' => 'pick',
1338
- 'pick_object' => 'comment',
1339
- 'pick_val' => '__current__',
1340
- 'alias' => array( 'parent' ),
1341
- 'data' => array(),
1342
- 'hidden' => true
1343
- )
1344
- );
1345
- } elseif ( 'taxonomy' === $object ) {
1346
- $fields = array(
1347
- 'term_id' => array(
1348
- 'name' => 'term_id',
1349
- 'label' => 'ID',
1350
- 'type' => 'number',
1351
- 'alias' => array( 'id', 'ID' ),
1352
- 'options' => array(
1353
- 'number_format' => '9999.99'
1354
- )
1355
- ),
1356
- 'name' => array(
1357
- 'name' => 'name',
1358
- 'label' => 'Title',
1359
- 'type' => 'text',
1360
- 'alias' => array( 'title' )
1361
- ),
1362
- 'slug' => array(
1363
- 'name' => 'slug',
1364
- 'label' => 'Permalink',
1365
- 'type' => 'slug',
1366
- 'alias' => array( 'permalink' )
1367
- ),
1368
- 'description' => array(
1369
- 'name' => 'description',
1370
- 'label' => 'Description',
1371
- 'type' => 'wysiwyg',
1372
- 'alias' => array( 'content' )
1373
- ),
1374
- 'taxonomy' => array(
1375
- 'name' => 'taxonomy',
1376
- 'label' => 'Taxonomy',
1377
- 'type' => 'text',
1378
- 'alias' => array()
1379
- ),
1380
- 'parent' => array(
1381
- 'name' => 'parent',
1382
- 'label' => 'Parent',
1383
- 'type' => 'pick',
1384
- 'pick_object' => 'taxonomy',
1385
- 'pick_val' => '__current__',
1386
- 'alias' => array( 'parent' ),
1387
- 'data' => array(),
1388
- 'hidden' => true
1389
- ),
1390
- 'term_taxonomy_id' => array(
1391
- 'name' => 'term_taxonomy_id',
1392
- 'label' => 'Term Taxonomy ID',
1393
- 'type' => 'number',
1394
- 'alias' => array(),
1395
- 'hidden' => true,
1396
- 'options' => array(
1397
- 'number_format' => '9999.99'
1398
- )
1399
- ),
1400
- 'term_group' => array(
1401
- 'name' => 'term_group',
1402
- 'label' => 'Term Group',
1403
- 'type' => 'number',
1404
- 'alias' => array( 'group' ),
1405
- 'hidden' => true,
1406
- 'options' => array(
1407
- 'number_format' => '9999.99'
1408
- )
1409
- ),
1410
- 'count' => array(
1411
- 'name' => 'count',
1412
- 'label' => 'Count',
1413
- 'type' => 'number',
1414
- 'alias' => array(),
1415
- 'hidden' => true,
1416
- 'options' => array(
1417
- 'number_format' => '9999.99'
1418
- )
1419
- )
1420
- );
1421
- }
1422
 
1423
- $fields = $this->do_hook( 'get_wp_object_fields', $fields, $object, $pod );
 
1424
 
1425
- foreach ( $fields as $field => $options ) {
1426
- if ( ! isset( $options['alias'] ) ) {
1427
- $options['alias'] = array();
1428
- } else {
1429
- $options['alias'] = (array) $options['alias'];
1430
- }
1431
 
1432
- if ( ! isset( $options['name'] ) ) {
1433
- $options['name'] = $field;
1434
- }
1435
 
1436
- $fields[ $field ] = $options;
1437
- }
1438
 
1439
- $fields = PodsForm::fields_setup( $fields );
 
1440
 
1441
- if ( did_action( 'init' ) && pods_api_cache() ) {
1442
- pods_transient_set( trim( 'pods_api_object_fields_' . $object . $pod_name . '_', '_' ), $fields );
1443
- }
1444
 
1445
- return $fields;
1446
- }
1447
 
1448
- /**
1449
- *
1450
- * @see PodsAPI::save_pod
1451
- *
1452
- * Add a Pod via the Wizard
1453
- *
1454
- * $params['create_extend'] string Create or Extend a Content Type
1455
- * $params['create_pod_type'] string Pod Type (for Creating)
1456
- * $params['create_name'] string Pod Name (for Creating)
1457
- * $params['create_label_plural'] string Plural Label (for Creating)
1458
- * $params['create_label_singular'] string Singular Label (for Creating)
1459
- * $params['create_storage'] string Storage Type (for Creating Post Types)
1460
- * $params['create_storage_taxonomy'] string Storage Type (for Creating Taxonomies)
1461
- * $params['extend_pod_type'] string Pod Type (for Extending)
1462
- * $params['extend_post_type'] string Post Type (for Extending Post Types)
1463
- * $params['extend_taxonomy'] string Taxonomy (for Extending Taxonomies)
1464
- * $params['extend_storage'] string Storage Type (for Extending Post Types / Users / Comments)
1465
- *
1466
- * @param array $params An associative array of parameters
1467
- *
1468
- * @return bool|int Pod ID
1469
- * @since 2.0.0
1470
- */
1471
- public function add_pod( $params ) {
1472
-
1473
- $defaults = array(
1474
- 'create_extend' => 'create',
1475
- 'create_pod_type' => 'post_type',
1476
-
1477
- 'create_name' => '',
1478
- 'create_label_singular' => '',
1479
- 'create_label_plural' => '',
1480
- 'create_storage' => 'meta',
1481
- 'create_storage_taxonomy' => '',
1482
-
1483
- 'create_setting_name' => '',
1484
- 'create_label_title' => '',
1485
- 'create_label_menu' => '',
1486
- 'create_menu_location' => 'settings',
1487
-
1488
- 'extend_pod_type' => 'post_type',
1489
- 'extend_post_type' => 'post',
1490
- 'extend_taxonomy' => 'category',
1491
- 'extend_table' => '',
1492
- 'extend_storage' => 'meta',
1493
- 'extend_storage_taxonomy' => '',
1494
- );
1495
 
1496
- if( !function_exists( 'get_term_meta' ) ) {
1497
- $defaults['create_storage_taxonomy'] = 'none';
1498
- $defaults['extend_storage_taxonomy' ] = 'table' ;
1499
- }
1500
 
1501
- $params = (object) array_merge( $defaults, (array) $params );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1502
 
1503
- if ( empty( $params->create_extend ) || ! in_array( $params->create_extend, array( 'create', 'extend' ) ) ) {
1504
- return pods_error( __( 'Please choose whether to Create or Extend a Content Type', 'pods' ), $this );
1505
- }
 
1506
 
1507
- $pod_params = array(
1508
- 'name' => '',
1509
- 'label' => '',
1510
- 'type' => '',
1511
- 'storage' => 'table',
1512
- 'object' => '',
1513
- 'options' => array(),
1514
- 'create_extend' => $params->create_extend,
1515
- );
1516
 
1517
- if ( 'create' === $params->create_extend ) {
1518
- $label = ucwords( str_replace( '_', ' ', $params->create_name ) );
 
1519
 
1520
- if ( ! empty( $params->create_label_singular ) ) {
1521
- $label = $params->create_label_singular;
1522
- }
 
1523
 
1524
- $pod_params['name'] = $params->create_name;
1525
- $pod_params['label'] = ( ! empty( $params->create_label_plural ) ? $params->create_label_plural : $label );
1526
- $pod_params['type'] = $params->create_pod_type;
1527
- $pod_params['options'] = array(
1528
- 'label_singular' => ( ! empty( $params->create_label_singular ) ? $params->create_label_singular : $pod_params['label'] ),
1529
- 'public' => 1,
1530
- 'show_ui' => 1
1531
- );
1532
 
1533
- // Auto-generate name if not provided
1534
- if ( empty( $pod_params['name'] ) && ! empty( $pod_params['options']['label_singular'] ) ) {
1535
- $pod_params['name'] = pods_clean_name( $pod_params['options']['label_singular'] );
1536
- }
1537
 
1538
- if ( 'post_type' === $pod_params['type'] ) {
1539
- if ( empty( $pod_params['name'] ) ) {
1540
- return pods_error( __( 'Please enter a Name for this Pod', 'pods' ), $this );
1541
- }
1542
 
1543
- $pod_params['storage'] = $params->create_storage;
 
 
 
1544
 
1545
- if ( pods_tableless() ) {
1546
- $pod_params['storage'] = 'meta';
1547
- }
1548
- } elseif ( 'taxonomy' === $pod_params['type'] ) {
1549
- if ( empty( $pod_params['name'] ) ) {
1550
- return pods_error( __( 'Please enter a Name for this Pod', 'pods' ), $this );
1551
- }
1552
 
1553
- $pod_params['storage'] = $params->create_storage;
 
 
 
 
1554
 
1555
- if ( ! function_exists( 'get_term_meta' ) || ! empty( $params->create_storage_taxonomy ) ) {
1556
- $pod_params['storage'] = $params->create_storage_taxonomy;
1557
- }
1558
 
1559
- if ( pods_tableless() ) {
1560
- $pod_params['storage'] = ( function_exists( 'get_term_meta' ) ? 'meta' : 'none' );
1561
- }
 
 
 
1562
 
1563
- $pod_params['options']['hierarchical'] = 1;
1564
- } elseif ( 'pod' === $pod_params['type'] ) {
1565
- if ( empty( $pod_params['name'] ) ) {
1566
- return pods_error( __( 'Please enter a Name for this Pod', 'pod' ), $this );
 
 
 
 
 
 
 
 
 
 
 
 
1567
  }
 
1568
 
1569
- if ( pods_tableless() ) {
1570
- $pod_params['type'] = 'post_type';
1571
- $pod_params['storage'] = 'meta';
 
1572
  }
1573
- } elseif ( 'settings' === $pod_params['type'] ) {
1574
- $pod_params['name'] = $params->create_setting_name;
1575
- $pod_params['label'] = ( ! empty( $params->create_label_title ) ? $params->create_label_title : ucwords( str_replace( '_', ' ', $params->create_setting_name ) ) );
1576
- $pod_params['options'] = array(
1577
- 'menu_name' => ( ! empty( $params->create_label_menu ) ? $params->create_label_menu : $pod_params['label'] ),
1578
- 'menu_location' => $params->create_menu_location
1579
- );
1580
- $pod_params['storage'] = 'none';
1581
-
1582
- // Auto-generate name if not provided
1583
- if ( empty( $pod_params['name'] ) && ! empty( $pod_params['label'] ) ) {
1584
- $pod_params['name'] = pods_clean_name( $pod_params['label'] );
1585
  }
1586
 
1587
- if ( empty( $pod_params['name'] ) ) {
1588
- return pods_error( __( 'Please enter a Name for this Pod', 'pods' ), $this );
 
 
 
1589
  }
1590
  }
1591
- } elseif ( 'extend' === $params->create_extend ) {
1592
- $pod_params['type'] = $params->extend_pod_type;
1593
 
1594
- if ( 'post_type' === $pod_params['type'] ) {
1595
- $pod_params['storage'] = $params->extend_storage;
 
1596
 
1597
- if ( pods_tableless() ) {
1598
- $pod_params['storage'] = 'meta';
1599
- }
1600
 
1601
- $pod_params['name'] = $params->extend_post_type;
1602
- } elseif ( 'taxonomy' === $pod_params['type'] ) {
1603
- $pod_params['storage'] = $params->extend_storage;
 
 
 
 
 
 
 
 
1604
 
1605
- if ( ! function_exists( 'get_term_meta' ) || ! empty( $params->extend_storage_taxonomy ) ) {
1606
- $pod_params['storage'] = $params->extend_storage_taxonomy;
1607
- }
1608
 
1609
- if ( pods_tableless() ) {
1610
- $pod_params['storage'] = ( function_exists( 'get_term_meta' ) ? 'meta' : 'none' );
1611
- }
1612
 
1613
- $pod_params['name'] = $params->extend_taxonomy;
1614
- } elseif ( 'table' === $pod_params['type'] ) {
1615
- $pod_params['storage'] = 'table';
1616
- $pod_params['name'] = $params->extend_table;
1617
- } else {
1618
- $pod_params['storage'] = $params->extend_storage;
1619
 
1620
- if ( pods_tableless() ) {
1621
- $pod_params['storage'] = 'meta';
1622
- }
1623
 
1624
- $pod_params['name'] = $params->extend_pod_type;
1625
- }
1626
 
1627
- $pod_params['label'] = ucwords( str_replace( '_', ' ', $pod_params['name'] ) );
1628
- $pod_params['object'] = $pod_params['name'];
1629
- }
1630
 
1631
- if ( empty( $pod_params['object'] ) ) {
1632
- if ( 'post_type' === $pod_params['type'] ) {
1633
- $check = get_post_type_object( $pod_params['name'] );
1634
 
1635
- if ( ! empty( $check ) ) {
1636
- return pods_error( sprintf( __( 'Post Type %s already exists, try extending it instead', 'pods' ), $pod_params['name'] ), $this );
1637
- }
 
 
1638
 
1639
- $pod_params['options']['supports_title'] = 1;
1640
- $pod_params['options']['supports_editor'] = 1;
1641
- } elseif ( 'taxonomy' === $pod_params['type'] ) {
1642
- $check = get_taxonomy( $pod_params['name'] );
1643
 
1644
- if ( ! empty( $check ) ) {
1645
- return pods_error( sprintf( __( 'Taxonomy %s already exists, try extending it instead', 'pods' ), $pod_params['name'] ), $this );
1646
- }
1647
- }
1648
- }
1649
 
1650
- if ( ! empty( $pod_params ) ) {
1651
- return $this->save_pod( $pod_params );
1652
- }
1653
 
1654
- return false;
1655
- }
 
 
1656
 
1657
- /**
1658
- * Add or edit a Pod
1659
- *
1660
- * $params['id'] int The Pod ID
1661
- * $params['name'] string The Pod name
1662
- * $params['label'] string The Pod label
1663
- * $params['type'] string The Pod type
1664
- * $params['object'] string The object being extended (if any)
1665
- * $params['storage'] string The Pod storage
1666
- * $params['options'] array Options
1667
- * $params['create_extend'] string Create or Extend a Content Type
1668
- *
1669
- * @param array $params An associative array of parameters
1670
- * @param bool $sanitized (optional) Decides whether the params have been sanitized before being passed, will
1671
- * sanitize them if false.
1672
- * @param bool|int $db (optional) Whether to save into the DB or just return Pod array.
1673
- *
1674
- * @return int Pod ID
1675
- * @since 1.7.9
1676
- */
1677
- public function save_pod( $params, $sanitized = false, $db = true ) {
1678
 
1679
- $tableless_field_types = PodsForm::tableless_field_types();
1680
- $simple_tableless_objects = PodsForm::simple_tableless_objects();
1681
 
1682
- $extend = ( is_array( $params ) && ! empty( $params['create_extend'] ) && 'extend' === $params['create_extend'] );
1683
- unset( $params['create_extend'] );
1684
 
1685
- $load_params = (object) $params;
 
 
 
 
 
1686
 
1687
- if ( isset( $load_params->id ) && isset( $load_params->name ) ) {
1688
- unset( $load_params->name );
1689
  }
1690
 
1691
- if ( isset( $load_params->old_name ) ) {
1692
- $load_params->name = $load_params->old_name;
1693
- }
1694
 
1695
- $load_params->table_info = true;
1696
 
1697
- $pod = $this->load_pod( $load_params, false );
1698
 
1699
- $params = (object) $params;
 
 
 
1700
 
1701
- if ( false === $sanitized ) {
1702
- $params = pods_sanitize( $params );
1703
- }
1704
 
1705
- $old_id = null;
1706
- $old_name = null;
1707
- $old_storage = null;
 
1708
 
1709
- $old_fields = array();
1710
- $old_options = array();
1711
 
1712
- if ( isset( $params->name ) && ! isset( $params->object ) ) {
1713
- $params->name = pods_clean_name( $params->name );
1714
- }
 
 
 
 
 
1715
 
1716
- if ( ! empty( $pod ) ) {
1717
- // Existing pod (update).
 
1718
 
1719
- if ( isset( $params->id ) && 0 < $params->id ) {
1720
- $old_id = $params->id;
1721
- }
 
 
 
1722
 
1723
- $params->id = $pod['id'];
 
 
 
1724
 
1725
- $old_name = $pod['name'];
1726
- $old_storage = $pod['storage'];
1727
- $old_fields = $pod['fields'];
1728
- $old_options = $pod['options'];
1729
 
1730
- // Check if name is intentionally not set, set it as current name.
1731
- if ( ! isset( $params->name ) ) {
1732
- $params->name = $pod['name'];
1733
- }
1734
 
1735
- if ( $old_name !== $params->name ) {
1736
- if ( false !== $this->pod_exists( array( 'name' => $params->name ) ) ) {
1737
- return pods_error( sprintf( __( 'Pod %1$s already exists, you cannot rename %2$s to that', 'pods' ), $params->name, $old_name ), $this );
1738
- }
1739
 
1740
- if (
1741
- in_array( $pod['type'], array( 'user', 'comment', 'media' ), true )
1742
- && in_array( $pod['object'], array( 'user', 'comment', 'media' ), true )
1743
- ) {
1744
- return pods_error( sprintf( __( 'Pod %s cannot be renamed, it extends an existing WP Object', 'pods' ), $old_name ), $this );
1745
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1746
 
1747
- if (
1748
- in_array( $pod['type'], array( 'post_type', 'taxonomy' ), true )
1749
- && ! empty( $pod['object'] )
1750
- && $pod['object'] == $old_name
1751
- ) {
1752
- return pods_error( sprintf( __( 'Pod %s cannot be renamed, it extends an existing WP Object', 'pods' ), $old_name ), $this );
1753
  }
1754
- }
1755
-
1756
- if ( $old_id != $params->id ) {
1757
- if ( $params->type == $pod['type'] && isset( $params->object ) && $params->object == $pod['object'] ) {
1758
- return pods_error( sprintf( __( 'Pod using %s already exists, you can not reuse an object across multiple pods', 'pods' ), $params->object ), $this );
1759
- } else {
1760
- return pods_error( sprintf( __( 'Pod %s already exists', 'pods' ), $params->name ), $this );
1761
  }
1762
- }
1763
- } else {
1764
- // New pod (create).
1765
-
1766
- if (
1767
- in_array( $params->name, pods_reserved_keywords(), true )
1768
- && in_array( pods_v( 'type', $params ), array( 'post_type', 'taxonomy' ), true )
1769
- ) {
1770
- $valid_name = false;
1771
-
1772
- // Only if it's extending an existing content type then these
1773
- // names are still allowed, even if they are reserved.
1774
- if ( $extend ) {
1775
- if ( 'post_type' === pods_v( 'type', $params ) ) {
1776
- $valid_name = in_array( $params->name, get_post_types(), true );
1777
- } elseif ( 'taxonomy' === pods_v( 'type', $params ) ) {
1778
- $valid_name = in_array( $params->name, get_taxonomies(), true );
1779
- }
1780
  }
1781
 
1782
- if ( ! $valid_name ) {
1783
- return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name', 'pods' ), $params->name ), $this );
1784
- }
1785
  }
1786
 
1787
- $pod = array(
1788
- 'id' => 0,
1789
- 'name' => $params->name,
1790
- 'label' => $params->name,
1791
- 'description' => '',
1792
- 'type' => 'pod',
1793
- 'storage' => 'table',
1794
- 'object' => '',
1795
- 'alias' => '',
1796
- 'options' => array(),
1797
- 'fields' => array(),
1798
- );
1799
- }
1800
-
1801
- // Blank out fields and options for AJAX calls (everything should be sent to it for a full overwrite)
1802
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
1803
- $pod['fields'] = array();
1804
- $pod['options'] = array();
1805
- }
1806
 
1807
- // Setup options
1808
- $options = get_object_vars( $params );
 
 
 
 
 
1809
 
1810
- if ( isset( $options['method'] ) ) {
1811
- unset( $options['method'] );
1812
- }
 
 
1813
 
1814
- $options_ignore = array(
1815
- 'object_type',
1816
- 'object_name',
1817
- 'table',
1818
- 'meta_table',
1819
- 'pod_table',
1820
- 'field_id',
1821
- 'field_index',
1822
- 'field_slug',
1823
- 'field_type',
1824
- 'field_parent',
1825
- 'field_parent_select',
1826
- 'meta_field_id',
1827
- 'meta_field_index',
1828
- 'meta_field_value',
1829
- 'pod_field_id',
1830
- 'pod_field_index',
1831
- 'object_fields',
1832
- 'join',
1833
- 'where',
1834
- 'where_default',
1835
- 'orderby',
1836
- 'pod',
1837
- 'recurse',
1838
- 'table_info',
1839
- 'attributes',
1840
- 'group',
1841
- 'grouped',
1842
- 'developer_mode',
1843
- 'dependency',
1844
- 'depends-on',
1845
- 'excludes-on'
1846
- );
1847
 
1848
- foreach ( $options_ignore as $ignore ) {
1849
- if ( isset( $options[ $ignore ] ) ) {
1850
- unset( $options[ $ignore ] );
1851
- }
1852
- }
1853
 
1854
- $exclude = array(
1855
- 'id',
1856
- 'name',
1857
- 'label',
1858
- 'description',
1859
- 'type',
1860
- 'storage',
1861
- 'object',
1862
- 'alias',
1863
- 'options',
1864
- 'fields'
1865
- );
1866
 
1867
- foreach ( $exclude as $k => $exclude_field ) {
1868
- $aliases = array( $exclude_field );
 
 
 
1869
 
1870
- if ( is_array( $exclude_field ) ) {
1871
- $aliases = array_merge( array( $k ), $exclude_field );
1872
- $exclude_field = $k;
1873
- }
1874
 
1875
- foreach ( $aliases as $alias ) {
1876
- if ( isset( $options[ $alias ] ) ) {
1877
- $pod[ $exclude_field ] = pods_trim( $options[ $alias ] );
 
1878
 
1879
- unset( $options[ $alias ] );
1880
- }
1881
- }
1882
- }
1883
 
1884
- if ( pods_tableless() && ! in_array( $pod['type'], array( 'settings', 'table' ) ) ) {
1885
- if ( 'pod' === $pod['type'] ) {
1886
- $pod['type'] = 'post_type';
1887
- }
1888
 
1889
- if ( 'table' === $pod['storage'] ) {
1890
- if ( 'taxonomy' === $pod['type'] && ! function_exists( 'get_term_meta' ) ) {
1891
- $pod['storage'] = 'none';
1892
- } else {
1893
- $pod['storage'] = 'meta';
1894
- }
1895
  }
1896
  }
1897
 
1898
- $pod['options']['type'] = $pod['type'];
1899
- $pod['options']['storage'] = $pod['storage'];
1900
- $pod['options']['object'] = $pod['object'];
1901
- $pod['options']['alias'] = $pod['alias'];
1902
-
1903
- $pod['options'] = array_merge( $pod['options'], $options );
1904
 
1905
- /**
1906
- * @var WP_Query
1907
- */
1908
- global $wp_query;
1909
 
1910
- $reserved_query_vars = array(
1911
- 'post_type',
1912
- 'taxonomy',
1913
- 'output'
1914
- );
 
 
1915
 
1916
- if ( is_object( $wp_query ) ) {
1917
- $reserved_query_vars = array_merge( $reserved_query_vars, array_keys( $wp_query->fill_query_vars( array() ) ) );
1918
- }
1919
 
1920
- if ( isset( $pod['options']['query_var_string'] ) ) {
1921
- if ( in_array( $pod['options']['query_var_string'], $reserved_query_vars ) ) {
1922
- $pod['options']['query_var_string'] = $pod['options']['type'] . '_' . $pod['options']['query_var_string'];
1923
- }
1924
- }
1925
 
1926
- if ( isset( $pod['options']['query_var'] ) ) {
1927
- if ( in_array( $pod['options']['query_var'], $reserved_query_vars ) ) {
1928
- $pod['options']['query_var'] = $pod['options']['type'] . '_' . $pod['options']['query_var'];
1929
- }
1930
- }
 
 
 
 
 
 
1931
 
1932
- if ( strlen( $pod['label'] ) < 1 ) {
1933
- $pod['label'] = $pod['name'];
1934
- }
1935
 
1936
- if ( 'post_type' === $pod['type'] ) {
1937
- // Max length for post types are 20 characters
1938
- $pod['name'] = substr( $pod['name'], 0, 20 );
1939
- } elseif ( 'taxonomy' === $pod['type'] ) {
1940
- // Max length for taxonomies are 32 characters
1941
- $pod['name'] = substr( $pod['name'], 0, 32 );
1942
- }
1943
 
1944
- $params->id = $pod['id'];
1945
- $params->name = $pod['name'];
 
 
 
1946
 
1947
- if ( null !== $old_name && $old_name !== $params->name && empty( $pod['object'] ) ) {
1948
- if ( 'post_type' === $pod['type'] ) {
1949
- $check = get_post_type_object( $params->name );
1950
 
1951
- if ( ! empty( $check ) ) {
1952
- return pods_error( sprintf( __( 'Post Type %1$s already exists, you cannot rename %2$s to that', 'pods' ), $params->name, $old_name ), $this );
1953
- }
1954
- } elseif ( 'taxonomy' === $pod['type'] ) {
1955
- $check = get_taxonomy( $params->name );
 
 
1956
 
1957
- if ( ! empty( $check ) ) {
1958
- return pods_error( sprintf( __( 'Taxonomy %1$s already exists, you cannot rename %2$s to that', 'pods' ), $params->name, $old_name ), $this );
1959
- }
1960
- }
1961
- }
 
1962
 
1963
- $field_table_operation = true;
1964
 
1965
- // Add new pod
1966
- if ( empty( $params->id ) ) {
1967
- if ( strlen( $params->name ) < 1 ) {
1968
- return pods_error( __( 'Pod name cannot be empty', 'pods' ), $this );
1969
- }
1970
 
1971
- $post_data = array(
1972
- 'post_name' => $pod['name'],
1973
- 'post_title' => $pod['label'],
1974
- 'post_content' => $pod['description'],
1975
- 'post_type' => '_pods_pod',
1976
- 'post_status' => 'publish'
1977
- );
1978
 
1979
- if ( 'pod' === $pod['type'] && ( ! is_array( $pod['fields'] ) || empty( $pod['fields'] ) ) ) {
1980
- $pod['fields'] = array();
1981
 
1982
- $pod['fields']['name'] = array(
1983
- 'name' => 'name',
1984
- 'label' => 'Name',
1985
- 'type' => 'text',
1986
- 'options' => array(
1987
- 'required' => '1'
1988
- )
1989
- );
1990
-
1991
- $pod['fields']['created'] = array(
1992
- 'name' => 'created',
1993
- 'label' => 'Date Created',
1994
- 'type' => 'datetime',
1995
- 'options' => array(
1996
- 'datetime_format' => 'ymd_slash',
1997
- 'datetime_time_type' => '12',
1998
- 'datetime_time_format' => 'h_mm_ss_A'
1999
- )
2000
- );
2001
-
2002
- $pod['fields']['modified'] = array(
2003
- 'name' => 'modified',
2004
- 'label' => 'Date Modified',
2005
- 'type' => 'datetime',
2006
- 'options' => array(
2007
- 'datetime_format' => 'ymd_slash',
2008
- 'datetime_time_type' => '12',
2009
- 'datetime_time_format' => 'h_mm_ss_A'
2010
- )
2011
- );
2012
-
2013
- $pod['fields']['author'] = array(
2014
- 'name' => 'author',
2015
- 'label' => 'Author',
2016
- 'type' => 'pick',
2017
- 'pick_object' => 'user',
2018
- 'options' => array(
2019
- 'pick_format_type' => 'single',
2020
- 'pick_format_single' => 'autocomplete',
2021
- 'default_value' => '{@user.ID}'
2022
- )
2023
- );
2024
 
2025
- $pod['fields']['permalink'] = array(
2026
- 'name' => 'permalink',
2027
- 'label' => 'Permalink',
2028
- 'type' => 'slug',
2029
- 'description' => 'Leave blank to auto-generate from Name'
2030
- );
 
 
2031
 
2032
- if ( ! isset( $pod['options']['pod_index'] ) ) {
2033
- $pod['options']['pod_index'] = 'name';
2034
- }
2035
- }
2036
 
2037
- $pod = $this->do_hook( 'save_pod_default_pod', $pod, $params, $sanitized, $db );
2038
 
2039
- $field_table_operation = false;
2040
- } else {
2041
- $post_data = array(
2042
- 'ID' => $pod['id'],
2043
- 'post_name' => $pod['name'],
2044
- 'post_title' => $pod['label'],
2045
- 'post_content' => $pod['description'],
2046
- 'post_status' => 'publish'
2047
- );
2048
- }
2049
 
2050
- if ( true === $db ) {
2051
- if ( ! has_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ) ) ) {
2052
- add_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ), 100, 6 );
2053
- }
 
 
 
 
2054
 
2055
- $conflicted = false;
 
 
2056
 
2057
- // Headway compatibility fix
2058
- if ( has_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 ) ) {
2059
- remove_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
 
 
 
 
 
 
 
 
 
2060
 
2061
- $conflicted = true;
2062
- }
2063
 
2064
- $params->id = $this->save_wp_object( 'post', $post_data, $pod['options'], true, true );
 
 
 
 
 
 
 
 
 
2065
 
2066
- if ( $conflicted ) {
2067
- add_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
2068
- }
 
 
2069
 
2070
- if ( false === $params->id ) {
2071
- return pods_error( __( 'Cannot save Pod', 'pods' ), $this );
2072
- }
2073
- } elseif ( empty( $params->id ) ) {
2074
- $params->id = (int) $db;
2075
- }
2076
 
2077
- $pod['id'] = $params->id;
 
 
 
2078
 
2079
- // Setup / update tables
2080
- if ( 'table' !== $pod['type'] && 'table' === $pod['storage'] && $old_storage !== $pod['storage'] && $db ) {
2081
- $definitions = array( "`id` BIGINT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY" );
2082
 
2083
- $defined_fields = array();
 
 
 
 
2084
 
2085
- foreach ( $pod['fields'] as $field ) {
2086
- if ( ! is_array( $field ) || ! isset( $field['name'] ) || in_array( $field['name'], $defined_fields ) ) {
2087
- continue;
2088
- }
 
2089
 
2090
- $defined_fields[] = $field['name'];
 
2091
 
2092
- if ( ! in_array( $field['type'], $tableless_field_types ) || ( 'pick' === $field['type'] && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) ) {
2093
- $definition = $this->get_field_definition( $field['type'], array_merge( $field, pods_var_raw( 'options', $field, array() ) ) );
 
2094
 
2095
- if ( 0 < strlen( $definition ) ) {
2096
- $definitions[] = "`{$field['name']}` " . $definition;
2097
- }
2098
- }
2099
- }
2100
 
2101
- pods_query( "DROP TABLE IF EXISTS `@wp_pods_{$params->name}`" );
2102
 
2103
- /**
2104
- * @todo Central function to fetch charset.
2105
- * @see PodsUpgrade::install() L64-L76
2106
- */
2107
- $charset_collate = 'DEFAULT CHARSET utf8';
2108
 
2109
- global $wpdb;
2110
- if ( ! empty( $wpdb->charset ) ) {
2111
- $charset_collate = "DEFAULT CHARSET {$wpdb->charset}";
2112
- }
2113
 
2114
- if ( ! empty( $wpdb->collate ) ) {
2115
- $charset_collate .= " COLLATE {$wpdb->collate}";
2116
- }
 
 
 
 
 
 
 
 
2117
 
2118
- $result = pods_query( "CREATE TABLE `@wp_pods_{$params->name}` (" . implode( ', ', $definitions ) . ") {$charset_collate}", $this );
 
2119
 
2120
- if ( empty( $result ) ) {
2121
- return pods_error( __( 'Cannot add Database Table for Pod', 'pods' ), $this );
2122
- }
2123
 
2124
- } elseif ( 'table' !== $pod['type'] && 'table' === $pod['storage'] && $pod['storage'] == $old_storage && null !== $old_name && $old_name !== $params->name && $db ) {
2125
- $result = pods_query( "ALTER TABLE `@wp_pods_{$old_name}` RENAME `@wp_pods_{$params->name}`", $this );
2126
 
2127
- if ( empty( $result ) ) {
2128
- return pods_error( __( 'Cannot update Database Table for Pod', 'pods' ), $this );
2129
- }
2130
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2131
 
2132
- /**
2133
- * @var $wpdb wpdb
2134
- */
2135
- global $wpdb;
 
 
 
 
2136
 
2137
- if ( null !== $old_name && $old_name !== $params->name && $db ) {
2138
- // Rename items in the DB pointed at the old WP Object names
2139
- if ( 'post_type' === $pod['type'] && empty( $pod['object'] ) ) {
2140
- $this->rename_wp_object_type( 'post', $old_name, $params->name );
2141
- } elseif ( 'taxonomy' === $pod['type'] && empty( $pod['object'] ) ) {
2142
- $this->rename_wp_object_type( 'taxonomy', $old_name, $params->name );
2143
- } elseif ( 'comment' === $pod['type'] && empty( $pod['object'] ) ) {
2144
- $this->rename_wp_object_type( 'comment', $old_name, $params->name );
2145
- } elseif ( 'settings' === $pod['type'] ) {
2146
- $this->rename_wp_object_type( 'settings', $old_name, $params->name );
2147
- }
2148
 
2149
- // Sync any related fields if the name has changed
2150
- $fields = pods_query( "
2151
- SELECT `p`.`ID`
2152
- FROM `{$wpdb->posts}` AS `p`
2153
- LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
2154
- LEFT JOIN `{$wpdb->postmeta}` AS `pm2` ON `pm2`.`post_id` = `p`.`ID`
2155
- WHERE
2156
- `p`.`post_type` = '_pods_field'
2157
- AND `pm`.`meta_key` = 'pick_object'
2158
- AND (
2159
- `pm`.`meta_value` = 'pod'
2160
- OR `pm`.`meta_value` = '" . $pod['type'] . "'
2161
- )
2162
- AND `pm2`.`meta_key` = 'pick_val'
2163
- AND `pm2`.`meta_value` = '{$old_name}'
2164
- " );
2165
-
2166
- if ( ! empty( $fields ) ) {
2167
- foreach ( $fields as $field ) {
2168
- update_post_meta( $field->ID, 'pick_object', $pod['type'] );
2169
- update_post_meta( $field->ID, 'pick_val', $params->name );
2170
- }
2171
- }
2172
 
2173
- $fields = pods_query( "
2174
- SELECT `p`.`ID`
2175
- FROM `{$wpdb->posts}` AS `p`
2176
- LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
2177
- WHERE
2178
- `p`.`post_type` = '_pods_field'
2179
- AND `pm`.`meta_key` = 'pick_object'
2180
- AND (
2181
- `pm`.`meta_value` = 'pod-{$old_name}'
2182
- OR `pm`.`meta_value` = '" . $pod['type'] . "-{$old_name}'
2183
- )
2184
- " );
2185
 
2186
- if ( ! empty( $fields ) ) {
2187
- foreach ( $fields as $field ) {
2188
- update_post_meta( $field->ID, 'pick_object', $pod['type'] );
2189
- update_post_meta( $field->ID, 'pick_val', $params->name );
2190
  }
2191
  }
2192
  }
2193
 
2194
- // Sync built-in options for post types and taxonomies
2195
- if ( in_array( $pod['type'], array( 'post_type', 'taxonomy' ) ) && empty( $pod['object'] ) && $db ) {
2196
- // Build list of 'built_in' for later
2197
- $built_in = array();
2198
-
2199
- foreach ( $pod['options'] as $key => $val ) {
2200
- if ( false === strpos( $key, 'built_in_' ) ) {
2201
- continue;
2202
- } elseif ( false !== strpos( $key, 'built_in_post_types_' ) ) {
2203
- $built_in_type = 'post_type';
2204
- } elseif ( false !== strpos( $key, 'built_in_taxonomies_' ) ) {
2205
- $built_in_type = 'taxonomy';
2206
- } else {
2207
- continue;
2208
- }
2209
-
2210
- if ( $built_in_type == $pod['type'] ) {
2211
- continue;
2212
- }
2213
-
2214
- if ( ! isset( $built_in[ $built_in_type ] ) ) {
2215
- $built_in[ $built_in_type ] = array();
2216
- }
2217
-
2218
- $built_in_object = str_replace( array( 'built_in_post_types_', 'built_in_taxonomies_' ), '', $key );
2219
-
2220
- $built_in[ $built_in_type ][ $built_in_object ] = (int) $val;
2221
- }
2222
 
2223
- $lookup_option = false;
2224
- $lookup_built_in = false;
2225
 
2226
- $lookup_name = $pod['name'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2227
 
2228
- if ( 'post_type' === $pod['type'] ) {
2229
- $lookup_option = 'built_in_post_types_' . $lookup_name;
2230
- $lookup_built_in = 'taxonomy';
2231
- } elseif ( 'taxonomy' === $pod['type'] ) {
2232
- $lookup_option = 'built_in_taxonomies_' . $lookup_name;
2233
- $lookup_built_in = 'post_type';
2234
  }
2235
-
2236
- if ( ! empty( $lookup_option ) && ! empty( $lookup_built_in ) && isset( $built_in[ $lookup_built_in ] ) ) {
2237
- foreach ( $built_in[ $lookup_built_in ] as $built_in_object => $val ) {
2238
- $search_val = 1;
2239
-
2240
- if ( 1 == $val ) {
2241
- $search_val = 0;
2242
- }
2243
-
2244
- $query = "SELECT p.ID FROM {$wpdb->posts} AS p
2245
- LEFT JOIN {$wpdb->postmeta} AS pm ON pm.post_id = p.ID AND pm.meta_key = '{$lookup_option}'
2246
- LEFT JOIN {$wpdb->postmeta} AS pm2 ON pm2.post_id = p.ID AND pm2.meta_key = 'type' AND pm2.meta_value = '{$lookup_built_in}'
2247
- LEFT JOIN {$wpdb->postmeta} AS pm3 ON pm3.post_id = p.ID AND pm3.meta_key = 'object' AND pm3.meta_value = ''
2248
- WHERE p.post_type = '_pods_pod' AND p.post_name = '{$built_in_object}'
2249
- AND pm2.meta_id IS NOT NULL
2250
- AND ( pm.meta_id IS NULL OR pm.meta_value = {$search_val} )";
2251
-
2252
- $results = pods_query( $query );
2253
-
2254
- if ( ! empty( $results ) ) {
2255
- foreach ( $results as $the_pod ) {
2256
- delete_post_meta( $the_pod->ID, $lookup_option );
2257
-
2258
- add_post_meta( $the_pod->ID, $lookup_option, $val );
2259
- }
2260
- }
2261
- }
2262
  }
2263
  }
2264
 
2265
- $saved = array();
2266
- $errors = array();
2267
 
2268
- $field_index_change = false;
2269
- $field_index_id = 0;
2270
 
2271
- $id_required = false;
2272
 
2273
- $field_index = pods_var( 'pod_index', $pod['options'], 'id', null, true );
 
 
 
2274
 
2275
- if ( 'pod' === $pod['type'] && ! empty( $pod['fields'] ) && isset( $pod['fields'][ $field_index ] ) ) {
2276
- $field_index_id = $pod['fields'][ $field_index ];
2277
  }
2278
 
2279
- if ( isset( $params->fields ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
2280
- $fields = array();
2281
-
2282
- if ( isset( $params->fields ) ) {
2283
- $params->fields = (array) $params->fields;
2284
-
2285
- $weight = 0;
2286
-
2287
- foreach ( $params->fields as $field ) {
2288
- if ( ! is_array( $field ) || ! isset( $field['name'] ) ) {
2289
- continue;
2290
- }
2291
-
2292
- if ( ! isset( $field['weight'] ) ) {
2293
- $field['weight'] = $weight;
2294
-
2295
- $weight ++;
2296
- }
2297
-
2298
- $fields[ $field['name'] ] = $field;
2299
- }
2300
- }
2301
 
2302
- $weight = 0;
2303
-
2304
- $saved_field_ids = array();
2305
 
2306
- foreach ( $pod['fields'] as $k => $field ) {
2307
- if ( ! empty( $old_id ) && ( ! is_array( $field ) || ! isset( $field['name'] ) || ! isset( $fields[ $field['name'] ] ) ) ) {
2308
- // Iterative change handling for setup-edit.php
2309
- if ( ! is_array( $field ) && isset( $old_fields[ $k ] ) ) {
2310
- $saved[ $old_fields[ $k ]['name'] ] = true;
2311
- }
2312
 
2313
- continue;
2314
- }
2315
 
2316
- if ( ! empty( $old_id ) ) {
2317
- $field = array_merge( $field, $fields[ $field['name'] ] );
2318
- }
2319
 
2320
- $field['pod'] = $pod;
 
 
2321
 
2322
- if ( ! isset( $field['weight'] ) ) {
2323
- $field['weight'] = $weight;
2324
 
2325
- $weight ++;
2326
- }
2327
 
2328
- if ( 0 < $field_index_id && pods_var( 'id', $field ) == $field_index_id ) {
2329
- $field_index_change = $field['name'];
2330
- }
2331
 
2332
- if ( 0 < pods_var( 'id', $field ) ) {
2333
- $id_required = true;
2334
- }
 
 
 
 
 
 
 
 
 
 
 
 
2335
 
2336
- if ( $id_required ) {
2337
- $field['id_required'] = true;
2338
- }
2339
 
2340
- $field_data = $field;
 
 
 
2341
 
2342
- $field = $this->save_field( $field_data, $field_table_operation, true, $db );
2343
 
2344
- if ( true !== $db ) {
2345
- $pod['fields'][ $k ] = $field;
2346
- $saved_field_ids[] = $field['id'];
2347
- } else {
2348
- if ( ! empty( $field ) && 0 < $field ) {
2349
- $saved[ $field_data['name'] ] = true;
2350
- $saved_field_ids[] = $field;
2351
- } else {
2352
- $errors[] = sprintf( __( 'Cannot save the %s field', 'pods' ), $field_data['name'] );
2353
- }
2354
- }
2355
- }
2356
 
2357
- if ( true === $db ) {
2358
- foreach ( $old_fields as $field ) {
2359
- if ( isset( $pod['fields'][ $field['name'] ] ) || isset( $saved[ $field['name'] ] ) || in_array( $field['id'], $saved_field_ids ) ) {
2360
- continue;
2361
- }
2362
 
2363
- if ( $field['id'] == $field_index_id ) {
2364
- $field_index_change = 'id';
2365
- } elseif ( $field['name'] == $field_index ) {
2366
- $field_index_change = 'id';
2367
- }
2368
 
2369
- $this->delete_field( array(
2370
- 'id' => (int) $field['id'],
2371
- 'name' => $field['name'],
2372
- 'pod' => $pod
2373
- ), $field_table_operation );
2374
- }
2375
- }
2376
 
2377
- // Update field index if the name has changed or the field has been removed
2378
- if ( false !== $field_index_change && true === $db ) {
2379
- update_post_meta( $pod['id'], 'pod_index', $field_index_change );
2380
- }
2381
  }
2382
 
2383
- $this->cache_flush_pods( $pod );
 
 
 
2384
 
2385
- if ( ! empty( $errors ) ) {
2386
- return pods_error( $errors, $this );
2387
- }
 
2388
 
2389
- $refresh_pod = $this->load_pod( array( 'name' => $pod['name'] ), false );
2390
-
2391
- if ( $refresh_pod ) {
2392
- $pod = $refresh_pod;
2393
- }
2394
-
2395
- if ( 'post_type' === $pod['type'] ) {
2396
- PodsMeta::$post_types[ $pod['id'] ] = $pod;
2397
- } elseif ( 'taxonomy' === $pod['type'] ) {
2398
- PodsMeta::$taxonomies[ $pod['id'] ] = $pod;
2399
- } elseif ( 'media' === $pod['type'] ) {
2400
- PodsMeta::$media[ $pod['id'] ] = $pod;
2401
- } elseif ( 'user' === $pod['type'] ) {
2402
- PodsMeta::$user[ $pod['id'] ] = $pod;
2403
- } elseif ( 'comment' === $pod['type'] ) {
2404
- PodsMeta::$comment[ $pod['id'] ] = $pod;
2405
- }
2406
-
2407
- if ( ! class_exists( 'PodsInit' ) ) {
2408
- pods_init();
2409
- }
2410
-
2411
- // Register Post Types / Taxonomies post-registration from PodsInit
2412
- if (
2413
- ! empty( PodsInit::$content_types_registered )
2414
- && in_array( $pod['type'], array(
2415
- 'post_type',
2416
- 'taxonomy'
2417
- ) )
2418
- && empty( $pod['object'] )
2419
- ) {
2420
- pods_init()->setup_content_types( true );
2421
- }
2422
-
2423
- if ( true === $db ) {
2424
- return $pod['id'];
2425
- } else {
2426
- return $pod;
2427
- }
2428
- }
2429
-
2430
- /**
2431
- * Add or edit a field within a Pod
2432
- *
2433
- * $params['id'] int Field ID (id OR pod_id+pod+name required)
2434
- * $params['pod_id'] int Pod ID (id OR pod_id+pod+name required)
2435
- * $params['pod'] string Pod name (id OR pod_id+pod+name required)
2436
- * $params['name'] string Field name (id OR pod_id+pod+name required)
2437
- * $params['label'] string (optional) Field label
2438
- * $params['type'] string (optional) Field type (avatar, boolean, code, color, currency, date, datetime, email,
2439
- * file, number, paragraph, password, phone, pick, slug, text, time, website, wysiwyg)
2440
- * $params['pick_object'] string (optional) Related Object (for relationships)
2441
- * $params['pick_val'] string (optional) Related Object name (for relationships)
2442
- * $params['sister_id'] int (optional) Related Field ID (for bidirectional relationships)
2443
- * $params['weight'] int (optional) Order in which the field appears
2444
- * $params['options'] array (optional) Options
2445
- *
2446
- * @param array $params An associative array of parameters
2447
- * @param bool $table_operation (optional) Whether or not to handle table operations
2448
- * @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed,
2449
- * will sanitize them if false.
2450
- * @param bool|int $db (optional) Whether to save into the DB or just return field array.
2451
- *
2452
- * @return int|array The field ID or field array (if !$db)
2453
- * @since 1.7.9
2454
- */
2455
- public function save_field( $params, $table_operation = true, $sanitized = false, $db = true ) {
2456
-
2457
- /**
2458
- * @var $wpdb wpdb
2459
- */
2460
- global $wpdb;
2461
-
2462
- if ( true !== $db ) {
2463
- $table_operation = false;
2464
- }
2465
-
2466
- $tableless_field_types = PodsForm::tableless_field_types();
2467
- $simple_tableless_objects = PodsForm::simple_tableless_objects();
2468
-
2469
- $params = (object) $params;
2470
-
2471
- if ( false === $sanitized ) {
2472
- $params = pods_sanitize( $params );
2473
- }
2474
-
2475
- if ( isset( $params->pod_id ) ) {
2476
- $params->pod_id = pods_absint( $params->pod_id );
2477
- }
2478
-
2479
- if ( true !== $db ) {
2480
- $params->pod_id = (int) $db;
2481
- }
2482
-
2483
- $pod = null;
2484
- $save_pod = false;
2485
- $id_required = false;
2486
-
2487
- if ( isset( $params->id_required ) ) {
2488
- unset( $params->id_required );
2489
-
2490
- $id_required = true;
2491
- }
2492
-
2493
- if ( ( ! isset( $params->pod ) || empty( $params->pod ) ) && ( ! isset( $params->pod_id ) || empty( $params->pod_id ) ) ) {
2494
- return pods_error( __( 'Pod ID or name is required', 'pods' ), $this );
2495
- }
2496
-
2497
- if ( isset( $params->pod ) && is_array( $params->pod ) ) {
2498
- $pod = $params->pod;
2499
-
2500
- $save_pod = true;
2501
- } elseif ( ( ! isset( $params->pod_id ) || empty( $params->pod_id ) ) && ( true === $db || 0 < $db ) ) {
2502
- $pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => true ) );
2503
- } elseif ( ! isset( $params->pod ) && ( true === $db || 0 < $db ) ) {
2504
- $pod = $this->load_pod( array( 'id' => $params->pod_id, 'table_info' => true ) );
2505
- } elseif ( true === $db || 0 < $db ) {
2506
- $pod = $this->load_pod( array( 'id' => $params->pod_id, 'name' => $params->pod, 'table_info' => true ) );
2507
- }
2508
-
2509
- if ( empty( $pod ) && true === $db ) {
2510
- return pods_error( __( 'Pod not found', 'pods' ), $this );
2511
- }
2512
-
2513
- $params->pod_id = $pod['id'];
2514
- $params->pod = $pod['name'];
2515
- $params->pod_data = $pod;
2516
-
2517
- $params->name = pods_clean_name( $params->name, true, ( 'meta' === $pod['storage'] ? false : true ) );
2518
-
2519
- if ( ! isset( $params->id ) ) {
2520
- $params->id = 0;
2521
- }
2522
-
2523
- if ( empty( $params->name ) ) {
2524
- return pods_error( __( 'Pod field name is required', 'pods' ), $this );
2525
- }
2526
-
2527
- $field = $this->load_field( $params );
2528
-
2529
- unset( $params->pod_data );
2530
-
2531
- $old_id = null;
2532
- $old_name = null;
2533
- $old_type = null;
2534
- $old_definition = null;
2535
- $old_simple = null;
2536
- $old_options = null;
2537
- $old_sister_id = null;
2538
-
2539
- // @todo pods_reserved_keywords();
2540
- $reserved_keywords = array( 'id', 'ID' );
2541
-
2542
- if ( ! empty( $field ) ) {
2543
- $old_id = pods_var( 'id', $field );
2544
- $old_name = pods_clean_name( $field['name'], true, ( 'meta' === $pod['storage'] ? false : true ) );
2545
- $old_type = $field['type'];
2546
- $old_options = $field['options'];
2547
- $old_sister_id = (int) pods_var( 'sister_id', $old_options, 0 );
2548
-
2549
- $old_simple = ( 'pick' === $old_type && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) );
2550
-
2551
- if ( isset( $params->name ) && ! empty( $params->name ) ) {
2552
- $field['name'] = $params->name;
2553
- }
2554
-
2555
- if ( $old_name !== $field['name'] ) {
2556
- if ( in_array( $field['name'], $reserved_keywords, true ) ) {
2557
- return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
2558
- }
2559
-
2560
- if ( false !== $this->field_exists( $params ) ) {
2561
- return pods_error( sprintf( __( 'Field %1$s already exists, you cannot rename %2$s to that', 'pods' ), $field['name'], $old_name ), $this );
2562
- }
2563
- }
2564
-
2565
- if ( ( $id_required || ! empty( $params->id ) ) && ( empty( $old_id ) || $old_id != $params->id ) ) {
2566
- return pods_error( sprintf( __( 'Field %s already exists', 'pods' ), $field['name'] ), $this );
2567
- }
2568
-
2569
- if ( empty( $params->id ) ) {
2570
- $params->id = $old_id;
2571
- }
2572
-
2573
- if ( ! in_array( $old_type, $tableless_field_types ) || $old_simple ) {
2574
- $definition = $this->get_field_definition( $old_type, array_merge( $field, $old_options ) );
2575
-
2576
- if ( 0 < strlen( $definition ) ) {
2577
- $old_definition = "`{$old_name}` " . $definition;
2578
- }
2579
- }
2580
- } else {
2581
- $field = array(
2582
- 'id' => 0,
2583
- 'pod_id' => $params->pod_id,
2584
- 'name' => $params->name,
2585
- 'label' => $params->name,
2586
- 'description' => '',
2587
- 'type' => 'text',
2588
- 'pick_object' => '',
2589
- 'pick_val' => '',
2590
- 'sister_id' => '',
2591
- 'weight' => null,
2592
- 'options' => array()
2593
- );
2594
- }
2595
-
2596
- // Setup options
2597
- $options = get_object_vars( $params );
2598
-
2599
- $options_ignore = array(
2600
- 'method',
2601
- 'table_info',
2602
- 'attributes',
2603
- 'group',
2604
- 'grouped',
2605
- 'developer_mode',
2606
- 'dependency',
2607
- 'depends-on',
2608
- 'excludes-on'
2609
- );
2610
-
2611
- foreach ( $options_ignore as $ignore ) {
2612
- if ( isset( $options[ $ignore ] ) ) {
2613
- unset( $options[ $ignore ] );
2614
- }
2615
- }
2616
-
2617
- if ( isset( $options['method'] ) ) {
2618
- unset( $options['method'] );
2619
- } elseif ( isset( $options['table_info'] ) ) {
2620
- unset( $options['table_info'] );
2621
- }
2622
-
2623
- $exclude = array(
2624
- 'id',
2625
- 'pod_id',
2626
- 'pod',
2627
- 'name',
2628
- 'label',
2629
- 'description',
2630
- 'type',
2631
- 'pick_object',
2632
- 'pick_val',
2633
- 'sister_id',
2634
- 'weight',
2635
- 'options'
2636
- );
2637
-
2638
- foreach ( $exclude as $k => $exclude_field ) {
2639
- $aliases = array( $exclude_field );
2640
-
2641
- if ( is_array( $exclude_field ) ) {
2642
- $aliases = array_merge( array( $k ), $exclude_field );
2643
- $exclude_field = $k;
2644
- }
2645
-
2646
- foreach ( $aliases as $alias ) {
2647
- if ( isset( $options[ $alias ] ) ) {
2648
- $field[ $exclude_field ] = pods_trim( $options[ $alias ] );
2649
-
2650
- unset( $options[ $alias ] );
2651
- }
2652
- }
2653
- }
2654
-
2655
- if ( strlen( $field['label'] ) < 1 ) {
2656
- $field['label'] = $field['name'];
2657
- }
2658
-
2659
- $field['options']['type'] = $field['type'];
2660
-
2661
- if ( in_array( $field['options']['type'], $tableless_field_types ) ) {
2662
- // Clean up special drop-down in field editor and save out pick_val
2663
- $field['pick_object'] = pods_var( 'pick_object', $field, '', null, true );
2664
-
2665
- if ( 0 === strpos( $field['pick_object'], 'pod-' ) ) {
2666
- $field['pick_val'] = pods_str_replace( 'pod-', '', $field['pick_object'], 1 );
2667
- $field['pick_object'] = 'pod';
2668
- } elseif ( 0 === strpos( $field['pick_object'], 'post_type-' ) ) {
2669
- $field['pick_val'] = pods_str_replace( 'post_type-', '', $field['pick_object'], 1 );
2670
- $field['pick_object'] = 'post_type';
2671
- } elseif ( 0 === strpos( $field['pick_object'], 'taxonomy-' ) ) {
2672
- $field['pick_val'] = pods_str_replace( 'taxonomy-', '', $field['pick_object'], 1 );
2673
- $field['pick_object'] = 'taxonomy';
2674
- } elseif ( 'table' === $field['pick_object'] && 0 < strlen( pods_var_raw( 'pick_table', $field['options'] ) ) ) {
2675
- $field['pick_val'] = $field['options']['pick_table'];
2676
- $field['pick_object'] = 'table';
2677
- } elseif ( false === strpos( $field['pick_object'], '-' ) && ! in_array( $field['pick_object'], array(
2678
- 'pod',
2679
- 'post_type',
2680
- 'taxonomy'
2681
- ) ) ) {
2682
- $field['pick_val'] = '';
2683
- } elseif ( 'custom-simple' === $field['pick_object'] ) {
2684
- $field['pick_val'] = '';
2685
- }
2686
-
2687
- $field['options']['pick_object'] = $field['pick_object'];
2688
- $field['options']['pick_val'] = $field['pick_val'];
2689
- $field['options']['sister_id'] = pods_var( 'sister_id', $field );
2690
-
2691
- unset( $field['pick_object'] );
2692
- unset( $field['pick_val'] );
2693
-
2694
- if ( isset( $field['sister_id'] ) ) {
2695
- unset( $field['sister_id'] );
2696
- }
2697
- }
2698
-
2699
- $field['options'] = array_merge( $field['options'], $options );
2700
-
2701
- $object_fields = (array) pods_var_raw( 'object_fields', $pod, array(), null, true );
2702
-
2703
- if ( 0 < $old_id && defined( 'PODS_FIELD_STRICT' ) && ! PODS_FIELD_STRICT ) {
2704
- $params->id = $old_id;
2705
- $field['id'] = $old_id;
2706
- }
2707
-
2708
- // Add new field
2709
- if ( ! isset( $params->id ) || empty( $params->id ) || empty( $field ) ) {
2710
- if ( $table_operation && in_array( $field['name'], array(
2711
- 'created',
2712
- 'modified'
2713
- ) ) && ! in_array( $field['type'], array(
2714
- 'date',
2715
- 'datetime'
2716
- ) ) && ( ! defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) ) {
2717
- return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
2718
- }
2719
-
2720
- if ( $table_operation && 'author' === $field['name'] && 'pick' !== $field['type'] && ( ! defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) ) {
2721
- return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
2722
- }
2723
-
2724
- if ( in_array( $field['name'], $reserved_keywords, true ) ) {
2725
- return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
2726
- }
2727
-
2728
- foreach ( $object_fields as $object_field => $object_field_opt ) {
2729
- if ( $object_field == $field['name'] || in_array( $field['name'], $object_field_opt['alias'] ) ) {
2730
- return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name. Also consider what WordPress and Pods provide you built-in.', 'pods' ), $field['name'] ), $this );
2731
- }
2732
- }
2733
-
2734
- if ( in_array( $field['name'], array( 'rss' ) ) ) // Reserved post_name values that can't be used as field names
2735
- {
2736
- $field['name'] .= '2';
2737
- }
2738
-
2739
- if ( 'slug' === $field['type'] && true === $db ) {
2740
- if ( in_array( $pod['type'], array( 'post_type', 'taxonomy', 'user' ) ) ) {
2741
- return pods_error( __( 'This pod already has an internal WordPress permalink field', 'pods' ), $this );
2742
- }
2743
-
2744
- $slug_field = get_posts( array(
2745
- 'post_type' => '_pods_field',
2746
- 'orderby' => 'menu_order',
2747
- 'order' => 'ASC',
2748
- 'posts_per_page' => 1,
2749
- 'post_parent' => $field['pod_id'],
2750
- 'meta_query' => array(
2751
- array(
2752
- 'key' => 'type',
2753
- 'value' => 'slug'
2754
- )
2755
- )
2756
- ) );
2757
-
2758
- if ( ! empty( $slug_field ) ) {
2759
- return pods_error( __( 'This pod already has a permalink field', 'pods' ), $this );
2760
- }
2761
- }
2762
-
2763
- // Sink the new field to the bottom of the list
2764
- if ( null === $field['weight'] ) {
2765
- $field['weight'] = 0;
2766
-
2767
- $bottom_most_field = get_posts( array(
2768
- 'post_type' => '_pods_field',
2769
- 'orderby' => 'menu_order',
2770
- 'order' => 'DESC',
2771
- 'posts_per_page' => 1,
2772
- 'post_parent' => $field['pod_id']
2773
- ) );
2774
-
2775
- if ( ! empty( $bottom_most_field ) ) {
2776
- $field['weight'] = pods_absint( $bottom_most_field[0]->menu_order ) + 1;
2777
- }
2778
- }
2779
-
2780
- $field['weight'] = pods_absint( $field['weight'] );
2781
-
2782
- $post_data = array(
2783
- 'post_name' => $field['name'],
2784
- 'post_title' => $field['label'],
2785
- 'post_content' => $field['description'],
2786
- 'post_type' => '_pods_field',
2787
- 'post_parent' => $field['pod_id'],
2788
- 'post_status' => 'publish',
2789
- 'menu_order' => $field['weight']
2790
- );
2791
- } else {
2792
- if ( in_array( $field['name'], array( 'id', 'ID' ) ) ) {
2793
- if ( null !== $old_name ) {
2794
- return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
2795
- } else {
2796
- return pods_error( sprintf( __( '%s is not editable', 'pods' ), $field['name'] ), $this );
2797
- }
2798
- }
2799
-
2800
- if ( null !== $old_name && $field['name'] !== $old_name && in_array( $field['name'], array(
2801
- 'created',
2802
- 'modified'
2803
- ) ) && ! in_array( $field['type'], array(
2804
- 'date',
2805
- 'datetime'
2806
- ) ) && ( ! defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) ) {
2807
- return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
2808
- }
2809
-
2810
- if ( null !== $old_name && $field['name'] !== $old_name && 'author' === $field['name'] && 'pick' !== $field['type'] && ( ! defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) ) {
2811
- return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
2812
- }
2813
-
2814
- foreach ( $object_fields as $object_field => $object_field_opt ) {
2815
- if ( $object_field !== $field['name'] && ! in_array( $field['name'], $object_field_opt['alias'] ) ) {
2816
- continue;
2817
- }
2818
-
2819
- if ( null !== $old_name ) {
2820
- return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
2821
- } else {
2822
- return pods_error( sprintf( __( '%s is not editable', 'pods' ), $field['name'] ), $this );
2823
- }
2824
- }
2825
-
2826
- $post_data = array(
2827
- 'ID' => $field['id'],
2828
- 'post_name' => $field['name'],
2829
- 'post_title' => $field['label'],
2830
- 'post_content' => $field['description']
2831
- );
2832
-
2833
- if ( null !== $field['weight'] ) {
2834
- $field['weight'] = pods_absint( $field['weight'] );
2835
-
2836
- $post_data['menu_order'] = $field['weight'];
2837
- }
2838
- }
2839
-
2840
- if ( true === $db ) {
2841
- if ( ! has_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ) ) ) {
2842
- add_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ), 100, 6 );
2843
- }
2844
-
2845
- $conflicted = false;
2846
-
2847
- // Headway compatibility fix
2848
- if ( has_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 ) ) {
2849
- remove_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
2850
-
2851
- $conflicted = true;
2852
- }
2853
-
2854
- // Store the old field name
2855
- if ( $old_name && $old_name !== $post_data['post_name'] ) {
2856
- $field['options']['old_name'] = $old_name;
2857
- }
2858
-
2859
- $params->id = $this->save_wp_object( 'post', $post_data, $field['options'], true, true );
2860
-
2861
- if ( $conflicted ) {
2862
- add_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
2863
- }
2864
-
2865
- if ( false === $params->id ) {
2866
- return pods_error( __( 'Cannot save Field', 'pods' ), $this );
2867
- }
2868
- } else {
2869
- $params->id = $field['name'];
2870
- }
2871
-
2872
- $field['id'] = $params->id;
2873
-
2874
- $simple = ( 'pick' === $field['type'] && in_array( pods_v( 'pick_object', $field['options'] ), $simple_tableless_objects, true ) );
2875
-
2876
- $definition = false;
2877
-
2878
- if ( ! in_array( $field['type'], $tableless_field_types ) || $simple ) {
2879
- $field_definition = $this->get_field_definition( $field['type'], array_merge( $field, $field['options'] ) );
2880
-
2881
- if ( 0 < strlen( $field_definition ) ) {
2882
- $definition = '`' . $field['name'] . '` ' . $field_definition;
2883
- }
2884
- }
2885
-
2886
- $sister_id = (int) pods_var( 'sister_id', $field['options'], 0 );
2887
-
2888
- $definition_mode = 'bypass';
2889
-
2890
- if ( $table_operation && 'table' === $pod['storage'] && ! pods_tableless() ) {
2891
- if ( ! empty( $old_id ) ) {
2892
- if ( ( $field['type'] !== $old_type || $old_simple !== $simple ) && empty( $definition ) ) {
2893
- $definition_mode = 'drop';
2894
- } elseif ( 0 < strlen( $definition ) ) {
2895
- if ( $old_name !== $field['name'] || $old_simple !== $simple || $old_definition !== $definition ) {
2896
- $definition_mode = 'add';
2897
-
2898
- if ( 0 < strlen( $old_definition ) ) {
2899
- $definition_mode = 'change';
2900
- }
2901
- } elseif ( null !== $old_definition && $definition !== $old_definition ) {
2902
- $definition_mode = 'change';
2903
- }
2904
- }
2905
- } elseif ( 0 < strlen( $definition ) ) {
2906
- $definition_mode = 'add';
2907
-
2908
- if ( 0 < strlen( $old_definition ) ) {
2909
- $definition_mode = 'change';
2910
- }
2911
- }
2912
-
2913
- if ( 'bypass' !== $definition_mode ) {
2914
- /**
2915
- * Allow hooking into before the table has been altered for any custom functionality needed.
2916
- *
2917
- * @since 2.7.17
2918
- *
2919
- * @param string $definition_mode The definition mode used for the table field.
2920
- * @param array $pod The pod object.
2921
- * @param string $type The field type.
2922
- * @param array $field The field object.
2923
- * @param array $extra_info {
2924
- * Extra information about the field.
2925
- *
2926
- * @type bool $simple Whether the field is a simple tableless field.
2927
- * @type string $definition The field definition.
2928
- * @type null|string $old_name The old field name (if preexisting).
2929
- * @type null|string $old_definition The old field definition (if preexisting).
2930
- * @type null|array $old_options The old field options (if preexisting).
2931
- * }
2932
- */
2933
- do_action( 'pods_api_save_field_table_pre_alter', $definition_mode, $pod, $field['type'], $field, array(
2934
- 'simple' => $simple,
2935
- 'definition' => $definition,
2936
- 'old_name' => $old_name,
2937
- 'old_definition' => $old_definition,
2938
- 'old_options' => $old_options,
2939
- ) );
2940
-
2941
- if ( 'drop' === $definition_mode ) {
2942
- // Drop field column.
2943
- pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` DROP COLUMN `{$old_name}`", false );
2944
- } elseif ( 'change' === $definition_mode ) {
2945
- // Change field column definition.
2946
- if ( $old_name && $old_name !== $field['name'] ) {
2947
- $test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` CHANGE `{$old_name}` {$definition}", false );
2948
- } else {
2949
- $test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` MODIFY {$definition}", false );
2950
- }
2951
-
2952
- if ( false === $test ) {
2953
- $definition_mode = 'add';
2954
- }
2955
- }
2956
-
2957
- // If the old field doesn't exist, continue to add a new field
2958
- if ( 'add' === $definition_mode ) {
2959
- pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` ADD COLUMN {$definition}", __( 'Cannot create new field', 'pods' ) );
2960
- }
2961
-
2962
- /**
2963
- * Allow hooking into after the table has been altered for any custom functionality needed.
2964
- *
2965
- * @since 2.7.17
2966
- *
2967
- * @param string $definition_mode The definition mode used for the table field.
2968
- * @param array $pod The pod object.
2969
- * @param string $type The field type.
2970
- * @param array $field The field object.
2971
- * @param array $extra_info {
2972
- * Extra information about the field.
2973
- *
2974
- * @type bool $simple Whether the field is a simple tableless field.
2975
- * @type string $definition The field definition.
2976
- * @type null|string $old_name The old field name (if preexisting).
2977
- * @type null|string $old_definition The old field definition (if preexisting).
2978
- * @type null|array $old_options The old field options (if preexisting).
2979
- * }
2980
- */
2981
- do_action( 'pods_api_save_field_table_altered', $definition_mode, $pod, $field['type'], $field, array(
2982
- 'simple' => $simple,
2983
- 'definition' => $definition,
2984
- 'old_name' => $old_name,
2985
- 'old_definition' => $old_definition,
2986
- 'old_options' => $old_options,
2987
- ) );
2988
- }
2989
- }
2990
-
2991
- if ( ! empty( $old_id ) && 'meta' === $pod['storage'] && $old_name !== $field['name'] && $pod['meta_table'] !== $pod['table'] ) {
2992
- $prepare = array(
2993
- $field['name'],
2994
- $old_name
2995
- );
2996
-
2997
- // Users don't have a type
2998
- if ( ! empty( $pod['field_type'] ) ) {
2999
- $prepare[] = $pod['name'];
3000
- }
3001
-
3002
- $join_table = $pod['table'];
3003
-
3004
- // Taxonomies are the odd type out, terrible I know
3005
- if ( 'taxonomy' === $pod['type'] ) {
3006
- // wp_term_taxonomy has the 'taxonomy' field we need to limit by
3007
- $join_table = $wpdb->term_taxonomy;
3008
- }
3009
-
3010
- pods_query( "
3011
- UPDATE `{$pod[ 'meta_table' ]}` AS `m`
3012
- LEFT JOIN `{$join_table}` AS `t`
3013
- ON `t`.`{$pod[ 'field_id' ]}` = `m`.`{$pod[ 'meta_field_id' ]}`
3014
- SET
3015
- `m`.`{$pod[ 'meta_field_index' ]}` = %s
3016
- WHERE
3017
- `m`.`{$pod[ 'meta_field_index' ]}` = %s
3018
- " . ( ! empty( $pod['field_type'] ) ? " AND `t`.`{$pod[ 'field_type' ]}` = %s" : "" ), $prepare );
3019
- }
3020
-
3021
- if ( $field['type'] !== $old_type && in_array( $old_type, $tableless_field_types ) ) {
3022
- delete_post_meta( $old_sister_id, 'sister_id' );
3023
-
3024
- if ( true === $db ) {
3025
- pods_query( "
3026
- DELETE pm
3027
- FROM {$wpdb->postmeta} AS pm
3028
- LEFT JOIN {$wpdb->posts} AS p
3029
- ON p.post_type = '_pods_field'
3030
- AND p.ID = pm.post_id
3031
- WHERE
3032
- p.ID IS NOT NULL
3033
- AND pm.meta_key = 'sister_id'
3034
- AND pm.meta_value = %d
3035
- ", array(
3036
- $params->id
3037
- ) );
3038
-
3039
- if ( ! pods_tableless() ) {
3040
- pods_query( "DELETE FROM @wp_podsrel WHERE `field_id` = {$params->id}", false );
3041
-
3042
- pods_query( "
3043
- UPDATE `@wp_podsrel`
3044
- SET `related_field_id` = 0
3045
- WHERE `field_id` = %d
3046
- ", array(
3047
- $old_sister_id
3048
- ) );
3049
- }
3050
- }
3051
- } elseif ( 0 < $sister_id ) {
3052
- update_post_meta( $sister_id, 'sister_id', $params->id );
3053
-
3054
- if ( true === $db && ( ! pods_tableless() ) ) {
3055
- pods_query( "
3056
- UPDATE `@wp_podsrel`
3057
- SET `related_field_id` = %d
3058
- WHERE `field_id` = %d
3059
- ", array(
3060
- $params->id,
3061
- $sister_id
3062
- ) );
3063
- }
3064
- } elseif ( 0 < $old_sister_id ) {
3065
- delete_post_meta( $old_sister_id, 'sister_id' );
3066
-
3067
- if ( true === $db && ( ! pods_tableless() ) ) {
3068
- pods_query( "
3069
- UPDATE `@wp_podsrel`
3070
- SET `related_field_id` = 0
3071
- WHERE `field_id` = %d
3072
- ", array(
3073
- $old_sister_id
3074
- ) );
3075
- }
3076
- }
3077
-
3078
- if ( ! empty( $old_id ) && $old_name !== $field['name'] && true === $db ) {
3079
- pods_query( "
3080
- UPDATE `@wp_postmeta`
3081
- SET `meta_value` = %s
3082
- WHERE
3083
- `post_id` = %d
3084
- AND `meta_key` = 'pod_index'
3085
- AND `meta_value` = %s
3086
- ", array(
3087
- $field['name'],
3088
- $pod['id'],
3089
- $old_name
3090
- ) );
3091
- }
3092
-
3093
- if ( ! $save_pod ) {
3094
- $this->cache_flush_pods( $pod );
3095
- } else {
3096
- pods_transient_clear( 'pods_field_' . $pod['name'] . '_' . $field['name'] );
3097
-
3098
- if ( ! empty( $old_id ) && $old_name !== $field['name'] ) {
3099
- pods_transient_clear( 'pods_field_' . $pod['name'] . '_' . $old_name );
3100
- }
3101
- }
3102
-
3103
- if ( true === $db ) {
3104
- return $params->id;
3105
- } else {
3106
- return $field;
3107
- }
3108
- }
3109
-
3110
- /**
3111
- * Fix Pod / Field post_name to ensure they are exactly as saved (allow multiple posts w/ same post_name)
3112
- *
3113
- * @param string $slug Unique slug value
3114
- * @param int $post_ID Post ID
3115
- * @param string $post_status Post Status
3116
- * @param string $post_type Post Type
3117
- * @param int $post_parent Post Parent ID
3118
- * @param string $original_slug Original slug value
3119
- *
3120
- * @return string Final slug value
3121
- *
3122
- * @since 2.3.3
3123
- */
3124
- public function save_slug_fix( $slug, $post_ID, $post_status, $post_type, $post_parent = 0, $original_slug = null ) {
3125
-
3126
- if ( in_array( $post_type, array( '_pods_field', '_pods_pod' ) ) && false !== strpos( $slug, '-' ) ) {
3127
- $slug = $original_slug;
3128
- }
3129
-
3130
- return $slug;
3131
- }
3132
-
3133
- /**
3134
- * Add or Edit a Pods Object
3135
- *
3136
- * $params['id'] int The Object ID
3137
- * $params['name'] string The Object name
3138
- * $params['type'] string The Object type
3139
- * $params['options'] Associative array of Object options
3140
- *
3141
- * @param array|object $params An associative array of parameters
3142
- * @param bool $sanitized (optional) Decides whether the params have been sanitized before being passed,
3143
- * will sanitize them if false.
3144
- *
3145
- * @return int The Object ID
3146
- * @since 2.0.0
3147
- */
3148
- public function save_object( $params, $sanitized = false ) {
3149
-
3150
- $params = (object) $params;
3151
-
3152
- if ( false === $sanitized ) {
3153
- $params = pods_sanitize( $params );
3154
- }
3155
-
3156
- if ( ! isset( $params->name ) || empty( $params->name ) ) {
3157
- return pods_error( __( 'Name must be given to save an Object', 'pods' ), $this );
3158
- }
3159
-
3160
- if ( ! isset( $params->type ) || empty( $params->type ) ) {
3161
- return pods_error( __( 'Type must be given to save an Object', 'pods' ), $this );
3162
- }
3163
-
3164
- $object = array(
3165
- 'id' => 0,
3166
- 'name' => $params->name,
3167
- 'type' => $params->type,
3168
- 'code' => '',
3169
- 'options' => array()
3170
- );
3171
-
3172
- // Setup options
3173
- $options = get_object_vars( $params );
3174
-
3175
- if ( isset( $options['method'] ) ) {
3176
- unset( $options['method'] );
3177
- }
3178
-
3179
- $exclude = array(
3180
- 'id',
3181
- 'name',
3182
- 'helper_type',
3183
- 'code',
3184
- 'options',
3185
- 'status'
3186
- );
3187
-
3188
- foreach ( $exclude as $k => $exclude_field ) {
3189
- $aliases = array( $exclude_field );
3190
-
3191
- if ( is_array( $exclude_field ) ) {
3192
- $aliases = array_merge( array( $k ), $exclude_field );
3193
- $exclude_field = $k;
3194
- }
3195
-
3196
- foreach ( $aliases as $alias ) {
3197
- if ( isset( $options[ $alias ] ) ) {
3198
- $object[ $exclude_field ] = pods_trim( $options[ $alias ] );
3199
-
3200
- unset( $options[ $alias ] );
3201
- }
3202
- }
3203
- }
3204
-
3205
- if ( 'helper' === $object['type'] ) {
3206
- $object['options']['helper_type'] = $object['helper_type'];
3207
- }
3208
-
3209
- if ( isset( $object['options']['code'] ) ) {
3210
- unset( $object['options']['code'] );
3211
- }
3212
-
3213
- $object['options'] = array_merge( $object['options'], $options );
3214
-
3215
- $post_data = array(
3216
- 'post_name' => pods_clean_name( $object['name'], true ),
3217
- 'post_title' => $object['name'],
3218
- 'post_content' => $object['code'],
3219
- 'post_type' => '_pods_' . $object['type'],
3220
- 'post_status' => 'publish'
3221
- );
3222
-
3223
- if ( ! empty( $object['id'] ) ) {
3224
- $post_data['ID'] = $object['id'];
3225
- }
3226
-
3227
- if ( null !== pods_var( 'status', $object, null, null, true ) ) {
3228
- $post_data['post_status'] = pods_var( 'status', $object, null, null, true );
3229
- }
3230
-
3231
- remove_filter( 'content_save_pre', 'balanceTags', 50 );
3232
-
3233
- $post_data = pods_sanitize( $post_data );
3234
-
3235
- $params->id = $this->save_post( $post_data, $object['options'], true, true );
3236
-
3237
- pods_transient_clear( 'pods_objects_' . $params->type );
3238
- pods_transient_clear( 'pods_objects_' . $params->type . '_get' );
3239
-
3240
- return $params->id;
3241
- }
3242
-
3243
- /**
3244
- * @see PodsAPI::save_object
3245
- *
3246
- * Add or edit a Pod Template
3247
- *
3248
- * $params['id'] int The template ID
3249
- * $params['name'] string The template name
3250
- * $params['code'] string The template code
3251
- *
3252
- * @param array|object $params An associative array of parameters
3253
- * @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed,
3254
- * will sanitize them if false.
3255
- *
3256
- * @return int The Template ID
3257
- *
3258
- * @since 1.7.9
3259
- */
3260
- public function save_template( $params, $sanitized = false ) {
3261
-
3262
- $params = (object) $params;
3263
-
3264
- $params->type = 'template';
3265
-
3266
- return $this->save_object( $params, $sanitized );
3267
- }
3268
-
3269
- /**
3270
- * @see PodsAPI::save_object
3271
- *
3272
- * Add or edit a Pod Page
3273
- *
3274
- * $params['id'] int The page ID
3275
- * $params['name'] string The page URI
3276
- * $params['code'] string The page code
3277
- *
3278
- * @param array|object $params An associative array of parameters
3279
- * @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed,
3280
- * will sanitize them if false.
3281
- *
3282
- * @return int The page ID
3283
- * @since 1.7.9
3284
- */
3285
- public function save_page( $params, $sanitized = false ) {
3286
-
3287
- $params = (object) $params;
3288
-
3289
- if ( ! isset( $params->name ) ) {
3290
- $params->name = $params->uri;
3291
- unset( $params->uri );
3292
- }
3293
-
3294
- if ( isset( $params->phpcode ) ) {
3295
- $params->code = $params->phpcode;
3296
- unset( $params->phpcode );
3297
- }
3298
-
3299
- $params->name = trim( $params->name, '/' );
3300
- $params->type = 'page';
3301
-
3302
- return $this->save_object( $params, $sanitized );
3303
- }
3304
-
3305
- /**
3306
- * @see PodsAPI::save_object
3307
- *
3308
- * Add or edit a Pod Helper
3309
- *
3310
- * $params['id'] int The helper ID
3311
- * $params['name'] string The helper name
3312
- * $params['helper_type'] string The helper type ("pre_save", "display", etc)
3313
- * $params['code'] string The helper code
3314
- *
3315
- * @param array $params An associative array of parameters
3316
- * @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will
3317
- * sanitize them if false.
3318
- *
3319
- * @return int The helper ID
3320
- * @since 1.7.9
3321
- */
3322
- public function save_helper( $params, $sanitized = false ) {
3323
-
3324
- $params = (object) $params;
3325
-
3326
- if ( isset( $params->phpcode ) ) {
3327
- $params->code = $params->phpcode;
3328
- unset( $params->phpcode );
3329
- }
3330
-
3331
- if ( isset( $params->type ) ) {
3332
- $params->helper_type = $params->type;
3333
- unset( $params->type );
3334
- }
3335
-
3336
- $params->type = 'helper';
3337
-
3338
- return $this->save_object( $params, $sanitized );
3339
- }
3340
-
3341
- /**
3342
- * Add or edit a single pod item
3343
- *
3344
- * $params['pod'] string The Pod name (pod or pod_id is required)
3345
- * $params['pod_id'] string The Pod ID (pod or pod_id is required)
3346
- * $params['id'] int|array The item ID, or an array of item IDs to save data for
3347
- * $params['data'] array (optional) Associative array of field names + values
3348
- * $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
3349
- * $params['track_changed_fields'] bool Set to true to enable tracking of saved fields via
3350
- * PodsAPI::get_changed_fields()
3351
- * $params['error_mode'] string Throw an 'exception', 'exit' with the message, return 'false', or return 'wp_error'
3352
- *
3353
- * @param array|object $params An associative array of parameters
3354
- *
3355
- * @return int|array The item ID, or an array of item IDs (if `id` is an array if IDs)
3356
- *
3357
- * @since 1.7.9
3358
- */
3359
- public function save_pod_item( $params ) {
3360
-
3361
- global $wpdb;
3362
-
3363
- $params = (object) pods_str_replace( '@wp_', '{prefix}', $params );
3364
-
3365
- $tableless_field_types = PodsForm::tableless_field_types();
3366
- $repeatable_field_types = PodsForm::repeatable_field_types();
3367
- $simple_tableless_objects = PodsForm::simple_tableless_objects();
3368
-
3369
- $error_mode = $this->display_errors;
3370
-
3371
- if ( ! empty( $params->error_mode ) ) {
3372
- $error_mode = $params->error_mode;
3373
- }
3374
-
3375
- // @deprecated 2.0.0
3376
- if ( isset( $params->datatype ) ) {
3377
- pods_deprecated( '$params->pod instead of $params->datatype', '2.0' );
3378
-
3379
- $params->pod = $params->datatype;
3380
-
3381
- unset( $params->datatype );
3382
-
3383
- if ( isset( $params->pod_id ) ) {
3384
- pods_deprecated( '$params->id instead of $params->pod_id', '2.0' );
3385
-
3386
- $params->id = $params->pod_id;
3387
-
3388
- unset( $params->pod_id );
3389
- }
3390
-
3391
- if ( isset( $params->data ) && ! empty( $params->data ) && is_array( $params->data ) ) {
3392
- $check = current( $params->data );
3393
-
3394
- if ( is_array( $check ) ) {
3395
- pods_deprecated( 'PodsAPI::save_pod_items', '2.0' );
3396
-
3397
- return $this->save_pod_items( $params, $params->data );
3398
- }
3399
- }
3400
- }
3401
-
3402
- // @deprecated 2.0.0
3403
- if ( isset( $params->tbl_row_id ) ) {
3404
- pods_deprecated( '$params->id instead of $params->tbl_row_id', '2.0' );
3405
-
3406
- $params->id = $params->tbl_row_id;
3407
-
3408
- unset( $params->tbl_row_id );
3409
- }
3410
-
3411
- // @deprecated 2.0.0
3412
- if ( isset( $params->columns ) ) {
3413
- pods_deprecated( '$params->data instead of $params->columns', '2.0' );
3414
-
3415
- $params->data = $params->columns;
3416
-
3417
- unset( $params->columns );
3418
- }
3419
-
3420
- if ( ! isset( $params->pod ) ) {
3421
- $params->pod = false;
3422
- }
3423
- if ( isset( $params->pod_id ) ) {
3424
- $params->pod_id = pods_absint( $params->pod_id );
3425
- } else {
3426
- $params->pod_id = 0;
3427
- }
3428
-
3429
- if ( isset( $params->id ) ) {
3430
- $params->id = pods_absint( $params->id );
3431
- } else {
3432
- $params->id = 0;
3433
- }
3434
-
3435
- if ( ! isset( $params->from ) ) {
3436
- $params->from = 'save';
3437
- }
3438
-
3439
- if ( ! isset( $params->location ) ) {
3440
- $params->location = null;
3441
- }
3442
-
3443
- if ( ! isset( $params->track_changed_fields ) ) {
3444
- $params->track_changed_fields = false;
3445
- }
3446
-
3447
- $pod_name = $params->pod;
3448
- /**
3449
- * Override $params['track_changed_fields']
3450
- *
3451
- * Use for globally setting field change tracking.
3452
- *
3453
- * @param bool
3454
- *
3455
- * @since 2.3.19
3456
- */
3457
- $track_changed_fields = apply_filters( "pods_api_save_pod_item_track_changed_fields_{$pod_name}", (boolean) $params->track_changed_fields, $params );
3458
-
3459
- $changed_fields = array();
3460
-
3461
- if ( ! isset( $params->clear_slug_cache ) ) {
3462
- $params->clear_slug_cache = true;
3463
- }
3464
-
3465
- // Support for bulk edit
3466
- if ( isset( $params->id ) && ! empty( $params->id ) && is_array( $params->id ) ) {
3467
- $ids = array();
3468
- $new_params = $params;
3469
-
3470
- foreach ( $params->id as $id ) {
3471
- $new_params->id = $id;
3472
-
3473
- $ids[] = $this->save_pod_item( $new_params );
3474
- }
3475
-
3476
- return $ids;
3477
- }
3478
-
3479
- // Allow Helpers to know what's going on, are we adding or saving?
3480
- $is_new_item = false;
3481
-
3482
- if ( empty( $params->id ) ) {
3483
- $is_new_item = true;
3484
- }
3485
-
3486
- if ( isset( $params->is_new_item ) ) {
3487
- $is_new_item = (boolean) $params->is_new_item;
3488
- }
3489
-
3490
- // Allow Helpers to bypass subsequent helpers in recursive save_pod_item calls
3491
- $bypass_helpers = false;
3492
-
3493
- if ( isset( $params->bypass_helpers ) && false !== $params->bypass_helpers ) {
3494
- $bypass_helpers = true;
3495
- }
3496
-
3497
- // Allow Custom Fields not defined by Pods to be saved
3498
- $allow_custom_fields = false;
3499
-
3500
- if ( isset( $params->allow_custom_fields ) && false !== $params->allow_custom_fields ) {
3501
- $allow_custom_fields = true;
3502
- }
3503
-
3504
- // Get array of Pods
3505
- $pod = $this->load_pod( array( 'id' => $params->pod_id, 'name' => $params->pod, 'table_info' => true ) );
3506
-
3507
- if ( false === $pod ) {
3508
- return pods_error( __( 'Pod not found', 'pods' ), $error_mode );
3509
- }
3510
-
3511
- $params->pod = $pod['name'];
3512
- $params->pod_id = $pod['id'];
3513
-
3514
- if ( 'settings' === $pod['type'] ) {
3515
- $params->id = $pod['id'];
3516
- }
3517
-
3518
- $fields = $pod['fields'];
3519
-
3520
- $object_fields = (array) pods_var_raw( 'object_fields', $pod, array(), null, true );
3521
-
3522
- $fields_active = array();
3523
- $custom_data = array();
3524
- $custom_fields = array();
3525
-
3526
- // Find the active fields (loop through $params->data to retain order)
3527
- if ( ! empty( $params->data ) && is_array( $params->data ) ) {
3528
- foreach ( $params->data as $field => $value ) {
3529
- if ( isset( $object_fields[ $field ] ) ) {
3530
- $object_fields[ $field ]['value'] = $value;
3531
- $fields_active[] = $field;
3532
- } elseif ( isset( $fields[ $field ] ) ) {
3533
- if ( 'save' === $params->from || true === PodsForm::permission( $fields[ $field ]['type'], $field, $fields[ $field ], $fields, $pod, $params->id, $params ) ) {
3534
- $fields[ $field ]['value'] = $value;
3535
- $fields_active[] = $field;
3536
- } elseif ( ! pods_has_permissions( $fields[ $field ]['options'] ) && pods_var( 'hidden', $fields[ $field ]['options'], false ) ) {
3537
- $fields[ $field ]['value'] = $value;
3538
- $fields_active[] = $field;
3539
- }
3540
- } else {
3541
- $found = false;
3542
-
3543
- foreach ( $object_fields as $object_field => $object_field_opt ) {
3544
- if ( in_array( $field, $object_field_opt['alias'] ) ) {
3545
- $object_fields[ $object_field ]['value'] = $value;
3546
- $fields_active[] = $object_field;
3547
-
3548
- $found = true;
3549
-
3550
- break;
3551
- }
3552
- }
3553
-
3554
- if ( $allow_custom_fields && ! $found ) {
3555
- $custom_fields[] = $field;
3556
- }
3557
- }
3558
- }
3559
-
3560
- if ( $allow_custom_fields && ! empty( $custom_fields ) ) {
3561
- foreach ( $custom_fields as $field ) {
3562
- $custom_data[ $field ] = $params->data[ $field ];
3563
- }
3564
- }
3565
-
3566
- unset( $params->data );
3567
- }
3568
-
3569
- if ( empty( $params->id ) && ! in_array( 'created', $fields_active ) && isset( $fields['created'] ) && in_array( $fields['created']['type'], array(
3570
- 'date',
3571
- 'datetime'
3572
- ) ) ) {
3573
- $fields['created']['value'] = current_time( 'mysql' );
3574
- $fields_active[] = 'created';
3575
- }
3576
-
3577
- if ( ! in_array( 'modified', $fields_active ) && isset( $fields['modified'] ) && in_array( $fields['modified']['type'], array(
3578
- 'date',
3579
- 'datetime'
3580
- ) ) ) {
3581
- $fields['modified']['value'] = current_time( 'mysql' );
3582
- $fields_active[] = 'modified';
3583
- }
3584
-
3585
- if ( in_array( $pod['type'], array(
3586
- 'pod',
3587
- 'table'
3588
- ) ) && empty( $params->id ) && ! empty( $pod['pod_field_index'] ) && in_array( $pod['pod_field_index'], $fields_active ) && ! in_array( $pod['pod_field_slug'], $fields_active ) && isset( $fields[ $pod['pod_field_slug'] ] ) ) {
3589
- $fields[ $pod['pod_field_slug'] ]['value'] = ''; // this will get picked up by slug pre_save method
3590
- $fields_active[] = $pod['pod_field_slug'];
3591
- }
3592
-
3593
- // Handle hidden fields
3594
- if ( empty( $params->id ) ) {
3595
- foreach ( $fields as $field => $field_data ) {
3596
- if ( in_array( $field, $fields_active ) ) {
3597
- continue;
3598
- }
3599
-
3600
- if ( in_array( $params->from, array(
3601
- 'save',
3602
- 'process_form'
3603
- ) ) || true === PodsForm::permission( $fields[ $field ]['type'], $field, $fields[ $field ], $fields, $pod, $params->id, $params ) ) {
3604
- $value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data['type'], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
3605
-
3606
- if ( null !== $value && '' !== $value && false !== $value ) {
3607
- $fields[ $field ]['value'] = $value;
3608
- $fields_active[] = $field;
3609
- }
3610
- }
3611
- }
3612
-
3613
- // Set default field values for object fields
3614
- if ( ! empty( $object_fields ) ) {
3615
- foreach ( $object_fields as $field => $field_data ) {
3616
- if ( in_array( $field, $fields_active ) ) {
3617
- continue;
3618
- } elseif ( ! isset( $field_data['default'] ) || strlen( $field_data['default'] ) < 1 ) {
3619
- continue;
3620
- }
3621
-
3622
- $value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data['type'], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
3623
-
3624
- if ( null !== $value && '' !== $value && false !== $value ) {
3625
- $object_fields[ $field ]['value'] = $value;
3626
- $fields_active[] = $field;
3627
- }
3628
- }
3629
- }
3630
-
3631
- // Set default field values for Pod fields
3632
- foreach ( $fields as $field => $field_data ) {
3633
- if ( in_array( $field, $fields_active ) ) {
3634
- continue;
3635
- } elseif ( ! isset( $field_data['default'] ) || strlen( $field_data['default'] ) < 1 ) {
3636
- continue;
3637
- }
3638
-
3639
- $value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data['type'], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
3640
-
3641
- if ( null !== $value && '' !== $value && false !== $value ) {
3642
- $fields[ $field ]['value'] = $value;
3643
- $fields_active[] = $field;
3644
- }
3645
- }
3646
- }
3647
-
3648
- $columns =& $fields; // @deprecated 2.0.0
3649
- $active_columns =& $fields_active; // @deprecated 2.0.0
3650
- $params->tbl_row_id =& $params->id; // @deprecated 2.0.0
3651
-
3652
- $pre_save_helpers = array();
3653
- $post_save_helpers = array();
3654
-
3655
- $pieces = array(
3656
- 'fields',
3657
- 'params',
3658
- 'pod',
3659
- 'fields_active',
3660
- 'object_fields',
3661
- 'custom_fields',
3662
- 'custom_data',
3663
- 'track_changed_fields',
3664
- 'changed_fields'
3665
- );
3666
-
3667
- if ( $track_changed_fields ) {
3668
- self::handle_changed_fields( $params->pod, $params->id, 'set' );
3669
- }
3670
-
3671
- if ( false === $bypass_helpers ) {
3672
- // Plugin hooks
3673
- $hooked = $this->do_hook( 'pre_save_pod_item', compact( $pieces ), $is_new_item, $params->id );
3674
-
3675
- if ( is_array( $hooked ) && ! empty( $hooked ) ) {
3676
- extract( $hooked );
3677
- }
3678
-
3679
- $hooked = $this->do_hook( "pre_save_pod_item_{$params->pod}", compact( $pieces ), $is_new_item, $params->id );
3680
-
3681
- if ( is_array( $hooked ) && ! empty( $hooked ) ) {
3682
- extract( $hooked );
3683
- }
3684
-
3685
- if ( $is_new_item ) {
3686
- $hooked = $this->do_hook( 'pre_create_pod_item', compact( $pieces ) );
3687
-
3688
- if ( is_array( $hooked ) && ! empty( $hooked ) ) {
3689
- extract( $hooked );
3690
- }
3691
-
3692
- $hooked = $this->do_hook( "pre_create_pod_item_{$params->pod}", compact( $pieces ) );
3693
-
3694
- if ( is_array( $hooked ) && ! empty( $hooked ) ) {
3695
- extract( $hooked );
3696
- }
3697
- } else {
3698
- $hooked = $this->do_hook( 'pre_edit_pod_item', compact( $pieces ), $params->id );
3699
-
3700
- if ( is_array( $hooked ) && ! empty( $hooked ) ) {
3701
- extract( $hooked );
3702
- }
3703
-
3704
- $hooked = $this->do_hook( "pre_edit_pod_item_{$params->pod}", compact( $pieces ), $params->id );
3705
-
3706
- if ( is_array( $hooked ) && ! empty( $hooked ) ) {
3707
- extract( $hooked );
3708
- }
3709
- }
3710
-
3711
- // Call any pre-save helpers (if not bypassed)
3712
- if ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) {
3713
- if ( ! empty( $pod['options'] ) && is_array( $pod['options'] ) ) {
3714
- $helpers = array( 'pre_save_helpers', 'post_save_helpers' );
3715
-
3716
- foreach ( $helpers as $helper ) {
3717
- if ( isset( $pod['options'][ $helper ] ) && ! empty( $pod['options'][ $helper ] ) ) {
3718
- ${$helper} = explode( ',', $pod['options'][ $helper ] );
3719
- }
3720
- }
3721
- }
3722
-
3723
- if ( ! empty( $pre_save_helpers ) ) {
3724
- pods_deprecated( sprintf( __( 'Pre-save helpers are deprecated, use the action pods_pre_save_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
3725
-
3726
- foreach ( $pre_save_helpers as $helper ) {
3727
- $helper = $this->load_helper( array( 'name' => $helper ) );
3728
-
3729
- if ( false !== $helper ) {
3730
- eval( '?>' . $helper['code'] );
3731
- }
3732
- }
3733
- }
3734
- }
3735
- }
3736
-
3737
- $table_data = array();
3738
- $table_formats = array();
3739
- $update_values = array();
3740
- $rel_fields = array();
3741
- $rel_field_ids = array();
3742
-
3743
- $object_type = $pod['type'];
3744
-
3745
- $object_ID = 'ID';
3746
-
3747
- if ( 'comment' === $object_type ) {
3748
- $object_ID = 'comment_ID';
3749
- } elseif ( 'taxonomy' === $object_type ) {
3750
- $object_ID = 'term_id';
3751
- }
3752
-
3753
- $object_data = array();
3754
- $object_meta = array();
3755
- $post_term_data = array();
3756
-
3757
- if ( 'settings' === $object_type ) {
3758
- $object_data['option_id'] = $pod['name'];
3759
- } elseif ( ! empty( $params->id ) ) {
3760
- $object_data[ $object_ID ] = $params->id;
3761
- }
3762
-
3763
- $fields_active = array_unique( $fields_active );
3764
-
3765
- // Loop through each active field, validating and preparing the table data
3766
- foreach ( $fields_active as $field ) {
3767
- if ( isset( $object_fields[ $field ] ) ) {
3768
- $field_data = $object_fields[ $field ];
3769
- } elseif ( isset( $fields[ $field ] ) ) {
3770
- $field_data = $fields[ $field ];
3771
- } else {
3772
- continue;
3773
- }
3774
-
3775
- $value = $field_data['value'];
3776
- $type = $field_data['type'];
3777
- $options = pods_var( 'options', $field_data, array() );
3778
-
3779
- // WPML AJAX compatibility
3780
- if ( is_admin()
3781
- && ( isset( $_POST['action'] ) && 'wpml_save_job_ajax' === $_POST['action'] )
3782
- || ( isset( $_GET['page'] ) && false !== strpos( $_GET['page'], '/menu/languages.php' )
3783
- && isset( $_POST['icl_ajx_action'] ) && isset( $_POST['_icl_nonce'] )
3784
- && wp_verify_nonce( $_POST['_icl_nonce'], $_POST['icl_ajx_action'] . '_nonce' ) )
3785
- ) {
3786
- $options['unique'] = 0;
3787
- $fields[ $field ]['options']['unique'] = 0;
3788
- $options['required'] = 0;
3789
- $fields[ $field ]['options']['required'] = 0;
3790
- } else {
3791
- // Validate value
3792
- $validate = $this->handle_field_validation( $value, $field, $object_fields, $fields, $pod, $params );
3793
-
3794
- if ( false === $validate ) {
3795
- $validate = sprintf( __( 'There was an issue validating the field %s', 'pods' ), $field_data['label'] );
3796
- } elseif ( true !== $validate ) {
3797
- $validate = (array) $validate;
3798
- }
3799
-
3800
- if ( ! is_bool( $validate ) && ! empty( $validate ) ) {
3801
- return pods_error( $validate, $error_mode );
3802
- }
3803
- }
3804
-
3805
- $value = PodsForm::pre_save( $field_data['type'], $value, $params->id, $field, array_merge( $field_data, $options ), array_merge( $fields, $object_fields ), $pod, $params );
3806
-
3807
- $field_data['value'] = $value;
3808
-
3809
- if ( isset( $object_fields[ $field ] ) ) {
3810
- // @todo Eventually support 'comment' field type saving here too
3811
- if ( 'taxonomy' === $object_fields[ $field ]['type'] ) {
3812
- $post_term_data[ $field ] = $value;
3813
- } else {
3814
- $object_data[ $field ] = $value;
3815
- }
3816
- } else {
3817
- $simple = ( 'pick' === $type && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
3818
- $simple = (boolean) $this->do_hook( 'tableless_custom', $simple, $field_data, $field, $fields, $pod, $params );
3819
-
3820
- // Handle Simple Relationships
3821
- if ( $simple ) {
3822
- if ( ! is_array( $value ) ) {
3823
- if ( 0 < strlen( $value ) ) {
3824
- $value = array( $value );
3825
- } else {
3826
- $value = array();
3827
- }
3828
- }
3829
-
3830
- $pick_limit = (int) pods_var_raw( 'pick_limit', $options, 0 );
3831
-
3832
- if ( 'single' === pods_var_raw( 'pick_format_type', $options ) ) {
3833
- $pick_limit = 1;
3834
- }
3835
-
3836
- if ( 'custom-simple' === pods_var( 'pick_object', $field_data ) ) {
3837
- $custom = pods_var_raw( 'pick_custom', $options, '' );
3838
-
3839
- $custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $field_data['name'], $value, array_merge( $field_data, $options ), $pod, $params->id );
3840
-
3841
- // Input values are unslashed. Unslash database values as well to ensure correct comparison.
3842
- $custom = pods_unslash( $custom );
3843
-
3844
- if ( empty( $value ) || empty( $custom ) ) {
3845
- $value = '';
3846
- } elseif ( ! empty( $custom ) ) {
3847
- if ( ! is_array( $custom ) ) {
3848
- $custom = explode( "\n", $custom );
3849
-
3850
- $custom_values = array();
3851
-
3852
- foreach ( $custom as $c => $cv ) {
3853
- if ( 0 < strlen( $cv ) ) {
3854
- $custom_label = explode( '|', $cv );
3855
-
3856
- if ( ! isset( $custom_label[1] ) ) {
3857
- $custom_label[1] = $custom_label[0];
3858
- }
3859
-
3860
- $custom_label[0] = trim( (string) $custom_label[0] );
3861
- $custom_label[1] = trim( (string) $custom_label[1] );
3862
- $custom_values[ $custom_label[0] ] = $custom_label[1];
3863
- }
3864
- }
3865
- } else {
3866
- $custom_values = $custom;
3867
- }
3868
-
3869
- $values = array();
3870
-
3871
- foreach ( $value as $k => $v ) {
3872
- $v = pods_unsanitize( $v );
3873
-
3874
- if ( isset( $custom_values[ $v ] ) ) {
3875
- $values[ $k ] = $v;
3876
- }
3877
- }
3878
-
3879
- $value = $values;
3880
- }
3881
- }
3882
-
3883
- if ( 0 < $pick_limit && ! empty( $value ) ) {
3884
- $value = array_slice( $value, 0, $pick_limit );
3885
- }
3886
-
3887
- // Don't save an empty array, just make it an empty string
3888
- if ( empty( $value ) ) {
3889
- $value = '';
3890
- } elseif ( is_array( $value ) ) {
3891
- if ( 1 == $pick_limit || 1 == count( $value ) ) {
3892
- // If there's just one item, don't save as an array, save the string
3893
- $value = implode( '', $value );
3894
- } elseif ( 'table' === pods_var( 'storage', $pod ) ) {
3895
- // If storage is set to table, json encode, otherwise WP will serialize automatically
3896
- $value = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $value, JSON_UNESCAPED_UNICODE ) : json_encode( $value );
3897
- }
3898
- }
3899
- }
3900
-
3901
- // Prepare all table / meta data
3902
- if ( ! in_array( $type, $tableless_field_types ) || $simple ) {
3903
- if ( in_array( $type, $repeatable_field_types ) && 1 == pods_var( $type . '_repeatable', $field_data, 0 ) ) {
3904
- // Don't save an empty array, just make it an empty string
3905
- if ( empty( $value ) ) {
3906
- $value = '';
3907
- } elseif ( is_array( $value ) ) {
3908
- if ( 1 == count( $value ) ) {
3909
- // If there's just one item, don't save as an array, save the string
3910
- $value = implode( '', $value );
3911
- } elseif ( 'table' === pods_var( 'storage', $pod ) ) {
3912
- // If storage is set to table, json encode, otherwise WP will serialize automatically
3913
- $value = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $value, JSON_UNESCAPED_UNICODE ) : json_encode( $value );
3914
- }
3915
- }
3916
- }
3917
-
3918
- $table_data[ $field ] = str_replace( array( '{prefix}', '@wp_' ), array(
3919
- '{/prefix/}',
3920
- '{prefix}'
3921
- ), $value ); // Fix for pods_query
3922
- $table_formats[] = PodsForm::prepare( $type, $options );
3923
-
3924
- $object_meta[ $field ] = $value;
3925
- } else {
3926
- // Store relational field data to be looped through later
3927
- // Convert values from a comma-separated string into an array
3928
- if ( ! is_array( $value ) ) {
3929
- $value = explode( ',', $value );
3930
- }
3931
-
3932
- $rel_fields[ $type ][ $field ] = $value;
3933
- $rel_field_ids[] = $field_data['id'];
3934
- }
3935
- }
3936
- }
3937
-
3938
- if ( in_array( $pod['type'], array( 'post_type', 'taxonomy' ) ) ) {
3939
- $object_name = $pod['name'];
3940
-
3941
- if ( ! empty( $pod['object'] ) ) {
3942
- $object_name = $pod['object'];
3943
- }
3944
-
3945
- $object_name_field = 'post_type';
3946
-
3947
- if ( 'taxonomy' === $pod['type'] ) {
3948
- $object_name_field = 'taxonomy';
3949
- }
3950
-
3951
- $object_data[ $object_name_field ] = $object_name;
3952
- }
3953
-
3954
- if ( ! in_array( $pod['type'], array( 'pod', 'table', '' ) ) ) {
3955
- $meta_fields = array();
3956
-
3957
- if ( 'meta' === $pod['storage'] || 'settings' === $pod['type'] || ( 'taxonomy' === $pod['type'] && 'none' === $pod['storage'] ) ) {
3958
- $meta_fields = $object_meta;
3959
- }
3960
-
3961
- if ( $allow_custom_fields && ! empty( $custom_data ) ) {
3962
- $meta_fields = array_merge( $custom_data, $meta_fields );
3963
- }
3964
-
3965
- $fields_to_send = array_flip( array_keys( $meta_fields ) );
3966
-
3967
- foreach ( $fields_to_send as $field => $field_data ) {
3968
- if ( isset( $object_fields[ $field ] ) ) {
3969
- $field_data = $object_fields[ $field ];
3970
- } elseif ( isset( $fields[ $field ] ) ) {
3971
- $field_data = $fields[ $field ];
3972
- } else {
3973
- unset( $fields_to_send[ $field ] );
3974
- }
3975
-
3976
- $fields_to_send[ $field ] = $field_data;
3977
- }
3978
-
3979
- $params->id = $this->save_wp_object( $object_type, $object_data, $meta_fields, false, true, $fields_to_send );
3980
-
3981
- if ( ! empty( $params->id ) && 'settings' === $pod['type'] ) {
3982
- $params->id = $pod['id'];
3983
- }
3984
- }
3985
-
3986
- if ( 'table' === $pod['storage'] ) {
3987
- // Every row should have an id set here, otherwise Pods with nothing
3988
- // but relationship fields won't get properly ID'd
3989
- if ( empty( $params->id ) ) {
3990
- $params->id = 0;
3991
- }
3992
-
3993
- $table_data = array( 'id' => $params->id ) + $table_data;
3994
- array_unshift( $table_formats, '%d' );
3995
-
3996
- if ( ! empty( $table_data ) ) {
3997
- $sql = pods_data()->insert_on_duplicate( "@wp_pods_{$params->pod}", $table_data, $table_formats );
3998
-
3999
- $id = pods_query( $sql, 'Cannot add/save table row' );
4000
-
4001
- if ( empty( $params->id ) ) {
4002
- $params->id = $id;
4003
- }
4004
- }
4005
- }
4006
-
4007
- $params->id = (int) $params->id;
4008
-
4009
- // Save terms for taxonomies associated to a post type
4010
- if ( 0 < $params->id && 'post_type' === $pod['type'] && ! empty( $post_term_data ) ) {
4011
- foreach ( $post_term_data as $post_taxonomy => $post_terms ) {
4012
- $post_terms = (array) $post_terms;
4013
-
4014
- foreach ( $post_terms as $k => $v ) {
4015
- if ( ! preg_match( '/[^0-9]/', $v ) ) {
4016
- $v = (int) $v;
4017
- }
4018
-
4019
- $post_terms[ $k ] = $v;
4020
- }
4021
-
4022
- wp_set_object_terms( $params->id, $post_terms, $post_taxonomy );
4023
- }
4024
- }
4025
-
4026
- $no_conflict = pods_no_conflict_check( $pod['type'] );
4027
-
4028
- if ( ! $no_conflict ) {
4029
- pods_no_conflict_on( $pod['type'] );
4030
- }
4031
-
4032
- // Save relationship / file data
4033
- if ( ! empty( $rel_fields ) ) {
4034
- foreach ( $rel_fields as $type => $data ) {
4035
- // Only handle tableless fields
4036
- if ( ! in_array( $type, $tableless_field_types ) ) {
4037
- continue;
4038
- }
4039
-
4040
- foreach ( $data as $field => $values ) {
4041
- $pick_val = pods_var( 'pick_val', $fields[ $field ] );
4042
-
4043
- if ( 'table' === pods_var( 'pick_object', $fields[ $field ] ) ) {
4044
- $pick_val = pods_var( 'pick_table', $fields[ $field ]['options'], $pick_val, null, true );
4045
- }
4046
-
4047
- if ( '__current__' === $pick_val ) {
4048
- if ( is_object( $pod ) ) {
4049
- $pick_val = $pod->pod;
4050
- } elseif ( is_array( $pod ) ) {
4051
- $pick_val = $pod['name'];
4052
- } elseif ( 0 < strlen( $pod ) ) {
4053
- $pick_val = $pod;
4054
- }
4055
- }
4056
-
4057
- $fields[ $field ]['options']['table_info'] = pods_api()->get_table_info( pods_var( 'pick_object', $fields[ $field ] ), $pick_val, null, null, $fields[ $field ]['options'] );
4058
-
4059
- if ( isset( $fields[ $field ]['options']['table_info']['pod'] ) && ! empty( $fields[ $field ]['options']['table_info']['pod'] ) && isset( $fields[ $field ]['options']['table_info']['pod']['name'] ) ) {
4060
- $search_data = pods( $fields[ $field ]['options']['table_info']['pod']['name'] );
4061
-
4062
- $data_mode = 'pods';
4063
- } else {
4064
- $search_data = pods_data();
4065
- $search_data->table( $fields[ $field ]['options']['table_info'] );
4066
-
4067
- $data_mode = 'data';
4068
- }
4069
-
4070
- $find_rel_params = array(
4071
- 'select' => "`t`.`{$search_data->field_id}`",
4072
- 'where' => "`t`.`{$search_data->field_slug}` = %s OR `t`.`{$search_data->field_index}` = %s",
4073
- 'limit' => 1,
4074
- 'pagination' => false,
4075
- 'search' => false
4076
- );
4077
-
4078
- if ( empty( $search_data->field_slug ) && ! empty( $search_data->field_index ) ) {
4079
- $find_rel_params['where'] = "`t`.`{$search_data->field_index}` = %s";
4080
- } elseif ( empty( $search_data->field_slug ) && empty( $search_data->field_index ) ) {
4081
- $find_rel_params = false;
4082
- }
4083
-
4084
- $related_limit = (int) pods_var_raw( $type . '_limit', $fields[ $field ]['options'], 0 );
4085
-
4086
- if ( 'single' === pods_var_raw( $type . '_format_type', $fields[ $field ]['options'] ) ) {
4087
- $related_limit = 1;
4088
- }
4089
-
4090
- // Enforce integers / unique values for IDs
4091
- $value_ids = array();
4092
-
4093
- $is_file_field = in_array( $type, PodsForm::file_field_types() );
4094
- $is_taggable = ( in_array( $type, PodsForm::tableless_field_types() ) && 1 == pods_v( $type . '_taggable', $fields[ $field ]['options'] ) );
4095
-
4096
- // @todo Handle simple relationships eventually
4097
- foreach ( $values as $v ) {
4098
- if ( ! empty( $v ) ) {
4099
- if ( ! is_array( $v ) ) {
4100
- if ( ! preg_match( '/[^0-9]/', $v ) ) {
4101
- $v = (int) $v;
4102
- } elseif ( $is_file_field ) {
4103
- // File handling
4104
- // Get ID from GUID
4105
- $v = pods_image_id_from_field( $v );
4106
-
4107
- // If file not found, add it
4108
- if ( empty( $v ) ) {
4109
- $v = pods_attachment_import( $v );
4110
- }
4111
- } else {
4112
- // Reference by slug
4113
- $v_data = false;
4114
-
4115
- if ( false !== $find_rel_params ) {
4116
- $rel_params = $find_rel_params;
4117
- $rel_params['where'] = $wpdb->prepare( $rel_params['where'], array( $v, $v ) );
4118
-
4119
- $search_data->select( $rel_params );
4120
-
4121
- $v_data = $search_data->fetch( $v );
4122
- }
4123
-
4124
- if ( ! empty( $v_data ) && isset( $v_data[ $search_data->field_id ] ) ) {
4125
- $v = (int) $v_data[ $search_data->field_id ];
4126
- } elseif ( $is_taggable && 'pods' === $data_mode ) {
4127
- // Allow tagging for Pods objects
4128
- $tag_data = array(
4129
- $search_data->field_index => $v
4130
- );
4131
-
4132
- if ( 'post_type' === $search_data->pod_data['type'] ) {
4133
- $tag_data['post_status'] = 'publish';
4134
- }
4135
-
4136
- /**
4137
- * Filter for changing tag before adding new item.
4138
- *
4139
- * @param array $tag_data Fields for creating new item.
4140
- * @param int $v Field ID of tag.
4141
- * @param Pods $search_data Search object for tag.
4142
- * @param string $field Table info for field.
4143
- * @param array $pieces Field array.
4144
- *
4145
- * @since 2.3.19
4146
- */
4147
- $tag_data = apply_filters( 'pods_api_save_pod_item_taggable_data', $tag_data, $v, $search_data, $field, compact( $pieces ) );
4148
-
4149
- // Save $v to a new item on related object
4150
- $v = $search_data->add( $tag_data );
4151
-
4152
- // @todo Support non-Pods for tagging
4153
- }
4154
- }
4155
- } elseif ( $is_file_field && isset( $v['id'] ) ) {
4156
- $v = (int) $v['id'];
4157
- } else {
4158
- continue;
4159
- }
4160
-
4161
- if ( ! empty( $v ) && ! in_array( $v, $value_ids ) ) {
4162
- $value_ids[] = $v;
4163
- }
4164
- }
4165
- }
4166
-
4167
- $value_ids = array_unique( array_filter( $value_ids ) );
4168
-
4169
- // Filter unique values not equal to false in case of a multidimensional array
4170
- $filtered_values = $this->array_filter_walker( $values );
4171
- $serialized_values = array_map( 'serialize', $filtered_values );
4172
- $unique_serialized_values = array_unique( $serialized_values );
4173
-
4174
- $values = array_map( 'unserialize', $unique_serialized_values );
4175
-
4176
- // Limit values
4177
- if ( 0 < $related_limit && ! empty( $value_ids ) ) {
4178
- $value_ids = array_slice( $value_ids, 0, $related_limit );
4179
- $values = array_slice( $values, 0, $related_limit );
4180
- }
4181
-
4182
- // Get current values
4183
- if ( 'pick' === $type && isset( PodsField_Pick::$related_data[ $fields[ $field ]['id'] ] ) && isset( PodsField_Pick::$related_data[ $fields[ $field ]['id'] ]['current_ids'] ) ) {
4184
- $related_ids = PodsField_Pick::$related_data[ $fields[ $field ]['id'] ]['current_ids'];
4185
- } else {
4186
- $related_ids = $this->lookup_related_items( $fields[ $field ]['id'], $pod['id'], $params->id, $fields[ $field ], $pod );
4187
- }
4188
-
4189
- // Get ids to remove
4190
- $remove_ids = array_diff( $related_ids, $value_ids );
4191
-
4192
- // Delete relationships
4193
- if ( ! empty( $remove_ids ) ) {
4194
- $this->delete_relationships( $params->id, $remove_ids, $pod, $fields[ $field ] );
4195
- }
4196
-
4197
- // Save relationships
4198
- if ( ! empty( $value_ids ) ) {
4199
- $this->save_relationships( $params->id, $value_ids, $pod, $fields[ $field ] );
4200
- }
4201
-
4202
- $field_save_values = $value_ids;
4203
-
4204
- if ( 'file' === $type ) {
4205
- $field_save_values = $values;
4206
- }
4207
-
4208
- // Run save function for field type (where needed)
4209
- PodsForm::save( $type, $field_save_values, $params->id, $field, array_merge( $fields[ $field ], $fields[ $field ]['options'] ), array_merge( $fields, $object_fields ), $pod, $params );
4210
- }
4211
-
4212
- // Unset data no longer needed
4213
- if ( 'pick' === $type ) {
4214
- foreach ( $data as $field => $values ) {
4215
- if ( isset( PodsField_Pick::$related_data[ $fields[ $field ]['id'] ] ) ) {
4216
- unset( PodsField_Pick::$related_data[ PodsField_Pick::$related_data[ $fields[ $field ]['id'] ]['related_field']['id'] ] );
4217
- unset( PodsField_Pick::$related_data[ $fields[ $field ]['id'] ] );
4218
- }
4219
- }
4220
- }
4221
- }
4222
- }
4223
-
4224
- if ( ! $no_conflict ) {
4225
- pods_no_conflict_off( $pod['type'] );
4226
- }
4227
-
4228
- // Clear cache
4229
- pods_cache_clear( $params->id, 'pods_items_' . $pod['name'] );
4230
-
4231
- if ( $params->clear_slug_cache && ! empty( $pod['field_slug'] ) ) {
4232
- $slug = pods( $pod['name'], $params->id )->field( $pod['field_slug'] );
4233
-
4234
- if ( 0 < strlen( $slug ) ) {
4235
- pods_cache_clear( $slug, 'pods_items_' . $pod['name'] );
4236
- }
4237
- }
4238
-
4239
- // Clear WP meta cache
4240
- if ( in_array( $pod['type'], array( 'post_type', 'media', 'taxonomy', 'user', 'comment' ) ) ) {
4241
- $meta_type = $pod['type'];
4242
-
4243
- if ( 'post_type' === $meta_type ) {
4244
- $meta_type = 'post';
4245
- }
4246
-
4247
- wp_cache_delete( $params->id, $meta_type . '_meta' );
4248
- wp_cache_delete( $params->id, 'pods_' . $meta_type . '_meta' );
4249
- }
4250
-
4251
- if ( false === $bypass_helpers ) {
4252
- if ( $track_changed_fields ) {
4253
- $changed_fields = self::handle_changed_fields( $params->pod, $params->id, 'get' );
4254
- }
4255
-
4256
- $compact_pieces = compact( $pieces );
4257
-
4258
- // Plugin hooks
4259
- $this->do_hook( 'post_save_pod_item', $compact_pieces, $is_new_item, $params->id );
4260
- $this->do_hook( "post_save_pod_item_{$params->pod}", $compact_pieces, $is_new_item, $params->id );
4261
-
4262
- if ( $is_new_item ) {
4263
- $this->do_hook( 'post_create_pod_item', $compact_pieces, $params->id );
4264
- $this->do_hook( "post_create_pod_item_{$params->pod}", $compact_pieces, $params->id );
4265
- } else {
4266
- $this->do_hook( 'post_edit_pod_item', $compact_pieces, $params->id );
4267
- $this->do_hook( "post_edit_pod_item_{$params->pod}", $compact_pieces, $params->id );
4268
- }
4269
-
4270
- // Call any post-save helpers (if not bypassed)
4271
- if ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) {
4272
- if ( ! empty( $post_save_helpers ) ) {
4273
- pods_deprecated( sprintf( __( 'Post-save helpers are deprecated, use the action pods_post_save_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
4274
-
4275
- foreach ( $post_save_helpers as $helper ) {
4276
- $helper = $this->load_helper( array( 'name' => $helper ) );
4277
-
4278
- if ( false !== $helper && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) {
4279
- eval( '?>' . $helper['code'] );
4280
- }
4281
- }
4282
- }
4283
- }
4284
- }
4285
-
4286
- // Success! Return the id
4287
- return $params->id;
4288
-
4289
- }
4290
-
4291
- /**
4292
- * @see PodsAPI::save_pod_item
4293
- * Add multiple pod items
4294
- *
4295
- * $params['pod'] string The Pod name (pod or pod_id is required)
4296
- * $params['pod_id'] string The Pod ID (pod or pod_id is required)
4297
- * $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
4298
- *
4299
- * $data['id'] int The item ID (optional)
4300
- * $data['data'] array An associative array of field names + values
4301
- *
4302
- * @param array|object $params An associative array of parameters, data excluded
4303
- * @param array $data An associative array of pod ids and field names + values (arrays of field data)
4304
- *
4305
- * @return int The item ID
4306
- * @since 2.0.0
4307
- */
4308
- public function save_pod_items( $params, $data ) {
4309
-
4310
- $params = (object) $params;
4311
-
4312
- $ids = array();
4313
-
4314
- foreach ( $data as $fields ) {
4315
- $params->data = $fields;
4316
-
4317
- if ( isset( $fields['id'] ) && isset( $fields['data'] ) ) {
4318
- $params->id = $fields['id'];
4319
- $params->data = $fields['data'];
4320
- }
4321
-
4322
- $ids[] = $this->save_pod_item( $params );
4323
- }
4324
-
4325
- return $ids;
4326
- }
4327
-
4328
- /**
4329
- * Handle tracking changed fields or get them.
4330
- *
4331
- * @since 2.7.0
4332
- *
4333
- * @param string $pod
4334
- * @param int $id
4335
- * @param string $mode
4336
- *
4337
- * @return array List of changed fields (if $mode = 'get')
4338
- */
4339
- public static function handle_changed_fields( $pod, $id, $mode = 'set' ) {
4340
-
4341
- static $changed_pods_cache = array();
4342
- static $old_fields_cache = array();
4343
- static $changed_fields_cache = array();
4344
-
4345
- $cache_key = $pod . '|' . $id;
4346
-
4347
- $export_params = array(
4348
- 'depth' => 1,
4349
- );
4350
-
4351
- if ( in_array( $mode, array( 'set', 'reset' ), true ) ) {
4352
- if ( isset( $changed_fields_cache[ $cache_key ] ) ) {
4353
- unset( $changed_fields_cache[ $cache_key ] );
4354
- }
4355
-
4356
- if ( empty( $old_fields_cache[ $cache_key ] ) || 'reset' === $mode ) {
4357
- $old_fields_cache[ $cache_key ] = array();
4358
-
4359
- if ( ! empty( $id ) ) {
4360
- if ( ! isset( $changed_pods_cache[ $pod ] ) ) {
4361
- $changed_pods_cache[ $pod ] = pods( $pod );
4362
- }
4363
-
4364
- if ( $changed_pods_cache[ $pod ] && $changed_pods_cache[ $pod ]->valid() ) {
4365
- $changed_pods_cache[ $pod ]->fetch( $id );
4366
-
4367
- $old_fields_cache[ $cache_key ] = $changed_pods_cache[ $pod ]->export( $export_params );
4368
- }
4369
- }
4370
- }
4371
- }
4372
-
4373
- $changed_fields = array();
4374
-
4375
- if ( isset( $changed_fields_cache[ $cache_key ] ) ) {
4376
- $changed_fields = $changed_fields_cache[ $cache_key ];
4377
- } elseif ( isset( $old_fields_cache[ $cache_key ] ) ) {
4378
- $old_fields = $old_fields_cache[ $cache_key ];
4379
-
4380
- if ( 'get' === $mode ) {
4381
- $changed_fields_cache[ $cache_key ] = array();
4382
-
4383
- if ( ! empty( $changed_pods_cache[ $pod ] ) ) {
4384
- if ( $id != $changed_pods_cache[ $pod ]->id() ) {
4385
- $changed_pods_cache[ $pod ]->fetch( $id );
4386
- }
4387
-
4388
- $new_fields = $changed_pods_cache[ $pod ]->export( $export_params );
4389
-
4390
- foreach ( $new_fields as $field => $value ) {
4391
- if ( ! isset( $old_fields[ $field ] ) || $value != $old_fields[ $field ] ) {
4392
- $changed_fields[ $field ] = $value;
4393
- }
4394
- }
4395
-
4396
- $changed_fields_cache[ $cache_key ] = $changed_fields;
4397
- }
4398
- }
4399
- }
4400
-
4401
- return $changed_fields;
4402
-
4403
- }
4404
-
4405
- /**
4406
- * Get the fields that have changed during a save
4407
- *
4408
- * @param array $pieces Pieces array from save_pod_item
4409
- *
4410
- * @return array Array of fields and values that have changed
4411
- *
4412
- * @deprecated 2.7.0 Use PodsAPI::handle_changed_fields
4413
- */
4414
- public function get_changed_fields( $pieces ) {
4415
-
4416
- return self::handle_changed_fields( $pieces['params']->pod, $pieces['params']->id, 'get' );
4417
-
4418
- }
4419
-
4420
- /**
4421
- * Save relationships
4422
- *
4423
- * @param int $id ID of item
4424
- * @param int|array $related_id ID or IDs to save
4425
- * @param array $pod Pod data
4426
- * @param array $field Field data
4427
- */
4428
- public function save_relationships( $id, $related_ids, $pod, $field ) {
4429
-
4430
- // Get current values
4431
- if ( 'pick' === $field['type'] && isset( PodsField_Pick::$related_data[ $field['id'] ] ) && isset( PodsField_Pick::$related_data[ $field['id'] ]['current_ids'] ) ) {
4432
- $current_ids = PodsField_Pick::$related_data[ $field['id'] ]['current_ids'];
4433
- } else {
4434
- $current_ids = $this->lookup_related_items( $field['id'], $pod['id'], $id, $field, $pod );
4435
- }
4436
-
4437
- if ( isset( self::$related_item_cache[ $pod['id'] ][ $field['id'] ] ) ) {
4438
- // Delete relationship from cache
4439
- unset( self::$related_item_cache[ $pod['id'] ][ $field['id'] ] );
4440
- }
4441
-
4442
- if ( ! is_array( $related_ids ) ) {
4443
- $related_ids = implode( ',', $related_ids );
4444
- }
4445
-
4446
- foreach ( $related_ids as $k => $related_id ) {
4447
- $related_ids[ $k ] = (int) $related_id;
4448
- }
4449
-
4450
- $related_ids = array_unique( array_filter( $related_ids ) );
4451
-
4452
- $related_limit = (int) pods_var_raw( $field['type'] . '_limit', $field['options'], 0 );
4453
-
4454
- if ( 'single' === pods_var_raw( $field['type'] . '_format_type', $field['options'] ) ) {
4455
- $related_limit = 1;
4456
- }
4457
-
4458
- // Limit values
4459
- if ( 0 < $related_limit && ! empty( $related_ids ) ) {
4460
- $related_ids = array_slice( $related_ids, 0, $related_limit );
4461
- }
4462
-
4463
- // Post Types, Media, Users, and Comments (meta-based)
4464
- if ( in_array( $pod['type'], array( 'post_type', 'media', 'taxonomy', 'user', 'comment' ) ) ) {
4465
- $object_type = $pod['type'];
4466
-
4467
- if ( in_array( $object_type, array( 'post_type', 'media' ) ) ) {
4468
- $object_type = 'post';
4469
- } elseif ( 'taxonomy' === $object_type ) {
4470
- $object_type = 'term';
4471
- }
4472
-
4473
- delete_metadata( $object_type, $id, $field['name'] );
4474
-
4475
- if ( ! empty( $related_ids ) ) {
4476
- update_metadata( $object_type, $id, '_pods_' . $field['name'], $related_ids );
4477
-
4478
- foreach ( $related_ids as $related_id ) {
4479
- add_metadata( $object_type, $id, $field['name'], $related_id );
4480
- }
4481
- } else {
4482
- delete_metadata( $object_type, $id, '_pods_' . $field['name'] );
4483
- }
4484
- } elseif ( 'settings' === $pod['type'] ) {
4485
- // Custom Settings Pages (options-based)
4486
- if ( ! empty( $related_ids ) ) {
4487
- update_option( $pod['name'] . '_' . $field['name'], $related_ids );
4488
- } else {
4489
- delete_option( $pod['name'] . '_' . $field['name'] );
4490
- }
4491
- }
4492
-
4493
- $related_pod_id = 0;
4494
- $related_field_id = 0;
4495
-
4496
- if ( 'pick' === $field['type'] && isset( PodsField_Pick::$related_data[ $field['id'] ] ) && ! empty( PodsField_Pick::$related_data[ $field['id'] ]['related_field'] ) ) {
4497
- $related_pod_id = PodsField_Pick::$related_data[ $field['id'] ]['related_pod']['id'];
4498
- $related_field_id = PodsField_Pick::$related_data[ $field['id'] ]['related_field']['id'];
4499
- }
4500
-
4501
- // Relationships table
4502
- if ( ! pods_tableless() ) {
4503
- $related_weight = 0;
4504
-
4505
- foreach ( $related_ids as $related_id ) {
4506
- if ( in_array( $related_id, $current_ids ) ) {
4507
- pods_query( "
4508
- UPDATE `@wp_podsrel`
4509
- SET
4510
- `pod_id` = %d,
4511
- `field_id` = %d,
4512
- `item_id` = %d,
4513
- `related_pod_id` = %d,
4514
- `related_field_id` = %d,
4515
- `related_item_id` = %d,
4516
- `weight` = %d
4517
- WHERE
4518
- `pod_id` = %d
4519
- AND `field_id` = %d
4520
- AND `item_id` = %d
4521
- AND `related_item_id` = %d
4522
- ", array(
4523
- $pod['id'],
4524
- $field['id'],
4525
- $id,
4526
- $related_pod_id,
4527
- $related_field_id,
4528
- $related_id,
4529
- $related_weight,
4530
-
4531
- $pod['id'],
4532
- $field['id'],
4533
- $id,
4534
- $related_id,
4535
- ) );
4536
- } else {
4537
- pods_query( "
4538
- INSERT INTO `@wp_podsrel`
4539
- (
4540
- `pod_id`,
4541
- `field_id`,
4542
- `item_id`,
4543
- `related_pod_id`,
4544
- `related_field_id`,
4545
- `related_item_id`,
4546
- `weight`
4547
- )
4548
- VALUES ( %d, %d, %d, %d, %d, %d, %d )
4549
- ", array(
4550
- $pod['id'],
4551
- $field['id'],
4552
- $id,
4553
- $related_pod_id,
4554
- $related_field_id,
4555
- $related_id,
4556
- $related_weight
4557
- ) );
4558
- }
4559
-
4560
- $related_weight ++;
4561
- }
4562
- }
4563
- }
4564
-
4565
- /**
4566
- * Duplicate a Pod
4567
- *
4568
- * $params['id'] int The Pod ID
4569
- * $params['name'] string The Pod name
4570
- * $params['new_name'] string The new Pod name
4571
- *
4572
- * @param array $params An associative array of parameters
4573
- * @param bool $strict (optional) Makes sure a pod exists, if it doesn't throws an error
4574
- *
4575
- * @return int New Pod ID
4576
- * @since 2.3.0
4577
- */
4578
- public function duplicate_pod( $params, $strict = false ) {
4579
-
4580
- if ( ! is_object( $params ) && ! is_array( $params ) ) {
4581
- if ( is_numeric( $params ) ) {
4582
- $params = array( 'id' => $params );
4583
- } else {
4584
- $params = array( 'name' => $params );
4585
- }
4586
-
4587
- $params = (object) pods_sanitize( $params );
4588
- } else {
4589
- $params = (object) pods_sanitize( $params );
4590
- }
4591
-
4592
- $params->table_info = false;
4593
-
4594
- $pod = $this->load_pod( $params, $strict );
4595
-
4596
- if ( empty( $pod ) ) {
4597
- if ( false !== $strict ) {
4598
- return pods_error( __( 'Pod not found', 'pods' ), $this );
4599
- }
4600
-
4601
- return false;
4602
- } elseif ( in_array( $pod['type'], array( 'media', 'user', 'comment' ) ) ) {
4603
- if ( false !== $strict ) {
4604
- return pods_error( __( 'Pod not allowed to be duplicated', 'pods' ), $this );
4605
- }
4606
-
4607
- return false;
4608
- } elseif ( in_array( $pod['type'], array( 'post_type', 'taxonomy' ) ) && 0 < strlen( $pod['object'] ) ) {
4609
- $pod['object'] = '';
4610
- }
4611
-
4612
- unset( $pod['id'] );
4613
-
4614
- if ( isset( $params->new_name ) ) {
4615
- $pod['name'] = $params->new_name;
4616
- }
4617
-
4618
- $try = 1;
4619
-
4620
- $check_name = $pod['name'];
4621
- $new_label = $pod['label'];
4622
-
4623
- while ( $this->load_pod( array( 'name' => $check_name, 'table_info' => false ), false ) ) {
4624
- $try ++;
4625
-
4626
- $check_name = $pod['name'] . $try;
4627
- $new_label = $pod['label'] . $try;
4628
- }
4629
-
4630
- $pod['name'] = $check_name;
4631
- $pod['label'] = $new_label;
4632
-
4633
- foreach ( $pod['fields'] as $field => $field_data ) {
4634
- unset( $pod['fields'][ $field ]['id'] );
4635
- }
4636
-
4637
- return $this->save_pod( $pod );
4638
- }
4639
-
4640
- /**
4641
- * Duplicate a Field
4642
- *
4643
- * $params['pod_id'] int The Pod ID
4644
- * $params['pod'] string The Pod name
4645
- * $params['id'] int The Field ID
4646
- * $params['name'] string The Field name
4647
- * $params['new_name'] string The new Field name
4648
- *
4649
- * @param array $params An associative array of parameters
4650
- * @param bool $strict (optional) Makes sure a field exists, if it doesn't throws an error
4651
- *
4652
- * @return int New Field ID
4653
- * @since 2.3.10
4654
- */
4655
- public function duplicate_field( $params, $strict = false ) {
4656
-
4657
- if ( ! is_object( $params ) && ! is_array( $params ) ) {
4658
- if ( is_numeric( $params ) ) {
4659
- $params = array( 'id' => $params );
4660
- } else {
4661
- $params = array( 'name' => $params );
4662
- }
4663
- }
4664
-
4665
- $params = (object) pods_sanitize( $params );
4666
-
4667
- $params->table_info = false;
4668
-
4669
- $field = $this->load_field( $params, $strict );
4670
-
4671
- if ( empty( $field ) ) {
4672
- if ( false !== $strict ) {
4673
- return pods_error( __( 'Field not found', 'pods' ), $this );
4674
- }
4675
-
4676
- return false;
4677
- }
4678
-
4679
- unset( $field['id'] );
4680
-
4681
- if ( isset( $params->new_name ) ) {
4682
- $field['name'] = $params->new_name;
4683
- }
4684
-
4685
- $try = 1;
4686
-
4687
- $check_name = $field['name'];
4688
- $new_label = $field['label'];
4689
-
4690
- while ( $this->load_field( array(
4691
- 'pod_id' => $field['pod_id'],
4692
- 'name' => $check_name,
4693
- 'table_info' => false
4694
- ), false ) ) {
4695
- $try ++;
4696
-
4697
- $check_name = $field['name'] . $try;
4698
- $new_label = $field['label'] . $try;
4699
- }
4700
-
4701
- $field['name'] = $check_name;
4702
- $field['label'] = $new_label;
4703
-
4704
- return $this->save_field( $field );
4705
-
4706
- }
4707
-
4708
- /**
4709
- * @see PodsAPI::save_pod_item
4710
- *
4711
- * Duplicate a pod item
4712
- *
4713
- * $params['pod'] string The Pod name
4714
- * $params['id'] int The item's ID from the wp_pods_* table
4715
- *
4716
- * @param array $params An associative array of parameters
4717
- *
4718
- * @return int The table row ID
4719
- *
4720
- * @since 1.12
4721
- */
4722
- public function duplicate_pod_item( $params ) {
4723
-
4724
- $params = (object) pods_sanitize( $params );
4725
-
4726
- $load_pod_params = array(
4727
- 'name' => $params->pod,
4728
- 'table_info' => false,
4729
- );
4730
-
4731
- $pod = $this->load_pod( $load_pod_params );
4732
-
4733
- if ( false === $pod ) {
4734
- return pods_error( __( 'Pod not found', 'pods' ), $this );
4735
- }
4736
-
4737
- $pod = pods( $params->pod, $params->id );
4738
-
4739
- $params->pod = $pod->pod;
4740
- $params->pod_id = $pod->pod_id;
4741
-
4742
- $fields = (array) pods_var_raw( 'fields', $pod->pod_data, array(), null, true );
4743
- $object_fields = (array) pods_var_raw( 'object_fields', $pod->pod_data, array(), null, true );
4744
-
4745
- if ( ! empty( $object_fields ) ) {
4746
- $fields = array_merge( $object_fields, $fields );
4747
- }
4748
-
4749
- $save_params = array(
4750
- 'pod' => $params->pod,
4751
- 'data' => array(),
4752
- 'is_new_item' => true,
4753
- );
4754
-
4755
- $ignore_fields = array(
4756
- $pod->pod_data['field_id'],
4757
- $pod->pod_data['field_slug'],
4758
- );
4759
-
4760
- if ( in_array( $pod->pod_data['type'], array( 'post_type', 'media' ) ) ) {
4761
- $ignore_fields = array(
4762
- 'ID',
4763
- 'post_name',
4764
- 'post_date',
4765
- 'post_date_gmt',
4766
- 'post_modified',
4767
- 'post_modified_gmt',
4768
- 'guid',
4769
- );
4770
- } elseif ( 'term' === $pod->pod_data['type'] ) {
4771
- $ignore_fields = array(
4772
- 'term_id',
4773
- 'term_taxonomy_id',
4774
- 'slug',
4775
- );
4776
- } elseif ( 'user' === $pod->pod_data['type'] ) {
4777
- $ignore_fields = array(
4778
- 'ID',
4779
- 'user_nicename',
4780
- );
4781
- } elseif ( 'comment' === $pod->pod_data['type'] ) {
4782
- $ignore_fields = array(
4783
- 'comment_ID',
4784
- );
4785
- } elseif ( 'settings' === $pod->pod_data['type'] ) {
4786
- return pods_error( __( 'Settings do not support duplication.', 'pods' ), $this );
4787
- }
4788
-
4789
- /**
4790
- * Filter the fields to ignore during duplication
4791
- *
4792
- * @since 2.6.6
4793
- *
4794
- * @param array $ignore_fields Fields to ignore and not save during duplication
4795
- * @param Pods $pod Pod object
4796
- * @param array $fields Fields on the pod to duplicate
4797
- * @param object $params Params passed into duplicate_pod_item()
4798
- */
4799
- $ignore_fields = apply_filters( 'pods_api_duplicate_pod_item_ignore_fields', $ignore_fields, $pod, $fields, $params );
4800
-
4801
- foreach ( $fields as $field ) {
4802
- if ( in_array( $field['name'], $ignore_fields ) ) {
4803
- continue;
4804
- }
4805
-
4806
- $field = array(
4807
- 'name' => $field['name'],
4808
- 'output' => 'ids'
4809
- );
4810
-
4811
- $value = $pod->field( $field );
4812
-
4813
- // @todo Add post type compatibility to set unique post_title
4814
- // @todo Add term compatibility to set unique name
4815
- // @todo Add user compatibility to set unique user_login/user_email
4816
-
4817
- if ( ! empty( $value ) || ( ! is_array( $value ) && 0 < strlen( $value ) ) ) {
4818
- $save_params['data'][ $field['name'] ] = $value;
4819
- }
4820
- }
4821
-
4822
- $save_params = $this->do_hook( 'duplicate_pod_item', $save_params, $pod->pod, $pod->id(), $params );
4823
-
4824
- $id = $this->save_pod_item( $save_params );
4825
-
4826
- return $id;
4827
-
4828
- }
4829
-
4830
- /**
4831
- * @see pods()
4832
- *
4833
- * Export a pod item
4834
- *
4835
- * $params['pod'] string The Pod name
4836
- * $params['id'] int The item's ID from the wp_pods_* table
4837
- * $params['fields'] array The fields to export
4838
- * $params['depth'] int How many levels deep to export data
4839
- *
4840
- * @param array $params An associative array of parameters
4841
- * @param object $pod (optional) Pods object
4842
- *
4843
- * @return int The table row ID
4844
- * @since 1.12
4845
- */
4846
- public function export_pod_item( $params, $pod = null ) {
4847
-
4848
- if ( ! is_object( $pod ) || 'Pods' !== get_class( $pod ) ) {
4849
- if ( empty( $params ) ) {
4850
- return false;
4851
- }
4852
-
4853
- if ( is_object( $params ) ) {
4854
- $params = get_object_vars( (object) $params );
4855
- }
4856
-
4857
- $params = pods_sanitize( $params );
4858
-
4859
- $pod = pods( $params['pod'], $params['id'], false );
4860
-
4861
- if ( empty( $pod ) ) {
4862
- return false;
4863
- }
4864
- }
4865
-
4866
- $params['fields'] = (array) pods_v( 'fields', $params, array(), true );
4867
- $params['depth'] = (int) pods_v( 'depth', $params, 2, true );
4868
- $params['object_fields'] = (array) pods_v( 'object_fields', $pod->pod_data, array(), true );
4869
- $params['flatten'] = (boolean) pods_v( 'flatten', $params, false, true );
4870
- $params['context'] = pods_v( 'context', $params, null, true );
4871
-
4872
- if ( empty( $params['fields'] ) ) {
4873
- $params['fields'] = array_merge( $pod->fields, $params['object_fields'] );
4874
- }
4875
-
4876
- $data = $this->export_pod_item_level( $pod, $params );
4877
-
4878
- $data = $this->do_hook( 'export_pod_item', $data, $pod->pod, $pod->id(), $pod, $params['fields'], $params['depth'], $params['flatten'], $params );
4879
-
4880
- return $data;
4881
- }
4882
-
4883
- /**
4884
- * Export a pod item by depth level
4885
- *
4886
- * @param Pods $pod Pods object
4887
- * @param array $params Export params
4888
- *
4889
- * @return array Data array
4890
- *
4891
- * @since 2.3.0
4892
- */
4893
- private function export_pod_item_level( $pod, $params ) {
4894
-
4895
- $fields = $params['fields'];
4896
- $depth = $params['depth'];
4897
- $flatten = $params['flatten'];
4898
- $current_depth = pods_v( 'current_depth', $params, 1, true );
4899
- $context = $params['context'];
4900
-
4901
- $tableless_field_types = PodsForm::tableless_field_types();
4902
- $simple_tableless_objects = PodsForm::simple_tableless_objects();
4903
-
4904
- $object_fields = (array) pods_v( 'object_fields', $pod->pod_data, array(), true );
4905
-
4906
- $export_fields = array();
4907
-
4908
- $pod_type = $pod->pod_data['type'];
4909
-
4910
- if ( 'post_type' === $pod_type ) {
4911
- $pod_type = 'post';
4912
- } elseif ( 'taxonomy' === $pod_type ) {
4913
- $pod_type = 'term';
4914
- }
4915
-
4916
- $registered_meta_keys = false;
4917
-
4918
- if ( function_exists( 'get_registered_meta_keys' ) ) {
4919
- $registered_meta_keys = get_registered_meta_keys( $pod_type );
4920
- }
4921
-
4922
- $show_in_rest = false;
4923
-
4924
- // If in rest, check if this pod can be exposed
4925
- if ( 'rest' === $context ) {
4926
- $read_all = (int) pods_v( 'read_all', $pod->pod_data['options'], 0 );
4927
-
4928
- if ( 1 === $read_all ) {
4929
- $show_in_rest = true;
4930
- }
4931
- }
4932
-
4933
- foreach ( $fields as $k => $field ) {
4934
- if ( ! is_array( $field ) ) {
4935
- $field = array(
4936
- 'id' => 0,
4937
- 'name' => $field
4938
- );
4939
- }
4940
-
4941
- if ( isset( $pod->fields[ $field['name'] ] ) ) {
4942
- // If in rest, check if this field can be exposed
4943
- if ( 'rest' === $context && false === $show_in_rest ) {
4944
- $show_in_rest = PodsRESTFields::field_allowed_to_extend( $field['name'], $pod, 'read' );
4945
-
4946
- if ( false === $show_in_rest ) {
4947
- // Fallback to checking $registered_meta_keys
4948
- if ( false !== $registered_meta_keys ) {
4949
- if ( ! isset( $registered_meta_keys[ $field['name'] ] ) ) {
4950
- continue;
4951
- } elseif ( empty( $registered_meta_keys[ $field['name'] ]['show_in_rest'] ) ) {
4952
- continue;
4953
- }
4954
- }
4955
- }
4956
- }
4957
-
4958
- $field = $pod->fields[ $field['name'] ];
4959
- $field['lookup_name'] = $field['name'];
4960
-
4961
- if ( in_array( $field['type'], $tableless_field_types, true ) && ! in_array( pods_v( 'pick_object', $field ), $simple_tableless_objects, true ) ) {
4962
- if ( 'pick' === $field['type'] ) {
4963
- if ( empty( $field['table_info'] ) ) {
4964
- $field['table_info'] = $this->get_table_info( pods_v( 'pick_object', $field ), pods_v( 'pick_val', $field ), null, null, $field );
4965
- }
4966
-
4967
- if ( ! empty( $field['table_info'] ) && 'table' !== $field['table_info']['object_type'] ) {
4968
- $field['lookup_name'] .= '.' . $field['table_info']['field_id'];
4969
- }
4970
- } elseif ( in_array( $field['type'], PodsForm::file_field_types() ) ) {
4971
- $field['lookup_name'] .= '.guid';
4972
- }
4973
- }
4974
-
4975
- $export_fields[ $field['name'] ] = $field;
4976
- } elseif ( isset( $object_fields[ $field['name'] ] ) ) {
4977
- $field = $object_fields[ $field['name'] ];
4978
- $field['lookup_name'] = $field['name'];
4979
-
4980
- $export_fields[ $field['name'] ] = $field;
4981
- } elseif ( $field['name'] == $pod->pod_data['field_id'] ) {
4982
- $field['type'] = 'number';
4983
- $field['lookup_name'] = $field['name'];
4984
-
4985
- $export_fields[ $field['name'] ] = $field;
4986
- }
4987
- }
4988
-
4989
- $data = array();
4990
-
4991
- foreach ( $export_fields as $field ) {
4992
- // Return IDs (or guid for files) if only one level deep
4993
- if ( 1 == $depth ) {
4994
- $data[ $field['name'] ] = $pod->field( array( 'name' => $field['lookup_name'], 'output' => 'arrays' ) );
4995
- } elseif ( ( - 1 == $depth || $current_depth < $depth ) && 'pick' === $field['type'] && ! in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) {
4996
- // Recurse depth levels for pick fields if $depth allows
4997
- $related_data = array();
4998
-
4999
- $related_ids = $pod->field( array( 'name' => $field['name'], 'output' => 'ids' ) );
5000
-
5001
- if ( ! empty( $related_ids ) ) {
5002
- $related_ids = (array) $related_ids;
5003
-
5004
- $pick_object = pods_var_raw( 'pick_object', $field );
5005
-
5006
- $related_pod = pods( pods_var_raw( 'pick_val', $field ), null, false );
5007
-
5008
- // If this isn't a Pod, return data exactly as Pods does normally
5009
- if ( empty( $related_pod ) || ( 'pod' !== $pick_object && $pick_object !== $related_pod->pod_data['type'] ) || $related_pod->pod == $pod->pod ) {
5010
- $related_data = $pod->field( array( 'name' => $field['name'], 'output' => 'arrays' ) );
5011
- } else {
5012
- $related_object_fields = (array) pods_var_raw( 'object_fields', $related_pod->pod_data, array(), null, true );
5013
-
5014
- $related_fields = array_merge( $related_pod->fields, $related_object_fields );
5015
-
5016
- foreach ( $related_ids as $related_id ) {
5017
- if ( $related_pod->fetch( $related_id ) ) {
5018
- $related_params = array(
5019
- 'fields' => $related_fields,
5020
- 'depth' => $depth,
5021
- 'flatten' => $flatten,
5022
- 'current_depth' => $current_depth + 1,
5023
- 'context' => $context,
5024
- );
5025
-
5026
- $related_item = $this->export_pod_item_level( $related_pod, $related_params );
5027
-
5028
- $related_item_data = $this->do_hook( 'export_pod_item_level', $related_item, $related_pod->pod, $related_pod->id(), $related_pod, $related_fields, $depth, $flatten, ( $current_depth + 1 ), $params );
5029
-
5030
- if ( function_exists( 'wp_is_json_request' ) && wp_is_json_request() ) {
5031
- // Don't pass IDs as keys for REST API context to ensure arrays of data are returned.
5032
- $related_data[] = $related_item_data;
5033
- } else {
5034
- $related_data[ $related_id ] = $related_item_data;
5035
- }
5036
- }
5037
- }
5038
-
5039
- if ( $flatten && ! empty( $related_data ) ) {
5040
- $related_data = pods_serial_comma( array_values( $related_data ), array(
5041
- 'and' => '',
5042
- 'field_index' => $related_pod->pod_data['field_index']
5043
- ) );
5044
- }
5045
- }
5046
- }
5047
-
5048
- $data[ $field['name'] ] = $related_data;
5049
- } else {
5050
- // Return data exactly as Pods does normally
5051
- $data[ $field['name'] ] = $pod->field( array( 'name' => $field['name'], 'output' => 'arrays' ) );
5052
- }
5053
-
5054
- if ( $flatten && is_array( $data[ $field['name'] ] ) ) {
5055
- $data[ $field['name'] ] = pods_serial_comma( $data[ $field['name'] ], array(
5056
- 'field' => $field['name'],
5057
- 'fields' => $export_fields,
5058
- 'and' => ''
5059
- ) );
5060
- }
5061
- }
5062
-
5063
- $data['id'] = (int) $pod->id();
5064
-
5065
- return $data;
5066
- }
5067
-
5068
- /**
5069
- * Reorder a Pod
5070
- *
5071
- * $params['pod'] string The Pod name
5072
- * $params['field'] string The field name of the field to reorder
5073
- * $params['order'] array The key => value array of items to reorder (key should be an integer)
5074
- *
5075
- * @param array $params An associative array of parameters
5076
- *
5077
- * @return bool
5078
- *
5079
- * @since 1.9.0
5080
- */
5081
- public function reorder_pod_item( $params ) {
5082
-
5083
- $params = (object) pods_sanitize( $params );
5084
-
5085
- // @deprecated 2.0.0
5086
- if ( isset( $params->datatype ) ) {
5087
- pods_deprecated( __( '$params->pod instead of $params->datatype', 'pods' ), '2.0' );
5088
-
5089
- $params->pod = $params->datatype;
5090
-
5091
- unset( $params->datatype );
5092
- }
5093
-
5094
- if ( null === pods_var_raw( 'pod', $params, null, null, true ) ) {
5095
- return pods_error( __( '$params->pod is required', 'pods' ), $this );
5096
- }
5097
-
5098
- if ( ! is_array( $params->order ) ) {
5099
- $params->order = explode( ',', $params->order );
5100
- }
5101
-
5102
- $pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => true ) );
5103
-
5104
- $params->name = $pod['name'];
5105
-
5106
- if ( false === $pod ) {
5107
- return pods_error( __( 'Pod is required', 'pods' ), $this );
5108
- }
5109
-
5110
- foreach ( $params->order as $order => $id ) {
5111
- if ( isset( $pod['fields'][ $params->field ] ) || isset( $pod['object_fields'][ $params->field ] ) ) {
5112
- if ( 'table' === $pod['storage'] && ( ! pods_tableless() ) ) {
5113
- if ( isset( $pod['fields'][ $params->field ] ) ) {
5114
- pods_query( "UPDATE `@wp_pods_{$params->name}` SET `{$params->field}` = " . pods_absint( $order ) . " WHERE `id` = " . pods_absint( $id ) . " LIMIT 1" );
5115
- } else {
5116
- pods_query( "UPDATE `{$pod['table']}` SET `{$params->field}` = " . pods_absint( $order ) . " WHERE `{$pod['field_id']}` = " . pods_absint( $id ) . " LIMIT 1" );
5117
- }
5118
- } else {
5119
- $this->save_pod_item( array(
5120
- 'pod' => $params->pod,
5121
- 'pod_id' => $params->pod_id,
5122
- 'id' => $id,
5123
- 'data' => array( $params->field => pods_absint( $order ) )
5124
- ) );
5125
- }
5126
- }
5127
- }
5128
-
5129
- return true;
5130
- }
5131
-
5132
- /**
5133
- *
5134
- * Delete all content for a Pod
5135
- *
5136
- * $params['id'] int The Pod ID
5137
- * $params['name'] string The Pod name
5138
- *
5139
- * @param array $params An associative array of parameters
5140
- * @param array $pod Pod data
5141
- *
5142
- * @return bool
5143
- *
5144
- * @uses pods_query
5145
- * @uses pods_cache_clear
5146
- *
5147
- * @since 1.9.0
5148
- */
5149
- public function reset_pod( $params, $pod = false ) {
5150
-
5151
- $params = (object) pods_sanitize( $params );
5152
-
5153
- $params->table_info = true;
5154
-
5155
- if ( empty( $pod ) ) {
5156
- $pod = $this->load_pod( $params );
5157
- }
5158
-
5159
- if ( false === $pod ) {
5160
- return pods_error( __( 'Pod not found', 'pods' ), $this );
5161
- }
5162
-
5163
- $params->id = $pod['id'];
5164
- $params->name = $pod['name'];
5165
-
5166
- if ( ! pods_tableless() ) {
5167
- if ( 'table' === $pod['storage'] ) {
5168
- try {
5169
- pods_query( "TRUNCATE `@wp_pods_{$params->name}`", false );
5170
- } catch ( Exception $e ) {
5171
- // Allow pod to be reset if the table doesn't exist
5172
- if ( false === strpos( $e->getMessage(), 'Unknown table' ) ) {
5173
- return pods_error( $e->getMessage(), $this );
5174
- }
5175
- }
5176
- }
5177
-
5178
- pods_query( "DELETE FROM `@wp_podsrel` WHERE `pod_id` = {$params->id} OR `related_pod_id` = {$params->id}", false );
5179
- }
5180
-
5181
- // @todo Delete relationships from tableless relationships
5182
-
5183
- // Delete all posts/revisions from this post type
5184
- if ( in_array( $pod['type'], array( 'post_type', 'media' ) ) ) {
5185
- $type = pods_var( 'object', $pod, $pod['name'], null, true );
5186
-
5187
- $sql = "
5188
- DELETE `t`, `r`, `m`
5189
- FROM `{$pod['table']}` AS `t`
5190
- LEFT JOIN `{$pod['meta_table']}` AS `m`
5191
- ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
5192
- LEFT JOIN `{$pod['table']}` AS `r`
5193
- ON `r`.`post_parent` = `t`.`{$pod['field_id']}` AND `r`.`post_status` = 'inherit'
5194
- WHERE `t`.`{$pod['field_type']}` = '{$type}'
5195
- ";
5196
-
5197
- pods_query( $sql, false );
5198
- } elseif ( 'taxonomy' === $pod['type'] ) {
5199
- // Delete all terms from this taxonomy
5200
- if ( function_exists( 'get_term_meta' ) ) {
5201
- $sql = "
5202
- DELETE `t`, `m`, `tt`, `tr`
5203
- FROM `{$pod['table']}` AS `t`
5204
- LEFT JOIN `{$pod['meta_table']}` AS `m`
5205
- ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
5206
- " . $pod['join']['tt'] . "
5207
- " . $pod['join']['tr'] . "
5208
- WHERE " . implode( ' AND ', $pod['where'] ) . "
5209
- ";
5210
- } else {
5211
- $sql = "
5212
- DELETE `t`, `tt`, `tr`
5213
- FROM `{$pod['table']}` AS `t`
5214
- " . $pod['join']['tt'] . "
5215
- " . $pod['join']['tr'] . "
5216
- WHERE " . implode( ' AND ', $pod['where'] ) . "
5217
- ";
5218
- }
5219
-
5220
- pods_query( $sql, false );
5221
- } elseif ( 'user' === $pod['type'] ) {
5222
- // Delete all users except the current one
5223
- $sql = "
5224
- DELETE `t`, `m`
5225
- FROM `{$pod['table']}` AS `t`
5226
- LEFT JOIN `{$pod['meta_table']}` AS `m`
5227
- ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
5228
- WHERE `t`.`{$pod['field_id']}` != " . (int) get_current_user_id() . "
5229
- ";
5230
-
5231
- pods_query( $sql, false );
5232
- } elseif ( 'comment' === $pod['type'] ) {
5233
- // Delete all comments
5234
- $type = pods_var( 'object', $pod, $pod['name'], null, true );
5235
-
5236
- $sql = "
5237
- DELETE `t`, `m`
5238
- FROM `{$pod['table']}` AS `t`
5239
- LEFT JOIN `{$pod['meta_table']}` AS `m`
5240
- ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
5241
- WHERE `t`.`{$pod['field_type']}` = '{$type}'
5242
- ";
5243
-
5244
- pods_query( $sql, false );
5245
- }
5246
-
5247
- pods_cache_clear( true ); // only way to reliably clear out cached data across an entire group
5248
-
5249
- return true;
5250
- }
5251
-
5252
- /**
5253
- * Delete a Pod and all its content
5254
- *
5255
- * $params['id'] int The Pod ID
5256
- * $params['name'] string The Pod name
5257
- *
5258
- * @param array $params An associative array of parameters
5259
- * @param bool $strict (optional) Makes sure a pod exists, if it doesn't throws an error
5260
- * @param bool $delete_all (optional) Whether to delete all content from a WP object
5261
- *
5262
- * @uses PodsAPI::load_pod
5263
- * @uses wp_delete_post
5264
- * @uses pods_query
5265
- *
5266
- * @return bool
5267
- * @since 1.7.9
5268
- */
5269
- public function delete_pod( $params, $strict = false, $delete_all = false ) {
5270
-
5271
- /**
5272
- * @var $wpdb wpdb
5273
- */
5274
- global $wpdb;
5275
-
5276
- if ( ! is_object( $params ) && ! is_array( $params ) ) {
5277
- if ( is_numeric( $params ) ) {
5278
- $params = array( 'id' => $params );
5279
- } else {
5280
- $params = array( 'name' => $params );
5281
- }
5282
-
5283
- $params = (object) pods_sanitize( $params );
5284
- } else {
5285
- $params = (object) pods_sanitize( $params );
5286
- }
5287
-
5288
- if ( ! isset( $params->delete_all ) ) {
5289
- $params->delete_all = $delete_all;
5290
- }
5291
-
5292
- $params->table_info = false;
5293
-
5294
- $pod = $this->load_pod( $params, $strict );
5295
-
5296
- if ( empty( $pod ) ) {
5297
- if ( false !== $strict ) {
5298
- return pods_error( __( 'Pod not found', 'pods' ), $this );
5299
- }
5300
-
5301
- return false;
5302
- }
5303
-
5304
- $params->id = (int) $pod['id'];
5305
- $params->name = $pod['name'];
5306
-
5307
- // Reset content
5308
- if ( true === $params->delete_all ) {
5309
- $this->reset_pod( $params, $pod );
5310
- }
5311
-
5312
- foreach ( $pod['fields'] as $field ) {
5313
- $field['pod'] = $pod;
5314
-
5315
- $this->delete_field( $field, false );
5316
- }
5317
-
5318
- // Only delete the post once the fields are taken care of, it's not required anymore
5319
- $success = wp_delete_post( $params->id );
5320
-
5321
- if ( ! $success ) {
5322
- return pods_error( __( 'Pod unable to be deleted', 'pods' ), $this );
5323
- }
5324
-
5325
- if ( ! pods_tableless() ) {
5326
- if ( 'table' === $pod['storage'] ) {
5327
- try {
5328
- pods_query( "DROP TABLE IF EXISTS `@wp_pods_{$params->name}`", false );
5329
- } catch ( Exception $e ) {
5330
- // Allow pod to be deleted if the table doesn't exist
5331
- if ( false === strpos( $e->getMessage(), 'Unknown table' ) ) {
5332
- return pods_error( $e->getMessage(), $this );
5333
- }
5334
- }
5335
- }
5336
-
5337
- pods_query( "DELETE FROM `@wp_podsrel` WHERE `pod_id` = {$params->id} OR `related_pod_id` = {$params->id}", false );
5338
- }
5339
-
5340
- // @todo Delete relationships from tableless relationships
5341
-
5342
- // Delete any relationship references
5343
- $sql = "
5344
- DELETE `pm`
5345
- FROM `{$wpdb->postmeta}` AS `pm`
5346
- LEFT JOIN `{$wpdb->posts}` AS `p`
5347
- ON `p`.`post_type` = '_pods_field'
5348
- AND `p`.`ID` = `pm`.`post_id`
5349
- LEFT JOIN `{$wpdb->postmeta}` AS `pm2`
5350
- ON `pm2`.`meta_key` = 'pick_object'
5351
- AND `pm2`.`meta_value` = 'pod'
5352
- AND `pm2`.`post_id` = `pm`.`post_id`
5353
- WHERE
5354
- `p`.`ID` IS NOT NULL
5355
- AND `pm2`.`meta_id` IS NOT NULL
5356
- AND `pm`.`meta_key` = 'pick_val'
5357
- AND `pm`.`meta_value` = '{$params->name}'
5358
- ";
5359
-
5360
- pods_query( $sql );
5361
-
5362
- $this->cache_flush_pods( $pod );
5363
-
5364
- return true;
5365
- }
5366
-
5367
- /**
5368
- * Drop a field within a Pod
5369
- *
5370
- * $params['id'] int The field ID
5371
- * $params['name'] int The field name
5372
- * $params['pod'] string The Pod name
5373
- * $params['pod_id'] string The Pod name
5374
- *
5375
- * @param array $params An associative array of parameters
5376
- * @param bool $table_operation Whether or not to handle table operations
5377
- *
5378
- * @uses PodsAPI::load_field
5379
- * @uses wp_delete_post
5380
- * @uses pods_query
5381
- *
5382
- * @return bool
5383
- * @since 1.7.9
5384
- */
5385
- public function delete_field( $params, $table_operation = true ) {
5386
-
5387
- /**
5388
- * @var $wpdb wpdb
5389
- */
5390
- global $wpdb;
5391
-
5392
- $tableless_field_types = PodsForm::tableless_field_types();
5393
- $simple_tableless_objects = PodsForm::simple_tableless_objects();
5394
-
5395
- $params = (object) pods_sanitize( $params );
5396
-
5397
- if ( ! isset( $params->pod ) ) {
5398
- $params->pod = '';
5399
- }
5400
-
5401
- if ( ! isset( $params->pod_id ) ) {
5402
- $params->pod_id = 0;
5403
- }
5404
-
5405
- $pod = $params->pod;
5406
-
5407
- $save_pod = false;
5408
-
5409
- if ( ! is_array( $pod ) ) {
5410
- $pod = $this->load_pod( array( 'name' => $pod, 'id' => $params->pod_id, 'table_info' => false ) );
5411
- } else {
5412
- $save_pod = true;
5413
- }
5414
-
5415
- if ( empty( $pod ) ) {
5416
- return pods_error( __( 'Pod not found', 'pods' ), $this );
5417
- }
5418
-
5419
- $params->pod_id = $pod['id'];
5420
- $params->pod = $pod['name'];
5421
-
5422
- if ( ! isset( $params->name ) ) {
5423
- $params->name = '';
5424
- }
5425
-
5426
- if ( ! isset( $params->id ) ) {
5427
- $params->id = 0;
5428
- }
5429
-
5430
- $field = $this->load_field( array(
5431
- 'name' => $params->name,
5432
- 'id' => $params->id,
5433
- 'pod' => $params->pod,
5434
- 'pod_id' => $params->pod_id
5435
- ) );
5436
-
5437
- if ( false === $field ) {
5438
- return pods_error( __( 'Field not found', 'pods' ), $this );
5439
- }
5440
-
5441
- $params->id = $field['id'];
5442
- $params->name = $field['name'];
5443
-
5444
- $simple = ( 'pick' === $field['type'] && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) );
5445
- $simple = (boolean) $this->do_hook( 'tableless_custom', $simple, $field, $pod, $params );
5446
-
5447
- if ( $table_operation && 'table' === $pod['storage'] && ( ! in_array( $field['type'], $tableless_field_types ) || $simple ) ) {
5448
- pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` DROP COLUMN `{$params->name}`", false );
5449
- }
5450
-
5451
- $success = wp_delete_post( $params->id );
5452
-
5453
- if ( ! $success ) {
5454
- return pods_error( __( 'Field unable to be deleted', 'pods' ), $this );
5455
- }
5456
-
5457
- $wpdb->query( $wpdb->prepare( "DELETE pm FROM {$wpdb->postmeta} AS pm
5458
- LEFT JOIN {$wpdb->posts} AS p
5459
- ON p.post_type = '_pods_field' AND p.ID = pm.post_id
5460
- WHERE p.ID IS NOT NULL AND pm.meta_key = 'sister_id' AND pm.meta_value = %d", $params->id ) );
5461
-
5462
- if ( ( ! pods_tableless() ) && $table_operation ) {
5463
- pods_query( "DELETE FROM `@wp_podsrel` WHERE (`pod_id` = {$params->pod_id} AND `field_id` = {$params->id}) OR (`related_pod_id` = {$params->pod_id} AND `related_field_id` = {$params->id})", false );
5464
- }
5465
-
5466
- // @todo Delete tableless relationship meta
5467
-
5468
- if ( true === $save_pod ) {
5469
- $this->cache_flush_pods( $pod );
5470
- }
5471
-
5472
- return true;
5473
- }
5474
-
5475
- /**
5476
- * Drop a Pod Object
5477
- *
5478
- * $params['id'] int The object ID
5479
- * $params['name'] string The object name
5480
- * $params['type'] string The object type
5481
- *
5482
- * @param array|object $params An associative array of parameters
5483
- *
5484
- * @uses wp_delete_post
5485
- *
5486
- * @return bool
5487
- * @since 2.0.0
5488
- */
5489
- public function delete_object( $params ) {
5490
-
5491
- $params = (object) $params;
5492
- $object = $this->load_object( $params );
5493
-
5494
- if ( empty( $object ) ) {
5495
- return pods_error( sprintf( __( "%s Object not found", 'pods' ), ucwords( $params->type ) ), $this );
5496
- }
5497
-
5498
- $success = wp_delete_post( $params->id );
5499
-
5500
- if ( ! $success ) {
5501
- return pods_error( sprintf( __( "%s Object not deleted", 'pods' ), ucwords( $params->type ) ), $this );
5502
- }
5503
-
5504
- pods_transient_clear( 'pods_objects_' . $params->type );
5505
-
5506
- return true;
5507
- }
5508
-
5509
- /**
5510
- * @see PodsAPI::delete_object
5511
- *
5512
- * Drop a Pod Template
5513
- *
5514
- * $params['id'] int The template ID
5515
- * $params['name'] string The template name
5516
- *
5517
- * @param array $params An associative array of parameters
5518
- *
5519
- * @return bool
5520
- * @since 1.7.9
5521
- */
5522
- public function delete_template( $params ) {
5523
-
5524
- $params = (object) $params;
5525
- $params->type = 'template';
5526
-
5527
- return $this->delete_object( $params );
5528
- }
5529
-
5530
- /**
5531
- * @see PodsAPI::delete_object
5532
- *
5533
- * Drop a Pod Page
5534
- *
5535
- * $params['id'] int The page ID
5536
- * $params['uri'] string The page URI
5537
- *
5538
- * @param array $params An associative array of parameters
5539
- *
5540
- * @return bool
5541
- * @since 1.7.9
5542
- */
5543
- public function delete_page( $params ) {
5544
-
5545
- $params = (object) $params;
5546
- if ( isset( $params->uri ) ) {
5547
- $params->name = $params->uri;
5548
- unset( $params->uri );
5549
- }
5550
- if ( isset( $params->name ) ) {
5551
- $params->name = trim( $params->name, '/' );
5552
- }
5553
- $params->type = 'page';
5554
-
5555
- return $this->delete_object( $params );
5556
- }
5557
-
5558
- /**
5559
- * @see PodsAPI::delete_object
5560
- *
5561
- * Drop a Pod Helper
5562
- *
5563
- * $params['id'] int The helper ID
5564
- * $params['name'] string The helper name
5565
- *
5566
- * @param array $params An associative array of parameters
5567
- *
5568
- * @return bool
5569
- * @since 1.7.9
5570
- */
5571
- public function delete_helper( $params ) {
5572
-
5573
- $params = (object) $params;
5574
- $params->type = 'helper';
5575
-
5576
- return $this->delete_object( $params );
5577
- }
5578
-
5579
- /**
5580
- * Drop a single pod item
5581
- *
5582
- * $params['id'] int (optional) The item's ID from the wp_pod_* table (used with datatype parameter)
5583
- * $params['pod'] string (optional) The Pod name (used with id parameter)
5584
- * $params['pod_id'] int (optional) The Pod ID (used with id parameter)
5585
- * $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
5586
- *
5587
- * @param array $params An associative array of parameters
5588
- * @param bool $wp Whether to run WP object delete action
5589
- *
5590
- * @return bool
5591
- * @since 1.7.9
5592
- */
5593
- public function delete_pod_item( $params, $wp = true ) {
5594
-
5595
- $params = (object) pods_sanitize( $params );
5596
-
5597
- // @deprecated 2.0.0
5598
- if ( isset( $params->datatype_id ) || isset( $params->datatype ) || isset( $params->tbl_row_id ) ) {
5599
- if ( isset( $params->tbl_row_id ) ) {
5600
- pods_deprecated( __( '$params->id instead of $params->tbl_row_id', 'pods' ), '2.0' );
5601
- $params->id = $params->tbl_row_id;
5602
- unset( $params->tbl_row_id );
5603
- }
5604
-
5605
- if ( isset( $params->pod_id ) ) {
5606
- pods_deprecated( __( '$params->id instead of $params->pod_id', 'pods' ), '2.0' );
5607
- $params->id = $params->pod_id;
5608
- unset( $params->pod_id );
5609
- }
5610
-
5611
- if ( isset( $params->dataype_id ) ) {
5612
- pods_deprecated( __( '$params->pod_id instead of $params->datatype_id', 'pods' ), '2.0' );
5613
- $params->pod_id = $params->dataype_id;
5614
- unset( $params->dataype_id );
5615
- }
5616
-
5617
- if ( isset( $params->datatype ) ) {
5618
- pods_deprecated( __( '$params->pod instead of $params->datatype', 'pods' ), '2.0' );
5619
- $params->pod = $params->datatype;
5620
- unset( $params->datatype );
5621
- }
5622
- }
5623
-
5624
- if ( ! isset( $params->id ) ) {
5625
- return pods_error( __( 'Pod Item not found', 'pods' ), $this );
5626
- }
5627
-
5628
- $params->id = pods_absint( $params->id );
5629
-
5630
- if ( ! isset( $params->pod ) ) {
5631
- $params->pod = '';
5632
- }
5633
-
5634
- if ( ! isset( $params->pod_id ) ) {
5635
- $params->pod_id = 0;
5636
- }
5637
-
5638
- $pod = $this->load_pod( array( 'name' => $params->pod, 'id' => $params->pod_id, 'table_info' => false ) );
5639
-
5640
- if ( false === $pod ) {
5641
- return pods_error( __( 'Pod not found', 'pods' ), $this );
5642
- }
5643
-
5644
- $params->pod_id = $pod['id'];
5645
- $params->pod = $pod['name'];
5646
-
5647
- // Allow Helpers to bypass subsequent helpers in recursive delete_pod_item calls
5648
- $bypass_helpers = false;
5649
-
5650
- if ( isset( $params->bypass_helpers ) && false !== $params->bypass_helpers ) {
5651
- $bypass_helpers = true;
5652
- }
5653
-
5654
- $pre_delete_helpers = array();
5655
- $post_delete_helpers = array();
5656
-
5657
- if ( false === $bypass_helpers ) {
5658
- // Plugin hook
5659
- $this->do_hook( 'pre_delete_pod_item', $params, $pod );
5660
- $this->do_hook( "pre_delete_pod_item_{$params->pod}", $params, $pod );
5661
-
5662
- // Call any pre-save helpers (if not bypassed)
5663
- if ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) {
5664
- if ( ! empty( $pod['options'] ) && is_array( $pod['options'] ) ) {
5665
- $helpers = array( 'pre_delete_helpers', 'post_delete_helpers' );
5666
-
5667
- foreach ( $helpers as $helper ) {
5668
- if ( isset( $pod['options'][ $helper ] ) && ! empty( $pod['options'][ $helper ] ) ) {
5669
- ${$helper} = explode( ',', $pod['options'][ $helper ] );
5670
- }
5671
- }
5672
- }
5673
-
5674
- if ( ! empty( $pre_delete_helpers ) ) {
5675
- pods_deprecated( sprintf( __( 'Pre-delete helpers are deprecated, use the action pods_pre_delete_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
5676
-
5677
- foreach ( $pre_delete_helpers as $helper ) {
5678
- $helper = $this->load_helper( array( 'name' => $helper ) );
5679
-
5680
- if ( false !== $helper ) {
5681
- eval( '?>' . $helper['code'] );
5682
- }
5683
- }
5684
- }
5685
- }
5686
- }
5687
-
5688
- // Delete object from relationship fields
5689
- $this->delete_object_from_relationships( $params->id, $pod );
5690
-
5691
- if ( 'table' === $pod['storage'] ) {
5692
- pods_query( "DELETE FROM `@wp_pods_{$params->pod}` WHERE `id` = {$params->id} LIMIT 1" );
5693
- }
5694
-
5695
- if ( $wp ) {
5696
- if ( 'taxonomy' === $pod['type'] ) {
5697
- $taxonomy = $pod['name'];
5698
-
5699
- if ( ! empty( $pod['object'] ) ) {
5700
- $taxonomy = $pod['object'];
5701
- }
5702
-
5703
- wp_delete_term( $params->id, $taxonomy );
5704
- } elseif ( ! in_array( $pod['type'], array( 'pod', 'table', '', 'taxonomy' ) ) ) {
5705
- $this->delete_wp_object( $pod['type'], $params->id );
5706
- }
5707
- }
5708
-
5709
- if ( false === $bypass_helpers ) {
5710
- // Plugin hook
5711
- $this->do_hook( 'post_delete_pod_item', $params, $pod );
5712
- $this->do_hook( "post_delete_pod_item_{$params->pod}", $params, $pod );
5713
-
5714
- // Call any post-save helpers (if not bypassed)
5715
- if ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) {
5716
- if ( ! empty( $post_delete_helpers ) ) {
5717
- pods_deprecated( sprintf( __( 'Post-delete helpers are deprecated, use the action pods_post_delete_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
5718
-
5719
- foreach ( $post_delete_helpers as $helper ) {
5720
- $helper = $this->load_helper( array( 'name' => $helper ) );
5721
-
5722
- if ( false !== $helper ) {
5723
- eval( '?>' . $helper['code'] );
5724
- }
5725
- }
5726
- }
5727
- }
5728
- }
5729
-
5730
- pods_cache_clear( $params->id, 'pods_items_' . $params->pod );
5731
-
5732
- return true;
5733
- }
5734
-
5735
- /**
5736
- * Delete an object from tableless fields
5737
- *
5738
- * @param int $id
5739
- * @param string $type
5740
- * @param string $name
5741
- *
5742
- * @return bool
5743
- *
5744
- * @since 2.3.0
5745
- */
5746
- public function delete_object_from_relationships( $id, $object, $name = null ) {
5747
-
5748
- /**
5749
- * @var $pods_init \PodsInit
5750
- * @todo Use pods_init() function?
5751
- */
5752
- global $pods_init;
5753
-
5754
- $pod = false;
5755
-
5756
- // Run any bidirectional delete operations
5757
- if ( is_array( $object ) ) {
5758
- $pod = $object;
5759
- } elseif ( is_object( $pods_init ) ) {
5760
- $pod = PodsInit::$meta->get_object( $object, $name );
5761
- }
5762
-
5763
- if ( ! empty( $pod ) ) {
5764
- $object = $pod['type'];
5765
- $name = $pod['name'];
5766
-
5767
- foreach ( $pod['fields'] as $field ) {
5768
- PodsForm::delete( $field['type'], $id, $field['name'], array_merge( $field, $field['options'] ), $pod );
5769
- }
5770
- }
5771
-
5772
- // Lookup related fields (non-bidirectional)
5773
- $params = array(
5774
- 'where' => array(
5775
- array(
5776
- 'key' => 'type',
5777
- 'value' => 'pick'
5778
- ),
5779
- array(
5780
- 'key' => 'pick_object',
5781
- 'value' => $object
5782
- )
5783
- )
5784
- );
5785
-
5786
- if ( ! empty( $name ) && $name !== $object ) {
5787
- $params['where'][] = array(
5788
- 'key' => 'pick_val',
5789
- 'value' => $name
5790
- );
5791
- }
5792
-
5793
- $fields = $this->load_fields( $params, false );
5794
-
5795
- if ( ! empty( $pod ) && 'media' === $pod['type'] ) {
5796
- $params['where'] = array(
5797
- array(
5798
- 'key' => 'type',
5799
- 'value' => 'file'
5800
- )
5801
- );
5802
-
5803
- $fields = array_merge( $fields, $this->load_fields( $params, false ) );
5804
- }
5805
-
5806
- if ( is_array( $fields ) && ! empty( $fields ) ) {
5807
- foreach ( $fields as $related_field ) {
5808
- $related_pod = $this->load_pod( array( 'id' => $related_field['pod_id'], 'fields' => false ), false );
5809
-
5810
- if ( empty( $related_pod ) ) {
5811
- continue;
5812
- }
5813
-
5814
- $related_from = $this->lookup_related_items_from( $related_field['id'], $related_pod['id'], $id, $related_field, $related_pod );
5815
-
5816
- $this->delete_relationships( $related_from, $id, $related_pod, $related_field );
5817
- }
5818
- }
5819
-
5820
- if ( ! empty( $pod ) && ! pods_tableless() ) {
5821
- pods_query( "
5822
- DELETE FROM `@wp_podsrel`
5823
- WHERE
5824
- (
5825
- `pod_id` = %d
5826
- AND `item_id` = %d
5827
- )
5828
- OR (
5829
- `related_pod_id` = %d
5830
- AND `related_item_id` = %d
5831
- )
5832
- ", array(
5833
- $pod['id'],
5834
- $id,
5835
-
5836
- $pod['id'],
5837
- $id
5838
- ) );
5839
- }
5840
-
5841
- return true;
5842
- }
5843
-
5844
- /**
5845
- * Delete relationships
5846
- *
5847
- * @param int|array $related_id IDs for items to save
5848
- * @param int|array $id ID or IDs to remove
5849
- * @param array $related_pod Pod data
5850
- * @param array $related_field Field data
5851
- *
5852
- * @return void
5853
- *
5854
- * @since 2.3.0
5855
- */
5856
- public function delete_relationships( $related_id, $id, $related_pod, $related_field ) {
5857
-
5858
- if ( is_array( $related_id ) ) {
5859
- foreach ( $related_id as $rid ) {
5860
- $this->delete_relationships( $rid, $id, $related_pod, $related_field );
5861
- }
5862
-
5863
- return;
5864
- }
5865
-
5866
- if ( is_array( $id ) ) {
5867
- foreach ( $id as $rid ) {
5868
- $this->delete_relationships( $related_id, $rid, $related_pod, $related_field );
5869
- }
5870
-
5871
- return;
5872
- }
5873
-
5874
- $id = (int) $id;
5875
-
5876
- if ( empty( $id ) ) {
5877
- return;
5878
- }
5879
-
5880
- $related_ids = $this->lookup_related_items( $related_field['id'], $related_pod['id'], $related_id, $related_field, $related_pod );
5881
-
5882
- if ( empty( $related_ids ) ) {
5883
- return;
5884
- } elseif ( ! in_array( $id, $related_ids ) ) {
5885
- return;
5886
- }
5887
-
5888
- if ( isset( self::$related_item_cache[ $related_pod['id'] ][ $related_field['id'] ] ) ) {
5889
- // Delete relationship from cache
5890
- unset( self::$related_item_cache[ $related_pod['id'] ][ $related_field['id'] ] );
5891
- }
5892
-
5893
- // @codingStandardsIgnoreLine
5894
- unset( $related_ids[ array_search( $id, $related_ids ) ] );
5895
-
5896
- $no_conflict = pods_no_conflict_check( $related_pod['type'] );
5897
-
5898
- if ( ! $no_conflict ) {
5899
- pods_no_conflict_on( $related_pod['type'] );
5900
- }
5901
-
5902
- // Post Types, Media, Users, and Comments (meta-based)
5903
- if ( in_array( $related_pod['type'], array( 'post_type', 'media', 'taxonomy', 'user', 'comment' ) ) ) {
5904
- $object_type = $related_pod['type'];
5905
-
5906
- if ( in_array( $object_type, array( 'post_type', 'media' ) ) ) {
5907
- $object_type = 'post';
5908
- } elseif ( 'taxonomy' === $object_type ) {
5909
- $object_type = 'term';
5910
- }
5911
-
5912
- delete_metadata( $object_type, $related_id, $related_field['name'] );
5913
-
5914
- if ( ! empty( $related_ids ) ) {
5915
- update_metadata( $object_type, $related_id, '_pods_' . $related_field['name'], $related_ids );
5916
-
5917
- foreach ( $related_ids as $rel_id ) {
5918
- add_metadata( $object_type, $related_id, $related_field['name'], $rel_id );
5919
- }
5920
- } else {
5921
- delete_metadata( $object_type, $related_id, '_pods_' . $related_field['name'] );
5922
- }
5923
- } elseif ( 'settings' === $related_pod['type'] ) {
5924
- // Custom Settings Pages (options-based)
5925
- if ( ! empty( $related_ids ) ) {
5926
- update_option( $related_pod['name'] . '_' . $related_field['name'], $related_ids );
5927
- } else {
5928
- delete_option( $related_pod['name'] . '_' . $related_field['name'] );
5929
- }
5930
- }
5931
-
5932
- // Relationships table
5933
- if ( ! pods_tableless() ) {
5934
- pods_query( "
5935
- DELETE FROM `@wp_podsrel`
5936
- WHERE
5937
- (
5938
- `pod_id` = %d
5939
- AND `field_id` = %d
5940
- AND `item_id` = %d
5941
- AND `related_item_id` = %d
5942
- )
5943
- OR (
5944
- `related_pod_id` = %d
5945
- AND `related_field_id` = %d
5946
- AND `related_item_id` = %d
5947
- AND `item_id` = %d
5948
- )
5949
- ", array(
5950
- $related_pod['id'],
5951
- $related_field['id'],
5952
- $related_id,
5953
- $id,
5954
-
5955
- $related_pod['id'],
5956
- $related_field['id'],
5957
- $related_id,
5958
- $id
5959
- ) );
5960
- }
5961
-
5962
- if ( ! $no_conflict ) {
5963
- pods_no_conflict_off( $related_pod['type'] );
5964
- }
5965
- }
5966
-
5967
- /**
5968
- * Check if a Pod exists
5969
- *
5970
- * $params['id'] int Pod ID
5971
- * $params['name'] string Pod name
5972
- *
5973
- * @param array $params An associative array of parameters
5974
- *
5975
- * @return bool True if exists
5976
- *
5977
- * @since 1.12
5978
- */
5979
- public function pod_exists( $params, $type = null ) {
5980
-
5981
- if ( is_string( $params ) ) {
5982
- $params = array( 'name' => $params );
5983
- }
5984
-
5985
- $params = (object) pods_sanitize( $params );
5986
-
5987
- if ( ! empty( $params->id ) || ! empty( $params->name ) ) {
5988
- if ( ! isset( $params->name ) ) {
5989
- $dummy = (int) $params->id;
5990
- $pod = get_post( $dummy );
5991
- } else {
5992
- $pod = get_posts( array(
5993
- 'name' => $params->name,
5994
- 'post_type' => '_pods_pod',
5995
- 'posts_per_page' => 1
5996
- ) );
5997
-
5998
- if ( is_array( $pod ) && ! empty( $pod[0] ) ) {
5999
- $pod = $pod[0];
6000
- }
6001
- }
6002
-
6003
- if ( ! empty( $pod ) && ( empty( $type ) || $type == get_post_meta( $pod->ID, 'type', true ) ) ) {
6004
- return true;
6005
- }
6006
- }
6007
-
6008
- return false;
6009
- }
6010
-
6011
- /**
6012
- * Get number of pods for a specific pod type
6013
- *
6014
- * @param string $type Type to get count
6015
- *
6016
- * @return int Total number of pods for a type
6017
- *
6018
- * @since 2.6.6
6019
- */
6020
- public function get_pod_type_count( $type ) {
6021
-
6022
- $args = array(
6023
- 'post_type' => '_pods_pod',
6024
- 'posts_per_page' => - 1,
6025
- 'nopaging' => true,
6026
- 'fields' => 'ids',
6027
- 'meta_query' => array(
6028
- array(
6029
- 'key' => 'type',
6030
- 'value' => $type,
6031
- ),
6032
- ),
6033
- );
6034
-
6035
- $posts = get_posts( $args );
6036
-
6037
- $total = count( $posts );
6038
-
6039
- return $total;
6040
-
6041
- }
6042
-
6043
- /**
6044
- * Load a Pod and all of its fields
6045
- *
6046
- * $params['id'] int The Pod ID
6047
- * $params['name'] string The Pod name
6048
- * $params['fields'] bool Whether to load fields (default is true)
6049
- * $params['bypass_cache'] boolean Bypass the cache when getting data
6050
- *
6051
- * @param array|object $params An associative array of parameters or pod name as a string
6052
- * @param bool $strict Makes sure the pod exists, throws an error if it doesn't work
6053
- *
6054
- * @return array|bool|mixed|void
6055
- * @since 1.7.9
6056
- */
6057
- public function load_pod( $params, $strict = true ) {
6058
-
6059
- /**
6060
- * @var $sitepress SitePress
6061
- * @var $wpdb wpdb
6062
- */
6063
- global $wpdb;
6064
-
6065
- $current_language = false;
6066
- $load_fields = true;
6067
- $bypass_cache = false;
6068
-
6069
- // Get current language data
6070
- $lang_data = pods_i18n()->get_current_language_data();
6071
-
6072
- if ( $lang_data ) {
6073
- if ( ! empty( $lang_data['language'] ) ) {
6074
- $current_language = $lang_data['language'];
6075
- }
6076
- }
6077
-
6078
- if ( ! is_array( $params ) && ! is_object( $params ) ) {
6079
- $params = array( 'name' => $params, 'table_info' => false, 'fields' => true );
6080
- }
6081
-
6082
- if ( is_object( $params ) && ! is_a( $params, 'WP_Post' ) && isset( $params->fields ) && ! $params->fields ) {
6083
- $load_fields = false;
6084
- } elseif ( is_array( $params ) && isset( $params['fields'] ) && ! $params['fields'] ) {
6085
- $load_fields = false;
6086
- }
6087
-
6088
- $table_info = false;
6089
-
6090
- if ( is_object( $params ) && ! is_a( $params, 'WP_Post' ) && ! empty( $params->table_info ) ) {
6091
- $table_info = true;
6092
- } elseif ( is_array( $params ) && ! empty( $params['table_info'] ) ) {
6093
- $table_info = true;
6094
- }
6095
-
6096
- $transient = 'pods_' . $wpdb->prefix . '_pod';
6097
-
6098
- if ( ! empty( $current_language ) ) {
6099
- $transient .= '_' . $current_language;
6100
- }
6101
-
6102
- if ( ! $load_fields ) {
6103
- $transient .= '_nofields';
6104
- }
6105
-
6106
- if ( $table_info ) {
6107
- $transient .= '_tableinfo';
6108
- }
6109
-
6110
- $check_pod = $params;
6111
-
6112
- if ( is_object( $params ) && ! is_a( $params, 'WP_Post' ) && ! empty( $params->pod ) ) {
6113
- $check_pod = $params->pod;
6114
- } elseif ( is_array( $params ) && ! empty( $params['pod'] ) ) {
6115
- $check_pod = $params['pod'];
6116
- }
6117
-
6118
- if ( is_object( $check_pod ) && ( is_a( $check_pod, 'WP_Post' ) || isset( $check_pod->post_name ) ) ) {
6119
- $pod = false;
6120
-
6121
- if ( pods_api_cache() ) {
6122
- $pod = pods_transient_get( $transient . '_' . $check_pod->post_name );
6123
- }
6124
-
6125
- if ( false !== $pod && ( ! $table_info || isset( $pod['table'] ) ) ) {
6126
- // @todo Is this needed anymore for WPML?
6127
- if ( in_array( $pod['type'], array(
6128
- 'post_type',
6129
- 'taxonomy'
6130
- ) ) && did_action( 'wpml_loaded' ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
6131
- $pod = array_merge( $pod, $this->get_table_info( $pod['type'], $pod['object'], $pod['name'], $pod ) );
6132
- }
6133
-
6134
- return $pod;
6135
- }
6136
-
6137
- $_pod = get_object_vars( $check_pod );
6138
- } else {
6139
- $params = (object) pods_sanitize( $params );
6140
-
6141
- if ( ( ! isset( $params->id ) || empty( $params->id ) ) && ( ! isset( $params->name ) || empty( $params->name ) ) ) {
6142
- if ( $strict ) {
6143
- return pods_error( __( 'Either Pod ID or Name are required', 'pods' ), $this );
6144
- }
6145
-
6146
- return false;
6147
- }
6148
-
6149
- if ( ! empty( $params->bypass_cache ) ) {
6150
- $bypass_cache = true;
6151
- }
6152
-
6153
- if ( isset( $params->name ) ) {
6154
- $pod = false;
6155
-
6156
- if ( '_pods_pod' === $params->name ) {
6157
- $pod = array(
6158
- 'id' => 0,
6159
- 'name' => $params->name,
6160
- 'object' => $params->name,
6161
- 'label' => __( 'Pods', 'pods' ),
6162
- 'type' => 'post_type',
6163
- 'storage' => 'meta',
6164
- 'options' => array(
6165
- 'label_singular' => __( 'Pod', 'pods' )
6166
- ),
6167
- 'fields' => array()
6168
- );
6169
- } elseif ( '_pods_field' === $params->name ) {
6170
- $pod = array(
6171
- 'id' => 0,
6172
- 'name' => $params->name,
6173
- 'object' => $params->name,
6174
- 'label' => __( 'Pod Fields', 'pods' ),
6175
- 'type' => 'post_type',
6176
- 'storage' => 'meta',
6177
- 'options' => array(
6178
- 'label_singular' => __( 'Pod Field', 'pods' )
6179
- ),
6180
- 'fields' => array()
6181
- );
6182
- } elseif ( ! $bypass_cache & pods_api_cache() ) {
6183
- $pod = pods_transient_get( $transient . '_' . $params->name );
6184
- }
6185
-
6186
- if ( false !== $pod && ( ! $table_info || isset( $pod['table'] ) ) ) {
6187
- if ( in_array( $pod['type'], array(
6188
- 'post_type',
6189
- 'taxonomy'
6190
- ) ) && did_action( 'wpml_loaded' ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
6191
- $pod = array_merge( $pod, $this->get_table_info( $pod['type'], $pod['object'], $pod['name'], $pod ) );
6192
- }
6193
-
6194
- return $pod;
6195
- }
6196
- }
6197
-
6198
- if ( ! isset( $params->name ) ) {
6199
- $dummy = (int) $params->id;
6200
- $pod = get_post( $dummy );
6201
- } else {
6202
- $pod = get_posts( array(
6203
- 'name' => $params->name,
6204
- 'post_type' => '_pods_pod',
6205
- 'posts_per_page' => 1
6206
- ) );
6207
- }
6208
-
6209
- if ( empty( $pod ) ) {
6210
- if ( $strict ) {
6211
- return pods_error( __( 'Pod not found', 'pods' ), $this );
6212
- }
6213
-
6214
- return false;
6215
- }
6216
-
6217
- if ( is_array( $pod ) && ! empty( $pod[0] ) ) {
6218
- $pod = $pod[0];
6219
- }
6220
-
6221
- $_pod = get_object_vars( $pod );
6222
- }
6223
-
6224
- $pod = false;
6225
-
6226
- if ( ! $bypass_cache || pods_api_cache() ) {
6227
- $pod = pods_transient_get( $transient . '_' . $_pod['post_name'] );
6228
- }
6229
-
6230
- if ( false !== $pod && ( ! $table_info || isset( $pod['table'] ) ) ) {
6231
- if ( in_array( $pod['type'], array(
6232
- 'post_type',
6233
- 'taxonomy'
6234
- ) ) && did_action( 'wpml_loaded' ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
6235
- $pod = array_merge( $pod, $this->get_table_info( $pod['type'], $pod['object'], $pod['name'], $pod ) );
6236
- }
6237
-
6238
- return $pod;
6239
- }
6240
-
6241
- $pod = array(
6242
- 'id' => $_pod['ID'],
6243
- 'name' => $_pod['post_name'],
6244
- 'label' => $_pod['post_title'],
6245
- 'description' => $_pod['post_content']
6246
- );
6247
-
6248
- if ( strlen( $pod['label'] ) < 1 ) {
6249
- $pod['label'] = $pod['name'];
6250
- }
6251
-
6252
- // @todo update with a method to put all options in
6253
- $defaults = array(
6254
- 'show_in_menu' => 1,
6255
- 'type' => 'post_type',
6256
- 'storage' => 'meta',
6257
- 'object' => '',
6258
- 'alias' => ''
6259
- );
6260
-
6261
- if ( $bypass_cache ) {
6262
- wp_cache_delete( $pod['id'], 'post_meta' );
6263
-
6264
- update_postmeta_cache( array( $pod['id'] ) );
6265
- }
6266
-
6267
- $pod['options'] = get_post_meta( $pod['id'] );
6268
-
6269
- foreach ( $pod['options'] as $option => $value ) {
6270
- if ( is_array( $value ) ) {
6271
- foreach ( $value as $k => $v ) {
6272
- if ( ! is_array( $v ) ) {
6273
- $value[ $k ] = maybe_unserialize( $v );
6274
- }
6275
- }
6276
-
6277
- if ( 1 == count( $value ) ) {
6278
- $value = current( $value );
6279
- }
6280
- } else {
6281
- $value = maybe_unserialize( $value );
6282
- }
6283
-
6284
- $pod['options'][ $option ] = $value;
6285
- }
6286
-
6287
- $pod['options'] = array_merge( $defaults, $pod['options'] );
6288
-
6289
- $pod['type'] = $pod['options']['type'];
6290
- $pod['storage'] = $pod['options']['storage'];
6291
- $pod['object'] = $pod['options']['object'];
6292
- $pod['alias'] = $pod['options']['alias'];
6293
-
6294
- unset( $pod['options']['type'] );
6295
- unset( $pod['options']['storage'] );
6296
- unset( $pod['options']['object'] );
6297
- unset( $pod['options']['alias'] );
6298
-
6299
- if ( $table_info ) {
6300
- $pod = array_merge( $this->get_table_info( $pod['type'], $pod['object'], $pod['name'], $pod ), $pod );
6301
- }
6302
-
6303
- // Override old 'none' storage type
6304
- if ( 'taxonomy' === $pod['type'] && 'none' === $pod['storage'] && function_exists( 'get_term_meta' ) ) {
6305
- $pod['storage'] = 'meta';
6306
- }
6307
-
6308
- if ( isset( $pod['pod'] ) ) {
6309
- unset( $pod['pod'] );
6310
- }
6311
-
6312
- $pod['fields'] = array();
6313
-
6314
- $pod['object_fields'] = array();
6315
-
6316
- if ( 'pod' !== $pod['type'] ) {
6317
- $pod['object_fields'] = $this->get_wp_object_fields( $pod['type'], $pod );
6318
- }
6319
-
6320
- $fields = get_posts( array(
6321
- 'post_type' => '_pods_field',
6322
- 'posts_per_page' => - 1,
6323
- 'nopaging' => true,
6324
- 'post_parent' => $pod['id'],
6325
- 'orderby' => 'menu_order',
6326
- 'order' => 'ASC'
6327
- ) );
6328
-
6329
- if ( ! empty( $fields ) ) {
6330
- foreach ( $fields as $field ) {
6331
- $field->pod = $pod['name'];
6332
- $field->table_info = $table_info;
6333
- $field->bypass_cache = $bypass_cache;
6334
-
6335
- if ( $load_fields ) {
6336
- $field = $this->load_field( $field );
6337
-
6338
- $field = PodsForm::field_setup( $field, null, $field['type'] );
6339
- } else {
6340
- if ( $bypass_cache ) {
6341
- wp_cache_delete( $field->ID, 'post_meta' );
6342
-
6343
- update_postmeta_cache( array( $field->ID ) );
6344
- }
6345
-
6346
- $field = array(
6347
- 'id' => $field->ID,
6348
- 'name' => $field->post_name,
6349
- 'label' => $field->post_title,
6350
- 'type' => get_post_meta( $field->ID, 'type', true )
6351
- );
6352
- }
6353
-
6354
- $pod['fields'][ $field['name'] ] = $field;
6355
- }
6356
- }
6357
-
6358
- if ( did_action( 'init' ) && pods_api_cache() ) {
6359
- pods_transient_set( $transient . '_' . $pod['name'], $pod );
6360
- }
6361
-
6362
- return $pod;
6363
- }
6364
-
6365
- /**
6366
- * Load a list of Pods based on filters specified.
6367
- *
6368
- * $params['type'] string/array Pod Type(s) to filter by
6369
- * $params['object'] string/array Pod Object(s) to filter by
6370
- * $params['options'] array Pod Option(s) key=>value array to filter by
6371
- * $params['orderby'] string ORDER BY clause of query
6372
- * $params['limit'] string Number of Pods to return
6373
- * $params['where'] string WHERE clause of query
6374
- * $params['ids'] string|array IDs of Objects
6375
- * $params['count'] boolean Return only a count of Pods
6376
- * $params['names'] boolean Return only an array of name => label
6377
- * $params['ids'] boolean Return only an array of ID => label
6378
- * $params['fields'] boolean Return pod fields with Pods (default is true)
6379
- * $params['key_names'] boolean Return pods keyed by name
6380
- * $params['bypass_cache'] boolean Bypass the cache when getting data
6381
- *
6382
- * @param array $params An associative array of parameters
6383
- *
6384
- * @return array|mixed
6385
- *
6386
- * @uses PodsAPI::load_pod
6387
- *
6388
- * @since 2.0.0
6389
- */
6390
- public function load_pods( $params = null ) {
6391
-
6392
- $current_language = false;
6393
-
6394
- // Get current language data
6395
- $lang_data = pods_i18n()->get_current_language_data();
6396
-
6397
- if ( $lang_data ) {
6398
- if ( ! empty( $lang_data['language'] ) ) {
6399
- $current_language = $lang_data['language'];
6400
- }
6401
- }
6402
-
6403
- $params = (object) pods_sanitize( $params );
6404
-
6405
- $order = 'ASC';
6406
- $orderby = 'menu_order title';
6407
- $limit = - 1;
6408
- $ids = false;
6409
-
6410
- $meta_query = array();
6411
- $cache_key = '';
6412
-
6413
- $bypass_cache = false;
6414
-
6415
- if ( ! empty( $params->bypass_cache ) ) {
6416
- $bypass_cache = true;
6417
- }
6418
-
6419
- if ( isset( $params->type ) && ! empty( $params->type ) ) {
6420
- if ( ! is_array( $params->type ) ) {
6421
- $params->type = array( trim( $params->type ) );
6422
- }
6423
-
6424
- sort( $params->type );
6425
-
6426
- $meta_query[] = array(
6427
- 'key' => 'type',
6428
- 'value' => $params->type,
6429
- 'compare' => 'IN'
6430
- );
6431
-
6432
- if ( 0 < count( $params->type ) ) {
6433
- $cache_key .= '_type_' . trim( implode( '_', $params->type ) );
6434
- }
6435
- }
6436
-
6437
- if ( isset( $params->object ) && ! empty( $params->object ) ) {
6438
- if ( ! is_array( $params->object ) ) {
6439
- $params->object = array( $params->object );
6440
- }
6441
-
6442
- $params->object = pods_trim( $params->object );
6443
-
6444
- sort( $params->object );
6445
-
6446
- $meta_query[] = array(
6447
- 'key' => 'object',
6448
- 'value' => $params->object,
6449
- 'compare' => 'IN'
6450
- );
6451
-
6452
- if ( 1 == count( $params->object ) ) {
6453
- $cache_key .= '_object_' . trim( implode( '', $params->object ) );
6454
- }
6455
- }
6456
-
6457
- if ( isset( $params->options ) && ! empty( $params->options ) && is_array( $params->options ) ) {
6458
- foreach ( $params->options as $option => $value ) {
6459
- if ( ! is_array( $value ) ) {
6460
- $value = array( $value );
6461
- }
6462
-
6463
- $value = pods_trim( $value );
6464
-
6465
- sort( $value );
6466
-
6467
- $meta_query[] = array(
6468
- 'key' => $option,
6469
- 'value' => pods_sanitize( $value ),
6470
- 'compare' => 'IN'
6471
- );
6472
- }
6473
-
6474
- $cache_key = '';
6475
- }
6476
-
6477
- if ( isset( $params->where ) && is_array( $params->where ) ) {
6478
- $meta_query = array_merge( $meta_query, (array) $params->where );
6479
- }
6480
-
6481
- if ( isset( $params->order ) && ! empty( $params->order ) && in_array( strtoupper( $params->order ), array(
6482
- 'ASC',
6483
- 'DESC'
6484
- ) ) ) {
6485
- $order = strtoupper( $params->order );
6486
- }
6487
-
6488
- if ( isset( $params->orderby ) && ! empty( $params->orderby ) ) {
6489
- $orderby = strtoupper( $params->orderby );
6490
- }
6491
-
6492
- if ( isset( $params->limit ) && ! empty( $params->limit ) ) {
6493
- $limit = pods_absint( $params->limit );
6494
- }
6495
-
6496
- if ( isset( $params->ids ) && ! empty( $params->ids ) ) {
6497
- $ids = $params->ids;
6498
-
6499
- if ( ! is_array( $ids ) ) {
6500
- $ids = explode( ',', $ids );
6501
- }
6502
- }
6503
-
6504
- if ( empty( $ids ) ) {
6505
- $ids = false;
6506
- }
6507
-
6508
- $pre_key = '';
6509
-
6510
- if ( ! empty( $current_language ) ) {
6511
- $pre_key .= '_' . $current_language;
6512
- }
6513
-
6514
- if ( isset( $params->count ) && $params->count ) {
6515
- $pre_key .= '_count';
6516
- }
6517
-
6518
- if ( isset( $params->ids ) && $params->ids && ! empty( $ids ) ) {
6519
- $pre_key .= '_ids_' . implode( '_', $ids );
6520
- }
6521
-
6522
- if ( isset( $params->names ) && $params->names ) {
6523
- $pre_key .= '_names';
6524
- } elseif ( isset( $params->names_ids ) && $params->names_ids ) {
6525
- $pre_key .= '_names_ids';
6526
- }
6527
-
6528
- if ( isset( $params->key_names ) && $params->key_names ) {
6529
- $pre_key .= '_namekeys';
6530
- }
6531
-
6532
- if ( isset( $params->fields ) && ! $params->fields ) {
6533
- $pre_key .= '_nofields';
6534
- }
6535
-
6536
- if ( isset( $params->table_info ) && $params->table_info ) {
6537
- $pre_key .= '_tableinfo';
6538
- }
6539
-
6540
- $pre_key .= '_get';
6541
-
6542
- if ( empty( $cache_key ) ) {
6543
- $cache_key = 'pods' . $pre_key . '_all';
6544
- } else {
6545
- $cache_key = 'pods' . $pre_key . $cache_key;
6546
- }
6547
-
6548
- if ( ! $bypass_cache && pods_api_cache() && ! empty( $cache_key ) && ( 'pods' . ( ! empty( $current_language ) ? '_' . $current_language : '' ) . '_get_all' !== $cache_key || empty( $meta_query ) ) && $limit < 1 && ( empty( $orderby ) || 'menu_order title' === $orderby ) && empty( $ids ) ) {
6549
- $the_pods = pods_transient_get( $cache_key );
6550
-
6551
- if ( false === $the_pods ) {
6552
- $the_pods = pods_cache_get( $cache_key, 'pods' );
6553
- }
6554
-
6555
- if ( ! is_array( $the_pods ) && 'none' === $the_pods ) {
6556
- return array();
6557
- } elseif ( false !== $the_pods ) {
6558
- return $the_pods;
6559
- }
6560
- }
6561
-
6562
- $the_pods = array();
6563
-
6564
- $args = array(
6565
- 'post_type' => '_pods_pod',
6566
- 'nopaging' => true,
6567
- 'posts_per_page' => $limit,
6568
- 'order' => $order,
6569
- 'orderby' => $orderby,
6570
- 'meta_query' => $meta_query,
6571
- );
6572
-
6573
- // Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
6574
- if ( false !== $ids ) {
6575
- $args['post__in'] = $ids;
6576
- }
6577
-
6578
- $_pods = get_posts( $args );
6579
-
6580
- $export_ignore = array(
6581
- 'object_type',
6582
- 'object_name',
6583
- 'table',
6584
- 'meta_table',
6585
- 'pod_table',
6586
- 'field_id',
6587
- 'field_index',
6588
- 'field_slug',
6589
- 'field_type',
6590
- 'field_parent',
6591
- 'field_parent_select',
6592
- 'meta_field_id',
6593
- 'meta_field_index',
6594
- 'meta_field_value',
6595
- 'pod_field_id',
6596
- 'pod_field_index',
6597
- 'object_fields',
6598
- 'join',
6599
- 'where',
6600
- 'where_default',
6601
- 'orderby',
6602
- 'pod',
6603
- 'recurse',
6604
- 'table_info',
6605
- 'attributes',
6606
- 'group',
6607
- 'grouped',
6608
- 'developer_mode',
6609
- 'dependency',
6610
- 'depends-on',
6611
- 'excludes-on'
6612
- );
6613
-
6614
- $total_fields = 0;
6615
-
6616
- if ( isset( $params->count ) && $params->count ) {
6617
- $the_pods = count( $_pods );
6618
- } else {
6619
- foreach ( $_pods as $pod ) {
6620
- if ( isset( $params->names ) && $params->names ) {
6621
- $the_pods[ $pod->post_name ] = $pod->post_title;
6622
- } elseif ( isset( $params->names_ids ) && $params->names_ids ) {
6623
- $the_pods[ $pod->ID ] = $pod->post_name;
6624
- } else {
6625
- if ( isset( $params->fields ) && ! $params->fields ) {
6626
- $pod->fields = false;
6627
- }
6628
-
6629
- $pod = $this->load_pod( array(
6630
- 'pod' => $pod,
6631
- 'table_info' => ! empty( $params->table_info ),
6632
- 'bypass_cache' => $bypass_cache
6633
- ) );
6634
-
6635
- // Remove extra data not needed
6636
- if ( pods_var( 'export', $params, false ) && ( ! isset( $params->fields ) || $params->fields ) ) {
6637
- foreach ( $export_ignore as $ignore ) {
6638
- if ( isset( $pod[ $ignore ] ) ) {
6639
- unset( $pod[ $ignore ] );
6640
- }
6641
- }
6642
-
6643
- foreach ( $pod['fields'] as $field => $field_data ) {
6644
- if ( isset( $pod['fields'][ $field ]['table_info'] ) ) {
6645
- unset( $pod['fields'][ $field ]['table_info'] );
6646
- }
6647
- }
6648
- }
6649
-
6650
- $total_fields += count( $pod['fields'] );
6651
-
6652
- if ( isset( $params->key_names ) && $params->key_names ) {
6653
- $the_pods[ $pod['name'] ] = $pod;
6654
- } else {
6655
- $the_pods[ $pod['id'] ] = $pod;
6656
- }
6657
- }
6658
- }
6659
- }
6660
-
6661
- if ( ( ! function_exists( 'pll_current_language' ) || ! empty( $params->refresh ) ) && ! empty( $cache_key ) && ( 'pods' !== $cache_key || empty( $meta_query ) ) && $limit < 1 && ( empty( $orderby ) || 'menu_order title' === $orderby ) && empty( $ids ) ) {
6662
- $total_pods = (int) ( is_array( $the_pods ) ) ? count( $the_pods ) : $the_pods;
6663
- // Too many Pods can cause issues with the DB when caching is not enabled
6664
- if ( 15 < $total_pods || 75 < (int) $total_fields ) {
6665
- pods_transient_clear( $cache_key );
6666
-
6667
- if ( pods_api_cache() ) {
6668
- if ( empty( $the_pods ) && ( ! isset( $params->count ) || ! $params->count ) ) {
6669
- pods_cache_set( $cache_key, 'none', 'pods' );
6670
- } else {
6671
- pods_cache_set( $cache_key, $the_pods, 'pods' );
6672
- }
6673
- }
6674
- } else {
6675
- pods_cache_clear( $cache_key, 'pods' );
6676
-
6677
- if ( pods_api_cache() ) {
6678
- if ( empty( $the_pods ) && ( ! isset( $params->count ) || ! $params->count ) ) {
6679
- pods_transient_set( $cache_key, 'none' );
6680
- } else {
6681
- pods_transient_set( $cache_key, $the_pods );
6682
- }
6683
- }
6684
- }
6685
- }
6686
-
6687
- return $the_pods;
6688
- }
6689
-
6690
- /**
6691
- * Check if a Pod's field exists
6692
- *
6693
- * $params['pod_id'] int The Pod ID
6694
- * $params['id'] int The field ID
6695
- * $params['name'] string The field name
6696
- *
6697
- * @param array $params An associative array of parameters
6698
- *
6699
- * @return bool
6700
- *
6701
- * @since 1.12
6702
- */
6703
- public function field_exists( $params ) {
6704
-
6705
- $params = (object) pods_sanitize( $params );
6706
-
6707
- if ( ( ! empty( $params->id ) || ! empty( $params->name ) ) && isset( $params->pod_id ) && ! empty( $params->pod_id ) ) {
6708
- if ( ! isset( $params->name ) ) {
6709
- $dummy = (int) $params->id;
6710
- $field = get_post( $dummy );
6711
- } else {
6712
- $field = get_posts( array(
6713
- 'name' => $params->name,
6714
- 'post_type' => '_pods_field',
6715
- 'posts_per_page' => 1,
6716
- 'post_parent' => $params->pod_id
6717
- ) );
6718
- }
6719
-
6720
- if ( ! empty( $field ) ) {
6721
- return true;
6722
- }
6723
- }
6724
-
6725
- return false;
6726
- }
6727
-
6728
- /**
6729
- * Load a field
6730
- *
6731
- * $params['pod_id'] int The Pod ID
6732
- * $params['pod'] string The Pod name
6733
- * $params['id'] int The field ID
6734
- * $params['name'] string The field name
6735
- * $params['table_info'] boolean Whether to lookup a pick field's table info
6736
- * $params['bypass_cache'] boolean Bypass the cache when getting data
6737
- *
6738
- * @param array $params An associative array of parameters
6739
- * @param boolean $strict Whether to require a field exist or not when loading the info
6740
- *
6741
- * @return array|bool Array with field data, false if field not found
6742
- * @since 1.7.9
6743
- */
6744
- public function load_field( $params, $strict = false ) {
6745
-
6746
- $params = (object) $params;
6747
-
6748
- if ( ! isset( $params->table_info ) ) {
6749
- $params->table_info = false;
6750
- }
6751
-
6752
- $bypass_cache = false;
6753
-
6754
- if ( ! empty( $params->bypass_cache ) ) {
6755
- $bypass_cache = true;
6756
- }
6757
-
6758
- $pod = array();
6759
- $field = array();
6760
-
6761
- if ( isset( $params->post_title ) ) {
6762
- $_field = $params;
6763
- } elseif ( isset( $params->id ) && ! empty( $params->id ) ) {
6764
- $dummy = (int) $params->id;
6765
- $_field = get_post( $dummy );
6766
- } else {
6767
- if ( ! isset( $params->pod ) ) {
6768
- $params->pod = '';
6769
- }
6770
-
6771
- if ( ! isset( $params->pod_id ) ) {
6772
- $params->pod_id = 0;
6773
- }
6774
-
6775
- if ( isset( $params->pod_data ) ) {
6776
- $pod = $params->pod_data;
6777
- } else {
6778
- $pod = $this->load_pod( array(
6779
- 'name' => $params->pod,
6780
- 'id' => $params->pod_id,
6781
- 'table_info' => false,
6782
- 'bypass_cache' => $bypass_cache
6783
- ), false );
6784
-
6785
- if ( false === $pod ) {
6786
- if ( $strict ) {
6787
- return pods_error( __( 'Pod not found', 'pods' ), $this );
6788
- }
6789
-
6790
- return false;
6791
- }
6792
- }
6793
-
6794
- $params->pod_id = $pod['id'];
6795
- $params->pod = $pod['name'];
6796
-
6797
- if ( empty( $params->name ) && empty( $params->pod ) && empty( $params->pod_id ) ) {
6798
- return pods_error( __( 'Either Field Name or Field ID / Pod ID are required', 'pods' ), $this );
6799
- }
6800
-
6801
- $params->name = pods_clean_name( $params->name, true, ( 'meta' === $pod['storage'] ? false : true ) );
6802
-
6803
- if ( isset( $pod['fields'][ $params->name ] ) && isset( $pod['fields'][ $params->name ]['id'] ) ) {
6804
- return $pod['fields'][ $params->name ];
6805
- }
6806
-
6807
- $field = false;
6808
-
6809
- if ( ! $bypass_cache && pods_api_cache() ) {
6810
- $field = pods_transient_get( 'pods_field_' . $params->pod . '_' . $params->name );
6811
- }
6812
-
6813
- if ( empty( $field ) ) {
6814
- $field = get_posts( array(
6815
- 'name' => $params->name,
6816
- 'post_type' => '_pods_field',
6817
- 'posts_per_page' => 1,
6818
- 'post_parent' => $params->pod_id
6819
- ) );
6820
-
6821
- if ( empty( $field ) || empty( $field[0] ) ) {
6822
- if ( $strict ) {
6823
- return pods_error( __( 'Field not found', 'pods' ), $this );
6824
- }
6825
-
6826
- return false;
6827
- }
6828
-
6829
- $_field = $field[0];
6830
-
6831
- $field = array();
6832
- }
6833
- }
6834
-
6835
- if ( empty( $_field ) ) {
6836
- if ( $strict ) {
6837
- return pods_error( __( 'Field not found', 'pods' ), $this );
6838
- }
6839
-
6840
- return false;
6841
- }
6842
-
6843
- $_field = get_object_vars( $_field );
6844
-
6845
- if ( ! isset( $pod['name'] ) && ! isset( $_field['pod'] ) ) {
6846
- if ( 0 < $_field['post_parent'] ) {
6847
- $pod = $this->load_pod( array( 'id' => $_field['post_parent'], 'table_info' => false ), false );
6848
- }
6849
-
6850
- if ( empty( $pod ) ) {
6851
- if ( $strict ) {
6852
- return pods_error( __( 'Pod for field not found', 'pods' ), $this );
6853
- }
6854
-
6855
- return false;
6856
- }
6857
- }
6858
-
6859
- if ( empty( $field ) ) {
6860
- if ( ! $bypass_cache && pods_api_cache() && ( isset( $pod['name'] ) || isset( $_field['pod'] ) ) ) {
6861
- $field = pods_transient_get( 'pods_field_' . pods_var( 'name', $pod, pods_var( 'pod', $_field ), null, true ) . '_' . $_field['post_name'] );
6862
- }
6863
-
6864
- if ( empty( $field ) ) {
6865
- $defaults = array(
6866
- 'type' => 'text'
6867
- );
6868
-
6869
- $field = array(
6870
- 'id' => $_field['ID'],
6871
- 'name' => $_field['post_name'],
6872
- 'label' => $_field['post_title'],
6873
- 'description' => $_field['post_content'],
6874
- 'weight' => $_field['menu_order'],
6875
- 'pod_id' => $_field['post_parent'],
6876
- 'pick_object' => '',
6877
- 'pick_val' => '',
6878
- 'sister_id' => '',
6879
- 'table_info' => array()
6880
- );
6881
-
6882
- if ( isset( $pod['name'] ) ) {
6883
- $field['pod'] = $pod['name'];
6884
- } elseif ( isset( $_field['pod'] ) ) {
6885
- $field['pod'] = $_field['pod'];
6886
- }
6887
-
6888
- if ( $bypass_cache ) {
6889
- wp_cache_delete( $field['id'], 'post_meta' );
6890
-
6891
- update_postmeta_cache( array( $field['id'] ) );
6892
- }
6893
-
6894
- $field['options'] = get_post_meta( $field['id'] );
6895
-
6896
- $options_ignore = array(
6897
- 'method',
6898
- 'table_info',
6899
- 'attributes',
6900
- 'group',
6901
- 'grouped',
6902
- 'developer_mode',
6903
- 'dependency',
6904
- 'depends-on',
6905
- 'excludes-on'
6906
- );
6907
-
6908
- foreach ( $options_ignore as $ignore ) {
6909
- if ( isset( $field['options'][ $ignore ] ) ) {
6910
- unset( $field['options'][ $ignore ] );
6911
- }
6912
- }
6913
-
6914
- foreach ( $field['options'] as $option => $value ) {
6915
- if ( is_array( $value ) ) {
6916
- foreach ( $value as $k => $v ) {
6917
- if ( ! is_array( $v ) ) {
6918
- $value[ $k ] = maybe_unserialize( $v );
6919
- }
6920
- }
6921
-
6922
- if ( 1 == count( $value ) ) {
6923
- $value = current( $value );
6924
- }
6925
- } else {
6926
- $value = maybe_unserialize( $value );
6927
- }
6928
-
6929
- $field['options'][ $option ] = $value;
6930
- }
6931
-
6932
- $field['options'] = array_merge( $defaults, $field['options'] );
6933
-
6934
- $field['type'] = $field['options']['type'];
6935
-
6936
- unset( $field['options']['type'] );
6937
-
6938
- if ( isset( $field['options']['pick_object'] ) ) {
6939
- $field['pick_object'] = $field['options']['pick_object'];
6940
-
6941
- unset( $field['options']['pick_object'] );
6942
- }
6943
-
6944
- if ( isset( $field['options']['pick_val'] ) ) {
6945
- $field['pick_val'] = $field['options']['pick_val'];
6946
-
6947
- unset( $field['options']['pick_val'] );
6948
- }
6949
-
6950
- if ( isset( $field['options']['sister_id'] ) ) {
6951
- $field['sister_id'] = $field['options']['sister_id'];
6952
-
6953
- unset( $field['options']['sister_id'] );
6954
- }
6955
-
6956
- if ( isset( $field['options']['sister_field_id'] ) ) {
6957
- unset( $field['options']['sister_field_id'] );
6958
- }
6959
-
6960
- if ( pods_api_cache() && ( isset( $pod['name'] ) || isset( $_field['pod'] ) ) ) {
6961
- pods_transient_set( 'pods_field_' . pods_var( 'name', $pod, pods_var( 'pod', $_field ), null, true ) . '_' . $field['name'], $field );
6962
- }
6963
- }
6964
- }
6965
-
6966
- $field['table_info'] = array();
6967
-
6968
- if ( 'pick' === $field['type'] && $params->table_info ) {
6969
- $field['table_info'] = $this->get_table_info( $field['pick_object'], $field['pick_val'], null, null, $field );
6970
- }
6971
-
6972
- return $field;
6973
- }
6974
-
6975
- /**
6976
- * Load fields by Pod, ID, Name, and/or Type
6977
- *
6978
- * $params['pod_id'] int The Pod ID
6979
- * $params['pod'] string The Pod name
6980
- * $params['id'] array The field IDs
6981
- * $params['name'] array The field names
6982
- * $params['type'] array The field types
6983
- * $params['options'] array Field Option(s) key=>value array to filter by
6984
- * $params['where'] string WHERE clause of query
6985
- * $params['object_fields'] bool Whether to include the object fields for WP objects, default true
6986
- *
6987
- * @param array $params An associative array of parameters
6988
- * @param bool $strict Whether to require a field exist or not when loading the info
6989
- *
6990
- * @return array Array of field data.
6991
- *
6992
- * @since 1.7.9
6993
- */
6994
- public function load_fields( $params, $strict = false ) {
6995
-
6996
- // @todo Get away from using md5/serialize, I'm sure we can cache specific parts
6997
- $cache_key = md5( serialize( $params ) );
6998
- if ( isset( $this->fields_cache[ $cache_key ] ) ) {
6999
- return $this->fields_cache[ $cache_key ];
7000
- }
7001
-
7002
- $params = (object) pods_sanitize( $params );
7003
-
7004
- if ( ! isset( $params->pod ) || empty( $params->pod ) ) {
7005
- $params->pod = '';
7006
- }
7007
-
7008
- if ( ! isset( $params->pod_id ) || empty( $params->pod_id ) ) {
7009
- $params->pod_id = 0;
7010
- }
7011
-
7012
- if ( ! isset( $params->name ) || empty( $params->name ) ) {
7013
- $params->name = array();
7014
- } else {
7015
- $params->name = (array) $params->name;
7016
- }
7017
-
7018
- if ( ! isset( $params->id ) || empty( $params->id ) ) {
7019
- $params->id = array();
7020
- } else {
7021
- $params->id = (array) $params->id;
7022
-
7023
- foreach ( $params->id as &$id ) {
7024
- $id = pods_absint( $id );
7025
- }
7026
- }
7027
-
7028
- if ( ! isset( $params->type ) || empty( $params->type ) ) {
7029
- $params->type = array();
7030
- } else {
7031
- $params->type = (array) $params->type;
7032
- }
7033
-
7034
- if ( ! isset( $params->object_fields ) ) {
7035
- $params->object_fields = true;
7036
- } else {
7037
- $params->object_fields = (boolean) $params->object_fields;
7038
- }
7039
-
7040
- $fields = array();
7041
-
7042
- if ( ! empty( $params->pod ) || ! empty( $params->pod_id ) ) {
7043
- $pod = $this->load_pod( array(
7044
- 'name' => $params->pod,
7045
- 'id' => $params->pod_id,
7046
- 'table_info' => true
7047
- ), false );
7048
-
7049
- if ( false === $pod ) {
7050
- if ( $strict ) {
7051
- return pods_error( __( 'Pod not found', 'pods' ), $this );
7052
- }
7053
-
7054
- return $fields;
7055
- }
7056
-
7057
- if ( $params->object_fields && ! empty( $pod['object_fields'] ) ) {
7058
- $pod['fields'] = array_merge( $pod['object_fields'], $pod['fields'] );
7059
- }
7060
-
7061
- foreach ( $pod['fields'] as $field ) {
7062
- if ( empty( $params->name ) && empty( $params->id ) && empty( $params->type ) ) {
7063
- $fields[ $field['name'] ] = $field;
7064
- } elseif ( in_array( $fields['name'], $params->name ) || in_array( $fields['id'], $params->id ) || in_array( $fields['type'], $params->type ) ) {
7065
- $fields[ $field['name'] ] = $field;
7066
- }
7067
- }
7068
- } elseif ( ( isset( $params->options ) && ! empty( $params->options ) && is_array( $params->options ) ) || ( isset( $params->where ) && ! empty( $params->where ) && is_array( $params->where ) ) ) {
7069
- $order = 'ASC';
7070
- $orderby = 'menu_order title';
7071
- $limit = - 1;
7072
- $ids = false;
7073
-
7074
- $meta_query = array();
7075
-
7076
- if ( isset( $params->options ) && ! empty( $params->options ) && is_array( $params->options ) ) {
7077
- foreach ( $params->options as $option => $value ) {
7078
- if ( ! is_array( $value ) ) {
7079
- $value = array( $value );
7080
- }
7081
-
7082
- $value = pods_trim( $value );
7083
-
7084
- sort( $value );
7085
-
7086
- $meta_query[] = array(
7087
- 'key' => $option,
7088
- 'value' => pods_sanitize( $value ),
7089
- 'compare' => 'IN'
7090
- );
7091
- }
7092
- }
7093
-
7094
- if ( isset( $params->where ) && ! empty( $params->where ) && is_array( $params->where ) ) {
7095
- $meta_query = array_merge( $meta_query, (array) $params->where );
7096
- }
7097
-
7098
- $args = array(
7099
- 'post_type' => '_pods_field',
7100
- 'nopaging' => true,
7101
- 'posts_per_page' => $limit,
7102
- 'order' => $order,
7103
- 'orderby' => $orderby,
7104
- 'meta_query' => $meta_query,
7105
- );
7106
-
7107
- // Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
7108
- if ( false !== $ids ) {
7109
- $args['post__in'] = $ids;
7110
- }
7111
-
7112
- $fields = array();
7113
-
7114
- $_fields = get_posts( $args );
7115
-
7116
- foreach ( $_fields as $field ) {
7117
- $field = $this->load_field( $field, false );
7118
-
7119
- if ( ! empty( $field ) ) {
7120
- $fields[ $field['id'] ] = $field;
7121
- }
7122
- }
7123
- } else {
7124
- if ( empty( $params->name ) && empty( $params->id ) && empty( $params->type ) ) {
7125
- return pods_error( __( 'Either Field Name / Field ID / Field Type, or Pod Name / Pod ID are required', 'pods' ), $this );
7126
- }
7127
-
7128
- $lookup = array();
7129
-
7130
- if ( ! empty( $params->name ) ) {
7131
- $fields = implode( "', '", $params->name );
7132
-
7133
- $lookup[] = "`post_name` IN ( '{$fields}' )";
7134
- }
7135
-
7136
- if ( ! empty( $params->id ) ) {
7137
- $fields = implode( ", ", $params->id );
7138
-
7139
- $lookup[] = "`ID` IN ( {$fields} )";
7140
- }
7141
-
7142
- $lookup = implode( ' AND ', $lookup );
7143
-
7144
- $result = pods_query( "SELECT `ID`, `post_name`, `post_parent` FROM `@wp_posts` WHERE `post_type` = '_pods_field' AND ( {$lookup} )" );
7145
-
7146
- $fields = array();
7147
-
7148
- if ( ! empty( $result ) ) {
7149
- foreach ( $result as $field ) {
7150
- $field = $this->load_field( array(
7151
- 'id' => $field->ID,
7152
- 'name' => $field->post_name,
7153
- 'pod_id' => $field->post_parent
7154
- ), false );
7155
-
7156
- if ( ! empty( $field ) && ( empty( $params->type ) || in_array( $field['type'], $params->type ) ) ) {
7157
- $fields[ $field['id'] ] = $field;
7158
- }
7159
- }
7160
- }
7161
- }
7162
- if ( isset( $cache_key ) ) {
7163
- $this->fields_cache[ $cache_key ] = $fields;
7164
- }
7165
-
7166
- return $fields;
7167
- }
7168
-
7169
- /**
7170
- * Load a Pods Object
7171
- *
7172
- * $params['id'] int The Object ID
7173
- * $params['name'] string The Object name
7174
- * $params['type'] string The Object type
7175
- *
7176
- * @param array|object $params An associative array of parameters
7177
- * @param bool $strict
7178
- *
7179
- * @return array|bool
7180
- * @since 2.0.0
7181
- */
7182
- public function load_object( $params, $strict = false ) {
7183
-
7184
- if ( is_object( $params ) && isset( $params->post_title ) ) {
7185
- $_object = get_object_vars( $params );
7186
- } else {
7187
- $params = (object) pods_sanitize( $params );
7188
-
7189
- if ( ! isset( $params->type ) || empty( $params->type ) ) {
7190
- return pods_error( __( 'Object type is required', 'pods' ), $this );
7191
- }
7192
-
7193
- if ( ( ! isset( $params->id ) || empty( $params->id ) ) && ( ! isset( $params->name ) || empty( $params->name ) ) ) {
7194
- return pods_error( __( 'Either Object ID or Name are required', 'pods' ), $this );
7195
- }
7196
-
7197
- /**
7198
- * @var $wpdb wpdb
7199
- */
7200
- global $wpdb;
7201
-
7202
- if ( isset( $params->name ) ) {
7203
- $_object = pods_by_title( $params->name, ARRAY_A, '_pods_' . $params->type, 'publish' );
7204
- } else {
7205
- $object = $params->id;
7206
-
7207
- $_object = get_post( $object, ARRAY_A );
7208
- }
7209
-
7210
- if ( empty( $_object ) ) {
7211
- if ( $strict ) {
7212
- return pods_error( __( 'Object not found', 'pods' ), $this );
7213
- }
7214
-
7215
- return false;
7216
- }
7217
- }
7218
-
7219
- $object = array(
7220
- 'id' => $_object['ID'],
7221
- 'name' => $_object['post_title'],
7222
- 'code' => $_object['post_content'],
7223
- 'type' => str_replace( '_pods_', '', $_object['post_type'] ),
7224
- 'slug' => $_object['post_name']
7225
- );
7226
-
7227
- $object['options'] = get_post_meta( $object['id'] );
7228
-
7229
- foreach ( $object['options'] as $option => &$value ) {
7230
- if ( is_array( $value ) && 1 == count( $value ) ) {
7231
- $value = current( $value );
7232
- }
7233
- }
7234
-
7235
- return $object;
7236
- }
7237
-
7238
- /**
7239
- * Load Multiple Pods Objects
7240
- *
7241
- * $params['type'] string The Object type
7242
- * $params['options'] array Pod Option(s) key=>value array to filter by
7243
- * $params['orderby'] string ORDER BY clause of query
7244
- * $params['limit'] string Number of objects to return
7245
- * $params['where'] string WHERE clause of query
7246
- * $params['ids'] string|array IDs of Objects
7247
- *
7248
- * @param array|object $params An associative array of parameters
7249
- *
7250
- * @return array
7251
- * @since 2.0.0
7252
- */
7253
- public function load_objects( $params ) {
7254
-
7255
- $params = (object) pods_sanitize( $params );
7256
-
7257
- if ( ! isset( $params->type ) || empty( $params->type ) ) {
7258
- return pods_error( __( 'Pods Object type is required', 'pods' ), $this );
7259
- }
7260
-
7261
- $order = 'ASC';
7262
- $orderby = 'menu_order';
7263
- $limit = - 1;
7264
- $ids = false;
7265
-
7266
- $meta_query = array();
7267
- $cache_key = '';
7268
-
7269
- if ( isset( $params->options ) && ! empty( $params->options ) && is_array( $params->options ) ) {
7270
- foreach ( $params->options as $option => $value ) {
7271
- if ( ! is_array( $value ) ) {
7272
- $value = array( $value );
7273
- }
7274
-
7275
- $value = pods_trim( $value );
7276
-
7277
- sort( $value );
7278
-
7279
- $meta_query[] = array(
7280
- 'key' => $option,
7281
- 'value' => pods_sanitize( $value ),
7282
- 'compare' => 'IN'
7283
- );
7284
- }
7285
- }
7286
-
7287
- if ( isset( $params->where ) && is_array( $params->where ) ) {
7288
- $meta_query = array_merge( $meta_query, (array) $params->where );
7289
- }
7290
-
7291
- if ( isset( $params->order ) && ! empty( $params->order ) && in_array( strtoupper( $params->order ), array(
7292
- 'ASC',
7293
- 'DESC'
7294
- ) ) ) {
7295
- $order = strtoupper( $params->order );
7296
- }
7297
-
7298
- if ( isset( $params->orderby ) && ! empty( $params->orderby ) ) {
7299
- $orderby = strtoupper( $params->orderby );
7300
- }
7301
-
7302
- if ( isset( $params->limit ) && ! empty( $params->limit ) ) {
7303
- $limit = pods_absint( $params->limit );
7304
- }
7305
-
7306
- if ( isset( $params->ids ) && ! empty( $params->ids ) ) {
7307
- $ids = $params->ids;
7308
-
7309
- if ( ! is_array( $ids ) ) {
7310
- $ids = explode( ',', $ids );
7311
- }
7312
- }
7313
-
7314
- if ( empty( $ids ) ) {
7315
- $ids = false;
7316
- }
7317
-
7318
- if ( pods_api_cache() && empty( $meta_query ) && empty( $limit ) && ( empty( $orderby ) || 'menu_order' === $orderby ) && empty( $ids ) ) {
7319
- $cache_key = 'pods_objects_' . $params->type;
7320
-
7321
- $the_objects = pods_transient_get( $cache_key );
7322
-
7323
- if ( false !== $the_objects ) {
7324
- return $the_objects;
7325
- }
7326
- }
7327
-
7328
- $the_objects = array();
7329
-
7330
- $args = array(
7331
- 'post_type' => '_pods_' . $params->type,
7332
- 'nopaging' => true,
7333
- 'posts_per_page' => $limit,
7334
- 'order' => $order,
7335
- 'orderby' => $orderby,
7336
- 'meta_query' => $meta_query,
7337
- );
7338
-
7339
- // Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
7340
- if ( false !== $ids ) {
7341
- $args['post__in'] = $ids;
7342
- }
7343
-
7344
- $objects = get_posts( $args );
7345
-
7346
- foreach ( $objects as $object ) {
7347
- $object = $this->load_object( $object );
7348
-
7349
- $the_objects[ $object['name'] ] = $object;
7350
- }
7351
-
7352
- if ( pods_api_cache() && ! empty( $cache_key ) ) {
7353
- pods_transient_set( $cache_key, $the_objects );
7354
- }
7355
-
7356
- return $the_objects;
7357
- }
7358
-
7359
- /**
7360
- * @see PodsAPI::load_object
7361
- *
7362
- * Load a Pod Template
7363
- *
7364
- * $params['id'] int The template ID
7365
- * $params['name'] string The template name
7366
- *
7367
- * @param array $params An associative array of parameters
7368
- *
7369
- * @return array|bool
7370
- * @since 1.7.9
7371
- */
7372
- public function load_template( $params ) {
7373
-
7374
- if ( ! class_exists( 'Pods_Templates' ) ) {
7375
- return false;
7376
- }
7377
-
7378
- $params = (object) $params;
7379
- $params->type = 'template';
7380
-
7381
- return $this->load_object( $params );
7382
- }
7383
-
7384
- /**
7385
- * @see PodsAPI::load_objects
7386
- *
7387
- * Load Multiple Pod Templates
7388
- *
7389
- * $params['where'] string The WHERE clause of query
7390
- * $params['options'] array Pod Option(s) key=>value array to filter by
7391
- * $params['orderby'] string ORDER BY clause of query
7392
- * $params['limit'] string Number of templates to return
7393
- *
7394
- * @param array $params (optional) An associative array of parameters
7395
- *
7396
- * @return array
7397
- *
7398
- * @since 2.0.0
7399
- */
7400
- public function load_templates( $params = null ) {
7401
-
7402
- if ( ! class_exists( 'Pods_Templates' ) ) {
7403
- return array();
7404
- }
7405
-
7406
- $params = (object) $params;
7407
- $params->type = 'template';
7408
-
7409
- return $this->load_objects( $params );
7410
- }
7411
-
7412
- /**
7413
- * @see PodsAPI::load_object
7414
- *
7415
- * Load a Pod Page
7416
- *
7417
- * $params['id'] int The page ID
7418
- * $params['name'] string The page URI
7419
- *
7420
- * @param array $params An associative array of parameters
7421
- *
7422
- * @return array|bool
7423
- *
7424
- * @since 1.7.9
7425
- */
7426
- public function load_page( $params ) {
7427
-
7428
- if ( ! class_exists( 'Pods_Pages' ) ) {
7429
- return false;
7430
- }
7431
-
7432
- $params = (object) $params;
7433
- if ( ! isset( $params->name ) && isset( $params->uri ) ) {
7434
- $params->name = $params->uri;
7435
- unset( $params->uri );
7436
- }
7437
- $params->type = 'page';
7438
-
7439
- return $this->load_object( $params );
7440
- }
7441
-
7442
- /**
7443
- * @see PodsAPI::load_objects
7444
- *
7445
- * Load Multiple Pod Pages
7446
- *
7447
- * $params['where'] string The WHERE clause of query
7448
- * $params['options'] array Pod Option(s) key=>value array to filter by
7449
- * $params['orderby'] string ORDER BY clause of query
7450
- * $params['limit'] string Number of pages to return
7451
- *
7452
- * @param array $params (optional) An associative array of parameters
7453
- *
7454
- * @return array
7455
- *
7456
- * @since 2.0.0
7457
- */
7458
- public function load_pages( $params = null ) {
7459
-
7460
- if ( ! class_exists( 'Pods_Pages' ) ) {
7461
- return array();
7462
- }
7463
-
7464
- $params = (object) $params;
7465
- $params->type = 'page';
7466
-
7467
- return $this->load_objects( $params );
7468
- }
7469
-
7470
- /**
7471
- * @see PodsAPI::load_object
7472
- *
7473
- * Load a Pod Helper
7474
- *
7475
- * $params['id'] int The helper ID
7476
- * $params['name'] string The helper name
7477
- *
7478
- * @param array $params An associative array of parameters
7479
- *
7480
- * @return array|bool
7481
- *
7482
- * @since 1.7.9
7483
- */
7484
- public function load_helper( $params ) {
7485
-
7486
- if ( ! class_exists( 'Pods_Helpers' ) ) {
7487
- return false;
7488
- }
7489
-
7490
- $params = (object) $params;
7491
- $params->type = 'helper';
7492
-
7493
- return $this->load_object( $params );
7494
- }
7495
-
7496
- /**
7497
- * @see PodsAPI::load_objects
7498
- *
7499
- * Load Multiple Pod Helpers
7500
- *
7501
- * $params['where'] string The WHERE clause of query
7502
- * $params['options'] array Pod Option(s) key=>value array to filter by
7503
- * $params['orderby'] string ORDER BY clause of query
7504
- * $params['limit'] string Number of pages to return
7505
- *
7506
- * @param array $params (optional) An associative array of parameters
7507
- *
7508
- * @return array
7509
- *
7510
- * @since 2.0.0
7511
- */
7512
- public function load_helpers( $params = null ) {
7513
-
7514
- if ( ! class_exists( 'Pods_Helpers' ) ) {
7515
- return array();
7516
- }
7517
-
7518
- $params = (object) $params;
7519
- $params->type = 'helper';
7520
-
7521
- return $this->load_objects( $params );
7522
- }
7523
-
7524
- /**
7525
- * Load the pod item object
7526
- *
7527
- * $params['pod'] string The datatype name
7528
- * $params['id'] int (optional) The item's ID
7529
- *
7530
- * @param array $params An associative array of parameters
7531
- *
7532
- * @return bool|\Pods
7533
- *
7534
- * @uses pods()
7535
- *
7536
- * @since 2.0.0
7537
- */
7538
- public function load_pod_item( $params ) {
7539
-
7540
- $params = (object) pods_sanitize( $params );
7541
-
7542
- if ( ! isset( $params->pod ) || empty( $params->pod ) ) {
7543
- return pods_error( __( 'Pod name required', 'pods' ), $this );
7544
- }
7545
- if ( ! isset( $params->id ) || empty( $params->id ) ) {
7546
- return pods_error( __( 'Item ID required', 'pods' ), $this );
7547
- }
7548
-
7549
- $pod = false;
7550
-
7551
- if ( pods_api_cache() ) {
7552
- $pod = pods_cache_get( $params->id, 'pods_item_object_' . $params->pod );
7553
- }
7554
-
7555
- if ( false !== $pod ) {
7556
- return $pod;
7557
- }
7558
-
7559
- $pod = pods( $params->pod, $params->id );
7560
-
7561
- if ( pods_api_cache() ) {
7562
- pods_cache_set( $params->id, $pod, 'pods_item_object_' . $params->pod );
7563
- }
7564
-
7565
- return $pod;
7566
- }
7567
-
7568
- /**
7569
- * Load potential sister fields for a specific field
7570
- *
7571
- * $params['pod'] int The Pod name
7572
- * $params['related_pod'] string The related Pod name
7573
- *
7574
- * @param array $params An associative array of parameters
7575
- * @param array $pod (optional) Array of Pod data to use (to avoid lookup)
7576
- *
7577
- * @return array|bool
7578
- *
7579
- * @since 1.7.9
7580
- *
7581
- * @uses PodsAPI::load_pod
7582
- */
7583
- public function load_sister_fields( $params, $pod = null ) {
7584
-
7585
- $params = (object) pods_sanitize( $params );
7586
-
7587
- if ( empty( $pod ) ) {
7588
- $pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => false ), false );
7589
-
7590
- if ( false === $pod ) {
7591
- return pods_error( __( 'Pod not found', 'pods' ), $this );
7592
- }
7593
- }
7594
-
7595
- $params->pod_id = $pod['id'];
7596
- $params->pod = $pod['name'];
7597
-
7598
- $type = false;
7599
-
7600
- if ( 0 === strpos( $params->related_pod, 'pod-' ) ) {
7601
- $params->related_pod = pods_str_replace( 'pod-', '', $params->related_pod, 1 );
7602
- $type = 'pod';
7603
- } elseif ( 0 === strpos( $params->related_pod, 'post_type-' ) ) {
7604
- $params->related_pod = pods_str_replace( 'post_type-', '', $params->related_pod, 1 );
7605
- $type = 'post_type';
7606
- } elseif ( 0 === strpos( $params->related_pod, 'taxonomy-' ) ) {
7607
- $params->related_pod = pods_str_replace( 'taxonomy-', '', $params->related_pod, 1 );
7608
- $type = 'taxonomy';
7609
- } elseif ( 'comment' === $params->related_pod ) {
7610
- $type = $params->related_pod;
7611
- }
7612
-
7613
- $related_pod = $this->load_pod( array( 'name' => $params->related_pod, 'table_info' => false ), false );
7614
-
7615
- if ( false === $related_pod || ( false !== $type && 'pod' !== $type && $type !== $related_pod['type'] ) ) {
7616
- return pods_error( __( 'Related Pod not found', 'pods' ), $this );
7617
- }
7618
-
7619
- $params->related_pod_id = $related_pod['id'];
7620
- $params->related_pod = $related_pod['name'];
7621
-
7622
- $sister_fields = array();
7623
-
7624
- foreach ( $related_pod['fields'] as $field ) {
7625
- if ( 'pick' === $field['type'] && in_array( $field['pick_object'], array(
7626
- $pod['type'],
7627
- 'pod'
7628
- ) ) && ( $params->pod == $field['pick_object'] || $params->pod == $field['pick_val'] ) ) {
7629
- $sister_fields[ $field['id'] ] = esc_html( $field['label'] . ' (' . $field['name'] . ')' );
7630
- }
7631
- }
7632
-
7633
- return $sister_fields;
7634
- }
7635
-
7636
- /**
7637
- * Takes a sql field such as tinyint and returns the pods field type, such as num.
7638
- *
7639
- * @param string $sql_field The SQL field to look for
7640
- *
7641
- * @return string The field type
7642
- *
7643
- * @since 2.0.0
7644
- */
7645
- public static function detect_pod_field_from_sql_data_type( $sql_field ) {
7646
-
7647
- $sql_field = strtolower( $sql_field );
7648
-
7649
- $field_to_field_map = array(
7650
- 'tinyint' => 'number',
7651
- 'smallint' => 'number',
7652
- 'mediumint' => 'number',
7653
- 'int' => 'number',
7654
- 'bigint' => 'number',
7655
- 'float' => 'number',
7656
- 'double' => 'number',
7657
- 'decimal' => 'number',
7658
- 'date' => 'date',
7659
- 'datetime' => 'datetime',
7660
- 'timestamp' => 'datetime',
7661
- 'time' => 'time',
7662
- 'year' => 'date',
7663
- 'varchar' => 'text',
7664
- 'text' => 'paragraph',
7665
- 'mediumtext' => 'paragraph',
7666
- 'longtext' => 'paragraph'
7667
- );
7668
-
7669
- return ( array_key_exists( $sql_field, $field_to_field_map ) ) ? $field_to_field_map[ $sql_field ] : 'paragraph';
7670
- }
7671
-
7672
- /**
7673
- * Gets all field types
7674
- *
7675
- * @return array Array of field types
7676
- *
7677
- * @uses PodsForm::field_loader
7678
- *
7679
- * @since 2.0.0
7680
- * @deprecated 2.3.0
7681
- */
7682
- public function get_field_types() {
7683
-
7684
- return PodsForm::field_types();
7685
- }
7686
-
7687
- /**
7688
- * Gets the schema definition of a field.
7689
- *
7690
- * @param string $type Field type to look for
7691
- * @param array $options (optional) Options of the field to pass to the schema function.
7692
- *
7693
- * @return array|bool|mixed|null
7694
- *
7695
- * @since 2.0.0
7696
- */
7697
- private function get_field_definition( $type, $options = null ) {
7698
-
7699
- $definition = PodsForm::field_method( $type, 'schema', $options );
7700
-
7701
- return $this->do_hook( 'field_definition', $definition, $type, $options );
7702
- }
7703
-
7704
- /**
7705
- * @see PodsForm:validate
7706
- *
7707
- * Validates the value of a field.
7708
- *
7709
- * @param mixed $value The value to validate
7710
- * @param string $field Field to use for validation
7711
- * @param array $object_fields Fields of the object we're validating
7712
- * @param array $fields Array of all fields data
7713
- * @param array|Pods $pod Array of pod data (or Pods object)
7714
- * @param array|object $params Extra parameters to pass to the validation function of the field.
7715
- *
7716
- * @return array|bool
7717
- *
7718
- * @uses PodsForm::validate
7719
- *
7720
- * @since 2.0.0
7721
- */
7722
- public function handle_field_validation( &$value, $field, $object_fields, $fields, $pod, $params ) {
7723
-
7724
- $tableless_field_types = PodsForm::tableless_field_types();
7725
-
7726
- $fields = array_merge( $fields, $object_fields );
7727
-
7728
- $options = $fields[ $field ];
7729
-
7730
- $id = ( is_object( $params ) ? $params->id : ( is_object( $pod ) ? $pod->id() : 0 ) );
7731
-
7732
- if ( is_object( $pod ) ) {
7733
- $pod = $pod->pod_data;
7734
- }
7735
-
7736
- $type = $options['type'];
7737
- $label = $options['label'];
7738
- $label = empty( $label ) ? $field : $label;
7739
-
7740
- // Verify required fields
7741
- if ( 1 == pods_var( 'required', $options['options'], 0 ) && 'slug' !== $type ) {
7742
- if ( '' === $value || null === $value || array() === $value ) {
7743
- return pods_error( sprintf( __( '%s is empty', 'pods' ), $label ), $this );
7744
- }
7745
-
7746
- if ( 'multi' === pods_var( 'pick_format_type', $options['options'] ) && 'autocomplete' !== pods_var( 'pick_format_multi', $options['options'] ) ) {
7747
- $has_value = false;
7748
-
7749
- $check_value = (array) $value;
7750
-
7751
- foreach ( $check_value as $val ) {
7752
- if ( '' !== $val && null !== $val && 0 !== $val && '0' !== $val ) {
7753
- $has_value = true;
7754
-
7755
- continue;
7756
- }
7757
- }
7758
-
7759
- if ( ! $has_value ) {
7760
- return pods_error( sprintf( __( '%s is required', 'pods' ), $label ), $this );
7761
- }
7762
- }
7763
-
7764
- }
7765
-
7766
- // @todo move this to after pre-save preparations
7767
- // Verify unique fields
7768
- if ( 1 == pods_var( 'unique', $options['options'], 0 ) && '' !== $value && null !== $value && array() !== $value ) {
7769
- if ( empty( $pod ) ) {
7770
- return false;
7771
- }
7772
-
7773
- if ( ! in_array( $type, $tableless_field_types ) ) {
7774
- $exclude = '';
7775
-
7776
- if ( ! empty( $id ) ) {
7777
- $exclude = "AND `id` != {$id}";
7778
- }
7779
-
7780
- $check = false;
7781
-
7782
- $check_value = pods_sanitize( $value );
7783
-
7784
- // @todo handle meta-based fields
7785
- // Trigger an error if not unique
7786
- if ( 'table' === $pod['storage'] ) {
7787
- $check = pods_query( "SELECT `id` FROM `@wp_pods_" . $pod['name'] . "` WHERE `{$field}` = '{$check_value}' {$exclude} LIMIT 1", $this );
7788
- }
7789
-
7790
- if ( ! empty( $check ) ) {
7791
- return pods_error( sprintf( __( '%s needs to be unique', 'pods' ), $label ), $this );
7792
- }
7793
- } else {
7794
- // @todo handle tableless check
7795
- }
7796
- }
7797
-
7798
- $validate = PodsForm::validate( $options['type'], $value, $field, array_merge( $options, pods_var( 'options', $options, array() ) ), $fields, $pod, $id, $params );
7799
-
7800
- $validate = $this->do_hook( 'field_validation', $validate, $value, $field, $object_fields, $fields, $pod, $params );
7801
-
7802
- return $validate;
7803
- }
7804
-
7805
- /**
7806
- * Find items related to a parent field
7807
- *
7808
- * @param int $field_id The Field ID
7809
- * @param int $pod_id The Pod ID
7810
- * @param mixed $ids A comma-separated string (or array) of item IDs
7811
- * @param array $field Field data array
7812
- * @param array $pod Pod data array
7813
- *
7814
- * @return int[]
7815
- *
7816
- * @since 2.0.0
7817
- *
7818
- * @uses pods_query()
7819
- */
7820
- public function lookup_related_items( $field_id, $pod_id, $ids, $field = null, $pod = null ) {
7821
-
7822
- $related_ids = array();
7823
-
7824
- if ( ! is_array( $ids ) ) {
7825
- $ids = explode( ',', $ids );
7826
- }
7827
-
7828
- $ids = array_map( 'absint', $ids );
7829
-
7830
- $ids = array_unique( array_filter( $ids ) );
7831
-
7832
- $idstring = implode( ',', $ids );
7833
-
7834
- if ( 0 != $pod_id && 0 != $field_id && isset( self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ] ) ) {
7835
- // Check cache first, no point in running the same query multiple times
7836
- return self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ];
7837
- }
7838
-
7839
- $tableless_field_types = PodsForm::tableless_field_types();
7840
-
7841
- $field_type = pods_v( 'type', $field );
7842
-
7843
- if ( empty( $ids ) || ! in_array( $field_type, $tableless_field_types ) ) {
7844
- return array();
7845
- }
7846
-
7847
- $related_pick_limit = 0;
7848
-
7849
- if ( empty( $field ) ) {
7850
- $field = $this->load_field( array( 'id' => $field_id ) );
7851
- }
7852
-
7853
- if ( ! empty( $field ) ) {
7854
- $options = (array) pods_var_raw( 'options', $field, $field, null, true );
7855
-
7856
- $related_pick_limit = (int) pods_v( $field_type . '_limit', $options, 0 );
7857
-
7858
- if ( 'single' === pods_var_raw( $field_type . '_format_type', $options ) ) {
7859
- $related_pick_limit = 1;
7860
- }
7861
-
7862
- // Temporary hack until there's some better handling here
7863
- $related_pick_limit = $related_pick_limit * count( $ids );
7864
- }
7865
-
7866
- if ( 'taxonomy' === $field_type ) {
7867
- $related = wp_get_object_terms( $ids, pods_v( 'name', $field ), array( 'fields' => 'ids' ) );
7868
-
7869
- if ( ! is_wp_error( $related ) ) {
7870
- $related_ids = $related;
7871
- }
7872
- } elseif ( 'comment' === $field_type ) {
7873
- $comment_args = array(
7874
- 'post__in' => $ids,
7875
- 'fields' => 'ids',
7876
- );
7877
-
7878
- $related = get_comments( $comment_args );
7879
-
7880
- if ( ! is_wp_error( $related ) ) {
7881
- $related_ids = $related;
7882
- }
7883
- } elseif ( ! pods_tableless() ) {
7884
- $ids = implode( ', ', $ids );
7885
-
7886
- $field_id = (int) $field_id;
7887
- $sister_id = (int) pods_var_raw( 'sister_id', $field, 0 );
7888
-
7889
- $related_where = "
7890
- `field_id` = {$field_id}
7891
- AND `item_id` IN ( {$ids} )
7892
- ";
7893
-
7894
- $sql = "
7895
- SELECT item_id, related_item_id, related_field_id
7896
- FROM `@wp_podsrel`
7897
- WHERE
7898
- {$related_where}
7899
- ORDER BY `weight`
7900
- ";
7901
-
7902
- $relationships = pods_query( $sql );
7903
-
7904
- if ( ! empty( $relationships ) ) {
7905
- foreach ( $relationships as $relation ) {
7906
- if ( ! in_array( $relation->related_item_id, $related_ids ) ) {
7907
- $related_ids[] = (int) $relation->related_item_id;
7908
- } elseif ( 0 < $sister_id && $field_id == $relation->related_field_id && ! in_array( $relation->item_id, $related_ids ) ) {
7909
- $related_ids[] = (int) $relation->item_id;
7910
- }
7911
- }
7912
- }
7913
- } else {
7914
- if ( ! is_array( $pod ) ) {
7915
- $pod = $this->load_pod( array( 'id' => $pod_id, 'table_info' => false ), false );
7916
- }
7917
-
7918
- if ( ! empty( $pod ) && in_array( $pod['type'], array(
7919
- 'post_type',
7920
- 'media',
7921
- 'taxonomy',
7922
- 'user',
7923
- 'comment',
7924
- 'settings'
7925
- ) ) ) {
7926
- $meta_type = $pod['type'];
7927
-
7928
- if ( in_array( $meta_type, array( 'post_type', 'media' ) ) ) {
7929
- $meta_type = 'post';
7930
- } elseif ( 'taxonomy' === $meta_type ) {
7931
- $meta_type = 'term';
7932
- }
7933
-
7934
- $no_conflict = pods_no_conflict_check( ( 'term' === $meta_type ? 'taxonomy' : $meta_type ) );
7935
-
7936
- if ( ! $no_conflict ) {
7937
- pods_no_conflict_on( ( 'term' === $meta_type ? 'taxonomy' : $meta_type ) );
7938
- }
7939
-
7940
- foreach ( $ids as $id ) {
7941
- if ( 'settings' === $meta_type ) {
7942
- $related_id = get_option( '_pods_' . $pod['name'] . '_' . $field['name'] );
7943
-
7944
- if ( empty( $related_id ) ) {
7945
- $related_id = get_option( $pod['name'] . '_' . $field['name'] );
7946
- }
7947
-
7948
- if ( is_array( $related_id ) && ! empty( $related_id ) ) {
7949
- foreach ( $related_id as $related ) {
7950
- if ( is_array( $related ) && ! empty( $related ) ) {
7951
- if ( isset( $related['id'] ) ) {
7952
- $related_ids[] = (int) $related['id'];
7953
- } else {
7954
- foreach ( $related as $r ) {
7955
- $related_ids[] = (int) $r;
7956
- }
7957
- }
7958
- } else {
7959
- $related_ids[] = (int) $related;
7960
- }
7961
- }
7962
- }
7963
- } else {
7964
- $related_id = get_metadata( $meta_type, $id, '_pods_' . $field['name'], true );
7965
-
7966
- if ( empty( $related_id ) ) {
7967
- $related_id = get_metadata( $meta_type, $id, $field['name'] );
7968
- }
7969
-
7970
- if ( is_array( $related_id ) && ! empty( $related_id ) ) {
7971
- foreach ( $related_id as $related ) {
7972
- if ( is_array( $related ) && ! empty( $related ) ) {
7973
- if ( isset( $related['id'] ) ) {
7974
- $related_ids[] = (int) $related['id'];
7975
- } else {
7976
- foreach ( $related as $r ) {
7977
- if ( isset( $related['id'] ) ) {
7978
- $related_ids[] = (int) $r['id'];
7979
- } else {
7980
- $related_ids[] = (int) $r;
7981
- }
7982
- }
7983
- }
7984
- } else {
7985
- $related_ids[] = (int) $related;
7986
- }
7987
- }
7988
- }
7989
- }
7990
- }
7991
-
7992
- if ( ! $no_conflict ) {
7993
- pods_no_conflict_off( ( 'term' === $meta_type ? 'taxonomy' : $meta_type ) );
7994
- }
7995
- }
7996
- }
7997
-
7998
- if ( is_array( $related_ids ) ) {
7999
- $related_ids = array_unique( array_filter( $related_ids ) );
8000
-
8001
- if ( 0 < $related_pick_limit && ! empty( $related_ids ) ) {
8002
- $related_ids = array_slice( $related_ids, 0, $related_pick_limit );
8003
- }
8004
- }
8005
- if ( 0 != $pod_id && 0 != $field_id && ! empty( $related_ids ) ) {
8006
- // Only cache if $pod_id and $field_id were passed
8007
- self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ] = $related_ids;
8008
- }
8009
-
8010
- return $related_ids;
8011
- }
8012
-
8013
- /**
8014
- * Find related items related to an item
8015
- *
8016
- * @param int $field_id The Field ID
8017
- * @param int $pod_id The Pod ID
8018
- * @param int $id Item ID to get related IDs from
8019
- * @param array $field Field data array
8020
- * @param array $pod Pod data array
8021
- *
8022
- * @return array|bool
8023
- *
8024
- * @since 2.3.0
8025
- *
8026
- * @uses pods_query()
8027
- */
8028
- public function lookup_related_items_from( $field_id, $pod_id, $id, $field = null, $pod = null ) {
8029
-
8030
- $related_ids = false;
8031
-
8032
- $id = (int) $id;
8033
-
8034
- $tableless_field_types = PodsForm::tableless_field_types();
8035
-
8036
- if ( empty( $id ) || ! in_array( pods_v( 'type', $field ), $tableless_field_types ) ) {
8037
- return false;
8038
- }
8039
-
8040
- $related_pick_limit = 0;
8041
-
8042
- if ( ! empty( $field ) ) {
8043
- $options = (array) pods_var_raw( 'options', $field, $field, null, true );
8044
-
8045
- $related_pick_limit = (int) pods_v( 'pick_limit', $options, 0 );
8046
-
8047
- if ( 'single' === pods_var_raw( 'pick_format_type', $options ) ) {
8048
- $related_pick_limit = 1;
8049
- }
8050
- }
8051
-
8052
- if ( ! pods_tableless() ) {
8053
- $field_id = (int) $field_id;
8054
- $sister_id = (int) pods_var_raw( 'sister_id', $field, 0 );
8055
-
8056
- $related_where = "
8057
- `field_id` = {$field_id}
8058
- AND `related_item_id` = {$id}
8059
- ";
8060
-
8061
- $sql = "
8062
- SELECT *
8063
- FROM `@wp_podsrel`
8064
- WHERE
8065
- {$related_where}
8066
- ORDER BY `weight`
8067
- ";
8068
-
8069
- $relationships = pods_query( $sql );
8070
-
8071
- if ( ! empty( $relationships ) ) {
8072
- $related_ids = array();
8073
-
8074
- foreach ( $relationships as $relation ) {
8075
- if ( $field_id == $relation->field_id && ! in_array( $relation->item_id, $related_ids ) ) {
8076
- $related_ids[] = (int) $relation->item_id;
8077
- } elseif ( 0 < $sister_id && $field_id == $relation->related_field_id && ! in_array( $relation->related_item_id, $related_ids ) ) {
8078
- $related_ids[] = (int) $relation->related_item_id;
8079
- }
8080
- }
8081
- }
8082
- } else {
8083
- // @todo handle meta-based lookups
8084
- return false;
8085
-
8086
- if ( ! is_array( $pod ) ) {
8087
- $pod = $this->load_pod( array( 'id' => $pod_id, 'table_info' => false ), false );
8088
- }
8089
-
8090
- if ( ! empty( $pod ) && in_array( $pod['type'], array(
8091
- 'post_type',
8092
- 'media',
8093
- 'taxonomy',
8094
- 'user',
8095
- 'comment',
8096
- 'settings'
8097
- ) ) ) {
8098
- $related_ids = array();
8099
-
8100
- $meta_type = $pod['type'];
8101
-
8102
- if ( in_array( $meta_type, array( 'post_type', 'media' ) ) ) {
8103
- $meta_type = 'post';
8104
- } elseif ( 'taxonomy' === $meta_type ) {
8105
- $meta_type = 'term';
8106
- }
8107
-
8108
- $no_conflict = pods_no_conflict_check( ( 'term' === $meta_type ? 'taxonomy' : $meta_type ) );
8109
-
8110
- if ( ! $no_conflict ) {
8111
- pods_no_conflict_on( ( 'term' === $meta_type ? 'taxonomy' : $meta_type ) );
8112
- }
8113
-
8114
- if ( 'settings' === $meta_type ) {
8115
- $related_id = get_option( '_pods_' . $pod['name'] . '_' . $field['name'] );
8116
-
8117
- if ( empty( $related_id ) ) {
8118
- $related_id = get_option( $pod['name'] . '_' . $field['name'] );
8119
- }
8120
-
8121
- if ( is_array( $related_id ) && ! empty( $related_id ) ) {
8122
- foreach ( $related_id as $related ) {
8123
- if ( is_array( $related ) && ! empty( $related ) ) {
8124
- if ( isset( $related['id'] ) ) {
8125
- $related_ids[] = (int) $related['id'];
8126
- } else {
8127
- foreach ( $related as $r ) {
8128
- $related_ids[] = (int) $r;
8129
- }
8130
- }
8131
- } else {
8132
- $related_ids[] = (int) $related;
8133
- }
8134
- }
8135
- }
8136
- } else {
8137
- $related_id = get_metadata( $meta_type, $id, '_pods_' . $field['name'], true );
8138
-
8139
- if ( empty( $related_id ) ) {
8140
- $related_id = get_metadata( $meta_type, $id, $field['name'] );
8141
- }
8142
-
8143
- if ( is_array( $related_id ) && ! empty( $related_id ) ) {
8144
- foreach ( $related_id as $related ) {
8145
- if ( is_array( $related ) && ! empty( $related ) ) {
8146
- if ( isset( $related['id'] ) ) {
8147
- $related_ids[] = (int) $related['id'];
8148
- } else {
8149
- foreach ( $related as $r ) {
8150
- if ( isset( $related['id'] ) ) {
8151
- $related_ids[] = (int) $r['id'];
8152
- } else {
8153
- $related_ids[] = (int) $r;
8154
- }
8155
- }
8156
- }
8157
- } else {
8158
- $related_ids[] = (int) $related;
8159
- }
8160
- }
8161
- }
8162
- }
8163
-
8164
- if ( ! $no_conflict ) {
8165
- pods_no_conflict_off( ( 'term' === $meta_type ? 'taxonomy' : $meta_type ) );
8166
- }
8167
- }
8168
- }
8169
-
8170
- if ( is_array( $related_ids ) ) {
8171
- $related_ids = array_unique( array_filter( $related_ids ) );
8172
  }
8173
 
8174
- return $related_ids;
8175
- }
8176
-
8177
- /**
8178
- *
8179
- * Load the information about an objects MySQL table
8180
- *
8181
- * @param $object_type
8182
- * @param string $object The object to look for
8183
- * @param null $name (optional) Name of the pod to load
8184
- * @param array $pod (optional) Array with pod information
8185
- *
8186
- * @return array
8187
- *
8188
- * @since 2.5.0
8189
- */
8190
- public function get_table_info_load( $object_type, $object, $name = null, $pod = null ) {
8191
-
8192
- $info = array();
8193
-
8194
- if ( 'pod' === $object_type && null === $pod ) {
8195
- if ( empty( $name ) ) {
8196
- $prefix = 'pod-';
8197
-
8198
- // Make sure we actually have the prefix before trying anything with the name
8199
- if ( 0 === strpos( $object_type, $prefix ) ) {
8200
- $name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
8201
- }
8202
- }
8203
-
8204
- if ( empty( $name ) && ! empty( $object ) ) {
8205
- $name = $object;
8206
- }
8207
-
8208
- $pod = $this->load_pod( array( 'name' => $name, 'table_info' => false ), false );
8209
-
8210
- if ( ! empty( $pod ) ) {
8211
- $object_type = $pod['type'];
8212
- $name = $pod['name'];
8213
- $object = $pod['object'];
8214
-
8215
- $info['pod'] = $pod;
8216
- }
8217
- } elseif ( null === $pod ) {
8218
- if ( empty( $name ) ) {
8219
- $prefix = $object_type . '-';
8220
 
8221
- // Make sure we actually have the prefix before trying anything with the name
8222
- if ( 0 === strpos( $object_type, $prefix ) ) {
8223
- $name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
8224
- }
8225
  }
8226
 
8227
- if ( empty( $name ) && ! empty( $object ) ) {
8228
- $name = $object;
8229
- }
 
8230
 
8231
- if ( ! empty( $name ) ) {
8232
- $pod = $this->load_pod( array( 'name' => $name, 'table_info' => false ), false );
8233
 
8234
- if ( ! empty( $pod ) && ( null === $object_type || $object_type == $pod['type'] ) ) {
8235
- $object_type = $pod['type'];
8236
- $name = $pod['name'];
8237
- $object = $pod['object'];
8238
 
8239
- $info['pod'] = $pod;
8240
- }
8241
  }
8242
- } elseif ( ! empty( $pod ) ) {
8243
- $info['pod'] = $pod;
8244
  }
8245
 
8246
- if ( 0 === strpos( $object_type, 'pod' ) ) {
8247
- if ( empty( $name ) ) {
8248
- $prefix = 'pod-';
8249
-
8250
- // Make sure we actually have the prefix before trying anything with the name
8251
- if ( 0 === strpos( $object_type, $prefix ) ) {
8252
- $name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
8253
- }
8254
- }
8255
-
8256
- $info['type'] = 'pod';
8257
- global $wpdb;
8258
-
8259
- $info['meta_table'] = $wpdb->prefix . 'pods_' . ( empty( $object ) ? $name : $object );
8260
- $info['table'] = $info['meta_table'];
8261
-
8262
- if ( is_array( $info['pod'] ) && 'pod' === pods_v( 'type', $info['pod'] ) ) {
8263
- $info['meta_field_value'] = pods_v( 'pod_index', $info['pod']['options'], 'id', true );
8264
- $info['pod_field_index'] = $info['meta_field_value'];
8265
- $info['field_index'] = $info['meta_field_value'];
8266
- $info['meta_field_index'] = $info['meta_field_value'];
8267
-
8268
- $slug_field = get_posts( array(
8269
- 'post_type' => '_pods_field',
8270
- 'posts_per_page' => 1,
8271
- 'nopaging' => true,
8272
- 'post_parent' => $info['pod']['id'],
8273
- 'orderby' => 'menu_order',
8274
- 'order' => 'ASC',
8275
- 'meta_query' => array(
8276
- array(
8277
- 'key' => 'type',
8278
- 'value' => 'slug',
8279
- )
8280
- )
8281
- ) );
8282
-
8283
- if ( ! empty( $slug_field[0] ) ) {
8284
- $slug_field = $slug_field[0];
8285
-
8286
- $info['pod_field_slug'] = $slug_field->post_name;
8287
- $info['field_slug'] = $slug_field->post_name;
8288
- }
8289
-
8290
- if ( 1 == pods_v( 'hierarchical', $info['pod']['options'], 0 ) ) {
8291
- $parent_field = pods_v( 'pod_parent', $info['pod']['options'], 'id', true );
8292
 
8293
- if ( ! empty( $parent_field ) && isset( $info['pod']['fields'][ $parent_field ] ) ) {
8294
- $info['object_hierarchical'] = true;
8295
 
8296
- $info['field_parent'] = $parent_field . '_select';
8297
- $info['pod_field_parent'] = $info['field_parent'];
8298
- $info['field_parent_select'] = '`' . $parent_field . '`.`id` AS `' . $info['field_parent'] . '`';
8299
- }
8300
- }
8301
- }
8302
- }
8303
 
8304
- return $info;
8305
  }
8306
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8307
  /**
8308
- * Get information about an objects MySQL table
8309
  *
8310
- * @param string $object_type
8311
- * @param string $object The object to look for
8312
- * @param null $name (optional) Name of the pod to load
8313
- * @param array $pod (optional) Array with pod information
8314
- * @param array $field (optional) Array with field information
8315
  *
8316
- * @return array|bool
8317
  *
8318
- * @since 2.0.0
8319
  */
8320
- public function get_table_info( $object_type, $object, $name = null, $pod = null, $field = null ) {
8321
-
8322
- /**
8323
- * @var $wpdb wpdb
8324
- * @var $sitepress SitePress
8325
- * @var $polylang object
8326
- */
8327
- /*
8328
- * @todo wpml-comp Remove global object usage
8329
- */
8330
- global $wpdb, $sitepress, $polylang;
8331
-
8332
- // @todo Handle $object arrays for Post Types, Taxonomies, Comments (table pulled from first object in array)
8333
-
8334
- $info = array(
8335
- //'select' => '`t`.*',
8336
- 'object_type' => $object_type,
8337
- 'type' => null,
8338
- 'object_name' => $object,
8339
- 'object_hierarchical' => false,
8340
-
8341
- 'table' => $object,
8342
- 'meta_table' => $object,
8343
- 'pod_table' => $wpdb->prefix . 'pods_' . ( empty( $object ) ? $name : $object ),
8344
-
8345
- 'field_id' => 'id',
8346
- 'field_index' => 'name',
8347
- 'field_slug' => null,
8348
- 'field_type' => null,
8349
- 'field_parent' => null,
8350
- 'field_parent_select' => null,
8351
-
8352
- 'meta_field_id' => 'id',
8353
- 'meta_field_index' => 'name',
8354
- 'meta_field_value' => 'name',
8355
-
8356
- 'pod_field_id' => 'id',
8357
- 'pod_field_index' => 'name',
8358
- 'pod_field_slug' => null,
8359
- 'pod_field_parent' => null,
8360
-
8361
- 'join' => array(),
8362
-
8363
- 'where' => null,
8364
- 'where_default' => null,
8365
-
8366
- 'orderby' => null,
8367
 
8368
- 'pod' => null,
8369
- 'recurse' => false
 
 
 
 
 
 
 
 
 
8370
  );
8371
 
8372
- if ( empty( $object_type ) ) {
8373
- $object_type = 'post_type';
8374
- $object = 'post';
8375
- } elseif ( empty( $object ) && in_array( $object_type, array( 'user', 'media', 'comment' ), true ) ) {
8376
- $object = $object_type;
8377
- }
8378
-
8379
- $pod_name = $pod;
8380
-
8381
- if ( is_array( $pod_name ) ) {
8382
- $pod_name = pods_var_raw( 'name', $pod_name, ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $pod_name, JSON_UNESCAPED_UNICODE ) : json_encode( $pod_name ) ), null, true );
8383
- } else {
8384
- $pod_name = $object;
8385
- }
8386
 
8387
- $field_name = $field;
8388
 
8389
- if ( is_array( $field_name ) ) {
8390
- $field_name = pods_var_raw( 'name', $field_name, ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $pod_name, JSON_UNESCAPED_UNICODE ) : json_encode( $field_name ) ), null, true );
8391
- }
8392
 
8393
- $transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
8394
 
8395
- $current_language = false;
8396
- $current_language_t_id = 0;
8397
- $current_language_tt_id = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8398
 
8399
- // Get current language data
8400
- $lang_data = pods_i18n()->get_current_language_data();
 
8401
 
8402
- if ( $lang_data ) {
8403
- if ( ! empty( $lang_data['language'] ) ) {
8404
- $current_language = $lang_data['language'];
8405
- }
8406
 
8407
- if ( ! empty( $lang_data['t_id'] ) ) {
8408
- $current_language_t_id = $lang_data['t_id'];
8409
- }
 
 
8410
 
8411
- if ( ! empty( $lang_data['tt_id'] ) ) {
8412
- $current_language_tt_id = $lang_data['tt_id'];
8413
- }
8414
 
8415
- if ( ! empty( $lang_data['tl_t_id'] ) ) {
8416
- $current_language_tl_t_id = $lang_data['tl_t_id'];
8417
- }
 
8418
 
8419
- if ( ! empty( $lang_data['tl_tt_id'] ) ) {
8420
- $current_language_tl_tt_id = $lang_data['tl_tt_id'];
8421
- }
8422
- }
8423
 
8424
- if ( ! empty( $current_language ) ) {
8425
- $transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . $current_language . '_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
8426
- }
 
8427
 
8428
- $_info = false;
8429
- $transient_cached = false;
8430
 
8431
- if ( isset( self::$table_info_cache[ $transient ] ) ) {
8432
- // Prefer info from the object internal cache
8433
- $_info = self::$table_info_cache[ $transient ];
8434
- } elseif ( pods_api_cache() ) {
8435
- $_info = pods_transient_get( $transient );
8436
- if ( false === $_info && ! did_action( 'init' ) ) {
8437
- $_info = pods_transient_get( $transient . '_pre_init' );
8438
- }
8439
- $transient_cached = true;
8440
- }
8441
 
8442
- if ( false !== $_info && is_array( $_info ) ) {
8443
- // Data was cached, use that
8444
- $info = $_info;
8445
- } else {
8446
- // Data not cached, load it up
8447
- $_info = $this->get_table_info_load( $object_type, $object, $name, $pod );
8448
- if ( isset( $_info['type'] ) ) {
8449
- // Allow function to override $object_type
8450
- $object_type = $_info['type'];
8451
- }
8452
- $info = array_merge( $info, $_info );
8453
- }
8454
 
8455
- if ( 0 === strpos( $object_type, 'post_type' ) || 'media' === $object_type || in_array( pods_var_raw( 'type', $info['pod'] ), array(
8456
- 'post_type',
8457
- 'media'
8458
- ) ) ) {
8459
- $info['table'] = $wpdb->posts;
8460
- $info['meta_table'] = $wpdb->postmeta;
8461
-
8462
- $info['field_id'] = 'ID';
8463
- $info['field_index'] = 'post_title';
8464
- $info['field_slug'] = 'post_name';
8465
- $info['field_type'] = 'post_type';
8466
- $info['field_parent'] = 'post_parent';
8467
- $info['field_parent_select'] = '`t`.`' . $info['field_parent'] . '`';
8468
-
8469
- $info['meta_field_id'] = 'post_id';
8470
- $info['meta_field_index'] = 'meta_key';
8471
- $info['meta_field_value'] = 'meta_value';
8472
-
8473
- if ( 'media' === $object_type ) {
8474
- $object = 'attachment';
8475
- }
8476
 
8477
- if ( empty( $name ) ) {
8478
- $prefix = 'post_type-';
8479
 
8480
- // Make sure we actually have the prefix before trying anything with the name
8481
- if ( 0 === strpos( $object_type, $prefix ) ) {
8482
- $name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
8483
- }
8484
- }
8485
 
8486
- if ( 'media' !== $object_type ) {
8487
- $object_type = 'post_type';
8488
- }
8489
 
8490
- $post_type = pods_sanitize( ( empty( $object ) ? $name : $object ) );
 
8491
 
8492
- if ( 'attachment' === $post_type || 'media' === $object_type ) {
8493
- $info['pod_table'] = $wpdb->prefix . 'pods_media';
8494
- } else {
8495
- $info['pod_table'] = $wpdb->prefix . 'pods_' . pods_clean_name( $post_type, true, false );
8496
- }
 
 
8497
 
8498
- $post_type_object = get_post_type_object( $post_type );
 
8499
 
8500
- if ( is_object( $post_type_object ) && $post_type_object->hierarchical ) {
8501
- $info['object_hierarchical'] = true;
8502
- }
 
8503
 
8504
- // Post Status default
8505
- $post_status = array( 'publish' );
 
 
8506
 
8507
- // Pick field post_status option
8508
- if ( ! empty( $field['options']['pick_post_status'] ) ) {
8509
- $post_status = (array) $field['options']['pick_post_status'];
8510
- } elseif ( ! empty( $field['pick_post_status'] ) ) {
8511
- $post_status = (array) $field['pick_post_status'];
8512
- }
8513
 
8514
- /**
8515
- * Default Post Status to query for.
8516
- *
8517
- * Use to change "default" post status from publish to any other status or statuses.
8518
- *
8519
- * @param array $post_status List of post statuses. Default is 'publish' or field setting (if available).
8520
- * @param string $post_type Post type of current object.
8521
- * @param array $info Array of information about the object.
8522
- * @param string $object Type of object.
8523
- * @param string $name Name of pod to load.
8524
- * @param array $pod Array with Pod information. Result of PodsAPI::load_pod().
8525
- * @param array $field Array with field information.
8526
- *
8527
- * @since unknown
8528
- */
8529
- $post_status = apply_filters( 'pods_api_get_table_info_default_post_status', $post_status, $post_type, $info, $object_type, $object, $name, $pod, $field );
8530
 
8531
- $info['where'] = array(
8532
- //'post_status' => '`t`.`post_status` IN ( "inherit", "publish" )', // @todo Figure out what statuses Attachments can be
8533
- 'post_type' => '`t`.`' . $info['field_type'] . '` = "' . $post_type . '"'
8534
- );
8535
 
8536
- if ( 'post_type' === $object_type ) {
8537
- $info['where_default'] = '`t`.`post_status` IN ( "' . implode( '", "', $post_status ) . '" )';
8538
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8539
 
8540
- $info['orderby'] = '`t`.`menu_order`, `t`.`' . $info['field_index'] . '`, `t`.`post_date`';
 
 
8541
 
8542
- /*
8543
- * @todo wpml-comp Check if WPML filters can be applied afterwards
8544
- */
8545
- // WPML support
8546
- if ( did_action( 'wpml_loaded' ) && ! empty( $current_language ) && apply_filters( 'wpml_is_translated_post_type', false, $post_type ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
8547
- $info['join']['wpml_translations'] = "
8548
- LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`
8549
- ON `wpml_translations`.`element_id` = `t`.`ID`
8550
- AND `wpml_translations`.`element_type` = 'post_{$post_type}'
8551
- AND `wpml_translations`.`language_code` = '{$current_language}'
8552
- ";
8553
-
8554
- $info['join']['wpml_languages'] = "
8555
- LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`
8556
- ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1
8557
- ";
8558
-
8559
- $info['where']['wpml_languages'] = "`wpml_languages`.`code` IS NOT NULL";
8560
- } elseif ( ( function_exists( 'PLL' ) || is_object( $polylang ) ) && ! empty( $current_language ) && function_exists( 'pll_is_translated_post_type' ) && pll_is_translated_post_type( $post_type ) ) {
8561
- // Polylang support
8562
- $info['join']['polylang_languages'] = "
8563
- LEFT JOIN `{$wpdb->term_relationships}` AS `polylang_languages`
8564
- ON `polylang_languages`.`object_id` = `t`.`ID`
8565
- AND `polylang_languages`.`term_taxonomy_id` = {$current_language_tt_id}
8566
- ";
8567
-
8568
- $info['where']['polylang_languages'] = "`polylang_languages`.`object_id` IS NOT NULL";
8569
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8570
 
8571
- $info['object_fields'] = $this->get_wp_object_fields( $object_type, $info['pod'] );
8572
- } elseif ( 0 === strpos( $object_type, 'taxonomy' ) || in_array( $object_type, array(
8573
- 'nav_menu',
8574
- 'post_format'
8575
- ) ) || 'taxonomy' === pods_var_raw( 'type', $info['pod'] ) ) {
8576
- $info['table'] = $wpdb->terms;
8577
- $info['meta_table'] = $wpdb->terms;
8578
-
8579
- $info['join']['tt'] = "LEFT JOIN `{$wpdb->term_taxonomy}` AS `tt` ON `tt`.`term_id` = `t`.`term_id`";
8580
- $info['join']['tr'] = "LEFT JOIN `{$wpdb->term_relationships}` AS `tr` ON `tr`.`term_taxonomy_id` = `tt`.`term_taxonomy_id`";
8581
- $info['meta_field_id'] = 'term_id';
8582
- $info['field_id'] = 'term_id';
8583
- $info['meta_field_value'] = 'name';
8584
- $info['field_index'] = 'name';
8585
- $info['meta_field_index'] = 'name';
8586
- $info['field_slug'] = 'slug';
8587
- $info['field_type'] = 'taxonomy';
8588
- $info['field_parent'] = 'parent';
8589
- $info['field_parent_select'] = '`tt`.`' . $info['field_parent'] . '`';
8590
-
8591
- if ( ! empty( $wpdb->termmeta ) ) {
8592
- $info['meta_table'] = $wpdb->termmeta;
8593
-
8594
- $info['meta_field_id'] = 'term_id';
8595
- $info['meta_field_index'] = 'meta_key';
8596
- $info['meta_field_value'] = 'meta_value';
8597
- }
8598
 
8599
- if ( 'nav_menu' === $object_type ) {
8600
- $object = 'nav_menu';
8601
- } elseif ( 'post_format' === $object_type ) {
8602
- $object = 'post_format';
8603
- }
8604
 
8605
- if ( empty( $name ) ) {
8606
- $prefix = 'taxonomy-';
8607
 
8608
- // Make sure we actually have the prefix before trying anything with the name
8609
- if ( 0 === strpos( $object_type, $prefix ) ) {
8610
- $name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
8611
- }
8612
- }
8613
 
8614
- if ( ! in_array( $object_type, array( 'nav_menu', 'post_format' ) ) ) {
8615
- $object_type = 'taxonomy';
8616
- }
 
 
8617
 
8618
- $taxonomy = pods_sanitize( ( empty( $object ) ? $name : $object ) );
 
 
8619
 
8620
- $info['pod_table'] = $wpdb->prefix . 'pods_' . pods_clean_name( $taxonomy, true, false );
 
 
 
8621
 
8622
- $taxonomy_object = get_taxonomy( $taxonomy );
8623
 
8624
- if ( is_object( $taxonomy_object ) && $taxonomy_object->hierarchical ) {
8625
- $info['object_hierarchical'] = true;
8626
- }
8627
 
8628
- $info['where'] = array(
8629
- 'tt.taxonomy' => '`tt`.`' . $info['field_type'] . '` = "' . $taxonomy . '"'
8630
- );
 
 
 
8631
 
8632
- /*
8633
- * @todo wpml-comp WPML API call for is_translated_taxononomy
8634
- * @todo wpml-comp Check if WPML filters can be applied afterwards
8635
- */
8636
- // WPML Support
8637
- if ( is_object( $sitepress ) && ! empty( $current_language ) && $sitepress->is_translated_taxonomy( $taxonomy ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
8638
- $info['join']['wpml_translations'] = "
8639
- LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`
8640
- ON `wpml_translations`.`element_id` = `tt`.`term_taxonomy_id`
8641
- AND `wpml_translations`.`element_type` = 'tax_{$taxonomy}'
8642
- AND `wpml_translations`.`language_code` = '{$current_language}'
8643
- ";
8644
-
8645
- $info['join']['wpml_languages'] = "
8646
- LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`
8647
- ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1
8648
- ";
8649
-
8650
- $info['where']['wpml_languages'] = "`wpml_languages`.`code` IS NOT NULL";
8651
- } elseif ( ( function_exists( 'PLL' ) || is_object( $polylang ) ) && ! empty( $current_language ) && ! empty( $current_language_tl_tt_id ) && function_exists( 'pll_is_translated_taxonomy' ) && pll_is_translated_taxonomy( $taxonomy ) ) {
8652
- // Polylang support
8653
- $info['join']['polylang_languages'] = "
8654
- LEFT JOIN `{$wpdb->term_relationships}` AS `polylang_languages`
8655
- ON `polylang_languages`.`object_id` = `t`.`term_id`
8656
- AND `polylang_languages`.`term_taxonomy_id` = {$current_language_tl_tt_id}
8657
- ";
8658
 
8659
- $info['where']['polylang_languages'] = "`polylang_languages`.`object_id` IS NOT NULL";
8660
- }
8661
 
8662
- $info['object_fields'] = $this->get_wp_object_fields( $object_type, $info['pod'] );
8663
- } elseif ( 'user' === $object_type || 'user' === pods_var_raw( 'type', $info['pod'] ) ) {
8664
- $info['table'] = $wpdb->users;
8665
- $info['meta_table'] = $wpdb->usermeta;
8666
- $info['pod_table'] = $wpdb->prefix . 'pods_user';
8667
 
8668
- $info['field_id'] = 'ID';
8669
- $info['field_index'] = 'display_name';
8670
- $info['field_slug'] = 'user_nicename';
8671
 
8672
- $info['meta_field_id'] = 'user_id';
8673
- $info['meta_field_index'] = 'meta_key';
8674
- $info['meta_field_value'] = 'meta_value';
8675
 
8676
- $info['where'] = array(
8677
- 'user_status' => '`t`.`user_status` = 0'
8678
- );
8679
 
8680
- $info['object_fields'] = $this->get_wp_object_fields( $object_type, $info['pod'] );
8681
- } elseif ( 'comment' === $object_type || 'comment' === pods_var_raw( 'type', $info['pod'] ) ) {
8682
- //$info[ 'object_hierarchical' ] = true;
8683
 
8684
- $info['table'] = $wpdb->comments;
8685
- $info['meta_table'] = $wpdb->commentmeta;
8686
- $info['pod_table'] = $wpdb->prefix . 'pods_comment';
8687
 
8688
- $info['field_id'] = 'comment_ID';
8689
- $info['field_index'] = 'comment_date';
8690
- $info['field_type'] = 'comment_type';
8691
- $info['field_parent'] = 'comment_parent';
8692
- $info['field_parent_select'] = '`t`.`' . $info['field_parent'] . '`';
8693
 
8694
- $info['meta_field_id'] = 'comment_id';
8695
- $info['meta_field_index'] = 'meta_key';
8696
- $info['meta_field_value'] = 'meta_value';
8697
 
8698
- $object = 'comment';
 
8699
 
8700
- $comment_type = ( empty( $object ) ? $name : $object );
 
8701
 
8702
- $comment_type_clause = '`t`.`' . $info['field_type'] . '` = "' . $comment_type . '"';
 
 
 
8703
 
8704
- if ( 'comment' === $comment_type ) {
8705
- $comment_type_clause = '( ' . $comment_type_clause . ' OR `t`.`' . $info['field_type'] . '` = "" )';
8706
- }
8707
 
8708
- $info['where'] = array(
8709
- 'comment_approved' => '`t`.`comment_approved` = 1',
8710
- 'comment_type' => $comment_type_clause
8711
- );
8712
 
8713
- $info['orderby'] = '`t`.`' . $info['field_index'] . '` DESC, `t`.`' . $info['field_id'] . '`';
8714
- } elseif ( in_array( $object_type, array(
8715
- 'option',
8716
- 'settings'
8717
- ) ) || 'settings' === pods_var_raw( 'type', $info['pod'] ) ) {
8718
- $info['table'] = $wpdb->options;
8719
- $info['meta_table'] = $wpdb->options;
8720
-
8721
- $info['field_id'] = 'option_id';
8722
- $info['field_index'] = 'option_name';
8723
-
8724
- $info['meta_field_id'] = 'option_id';
8725
- $info['meta_field_index'] = 'option_name';
8726
- $info['meta_field_value'] = 'option_value';
8727
-
8728
- $info['orderby'] = '`t`.`' . $info['field_index'] . '` ASC';
8729
- } elseif ( is_multisite() && ( in_array( $object_type, array(
8730
- 'site_option',
8731
- 'site_settings'
8732
- ) ) || 'site_settings' === pods_var_raw( 'type', $info['pod'] ) ) ) {
8733
- $info['table'] = $wpdb->sitemeta;
8734
- $info['meta_table'] = $wpdb->sitemeta;
8735
-
8736
- $info['field_id'] = 'site_id';
8737
- $info['field_index'] = 'meta_key';
8738
-
8739
- $info['meta_field_id'] = 'site_id';
8740
- $info['meta_field_index'] = 'meta_key';
8741
- $info['meta_field_value'] = 'meta_value';
8742
-
8743
- $info['orderby'] = '`t`.`' . $info['field_index'] . '` ASC';
8744
- } elseif ( is_multisite() && 'network' === $object_type ) { // Network = Site
8745
- $info['table'] = $wpdb->site;
8746
- $info['meta_table'] = $wpdb->sitemeta;
8747
-
8748
- $info['field_id'] = 'id';
8749
- $info['field_index'] = 'domain';
8750
-
8751
- $info['meta_field_id'] = 'site_id';
8752
- $info['meta_field_index'] = 'meta_key';
8753
- $info['meta_field_value'] = 'meta_value';
8754
-
8755
- $info['orderby'] = '`t`.`' . $info['field_index'] . '` ASC, `t`.`path` ASC, `t`.`' . $info['field_id'] . '`';
8756
- } elseif ( is_multisite() && 'site' === $object_type ) { // Site = Blog
8757
- $info['table'] = $wpdb->blogs;
8758
-
8759
- $info['field_id'] = 'blog_id';
8760
- $info['field_index'] = 'domain';
8761
- $info['field_type'] = 'site_id';
8762
-
8763
- $info['where'] = array(
8764
- 'archived' => '`t`.`archived` = 0',
8765
- 'spam' => '`t`.`spam` = 0',
8766
- 'deleted' => '`t`.`deleted` = 0',
8767
- 'site_id' => '`t`.`' . $info['field_type'] . '` = ' . (int) get_current_site()->id
8768
- );
8769
 
8770
- $info['orderby'] = '`t`.`' . $info['field_index'] . '` ASC, `t`.`path` ASC, `t`.`' . $info['field_id'] . '`';
8771
- } elseif ( 'table' === $object_type || 'table' === pods_var_raw( 'type', $info['pod'] ) ) {
8772
- $info['table'] = ( empty( $object ) ? $name : $object );
8773
- $info['pod_table'] = $wpdb->prefix . 'pods_' . $info['table'];
8774
 
 
8775
 
8776
- if ( ! empty( $field ) ) {
8777
- if ( ! is_array( $field ) ) {
8778
- if ( is_string( $pod ) ) {
8779
- $pod = pods( $pod );
8780
- }
8781
- if ( $pod && ! empty( $pod->fields[ $field ] ) ) {
8782
- $field = $pod->fields[ $field ];
8783
- }
8784
- }
8785
- if ( is_array( $field ) ) {
8786
- $info['table'] = pods_var_raw( 'pick_table', pods_var_raw( 'options', $field, $field ) );
8787
- $info['field_id'] = pods_var_raw( 'pick_table_id', pods_var_raw( 'options', $field, $field ) );
8788
- $info['meta_field_value'] = pods_var_raw( 'pick_table_index', pods_var_raw( 'options', $field, $field ) );
8789
- $info['field_index'] = $info['meta_field_value'];
8790
- $info['meta_field_index'] = $info['meta_field_value'];
8791
- }
8792
- }
8793
- }
8794
 
8795
- $info['table'] = pods_clean_name( $info['table'], false, false );
8796
- $info['meta_table'] = pods_clean_name( $info['meta_table'], false, false );
8797
- $info['pod_table'] = pods_clean_name( $info['pod_table'], false, false );
8798
 
8799
- $info['field_id'] = pods_clean_name( $info['field_id'], false, false );
8800
- $info['field_index'] = pods_clean_name( $info['field_index'], false, false );
8801
- $info['field_slug'] = pods_clean_name( $info['field_slug'], false, false );
8802
 
8803
- $info['meta_field_id'] = pods_clean_name( $info['meta_field_id'], false, false );
8804
- $info['meta_field_index'] = pods_clean_name( $info['meta_field_index'], false, false );
8805
- $info['meta_field_value'] = pods_clean_name( $info['meta_field_value'], false, false );
 
 
8806
 
8807
- if ( empty( $info['orderby'] ) ) {
8808
- $info['orderby'] = '`t`.`' . $info['field_index'] . '`, `t`.`' . $info['field_id'] . '`';
8809
- }
8810
 
8811
- if ( 'table' === pods_var_raw( 'storage', $info['pod'] ) && ! in_array( $object_type, array(
8812
- 'pod',
8813
- 'table'
8814
- ) ) ) {
8815
- $info['join']['d'] = 'LEFT JOIN `' . $info['pod_table'] . '` AS `d` ON `d`.`id` = `t`.`' . $info['field_id'] . '`';
8816
- //$info[ 'select' ] .= ', `d`.*';
8817
- }
 
8818
 
8819
- if ( ! empty( $info['pod'] ) && is_array( $info['pod'] ) ) {
8820
- $info['recurse'] = true;
 
8821
  }
8822
 
8823
- $info['type'] = $object_type;
8824
- $info['object_name'] = $object;
8825
 
8826
- if ( pods_api_cache() ) {
8827
- if ( ! did_action( 'init' ) ) {
8828
- $transient .= '_pre_init';
8829
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8830
 
8831
- if ( !$transient_cached ) {
8832
- pods_transient_set( $transient, $info );
8833
- }
8834
- }
8835
 
8836
- self::$table_info_cache[ $transient ] = apply_filters( 'pods_api_get_table_info', $info, $object_type, $object, $name, $pod, $field, $this );
 
 
 
8837
 
8838
- return self::$table_info_cache[ $transient ];
8839
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8840
 
8841
- /**
8842
- * Export a package
8843
- *
8844
- * $params['pods'] array Pod Type IDs to export
8845
- * $params['templates'] array Template IDs to export
8846
- * $params['pages'] array Pod Page IDs to export
8847
- * $params['helpers'] array Helper IDs to export
8848
- *
8849
- * @param array $params An associative array of parameters
8850
- *
8851
- * @return array|bool
8852
- *
8853
- * @since 1.9.0
8854
- * @deprecated 2.0.0
8855
- */
8856
- public function export_package( $params ) {
8857
 
8858
- if ( class_exists( 'Pods_Migrate_Packages' ) ) {
8859
- return Pods_Migrate_Packages::export( $params );
8860
- }
8861
 
8862
- return false;
8863
- }
8864
 
8865
- /**
8866
- * Replace an existing package
8867
- *
8868
- * @param mixed $data (optional) An associative array containing a package, or the json encoded package
8869
- *
8870
- * @return bool
8871
- *
8872
- * @since 1.9.8
8873
- * @deprecated 2.0.0
8874
- */
8875
- public function replace_package( $data = false ) {
8876
 
8877
- return $this->import_package( $data, true );
8878
- }
 
 
8879
 
8880
- /**
8881
- * Import a package
8882
- *
8883
- * @param mixed $data (optional) An associative array containing a package, or the json encoded package
8884
- * @param bool $replace (optional) Replace existing items when found
8885
- *
8886
- * @return bool
8887
- *
8888
- * @since 1.9.0
8889
- * @deprecated 2.0.0
8890
- */
8891
- public function import_package( $data = false, $replace = false ) {
8892
 
8893
- if ( class_exists( 'Pods_Migrate_Packages' ) ) {
8894
- return Pods_Migrate_Packages::import( $data, $replace );
8895
- }
 
8896
 
8897
- return false;
8898
- }
8899
 
8900
- /**
8901
- * Validate a package
8902
- *
8903
- * @param array|string $data (optional) An associative array containing a package, or the json encoded package
8904
- * @param bool $output (optional)
8905
- *
8906
- * @return array|bool
8907
- *
8908
- * @since 1.9.0
8909
- * @deprecated 2.0.0
8910
- */
8911
- public function validate_package( $data = false, $output = false ) {
8912
 
8913
- return true;
8914
- }
 
8915
 
8916
- /**
8917
- * Import data from an array or a CSV file.
8918
- *
8919
- * @param mixed $import_data PHP associative array or CSV input
8920
- * @param bool $numeric_mode Use IDs instead of the name field when matching
8921
- * @param string $format Format of import data, options are php or csv
8922
- *
8923
- * @return array IDs of imported items
8924
- *
8925
- * @since 1.7.1
8926
- * @todo This needs some love and use of table_info etc for relationships
8927
- */
8928
- public function import( $import_data, $numeric_mode = false, $format = null ) {
8929
 
8930
- /**
8931
- * @var $wpdb wpdb
8932
- */
8933
- global $wpdb;
8934
 
8935
- if ( null === $format && null !== $this->format ) {
8936
- $format = $this->format;
8937
- }
 
 
 
 
 
 
 
 
 
8938
 
8939
- if ( 'csv' === $format && ! is_array( $import_data ) ) {
8940
- $data = pods_migrate( 'sv', ',' )->parse( $import_data );
8941
 
8942
- $import_data = $data['items'];
8943
- }
 
 
8944
 
8945
- pods_query( "SET NAMES utf8" );
8946
- pods_query( "SET CHARACTER SET utf8" );
8947
 
8948
- // Loop through the array of items
8949
- $ids = array();
8950
 
8951
- // Test to see if it's an array of arrays
8952
- if ( ! is_array( @current( $import_data ) ) ) {
8953
- $import_data = array( $import_data );
8954
- }
 
 
 
8955
 
8956
- $pod = $this->load_pod( array( 'name' => $this->pod ) );
 
8957
 
8958
- if ( false === $pod ) {
8959
- return pods_error( __( 'Pod not found', 'pods' ), $this );
8960
- }
 
 
 
 
 
8961
 
8962
- $fields = array_merge( $pod['fields'], $pod['object_fields'] );
 
 
 
8963
 
8964
- $simple_tableless_objects = PodsForm::simple_tableless_objects();
8965
 
8966
- foreach ( $import_data as $key => $data_row ) {
8967
- $data = array();
8968
 
8969
- // Loop through each field (use $fields so only valid fields get parsed)
8970
- foreach ( $fields as $field_name => $field_data ) {
8971
- if ( ! isset( $data_row[ $field_name ] ) && ! isset( $data_row[ $field_data['label'] ] ) ) {
8972
- continue;
8973
- }
8974
 
8975
- $field_id = $field_data['id'];
8976
- $type = $field_data['type'];
8977
- $pick_object = isset( $field_data['pick_object'] ) ? $field_data['pick_object'] : '';
8978
- $pick_val = isset( $field_data['pick_val'] ) ? $field_data['pick_val'] : '';
 
 
 
8979
 
8980
- if ( isset( $data_row[ $field_name ] ) ) {
8981
- $field_value = $data_row[ $field_name ];
8982
- } else {
8983
- $field_value = $data_row[ $field_data['label'] ];
8984
- }
8985
 
8986
- if ( null !== $field_value && false !== $field_value && '' !== $field_value ) {
8987
- if ( 'pick' === $type || in_array( $type, PodsForm::file_field_types() ) ) {
8988
- $field_values = is_array( $field_value ) ? $field_value : array( $field_value );
8989
- $pick_values = array();
8990
 
8991
- foreach ( $field_values as $pick_value ) {
8992
- if ( in_array( $type, PodsForm::file_field_types() ) || 'media' === $pick_object ) {
8993
- $where = "`guid` = '" . pods_sanitize( $pick_value ) . "'";
8994
 
8995
- if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode ) {
8996
- $where = "`ID` = " . pods_absint( $pick_value );
8997
- }
8998
 
8999
- $result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = 'attachment' AND {$where} ORDER BY `ID`", $this );
 
9000
 
9001
- if ( ! empty( $result ) ) {
9002
- $pick_values[] = $result[0]->id;
9003
- }
9004
- } elseif ( 'pick' === $type ) {
9005
- // @todo This could and should be abstracted better and simplified
9006
- $related_pod = false;
9007
-
9008
- if ( 'pod' === $pick_object ) {
9009
- $related_pod = $this->load_pod( array(
9010
- 'name' => $pick_val,
9011
- 'table_info' => true
9012
- ), false );
9013
- }
9014
 
9015
- if ( empty( $related_pod ) ) {
9016
- $related_pod = array(
9017
- 'id' => 0,
9018
- 'type' => $pick_object
9019
- );
9020
- }
9021
 
9022
- if ( in_array( 'taxonomy', array( $pick_object, $related_pod['type'] ) ) ) {
9023
- $where = "`t`.`name` = '" . pods_sanitize( $pick_value ) . "'";
9024
 
9025
- if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode ) {
9026
- $where = "`tt`.`term_id` = " . pods_absint( $pick_value );
9027
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9028
 
9029
- $result = pods_query( "SELECT `t`.`term_id` AS `id` FROM `{$wpdb->term_taxonomy}` AS `tt` LEFT JOIN `{$wpdb->terms}` AS `t` ON `t`.`term_id` = `tt`.`term_id` WHERE `taxonomy` = '{$pick_val}' AND {$where} ORDER BY `t`.`term_id` LIMIT 1", $this );
 
9030
 
9031
- if ( ! empty( $result ) ) {
9032
- $pick_values[] = $result[0]->id;
9033
- }
9034
- } elseif ( in_array( 'post_type', array(
9035
- $pick_object,
9036
- $related_pod['type']
9037
- ) ) || in_array( 'media', array( $pick_object, $related_pod['type'] ) ) ) {
9038
- $where = "`post_title` = '" . pods_sanitize( $pick_value ) . "'";
9039
-
9040
- if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode ) {
9041
- $where = "`ID` = " . pods_absint( $pick_value );
9042
- }
9043
 
9044
- $result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = '{$pick_val}' AND {$where} ORDER BY `ID` LIMIT 1", $this );
 
 
9045
 
9046
- if ( ! empty( $result ) ) {
9047
- $pick_values[] = $result[0]->id;
9048
- }
9049
- } elseif ( in_array( 'user', array( $pick_object, $related_pod['type'] ) ) ) {
9050
- $where = "`user_login` = '" . pods_sanitize( $pick_value ) . "'";
9051
 
9052
- if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode ) {
9053
- $where = "`ID` = " . pods_absint( $pick_value );
9054
- }
9055
 
9056
- $result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->users}` WHERE {$where} ORDER BY `ID` LIMIT 1", $this );
 
 
9057
 
9058
- if ( ! empty( $result ) ) {
9059
- $pick_values[] = $result[0]->id;
9060
- }
9061
- } elseif ( in_array( 'comment', array( $pick_object, $related_pod['type'] ) ) ) {
9062
- $where = "`comment_ID` = " . pods_absint( $pick_value );
9063
 
9064
- $result = pods_query( "SELECT `comment_ID` AS `id` FROM `{$wpdb->comments}` WHERE {$where} ORDER BY `ID` LIMIT 1", $this );
 
 
 
 
 
 
 
9065
 
9066
- if ( ! empty( $result ) ) {
9067
- $pick_values[] = $result[0]->id;
9068
- }
9069
- } elseif ( in_array( $pick_object, $simple_tableless_objects ) ) {
9070
- $pick_values[] = $pick_value;
9071
- } elseif ( ! empty( $related_pod['id'] ) ) {
9072
- $where = "`" . $related_pod['field_index'] . "` = '" . pods_sanitize( $pick_value ) . "'";
9073
 
9074
- if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode ) {
9075
- $where = "`" . $related_pod['field_id'] . "` = " . pods_absint( $pick_value );
9076
- }
9077
 
9078
- $result = pods_query( "SELECT `" . $related_pod['field_id'] . "` AS `id` FROM `" . $related_pod['table'] . "` WHERE {$where} ORDER BY `" . $related_pod['field_id'] . "` LIMIT 1", $this );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9079
 
9080
- if ( ! empty( $result ) ) {
9081
- $pick_values[] = $result[0]->id;
9082
- }
9083
- }
9084
- }
9085
- }
9086
 
9087
- $field_value = implode( ',', $pick_values );
9088
- }
 
9089
 
9090
- $data[ $field_name ] = $field_value;
9091
- }
9092
- }
9093
 
9094
- if ( ! empty( $data ) ) {
9095
- $params = array(
9096
- 'pod' => $this->pod,
9097
- 'data' => $data
9098
- );
9099
 
9100
- $ids[] = $this->save_pod_item( $params );
9101
- }
9102
- }
9103
 
9104
- return $ids;
9105
- }
9106
 
9107
- /**
9108
- * Export data from a Pod
9109
- *
9110
- * @param string|object $pod The pod name or Pods object
9111
- * @param array $params An associative array of parameters
9112
- *
9113
- * @return array Data arrays of all exported pod items
9114
- * @since 1.7.1
9115
- */
9116
- public function export( $pod = null, $params = null ) {
9117
 
9118
- if ( empty( $pod ) ) {
9119
- $pod = $this->pod;
 
 
9120
  }
9121
 
9122
- $find = array(
9123
- 'limit' => - 1,
9124
- 'search' => false,
9125
- 'pagination' => false
9126
- );
9127
 
9128
- if ( ! empty( $params ) && isset( $params['params'] ) ) {
9129
- $find = array_merge( $find, (array) $params['params'] );
9130
 
9131
- unset( $params['params'] );
 
9132
 
9133
- $pod = pods( $pod, $find );
9134
- } elseif ( ! is_object( $pod ) ) {
9135
- $pod = pods( $pod, $find );
9136
- }
9137
 
9138
- $data = array();
 
9139
 
9140
- while ( $pod->fetch() ) {
9141
- $data[ $pod->id() ] = $this->export_pod_item( $params, $pod );
 
9142
  }
9143
-
9144
- $data = $this->do_hook( 'export', $data, $pod->pod, $pod );
9145
-
9146
- return $data;
9147
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9148
 
9149
  /**
9150
- * Convert CSV to a PHP array
9151
  *
9152
- * @param string $data The CSV input
 
 
 
 
 
9153
  *
9154
  * @return array
9155
- * @since 1.7.1
9156
  *
9157
- * @deprecated 2.3.5
9158
  */
9159
- public function csv_to_php( $data, $delimiter = ',' ) {
9160
 
9161
- pods_deprecated( "PodsAPI->csv_to_php", '2.3.5' );
9162
 
9163
- $data = pods_migrate( 'sv', $delimiter, $data )->parse();
 
 
9164
 
9165
- return $data['items'];
9166
- }
 
 
9167
 
9168
- /**
9169
- * Clear Pod-related cache
9170
- *
9171
- * @param array $pod
9172
- *
9173
- * @return void
9174
- *
9175
- * @since 2.0.0
9176
- */
9177
- public function cache_flush_pods( $pod = null ) {
9178
 
9179
- /**
9180
- * @var $wpdb wpdb
9181
- */
9182
- global $wpdb;
9183
 
9184
- pods_transient_clear( 'pods' );
9185
- pods_transient_clear( 'pods_components' );
 
 
9186
 
9187
- if ( null !== $pod && is_array( $pod ) ) {
9188
- pods_transient_clear( 'pods_pod_' . $pod['name'] );
9189
- pods_cache_clear( $pod['name'], 'pods-class' );
 
 
 
9190
 
9191
- foreach ( $pod['fields'] as $field ) {
9192
- pods_transient_clear( 'pods_field_' . $pod['name'] . '_' . $field['name'] );
 
9193
  }
9194
 
9195
- if ( in_array( $pod['type'], array( 'post_type', 'taxonomy' ) ) ) {
9196
- pods_transient_clear( 'pods_wp_cpt_ct' );
 
 
 
 
 
 
 
 
 
 
 
9197
  }
9198
- } else {
9199
- pods_transient_clear( 'pods_wp_cpt_ct' );
9200
  }
 
 
9201
 
9202
- // Delete transients in the database
9203
- $wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_pods%'" );
9204
- $wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_timeout_pods%'" );
9205
 
9206
- // Delete Pods Options Cache in the database
9207
- $wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_pods_option_%'" );
 
 
9208
 
9209
- pods_cache_clear( true );
 
9210
 
9211
- pods_transient_set( 'pods_flush_rewrites', 1 );
9212
 
9213
- do_action( 'pods_cache_flushed' );
9214
- }
9215
 
9216
- /**
9217
- * Process a Pod-based form
9218
- *
9219
- * @param mixed $params
9220
- * @param object $obj Pod object
9221
- * @param array $fields Fields being submitted in form ( key => settings )
9222
- * @param string $thank_you URL to send to upon success
9223
- *
9224
- * @return mixed
9225
- *
9226
- * @since 2.0.0
9227
- */
9228
- public function process_form( $params, $obj = null, $fields = null, $thank_you = null ) {
 
9229
 
9230
- $this->display_errors = false;
 
9231
 
9232
- $form = null;
 
9233
 
9234
- $nonce = pods_var( '_pods_nonce', $params );
9235
- $pod = pods_var( '_pods_pod', $params );
9236
- $id = pods_var( '_pods_id', $params );
9237
- $uri = pods_var( '_pods_uri', $params );
9238
- $form = pods_var( '_pods_form', $params );
9239
- $location = pods_var( '_pods_location', $params );
9240
 
9241
- if ( is_object( $obj ) ) {
9242
- $pod = $obj->pod;
9243
- $id = $obj->id();
9244
- }
9245
 
9246
- if ( ! empty( $fields ) ) {
9247
- $fields = array_keys( $fields );
9248
- $form = implode( ',', $fields );
9249
- } else {
9250
- $fields = explode( ',', $form );
9251
  }
 
 
9252
 
9253
- if ( empty( $nonce ) || empty( $pod ) || empty( $uri ) || empty( $fields ) ) {
9254
- return pods_error( __( 'Invalid submission', 'pods' ), $this );
9255
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9256
 
9257
- $uid = pods_session_id();
9258
 
9259
- if ( is_user_logged_in() ) {
9260
- $uid = 'user_' . get_current_user_id();
9261
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9262
 
9263
  $field_hash = wp_create_nonce( 'pods_fields_' . $form );
9264
 
9265
- $action = 'pods_form_' . $pod . '_' . $uid . '_' . $id . '_' . $uri . '_' . $field_hash;
9266
 
9267
- if ( empty( $uid ) ) {
9268
- return pods_error( __( 'Access denied for your session, please refresh and try again.', 'pods' ), $this );
9269
- }
9270
 
9271
- if ( false === wp_verify_nonce( $nonce, $action ) ) {
9272
- return pods_error( __( 'Access denied, please refresh and try again.', 'pods' ), $this );
9273
- }
9274
 
9275
- $data = array();
9276
 
9277
- foreach ( $fields as $field ) {
9278
- $data[ $field ] = pods_var_raw( 'pods_field_' . $field, $params, '' );
9279
- }
9280
 
9281
- $params = array(
9282
- 'pod' => $pod,
9283
- 'id' => $id,
9284
- 'data' => $data,
9285
- 'from' => 'process_form',
9286
  'location' => $location
9287
- );
9288
-
9289
- $id = $this->save_pod_item( $params );
9290
 
9291
- /**
9292
- * Fires after the form has been processed and save_pod_item has run.
9293
- *
9294
- * @param int $id Item ID.
9295
- * @param array $params save_pod_item parameters.
9296
- * @param null|Pods $obj Pod object (if set).
9297
- */
9298
- do_action( 'pods_api_processed_form', $id, $params, $obj );
9299
 
9300
- // Always return $id for AJAX requests.
9301
- if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
9302
- if ( 0 < $id && ! empty( $thank_you ) ) {
9303
- $thank_you = str_replace( 'X_ID_X', $id, $thank_you );
9304
 
9305
- pods_redirect( $thank_you, 302, false );
9306
- }
9307
  }
9308
-
9309
- return $id;
9310
  }
9311
 
 
 
 
9312
  /**
9313
- * Handle filters / actions for the class
 
 
9314
  *
9315
- * @since 2.0.0
9316
  */
9317
- private function do_hook() {
9318
 
9319
- $args = func_get_args();
9320
- if ( empty( $args ) ) {
9321
- return false;
9322
- }
9323
- $name = array_shift( $args );
 
 
 
9324
 
9325
- return pods_do_hook( "api", $name, $args, $this );
9326
- }
 
9327
 
9328
- /**
9329
- * Handle variables that have been deprecated
9330
- *
9331
- * @since 2.0.0
9332
- */
9333
- public function __get( $name ) {
 
 
9334
 
9335
- $name = (string) $name;
 
 
9336
 
9337
- if ( ! isset( $this->deprecated ) ) {
9338
- require_once( PODS_DIR . 'deprecated/classes/PodsAPI.php' );
9339
- $this->deprecated = new PodsAPI_Deprecated( $this );
9340
  }
9341
 
9342
- $var = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9343
 
9344
- if ( isset( $this->deprecated->{$name} ) ) {
9345
- pods_deprecated( "PodsAPI->{$name}", '2.0' );
 
9346
 
9347
- $var = $this->deprecated->{$name};
9348
- } else {
9349
- pods_deprecated( "PodsAPI->{$name}", '2.0' );
9350
- }
 
 
 
 
 
 
 
 
 
 
 
 
9351
 
9352
- return $var;
9353
- }
 
 
 
 
 
 
 
 
 
 
 
9354
 
9355
- /**
9356
- * Handle methods that have been deprecated
9357
- *
9358
- * @since 2.0.0
9359
- */
9360
- public function __call( $name, $args ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9361
 
9362
- $name = (string) $name;
 
 
 
 
 
 
 
 
 
 
 
 
 
9363
 
9364
- if ( ! isset( $this->deprecated ) ) {
9365
- require_once( PODS_DIR . 'deprecated/classes/PodsAPI.php' );
9366
- $this->deprecated = new PodsAPI_Deprecated( $this );
 
 
 
 
 
 
 
 
 
 
 
9367
  }
9368
 
9369
- if ( method_exists( $this->deprecated, $name ) ) {
9370
- return call_user_func_array( array( $this->deprecated, $name ), $args );
9371
- } else {
9372
- pods_deprecated( "PodsAPI::{$name}", '2.0' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9373
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9374
  }
9375
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9376
  /**
9377
  * Filter an array of arrays without causing PHP notices/warnings.
9378
  *
@@ -9386,11 +8639,11 @@ class PodsAPI {
9386
 
9387
  $values = (array) $values;
9388
 
9389
- foreach ( $values as $k => $v ) {
9390
  if ( is_object( $v ) ) {
9391
  // Skip objects
9392
  continue;
9393
- } elseif ( is_array( $v ) ) {
9394
  if ( empty( $v ) ) {
9395
  // Filter values with empty arrays
9396
  unset( $values[ $k ] );
1
  <?php
 
2
  /**
3
  * @package Pods
4
  */
5
  class PodsAPI {
6
 
7
+ /**
8
+ * @var PodsAPI
9
+ */
10
+ static $instance = null;
11
 
12
  /**
13
  * @var array PodsAPI
14
  */
15
  static $instances = array();
16
 
 
 
 
 
17
 
18
+ /**
19
+ * @var bool
20
+ */
21
+ public $display_errors = false;
22
 
23
+ /**
24
+ * @var array|bool|mixed|null|void
25
+ */
26
+ public $pod_data;
27
 
28
+ /**
29
+ * @var
30
+ */
31
+ public $pod;
32
 
33
+ /**
34
+ * @var
35
+ */
36
+ public $pod_id;
37
 
38
+ /**
39
+ * @var
40
+ */
41
+ public $fields;
 
42
 
43
+ /**
44
+ * @var
45
+ * @deprecated 2.0
46
+ */
47
+ public $format = null;
48
+
49
+ /**
50
+ * @var
51
+ */
52
+ private $deprecated;
53
 
54
  /**
55
  * @var array
56
+ * @since 2.5
57
  */
58
  private $fields_cache = array();
59
 
60
  /**
61
  * @var array
62
+ * @since 2.5
63
  *
64
  */
65
  private static $table_info_cache = array();
66
 
67
  /**
68
  * @var array
69
+ * @since 2.5
70
  *
71
  */
72
  private static $related_item_cache = array();
73
 
74
  /**
75
+ * Singleton-ish handling for a basic pods_api() request
76
+ *
77
+ * @param string $pod (optional) The pod name
78
+ * @param string $format (deprecated) Format for import/export, "php" or "csv"
79
+ *
80
+ * @return \PodsAPI
81
+ *
82
+ * @since 2.3.5
83
+ */
84
+ public static function init ( $pod = null, $format = null ) {
 
85
  if ( null !== $pod || null !== $format ) {
86
  if ( ! isset( self::$instances[ $pod ] ) ) {
87
  // Cache API singleton per Pod
88
  self::$instances[ $pod ] = new PodsAPI( $pod, $format );
89
  }
 
90
  return self::$instances[ $pod ];
91
+ }
92
+ elseif ( !is_object( self::$instance ) ) {
93
  self::$instance = new PodsAPI();
94
  }
95
 
96
  return self::$instance;
97
  }
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
+ /**
101
+ * Store and retrieve data programatically
102
+ *
103
+ * @param string $pod (optional) The pod name
104
+ * @param string $format (deprecated) Format for import/export, "php" or "csv"
105
+ *
106
+ * @return \PodsAPI
107
+ *
108
+ * @license http://www.gnu.org/licenses/gpl-2.0.html
109
+ * @since 1.7.1
110
+ */
111
+ public function __construct ( $pod = null, $format = null ) {
112
+ if ( null !== $pod && 0 < strlen( (string) $pod ) ) {
113
+ if ( null !== $format ) {
114
+ $this->format = $format;
115
+
116
+ pods_deprecated( 'pods_api( $pod, $format )', '2.0', 'pods_api( $pod )' );
117
+ }
118
+
119
+ $pod = pods_clean_name( $pod );
120
+
121
+ $pod = $this->load_pod( array( 'name' => $pod, 'table_info' => true ), false );
122
+
123
+ if ( !empty( $pod ) ) {
124
+ $this->pod_data = $pod;
125
+ $this->pod = $pod[ 'name' ];
126
+ $this->pod_id = $pod[ 'id' ];
127
+ $this->fields = $pod[ 'fields' ];
128
+ }
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Save a WP object and its meta
134
+ *
135
+ * @param string $object_type Object type: post|taxonomy|user|comment|setting
136
+ * @param array $data All post data to be saved
137
+ * @param array $meta (optional) Associative array of meta keys and values
138
+ * @param bool $strict (optional) Decides whether the previous saved meta should be deleted or not
139
+ * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
140
+ * @param array $fields (optional) The array of fields and their options, for further processing with
141
+ *
142
+ * @return bool|mixed
143
+ *
144
+ * @since 2.0
145
+ */
146
+ public function save_wp_object ( $object_type, $data, $meta = array(), $strict = false, $sanitized = false, $fields = array() ) {
147
+ if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
148
+ $object_type = 'post';
149
+
150
+ if ( 'taxonomy' == $object_type )
151
+ $object_type = 'term';
152
+
153
+ if ( $sanitized ) {
154
+ $data = pods_unsanitize( $data );
155
+ $meta = pods_unsanitize( $meta );
156
+ }
157
+
158
+ if ( in_array( $object_type, array( 'post', 'term', 'user', 'comment' ) ) )
159
+ return call_user_func( array( $this, 'save_' . $object_type ), $data, $meta, $strict, false, $fields );
160
+ elseif ( 'settings' == $object_type ) {
161
+ // Nothing to save
162
+ if ( empty( $meta ) )
163
+ return true;
164
+
165
+ return $this->save_setting( pods_var( 'option_id', $data ), $meta, false );
166
+ }
167
+
168
+ return false;
169
+ }
170
+
171
+ /**
172
+ * Delete a WP object
173
+ *
174
+ * @param string $object_type Object type: post|user|comment
175
+ * @param int $id Object ID
176
+ * @param bool $force_delete (optional) Force deletion instead of trashing (post types only)
177
+ *
178
+ * @return bool|mixed
179
+ *
180
+ * @since 2.0
181
+ */
182
+ public function delete_wp_object ( $object_type, $id, $force_delete = true ) {
183
+ if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
184
+ $object_type = 'post';
185
+
186
+ if ( 'taxonomy' == $object_type )
187
+ $object_type = 'term';
188
+
189
+ if ( empty( $id ) )
190
+ return false;
191
+
192
+ if ( in_array( $object_type, array( 'post' ) ) )
193
+ return wp_delete_post( $id, $force_delete );
194
+
195
+ if ( function_exists( 'wp_delete_' . $object_type ) )
196
+ return call_user_func( 'wp_delete_' . $object_type, $id );
197
+
198
+ return false;
199
+ }
200
+
201
+ /**
202
+ * Save a post and it's meta
203
+ *
204
+ * @param array $post_data All post data to be saved (using wp_insert_post / wp_update_post)
205
+ * @param array $post_meta (optional) All meta to be saved (set value to null to delete)
206
+ * @param bool $strict (optional) Whether to delete previously saved meta not in $post_meta
207
+ * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
208
+ * @param array $fields (optional) The array of fields and their options, for further processing with
209
+ *
210
+ * @return mixed|void
211
+ *
212
+ * @since 2.0
213
+ */
214
+ public function save_post ( $post_data, $post_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
215
+ $conflicted = pods_no_conflict_check( 'post' );
216
+
217
+ if ( !$conflicted )
218
+ pods_no_conflict_on( 'post' );
219
+
220
+ if ( !is_array( $post_data ) || empty( $post_data ) )
221
+ $post_data = array( 'post_title' => '' );
222
+
223
+ if ( !is_array( $post_meta ) )
224
+ $post_meta = array();
225
+
226
+ if ( $sanitized ) {
227
+ $post_data = pods_unsanitize( $post_data );
228
+ $post_meta = pods_unsanitize( $post_meta );
229
+ }
230
+
231
+ if ( !isset( $post_data[ 'ID' ] ) || empty( $post_data[ 'ID' ] ) )
232
+ $post_data[ 'ID' ] = wp_insert_post( $post_data, true );
233
+ elseif ( 2 < count( $post_data ) || !isset( $post_data[ 'post_type' ] ) )
234
+ $post_data[ 'ID' ] = wp_update_post( $post_data, true );
235
+
236
+ if ( is_wp_error( $post_data[ 'ID' ] ) ) {
237
+ if ( !$conflicted )
238
+ pods_no_conflict_off( 'post' );
239
+
240
+ /**
241
+ * @var $post_error WP_Error
242
+ */
243
+ $post_error = $post_data[ 'ID' ];
244
+
245
+ return pods_error( $post_error->get_error_message(), $this );
246
+ }
247
+
248
+ $this->save_post_meta( $post_data[ 'ID' ], $post_meta, $strict, $fields );
249
+
250
+ if ( !$conflicted )
251
+ pods_no_conflict_off( 'post' );
252
+
253
+ return $post_data[ 'ID' ];
254
+ }
255
+
256
+ /**
257
+ * Save a post's meta
258
+ *
259
+ * @param int $id Post ID
260
+ * @param array $post_meta All meta to be saved (set value to null to delete)
261
+ * @param bool $strict Whether to delete previously saved meta not in $post_meta
262
+ * @param array $fields (optional) The array of fields and their options, for further processing with
263
+ *
264
+ * @return int Id of the post with the meta
265
+ *
266
+ * @since 2.0
267
+ */
268
+ public function save_post_meta ( $id, $post_meta = null, $strict = false, $fields = array() ) {
269
+ $simple_tableless_objects = PodsForm::simple_tableless_objects();
270
+
271
+ $conflicted = pods_no_conflict_check( 'post' );
272
+
273
+ if ( !$conflicted )
274
+ pods_no_conflict_on( 'post' );
275
+
276
+ if ( !is_array( $post_meta ) )
277
+ $post_meta = array();
278
+
279
+ $id = (int) $id;
280
+
281
+ $meta = get_post_meta( $id );
282
+
283
+ foreach ( $meta as $k => $value ) {
284
+ if ( is_array( $value ) && 1 == count( $value ) )
285
+ $meta[ $k ] = current( $value );
286
+ }
287
+
288
+ foreach ( $post_meta as $meta_key => $meta_value ) {
289
+ if ( null === $meta_value || ( $strict && '' === $post_meta[ $meta_key ] ) ) {
290
+ $old_meta_value = '';
291
+
292
+ if ( isset( $meta[ $meta_key ] ) )
293
+ $old_meta_value = $meta[ $meta_key ];
294
+
295
+ delete_post_meta( $id, $meta_key, $old_meta_value );
296
+ }
297
+ else {
298
+ $simple = false;
299
 
300
+ if ( isset( $fields[ $meta_key ] ) ) {
301
+ $field_data = $fields[ $meta_key ];
 
 
 
 
 
 
302
 
303
+ $simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
304
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
 
306
+ if ( $simple ) {
307
+ delete_post_meta( $id, $meta_key );
 
308
 
309
+ update_post_meta( $id, '_pods_' . $meta_key, $meta_value );
 
 
310
 
311
+ if ( ! is_array( $meta_value ) ) {
312
+ $meta_value = array( $meta_value );
313
+ }
 
314
 
315
+ foreach ( $meta_value as $value ) {
316
+ add_post_meta( $id, $meta_key, $value );
317
+ }
318
+ }
319
+ else {
320
+ update_post_meta( $id, $meta_key, $meta_value );
321
+ }
322
  }
323
+ }
324
 
325
+ if ( $strict ) {
326
+ foreach ( $meta as $meta_key => $meta_value ) {
327
+ if ( !isset( $post_meta[ $meta_key ] ) )
328
+ delete_post_meta( $id, $meta_key, $meta_value );
329
+ }
330
+ }
 
 
 
 
 
 
 
 
 
 
 
 
331
 
332
+ if ( !$conflicted )
333
+ pods_no_conflict_off( 'post' );
 
334
 
335
+ return $id;
336
+ }
 
337
 
338
+ /**
339
+ * Save a user and it's meta
340
+ *
341
+ * @param array $user_data All user data to be saved (using wp_insert_user / wp_update_user)
342
+ * @param array $user_meta (optional) All meta to be saved (set value to null to delete)
343
+ * @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
344
+ * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
345
+ * @param array $fields (optional) The array of fields and their options, for further processing with
346
+ *
347
+ * @return int Returns user id on success
348
+ *
349
+ * @since 2.0
350
+ */
351
+ public function save_user ( $user_data, $user_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
352
+ if ( !is_array( $user_data ) || empty( $user_data ) )
353
+ return pods_error( __( 'User data is required but is either invalid or empty', 'pods' ), $this );
354
 
355
+ $conflicted = pods_no_conflict_check( 'user' );
 
 
356
 
357
+ if ( !$conflicted )
358
+ pods_no_conflict_on( 'user' );
 
359
 
360
+ if ( !is_array( $user_meta ) )
361
+ $user_meta = array();
362
 
363
+ if ( $sanitized ) {
364
+ $user_data = pods_unsanitize( $user_data );
365
+ $user_meta = pods_unsanitize( $user_meta );
366
+ }
 
 
 
 
 
 
 
 
 
 
 
367
 
368
+ // Set role
369
+ if ( isset( $user_meta[ 'role' ] ) ) {
370
+ $user_data[ 'role' ] = $user_meta[ 'role' ];
371
 
372
+ unset( $user_meta[ 'role' ] );
 
373
  }
374
 
375
+ if ( !isset( $user_data[ 'ID' ] ) || empty( $user_data[ 'ID' ] ) )
376
+ $user_data[ 'ID' ] = wp_insert_user( $user_data );
377
+ elseif ( 1 < count( $user_data ) )
378
+ wp_update_user( $user_data );
379
 
380
+ if ( is_wp_error( $user_data[ 'ID' ] ) ) {
381
+ if ( !$conflicted )
382
+ pods_no_conflict_off( 'user' );
383
 
384
+ /**
385
+ * @var $user_error WP_Error
386
+ */
387
+ $user_error = $user_data[ 'ID' ];
388
 
389
+ return pods_error( $user_error->get_error_message(), $this );
390
+ }
 
 
 
391
 
392
+ $this->save_user_meta( $user_data[ 'ID' ], $user_meta, $strict, $fields );
 
 
 
393
 
394
+ if ( !$conflicted )
395
+ pods_no_conflict_off( 'user' );
 
 
396
 
397
+ return $user_data[ 'ID' ];
398
+ }
399
 
400
+ /**
401
+ * Save a user meta
402
+ *
403
+ * @param int $id User ID
404
+ * @param array $user_meta (optional) All meta to be saved (set value to null to delete)
405
+ * @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
406
+ * @param array $fields (optional) The array of fields and their options, for further processing with
407
+ *
408
+ * @return int User ID
409
+ *
410
+ * @since 2.0
411
+ *
412
+ */
413
+ public function save_user_meta ( $id, $user_meta = null, $strict = false, $fields = array() ) {
414
+ $simple_tableless_objects = PodsForm::simple_tableless_objects();
415
 
416
+ $conflicted = pods_no_conflict_check( 'user' );
 
 
417
 
418
+ if ( !$conflicted )
419
+ pods_no_conflict_on( 'user' );
420
 
421
+ if ( !is_array( $user_meta ) )
422
+ $user_meta = array();
 
 
 
 
 
 
 
 
 
 
 
423
 
424
+ $id = (int) $id;
425
 
426
+ $meta = get_user_meta( $id );
427
 
428
+ foreach ( $user_meta as $meta_key => $meta_value ) {
429
+ if ( null === $meta_value ) {
430
+ $old_meta_value = '';
431
 
432
+ if ( isset( $meta[ $meta_key ] ) )
433
+ $old_meta_value = $meta[ $meta_key ];
 
434
 
435
+ delete_user_meta( $id, $meta_key, $old_meta_value );
436
+ }
437
+ else {
438
+ $simple = false;
439
 
440
+ if ( isset( $fields[ $meta_key ] ) ) {
441
+ $field_data = $fields[ $meta_key ];
442
 
443
+ $simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
444
+ }
445
+
446
+ if ( $simple ) {
447
+ delete_user_meta( $id, $meta_key );
448
 
449
+ if ( ! is_array( $meta_value ) ) {
450
+ $meta_value = array( $meta_value );
451
+ }
452
 
453
+ foreach ( $meta_value as $value ) {
454
+ add_user_meta( $id, $meta_key, $value );
455
+ }
456
  }
457
+ else {
458
+ update_user_meta( $id, $meta_key, $meta_value );
459
+ }
460
+ }
461
+ }
462
 
463
+ if ( $strict ) {
464
+ foreach ( $meta as $meta_key => $meta_value ) {
465
+ if ( !isset( $user_meta[ $meta_key ] ) )
466
+ delete_user_meta( $id, $meta_key, $user_meta[ $meta_key ] );
467
+ }
468
+ }
469
+
470
+ if ( !$conflicted )
471
+ pods_no_conflict_off( 'user' );
472
+
473
+ return $id;
474
+ }
475
+
476
+ /**
477
+ * Save a comment and it's meta
478
+ *
479
+ * @param array $comment_data All comment data to be saved (using wp_insert_comment / wp_update_comment)
480
+ * @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
481
+ * @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
482
+ * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
483
+ * @param array $fields (optional) The array of fields and their options, for further processing with
484
+ *
485
+ * @return int Comment ID
486
+ *
487
+ * @since 2.0
488
+ */
489
+ public function save_comment ( $comment_data, $comment_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
490
+ if ( !is_array( $comment_data ) || empty( $comment_data ) )
491
+ return pods_error( __( 'Comment data is required but is either invalid or empty', 'pods' ), $this );
492
+
493
+ $conflicted = pods_no_conflict_check( 'comment' );
494
+
495
+ if ( !$conflicted )
496
+ pods_no_conflict_on( 'comment' );
497
+
498
+ if ( !is_array( $comment_meta ) )
499
+ $comment_meta = array();
500
+
501
+ if ( $sanitized ) {
502
+ $comment_data = pods_unsanitize( $comment_data );
503
+ $comment_meta = pods_unsanitize( $comment_meta );
504
+ }
505
+
506
+ if ( !isset( $comment_data[ 'comment_ID' ] ) || empty( $comment_data[ 'comment_ID' ] ) )
507
+ $comment_data[ 'comment_ID' ] = wp_insert_comment( pods_slash( $comment_data ) ); // Expects slashed
508
+ elseif ( 1 < count( $comment_data ) )
509
+ wp_update_comment( $comment_data );
510
+
511
+ if ( is_wp_error( $comment_data[ 'comment_ID' ] ) ) {
512
+ if ( !$conflicted )
513
+ pods_no_conflict_off( 'comment' );
514
+
515
+ /**
516
+ * @var $comment_error WP_Error
517
+ */
518
+ $comment_error = $comment_data[ 'comment_ID' ];
519
+
520
+ return pods_error( $comment_error->get_error_message(), $this );
521
+ }
522
+
523
+ $this->save_comment_meta( $comment_data[ 'comment_ID' ], $comment_meta, $strict, $fields );
524
+
525
+ if ( !$conflicted )
526
+ pods_no_conflict_off( 'comment' );
527
+
528
+ return $comment_data[ 'comment_ID' ];
529
+ }
530
+
531
+ /**
532
+ * Save a comment meta
533
+ *
534
+ * @param int $id Comment ID
535
+ * @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
536
+ * @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
537
+ * @param array $fields (optional) The array of fields and their options, for further processing with
538
+ *
539
+ * @return int Comment ID
540
+ *
541
+ * @since 2.0
542
+ */
543
+ public function save_comment_meta ( $id, $comment_meta = null, $strict = false, $fields = array() ) {
544
+ $simple_tableless_objects = PodsForm::simple_tableless_objects();
545
+
546
+ $conflicted = pods_no_conflict_check( 'comment' );
547
+
548
+ if ( !$conflicted )
549
+ pods_no_conflict_on( 'comment' );
550
+
551
+ if ( !is_array( $comment_meta ) )
552
+ $comment_meta = array();
553
+
554
+ $id = (int) $id;
555
+
556
+ $meta = get_comment_meta( $id );
557
+
558
+ foreach ( $comment_meta as $meta_key => $meta_value ) {
559
+ if ( null === $meta_value ) {
560
+ $old_meta_value = '';
561
+
562
+ if ( isset( $meta[ $meta_key ] ) )
563
+ $old_meta_value = $meta[ $meta_key ];
564
+
565
+ delete_comment_meta( $id, $meta_key, $old_meta_value );
566
+ }
567
+ else {
568
  $simple = false;
569
 
570
  if ( isset( $fields[ $meta_key ] ) ) {
571
  $field_data = $fields[ $meta_key ];
572
 
573
+ $simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
574
  }
575
 
576
  if ( $simple ) {
577
+ delete_comment_meta( $id, $meta_key );
 
 
578
 
579
  if ( ! is_array( $meta_value ) ) {
580
  $meta_value = array( $meta_value );
581
  }
582
 
583
  foreach ( $meta_value as $value ) {
584
+ add_comment_meta( $id, $meta_key, $value );
585
  }
 
 
 
 
 
 
 
 
 
 
586
  }
587
+ else {
588
+ update_comment_meta( $id, $meta_key, $meta_value );
589
+ }
590
+ }
591
+ }
592
+
593
+ if ( $strict ) {
594
+ foreach ( $meta as $meta_key => $meta_value ) {
595
+ if ( !isset( $comment_meta[ $meta_key ] ) )
596
+ delete_comment_meta( (int) $id, $meta_key, $comment_meta[ $meta_key ] );
597
+ }
598
+ }
599
+
600
+ if ( !$conflicted )
601
+ pods_no_conflict_off( 'comment' );
602
+
603
+ return $id;
604
+ }
605
+
606
+ /**
607
+ * Save a taxonomy's term
608
+ *
609
+ * @param array $term_data All term data to be saved (using wp_insert_term / wp_update_term)
610
+ * @param array $term_meta All meta to be saved (set value to null to delete)
611
+ * @param bool $strict (optional) Whether to delete previously saved meta not in $post_meta
612
+ * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
613
+ * @param array $fields (optional) The array of fields and their options, for further processing with
614
+ *
615
+ * @return int Term ID
616
+ *
617
+ * @since 2.0
618
+ */
619
+ public function save_term ( $term_data, $term_meta, $strict = false, $sanitized = false, $fields = array() ) {
620
+ if ( empty( $term_data['taxonomy'] ) ) {
621
+ return 0;
622
  }
623
 
624
+ $conflicted = pods_no_conflict_check( 'taxonomy' );
 
 
625
 
626
+ if ( !is_array( $term_data ) || empty( $term_data ) )
627
+ $term_data = array( 'name' => '' );
628
 
629
+ if ( !$conflicted )
630
+ pods_no_conflict_on( 'taxonomy' );
 
 
 
 
 
 
 
 
 
 
 
 
 
631
 
632
+ if ( !is_array( $term_meta ) )
633
+ $term_meta = array();
 
634
 
635
+ if ( $sanitized ) {
636
+ $term_data = pods_unsanitize( $term_data );
637
+ $term_meta = pods_unsanitize( $term_meta );
638
+ }
639
 
640
+ $taxonomy = $term_data['taxonomy'];
 
 
641
 
642
+ unset( $term_data['taxonomy'] );
 
 
643
 
644
+ if ( empty( $term_data['term_id'] ) ) {
645
+ $term_name = $term_data['name'];
 
 
646
 
647
+ unset( $term_data['name'] );
 
 
648
 
649
+ $term_data['term_id'] = wp_insert_term( $term_name, $taxonomy, $term_data );
650
+ } elseif ( 2 < count( $term_data ) ) {
651
+ $term_data['term_id'] = wp_update_term( $term_data['term_id'], $taxonomy, $term_data );
652
+ }
653
 
654
+ if ( is_wp_error( $term_data['term_id'] ) ) {
655
+ if ( !$conflicted )
656
+ pods_no_conflict_off( 'taxonomy' );
 
 
657
 
658
+ /**
659
+ * @var $term_error WP_Error
660
+ */
661
+ $term_error = $term_data[ 'term_id' ];
662
 
663
+ return pods_error( $term_error->get_error_message(), $this );
664
+ }
665
+ elseif ( is_array( $term_data['term_id'] ) )
666
+ $term_data['term_id'] = $term_data['term_id'][ 'term_id' ];
667
 
668
+ $this->save_term_meta( $term_data['term_id'], $term_meta, $strict, $fields );
 
669
 
670
+ if ( !$conflicted )
671
+ pods_no_conflict_off( 'taxonomy' );
672
 
673
+ return $term_data['term_id'];
674
+ }
 
675
 
676
+ /**
677
+ * Save a term's meta
678
+ *
679
+ * @param int $id Term ID
680
+ * @param array $term_meta All meta to be saved (set value to null to delete)
681
+ * @param bool $strict Whether to delete previously saved meta not in $term_meta
682
+ * @param array $fields (optional) The array of fields and their options, for further processing with
683
+ *
684
+ * @return int Id of the term with the meta
685
+ *
686
+ * @since 2.0
687
+ */
688
+ public function save_term_meta ( $id, $term_meta = null, $strict = false, $fields = array() ) {
689
+ if ( ! function_exists( 'get_term_meta' ) ) {
690
+ return $id;
691
+ }
692
 
693
+ $simple_tableless_objects = PodsForm::simple_tableless_objects();
 
 
 
 
 
 
 
 
 
 
 
 
 
694
 
695
+ $conflicted = pods_no_conflict_check( 'taxonomy' );
696
 
697
+ if ( !$conflicted )
698
+ pods_no_conflict_on( 'taxonomy' );
699
 
700
+ if ( !is_array( $term_meta ) )
701
+ $term_meta = array();
 
702
 
703
+ $id = (int) $id;
 
 
704
 
705
+ $meta = get_term_meta( $id );
706
 
707
+ foreach ( $meta as $k => $value ) {
708
+ if ( is_array( $value ) && 1 == count( $value ) )
709
+ $meta[ $k ] = current( $value );
710
+ }
711
 
712
+ foreach ( $term_meta as $meta_key => $meta_value ) {
713
+ if ( null === $meta_value || ( $strict && '' === $term_meta[ $meta_key ] ) ) {
714
+ $old_meta_value = '';
715
 
716
+ if ( isset( $meta[ $meta_key ] ) )
717
+ $old_meta_value = $meta[ $meta_key ];
 
718
 
719
+ delete_term_meta( $id, $meta_key, $old_meta_value );
720
+ }
721
+ else {
722
  $simple = false;
723
 
724
  if ( isset( $fields[ $meta_key ] ) ) {
725
  $field_data = $fields[ $meta_key ];
726
 
727
+ $simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
728
  }
729
 
730
  if ( $simple ) {
731
+ delete_term_meta( $id, $meta_key );
732
+
733
+ update_term_meta( $id, '_pods_' . $meta_key, $meta_value );
734
 
735
  if ( ! is_array( $meta_value ) ) {
736
  $meta_value = array( $meta_value );
737
  }
738
 
739
  foreach ( $meta_value as $value ) {
740
+ add_term_meta( $id, $meta_key, $value );
741
  }
 
 
 
 
 
 
 
 
 
 
742
  }
743
+ else {
744
+ update_term_meta( $id, $meta_key, $meta_value );
745
+ }
746
+ }
747
+ }
748
+
749
+ if ( $strict ) {
750
+ foreach ( $meta as $meta_key => $meta_value ) {
751
+ if ( !isset( $term_meta[ $meta_key ] ) )
752
+ delete_term_meta( $id, $meta_key, $meta_value );
753
+ }
754
+ }
755
+
756
+ if ( !$conflicted )
757
+ pods_no_conflict_off( 'taxonomy' );
758
+
759
+ return $id;
760
+ }
761
+
762
+ /**
763
+ * Save a set of options
764
+ *
765
+ * @param string $setting Setting group name
766
+ * @param array $option_data All option data to be saved
767
+ * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
768
+ *
769
+ * @return bool
770
+ *
771
+ * @since 2.3
772
+ */
773
+ public function save_setting ( $setting, $option_data, $sanitized = false ) {
774
+ if ( !is_array( $option_data ) || empty( $option_data ) )
775
+ return pods_error( __( 'Setting data is required but is either invalid or empty', 'pods' ), $this );
776
+
777
+ $conflicted = pods_no_conflict_check( 'settings' );
778
+
779
+ if ( !$conflicted )
780
+ pods_no_conflict_on( 'settings' );
781
+
782
+ if ( $sanitized )
783
+ $option_data = pods_unsanitize( $option_data );
784
+
785
+ foreach ( $option_data as $option => $value ) {
786
+ if ( !empty( $setting ) )
787
+ $option = $setting . '_' . $option;
788
+
789
+ update_option( $option, $value );
790
+ }
791
+
792
+ if ( !$conflicted )
793
+ pods_no_conflict_off( 'settings' );
794
+
795
+ return true;
796
+ }
797
+
798
+ /**
799
+ * Rename a WP object's type
800
+ *
801
+ * @param string $object_type Object type: post|taxonomy|comment|setting
802
+ * @param string $old_name The old name
803
+ * @param string $new_name The new name
804
+ *
805
+ * @return bool
806
+ *
807
+ * @since 2.0
808
+ */
809
+ public function rename_wp_object_type ( $object_type, $old_name, $new_name ) {
810
+ /**
811
+ * @var $wpdb wpdb
812
+ */
813
+ global $wpdb;
814
+
815
+ if ( 'post_type' == $object_type )
816
+ $object_type = 'post';
817
+
818
+ if ( 'post' == $object_type ) {
819
+ pods_query( "UPDATE `{$wpdb->posts}` SET `post_type` = %s WHERE `post_type` = %s", array(
820
+ $new_name,
821
+ $old_name
822
+ ) );
823
+ }
824
+ elseif ( 'taxonomy' == $object_type ) {
825
+ pods_query( "UPDATE `{$wpdb->term_taxonomy}` SET `taxonomy` = %s WHERE `taxonomy` = %s", array(
826
+ $new_name,
827
+ $old_name
828
+ ) );
829
+ }
830
+ elseif ( 'comment' == $object_type ) {
831
+ pods_query( "UPDATE `{$wpdb->comments}` SET `comment_type` = %s WHERE `comment_type` = %s", array(
832
+ $new_name,
833
+ $old_name
834
+ ) );
835
+ }
836
+ elseif ( 'settings' == $object_type ) {
837
+ pods_query( "UPDATE `{$wpdb->options}` SET `option_name` = REPLACE( `option_name`, %s, %s ) WHERE `option_name` LIKE '" . pods_sanitize_like( $old_name ) . "_%'", array(
838
+ $new_name . '_',
839
+ $old_name . '_'
840
+ ) );
841
+ }
842
+
843
+ return true;
844
+ }
845
+
846
+ /**
847
+ * Get a list of core WP object fields for a specific object
848
+ *
849
+ * @param string $object The pod type to look for, possible values: post_type, user, comment, taxonomy
850
+ * @param array $pod Array of Pod data
851
+ * @param boolean $refresh Whether to force refresh the information
852
+ *
853
+ * @return array Array of fields
854
+ *
855
+ * @since 2.0
856
+ */
857
+ public function get_wp_object_fields ( $object = 'post_type', $pod = null, $refresh = false ) {
858
+ $pod_name = pods_var_raw( 'name', $pod, $object, null, true );
859
+
860
+ if ( 'media' == $pod_name ) {
861
+ $object = 'post_type';
862
+ $pod_name = 'attachment';
863
  }
864
 
865
+ $fields = false;
866
+
867
+ if ( pods_api_cache() )
868
+ $fields = pods_transient_get( trim( 'pods_api_object_fields_' . $object . $pod_name . '_', '_' ) );
869
+
870
+ if ( false !== $fields && !$refresh )
871
+ return $this->do_hook( 'get_wp_object_fields', $fields, $object, $pod );
872
+
873
+ $fields = array();
874
+
875
+ if ( 'post_type' == $object ) {
876
+ $fields = array(
877
+ 'ID' => array(
878
+ 'name' => 'ID',
879
+ 'label' => 'ID',
880
+ 'type' => 'number',
881
+ 'alias' => array( 'id' ),
882
+ 'options' => array(
883
+ 'number_format' => '9999.99'
884
+ )
885
+ ),
886
+ 'post_title' => array(
887
+ 'name' => 'post_title',
888
+ 'label' => 'Title',
889
+ 'type' => 'text',
890
+ 'alias' => array( 'title', 'name' ),
891
+ 'options' => array(
892
+ 'display_filter' => 'the_title',
893
+ 'display_filter_args' => array( 'post_ID' )
894
+ )
895
+ ),
896
+ 'post_content' => array(
897
+ 'name' => 'post_content',
898
+ 'label' => 'Content',
899
+ 'type' => 'wysiwyg',
900
+ 'alias' => array( 'content' ),
901
+ 'options' => array(
902
+ 'wysiwyg_allowed_html_tags' => '',
903
+ 'display_filter' => 'the_content',
904
+ 'pre_save' => 0
905
+ )
906
+ ),
907
+ 'post_excerpt' => array(
908
+ 'name' => 'post_excerpt',
909
+ 'label' => 'Excerpt',
910
+ 'type' => 'paragraph',
911
+ 'alias' => array( 'excerpt' ),
912
+ 'options' => array(
913
+ 'paragraph_allow_html' => 1,
914
+ 'paragraph_allowed_html_tags' => '',
915
+ 'display_filter' => 'the_excerpt',
916
+ 'pre_save' => 0
917
+ )
918
+ ),
919
+ 'post_author' => array(
920
+ 'name' => 'post_author',
921
+ 'label' => 'Author',
922
+ 'type' => 'pick',
923
+ 'alias' => array( 'author' ),
924
+ 'pick_object' => 'user',
925
+ 'options' => array(
926
+ 'pick_format_type' => 'single',
927
+ 'pick_format_single' => 'autocomplete',
928
+ 'default_value' => '{@user.ID}'
929
+ )
930
+ ),
931
+ 'post_date' => array(
932
+ 'name' => 'post_date',
933
+ 'label' => 'Publish Date',
934
+ 'type' => 'datetime',
935
+ 'alias' => array( 'created', 'date' )
936
+ ),
937
+ 'post_date_gmt' => array(
938
+ 'name' => 'post_date_gmt',
939
+ 'label' => 'Publish Date (GMT)',
940
+ 'type' => 'datetime',
941
+ 'alias' => array(),
942
+ 'hidden' => true
943
+ ),
944
+ 'post_status' => array(
945
+ 'name' => 'post_status',
946
+ 'label' => 'Status',
947
+ 'type' => 'pick',
948
+ 'pick_object' => 'post-status',
949
+ 'default' => $this->do_hook( 'default_status_' . $pod_name, pods_var( 'default_status', pods_var_raw( 'options', $pod ), 'draft', null, true ), $pod ),
950
+ 'alias' => array( 'status' )
951
+ ),
952
+ 'comment_status' => array(
953
+ 'name' => 'comment_status',
954
+ 'label' => 'Comment Status',
955
+ 'type' => 'text',
956
+ 'default' => get_option( 'default_comment_status', 'open' ),
957
+ 'alias' => array(),
958
+ 'data' => array(
959
+ 'open' => __( 'Open', 'pods' ),
960
+ 'closed' => __( 'Closed', 'pods' )
961
+ )
962
+ ),
963
+ 'ping_status' => array(
964
+ 'name' => 'ping_status',
965
+ 'label' => 'Ping Status',
966
+ 'default' => get_option( 'default_ping_status', 'open' ),
967
+ 'type' => 'text',
968
+ 'alias' => array(),
969
+ 'data' => array(
970
+ 'open' => __( 'Open', 'pods' ),
971
+ 'closed' => __( 'Closed', 'pods' )
972
+ )
973
+ ),
974
+ 'post_password' => array(
975
+ 'name' => 'post_password',
976
+ 'label' => 'Password',
977
+ 'type' => 'text',
978
+ 'alias' => array()
979
+ ),
980
+ 'post_name' => array(
981
+ 'name' => 'post_name',
982
+ 'label' => 'Permalink',
983
+ 'type' => 'slug',
984
+ 'alias' => array( 'slug', 'permalink' )
985
+ ),
986
+ 'to_ping' => array(
987
+ 'name' => 'to_ping',
988
+ 'label' => 'To Ping',
989
+ 'type' => 'text',
990
+ 'alias' => array(),
991
+ 'hidden' => true
992
+ ),
993
+ 'pinged' => array(
994
+ 'name' => 'pinged',
995
+ 'label' => 'Pinged',
996
+ 'type' => 'text',
997
+ 'alias' => array(),
998
+ 'hidden' => true
999
+ ),
1000
+ 'post_modified' => array(
1001
+ 'name' => 'post_modified',
1002
+ 'label' => 'Last Modified Date',
1003
+ 'type' => 'datetime',
1004
+ 'alias' => array( 'modified' ),
1005
+ 'hidden' => true
1006
+ ),
1007
+ 'post_modified_gmt' => array(
1008
+ 'name' => 'post_modified_gmt',
1009
+ 'label' => 'Last Modified Date (GMT)',
1010
+ 'type' => 'datetime',
1011
+ 'alias' => array(),
1012
+ 'hidden' => true
1013
+ ),
1014
+ 'post_content_filtered' => array(
1015
+ 'name' => 'post_content_filtered',
1016
+ 'label' => 'Content (filtered)',
1017
+ 'type' => 'paragraph',
1018
+ 'alias' => array(),
1019
+ 'hidden' => true,
1020
+ 'options' => array(
1021
+ 'paragraph_allow_html' => 1,
1022
+ 'paragraph_oembed' => 1,
1023
+ 'paragraph_wptexturize' => 1,
1024
+ 'paragraph_convert_chars' => 1,
1025
+ 'paragraph_wpautop' => 1,
1026
+ 'paragraph_allow_shortcode' => 1,
1027
+ 'paragraph_allowed_html_tags' => ''
1028
+ )
1029
+ ),
1030
+ 'post_parent' => array(
1031
+ 'name' => 'post_parent',
1032
+ 'label' => 'Parent',
1033
+ 'type' => 'pick',
1034
+ 'pick_object' => 'post_type',
1035
+ 'pick_val' => '__current__',
1036
+ 'alias' => array( 'parent' ),
1037
+ 'data' => array(),
1038
+ 'hidden' => true
1039
+ ),
1040
+ 'guid' => array(
1041
+ 'name' => 'guid',
1042
+ 'label' => 'GUID',
1043
+ 'type' => 'text',
1044
+ 'alias' => array(),
1045
+ 'hidden' => true
1046
+ ),
1047
+ 'menu_order' => array(
1048
+ 'name' => 'menu_order',
1049
+ 'label' => 'Menu Order',
1050
+ 'type' => 'number',
1051
+ 'alias' => array(),
1052
+ 'options' => array(
1053
+ 'number_format' => '9999.99'
1054
+ )
1055
+ ),
1056
+ 'post_type' => array(
1057
+ 'name' => 'post_type',
1058
+ 'label' => 'Type',
1059
+ 'type' => 'text',
1060
+ 'alias' => array( 'type' ),
1061
+ 'hidden' => true
1062
+ ),
1063
+ 'post_mime_type' => array(
1064
+ 'name' => 'post_mime_type',
1065
+ 'label' => 'Mime Type',
1066
+ 'type' => 'text',
1067
+ 'alias' => array(),
1068
+ 'hidden' => true
1069
+ ),
1070
+ 'comment_count' => array(
1071
+ 'name' => 'comment_count',
1072
+ 'label' => 'Comment Count',
1073
+ 'type' => 'number',
1074
+ 'alias' => array(),
1075
+ 'hidden' => true
1076
+ )
1077
+ );
1078
+
1079
+ if ( !empty( $pod ) ) {
1080
+ $taxonomies = get_object_taxonomies( $pod_name, 'objects' );
1081
+
1082
+ foreach ( $taxonomies as $taxonomy ) {
1083
+ $fields[ $taxonomy->name ] = array(
1084
+ 'name' => $taxonomy->name,
1085
+ 'label' => $taxonomy->labels->name,
1086
+ 'type' => 'taxonomy',
1087
+ 'pick_object' => 'taxonomy',
1088
+ 'pick_val' => $taxonomy->name,
1089
+ 'alias' => array(),
1090
+ 'hidden' => true,
1091
+ 'options' => array(
1092
+ 'taxonomy_format_type' => 'multi'
1093
+ )
1094
+ );
1095
+ }
1096
+ }
1097
+ }
1098
+ elseif ( 'user' == $object ) {
1099
+ $fields = array(
1100
+ 'ID' => array(
1101
+ 'name' => 'ID',
1102
+ 'label' => 'ID',
1103
+ 'type' => 'number',
1104
+ 'alias' => array( 'id' ),
1105
+ 'options' => array(
1106
+ 'number_format' => '9999.99'
1107
+ )
1108
+ ),
1109
+ 'user_login' => array(
1110
+ 'name' => 'user_login',
1111
+ 'label' => 'Title',
1112
+ 'type' => 'text',
1113
+ 'alias' => array( 'login' ),
1114
+ 'options' => array(
1115
+ 'required' => 1
1116
+ )
1117
+ ),
1118
+ 'user_nicename' => array(
1119
+ 'name' => 'user_nicename',
1120
+ 'label' => 'Permalink',
1121
+ 'type' => 'slug',
1122
+ 'alias' => array( 'nicename', 'slug', 'permalink' )
1123
+ ),
1124
+ 'display_name' => array(
1125
+ 'name' => 'display_name',
1126
+ 'label' => 'Display Name',
1127
+ 'type' => 'text',
1128
+ 'alias' => array( 'title', 'name' )
1129
+ ),
1130
+ 'user_pass' => array(
1131
+ 'name' => 'user_pass',
1132
+ 'label' => 'Password',
1133
+ 'type' => 'text',
1134
+ 'alias' => array( 'password', 'pass' ),
1135
+ 'options' => array(
1136
+ 'required' => 1,
1137
+ 'text_format_type' => 'password'
1138
+ )
1139
+ ),
1140
+ 'user_email' => array(
1141
+ 'name' => 'user_email',
1142
+ 'label' => 'E-mail',
1143
+ 'type' => 'text',
1144
+ 'alias' => array( 'email' ),
1145
+ 'options' => array(
1146
+ 'required' => 1,
1147
+ 'text_format_type' => 'email'
1148
+ )
1149
+ ),
1150
+ 'user_url' => array(
1151
+ 'name' => 'user_url',
1152
+ 'label' => 'URL',
1153
+ 'type' => 'text',
1154
+ 'alias' => array( 'url', 'website' ),
1155
+ 'options' => array(
1156
+ 'required' => 0,
1157
+ 'text_format_type' => 'website',
1158
+ 'text_format_website' => 'normal'
1159
+ )
1160
+ ),
1161
+ 'user_registered' => array(
1162
+ 'name' => 'user_registered',
1163
+ 'label' => 'Registration Date',
1164
+ 'type' => 'date',
1165
+ 'alias' => array( 'created', 'date', 'registered' ),
1166
+ 'options' => array(
1167
+ 'date_format_type' => 'datetime'
1168
+ )
1169
+ )
1170
+ );
1171
+ }
1172
+ elseif ( 'comment' == $object ) {
1173
+ $fields = array(
1174
+ 'comment_ID' => array(
1175
+ 'name' => 'comment_ID',
1176
+ 'label' => 'ID',
1177
+ 'type' => 'number',
1178
+ 'alias' => array( 'id', 'ID', 'comment_id' ),
1179
+ 'options' => array(
1180
+ 'number_format' => '9999.99'
1181
+ )
1182
+ ),
1183
+ 'comment_content' => array(
1184
+ 'name' => 'comment_content',
1185
+ 'label' => 'Content',
1186
+ 'type' => 'wysiwyg',
1187
+ 'alias' => array( 'content' )
1188
+ ),
1189
+ 'comment_approved' => array(
1190
+ 'name' => 'comment_approved',
1191
+ 'label' => 'Approved',
1192
+ 'type' => 'number',
1193
+ 'alias' => array( 'approved' ),
1194
+ 'options' => array(
1195
+ 'number_format' => '9999.99'
1196
+ )
1197
+ ),
1198
+ 'comment_post_ID' => array(
1199
+ 'name' => 'comment_post_ID',
1200
+ 'label' => 'Post',
1201
+ 'type' => 'pick',
1202
+ 'alias' => array( 'post', 'post_id' ),
1203
+ 'data' => array()
1204
+ ),
1205
+ 'user_id' => array(
1206
+ 'name' => 'user_id',
1207
+ 'label' => 'Author',
1208
+ 'type' => 'pick',
1209
+ 'alias' => array( 'author' ),
1210
+ 'pick_object' => 'user',
1211
+ 'data' => array()
1212
+ ),
1213
+ 'comment_date' => array(
1214
+ 'name' => 'comment_date',
1215
+ 'label' => 'Date',
1216
+ 'type' => 'date',
1217
+ 'alias' => array( 'created', 'date' ),
1218
+ 'options' => array(
1219
+ 'date_format_type' => 'datetime'
1220
+ )
1221
+ ),
1222
+ 'comment_author' => array(
1223
+ 'name' => 'comment_author',
1224
+ 'label' => 'Author',
1225
+ 'type' => 'text',
1226
+ 'alias' => array( 'author' )
1227
+ ),
1228
+ 'comment_author_email' => array(
1229
+ 'name' => 'comment_author_email',
1230
+ 'label' => 'Author E-mail',
1231
+ 'type' => 'email',
1232
+ 'alias' => array( 'author_email' )
1233
+ ),
1234
+ 'comment_author_url' => array(
1235
+ 'name' => 'comment_author_url',
1236
+ 'label' => 'Author URL',
1237
+ 'type' => 'text',
1238
+ 'alias' => array( 'author_url' )
1239
+ ),
1240
+ 'comment_author_IP' => array(
1241
+ 'name' => 'comment_author_IP',
1242
+ 'label' => 'Author IP',
1243
+ 'type' => 'text',
1244
+ 'alias' => array( 'author_IP' )
1245
+ ),
1246
+ 'comment_type' => array(
1247
+ 'name' => 'comment_type',
1248
+ 'label' => 'Type',
1249
+ 'type' => 'text',
1250
+ 'alias' => array( 'type' ),
1251
+ 'hidden' => true
1252
+ ),
1253
+ 'comment_parent' => array(
1254
+ 'name' => 'comment_parent',
1255
+ 'label' => 'Parent',
1256
+ 'type' => 'pick',
1257
+ 'pick_object' => 'comment',
1258
+ 'pick_val' => '__current__',
1259
+ 'alias' => array( 'parent' ),
1260
+ 'data' => array(),
1261
+ 'hidden' => true
1262
+ )
1263
+ );
1264
+ }
1265
+ elseif ( 'taxonomy' == $object ) {
1266
+ $fields = array(
1267
+ 'term_id' => array(
1268
+ 'name' => 'term_id',
1269
+ 'label' => 'ID',
1270
+ 'type' => 'number',
1271
+ 'alias' => array( 'id', 'ID' ),
1272
+ 'options' => array(
1273
+ 'number_format' => '9999.99'
1274
+ )
1275
+ ),
1276
+ 'name' => array(
1277
+ 'name' => 'name',
1278
+ 'label' => 'Title',
1279
+ 'type' => 'text',
1280
+ 'alias' => array( 'title' )
1281
+ ),
1282
+ 'slug' => array(
1283
+ 'name' => 'slug',
1284
+ 'label' => 'Permalink',
1285
+ 'type' => 'slug',
1286
+ 'alias' => array( 'permalink' )
1287
+ ),
1288
+ 'description' => array(
1289
+ 'name' => 'description',
1290
+ 'label' => 'Description',
1291
+ 'type' => 'wysiwyg',
1292
+ 'alias' => array( 'content' )
1293
+ ),
1294
+ 'taxonomy' => array(
1295
+ 'name' => 'taxonomy',
1296
+ 'label' => 'Taxonomy',
1297
+ 'type' => 'text',
1298
+ 'alias' => array()
1299
+ ),
1300
+ 'parent' => array(
1301
+ 'name' => 'parent',
1302
+ 'label' => 'Parent',
1303
+ 'type' => 'pick',
1304
+ 'pick_object' => 'taxonomy',
1305
+ 'pick_val' => '__current__',
1306
+ 'alias' => array( 'parent' ),
1307
+ 'data' => array(),
1308
+ 'hidden' => true
1309
+ ),
1310
+ 'term_taxonomy_id' => array(
1311
+ 'name' => 'term_taxonomy_id',
1312
+ 'label' => 'Term Taxonomy ID',
1313
+ 'type' => 'number',
1314
+ 'alias' => array(),
1315
+ 'hidden' => true,
1316
+ 'options' => array(
1317
+ 'number_format' => '9999.99'
1318
+ )
1319
+ ),
1320
+ 'term_group' => array(
1321
+ 'name' => 'term_group',
1322
+ 'label' => 'Term Group',
1323
+ 'type' => 'number',
1324
+ 'alias' => array( 'group' ),
1325
+ 'hidden' => true,
1326
+ 'options' => array(
1327
+ 'number_format' => '9999.99'
1328
+ )
1329
+ ),
1330
+ 'count' => array(
1331
+ 'name' => 'count',
1332
+ 'label' => 'Count',
1333
+ 'type' => 'number',
1334
+ 'alias' => array(),
1335
+ 'hidden' => true,
1336
+ 'options' => array(
1337
+ 'number_format' => '9999.99'
1338
+ )
1339
+ )
1340
+ );
1341
+ }
1342
+
1343
+ $fields = $this->do_hook( 'get_wp_object_fields', $fields, $object, $pod );
1344
+
1345
+ foreach ( $fields as $field => $options ) {
1346
+ if ( !isset( $options[ 'alias' ] ) )
1347
+ $options[ 'alias' ] = array();
1348
+ else
1349
+ $options[ 'alias' ] = (array) $options[ 'alias' ];
1350
+
1351
+ if ( !isset( $options[ 'name' ] ) )
1352
+ $options[ 'name' ] = $field;
1353
+
1354
+ $fields[ $field ] = $options;
1355
+ }
1356
+
1357
+ $fields = PodsForm::fields_setup( $fields );
1358
+
1359
+ if ( did_action( 'init' ) && pods_api_cache() )
1360
+ pods_transient_set( trim( 'pods_api_object_fields_' . $object . $pod_name . '_', '_' ), $fields );
1361
+
1362
+ return $fields;
1363
+ }
1364
+
1365
+ /**
1366
+ *
1367
+ * @see PodsAPI::save_pod
1368
+ *
1369
+ * Add a Pod via the Wizard
1370
+ *
1371
+ * $params['create_extend'] string Create or Extend a Content Type
1372
+ * $params['create_pod_type'] string Pod Type (for Creating)
1373
+ * $params['create_name'] string Pod Name (for Creating)
1374
+ * $params['create_label_plural'] string Plural Label (for Creating)
1375
+ * $params['create_label_singular'] string Singular Label (for Creating)
1376
+ * $params['create_storage'] string Storage Type (for Creating Post Types)
1377
+ * $params['create_storage_taxonomy'] string Storage Type (for Creating Taxonomies)
1378
+ * $params['extend_pod_type'] string Pod Type (for Extending)
1379
+ * $params['extend_post_type'] string Post Type (for Extending Post Types)
1380
+ * $params['extend_taxonomy'] string Taxonomy (for Extending Taxonomies)
1381
+ * $params['extend_storage'] string Storage Type (for Extending Post Types / Users / Comments)
1382
+ *
1383
+ * @param array $params An associative array of parameters
1384
+ *
1385
+ * @return bool|int Pod ID
1386
+ * @since 2.0
1387
+ */
1388
+ public function add_pod ( $params ) {
1389
+ $defaults = array(
1390
+ 'create_extend' => 'create',
1391
+ 'create_pod_type' => 'post_type',
1392
+
1393
+ 'create_name' => '',
1394
+ 'create_label_singular' => '',
1395
+ 'create_label_plural' => '',
1396
+ 'create_storage' => 'meta',
1397
+ 'create_storage_taxonomy' => ( function_exists( 'get_term_meta' ) ? 'meta' : 'none' ),
1398
+
1399
+ 'create_setting_name' => '',
1400
+ 'create_label_title' => '',
1401
+ 'create_label_menu' => '',
1402
+ 'create_menu_location' => 'settings',
1403
+
1404
+ 'extend_pod_type' => 'post_type',
1405
+ 'extend_post_type' => 'post',
1406
+ 'extend_taxonomy' => 'category',
1407
+ 'extend_table' => '',
1408
+ 'extend_storage' => 'meta',
1409
+ 'extend_storage_taxonomy' => ( function_exists( 'get_term_meta' ) ? 'meta' : 'table' ),
1410
+ );
1411
+
1412
+ $params = (object) array_merge( $defaults, (array) $params );
1413
+
1414
+ if ( empty( $params->create_extend ) || !in_array( $params->create_extend, array( 'create', 'extend' ) ) )
1415
+ return pods_error( __( 'Please choose whether to Create or Extend a Content Type', 'pods' ), $this );
1416
+
1417
+ $pod_params = array(
1418
+ 'name' => '',
1419
+ 'label' => '',
1420
+ 'type' => '',
1421
+ 'storage' => 'table',
1422
+ 'object' => '',
1423
+ 'options' => array()
1424
+ );
1425
+
1426
+ if ( 'create' == $params->create_extend ) {
1427
+ $label = ucwords( str_replace( '_', ' ', $params->create_name ) );
1428
+
1429
+ if ( !empty( $params->create_label_singular ) )
1430
+ $label = $params->create_label_singular;
1431
+
1432
+ $pod_params[ 'name' ] = $params->create_name;
1433
+ $pod_params[ 'label' ] = ( !empty( $params->create_label_plural ) ? $params->create_label_plural : $label );
1434
+ $pod_params[ 'type' ] = $params->create_pod_type;
1435
+ $pod_params[ 'options' ] = array(
1436
+ 'label_singular' => ( !empty( $params->create_label_singular ) ? $params->create_label_singular : $pod_params[ 'label' ] ),
1437
+ 'public' => 1,
1438
+ 'show_ui' => 1
1439
+ );
1440
+
1441
+ // Auto-generate name if not provided
1442
+ if ( empty( $pod_params[ 'name' ] ) && !empty( $pod_params[ 'options' ][ 'label_singular' ] ) )
1443
+ $pod_params[ 'name' ] = pods_clean_name( $pod_params[ 'options' ][ 'label_singular' ] );
1444
+
1445
+ if ( 'post_type' == $pod_params[ 'type' ] ) {
1446
+ if ( empty( $pod_params[ 'name' ] ) )
1447
+ return pods_error( 'Please enter a Name for this Pod', $this );
1448
+
1449
+ $pod_params[ 'storage' ] = $params->create_storage;
1450
+
1451
+ if ( pods_tableless() )
1452
+ $pod_params[ 'storage' ] = 'meta';
1453
+ }
1454
+ elseif ( 'taxonomy' == $pod_params[ 'type' ] ) {
1455
+ if ( empty( $pod_params[ 'name' ] ) )
1456
+ return pods_error( 'Please enter a Name for this Pod', $this );
1457
+
1458
+ $pod_params[ 'storage' ] = $params->create_storage_taxonomy;
1459
+
1460
+ if ( pods_tableless() )
1461
+ $pod_params[ 'storage' ] = ( function_exists( 'get_term_meta' ) ? 'meta' : 'none' );
1462
 
1463
+ $pod_params['options']['hierarchical'] = 1;
1464
+ }
1465
+ elseif ( 'pod' == $pod_params[ 'type' ] ) {
1466
+ if ( empty( $pod_params[ 'name' ] ) )
1467
+ return pods_error( 'Please enter a Name for this Pod', $this );
1468
+
1469
+ if ( pods_tableless() ) {
1470
+ $pod_params[ 'type' ] = 'post_type';
1471
+ $pod_params[ 'storage' ] = 'meta';
1472
+ }
1473
+ }
1474
+ elseif ( 'settings' == $pod_params[ 'type' ] ) {
1475
+ $pod_params[ 'name' ] = $params->create_setting_name;
1476
+ $pod_params[ 'label' ] = ( !empty( $params->create_label_title ) ? $params->create_label_title : ucwords( str_replace( '_', ' ', $params->create_setting_name ) ) );
1477
+ $pod_params[ 'options' ] = array(
1478
+ 'menu_name' => ( !empty( $params->create_label_menu ) ? $params->create_label_menu : $pod_params[ 'label' ] ),
1479
+ 'menu_location' => $params->create_menu_location
1480
+ );
1481
+ $pod_params[ 'storage' ] = 'none';
1482
+
1483
+ // Auto-generate name if not provided
1484
+ if ( empty( $pod_params[ 'name' ] ) && !empty( $pod_params[ 'label' ] ) )
1485
+ $pod_params[ 'name' ] = pods_clean_name( $pod_params[ 'label' ] );
1486
+
1487
+ if ( empty( $pod_params[ 'name' ] ) )
1488
+ return pods_error( 'Please enter a Name for this Pod', $this );
1489
+ }
1490
+ }
1491
+ elseif ( 'extend' == $params->create_extend ) {
1492
+ $pod_params[ 'type' ] = $params->extend_pod_type;
1493
+
1494
+ if ( 'post_type' == $pod_params[ 'type' ] ) {
1495
+ $pod_params[ 'storage' ] = $params->extend_storage;
1496
+
1497
+ if ( pods_tableless() )
1498
+ $pod_params[ 'storage' ] = 'meta';
1499
+
1500
+ $pod_params[ 'name' ] = $params->extend_post_type;
1501
+ }
1502
+ elseif ( 'taxonomy' == $pod_params[ 'type' ] ) {
1503
+ $pod_params[ 'storage' ] = $params->extend_storage_taxonomy;
1504
+
1505
+ if ( pods_tableless() )
1506
+ $pod_params[ 'storage' ] = ( function_exists( 'get_term_meta' ) ? 'meta' : 'none' );
1507
+
1508
+ $pod_params[ 'name' ] = $params->extend_taxonomy;
1509
+ }
1510
+ elseif ( 'table' == $pod_params[ 'type' ] ) {
1511
+ $pod_params[ 'storage' ] = 'table';
1512
+ $pod_params[ 'name' ] = $params->extend_table;
1513
+ }
1514
+ else {
1515
+ $pod_params[ 'storage' ] = $params->extend_storage;
1516
+
1517
+ if ( pods_tableless() )
1518
+ $pod_params[ 'storage' ] = 'meta';
1519
+
1520
+ $pod_params[ 'name' ] = $params->extend_pod_type;
1521
+ }
1522
+
1523
+ $pod_params[ 'label' ] = ucwords( str_replace( '_', ' ', $pod_params[ 'name' ] ) );
1524
+ $pod_params[ 'object' ] = $pod_params[ 'name' ];
1525
+ }
1526
+
1527
+ if ( empty( $pod_params[ 'object' ] ) ) {
1528
+ if ( 'post_type' == $pod_params[ 'type' ] ) {
1529
+ $check = get_post_type_object( $pod_params[ 'name' ] );
1530
+
1531
+ if ( !empty( $check ) )
1532
+ return pods_error( sprintf( __( 'Post Type %s already exists, try extending it instead', 'pods' ), $pod_params[ 'name' ] ), $this );
1533
+
1534
+ $pod_params[ 'options' ][ 'supports_title' ] = 1;
1535
+ $pod_params[ 'options' ][ 'supports_editor' ] = 1;
1536
+ }
1537
+ elseif ( 'taxonomy' == $pod_params[ 'type' ] ) {
1538
+ $check = get_taxonomy( $pod_params[ 'name' ] );
1539
+
1540
+ if ( !empty( $check ) )
1541
+ return pods_error( sprintf( __( 'Taxonomy %s already exists, try extending it instead', 'pods' ), $pod_params[ 'name' ] ), $this );
1542
+ }
1543
+ }
1544
+
1545
+ if ( !empty( $pod_params ) )
1546
+ return $this->save_pod( $pod_params );
1547
+
1548
+ return false;
1549
+ }
1550
+
1551
+ /**
1552
+ * Add or edit a Pod
1553
+ *
1554
+ * $params['id'] int The Pod ID
1555
+ * $params['name'] string The Pod name
1556
+ * $params['label'] string The Pod label
1557
+ * $params['type'] string The Pod type
1558
+ * $params['object'] string The object being extended (if any)
1559
+ * $params['storage'] string The Pod storage
1560
+ * $params['options'] array Options
1561
+ *
1562
+ * @param array $params An associative array of parameters
1563
+ * @param bool $sanitized (optional) Decides whether the params have been sanitized before being passed, will sanitize them if false.
1564
+ * @param bool|int $db (optional) Whether to save into the DB or just return Pod array.
1565
+ *
1566
+ * @return int Pod ID
1567
+ * @since 1.7.9
1568
+ */
1569
+ public function save_pod ( $params, $sanitized = false, $db = true ) {
1570
+ $tableless_field_types = PodsForm::tableless_field_types();
1571
+ $simple_tableless_objects = PodsForm::simple_tableless_objects();
1572
+
1573
+ $load_params = (object) $params;
1574
+
1575
+ if ( isset( $load_params->id ) && isset( $load_params->name ) )
1576
+ unset( $load_params->name );
1577
+
1578
+ if ( isset( $load_params->old_name ) )
1579
+ $load_params->name = $load_params->old_name;
1580
+
1581
+ $load_params->table_info = true;
1582
+
1583
+ $pod = $this->load_pod( $load_params, false );
1584
+
1585
+ $params = (object) $params;
1586
+
1587
+ if ( false === $sanitized )
1588
+ $params = pods_sanitize( $params );
1589
+
1590
+ $old_id = $old_name = $old_storage = null;
1591
 
1592
+ $old_fields = $old_options = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1593
 
1594
+ if ( isset( $params->name ) && ! isset( $params->object ) ) {
1595
+ $params->name = pods_clean_name( $params->name );
1596
  }
1597
 
1598
+ if ( !empty( $pod ) ) {
1599
+ if ( isset( $params->id ) && 0 < $params->id )
1600
+ $old_id = $params->id;
1601
+
1602
+ $params->id = $pod[ 'id' ];
1603
+
1604
+ $old_name = $pod[ 'name' ];
1605
+ $old_storage = $pod[ 'storage' ];
1606
+ $old_fields = $pod[ 'fields' ];
1607
+ $old_options = $pod[ 'options' ];
1608
+
1609
+ if ( !isset( $params->name ) && empty( $params->name ) )
1610
+ $params->name = $pod[ 'name' ];
1611
+
1612
+ if ( $old_name != $params->name && false !== $this->pod_exists( array( 'name' => $params->name ) ) )
1613
+ return pods_error( sprintf( __( 'Pod %s already exists, you cannot rename %s to that', 'pods' ), $params->name, $old_name ), $this );
1614
+
1615
+ if ( $old_name != $params->name && in_array( $pod[ 'type' ], array( 'user', 'comment', 'media' ) ) && in_array( $pod[ 'object' ], array( 'user', 'comment', 'media' ) ) )
1616
+ return pods_error( sprintf( __( 'Pod %s cannot be renamed, it extends an existing WP Object', 'pods' ), $old_name ), $this );
1617
+
1618
+ if ( $old_name != $params->name && in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && !empty( $pod[ 'object' ] ) && $pod[ 'object' ] == $old_name )
1619
+ return pods_error( sprintf( __( 'Pod %s cannot be renamed, it extends an existing WP Object', 'pods' ), $old_name ), $this );
1620
+
1621
+ if ( $old_id != $params->id ) {
1622
+ if ( $params->type == $pod[ 'type' ] && isset( $params->object ) && $params->object == $pod[ 'object' ] )
1623
+ return pods_error( sprintf( __( 'Pod using %s already exists, you can not reuse an object across multiple pods', 'pods' ), $params->object ), $this );
1624
+ else
1625
+ return pods_error( sprintf( __( 'Pod %s already exists', 'pods' ), $params->name ), $this );
1626
+ }
1627
+ }
1628
+ elseif ( in_array( $params->name, array( 'order','orderby','post_type' ) ) && 'post_type' == pods_var( 'type', $params ) ) {
1629
+ return pods_error( sprintf( 'There are certain names that a Custom Post Types cannot be named and unfortunately, %s is one of them.', $params->name ), $this );
1630
+ }
1631
+ else {
1632
+ $pod = array(
1633
+ 'id' => 0,
1634
+ 'name' => $params->name,
1635
+ 'label' => $params->name,
1636
+ 'description' => '',
1637
+ 'type' => 'pod',
1638
+ 'storage' => 'table',
1639
+ 'object' => '',
1640
+ 'alias' => '',
1641
+ 'options' => array(),
1642
+ 'fields' => array()
1643
+ );
1644
+ }
1645
+
1646
+ // Blank out fields and options for AJAX calls (everything should be sent to it for a full overwrite)
1647
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
1648
+ $pod[ 'fields' ] = array();
1649
+ $pod[ 'options' ] = array();
1650
+ }
1651
+
1652
+ // Setup options
1653
+ $options = get_object_vars( $params );
1654
+
1655
+ if ( isset( $options[ 'method' ] ) )
1656
+ unset( $options[ 'method' ] );
1657
+
1658
+ $options_ignore = array(
1659
+ 'object_type',
1660
+ 'object_name',
1661
+ 'table',
1662
+ 'meta_table',
1663
+ 'pod_table',
1664
+ 'field_id',
1665
+ 'field_index',
1666
+ 'field_slug',
1667
+ 'field_type',
1668
+ 'field_parent',
1669
+ 'field_parent_select',
1670
+ 'meta_field_id',
1671
+ 'meta_field_index',
1672
+ 'meta_field_value',
1673
+ 'pod_field_id',
1674
+ 'pod_field_index',
1675
+ 'object_fields',
1676
+ 'join',
1677
+ 'where',
1678
+ 'where_default',
1679
+ 'orderby',
1680
+ 'pod',
1681
+ 'recurse',
1682
+ 'table_info',
1683
+ 'attributes',
1684
+ 'group',
1685
+ 'grouped',
1686
+ 'developer_mode',
1687
+ 'dependency',
1688
+ 'depends-on',
1689
+ 'excludes-on'
1690
+ );
1691
+
1692
+ foreach ( $options_ignore as $ignore ) {
1693
+ if ( isset( $options[ $ignore ] ) )
1694
+ unset( $options[ $ignore ] );
1695
+ }
1696
+
1697
+ $exclude = array(
1698
+ 'id',
1699
+ 'name',
1700
+ 'label',
1701
+ 'description',
1702
+ 'type',
1703
+ 'storage',
1704
+ 'object',
1705
+ 'alias',
1706
+ 'options',
1707
+ 'fields'
1708
+ );
1709
+
1710
+ foreach ( $exclude as $k => $exclude_field ) {
1711
+ $aliases = array( $exclude_field );
1712
+
1713
+ if ( is_array( $exclude_field ) ) {
1714
+ $aliases = array_merge( array( $k ), $exclude_field );
1715
+ $exclude_field = $k;
1716
+ }
1717
+
1718
+ foreach ( $aliases as $alias ) {
1719
+ if ( isset( $options[ $alias ] ) ) {
1720
+ $pod[ $exclude_field ] = pods_trim( $options[ $alias ] );
1721
+
1722
+ unset( $options[ $alias ] );
1723
+ }
1724
+ }
1725
+ }
1726
+
1727
+ if ( pods_tableless() && !in_array( $pod[ 'type' ], array( 'settings', 'table' ) ) ) {
1728
+ if ( 'pod' == $pod[ 'type' ] )
1729
+ $pod[ 'type' ] = 'post_type';
1730
+
1731
+ if ( 'table' == $pod[ 'storage' ] ) {
1732
+ if ( 'taxonomy' == $pod[ 'type' ] && ! function_exists( 'get_term_meta' ) )
1733
+ $pod[ 'storage' ] = 'none';
1734
+ else
1735
+ $pod[ 'storage' ] = 'meta';
1736
+ }
1737
+ }
1738
+
1739
+ $pod[ 'options' ][ 'type' ] = $pod[ 'type' ];
1740
+ $pod[ 'options' ][ 'storage' ] = $pod[ 'storage' ];
1741
+ $pod[ 'options' ][ 'object' ] = $pod[ 'object' ];
1742
+ $pod[ 'options' ][ 'alias' ] = $pod[ 'alias' ];
1743
+
1744
+ $pod[ 'options' ] = array_merge( $pod[ 'options' ], $options );
1745
 
1746
+ /**
1747
+ * @var WP_Query
1748
+ */
1749
+ global $wp_query;
1750
 
1751
+ $reserved_query_vars = array(
1752
+ 'post_type',
1753
+ 'taxonomy',
1754
+ 'output'
1755
+ );
1756
 
1757
+ if ( is_object( $wp_query ) ) {
1758
+ $reserved_query_vars = array_merge( $reserved_query_vars, array_keys( $wp_query->fill_query_vars( array() ) ) );
 
 
 
1759
  }
1760
 
1761
+ if ( isset( $pod[ 'options' ][ 'query_var_string' ] ) ) {
1762
+ if ( in_array( $pod[ 'options' ][ 'query_var_string' ], $reserved_query_vars ) ) {
1763
+ $pod[ 'options' ][ 'query_var_string' ] = $pod[ 'options' ][ 'type' ] . '_' . $pod[ 'options' ][ 'query_var_string' ];
1764
+ }
1765
+ }
1766
+
1767
+ if ( isset( $pod[ 'options' ][ 'query_var' ] ) ) {
1768
+ if ( in_array( $pod[ 'options' ][ 'query_var' ], $reserved_query_vars ) ) {
1769
+ $pod[ 'options' ][ 'query_var' ] = $pod[ 'options' ][ 'type' ] . '_' . $pod[ 'options' ][ 'query_var' ];
1770
+ }
1771
+ }
1772
+
1773
+ if ( strlen( $pod[ 'label' ] ) < 1 )
1774
+ $pod[ 'label' ] = $pod[ 'name' ];
1775
+
1776
+ if ( 'post_type' == $pod[ 'type' ] ) {
1777
+ // Max length for post types are 20 characters
1778
+ $pod[ 'name' ] = substr( $pod[ 'name' ], 0, 20 );
1779
+ }
1780
+ elseif ( 'taxonomy' == $pod[ 'type' ] ) {
1781
+ // Max length for taxonomies are 32 characters
1782
+ $pod[ 'name' ] = substr( $pod[ 'name' ], 0, 32 );
1783
+ }
1784
+
1785
+ $params->id = $pod[ 'id' ];
1786
+ $params->name = $pod[ 'name' ];
1787
+
1788
+ if ( null !== $old_name && $old_name != $params->name && empty( $pod[ 'object' ] ) ) {
1789
+ if ( 'post_type' == $pod[ 'type' ] ) {
1790
+ $check = get_post_type_object( $params->name );
1791
+
1792
+ if ( !empty( $check ) )
1793
+ return pods_error( sprintf( __( 'Post Type %s already exists, you cannot rename %s to that', 'pods' ), $params->name, $old_name ), $this );
1794
+ }
1795
+ elseif ( 'taxonomy' == $pod[ 'type' ] ) {
1796
+ $check = get_taxonomy( $params->name );
1797
+
1798
+ if ( !empty( $check ) )
1799
+ return pods_error( sprintf( __( 'Taxonomy %s already exists, you cannot rename %s to that', 'pods' ), $params->name, $old_name ), $this );
1800
+ }
1801
+ }
1802
+
1803
+ $field_table_operation = true;
1804
+
1805
+ // Add new pod
1806
+ if ( empty( $params->id ) ) {
1807
+ if ( strlen( $params->name ) < 1 )
1808
+ return pods_error( __( 'Pod name cannot be empty', 'pods' ), $this );
1809
+
1810
+ $post_data = array(
1811
+ 'post_name' => $pod[ 'name' ],
1812
+ 'post_title' => $pod[ 'label' ],
1813
+ 'post_content' => $pod[ 'description' ],
1814
+ 'post_type' => '_pods_pod',
1815
+ 'post_status' => 'publish'
1816
+ );
1817
+
1818
+ if ( 'pod' == $pod[ 'type' ] && ( !is_array( $pod[ 'fields' ] ) || empty( $pod[ 'fields' ] ) ) ) {
1819
+ $pod[ 'fields' ] = array();
1820
+
1821
+ $pod[ 'fields' ][ 'name' ] = array(
1822
+ 'name' => 'name',
1823
+ 'label' => 'Name',
1824
+ 'type' => 'text',
1825
+ 'options' => array(
1826
+ 'required' => '1'
1827
+ )
1828
+ );
1829
+
1830
+ $pod[ 'fields' ][ 'created' ] = array(
1831
+ 'name' => 'created',
1832
+ 'label' => 'Date Created',
1833
+ 'type' => 'datetime',
1834
+ 'options' => array(
1835
+ 'datetime_format' => 'ymd_slash',
1836
+ 'datetime_time_type' => '12',
1837
+ 'datetime_time_format' => 'h_mm_ss_A'
1838
+ )
1839
+ );
1840
+
1841
+ $pod[ 'fields' ][ 'modified' ] = array(
1842
+ 'name' => 'modified',
1843
+ 'label' => 'Date Modified',
1844
+ 'type' => 'datetime',
1845
+ 'options' => array(
1846
+ 'datetime_format' => 'ymd_slash',
1847
+ 'datetime_time_type' => '12',
1848
+ 'datetime_time_format' => 'h_mm_ss_A'
1849
+ )
1850
+ );
1851
+
1852
+ $pod[ 'fields' ][ 'author' ] = array(
1853
+ 'name' => 'author',
1854
+ 'label' => 'Author',
1855
+ 'type' => 'pick',
1856
+ 'pick_object' => 'user',
1857
+ 'options' => array(
1858
+ 'pick_format_type' => 'single',
1859
+ 'pick_format_single' => 'autocomplete',
1860
+ 'default_value' => '{@user.ID}'
1861
+ )
1862
+ );
1863
+
1864
+ $pod[ 'fields' ][ 'permalink' ] = array(
1865
+ 'name' => 'permalink',
1866
+ 'label' => 'Permalink',
1867
+ 'type' => 'slug',
1868
+ 'description' => 'Leave blank to auto-generate from Name'
1869
+ );
1870
+
1871
+ if ( !isset( $pod[ 'options' ][ 'pod_index' ] ) )
1872
+ $pod[ 'options' ][ 'pod_index' ] = 'name';
1873
+ }
1874
+
1875
+ $pod = $this->do_hook( 'save_pod_default_pod', $pod, $params, $sanitized, $db );
1876
+
1877
+ $field_table_operation = false;
1878
+ }
1879
+ else {
1880
+ $post_data = array(
1881
+ 'ID' => $pod[ 'id' ],
1882
+ 'post_name' => $pod[ 'name' ],
1883
+ 'post_title' => $pod[ 'label' ],
1884
+ 'post_content' => $pod[ 'description' ],
1885
+ 'post_status' => 'publish'
1886
+ );
1887
+ }
1888
+
1889
+ if ( true === $db ) {
1890
+ if ( !has_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ) ) )
1891
+ add_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ), 100, 6 );
1892
+
1893
+ $conflicted = false;
1894
+
1895
+ // Headway compatibility fix
1896
+ if ( has_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 ) ) {
1897
+ remove_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
1898
+
1899
+ $conflicted = true;
1900
+ }
1901
+
1902
+ $params->id = $this->save_wp_object( 'post', $post_data, $pod[ 'options' ], true, true );
1903
+
1904
+ if ( $conflicted )
1905
+ add_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
1906
+
1907
+ if ( false === $params->id )
1908
+ return pods_error( __( 'Cannot save Pod', 'pods' ), $this );
1909
+ }
1910
+ elseif ( empty( $params->id ) )
1911
+ $params->id = (int) $db;
1912
+
1913
+ $pod[ 'id' ] = $params->id;
1914
+
1915
+ // Setup / update tables
1916
+ if ( 'table' != $pod[ 'type' ] && 'table' == $pod[ 'storage' ] && $old_storage != $pod[ 'storage' ] && $db ) {
1917
+ $definitions = array( "`id` BIGINT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY" );
1918
+
1919
+ $defined_fields = array();
1920
+
1921
+ foreach ( $pod[ 'fields' ] as $field ) {
1922
+ if ( !is_array( $field ) || !isset( $field[ 'name' ] ) || in_array( $field[ 'name' ], $defined_fields ) )
1923
+ continue;
1924
+
1925
+ $defined_fields[] = $field[ 'name' ];
1926
+
1927
+ if ( !in_array( $field[ 'type' ], $tableless_field_types ) || ( 'pick' == $field[ 'type' ] && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) ) {
1928
+ $definition = $this->get_field_definition( $field[ 'type' ], array_merge( $field, pods_var_raw( 'options', $field, array() ) ) );
1929
+
1930
+ if ( 0 < strlen( $definition ) )
1931
+ $definitions[] = "`{$field['name']}` " . $definition;
1932
+ }
1933
+ }
1934
+
1935
+ pods_query( "DROP TABLE IF EXISTS `@wp_pods_{$params->name}`" );
1936
+
1937
+ $result = pods_query( "CREATE TABLE `@wp_pods_{$params->name}` (" . implode( ', ', $definitions ) . ") DEFAULT CHARSET utf8", $this );
1938
+
1939
+ if ( empty( $result ) )
1940
+ return pods_error( __( 'Cannot add Database Table for Pod', 'pods' ), $this );
1941
+
1942
+ }
1943
+ elseif ( 'table' != $pod[ 'type' ] && 'table' == $pod[ 'storage' ] && $pod[ 'storage' ] == $old_storage && null !== $old_name && $old_name != $params->name && $db ) {
1944
+ $result = pods_query( "ALTER TABLE `@wp_pods_{$old_name}` RENAME `@wp_pods_{$params->name}`", $this );
1945
+
1946
+ if ( empty( $result ) )
1947
+ return pods_error( __( 'Cannot update Database Table for Pod', 'pods' ), $this );
1948
+ }
1949
+
1950
+ /**
1951
+ * @var $wpdb wpdb
1952
+ */
1953
+ global $wpdb;
1954
+
1955
+ if ( null !== $old_name && $old_name != $params->name && $db ) {
1956
+ // Rename items in the DB pointed at the old WP Object names
1957
+ if ( 'post_type' == $pod[ 'type' ] && empty( $pod[ 'object' ] ) ) {
1958
+ $this->rename_wp_object_type( 'post', $old_name, $params->name );
1959
+ }
1960
+ elseif ( 'taxonomy' == $pod[ 'type' ] && empty( $pod[ 'object' ] ) ) {
1961
+ $this->rename_wp_object_type( 'taxonomy', $old_name, $params->name );
1962
+ }
1963
+ elseif ( 'comment' == $pod[ 'type' ] && empty( $pod[ 'object' ] ) ) {
1964
+ $this->rename_wp_object_type( 'comment', $old_name, $params->name );
1965
+ }
1966
+ elseif ( 'settings' == $pod[ 'type' ] ) {
1967
+ $this->rename_wp_object_type( 'settings', $old_name, $params->name );
1968
  }
1969
 
1970
+ // Sync any related fields if the name has changed
1971
+ $fields = pods_query( "
1972
+ SELECT `p`.`ID`
1973
+ FROM `{$wpdb->posts}` AS `p`
1974
+ LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
1975
+ LEFT JOIN `{$wpdb->postmeta}` AS `pm2` ON `pm2`.`post_id` = `p`.`ID`
1976
+ WHERE
1977
+ `p`.`post_type` = '_pods_field'
1978
+ AND `pm`.`meta_key` = 'pick_object'
1979
+ AND (
1980
+ `pm`.`meta_value` = 'pod'
1981
+ OR `pm`.`meta_value` = '" . $pod[ 'type' ] . "'
1982
+ )
1983
+ AND `pm2`.`meta_key` = 'pick_val'
1984
+ AND `pm2`.`meta_value` = '{$old_name}'
1985
+ " );
1986
+
1987
+ if ( !empty( $fields ) ) {
1988
+ foreach ( $fields as $field ) {
1989
+ update_post_meta( $field->ID, 'pick_object', $pod[ 'type' ] );
1990
+ update_post_meta( $field->ID, 'pick_val', $params->name );
1991
+ }
1992
+ }
1993
+
1994
+ $fields = pods_query( "
1995
+ SELECT `p`.`ID`
1996
+ FROM `{$wpdb->posts}` AS `p`
1997
+ LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
1998
+ WHERE
1999
+ `p`.`post_type` = '_pods_field'
2000
+ AND `pm`.`meta_key` = 'pick_object'
2001
+ AND (
2002
+ `pm`.`meta_value` = 'pod-{$old_name}'
2003
+ OR `pm`.`meta_value` = '" . $pod[ 'type' ] . "-{$old_name}'
2004
+ )
2005
+ " );
2006
 
2007
+ if ( !empty( $fields ) ) {
2008
+ foreach ( $fields as $field ) {
2009
+ update_post_meta( $field->ID, 'pick_object', $pod[ 'type' ] );
2010
+ update_post_meta( $field->ID, 'pick_val', $params->name );
2011
+ }
2012
+ }
2013
+ }
2014
 
2015
+ // Sync built-in options for post types and taxonomies
2016
+ if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && empty( $pod[ 'object' ] ) && $db ) {
2017
+ // Build list of 'built_in' for later
2018
+ $built_in = array();
2019
 
2020
+ foreach ( $pod[ 'options' ] as $key => $val ) {
2021
+ if ( false === strpos( $key, 'built_in_' ) )
2022
+ continue;
2023
+ elseif ( false !== strpos( $key, 'built_in_post_types_' ) )
2024
+ $built_in_type = 'post_type';
2025
+ elseif ( false !== strpos( $key, 'built_in_taxonomies_' ) )
2026
+ $built_in_type = 'taxonomy';
2027
+ else
2028
+ continue;
2029
 
2030
+ if ( $built_in_type == $pod[ 'type' ] )
2031
+ continue;
2032
 
2033
+ if ( !isset( $built_in[ $built_in_type ] ) )
2034
+ $built_in[ $built_in_type ] = array();
 
 
 
 
 
 
 
 
 
 
 
2035
 
2036
+ $built_in_object = str_replace( array( 'built_in_post_types_', 'built_in_taxonomies_' ), '', $key );
2037
 
2038
+ $built_in[ $built_in_type ][ $built_in_object ] = (int) $val;
2039
+ }
2040
 
2041
+ $lookup_option = $lookup_built_in = false;
 
 
2042
 
2043
+ $lookup_name = $pod[ 'name' ];
 
 
2044
 
2045
+ if ( 'post_type' == $pod[ 'type' ] ) {
2046
+ $lookup_option = 'built_in_post_types_' . $lookup_name;
2047
+ $lookup_built_in = 'taxonomy';
2048
+ }
2049
+ elseif ( 'taxonomy' == $pod[ 'type' ] ) {
2050
+ $lookup_option = 'built_in_taxonomies_' . $lookup_name;
2051
+ $lookup_built_in = 'post_type';
2052
+ }
2053
 
2054
+ if ( !empty( $lookup_option ) && !empty( $lookup_built_in ) && isset( $built_in[ $lookup_built_in ] ) ) {
2055
+ foreach ( $built_in[ $lookup_built_in ] as $built_in_object => $val ) {
2056
+ $search_val = 1;
2057
 
2058
+ if ( 1 == $val )
2059
+ $search_val = 0;
 
2060
 
2061
+ $query = "SELECT p.ID FROM {$wpdb->posts} AS p
2062
+ LEFT JOIN {$wpdb->postmeta} AS pm ON pm.post_id = p.ID AND pm.meta_key = '{$lookup_option}'
2063
+ LEFT JOIN {$wpdb->postmeta} AS pm2 ON pm2.post_id = p.ID AND pm2.meta_key = 'type' AND pm2.meta_value = '{$lookup_built_in}'
2064
+ LEFT JOIN {$wpdb->postmeta} AS pm3 ON pm3.post_id = p.ID AND pm3.meta_key = 'object' AND pm3.meta_value = ''
2065
+ WHERE p.post_type = '_pods_pod' AND p.post_name = '{$built_in_object}'
2066
+ AND pm2.meta_id IS NOT NULL
2067
+ AND ( pm.meta_id IS NULL OR pm.meta_value = {$search_val} )";
2068
 
2069
+ $results = pods_query( $query );
 
 
2070
 
2071
+ if ( !empty( $results ) ) {
2072
+ foreach ( $results as $the_pod ) {
2073
+ delete_post_meta( $the_pod->ID, $lookup_option );
2074
 
2075
+ add_post_meta( $the_pod->ID, $lookup_option, $val );
2076
+ }
2077
+ }
2078
+ }
2079
+ }
2080
+ }
2081
 
2082
+ $saved = array();
2083
+ $errors = array();
2084
 
2085
+ $field_index_change = false;
2086
+ $field_index_id = 0;
 
2087
 
2088
+ $id_required = false;
 
 
 
 
 
 
 
2089
 
2090
+ $field_index = pods_var( 'pod_index', $pod[ 'options' ], 'id', null, true );
 
 
 
 
 
 
2091
 
2092
+ if ( 'pod' == $pod[ 'type' ] && !empty( $pod[ 'fields' ] ) && isset( $pod[ 'fields' ][ $field_index ] ) )
2093
+ $field_index_id = $pod[ 'fields' ][ $field_index ];
 
2094
 
2095
+ if ( isset( $params->fields ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
2096
+ $fields = array();
2097
 
2098
+ if ( isset( $params->fields ) ) {
2099
+ $params->fields = (array) $params->fields;
 
 
 
 
 
 
 
 
 
 
 
 
 
2100
 
2101
+ $weight = 0;
 
 
2102
 
2103
+ foreach ( $params->fields as $field ) {
2104
+ if ( !is_array( $field ) || !isset( $field[ 'name' ] ) )
2105
+ continue;
2106
 
2107
+ if ( !isset( $field[ 'weight' ] ) ) {
2108
+ $field[ 'weight' ] = $weight;
 
2109
 
2110
+ $weight++;
2111
+ }
 
2112
 
2113
+ $fields[ $field[ 'name' ] ] = $field;
2114
+ }
2115
+ }
2116
 
2117
+ $weight = 0;
 
 
 
2118
 
2119
+ $saved_field_ids = array();
2120
 
2121
+ foreach ( $pod[ 'fields' ] as $k => $field ) {
2122
+ if ( !empty( $old_id ) && ( !is_array( $field ) || !isset( $field[ 'name' ] ) || !isset( $fields[ $field[ 'name' ] ] ) ) ) {
2123
+ // Iterative change handling for setup-edit.php
2124
+ if ( !is_array( $field ) && isset( $old_fields[ $k ] ) )
2125
+ $saved[ $old_fields[ $k ][ 'name' ] ] = true;
2126
 
2127
+ continue;
2128
+ }
2129
 
2130
+ if ( !empty( $old_id ) )
2131
+ $field = array_merge( $field, $fields[ $field[ 'name' ] ] );
2132
 
2133
+ $field[ 'pod' ] = $pod;
 
 
 
2134
 
2135
+ if ( !isset( $field[ 'weight' ] ) ) {
2136
+ $field[ 'weight' ] = $weight;
 
 
2137
 
2138
+ $weight++;
2139
+ }
 
 
2140
 
2141
+ if ( 0 < $field_index_id && pods_var( 'id', $field ) == $field_index_id )
2142
+ $field_index_change = $field[ 'name' ];
 
 
2143
 
2144
+ if ( 0 < pods_var( 'id', $field ) )
2145
+ $id_required = true;
2146
 
2147
+ if ( $id_required )
2148
+ $field[ 'id_required' ] = true;
 
2149
 
2150
+ $field_data = $field;
 
2151
 
2152
+ $field = $this->save_field( $field_data, $field_table_operation, true, $db );
 
 
 
 
 
 
 
 
 
 
 
 
2153
 
2154
+ if ( true !== $db ) {
2155
+ $pod[ 'fields' ][ $k ] = $field;
2156
+ $saved_field_ids[] = $field[ 'id' ];
2157
+ }
2158
+ else {
2159
+ if ( !empty( $field ) && 0 < $field ) {
2160
+ $saved[ $field_data[ 'name' ] ] = true;
2161
+ $saved_field_ids[] = $field;
2162
+ }
2163
+ else
2164
+ $errors[] = sprintf( __( 'Cannot save the %s field', 'pods' ), $field_data[ 'name' ] );
2165
+ }
2166
+ }
2167
+
2168
+ if ( true === $db ) {
2169
+ foreach ( $old_fields as $field ) {
2170
+ if ( isset( $pod[ 'fields' ][ $field[ 'name' ] ] ) || isset( $saved[ $field[ 'name' ] ] ) || in_array( $field[ 'id' ], $saved_field_ids ) )
2171
+ continue;
2172
+
2173
+ if ( $field[ 'id' ] == $field_index_id )
2174
+ $field_index_change = 'id';
2175
+ elseif ( $field[ 'name' ] == $field_index )
2176
+ $field_index_change = 'id';
2177
+
2178
+ $this->delete_field( array(
2179
+ 'id' => (int) $field[ 'id' ],
2180
+ 'name' => $field[ 'name' ],
2181
+ 'pod' => $pod
2182
+ ), $field_table_operation );
2183
+ }
2184
+ }
2185
+
2186
+ // Update field index if the name has changed or the field has been removed
2187
+ if ( false !== $field_index_change && true === $db )
2188
+ update_post_meta( $pod[ 'id' ], 'pod_index', $field_index_change );
2189
+ }
2190
 
2191
+ if ( !empty( $errors ) )
2192
+ return pods_error( $errors, $this );
2193
 
2194
+ $this->cache_flush_pods( $pod );
2195
 
2196
+ $refresh_pod = $this->load_pod( array( 'name' => $pod['name'] ), false );
2197
+
2198
+ if ( $refresh_pod ) {
2199
+ $pod = $refresh_pod;
2200
  }
2201
 
2202
+ if ( 'post_type' == $pod['type'] ) {
2203
+ PodsMeta::$post_types[ $pod['id'] ] = $pod;
2204
+ } elseif ( 'taxonomy' == $pod['type'] ) {
2205
+ PodsMeta::$taxonomies[ $pod['id'] ] = $pod;
2206
+ } elseif ( 'media' == $pod['type'] ) {
2207
+ PodsMeta::$media[ $pod['id'] ] = $pod;
2208
+ } elseif ( 'user' == $pod['type'] ) {
2209
+ PodsMeta::$user[ $pod['id'] ] = $pod;
2210
+ } elseif ( 'comment' == $pod['type'] ) {
2211
+ PodsMeta::$comment[ $pod['id'] ] = $pod;
2212
  }
2213
 
2214
+ // Register Post Types / Taxonomies post-registration from PodsInit
2215
+ if ( !empty( PodsInit::$content_types_registered ) && in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && empty( $pod[ 'object' ] ) ) {
2216
+ global $pods_init;
2217
+
2218
+ $pods_init->setup_content_types( true );
2219
+ }
2220
+
2221
+ if ( true === $db )
2222
+ return $pod[ 'id' ];
2223
+ else
2224
+ return $pod;
2225
+ }
2226
+
2227
+ /**
2228
+ * Add or edit a field within a Pod
2229
+ *
2230
+ * $params['id'] int Field ID (id OR pod_id+pod+name required)
2231
+ * $params['pod_id'] int Pod ID (id OR pod_id+pod+name required)
2232
+ * $params['pod'] string Pod name (id OR pod_id+pod+name required)
2233
+ * $params['name'] string Field name (id OR pod_id+pod+name required)
2234
+ * $params['label'] string (optional) Field label
2235
+ * $params['type'] string (optional) Field type (avatar, boolean, code, color, currency, date, datetime, email, file, number, paragraph, password, phone, pick, slug, text, time, website, wysiwyg)
2236
+ * $params['pick_object'] string (optional) Related Object (for relationships)
2237
+ * $params['pick_val'] string (optional) Related Object name (for relationships)
2238
+ * $params['sister_id'] int (optional) Related Field ID (for bidirectional relationships)
2239
+ * $params['weight'] int (optional) Order in which the field appears
2240
+ * $params['options'] array (optional) Options
2241
+ *
2242
+ * @param array $params An associative array of parameters
2243
+ * @param bool $table_operation (optional) Whether or not to handle table operations
2244
+ * @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will sanitize them if false.
2245
+ * @param bool|int $db (optional) Whether to save into the DB or just return field array.
2246
+ *
2247
+ * @return int|array The field ID or field array (if !$db)
2248
+ * @since 1.7.9
2249
+ */
2250
+ public function save_field ( $params, $table_operation = true, $sanitized = false, $db = true ) {
2251
+ /**
2252
+ * @var $wpdb wpdb
2253
+ */
2254
+ global $wpdb;
2255
+
2256
+ if ( true !== $db )
2257
+ $table_operation = false;
2258
+
2259
+ $tableless_field_types = PodsForm::tableless_field_types();
2260
+ $simple_tableless_objects = PodsForm::simple_tableless_objects();
2261
+
2262
+ $params = (object) $params;
2263
+
2264
+ if ( false === $sanitized )
2265
+ $params = pods_sanitize( $params );
2266
+
2267
+ if ( isset( $params->pod_id ) )
2268
+ $params->pod_id = pods_absint( $params->pod_id );
2269
+
2270
+ if ( true !== $db )
2271
+ $params->pod_id = (int) $db;
2272
+
2273
+ $pod = null;
2274
+ $save_pod = false;
2275
+ $id_required = false;
2276
+
2277
+ if ( isset( $params->id_required ) ) {
2278
+ unset( $params->id_required );
2279
+
2280
+ $id_required = true;
2281
+ }
2282
+
2283
+ if ( ( !isset( $params->pod ) || empty( $params->pod ) ) && ( !isset( $params->pod_id ) || empty( $params->pod_id ) ) )
2284
+ return pods_error( __( 'Pod ID or name is required', 'pods' ), $this );
2285
+
2286
+ if ( isset( $params->pod ) && is_array( $params->pod ) ) {
2287
+ $pod = $params->pod;
2288
+
2289
+ $save_pod = true;
2290
+ }
2291
+ elseif ( ( !isset( $params->pod_id ) || empty( $params->pod_id ) ) && ( true === $db || 0 < $db ) )
2292
+ $pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => true ) );
2293
+ elseif ( !isset( $params->pod ) && ( true === $db || 0 < $db ) )
2294
+ $pod = $this->load_pod( array( 'id' => $params->pod_id, 'table_info' => true ) );
2295
+ elseif ( true === $db || 0 < $db )
2296
+ $pod = $this->load_pod( array( 'id' => $params->pod_id, 'name' => $params->pod, 'table_info' => true ) );
2297
+
2298
+ if ( empty( $pod ) && true === $db )
2299
+ return pods_error( __( 'Pod not found', 'pods' ), $this );
2300
+
2301
+ $params->pod_id = $pod[ 'id' ];
2302
+ $params->pod = $pod[ 'name' ];
2303
+ $params->pod_data = $pod;
2304
+
2305
+ $params->name = pods_clean_name( $params->name, true, ( 'meta' == $pod[ 'storage' ] ? false : true ) );
2306
+
2307
+ if ( !isset( $params->id ) )
2308
+ $params->id = 0;
2309
+
2310
+ if ( empty( $params->name ) )
2311
+ return pods_error( 'Pod field name is required', $this );
2312
+
2313
+ $field = $this->load_field( $params );
2314
+
2315
+ unset( $params->pod_data );
2316
+
2317
+ $old_id = $old_name = $old_type = $old_definition = $old_simple = $old_options = $old_sister_id = null;
2318
+
2319
+ if ( !empty( $field ) ) {
2320
+ $old_id = pods_var( 'id', $field );
2321
+ $old_name = pods_clean_name( $field[ 'name' ], true, ( 'meta' == $pod[ 'storage' ] ? false : true ) );
2322
+ $old_type = $field[ 'type' ];
2323
+ $old_options = $field[ 'options' ];
2324
+ $old_sister_id = (int) pods_var( 'sister_id', $old_options, 0 );
2325
+
2326
+ $old_simple = ( 'pick' == $old_type && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) );
2327
+
2328
+ if ( isset( $params->name ) && !empty( $params->name ) )
2329
+ $field[ 'name' ] = $params->name;
2330
+
2331
+ if ( $old_name != $field[ 'name' ] && false !== $this->field_exists( $params ) )
2332
+ return pods_error( sprintf( __( 'Field %s already exists, you cannot rename %s to that', 'pods' ), $field[ 'name' ], $old_name ), $this );
2333
+
2334
+ if ( ( $id_required || !empty( $params->id ) ) && ( empty( $old_id ) || $old_id != $params->id ) )
2335
+ return pods_error( sprintf( __( 'Field %s already exists', 'pods' ), $field[ 'name' ] ), $this );
2336
+
2337
+ if ( empty( $params->id ) )
2338
+ $params->id = $old_id;
2339
+
2340
+ if ( !in_array( $old_type, $tableless_field_types ) || $old_simple ) {
2341
+ $definition = $this->get_field_definition( $old_type, array_merge( $field, $old_options ) );
2342
+
2343
+ if ( 0 < strlen( $definition ) )
2344
+ $old_definition = "`{$old_name}` " . $definition;
2345
+ }
2346
+ }
2347
+ else {
2348
+ $field = array(
2349
+ 'id' => 0,
2350
+ 'pod_id' => $params->pod_id,
2351
+ 'name' => $params->name,
2352
+ 'label' => $params->name,
2353
+ 'description' => '',
2354
+ 'type' => 'text',
2355
+ 'pick_object' => '',
2356
+ 'pick_val' => '',
2357
+ 'sister_id' => '',
2358
+ 'weight' => null,
2359
+ 'options' => array()
2360
+ );
2361
+ }
2362
+
2363
+ // Setup options
2364
+ $options = get_object_vars( $params );
2365
+
2366
+ $options_ignore = array(
2367
+ 'method',
2368
+ 'table_info',
2369
+ 'attributes',
2370
+ 'group',
2371
+ 'grouped',
2372
+ 'developer_mode',
2373
+ 'dependency',
2374
+ 'depends-on',
2375
+ 'excludes-on'
2376
+ );
2377
+
2378
+ foreach ( $options_ignore as $ignore ) {
2379
+ if ( isset( $options[ $ignore ] ) )
2380
+ unset( $options[ $ignore ] );
2381
+ }
2382
+
2383
+ if ( isset( $options[ 'method' ] ) )
2384
+ unset( $options[ 'method' ] );
2385
+ elseif ( isset( $options[ 'table_info' ] ) )
2386
+ unset( $options[ 'table_info' ] );
2387
+
2388
+ $exclude = array(
2389
+ 'id',
2390
+ 'pod_id',
2391
+ 'pod',
2392
+ 'name',
2393
+ 'label',
2394
+ 'description',
2395
+ 'type',
2396
+ 'pick_object',
2397
+ 'pick_val',
2398
+ 'sister_id',
2399
+ 'weight',
2400
+ 'options'
2401
+ );
2402
+
2403
+ foreach ( $exclude as $k => $exclude_field ) {
2404
+ $aliases = array( $exclude_field );
2405
+
2406
+ if ( is_array( $exclude_field ) ) {
2407
+ $aliases = array_merge( array( $k ), $exclude_field );
2408
+ $exclude_field = $k;
2409
+ }
2410
+
2411
+ foreach ( $aliases as $alias ) {
2412
+ if ( isset( $options[ $alias ] ) ) {
2413
+ $field[ $exclude_field ] = pods_trim( $options[ $alias ] );
2414
+
2415
+ unset( $options[ $alias ] );
2416
+ }
2417
+ }
2418
+ }
2419
+
2420
+ if ( strlen( $field[ 'label' ] ) < 1 )
2421
+ $field[ 'label' ] = $field[ 'name' ];
2422
+
2423
+ $field[ 'options' ][ 'type' ] = $field[ 'type' ];
2424
+
2425
+ if ( in_array( $field[ 'options' ][ 'type' ], $tableless_field_types ) ) {
2426
+ // Clean up special drop-down in field editor and save out pick_val
2427
+ $field[ 'pick_object' ] = pods_var( 'pick_object', $field, '', null, true );
2428
+
2429
+ if ( 0 === strpos( $field[ 'pick_object' ], 'pod-' ) ) {
2430
+ $field[ 'pick_val' ] = pods_str_replace( 'pod-', '', $field[ 'pick_object' ], 1 );
2431
+ $field[ 'pick_object' ] = 'pod';
2432
+ }
2433
+ elseif ( 0 === strpos( $field[ 'pick_object' ], 'post_type-' ) ) {
2434
+ $field[ 'pick_val' ] = pods_str_replace( 'post_type-', '', $field[ 'pick_object' ], 1 );
2435
+ $field[ 'pick_object' ] = 'post_type';
2436
+ }
2437
+ elseif ( 0 === strpos( $field[ 'pick_object' ], 'taxonomy-' ) ) {
2438
+ $field[ 'pick_val' ] = pods_str_replace( 'taxonomy-', '', $field[ 'pick_object' ], 1 );
2439
+ $field[ 'pick_object' ] = 'taxonomy';
2440
+ }
2441
+ elseif ( 'table' == $field[ 'pick_object' ] && 0 < strlen( pods_var_raw( 'pick_table', $field[ 'options' ] ) ) ) {
2442
+ $field[ 'pick_val' ] = $field[ 'options' ][ 'pick_table' ];
2443
+ $field[ 'pick_object' ] = 'table';
2444
+ }
2445
+ elseif ( false === strpos( $field[ 'pick_object' ], '-' ) && !in_array( $field[ 'pick_object' ], array( 'pod', 'post_type', 'taxonomy' ) ) ) {
2446
+ $field[ 'pick_val' ] = '';
2447
+ }
2448
+ elseif ( 'custom-simple' == $field[ 'pick_object' ] ) {
2449
+ $field[ 'pick_val' ] = '';
2450
+ }
2451
+
2452
+ $field[ 'options' ][ 'pick_object' ] = $field[ 'pick_object' ];
2453
+ $field[ 'options' ][ 'pick_val' ] = $field[ 'pick_val' ];
2454
+ $field[ 'options' ][ 'sister_id' ] = pods_var( 'sister_id', $field );
2455
+
2456
+ unset( $field[ 'pick_object' ] );
2457
+ unset( $field[ 'pick_val' ] );
2458
+
2459
+ if ( isset( $field[ 'sister_id' ] ) )
2460
+ unset( $field[ 'sister_id' ] );
2461
+ }
2462
+
2463
+ $field[ 'options' ] = array_merge( $field[ 'options' ], $options );
2464
+
2465
+ $object_fields = (array) pods_var_raw( 'object_fields', $pod, array(), null, true );
2466
+
2467
+ if ( 0 < $old_id && defined( 'PODS_FIELD_STRICT' ) && !PODS_FIELD_STRICT )
2468
+ $params->id = $field[ 'id' ] = $old_id;
2469
+
2470
+ // Add new field
2471
+ if ( !isset( $params->id ) || empty( $params->id ) || empty( $field ) ) {
2472
+ if ( $table_operation && in_array( $field[ 'name' ], array( 'created', 'modified' ) ) && !in_array( $field[ 'type' ], array( 'date', 'datetime' ) ) && ( !defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) )
2473
+ return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
2474
+
2475
+ if ( $table_operation && 'author' == $field[ 'name' ] && 'pick' != $field[ 'type' ] && ( !defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) )
2476
+ return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
2477
+
2478
+ if ( in_array( $field[ 'name' ], array( 'id', 'ID' ) ) )
2479
+ return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
2480
+
2481
+ foreach ( $object_fields as $object_field => $object_field_opt ) {
2482
+ if ( $object_field == $field[ 'name' ] || in_array( $field[ 'name' ], $object_field_opt[ 'alias' ] ) )
2483
+ return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name. Also consider what WordPress and Pods provide you built-in.', 'pods' ), $field[ 'name' ] ), $this );
2484
+ }
2485
+
2486
+ if ( in_array( $field[ 'name' ], array( 'rss' ) ) ) // Reserved post_name values that can't be used as field names
2487
+ $field[ 'name' ] .= '2';
2488
+
2489
+ if ( 'slug' == $field[ 'type' ] && true === $db ) {
2490
+ if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy', 'user' ) ) )
2491
+ return pods_error( __( 'This pod already has an internal WordPress permalink field', 'pods' ), $this );
2492
+
2493
+ $slug_field = get_posts( array(
2494
+ 'post_type' => '_pods_field',
2495
+ 'orderby' => 'menu_order',
2496
+ 'order' => 'ASC',
2497
+ 'posts_per_page' => 1,
2498
+ 'post_parent' => $field[ 'pod_id' ],
2499
+ 'meta_query' => array(
2500
+ array(
2501
+ 'key' => 'type',
2502
+ 'value' => 'slug'
2503
+ )
2504
+ )
2505
+ ) );
2506
+
2507
+ if ( !empty( $slug_field ) )
2508
+ return pods_error( __( 'This pod already has a permalink field', 'pods' ), $this );
2509
+ }
2510
+
2511
+ // Sink the new field to the bottom of the list
2512
+ if ( null === $field[ 'weight' ] ) {
2513
+ $field[ 'weight' ] = 0;
2514
+
2515
+ $bottom_most_field = get_posts( array(
2516
+ 'post_type' => '_pods_field',
2517
+ 'orderby' => 'menu_order',
2518
+ 'order' => 'DESC',
2519
+ 'posts_per_page' => 1,
2520
+ 'post_parent' => $field[ 'pod_id' ]
2521
+ ) );
2522
+
2523
+ if ( !empty( $bottom_most_field ) )
2524
+ $field[ 'weight' ] = pods_absint( $bottom_most_field[ 0 ]->menu_order ) + 1;
2525
+ }
2526
+
2527
+ $field[ 'weight' ] = pods_absint( $field[ 'weight' ] );
2528
+
2529
+ $post_data = array(
2530
+ 'post_name' => $field[ 'name' ],
2531
+ 'post_title' => $field[ 'label' ],
2532
+ 'post_content' => $field[ 'description' ],
2533
+ 'post_type' => '_pods_field',
2534
+ 'post_parent' => $field[ 'pod_id' ],
2535
+ 'post_status' => 'publish',
2536
+ 'menu_order' => $field[ 'weight' ]
2537
+ );
2538
+ }
2539
+ else {
2540
+ if ( in_array( $field[ 'name' ], array( 'id', 'ID' ) ) ) {
2541
+ if ( null !== $old_name )
2542
+ return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
2543
+ else
2544
+ return pods_error( sprintf( __( '%s is not editable', 'pods' ), $field[ 'name' ] ), $this );
2545
+ }
2546
+
2547
+ if ( null !== $old_name && $field[ 'name' ] != $old_name && in_array( $field[ 'name' ], array( 'created', 'modified' ) ) && !in_array( $field[ 'type' ], array( 'date', 'datetime' ) ) && ( !defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) )
2548
+ return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
2549
+
2550
+ if ( null !== $old_name && $field[ 'name' ] != $old_name && 'author' == $field[ 'name' ] && 'pick' != $field[ 'type' ] && ( !defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) )
2551
+ return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
2552
+
2553
+ foreach ( $object_fields as $object_field => $object_field_opt ) {
2554
+ if ( $object_field != $field[ 'name' ] && !in_array( $field[ 'name' ], $object_field_opt[ 'alias' ] ) )
2555
+ continue;
2556
+
2557
+ if ( null !== $old_name )
2558
+ return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
2559
+ else
2560
+ return pods_error( sprintf( __( '%s is not editable', 'pods' ), $field[ 'name' ] ), $this );
2561
+ }
2562
+
2563
+ $post_data = array(
2564
+ 'ID' => $field[ 'id' ],
2565
+ 'post_name' => $field[ 'name' ],
2566
+ 'post_title' => $field[ 'label' ],
2567
+ 'post_content' => $field[ 'description' ]
2568
+ );
2569
+
2570
+ if ( null !== $field[ 'weight' ] ) {
2571
+ $field[ 'weight' ] = pods_absint( $field[ 'weight' ] );
2572
+
2573
+ $post_data[ 'menu_order' ] = $field[ 'weight' ];
2574
+ }
2575
+ }
2576
+
2577
+ if ( true === $db ) {
2578
+ if ( !has_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ) ) )
2579
+ add_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ), 100, 6 );
2580
+
2581
+ $conflicted = false;
2582
+
2583
+ // Headway compatibility fix
2584
+ if ( has_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 ) ) {
2585
+ remove_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
2586
+
2587
+ $conflicted = true;
2588
+ }
2589
+
2590
+ // Store the old field name
2591
+ if ( $old_name && $old_name != $post_data['post_name'] ) {
2592
+ $field['options']['old_name'] = $old_name;
2593
+ }
2594
+
2595
+ $params->id = $this->save_wp_object( 'post', $post_data, $field[ 'options' ], true, true );
2596
+
2597
+ if ( $conflicted )
2598
+ add_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
2599
+
2600
+ if ( false === $params->id )
2601
+ return pods_error( __( 'Cannot save Field', 'pods' ), $this );
2602
+ }
2603
+ else
2604
+ $params->id = $field[ 'name' ];
2605
+
2606
+ $field[ 'id' ] = $params->id;
2607
+
2608
+ $simple = ( 'pick' == $field[ 'type' ] && in_array( pods_var( 'pick_object', $field[ 'options' ] ), $simple_tableless_objects ) );
2609
+
2610
+ $definition = false;
2611
+
2612
+ if ( !in_array( $field[ 'type' ], $tableless_field_types ) || $simple ) {
2613
+ $field_definition = $this->get_field_definition( $field[ 'type' ], array_merge( $field, $field[ 'options' ] ) );
2614
+
2615
+ if ( 0 < strlen( $field_definition ) )
2616
+ $definition = '`' . $field[ 'name' ] . '` ' . $field_definition;
2617
+ }
2618
+
2619
+ $sister_id = (int) pods_var( 'sister_id', $field[ 'options' ], 0 );
2620
+
2621
+ if ( $table_operation && 'table' == $pod[ 'storage' ] && !pods_tableless() ) {
2622
+ if ( !empty( $old_id ) ) {
2623
+ if ( ( $field[ 'type' ] != $old_type || $old_simple != $simple ) && empty( $definition ) )
2624
+ pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` DROP COLUMN `{$old_name}`", false );
2625
+ elseif ( 0 < strlen( $definition ) ) {
2626
+ if ( $old_name != $field[ 'name' ] || $old_simple != $simple ) {
2627
+ $test = false;
2628
+
2629
+ if ( 0 < strlen( $old_definition ) )
2630
+ $test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` CHANGE `{$old_name}` {$definition}", false );
2631
+
2632
+ // If the old field doesn't exist, continue to add a new field
2633
+ if ( false === $test )
2634
+ pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` ADD COLUMN {$definition}", __( 'Cannot create new field', 'pods' ) );
2635
+ }
2636
+ elseif ( null !== $old_definition && $definition != $old_definition ) {
2637
+ $test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` CHANGE `{$old_name}` {$definition}", false );
2638
+
2639
+ // If the old field doesn't exist, continue to add a new field
2640
+ if ( false === $test )
2641
+ pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` ADD COLUMN {$definition}", __( 'Cannot create new field', 'pods' ) );
2642
+ }
2643
+ }
2644
+ }
2645
+ elseif ( 0 < strlen( $definition ) ) {
2646
+ $test = false;
2647
+
2648
+ if ( 0 < strlen( $old_definition ) )
2649
+ $test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` CHANGE `" . $field[ 'name' ] . "` {$definition}", false );
2650
+
2651
+ // If the old field doesn't exist, continue to add a new field
2652
+ if ( false === $test )
2653
+ pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` ADD COLUMN {$definition}", __( 'Cannot create new field', 'pods' ) );
2654
+ }
2655
+ }
2656
+
2657
+ if ( !empty( $old_id ) && 'meta' == $pod[ 'storage' ] && $old_name != $field[ 'name' ] && $pod[ 'meta_table' ] != $pod[ 'table' ] ) {
2658
+ $prepare = array(
2659
+ $field[ 'name' ],
2660
+ $old_name
2661
+ );
2662
+
2663
+ // Users don't have a type
2664
+ if ( !empty( $pod[ 'field_type' ] ) )
2665
+ $prepare[] = $pod[ 'name' ];
2666
+
2667
+ pods_query( "
2668
+ UPDATE `{$pod[ 'meta_table' ]}` AS `m`
2669
+ LEFT JOIN `{$pod[ 'table' ]}` AS `t`
2670
+ ON `t`.`{$pod[ 'field_id' ]}` = `m`.`{$pod[ 'meta_field_id' ]}`
2671
+ SET
2672
+ `m`.`{$pod[ 'meta_field_index' ]}` = %s
2673
+ WHERE
2674
+ `m`.`{$pod[ 'meta_field_index' ]}` = %s
2675
+ " . ( !empty( $pod[ 'field_type' ] ) ? " AND `t`.`{$pod[ 'field_type' ]}` = %s" : "" ),
2676
+ $prepare
2677
+ );
2678
+ }
2679
+
2680
+ if ( $field[ 'type' ] != $old_type && in_array( $old_type, $tableless_field_types ) ) {
2681
+ delete_post_meta( $old_sister_id, 'sister_id' );
2682
+
2683
+ if ( true === $db ) {
2684
+ pods_query( "
2685
+ DELETE pm
2686
+ FROM {$wpdb->postmeta} AS pm
2687
+ LEFT JOIN {$wpdb->posts} AS p
2688
+ ON p.post_type = '_pods_field'
2689
+ AND p.ID = pm.post_id
2690
+ WHERE
2691
+ p.ID IS NOT NULL
2692
+ AND pm.meta_key = 'sister_id'
2693
+ AND pm.meta_value = %d
2694
+ ", array(
2695
+ $params->id
2696
+ )
2697
+ );
2698
+
2699
+ if ( !pods_tableless() ) {
2700
+ pods_query( "DELETE FROM @wp_podsrel WHERE `field_id` = {$params->id}", false );
2701
+
2702
+ pods_query( "
2703
+ UPDATE `@wp_podsrel`
2704
+ SET `related_field_id` = 0
2705
+ WHERE `field_id` = %d
2706
+ ", array(
2707
+ $old_sister_id
2708
+ )
2709
+ );
2710
+ }
2711
+ }
2712
+ }
2713
+ elseif ( 0 < $sister_id ) {
2714
+ update_post_meta( $sister_id, 'sister_id', $params->id );
2715
+
2716
+ if ( true === $db && ( !pods_tableless() ) ) {
2717
+ pods_query( "
2718
+ UPDATE `@wp_podsrel`
2719
+ SET `related_field_id` = %d
2720
+ WHERE `field_id` = %d
2721
+ ",
2722
+ array(
2723
+ $params->id,
2724
+ $sister_id
2725
+ )
2726
+ );
2727
+ }
2728
+ }
2729
+ elseif ( 0 < $old_sister_id ) {
2730
+ delete_post_meta( $old_sister_id, 'sister_id' );
2731
+
2732
+ if ( true === $db && ( !pods_tableless() ) ) {
2733
+ pods_query( "
2734
+ UPDATE `@wp_podsrel`
2735
+ SET `related_field_id` = 0
2736
+ WHERE `field_id` = %d
2737
+ ", array(
2738
+ $old_sister_id
2739
+ )
2740
+ );
2741
+ }
2742
+ }
2743
+
2744
+ if ( !empty( $old_id ) && $old_name != $field[ 'name' ] && true === $db ) {
2745
+ pods_query( "
2746
+ UPDATE `@wp_postmeta`
2747
+ SET `meta_value` = %s
2748
+ WHERE
2749
+ `post_id` = %d
2750
+ AND `meta_key` = 'pod_index'
2751
+ AND `meta_value` = %s
2752
+ ", array(
2753
+ $field[ 'name' ],
2754
+ $pod[ 'id' ],
2755
+ $old_name
2756
+ )
2757
+ );
2758
+ }
2759
+
2760
+ if ( !$save_pod )
2761
+ $this->cache_flush_pods( $pod );
2762
+ else {
2763
+ pods_transient_clear( 'pods_field_' . $pod[ 'name' ] . '_' . $field[ 'name' ] );
2764
+
2765
+ if ( !empty( $old_id ) && $old_name != $field[ 'name' ] )
2766
+ pods_transient_clear( 'pods_field_' . $pod[ 'name' ] . '_' . $old_name );
2767
+ }
2768
+
2769
+ if ( true === $db )
2770
+ return $params->id;
2771
+ else
2772
+ return $field;
2773
+ }
2774
+
2775
+ /**
2776
+ * Fix Pod / Field post_name to ensure they are exactly as saved (allow multiple posts w/ same post_name)
2777
+ *
2778
+ * @param string $slug Unique slug value
2779
+ * @param int $post_ID Post ID
2780
+ * @param string $post_status Post Status
2781
+ * @param string $post_type Post Type
2782
+ * @param int $post_parent Post Parent ID
2783
+ * @param string $original_slug Original slug value
2784
+ *
2785
+ * @return string Final slug value
2786
+ *
2787
+ * @since 2.3.3
2788
+ */
2789
+ public function save_slug_fix ( $slug, $post_ID, $post_status, $post_type, $post_parent = 0, $original_slug = null ) {
2790
+ if ( in_array( $post_type, array( '_pods_field', '_pods_pod' ) ) && false !== strpos( $slug, '-' ) )
2791
+ $slug = $original_slug;
2792
+
2793
+ return $slug;
2794
+ }
2795
+
2796
+ /**
2797
+ * Add or Edit a Pods Object
2798
+ *
2799
+ * $params['id'] int The Object ID
2800
+ * $params['name'] string The Object name
2801
+ * $params['type'] string The Object type
2802
+ * $params['options'] Associative array of Object options
2803
+ *
2804
+ * @param array|object $params An associative array of parameters
2805
+ * @param bool $sanitized (optional) Decides whether the params have been sanitized before being passed, will sanitize them if false.
2806
+ *
2807
+ * @return int The Object ID
2808
+ * @since 2.0
2809
+ */
2810
+ public function save_object ( $params, $sanitized = false ) {
2811
+ $params = (object) $params;
2812
+
2813
+ if ( false === $sanitized )
2814
+ $params = pods_sanitize( $params );
2815
+
2816
+ if ( !isset( $params->name ) || empty( $params->name ) )
2817
+ return pods_error( __( 'Name must be given to save an Object', 'pods' ), $this );
2818
+
2819
+ if ( !isset( $params->type ) || empty( $params->type ) )
2820
+ return pods_error( __( 'Type must be given to save an Object', 'pods' ), $this );
2821
+
2822
+ $object = array(
2823
+ 'id' => 0,
2824
+ 'name' => $params->name,
2825
+ 'type' => $params->type,
2826
+ 'code' => '',
2827
+ 'options' => array()
2828
+ );
2829
+
2830
+ // Setup options
2831
+ $options = get_object_vars( $params );
2832
+
2833
+ if ( isset( $options[ 'method' ] ) )
2834
+ unset( $options[ 'method' ] );
2835
+
2836
+ $exclude = array(
2837
+ 'id',
2838
+ 'name',
2839
+ 'helper_type',
2840
+ 'code',
2841
+ 'options',
2842
+ 'status'
2843
+ );
2844
+
2845
+ foreach ( $exclude as $k => $exclude_field ) {
2846
+ $aliases = array( $exclude_field );
2847
+
2848
+ if ( is_array( $exclude_field ) ) {
2849
+ $aliases = array_merge( array( $k ), $exclude_field );
2850
+ $exclude_field = $k;
2851
+ }
2852
+
2853
+ foreach ( $aliases as $alias ) {
2854
+ if ( isset( $options[ $alias ] ) ) {
2855
+ $object[ $exclude_field ] = pods_trim( $options[ $alias ] );
2856
+
2857
+ unset( $options[ $alias ] );
2858
+ }
2859
+ }
2860
+ }
2861
+
2862
+ if ( 'helper' == $object[ 'type' ] )
2863
+ $object[ 'options' ][ 'helper_type' ] = $object[ 'helper_type' ];
2864
+
2865
+ if ( isset( $object[ 'options' ][ 'code' ] ) )
2866
+ unset( $object[ 'options' ][ 'code' ] );
2867
+
2868
+ $object[ 'options' ] = array_merge( $object[ 'options' ], $options );
2869
+
2870
+ $post_data = array(
2871
+ 'post_name' => pods_clean_name( $object[ 'name' ], true),
2872
+ 'post_title' => $object[ 'name' ],
2873
+ 'post_content' => $object[ 'code' ],
2874
+ 'post_type' => '_pods_' . $object[ 'type' ],
2875
+ 'post_status' => 'publish'
2876
+ );
2877
+
2878
+ if ( !empty( $object[ 'id' ] ) )
2879
+ $post_data[ 'ID' ] = $object[ 'id' ];
2880
+
2881
+ if ( null !== pods_var( 'status', $object, null, null, true ) )
2882
+ $post_data[ 'post_status' ] = pods_var( 'status', $object, null, null, true );
2883
+
2884
+ remove_filter( 'content_save_pre', 'balanceTags', 50 );
2885
+
2886
+ $post_data = pods_sanitize( $post_data );
2887
+
2888
+ $params->id = $this->save_post( $post_data, $object[ 'options' ], true, true );
2889
+
2890
+ pods_transient_clear( 'pods_objects_' . $params->type );
2891
+ pods_transient_clear( 'pods_objects_' . $params->type . '_get' );
2892
+
2893
+ return $params->id;
2894
+ }
2895
+
2896
+ /**
2897
+ * @see PodsAPI::save_object
2898
+ *
2899
+ * Add or edit a Pod Template
2900
+ *
2901
+ * $params['id'] int The template ID
2902
+ * $params['name'] string The template name
2903
+ * $params['code'] string The template code
2904
+ *
2905
+ * @param array|object $params An associative array of parameters
2906
+ * @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will sanitize them if false.
2907
+ *
2908
+ * @return int The Template ID
2909
+ *
2910
+ * @since 1.7.9
2911
+ */
2912
+ public function save_template ( $params, $sanitized = false ) {
2913
+ $params = (object) $params;
2914
+
2915
+ $params->type = 'template';
2916
+
2917
+ return $this->save_object( $params, $sanitized );
2918
+ }
2919
+
2920
+ /**
2921
+ * @see PodsAPI::save_object
2922
+ *
2923
+ * Add or edit a Pod Page
2924
+ *
2925
+ * $params['id'] int The page ID
2926
+ * $params['name'] string The page URI
2927
+ * $params['code'] string The page code
2928
+ *
2929
+ * @param array|object $params An associative array of parameters
2930
+ * @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will sanitize them if false.
2931
+ *
2932
+ * @return int The page ID
2933
+ * @since 1.7.9
2934
+ */
2935
+ public function save_page ( $params, $sanitized = false ) {
2936
+ $params = (object) $params;
2937
+
2938
+ if ( !isset( $params->name ) ) {
2939
+ $params->name = $params->uri;
2940
+ unset( $params->uri );
2941
+ }
2942
+
2943
+ if ( isset( $params->phpcode ) ) {
2944
+ $params->code = $params->phpcode;
2945
+ unset( $params->phpcode );
2946
+ }
2947
+
2948
+ $params->name = trim( $params->name, '/' );
2949
+ $params->type = 'page';
2950
+
2951
+ return $this->save_object( $params, $sanitized );
2952
+ }
2953
+
2954
+ /**
2955
+ * @see PodsAPI::save_object
2956
+ *
2957
+ * Add or edit a Pod Helper
2958
+ *
2959
+ * $params['id'] int The helper ID
2960
+ * $params['name'] string The helper name
2961
+ * $params['helper_type'] string The helper type ("pre_save", "display", etc)
2962
+ * $params['code'] string The helper code
2963
+ *
2964
+ * @param array $params An associative array of parameters
2965
+ * @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will sanitize them if false.
2966
+ *
2967
+ * @return int The helper ID
2968
+ * @since 1.7.9
2969
+ */
2970
+ public function save_helper ( $params, $sanitized = false ) {
2971
+ $params = (object) $params;
2972
+
2973
+ if ( isset( $params->phpcode ) ) {
2974
+ $params->code = $params->phpcode;
2975
+ unset( $params->phpcode );
2976
+ }
2977
+
2978
+ if ( isset( $params->type ) ) {
2979
+ $params->helper_type = $params->type;
2980
+ unset( $params->type );
2981
+ }
2982
+
2983
+ $params->type = 'helper';
2984
+
2985
+ return $this->save_object( $params, $sanitized );
2986
+ }
2987
+
2988
+ /**
2989
+ * Add or edit a single pod item
2990
+ *
2991
+ * $params['pod'] string The Pod name (pod or pod_id is required)
2992
+ * $params['pod_id'] string The Pod ID (pod or pod_id is required)
2993
+ * $params['id'] int|array The item ID, or an array of item IDs to save data for
2994
+ * $params['data'] array (optional) Associative array of field names + values
2995
+ * $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
2996
+ * $params['track_changed_fields'] bool Set to true to enable tracking of saved fields via PodsAPI::get_changed_fields()
2997
+ * $params['error_mode'] string Throw an 'exception', 'exit' with the message, return 'false', or return 'wp_error'
2998
+ *
2999
+ * @param array|object $params An associative array of parameters
3000
+ *
3001
+ * @return int|array The item ID, or an array of item IDs (if `id` is an array if IDs)
3002
+ *
3003
+ * @since 1.7.9
3004
+ */
3005
+ public function save_pod_item ( $params ) {
3006
 
3007
+ global $wpdb;
3008
 
3009
+ $params = (object) pods_str_replace( '@wp_', '{prefix}', $params );
 
 
 
 
3010
 
3011
+ $tableless_field_types = PodsForm::tableless_field_types();
3012
+ $repeatable_field_types = PodsForm::repeatable_field_types();
3013
+ $simple_tableless_objects = PodsForm::simple_tableless_objects();
3014
 
3015
+ $error_mode = $this->display_errors;
 
 
3016
 
3017
+ if ( ! empty( $params->error_mode ) ) {
3018
+ $error_mode = $params->error_mode;
3019
+ }
3020
 
3021
+ // @deprecated 2.0
3022
+ if ( isset( $params->datatype ) ) {
3023
+ pods_deprecated( '$params->pod instead of $params->datatype', '2.0' );
3024
 
3025
+ $params->pod = $params->datatype;
 
3026
 
3027
+ unset( $params->datatype );
 
3028
 
3029
+ if ( isset( $params->pod_id ) ) {
3030
+ pods_deprecated( '$params->id instead of $params->pod_id', '2.0' );
3031
 
3032
+ $params->id = $params->pod_id;
 
 
3033
 
3034
+ unset( $params->pod_id );
3035
+ }
 
 
 
 
 
 
3036
 
3037
+ if ( isset( $params->data ) && !empty( $params->data ) && is_array( $params->data ) ) {
3038
+ $check = current( $params->data );
 
 
 
 
 
3039
 
3040
+ if ( is_array( $check ) ) {
3041
+ pods_deprecated( 'PodsAPI::save_pod_items', '2.0' );
 
3042
 
3043
+ return $this->save_pod_items( $params, $params->data );
3044
+ }
3045
+ }
3046
+ }
3047
 
3048
+ // @deprecated 2.0
3049
+ if ( isset( $params->tbl_row_id ) ) {
3050
+ pods_deprecated( '$params->id instead of $params->tbl_row_id', '2.0' );
 
 
 
 
 
 
 
 
 
 
3051
 
3052
+ $params->id = $params->tbl_row_id;
 
 
3053
 
3054
+ unset( $params->tbl_row_id );
3055
+ }
3056
 
3057
+ // @deprecated 2.0
3058
+ if ( isset( $params->columns ) ) {
3059
+ pods_deprecated( '$params->data instead of $params->columns', '2.0' );
3060
 
3061
+ $params->data = $params->columns;
 
 
3062
 
3063
+ unset( $params->columns );
3064
+ }
 
 
3065
 
3066
+ if ( !isset( $params->pod ) )
3067
+ $params->pod = false;
3068
+ if ( isset( $params->pod_id ) )
3069
+ $params->pod_id = pods_absint( $params->pod_id );
3070
+ else
3071
+ $params->pod_id = 0;
3072
 
3073
+ if ( isset( $params->id ) )
3074
+ $params->id = pods_absint( $params->id );
3075
+ else
3076
+ $params->id = 0;
3077
 
3078
+ if ( !isset( $params->from ) )
3079
+ $params->from = 'save';
3080
 
3081
+ if ( !isset( $params->location ) )
3082
+ $params->location = null;
3083
+
3084
+ if ( !isset( $params->track_changed_fields ) )
3085
+ $params->track_changed_fields = false;
 
 
 
 
 
 
 
3086
 
3087
  /**
3088
+ * Override $params['track_changed_fields']
3089
+ *
3090
+ * Use for globally setting field change tracking.
3091
+ *
3092
+ * @param bool
3093
+ *
3094
+ * @since 2.3.19
3095
  */
3096
+ $track_changed_fields = apply_filters( 'pods_api_save_pod_item_track_changed_fields_' . $params->pod, (boolean) $params->track_changed_fields, $params );
3097
 
3098
+ $changed_fields = array();
 
 
3099
 
3100
+ if ( !isset( $params->clear_slug_cache ) ) {
3101
+ $params->clear_slug_cache = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3102
  }
3103
 
3104
+ // Support for bulk edit
3105
+ if ( isset( $params->id ) && !empty( $params->id ) && is_array( $params->id ) ) {
3106
+ $ids = array();
3107
+ $new_params = $params;
3108
 
3109
+ foreach ( $params->id as $id ) {
3110
+ $new_params->id = $id;
 
 
 
 
 
 
 
 
 
 
3111
 
3112
+ $ids[] = $this->save_pod_item( $new_params );
3113
+ }
3114
 
3115
+ return $ids;
3116
+ }
 
 
3117
 
3118
+ // Allow Helpers to know what's going on, are we adding or saving?
3119
+ $is_new_item = false;
3120
 
3121
+ if ( empty( $params->id ) )
3122
+ $is_new_item = true;
 
3123
 
3124
+ if ( isset( $params->is_new_item ) )
3125
+ $is_new_item = (boolean) $params->is_new_item;
 
3126
 
3127
+ // Allow Helpers to bypass subsequent helpers in recursive save_pod_item calls
3128
+ $bypass_helpers = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3129
 
3130
+ if ( isset( $params->bypass_helpers ) && false !== $params->bypass_helpers )
3131
+ $bypass_helpers = true;
3132
 
3133
+ // Allow Custom Fields not defined by Pods to be saved
3134
+ $allow_custom_fields = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3135
 
3136
+ if ( isset( $params->allow_custom_fields ) && false !== $params->allow_custom_fields )
3137
+ $allow_custom_fields = true;
3138
 
3139
+ // Get array of Pods
3140
+ $pod = $this->load_pod( array( 'id' => $params->pod_id, 'name' => $params->pod, 'table_info' => true ) );
 
 
 
 
3141
 
3142
+ if ( false === $pod )
3143
+ return pods_error( __( 'Pod not found', 'pods' ), $error_mode );
 
3144
 
3145
+ $params->pod = $pod[ 'name' ];
3146
+ $params->pod_id = $pod[ 'id' ];
3147
 
3148
+ if ( 'settings' == $pod[ 'type' ] )
3149
+ $params->id = $pod[ 'id' ];
3150
 
3151
+ $fields = $pod[ 'fields' ];
 
 
3152
 
3153
+ $object_fields = (array) pods_var_raw( 'object_fields', $pod, array(), null, true );
 
3154
 
3155
+ $fields_active = array();
3156
+ $custom_data = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3157
 
3158
+ // Find the active fields (loop through $params->data to retain order)
3159
+ if ( !empty( $params->data ) && is_array( $params->data ) ) {
3160
+ $custom_fields = array();
 
3161
 
3162
+ foreach ( $params->data as $field => $value ) {
3163
+ if ( isset( $object_fields[ $field ] ) ) {
3164
+ $object_fields[ $field ][ 'value' ] = $value;
3165
+ $fields_active[] = $field;
3166
+ }
3167
+ elseif ( isset( $fields[ $field ] ) ) {
3168
+ if ( 'save' == $params->from || true === PodsForm::permission( $fields[ $field ][ 'type' ], $field, $fields[ $field ], $fields, $pod, $params->id, $params ) ) {
3169
+ $fields[ $field ][ 'value' ] = $value;
3170
+ $fields_active[] = $field;
3171
+ }
3172
+ elseif ( !pods_has_permissions( $fields[ $field ][ 'options' ] ) && pods_var( 'hidden', $fields[ $field ][ 'options' ], false ) ) {
3173
+ $fields[ $field ][ 'value' ] = $value;
3174
+ $fields_active[] = $field;
3175
+ }
3176
+ }
3177
+ else {
3178
+ $found = false;
3179
 
3180
+ foreach ( $object_fields as $object_field => $object_field_opt ) {
3181
+ if ( in_array( $field, $object_field_opt[ 'alias' ] ) ) {
3182
+ $object_fields[ $object_field ][ 'value' ] = $value;
3183
+ $fields_active[] = $object_field;
3184
 
3185
+ $found = true;
 
 
 
 
 
 
 
 
3186
 
3187
+ break;
3188
+ }
3189
+ }
3190
 
3191
+ if ( $allow_custom_fields && !$found )
3192
+ $custom_fields[] = $field;
3193
+ }
3194
+ }
3195
 
3196
+ if ( $allow_custom_fields && !empty( $custom_fields ) ) {
3197
+ foreach ( $custom_fields as $field ) {
3198
+ $custom_data[ $field ] = $params->data[ $field ];
3199
+ }
3200
+ }
 
 
 
3201
 
3202
+ unset( $params->data );
3203
+ }
 
 
3204
 
3205
+ if ( empty( $params->id ) && !in_array( 'created', $fields_active ) && isset( $fields[ 'created' ] ) && in_array( $fields[ 'created' ][ 'type' ], array( 'date', 'datetime' ) ) ) {
3206
+ $fields[ 'created' ][ 'value' ] = current_time( 'mysql' );
3207
+ $fields_active[] = 'created';
3208
+ }
3209
 
3210
+ if ( !in_array( 'modified', $fields_active ) && isset( $fields[ 'modified' ] ) && in_array( $fields[ 'modified' ][ 'type' ], array( 'date', 'datetime' ) ) ) {
3211
+ $fields[ 'modified' ][ 'value' ] = current_time( 'mysql' );
3212
+ $fields_active[] = 'modified';
3213
+ }
3214
 
3215
+ if ( in_array( $pod[ 'type' ], array( 'pod', 'table' ) ) && empty( $params->id ) && !empty( $pod[ 'pod_field_index' ] ) && in_array( $pod[ 'pod_field_index' ], $fields_active ) && !in_array( $pod[ 'pod_field_slug' ], $fields_active ) && isset( $fields[ $pod[ 'pod_field_slug' ] ] ) ) {
3216
+ $fields[ $pod[ 'pod_field_slug' ] ][ 'value' ] = ''; // this will get picked up by slug pre_save method
3217
+ $fields_active[] = $pod[ 'pod_field_slug' ];
3218
+ }
 
 
 
3219
 
3220
+ // Handle hidden fields
3221
+ if ( empty( $params->id ) ) {
3222
+ foreach ( $fields as $field => $field_data ) {
3223
+ if ( in_array( $field, $fields_active ) )
3224
+ continue;
3225
 
3226
+ if ( in_array( $params->from, array( 'save', 'process_form' ) ) || true === PodsForm::permission( $fields[ $field ][ 'type' ], $field, $fields[ $field ], $fields, $pod, $params->id, $params ) ) {
3227
+ $value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data[ 'type' ], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
 
3228
 
3229
+ if ( null !== $value && '' !== $value && false !== $value ) {
3230
+ $fields[ $field ][ 'value' ] = $value;
3231
+ $fields_active[] = $field;
3232
+ }
3233
+ }
3234
+ }
3235
 
3236
+ // Set default field values for object fields
3237
+ if ( !empty( $object_fields ) ) {
3238
+ foreach ( $object_fields as $field => $field_data ) {
3239
+ if ( in_array( $field, $fields_active ) ) {
3240
+ continue;
3241
+ }
3242
+ elseif ( !isset( $field_data[ 'default' ] ) || strlen( $field_data[ 'default' ] ) < 1 ) {
3243
+ continue;
3244
+ }
3245
+
3246
+ $value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data[ 'type' ], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
3247
+
3248
+ if ( null !== $value && '' !== $value && false !== $value ) {
3249
+ $object_fields[ $field ][ 'value' ] = $value;
3250
+ $fields_active[] = $field;
3251
+ }
3252
  }
3253
+ }
3254
 
3255
+ // Set default field values for Pod fields
3256
+ foreach ( $fields as $field => $field_data ) {
3257
+ if ( in_array( $field, $fields_active ) ) {
3258
+ continue;
3259
  }
3260
+ elseif ( !isset( $field_data[ 'default' ] ) || strlen( $field_data[ 'default' ] ) < 1 ) {
3261
+ continue;
 
 
 
 
 
 
 
 
 
 
3262
  }
3263
 
3264
+ $value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data[ 'type' ], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
3265
+
3266
+ if ( null !== $value && '' !== $value && false !== $value ) {
3267
+ $fields[ $field ][ 'value' ] = $value;
3268
+ $fields_active[] = $field;
3269
  }
3270
  }
3271
+ }
 
3272
 
3273
+ $columns =& $fields; // @deprecated 2.0
3274
+ $active_columns =& $fields_active; // @deprecated 2.0
3275
+ $params->tbl_row_id =& $params->id; // @deprecated 2.0
3276
 
3277
+ $pre_save_helpers = $post_save_helpers = array();
 
 
3278
 
3279
+ $pieces = array(
3280
+ 'fields',
3281
+ 'params',
3282
+ 'pod',
3283
+ 'fields_active',
3284
+ 'object_fields',
3285
+ 'custom_fields',
3286
+ 'custom_data',
3287
+ 'track_changed_fields',
3288
+ 'changed_fields'
3289
+ );
3290
 
3291
+ if ( false === $bypass_helpers ) {
3292
+ // Plugin hooks
3293
+ $hooked = $this->do_hook( 'pre_save_pod_item', compact( $pieces ), $is_new_item, $params->id );
3294
 
3295
+ if ( is_array( $hooked ) && !empty( $hooked ) )
3296
+ extract( $hooked );
 
3297
 
3298
+ $hooked = $this->do_hook( "pre_save_pod_item_{$params->pod}", compact( $pieces ), $is_new_item, $params->id );
 
 
 
 
 
3299
 
3300
+ if ( is_array( $hooked ) && !empty( $hooked ) )
3301
+ extract( $hooked );
 
3302
 
3303
+ if ( $is_new_item ) {
3304
+ $hooked = $this->do_hook( 'pre_create_pod_item', compact( $pieces ) );
3305
 
3306
+ if ( is_array( $hooked ) && !empty( $hooked ) )
3307
+ extract( $hooked );
 
3308
 
3309
+ $hooked = $this->do_hook( "pre_create_pod_item_{$params->pod}", compact( $pieces ) );
 
 
3310
 
3311
+ if ( is_array( $hooked ) && !empty( $hooked ) )
3312
+ extract( $hooked );
3313
+ }
3314
+ else {
3315
+ $hooked = $this->do_hook( 'pre_edit_pod_item', compact( $pieces ), $params->id );
3316
 
3317
+ if ( is_array( $hooked ) && !empty( $hooked ) )
3318
+ extract( $hooked );
 
 
3319
 
3320
+ $hooked = $this->do_hook( "pre_edit_pod_item_{$params->pod}", compact( $pieces ), $params->id );
 
 
 
 
3321
 
3322
+ if ( is_array( $hooked ) && !empty( $hooked ) )
3323
+ extract( $hooked );
3324
+ }
3325
 
3326
+ // Call any pre-save helpers (if not bypassed)
3327
+ if ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) {
3328
+ if ( !empty( $pod[ 'options' ] ) && is_array( $pod[ 'options' ] ) ) {
3329
+ $helpers = array( 'pre_save_helpers', 'post_save_helpers' );
3330
 
3331
+ foreach ( $helpers as $helper ) {
3332
+ if ( isset( $pod[ 'options' ][ $helper ] ) && !empty( $pod[ 'options' ][ $helper ] ) )
3333
+ ${$helper} = explode( ',', $pod[ 'options' ][ $helper ] );
3334
+ }
3335
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3336
 
3337
+ if ( !empty( $pre_save_helpers ) ) {
3338
+ pods_deprecated( sprintf( __( 'Pre-save helpers are deprecated, use the action pods_pre_save_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
3339
 
3340
+ foreach ( $pre_save_helpers as $helper ) {
3341
+ $helper = $this->load_helper( array( 'name' => $helper ) );
3342
 
3343
+ if ( false !== $helper )
3344
+ eval( '?>' . $helper[ 'code' ] );
3345
+ }
3346
+ }
3347
+ }
3348
+ }
3349
 
3350
+ if ( $track_changed_fields ) {
3351
+ $changed_fields = $this->get_changed_fields( compact( $pieces ) );
3352
  }
3353
 
3354
+ $table_data = $table_formats = $update_values = $rel_fields = $rel_field_ids = array();
 
 
3355
 
3356
+ $object_type = $pod[ 'type' ];
3357
 
3358
+ $object_ID = 'ID';
3359
 
3360
+ if ( 'comment' == $object_type )
3361
+ $object_ID = 'comment_ID';
3362
+ elseif ( 'taxonomy' == $object_type )
3363
+ $object_ID = 'term_id';
3364
 
3365
+ $object_data = $object_meta = $post_term_data = array();
 
 
3366
 
3367
+ if ( 'settings' == $object_type )
3368
+ $object_data[ 'option_id' ] = $pod[ 'name' ];
3369
+ elseif ( !empty( $params->id ) )
3370
+ $object_data[ $object_ID ] = $params->id;
3371
 
3372
+ $fields_active = array_unique( $fields_active );
 
3373
 
3374
+ // Loop through each active field, validating and preparing the table data
3375
+ foreach ( $fields_active as $field ) {
3376
+ if ( isset( $object_fields[ $field ] ) )
3377
+ $field_data = $object_fields[ $field ];
3378
+ elseif ( isset( $fields[ $field ] ) )
3379
+ $field_data = $fields[ $field ];
3380
+ else
3381
+ continue;
3382
 
3383
+ $value = $field_data[ 'value' ];
3384
+ $type = $field_data[ 'type' ];
3385
+ $options = pods_var( 'options', $field_data, array() );
3386
 
3387
+ // WPML AJAX compatibility
3388
+ if ( is_admin() && isset( $_GET[ 'page' ] ) && false !== strpos( $_GET[ 'page' ], '/menu/languages.php' ) && isset( $_POST[ 'icl_ajx_action' ] ) && isset( $_POST[ '_icl_nonce' ] ) && wp_verify_nonce( $_POST[ '_icl_nonce' ], $_POST[ 'icl_ajx_action' ] . '_nonce' ) )
3389
+ $options[ 'unique' ] = $fields[ $field ][ 'options' ][ 'unique' ] = $options[ 'required' ] = $fields[ $field ][ 'options' ][ 'required' ] = 0;
3390
+ else {
3391
+ // Validate value
3392
+ $validate = $this->handle_field_validation( $value, $field, $object_fields, $fields, $pod, $params );
3393
 
3394
+ if ( false === $validate )
3395
+ $validate = sprintf( __( 'There was an issue validating the field %s', 'pods' ), $field_data[ 'label' ] );
3396
+ elseif ( true !== $validate )
3397
+ $validate = (array) $validate;
3398
 
3399
+ if ( !is_bool( $validate ) && !empty( $validate ) )
3400
+ return pods_error( $validate, $error_mode );
3401
+ }
 
3402
 
3403
+ $value = PodsForm::pre_save( $field_data[ 'type' ], $value, $params->id, $field, array_merge( $field_data, $options ), array_merge( $fields, $object_fields ), $pod, $params );
 
 
 
3404
 
3405
+ $field_data[ 'value' ] = $value;
 
 
 
3406
 
3407
+ if ( isset( $object_fields[ $field ] ) ) {
3408
+ if ( 'taxonomy' == $object_fields[ $field ][ 'type' ] ) {
3409
+ $post_term_data[ $field ] = $value;
 
 
3410
  }
3411
+ else {
3412
+ $object_data[ $field ] = $value;
3413
+ }
3414
+ }
3415
+ else {
3416
+ $simple = ( 'pick' == $type && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
3417
+ $simple = (boolean) $this->do_hook( 'tableless_custom', $simple, $field_data, $field, $fields, $pod, $params );
3418
+
3419
+ // Handle Simple Relationships
3420
+ if ( $simple ) {
3421
+ if ( !is_array( $value ) )
3422
+ $value = explode( ',', $value );
3423
+
3424
+ $pick_limit = (int) pods_var_raw( 'pick_limit', $options, 0 );
3425
+
3426
+ if ( 'single' == pods_var_raw( 'pick_format_type', $options ) )
3427
+ $pick_limit = 1;
3428
+
3429
+ if ( 'custom-simple' == pods_var( 'pick_object', $field_data ) ) {
3430
+ $custom = pods_var_raw( 'pick_custom', $options, '' );
3431
+
3432
+ $custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $field_data[ 'name' ], $value, array_merge( $field_data, $options ), $pod, $params->id );
3433
+
3434
+ if ( empty( $value ) || empty( $custom ) )
3435
+ $value = '';
3436
+ elseif ( !empty( $custom ) ) {
3437
+ if ( !is_array( $custom ) ) {
3438
+ $custom = explode( "\n", $custom );
3439
+
3440
+ $custom_values = array();
3441
+
3442
+ foreach ( $custom as $c => $cv ) {
3443
+ if ( 0 < strlen( $cv ) ) {
3444
+ $custom_label = explode( '|', $cv );
3445
+
3446
+ if ( !isset( $custom_label[ 1 ] ) )
3447
+ $custom_label[ 1 ] = $custom_label[ 0 ];
3448
+
3449
+ $custom_label[ 0 ] = trim( (string) $custom_label[ 0 ] );
3450
+ $custom_label[ 1 ] = trim( (string) $custom_label[ 1 ] );
3451
+ $custom_values[ $custom_label[ 0 ] ] = $custom_label[ 1 ];
3452
+ }
3453
+ }
3454
+ }
3455
+ else
3456
+ $custom_values = $custom;
3457
+
3458
+ $values = array();
3459
+
3460
+ foreach ( $value as $k => $v ) {
3461
+ $v = pods_unsanitize( $v );
3462
+
3463
+ if ( isset( $custom_values[ $v ] ) )
3464
+ $values[ $k ] = $v;
3465
+ }
3466
+
3467
+ $value = $values;
3468
+ }
3469
+ }
3470
+
3471
+ if ( 0 < $pick_limit && !empty( $value ) )
3472
+ $value = array_slice( $value, 0, $pick_limit );
3473
+
3474
+ // Don't save an empty array, just make it an empty string
3475
+ if ( empty( $value ) )
3476
+ $value = '';
3477
+ elseif ( is_array( $value ) ) {
3478
+ // If there's just one item, don't save as an array, save the string
3479
+ if ( 1 == $pick_limit || 1 == count( $value ) )
3480
+ $value = implode( '', $value );
3481
+ // If storage is set to table, json encode, otherwise WP will serialize automatically
3482
+ elseif ( 'table' == pods_var( 'storage', $pod ) )
3483
+ $value = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $value, JSON_UNESCAPED_UNICODE ) : json_encode( $value );
3484
+ }
3485
+ }
3486
+
3487
+ // Prepare all table / meta data
3488
+ if ( !in_array( $type, $tableless_field_types ) || $simple ) {
3489
+ if ( in_array( $type, $repeatable_field_types ) && 1 == pods_var( $type . '_repeatable', $field_data, 0 ) ) {
3490
+ // Don't save an empty array, just make it an empty string
3491
+ if ( empty( $value ) )
3492
+ $value = '';
3493
+ elseif ( is_array( $value ) ) {
3494
+ // If there's just one item, don't save as an array, save the string
3495
+ if ( 1 == count( $value ) )
3496
+ $value = implode( '', $value );
3497
+ // If storage is set to table, json encode, otherwise WP will serialize automatically
3498
+ elseif ( 'table' == pods_var( 'storage', $pod ) )
3499
+ $value = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $value, JSON_UNESCAPED_UNICODE ) : json_encode( $value );
3500
+ }
3501
+ }
3502
+
3503
+ $table_data[ $field ] = str_replace( array( '{prefix}', '@wp_' ), array( '{/prefix/}', '{prefix}' ), $value ); // Fix for pods_query
3504
+ $table_formats[] = PodsForm::prepare( $type, $options );
3505
+
3506
+ $object_meta[ $field ] = $value;
3507
+ }
3508
+ // Store relational field data to be looped through later
3509
+ else {
3510
+ // Convert values from a comma-separated string into an array
3511
+ if ( !is_array( $value ) )
3512
+ $value = explode( ',', $value );
3513
+
3514
+ $rel_fields[ $type ][ $field ] = $value;
3515
+ $rel_field_ids[] = $field_data[ 'id' ];
3516
+ }
3517
+ }
3518
+ }
3519
+
3520
+ if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) ) {
3521
+ $object_name = $pod[ 'name' ];
3522
+
3523
+ if ( !empty( $pod[ 'object' ] ) )
3524
+ $object_name = $pod[ 'object' ];
3525
+
3526
+ $object_name_field = 'post_type';
3527
+
3528
+ if ( 'taxonomy' == $pod['type'] ) {
3529
+ $object_name_field = 'taxonomy';
3530
+ }
3531
+
3532
+ $object_data[ $object_name_field ] = $object_name;
3533
+ }
3534
+
3535
+ if ( ( 'meta' == $pod[ 'storage' ] || 'settings' == $pod[ 'type' ] || ( 'taxonomy' == $pod[ 'type' ] && 'none' == $pod[ 'storage' ] ) ) && !in_array( $pod[ 'type' ], array( 'pod', 'table', '' ) ) ) {
3536
+ if ( $allow_custom_fields && !empty( $custom_data ) )
3537
+ $object_meta = array_merge( $custom_data, $object_meta );
3538
+
3539
+ $fields_to_send = array_flip( array_keys( $object_meta ) );
3540
 
3541
+ foreach ( $fields_to_send as $field => $field_data ) {
3542
+ if ( isset( $object_fields[ $field ] ) ) {
3543
+ $field_data = $object_fields[ $field ];
 
 
 
3544
  }
3545
+ elseif ( isset( $fields[ $field ] ) ) {
3546
+ $field_data = $fields[ $field ];
 
 
 
 
 
3547
  }
3548
+ else {
3549
+ unset( $fields_to_send[ $field ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3550
  }
3551
 
3552
+ $fields_to_send[ $field ] = $field_data;
 
 
3553
  }
3554
 
3555
+ $params->id = $this->save_wp_object( $object_type, $object_data, $object_meta, false, true, $fields_to_send );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3556
 
3557
+ if ( !empty( $params->id ) && 'settings' == $object_type )
3558
+ $params->id = $pod[ 'id' ];
3559
+ }
3560
+ else {
3561
+ if ( ! in_array( $pod[ 'type' ], array( 'pod', 'table', '' ) ) ) {
3562
+ $params->id = $this->save_wp_object( $object_type, $object_data, array(), false, true );
3563
+ }
3564
 
3565
+ if ( 'table' == $pod[ 'storage' ] ) {
3566
+ // Every row should have an id set here, otherwise Pods with nothing
3567
+ // but relationship fields won't get properly ID'd
3568
+ if ( empty( $params->id ) )
3569
+ $params->id = 0;
3570
 
3571
+ $table_data = array( 'id' => $params->id ) + $table_data;
3572
+ array_unshift( $table_formats, '%d' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3573
 
3574
+ if ( !empty( $table_data ) ) {
3575
+ $sql = pods_data()->insert_on_duplicate( "@wp_pods_{$params->pod}", $table_data, $table_formats );
 
 
 
3576
 
3577
+ $id = pods_query( $sql, 'Cannot add/save table row' );
 
 
 
 
 
 
 
 
 
 
 
3578
 
3579
+ if ( empty( $params->id ) )
3580
+ $params->id = $id;
3581
+ }
3582
+ }
3583
+ }
3584
 
3585
+ $params->id = (int) $params->id;
 
 
 
3586
 
3587
+ // Save terms for taxonomies associated to a post type
3588
+ if ( 0 < $params->id && 'post_type' == $pod[ 'type' ] && !empty( $post_term_data ) ) {
3589
+ foreach ( $post_term_data as $post_taxonomy => $post_terms ) {
3590
+ $post_terms = (array) $post_terms;
3591
 
3592
+ foreach ( $post_terms as $k => $v ) {
3593
+ if ( ! preg_match( '/[^0-9]/', $v ) ) {
3594
+ $v = (int) $v;
3595
+ }
3596
 
3597
+ $post_terms[ $k ] = $v;
3598
+ }
 
 
3599
 
3600
+ wp_set_object_terms( $params->id, $post_terms, $post_taxonomy );
 
 
 
 
 
3601
  }
3602
  }
3603
 
3604
+ $no_conflict = pods_no_conflict_check( $pod[ 'type' ] );
 
 
 
 
 
3605
 
3606
+ if ( !$no_conflict )
3607
+ pods_no_conflict_on( $pod[ 'type' ] );
 
 
3608
 
3609
+ // Save relationship / file data
3610
+ if ( !empty( $rel_fields ) ) {
3611
+ foreach ( $rel_fields as $type => $data ) {
3612
+ // Only handle tableless fields
3613
+ if ( !in_array( $type, $tableless_field_types ) ) {
3614
+ continue;
3615
+ }
3616
 
3617
+ foreach ( $data as $field => $values ) {
3618
+ $pick_val = pods_var( 'pick_val', $fields[ $field ] );
 
3619
 
3620
+ if ( 'table' == pods_var( 'pick_object', $fields[ $field ] ) ) {
3621
+ $pick_val = pods_var( 'pick_table', $fields[ $field ][ 'options' ], $pick_val, null, true );
3622
+ }
 
 
3623
 
3624
+ if ( '__current__' == $pick_val ) {
3625
+ if ( is_object( $pod ) ) {
3626
+ $pick_val = $pod->pod;
3627
+ }
3628
+ elseif ( is_array( $pod ) ) {
3629
+ $pick_val = $pod[ 'name' ];
3630
+ }
3631
+ elseif ( 0 < strlen( $pod ) ) {
3632
+ $pick_val = $pod;
3633
+ }
3634
+ }
3635
 
3636
+ $fields[ $field ][ 'options' ][ 'table_info' ] = pods_api()->get_table_info( pods_var( 'pick_object', $fields[ $field ] ), $pick_val, null, null, $fields[ $field ][ 'options' ] );
 
 
3637
 
3638
+ if ( isset( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ] ) && !empty( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ] ) && isset( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ][ 'name' ] ) ) {
3639
+ $search_data = pods( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ][ 'name' ] );
 
 
 
 
 
3640
 
3641
+ $data_mode = 'pods';
3642
+ }
3643
+ else {
3644
+ $search_data = pods_data();
3645
+ $search_data->table( $fields[ $field ][ 'options' ][ 'table_info' ] );
3646
 
3647
+ $data_mode = 'data';
3648
+ }
 
3649
 
3650
+ $find_rel_params = array(
3651
+ 'select' => "`t`.`{$search_data->field_id}`",
3652
+ 'where' => "`t`.`{$search_data->field_slug}` = %s OR `t`.`{$search_data->field_index}` = %s",
3653
+ 'limit' => 1,
3654
+ 'pagination' => false,
3655
+ 'search' => false
3656
+ );
3657
 
3658
+ if ( empty( $search_data->field_slug ) && !empty( $search_data->field_index ) ) {
3659
+ $find_rel_params[ 'where' ] = "`t`.`{$search_data->field_index}` = %s";
3660
+ }
3661
+ elseif ( empty( $search_data->field_slug ) && empty( $search_data->field_index ) ) {
3662
+ $find_rel_params = false;
3663
+ }
3664
 
3665
+ $related_limit = (int) pods_var_raw( $type . '_limit', $fields[ $field ][ 'options' ], 0 );
3666
 
3667
+ if ( 'single' == pods_var_raw( $type . '_format_type', $fields[ $field ][ 'options' ] ) ) {
3668
+ $related_limit = 1;
3669
+ }
 
 
3670
 
3671
+ // Enforce integers / unique values for IDs
3672
+ $value_ids = array();
 
 
 
 
 
3673
 
3674
+ $is_file_field = in_array( $type, PodsForm::file_field_types() );
3675
+ $is_taggable = ( in_array( $type, PodsForm::tableless_field_types() ) && 1 == pods_v( $type . '_taggable', $fields[ $field ][ 'options' ] ) );
3676
 
3677
+ // @todo Handle simple relationships eventually
3678
+ foreach ( $values as $v ) {
3679
+ if ( !empty( $v ) ) {
3680
+ if ( !is_array( $v ) ) {
3681
+ if ( !preg_match( '/[^0-9]/', $v ) ) {
3682
+ $v = (int) $v;
3683
+ }
3684
+ // File handling
3685
+ elseif ( $is_file_field ) {
3686
+ // Get ID from GUID
3687
+ $v = pods_image_id_from_field( $v );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3688
 
3689
+ // If file not found, add it
3690
+ if ( empty( $v ) ) {
3691
+ $v = pods_attachment_import( $v );
3692
+ }
3693
+ }
3694
+ // Reference by slug
3695
+ else {
3696
+ $v_data = false;
3697
 
3698
+ if ( false !== $find_rel_params ) {
3699
+ $rel_params = $find_rel_params;
3700
+ $rel_params[ 'where' ] = $wpdb->prepare( $rel_params[ 'where' ], array( $v, $v ) );
 
3701
 
3702
+ $search_data->select( $rel_params );
3703
 
3704
+ $v_data = $search_data->fetch( $v );
3705
+ }
 
 
 
 
 
 
 
 
3706
 
3707
+ if ( !empty( $v_data ) && isset( $v_data[ $search_data->field_id ] ) ) {
3708
+ $v = (int) $v_data[ $search_data->field_id ];
3709
+ }
3710
+ // Allow tagging for Pods objects
3711
+ elseif ( $is_taggable && 'pods' == $data_mode ) {
3712
+ $tag_data = array(
3713
+ $search_data->field_index => $v
3714
+ );
3715
 
3716
+ if ( 'post_type' == $search_data->pod_data[ 'type' ] ) {
3717
+ $tag_data[ 'post_status' ] = 'publish';
3718
+ }
3719
 
3720
+ /**
3721
+ * Filter for changing tag before adding new item.
3722
+ *
3723
+ * @param array $tag_data Fields for creating new item.
3724
+ * @param int $v Field ID of tag.
3725
+ * @param obj $search_data Search object for tag.
3726
+ * @param string $field Table info for field.
3727
+ * @param array $pieces Field array.
3728
+ *
3729
+ * @since 2.3.19
3730
+ */
3731
+ $tag_data = apply_filters( 'pods_api_save_pod_item_taggable_data', $tag_data, $v, $search_data, $field, compact( $pieces ) );
3732
 
3733
+ // Save $v to a new item on related object
3734
+ $v = $search_data->add( $tag_data );
3735
 
3736
+ // @todo Support non-Pods for tagging
3737
+ }
3738
+ }
3739
+ }
3740
+ elseif ( $is_file_field && isset( $v[ 'id' ] ) ) {
3741
+ $v = (int) $v[ 'id' ];
3742
+ }
3743
+ else {
3744
+ continue;
3745
+ }
3746
 
3747
+ if ( !empty( $v ) && !in_array( $v, $value_ids ) ) {
3748
+ $value_ids[] = $v;
3749
+ }
3750
+ }
3751
+ }
3752
 
3753
+ $value_ids = array_unique( array_filter( $value_ids ) );
 
 
 
 
 
3754
 
3755
+ // Filter unique values not equal to false in case of a multidimensional array
3756
+ $filtered_values = $this->array_filter_walker( $values );
3757
+ $serialized_values = array_map( 'serialize', $filtered_values );
3758
+ $unique_serialized_values = array_unique( $serialized_values );
3759
 
3760
+ $values = array_map( 'unserialize', $unique_serialized_values );
 
 
3761
 
3762
+ // Limit values
3763
+ if ( 0 < $related_limit && !empty( $value_ids ) ) {
3764
+ $value_ids = array_slice( $value_ids, 0, $related_limit );
3765
+ $values = array_slice( $values, 0, $related_limit );
3766
+ }
3767
 
3768
+ // Get current values
3769
+ if ( 'pick' == $type && isset( PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ] ) && isset( PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ][ 'current_ids' ] ) )
3770
+ $related_ids = PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ][ 'current_ids' ];
3771
+ else
3772
+ $related_ids = $this->lookup_related_items( $fields[ $field ][ 'id' ], $pod[ 'id' ], $params->id, $fields[ $field ], $pod );
3773
 
3774
+ // Get ids to remove
3775
+ $remove_ids = array_diff( $related_ids, $value_ids );
3776
 
3777
+ // Delete relationships
3778
+ if ( !empty( $remove_ids ) )
3779
+ $this->delete_relationships( $params->id, $remove_ids, $pod, $fields[ $field ] );
3780
 
3781
+ // Save relationships
3782
+ if ( !empty( $value_ids ) )
3783
+ $this->save_relationships( $params->id, $value_ids, $pod, $fields[ $field ] );
 
 
3784
 
3785
+ $field_save_values = $value_ids;
3786
 
3787
+ if ( 'file' === $type ) {
3788
+ $field_save_values = $values;
3789
+ }
 
 
3790
 
3791
+ // Run save function for field type (where needed)
3792
+ PodsForm::save( $type, $field_save_values, $params->id, $field, array_merge( $fields[ $field ], $fields[ $field ][ 'options' ] ), array_merge( $fields, $object_fields ), $pod, $params );
3793
+ }
 
3794
 
3795
+ // Unset data no longer needed
3796
+ if ( 'pick' == $type ) {
3797
+ foreach ( $data as $field => $values ) {
3798
+ if ( isset( PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ] ) ) {
3799
+ unset( PodsField_Pick::$related_data[ PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ][ 'related_field' ][ 'id' ] ] );
3800
+ unset( PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ] );
3801
+ }
3802
+ }
3803
+ }
3804
+ }
3805
+ }
3806
 
3807
+ if ( !$no_conflict )
3808
+ pods_no_conflict_off( $pod[ 'type' ] );
3809
 
3810
+ // Clear cache
3811
+ pods_cache_clear( $params->id, 'pods_items_' . $pod[ 'name' ] );
 
3812
 
3813
+ if ( $params->clear_slug_cache && !empty( $pod[ 'field_slug' ] ) ) {
3814
+ $slug = pods( $pod[ 'name' ], $params->id )->field( $pod[ 'field_slug' ] );
3815
 
3816
+ if ( 0 < strlen( $slug ) ) {
3817
+ pods_cache_clear( $slug, 'pods_items_' . $pod[ 'name' ] );
3818
+ }
3819
+ }
3820
+
3821
+ // Clear WP meta cache
3822
+ if ( in_array( $pod[ 'type' ], array( 'post_type', 'media', 'taxonomy', 'user', 'comment' ) ) ) {
3823
+ $meta_type = $pod[ 'type' ];
3824
+
3825
+ if ( 'post_type' == $meta_type )
3826
+ $meta_type = 'post';
3827
+
3828
+ wp_cache_delete( $params->id, $meta_type . '_meta' );
3829
+ wp_cache_delete( $params->id, 'pods_' . $meta_type . '_meta' );
3830
+ }
3831
+
3832
+ if ( false === $bypass_helpers ) {
3833
+ $pieces = compact( $pieces );
3834
+
3835
+ // Plugin hooks
3836
+ $this->do_hook( 'post_save_pod_item', $pieces, $is_new_item, $params->id );
3837
+ $this->do_hook( "post_save_pod_item_{$params->pod}", $pieces, $is_new_item, $params->id );
3838
+
3839
+ if ( $is_new_item ) {
3840
+ $this->do_hook( 'post_create_pod_item', $pieces, $params->id );
3841
+ $this->do_hook( "post_create_pod_item_{$params->pod}", $pieces, $params->id );
3842
+ }
3843
+ else {
3844
+ $this->do_hook( 'post_edit_pod_item', $pieces, $params->id );
3845
+ $this->do_hook( "post_edit_pod_item_{$params->pod}", $pieces, $params->id );
3846
+ }
3847
+
3848
+ // Call any post-save helpers (if not bypassed)
3849
+ if ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) {
3850
+ if ( !empty( $post_save_helpers ) ) {
3851
+ pods_deprecated( sprintf( __( 'Post-save helpers are deprecated, use the action pods_post_save_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
3852
+
3853
+ foreach ( $post_save_helpers as $helper ) {
3854
+ $helper = $this->load_helper( array( 'name' => $helper ) );
3855
+
3856
+ if ( false !== $helper && ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) )
3857
+ eval( '?>' . $helper[ 'code' ] );
3858
+ }
3859
+ }
3860
+ }
3861
+ }
3862
+
3863
+ // Success! Return the id
3864
+ return $params->id;
3865
+
3866
+ }
3867
+
3868
+ /**
3869
+ * @see PodsAPI::save_pod_item
3870
+ * Add multiple pod items
3871
+ *
3872
+ * $params['pod'] string The Pod name (pod or pod_id is required)
3873
+ * $params['pod_id'] string The Pod ID (pod or pod_id is required)
3874
+ * $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
3875
+ *
3876
+ * $data['id'] int The item ID (optional)
3877
+ * $data['data'] array An associative array of field names + values
3878
+ *
3879
+ * @param array|object $params An associative array of parameters, data excluded
3880
+ * @param array $data An associative array of pod ids and field names + values (arrays of field data)
3881
+ *
3882
+ * @return int The item ID
3883
+ * @since 2.0
3884
+ */
3885
+ public function save_pod_items ( $params, $data ) {
3886
+ $params = (object) $params;
3887
+
3888
+ $ids = array();
3889
+
3890
+ foreach ( $data as $fields ) {
3891
+ $params->data = $fields;
3892
+
3893
+ if ( isset( $fields[ 'id' ] ) && isset( $fields[ 'data' ] ) ) {
3894
+ $params->id = $fields[ 'id' ];
3895
+ $params->data = $fields[ 'data' ];
3896
+ }
3897
+
3898
+ $ids[] = $this->save_pod_item( $params );
3899
+ }
3900
+
3901
+ return $ids;
3902
+ }
3903
 
3904
+ /**
3905
+ * Get the fields that have changed during a save
3906
+ *
3907
+ * @param array $pieces Pieces array from save_pod_item
3908
+ *
3909
+ * @return array Array of fields and values that have changed
3910
+ */
3911
+ public function get_changed_fields( $pieces ) {
3912
 
3913
+ $fields = $pieces[ 'fields' ];
3914
+ $fields_active = $pieces[ 'fields_active' ];
 
 
 
 
 
 
 
 
 
3915
 
3916
+ $fields_changed = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3917
 
3918
+ if ( 0 < $pieces[ 'params' ]->id ) {
3919
+ $pod = pods( $pieces[ 'params' ]->pod, $pieces[ 'params' ]->id );
 
 
 
 
 
 
 
 
 
 
3920
 
3921
+ foreach ( $fields_active as $field ) {
3922
+ if ( isset( $fields[ $field ] ) && $pod->raw( $field ) != $fields[ $field ][ 'value' ] ) {
3923
+ $fields_changed[ $field ] = $fields[ $field ][ 'value' ];
 
3924
  }
3925
  }
3926
  }
3927
 
3928
+ return $fields_changed;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3929
 
3930
+ }
 
3931
 
3932
+ /**
3933
+ * Save relationships
3934
+ *
3935
+ * @param int $id ID of item
3936
+ * @param int|array $related_id ID or IDs to save
3937
+ * @param array $pod Pod data
3938
+ * @param array $field Field data
3939
+ */
3940
+ public function save_relationships ( $id, $related_ids, $pod, $field ) {
3941
+ // Get current values
3942
+ if ( 'pick' == $field[ 'type' ] && isset( PodsField_Pick::$related_data[ $field[ 'id' ] ] ) && isset( PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'current_ids' ] ) )
3943
+ $current_ids = PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'current_ids' ];
3944
+ else
3945
+ $current_ids = $this->lookup_related_items( $field[ 'id' ], $pod[ 'id' ], $id, $field, $pod );
3946
+
3947
+ if ( isset( self::$related_item_cache[ $pod['id'] ][ $field['id'] ] ) ) {
3948
+ // Delete relationship from cache
3949
+ unset( self::$related_item_cache[ $pod['id'] ][ $field['id'] ] );
3950
+ }
3951
+
3952
+ if ( !is_array( $related_ids ) )
3953
+ $related_ids = implode( ',', $related_ids );
3954
+
3955
+ foreach ( $related_ids as $k => $related_id ) {
3956
+ $related_ids[ $k ] = (int) $related_id;
3957
+ }
3958
+
3959
+ $related_ids = array_unique( array_filter( $related_ids ) );
3960
+
3961
+ $related_limit = (int) pods_var_raw( $field[ 'type' ] . '_limit', $field[ 'options' ], 0 );
3962
+
3963
+ if ( 'single' == pods_var_raw( $field[ 'type' ] . '_format_type', $field[ 'options' ] ) )
3964
+ $related_limit = 1;
3965
+
3966
+ // Limit values
3967
+ if ( 0 < $related_limit && !empty( $related_ids ) )
3968
+ $related_ids = array_slice( $related_ids, 0, $related_limit );
3969
+
3970
+ // Post Types, Media, Users, and Comments (meta-based)
3971
+ if ( in_array( $pod[ 'type' ], array( 'post_type', 'media', 'taxonomy', 'user', 'comment' ) ) ) {
3972
+ $object_type = $pod[ 'type' ];
3973
+
3974
+ if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
3975
+ $object_type = 'post';
3976
+ elseif ( 'taxonomy' == $object_type )
3977
+ $object_type = 'term';
3978
+
3979
+ delete_metadata( $object_type, $id, $field[ 'name' ] );
3980
+
3981
+ if ( !empty( $related_ids ) ) {
3982
+ update_metadata( $object_type, $id, '_pods_' . $field[ 'name' ], $related_ids );
3983
+
3984
+ foreach ( $related_ids as $related_id ) {
3985
+ add_metadata( $object_type, $id, $field[ 'name' ], $related_id );
3986
+ }
3987
+ }
3988
+ else
3989
+ delete_metadata( $object_type, $id, '_pods_' . $field[ 'name' ] );
3990
+ }
3991
+ // Custom Settings Pages (options-based)
3992
+ elseif ( 'settings' == $pod[ 'type' ] ) {
3993
+ if ( !empty( $related_ids ) )
3994
+ update_option( $pod[ 'name' ] . '_' . $field[ 'name' ], $related_ids );
3995
+ else
3996
+ delete_option( $pod[ 'name' ] . '_' . $field[ 'name' ] );
3997
+ }
3998
+
3999
+ $related_pod_id = $related_field_id = 0;
4000
+
4001
+ if ( 'pick' == $field[ 'type' ] && isset( PodsField_Pick::$related_data[ $field[ 'id' ] ] ) && !empty( PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'related_field' ] ) ) {
4002
+ $related_pod_id = PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'related_pod' ][ 'id' ];
4003
+ $related_field_id = PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'related_field' ][ 'id' ];
4004
+ }
4005
+
4006
+ // Relationships table
4007
+ if ( !pods_tableless() ) {
4008
+ $related_weight = 0;
4009
+
4010
+ foreach ( $related_ids as $related_id ) {
4011
+ if ( in_array( $related_id, $current_ids ) ) {
4012
+ pods_query( "
4013
+ UPDATE `@wp_podsrel`
4014
+ SET
4015
+ `pod_id` = %d,
4016
+ `field_id` = %d,
4017
+ `item_id` = %d,
4018
+ `related_pod_id` = %d,
4019
+ `related_field_id` = %d,
4020
+ `related_item_id` = %d,
4021
+ `weight` = %d
4022
+ WHERE
4023
+ `pod_id` = %d
4024
+ AND `field_id` = %d
4025
+ AND `item_id` = %d
4026
+ AND `related_item_id` = %d
4027
+ ", array(
4028
+ $pod[ 'id' ],
4029
+ $field[ 'id' ],
4030
+ $id,
4031
+ $related_pod_id,
4032
+ $related_field_id,
4033
+ $related_id,
4034
+ $related_weight,
4035
+
4036
+ $pod[ 'id' ],
4037
+ $field[ 'id' ],
4038
+ $id,
4039
+ $related_id,
4040
+ ) );
4041
+ }
4042
+ else {
4043
+ pods_query( "
4044
+ INSERT INTO `@wp_podsrel`
4045
+ (
4046
+ `pod_id`,
4047
+ `field_id`,
4048
+ `item_id`,
4049
+ `related_pod_id`,
4050
+ `related_field_id`,
4051
+ `related_item_id`,
4052
+ `weight`
4053
+ )
4054
+ VALUES ( %d, %d, %d, %d, %d, %d, %d )
4055
+ ", array(
4056
+ $pod[ 'id' ],
4057
+ $field[ 'id' ],
4058
+ $id,
4059
+ $related_pod_id,
4060
+ $related_field_id,
4061
+ $related_id,
4062
+ $related_weight
4063
+ ) );
4064
+ }
4065
+
4066
+ $related_weight++;
4067
+ }
4068
+ }
4069
+ }
4070
+
4071
+ /**
4072
+ * Duplicate a Pod
4073
+ *
4074
+ * $params['id'] int The Pod ID
4075
+ * $params['name'] string The Pod name
4076
+ * $params['new_name'] string The new Pod name
4077
+ *
4078
+ * @param array $params An associative array of parameters
4079
+ * @param bool $strict (optional) Makes sure a pod exists, if it doesn't throws an error
4080
+ *
4081
+ * @return int New Pod ID
4082
+ * @since 2.3
4083
+ */
4084
+ public function duplicate_pod ( $params, $strict = false ) {
4085
+ if ( !is_object( $params ) && !is_array( $params ) ) {
4086
+ if ( is_numeric( $params ) )
4087
+ $params = array( 'id' => $params );
4088
+ else
4089
+ $params = array( 'name' => $params );
4090
+
4091
+ $params = (object) pods_sanitize( $params );
4092
+ }
4093
+ else
4094
+ $params = (object) pods_sanitize( $params );
4095
+
4096
+ $params->table_info = false;
4097
+
4098
+ $pod = $this->load_pod( $params, $strict );
4099
+
4100
+ if ( empty( $pod ) ) {
4101
+ if ( false !== $strict )
4102
+ return pods_error( __( 'Pod not found', 'pods' ), $this );
4103
+
4104
+ return false;
4105
+ }
4106
+ elseif ( in_array( $pod[ 'type' ], array( 'media', 'user', 'comment' ) ) ) {
4107
+ if ( false !== $strict )
4108
+ return pods_error( __( 'Pod not allowed to be duplicated', 'pods' ), $this );
4109
+
4110
+ return false;
4111
+ }
4112
+ elseif ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && 0 < strlen( $pod[ 'object' ] ) ) {
4113
+ $pod[ 'object' ] = '';
4114
+ }
4115
+
4116
+ unset( $pod[ 'id' ] );
4117
+
4118
+ if ( isset( $params->new_name ) )
4119
+ $pod[ 'name' ] = $params->new_name;
4120
+
4121
+ $try = 1;
4122
+
4123
+ $check_name = $pod[ 'name' ];
4124
+ $new_label = $pod[ 'label' ];
4125
+
4126
+ while ( $this->load_pod( array( 'name' => $check_name, 'table_info' => false ), false ) ) {
4127
+ $try++;
4128
+
4129
+ $check_name = $pod[ 'name' ] . $try;
4130
+ $new_label = $pod[ 'label' ] . $try;
4131
+ }
4132
+
4133
+ $pod[ 'name' ] = $check_name;
4134
+ $pod[ 'label' ] = $new_label;
4135
+
4136
+ foreach ( $pod[ 'fields' ] as $field => $field_data ) {
4137
+ unset( $pod[ 'fields' ][ $field ][ 'id' ] );
4138
+ }
4139
+
4140
+ return $this->save_pod( $pod );
4141
+ }
4142
+
4143
+ /**
4144
+ * Duplicate a Field
4145
+ *
4146
+ * $params['pod_id'] int The Pod ID
4147
+ * $params['pod'] string The Pod name
4148
+ * $params['id'] int The Field ID
4149
+ * $params['name'] string The Field name
4150
+ * $params['new_name'] string The new Field name
4151
+ *
4152
+ * @param array $params An associative array of parameters
4153
+ * @param bool $strict (optional) Makes sure a field exists, if it doesn't throws an error
4154
+ *
4155
+ * @return int New Field ID
4156
+ * @since 2.3.10
4157
+ */
4158
+ public function duplicate_field( $params, $strict = false ) {
4159
 
4160
+ if ( !is_object( $params ) && !is_array( $params ) ) {
4161
+ if ( is_numeric( $params ) ) {
4162
+ $params = array( 'id' => $params );
 
 
 
4163
  }
4164
+ else {
4165
+ $params = array( 'name' => $params );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4166
  }
4167
  }
4168
 
4169
+ $params = (object) pods_sanitize( $params );
 
4170
 
4171
+ $params->table_info = false;
 
4172
 
4173
+ $field = $this->load_field( $params, $strict );
4174
 
4175
+ if ( empty( $field ) ) {
4176
+ if ( false !== $strict ) {
4177
+ return pods_error( __( 'Field not found', 'pods' ), $this );
4178
+ }
4179
 
4180
+ return false;
 
4181
  }
4182
 
4183
+ unset( $field[ 'id' ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4184
 
4185
+ if ( isset( $params->new_name ) ) {
4186
+ $field[ 'name' ] = $params->new_name;
4187
+ }
4188
 
4189
+ $try = 1;
 
 
 
 
 
4190
 
4191
+ $check_name = $field[ 'name' ];
4192
+ $new_label = $field[ 'label' ];
4193
 
4194
+ while ( $this->load_field( array( 'pod_id' => $field[ 'pod_id' ], 'name' => $check_name, 'table_info' => false ), false ) ) {
4195
+ $try++;
 
4196
 
4197
+ $check_name = $field[ 'name' ] . $try;
4198
+ $new_label = $field[ 'label' ] . $try;
4199
+ }
4200
 
4201
+ $field[ 'name' ] = $check_name;
4202
+ $field[ 'label' ] = $new_label;
4203
 
4204
+ return $this->save_field( $field );
 
4205
 
4206
+ }
 
 
4207
 
4208
+ /**
4209
+ * @see PodsAPI::save_pod_item
4210
+ *
4211
+ * Duplicate a pod item
4212
+ *
4213
+ * $params['pod'] string The Pod name
4214
+ * $params['id'] int The item's ID from the wp_pods_* table
4215
+ *
4216
+ * @param array $params An associative array of parameters
4217
+ *
4218
+ * @return int The table row ID
4219
+ *
4220
+ * @since 1.12
4221
+ */
4222
+ public function duplicate_pod_item ( $params ) {
4223
 
4224
+ $params = (object) pods_sanitize( $params );
 
 
4225
 
4226
+ $load_pod_params = array(
4227
+ 'name' => $params->pod,
4228
+ 'table_info' => false,
4229
+ );
4230
 
4231
+ $pod = $this->load_pod( $load_pod_params );
4232
 
4233
+ if ( false === $pod ) {
4234
+ return pods_error( __( 'Pod not found', 'pods' ), $this );
4235
+ }
 
 
 
 
 
 
 
 
 
4236
 
4237
+ $pod = pods( $params->pod, $params->id );
 
 
 
 
4238
 
4239
+ $params->pod = $pod->pod;
4240
+ $params->pod_id = $pod->pod_id;
 
 
 
4241
 
4242
+ $fields = (array) pods_var_raw( 'fields', $pod->pod_data, array(), null, true );
4243
+ $object_fields = (array) pods_var_raw( 'object_fields', $pod->pod_data, array(), null, true );
 
 
 
 
 
4244
 
4245
+ if ( ! empty( $object_fields ) ) {
4246
+ $fields = array_merge( $object_fields, $fields );
 
 
4247
  }
4248
 
4249
+ $save_params = array(
4250
+ 'pod' => $params->pod,
4251
+ 'data' => array()
4252
+ );
4253
 
4254
+ $ignore_fields = array(
4255
+ $pod->pod_data['field_id'],
4256
+ $pod->pod_data['field_slug'],
4257
+ );
4258
 
4259
+ if ( in_array( $pod->pod_data['type'], array( 'post_type', 'media' ) ) ) {
4260
+ $ignore_fields = array(
4261
+ 'ID',
4262
+ 'post_name',
4263
+ 'post_date',
4264
+ 'post_date_gmt',
4265
+ 'post_modified',
4266
+ 'post_modified_gmt',
4267
+ 'guid',
4268
+ );
4269
+ } elseif ( 'term' == $pod->pod_data['type'] ) {
4270
+ $ignore_fields = array(
4271
+ 'term_id',
4272
+ 'term_taxonomy_id',
4273
+ 'slug',
4274
+ );
4275
+ } elseif ( 'user' == $pod->pod_data['type'] ) {
4276
+ $ignore_fields = array(
4277
+ 'ID',
4278
+ 'user_nicename',
4279
+ );
4280
+ } elseif ( 'comment' == $pod->pod_data['type'] ) {
4281
+ $ignore_fields = array(
4282
+ 'comment_ID',
4283
+ );
4284
+ } elseif ( 'settings' == $pod->pod_data['type'] ) {
4285
+ return pods_error( __( 'Settings do not support duplication.', 'pods' ), $this );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4286
  }
4287
 
4288
+ /**
4289
+ * Filter the fields to ignore during duplication
4290
+ *
4291
+ * @since 2.6.6
4292
+ *
4293
+ * @param array $ignore_fields Fields to ignore and not save during duplication
4294
+ * @param Pods $pod Pod object
4295
+ * @param array $fields Fields on the pod to duplicate
4296
+ * @param object $params Params passed into duplicate_pod_item()
4297
+ */
4298
+ $ignore_fields = apply_filters( 'pods_api_duplicate_pod_item_ignore_fields', $ignore_fields, $pod, $fields, $params );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4299
 
4300
+ foreach ( $fields as $field ) {
4301
+ if ( in_array( $field['name'], $ignore_fields ) ) {
4302
+ continue;
 
4303
  }
4304
 
4305
+ $field = array(
4306
+ 'name' => $field['name'],
4307
+ 'output' => 'ids'
4308
+ );
4309
 
4310
+ $value = $pod->field( $field );
 
4311
 
4312
+ // @todo Add post type compatibility to set unique post_title
4313
+ // @todo Add term compatibility to set unique name
4314
+ // @todo Add user compatibility to set unique user_login/user_email
 
4315
 
4316
+ if ( ! empty( $value ) || ( ! is_array( $value ) && 0 < strlen( $value ) ) ) {
4317
+ $save_params['data'][ $field['name'] ] = $value;
4318
  }
 
 
4319
  }
4320
 
4321
+ $save_params = $this->do_hook( 'duplicate_pod_item', $save_params, $pod->pod, $pod->id(), $params );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4322
 
4323
+ $id = $this->save_pod_item( $save_params );
 
4324
 
4325
+ return $id;
 
 
 
 
 
 
4326
 
 
4327
  }
4328
 
4329
+ /**
4330
+ * @see pods()
4331
+ *
4332
+ * Export a pod item
4333
+ *
4334
+ * $params['pod'] string The Pod name
4335
+ * $params['id'] int The item's ID from the wp_pods_* table
4336
+ * $params['fields'] array The fields to export
4337
+ * $params['depth'] int How many levels deep to export data
4338
+ *
4339
+ * @param array $params An associative array of parameters
4340
+ * @param object $pod (optional) Pods object
4341
+ *
4342
+ * @return int The table row ID
4343
+ * @since 1.12
4344
+ */
4345
+ public function export_pod_item ( $params, $pod = null ) {
4346
+ if ( !is_object( $pod ) || 'Pods' != get_class( $pod ) ) {
4347
+ if ( empty( $params ) )
4348
+ return false;
4349
+
4350
+ $params = (object) pods_sanitize( $params );
4351
+
4352
+ $pod = pods( $params->pod, $params->id, false );
4353
+
4354
+ if ( empty( $pod ) )
4355
+ return false;
4356
+ }
4357
+
4358
+ $fields = (array) pods_var_raw( 'fields', $params, array(), null, true );
4359
+ $depth = (int) pods_var_raw( 'depth', $params, 2, null, true );
4360
+ $object_fields = (array) pods_var_raw( 'object_fields', $pod->pod_data, array(), null, true );
4361
+ $flatten = (boolean) pods_var( 'flatten', $params, false, null, true );
4362
+
4363
+ if ( empty( $fields ) ) {
4364
+ $fields = $pod->fields;
4365
+ $fields = array_merge( $fields, $object_fields );
4366
+ }
4367
+
4368
+ $data = $this->export_pod_item_level( $pod, $fields, $depth, $flatten );
4369
+
4370
+ $data = $this->do_hook( 'export_pod_item', $data, $pod->pod, $pod->id(), $pod, $fields, $depth, $flatten );
4371
+
4372
+ return $data;
4373
+ }
4374
+
4375
+ /**
4376
+ * Export a pod item by depth level
4377
+ *
4378
+ * @param Pods $pod Pods object
4379
+ * @param array $fields Fields to export
4380
+ * @param int $depth Depth limit
4381
+ * @param boolean $flatten Whether to flatten arrays for display
4382
+ * @param int $current_depth Current depth level
4383
+ *
4384
+ * @return array Data array
4385
+ *
4386
+ * @since 2.3
4387
+ */
4388
+ private function export_pod_item_level ( $pod, $fields, $depth, $flatten = false, $current_depth = 1 ) {
4389
+ $tableless_field_types = PodsForm::tableless_field_types();
4390
+ $simple_tableless_objects = PodsForm::simple_tableless_objects();
4391
+
4392
+ $object_fields = (array) pods_var_raw( 'object_fields', $pod->pod_data, array(), null, true );
4393
+
4394
+ $export_fields = array();
4395
+
4396
+ foreach ( $fields as $k => $field ) {
4397
+ if ( !is_array( $field ) ) {
4398
+ $field = array(
4399
+ 'id' => 0,
4400
+ 'name' => $field
4401
+ );
4402
+ }
4403
+
4404
+ if ( isset( $pod->fields[ $field[ 'name' ] ] ) ) {
4405
+ $field = $pod->fields[ $field[ 'name' ] ];
4406
+ $field[ 'lookup_name' ] = $field[ 'name' ];
4407
+
4408
+ if ( in_array( $field[ 'type' ], $tableless_field_types ) && !in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) {
4409
+ if ( 'pick' == $field[ 'type' ] ) {
4410
+ if ( empty( $field[ 'table_info' ] ) )
4411
+ $field[ 'table_info' ] = $this->get_table_info( pods_var_raw( 'pick_object', $field ), pods_var_raw( 'pick_val', $field ), null, null, $field );
4412
+
4413
+ if ( !empty( $field[ 'table_info' ] ) )
4414
+ $field[ 'lookup_name' ] .= '.' . $field[ 'table_info' ][ 'field_id' ];
4415
+ }
4416
+ elseif ( in_array( $field[ 'type' ], PodsForm::file_field_types() ) )
4417
+ $field[ 'lookup_name' ] .= '.guid';
4418
+ }
4419
+
4420
+ $export_fields[ $field[ 'name' ] ] = $field;
4421
+ }
4422
+ elseif ( isset( $object_fields[ $field[ 'name' ] ] ) ) {
4423
+ $field = $object_fields[ $field[ 'name' ] ];
4424
+ $field[ 'lookup_name' ] = $field[ 'name' ];
4425
+
4426
+ $export_fields[ $field[ 'name' ] ] = $field;
4427
+ }
4428
+ elseif ( $field[ 'name' ] == $pod->pod_data[ 'field_id' ] ) {
4429
+ $field[ 'type' ] = 'number';
4430
+ $field[ 'lookup_name' ] = $field[ 'name' ];
4431
+
4432
+ $export_fields[ $field[ 'name' ] ] = $field;
4433
+ }
4434
+ }
4435
+
4436
+ $data = array();
4437
+
4438
+ foreach ( $export_fields as $field ) {
4439
+ // Return IDs (or guid for files) if only one level deep
4440
+ if ( 1 == $depth )
4441
+ $data[ $field[ 'name' ] ] = $pod->field( array( 'name' => $field[ 'lookup_name' ], 'output' => 'arrays' ) );
4442
+ // Recurse depth levels for pick fields if $depth allows
4443
+ elseif ( ( -1 == $depth || $current_depth < $depth ) && 'pick' == $field[ 'type' ] && !in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) {
4444
+ $related_data = array();
4445
+
4446
+ $related_ids = $pod->field( array( 'name' => $field[ 'name' ], 'output' => 'ids' ) );
4447
+
4448
+ if ( !empty( $related_ids ) ) {
4449
+ $related_ids = (array) $related_ids;
4450
+
4451
+ $pick_object = pods_var_raw( 'pick_object', $field );
4452
+
4453
+ $related_pod = pods( pods_var_raw( 'pick_val', $field ), null, false );
4454
+
4455
+ // If this isn't a Pod, return data exactly as Pods does normally
4456
+ if ( empty( $related_pod ) || ( 'pod' != $pick_object && $pick_object != $related_pod->pod_data[ 'type' ] ) || $related_pod->pod == $pod->pod )
4457
+ $related_data = $pod->field( array( 'name' => $field[ 'name' ], 'output' => 'arrays' ) );
4458
+ else {
4459
+ $related_object_fields = (array) pods_var_raw( 'object_fields', $related_pod->pod_data, array(), null, true );
4460
+
4461
+ $related_fields = array_merge( $related_pod->fields, $related_object_fields );
4462
+
4463
+ foreach ( $related_ids as $related_id ) {
4464
+ if ( $related_pod->fetch( $related_id ) ) {
4465
+ $related_item = $this->export_pod_item_level( $related_pod, $related_fields, $depth, $flatten, ( $current_depth + 1 ) );
4466
+
4467
+ $related_data[ $related_id ] = $this->do_hook( 'export_pod_item_level', $related_item, $related_pod->pod, $related_pod->id(), $related_pod, $related_fields, $depth, $flatten, ( $current_depth + 1 ) );
4468
+ }
4469
+ }
4470
+
4471
+ if ( $flatten && !empty( $related_data ) )
4472
+ $related_data = pods_serial_comma( array_values( $related_data ), array( 'and' => '', 'field_index' => $related_pod->pod_data[ 'field_index' ] ) );
4473
+ }
4474
+ }
4475
+
4476
+ $data[ $field[ 'name' ] ] = $related_data;
4477
+ }
4478
+ // Return data exactly as Pods does normally
4479
+ else
4480
+ $data[ $field[ 'name' ] ] = $pod->field( array( 'name' => $field[ 'name' ], 'output' => 'arrays' ) );
4481
+
4482
+ if ( $flatten && is_array( $data[ $field[ 'name' ] ] ) )
4483
+ $data[ $field[ 'name' ] ] = pods_serial_comma( $data[ $field[ 'name' ] ], array( 'field' => $field[ 'name' ], 'fields' => $export_fields, 'and' => '' ) );
4484
+ }
4485
+
4486
+ $data[ 'id' ] = (int) $pod->id();
4487
+ return $data;
4488
+ }
4489
+
4490
+ /**
4491
+ * Reorder a Pod
4492
+ *
4493
+ * $params['pod'] string The Pod name
4494
+ * $params['field'] string The field name of the field to reorder
4495
+ * $params['order'] array The key => value array of items to reorder (key should be an integer)
4496
+ *
4497
+ * @param array $params An associative array of parameters
4498
+ *
4499
+ * @return bool
4500
+ *
4501
+ * @since 1.9.0
4502
+ */
4503
+ public function reorder_pod_item ( $params ) {
4504
+ $params = (object) pods_sanitize( $params );
4505
+
4506
+ // @deprecated 2.0
4507
+ if ( isset( $params->datatype ) ) {
4508
+ pods_deprecated( __( '$params->pod instead of $params->datatype', 'pods' ), '2.0' );
4509
+
4510
+ $params->pod = $params->datatype;
4511
+
4512
+ unset( $params->datatype );
4513
+ }
4514
+
4515
+ if ( null === pods_var_raw( 'pod', $params, null, null, true ) )
4516
+ return pods_error( __( '$params->pod is required', 'pods' ), $this );
4517
+
4518
+ if ( !is_array( $params->order ) )
4519
+ $params->order = explode( ',', $params->order );
4520
+
4521
+ $pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => true ) );
4522
+
4523
+ $params->name = $pod[ 'name' ];
4524
+
4525
+ if ( false === $pod )
4526
+ return pods_error( __( 'Pod is required', 'pods' ), $this );
4527
+
4528
+ foreach ( $params->order as $order => $id ) {
4529
+ if ( isset( $pod[ 'fields' ][ $params->field ] ) || isset( $pod[ 'object_fields' ][ $params->field ] ) ) {
4530
+ if ( 'table' == $pod[ 'storage' ] && ( !pods_tableless() ) ) {
4531
+ if ( isset( $pod[ 'fields' ][ $params->field ] ) )
4532
+ pods_query( "UPDATE `@wp_pods_{$params->name}` SET `{$params->field}` = " . pods_absint( $order ) . " WHERE `id` = " . pods_absint( $id ) . " LIMIT 1" );
4533
+ else
4534
+ pods_query( "UPDATE `{$pod['table']}` SET `{$params->field}` = " . pods_absint( $order ) . " WHERE `{$pod['field_id']}` = " . pods_absint( $id ) . " LIMIT 1" );
4535
+ }
4536
+ else
4537
+ $this->save_pod_item( array( 'pod' => $params->pod, 'pod_id' => $params->pod_id, 'id' => $id, 'data' => array( $params->field => pods_absint( $order ) ) ) );
4538
+ }
4539
+ }
4540
+
4541
+ return true;
4542
+ }
4543
+
4544
+ /**
4545
+ *
4546
+ * Delete all content for a Pod
4547
+ *
4548
+ * $params['id'] int The Pod ID
4549
+ * $params['name'] string The Pod name
4550
+ *
4551
+ * @param array $params An associative array of parameters
4552
+ * @param array $pod Pod data
4553
+ *
4554
+ * @return bool
4555
+ *
4556
+ * @uses pods_query
4557
+ * @uses pods_cache_clear
4558
+ *
4559
+ * @since 1.9.0
4560
+ */
4561
+ public function reset_pod ( $params, $pod = false ) {
4562
+ $params = (object) pods_sanitize( $params );
4563
+
4564
+ $params->table_info = true;
4565
+
4566
+ if ( empty( $pod ) )
4567
+ $pod = $this->load_pod( $params );
4568
+
4569
+ if ( false === $pod )
4570
+ return pods_error( __( 'Pod not found', 'pods' ), $this );
4571
+
4572
+ $params->id = $pod[ 'id' ];
4573
+ $params->name = $pod[ 'name' ];
4574
+
4575
+ if ( !pods_tableless() ) {
4576
+ if ( 'table' == $pod[ 'storage' ] ) {
4577
+ try {
4578
+ pods_query( "TRUNCATE `@wp_pods_{$params->name}`", false );
4579
+ }
4580
+ catch ( Exception $e ) {
4581
+ // Allow pod to be reset if the table doesn't exist
4582
+ if ( false === strpos( $e->getMessage(), 'Unknown table' ) )
4583
+ return pods_error( $e->getMessage(), $this );
4584
+ }
4585
+ }
4586
+
4587
+ pods_query( "DELETE FROM `@wp_podsrel` WHERE `pod_id` = {$params->id} OR `related_pod_id` = {$params->id}", false );
4588
+ }
4589
+
4590
+ // @todo Delete relationships from tableless relationships
4591
+
4592
+ // Delete all posts/revisions from this post type
4593
+ if ( in_array( $pod[ 'type' ], array( 'post_type', 'media' ) ) ) {
4594
+ $type = pods_var( 'object', $pod, $pod[ 'name' ], null, true );
4595
+
4596
+ $sql = "
4597
+ DELETE `t`, `r`, `m`
4598
+ FROM `{$pod['table']}` AS `t`
4599
+ LEFT JOIN `{$pod['meta_table']}` AS `m`
4600
+ ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
4601
+ LEFT JOIN `{$pod['table']}` AS `r`
4602
+ ON `r`.`post_parent` = `t`.`{$pod['field_id']}` AND `r`.`post_status` = 'inherit'
4603
+ WHERE `t`.`{$pod['field_type']}` = '{$type}'
4604
+ ";
4605
+
4606
+ pods_query( $sql, false );
4607
+ }
4608
+ // Delete all terms from this taxonomy
4609
+ elseif ( 'taxonomy' == $pod[ 'type' ] ) {
4610
+ if ( function_exists( 'get_term_meta' ) ) {
4611
+ $sql = "
4612
+ DELETE `t`, `m`, `tt`, `tr`
4613
+ FROM `{$pod['table']}` AS `t`
4614
+ LEFT JOIN `{$pod['meta_table']}` AS `m`
4615
+ ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
4616
+ " . $pod['join']['tt'] . "
4617
+ " . $pod['join']['tr'] . "
4618
+ WHERE " . implode( ' AND ', $pod['where'] ) . "
4619
+ ";
4620
+ } else {
4621
+ $sql = "
4622
+ DELETE `t`, `tt`, `tr`
4623
+ FROM `{$pod['table']}` AS `t`
4624
+ " . $pod['join']['tt'] . "
4625
+ " . $pod['join']['tr'] . "
4626
+ WHERE " . implode( ' AND ', $pod['where'] ) . "
4627
+ ";
4628
+ }
4629
+
4630
+ pods_query( $sql, false );
4631
+ }
4632
+ // Delete all users except the current one
4633
+ elseif ( 'user' == $pod[ 'type' ] ) {
4634
+ $sql = "
4635
+ DELETE `t`, `m`
4636
+ FROM `{$pod['table']}` AS `t`
4637
+ LEFT JOIN `{$pod['meta_table']}` AS `m`
4638
+ ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
4639
+ WHERE `t`.`{$pod['field_id']}` != " . (int) get_current_user_id() . "
4640
+ ";
4641
+
4642
+ pods_query( $sql, false );
4643
+ }
4644
+ // Delete all comments
4645
+ elseif ( 'comment' == $pod[ 'type' ] ) {
4646
+ $type = pods_var( 'object', $pod, $pod[ 'name' ], null, true );
4647
+
4648
+ $sql = "
4649
+ DELETE `t`, `m`
4650
+ FROM `{$pod['table']}` AS `t`
4651
+ LEFT JOIN `{$pod['meta_table']}` AS `m`
4652
+ ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
4653
+ WHERE `t`.`{$pod['field_type']}` = '{$type}'
4654
+ ";
4655
+
4656
+ pods_query( $sql, false );
4657
+ }
4658
+
4659
+ pods_cache_clear( true ); // only way to reliably clear out cached data across an entire group
4660
+
4661
+ return true;
4662
+ }
4663
+
4664
+ /**
4665
+ * Delete a Pod and all its content
4666
+ *
4667
+ * $params['id'] int The Pod ID
4668
+ * $params['name'] string The Pod name
4669
+ *
4670
+ * @param array $params An associative array of parameters
4671
+ * @param bool $strict (optional) Makes sure a pod exists, if it doesn't throws an error
4672
+ * @param bool $delete_all (optional) Whether to delete all content from a WP object
4673
+ *
4674
+ * @uses PodsAPI::load_pod
4675
+ * @uses wp_delete_post
4676
+ * @uses pods_query
4677
+ *
4678
+ * @return bool
4679
+ * @since 1.7.9
4680
+ */
4681
+ public function delete_pod ( $params, $strict = false, $delete_all = false ) {
4682
+ /**
4683
+ * @var $wpdb wpdb
4684
+ */
4685
+ global $wpdb;
4686
+
4687
+ if ( !is_object( $params ) && !is_array( $params ) ) {
4688
+ if ( is_numeric( $params ) )
4689
+ $params = array( 'id' => $params );
4690
+ else
4691
+ $params = array( 'name' => $params );
4692
+
4693
+ $params = (object) pods_sanitize( $params );
4694
+ }
4695
+ else
4696
+ $params = (object) pods_sanitize( $params );
4697
+
4698
+ $params->table_info = false;
4699
+
4700
+ $pod = $this->load_pod( $params, $strict );
4701
+
4702
+ if ( empty( $pod ) ) {
4703
+ if ( false !== $strict )
4704
+ return pods_error( __( 'Pod not found', 'pods' ), $this );
4705
+
4706
+ return false;
4707
+ }
4708
+
4709
+ $params->id = (int) $pod[ 'id' ];
4710
+ $params->name = $pod[ 'name' ];
4711
+
4712
+ foreach ( $pod[ 'fields' ] as $field ) {
4713
+ $field[ 'pod' ] = $pod;
4714
+
4715
+ $this->delete_field( $field, false );
4716
+ }
4717
+
4718
+ // Only delete the post once the fields are taken care of, it's not required anymore
4719
+ $success = wp_delete_post( $params->id );
4720
+
4721
+ if ( !$success )
4722
+ return pods_error( __( 'Pod unable to be deleted', 'pods' ), $this );
4723
+
4724
+ // Reset content
4725
+ if ( $delete_all )
4726
+ $this->reset_pod( $params, $pod );
4727
+
4728
+ if ( !pods_tableless() ) {
4729
+ if ( 'table' == $pod[ 'storage' ] ) {
4730
+ try {
4731
+ pods_query( "DROP TABLE IF EXISTS `@wp_pods_{$params->name}`", false );
4732
+ }
4733
+ catch ( Exception $e ) {
4734
+ // Allow pod to be deleted if the table doesn't exist
4735
+ if ( false === strpos( $e->getMessage(), 'Unknown table' ) )
4736
+ return pods_error( $e->getMessage(), $this );
4737
+ }
4738
+ }
4739
+
4740
+ pods_query( "DELETE FROM `@wp_podsrel` WHERE `pod_id` = {$params->id} OR `related_pod_id` = {$params->id}", false );
4741
+ }
4742
+
4743
+ // @todo Delete relationships from tableless relationships
4744
+
4745
+ // Delete any relationship references
4746
+ $sql = "
4747
+ DELETE `pm`
4748
+ FROM `{$wpdb->postmeta}` AS `pm`
4749
+ LEFT JOIN `{$wpdb->posts}` AS `p`
4750
+ ON `p`.`post_type` = '_pods_field'
4751
+ AND `p`.`ID` = `pm`.`post_id`
4752
+ LEFT JOIN `{$wpdb->postmeta}` AS `pm2`
4753
+ ON `pm2`.`meta_key` = 'pick_object'
4754
+ AND `pm2`.`meta_value` = 'pod'
4755
+ AND `pm2`.`post_id` = `pm`.`post_id`
4756
+ WHERE
4757
+ `p`.`ID` IS NOT NULL
4758
+ AND `pm2`.`meta_id` IS NOT NULL
4759
+ AND `pm`.`meta_key` = 'pick_val'
4760
+ AND `pm`.`meta_value` = '{$params->name}'
4761
+ ";
4762
+
4763
+ pods_query( $sql );
4764
+
4765
+ $this->cache_flush_pods( $pod );
4766
+
4767
+ return true;
4768
+ }
4769
+
4770
+ /**
4771
+ * Drop a field within a Pod
4772
+ *
4773
+ * $params['id'] int The field ID
4774
+ * $params['name'] int The field name
4775
+ * $params['pod'] string The Pod name
4776
+ * $params['pod_id'] string The Pod name
4777
+ *
4778
+ * @param array $params An associative array of parameters
4779
+ * @param bool $table_operation Whether or not to handle table operations
4780
+ *
4781
+ * @uses PodsAPI::load_field
4782
+ * @uses wp_delete_post
4783
+ * @uses pods_query
4784
+ *
4785
+ * @return bool
4786
+ * @since 1.7.9
4787
+ */
4788
+ public function delete_field ( $params, $table_operation = true ) {
4789
+ /**
4790
+ * @var $wpdb wpdb
4791
+ */
4792
+ global $wpdb;
4793
+
4794
+ $tableless_field_types = PodsForm::tableless_field_types();
4795
+ $simple_tableless_objects = PodsForm::simple_tableless_objects();
4796
+
4797
+ $params = (object) pods_sanitize( $params );
4798
+
4799
+ if ( !isset( $params->pod ) )
4800
+ $params->pod = '';
4801
+
4802
+ if ( !isset( $params->pod_id ) )
4803
+ $params->pod_id = 0;
4804
+
4805
+ $pod = $params->pod;
4806
+
4807
+ $save_pod = false;
4808
+
4809
+ if ( !is_array( $pod ) )
4810
+ $pod = $this->load_pod( array( 'name' => $pod, 'id' => $params->pod_id, 'table_info' => false ) );
4811
+ else
4812
+ $save_pod = true;
4813
+
4814
+ if ( empty( $pod ) )
4815
+ return pods_error( __( 'Pod not found', 'pods' ), $this );
4816
+
4817
+ $params->pod_id = $pod[ 'id' ];
4818
+ $params->pod = $pod[ 'name' ];
4819
+
4820
+ if ( !isset( $params->name ) )
4821
+ $params->name = '';
4822
+
4823
+ if ( !isset( $params->id ) )
4824
+ $params->id = 0;
4825
+
4826
+ $field = $this->load_field( array( 'name' => $params->name, 'id' => $params->id, 'pod' => $params->pod, 'pod_id' => $params->pod_id ) );
4827
+
4828
+ if ( false === $field )
4829
+ return pods_error( __( 'Field not found', 'pods' ), $this );
4830
+
4831
+ $params->id = $field[ 'id' ];
4832
+ $params->name = $field[ 'name' ];
4833
+
4834
+ $simple = ( 'pick' == $field[ 'type' ] && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) );
4835
+ $simple = (boolean) $this->do_hook( 'tableless_custom', $simple, $field, $pod, $params );
4836
+
4837
+ if ( $table_operation && 'table' == $pod[ 'storage' ] && ( !in_array( $field[ 'type' ], $tableless_field_types ) || $simple ) )
4838
+ pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` DROP COLUMN `{$params->name}`", false );
4839
+
4840
+ $success = wp_delete_post( $params->id );
4841
+
4842
+ if ( !$success )
4843
+ return pods_error( __( 'Field unable to be deleted', 'pods' ), $this );
4844
+
4845
+ $wpdb->query( $wpdb->prepare( "DELETE pm FROM {$wpdb->postmeta} AS pm
4846
+ LEFT JOIN {$wpdb->posts} AS p
4847
+ ON p.post_type = '_pods_field' AND p.ID = pm.post_id
4848
+ WHERE p.ID IS NOT NULL AND pm.meta_key = 'sister_id' AND pm.meta_value = %d", $params->id ) );
4849
+
4850
+ if ( ( !pods_tableless() ) && $table_operation ) {
4851
+ pods_query( "DELETE FROM `@wp_podsrel` WHERE (`pod_id` = {$params->pod_id} AND `field_id` = {$params->id}) OR (`related_pod_id` = {$params->pod_id} AND `related_field_id` = {$params->id})", false );
4852
+ }
4853
+
4854
+ // @todo Delete tableless relationship meta
4855
+
4856
+ if ( true === $save_pod )
4857
+ $this->cache_flush_pods( $pod );
4858
+
4859
+ return true;
4860
+ }
4861
+
4862
+ /**
4863
+ * Drop a Pod Object
4864
+ *
4865
+ * $params['id'] int The object ID
4866
+ * $params['name'] string The object name
4867
+ * $params['type'] string The object type
4868
+ *
4869
+ * @param array|object $params An associative array of parameters
4870
+ *
4871
+ * @uses wp_delete_post
4872
+ *
4873
+ * @return bool
4874
+ * @since 2.0
4875
+ */
4876
+ public function delete_object ( $params ) {
4877
+ $params = (object) $params;
4878
+ $object = $this->load_object( $params );
4879
+
4880
+ if ( empty( $object ) )
4881
+ return pods_error( sprintf( __( "%s Object not found", 'pods' ), ucwords( $params->type ) ), $this );
4882
+
4883
+ $success = wp_delete_post( $params->id );
4884
+
4885
+ if ( !$success )
4886
+ return pods_error( sprintf( __( "%s Object not deleted", 'pods' ), ucwords( $params->type ) ), $this );
4887
+
4888
+ pods_transient_clear( 'pods_objects_' . $params->type );
4889
+
4890
+ return true;
4891
+ }
4892
+
4893
+ /**
4894
+ * @see PodsAPI::delete_object
4895
+ *
4896
+ * Drop a Pod Template
4897
+ *
4898
+ * $params['id'] int The template ID
4899
+ * $params['name'] string The template name
4900
+ *
4901
+ * @param array $params An associative array of parameters
4902
+ *
4903
+ * @return bool
4904
+ * @since 1.7.9
4905
+ */
4906
+ public function delete_template ( $params ) {
4907
+ $params = (object) $params;
4908
+ $params->type = 'template';
4909
+ return $this->delete_object( $params );
4910
+ }
4911
+
4912
+ /**
4913
+ * @see PodsAPI::delete_object
4914
+ *
4915
+ * Drop a Pod Page
4916
+ *
4917
+ * $params['id'] int The page ID
4918
+ * $params['uri'] string The page URI
4919
+ *
4920
+ * @param array $params An associative array of parameters
4921
+ *
4922
+ * @return bool
4923
+ * @since 1.7.9
4924
+ */
4925
+ public function delete_page ( $params ) {
4926
+ $params = (object) $params;
4927
+ if ( isset( $params->uri ) ) {
4928
+ $params->name = $params->uri;
4929
+ unset( $params->uri );
4930
+ }
4931
+ if ( isset( $params->name ) )
4932
+ $params->name = trim( $params->name, '/' );
4933
+ $params->type = 'page';
4934
+ return $this->delete_object( $params );
4935
+ }
4936
+
4937
+ /**
4938
+ * @see PodsAPI::delete_object
4939
+ *
4940
+ * Drop a Pod Helper
4941
+ *
4942
+ * $params['id'] int The helper ID
4943
+ * $params['name'] string The helper name
4944
+ *
4945
+ * @param array $params An associative array of parameters
4946
+ *
4947
+ * @return bool
4948
+ * @since 1.7.9
4949
+ */
4950
+ public function delete_helper ( $params ) {
4951
+ $params = (object) $params;
4952
+ $params->type = 'helper';
4953
+ return $this->delete_object( $params );
4954
+ }
4955
+
4956
+ /**
4957
+ * Drop a single pod item
4958
+ *
4959
+ * $params['id'] int (optional) The item's ID from the wp_pod_* table (used with datatype parameter)
4960
+ * $params['pod'] string (optional) The Pod name (used with id parameter)
4961
+ * $params['pod_id'] int (optional) The Pod ID (used with id parameter)
4962
+ * $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
4963
+ *
4964
+ * @param array $params An associative array of parameters
4965
+ * @param bool $wp Whether to run WP object delete action
4966
+ *
4967
+ * @return bool
4968
+ * @since 1.7.9
4969
+ */
4970
+ public function delete_pod_item ( $params, $wp = true ) {
4971
+ $params = (object) pods_sanitize( $params );
4972
+
4973
+ // @deprecated 2.0
4974
+ if ( isset( $params->datatype_id ) || isset( $params->datatype ) || isset( $params->tbl_row_id ) ) {
4975
+ if ( isset( $params->tbl_row_id ) ) {
4976
+ pods_deprecated( __( '$params->id instead of $params->tbl_row_id', 'pods' ), '2.0' );
4977
+ $params->id = $params->tbl_row_id;
4978
+ unset( $params->tbl_row_id );
4979
+ }
4980
+
4981
+ if ( isset( $params->pod_id ) ) {
4982
+ pods_deprecated( __( '$params->id instead of $params->pod_id', 'pods' ), '2.0' );
4983
+ $params->id = $params->pod_id;
4984
+ unset( $params->pod_id );
4985
+ }
4986
+
4987
+ if ( isset( $params->dataype_id ) ) {
4988
+ pods_deprecated( __( '$params->pod_id instead of $params->datatype_id', 'pods' ), '2.0' );
4989
+ $params->pod_id = $params->dataype_id;
4990
+ unset( $params->dataype_id );
4991
+ }
4992
+
4993
+ if ( isset( $params->datatype ) ) {
4994
+ pods_deprecated( __( '$params->pod instead of $params->datatype', 'pods' ), '2.0' );
4995
+ $params->pod = $params->datatype;
4996
+ unset( $params->datatype );
4997
+ }
4998
+ }
4999
+
5000
+ if ( !isset( $params->id ) )
5001
+ return pods_error( __( 'Pod Item not found', 'pods' ), $this );
5002
+
5003
+ $params->id = pods_absint( $params->id );
5004
+
5005
+ if ( !isset( $params->pod ) )
5006
+ $params->pod = '';
5007
+
5008
+ if ( !isset( $params->pod_id ) )
5009
+ $params->pod_id = 0;
5010
+
5011
+ $pod = $this->load_pod( array( 'name' => $params->pod, 'id' => $params->pod_id, 'table_info' => false ) );
5012
+
5013
+ if ( false === $pod )
5014
+ return pods_error( __( 'Pod not found', 'pods' ), $this );
5015
+
5016
+ $params->pod_id = $pod[ 'id' ];
5017
+ $params->pod = $pod[ 'name' ];
5018
+
5019
+ // Allow Helpers to bypass subsequent helpers in recursive delete_pod_item calls
5020
+ $bypass_helpers = false;
5021
+
5022
+ if ( isset( $params->bypass_helpers ) && false !== $params->bypass_helpers )
5023
+ $bypass_helpers = true;
5024
+
5025
+ $pre_delete_helpers = $post_delete_helpers = array();
5026
+
5027
+ if ( false === $bypass_helpers ) {
5028
+ // Plugin hook
5029
+ $this->do_hook( 'pre_delete_pod_item', $params, $pod );
5030
+ $this->do_hook( "pre_delete_pod_item_{$params->pod}", $params, $pod );
5031
+
5032
+ // Call any pre-save helpers (if not bypassed)
5033
+ if ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) {
5034
+ if ( !empty( $pod[ 'options' ] ) && is_array( $pod[ 'options' ] ) ) {
5035
+ $helpers = array( 'pre_delete_helpers', 'post_delete_helpers' );
5036
+
5037
+ foreach ( $helpers as $helper ) {
5038
+ if ( isset( $pod[ 'options' ][ $helper ] ) && !empty( $pod[ 'options' ][ $helper ] ) )
5039
+ ${$helper} = explode( ',', $pod[ 'options' ][ $helper ] );
5040
+ }
5041
+ }
5042
+
5043
+ if ( !empty( $pre_delete_helpers ) ) {
5044
+ pods_deprecated( sprintf( __( 'Pre-delete helpers are deprecated, use the action pods_pre_delete_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
5045
+
5046
+ foreach ( $pre_delete_helpers as $helper ) {
5047
+ $helper = $this->load_helper( array( 'name' => $helper ) );
5048
+
5049
+ if ( false !== $helper )
5050
+ eval( '?>' . $helper[ 'code' ] );
5051
+ }
5052
+ }
5053
+ }
5054
+ }
5055
+
5056
+ // Delete object from relationship fields
5057
+ $this->delete_object_from_relationships( $params->id, $pod );
5058
+
5059
+ if ( 'table' == $pod[ 'storage' ] )
5060
+ pods_query( "DELETE FROM `@wp_pods_{$params->pod}` WHERE `id` = {$params->id} LIMIT 1" );
5061
+
5062
+ if ( $wp ) {
5063
+ if ( 'taxonomy' == $pod['type'] ) {
5064
+ $taxonomy = $pod['name'];
5065
+
5066
+ if ( ! empty( $pod['object'] ) ) {
5067
+ $taxonomy = $pod['object'];
5068
+ }
5069
+
5070
+ wp_delete_term( $params->id, $taxonomy );
5071
+ } elseif ( ! in_array( $pod['type'], array( 'pod', 'table', '', 'taxonomy' ) ) ) {
5072
+ $this->delete_wp_object( $pod['type'], $params->id );
5073
+ }
5074
+ }
5075
+
5076
+ if ( false === $bypass_helpers ) {
5077
+ // Plugin hook
5078
+ $this->do_hook( 'post_delete_pod_item', $params, $pod );
5079
+ $this->do_hook( "post_delete_pod_item_{$params->pod}", $params, $pod );
5080
+
5081
+ // Call any post-save helpers (if not bypassed)
5082
+ if ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) {
5083
+ if ( !empty( $post_delete_helpers ) ) {
5084
+ pods_deprecated( sprintf( __( 'Post-delete helpers are deprecated, use the action pods_post_delete_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
5085
+
5086
+ foreach ( $post_delete_helpers as $helper ) {
5087
+ $helper = $this->load_helper( array( 'name' => $helper ) );
5088
+
5089
+ if ( false !== $helper )
5090
+ eval( '?>' . $helper[ 'code' ] );
5091
+ }
5092
+ }
5093
+ }
5094
+ }
5095
+
5096
+ pods_cache_clear( $params->id, 'pods_items_' . $params->pod );
5097
+
5098
+ return true;
5099
+ }
5100
+
5101
+ /**
5102
+ * Delete an object from tableless fields
5103
+ *
5104
+ * @param int $id
5105
+ * @param string $type
5106
+ * @param string $name
5107
+ *
5108
+ * @return bool
5109
+ *
5110
+ * @since 2.3
5111
+ */
5112
+ public function delete_object_from_relationships ( $id, $object, $name = null ) {
5113
+ /**
5114
+ * @var $pods_init \PodsInit
5115
+ */
5116
+ global $pods_init;
5117
+
5118
+ $pod = false;
5119
+
5120
+ // Run any bidirectional delete operations
5121
+ if ( is_array( $object ) )
5122
+ $pod = $object;
5123
+ elseif ( is_object( $pods_init ) )
5124
+ $pod = PodsInit::$meta->get_object( $object, $name );
5125
+
5126
+ if ( !empty( $pod ) ) {
5127
+ $object = $pod[ 'type' ];
5128
+ $name = $pod[ 'name' ];
5129
+
5130
+ foreach ( $pod[ 'fields' ] as $field ) {
5131
+ PodsForm::delete( $field[ 'type' ], $id, $field[ 'name' ], array_merge( $field, $field[ 'options' ] ), $pod );
5132
+ }
5133
+ }
5134
+
5135
+ // Lookup related fields (non-bidirectional)
5136
+ $params = array(
5137
+ 'where' => array(
5138
+ array(
5139
+ 'key' => 'type',
5140
+ 'value' => 'pick'
5141
+ ),
5142
+ array(
5143
+ 'key' => 'pick_object',
5144
+ 'value' => $object
5145
+ )
5146
+ )
5147
+ );
5148
+
5149
+ if ( !empty( $name ) && $name != $object ) {
5150
+ $params[ 'where' ][] = array(
5151
+ 'key' => 'pick_val',
5152
+ 'value' => $name
5153
+ );
5154
+ }
5155
+
5156
+ $fields = $this->load_fields( $params, false );
5157
+
5158
+ if ( !empty( $pod ) && 'media' == $pod[ 'type' ] ) {
5159
+ $params[ 'where' ] = array(
5160
+ array(
5161
+ 'key' => 'type',
5162
+ 'value' => 'file'
5163
+ )
5164
+ );
5165
+
5166
+ $fields = array_merge( $fields, $this->load_fields( $params, false ) );
5167
+ }
5168
+
5169
+ if ( is_array( $fields ) && !empty( $fields ) ) {
5170
+ foreach ( $fields as $related_field ) {
5171
+ $related_pod = $this->load_pod( array( 'id' => $related_field[ 'pod_id' ], 'fields' => false ), false );
5172
+
5173
+ if ( empty( $related_pod ) )
5174
+ continue;
5175
+
5176
+ $related_from = $this->lookup_related_items_from( $related_field[ 'id' ], $related_pod[ 'id' ], $id, $related_field, $related_pod );
5177
+
5178
+ $this->delete_relationships( $related_from, $id, $related_pod, $related_field );
5179
+ }
5180
+ }
5181
+
5182
+ if ( !empty( $pod ) && !pods_tableless() ) {
5183
+ pods_query( "
5184
+ DELETE FROM `@wp_podsrel`
5185
+ WHERE
5186
+ (
5187
+ `pod_id` = %d
5188
+ AND `item_id` = %d
5189
+ )
5190
+ OR (
5191
+ `related_pod_id` = %d
5192
+ AND `related_item_id` = %d
5193
+ )
5194
+ ", array(
5195
+ $pod[ 'id' ],
5196
+ $id,
5197
+
5198
+ $pod[ 'id' ],
5199
+ $id
5200
+ ) );
5201
+ }
5202
+
5203
+ return true;
5204
+ }
5205
+
5206
+ /**
5207
+ * Delete relationships
5208
+ *
5209
+ * @param int|array $related_id IDs for items to save
5210
+ * @param int|array $id ID or IDs to remove
5211
+ * @param array $related_pod Pod data
5212
+ * @param array $related_field Field data
5213
+ *
5214
+ * @return void
5215
+ *
5216
+ * @since 2.3
5217
+ */
5218
+ public function delete_relationships ( $related_id, $id, $related_pod, $related_field ) {
5219
+ if ( is_array( $related_id ) ) {
5220
+ foreach ( $related_id as $rid ) {
5221
+ $this->delete_relationships( $rid, $id, $related_pod, $related_field );
5222
+ }
5223
+
5224
+ return;
5225
+ }
5226
+
5227
+ if ( is_array( $id ) ) {
5228
+ foreach ( $id as $rid ) {
5229
+ $this->delete_relationships( $related_id, $rid, $related_pod, $related_field );
5230
+ }
5231
+
5232
+ return;
5233
+ }
5234
+
5235
+ $id = (int) $id;
5236
+
5237
+ if ( empty( $id ) )
5238
+ return;
5239
+
5240
+ $related_ids = $this->lookup_related_items( $related_field[ 'id' ], $related_pod[ 'id' ], $related_id, $related_field, $related_pod );
5241
+
5242
+ if ( empty( $related_ids ) )
5243
+ return;
5244
+ elseif ( !in_array( $id, $related_ids ) )
5245
+ return;
5246
+
5247
+ if ( isset( self::$related_item_cache[ $related_pod[ 'id' ] ][ $related_field[ 'id' ] ] ) ) {
5248
+ // Delete relationship from cache
5249
+ unset( self::$related_item_cache[ $related_pod[ 'id' ] ][ $related_field[ 'id' ] ] );
5250
+ }
5251
+ unset( $related_ids[ array_search( $id, $related_ids ) ] );
5252
+
5253
+ $no_conflict = pods_no_conflict_check( $related_pod[ 'type' ] );
5254
+
5255
+ if ( !$no_conflict )
5256
+ pods_no_conflict_on( $related_pod[ 'type' ] );
5257
+
5258
+ // Post Types, Media, Users, and Comments (meta-based)
5259
+ if ( in_array( $related_pod[ 'type' ], array( 'post_type', 'media', 'taxonomy', 'user', 'comment' ) ) ) {
5260
+ $object_type = $related_pod[ 'type' ];
5261
+
5262
+ if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
5263
+ $object_type = 'post';
5264
+ elseif ( 'taxonomy' == $object_type )
5265
+ $object_type = 'term';
5266
+
5267
+ delete_metadata( $object_type, $related_id, $related_field[ 'name' ] );
5268
+
5269
+ if ( !empty( $related_ids ) ) {
5270
+ update_metadata( $object_type, $related_id, '_pods_' . $related_field[ 'name' ], $related_ids );
5271
+
5272
+ foreach ( $related_ids as $rel_id ) {
5273
+ add_metadata( $object_type, $related_id, $related_field[ 'name' ], $rel_id );
5274
+ }
5275
+ }
5276
+ else
5277
+ delete_metadata( $object_type, $related_id, '_pods_' . $related_field[ 'name' ] );
5278
+ }
5279
+ // Custom Settings Pages (options-based)
5280
+ elseif ( 'settings' == $related_pod[ 'type' ] ) {
5281
+ if ( !empty( $related_ids ) )
5282
+ update_option( $related_pod[ 'name' ] . '_' . $related_field[ 'name' ], $related_ids );
5283
+ else
5284
+ delete_option( $related_pod[ 'name' ] . '_' . $related_field[ 'name' ] );
5285
+ }
5286
+
5287
+ // Relationships table
5288
+ if ( !pods_tableless() ) {
5289
+ pods_query( "
5290
+ DELETE FROM `@wp_podsrel`
5291
+ WHERE
5292
+ (
5293
+ `pod_id` = %d
5294
+ AND `field_id` = %d
5295
+ AND `item_id` = %d
5296
+ AND `related_item_id` = %d
5297
+ )
5298
+ OR (
5299
+ `related_pod_id` = %d
5300
+ AND `related_field_id` = %d
5301
+ AND `related_item_id` = %d
5302
+ AND `item_id` = %d
5303
+ )
5304
+ ", array(
5305
+ $related_pod[ 'id' ],
5306
+ $related_field[ 'id' ],
5307
+ $related_id,
5308
+ $id,
5309
+
5310
+ $related_pod[ 'id' ],
5311
+ $related_field[ 'id' ],
5312
+ $related_id,
5313
+ $id
5314
+ ) );
5315
+ }
5316
+
5317
+ if ( !$no_conflict )
5318
+ pods_no_conflict_off( $related_pod[ 'type' ] );
5319
+ }
5320
+
5321
+ /**
5322
+ * Check if a Pod exists
5323
+ *
5324
+ * $params['id'] int Pod ID
5325
+ * $params['name'] string Pod name
5326
+ *
5327
+ * @param array $params An associative array of parameters
5328
+ *
5329
+ * @return bool True if exists
5330
+ *
5331
+ * @since 1.12
5332
+ */
5333
+ public function pod_exists ( $params, $type = null ) {
5334
+ if ( is_string( $params ) )
5335
+ $params = array( 'name' => $params );
5336
+
5337
+ $params = (object) pods_sanitize( $params );
5338
+
5339
+ if ( !empty( $params->id ) || !empty( $params->name ) ) {
5340
+ if ( !isset( $params->name ) )
5341
+ $pod = get_post( $dummy = (int) $params->id );
5342
+ else {
5343
+ $pod = get_posts( array(
5344
+ 'name' => $params->name,
5345
+ 'post_type' => '_pods_pod',
5346
+ 'posts_per_page' => 1
5347
+ ) );
5348
+ }
5349
+
5350
+ if ( !empty( $pod ) && ( empty( $type ) || $type == get_post_meta( $pod->ID, 'type', true ) ) )
5351
+ return true;
5352
+ }
5353
+
5354
+ return false;
5355
+ }
5356
+
5357
  /**
5358
+ * Get number of pods for a specific pod type
5359
  *
5360
+ * @param string $type Type to get count
 
 
 
 
5361
  *
5362
+ * @return int Total number of pods for a type
5363
  *
5364
+ * @since 2.6.6
5365
  */
5366
+ public function get_pod_type_count( $type ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5367
 
5368
+ $args = array(
5369
+ 'post_type' => '_pods_pod',
5370
+ 'posts_per_page' => - 1,
5371
+ 'nopaging' => true,
5372
+ 'fields' => 'ids',
5373
+ 'meta_query' => array(
5374
+ array(
5375
+ 'key' => 'type',
5376
+ 'value' => $type,
5377
+ ),
5378
+ ),
5379
  );
5380
 
5381
+ $posts = get_posts( $args );
 
 
 
 
 
 
 
 
 
 
 
 
 
5382
 
5383
+ $total = count( $posts );
5384
 
5385
+ return $total;
 
 
5386
 
5387
+ }
5388
 
5389
+ /**
5390
+ * Load a Pod and all of its fields
5391
+ *
5392
+ * $params['id'] int The Pod ID
5393
+ * $params['name'] string The Pod name
5394
+ * $params['fields'] bool Whether to load fields (default is true)
5395
+ * $params['bypass_cache'] boolean Bypass the cache when getting data
5396
+ *
5397
+ * @param array|object $params An associative array of parameters or pod name as a string
5398
+ * @param bool $strict Makes sure the pod exists, throws an error if it doesn't work
5399
+ *
5400
+ * @return array|bool|mixed|void
5401
+ * @since 1.7.9
5402
+ */
5403
+ public function load_pod ( $params, $strict = true ) {
5404
+
5405
+ /**
5406
+ * @var $sitepress SitePress
5407
+ * @var $wpdb wpdb
5408
+ */
5409
+ global $wpdb;
5410
 
5411
+ $current_language = false;
5412
+ $load_fields = true;
5413
+ $bypass_cache = false;
5414
 
5415
+ // Get current language data
5416
+ $lang_data = self::get_current_language();
 
 
5417
 
5418
+ if ( $lang_data ) {
5419
+ if ( ! empty( $lang_data['language'] ) ) {
5420
+ $current_language = $lang_data['language'];
5421
+ }
5422
+ }
5423
 
5424
+ if ( !is_array( $params ) && !is_object( $params ) )
5425
+ $params = array( 'name' => $params, 'table_info' => false, 'fields' => true );
 
5426
 
5427
+ if ( is_object( $params ) && ! is_a( $params, 'WP_Post' ) && isset( $params->fields ) && !$params->fields )
5428
+ $load_fields = false;
5429
+ elseif ( is_array( $params ) && isset( $params[ 'fields' ] ) && !$params[ 'fields' ] )
5430
+ $load_fields = false;
5431
 
5432
+ $table_info = false;
 
 
 
5433
 
5434
+ if ( is_object( $params ) && ! is_a( $params, 'WP_Post' ) && ! empty( $params->table_info ) )
5435
+ $table_info = true;
5436
+ elseif ( is_array( $params ) && ! empty( $params[ 'table_info' ] ) )
5437
+ $table_info = true;
5438
 
5439
+ $transient = 'pods_' . $wpdb->prefix . '_pod';
 
5440
 
5441
+ if ( !empty( $current_language ) )
5442
+ $transient .= '_' . $current_language;
 
 
 
 
 
 
 
 
5443
 
5444
+ if ( !$load_fields )
5445
+ $transient .= '_nofields';
 
 
 
 
 
 
 
 
 
 
5446
 
5447
+ if ( $table_info )
5448
+ $transient .= '_tableinfo';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5449
 
5450
+ $check_pod = $params;
 
5451
 
5452
+ if ( is_object( $params ) && ! is_a( $params, 'WP_Post' ) && ! empty( $params->pod ) ) {
5453
+ $check_pod = $params->pod;
5454
+ } elseif ( is_array( $params ) && ! empty( $params['pod'] ) ) {
5455
+ $check_pod = $params['pod'];
5456
+ }
5457
 
5458
+ if ( is_object( $check_pod ) && ( is_a( $check_pod, 'WP_Post' ) || isset( $check_pod->post_name ) ) ) {
5459
+ $pod = false;
 
5460
 
5461
+ if ( pods_api_cache() )
5462
+ $pod = pods_transient_get( $transient . '_' . $check_pod->post_name );
5463
 
5464
+ if ( false !== $pod && ( ! $table_info || isset( $pod[ 'table' ] ) ) ) {
5465
+ // @todo Is this needed anymore for WPML?
5466
+ if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) )
5467
+ && did_action( 'wpml_loaded' )
5468
+ && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
5469
+ $pod = array_merge( $pod, $this->get_table_info( $pod['type'], $pod['object'], $pod['name'], $pod ) );
5470
+ }
5471
 
5472
+ return $pod;
5473
+ }
5474
 
5475
+ $_pod = get_object_vars( $check_pod );
5476
+ }
5477
+ else {
5478
+ $params = (object) pods_sanitize( $params );
5479
 
5480
+ if ( ( !isset( $params->id ) || empty( $params->id ) ) && ( !isset( $params->name ) || empty( $params->name ) ) ) {
5481
+ if ( $strict ) {
5482
+ return pods_error( 'Either Pod ID or Name are required', $this );
5483
+ }
5484
 
5485
+ return false;
5486
+ }
 
 
 
 
5487
 
5488
+ if ( ! empty( $params->bypass_cache ) ) {
5489
+ $bypass_cache = true;
5490
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
5491
 
5492
+ if ( isset( $params->name ) ) {
5493
+ $pod = false;
 
 
5494
 
5495
+ if ( '_pods_pod' == $params->name ) {
5496
+ $pod = array(
5497
+ 'id' => 0,
5498
+ 'name' => $params->name,
5499
+ 'label' => __( 'Pods', 'pods' ),
5500
+ 'type' => 'post_type',
5501
+ 'storage' => 'meta',
5502
+ 'options' => array(
5503
+ 'label_singular' => __( 'Pod', 'pods' )
5504
+ ),
5505
+ 'fields' => array()
5506
+ );
5507
+ }
5508
+ elseif ( '_pods_field' == $params->name ) {
5509
+ $pod = array(
5510
+ 'id' => 0,
5511
+ 'name' => $params->name,
5512
+ 'label' => __( 'Pod Fields', 'pods' ),
5513
+ 'type' => 'post_type',
5514
+ 'storage' => 'meta',
5515
+ 'options' => array(
5516
+ 'label_singular' => __( 'Pod Field', 'pods' )
5517
+ ),
5518
+ 'fields' => array()
5519
+ );
5520
+ }
5521
+ elseif ( ! $bypass_cache & pods_api_cache() )
5522
+ $pod = pods_transient_get( $transient . '_' . $params->name );
5523
+
5524
+ if ( false !== $pod && ( ! $table_info || isset( $pod[ 'table' ] ) ) ) {
5525
+ if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && did_action( 'wpml_loaded' )
5526
+ && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) )
5527
+ $pod = array_merge( $pod, $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ) );
5528
+
5529
+ return $pod;
5530
+ }
5531
+ }
5532
+
5533
+ if ( !isset( $params->name ) )
5534
+ $pod = get_post( $dummy = (int) $params->id );
5535
+ else {
5536
+ $pod = get_posts( array(
5537
+ 'name' => $params->name,
5538
+ 'post_type' => '_pods_pod',
5539
+ 'posts_per_page' => 1
5540
+ ) );
5541
+ }
5542
 
5543
+ if ( empty( $pod ) ) {
5544
+ if ( $strict )
5545
+ return pods_error( __( 'Pod not found', 'pods' ), $this );
5546
 
5547
+ return false;
5548
+ }
5549
+
5550
+ if ( is_array( $pod ) )
5551
+ $pod = $pod[ 0 ];
5552
+
5553
+ $_pod = get_object_vars( $pod );
5554
+ }
5555
+
5556
+ $pod = false;
5557
+
5558
+ if ( ! $bypass_cache || pods_api_cache() )
5559
+ $pod = pods_transient_get( $transient . '_' . $_pod[ 'post_name' ] );
5560
+
5561
+ if ( false !== $pod && ( ! $table_info || isset( $pod[ 'table' ] ) ) ) {
5562
+ if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) )
5563
+ && did_action( 'wpml_loaded' )
5564
+ && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
5565
+ $pod = array_merge( $pod, $this->get_table_info( $pod['type'], $pod['object'], $pod['name'], $pod ) );
5566
+ }
5567
+
5568
+ return $pod;
5569
+ }
5570
+
5571
+ $pod = array(
5572
+ 'id' => $_pod[ 'ID' ],
5573
+ 'name' => $_pod[ 'post_name' ],
5574
+ 'label' => $_pod[ 'post_title' ],
5575
+ 'description' => $_pod[ 'post_content' ]
5576
+ );
5577
+
5578
+ if ( strlen( $pod[ 'label' ] ) < 1 )
5579
+ $pod[ 'label' ] = $pod[ 'name' ];
5580
+
5581
+ // @todo update with a method to put all options in
5582
+ $defaults = array(
5583
+ 'show_in_menu' => 1,
5584
+ 'type' => 'post_type',
5585
+ 'storage' => 'meta',
5586
+ 'object' => '',
5587
+ 'alias' => ''
5588
+ );
5589
+
5590
+ if ( $bypass_cache ) {
5591
+ wp_cache_delete( $pod['id'], 'post_meta' );
5592
+
5593
+ update_postmeta_cache( array( $pod['id'] ) );
5594
+ }
5595
+
5596
+ $pod[ 'options' ] = get_post_meta( $pod[ 'id' ] );
5597
+
5598
+ foreach ( $pod[ 'options' ] as $option => $value ) {
5599
+ if ( is_array( $value ) ) {
5600
+ foreach ( $value as $k => $v ) {
5601
+ if ( !is_array( $v ) )
5602
+ $value[ $k ] = maybe_unserialize( $v );
5603
+ }
5604
+
5605
+ if ( 1 == count( $value ) )
5606
+ $value = current( $value );
5607
+ }
5608
+ else
5609
+ $value = maybe_unserialize( $value );
5610
+
5611
+ $pod[ 'options' ][ $option ] = $value;
5612
+ }
5613
+
5614
+ $pod[ 'options' ] = array_merge( $defaults, $pod[ 'options' ] );
5615
+
5616
+ $pod[ 'type' ] = $pod[ 'options' ][ 'type' ];
5617
+ $pod[ 'storage' ] = $pod[ 'options' ][ 'storage' ];
5618
+ $pod[ 'object' ] = $pod[ 'options' ][ 'object' ];
5619
+ $pod[ 'alias' ] = $pod[ 'options' ][ 'alias' ];
5620
+
5621
+ unset( $pod[ 'options' ][ 'type' ] );
5622
+ unset( $pod[ 'options' ][ 'storage' ] );
5623
+ unset( $pod[ 'options' ][ 'object' ] );
5624
+ unset( $pod[ 'options' ][ 'alias' ] );
5625
+
5626
+ if ( $table_info )
5627
+ $pod = array_merge( $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ), $pod );
5628
+
5629
+ // Override old 'none' storage type
5630
+ if ( 'taxonomy' == $pod['type'] && 'none' == $pod['storage'] && function_exists( 'get_term_meta' ) ) {
5631
+ $pod[ 'storage' ] = 'meta';
5632
+ }
5633
+
5634
+ if ( isset( $pod[ 'pod' ] ) )
5635
+ unset( $pod[ 'pod' ] );
5636
+
5637
+ $pod[ 'fields' ] = array();
5638
+
5639
+ $pod[ 'object_fields' ] = array();
5640
+
5641
+ if ( 'pod' != $pod[ 'type' ] )
5642
+ $pod[ 'object_fields' ] = $this->get_wp_object_fields( $pod[ 'type' ], $pod );
5643
+
5644
+ $fields = get_posts( array(
5645
+ 'post_type' => '_pods_field',
5646
+ 'posts_per_page' => -1,
5647
+ 'nopaging' => true,
5648
+ 'post_parent' => $pod[ 'id' ],
5649
+ 'orderby' => 'menu_order',
5650
+ 'order' => 'ASC'
5651
+ ) );
5652
+
5653
+ if ( !empty( $fields ) ) {
5654
+ foreach ( $fields as $field ) {
5655
+ $field->pod = $pod[ 'name' ];
5656
+ $field->table_info = $table_info;
5657
+ $field->bypass_cache = $bypass_cache;
5658
+
5659
+ if ( $load_fields ) {
5660
+ $field = $this->load_field( $field );
5661
+
5662
+ $field = PodsForm::field_setup( $field, null, $field[ 'type' ] );
5663
+ }
5664
+ else {
5665
+ if ( $bypass_cache ) {
5666
+ wp_cache_delete( $field->ID, 'post_meta' );
5667
+
5668
+ update_postmeta_cache( array( $field->ID ) );
5669
+ }
5670
+
5671
+ $field = array(
5672
+ 'id' => $field->ID,
5673
+ 'name' => $field->post_name,
5674
+ 'label' => $field->post_title,
5675
+ 'type' => get_post_meta( $field->ID, 'type', true )
5676
+ );
5677
+ }
5678
+
5679
+ $pod[ 'fields' ][ $field[ 'name' ] ] = $field;
5680
+ }
5681
+ }
5682
+
5683
+ if ( did_action( 'init' ) && pods_api_cache() )
5684
+ pods_transient_set( $transient . '_' . $pod[ 'name' ], $pod );
5685
+
5686
+ return $pod;
5687
+ }
5688
+
5689
+ /**
5690
+ * Load a list of Pods based on filters specified.
5691
+ *
5692
+ * $params['type'] string/array Pod Type(s) to filter by
5693
+ * $params['object'] string/array Pod Object(s) to filter by
5694
+ * $params['options'] array Pod Option(s) key=>value array to filter by
5695
+ * $params['orderby'] string ORDER BY clause of query
5696
+ * $params['limit'] string Number of Pods to return
5697
+ * $params['where'] string WHERE clause of query
5698
+ * $params['ids'] string|array IDs of Objects
5699
+ * $params['count'] boolean Return only a count of Pods
5700
+ * $params['names'] boolean Return only an array of name => label
5701
+ * $params['ids'] boolean Return only an array of ID => label
5702
+ * $params['fields'] boolean Return pod fields with Pods (default is true)
5703
+ * $params['key_names'] boolean Return pods keyed by name
5704
+ * $params['bypass_cache'] boolean Bypass the cache when getting data
5705
+ *
5706
+ * @param array $params An associative array of parameters
5707
+ *
5708
+ * @return array|mixed
5709
+ *
5710
+ * @uses PodsAPI::load_pod
5711
+ *
5712
+ * @since 2.0
5713
+ */
5714
+ public function load_pods ( $params = null ) {
5715
+
5716
+ $current_language = false;
5717
+
5718
+ // Get current language data
5719
+ $lang_data = self::get_current_language();
5720
+
5721
+ if ( $lang_data ) {
5722
+ if ( ! empty( $lang_data['language'] ) ) {
5723
+ $current_language = $lang_data['language'];
5724
+ }
5725
+ }
5726
+
5727
+ $params = (object) pods_sanitize( $params );
5728
+
5729
+ $order = 'ASC';
5730
+ $orderby = 'menu_order title';
5731
+ $limit = -1;
5732
+ $ids = false;
5733
+
5734
+ $meta_query = array();
5735
+ $cache_key = '';
5736
+
5737
+ $bypass_cache = false;
5738
+
5739
+ if ( ! empty( $params->bypass_cache ) ) {
5740
+ $bypass_cache = true;
5741
+ }
5742
+
5743
+ if ( isset( $params->type ) && !empty( $params->type ) ) {
5744
+ if ( !is_array( $params->type ) )
5745
+ $params->type = array( trim( $params->type ) );
5746
+
5747
+ sort( $params->type );
5748
+
5749
+ $meta_query[] = array(
5750
+ 'key' => 'type',
5751
+ 'value' => $params->type,
5752
+ 'compare' => 'IN'
5753
+ );
5754
 
5755
+ if ( 0 < count( $params->type ) )
5756
+ $cache_key .= '_type_' . trim( implode( '_', $params->type ) );
5757
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5758
 
5759
+ if ( isset( $params->object ) && !empty( $params->object ) ) {
5760
+ if ( !is_array( $params->object ) )
5761
+ $params->object = array( $params->object );
 
 
5762
 
5763
+ $params->object = pods_trim( $params->object );
 
5764
 
5765
+ sort( $params->object );
 
 
 
 
5766
 
5767
+ $meta_query[] = array(
5768
+ 'key' => 'object',
5769
+ 'value' => $params->object,
5770
+ 'compare' => 'IN'
5771
+ );
5772
 
5773
+ if ( 1 == count( $params->object ) )
5774
+ $cache_key .= '_object_' . trim( implode( '', $params->object ) );
5775
+ }
5776
 
5777
+ if ( isset( $params->options ) && !empty( $params->options ) && is_array( $params->options ) ) {
5778
+ foreach ( $params->options as $option => $value ) {
5779
+ if ( !is_array( $value ) )
5780
+ $value = array( $value );
5781
 
5782
+ $value = pods_trim( $value );
5783
 
5784
+ sort( $value );
 
 
5785
 
5786
+ $meta_query[] = array(
5787
+ 'key' => $option,
5788
+ 'value' => pods_sanitize( $value ),
5789
+ 'compare' => 'IN'
5790
+ );
5791
+ }
5792
 
5793
+ $cache_key = '';
5794
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5795
 
5796
+ if ( isset( $params->where ) && is_array( $params->where ) )
5797
+ $meta_query = array_merge( $meta_query, (array) $params->where );
5798
 
5799
+ if ( isset( $params->order ) && !empty( $params->order ) && in_array( strtoupper( $params->order ), array( 'ASC', 'DESC' ) ) )
5800
+ $order = strtoupper( $params->order );
 
 
 
5801
 
5802
+ if ( isset( $params->orderby ) && !empty( $params->orderby ) )
5803
+ $orderby = strtoupper( $params->orderby );
 
5804
 
5805
+ if ( isset( $params->limit ) && !empty( $params->limit ) )
5806
+ $limit = pods_absint( $params->limit );
 
5807
 
5808
+ if ( isset( $params->ids ) && !empty( $params->ids ) ) {
5809
+ $ids = $params->ids;
 
5810
 
5811
+ if ( !is_array( $ids ) )
5812
+ $ids = explode( ',', $ids );
5813
+ }
5814
 
5815
+ if ( empty( $ids ) )
5816
+ $ids = false;
 
5817
 
5818
+ $pre_key = '';
 
 
 
 
5819
 
5820
+ if ( !empty( $current_language ) )
5821
+ $pre_key .= '_' . $current_language;
 
5822
 
5823
+ if ( isset( $params->count ) && $params->count )
5824
+ $pre_key .= '_count';
5825
 
5826
+ if ( isset( $params->ids ) && $params->ids && !empty( $ids ) )
5827
+ $pre_key .= '_ids_' . implode( '_', $ids );
5828
 
5829
+ if ( isset( $params->names ) && $params->names )
5830
+ $pre_key .= '_names';
5831
+ elseif ( isset( $params->names_ids ) && $params->names_ids )
5832
+ $pre_key .= '_names_ids';
5833
 
5834
+ if ( isset( $params->key_names ) && $params->key_names )
5835
+ $pre_key .= '_namekeys';
 
5836
 
5837
+ if ( isset( $params->fields ) && !$params->fields )
5838
+ $pre_key .= '_nofields';
 
 
5839
 
5840
+ if ( isset( $params->table_info ) && $params->table_info )
5841
+ $pre_key .= '_tableinfo';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5842
 
 
 
 
 
5843
 
5844
+ $pre_key .= '_get';
5845
 
5846
+ if ( empty( $cache_key ) )
5847
+ $cache_key = 'pods' . $pre_key . '_all';
5848
+ else
5849
+ $cache_key = 'pods' . $pre_key . $cache_key;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5850
 
5851
+ if ( ! $bypass_cache && pods_api_cache() && !empty( $cache_key ) && ( 'pods' . ( !empty( $current_language ) ? '_' . $current_language : '' ) . '_get_all' != $cache_key || empty( $meta_query ) ) && $limit < 1 && ( empty( $orderby ) || 'menu_order title' == $orderby ) && empty( $ids ) ) {
5852
+ $the_pods = pods_transient_get( $cache_key );
 
5853
 
5854
+ if ( false === $the_pods )
5855
+ $the_pods = pods_cache_get( $cache_key, 'pods' );
 
5856
 
5857
+ if ( !is_array( $the_pods ) && 'none' == $the_pods )
5858
+ return array();
5859
+ elseif ( false !== $the_pods )
5860
+ return $the_pods;
5861
+ }
5862
 
5863
+ $the_pods = array();
 
 
5864
 
5865
+ $args = array(
5866
+ 'post_type' => '_pods_pod',
5867
+ 'nopaging' => true,
5868
+ 'posts_per_page' => $limit,
5869
+ 'order' => $order,
5870
+ 'orderby' => $orderby,
5871
+ 'meta_query' => $meta_query,
5872
+ );
5873
 
5874
+ // Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
5875
+ if ( false != $ids ) {
5876
+ $args[ 'post__in' ] = $ids;
5877
  }
5878
 
5879
+ $_pods = get_posts( $args );
 
5880
 
5881
+ $export_ignore = array(
5882
+ 'object_type',
5883
+ 'object_name',
5884
+ 'table',
5885
+ 'meta_table',
5886
+ 'pod_table',
5887
+ 'field_id',
5888
+ 'field_index',
5889
+ 'field_slug',
5890
+ 'field_type',
5891
+ 'field_parent',
5892
+ 'field_parent_select',
5893
+ 'meta_field_id',
5894
+ 'meta_field_index',
5895
+ 'meta_field_value',
5896
+ 'pod_field_id',
5897
+ 'pod_field_index',
5898
+ 'object_fields',
5899
+ 'join',
5900
+ 'where',
5901
+ 'where_default',
5902
+ 'orderby',
5903
+ 'pod',
5904
+ 'recurse',
5905
+ 'table_info',
5906
+ 'attributes',
5907
+ 'group',
5908
+ 'grouped',
5909
+ 'developer_mode',
5910
+ 'dependency',
5911
+ 'depends-on',
5912
+ 'excludes-on'
5913
+ );
5914
+
5915
+ $total_fields = 0;
5916
+
5917
+ if ( isset( $params->count ) && $params->count )
5918
+ $the_pods = count( $_pods );
5919
+ else {
5920
+ foreach ( $_pods as $pod ) {
5921
+ if ( isset( $params->names ) && $params->names )
5922
+ $the_pods[ $pod->post_name ] = $pod->post_title;
5923
+ elseif ( isset( $params->names_ids ) && $params->names_ids )
5924
+ $the_pods[ $pod->ID ] = $pod->post_name;
5925
+ else {
5926
+ if ( isset( $params->fields ) && !$params->fields )
5927
+ $pod->fields = false;
5928
+
5929
+ $pod = $this->load_pod( array( 'pod' => $pod, 'table_info' => ! empty( $params->table_info ), 'bypass_cache' => $bypass_cache ) );
5930
+
5931
+ // Remove extra data not needed
5932
+ if ( pods_var( 'export', $params, false ) && ( !isset( $params->fields ) || $params->fields ) ) {
5933
+ foreach ( $export_ignore as $ignore ) {
5934
+ if ( isset( $pod[ $ignore ] ) )
5935
+ unset( $pod[ $ignore ] );
5936
+ }
5937
+
5938
+ foreach ( $pod[ 'fields' ] as $field => $field_data ) {
5939
+ if ( isset( $pod[ 'fields' ][ $field ][ 'table_info' ] ) )
5940
+ unset( $pod[ 'fields' ][ $field ][ 'table_info' ] );
5941
+ }
5942
+ }
5943
+
5944
+ $total_fields += count( $pod[ 'fields' ] );
5945
+
5946
+ if ( isset( $params->key_names ) && $params->key_names )
5947
+ $the_pods[ $pod[ 'name' ] ] = $pod;
5948
+ else
5949
+ $the_pods[ $pod[ 'id' ] ] = $pod;
5950
+ }
5951
+ }
5952
+ }
5953
+
5954
+ if ( ( !function_exists( 'pll_current_language' ) || ( isset( $params->refresh ) && $params->refresh ) ) && !empty( $cache_key ) && ( 'pods' != $cache_key || empty( $meta_query ) ) && $limit < 1 && ( empty( $orderby ) || 'menu_order title' == $orderby ) && empty( $ids ) ) {
5955
+ // Too many Pods can cause issues with the DB when caching is not enabled
5956
+ if ( 15 < count( $the_pods ) || 75 < count( $total_fields ) ) {
5957
+ pods_transient_clear( $cache_key );
5958
+
5959
+ if ( pods_api_cache() ) {
5960
+ if ( empty( $the_pods ) && ( !isset( $params->count ) || !$params->count ) )
5961
+ pods_cache_set( $cache_key, 'none', 'pods' );
5962
+ else
5963
+ pods_cache_set( $cache_key, $the_pods, 'pods' );
5964
+ }
5965
+ }
5966
+ else {
5967
+ pods_cache_clear( $cache_key, 'pods' );
5968
+
5969
+ if ( pods_api_cache() ) {
5970
+ if ( empty( $the_pods ) && ( !isset( $params->count ) || !$params->count ) )
5971
+ pods_transient_set( $cache_key, 'none' );
5972
+ else
5973
+ pods_transient_set( $cache_key, $the_pods );
5974
+ }
5975
+ }
5976
+ }
5977
+
5978
+ return $the_pods;
5979
+ }
5980
+
5981
+ /**
5982
+ * Check if a Pod's field exists
5983
+ *
5984
+ * $params['pod_id'] int The Pod ID
5985
+ * $params['id'] int The field ID
5986
+ * $params['name'] string The field name
5987
+ *
5988
+ * @param array $params An associative array of parameters
5989
+ *
5990
+ * @return bool
5991
+ *
5992
+ * @since 1.12
5993
+ */
5994
+ public function field_exists ( $params ) {
5995
+ $params = (object) pods_sanitize( $params );
5996
+
5997
+ if ( ( !empty( $params->id ) || !empty( $params->name ) ) && isset( $params->pod_id ) && !empty( $params->pod_id ) ) {
5998
+ if ( !isset( $params->name ) )
5999
+ $field = get_post( $dummy = (int) $params->id );
6000
+ else {
6001
+ $field = get_posts( array(
6002
+ 'name' => $params->name,
6003
+ 'post_type' => '_pods_field',
6004
+ 'posts_per_page' => 1,
6005
+ 'post_parent' => $params->pod_id
6006
+ ) );
6007
+ }
6008
+
6009
+ if ( !empty( $field ) )
6010
+ return true;
6011
+ }
6012
+
6013
+ return false;
6014
+ }
6015
+
6016
+ /**
6017
+ * Load a field
6018
+ *
6019
+ * $params['pod_id'] int The Pod ID
6020
+ * $params['pod'] string The Pod name
6021
+ * $params['id'] int The field ID
6022
+ * $params['name'] string The field name
6023
+ * $params['table_info'] boolean Whether to lookup a pick field's table info
6024
+ * $params['bypass_cache'] boolean Bypass the cache when getting data
6025
+ *
6026
+ * @param array $params An associative array of parameters
6027
+ * @param boolean $strict Whether to require a field exist or not when loading the info
6028
+ *
6029
+ * @return array|bool Array with field data, false if field not found
6030
+ * @since 1.7.9
6031
+ */
6032
+ public function load_field ( $params, $strict = false ) {
6033
+ $params = (object) $params;
6034
+
6035
+ if ( !isset( $params->table_info ) )
6036
+ $params->table_info = false;
6037
+
6038
+ $bypass_cache = false;
6039
+
6040
+ if ( ! empty( $params->bypass_cache ) )
6041
+ $bypass_cache = true;
6042
+
6043
+ $pod = array();
6044
+ $field = array();
6045
+
6046
+ if ( isset( $params->post_title ) )
6047
+ $_field = $params;
6048
+ elseif ( isset( $params->id ) && !empty( $params->id ) )
6049
+ $_field = get_post( $dumb = (int) $params->id );
6050
+ else {
6051
+ if ( !isset( $params->pod ) )
6052
+ $params->pod = '';
6053
+
6054
+ if ( !isset( $params->pod_id ) )
6055
+ $params->pod_id = 0;
6056
+
6057
+ if ( isset( $params->pod_data ) )
6058
+ $pod = $params->pod_data;
6059
+ else {
6060
+ $pod = $this->load_pod( array( 'name' => $params->pod, 'id' => $params->pod_id, 'table_info' => false, 'bypass_cache' => $bypass_cache ), false );
6061
+
6062
+ if ( false === $pod ) {
6063
+ if ( $strict )
6064
+ return pods_error( __( 'Pod not found', 'pods' ), $this );
6065
+
6066
+ return false;
6067
+ }
6068
+ }
6069
+
6070
+ $params->pod_id = $pod[ 'id' ];
6071
+ $params->pod = $pod[ 'name' ];
6072
+
6073
+ if ( empty( $params->name ) && empty( $params->pod ) && empty( $params->pod_id ) )
6074
+ return pods_error( __( 'Either Field Name or Field ID / Pod ID are required', 'pods' ), $this );
6075
+
6076
+ $params->name = pods_clean_name( $params->name, true, ( 'meta' == $pod[ 'storage' ] ? false : true ) );
6077
+
6078
+ if ( isset( $pod[ 'fields' ][ $params->name ] ) && isset( $pod[ 'fields' ][ $params->name ][ 'id' ] ) )
6079
+ return $pod[ 'fields' ][ $params->name ];
6080
+
6081
+ $field = false;
6082
+
6083
+ if ( ! $bypass_cache && pods_api_cache() )
6084
+ $field = pods_transient_get( 'pods_field_' . $params->pod . '_' . $params->name );
6085
+
6086
+ if ( empty( $field ) ) {
6087
+ $field = get_posts( array(
6088
+ 'name' => $params->name,
6089
+ 'post_type' => '_pods_field',
6090
+ 'posts_per_page' => 1,
6091
+ 'post_parent' => $params->pod_id
6092
+ ) );
6093
+
6094
+ if ( empty( $field ) ) {
6095
+ if ( $strict )
6096
+ return pods_error( __( 'Field not found', 'pods' ), $this );
6097
+
6098
+ return false;
6099
+ }
6100
+
6101
+ $_field = $field[ 0 ];
6102
+
6103
+ $field = array();
6104
+ }
6105
+ }
6106
+
6107
+ if ( empty( $_field ) ) {
6108
+ if ( $strict )
6109
+ return pods_error( __( 'Field not found', 'pods' ), $this );
6110
+
6111
+ return false;
6112
+ }
6113
+
6114
+ $_field = get_object_vars( $_field );
6115
+
6116
+ if ( !isset( $pod[ 'name' ] ) && !isset( $_field[ 'pod' ] ) ) {
6117
+ if ( 0 < $_field[ 'post_parent' ] )
6118
+ $pod = $this->load_pod( array( 'id' => $_field[ 'post_parent' ], 'table_info' => false ), false );
6119
+
6120
+ if ( empty( $pod ) ) {
6121
+ if ( $strict )
6122
+ return pods_error( __( 'Pod for field not found', 'pods' ), $this );
6123
+
6124
+ return false;
6125
+ }
6126
+ }
6127
 
6128
+ if ( empty( $field ) ) {
6129
+ if ( ! $bypass_cache && pods_api_cache() && ( isset( $pod[ 'name' ] ) || isset( $_field[ 'pod' ] ) ) )
6130
+ $field = pods_transient_get( 'pods_field_' . pods_var( 'name', $pod, pods_var( 'pod', $_field ), null, true ) . '_' . $_field[ 'post_name' ] );
 
6131
 
6132
+ if ( empty( $field ) ) {
6133
+ $defaults = array(
6134
+ 'type' => 'text'
6135
+ );
6136
 
6137
+ $field = array(
6138
+ 'id' => $_field[ 'ID' ],
6139
+ 'name' => $_field[ 'post_name' ],
6140
+ 'label' => $_field[ 'post_title' ],
6141
+ 'description' => $_field[ 'post_content' ],
6142
+ 'weight' => $_field[ 'menu_order' ],
6143
+ 'pod_id' => $_field[ 'post_parent' ],
6144
+ 'pick_object' => '',
6145
+ 'pick_val' => '',
6146
+ 'sister_id' => '',
6147
+ 'table_info' => array()
6148
+ );
6149
+
6150
+ if ( isset( $pod[ 'name' ] ) )
6151
+ $field[ 'pod' ] = $pod[ 'name' ];
6152
+ elseif ( isset( $_field[ 'pod' ] ) )
6153
+ $field[ 'pod' ] = $_field[ 'pod' ];
6154
+
6155
+ if ( $bypass_cache ) {
6156
+ wp_cache_delete( $field['id'], 'post_meta' );
6157
+
6158
+ update_postmeta_cache( array( $field['id'] ) );
6159
+ }
6160
+
6161
+ $field[ 'options' ] = get_post_meta( $field[ 'id' ] );
6162
+
6163
+ $options_ignore = array(
6164
+ 'method',
6165
+ 'table_info',
6166
+ 'attributes',
6167
+ 'group',
6168
+ 'grouped',
6169
+ 'developer_mode',
6170
+ 'dependency',
6171
+ 'depends-on',
6172
+ 'excludes-on'
6173
+ );
6174
+
6175
+ foreach ( $options_ignore as $ignore ) {
6176
+ if ( isset( $field[ 'options' ][ $ignore ] ) )
6177
+ unset( $field[ 'options' ][ $ignore ] );
6178
+ }
6179
+
6180
+ foreach ( $field[ 'options' ] as $option => $value ) {
6181
+ if ( is_array( $value ) ) {
6182
+ foreach ( $value as $k => $v ) {
6183
+ if ( !is_array( $v ) )
6184
+ $value[ $k ] = maybe_unserialize( $v );
6185
+ }
6186
+
6187
+ if ( 1 == count( $value ) )
6188
+ $value = current( $value );
6189
+ }
6190
+ else
6191
+ $value = maybe_unserialize( $value );
6192
+
6193
+ $field[ 'options' ][ $option ] = $value;
6194
+ }
6195
+
6196
+ $field[ 'options' ] = array_merge( $defaults, $field[ 'options' ] );
6197
+
6198
+ $field[ 'type' ] = $field[ 'options' ][ 'type' ];
6199
+
6200
+ unset( $field[ 'options' ][ 'type' ] );
6201
+
6202
+ if ( isset( $field[ 'options' ][ 'pick_object' ] ) ) {
6203
+ $field[ 'pick_object' ] = $field[ 'options' ][ 'pick_object' ];
6204
+
6205
+ unset( $field[ 'options' ][ 'pick_object' ] );
6206
+ }
6207
+
6208
+ if ( isset( $field[ 'options' ][ 'pick_val' ] ) ) {
6209
+ $field[ 'pick_val' ] = $field[ 'options' ][ 'pick_val' ];
6210
+
6211
+ unset( $field[ 'options' ][ 'pick_val' ] );
6212
+ }
6213
+
6214
+ if ( isset( $field[ 'options' ][ 'sister_id' ] ) ) {
6215
+ $field[ 'sister_id' ] = $field[ 'options' ][ 'sister_id' ];
6216
+
6217
+ unset( $field[ 'options' ][ 'sister_id' ] );
6218
+ }
6219
+
6220
+ if ( isset( $field[ 'options' ][ 'sister_field_id' ] ) )
6221
+ unset( $field[ 'options' ][ 'sister_field_id' ] );
6222
+
6223
+ if ( pods_api_cache() && ( isset( $pod[ 'name' ] ) || isset( $_field[ 'pod' ] ) ) )
6224
+ pods_transient_set( 'pods_field_' . pods_var( 'name', $pod, pods_var( 'pod', $_field ), null, true ) . '_' . $field[ 'name' ], $field );
6225
+ }
6226
+ }
6227
+
6228
+ $field[ 'table_info' ] = array();
6229
+
6230
+ if ( 'pick' == $field[ 'type' ] && $params->table_info )
6231
+ $field[ 'table_info' ] = $this->get_table_info( $field[ 'pick_object' ], $field[ 'pick_val' ], null, null, $field );
6232
+
6233
+ return $field;
6234
+ }
6235
+
6236
+ /**
6237
+ * Load fields by Pod, ID, Name, and/or Type
6238
+ *
6239
+ * $params['pod_id'] int The Pod ID
6240
+ * $params['pod'] string The Pod name
6241
+ * $params['id'] array The field IDs
6242
+ * $params['name'] array The field names
6243
+ * $params['type'] array The field types
6244
+ * $params['options'] array Field Option(s) key=>value array to filter by
6245
+ * $params['where'] string WHERE clause of query
6246
+ *
6247
+ * @param array $params An associative array of parameters
6248
+ * @param bool $strict Whether to require a field exist or not when loading the info
6249
+ *
6250
+ * @return array Array of field data.
6251
+ *
6252
+ * @since 1.7.9
6253
+ */
6254
+ public function load_fields ( $params, $strict = false ) {
6255
+ // @todo Get away from using md5/serialize, I'm sure we can cache specific parts
6256
+ $cache_key = md5( serialize( $params ) );
6257
+ if ( isset( $this->fields_cache[ $cache_key ] ) ) {
6258
+ return $this->fields_cache[ $cache_key ];
6259
+ }
6260
 
6261
+ $params = (object) pods_sanitize( $params );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6262
 
6263
+ if ( !isset( $params->pod ) || empty( $params->pod ) )
6264
+ $params->pod = '';
 
6265
 
6266
+ if ( !isset( $params->pod_id ) || empty( $params->pod_id ) )
6267
+ $params->pod_id = 0;
6268
 
6269
+ if ( !isset( $params->name ) || empty( $params->name ) )
6270
+ $params->name = array();
6271
+ else
6272
+ $params->name = (array) $params->name;
 
 
 
 
 
 
 
6273
 
6274
+ if ( !isset( $params->id ) || empty( $params->id ) )
6275
+ $params->id = array();
6276
+ else {
6277
+ $params->id = (array) $params->id;
6278
 
6279
+ foreach ( $params->id as &$id ) {
6280
+ $id = pods_absint( $id );
6281
+ }
6282
+ }
 
 
 
 
 
 
 
 
6283
 
6284
+ if ( !isset( $params->type ) || empty( $params->type ) )
6285
+ $params->type = array();
6286
+ else
6287
+ $params->type = (array) $params->type;
6288
 
6289
+ $fields = array();
 
6290
 
6291
+ if ( !empty( $params->pod ) || !empty( $params->pod_id ) ) {
6292
+ $pod = $this->load_pod( array( 'name' => $params->pod, 'id' => $params->pod_id, 'table_info' => true ), false );
 
 
 
 
 
 
 
 
 
 
6293
 
6294
+ if ( false === $pod ) {
6295
+ if ( $strict )
6296
+ return pods_error( __( 'Pod not found', 'pods' ), $this );
6297
 
6298
+ return $fields;
6299
+ }
 
 
 
 
 
 
 
 
 
 
 
6300
 
6301
+ $pod[ 'fields' ] = array_merge( pods_var_raw( 'object_fields', $pod, array() ), $pod[ 'fields' ] );
 
 
 
6302
 
6303
+ foreach ( $pod[ 'fields' ] as $field ) {
6304
+ if ( empty( $params->name ) && empty( $params->id ) && empty( $params->type ) )
6305
+ $fields[ $field[ 'name' ] ] = $field;
6306
+ elseif ( in_array( $fields[ 'name' ], $params->name ) || in_array( $fields[ 'id' ], $params->id ) || in_array( $fields[ 'type' ], $params->type ) )
6307
+ $fields[ $field[ 'name' ] ] = $field;
6308
+ }
6309
+ }
6310
+ elseif ( ( isset( $params->options ) && !empty( $params->options ) && is_array( $params->options ) ) || ( isset( $params->where ) && !empty( $params->where ) && is_array( $params->where ) ) ) {
6311
+ $order = 'ASC';
6312
+ $orderby = 'menu_order title';
6313
+ $limit = -1;
6314
+ $ids = false;
6315
 
6316
+ $meta_query = array();
 
6317
 
6318
+ if ( isset( $params->options ) && !empty( $params->options ) && is_array( $params->options ) ) {
6319
+ foreach ( $params->options as $option => $value ) {
6320
+ if ( !is_array( $value ) )
6321
+ $value = array( $value );
6322
 
6323
+ $value = pods_trim( $value );
 
6324
 
6325
+ sort( $value );
 
6326
 
6327
+ $meta_query[] = array(
6328
+ 'key' => $option,
6329
+ 'value' => pods_sanitize( $value ),
6330
+ 'compare' => 'IN'
6331
+ );
6332
+ }
6333
+ }
6334
 
6335
+ if ( isset( $params->where ) && !empty( $params->where ) && is_array( $params->where ) )
6336
+ $meta_query = array_merge( $meta_query, (array) $params->where );
6337
 
6338
+ $args = array(
6339
+ 'post_type' => '_pods_field',
6340
+ 'nopaging' => true,
6341
+ 'posts_per_page' => $limit,
6342
+ 'order' => $order,
6343
+ 'orderby' => $orderby,
6344
+ 'meta_query' => $meta_query,
6345
+ );
6346
 
6347
+ // Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
6348
+ if ( false != $ids ) {
6349
+ $args[ 'post__in' ] = $ids;
6350
+ }
6351
 
6352
+ $fields = array();
6353
 
6354
+ $_fields = get_posts( $args );
 
6355
 
6356
+ foreach ( $_fields as $field ) {
6357
+ $field = $this->load_field( $field, false );
 
 
 
6358
 
6359
+ if ( !empty( $field ) )
6360
+ $fields[ $field[ 'id' ] ] = $field;
6361
+ }
6362
+ }
6363
+ else {
6364
+ if ( empty( $params->name ) && empty( $params->id ) && empty( $params->type ) )
6365
+ return pods_error( __( 'Either Field Name / Field ID / Field Type, or Pod Name / Pod ID are required', 'pods' ), $this );
6366
 
6367
+ $lookup = array();
 
 
 
 
6368
 
6369
+ if ( !empty( $params->name ) ) {
6370
+ $fields = implode( "', '", $params->name );
 
 
6371
 
6372
+ $lookup[] = "`post_name` IN ( '{$fields}' )";
6373
+ }
 
6374
 
6375
+ if ( !empty( $params->id ) ) {
6376
+ $fields = implode( ", ", $params->id );
 
6377
 
6378
+ $lookup[] = "`ID` IN ( {$fields} )";
6379
+ }
6380
 
6381
+ $lookup = implode( ' AND ', $lookup );
 
 
 
 
 
 
 
 
 
 
 
 
6382
 
6383
+ $result = pods_query( "SELECT `ID`, `post_name`, `post_parent` FROM `@wp_posts` WHERE `post_type` = '_pods_field' AND ( {$lookup} )" );
 
 
 
 
 
6384
 
6385
+ $fields = array();
 
6386
 
6387
+ if ( !empty( $result ) ) {
6388
+ foreach ( $result as $field ) {
6389
+ $field = $this->load_field( array(
6390
+ 'id' => $field->ID,
6391
+ 'name' => $field->post_name,
6392
+ 'pod_id' => $field->post_parent
6393
+ ), false );
6394
+
6395
+ if ( !empty( $field ) && ( empty( $params->type ) || in_array( $field[ 'type' ], $params->type ) ) )
6396
+ $fields[ $field[ 'id' ] ] = $field;
6397
+ }
6398
+ }
6399
+ }
6400
+ if ( isset( $cache_key ) ) {
6401
+ $this->fields_cache[ $cache_key ] = $fields;
6402
+ }
6403
+ return $fields;
6404
+ }
6405
+
6406
+ /**
6407
+ * Load a Pods Object
6408
+ *
6409
+ * $params['id'] int The Object ID
6410
+ * $params['name'] string The Object name
6411
+ * $params['type'] string The Object type
6412
+ *
6413
+ * @param array|object $params An associative array of parameters
6414
+ * @param bool $strict
6415
+ *
6416
+ * @return array|bool
6417
+ * @since 2.0
6418
+ */
6419
+ public function load_object ( $params, $strict = false ) {
6420
+ if ( is_object( $params ) && isset( $params->post_title ) )
6421
+ $_object = get_object_vars( $params );
6422
+ else {
6423
+ $params = (object) pods_sanitize( $params );
6424
+
6425
+ if ( !isset( $params->type ) || empty( $params->type ) )
6426
+ return pods_error( __( 'Object type is required', 'pods' ), $this );
6427
+
6428
+ if ( ( !isset( $params->id ) || empty( $params->id ) ) && ( !isset( $params->name ) || empty( $params->name ) ) )
6429
+ return pods_error( __( 'Either Object ID or Name are required', 'pods' ), $this );
6430
+
6431
+ /**
6432
+ * @var $wpdb wpdb
6433
+ */
6434
+ global $wpdb;
6435
+
6436
+ if ( isset( $params->name ) )
6437
+ $_object = pods_by_title( $params->name, ARRAY_A, '_pods_' . $params->type, 'publish' );
6438
+ else {
6439
+ $object = $params->id;
6440
+
6441
+ $_object = get_post( $object, ARRAY_A );
6442
+ }
6443
+
6444
+ if ( empty( $_object ) ) {
6445
+ if ( $strict )
6446
+ return pods_error( __( 'Object not found', 'pods' ), $this );
6447
+
6448
+ return false;
6449
+ }
6450
+ }
6451
+
6452
+ $object = array(
6453
+ 'id' => $_object[ 'ID' ],
6454
+ 'name' => $_object[ 'post_title' ],
6455
+ 'code' => $_object[ 'post_content' ],
6456
+ 'type' => str_replace( '_pods_', '', $_object[ 'post_type' ] ),
6457
+ 'slug' => $_object[ 'post_name' ]
6458
+ );
6459
+
6460
+ $object[ 'options' ] = get_post_meta( $object[ 'id' ] );
6461
+
6462
+ foreach ( $object[ 'options' ] as $option => &$value ) {
6463
+ if ( is_array( $value ) && 1 == count( $value ) )
6464
+ $value = current( $value );
6465
+ }
6466
+
6467
+ return $object;
6468
+ }
6469
+
6470
+ /**
6471
+ * Load Multiple Pods Objects
6472
+ *
6473
+ * $params['type'] string The Object type
6474
+ * $params['options'] array Pod Option(s) key=>value array to filter by
6475
+ * $params['orderby'] string ORDER BY clause of query
6476
+ * $params['limit'] string Number of objects to return
6477
+ * $params['where'] string WHERE clause of query
6478
+ * $params['ids'] string|array IDs of Objects
6479
+ *
6480
+ * @param array|object $params An associative array of parameters
6481
+ *
6482
+ * @return array
6483
+ * @since 2.0
6484
+ */
6485
+ public function load_objects ( $params ) {
6486
+ $params = (object) pods_sanitize( $params );
6487
+
6488
+ if ( !isset( $params->type ) || empty( $params->type ) )
6489
+ return pods_error( __( 'Pods Object type is required', 'pods' ), $this );
6490
+
6491
+ $order = 'ASC';
6492
+ $orderby = 'menu_order';
6493
+ $limit = -1;
6494
+ $ids = false;
6495
+
6496
+ $meta_query = array();
6497
+ $cache_key = '';
6498
+
6499
+ if ( isset( $params->options ) && !empty( $params->options ) && is_array( $params->options ) ) {
6500
+ foreach ( $params->options as $option => $value ) {
6501
+ if ( !is_array( $value ) )
6502
+ $value = array( $value );
6503
+
6504
+ $value = pods_trim( $value );
6505
+
6506
+ sort( $value );
6507
+
6508
+ $meta_query[] = array(
6509
+ 'key' => $option,
6510
+ 'value' => pods_sanitize( $value ),
6511
+ 'compare' => 'IN'
6512
+ );
6513
+ }
6514
+ }
6515
+
6516
+ if ( isset( $params->where ) && is_array( $params->where ) )
6517
+ $meta_query = array_merge( $meta_query, (array) $params->where );
6518
+
6519
+ if ( isset( $params->order ) && !empty( $params->order ) && in_array( strtoupper( $params->order ), array( 'ASC', 'DESC' ) ) )
6520
+ $order = strtoupper( $params->order );
6521
+
6522
+ if ( isset( $params->orderby ) && !empty( $params->orderby ) )
6523
+ $orderby = strtoupper( $params->orderby );
6524
 
6525
+ if ( isset( $params->limit ) && !empty( $params->limit ) )
6526
+ $limit = pods_absint( $params->limit );
6527
 
6528
+ if ( isset( $params->ids ) && !empty( $params->ids ) ) {
6529
+ $ids = $params->ids;
 
 
 
 
 
 
 
 
 
 
6530
 
6531
+ if ( !is_array( $ids ) )
6532
+ $ids = explode( ',', $ids );
6533
+ }
6534
 
6535
+ if ( empty( $ids ) )
6536
+ $ids = false;
6537
+
6538
+ if ( pods_api_cache() && empty( $meta_query ) && empty( $limit ) && ( empty( $orderby ) || 'menu_order' == $orderby ) && empty( $ids ) ) {
6539
+ $cache_key = 'pods_objects_' . $params->type;
6540
 
6541
+ $the_objects = pods_transient_get( $cache_key );
 
 
6542
 
6543
+ if ( false !== $the_objects )
6544
+ return $the_objects;
6545
+ }
6546
 
6547
+ $the_objects = array();
 
 
 
 
6548
 
6549
+ $args = array(
6550
+ 'post_type' => '_pods_' . $params->type,
6551
+ 'nopaging' => true,
6552
+ 'posts_per_page' => $limit,
6553
+ 'order' => $order,
6554
+ 'orderby' => $orderby,
6555
+ 'meta_query' => $meta_query,
6556
+ );
6557
 
6558
+ // Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
6559
+ if ( false != $ids ) {
6560
+ $args[ 'post__in' ] = $ids;
6561
+ }
 
 
 
6562
 
6563
+ $objects = get_posts( $args );
 
 
6564
 
6565
+ foreach ( $objects as $object ) {
6566
+ $object = $this->load_object( $object );
6567
+
6568
+ $the_objects[ $object[ 'name' ] ] = $object;
6569
+ }
6570
+
6571
+ if ( pods_api_cache() && !empty( $cache_key ) )
6572
+ pods_transient_set( $cache_key, $the_objects );
6573
+
6574
+ return $the_objects;
6575
+ }
6576
+
6577
+ /**
6578
+ * @see PodsAPI::load_object
6579
+ *
6580
+ * Load a Pod Template
6581
+ *
6582
+ * $params['id'] int The template ID
6583
+ * $params['name'] string The template name
6584
+ *
6585
+ * @param array $params An associative array of parameters
6586
+ *
6587
+ * @return array|bool
6588
+ * @since 1.7.9
6589
+ */
6590
+ public function load_template ( $params ) {
6591
+ if ( !class_exists( 'Pods_Templates' ) )
6592
+ return false;
6593
+
6594
+ $params = (object) $params;
6595
+ $params->type = 'template';
6596
+ return $this->load_object( $params );
6597
+ }
6598
+
6599
+ /**
6600
+ * @see PodsAPI::load_objects
6601
+ *
6602
+ * Load Multiple Pod Templates
6603
+ *
6604
+ * $params['where'] string The WHERE clause of query
6605
+ * $params['options'] array Pod Option(s) key=>value array to filter by
6606
+ * $params['orderby'] string ORDER BY clause of query
6607
+ * $params['limit'] string Number of templates to return
6608
+ *
6609
+ * @param array $params (optional) An associative array of parameters
6610
+ *
6611
+ * @return array
6612
+ *
6613
+ * @since 2.0
6614
+ */
6615
+ public function load_templates ( $params = null ) {
6616
+ if ( !class_exists( 'Pods_Templates' ) )
6617
+ return array();
6618
+
6619
+ $params = (object) $params;
6620
+ $params->type = 'template';
6621
+ return $this->load_objects( $params );
6622
+ }
6623
+
6624
+ /**
6625
+ * @see PodsAPI::load_object
6626
+ *
6627
+ * Load a Pod Page
6628
+ *
6629
+ * $params['id'] int The page ID
6630
+ * $params['name'] string The page URI
6631
+ *
6632
+ * @param array $params An associative array of parameters
6633
+ *
6634
+ * @return array|bool
6635
+ *
6636
+ * @since 1.7.9
6637
+ */
6638
+ public function load_page ( $params ) {
6639
+ if ( !class_exists( 'Pods_Pages' ) )
6640
+ return false;
6641
+
6642
+ $params = (object) $params;
6643
+ if ( !isset( $params->name ) && isset( $params->uri ) ) {
6644
+ $params->name = $params->uri;
6645
+ unset( $params->uri );
6646
+ }
6647
+ $params->type = 'page';
6648
+ return $this->load_object( $params );
6649
+ }
6650
+
6651
+ /**
6652
+ * @see PodsAPI::load_objects
6653
+ *
6654
+ * Load Multiple Pod Pages
6655
+ *
6656
+ * $params['where'] string The WHERE clause of query
6657
+ * $params['options'] array Pod Option(s) key=>value array to filter by
6658
+ * $params['orderby'] string ORDER BY clause of query
6659
+ * $params['limit'] string Number of pages to return
6660
+ *
6661
+ * @param array $params (optional) An associative array of parameters
6662
+ *
6663
+ * @return array
6664
+ *
6665
+ * @since 2.0
6666
+ */
6667
+ public function load_pages ( $params = null ) {
6668
+ if ( !class_exists( 'Pods_Pages' ) )
6669
+ return array();
6670
+
6671
+ $params = (object) $params;
6672
+ $params->type = 'page';
6673
+ return $this->load_objects( $params );
6674
+ }
6675
+
6676
+ /**
6677
+ * @see PodsAPI::load_object
6678
+ *
6679
+ * Load a Pod Helper
6680
+ *
6681
+ * $params['id'] int The helper ID
6682
+ * $params['name'] string The helper name
6683
+ *
6684
+ * @param array $params An associative array of parameters
6685
+ *
6686
+ * @return array|bool
6687
+ *
6688
+ * @since 1.7.9
6689
+ */
6690
+ public function load_helper ( $params ) {
6691
+ if ( !class_exists( 'Pods_Helpers' ) )
6692
+ return false;
6693
+
6694
+ $params = (object) $params;
6695
+ $params->type = 'helper';
6696
+ return $this->load_object( $params );
6697
+ }
6698
+
6699
+ /**
6700
+ * @see PodsAPI::load_objects
6701
+ *
6702
+ * Load Multiple Pod Helpers
6703
+ *
6704
+ * $params['where'] string The WHERE clause of query
6705
+ * $params['options'] array Pod Option(s) key=>value array to filter by
6706
+ * $params['orderby'] string ORDER BY clause of query
6707
+ * $params['limit'] string Number of pages to return
6708
+ *
6709
+ * @param array $params (optional) An associative array of parameters
6710
+ *
6711
+ * @return array
6712
+ *
6713
+ * @since 2.0
6714
+ */
6715
+ public function load_helpers ( $params = null ) {
6716
+ if ( !class_exists( 'Pods_Helpers' ) )
6717
+ return array();
6718
+
6719
+ $params = (object) $params;
6720
+ $params->type = 'helper';
6721
+ return $this->load_objects( $params );
6722
+ }
6723
+
6724
+ /**
6725
+ * Load the pod item object
6726
+ *
6727
+ * $params['pod'] string The datatype name
6728
+ * $params['id'] int (optional) The item's ID
6729
+ *
6730
+ * @param array $params An associative array of parameters
6731
+ *
6732
+ * @return bool|\Pods
6733
+ *
6734
+ * @uses pods()
6735
+ *
6736
+ * @since 2.0
6737
+ */
6738
+ public function load_pod_item ( $params ) {
6739
+ $params = (object) pods_sanitize( $params );
6740
+
6741
+ if ( !isset( $params->pod ) || empty( $params->pod ) )
6742
+ return pods_error( __( 'Pod name required', 'pods' ), $this );
6743
+ if ( !isset( $params->id ) || empty( $params->id ) )
6744
+ return pods_error( __( 'Item ID required', 'pods' ), $this );
6745
+
6746
+ $pod = false;
6747
+
6748
+ if ( pods_api_cache() )
6749
+ $pod = pods_cache_get( $params->id, 'pods_item_object_' . $params->pod );
6750
+
6751
+ if ( false !== $pod )
6752
+ return $pod;
6753
+
6754
+ $pod = pods( $params->pod, $params->id );
6755
+
6756
+ if ( pods_api_cache() )
6757
+ pods_cache_set( $params->id, $pod, 'pods_item_object_' . $params->pod );
6758
+
6759
+ return $pod;
6760
+ }
6761
+
6762
+ /**
6763
+ * Load potential sister fields for a specific field
6764
+ *
6765
+ * $params['pod'] int The Pod name
6766
+ * $params['related_pod'] string The related Pod name
6767
+ *
6768
+ * @param array $params An associative array of parameters
6769
+ * @param array $pod (optional) Array of Pod data to use (to avoid lookup)
6770
+ *
6771
+ * @return array|bool
6772
+ *
6773
+ * @since 1.7.9
6774
+ *
6775
+ * @uses PodsAPI::load_pod
6776
+ */
6777
+ public function load_sister_fields ( $params, $pod = null ) {
6778
+ $params = (object) pods_sanitize( $params );
6779
+
6780
+ if ( empty( $pod ) ) {
6781
+ $pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => false ), false );
6782
+
6783
+ if ( false === $pod )
6784
+ return pods_error( __( 'Pod not found', 'pods' ), $this );
6785
+ }
6786
+
6787
+ $params->pod_id = $pod[ 'id' ];
6788
+ $params->pod = $pod[ 'name' ];
6789
+
6790
+ $type = false;
6791
+
6792
+ if ( 0 === strpos( $params->related_pod, 'pod-' ) ) {
6793
+ $params->related_pod = pods_str_replace( 'pod-', '', $params->related_pod, 1 );
6794
+ $type = 'pod';
6795
+ }
6796
+ elseif ( 0 === strpos( $params->related_pod, 'post_type-' ) ) {
6797
+ $params->related_pod = pods_str_replace( 'post_type-', '', $params->related_pod, 1 );
6798
+ $type = 'post_type';
6799
+ }
6800
+ elseif ( 0 === strpos( $params->related_pod, 'taxonomy-' ) ) {
6801
+ $params->related_pod = pods_str_replace( 'taxonomy-', '', $params->related_pod, 1 );
6802
+ $type = 'taxonomy';
6803
+ }
6804
+
6805
+ $related_pod = $this->load_pod( array( 'name' => $params->related_pod, 'table_info' => false ), false );
6806
+
6807
+ if ( false === $related_pod || ( false !== $type && 'pod' != $type && $type != $related_pod[ 'type' ] ) )
6808
+ return pods_error( __( 'Related Pod not found', 'pods' ), $this );
6809
+
6810
+ $params->related_pod_id = $related_pod[ 'id' ];
6811
+ $params->related_pod = $related_pod[ 'name' ];
6812
+
6813
+ $sister_fields = array();
6814
+
6815
+ foreach ( $related_pod[ 'fields' ] as $field ) {
6816
+ if ( 'pick' == $field[ 'type' ] && in_array( $field[ 'pick_object' ], array( $pod[ 'type' ], 'pod' ) ) && ( $params->pod == $field[ 'pick_object' ] || $params->pod == $field[ 'pick_val' ] ) )
6817
+ $sister_fields[ $field[ 'id' ] ] = esc_html( $field[ 'label' ] . ' (' . $field[ 'name' ] . ')' );
6818
+ }
6819
+
6820
+ return $sister_fields;
6821
+ }
6822
+
6823
+ /**
6824
+ * Takes a sql field such as tinyint and returns the pods field type, such as num.
6825
+ *
6826
+ * @param string $sql_field The SQL field to look for
6827
+ *
6828
+ * @return string The field type
6829
+ *
6830
+ * @since 2.0
6831
+ */
6832
+ public static function detect_pod_field_from_sql_data_type ( $sql_field ) {
6833
+ $sql_field = strtolower( $sql_field );
6834
+
6835
+ $field_to_field_map = array(
6836
+ 'tinyint' => 'number',
6837
+ 'smallint' => 'number',
6838
+ 'mediumint' => 'number',
6839
+ 'int' => 'number',
6840
+ 'bigint' => 'number',
6841
+ 'float' => 'number',
6842
+ 'double' => 'number',
6843
+ 'decimal' => 'number',
6844
+ 'date' => 'date',
6845
+ 'datetime' => 'datetime',
6846
+ 'timestamp' => 'datetime',
6847
+ 'time' => 'time',
6848
+ 'year' => 'date',
6849
+ 'varchar' => 'text',
6850
+ 'text' => 'paragraph',
6851
+ 'mediumtext' => 'paragraph',
6852
+ 'longtext' => 'paragraph'
6853
+ );
6854
+
6855
+ return ( array_key_exists( $sql_field, $field_to_field_map ) ) ? $field_to_field_map[ $sql_field ] : 'paragraph';
6856
+ }
6857
+
6858
+ /**
6859
+ * Gets all field types
6860
+ *
6861
+ * @return array Array of field types
6862
+ *
6863
+ * @uses PodsForm::field_loader
6864
+ *
6865
+ * @since 2.0
6866
+ * @deprecated
6867
+ */
6868
+ public function get_field_types () {
6869
+ return PodsForm::field_types();
6870
+ }
6871
+
6872
+ /**
6873
+ * Gets the schema definition of a field.
6874
+ *
6875
+ * @param string $type Field type to look for
6876
+ * @param array $options (optional) Options of the field to pass to the schema function.
6877
+ *
6878
+ * @return array|bool|mixed|null
6879
+ *
6880
+ * @since 2.0
6881
+ */
6882
+ private function get_field_definition ( $type, $options = null ) {
6883
+ $definition = PodsForm::field_method( $type, 'schema', $options );
6884
+
6885
+ return $this->do_hook( 'field_definition', $definition, $type, $options );
6886
+ }
6887
+
6888
+ /**
6889
+ * @see PodsForm:validate
6890
+ *
6891
+ * Validates the value of a field.
6892
+ *
6893
+ * @param mixed $value The value to validate
6894
+ * @param string $field Field to use for validation
6895
+ * @param array $object_fields Fields of the object we're validating
6896
+ * @param array $fields Array of all fields data
6897
+ * @param array|Pods $pod Array of pod data (or Pods object)
6898
+ * @param array|object $params Extra parameters to pass to the validation function of the field.
6899
+ *
6900
+ * @return array|bool
6901
+ *
6902
+ * @uses PodsForm::validate
6903
+ *
6904
+ * @since 2.0
6905
+ */
6906
+ public function handle_field_validation ( &$value, $field, $object_fields, $fields, $pod, $params ) {
6907
+ $tableless_field_types = PodsForm::tableless_field_types();
6908
+
6909
+ $fields = array_merge( $fields, $object_fields );
6910
+
6911
+ $options = $fields[ $field ];
6912
+
6913
+ $id = ( is_object( $params ) ? $params->id : ( is_object( $pod ) ? $pod->id() : 0 ) );
6914
+
6915
+ if ( is_object( $pod ) )
6916
+ $pod = $pod->pod_data;
6917
+
6918
+ $type = $options[ 'type' ];
6919
+ $label = $options[ 'label' ];
6920
+ $label = empty( $label ) ? $field : $label;
6921
+
6922
+ // Verify required fields
6923
+ if ( 1 == pods_var( 'required', $options[ 'options' ], 0 ) && 'slug' != $type ) {
6924
+ if ( '' == $value || null === $value || array() === $value )
6925
+ return pods_error( sprintf( __( '%s is empty', 'pods' ), $label ), $this );
6926
+
6927
+ if ( 'multi' == pods_var( 'pick_format_type', $options[ 'options' ] ) && 'autocomplete' != pods_var( 'pick_format_multi', $options[ 'options' ] ) ) {
6928
+ $has_value = false;
6929
+
6930
+ $check_value = (array) $value;
6931
+
6932
+ foreach ( $check_value as $val ) {
6933
+ if ( '' != $val && null !== $val && 0 !== $val && '0' !== $val ) {
6934
+ $has_value = true;
6935
+
6936
+ continue;
6937
+ }
6938
+ }
6939
+
6940
+ if ( !$has_value )
6941
+ return pods_error( sprintf( __( '%s is required', 'pods' ), $label ), $this );
6942
+ }
6943
+
6944
+ }
6945
+
6946
+ // @todo move this to after pre-save preparations
6947
+ // Verify unique fields
6948
+ if ( 1 == pods_var( 'unique', $options[ 'options' ], 0 ) && '' !== $value && null !== $value && array() !== $value ) {
6949
+ if ( empty( $pod ) )
6950
+ return false;
6951
+
6952
+ if ( !in_array( $type, $tableless_field_types ) ) {
6953
+ $exclude = '';
6954
+
6955
+ if ( !empty( $id ) )
6956
+ $exclude = "AND `id` != {$id}";
6957
+
6958
+ $check = false;
6959
+
6960
+ $check_value = pods_sanitize( $value );
6961
+
6962
+ // @todo handle meta-based fields
6963
+ // Trigger an error if not unique
6964
+ if ( 'table' == $pod[ 'storage' ] )
6965
+ $check = pods_query( "SELECT `id` FROM `@wp_pods_" . $pod[ 'name' ] . "` WHERE `{$field}` = '{$check_value}' {$exclude} LIMIT 1", $this );
6966
+
6967
+ if ( !empty( $check ) )
6968
+ return pods_error( sprintf( __( '%s needs to be unique', 'pods' ), $label ), $this );
6969
+ }
6970
+ else {
6971
+ // @todo handle tableless check
6972
+ }
6973
+ }
6974
+
6975
+ $validate = PodsForm::validate( $options[ 'type' ], $value, $field, array_merge( $options, pods_var( 'options', $options, array() ) ), $fields, $pod, $id, $params );
6976
+
6977
+ $validate = $this->do_hook( 'field_validation', $validate, $value, $field, $object_fields, $fields, $pod, $params );
6978
+
6979
+ return $validate;
6980
+ }
6981
+
6982
+ /**
6983
+ * Find items related to a parent field
6984
+ *
6985
+ * @param int $field_id The Field ID
6986
+ * @param int $pod_id The Pod ID
6987
+ * @param mixed $ids A comma-separated string (or array) of item IDs
6988
+ * @param array $field Field data array
6989
+ * @param array $pod Pod data array
6990
+ *
6991
+ * @return array
6992
+ *
6993
+ * @since 2.0
6994
+ *
6995
+ * @uses pods_query()
6996
+ */
6997
+ public function lookup_related_items ( $field_id, $pod_id, $ids, $field = null, $pod = null ) {
6998
+ $related_ids = array();
6999
 
7000
+ if ( !is_array( $ids ) )
7001
+ $ids = explode( ',', $ids );
 
 
 
 
7002
 
7003
+ foreach ( $ids as $k => $id ) {
7004
+ $ids[ $k ] = (int) $id;
7005
+ }
7006
 
7007
+ $ids = array_unique( array_filter( $ids ) );
 
 
7008
 
7009
+ $idstring = implode( ',', $ids );
7010
+ if ( 0 != $pod_id && 0 != $field_id && isset( self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ] ) ) {
7011
+ // Check cache first, no point in running the same query multiple times
7012
+ return self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ];
7013
+ }
7014
 
7015
+ $tableless_field_types = PodsForm::tableless_field_types();
 
 
7016
 
7017
+ $field_type = pods_v( 'type', $field );
 
7018
 
7019
+ if ( empty( $ids ) || !in_array( $field_type, $tableless_field_types ) )
7020
+ return array();
 
 
 
 
 
 
 
 
7021
 
7022
+ $related_pick_limit = 0;
7023
+
7024
+ if ( empty( $field ) ) {
7025
+ $field = $this->load_field( array( 'id' => $field_id ) );
7026
  }
7027
 
7028
+ if ( !empty( $field ) ) {
7029
+ $options = (array) pods_var_raw( 'options', $field, $field, null, true );
 
 
 
7030
 
7031
+ $related_pick_limit = (int) pods_v( $field_type . '_limit', $options, 0 );
 
7032
 
7033
+ if ( 'single' == pods_var_raw( $field_type . '_format_type', $options ) )
7034
+ $related_pick_limit = 1;
7035
 
7036
+ // Temporary hack until there's some better handling here
7037
+ $related_pick_limit = $related_pick_limit * count( $ids );
7038
+ }
 
7039
 
7040
+ if ( 'taxonomy' == $field_type ) {
7041
+ $related = wp_get_object_terms( $ids, pods_v( 'name', $field ), array( 'fields' => 'ids' ) );
7042
 
7043
+ if ( !is_wp_error( $related ) ) {
7044
+ $related_ids = $related;
7045
+ }
7046
  }
7047
+ elseif ( !pods_tableless() ) {
7048
+ $ids = implode( ', ', $ids );
7049
+
7050
+ $field_id = (int) $field_id;
7051
+ $sister_id = (int) pods_var_raw( 'sister_id', $field, 0 );
7052
+
7053
+ $related_where = "
7054
+ `field_id` = {$field_id}
7055
+ AND `item_id` IN ( {$ids} )
7056
+ ";
7057
+
7058
+ $sql = "
7059
+ SELECT item_id, related_item_id, related_field_id
7060
+ FROM `@wp_podsrel`
7061
+ WHERE
7062
+ {$related_where}
7063
+ ORDER BY `weight`
7064
+ ";
7065
+
7066
+ $relationships = pods_query( $sql );
7067
+
7068
+ if ( !empty( $relationships ) ) {
7069
+ foreach ( $relationships as $relation ) {
7070
+ if ( !in_array( $relation->related_item_id, $related_ids ) )
7071
+ $related_ids[] = (int) $relation->related_item_id;
7072
+ elseif ( 0 < $sister_id && $field_id == $relation->related_field_id && !in_array( $relation->item_id, $related_ids ) )
7073
+ $related_ids[] = (int) $relation->item_id;
7074
+ }
7075
+ }
7076
+ }
7077
+ else {
7078
+ if ( !is_array( $pod ) )
7079
+ $pod = $this->load_pod( array( 'id' => $pod_id, 'table_info' => false ), false );
7080
+
7081
+ if ( !empty( $pod ) && in_array( $pod[ 'type' ], array( 'post_type', 'media', 'taxonomy', 'user', 'comment', 'settings' ) ) ) {
7082
+ $meta_type = $pod[ 'type' ];
7083
+
7084
+ if ( in_array( $meta_type, array( 'post_type', 'media' ) ) )
7085
+ $meta_type = 'post';
7086
+ elseif ( 'taxonomy' == $meta_type )
7087
+ $meta_type = 'term';
7088
+
7089
+ $no_conflict = pods_no_conflict_check( ( 'term' == $meta_type ? 'taxonomy' : $meta_type ) );
7090
+
7091
+ if ( !$no_conflict )
7092
+ pods_no_conflict_on( ( 'term' == $meta_type ? 'taxonomy' : $meta_type ) );
7093
+
7094
+ foreach ( $ids as $id ) {
7095
+ if ( 'settings' == $meta_type ) {
7096
+ $related_id = get_option( '_pods_' . $pod[ 'name' ] . '_' . $field[ 'name' ] );
7097
+
7098
+ if ( empty( $related_id ) )
7099
+ $related_id = get_option( $pod[ 'name' ] . '_' . $field[ 'name' ] );
7100
+
7101
+ if ( is_array( $related_id ) && !empty( $related_id ) ) {
7102
+ foreach ( $related_id as $related ) {
7103
+ if ( is_array( $related ) && !empty( $related ) ) {
7104
+ if ( isset( $related[ 'id' ] ) )
7105
+ $related_ids[] = (int) $related[ 'id' ];
7106
+ else {
7107
+ foreach ( $related as $r ) {
7108
+ $related_ids[] = (int) $r;
7109
+ }
7110
+ }
7111
+ }
7112
+ else
7113
+ $related_ids[] = (int) $related;
7114
+ }
7115
+ }
7116
+ }
7117
+ else {
7118
+ $related_id = get_metadata( $meta_type, $id, '_pods_' . $field[ 'name' ], true );
7119
+
7120
+ if ( empty( $related_id ) )
7121
+ $related_id = get_metadata( $meta_type, $id, $field[ 'name' ] );
7122
+
7123
+ if ( is_array( $related_id ) && !empty( $related_id ) ) {
7124
+ foreach ( $related_id as $related ) {
7125
+ if ( is_array( $related ) && !empty( $related ) ) {
7126
+ if ( isset( $related[ 'id' ] ) )
7127
+ $related_ids[] = (int) $related[ 'id' ];
7128
+ else {
7129
+ foreach ( $related as $r ) {
7130
+ if ( isset( $related[ 'id' ] ) )
7131
+ $related_ids[] = (int) $r[ 'id' ];
7132
+ else
7133
+ $related_ids[] = (int) $r;
7134
+ }
7135
+ }
7136
+ }
7137
+ else
7138
+ $related_ids[] = (int) $related;
7139
+ }
7140
+ }
7141
+ }
7142
+ }
7143
+
7144
+ if ( !$no_conflict )
7145
+ pods_no_conflict_off( ( 'term' == $meta_type ? 'taxonomy' : $meta_type ) );
7146
+ }
7147
+ }
7148
+
7149
+ if ( is_array( $related_ids ) ) {
7150
+ $related_ids = array_unique( array_filter( $related_ids ) );
7151
+
7152
+ if ( 0 < $related_pick_limit && !empty( $related_ids ) )
7153
+ $related_ids = array_slice( $related_ids, 0, $related_pick_limit );
7154
+ }
7155
+ if ( 0 != $pod_id && 0 != $field_id && ! empty( $related_ids ) ) {
7156
+ // Only cache if $pod_id and $field_id were passed
7157
+ self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ] = $related_ids;
7158
+ }
7159
+
7160
+ return $related_ids;
7161
+ }
7162
+
7163
+ /**
7164
+ * Find related items related to an item
7165
+ *
7166
+ * @param int $field_id The Field ID
7167
+ * @param int $pod_id The Pod ID
7168
+ * @param int $id Item ID to get related IDs from
7169
+ * @param array $field Field data array
7170
+ * @param array $pod Pod data array
7171
+ *
7172
+ * @return array|bool
7173
+ *
7174
+ * @since 2.3
7175
+ *
7176
+ * @uses pods_query()
7177
+ */
7178
+ public function lookup_related_items_from ( $field_id, $pod_id, $id, $field = null, $pod = null ) {
7179
+ $related_ids = false;
7180
+
7181
+ $id = (int) $id;
7182
+
7183
+ $tableless_field_types = PodsForm::tableless_field_types();
7184
+
7185
+ if ( empty( $id ) || !in_array( pods_v( 'type', $field ), $tableless_field_types ) )
7186
+ return false;
7187
+
7188
+ $related_pick_limit = 0;
7189
+
7190
+ if ( !empty( $field ) ) {
7191
+ $options = (array) pods_var_raw( 'options', $field, $field, null, true );
7192
+
7193
+ $related_pick_limit = (int) pods_v( 'pick_limit', $options, 0 );
7194
+
7195
+ if ( 'single' == pods_var_raw( 'pick_format_type', $options ) )
7196
+ $related_pick_limit = 1;
7197
+ }
7198
+
7199
+ if ( !pods_tableless() ) {
7200
+ $field_id = (int) $field_id;
7201
+ $sister_id = (int) pods_var_raw( 'sister_id', $field, 0 );
7202
+
7203
+ $related_where = "
7204
+ `field_id` = {$field_id}
7205
+ AND `related_item_id` = {$id}
7206
+ ";
7207
+
7208
+ $sql = "
7209
+ SELECT *
7210
+ FROM `@wp_podsrel`
7211
+ WHERE
7212
+ {$related_where}
7213
+ ORDER BY `weight`
7214
+ ";
7215
+
7216
+ $relationships = pods_query( $sql );
7217
+
7218
+ if ( !empty( $relationships ) ) {
7219
+ $related_ids = array();
7220
+
7221
+ foreach ( $relationships as $relation ) {
7222
+ if ( $field_id == $relation->field_id && !in_array( $relation->item_id, $related_ids ) )
7223
+ $related_ids[] = (int) $relation->item_id;
7224
+ elseif ( 0 < $sister_id && $field_id == $relation->related_field_id && !in_array( $relation->related_item_id, $related_ids ) )
7225
+ $related_ids[] = (int) $relation->related_item_id;
7226
+ }
7227
+ }
7228
+ }
7229
+ else {
7230
+ // @todo handle meta-based lookups
7231
+ return false;
7232
+
7233
+ if ( !is_array( $pod ) )
7234
+ $pod = $this->load_pod( array( 'id' => $pod_id, 'table_info' => false ), false );
7235
+
7236
+ if ( !empty( $pod ) && in_array( $pod[ 'type' ], array( 'post_type', 'media', 'taxonomy', 'user', 'comment', 'settings' ) ) ) {
7237
+ $related_ids = array();
7238
+
7239
+ $meta_type = $pod[ 'type' ];
7240
+
7241
+ if ( in_array( $meta_type, array( 'post_type', 'media' ) ) )
7242
+ $meta_type = 'post';
7243
+ elseif ( 'taxonomy' == $meta_type )
7244
+ $meta_type = 'term';
7245
+
7246
+ $no_conflict = pods_no_conflict_check( ( 'term' == $meta_type ? 'taxonomy' : $meta_type ) );
7247
+
7248
+ if ( !$no_conflict )
7249
+ pods_no_conflict_on( ( 'term' == $meta_type ? 'taxonomy' : $meta_type ) );
7250
+
7251
+ if ( 'settings' == $meta_type ) {
7252
+ $related_id = get_option( '_pods_' . $pod[ 'name' ] . '_' . $field[ 'name' ] );
7253
+
7254
+ if ( empty( $related_id ) )
7255
+ $related_id = get_option( $pod[ 'name' ] . '_' . $field[ 'name' ] );
7256
+
7257
+ if ( is_array( $related_id ) && !empty( $related_id ) ) {
7258
+ foreach ( $related_id as $related ) {
7259
+ if ( is_array( $related ) && !empty( $related ) ) {
7260
+ if ( isset( $related[ 'id' ] ) )
7261
+ $related_ids[] = (int) $related[ 'id' ];
7262
+ else {
7263
+ foreach ( $related as $r ) {
7264
+ $related_ids[] = (int) $r;
7265
+ }
7266
+ }
7267
+ }
7268
+ else
7269
+ $related_ids[] = (int) $related;
7270
+ }
7271
+ }
7272
+ }
7273
+ else {
7274
+ $related_id = get_metadata( $meta_type, $id, '_pods_' . $field[ 'name' ], true );
7275
+
7276
+ if ( empty( $related_id ) )
7277
+ $related_id = get_metadata( $meta_type, $id, $field[ 'name' ] );
7278
+
7279
+ if ( is_array( $related_id ) && !empty( $related_id ) ) {
7280
+ foreach ( $related_id as $related ) {
7281
+ if ( is_array( $related ) && !empty( $related ) ) {
7282
+ if ( isset( $related[ 'id' ] ) )
7283
+ $related_ids[] = (int) $related[ 'id' ];
7284
+ else {
7285
+ foreach ( $related as $r ) {
7286
+ if ( isset( $related[ 'id' ] ) )
7287
+ $related_ids[] = (int) $r[ 'id' ];
7288
+ else
7289
+ $related_ids[] = (int) $r;
7290
+ }
7291
+ }
7292
+ }
7293
+ else
7294
+ $related_ids[] = (int) $related;
7295
+ }
7296
+ }
7297
+ }
7298
+
7299
+ if ( !$no_conflict )
7300
+ pods_no_conflict_off( ( 'term' == $meta_type ? 'taxonomy' : $meta_type ) );
7301
+ }
7302
+ }
7303
+
7304
+ if ( is_array( $related_ids ) )
7305
+ $related_ids = array_unique( array_filter( $related_ids ) );
7306
+
7307
+ return $related_ids;
7308
+ }
7309
 
7310
  /**
 
7311
  *
7312
+ * Load the information about an objects MySQL table
7313
+ *
7314
+ * @param $object_type
7315
+ * @param string $object The object to look for
7316
+ * @param null $name (optional) Name of the pod to load
7317
+ * @param array $pod (optional) Array with pod information
7318
  *
7319
  * @return array
 
7320
  *
7321
+ * @since 2.5
7322
  */
7323
+ public function get_table_info_load ( $object_type, $object, $name = null, $pod = null ) {
7324
 
7325
+ $info = array();
7326
 
7327
+ if ( 'pod' == $object_type && null === $pod ) {
7328
+ if ( empty( $name ) ) {
7329
+ $prefix = 'pod-';
7330
 
7331
+ // Make sure we actually have the prefix before trying anything with the name
7332
+ if ( 0 === strpos( $object_type, $prefix ) )
7333
+ $name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
7334
+ }
7335
 
7336
+ if ( empty( $name ) && !empty( $object ) )
7337
+ $name = $object;
 
 
 
 
 
 
 
 
7338
 
7339
+ $pod = $this->load_pod( array( 'name' => $name, 'table_info' => false ), false );
 
 
 
7340
 
7341
+ if ( !empty( $pod ) ) {
7342
+ $object_type = $pod[ 'type' ];
7343
+ $name = $pod[ 'name' ];
7344
+ $object = $pod[ 'object' ];
7345
 
7346
+ $info[ 'pod' ] = $pod;
7347
+ }
7348
+ }
7349
+ elseif ( null === $pod ) {
7350
+ if ( empty( $name ) ) {
7351
+ $prefix = $object_type . '-';
7352
 
7353
+ // Make sure we actually have the prefix before trying anything with the name
7354
+ if ( 0 === strpos( $object_type, $prefix ) )
7355
+ $name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
7356
  }
7357
 
7358
+ if ( empty( $name ) && !empty( $object ) )
7359
+ $name = $object;
7360
+
7361
+ if ( !empty( $name ) ) {
7362
+ $pod = $this->load_pod( array( 'name' => $name, 'table_info' => false ), false );
7363
+
7364
+ if ( !empty( $pod ) && ( null === $object_type || $object_type == $pod[ 'type' ] ) ) {
7365
+ $object_type = $pod[ 'type' ];
7366
+ $name = $pod[ 'name' ];
7367
+ $object = $pod[ 'object' ];
7368
+
7369
+ $info[ 'pod' ] = $pod;
7370
+ }
7371
  }
 
 
7372
  }
7373
+ elseif ( !empty( $pod ) )
7374
+ $info[ 'pod' ] = $pod;
7375
 
7376
+ if ( 0 === strpos( $object_type, 'pod' ) ) {
7377
+ if ( empty( $name ) ) {
7378
+ $prefix = 'pod-';
7379
 
7380
+ // Make sure we actually have the prefix before trying anything with the name
7381
+ if ( 0 === strpos( $object_type, $prefix ) )
7382
+ $name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
7383
+ }
7384
 
7385
+ $info[ 'type' ] = 'pod';
7386
+ global $wpdb;
7387
 
7388
+ $info[ 'table' ] = $info[ 'meta_table' ] = $wpdb->prefix . 'pods_' . ( empty( $object ) ? $name : $object );
7389
 
7390
+ if ( is_array( $info[ 'pod' ] ) && 'pod' == pods_v( 'type', $info[ 'pod' ] ) ) {
7391
+ $info[ 'pod_field_index' ] = $info[ 'field_index' ] = $info[ 'meta_field_index' ] = $info[ 'meta_field_value' ] = pods_v( 'pod_index', $info[ 'pod' ][ 'options' ], 'id', true );
7392
 
7393
+ $slug_field = get_posts( array(
7394
+ 'post_type' => '_pods_field',
7395
+ 'posts_per_page' => 1,
7396
+ 'nopaging' => true,
7397
+ 'post_parent' => $info[ 'pod' ][ 'id' ],
7398
+ 'orderby' => 'menu_order',
7399
+ 'order' => 'ASC',
7400
+ 'meta_query' => array(
7401
+ array(
7402
+ 'key' => 'type',
7403
+ 'value' => 'slug',
7404
+ )
7405
+ )
7406
+ ) );
7407
 
7408
+ if ( !empty( $slug_field ) ) {
7409
+ $slug_field = $slug_field[ 0 ];
7410
 
7411
+ $info[ 'field_slug' ] = $info[ 'pod_field_slug' ] = $slug_field->post_name;
7412
+ }
7413
 
7414
+ if ( 1 == pods_v( 'hierarchical', $info[ 'pod' ][ 'options' ], 0 ) ) {
7415
+ $parent_field = pods_v( 'pod_parent', $info[ 'pod' ][ 'options' ], 'id', true );
 
 
 
 
7416
 
7417
+ if ( !empty( $parent_field ) && isset( $info[ 'pod' ][ 'fields' ][ $parent_field ] ) ) {
7418
+ $info[ 'object_hierarchical' ] = true;
 
 
7419
 
7420
+ $info[ 'pod_field_parent' ] = $info[ 'field_parent' ] = $parent_field . '_select';
7421
+ $info[ 'field_parent_select' ] = '`' . $parent_field . '`.`id` AS `' . $info[ 'field_parent' ] . '`';
7422
+ }
7423
+ }
7424
+ }
7425
  }
7426
+ return $info;
7427
+ }
7428
 
7429
+ /**
7430
+ * Get information about an objects MySQL table
7431
+ *
7432
+ * @param string $object_type
7433
+ * @param string $object The object to look for
7434
+ * @param null $name (optional) Name of the pod to load
7435
+ * @param array $pod (optional) Array with pod information
7436
+ * @param array $field (optional) Array with field information
7437
+ *
7438
+ * @return array|bool
7439
+ *
7440
+ * @since 2.0
7441
+ */
7442
+ public function get_table_info ( $object_type, $object, $name = null, $pod = null, $field = null ) {
7443
+
7444
+ /**
7445
+ * @var $wpdb wpdb
7446
+ * @var $sitepress SitePress
7447
+ * @var $polylang object
7448
+ */
7449
+ /*
7450
+ * @todo wpml-comp Remove global object usage
7451
+ */
7452
+ global $wpdb, $sitepress, $polylang;
7453
 
7454
+ // @todo Handle $object arrays for Post Types, Taxonomies, Comments (table pulled from first object in array)
7455
 
7456
+ $info = array(
7457
+ //'select' => '`t`.*',
7458
+ 'object_type' => $object_type,
7459
+ 'type' => null,
7460
+ 'object_name' => $object,
7461
+ 'object_hierarchical' => false,
7462
+
7463
+ 'table' => $object,
7464
+ 'meta_table' => $object,
7465
+ 'pod_table' => $wpdb->prefix . 'pods_' . ( empty( $object ) ? $name : $object ),
7466
+
7467
+ 'field_id' => 'id',
7468
+ 'field_index' => 'name',
7469
+ 'field_slug' => null,
7470
+ 'field_type' => null,
7471
+ 'field_parent' => null,
7472
+ 'field_parent_select' => null,
7473
+
7474
+ 'meta_field_id' => 'id',
7475
+ 'meta_field_index' => 'name',
7476
+ 'meta_field_value' => 'name',
7477
+
7478
+ 'pod_field_id' => 'id',
7479
+ 'pod_field_index' => 'name',
7480
+ 'pod_field_slug' => null,
7481
+ 'pod_field_parent' => null,
7482
+
7483
+ 'join' => array(),
7484
+
7485
+ 'where' => null,
7486
+ 'where_default' => null,
7487
+
7488
+ 'orderby' => null,
7489
+
7490
+ 'pod' => null,
7491
+ 'recurse' => false
7492
+ );
7493
+
7494
+ if ( empty( $object_type ) ) {
7495
+ $object_type = 'post_type';
7496
+ $object = 'post';
7497
+ }
7498
+ elseif ( empty( $object ) && in_array( $object_type, array( 'user', 'media', 'comment' ) ) ) {
7499
+ $object = $object_type;
7500
+ }
7501
+
7502
+ $pod_name = $pod;
7503
+
7504
+ if ( is_array( $pod_name ) )
7505
+ $pod_name = pods_var_raw( 'name', $pod_name, ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $pod_name, JSON_UNESCAPED_UNICODE ) : json_encode( $pod_name ) ), null, true );
7506
+ else {
7507
+ $pod_name = $object;
7508
+ }
7509
+
7510
+ $field_name = $field;
7511
+
7512
+ if ( is_array( $field_name ) )
7513
+ $field_name = pods_var_raw( 'name', $field_name, ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $pod_name, JSON_UNESCAPED_UNICODE ) : json_encode( $field_name ) ), null, true );
7514
+
7515
+ $transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
7516
+
7517
+ $current_language = false;
7518
+ $current_language_t_id = $current_language_tt_id = 0;
7519
+
7520
+ // Get current language data
7521
+ $lang_data = self::get_current_language();
7522
+
7523
+ if ( $lang_data ) {
7524
+ if ( ! empty( $lang_data['language'] ) ) {
7525
+ $current_language = $lang_data['language'];
7526
+ }
7527
+
7528
+ if ( ! empty( $lang_data['t_id'] ) ) {
7529
+ $current_language_t_id = $lang_data['t_id'];
7530
+ }
7531
+
7532
+ if ( ! empty( $lang_data['tt_id'] ) ) {
7533
+ $current_language_tt_id = $lang_data['tt_id'];
7534
+ }
7535
+
7536
+ if ( ! empty( $lang_data['tl_t_id'] ) ) {
7537
+ $current_language_tl_t_id = $lang_data['tl_t_id'];
7538
+ }
7539
+
7540
+ if ( ! empty( $lang_data['tl_tt_id'] ) ) {
7541
+ $current_language_tl_tt_id = $lang_data['tl_tt_id'];
7542
+ }
7543
+ }
7544
+
7545
+ if ( !empty( $current_language ) )
7546
+ $transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . $current_language . '_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
7547
+
7548
+ $_info = false;
7549
+
7550
+ if ( isset( self::$table_info_cache[ $transient ] ) ) {
7551
+ // Prefer info from the object internal cache
7552
+ $_info = self::$table_info_cache[ $transient ];
7553
+ } elseif ( pods_api_cache() ) {
7554
+ $_info = pods_transient_get( $transient );
7555
+ if ( false === $_info && ! did_action( 'init' ) ) {
7556
+ $_info = pods_transient_get( $transient . '_pre_init' );
7557
+ }
7558
+ }
7559
+
7560
+ if ( false !== $_info && is_array( $_info ) ) {
7561
+ // Data was cached, use that
7562
+ $info = $_info;
7563
+ } else {
7564
+ // Data not cached, load it up
7565
+ $_info = $this->get_table_info_load( $object_type, $object, $name, $pod );
7566
+ if ( isset( $_info[ 'type' ] ) ) {
7567
+ // Allow function to override $object_type
7568
+ $object_type = $_info[ 'type' ];
7569
+ }
7570
+ $info = array_merge( $info, $_info );
7571
+ }
7572
+
7573
+ if ( 0 === strpos( $object_type, 'post_type' ) || 'media' == $object_type || in_array( pods_var_raw( 'type', $info[ 'pod' ] ), array( 'post_type', 'media' ) ) ) {
7574
+ $info[ 'table' ] = $wpdb->posts;
7575
+ $info[ 'meta_table' ] = $wpdb->postmeta;
7576
+
7577
+ $info[ 'field_id' ] = 'ID';
7578
+ $info[ 'field_index' ] = 'post_title';
7579
+ $info[ 'field_slug' ] = 'post_name';
7580
+ $info[ 'field_type' ] = 'post_type';
7581
+ $info[ 'field_parent' ] = 'post_parent';
7582
+ $info[ 'field_parent_select' ] = '`t`.`' . $info[ 'field_parent' ] . '`';
7583
+
7584
+ $info[ 'meta_field_id' ] = 'post_id';
7585
+ $info[ 'meta_field_index' ] = 'meta_key';
7586
+ $info[ 'meta_field_value' ] = 'meta_value';
7587
+
7588
+ if ( 'media' == $object_type )
7589
+ $object = 'attachment';
7590
+
7591
+ if ( empty( $name ) ) {
7592
+ $prefix = 'post_type-';
7593
+
7594
+ // Make sure we actually have the prefix before trying anything with the name
7595
+ if ( 0 === strpos( $object_type, $prefix ) )
7596
+ $name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
7597
+ }
7598
+
7599
+ if ( 'media' != $object_type )
7600
+ $object_type = 'post_type';
7601
+
7602
+ $post_type = pods_sanitize( ( empty( $object ) ? $name : $object ) );
7603
+
7604
+ if ( 'attachment' == $post_type || 'media' == $object_type )
7605
+ $info[ 'pod_table' ] = $wpdb->prefix . 'pods_media';
7606
+ else
7607
+ $info[ 'pod_table' ] = $wpdb->prefix . 'pods_' . pods_clean_name( $post_type, true, false );
7608
+
7609
+ $post_type_object = get_post_type_object( $post_type );
7610
+
7611
+ if ( is_object( $post_type_object ) && $post_type_object->hierarchical )
7612
+ $info[ 'object_hierarchical' ] = true;
7613
+
7614
+ // Post Status default
7615
+ $post_status = array( 'publish' );
7616
+
7617
+ // Pick field post_status option
7618
+ if ( ! empty( $field['pick_post_status'] ) ) {
7619
+ $post_status = (array) $field['pick_post_status'];
7620
+ }
7621
+
7622
+ /**
7623
+ * Default Post Status to query for.
7624
+ *
7625
+ * Use to change "default" post status from publish to any other status or statuses.
7626
+ *
7627
+ * @param array $post_status List of post statuses. Default is 'publish' or field setting (if available)
7628
+ * @param string $post_type Post type of current object
7629
+ * @param array $info Array of information about the object.
7630
+ * @param string $object Type of object
7631
+ * @param string $name Name of pod to load
7632
+ * @param array $pod Array with Pod information. Result of PodsAPI::load_pod()
7633
+ * @param array $field Array with field information
7634
+ *
7635
+ * @since unknown
7636
+ */
7637
+ $post_status = apply_filters( 'pods_api_get_table_info_default_post_status', $post_status, $post_type, $info, $object_type, $object, $name, $pod, $field );
7638
+
7639
+ $info[ 'where' ] = array(
7640
+ //'post_status' => '`t`.`post_status` IN ( "inherit", "publish" )', // @todo Figure out what statuses Attachments can be
7641
+ 'post_type' => '`t`.`' . $info[ 'field_type' ] . '` = "' . $post_type . '"'
7642
+ );
7643
+
7644
+ if ( 'post_type' == $object_type )
7645
+ $info[ 'where_default' ] = '`t`.`post_status` IN ( "' . implode( '", "', $post_status ) . '" )';
7646
+
7647
+ $info[ 'orderby' ] = '`t`.`menu_order`, `t`.`' . $info[ 'field_index' ] . '`, `t`.`post_date`';
7648
+
7649
+ /*
7650
+ * @todo wpml-comp Check if WPML filters can be applied afterwards
7651
+ */
7652
+ // WPML support
7653
+ if ( did_action( 'wpml_loaded' ) && !empty( $current_language ) && apply_filters( 'wpml_is_translated_post_type', false, $post_type ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' )) {
7654
+ $info[ 'join' ][ 'wpml_translations' ] = "
7655
+ LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`
7656
+ ON `wpml_translations`.`element_id` = `t`.`ID`
7657
+ AND `wpml_translations`.`element_type` = 'post_{$post_type}'
7658
+ AND `wpml_translations`.`language_code` = '{$current_language}'
7659
+ ";
7660
+
7661
+ $info[ 'join' ][ 'wpml_languages' ] = "
7662
+ LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`
7663
+ ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1
7664
+ ";
7665
+
7666
+ $info[ 'where' ][ 'wpml_languages' ] = "`wpml_languages`.`code` IS NOT NULL";
7667
+ }
7668
+ // Polylang support
7669
+ elseif( ( function_exists( 'PLL' ) || is_object( $polylang ) ) && !empty( $current_language ) && function_exists( 'pll_is_translated_post_type' ) && pll_is_translated_post_type( $post_type ) ) {
7670
+ $info[ 'join' ][ 'polylang_languages' ] = "
7671
+ LEFT JOIN `{$wpdb->term_relationships}` AS `polylang_languages`
7672
+ ON `polylang_languages`.`object_id` = `t`.`ID`
7673
+ AND `polylang_languages`.`term_taxonomy_id` = {$current_language_tt_id}
7674
+ ";
7675
+
7676
+ $info[ 'where' ][ 'polylang_languages' ] = "`polylang_languages`.`object_id` IS NOT NULL";
7677
+ }
7678
+
7679
+ $info[ 'object_fields' ] = $this->get_wp_object_fields( $object_type, $info[ 'pod' ] );
7680
+ }
7681
+ elseif ( 0 === strpos( $object_type, 'taxonomy' ) || in_array( $object_type, array( 'nav_menu', 'post_format' ) ) || 'taxonomy' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
7682
+ $info[ 'table' ] = $info[ 'meta_table' ] = $wpdb->terms;
7683
+
7684
+ $info[ 'join' ][ 'tt' ] = "LEFT JOIN `{$wpdb->term_taxonomy}` AS `tt` ON `tt`.`term_id` = `t`.`term_id`";
7685
+ $info[ 'join' ][ 'tr' ] = "LEFT JOIN `{$wpdb->term_relationships}` AS `tr` ON `tr`.`term_taxonomy_id` = `tt`.`term_taxonomy_id`";
7686
+ $info[ 'field_id' ] = $info[ 'meta_field_id' ] = 'term_id';
7687
+ $info[ 'field_index' ] = $info[ 'meta_field_index' ] = $info[ 'meta_field_value' ] = 'name';
7688
+ $info[ 'field_slug' ] = 'slug';
7689
+ $info[ 'field_type' ] = 'taxonomy';
7690
+ $info[ 'field_parent' ] = 'parent';
7691
+ $info[ 'field_parent_select' ] = '`tt`.`' . $info[ 'field_parent' ] . '`';
7692
+
7693
+ if ( ! empty( $wpdb->termmeta ) ) {
7694
+ $info[ 'meta_table' ] = $wpdb->termmeta;
7695
+
7696
+ $info[ 'meta_field_id' ] = 'term_id';
7697
+ $info[ 'meta_field_index' ] = 'meta_key';
7698
+ $info[ 'meta_field_value' ] = 'meta_value';
7699
+ }
7700
+
7701
+ if ( 'nav_menu' == $object_type )
7702
+ $object = 'nav_menu';
7703
+ elseif ( 'post_format' == $object_type )
7704
+ $object = 'post_format';
7705
+
7706
+ if ( empty( $name ) ) {
7707
+ $prefix = 'taxonomy-';
7708
+
7709
+ // Make sure we actually have the prefix before trying anything with the name
7710
+ if ( 0 === strpos( $object_type, $prefix ) )
7711
+ $name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
7712
+ }
7713
+
7714
+ if ( !in_array( $object_type, array( 'nav_menu', 'post_format' ) ) )
7715
+ $object_type = 'taxonomy';
7716
+
7717
+ $taxonomy = pods_sanitize( ( empty( $object ) ? $name : $object ) );
7718
+
7719
+ $info[ 'pod_table' ] = $wpdb->prefix . 'pods_' . pods_clean_name( $taxonomy, true, false );
7720
+
7721
+ $taxonomy_object = get_taxonomy( $taxonomy );
7722
+
7723
+ if ( is_object( $taxonomy_object ) && $taxonomy_object->hierarchical )
7724
+ $info[ 'object_hierarchical' ] = true;
7725
+
7726
+ $info[ 'where' ] = array(
7727
+ 'tt.taxonomy' => '`tt`.`' . $info[ 'field_type' ] . '` = "' . $taxonomy . '"'
7728
+ );
7729
+
7730
+ /*
7731
+ * @todo wpml-comp WPML API call for is_translated_taxononomy
7732
+ * @todo wpml-comp Check if WPML filters can be applied afterwards
7733
+ */
7734
+ // WPML Support
7735
+ if ( is_object( $sitepress ) && !empty( $current_language ) && $sitepress->is_translated_taxonomy( $taxonomy ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
7736
+ $info[ 'join' ][ 'wpml_translations' ] = "
7737
+ LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`
7738
+ ON `wpml_translations`.`element_id` = `tt`.`term_taxonomy_id`
7739
+ AND `wpml_translations`.`element_type` = 'tax_{$taxonomy}'
7740
+ AND `wpml_translations`.`language_code` = '{$current_language}'
7741
+ ";
7742
+
7743
+ $info[ 'join' ][ 'wpml_languages' ] = "
7744
+ LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`
7745
+ ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1
7746
+ ";
7747
+
7748
+ $info[ 'where' ][ 'wpml_languages' ] = "`wpml_languages`.`code` IS NOT NULL";
7749
+ }
7750
+ // Polylang support
7751
+ elseif ( ( function_exists( 'PLL' ) || is_object( $polylang ) ) && !empty( $current_language ) && !empty( $current_language_tl_tt_id ) && function_exists( 'pll_is_translated_taxonomy' ) && pll_is_translated_taxonomy( $taxonomy ) ) {
7752
+ $info[ 'join' ][ 'polylang_languages' ] = "
7753
+ LEFT JOIN `{$wpdb->term_relationships}` AS `polylang_languages`
7754
+ ON `polylang_languages`.`object_id` = `t`.`term_id`
7755
+ AND `polylang_languages`.`term_taxonomy_id` = {$current_language_tl_tt_id}
7756
+ ";
7757
+
7758
+ $info[ 'where' ][ 'polylang_languages' ] = "`polylang_languages`.`object_id` IS NOT NULL";
7759
+ }
7760
+
7761
+ $info[ 'object_fields' ] = $this->get_wp_object_fields( $object_type, $info[ 'pod' ] );
7762
+ }
7763
+ elseif ( 'user' == $object_type || 'user' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
7764
+ $info[ 'table' ] = $wpdb->users;
7765
+ $info[ 'meta_table' ] = $wpdb->usermeta;
7766
+ $info[ 'pod_table' ] = $wpdb->prefix . 'pods_user';
7767
+
7768
+ $info[ 'field_id' ] = 'ID';
7769
+ $info[ 'field_index' ] = 'display_name';
7770
+ $info[ 'field_slug' ] = 'user_nicename';
7771
+
7772
+ $info[ 'meta_field_id' ] = 'user_id';
7773
+ $info[ 'meta_field_index' ] = 'meta_key';
7774
+ $info[ 'meta_field_value' ] = 'meta_value';
7775
+
7776
+ $info[ 'where' ] = array(
7777
+ 'user_status' => '`t`.`user_status` = 0'
7778
+ );
7779
+
7780
+ $info[ 'object_fields' ] = $this->get_wp_object_fields( $object_type, $info[ 'pod' ] );
7781
+ }
7782
+ elseif ( 'comment' == $object_type || 'comment' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
7783
+ //$info[ 'object_hierarchical' ] = true;
7784
+
7785
+ $info[ 'table' ] = $wpdb->comments;
7786
+ $info[ 'meta_table' ] = $wpdb->commentmeta;
7787
+ $info[ 'pod_table' ] = $wpdb->prefix . 'pods_comment';
7788
+
7789
+ $info[ 'field_id' ] = 'comment_ID';
7790
+ $info[ 'field_index' ] = 'comment_date';
7791
+ $info[ 'field_type' ] = 'comment_type';
7792
+ $info[ 'field_parent' ] = 'comment_parent';
7793
+ $info[ 'field_parent_select' ] = '`t`.`' . $info[ 'field_parent' ] . '`';
7794
+
7795
+ $info[ 'meta_field_id' ] = 'comment_id';
7796
+ $info[ 'meta_field_index' ] = 'meta_key';
7797
+ $info[ 'meta_field_value' ] = 'meta_value';
7798
+
7799
+ $object = 'comment';
7800
+
7801
+ $comment_type = ( empty( $object ) ? $name : $object );
7802
+
7803
+ $comment_type_clause = '`t`.`' . $info[ 'field_type' ] . '` = "' . $comment_type . '"';
7804
+
7805
+ if ( 'comment' == $comment_type ) {
7806
+ $comment_type_clause = '( ' . $comment_type_clause . ' OR `t`.`' . $info[ 'field_type' ] . '` = "" )';
7807
+ }
7808
+
7809
+ $info[ 'where' ] = array(
7810
+ 'comment_approved' => '`t`.`comment_approved` = 1',
7811
+ 'comment_type' => $comment_type_clause
7812
+ );
7813
+
7814
+ $info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` DESC, `t`.`' . $info[ 'field_id' ] . '`';
7815
+ }
7816
+ elseif ( in_array( $object_type, array( 'option', 'settings' ) ) || 'settings' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
7817
+ $info[ 'table' ] = $wpdb->options;
7818
+ $info[ 'meta_table' ] = $wpdb->options;
7819
+
7820
+ $info[ 'field_id' ] = 'option_id';
7821
+ $info[ 'field_index' ] = 'option_name';
7822
+
7823
+ $info[ 'meta_field_id' ] = 'option_id';
7824
+ $info[ 'meta_field_index' ] = 'option_name';
7825
+ $info[ 'meta_field_value' ] = 'option_value';
7826
+
7827
+ $info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` ASC';
7828
+ }
7829
+ elseif ( is_multisite() && ( in_array( $object_type, array( 'site_option', 'site_settings' ) ) || 'site_settings' == pods_var_raw( 'type', $info[ 'pod' ] ) ) ) {
7830
+ $info[ 'table' ] = $wpdb->sitemeta;
7831
+ $info[ 'meta_table' ] = $wpdb->sitemeta;
7832
+
7833
+ $info[ 'field_id' ] = 'site_id';
7834
+ $info[ 'field_index' ] = 'meta_key';
7835
+
7836
+ $info[ 'meta_field_id' ] = 'site_id';
7837
+ $info[ 'meta_field_index' ] = 'meta_key';
7838
+ $info[ 'meta_field_value' ] = 'meta_value';
7839
+
7840
+ $info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` ASC';
7841
+ }
7842
+ elseif ( is_multisite() && 'network' == $object_type ) { // Network = Site
7843
+ $info[ 'table' ] = $wpdb->site;
7844
+ $info[ 'meta_table' ] = $wpdb->sitemeta;
7845
+
7846
+ $info[ 'field_id' ] = 'id';
7847
+ $info[ 'field_index' ] = 'domain';
7848
+
7849
+ $info[ 'meta_field_id' ] = 'site_id';
7850
+ $info[ 'meta_field_index' ] = 'meta_key';
7851
+ $info[ 'meta_field_value' ] = 'meta_value';
7852
+
7853
+ $info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` ASC, `t`.`path` ASC, `t`.`' . $info[ 'field_id' ] . '`';
7854
+ }
7855
+ elseif ( is_multisite() && 'site' == $object_type ) { // Site = Blog
7856
+ $info[ 'table' ] = $wpdb->blogs;
7857
+
7858
+ $info[ 'field_id' ] = 'blog_id';
7859
+ $info[ 'field_index' ] = 'domain';
7860
+ $info[ 'field_type' ] = 'site_id';
7861
+
7862
+ $info[ 'where' ] = array(
7863
+ 'archived' => '`t`.`archived` = 0',
7864
+ 'spam' => '`t`.`spam` = 0',
7865
+ 'deleted' => '`t`.`deleted` = 0',
7866
+ 'site_id' => '`t`.`' . $info[ 'field_type' ] . '` = ' . (int) get_current_site()->id
7867
+ );
7868
+
7869
+ $info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` ASC, `t`.`path` ASC, `t`.`' . $info[ 'field_id' ] . '`';
7870
+ }
7871
+ elseif ( 'table' == $object_type || 'table' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
7872
+ $info[ 'table' ] = ( empty( $object ) ? $name : $object );
7873
+ $info[ 'pod_table' ] = $wpdb->prefix . 'pods_' . $info[ 'table' ];
7874
+
7875
+ if ( !empty( $field ) && is_array( $field ) ) {
7876
+ $info[ 'table' ] = pods_var_raw( 'pick_table', pods_var_raw( 'options', $field, $field ) );
7877
+ $info[ 'field_id' ] = pods_var_raw( 'pick_table_id', pods_var_raw( 'options', $field, $field ) );
7878
+ $info[ 'field_index' ] = $info[ 'meta_field_index' ] = $info[ 'meta_field_value' ] = pods_var_raw( 'pick_table_index', pods_var_raw( 'options', $field, $field ) );
7879
+ }
7880
+ }
7881
+
7882
+ $info[ 'table' ] = pods_clean_name( $info[ 'table' ], false, false );
7883
+ $info[ 'meta_table' ] = pods_clean_name( $info[ 'meta_table' ], false, false );
7884
+ $info[ 'pod_table' ] = pods_clean_name( $info[ 'pod_table' ], false, false );
7885
+
7886
+ $info[ 'field_id' ] = pods_clean_name( $info[ 'field_id' ], false, false );
7887
+ $info[ 'field_index' ] = pods_clean_name( $info[ 'field_index' ], false, false );
7888
+ $info[ 'field_slug' ] = pods_clean_name( $info[ 'field_slug' ], false, false );
7889
+
7890
+ $info[ 'meta_field_id' ] = pods_clean_name( $info[ 'meta_field_id' ], false, false );
7891
+ $info[ 'meta_field_index' ] = pods_clean_name( $info[ 'meta_field_index' ], false, false );
7892
+ $info[ 'meta_field_value' ] = pods_clean_name( $info[ 'meta_field_value' ], false, false );
7893
+
7894
+ if ( empty( $info[ 'orderby' ] ) )
7895
+ $info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '`, `t`.`' . $info[ 'field_id' ] . '`';
7896
+
7897
+ if ( 'table' == pods_var_raw( 'storage', $info[ 'pod' ] ) && !in_array( $object_type, array( 'pod', 'table' ) ) ) {
7898
+ $info[ 'join' ][ 'd' ] = 'LEFT JOIN `' . $info[ 'pod_table' ] . '` AS `d` ON `d`.`id` = `t`.`' . $info[ 'field_id' ] . '`';
7899
+ //$info[ 'select' ] .= ', `d`.*';
7900
+ }
7901
+
7902
+ if ( !empty( $info[ 'pod' ] ) && is_array( $info[ 'pod' ] ) )
7903
+ $info[ 'recurse' ] = true;
7904
+
7905
+ $info[ 'type' ] = $object_type;
7906
+ $info[ 'object_name' ] = $object;
7907
+
7908
+ if ( pods_api_cache() ) {
7909
+ if ( ! did_action( 'init' ) ) {
7910
+ $transient .= '_pre_init';
7911
+ }
7912
+ pods_transient_set( $transient, $info );
7913
+ }
7914
+
7915
+
7916
+ self::$table_info_cache[ $transient ] = apply_filters( 'pods_api_get_table_info', $info, $object_type, $object, $name, $pod, $field, $this );
7917
+
7918
+ return self::$table_info_cache[ $transient ];
7919
+ }
7920
+
7921
+ /**
7922
+ * Export a package
7923
+ *
7924
+ * $params['pod'] string Pod Type IDs to export
7925
+ * $params['template'] string Template IDs to export
7926
+ * $params['podpage'] string Pod Page IDs to export
7927
+ * $params['helper'] string Helper IDs to export
7928
+ *
7929
+ * @param array $params An associative array of parameters
7930
+ *
7931
+ * @return array|bool
7932
+ *
7933
+ * @since 1.9.0
7934
+ * @deprecated 2.0
7935
+ */
7936
+ public function export_package ( $params ) {
7937
+ if ( class_exists( 'Pods_Migrate_Packages' ) )
7938
+ return Pods_Migrate_Packages::export( $params );
7939
+
7940
+ return false;
7941
+ }
7942
+
7943
+ /**
7944
+ * Replace an existing package
7945
+ *
7946
+ * @param mixed $data (optional) An associative array containing a package, or the json encoded package
7947
+ *
7948
+ * @return bool
7949
+ *
7950
+ * @since 1.9.8
7951
+ * @deprecated 2.0
7952
+ */
7953
+ public function replace_package ( $data = false ) {
7954
+ return $this->import_package( $data, true );
7955
+ }
7956
+
7957
+ /**
7958
+ * Import a package
7959
+ *
7960
+ * @param mixed $data (optional) An associative array containing a package, or the json encoded package
7961
+ * @param bool $replace (optional) Replace existing items when found
7962
+ *
7963
+ * @return bool
7964
+ *
7965
+ * @since 1.9.0
7966
+ * @deprecated 2.0
7967
+ */
7968
+ public function import_package ( $data = false, $replace = false ) {
7969
+ if ( class_exists( 'Pods_Migrate_Packages' ) )
7970
+ return Pods_Migrate_Packages::import( $data, $replace );
7971
+
7972
+ return false;
7973
+ }
7974
+
7975
+ /**
7976
+ * Validate a package
7977
+ *
7978
+ * @param array|string $data (optional) An associative array containing a package, or the json encoded package
7979
+ * @param bool $output (optional)
7980
+ *
7981
+ * @return array|bool
7982
+ *
7983
+ * @since 1.9.0
7984
+ * @deprecated 2.0
7985
+ */
7986
+ public function validate_package ( $data = false, $output = false ) {
7987
+ return true;
7988
+ }
7989
+
7990
+ /**
7991
+ * Import data from an array or a CSV file.
7992
+ *
7993
+ * @param mixed $import_data PHP associative array or CSV input
7994
+ * @param bool $numeric_mode Use IDs instead of the name field when matching
7995
+ * @param string $format Format of import data, options are php or csv
7996
+ *
7997
+ * @return array IDs of imported items
7998
+ *
7999
+ * @since 1.7.1
8000
+ * @todo This needs some love and use of table_info etc for relationships
8001
+ */
8002
+ public function import ( $import_data, $numeric_mode = false, $format = null ) {
8003
+ /**
8004
+ * @var $wpdb wpdb
8005
+ */
8006
+ global $wpdb;
8007
+
8008
+ if ( null === $format && null !== $this->format )
8009
+ $format = $this->format;
8010
+
8011
+ if ( 'csv' == $format && !is_array( $import_data ) ) {
8012
+ $data = pods_migrate( 'sv', ',' )->parse( $import_data );
8013
+
8014
+ $import_data = $data[ 'items' ];
8015
+ }
8016
+
8017
+ pods_query( "SET NAMES utf8" );
8018
+ pods_query( "SET CHARACTER SET utf8" );
8019
+
8020
+ // Loop through the array of items
8021
+ $ids = array();
8022
+
8023
+ // Test to see if it's an array of arrays
8024
+ if ( !is_array( @current( $import_data ) ) )
8025
+ $import_data = array( $import_data );
8026
+
8027
+ $pod = $this->load_pod( array( 'name' => $this->pod ) );
8028
+
8029
+ if ( false === $pod )
8030
+ return pods_error( __( 'Pod not found', 'pods' ), $this );
8031
+
8032
+ $fields = array_merge( $pod[ 'fields' ], $pod[ 'object_fields' ] );
8033
+
8034
+ $simple_tableless_objects = PodsForm::simple_tableless_objects();
8035
+
8036
+ foreach ( $import_data as $key => $data_row ) {
8037
+ $data = array();
8038
+
8039
+ // Loop through each field (use $fields so only valid fields get parsed)
8040
+ foreach ( $fields as $field_name => $field_data ) {
8041
+ if ( !isset( $data_row[ $field_name ] ) && !isset( $data_row[ $field_data[ 'label' ] ] ) )
8042
+ continue;
8043
+
8044
+ $field_id = $field_data[ 'id' ];
8045
+ $type = $field_data[ 'type' ];
8046
+ $pick_object = isset( $field_data[ 'pick_object' ] ) ? $field_data[ 'pick_object' ] : '';
8047
+ $pick_val = isset( $field_data[ 'pick_val' ] ) ? $field_data[ 'pick_val' ] : '';
8048
+
8049
+ if ( isset( $data_row[ $field_name] ) )
8050
+ $field_value = $data_row[ $field_name ];
8051
+ else
8052
+ $field_value = $data_row[ $field_data[ 'label' ] ];
8053
+
8054
+ if ( null !== $field_value && false !== $field_value && '' !== $field_value ) {
8055
+ if ( 'pick' == $type || in_array( $type, PodsForm::file_field_types() ) ) {
8056
+ $field_values = is_array( $field_value ) ? $field_value : array( $field_value );
8057
+ $pick_values = array();
8058
+
8059
+ foreach ( $field_values as $pick_value ) {
8060
+ if ( in_array( $type, PodsForm::file_field_types() ) || 'media' == $pick_object ) {
8061
+ $where = "`guid` = '" . pods_sanitize( $pick_value ) . "'";
8062
+
8063
+ if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
8064
+ $where = "`ID` = " . pods_absint( $pick_value );
8065
+
8066
+ $result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = 'attachment' AND {$where} ORDER BY `ID`", $this );
8067
+
8068
+ if ( !empty( $result ) )
8069
+ $pick_values[] = $result[ 0 ]->id;
8070
+ }
8071
+ // @todo This could and should be abstracted better and simplified
8072
+ elseif ( 'pick' == $type ) {
8073
+ $related_pod = false;
8074
+
8075
+ if ( 'pod' == $pick_object )
8076
+ $related_pod = $this->load_pod( array( 'name' => $pick_val, 'table_info' => true ), false );
8077
+
8078
+ if ( empty( $related_pod ) ) {
8079
+ $related_pod = array(
8080
+ 'id' => 0,
8081
+ 'type' => $pick_object
8082
+ );
8083
+ }
8084
+
8085
+ if ( in_array( 'taxonomy', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
8086
+ $where = "`t`.`name` = '" . pods_sanitize( $pick_value ) . "'";
8087
+
8088
+ if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
8089
+ $where = "`tt`.`term_id` = " . pods_absint( $pick_value );
8090
+
8091
+ $result = pods_query( "SELECT `t`.`term_id` AS `id` FROM `{$wpdb->term_taxonomy}` AS `tt` LEFT JOIN `{$wpdb->terms}` AS `t` ON `t`.`term_id` = `tt`.`term_id` WHERE `taxonomy` = '{$pick_val}' AND {$where} ORDER BY `t`.`term_id`", $this );
8092
+
8093
+ if ( !empty( $result ) )
8094
+ $pick_values[] = $result[ 0 ]->id;
8095
+ }
8096
+ elseif ( in_array( 'post_type', array( $pick_object, $related_pod[ 'type' ] ) ) || in_array( 'media', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
8097
+ $where = "`post_title` = '" . pods_sanitize( $pick_value ) . "'";
8098
+
8099
+ if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
8100
+ $where = "`ID` = " . pods_absint( $pick_value );
8101
+
8102
+ $result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = '{$pick_val}' AND {$where} ORDER BY `ID`", $this );
8103
+
8104
+ if ( !empty( $result ) )
8105
+ $pick_values[] = $result[ 0 ]->id;
8106
+ }
8107
+ elseif ( in_array( 'user', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
8108
+ $where = "`user_login` = '" . pods_sanitize( $pick_value ) . "'";
8109
+
8110
+ if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
8111
+ $where = "`ID` = " . pods_absint( $pick_value );
8112
+
8113
+ $result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->users}` WHERE {$where} ORDER BY `ID`", $this );
8114
+
8115
+ if ( !empty( $result ) )
8116
+ $pick_values[] = $result[ 0 ]->id;
8117
+ }
8118
+ elseif ( in_array( 'comment', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
8119
+ $where = "`comment_ID` = " . pods_absint( $pick_value );
8120
+
8121
+ $result = pods_query( "SELECT `comment_ID` AS `id` FROM `{$wpdb->comments}` WHERE {$where} ORDER BY `ID`", $this );
8122
+
8123
+ if ( !empty( $result ) )
8124
+ $pick_values[] = $result[ 0 ]->id;
8125
+ }
8126
+ elseif ( in_array( $pick_object, $simple_tableless_objects ) )
8127
+ $pick_values[] = $pick_value;
8128
+ elseif ( !empty( $related_pod[ 'id' ] ) ) {
8129
+ $where = "`" . $related_pod[ 'field_index' ] . "` = '" . pods_sanitize( $pick_value ) . "'";
8130
+
8131
+ if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
8132
+ $where = "`" . $related_pod[ 'field_id' ] . "` = " . pods_absint( $pick_value );
8133
+
8134
+ $result = pods_query( "SELECT `" . $related_pod[ 'field_id' ] . "` AS `id` FROM `" . $related_pod[ 'table' ] . "` WHERE {$where} ORDER BY `" . $related_pod[ 'field_id' ] . "`", $this );
8135
+
8136
+ if ( !empty( $result ) )
8137
+ $pick_values[] = $result[ 0 ]->id;
8138
+ }
8139
+ }
8140
+ }
8141
+
8142
+ $field_value = implode( ',', $pick_values );
8143
+ }
8144
+
8145
+ $data[ $field_name ] = $field_value;
8146
+ }
8147
+ }
8148
+
8149
+ if ( !empty( $data ) ) {
8150
+ $params = array(
8151
+ 'pod' => $this->pod,
8152
+ 'data' => $data
8153
+ );
8154
+
8155
+ $ids[] = $this->save_pod_item( $params );
8156
+ }
8157
+ }
8158
+
8159
+ return $ids;
8160
+ }
8161
+
8162
+ /**
8163
+ * Export data from a Pod
8164
+ *
8165
+ * @param string|object $pod The pod name or Pods object
8166
+ * @param array $params An associative array of parameters
8167
+ *
8168
+ * @return array Data arrays of all exported pod items
8169
+ * @since 1.7.1
8170
+ */
8171
+ public function export ( $pod = null, $params = null ) {
8172
+
8173
+ if ( empty( $pod ) ) {
8174
+ $pod = $this->pod;
8175
+ }
8176
+
8177
+ $find = array(
8178
+ 'limit' => -1,
8179
+ 'search' => false,
8180
+ 'pagination' => false
8181
+ );
8182
+
8183
+ if ( !empty( $params ) && isset( $params[ 'params' ] ) ) {
8184
+ $find = array_merge( $find, (array) $params[ 'params' ] );
8185
+
8186
+ unset( $params[ 'params' ] );
8187
+
8188
+ $pod = pods( $pod, $find );
8189
+ }
8190
+ elseif ( !is_object( $pod ) ) {
8191
+ $pod = pods( $pod, $find );
8192
+ }
8193
+
8194
+ $data = array();
8195
+
8196
+ while ( $pod->fetch() ) {
8197
+ $data[ $pod->id() ] = $this->export_pod_item( $params, $pod );
8198
+ }
8199
+
8200
+ $data = $this->do_hook( 'export', $data, $pod->pod, $pod );
8201
+
8202
+ return $data;
8203
+ }
8204
+
8205
+ /**
8206
+ * Convert CSV to a PHP array
8207
+ *
8208
+ * @param string $data The CSV input
8209
+ *
8210
+ * @return array
8211
+ * @since 1.7.1
8212
+ *
8213
+ * @deprecated 2.3.5
8214
+ */
8215
+ public function csv_to_php ( $data, $delimiter = ',' ) {
8216
+ pods_deprecated( "PodsAPI->csv_to_php", '2.3.5' );
8217
+
8218
+ $data = pods_migrate( 'sv', $delimiter, $data )->parse();
8219
+
8220
+ return $data[ 'items' ];
8221
+ }
8222
+
8223
+ /**
8224
+ * Clear Pod-related cache
8225
+ *
8226
+ * @param array $pod
8227
+ *
8228
+ * @return void
8229
+ *
8230
+ * @since 2.0
8231
+ */
8232
+ public function cache_flush_pods ( $pod = null ) {
8233
+ /**
8234
+ * @var $wpdb wpdb
8235
+ */
8236
+ global $wpdb;
8237
+
8238
+ pods_transient_clear( 'pods' );
8239
+ pods_transient_clear( 'pods_components' );
8240
+
8241
+ if ( null !== $pod && is_array( $pod ) ) {
8242
+ pods_transient_clear( 'pods_pod_' . $pod[ 'name' ] );
8243
+ pods_cache_clear( $pod[ 'name' ], 'pods-class' );
8244
+
8245
+ foreach ( $pod[ 'fields' ] as $field ) {
8246
+ pods_transient_clear( 'pods_field_' . $pod[ 'name' ] . '_' . $field[ 'name' ] );
8247
+ }
8248
+
8249
+ if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) )
8250
+ pods_transient_clear( 'pods_wp_cpt_ct' );
8251
+ }
8252
+ else
8253
+ pods_transient_clear( 'pods_wp_cpt_ct' );
8254
+
8255
+ // Delete transients in the database
8256
+ $wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_pods%'" );
8257
+ $wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_timeout_pods%'" );
8258
+
8259
+ // Delete Pods Options Cache in the database
8260
+ $wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_pods_option_%'" );
8261
+
8262
+ pods_cache_clear( true );
8263
+
8264
+ pods_transient_set( 'pods_flush_rewrites', 1 );
8265
+
8266
+ do_action( 'pods_cache_flushed' );
8267
+ }
8268
+
8269
+ /**
8270
+ * Process a Pod-based form
8271
+ *
8272
+ * @param mixed $params
8273
+ * @param object $obj Pod object
8274
+ * @param array $fields Fields being submitted in form ( key => settings )
8275
+ * @param string $thank_you URL to send to upon success
8276
+ *
8277
+ * @return mixed
8278
+ *
8279
+ * @since 2.0
8280
+ */
8281
+ public function process_form ( $params, $obj = null, $fields = null, $thank_you = null ) {
8282
+ $this->display_errors = false;
8283
+
8284
+ $form = null;
8285
+
8286
+ $nonce = pods_var( '_pods_nonce', $params );
8287
+ $pod = pods_var( '_pods_pod', $params );
8288
+ $id = pods_var( '_pods_id', $params );
8289
+ $uri = pods_var( '_pods_uri', $params );
8290
+ $form = pods_var( '_pods_form', $params );
8291
+ $location = pods_var( '_pods_location', $params );
8292
+
8293
+ if ( is_object( $obj ) ) {
8294
+ $pod = $obj->pod;
8295
+ $id = $obj->id();
8296
+ }
8297
+
8298
+ if ( ! empty( $fields ) ) {
8299
+ $fields = array_keys( $fields );
8300
+ $form = implode( ',', $fields );
8301
+ }
8302
+ else
8303
+ $fields = explode( ',', $form );
8304
+
8305
+ if ( empty( $nonce ) || empty( $pod ) || empty( $uri ) || empty( $fields ) )
8306
+ return pods_error( __( 'Invalid submission', 'pods' ), $this );
8307
+
8308
+ $uid = @session_id();
8309
+
8310
+ if ( is_user_logged_in() )
8311
+ $uid = 'user_' . get_current_user_id();
8312
 
8313
  $field_hash = wp_create_nonce( 'pods_fields_' . $form );
8314
 
8315
+ $action = 'pods_form_' . $pod . '_' . $uid . '_' . $id . '_' . $uri . '_' . $field_hash;
8316
 
8317
+ if ( empty( $uid ) )
8318
+ return pods_error( __( 'Access denied for your session, please refresh and try again.', 'pods' ), $this );
 
8319
 
8320
+ if ( false === wp_verify_nonce( $nonce, $action ) )
8321
+ return pods_error( __( 'Access denied, please refresh and try again.', 'pods' ), $this );
 
8322
 
8323
+ $data = array();
8324
 
8325
+ foreach ( $fields as $field ) {
8326
+ $data[ $field ] = pods_var_raw( 'pods_field_' . $field, $params, '' );
8327
+ }
8328
 
8329
+ $params = array(
8330
+ 'pod' => $pod,
8331
+ 'id' => $id,
8332
+ 'data' => $data,
8333
+ 'from' => 'process_form',
8334
  'location' => $location
8335
+ );
 
 
8336
 
8337
+ $id = $this->save_pod_item( $params );
 
 
 
 
 
 
 
8338
 
8339
+ // Always return $id for AJAX requests.
8340
+ if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
8341
+ if ( 0 < $id && ! empty( $thank_you ) ) {
8342
+ $thank_you = str_replace( 'X_ID_X', $id, $thank_you );
8343
 
8344
+ pods_redirect( $thank_you );
 
8345
  }
 
 
8346
  }
8347
 
8348
+ return $id;
8349
+ }
8350
+
8351
  /**
8352
+ * Get current language information from Multilingual plugins
8353
+ *
8354
+ * @since 2.6.6
8355
  *
8356
+ * @return array
8357
  */
8358
+ public static function get_current_language() {
8359
 
8360
+ /**
8361
+ * @var $sitepress SitePress object
8362
+ * @var $polylang object
8363
+ */
8364
+ /*
8365
+ * @todo wpml-comp Remove global object usage
8366
+ */
8367
+ global $sitepress, $polylang;
8368
 
8369
+ $lang_data = false;
8370
+ $translator = false;
8371
+ $current_language = false;
8372
 
8373
+ // Multilingual support
8374
+ if ( did_action( 'wpml_loaded' ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
8375
+ // WPML support
8376
+ $translator = 'WPML';
8377
+
8378
+ // Get the global current language (if set)
8379
+ $wpml_language = apply_filters( 'wpml_current_language', null );
8380
+ $current_language = ( $wpml_language != 'all' ) ? $wpml_language : '';
8381
 
8382
+ } elseif ( ( function_exists( 'PLL' ) || is_object( $polylang ) ) && function_exists( 'pll_current_language' ) ) {
8383
+ // Polylang support
8384
+ $translator = 'PLL';
8385
 
8386
+ // Get the global current language (if set)
8387
+ $current_language = pll_current_language( 'slug' );
 
8388
  }
8389
 
8390
+ /**
8391
+ * Admin functions that overwrite the current language
8392
+ *
8393
+ * @since 2.6.6
8394
+ */
8395
+ if ( is_admin() && ! empty( $translator ) ) {
8396
+ if ( $translator == 'PLL' ) {
8397
+ /**
8398
+ * Polylang support
8399
+ * Get the current user's perferred language.
8400
+ * This is a user meta setting that will overwrite the language returned from pll_current_language()
8401
+ * @see polylang/admin/admin-base.php -> init_user()
8402
+ */
8403
+ $current_language = get_user_meta( get_current_user_id(), 'pll_filter_content', true );
8404
+ }
8405
 
8406
+ // Get current language based on the object language if available
8407
+ if ( function_exists( 'get_current_screen' ) ) {
8408
+ $current_screen = get_current_screen();
8409
 
8410
+ /**
8411
+ * Overwrite the current language if needed for post types
8412
+ */
8413
+ if ( isset( $current_screen->base ) && ( $current_screen->base == 'post' || $current_screen->base == 'edit' ) ) {
8414
+ if ( ! empty( $_GET['post'] ) ) {
8415
+ /**
8416
+ * WPML support
8417
+ * In WPML the current language is always set to default on an edit screen
8418
+ * We need to overwrite this when the current object is not-translatable to enable relationships with different languages
8419
+ */
8420
+ if ( $translator == 'WPML'
8421
+ && ! apply_filters( 'wpml_is_translated_post_type', false, ( get_post_type( $_GET['post'] ) ) )
8422
+ ) {
8423
+ // Overwrite the current language to nothing if this is a NOT-translatable post_type
8424
+ $current_language = '';
8425
+ }
8426
 
8427
+ /**
8428
+ * Polylang support (1.5.4+)
8429
+ * In polylang the preferred language could be anything.
8430
+ * We only want the related objects if they are not translatable OR the same language as the current object
8431
+ */
8432
+ if ( $translator == 'PLL'
8433
+ && function_exists( 'pll_get_post_language' )
8434
+ && pll_is_translated_post_type( get_post_type( $_GET['post'] ) )
8435
+ ) {
8436
+ // Overwrite the current language if this is a translateable post_type
8437
+ $current_language = pll_get_post_language( (int) $_GET['post'] );
8438
+ }
8439
+ }
8440
 
8441
+ /**
8442
+ * Polylang support (1.0.1+)
8443
+ * In polylang the preferred language could be anything.
8444
+ * When we're adding a new object and language is set we only want the related objects if they are not translatable OR the same language
8445
+ */
8446
+ if ( $translator == 'PLL'
8447
+ && ! empty( $_GET['new_lang'] )
8448
+ && ! empty( $_GET['post_type'] )
8449
+ && pll_is_translated_post_type( sanitize_text_field( $_GET['post_type'] ) )
8450
+ ) {
8451
+ $current_language = $_GET['new_lang'];
8452
+ }
8453
+
8454
+ /**
8455
+ * Overwrite the current language if needed for taxonomies
8456
+ */
8457
+ } elseif ( isset( $current_screen->base ) && ( $current_screen->base == 'term' || $current_screen->base == 'edit-tags' ) ) {
8458
+ // @todo MAYBE: Similar function like get_post_type for taxonomies so we don't need to check for $_GET['taxonomy']
8459
+ if ( ! empty( $_GET['taxonomy'] ) ) {
8460
+ /*
8461
+ * @todo wpml-comp API call for taxonomy needed!
8462
+ * Suggested API call:
8463
+ * add_filter( 'wpml_is_translated_taxonomy', $_GET['taxonomy'], 10, 2 );
8464
+ */
8465
+ /**
8466
+ * WPML support
8467
+ * In WPML the current language is always set to default on an edit screen
8468
+ * We need to overwrite this when the current object is not-translatable to enable relationships with different languages
8469
+ */
8470
+ if ( $translator == 'WPML'
8471
+ && method_exists( $sitepress, 'is_translated_taxonomy')
8472
+ && ! $sitepress->is_translated_taxonomy( $_GET['taxonomy'] )
8473
+ ) {
8474
+ // Overwrite the current language to nothing if this is a NOT-translatable taxonomy
8475
+ $current_language = '';
8476
+ }
8477
 
8478
+ /**
8479
+ * Polylang support (1.5.4+)
8480
+ * In polylang the preferred language could be anything.
8481
+ * We only want the related objects if they are not translatable OR the same language as the current object
8482
+ */
8483
+ if ( $translator == 'PLL'
8484
+ && ! empty( $_GET['tag_ID'] )
8485
+ && function_exists( 'pll_get_term_language' )
8486
+ && pll_is_translated_taxonomy( sanitize_text_field( $_GET['taxonomy'] ) )
8487
+ ) {
8488
+ // Overwrite the current language if this is a translatable taxonomy
8489
+ $current_language = pll_get_term_language( (int) $_GET['tag_ID'] );
8490
+ }
8491
+ }
8492
 
8493
+ /**
8494
+ * Polylang support (1.0.1+)
8495
+ * In polylang the preferred language could be anything.
8496
+ * When we're adding a new object and language is set we only want the related objects if they are not translatable OR the same language
8497
+ */
8498
+ if ( $translator == 'PLL'
8499
+ && ! empty( $_GET['new_lang'] )
8500
+ && ! empty( $_GET['taxonomy'] )
8501
+ && pll_is_translated_taxonomy( sanitize_text_field( $_GET['taxonomy'] ) )
8502
+ ) {
8503
+ $current_language = $_GET['new_lang'];
8504
+ }
8505
+ }
8506
+ }
8507
  }
8508
 
8509
+ $current_language = pods_sanitize( sanitize_text_field( $current_language ) );
8510
+
8511
+ if ( ! empty( $current_language ) ) {
8512
+ // We need to return language data
8513
+ $lang_data = array(
8514
+ 'language' => $current_language,
8515
+ 't_id' => 0,
8516
+ 'tt_id' => 0,
8517
+ 'term' => null,
8518
+ );
8519
+
8520
+ /**
8521
+ * Polylang support
8522
+ * Get the language taxonomy object for the current language
8523
+ */
8524
+ if ( $translator == 'PLL' ) {
8525
+ $current_language_t = false;
8526
+
8527
+ // Get the language term object
8528
+ if ( function_exists( 'PLL' ) && isset( PLL()->model ) && method_exists( PLL()->model, 'get_language' ) ) {
8529
+ // Polylang 1.8 and newer
8530
+ $current_language_t = PLL()->model->get_language( $current_language );
8531
+ } elseif ( is_object( $polylang ) && isset( $polylang->model ) && method_exists( $polylang->model, 'get_language' ) ) {
8532
+ // Polylang 1.2 - 1.7.x
8533
+ $current_language_t = $polylang->model->get_language( $current_language );
8534
+ } elseif ( is_object( $polylang ) && method_exists( $polylang, 'get_language' ) ) {
8535
+ // Polylang 1.1.x and older
8536
+ $current_language_t = $polylang->get_language( $current_language );
8537
+ }
8538
+
8539
+ // If the language object exists, add it!
8540
+ if ( $current_language_t && ! empty( $current_language_t->term_id ) ) {
8541
+ $lang_data['t_id'] = (int) $current_language_t->term_id;
8542
+ $lang_data['tt_id'] = (int) $current_language_t->term_taxonomy_id;
8543
+ $lang_data['tl_t_id'] = (int) $current_language_t->tl_term_id;
8544
+ $lang_data['tl_tt_id'] = (int) $current_language_t->tl_term_taxonomy_id;
8545
+ $lang_data['term'] = $current_language_t;
8546
+ }
8547
+ }
8548
  }
8549
+
8550
+ /**
8551
+ * Override language data used by Pods.
8552
+ *
8553
+ * @since 2.6.6
8554
+ *
8555
+ * @param array|false $lang_data {
8556
+ * Language data
8557
+ *
8558
+ * @type string $language Language slug
8559
+ * @type int $t_id Language term_id
8560
+ * @type int $tt_id Language term_taxonomy_id
8561
+ * @type WP_Term $term Language term object
8562
+ * }
8563
+ * @param string|boolean $translator Language plugin used
8564
+ */
8565
+ $lang_data = apply_filters( 'pods_get_current_language', $lang_data, $translator );
8566
+
8567
+ return $lang_data;
8568
+
8569
  }
8570
 
8571
+ /**
8572
+ * Handle filters / actions for the class
8573
+ *
8574
+ * @since 2.0
8575
+ */
8576
+ private function do_hook () {
8577
+ $args = func_get_args();
8578
+ if ( empty( $args ) )
8579
+ return false;
8580
+ $name = array_shift( $args );
8581
+ return pods_do_hook( "api", $name, $args, $this );
8582
+ }
8583
+
8584
+ /**
8585
+ * Handle variables that have been deprecated
8586
+ *
8587
+ * @since 2.0
8588
+ */
8589
+ public function __get ( $name ) {
8590
+ $name = (string) $name;
8591
+
8592
+ if ( !isset( $this->deprecated ) ) {
8593
+ require_once( PODS_DIR . 'deprecated/classes/PodsAPI.php' );
8594
+ $this->deprecated = new PodsAPI_Deprecated( $this );
8595
+ }
8596
+
8597
+ $var = null;
8598
+
8599
+ if ( isset( $this->deprecated->{$name} ) ) {
8600
+ pods_deprecated( "PodsAPI->{$name}", '2.0' );
8601
+
8602
+ $var = $this->deprecated->{$name};
8603
+ }
8604
+ else
8605
+ pods_deprecated( "PodsAPI->{$name}", '2.0' );
8606
+
8607
+ return $var;
8608
+ }
8609
+
8610
+ /**
8611
+ * Handle methods that have been deprecated
8612
+ *
8613
+ * @since 2.0
8614
+ */
8615
+ public function __call ( $name, $args ) {
8616
+ $name = (string) $name;
8617
+
8618
+ if ( !isset( $this->deprecated ) ) {
8619
+ require_once( PODS_DIR . 'deprecated/classes/PodsAPI.php' );
8620
+ $this->deprecated = new PodsAPI_Deprecated( $this );
8621
+ }
8622
+
8623
+ if ( method_exists( $this->deprecated, $name ) )
8624
+ return call_user_func_array( array( $this->deprecated, $name ), $args );
8625
+ else
8626
+ pods_deprecated( "PodsAPI::{$name}", '2.0' );
8627
+ }
8628
+
8629
  /**
8630
  * Filter an array of arrays without causing PHP notices/warnings.
8631
  *
8639
 
8640
  $values = (array) $values;
8641
 
8642
+ foreach ( $values as $k => $v ){
8643
  if ( is_object( $v ) ) {
8644
  // Skip objects
8645
  continue;
8646
+ } elseif ( is_array( $v ) ){
8647
  if ( empty( $v ) ) {
8648
  // Filter values with empty arrays
8649
  unset( $values[ $k ] );
classes/PodsAdmin.php CHANGED
@@ -1,3885 +1,2843 @@
1
  <?php
2
-
3
  /**
4
  * @package Pods
5
  */
6
  class PodsAdmin {
7
 
8
- /**
9
- * @var PodsAdmin
10
- */
11
- public static $instance = null;
12
-
13
- /**
14
- * Singleton handling for a basic pods_admin() request
15
- *
16
- * @return \PodsAdmin
17
- *
18
- * @since 2.3.5
19
- */
20
- public static function init() {
21
-
22
- if ( ! is_object( self::$instance ) ) {
23
- self::$instance = new PodsAdmin();
24
- }
25
-
26
- return self::$instance;
27
- }
28
-
29
- /**
30
- * Setup and Handle Admin functionality
31
- *
32
- * @return \PodsAdmin
33
- *
34
- * @license http://www.gnu.org/licenses/gpl-2.0.html
35
- * @since 2.0.0
36
- */
37
- public function __construct() {
38
-
39
- // Scripts / Stylesheets
40
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_head' ), 20 );
41
-
42
- // AJAX $_POST fix
43
- add_action( 'admin_init', array( $this, 'admin_init' ), 9 );
44
-
45
- // Menus
46
- add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
47
-
48
- // AJAX for Admin
49
- add_action( 'wp_ajax_pods_admin', array( $this, 'admin_ajax' ) );
50
- add_action( 'wp_ajax_nopriv_pods_admin', array( $this, 'admin_ajax' ) );
51
-
52
- // Add Media Bar button for Shortcode
53
- add_action( 'media_buttons', array( $this, 'media_button' ), 12 );
54
-
55
- // Add the Pods capabilities
56
- add_filter( 'members_get_capabilities', array( $this, 'admin_capabilities' ) );
57
-
58
- add_action( 'admin_head-media-upload-popup', array( $this, 'register_media_assets' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
- // Add our debug to Site Info.
61
- add_filter( 'debug_information', array( $this, 'add_debug_information' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
- $this->rest_admin();
 
64
 
65
- }
66
-
67
- /**
68
- * Init the admin area
69
- *
70
- * @since 2.0.0
71
- */
72
- public function admin_init() {
73
-
74
- // Fix for plugins that *don't do it right* so we don't cause issues for users
75
- // @codingStandardsIgnoreLine
76
- if ( defined( 'DOING_AJAX' ) && ! empty( $_POST ) ) {
77
- $pods_admin_ajax_actions = array(
78
- 'pods_admin',
79
- 'pods_relationship',
80
- 'pods_upload',
81
- 'pods_admin_components',
82
- );
83
 
84
- /**
85
- * Admin AJAX Callbacks
86
- *
87
- * @since unknown
88
- *
89
- * @param array $pods_admin_ajax_actions Array of actions to handle.
90
- */
91
- $pods_admin_ajax_actions = apply_filters( 'pods_admin_ajax_actions', $pods_admin_ajax_actions );
92
-
93
- if ( in_array( pods_v( 'action' ), $pods_admin_ajax_actions, true ) || in_array( pods_v( 'action', 'post' ), $pods_admin_ajax_actions, true ) ) {
94
- // @codingStandardsIgnoreLine
95
- foreach ( $_POST as $key => $value ) {
96
- if ( 'action' === $key || 0 === strpos( $key, '_podsfix_' ) ) {
97
- continue;
98
- }
99
 
100
- // @codingStandardsIgnoreLine
101
- unset( $_POST[ $key ] );
102
 
103
- // @codingStandardsIgnoreLine
104
- $_POST[ '_podsfix_' . $key ] = $value;
105
- }
106
- }
107
- }//end if
108
- }
109
 
110
- /**
111
- * Attach requirements to admin header
112
- *
113
- * @since 2.0.0
114
- */
115
- public function admin_head() {
116
 
117
- wp_register_script( 'pods-floatmenu', PODS_URL . 'ui/js/floatmenu.js', array(), PODS_VERSION );
 
 
 
 
118
 
119
- wp_register_script( 'pods-admin-importer', PODS_URL . 'ui/js/admin-importer.js', array(), PODS_VERSION );
 
 
120
 
121
- wp_register_script( 'pods-upgrade', PODS_URL . 'ui/js/jquery.pods.upgrade.js', array(), PODS_VERSION );
 
122
 
123
- wp_register_script( 'pods-migrate', PODS_URL . 'ui/js/jquery.pods.migrate.js', array(), PODS_VERSION );
 
124
 
125
- // @codingStandardsIgnoreLine
126
- if ( isset( $_GET['page'] ) ) {
127
- // @codingStandardsIgnoreLine
128
- $page = $_GET['page'];
129
- if ( 'pods' === $page || ( false !== strpos( $page, 'pods-' ) && 0 === strpos( $page, 'pods-' ) ) ) {
130
- ?>
131
- <script type="text/javascript">
132
- var PODS_URL = "<?php echo esc_js( PODS_URL ); ?>";
133
- </script>
134
- <?php
135
- wp_enqueue_script( 'jquery' );
136
- wp_enqueue_script( 'jquery-ui-core' );
137
- wp_enqueue_script( 'jquery-ui-sortable' );
138
 
139
- wp_enqueue_script( 'pods-floatmenu' );
 
140
 
141
- wp_enqueue_script( 'jquery-qtip2' );
142
- wp_enqueue_script( 'pods-qtip-init' );
143
 
144
- wp_enqueue_script( 'pods' );
145
 
146
- if ( 0 === strpos( $page, 'pods-manage-' ) || 0 === strpos( $page, 'pods-add-new-' ) ) {
147
- wp_enqueue_script( 'post' );
148
- } elseif ( 0 === strpos( $page, 'pods-settings-' ) ) {
149
- wp_enqueue_script( 'post' );
150
- }
151
 
152
- if ( 'pods-advanced' === $page ) {
153
- wp_register_script( 'pods-advanced', PODS_URL . 'ui/js/advanced.js', array(), PODS_VERSION );
154
- wp_enqueue_script( 'jquery-ui-effects-core', PODS_URL . 'ui/js/jquery-ui/jquery.effects.core.js', array( 'jquery' ), '1.8.8' );
155
- wp_enqueue_script( 'jquery-ui-effects-fade', PODS_URL . 'ui/js/jquery-ui/jquery.effects.fade.js', array( 'jquery' ), '1.8.8' );
156
- wp_enqueue_script( 'jquery-ui-dialog' );
157
- wp_enqueue_script( 'pods-advanced' );
158
- } elseif ( 'pods-packages' === $page ) {
159
- wp_enqueue_style( 'pods-wizard' );
160
- } elseif ( 'pods-wizard' === $page || 'pods-upgrade' === $page || ( in_array(
161
- $page, array(
162
- 'pods',
163
- 'pods-add-new',
164
- ), true
165
- ) && in_array(
166
- pods_v( 'action', 'get', 'manage' ), array(
167
- 'add',
168
- 'manage',
169
- ), true
170
- ) ) ) {
171
- wp_enqueue_style( 'pods-wizard' );
172
-
173
- if ( 'pods-upgrade' === $page ) {
174
- wp_enqueue_script( 'pods-upgrade' );
175
- }
176
- }//end if
177
- }//end if
178
- }//end if
179
 
180
- /**
181
- * Filter to disable default loading of the DFV script. By default, Pods
182
- * will always enqueue the DFV script if is_admin()
183
- *
184
- * Example: add_filter( 'pods_default_enqueue_dfv', '__return_false');
185
- *
186
- * @param bool Whether or not to enqueue by default
187
- *
188
- * @since 2.7.10
189
- */
190
- if ( apply_filters( 'pods_default_enqueue_dfv', true ) ) {
191
- wp_enqueue_script( 'pods-dfv' );
192
- }
193
 
194
- // New Styles Enqueue
195
- wp_enqueue_style( 'pods-styles' );
196
- }
197
 
198
- /**
199
- * Build the admin menus
200
- *
201
- * @since 2.0.0
202
- */
203
- public function admin_menu() {
204
-
205
- $advanced_content_types = PodsMeta::$advanced_content_types;
206
- $taxonomies = PodsMeta::$taxonomies;
207
- $settings = PodsMeta::$settings;
208
-
209
- $all_pods = pods_api()->load_pods( array( 'count' => true ) );
210
-
211
- if ( ! PodsInit::$upgrade_needed || ( pods_is_admin() && 1 === (int) pods_v( 'pods_upgrade_bypass' ) ) ) {
212
- $submenu_items = array();
213
-
214
- if ( ! empty( $advanced_content_types ) ) {
215
- $submenu = array();
216
-
217
- $pods_pages = 0;
218
-
219
- foreach ( (array) $advanced_content_types as $pod ) {
220
- if ( ! isset( $pod['name'] ) || ! isset( $pod['options'] ) || empty( $pod['fields'] ) ) {
221
- continue;
222
- } elseif ( ! pods_is_admin(
223
- array(
224
- 'pods',
225
- 'pods_content',
226
- 'pods_add_' . $pod['name'],
227
- 'pods_edit_' . $pod['name'],
228
- 'pods_delete_' . $pod['name'],
229
- )
230
- ) ) {
231
- continue;
232
- }
233
 
234
- $pod_name = $pod['name'];
 
235
 
236
- $pod = apply_filters( "pods_advanced_content_type_pod_data_{$pod_name}", $pod, $pod['name'] );
237
- $pod = apply_filters( 'pods_advanced_content_type_pod_data', $pod, $pod['name'] );
 
 
 
 
238
 
239
- if ( 1 === (int) pods_v( 'show_in_menu', $pod['options'], 0 ) ) {
240
- $page_title = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true );
241
- $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
242
 
243
- $menu_label = pods_v( 'menu_name', $pod['options'], $page_title, true );
244
- $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
245
 
246
- $singular_label = pods_v( 'label_singular', $pod['options'], pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true ), true );
247
- $plural_label = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true );
248
 
249
- $menu_location = pods_v( 'menu_location', $pod['options'], 'objects' );
250
- $menu_location_custom = pods_v( 'menu_location_custom', $pod['options'], '' );
251
 
252
- $menu_position = pods_v( 'menu_position', $pod['options'], '', true );
253
- $menu_icon = pods_evaluate_tags( pods_v( 'menu_icon', $pod['options'], '', true ), true );
 
 
254
 
255
- if ( empty( $menu_position ) ) {
256
- $menu_position = null;
257
- }
258
 
259
- $parent_page = null;
260
-
261
- if ( pods_is_admin(
262
- array(
263
- 'pods',
264
- 'pods_content',
265
- 'pods_edit_' . $pod['name'],
266
- 'pods_delete_' . $pod['name'],
267
- )
268
- ) ) {
269
- if ( ! empty( $menu_location_custom ) ) {
270
- if ( ! isset( $submenu_items[ $menu_location_custom ] ) ) {
271
- $submenu_items[ $menu_location_custom ] = array();
272
- }
273
-
274
- $submenu_items[ $menu_location_custom ][] = array(
275
- $menu_location_custom,
276
- $page_title,
277
- $menu_label,
278
- 'read',
279
- 'pods-manage-' . $pod['name'],
280
- array( $this, 'admin_content' ),
281
- );
282
-
283
- continue;
284
- } else {
285
- $pods_pages ++;
286
-
287
- $page = 'pods-manage-' . $pod['name'];
288
- $parent_page = $page;
289
-
290
- if ( empty( $menu_position ) ) {
291
- $menu_position = null;
292
- }
293
- add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
294
-
295
- $all_title = $plural_label;
296
- $all_label = pods_v( 'label_all_items', $pod['options'], __( 'All', 'pods' ) . ' ' . $plural_label );
297
-
298
- if ( pods_v( 'page' ) === $page ) {
299
- if ( 'edit' === pods_v( 'action', 'get', 'manage' ) ) {
300
- $all_title = pods_v( 'label_edit_item', $pod['options'], __( 'Edit', 'pods' ) . ' ' . $singular_label );
301
- } elseif ( 'add' === pods_v( 'action', 'get', 'manage' ) ) {
302
- $all_title = pods_v( 'label_add_new_item', $pod['options'], __( 'Add New', 'pods' ) . ' ' . $singular_label );
303
- }
304
- }
305
-
306
- add_submenu_page(
307
- $parent_page, $all_title, $all_label, 'read', $page, array(
308
- $this,
309
- 'admin_content',
310
- )
311
- );
312
- }//end if
313
- }//end if
314
-
315
- if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod['name'] ) ) ) {
316
- $page = 'pods-add-new-' . $pod['name'];
317
-
318
- if ( null === $parent_page ) {
319
- $pods_pages ++;
320
-
321
- $parent_page = $page;
322
-
323
- if ( empty( $menu_position ) ) {
324
- $menu_position = null;
325
- }
326
- add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
327
- }
328
-
329
- $add_title = pods_v( 'label_add_new_item', $pod['options'], __( 'Add New', 'pods' ) . ' ' . $singular_label );
330
- $add_label = pods_v( 'label_add_new', $pod['options'], __( 'Add New', 'pods' ) );
331
-
332
- add_submenu_page(
333
- $parent_page, $add_title, $add_label, 'read', $page, array(
334
- $this,
335
- 'admin_content',
336
- )
337
- );
338
- }//end if
339
- } else {
340
- $submenu[] = $pod;
341
- }//end if
342
- }//end foreach
343
-
344
- $submenu = apply_filters( 'pods_admin_menu_secondary_content', $submenu );
345
-
346
- if ( ! empty( $submenu ) && ( ! defined( 'PODS_DISABLE_CONTENT_MENU' ) || ! PODS_DISABLE_CONTENT_MENU ) ) {
347
- $parent_page = null;
348
-
349
- foreach ( $submenu as $item ) {
350
- $singular_label = pods_v( 'label_singular', $item['options'], pods_v( 'label', $item, ucwords( str_replace( '_', ' ', $item['name'] ) ), true ), true );
351
- $plural_label = pods_v( 'label', $item, ucwords( str_replace( '_', ' ', $item['name'] ) ), true );
352
-
353
- if ( pods_is_admin(
354
- array(
355
- 'pods',
356
- 'pods_content',
357
- 'pods_edit_' . $item['name'],
358
- 'pods_delete_' . $item['name'],
359
- )
360
- ) ) {
361
- $page = 'pods-manage-' . $item['name'];
362
-
363
- if ( null === $parent_page ) {
364
- $parent_page = $page;
365
-
366
- add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' );
367
- }
368
-
369
- $all_title = $plural_label;
370
- $all_label = __( 'Manage', 'pods' ) . ' ' . $plural_label;
371
-
372
- if ( pods_v( 'page' ) === $page ) {
373
- if ( 'edit' === pods_v( 'action', 'get', 'manage' ) ) {
374
- $all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label;
375
- } elseif ( 'add' === pods_v( 'action', 'get', 'manage' ) ) {
376
- $all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
377
- }
378
- }
379
-
380
- add_submenu_page(
381
- $parent_page, $all_title, $all_label, 'read', $page, array(
382
- $this,
383
- 'admin_content',
384
- )
385
- );
386
- } elseif ( current_user_can( 'pods_add_' . $item['name'] ) ) {
387
- $page = 'pods-add-new-' . $item['name'];
388
-
389
- if ( null === $parent_page ) {
390
- $parent_page = $page;
391
-
392
- add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' );
393
- }
394
-
395
- $add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
396
- $add_label = __( 'Manage', 'pods' ) . ' ' . $plural_label;
397
-
398
- add_submenu_page(
399
- $parent_page, $add_title, $add_label, 'read', $page, array(
400
- $this,
401
- 'admin_content',
402
- )
403
- );
404
- }//end if
405
- }//end foreach
406
- }//end if
407
- }//end if
408
-
409
- if ( ! empty( $taxonomies ) ) {
410
- foreach ( (array) $taxonomies as $pod ) {
411
- // Default taxonomy capability
412
- $capability = 'manage_categories';
413
-
414
- if ( ! empty( $pod['options']['capability_type'] ) ) {
415
- if ( 'custom' === $pod['options']['capability_type'] && ! empty( $pod['options']['capability_type_custom'] ) ) {
416
- $capability = 'manage_' . (string) $pod['options']['capability_type_custom'] . '_terms';
417
- }
418
- }
419
 
420
- // Check capabilities.
421
- if ( ! pods_is_admin(
422
- array(
423
- 'pods',
424
- 'pods_content',
425
- 'pods_edit_' . $pod['name'],
426
- $capability,
427
- )
428
- ) ) {
429
- continue;
430
- }
431
 
432
- // Check UI settings
433
- if ( 1 !== (int) pods_v( 'show_ui', $pod['options'], 0 ) || 1 !== (int) pods_v( 'show_in_menu', $pod['options'], 0 ) ) {
434
- continue;
435
- }
436
 
437
- $menu_location = pods_v( 'menu_location', $pod['options'], 'default' );
 
 
438
 
439
- if ( 'default' === $menu_location ) {
440
- continue;
441
- }
442
 
443
- $page_title = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true );
444
- $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
445
 
446
- $menu_label = pods_v( 'menu_name', $pod['options'], $page_title, true );
447
- $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
448
 
449
- $menu_icon = pods_evaluate_tags( pods_v( 'menu_icon', $pod['options'], '', true ), true );
450
- $menu_slug = 'edit-tags.php?taxonomy=' . $pod['name'];
451
- $menu_location_custom = pods_v( 'menu_location_custom', $pod['options'], '' );
452
 
453
- $menu_position = pods_v( 'menu_position', $pod['options'], '', true );
454
- if ( empty( $menu_position ) ) {
455
- $menu_position = null;
456
- }
 
 
457
 
458
- $taxonomy_data = get_taxonomy( $pod['name'] );
 
 
 
459
 
460
- foreach ( (array) $taxonomy_data->object_type as $post_type ) {
461
- if ( 'post' === $post_type ) {
462
- remove_submenu_page( 'edit.php', $menu_slug );
463
- } elseif ( 'attachment' === $post_type ) {
464
- remove_submenu_page( 'upload.php', $menu_slug . '&amp;post_type=' . $post_type );
465
- } else {
466
- remove_submenu_page( 'edit.php?post_type=' . $post_type, $menu_slug . '&amp;post_type=' . $post_type );
467
- }
468
- }
469
 
470
- if ( 'settings' === $menu_location ) {
471
- add_options_page( $page_title, $menu_label, 'read', $menu_slug );
472
- } elseif ( 'appearances' === $menu_location ) {
473
- add_theme_page( $page_title, $menu_label, 'read', $menu_slug );
474
- } elseif ( 'objects' === $menu_location || 'top' === $menu_location ) {
475
- add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position );
476
- } elseif ( 'submenu' === $menu_location && ! empty( $menu_location_custom ) ) {
477
- if ( ! isset( $submenu_items[ $menu_location_custom ] ) ) {
478
- $submenu_items[ $menu_location_custom ] = array();
479
- }
480
 
481
- $submenu_items[ $menu_location_custom ][] = array(
482
- $menu_location_custom,
483
- $page_title,
484
- $menu_label,
485
- 'read',
486
- $menu_slug,
487
- '',
488
- );
489
- }//end if
490
- }//end foreach
491
- }//end if
492
-
493
- if ( ! empty( $settings ) ) {
494
- foreach ( (array) $settings as $pod ) {
495
- if ( ! pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod['name'] ) ) ) {
496
- continue;
497
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
498
 
499
- $page_title = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true );
500
- $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
 
 
 
 
 
 
501
 
502
- $menu_label = pods_v( 'menu_name', $pod['options'], $page_title, true );
503
- $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504
 
505
- $menu_icon = pods_evaluate_tags( pods_v( 'menu_icon', $pod['options'], '', true ), true );
 
 
 
 
 
 
 
 
 
 
506
 
507
- $menu_position = pods_v( 'menu_position', $pod['options'], '', true );
508
- if ( empty( $menu_position ) ) {
509
- $menu_position = null;
510
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
 
512
- $menu_slug = 'pods-settings-' . $pod['name'];
513
- $menu_location = pods_v( 'menu_location', $pod['options'], 'settings' );
514
- $menu_location_custom = pods_v( 'menu_location_custom', $pod['options'], '' );
515
- $menu_callback = array( $this, 'admin_content_settings' );
516
-
517
- if ( 'settings' === $menu_location ) {
518
- add_options_page( $page_title, $menu_label, 'read', $menu_slug, $menu_callback, $menu_position );
519
- } elseif ( 'appearances' === $menu_location ) {
520
- add_theme_page( $page_title, $menu_label, 'read', $menu_slug, $menu_callback, $menu_position );
521
- } elseif ( 'objects' === $menu_location || 'top' === $menu_location ) {
522
- add_menu_page( $page_title, $menu_label, 'read', $menu_slug, $menu_callback, $menu_icon, $menu_position );
523
- } elseif ( 'submenu' === $menu_location && ! empty( $menu_location_custom ) ) {
524
- if ( ! isset( $submenu_items[ $menu_location_custom ] ) ) {
525
- $submenu_items[ $menu_location_custom ] = array();
526
- }
527
 
528
- $submenu_items[ $menu_location_custom ][] = array(
529
- $menu_location_custom,
530
- $page_title,
531
- $menu_label,
532
- 'read',
533
- $menu_slug,
534
- $menu_callback,
535
- $menu_position,
536
- );
537
- }//end if
538
- }//end foreach
539
- }//end if
540
-
541
- foreach ( $submenu_items as $items ) {
542
- foreach ( $items as $item ) {
543
- call_user_func_array( 'add_submenu_page', $item );
544
- }
545
- }
546
 
547
- $admin_menus = array(
548
- 'pods' => array(
549
- 'label' => __( 'Edit Pods', 'pods' ),
550
- 'function' => array( $this, 'admin_setup' ),
551
- 'access' => 'pods',
552
- ),
553
- 'pods-add-new' => array(
554
- 'label' => __( 'Add New', 'pods' ),
555
- 'function' => array( $this, 'admin_setup' ),
556
- 'access' => 'pods',
557
- ),
558
- 'pods-components' => array(
559
- 'label' => __( 'Components', 'pods' ),
560
- 'function' => array( $this, 'admin_components' ),
561
- 'access' => 'pods_components',
562
- ),
563
- 'pods-settings' => array(
564
- 'label' => __( 'Settings', 'pods' ),
565
- 'function' => array( $this, 'admin_settings' ),
566
- 'access' => 'pods_settings',
567
- ),
568
- 'pods-help' => array(
569
- 'label' => __( 'Help', 'pods' ),
570
- 'function' => array( $this, 'admin_help' ),
571
- ),
572
- );
573
 
574
- if ( empty( $all_pods ) ) {
575
- unset( $admin_menus['pods'] );
 
 
576
 
577
- if ( 'pods' === pods_v( 'page', 'get' ) ) {
578
- // Replace `pods` page param with first existing pod page and redirect.
579
- $url = add_query_arg( 'page', key( $admin_menus ) );
580
- $url = get_site_url( null, $url );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
 
582
- wp_safe_redirect( $url );
583
- die();
584
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
585
  }
586
 
587
- add_filter( 'parent_file', array( $this, 'parent_file' ) );
588
- } else {
589
- $admin_menus = array(
590
- 'pods-upgrade' => array(
591
- 'label' => __( 'Upgrade', 'pods' ),
592
- 'function' => array( $this, 'admin_upgrade' ),
593
- 'access' => 'manage_options',
594
- ),
595
- 'pods-settings' => array(
596
- 'label' => __( 'Settings', 'pods' ),
597
- 'function' => array( $this, 'admin_settings' ),
598
- 'access' => 'pods_settings',
599
- ),
600
- 'pods-help' => array(
601
- 'label' => __( 'Help', 'pods' ),
602
- 'function' => array( $this, 'admin_help' ),
603
- ),
604
- );
605
-
606
- add_action( 'admin_notices', array( $this, 'upgrade_notice' ) );
607
- }//end if
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608
 
609
  /**
610
- * Add or change Pods Admin menu items
611
  *
612
- * @param array $admin_menus The submenu items in Pods Admin menu.
 
613
  *
614
- * @since unknown
615
  */
616
- $admin_menus = apply_filters( 'pods_admin_menu', $admin_menus );
617
 
618
- $parent = false;
619
-
620
- // PODS_LIGHT disables all Pods components so remove the components menu
621
- if ( pods_light() ) {
622
- unset( $admin_menus['pods-components'] );
623
- }
624
-
625
- if ( ! empty( $admin_menus ) && ( ! defined( 'PODS_DISABLE_ADMIN_MENU' ) || ! PODS_DISABLE_ADMIN_MENU ) ) {
626
- foreach ( $admin_menus as $page => $menu_item ) {
627
- if ( ! pods_is_admin( pods_v( 'access', $menu_item ) ) ) {
628
- continue;
629
- }
630
-
631
- // Don't just show the help page
632
- if ( false === $parent && 'pods-help' === $page ) {
633
- continue;
634
- }
635
-
636
- if ( ! isset( $menu_item['label'] ) ) {
637
- $menu_item['label'] = $page;
638
- }
639
-
640
- if ( false === $parent ) {
641
- $parent = $page;
642
-
643
- $menu = __( 'Pods Admin', 'pods' );
644
-
645
- if ( 'pods-upgrade' === $parent ) {
646
- $menu = __( 'Pods Upgrade', 'pods' );
647
- }
648
-
649
- add_menu_page( $menu, $menu, 'read', $parent, null, 'dashicons-pods' );
650
- }
651
 
652
- add_submenu_page( $parent, $menu_item['label'], $menu_item['label'], 'read', $page, $menu_item['function'] );
 
 
 
653
 
654
- if ( 'pods-components' === $page && is_object( PodsInit::$components ) ) {
655
- PodsInit::$components->menu( $parent );
656
- }
657
- }//end foreach
658
- }//end if
659
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
660
 
661
  /**
662
- * Set the correct parent_file to highlight the correct top level menu
663
- *
664
- * @param string $parent_file The parent file.
665
  *
666
- * @return mixed|string
 
 
 
 
667
  *
668
- * @since unknown
 
 
669
  */
670
- public function parent_file( $parent_file ) {
671
-
672
- global $current_screen;
673
-
674
- if ( isset( $current_screen ) && ! empty( $current_screen->taxonomy ) ) {
675
- $taxonomies = PodsMeta::$taxonomies;
676
- if ( ! empty( $taxonomies ) ) {
677
- foreach ( (array) $taxonomies as $pod ) {
678
- if ( $current_screen->taxonomy !== $pod['name'] ) {
679
- continue;
680
- }
681
-
682
- $menu_slug = 'edit-tags.php?taxonomy=' . $pod['name'];
683
- $menu_location = pods_v( 'menu_location', $pod['options'], 'default' );
684
- $menu_location_custom = pods_v( 'menu_location_custom', $pod['options'], '' );
685
-
686
- if ( 'settings' === $menu_location ) {
687
- $parent_file = 'options-general.php';
688
- } elseif ( 'appearances' === $menu_location ) {
689
- $parent_file = 'themes.php';
690
- } elseif ( 'objects' === $menu_location ) {
691
- $parent_file = $menu_slug;
692
- } elseif ( 'top' === $menu_location ) {
693
- $parent_file = $menu_slug;
694
- } elseif ( 'submenu' === $menu_location && ! empty( $menu_location_custom ) ) {
695
- $parent_file = $menu_location_custom;
696
- }
697
 
698
- break;
699
- }//end foreach
700
- }//end if
701
- }//end if
702
 
703
- if ( isset( $current_screen ) && ! empty( $current_screen->post_type ) && is_object( PodsInit::$components ) ) {
704
- global $submenu_file;
705
 
706
- $components = PodsInit::$components->components;
707
 
708
- foreach ( $components as $component => $component_data ) {
709
- if ( ! empty( $component_data['MenuPage'] ) && $parent_file === $component_data['MenuPage'] ) {
710
- $parent_file = 'pods';
 
 
 
 
 
 
711
 
712
- // @codingStandardsIgnoreLine
713
- $submenu_file = $component_data['MenuPage'];
714
- }
715
- }
716
- }
717
 
718
- return $parent_file;
719
- }
720
 
721
- /**
722
- * Show upgrade notice.
723
- */
724
- public function upgrade_notice() {
725
 
726
- echo '<div class="error fade"><p>';
727
- // @codingStandardsIgnoreLine
728
- echo sprintf( __( '<strong>NOTICE:</strong> Pods %1$s requires your action to complete the upgrade. Please run the <a href="%2$s">Upgrade Wizard</a>.', 'pods' ), esc_html( PODS_VERSION ), esc_url( admin_url( 'admin.php?page=pods-upgrade' ) ) );
729
- echo '</p></div>';
730
- }
731
 
732
  /**
733
- * Create PodsUI content for the administration pages
 
 
 
 
 
 
 
 
734
  */
735
- public function admin_content() {
736
-
737
- // @codingStandardsIgnoreLine
738
- $pod_name = str_replace( array( 'pods-manage-', 'pods-add-new-' ), '', $_GET['page'] );
739
-
740
- $pod = pods( $pod_name, pods_v( 'id', 'get', null, true ) );
741
 
742
- // @codingStandardsIgnoreLine
743
- if ( false !== strpos( $_GET['page'], 'pods-add-new-' ) ) {
744
- // @codingStandardsIgnoreLine
745
- $_GET['action'] = pods_v( 'action', 'get', 'add' );
746
  }
747
 
748
- $pod->ui();
 
749
  }
750
 
751
- /**
752
- * Create PodsUI content for the settings administration pages
753
- */
754
- public function admin_content_settings() {
 
 
 
 
 
 
755
 
756
- // @codingStandardsIgnoreLine
757
- $pod_name = str_replace( 'pods-settings-', '', $_GET['page'] );
758
 
759
- $pod = pods( $pod_name );
760
 
761
- if ( 'custom' !== pods_v( 'ui_style', $pod->pod_data['options'], 'settings', true ) ) {
762
- $actions_disabled = array(
763
- 'manage' => 'manage',
764
- 'add' => 'add',
765
- 'delete' => 'delete',
766
- 'duplicate' => 'duplicate',
767
- 'view' => 'view',
768
- 'export' => 'export',
769
- );
770
 
771
- // @codingStandardsIgnoreLine
772
- $_GET['action'] = 'edit';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
773
 
774
- $page_title = pods_v( 'label', $pod->pod_data, ucwords( str_replace( '_', ' ', $pod->pod_data['name'] ) ), true );
775
- $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod->pod_data );
776
 
777
- $ui = array(
778
- 'pod' => $pod,
779
- 'fields' => array(
780
- 'edit' => $pod->pod_data['fields'],
781
- ),
782
- 'header' => array(
783
- 'edit' => $page_title,
784
- ),
785
- 'label' => array(
786
- 'edit' => __( 'Save Changes', 'pods' ),
787
- ),
788
- 'style' => pods_v( 'ui_style', $pod->pod_data['options'], 'settings', true ),
789
- 'icon' => pods_evaluate_tags( pods_v( 'menu_icon', $pod->pod_data['options'] ), true ),
790
- 'actions_disabled' => $actions_disabled,
791
- );
792
 
793
- $pod_pod_name = $pod->pod;
 
794
 
795
- $ui = apply_filters( "pods_admin_ui_{$pod_pod_name}", apply_filters( 'pods_admin_ui', $ui, $pod->pod, $pod ), $pod->pod, $pod );
 
796
 
797
- // Force disabled actions, do not pass go, do not collect $two_hundred
798
- $ui['actions_disabled'] = $actions_disabled;
 
799
 
800
- pods_ui( $ui );
801
- } else {
802
- $pod_pod_name = $pod->pod;
803
- do_action( 'pods_admin_ui_custom', $pod );
804
- do_action( "pods_admin_ui_custom_{$pod_pod_name}", $pod );
805
- }//end if
806
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
807
 
808
  /**
809
- * Add media button for Pods shortcode
810
  *
811
- * @param string $context Media button context.
 
812
  *
813
- * @return string
 
 
814
  */
815
- public function media_button( $context = null ) {
 
816
 
817
- // If shortcodes are disabled don't show the button
818
- if ( defined( 'PODS_DISABLE_SHORTCODE' ) && PODS_DISABLE_SHORTCODE ) {
819
- return '';
820
  }
821
-
822
- /**
823
- * Filter to remove Pods shortcode button from the post editor.
824
- *
825
- * @param bool $show_button Set to false to block the shortcode button from appearing.
826
- * @param string $context Media button context.
827
- *
828
- * @since 2.3.19
829
- */
830
- if ( ! apply_filters( 'pods_admin_media_button', true, $context ) ) {
831
- return '';
832
  }
833
-
834
- $current_page = basename( $_SERVER['PHP_SELF'] );
835
- $current_page = explode( '?', $current_page );
836
- $current_page = explode( '#', $current_page[0] );
837
- $current_page = $current_page[0];
838
-
839
- // Only show the button on post type pages
840
- if ( ! in_array(
841
- $current_page, array(
842
- 'post-new.php',
843
- 'post.php',
844
- ), true
845
- ) ) {
846
- return '';
847
  }
848
 
849
- add_action( 'admin_footer', array( $this, 'mce_popup' ) );
850
-
851
- echo '<a href="#TB_inline?width=640&inlineId=pods_shortcode_form" class="thickbox button" id="add_pod_button" title="Pods Shortcode"><img style="padding: 0px 6px 0px 0px; margin: -3px 0px 0px;" src="' . esc_url( PODS_URL . 'ui/images/icon16.png' ) . '" alt="' . esc_attr__( 'Pods Shortcode', 'pods' ) . '" />' . esc_html__( 'Pods Shortcode', 'pods' ) . '</a>';
852
- }
853
-
854
- /**
855
- * Enqueue assets for Media Library Popup
856
- */
857
- public function register_media_assets() {
858
-
859
- if ( 'pods_media_attachment' === pods_v( 'inlineId' ) ) {
860
- wp_enqueue_style( 'pods-styles' );
861
  }
862
- }
863
-
864
- /**
865
- * Output Pods shortcode popup window
866
- */
867
- public function mce_popup() {
868
-
869
- pods_view( PODS_DIR . 'ui/admin/shortcode.php', compact( array_keys( get_defined_vars() ) ) );
870
- }
871
 
872
- /**
873
- * Handle main Pods Setup area for managing Pods and Fields
874
- */
875
- public function admin_setup() {
876
-
877
- $pods = pods_api()->load_pods( array( 'fields' => false ) );
878
-
879
- $view = pods_v( 'view', 'get', 'all', true );
880
-
881
- // @codingStandardsIgnoreLine
882
- if ( empty( $pods ) && ! isset( $_GET['action'] ) ) {
883
- // @codingStandardsIgnoreLine
884
- $_GET['action'] = 'add';
885
- }
886
 
887
- // @codingStandardsIgnoreLine
888
- if ( 'pods-add-new' === $_GET['page'] ) {
889
- // @codingStandardsIgnoreLine
890
- if ( isset( $_GET['action'] ) && 'add' !== $_GET['action'] ) {
891
- pods_redirect(
892
- pods_query_arg(
893
- array(
894
- 'page' => 'pods',
895
- // @codingStandardsIgnoreLine
896
- 'action' => $_GET['action'],
897
- )
898
- )
899
- );
900
- } else {
901
- // @codingStandardsIgnoreLine
902
- $_GET['action'] = 'add';
903
- }
904
- // @codingStandardsIgnoreLine
905
- } elseif ( isset( $_GET['action'] ) && 'add' === $_GET['action'] ) {
906
- pods_redirect(
907
- pods_query_arg(
908
- array(
909
- 'page' => 'pods-add-new',
910
- 'action' => '',
911
- )
912
- )
913
- );
914
- }//end if
915
-
916
- $types = array(
917
- 'post_type' => __( 'Post Type (extended)', 'pods' ),
918
- 'taxonomy' => __( 'Taxonomy (extended)', 'pods' ),
919
- 'cpt' => __( 'Custom Post Type', 'pods' ),
920
- 'ct' => __( 'Custom Taxonomy', 'pods' ),
921
- 'user' => __( 'User (extended)', 'pods' ),
922
- 'media' => __( 'Media (extended)', 'pods' ),
923
- 'comment' => __( 'Comments (extended)', 'pods' ),
924
- 'pod' => __( 'Advanced Content Type', 'pods' ),
925
- 'settings' => __( 'Custom Settings Page', 'pods' ),
926
- );
927
-
928
- $row = false;
929
-
930
- $pod_types_found = array();
931
-
932
- $fields = array(
933
- 'label' => array( 'label' => __( 'Label', 'pods' ) ),
934
- 'name' => array( 'label' => __( 'Name', 'pods' ) ),
935
- 'type' => array( 'label' => __( 'Type', 'pods' ) ),
936
- 'storage' => array(
937
- 'label' => __( 'Storage Type', 'pods' ),
938
- 'width' => '10%',
939
- ),
940
- 'field_count' => array(
941
- 'label' => __( 'Number of Fields', 'pods' ),
942
- 'width' => '8%',
943
- ),
944
- );
945
-
946
- $total_fields = 0;
947
-
948
- foreach ( $pods as $k => $pod ) {
949
- if ( isset( $types[ $pod['type'] ] ) ) {
950
- if ( in_array(
951
- $pod['type'], array(
952
- 'post_type',
953
- 'taxonomy',
954
- ), true
955
- ) ) {
956
- if ( empty( $pod['object'] ) ) {
957
- if ( 'post_type' === $pod['type'] ) {
958
- $pod['type'] = 'cpt';
959
- } else {
960
- $pod['type'] = 'ct';
961
  }
962
  }
963
- }
964
 
965
- if ( ! isset( $pod_types_found[ $pod['type'] ] ) ) {
966
- $pod_types_found[ $pod['type'] ] = 1;
967
- } else {
968
- $pod_types_found[ $pod['type'] ] ++;
969
- }
970
 
971
- if ( 'all' !== $view && $view !== $pod['type'] ) {
972
- unset( $pods[ $k ] );
973
 
974
- continue;
975
  }
976
 
977
- $pod['real_type'] = $pod['type'];
978
- $pod['type'] = $types[ $pod['type'] ];
979
- } elseif ( 'all' !== $view ) {
980
- continue;
981
- }//end if
982
-
983
- $pod['storage'] = ucwords( $pod['storage'] );
984
-
985
- // @codingStandardsIgnoreLine
986
- if ( $pod['id'] == pods_v( 'id' ) && 'delete' !== pods_v( 'action' ) ) {
987
- $row = $pod;
988
  }
989
 
990
- $pod = array(
991
- 'id' => $pod['id'],
992
- 'label' => pods_v( 'label', $pod ),
993
- 'name' => pods_v( 'name', $pod ),
994
- 'object' => pods_v( 'object', $pod ),
995
- 'type' => pods_v( 'type', $pod ),
996
- 'real_type' => pods_v( 'real_type', $pod ),
997
- 'storage' => pods_v( 'storage', $pod ),
998
- 'field_count' => count( $pod['fields'] ),
999
- );
1000
-
1001
- $total_fields += $pod['field_count'];
1002
-
1003
- $pods[ $k ] = $pod;
1004
- }//end foreach
1005
-
1006
- if ( false === $row && 0 < pods_v( 'id' ) && 'delete' !== pods_v( 'action' ) ) {
1007
- pods_message( 'Pod not found', 'error' );
1008
-
1009
- // @codingStandardsIgnoreLine
1010
- unset( $_GET['id'], $_GET['action'] );
1011
  }
1012
 
1013
- $ui = array(
1014
- 'data' => $pods,
1015
- 'row' => $row,
1016
- 'total' => count( $pods ),
1017
- 'total_found' => count( $pods ),
1018
- 'items' => 'Pods',
1019
- 'item' => 'Pod',
1020
- 'fields' => array(
1021
- 'manage' => $fields,
1022
- ),
1023
- 'actions_disabled' => array( 'view', 'export' ),
1024
- 'actions_custom' => array(
1025
- 'add' => array( $this, 'admin_setup_add' ),
1026
- 'edit' => array( $this, 'admin_setup_edit' ),
1027
- 'duplicate' => array(
1028
- 'callback' => array( $this, 'admin_setup_duplicate' ),
1029
- 'restrict_callback' => array( $this, 'admin_setup_duplicate_restrict' ),
1030
- ),
1031
- 'reset' => array(
1032
- 'label' => __( 'Delete All Items', 'pods' ),
1033
- 'confirm' => __( 'Are you sure you want to delete all items from this Pod? If this is an extended Pod, it will remove the original items extended too.', 'pods' ),
1034
- 'callback' => array( $this, 'admin_setup_reset' ),
1035
- 'restrict_callback' => array( $this, 'admin_setup_reset_restrict' ),
1036
- 'nonce' => true,
1037
- ),
1038
- 'delete' => array( $this, 'admin_setup_delete' ),
1039
- ),
1040
- 'action_links' => array(
1041
- 'add' => pods_query_arg(
1042
- array(
1043
- 'page' => 'pods-add-new',
1044
- 'action' => '',
1045
- 'id' => '',
1046
- 'do' => '',
1047
- )
1048
- ),
1049
- ),
1050
- 'search' => false,
1051
- 'searchable' => false,
1052
- 'sortable' => true,
1053
- 'pagination' => false,
1054
- 'extra' => array(
1055
- 'total' => ', ' . number_format_i18n( $total_fields ) . ' ' . _n( 'field', 'fields', $total_fields, 'pods' ),
1056
- ),
1057
- );
1058
-
1059
- if ( 1 < count( $pod_types_found ) ) {
1060
- $ui['views'] = array( 'all' => __( 'All', 'pods' ) );
1061
- $ui['view'] = $view;
1062
- $ui['heading'] = array( 'views' => __( 'Type', 'pods' ) );
1063
- $ui['filters_enhanced'] = true;
1064
-
1065
- foreach ( $pod_types_found as $pod_type => $number_found ) {
1066
- $ui['views'][ $pod_type ] = $types[ $pod_type ];
1067
- }
1068
- }
1069
-
1070
- // Add our custom callouts.
1071
- $this->handle_callouts_updates();
1072
 
1073
- add_filter( 'pods_ui_manage_custom_container_classes', array( $this, 'admin_manage_container_class' ) );
1074
- add_action( 'pods_ui_manage_after_container', array( $this, 'admin_manage_callouts' ) );
1075
 
1076
- pods_ui( $ui );
1077
  }
1078
 
1079
- /**
1080
- * Get list of callouts to show.
1081
- *
1082
- * @since 2.7.17
1083
- *
1084
- * @return array List of callouts.
1085
- */
1086
- public function get_callouts() {
1087
- $force_callouts = false;
1088
-
1089
- $page = pods_v( 'page' );
1090
-
1091
- if ( in_array( $page, array( 'pods-settings', 'pods-help' ), true ) ) {
1092
- $force_callouts = true;
1093
- }
1094
-
1095
- $callouts = get_option( 'pods_callouts' );
1096
-
1097
- if ( ! $callouts ) {
1098
- $callouts = array(
1099
- 'friends_2020' => 1,
1100
- );
1101
- }
1102
-
1103
- // Handle Friends of Pods 2020 callout logic.
1104
- $callouts['friends_2020'] = ! isset( $callouts['friends_2020'] ) || $callouts['friends_2020'] || $force_callouts ? 1 : 0;
1105
-
1106
- /**
1107
- * Allow hooking into whether or not the specific callouts should show.
1108
- *
1109
- * @since 2.7.17
1110
- *
1111
- * @param array List of callouts to enable.
1112
- */
1113
- $callouts = apply_filters( 'pods_admin_callouts', $callouts );
1114
-
1115
- return $callouts;
1116
- }
1117
-
1118
- /**
1119
- * Handle callouts update logic.
1120
- *
1121
- * @since 2.7.17
1122
- */
1123
- public function handle_callouts_updates() {
1124
- $callouts = get_option( 'pods_callouts' );
1125
-
1126
- if ( ! $callouts ) {
1127
- $callouts = array();
1128
- }
1129
-
1130
- $disable_pods = pods_v( 'pods_callout_dismiss' );
1131
-
1132
- // Disable Friends of Pods 2020 callout.
1133
- if ( 'friends_2020' === $disable_pods ) {
1134
- $callouts['friends_2020'] = 0;
1135
-
1136
- update_option( 'pods_callouts', $callouts );
1137
- } elseif ( 'reset' === $disable_pods ) {
1138
- $callouts = array();
1139
-
1140
- update_option( 'pods_callouts', $callouts );
1141
- }
1142
- }
1143
-
1144
- /**
1145
- * Add class to container if we have callouts to show.
1146
- *
1147
- * @since 2.7.17
1148
- *
1149
- * @param array $classes List of classes to use.
1150
- *
1151
- * @return array List of classes to use.
1152
- */
1153
- public function admin_manage_container_class( $classes ) {
1154
- $callouts = $this->get_callouts();
1155
-
1156
- // Only get enabled callouts.
1157
- $callouts = array_filter( $callouts );
1158
-
1159
- if ( ! empty( $callouts ) ) {
1160
- $classes[] = 'pods-admin--flex';
1161
- }
1162
-
1163
- return $classes;
1164
- }
1165
-
1166
- /**
1167
- * Add callouts to let admins know about certain things.
1168
- *
1169
- * @since 2.7.17
1170
- */
1171
- public function admin_manage_callouts() {
1172
- $force_callouts = false;
1173
-
1174
- $page = pods_v( 'page' );
1175
-
1176
- if ( in_array( $page, array( 'pods-settings', 'pods-help' ), true ) ) {
1177
- $force_callouts = true;
1178
- }
1179
-
1180
- $callouts = $this->get_callouts();
1181
-
1182
- if ( ! empty( $callouts['friends_2020'] ) ) {
1183
- ?>
1184
- <div class="pods-admin_friends-callout_container">
1185
- <?php if ( ! $force_callouts ) : ?>
1186
- <a href="<?php echo esc_url( add_query_arg( 'pods_callout_dismiss', 'friends_2020' ) ); ?>" class="pods-admin_friends-callout_close">
1187
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 100 125" enable-background="new 0 0 100 100" xml:space="preserve"><polygon points="95,17 83,5 50,38 17,5 5,17 38,50 5,83 17,95 50,62 83,95 95,83 62,50 "/></svg>
1188
- </a>
1189
- <?php endif; ?>
1190
- <div class="pods-admin_friends-callout_logo-container">
1191
- <svg version="1.1" viewBox="0 0 305 111" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><title>Friends of Pods Logo</title> <defs> <path id="a" d="m0.14762 49.116c0 27.103 21.919 49.075 48.956 49.075 19.888 0 37.007-11.888 44.669-28.962-2.1342-6.538-3.9812-18.041 3.3854-29.538-0.3152-1.624-0.71019-3.219-1.1807-4.781-22.589 22.49-40.827 24.596-54.558 24.229-0.12701-4e-3 -0.58883-0.079-0.71152-0.35667 0 0-0.20016-0.89933 0.38502-0.89933 26.307 0 41.29-15.518 53.531-26.865-0.66763-1.687-1.4264-3.3273-2.2695-4.9167-13.196-3.6393-18.267-14.475-20.067-20.221-6.9007-3.7267-14.796-5.8413-23.184-5.8413-27.037 0-48.956 21.972-48.956 49.076zm62.283-34.287s18.69-2.039 24.194 21.114c-20.424-1.412-24.194-21.114-24.194-21.114zm-7.4779 9.7423s16.57-0.55467 20.342 20.219c-17.938-2.602-20.342-20.219-20.342-20.219zm-9.1018 8.256s14.912-0.97567 18.728 17.626c-16.209-1.8273-18.728-17.626-18.728-17.626zm40.774 3.116c0.021279 0.0013333 0.040563 0.0026667 0.061842 0.0043333l-0.044886 0.067667c-0.0056523-0.024-0.011304-0.048-0.016957-0.072zm-48.709 3.445s13.103-0.859 16.456 15.486c-14.243-1.6047-16.456-15.486-16.456-15.486zm-10.498 1.6027s12.587-0.82333 15.808 14.877c-13.68-1.5417-15.808-14.877-15.808-14.877zm-10.391 0.72233s11.423-0.74667 14.347 13.502c-12.417-1.3997-14.347-13.502-14.347-13.502zm-11.298 2.0857s9.5832-2.526 13.712 9.0523c-0.44919 0.036667-0.88474 0.054333-1.3073 0.054333-9.6148-3.333e-4 -12.405-9.1067-12.405-9.1067zm81.565 0.964c-0.0073147-0.021333-0.014962-0.043667-0.021612-0.064667l0.066497 0.018333c-0.014962 0.015333-0.029924 0.030667-0.044886 0.046333 7.1338 21.557-5.5721 33.29-5.5721 33.29s-8.9279-18.395 5.5721-33.29zm-11.999 0.027333c0.017622 0.0023333 0.035576 5e-3 0.053198 0.0076667l-0.041561 0.056c-0.0036573-0.021667-0.0073147-0.042-0.011637-0.063667zm-10.716 5.6627c0.015959 2e-3 0.032916 0.0036666 0.048543 0.0056666l-0.036573 0.051c-0.0039899-0.019667-0.0076472-0.037333-0.01197-0.056667zm12.212 1.8693c-0.0023274-0.021-0.0046548-0.043333-0.0066497-0.064667l0.056523 0.035667c-0.016624 0.01-0.032916 0.019333-0.049873 0.029 2.2323 21.678-11.682 28.793-11.682 28.793s-4.4962-19.303 11.682-28.793zm-57.318 0.52633-0.018619 0.037333c-0.0039899-0.011667-0.0086447-0.023667-0.012302-0.034667 0.010307-1e-3 0.020614-0.0016667 0.030921-0.0026667zm34.9 2.0257c0.013964 0.0013333 0.027264 3e-3 0.041561 0.0043333l-0.031254 0.046333c-0.0036573-0.017-0.0069822-0.034-0.010307-0.050667zm-22.998 0.34067c0.012302 0.0016666 0.025269 3e-3 0.037571 0.0043333l-0.028594 0.039c-0.0029924-0.014667-0.0056523-0.028667-0.0089771-0.043333zm-16.9 3.542s8.0594-7.693 18.254 0.88467c-3.1137 2.6673-6.0605 3.5853-8.642 3.5853-5.6965 0-9.6125-4.47-9.6125-4.47zm28.752-2.8893c0.013632 0.0013334 0.027264 3e-3 0.040896 0.0043334l-0.030589 0.045c-0.0033249-0.016-0.0069822-0.033333-0.010307-0.049333zm21.183 2.4917c3.325e-4 -0.019 3.325e-4 -0.039333 6.65e-4 -0.058333l0.046548 0.039667c-0.015959 0.0063334-0.031254 0.012333-0.047213 0.018667-0.19118 19.436-13.172 23.733-13.172 23.733s-2.0415-17.662 13.172-23.733zm-31.651 1.257v0.05c-0.0099746-0.0083333-0.019617-0.016333-0.029259-0.024667 0.0093096-0.0086666 0.019284-0.017 0.029259-0.025333zm-6.6234 10.543s4.296-11.202 16.634-9.0197c-3.5273 8.062-9.0759 9.5947-12.782 9.5947-2.2719 0-3.8515-0.575-3.8515-0.575zm16.651-9.0593 0.018287 0.046c-0.01197-2e-3 -0.023606-0.0043334-0.035576-0.0063334 0.0059848-0.013333 0.011637-0.026333 0.017289-0.039667zm10.12 0.685c0.0029923-0.016333 0.0059847-0.033333 0.0089771-0.049667l0.034911 0.043c-0.014629 0.0023333-0.029259 0.0046667-0.043888 0.0066667-2.9518 16.71-14.755 17.762-14.755 17.762s0.77369-15.639 14.755-17.762z"/> </defs> <g fill="none" fill-rule="evenodd"> <g transform="translate(6.3172 6.3333)"> <mask id="b" fill="white"> <use xlink:href="#a"/> </mask> <polygon points="-3.1772 -3.2937 100.48 -3.2937 100.48 101.52 -3.1772 101.52" fill="#fff" mask="url(#b)"/> </g> <path d="m55.303 3.569c-28.538 0-51.754 23.273-51.754 51.88 0 28.607 23.216 51.88 51.754 51.88 28.538 0 51.754-23.273 51.754-51.88 0-28.607-23.217-51.88-51.754-51.88m0 107.18c-30.417 0-55.163-24.807-55.163-55.298 0-30.492 24.746-55.298 55.163-55.298 30.417 0 55.164 24.807 55.164 55.298 0 30.491-24.747 55.298-55.164 55.298" fill="#fff"/> <path d="m137.42 77.263-2.7699 22.725h-14.958l8.2174-67.434h22.252c4.001 0 7.4249 0.48597 10.272 1.4579 2.8469 0.97195 5.1859 2.3141 7.0171 4.0266 1.8312 1.7125 3.1777 3.7335 4.0395 6.0631 0.86176 2.3296 1.2926 4.8366 1.2926 7.521 0 3.6718-0.56167 7.0736-1.685 10.205-1.1234 3.1318-2.8392 5.8394-5.1474 8.1227s-5.232 4.0729-8.7714 5.3688-7.725 1.9439-12.557 1.9439h-7.2018zm4.1549-33.463-2.7238 22.123h7.248c2.1544 0 3.9625-0.31626 5.4244-0.9488 1.4619-0.63254 2.6468-1.5273 3.5547-2.6844 0.90792-1.1571 1.5619-2.5378 1.962-4.1423 0.4001-1.6045 0.60015-3.3632 0.60015-5.2763 0-1.3268-0.17696-2.5456-0.5309-3.6564-0.35394-1.1108-0.90022-2.0673-1.6389-2.8695-0.73865-0.80224-1.6696-1.4271-2.793-1.8745-1.1234-0.4474-2.4544-0.6711-3.9933-0.6711h-7.1095zm48.956 46.283c1.6004 0 3.0315-0.48597 4.2934-1.4579 1.2619-0.97195 2.3313-2.2987 3.2085-3.9803 0.87714-1.6816 1.5542-3.6409 2.0313-5.8779 0.47704-2.237 0.71556-4.6206 0.71556-7.1507 0-3.4867-0.46934-5.9782-1.408-7.4747-0.9387-1.4965-2.4698-2.2447-4.5934-2.2447-1.6004 0-3.0315 0.48597-4.2934 1.4579-1.2619 0.97195-2.3313 2.291-3.2085 3.9572s-1.5542 3.6255-2.0313 5.8779c-0.47704 2.2525-0.71556 4.6437-0.71556 7.1739 0 3.425 0.46934 5.9011 1.408 7.4284 0.9387 1.5273 2.4698 2.291 4.5934 2.291zm-1.2926 10.645c-2.6776 0-5.1782-0.4474-7.5019-1.3422-2.3237-0.89481-4.3395-2.1984-6.0477-3.9109-1.7081-1.7125-3.0469-3.8261-4.0164-6.3408-0.96948-2.5147-1.4542-5.4074-1.4542-8.6781 0-4.2581 0.70017-8.1689 2.1005-11.733 1.4004-3.5638 3.2854-6.6416 5.6552-9.2335s5.1166-4.6129 8.2405-6.0631 6.4093-2.1753 9.8563-2.1753c2.6776 0 5.1705 0.4474 7.4788 1.3422 2.3083 0.89481 4.3164 2.1984 6.0246 3.9109 1.7081 1.7125 3.0546 3.8261 4.0395 6.3408 0.98486 2.5147 1.4773 5.4074 1.4773 8.6781 0 4.1963-0.70017 8.0764-2.1005 11.64-1.4004 3.5638-3.2854 6.6493-5.6552 9.2566-2.3698 2.6073-5.1166 4.6437-8.2405 6.1094-3.1239 1.4656-6.4093 2.1984-9.8563 2.1984zm62.6-0.74053c-0.89253 0-1.6389-0.11571-2.239-0.34712-0.60015-0.23142-1.0772-0.54768-1.4311-0.9488s-0.60015-0.87937-0.73864-1.4348c-0.1385-0.5554-0.20774-1.1571-0.20774-1.805v-4.0266c-2.1852 2.9004-4.6011 5.176-7.248 6.8267-2.6468 1.6508-5.4629 2.4761-8.4482 2.4761-1.9697 0-3.7702-0.34712-5.4013-1.0414-1.6312-0.69425-3.0392-1.7819-4.2241-3.263s-2.1082-3.3709-2.7699-5.6697c-0.66171-2.2987-0.99255-5.0525-0.99255-8.2615 0-2.777 0.29238-5.4845 0.87714-8.1227 0.58476-2.6381 1.4003-5.1143 2.4468-7.4284s2.2929-4.4354 3.7394-6.3639c1.4465-1.9285 3.0392-3.5792 4.7781-4.9523 1.7389-1.3731 3.5778-2.4453 5.5168-3.2167s3.9394-1.1571 6.0015-1.1571c1.9697 0 3.7471 0.33169 5.3321 0.99508 1.585 0.66339 2.9777 1.535 4.178 2.615l3.0469-24.16h14.034l-8.5867 69.286h-7.6634zm-14.588-10.182c0.98486 0 2.0082-0.37026 3.07-1.1108s2.0928-1.7587 3.0931-3.0547 1.9312-2.8155 2.793-4.5589c0.86176-1.7433 1.6004-3.6178 2.2159-5.6234l1.4773-11.663c-0.89253-0.70968-1.8851-1.2188-2.9777-1.5273s-2.1313-0.46283-3.1162-0.46283c-1.662 0-3.1931 0.55539-4.5934 1.6662s-2.6083 2.5687-3.624 4.3737c-1.0156 1.805-1.8081 3.8646-2.3775 6.1788s-0.85406 4.6746-0.85406 7.0813c0 3.0547 0.44626 5.2685 1.3388 6.6416 0.89253 1.3731 2.0774 2.0596 3.5547 2.0596zm63.465-27.724c-0.43088 0.5554-0.83097 0.95651-1.2003 1.2034s-0.86175 0.37026-1.4773 0.37026-1.2234-0.13885-1.8235-0.41655-1.2465-0.59396-1.9389-0.9488c-0.69248-0.35484-1.4773-0.6711-2.3544-0.9488-0.87714-0.2777-1.8851-0.41655-3.0238-0.41655-2.1236 0-3.6394 0.40883-4.5473 1.2265-0.90792 0.81767-1.3619 1.8745-1.3619 3.1704 0 0.8331 0.25391 1.5428 0.76173 2.129 0.50782 0.58625 1.1772 1.1108 2.0082 1.5736 0.83098 0.46283 1.7774 0.88709 2.8392 1.2728 1.0618 0.38569 2.1467 0.81766 3.2547 1.2959 1.108 0.47826 2.1928 1.0259 3.2547 1.643s2.0082 1.3731 2.8392 2.2679c0.83098 0.89481 1.5004 1.9593 2.0082 3.1935 0.50782 1.2342 0.76173 2.6998 0.76173 4.3969 0 2.4067-0.47704 4.6823-1.4311 6.8267-0.95409 2.1445-2.3236 4.0112-4.1087 5.6002-1.7851 1.5891-3.9471 2.8541-6.4862 3.7952-2.5391 0.94109-5.3936 1.4116-8.5637 1.4116-1.5081 0-3.0007-0.15428-4.478-0.46283-1.4773-0.30856-2.8699-0.7251-4.178-1.2496s-2.5006-1.1494-3.5778-1.8745c-1.0772-0.7251-1.9543-1.5042-2.6314-2.3373l3.5086-5.2763c0.43088-0.61711 0.931-1.1031 1.5004-1.4579 0.56938-0.35484 1.2695-0.53225 2.1005-0.53225 0.76942 0 1.4311 0.18513 1.9851 0.5554 0.55399 0.37027 1.1541 0.77138 1.8004 1.2034s1.4157 0.83309 2.3083 1.2034c0.89253 0.37027 2.062 0.5554 3.5086 0.5554 2.0313 0 3.5393-0.45511 4.5242-1.3653 0.98486-0.91024 1.4773-1.9824 1.4773-3.2167 0-0.95652-0.25391-1.7433-0.76173-2.3604-0.50782-0.61711-1.1772-1.1494-2.0082-1.5968-0.83098-0.4474-1.7697-0.84852-2.8161-1.2034-1.0464-0.35484-2.1236-0.74824-3.2316-1.1802s-2.1852-0.93337-3.2316-1.5042c-1.0464-0.57083-1.9851-1.2882-2.8161-2.1522-0.83098-0.86395-1.5004-1.9285-2.0082-3.1935-0.50782-1.2651-0.76173-2.7924-0.76173-4.582 0-2.2216 0.40779-4.3814 1.2234-6.4796s2.0313-3.9572 3.6471-5.5771c1.6158-1.6199 3.624-2.9235 6.0246-3.9109s5.2013-1.4811 8.4021-1.4811c3.2008 0 6.0553 0.55539 8.5637 1.6662 2.5083 1.1108 4.578 2.4684 6.2092 4.0729l-3.6932 5.0911z" fill="#fff"/> <g transform="translate(128.86 3.5426)" fill="#fff"> <path d="m14.411 3.7958h-8.3873l-0.77821 6.399h7.0759l-0.3891 3.0104h-7.0471l-1.052 8.6095h-3.7613l2.5652-21.029h12.149l-0.37469 3.0104zm-0.59086 18.019 1.8014-14.936h1.8014c0.34587 0 0.62929 0.077562 0.85026 0.23269 0.22097 0.15513 0.33146 0.40236 0.33146 0.7417v0.050901c0 0.033934-0.0048037 0.13331-0.014411 0.29813s-0.019215 0.42417-0.028822 0.77806c-0.0096075 0.35388-0.028822 0.85077-0.057645 1.4907 0.60527-1.1732 1.2682-2.0797 1.9887-2.7196 0.72056-0.6399 1.4699-0.95985 2.2482-0.95985 0.39391 0 0.79262 0.087258 1.1961 0.26178l-0.6485 3.4322c-0.48038-0.2036-0.93673-0.30541-1.3691-0.30541-0.85507 0-1.6044 0.41205-2.2482 1.2362-0.6437 0.82411-1.1721 2.1136-1.5852 3.8685l-0.77821 6.5299h-3.4875zm16.083-14.921-1.7726 14.921h-3.5163l1.7726-14.921h3.5163zm0.8935-4.3484c0 0.31025-0.06485 0.60111-0.19455 0.87259-0.1297 0.27147-0.29783 0.50901-0.50439 0.71261-0.20656 0.2036-0.44434 0.366-0.71336 0.48719-0.26901 0.12119-0.54762 0.18179-0.83585 0.18179-0.27862 0-0.55003-0.060596-0.81423-0.18179-0.26421-0.12119-0.49719-0.28359-0.69894-0.48719s-0.36268-0.44114-0.48278-0.71261c-0.12009-0.27147-0.18014-0.56233-0.18014-0.87259s0.062448-0.60596 0.18735-0.88713 0.28822-0.52597 0.48998-0.73443c0.20176-0.20845 0.43474-0.37327 0.69894-0.49447 0.26421-0.12119 0.53562-0.18179 0.81423-0.18179 0.28823 0 0.56684 0.060596 0.83585 0.18179 0.26901 0.12119 0.50679 0.28359 0.71336 0.48719 0.20656 0.2036 0.37229 0.44599 0.49719 0.72716s0.18735 0.58172 0.18735 0.90167zm13.402 7.8097c0 0.66899-0.1321 1.2798-0.39631 1.8324-0.26421 0.55264-0.73737 1.0471-1.4195 1.4834-0.68213 0.4363-1.6068 0.81199-2.7742 1.1271-1.1673 0.3151-2.6541 0.56476-4.4603 0.74897v0.18906c0 2.3463 0.98476 3.5194 2.9543 3.5194 0.42273 0 0.79742-0.041205 1.1241-0.12362s0.61248-0.18179 0.85747-0.29813 0.46596-0.24723 0.66292-0.39266c0.19695-0.14543 0.37949-0.27632 0.54763-0.39266 0.16813-0.11635 0.33386-0.21572 0.49719-0.29813 0.16333-0.082411 0.34106-0.12362 0.53322-0.12362 0.11529 0 0.23058 0.026662 0.34587 0.079987 0.11529 0.053325 0.21136 0.13331 0.28822 0.23996l0.90791 1.1053c-0.5092 0.51386-1.0088 0.95984-1.4988 1.338-0.48998 0.37812-0.98957 0.68837-1.4988 0.93076-0.5092 0.24239-1.0472 0.42175-1.6141 0.5381-0.56684 0.11635-1.1865 0.17452-1.859 0.17452-0.86468 0-1.6477-0.14785-2.349-0.44356-0.70135-0.29571-1.3018-0.71261-1.8014-1.2507-0.49959-0.5381-0.88629-1.1877-1.1601-1.9488-0.27381-0.76109-0.41072-1.6119-0.41072-2.5523 0-0.78533 0.084065-1.5561 0.2522-2.3124 0.16813-0.75625 0.41072-1.4737 0.72777-2.1524 0.31705-0.67868 0.70615-1.304 1.1673-1.8761 0.46116-0.57203 0.98236-1.0665 1.5636-1.4834 0.58126-0.4169 1.2201-0.7417 1.9167-0.97439 0.69655-0.23269 1.4435-0.34903 2.2409-0.34903 0.77821 0 1.4579 0.1115 2.0392 0.33449 0.58126 0.223 1.0664 0.51143 1.4555 0.86532 0.3891 0.35388 0.67973 0.74897 0.87188 1.1853 0.19215 0.4363 0.28822 0.86289 0.28822 1.2798zm-4.8566-1.1634c-0.48038 0-0.92712 0.099377-1.3402 0.29813-0.41312 0.19876-0.78541 0.4775-1.1169 0.83623-0.33146 0.35873-0.61968 0.78775-0.86467 1.2871-0.24499 0.49932-0.43954 1.0447-0.58365 1.6361 1.1913-0.16482 2.1497-0.34419 2.875-0.5381 0.72537-0.19391 1.2874-0.40721 1.6861-0.6399 0.39871-0.23269 0.66292-0.47992 0.79262-0.7417 0.1297-0.26178 0.19455-0.54294 0.19455-0.8435 0-0.14543-0.031224-0.29571-0.093673-0.45084-0.062449-0.15513-0.15852-0.29329-0.28822-0.41448-0.1297-0.12119-0.29783-0.22299-0.50439-0.30541-0.20656-0.082411-0.45876-0.12362-0.75659-0.12362zm6.0095 12.623 1.7726-14.936h1.8158c0.37469 0 0.66532 0.092105 0.87188 0.27632 0.20656 0.18421 0.30984 0.47992 0.30984 0.88713l-0.10088 1.9342c0.74939-1.115 1.5804-1.9464 2.4931-2.4941 0.91272-0.54779 1.8542-0.82169 2.8246-0.82169 0.54763 0 1.0448 0.099377 1.4916 0.29813s0.82864 0.48962 1.1457 0.87259 0.56204 0.85319 0.73497 1.4107c0.17294 0.55749 0.2594 1.1998 0.2594 1.927 0 0.18421-0.0072055 0.37085-0.021617 0.55991s-0.031224 0.38539-0.050439 0.589l-1.1097 9.4967h-3.5596c0.19215-1.6385 0.35548-3.0274 0.48998-4.1666 0.13451-1.1392 0.24499-2.0869 0.33146-2.8432 0.086468-0.75625 0.15372-1.3501 0.20176-1.7815 0.048038-0.43145 0.084065-0.75866 0.10808-0.98166 0.024019-0.223 0.03843-0.37085 0.043234-0.44356s0.0072056-0.13331 0.0072056-0.18179c0-0.6399-0.11529-1.1029-0.34587-1.3889s-0.59086-0.42902-1.0808-0.42902c-0.39391 0-0.80222 0.11634-1.225 0.34903-0.42273 0.23269-0.82624 0.56233-1.2105 0.98893-0.3843 0.4266-0.73497 0.94045-1.052 1.5416-0.31705 0.60112-0.57645 1.2701-0.77821 2.0069l-0.80703 7.3297h-3.5596zm25.738 0c-0.43234 0-0.73497-0.1018-0.90791-0.30541-0.17294-0.2036-0.2594-0.46053-0.2594-0.77078l0.11529-2.1815c-0.71096 1.0665-1.5084 1.9124-2.3923 2.5378-0.88389 0.62536-1.8254 0.93803-2.8246 0.93803-0.61488 0-1.1745-0.11392-1.6789-0.34176-0.5044-0.22784-0.93433-0.5696-1.2898-1.0253s-0.62929-1.0326-0.82144-1.7306c-0.19215-0.69807-0.28822-1.5222-0.28822-2.4723 0-0.8435 0.086466-1.67 0.2594-2.4796 0.17294-0.80957 0.41792-1.5779 0.73497-2.3051 0.31705-0.72716 0.69414-1.3961 1.1313-2.0069 0.43714-0.61081 0.92472-1.1392 1.4627-1.5852 0.53802-0.44599 1.1121-0.79502 1.7221-1.0471s1.2418-0.37812 1.8951-0.37812c0.66292 0 1.2634 0.12119 1.8014 0.36358 0.53802 0.24239 1.0088 0.57203 1.4123 0.98893l0.96555-7.8097h3.4875l-2.6373 21.611h-1.8879zm-4.8854-2.6032c-0.60527 0-1.076-0.2545-1.4123-0.76351-0.33626-0.50901-0.50439-1.2871-0.50439-2.3342 0-0.80472 0.10088-1.607 0.30264-2.4069 0.20176-0.79988 0.48758-1.5198 0.85747-2.1597 0.36989-0.6399 0.81423-1.1586 1.333-1.5561 0.51881-0.39751 1.0952-0.59627 1.7293-0.59627 0.40352 0 0.81663 0.072715 1.2394 0.21815s0.79742 0.39751 1.1241 0.75624l-0.44675 3.6212c-0.23058 0.73685-0.50679 1.4228-0.82865 2.0579-0.32185 0.63505-0.67012 1.1877-1.0448 1.6579-0.37469 0.47023-0.76379 0.83865-1.1673 1.1053s-0.79742 0.39994-1.1817 0.39994zm19.549-9.5612c-0.10501 0.15274-0.20525 0.26014-0.30071 0.32219-0.095464 0.062051-0.21956 0.093077-0.37231 0.093077-0.16229 0-0.32935-0.047731-0.50118-0.14319-0.17183-0.095464-0.36992-0.20286-0.59426-0.32219-0.22434-0.11933-0.48209-0.22672-0.77325-0.32219s-0.64199-0.14319-1.0525-0.14319c-0.75416 0-1.3317 0.16945-1.7327 0.50834-0.40095 0.3389-0.60142 0.76132-0.60142 1.2673 0 0.29594 0.083529 0.54653 0.25059 0.75177s0.38424 0.38424 0.65154 0.53698c0.2673 0.15274 0.57278 0.29355 0.91645 0.42242s0.69688 0.2673 1.0596 0.41526 0.71597 0.31503 1.0596 0.50118c0.34367 0.18615 0.64915 0.41288 0.91645 0.68017 0.2673 0.2673 0.48447 0.58948 0.65154 0.96656s0.25059 0.82814 0.25059 1.3532c0 0.70643-0.14081 1.3794-0.42242 2.019-0.28162 0.63961-0.68495 1.2004-1.21 1.6825-0.52505 0.48209-1.1599 0.86394-1.9045 1.1456-0.74462 0.28162-1.5751 0.42242-2.4916 0.42242-0.46777 0-0.91883-0.045344-1.3532-0.13603-0.43436-0.09069-0.84246-0.21718-1.2243-0.37947-0.38185-0.16229-0.7279-0.35321-1.0382-0.57278-0.31026-0.21957-0.57516-0.45822-0.79473-0.71597l0.85917-1.346c0.10501-0.16229 0.2315-0.28639 0.37947-0.37231 0.14797-0.085917 0.32219-0.12888 0.52266-0.12888s0.38185 0.06205 0.54414 0.18615c0.16229 0.1241 0.35321 0.26014 0.57278 0.4081s0.48447 0.284 0.79473 0.4081 0.70881 0.18615 1.1957 0.18615c0.3914 0 0.73745-0.052504 1.0382-0.15751 0.30071-0.10501 0.55369-0.2482 0.75893-0.42958 0.20525-0.18138 0.36037-0.3914 0.46538-0.63006 0.10501-0.23866 0.15751-0.49163 0.15751-0.75893 0-0.32458-0.081143-0.59426-0.24343-0.80905-0.16229-0.21479-0.37946-0.40094-0.65154-0.55846-0.27207-0.15751-0.57994-0.29594-0.92361-0.41526s-0.69449-0.24582-1.0525-0.37947c-0.35799-0.13365-0.70643-0.28639-1.0453-0.45822s-0.64437-0.38901-0.91645-0.65154c-0.27207-0.26252-0.48925-0.58232-0.65154-0.9594-0.16229-0.37708-0.24343-0.83769-0.24343-1.3818 0-0.64915 0.1241-1.2816 0.37231-1.8973 0.24821-0.61574 0.61335-1.1599 1.0954-1.6324 0.48209-0.47254 1.074-0.85201 1.7756-1.1384 0.70166-0.28639 1.5059-0.42958 2.4128-0.42958 0.93554 0 1.7637 0.1599 2.4844 0.4797 0.72075 0.3198 1.3293 0.7279 1.8257 1.2243l-0.91645 1.2888z"/> <path d="m57.693 40.297c0.49639 0 0.94473-0.14341 1.345-0.43023 0.40031-0.28682 0.74258-0.6706 1.0268-1.1513 0.28422-0.48073 0.50239-1.0402 0.65451-1.6785 0.15212-0.63828 0.22818-1.3089 0.22818-2.0118 0-1.0099-0.17013-1.7533-0.5104-2.2299-0.34027-0.47669-0.85466-0.71504-1.5432-0.71504-0.49639 0-0.94473 0.14139-1.345 0.42417s-0.74058 0.66656-1.0208 1.1513c-0.28022 0.48477-0.49639 1.0463-0.6485 1.6846-0.15212 0.63828-0.22818 1.3129-0.22818 2.0239 0 1.0099 0.16813 1.7512 0.50439 2.2239s0.84866 0.70898 1.5372 0.70898zm-0.26421 2.3027c-0.68053 0-1.311-0.11513-1.8915-0.3454s-1.0808-0.56758-1.5012-1.012-0.75058-0.98974-0.99077-1.6361c-0.24019-0.64636-0.36028-1.3856-0.36028-2.2178 0-1.0746 0.17013-2.0764 0.5104-3.0056 0.34027-0.92915 0.80462-1.7331 1.3931-2.4117 0.58846-0.67868 1.275-1.2119 2.0596-1.5997 0.78461-0.38782 1.6213-0.58172 2.51-0.58172 0.68053 0 1.311 0.11513 1.8915 0.3454s1.0828 0.56758 1.5072 1.012c0.42433 0.44438 0.75659 0.98974 0.99678 1.6361 0.24019 0.64636 0.36028 1.3856 0.36028 2.2178 0 1.0665-0.17213 2.0623-0.5164 2.9874-0.34427 0.92511-0.81063 1.729-1.3991 2.4117-0.58846 0.68272-1.275 1.22-2.0596 1.6119-0.78461 0.39186-1.6213 0.58778-2.51 0.58778zm12.177-10.374-1.1649 9.6833-0.61248 2.2784c-0.11209 0.3959-0.28622 0.69888-0.52241 0.90894-0.23619 0.21007-0.57044 0.3151-1.0028 0.3151h-1.1889l1.5732-13.186-0.94874-0.16967c-0.17614-0.032318-0.32025-0.098973-0.43234-0.19997-0.11209-0.10099-0.16813-0.2444-0.16813-0.43023 0-0.0080796 0.0020015-0.024238 0.0060047-0.048477 0.0040031-0.024239 0.010008-0.078775 0.018014-0.16361 0.0080063-0.084835 0.022017-0.21411 0.042033-0.38782 0.020016-0.17371 0.050039-0.41811 0.09007-0.73322h1.6573l0.10808-0.92106c0.088069-0.711 0.27421-1.3493 0.55843-1.9148 0.28422-0.56557 0.6445-1.0463 1.0808-1.4422 0.43634-0.3959 0.93873-0.69888 1.5072-0.90894 0.56845-0.21007 1.1809-0.3151 1.8374-0.3151 0.5124 0 0.98476 0.076755 1.4171 0.23027l-0.26421 1.5513c-0.016013 0.088875-0.054042 0.15957-0.11409 0.21209-0.060047 0.052517-0.1341 0.090894-0.22217 0.11513s-0.18614 0.040398-0.29423 0.048477c-0.10808 0.0080796-0.21817 0.012119-0.33026 0.012119-0.32025 0-0.61448 0.044437-0.88269 0.13331s-0.50439 0.23228-0.70855 0.43023c-0.20416 0.19795-0.37229 0.45649-0.50439 0.77563-0.1321 0.31914-0.22618 0.70897-0.28222 1.1695l-0.096075 0.82411h2.7622l-0.27622 2.133h-2.6421z"/> </g> </g> </svg>
1192
- </div>
1193
- <div class="pods-admin_friends-callout_content-container">
1194
- <h2 class="pods-admin_friends-callout_headline"><?php printf( esc_html__( 'We need %1$sYOU%2$s in 2020 and beyond', 'pods' ), '<span class="pods-admin_friends-you">', '</span>' ); ?></h2>
1195
- <p class="pods-admin_friends-callout_text"><?php esc_html_e( 'Things are changing for Pods and we want you to be a part of it! Our goal is to be fully funded by users like you. Help us reach our goal of 200 recurring donors in 2020.', 'pods' ); ?></p>
1196
- <div class="pods-admin_friends-callout_button-group">
1197
- <a href="https://friends.pods.io/?utm_source=pods_plugin_callout&utm_medium=link&utm_campaign=friends_of_pods_2020" class="pods-admin_friends-callout_button"><?php esc_html_e( 'Learn More', 'pods' ); ?></a>
1198
- <a href="https://friends.pods.io/membership-levels/?utm_source=pods_plugin_callout&utm_medium=link&utm_campaign=friends_of_pods_2020" class="pods-admin_friends-callout_button--join"><?php esc_html_e( 'Join Now', 'pods' ); ?></a>
1199
- </div>
1200
- </div>
1201
- </div>
1202
- <?php
1203
- }
1204
- }
1205
-
1206
- /**
1207
- * Get the add page of an object
1208
- *
1209
- * @param PodsUI $obj PodsUI object.
1210
- */
1211
- public function admin_setup_add( $obj ) {
1212
-
1213
- pods_view( PODS_DIR . 'ui/admin/setup-add.php', compact( array_keys( get_defined_vars() ) ) );
1214
- }
1215
-
1216
- /**
1217
- * Get the edit page of an object
1218
- *
1219
- * @param boolean $duplicate Whether the screen is for duplicating.
1220
- * @param PodsUI $obj PodsUI object.
1221
- */
1222
- public function admin_setup_edit( $duplicate, $obj ) {
1223
-
1224
- pods_view( PODS_DIR . 'ui/admin/setup-edit.php', compact( array_keys( get_defined_vars() ) ) );
1225
- }
1226
-
1227
- /**
1228
- * Get list of Pod option tabs
1229
- *
1230
- * @param array $pod Pod options.
1231
- *
1232
- * @return array
1233
- */
1234
- public function admin_setup_edit_tabs( $pod ) {
1235
-
1236
- $fields = true;
1237
- $labels = false;
1238
- $admin_ui = false;
1239
- $advanced = false;
1240
-
1241
- if ( 'post_type' === pods_v( 'type', $pod ) && '' === pods_v( 'object', $pod ) ) {
1242
- $labels = true;
1243
- $admin_ui = true;
1244
- $advanced = true;
1245
- } elseif ( 'taxonomy' === pods_v( 'type', $pod ) && '' === pods_v( 'object', $pod ) ) {
1246
- $labels = true;
1247
- $admin_ui = true;
1248
- $advanced = true;
1249
- } elseif ( 'pod' === pods_v( 'type', $pod ) ) {
1250
- $labels = true;
1251
- $admin_ui = true;
1252
- $advanced = true;
1253
- } elseif ( 'settings' === pods_v( 'type', $pod ) ) {
1254
- $labels = true;
1255
- $admin_ui = true;
1256
- }
1257
-
1258
- if ( ! function_exists( 'get_term_meta' ) && 'none' === pods_v( 'storage', $pod, 'none', true ) && 'taxonomy' === pods_v( 'type', $pod ) ) {
1259
- $fields = false;
1260
- }
1261
-
1262
- $tabs = array();
1263
-
1264
- if ( $fields ) {
1265
- $tabs['manage-fields'] = __( 'Manage Fields', 'pods' );
1266
- }
1267
-
1268
- if ( $labels ) {
1269
- $tabs['labels'] = __( 'Labels', 'pods' );
1270
- }
1271
-
1272
- if ( $admin_ui ) {
1273
- $tabs['admin-ui'] = __( 'Admin UI', 'pods' );
1274
- }
1275
-
1276
- if ( $advanced ) {
1277
- $tabs['advanced'] = __( 'Advanced Options', 'pods' );
1278
- }
1279
-
1280
- if ( 'taxonomy' === pods_v( 'type', $pod ) && ! $fields ) {
1281
- $tabs['extra-fields'] = __( 'Extra Fields', 'pods' );
1282
- }
1283
-
1284
- $addtl_args = compact( array( 'fields', 'labels', 'admin_ui', 'advanced' ) );
1285
-
1286
- $pod_type = $pod['type'];
1287
- $pod_name = $pod['name'];
1288
-
1289
- /**
1290
- * Add or modify tabs in Pods editor for a specific Pod
1291
- *
1292
- * @param array $tabs Tabs to set.
1293
- * @param object $pod Current Pods object.
1294
- * @param array $addtl_args Additional args.
1295
- *
1296
- * @since unknown
1297
- */
1298
- $tabs = apply_filters( "pods_admin_setup_edit_tabs_{$pod_type}_{$pod_name}", $tabs, $pod, $addtl_args );
1299
-
1300
- /**
1301
- * Add or modify tabs for any Pod in Pods editor of a specific post type.
1302
- */
1303
- $tabs = apply_filters( "pods_admin_setup_edit_tabs_{$pod_type}", $tabs, $pod, $addtl_args );
1304
-
1305
- /**
1306
- * Add or modify tabs in Pods editor for all pods.
1307
- */
1308
- $tabs = apply_filters( 'pods_admin_setup_edit_tabs', $tabs, $pod, $addtl_args );
1309
-
1310
- return $tabs;
1311
- }
1312
-
1313
- /**
1314
- * Get list of Pod options
1315
- *
1316
- * @param array $pod Pod options.
1317
- *
1318
- * @return array
1319
- */
1320
- public function admin_setup_edit_options( $pod ) {
1321
-
1322
- $options = array();
1323
-
1324
- if ( '' === pods_v( 'object', $pod ) && 'settings' !== pods_v( 'type', $pod ) ) {
1325
- $labels = array(
1326
- 'label' => array(
1327
- 'label' => __( 'Label', 'pods' ),
1328
- 'help' => __( 'help', 'pods' ),
1329
- 'type' => 'text',
1330
- 'default' => str_replace( '_', ' ', pods_v( 'name', $pod ) ),
1331
- 'text_max_length' => 30,
1332
- ),
1333
- 'label_singular' => array(
1334
- 'label' => __( 'Singular Label', 'pods' ),
1335
- 'help' => __( 'help', 'pods' ),
1336
- 'type' => 'text',
1337
- 'default' => pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', pods_v( 'name', $pod ) ) ) ),
1338
- 'text_max_length' => 30,
1339
- ),
1340
- 'label_add_new' => array(
1341
- 'label' => __( 'Add New', 'pods' ),
1342
- 'help' => __( 'help', 'pods' ),
1343
- 'type' => 'text',
1344
- 'default' => '',
1345
- 'object_type' => array( 'post_type', 'pod' ),
1346
- ),
1347
- 'label_add_new_item' => array(
1348
- 'label' => __( 'Add new <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1349
- 'help' => __( 'help', 'pods' ),
1350
- 'type' => 'text',
1351
- 'default' => '',
1352
- ),
1353
- 'label_new_item' => array(
1354
- 'label' => __( 'New <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1355
- 'help' => __( 'help', 'pods' ),
1356
- 'type' => 'text',
1357
- 'default' => '',
1358
- 'object_type' => array( 'post_type', 'pod' ),
1359
- ),
1360
- 'label_new_item_name' => array(
1361
- 'label' => __( 'New <span class="pods-slugged" data-sluggable="label_singular">Item</span> Name', 'pods' ),
1362
- 'help' => __( 'help', 'pods' ),
1363
- 'type' => 'text',
1364
- 'default' => '',
1365
- 'object_type' => array( 'taxonomy' ),
1366
- ),
1367
- 'label_edit' => array(
1368
- 'label' => __( 'Edit', 'pods' ),
1369
- 'help' => __( 'help', 'pods' ),
1370
- 'type' => 'text',
1371
- 'default' => '',
1372
- 'object_type' => array( 'pod' ),
1373
- ),
1374
- 'label_edit_item' => array(
1375
- 'label' => __( 'Edit <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1376
- 'help' => __( 'help', 'pods' ),
1377
- 'type' => 'text',
1378
- 'default' => '',
1379
- ),
1380
- 'label_update_item' => array(
1381
- 'label' => __( 'Update <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1382
- 'help' => __( 'help', 'pods' ),
1383
- 'type' => 'text',
1384
- 'default' => '',
1385
- 'object_type' => array( 'taxonomy', 'pod' ),
1386
- ),
1387
- 'label_duplicate' => array(
1388
- 'label' => __( 'Duplicate', 'pods' ),
1389
- 'help' => __( 'help', 'pods' ),
1390
- 'type' => 'text',
1391
- 'default' => '',
1392
- 'object_type' => array( 'pod' ),
1393
- ),
1394
- 'label_duplicate_item' => array(
1395
- 'label' => __( 'Duplicate <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1396
- 'help' => __( 'help', 'pods' ),
1397
- 'type' => 'text',
1398
- 'default' => '',
1399
- 'object_type' => array( 'pod' ),
1400
- ),
1401
- 'label_delete_item' => array(
1402
- 'label' => __( 'Delete <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1403
- 'help' => __( 'help', 'pods' ),
1404
- 'type' => 'text',
1405
- 'default' => '',
1406
- 'object_type' => array( 'pod' ),
1407
- ),
1408
- 'label_view' => array(
1409
- 'label' => __( 'View', 'pods' ),
1410
- 'help' => __( 'help', 'pods' ),
1411
- 'type' => 'text',
1412
- 'default' => '',
1413
- 'object_type' => array( 'pod' ),
1414
- ),
1415
- 'label_view_item' => array(
1416
- 'label' => __( 'View <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1417
- 'help' => __( 'help', 'pods' ),
1418
- 'type' => 'text',
1419
- 'default' => '',
1420
- ),
1421
- 'label_view_items' => array(
1422
- 'label' => __( 'View <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1423
- 'help' => __( 'help', 'pods' ),
1424
- 'type' => 'text',
1425
- 'default' => '',
1426
- 'object_type' => array( 'post_type' ),
1427
- ),
1428
- 'label_back_to_manage' => array(
1429
- 'label' => __( 'Back to Manage', 'pods' ),
1430
- 'help' => __( 'help', 'pods' ),
1431
- 'type' => 'text',
1432
- 'default' => '',
1433
- 'object_type' => array( 'pod' ),
1434
- ),
1435
- 'label_manage' => array(
1436
- 'label' => __( 'Manage', 'pods' ),
1437
- 'help' => __( 'help', 'pods' ),
1438
- 'type' => 'text',
1439
- 'default' => '',
1440
- 'object_type' => array( 'pod' ),
1441
- ),
1442
- 'label_manage_items' => array(
1443
- 'label' => __( 'Manage <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1444
- 'help' => __( 'help', 'pods' ),
1445
- 'type' => 'text',
1446
- 'default' => '',
1447
- 'object_type' => array( 'pod' ),
1448
- ),
1449
- 'label_reorder' => array(
1450
- 'label' => __( 'Reorder', 'pods' ),
1451
- 'help' => __( 'help', 'pods' ),
1452
- 'type' => 'text',
1453
- 'default' => '',
1454
- 'object_type' => array( 'pod' ),
1455
- ),
1456
- 'label_reorder_items' => array(
1457
- 'label' => __( 'Reorder <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1458
- 'help' => __( 'help', 'pods' ),
1459
- 'type' => 'text',
1460
- 'default' => '',
1461
- 'object_type' => array( 'pod' ),
1462
- ),
1463
- 'label_all_items' => array(
1464
- 'label' => __( 'All <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1465
- 'help' => __( 'help', 'pods' ),
1466
- 'type' => 'text',
1467
- 'default' => '',
1468
- ),
1469
- 'label_search' => array(
1470
- 'label' => __( 'Search', 'pods' ),
1471
- 'help' => __( 'help', 'pods' ),
1472
- 'type' => 'text',
1473
- 'default' => '',
1474
- 'object_type' => array( 'pod' ),
1475
- ),
1476
- 'label_search_items' => array(
1477
- 'label' => __( 'Search <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1478
- 'help' => __( 'help', 'pods' ),
1479
- 'type' => 'text',
1480
- 'default' => '',
1481
- ),
1482
- 'label_popular_items' => array(
1483
- 'label' => __( 'Popular <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1484
- 'help' => __( 'help', 'pods' ),
1485
- 'type' => 'text',
1486
- 'default' => '',
1487
- 'object_type' => array( 'taxonomy' ),
1488
- ),
1489
- // @todo Why was label_parent added previously? Can't find it in WP
1490
- 'label_parent' => array(
1491
- 'label' => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1492
- 'help' => __( 'help', 'pods' ),
1493
- 'type' => 'text',
1494
- 'default' => '',
1495
- 'object_type' => array( 'post_type', 'pod' ),
1496
- ),
1497
- 'label_parent_item' => array(
1498
- 'label' => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1499
- 'help' => __( 'help', 'pods' ),
1500
- 'type' => 'text',
1501
- 'default' => '',
1502
- 'object_type' => array( 'taxonomy' ),
1503
- ),
1504
- 'label_parent_item_colon' => array(
1505
- 'label' => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>:', 'pods' ),
1506
- 'help' => __( 'help', 'pods' ),
1507
- 'type' => 'text',
1508
- 'default' => '',
1509
- ),
1510
- 'label_not_found' => array(
1511
- 'label' => __( 'Not Found', 'pods' ),
1512
- 'help' => __( 'help', 'pods' ),
1513
- 'type' => 'text',
1514
- 'default' => '',
1515
- ),
1516
- 'label_no_items_found' => array(
1517
- 'label' => __( 'No <span class="pods-slugged" data-sluggable="label_singular">Item</span> Found', 'pods' ),
1518
- 'help' => __( 'help', 'pods' ),
1519
- 'type' => 'text',
1520
- 'default' => '',
1521
- 'object_type' => array( 'pod' ),
1522
- ),
1523
- 'label_not_found_in_trash' => array(
1524
- 'label' => __( 'Not Found in Trash', 'pods' ),
1525
- 'help' => __( 'help', 'pods' ),
1526
- 'type' => 'text',
1527
- 'default' => '',
1528
- 'object_type' => array( 'post_type', 'pod' ),
1529
- ),
1530
- 'label_archives' => array(
1531
- 'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Archives', 'pods' ),
1532
- 'help' => __( 'help', 'pods' ),
1533
- 'type' => 'text',
1534
- 'default' => '',
1535
- 'object_type' => array( 'post_type' ),
1536
- ),
1537
- 'label_attributes' => array(
1538
- 'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Attributes', 'pods' ),
1539
- 'help' => __( 'help', 'pods' ),
1540
- 'type' => 'text',
1541
- 'default' => '',
1542
- 'object_type' => array( 'post_type' ),
1543
- ),
1544
- 'label_insert_into_item' => array(
1545
- 'label' => __( 'Insert into <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1546
- 'help' => __( 'help', 'pods' ),
1547
- 'type' => 'text',
1548
- 'default' => '',
1549
- 'object_type' => array( 'post_type' ),
1550
- ),
1551
- 'label_uploaded_to_this_item' => array(
1552
- 'label' => __( 'Uploaded to this <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1553
- 'help' => __( 'help', 'pods' ),
1554
- 'type' => 'text',
1555
- 'default' => '',
1556
- 'object_type' => array( 'post_type' ),
1557
- ),
1558
- 'label_featured_image' => array(
1559
- 'label' => __( 'Featured Image', 'pods' ),
1560
- 'help' => __( 'help', 'pods' ),
1561
- 'type' => 'text',
1562
- 'default' => '',
1563
- // 'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
1564
- 'object_type' => array( 'post_type' ),
1565
- ),
1566
- 'label_set_featured_image' => array(
1567
- 'label' => __( 'Set featured Image', 'pods' ),
1568
- 'help' => __( 'help', 'pods' ),
1569
- 'type' => 'text',
1570
- 'default' => '',
1571
- // 'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
1572
- 'object_type' => array( 'post_type' ),
1573
- ),
1574
- 'label_remove_featured_image' => array(
1575
- 'label' => __( 'Remove featured Image', 'pods' ),
1576
- 'help' => __( 'help', 'pods' ),
1577
- 'type' => 'text',
1578
- 'default' => '',
1579
- // 'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
1580
- 'object_type' => array( 'post_type' ),
1581
- ),
1582
- 'label_use_featured_image' => array(
1583
- 'label' => __( 'Use as featured Image', 'pods' ),
1584
- 'help' => __( 'help', 'pods' ),
1585
- 'type' => 'text',
1586
- 'default' => '',
1587
- // 'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
1588
- 'object_type' => array( 'post_type' ),
1589
- ),
1590
- 'label_filter_items_list' => array(
1591
- 'label' => __( 'Filter <span class="pods-slugged" data-sluggable="label">Items</span> lists', 'pods' ),
1592
- 'help' => __( 'help', 'pods' ),
1593
- 'type' => 'text',
1594
- 'default' => '',
1595
- 'object_type' => array( 'post_type' ),
1596
- ),
1597
- 'label_items_list_navigation' => array(
1598
- 'label' => __( '<span class="pods-slugged" data-sluggable="label">Items</span> list navigation', 'pods' ),
1599
- 'help' => __( 'help', 'pods' ),
1600
- 'type' => 'text',
1601
- 'default' => '',
1602
- 'object_type' => array( 'post_type', 'taxonomy' ),
1603
- ),
1604
- 'label_items_list' => array(
1605
- 'label' => __( '<span class="pods-slugged" data-sluggable="label">Items</span> list', 'pods' ),
1606
- 'help' => __( 'help', 'pods' ),
1607
- 'type' => 'text',
1608
- 'default' => '',
1609
- 'object_type' => array( 'post_type', 'taxonomy' ),
1610
- ),
1611
- 'label_separate_items_with_commas' => array(
1612
- 'label' => __( 'Separate <span class="pods-slugged-lower" data-sluggable="label">items</span> with commas', 'pods' ),
1613
- 'help' => __( 'help', 'pods' ),
1614
- 'type' => 'text',
1615
- 'default' => '',
1616
- 'object_type' => array( 'taxonomy' ),
1617
- ),
1618
- 'label_add_or_remove_items' => array(
1619
- 'label' => __( 'Add or remove <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ),
1620
- 'help' => __( 'help', 'pods' ),
1621
- 'type' => 'text',
1622
- 'default' => '',
1623
- 'object_type' => array( 'taxonomy' ),
1624
- ),
1625
- 'label_choose_from_the_most_used' => array(
1626
- 'label' => __( 'Choose from the most used <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ),
1627
- 'help' => __( 'help', 'pods' ),
1628
- 'type' => 'text',
1629
- 'default' => '',
1630
- 'object_type' => array( 'taxonomy' ),
1631
- ),
1632
- 'label_no_terms' => array(
1633
- 'label' => __( 'No <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ),
1634
- 'help' => __( 'help', 'pods' ),
1635
- 'type' => 'text',
1636
- 'default' => '',
1637
- 'object_type' => array( 'taxonomy' ),
1638
- ),
1639
- 'label_item_published' => array(
1640
- 'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Published.', 'pods' ),
1641
- 'help' => __( 'help', 'pods' ),
1642
- 'type' => 'text',
1643
- 'default' => '',
1644
- 'object_type' => array( 'post_type' ),
1645
- ),
1646
- 'label_item_published_privately' => array(
1647
- 'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> published privately.', 'pods' ),
1648
- 'help' => __( 'help', 'pods' ),
1649
- 'type' => 'text',
1650
- 'default' => '',
1651
- 'object_type' => array( 'post_type' ),
1652
- ),
1653
- 'label_item_reverted_to_draft' => array(
1654
- 'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> reverted to draft.', 'pods' ),
1655
- 'help' => __( 'help', 'pods' ),
1656
- 'type' => 'text',
1657
- 'default' => '',
1658
- 'object_type' => array( 'post_type' ),
1659
- ),
1660
- 'label_item_scheduled' => array(
1661
- 'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> scheduled.', 'pods' ),
1662
- 'help' => __( 'help', 'pods' ),
1663
- 'type' => 'text',
1664
- 'default' => '',
1665
- 'object_type' => array( 'post_type' ),
1666
- ),
1667
- 'label_item_updated' => array(
1668
- 'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> updated.', 'pods' ),
1669
- 'help' => __( 'help', 'pods' ),
1670
- 'type' => 'text',
1671
- 'default' => '',
1672
- 'object_type' => array( 'post_type' ),
1673
- ),
1674
- );
1675
-
1676
- $options['labels'] = array();
1677
-
1678
- /**
1679
- * Filter through all labels if they have an object_type set and match it against the current object type
1680
- */
1681
- foreach ( $labels as $label => $labeldata ) {
1682
- if ( array_key_exists( 'object_type', $labeldata ) ) {
1683
- if ( in_array( pods_v( 'type', $pod ), $labeldata['object_type'], true ) ) {
1684
- // Do not add the object_type to the actual label data
1685
- unset( $labeldata['object_type'] );
1686
- $options['labels'][ $label ] = $labeldata;
1687
- }
1688
- } else {
1689
- $options['labels'][ $label ] = $labeldata;
1690
- }
1691
- }
1692
- } elseif ( 'settings' === pods_v( 'type', $pod ) ) {
1693
-
1694
- $options['labels'] = array(
1695
- 'label' => array(
1696
- 'label' => __( 'Page Title', 'pods' ),
1697
- 'help' => __( 'help', 'pods' ),
1698
- 'type' => 'text',
1699
- 'default' => str_replace( '_', ' ', pods_v( 'name', $pod ) ),
1700
- 'text_max_length' => 30,
1701
- ),
1702
- 'menu_name' => array(
1703
- 'label' => __( 'Menu Name', 'pods' ),
1704
- 'help' => __( 'help', 'pods' ),
1705
- 'type' => 'text',
1706
- 'default' => pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', pods_v( 'name', $pod ) ) ) ),
1707
- 'text_max_length' => 30,
1708
- ),
1709
- );
1710
- }//end if
1711
-
1712
- if ( 'post_type' === $pod['type'] ) {
1713
- $options['admin-ui'] = array(
1714
- 'description' => array(
1715
- 'label' => __( 'Post Type Description', 'pods' ),
1716
- 'help' => __( 'A short descriptive summary of what the post type is.', 'pods' ),
1717
- 'type' => 'text',
1718
- 'default' => '',
1719
- ),
1720
- 'show_ui' => array(
1721
- 'label' => __( 'Show Admin UI', 'pods' ),
1722
- 'help' => __( 'Whether to generate a default UI for managing this post type in the admin.', 'pods' ),
1723
- 'type' => 'boolean',
1724
- 'default' => pods_v( 'public', $pod, true ),
1725
- 'boolean_yes_label' => '',
1726
- ),
1727
- 'show_in_menu' => array(
1728
- 'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
1729
- 'help' => __( 'Whether to show the post type in the admin menu.', 'pods' ),
1730
- 'type' => 'boolean',
1731
- 'default' => pods_v( 'public', $pod, true ),
1732
- 'dependency' => true,
1733
- 'boolean_yes_label' => '',
1734
- ),
1735
- 'menu_location_custom' => array(
1736
- 'label' => __( 'Parent Menu ID (optional)', 'pods' ),
1737
- 'help' => __( 'help', 'pods' ),
1738
- 'type' => 'text',
1739
- 'depends-on' => array( 'show_in_menu' => true ),
1740
- ),
1741
- 'menu_name' => array(
1742
- 'label' => __( 'Menu Name', 'pods' ),
1743
- 'help' => __( 'help', 'pods' ),
1744
- 'type' => 'text',
1745
- 'default' => '',
1746
- 'depends-on' => array( 'show_in_menu' => true ),
1747
- ),
1748
- 'menu_position' => array(
1749
- 'label' => __( 'Menu Position', 'pods' ),
1750
- 'help' => __( 'help', 'pods' ),
1751
- 'type' => 'number',
1752
- 'number_decimals' => 2,
1753
- 'number_format' => '9999.99',
1754
- 'number_format_soft' => 1,
1755
- 'default' => 0,
1756
- 'depends-on' => array( 'show_in_menu' => true ),
1757
- ),
1758
- 'menu_icon' => array(
1759
- 'label' => __( 'Menu Icon', 'pods' ),
1760
- 'help' => __( 'URL or Dashicon name for the menu icon. You may specify the path to the icon using one of the <a href="https://pods.io/docs/build/special-magic-tags/#site-tags" target="_blank" rel="noopener noreferrer">site tag</a> type <a href="https://pods.io/docs/build/special-magic-tags/" target="_blank" rel="noopener noreferrer">special magic tags</a>. For example, for a file in your theme directory, use "{@template-url}/path/to/image.png". You may also use the name of a <a href="https://developer.wordpress.org/resource/dashicons/" target="_blank" rel="noopener noreferrer">Dashicon</a>. For example, to use the empty star icon, use "dashicons-star-empty".', 'pods' ),
1761
- 'type' => 'text',
1762
- 'default' => '',
1763
- 'depends-on' => array( 'show_in_menu' => true ),
1764
- ),
1765
- 'show_in_nav_menus' => array(
1766
- 'label' => __( 'Show in Navigation Menus', 'pods' ),
1767
- 'help' => __( 'help', 'pods' ),
1768
- 'type' => 'boolean',
1769
- 'default' => true,
1770
- 'boolean_yes_label' => '',
1771
- ),
1772
- 'show_in_admin_bar' => array(
1773
- 'label' => __( 'Show in Admin Bar "New" Menu', 'pods' ),
1774
- 'help' => __( 'help', 'pods' ),
1775
- 'type' => 'boolean',
1776
- 'default' => true,
1777
- 'dependency' => true,
1778
- 'boolean_yes_label' => '',
1779
- ),
1780
- 'name_admin_bar' => array(
1781
- 'label' => __( 'Admin bar name', 'pods' ),
1782
- 'help' => __( 'Defaults to singular name', 'pods' ),
1783
- 'type' => 'text',
1784
- 'default' => '',
1785
- 'depends-on' => array( 'show_in_admin_bar' => true ),
1786
- ),
1787
- );
1788
-
1789
- $post_type_name = pods_v( 'name', $pod, 'post_type', true );
1790
-
1791
- $options['advanced'] = array(
1792
- 'public' => array(
1793
- 'label' => __( 'Public', 'pods' ),
1794
- 'help' => __( 'help', 'pods' ),
1795
- 'type' => 'boolean',
1796
- 'default' => true,
1797
- 'boolean_yes_label' => '',
1798
- ),
1799
- 'publicly_queryable' => array(
1800
- 'label' => __( 'Publicly Queryable', 'pods' ),
1801
- 'help' => __( 'help', 'pods' ),
1802
- 'type' => 'boolean',
1803
- 'default' => pods_v( 'public', $pod, true ),
1804
- 'boolean_yes_label' => '',
1805
- ),
1806
- 'exclude_from_search' => array(
1807
- 'label' => __( 'Exclude from Search', 'pods' ),
1808
- 'help' => __( 'help', 'pods' ),
1809
- 'type' => 'boolean',
1810
- 'default' => ! pods_v( 'public', $pod, true ),
1811
- 'boolean_yes_label' => '',
1812
- ),
1813
- 'capability_type' => array(
1814
- 'label' => __( 'User Capability', 'pods' ),
1815
- 'help' => __( 'Uses these capabilties for access to this post type: edit_{capability}, read_{capability}, and delete_{capability}', 'pods' ),
1816
- 'type' => 'pick',
1817
- 'default' => 'post',
1818
- 'data' => array(
1819
- 'post' => 'post',
1820
- 'page' => 'page',
1821
- 'custom' => __( 'Custom Capability', 'pods' ),
1822
- ),
1823
- 'dependency' => true,
1824
- ),
1825
- 'capability_type_custom' => array(
1826
- 'label' => __( 'Custom User Capability', 'pods' ),
1827
- 'help' => __( 'help', 'pods' ),
1828
- 'type' => 'text',
1829
- 'default' => pods_v( 'name', $pod ),
1830
- 'depends-on' => array( 'capability_type' => 'custom' ),
1831
- ),
1832
- 'capability_type_extra' => array(
1833
- 'label' => __( 'Additional User Capabilities', 'pods' ),
1834
- 'help' => __( 'Enables additional capabilities for this Post Type including: delete_{capability}s, delete_private_{capability}s, delete_published_{capability}s, delete_others_{capability}s, edit_private_{capability}s, and edit_published_{capability}s', 'pods' ),
1835
- 'type' => 'boolean',
1836
- 'default' => true,
1837
- 'boolean_yes_label' => '',
1838
- ),
1839
- 'has_archive' => array(
1840
- 'label' => __( 'Enable Archive Page', 'pods' ),
1841
- 'help' => __( 'If enabled, creates an archive page with list of of items in this custom post type. Functions like a category page for posts. Can be controlled with a template in your theme called "archive-{$post-type}.php".', 'pods' ),
1842
- 'type' => 'boolean',
1843
- 'default' => false,
1844
- 'dependency' => true,
1845
- 'boolean_yes_label' => '',
1846
- ),
1847
- 'has_archive_slug' => array(
1848
- 'label' => __( 'Archive Page Slug Override', 'pods' ),
1849
- 'help' => __( 'If archive page is enabled, you can override the slug used by WordPress, which defaults to the name of the post type.', 'pods' ),
1850
- 'type' => 'text',
1851
- 'default' => '',
1852
- 'depends-on' => array( 'has_archive' => true ),
1853
- ),
1854
- 'hierarchical' => array(
1855
- 'label' => __( 'Hierarchical', 'pods' ),
1856
- 'help' => __( 'Allows for parent/ child relationships between items, just like with Pages. Note: To edit relationships in the post editor, you must enable "Page Attributes" in the "Supports" section below.', 'pods' ),
1857
- 'type' => 'boolean',
1858
- 'default' => false,
1859
- 'dependency' => true,
1860
- 'boolean_yes_label' => '',
1861
- ),
1862
- 'label_parent_item_colon' => array(
1863
- 'label' => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1864
- 'help' => __( 'help', 'pods' ),
1865
- 'type' => 'text',
1866
- 'default' => '',
1867
- 'depends-on' => array( 'hierarchical' => true ),
1868
- ),
1869
- 'label_parent' => array(
1870
- 'label' => __( '<strong>Label: </strong> Parent', 'pods' ),
1871
- 'help' => __( 'help', 'pods' ),
1872
- 'type' => 'text',
1873
- 'default' => '',
1874
- 'depends-on' => array( 'hierarchical' => true ),
1875
- ),
1876
- 'rewrite' => array(
1877
- 'label' => __( 'Rewrite', 'pods' ),
1878
- 'help' => __( 'Allows you to use pretty permalinks, if set in WordPress Settings->Permalinks. If not enabled, your links will be in the form of "example.com/?pod_name=post_slug" regardless of your permalink settings.', 'pods' ),
1879
- 'type' => 'boolean',
1880
- 'default' => true,
1881
- 'dependency' => true,
1882
- 'boolean_yes_label' => '',
1883
- ),
1884
- 'rewrite_custom_slug' => array(
1885
- 'label' => __( 'Custom Rewrite Slug', 'pods' ),
1886
- 'help' => __( 'Changes the first segment of the URL, which by default is the name of the Pod. For example, if your Pod is called "foo", if this field is left blank, your link will be "example.com/foo/post_slug", but if you were to enter "bar" your link will be "example.com/bar/post_slug".', 'pods' ),
1887
- 'type' => 'text',
1888
- 'default' => '',
1889
- 'depends-on' => array( 'rewrite' => true ),
1890
- ),
1891
- 'rewrite_with_front' => array(
1892
- 'label' => __( 'Rewrite with Front', 'pods' ),
1893
- 'help' => __( 'Allows permalinks to be prepended with your front base (example: if your permalink structure is /blog/, then your links will be: Unchecked->/news/, Checked->/blog/news/)', 'pods' ),
1894
- 'type' => 'boolean',
1895
- 'default' => true,
1896
- 'depends-on' => array( 'rewrite' => true ),
1897
- 'boolean_yes_label' => '',
1898
- ),
1899
- 'rewrite_feeds' => array(
1900
- 'label' => __( 'Rewrite Feeds', 'pods' ),
1901
- 'help' => __( 'help', 'pods' ),
1902
- 'type' => 'boolean',
1903
- 'default' => false,
1904
- 'depends-on' => array( 'rewrite' => true ),
1905
- 'boolean_yes_label' => '',
1906
- ),
1907
- 'rewrite_pages' => array(
1908
- 'label' => __( 'Rewrite Pages', 'pods' ),
1909
- 'help' => __( 'help', 'pods' ),
1910
- 'type' => 'boolean',
1911
- 'default' => true,
1912
- 'depends-on' => array( 'rewrite' => true ),
1913
- 'boolean_yes_label' => '',
1914
- ),
1915
- 'query_var' => array(
1916
- 'label' => __( 'Query Var', 'pods' ),
1917
- 'help' => __( 'The Query Var is used in the URL and underneath the WordPress Rewrite API to tell WordPress what page or post type you are on. For a list of reserved Query Vars, read <a href="http://codex.wordpress.org/WordPress_Query_Vars">WordPress Query Vars</a> from the WordPress Codex.', 'pods' ),
1918
- 'type' => 'boolean',
1919
- 'default' => true,
1920
- 'boolean_yes_label' => '',
1921
- ),
1922
- 'can_export' => array(
1923
- 'label' => __( 'Exportable', 'pods' ),
1924
- 'help' => __( 'help', 'pods' ),
1925
- 'type' => 'boolean',
1926
- 'default' => true,
1927
- 'boolean_yes_label' => '',
1928
- ),
1929
- 'default_status' => array(
1930
- 'label' => __( 'Default Status', 'pods' ),
1931
- 'help' => __( 'help', 'pods' ),
1932
- 'type' => 'pick',
1933
- 'pick_object' => 'post-status',
1934
- 'default' => apply_filters( "pods_api_default_status_{$post_type_name}", 'draft', $pod ),
1935
- ),
1936
- );
1937
- } elseif ( 'taxonomy' === $pod['type'] ) {
1938
- $options['admin-ui'] = array(
1939
- 'description' => array(
1940
- 'label' => __( 'Taxonomy Description', 'pods' ),
1941
- 'help' => __( 'A short descriptive summary of what the taxonomy is.', 'pods' ),
1942
- 'type' => 'text',
1943
- 'default' => '',
1944
- ),
1945
- 'show_ui' => array(
1946
- 'label' => __( 'Show Admin UI', 'pods' ),
1947
- 'help' => __( 'Whether to generate a default UI for managing this taxonomy.', 'pods' ),
1948
- 'type' => 'boolean',
1949
- 'default' => pods_v( 'public', $pod, true ),
1950
- 'dependency' => true,
1951
- 'boolean_yes_label' => '',
1952
- ),
1953
- 'show_in_menu' => array(
1954
- 'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
1955
- 'help' => __( 'Whether to show the taxonomy in the admin menu.', 'pods' ),
1956
- 'type' => 'boolean',
1957
- 'default' => pods_v( 'public', $pod, true ),
1958
- 'dependency' => true,
1959
- 'depends-on' => array( 'show_ui' => true ),
1960
- 'boolean_yes_label' => '',
1961
- ),
1962
- 'menu_name' => array(
1963
- 'label' => __( 'Menu Name', 'pods' ),
1964
- 'help' => __( 'help', 'pods' ),
1965
- 'type' => 'text',
1966
- 'default' => '',
1967
- 'depends-on' => array( 'show_ui' => true ),
1968
- ),
1969
- 'menu_location' => array(
1970
- 'label' => __( 'Menu Location', 'pods' ),
1971
- 'help' => __( 'help', 'pods' ),
1972
- 'type' => 'pick',
1973
- 'default' => 'default',
1974
- 'depends-on' => array( 'show_ui' => true ),
1975
- 'data' => array(
1976
- 'default' => __( 'Default - Add to associated Post Type(s) menus', 'pods' ),
1977
- 'settings' => __( 'Add a submenu item to Settings menu', 'pods' ),
1978
- 'appearances' => __( 'Add a submenu item to Appearances menu', 'pods' ),
1979
- 'submenu' => __( 'Add a submenu item to another menu', 'pods' ),
1980
- 'objects' => __( 'Make a new menu item', 'pods' ),
1981
- 'top' => __( 'Make a new menu item below Settings', 'pods' ),
1982
- ),
1983
- 'dependency' => true,
1984
- ),
1985
- 'menu_location_custom' => array(
1986
- 'label' => __( 'Custom Menu Location', 'pods' ),
1987
- 'help' => __( 'help', 'pods' ),
1988
- 'type' => 'text',
1989
- 'depends-on' => array( 'menu_location' => 'submenu' ),
1990
- ),
1991
- 'menu_position' => array(
1992
- 'label' => __( 'Menu Position', 'pods' ),
1993
- 'help' => __( 'help', 'pods' ),
1994
- 'type' => 'number',
1995
- 'number_decimals' => 2,
1996
- 'number_format' => '9999.99',
1997
- 'number_format_soft' => 1,
1998
- 'default' => 0,
1999
- 'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) ),
2000
- ),
2001
- 'menu_icon' => array(
2002
- 'label' => __( 'Menu Icon URL', 'pods' ),
2003
- 'help' => __( 'help', 'pods' ),
2004
- 'type' => 'text',
2005
- 'default' => '',
2006
- 'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) ),
2007
- ),
2008
- 'show_in_nav_menus' => array(
2009
- 'label' => __( 'Show in Navigation Menus', 'pods' ),
2010
- 'help' => __( 'help', 'pods' ),
2011
- 'type' => 'boolean',
2012
- 'default' => pods_v( 'public', $pod, true ),
2013
- 'boolean_yes_label' => '',
2014
- ),
2015
- 'show_tagcloud' => array(
2016
- 'label' => __( 'Allow in Tagcloud Widget', 'pods' ),
2017
- 'help' => __( 'help', 'pods' ),
2018
- 'type' => 'boolean',
2019
- 'default' => pods_v( 'show_ui', $pod, pods_v( 'public', $pod, true ) ),
2020
- 'boolean_yes_label' => '',
2021
- ),
2022
- // @todo check https://core.trac.wordpress.org/ticket/36964
2023
- 'show_tagcloud_in_edit' => array(
2024
- 'label' => __( 'Allow Tagcloud on term edit pages', 'pods' ),
2025
- 'help' => __( 'help', 'pods' ),
2026
- 'type' => 'boolean',
2027
- 'default' => pods_v( 'show_ui', $pod, pods_v( 'show_tagcloud', $pod, true ) ),
2028
- 'boolean_yes_label' => '',
2029
- ),
2030
- 'show_in_quick_edit' => array(
2031
- 'label' => __( 'Allow in quick/bulk edit panel', 'pods' ),
2032
- 'help' => __( 'help', 'pods' ),
2033
- 'type' => 'boolean',
2034
- 'default' => pods_v( 'show_ui', $pod, pods_v( 'public', $pod, true ) ),
2035
- 'boolean_yes_label' => '',
2036
- ),
2037
- );
2038
-
2039
- $options['admin-ui']['show_admin_column'] = array(
2040
- 'label' => __( 'Show Taxonomy column on Post Types', 'pods' ),
2041
- 'help' => __( 'Whether to add a column for this taxonomy on the associated post types manage screens', 'pods' ),
2042
- 'type' => 'boolean',
2043
- 'default' => false,
2044
- 'boolean_yes_label' => '',
2045
- );
2046
-
2047
- // Integration for Single Value Taxonomy UI
2048
- if ( function_exists( 'tax_single_value_meta_box' ) ) {
2049
- $options['admin-ui']['single_value'] = array(
2050
- 'label' => __( 'Single Value Taxonomy', 'pods' ),
2051
- 'help' => __( 'Use a drop-down for the input instead of the WordPress default', 'pods' ),
2052
- 'type' => 'boolean',
2053
- 'default' => false,
2054
- 'boolean_yes_label' => '',
2055
- );
2056
-
2057
- $options['admin-ui']['single_value_required'] = array(
2058
- 'label' => __( 'Single Value Taxonomy - Required', 'pods' ),
2059
- 'help' => __( 'A term will be selected by default in the Post Editor, not optional', 'pods' ),
2060
- 'type' => 'boolean',
2061
- 'default' => false,
2062
- 'boolean_yes_label' => '',
2063
- );
2064
- }
2065
-
2066
- $options['advanced'] = array(
2067
- 'public' => array(
2068
- 'label' => __( 'Public', 'pods' ),
2069
- 'help' => __( 'help', 'pods' ),
2070
- 'type' => 'boolean',
2071
- 'default' => true,
2072
- 'boolean_yes_label' => '',
2073
- ),
2074
- 'hierarchical' => array(
2075
- 'label' => __( 'Hierarchical', 'pods' ),
2076
- 'help' => __( 'Hierarchical taxonomies will have a list with checkboxes to select an existing category in the taxonomy admin box on the post edit page (like default post categories). Non-hierarchical taxonomies will just have an empty text field to type-in taxonomy terms to associate with the post (like default post tags).', 'pods' ),
2077
- 'type' => 'boolean',
2078
- 'default' => true,
2079
- 'dependency' => true,
2080
- 'boolean_yes_label' => '',
2081
- ),
2082
- 'label_parent_item_colon' => array(
2083
- 'label' => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
2084
- 'help' => __( 'help', 'pods' ),
2085
- 'type' => 'text',
2086
- 'default' => '',
2087
- 'depends-on' => array( 'hierarchical' => true ),
2088
- ),
2089
- 'label_parent' => array(
2090
- 'label' => __( '<strong>Label: </strong> Parent', 'pods' ),
2091
- 'help' => __( 'help', 'pods' ),
2092
- 'type' => 'text',
2093
- 'default' => '',
2094
- 'depends-on' => array( 'hierarchical' => true ),
2095
- ),
2096
- 'label_no_terms' => array(
2097
- 'label' => __( '<strong>Label: </strong> No <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
2098
- 'help' => __( 'help', 'pods' ),
2099
- 'type' => 'text',
2100
- 'default' => '',
2101
- 'depends-on' => array( 'hierarchical' => true ),
2102
- ),
2103
- 'rewrite' => array(
2104
- 'label' => __( 'Rewrite', 'pods' ),
2105
- 'help' => __( 'help', 'pods' ),
2106
- 'type' => 'boolean',
2107
- 'default' => true,
2108
- 'dependency' => true,
2109
- 'boolean_yes_label' => '',
2110
- ),
2111
- 'rewrite_custom_slug' => array(
2112
- 'label' => __( 'Custom Rewrite Slug', 'pods' ),
2113
- 'help' => __( 'help', 'pods' ),
2114
- 'type' => 'text',
2115
- 'default' => '',
2116
- 'depends-on' => array( 'rewrite' => true ),
2117
- ),
2118
- 'rewrite_with_front' => array(
2119
- 'label' => __( 'Rewrite with Front', 'pods' ),
2120
- 'help' => __( 'Allows permalinks to be prepended with your front base (example: if your permalink structure is /blog/, then your links will be: Unchecked->/news/, Checked->/blog/news/)', 'pods' ),
2121
- 'type' => 'boolean',
2122
- 'default' => true,
2123
- 'boolean_yes_label' => '',
2124
- 'depends-on' => array( 'rewrite' => true ),
2125
- ),
2126
- 'rewrite_hierarchical' => array(
2127
- 'label' => __( 'Hierarchical Permalinks', 'pods' ),
2128
- 'help' => __( 'help', 'pods' ),
2129
- 'type' => 'boolean',
2130
- 'default' => true,
2131
- 'boolean_yes_label' => '',
2132
- 'depends-on' => array( 'rewrite' => true ),
2133
- ),
2134
- 'capability_type' => array(
2135
- 'label' => __( 'User Capability', 'pods' ),
2136
- 'help' => __( 'Uses WordPress term capabilities by default', 'pods' ),
2137
- 'type' => 'pick',
2138
- 'default' => 'default',
2139
- 'data' => array(
2140
- 'default' => 'Default',
2141
- 'custom' => __( 'Custom Capability', 'pods' ),
2142
- ),
2143
- 'dependency' => true,
2144
- ),
2145
- 'capability_type_custom' => array(
2146
- 'label' => __( 'Custom User Capability', 'pods' ),
2147
- 'help' => __( 'Enables additional capabilities for this Taxonomy including: manage_{capability}_terms, edit_{capability}_terms, assign_{capability}_terms, and delete_{capability}_terms', 'pods' ),
2148
- 'type' => 'text',
2149
- 'default' => pods_v( 'name', $pod ),
2150
- 'depends-on' => array( 'capability_type' => 'custom' ),
2151
- ),
2152
- 'query_var' => array(
2153
- 'label' => __( 'Query Var', 'pods' ),
2154
- 'help' => __( 'help', 'pods' ),
2155
- 'type' => 'boolean',
2156
- 'default' => false,
2157
- 'boolean_yes_label' => '',
2158
- ),
2159
- 'query_var' => array(
2160
- 'label' => __( 'Query Var', 'pods' ),
2161
- 'help' => __( 'help', 'pods' ),
2162
- 'type' => 'boolean',
2163
- 'default' => false,
2164
- 'dependency' => true,
2165
- 'boolean_yes_label' => '',
2166
- ),
2167
- 'query_var_string' => array(
2168
- 'label' => __( 'Custom Query Var Name', 'pods' ),
2169
- 'help' => __( 'help', 'pods' ),
2170
- 'type' => 'text',
2171
- 'default' => '',
2172
- 'depends-on' => array( 'query_var' => true ),
2173
- ),
2174
- 'sort' => array(
2175
- 'label' => __( 'Remember order saved on Post Types', 'pods' ),
2176
- 'help' => __( 'help', 'pods' ),
2177
- 'type' => 'boolean',
2178
- 'default' => false,
2179
- 'boolean_yes_label' => '',
2180
- ),
2181
- 'update_count_callback' => array(
2182
- 'label' => __( 'Function to call when updating counts', 'pods' ),
2183
- 'help' => __( 'help', 'pods' ),
2184
- 'type' => 'text',
2185
- 'default' => '',
2186
- ),
2187
- );
2188
- } elseif ( 'settings' === $pod['type'] ) {
2189
- $options['admin-ui'] = array(
2190
- 'ui_style' => array(
2191
- 'label' => __( 'Admin UI Style', 'pods' ),
2192
- 'help' => __( 'help', 'pods' ),
2193
- 'type' => 'pick',
2194
- 'default' => 'settings',
2195
- 'data' => array(
2196
- 'settings' => __( 'Normal Settings Form', 'pods' ),
2197
- 'post_type' => __( 'Post Type UI', 'pods' ),
2198
- 'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' ),
2199
- ),
2200
- 'dependency' => true,
2201
- ),
2202
- 'menu_location' => array(
2203
- 'label' => __( 'Menu Location', 'pods' ),
2204
- 'help' => __( 'help', 'pods' ),
2205
- 'type' => 'pick',
2206
- 'default' => 'settings',
2207
- 'data' => array(
2208
- 'settings' => __( 'Add a submenu item to Settings menu', 'pods' ),
2209
- 'appearances' => __( 'Add a submenu item to Appearances menu', 'pods' ),
2210
- 'submenu' => __( 'Add a submenu item to another menu', 'pods' ),
2211
- 'top' => __( 'Make a new menu item below Settings', 'pods' ),
2212
- ),
2213
- 'dependency' => true,
2214
- ),
2215
- 'menu_location_custom' => array(
2216
- 'label' => __( 'Custom Menu Location', 'pods' ),
2217
- 'help' => __( 'help', 'pods' ),
2218
- 'type' => 'text',
2219
- 'depends-on' => array( 'menu_location' => 'submenu' ),
2220
- ),
2221
- 'menu_position' => array(
2222
- 'label' => __( 'Menu Position', 'pods' ),
2223
- 'help' => __( 'help', 'pods' ),
2224
- 'type' => 'number',
2225
- 'number_decimals' => 2,
2226
- 'number_format' => '9999.99',
2227
- 'number_format_soft' => 1,
2228
- 'default' => 0,
2229
- 'depends-on' => array( 'menu_location' => 'top' ),
2230
- ),
2231
- 'menu_icon' => array(
2232
- 'label' => __( 'Menu Icon URL', 'pods' ),
2233
- 'help' => __( 'help', 'pods' ),
2234
- 'type' => 'text',
2235
- 'default' => '',
2236
- 'depends-on' => array( 'menu_location' => 'top' ),
2237
- ),
2238
- );
2239
-
2240
- // @todo fill this in
2241
- $options['advanced'] = array(
2242
- 'temporary' => 'This type has the fields hardcoded',
2243
- // :(
2244
- );
2245
- } elseif ( 'pod' === $pod['type'] ) {
2246
- $actions_enabled = array(
2247
- 'add',
2248
- 'edit',
2249
- 'duplicate',
2250
- 'delete',
2251
- );
2252
-
2253
- if ( 1 === (int) pods_v( 'ui_export', $pod ) ) {
2254
- $actions_enabled = array(
2255
- 'add',
2256
- 'edit',
2257
- 'duplicate',
2258
- 'delete',
2259
- 'export',
2260
- );
2261
- }
2262
-
2263
- $options['admin-ui'] = array(
2264
- 'ui_style' => array(
2265
- 'label' => __( 'Admin UI Style', 'pods' ),
2266
- 'help' => __( 'help', 'pods' ),
2267
- 'type' => 'pick',
2268
- 'default' => 'settings',
2269
- 'data' => array(
2270
- 'post_type' => __( 'Normal (Looks like the Post Type UI)', 'pods' ),
2271
- 'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' ),
2272
- ),
2273
- 'dependency' => true,
2274
- ),
2275
- 'show_in_menu' => array(
2276
- 'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
2277
- 'help' => __( 'help', 'pods' ),
2278
- 'type' => 'boolean',
2279
- 'default' => false,
2280
- 'boolean_yes_label' => '',
2281
- 'dependency' => true,
2282
- ),
2283
- 'menu_location_custom' => array(
2284
- 'label' => __( 'Parent Menu ID (optional)', 'pods' ),
2285
- 'help' => __( 'help', 'pods' ),
2286
- 'type' => 'text',
2287
- 'depends-on' => array( 'show_in_menu' => true ),
2288
- ),
2289
- 'menu_position' => array(
2290
- 'label' => __( 'Menu Position', 'pods' ),
2291
- 'help' => __( 'help', 'pods' ),
2292
- 'type' => 'number',
2293
- 'number_decimals' => 2,
2294
- 'number_format' => '9999.99',
2295
- 'number_format_soft' => 1,
2296
- 'default' => 0,
2297
- 'depends-on' => array( 'show_in_menu' => true ),
2298
- ),
2299
- 'menu_icon' => array(
2300
- 'label' => __( 'Menu Icon URL', 'pods' ),
2301
- 'help' => __( 'This is the icon shown to the left of the menu text for this content type.', 'pods' ),
2302
- 'type' => 'text',
2303
- 'default' => '',
2304
- 'depends-on' => array( 'show_in_menu' => true ),
2305
- ),
2306
- 'ui_icon' => array(
2307
- 'label' => __( 'Header Icon', 'pods' ),
2308
- 'help' => __( 'This is the icon shown to the left of the heading text at the top of the manage pages for this content type.', 'pods' ),
2309
- 'type' => 'file',
2310
- 'default' => '',
2311
- 'file_edit_title' => 0,
2312
- 'depends-on' => array( 'show_in_menu' => true ),
2313
- ),
2314
- 'ui_actions_enabled' => array(
2315
- 'label' => __( 'Actions Available', 'pods' ),
2316
- 'help' => __( 'help', 'pods' ),
2317
- 'type' => 'pick',
2318
- 'default' => $actions_enabled,
2319
- 'data' => array(
2320
- 'add' => __( 'Add New', 'pods' ),
2321
- 'edit' => __( 'Edit', 'pods' ),
2322
- 'duplicate' => __( 'Duplicate', 'pods' ),
2323
- 'delete' => __( 'Delete', 'pods' ),
2324
- 'reorder' => __( 'Reorder', 'pods' ),
2325
- 'export' => __( 'Export', 'pods' ),
2326
- ),
2327
- 'pick_format_type' => 'multi',
2328
- 'dependency' => true,
2329
- ),
2330
- 'ui_reorder_field' => array(
2331
- 'label' => __( 'Reorder Field', 'pods' ),
2332
- 'help' => __( 'This is the field that will be reordered on, it should be numeric.', 'pods' ),
2333
- 'type' => 'text',
2334
- 'default' => 'menu_order',
2335
- 'depends-on' => array( 'ui_actions_enabled' => 'reorder' ),
2336
- ),
2337
- 'ui_fields_manage' => array(
2338
- 'label' => __( 'Admin Table Columns', 'pods' ),
2339
- 'help' => __( 'help', 'pods' ),
2340
- 'type' => 'pick',
2341
- 'default' => array(),
2342
- 'data' => array(),
2343
- 'pick_format_type' => 'multi',
2344
- ),
2345
- 'ui_filters' => array(
2346
- 'label' => __( 'Search Filters', 'pods' ),
2347
- 'help' => __( 'help', 'pods' ),
2348
- 'type' => 'pick',
2349
- 'default' => array(),
2350
- 'data' => array(),
2351
- 'pick_format_type' => 'multi',
2352
- ),
2353
- );
2354
-
2355
- if ( ! empty( $pod['fields'] ) ) {
2356
- if ( isset( $pod['fields'][ pods_v( 'pod_index', $pod, 'name' ) ] ) ) {
2357
- $options['admin-ui']['ui_fields_manage']['default'][] = pods_v( 'pod_index', $pod, 'name' );
2358
- }
2359
-
2360
- if ( isset( $pod['fields']['modified'] ) ) {
2361
- $options['admin-ui']['ui_fields_manage']['default'][] = 'modified';
2362
- }
2363
-
2364
- foreach ( $pod['fields'] as $field ) {
2365
- $type = '';
2366
-
2367
- if ( isset( $field_types[ $field['type'] ] ) ) {
2368
- $type = ' <small>(' . $field_types[ $field['type'] ]['label'] . ')</small>';
2369
- }
2370
-
2371
- $options['admin-ui']['ui_fields_manage']['data'][ $field['name'] ] = $field['label'] . $type;
2372
- $options['admin-ui']['ui_filters']['data'][ $field['name'] ] = $field['label'] . $type;
2373
- }
2374
-
2375
- $options['admin-ui']['ui_fields_manage']['data']['id'] = 'ID';
2376
- } else {
2377
- unset( $options['admin-ui']['ui_fields_manage'] );
2378
- unset( $options['admin-ui']['ui_filters'] );
2379
- }//end if
2380
-
2381
- // @todo fill this in
2382
- $options['advanced'] = array(
2383
- 'temporary' => 'This type has the fields hardcoded',
2384
- // :(
2385
- );
2386
- }//end if
2387
-
2388
- $pod_type = $pod['type'];
2389
- $pod_name = $pod['name'];
2390
-
2391
- /**
2392
- * Add admin fields to the Pods editor for a specific Pod
2393
- *
2394
- * @param array $options The Options fields.
2395
- * @param object $pod Current Pods object.
2396
- *
2397
- * @since unkown
2398
- */
2399
- $options = apply_filters( "pods_admin_setup_edit_options_{$pod_type}_{$pod_name}", $options, $pod );
2400
-
2401
- /**
2402
- * Add admin fields to the Pods editor for any Pod of a specific content type.
2403
- *
2404
- * @param array $options The Options fields.
2405
- * @param object $pod Current Pods object.
2406
- */
2407
- $options = apply_filters( "pods_admin_setup_edit_options_{$pod_type}", $options, $pod );
2408
-
2409
- /**
2410
- * Add admin fields to the Pods editor for all Pods
2411
- *
2412
- * @param array $options The Options fields.
2413
- * @param object $pod Current Pods object.
2414
- */
2415
- $options = apply_filters( 'pods_admin_setup_edit_options', $options, $pod );
2416
-
2417
- return $options;
2418
- }
2419
-
2420
- /**
2421
- * Get list of Pod field option tabs
2422
- *
2423
- * @param array $pod Pod options.
2424
- *
2425
- * @return array
2426
- */
2427
- public function admin_setup_edit_field_tabs( $pod ) {
2428
-
2429
- $core_tabs = array(
2430
- 'basic' => __( 'Basic', 'pods' ),
2431
- 'additional-field' => __( 'Additional Field Options', 'pods' ),
2432
- 'advanced' => __( 'Advanced', 'pods' ),
2433
- );
2434
-
2435
- /**
2436
- * Field option tabs
2437
- *
2438
- * Use to add new tabs, default tabs are added after this filter (IE you can't remove/modify them with this, kthanksbye).
2439
- *
2440
- * @since unknown
2441
- *
2442
- * @param array $tabs Tabs to add, starts empty.
2443
- * @param object|Pod $pod Current Pods object.
2444
- */
2445
- $tabs = apply_filters( 'pods_admin_setup_edit_field_tabs', array(), $pod );
2446
-
2447
- $tabs = array_merge( $core_tabs, $tabs );
2448
-
2449
- return $tabs;
2450
- }
2451
-
2452
- /**
2453
- * Get list of Pod field options
2454
- *
2455
- * @param array $pod Pod options.
2456
- *
2457
- * @return array
2458
- */
2459
- public function admin_setup_edit_field_options( $pod ) {
2460
-
2461
- $options = array();
2462
-
2463
- $options['additional-field'] = array();
2464
-
2465
- $field_types = PodsForm::field_types();
2466
-
2467
- foreach ( $field_types as $type => $field_type_data ) {
2468
- /**
2469
- * @var $field_type PodsField
2470
- */
2471
- $field_type = PodsForm::field_loader( $type, $field_type_data['file'] );
2472
-
2473
- $field_type_vars = get_class_vars( get_class( $field_type ) );
2474
-
2475
- if ( ! isset( $field_type_vars['pod_types'] ) ) {
2476
- $field_type_vars['pod_types'] = true;
2477
- }
2478
-
2479
- $options['additional-field'][ $type ] = array();
2480
-
2481
- // Only show supported field types
2482
- if ( true !== $field_type_vars['pod_types'] ) {
2483
- if ( empty( $field_type_vars['pod_types'] ) ) {
2484
- continue;
2485
- } elseif ( is_array( $field_type_vars['pod_types'] ) && ! in_array( pods_v( 'type', $pod ), $field_type_vars['pod_types'], true ) ) {
2486
- continue;
2487
- } elseif ( ! is_array( $field_type_vars['pod_types'] ) && pods_v( 'type', $pod ) !== $field_type_vars['pod_types'] ) {
2488
- continue;
2489
- }
2490
- }
2491
-
2492
- $options['additional-field'][ $type ] = PodsForm::ui_options( $type );
2493
-
2494
- /**
2495
- * Modify Additional Field Options tab
2496
- *
2497
- * @since 2.7.0
2498
- *
2499
- * @param array $options Additional field type options,
2500
- * @param string $type Field type,
2501
- * @param array $options Tabs, indexed by label,
2502
- * @param object|Pods $pod Pods object for the Pod this UI is for.
2503
- */
2504
- $options['additional-field'][ $type ] = apply_filters( "pods_admin_setup_edit_{$type}_additional_field_options", $options['additional-field'][ $type ], $type, $options, $pod );
2505
- $options['additional-field'][ $type ] = apply_filters( 'pods_admin_setup_edit_additional_field_options', $options['additional-field'][ $type ], $type, $options, $pod );
2506
- }//end foreach
2507
-
2508
- $input_helpers = array(
2509
- '' => '-- Select --',
2510
- );
2511
-
2512
- if ( class_exists( 'Pods_Helpers' ) ) {
2513
- $helpers = pods_api()->load_helpers( array( 'options' => array( 'helper_type' => 'input' ) ) );
2514
-
2515
- foreach ( $helpers as $helper ) {
2516
- $input_helpers[ $helper['name'] ] = $helper['name'];
2517
- }
2518
- }
2519
-
2520
- $options['advanced'] = array(
2521
- __( 'Visual', 'pods' ) => array(
2522
- 'class' => array(
2523
- 'name' => 'class',
2524
- 'label' => __( 'Additional CSS Classes', 'pods' ),
2525
- 'help' => __( 'help', 'pods' ),
2526
- 'type' => 'text',
2527
- 'default' => '',
2528
- ),
2529
- 'input_helper' => array(
2530
- 'name' => 'input_helper',
2531
- 'label' => __( 'Input Helper', 'pods' ),
2532
- 'help' => __( 'help', 'pods' ),
2533
- 'type' => 'pick',
2534
- 'default' => '',
2535
- 'data' => $input_helpers,
2536
- ),
2537
- ),
2538
- __( 'Values', 'pods' ) => array(
2539
- 'default_value' => array(
2540
- 'name' => 'default_value',
2541
- 'label' => __( 'Default Value', 'pods' ),
2542
- 'help' => __( 'help', 'pods' ),
2543
- 'type' => 'text',
2544
- 'default' => '',
2545
- 'options' => array(
2546
- 'text_max_length' => - 1,
2547
- ),
2548
- ),
2549
- 'default_value_parameter' => array(
2550
- 'name' => 'default_value_parameter',
2551
- 'label' => __( 'Set Default Value via Parameter', 'pods' ),
2552
- 'help' => __( 'help', 'pods' ),
2553
- 'type' => 'text',
2554
- 'default' => '',
2555
- ),
2556
- ),
2557
- __( 'Visibility', 'pods' ) => array(
2558
- 'restrict_access' => array(
2559
- 'name' => 'restrict_access',
2560
- 'label' => __( 'Restrict Access', 'pods' ),
2561
- 'group' => array(
2562
- 'admin_only' => array(
2563
- 'name' => 'admin_only',
2564
- 'label' => __( 'Restrict access to Admins?', 'pods' ),
2565
- 'default' => 0,
2566
- 'type' => 'boolean',
2567
- 'dependency' => true,
2568
- 'help' => __( 'This field will only be able to be edited by users with the ability to manage_options or delete_users, or super admins of a WordPress Multisite network', 'pods' ),
2569
- ),
2570
- 'restrict_role' => array(
2571
- 'name' => 'restrict_role',
2572
- 'label' => __( 'Restrict access by Role?', 'pods' ),
2573
- 'default' => 0,
2574
- 'type' => 'boolean',
2575
- 'dependency' => true,
2576
- ),
2577
- 'restrict_capability' => array(
2578
- 'name' => 'restrict_capability',
2579
- 'label' => __( 'Restrict access by Capability?', 'pods' ),
2580
- 'default' => 0,
2581
- 'type' => 'boolean',
2582
- 'dependency' => true,
2583
- ),
2584
- 'hidden' => array(
2585
- 'name' => 'hidden',
2586
- 'label' => __( 'Hide field from UI', 'pods' ),
2587
- 'default' => 0,
2588
- 'type' => 'boolean',
2589
- 'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be hidden. If no access restrictions are set, this field will always be hidden.', 'pods' ),
2590
- ),
2591
- 'read_only' => array(
2592
- 'name' => 'read_only',
2593
- 'label' => __( 'Make field "Read Only" in UI', 'pods' ),
2594
- 'default' => 0,
2595
- 'type' => 'boolean',
2596
- 'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be read only. If no access restrictions are set, this field will always be read only.', 'pods' ),
2597
- 'depends-on' => array(
2598
- 'type' => array(
2599
- 'boolean',
2600
- 'color',
2601
- 'currency',
2602
- 'date',
2603
- 'datetime',
2604
- 'email',
2605
- 'number',
2606
- 'paragraph',
2607
- 'password',
2608
- 'phone',
2609
- 'slug',
2610
- 'text',
2611
- 'time',
2612
- 'website',
2613
- ),
2614
- ),
2615
- ),
2616
- ),
2617
- ),
2618
- 'roles_allowed' => array(
2619
- 'name' => 'roles_allowed',
2620
- 'label' => __( 'Role(s) Allowed', 'pods' ),
2621
- 'help' => __( 'help', 'pods' ),
2622
- 'type' => 'pick',
2623
- 'pick_object' => 'role',
2624
- 'pick_format_type' => 'multi',
2625
- 'default' => 'administrator',
2626
- 'depends-on' => array(
2627
- 'restrict_role' => true,
2628
- ),
2629
- ),
2630
- 'capability_allowed' => array(
2631
- 'name' => 'capability_allowed',
2632
- 'label' => __( 'Capability Allowed', 'pods' ),
2633
- 'help' => __( 'Comma-separated list of cababilities, for example add_podname_item, please see the Roles and Capabilities component for the complete list and a way to add your own.', 'pods' ),
2634
- 'type' => 'text',
2635
- 'default' => '',
2636
- 'depends-on' => array(
2637
- 'restrict_capability' => true,
2638
- ),
2639
- ),
2640
- ),
2641
- );
2642
-
2643
- /*
2644
- $options['advanced'][ __( 'Visibility', 'pods' ) ]['search'] = array(
2645
- 'label' => __( 'Include in searches', 'pods' ),
2646
- 'help' => __( 'help', 'pods' ),
2647
- 'default' => 1,
2648
- 'type' => 'boolean',
2649
- );
2650
- */
2651
-
2652
- /*
2653
- $options['advanced'][ __( 'Validation', 'pods' ) ] = array(
2654
- 'regex_validation' => array(
2655
- 'label' => __( 'RegEx Validation', 'pods' ),
2656
- 'help' => __( 'help', 'pods' ),
2657
- 'type' => 'text',
2658
- 'default' => '',
2659
- ),
2660
- 'message_regex' => array(
2661
- 'label' => __( 'Message if field does not pass RegEx', 'pods' ),
2662
- 'help' => __( 'help', 'pods' ),
2663
- 'type' => 'text',
2664
- 'default' => '',
2665
- ),
2666
- 'message_required' => array(
2667
- 'label' => __( 'Message if field is blank', 'pods' ),
2668
- 'help' => __( 'help', 'pods' ),
2669
- 'type' => 'text',
2670
- 'default' => '',
2671
- 'depends-on' => array( 'required' => true ),
2672
- ),
2673
- 'message_unique' => array(
2674
- 'label' => __( 'Message if field is not unique', 'pods' ),
2675
- 'help' => __( 'help', 'pods' ),
2676
- 'type' => 'text',
2677
- 'default' => '',
2678
- 'depends-on' => array( 'unique' => true ),
2679
- ),
2680
- );
2681
- */
2682
-
2683
- if ( ! class_exists( 'Pods_Helpers' ) ) {
2684
- unset( $options['advanced']['input_helper'] );
2685
- }
2686
-
2687
- /**
2688
- * Modify tabs and their contents for field options
2689
- *
2690
- * @since unknown
2691
- *
2692
- * @param array $options Tabs, indexed by label.
2693
- * @param object|Pods $pod Pods object for the Pod this UI is for.
2694
- */
2695
- $options = apply_filters( 'pods_admin_setup_edit_field_options', $options, $pod );
2696
-
2697
- return $options;
2698
- }
2699
-
2700
- /**
2701
- * Duplicate a pod
2702
- *
2703
- * @param PodsUI $obj PodsUI object.
2704
- */
2705
- public function admin_setup_duplicate( $obj ) {
2706
-
2707
- $new_id = pods_api()->duplicate_pod( array( 'id' => $obj->id ) );
2708
-
2709
- if ( 0 < $new_id ) {
2710
- pods_redirect(
2711
- pods_query_arg(
2712
- array(
2713
- 'action' => 'edit',
2714
- 'id' => $new_id,
2715
- 'do' => 'duplicate',
2716
- )
2717
- )
2718
- );
2719
- }
2720
- }
2721
-
2722
- /**
2723
- * Restrict Duplicate action to custom types, not extended
2724
- *
2725
- * @param bool $restricted Whether action is restricted.
2726
- * @param array $restrict Restriction array.
2727
- * @param string $action Current action.
2728
- * @param array $row Item data row.
2729
- * @param PodsUI $obj PodsUI object.
2730
- *
2731
- * @since 2.3.10
2732
- *
2733
- * @return bool
2734
- */
2735
- public function admin_setup_duplicate_restrict( $restricted, $restrict, $action, $row, $obj ) {
2736
-
2737
- if ( in_array(
2738
- $row['real_type'], array(
2739
- 'user',
2740
- 'media',
2741
- 'comment',
2742
- ), true
2743
- ) ) {
2744
- $restricted = true;
2745
- }
2746
-
2747
- return $restricted;
2748
-
2749
- }
2750
-
2751
- /**
2752
- * Reset a pod
2753
- *
2754
- * @param PodsUI $obj PodsUI object.
2755
- * @param int|string $id Item ID.
2756
- *
2757
- * @return mixed
2758
- */
2759
- public function admin_setup_reset( $obj, $id ) {
2760
-
2761
- $pod = pods_api()->load_pod( array( 'id' => $id ), false );
2762
-
2763
- if ( empty( $pod ) ) {
2764
- return $obj->error( __( 'Pod not found.', 'pods' ) );
2765
- }
2766
-
2767
- pods_api()->reset_pod( array( 'id' => $id ) );
2768
-
2769
- $obj->message( __( 'Pod reset successfully.', 'pods' ) );
2770
-
2771
- $obj->manage();
2772
- }
2773
-
2774
- /**
2775
- * Restrict Reset action from users and media
2776
- *
2777
- * @param bool $restricted Whether action is restricted.
2778
- * @param array $restrict Restriction array.
2779
- * @param string $action Current action.
2780
- * @param array $row Item data row.
2781
- * @param PodsUI $obj PodsUI object.
2782
- *
2783
- * @since 2.3.10
2784
- */
2785
- public function admin_setup_reset_restrict( $restricted, $restrict, $action, $row, $obj ) {
2786
-
2787
- if ( in_array(
2788
- $row['real_type'], array(
2789
- 'user',
2790
- 'media',
2791
- ), true
2792
- ) ) {
2793
- $restricted = true;
2794
- }
2795
-
2796
- return $restricted;
2797
-
2798
- }
2799
-
2800
- /**
2801
- * Delete a pod
2802
- *
2803
- * @param int|string $id Item ID.
2804
- * @param PodsUI $obj PodsUI object.
2805
- *
2806
- * @return mixed
2807
- */
2808
- public function admin_setup_delete( $id, $obj ) {
2809
-
2810
- $pod = pods_api()->load_pod( array( 'id' => $id ), false );
2811
-
2812
- if ( empty( $pod ) ) {
2813
- return $obj->error( __( 'Pod not found.', 'pods' ) );
2814
- }
2815
-
2816
- pods_api()->delete_pod( array( 'id' => $id ) );
2817
-
2818
- unset( $obj->data[ $pod['id'] ] );
2819
-
2820
- $obj->total = count( $obj->data );
2821
- $obj->total_found = count( $obj->data );
2822
-
2823
- $obj->message( __( 'Pod deleted successfully.', 'pods' ) );
2824
- }
2825
-
2826
- /**
2827
- * Get advanced administration view.
2828
- */
2829
- public function admin_advanced() {
2830
-
2831
- pods_view( PODS_DIR . 'ui/admin/advanced.php', compact( array_keys( get_defined_vars() ) ) );
2832
- }
2833
-
2834
- /**
2835
- * Get settings administration view
2836
- */
2837
- public function admin_settings() {
2838
-
2839
- // Add our custom callouts.
2840
- add_action( 'pods_admin_after_settings', array( $this, 'admin_manage_callouts' ) );
2841
-
2842
- pods_view( PODS_DIR . 'ui/admin/settings.php', compact( array_keys( get_defined_vars() ) ) );
2843
- }
2844
-
2845
- /**
2846
- * Get components administration UI
2847
- */
2848
- public function admin_components() {
2849
-
2850
- if ( ! is_object( PodsInit::$components ) ) {
2851
- return;
2852
- }
2853
-
2854
- $components = PodsInit::$components->components;
2855
-
2856
- $view = pods_v( 'view', 'get', 'all', true );
2857
-
2858
- $recommended = array(
2859
- 'advanced-relationships',
2860
- 'advanced-content-types',
2861
- 'migrate-packages',
2862
- 'roles-and-capabilities',
2863
- 'pages',
2864
- 'table-storage',
2865
- 'templates',
2866
- );
2867
-
2868
- foreach ( $components as $component => &$component_data ) {
2869
- if ( ! in_array(
2870
- $view, array(
2871
- 'all',
2872
- 'recommended',
2873
- 'dev',
2874
- ), true
2875
- ) && ( ! isset( $component_data['Category'] ) || sanitize_title( $component_data['Category'] ) !== $view ) ) {
2876
- unset( $components[ $component ] );
2877
-
2878
- continue;
2879
- } elseif ( 'recommended' === $view && ! in_array( $component_data['ID'], $recommended, true ) ) {
2880
- unset( $components[ $component ] );
2881
-
2882
- continue;
2883
- } elseif ( 'dev' === $view && pods_developer() && ! pods_v( 'DeveloperMode', $component_data, false ) ) {
2884
- unset( $components[ $component ] );
2885
-
2886
- continue;
2887
- } elseif ( pods_v( 'DeveloperMode', $component_data, false ) && ! pods_developer() ) {
2888
- unset( $components[ $component ] );
2889
-
2890
- continue;
2891
- } elseif ( ! pods_v( 'TablelessMode', $component_data, false ) && pods_tableless() ) {
2892
- unset( $components[ $component ] );
2893
-
2894
- continue;
2895
- }//end if
2896
-
2897
- $component_data['Name'] = strip_tags( $component_data['Name'] );
2898
-
2899
- if ( pods_v( 'DeveloperMode', $component_data, false ) ) {
2900
- $component_data['Name'] .= ' <em style="font-weight: normal; color:#333;">(Developer Preview)</em>';
2901
- }
2902
-
2903
- $meta = array();
2904
-
2905
- if ( ! empty( $component_data['Version'] ) ) {
2906
- $meta[] = sprintf( __( 'Version %s', 'pods' ), $component_data['Version'] );
2907
- }
2908
-
2909
- if ( empty( $component_data['Author'] ) ) {
2910
- $component_data['Author'] = 'Pods Framework Team';
2911
- $component_data['AuthorURI'] = 'https://pods.io/';
2912
- }
2913
-
2914
- if ( ! empty( $component_data['AuthorURI'] ) ) {
2915
- $component_data['Author'] = '<a href="' . $component_data['AuthorURI'] . '">' . $component_data['Author'] . '</a>';
2916
- }
2917
-
2918
- $meta[] = sprintf( __( 'by %s', 'pods' ), $component_data['Author'] );
2919
-
2920
- if ( ! empty( $component_data['URI'] ) ) {
2921
- $meta[] = '<a href="' . $component_data['URI'] . '">' . __( 'Visit component site', 'pods' ) . '</a>';
2922
- }
2923
-
2924
- $component_data['Description'] = wpautop( trim( make_clickable( strip_tags( $component_data['Description'], 'em,strong' ) ) ) );
2925
-
2926
- if ( ! empty( $meta ) ) {
2927
- $description_style = '';
2928
-
2929
- if ( ! empty( $component_data['Description'] ) ) {
2930
- $description_style = ' style="padding:8px 0 4px;"';
2931
- }
2932
-
2933
- $component_data['Description'] .= '<div class="pods-component-meta" ' . $description_style . '>' . implode( '&nbsp;&nbsp;|&nbsp;&nbsp;', $meta ) . '</div>';
2934
- }
2935
-
2936
- $component_data = array(
2937
- 'id' => $component_data['ID'],
2938
- 'name' => $component_data['Name'],
2939
- 'category' => $component_data['Category'],
2940
- 'version' => '',
2941
- 'description' => $component_data['Description'],
2942
- 'mustuse' => pods_v( 'MustUse', $component_data, false ),
2943
- 'toggle' => 0,
2944
- );
2945
-
2946
- if ( ! empty( $component_data['category'] ) ) {
2947
- $category_url = pods_query_arg(
2948
- array(
2949
- 'view' => sanitize_title( $component_data['category'] ),
2950
- 'pg' => '',
2951
- // @codingStandardsIgnoreLine
2952
- 'page' => $_GET['page'],
2953
- )
2954
- );
2955
-
2956
- $component_data['category'] = '<a href="' . esc_url( $category_url ) . '">' . $component_data['category'] . '</a>';
2957
- }
2958
-
2959
- if ( isset( PodsInit::$components->settings['components'][ $component_data['id'] ] ) && 0 !== PodsInit::$components->settings['components'][ $component_data['id'] ] ) {
2960
- $component_data['toggle'] = 1;
2961
- } elseif ( $component_data['mustuse'] ) {
2962
- $component_data['toggle'] = 1;
2963
- }
2964
- }//end foreach
2965
-
2966
- $ui = array(
2967
- 'data' => $components,
2968
- 'total' => count( $components ),
2969
- 'total_found' => count( $components ),
2970
- 'items' => __( 'Components', 'pods' ),
2971
- 'item' => __( 'Component', 'pods' ),
2972
- 'fields' => array(
2973
- 'manage' => array(
2974
- 'name' => array(
2975
- 'label' => __( 'Name', 'pods' ),
2976
- 'width' => '30%',
2977
- 'type' => 'text',
2978
- 'options' => array(
2979
- 'text_allow_html' => true,
2980
- ),
2981
- ),
2982
- 'category' => array(
2983
- 'label' => __( 'Category', 'pods' ),
2984
- 'width' => '10%',
2985
- 'type' => 'text',
2986
- 'options' => array(
2987
- 'text_allow_html' => true,
2988
- ),
2989
- ),
2990
- 'description' => array(
2991
- 'label' => __( 'Description', 'pods' ),
2992
- 'width' => '60%',
2993
- 'type' => 'text',
2994
- 'options' => array(
2995
- 'text_allow_html' => true,
2996
- 'text_allowed_html_tags' => 'strong em a ul ol li b i br div',
2997
- ),
2998
- ),
2999
- ),
3000
- ),
3001
- 'actions_disabled' => array( 'duplicate', 'view', 'export', 'add', 'edit', 'delete' ),
3002
- 'actions_custom' => array(
3003
- 'toggle' => array(
3004
- 'callback' => array( $this, 'admin_components_toggle' ),
3005
- 'nonce' => true,
3006
- ),
3007
- ),
3008
- 'filters_enhanced' => true,
3009
- 'views' => array(
3010
- 'all' => __( 'All', 'pods' ),
3011
- // 'recommended' => __( 'Recommended', 'pods' ),
3012
- 'field-types' => __( 'Field Types', 'pods' ),
3013
- 'tools' => __( 'Tools', 'pods' ),
3014
- 'integration' => __( 'Integration', 'pods' ),
3015
- 'migration' => __( 'Migration', 'pods' ),
3016
- 'advanced' => __( 'Advanced', 'pods' ),
3017
- ),
3018
- 'view' => $view,
3019
- 'heading' => array(
3020
- 'views' => __( 'Category', 'pods' ),
3021
- ),
3022
- 'search' => false,
3023
- 'searchable' => false,
3024
- 'sortable' => false,
3025
- 'pagination' => false,
3026
- );
3027
-
3028
- if ( pods_developer() ) {
3029
- $ui['views']['dev'] = __( 'Developer Preview', 'pods' );
3030
- }
3031
-
3032
- // Add our custom callouts.
3033
- $this->handle_callouts_updates();
3034
-
3035
- add_filter( 'pods_ui_manage_custom_container_classes', array( $this, 'admin_manage_container_class' ) );
3036
- add_action( 'pods_ui_manage_after_container', array( $this, 'admin_manage_callouts' ) );
3037
-
3038
- pods_ui( $ui );
3039
- }
3040
-
3041
- /**
3042
- * Toggle a component on or off
3043
- *
3044
- * @param PodsUI $ui PodsUI object.
3045
- *
3046
- * @return bool
3047
- */
3048
- public function admin_components_toggle( $ui ) {
3049
-
3050
- // @codingStandardsIgnoreLine
3051
- $component = $_GET['id'];
3052
-
3053
- if ( ! empty( PodsInit::$components->components[ $component ]['PluginDependency'] ) ) {
3054
- $dependency = explode( '|', PodsInit::$components->components[ $component ]['PluginDependency'] );
3055
-
3056
- if ( ! pods_is_plugin_active( $dependency[1] ) ) {
3057
- $website = 'http://wordpress.org/extend/plugins/' . dirname( $dependency[1] ) . '/';
3058
-
3059
- if ( isset( $dependency[2] ) ) {
3060
- $website = $dependency[2];
3061
- }
3062
-
3063
- if ( ! empty( $website ) ) {
3064
- $website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $website . '" target="_blank" rel="noopener noreferrer">' . $website . '</a>' );
3065
- }
3066
-
3067
- $message = sprintf( __( 'The %1$s component requires that you have the <strong>%2$s</strong> plugin installed and activated.', 'pods' ), PodsInit::$components->components[ $component ]['Name'], $dependency[0] ) . $website;
3068
-
3069
- $ui->error( $message );
3070
-
3071
- $ui->manage();
3072
-
3073
- return;
3074
- }
3075
- }//end if
3076
-
3077
- if ( ! empty( PodsInit::$components->components[ $component ]['ThemeDependency'] ) ) {
3078
- $dependency = explode( '|', PodsInit::$components->components[ $component ]['ThemeDependency'] );
3079
-
3080
- $check = strtolower( $dependency[1] );
3081
-
3082
- if ( strtolower( get_template() ) !== $check && strtolower( get_stylesheet() ) !== $check ) {
3083
- $website = '';
3084
-
3085
- if ( isset( $dependency[2] ) ) {
3086
- $website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $dependency[2] . '" target="_blank" rel="noopener noreferrer">' . $dependency[2] . '</a>' );
3087
- }
3088
-
3089
- $message = sprintf( __( 'The %1$s component requires that you have the <strong>%2$s</strong> theme installed and activated.', 'pods' ), PodsInit::$components->components[ $component ]['Name'], $dependency[0] ) . $website;
3090
-
3091
- $ui->error( $message );
3092
-
3093
- $ui->manage();
3094
-
3095
- return;
3096
- }
3097
- }//end if
3098
-
3099
- if ( ! empty( PodsInit::$components->components[ $component ]['MustUse'] ) ) {
3100
- $message = sprintf( __( 'The %s component can not be disabled from here. You must deactivate the plugin or theme that added it.', 'pods' ), PodsInit::$components->components[ $component ]['Name'] );
3101
-
3102
- $ui->error( $message );
3103
-
3104
- $ui->manage();
3105
-
3106
- return;
3107
- }
3108
-
3109
- if ( 1 === (int) pods_v( 'toggled' ) ) {
3110
- $toggle = PodsInit::$components->toggle( $component );
3111
-
3112
- if ( true === $toggle ) {
3113
- $ui->message( PodsInit::$components->components[ $component ]['Name'] . ' ' . __( 'Component enabled', 'pods' ) );
3114
- } elseif ( false === $toggle ) {
3115
- $ui->message( PodsInit::$components->components[ $component ]['Name'] . ' ' . __( 'Component disabled', 'pods' ) );
3116
- }
3117
-
3118
- $components = PodsInit::$components->components;
3119
-
3120
- foreach ( $components as $component => &$component_data ) {
3121
- $toggle = 0;
3122
-
3123
- if ( isset( PodsInit::$components->settings['components'][ $component_data['ID'] ] ) ) {
3124
- if ( 0 !== PodsInit::$components->settings['components'][ $component_data['ID'] ] ) {
3125
- $toggle = 1;
3126
- }
3127
- }
3128
- if ( true === $component_data['DeveloperMode'] ) {
3129
- if ( ! pods_developer() ) {
3130
- unset( $components[ $component ] );
3131
- continue;
3132
- }
3133
- }
3134
-
3135
- $component_data = array(
3136
- 'id' => $component_data['ID'],
3137
- 'name' => $component_data['Name'],
3138
- 'description' => make_clickable( $component_data['Description'] ),
3139
- 'version' => $component_data['Version'],
3140
- 'author' => $component_data['Author'],
3141
- 'toggle' => $toggle,
3142
- );
3143
- }//end foreach
3144
-
3145
- $ui->data = $components;
3146
-
3147
- pods_transient_clear( 'pods_components' );
3148
-
3149
- $url = pods_query_arg( array( 'toggled' => null ) );
3150
-
3151
- pods_redirect( $url );
3152
- } elseif ( 1 === (int) pods_v( 'toggle' ) ) {
3153
- $ui->message( PodsInit::$components->components[ $component ]['Name'] . ' ' . __( 'Component enabled', 'pods' ) );
3154
- } else {
3155
- $ui->message( PodsInit::$components->components[ $component ]['Name'] . ' ' . __( 'Component disabled', 'pods' ) );
3156
- }//end if
3157
-
3158
- $ui->manage();
3159
- }
3160
-
3161
- /**
3162
- * Get the admin upgrade page
3163
- */
3164
- public function admin_upgrade() {
3165
-
3166
- foreach ( PodsInit::$upgrades as $old_version => $new_version ) {
3167
- if ( version_compare( $old_version, PodsInit::$version_last, '<=' ) && version_compare( PodsInit::$version_last, $new_version, '<' ) ) {
3168
- $new_version = str_replace( '.', '_', $new_version );
3169
-
3170
- pods_view( PODS_DIR . 'ui/admin/upgrade/upgrade_' . $new_version . '.php', compact( array_keys( get_defined_vars() ) ) );
3171
-
3172
- break;
3173
- }
3174
- }
3175
- }
3176
-
3177
- /**
3178
- * Get the admin help page
3179
- */
3180
- public function admin_help() {
3181
-
3182
- // Add our custom callouts.
3183
- $this->handle_callouts_updates();
3184
-
3185
- add_action( 'pods_admin_after_help', array( $this, 'admin_manage_callouts' ) );
3186
-
3187
- pods_view( PODS_DIR . 'ui/admin/help.php', compact( array_keys( get_defined_vars() ) ) );
3188
- }
3189
-
3190
- /**
3191
- * Add pods specific capabilities.
3192
- *
3193
- * @param array $capabilities List of extra capabilities to add.
3194
- *
3195
- * @return array
3196
- */
3197
- public function admin_capabilities( $capabilities ) {
3198
-
3199
- $pods = pods_api()->load_pods(
3200
- array(
3201
- 'type' => array(
3202
- 'settings',
3203
- 'post_type',
3204
- 'taxonomy',
3205
- ),
3206
- 'fields' => false,
3207
- 'table_info' => false,
3208
- )
3209
- );
3210
-
3211
- $other_pods = pods_api()->load_pods(
3212
- array(
3213
- 'type' => array(
3214
- 'pod',
3215
- 'table',
3216
- ),
3217
- 'table_info' => false,
3218
- )
3219
- );
3220
-
3221
- $pods = array_merge( $pods, $other_pods );
3222
-
3223
- $capabilities[] = 'pods';
3224
- $capabilities[] = 'pods_content';
3225
- $capabilities[] = 'pods_settings';
3226
- $capabilities[] = 'pods_components';
3227
-
3228
- foreach ( $pods as $pod ) {
3229
- if ( 'settings' === $pod['type'] ) {
3230
- $capabilities[] = 'pods_edit_' . $pod['name'];
3231
- } elseif ( 'post_type' === $pod['type'] ) {
3232
- $capability_type = pods_v_sanitized( 'capability_type_custom', $pod['options'], pods_v( 'name', $pod ) );
3233
-
3234
- if ( 'custom' === pods_v( 'capability_type', $pod['options'] ) && 0 < strlen( $capability_type ) ) {
3235
- $capabilities[] = 'read_' . $capability_type;
3236
- $capabilities[] = 'edit_' . $capability_type;
3237
- $capabilities[] = 'delete_' . $capability_type;
3238
-
3239
- if ( 1 === (int) pods_v( 'capability_type_extra', $pod['options'], 1 ) ) {
3240
- $capability_type_plural = $capability_type . 's';
3241
-
3242
- $capabilities[] = 'read_private_' . $capability_type_plural;
3243
- $capabilities[] = 'edit_' . $capability_type_plural;
3244
- $capabilities[] = 'edit_others_' . $capability_type_plural;
3245
- $capabilities[] = 'edit_private_' . $capability_type_plural;
3246
- $capabilities[] = 'edit_published_' . $capability_type_plural;
3247
- $capabilities[] = 'publish_' . $capability_type_plural;
3248
- $capabilities[] = 'delete_' . $capability_type_plural;
3249
- $capabilities[] = 'delete_private_' . $capability_type_plural;
3250
- $capabilities[] = 'delete_published_' . $capability_type_plural;
3251
- $capabilities[] = 'delete_others_' . $capability_type_plural;
3252
- }
3253
- }
3254
- } elseif ( 'taxonomy' === $pod['type'] ) {
3255
- if ( 'custom' === pods_v( 'capability_type', $pod['options'], 'terms' ) ) {
3256
- $capability_type = pods_v_sanitized( 'capability_type_custom', $pod['options'], pods_v( 'name', $pod ) . 's' );
3257
-
3258
- $capability_type .= '_term';
3259
- $capability_type_plural = $capability_type . 's';
3260
-
3261
- // Singular
3262
- $capabilities[] = 'edit_' . $capability_type;
3263
- $capabilities[] = 'delete_' . $capability_type;
3264
- $capabilities[] = 'assign_' . $capability_type;
3265
- // Plural
3266
- $capabilities[] = 'manage_' . $capability_type_plural;
3267
- $capabilities[] = 'edit_' . $capability_type_plural;
3268
- $capabilities[] = 'delete_' . $capability_type_plural;
3269
- $capabilities[] = 'assign_' . $capability_type_plural;
3270
- }
3271
- } else {
3272
- $capabilities[] = 'pods_add_' . $pod['name'];
3273
- $capabilities[] = 'pods_edit_' . $pod['name'];
3274
-
3275
- if ( isset( $pod['fields']['author'] ) && 'pick' === $pod['fields']['author']['type'] && 'user' === $pod['fields']['author']['pick_object'] ) {
3276
- $capabilities[] = 'pods_edit_others_' . $pod['name'];
3277
- }
3278
-
3279
- $capabilities[] = 'pods_delete_' . $pod['name'];
3280
-
3281
- if ( isset( $pod['fields']['author'] ) && 'pick' === $pod['fields']['author']['type'] && 'user' === $pod['fields']['author']['pick_object'] ) {
3282
- $capabilities[] = 'pods_delete_others_' . $pod['name'];
3283
- }
3284
-
3285
- $actions_enabled = pods_v( 'ui_actions_enabled', $pod['options'] );
3286
-
3287
- if ( ! empty( $actions_enabled ) ) {
3288
- $actions_enabled = (array) $actions_enabled;
3289
- } else {
3290
- $actions_enabled = array(
1
  <?php
 
2
  /**
3
  * @package Pods
4
  */
5
  class PodsAdmin {
6
 
7
+ /**
8
+ * @var PodsAdmin
9
+ */
10
+ static $instance = null;
11
+
12
+ /**
13
+ * Singleton handling for a basic pods_admin() request
14
+ *
15
+ * @return \PodsAdmin
16
+ *
17
+ * @since 2.3.5
18
+ */
19
+ public static function init () {
20
+ if ( !is_object( self::$instance ) )
21
+ self::$instance = new PodsAdmin();
22
+
23
+ return self::$instance;
24
+ }
25
+
26
+ /**
27
+ * Setup and Handle Admin functionality
28
+ *
29
+ * @return \PodsAdmin
30
+ *
31
+ * @license http://www.gnu.org/licenses/gpl-2.0.html
32
+ * @since 2.0
33
+ */
34
+ public function __construct () {
35
+ // Scripts / Stylesheets
36
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_head' ), 20 );
37
+
38
+ // AJAX $_POST fix
39
+ add_action( 'admin_init', array( $this, 'admin_init' ), 9 );
40
+
41
+ // Menus
42
+ add_action( 'admin_menu', array( $this, 'admin_menu' ), 99 );
43
+
44
+ // AJAX for Admin
45
+ add_action( 'wp_ajax_pods_admin', array( $this, 'admin_ajax' ) );
46
+ add_action( 'wp_ajax_nopriv_pods_admin', array( $this, 'admin_ajax' ) );
47
+
48
+ // Add Media Bar button for Shortcode
49
+ add_action( 'media_buttons', array( $this, 'media_button' ), 12 );
50
+
51
+ // Add the Pods capabilities
52
+ add_filter( 'members_get_capabilities', array( $this, 'admin_capabilities' ) );
53
+
54
+ add_action( 'admin_head-media-upload-popup', array( $this, 'register_media_assets' ) );
55
+
56
+ $this->rest_admin();
57
+
58
+ }
59
+
60
+ /**
61
+ * Init the admin area
62
+ *
63
+ * @since 2.0
64
+ */
65
+ public function admin_init () {
66
+ // Fix for plugins that *don't do it right* so we don't cause issues for users
67
+ if ( defined( 'DOING_AJAX' ) && !empty( $_POST ) ) {
68
+ $pods_admin_ajax_actions = array(
69
+ 'pods_admin',
70
+ 'pods_relationship',
71
+ 'pods_upload',
72
+ 'pods_admin_components'
73
+ );
74
+
75
+ /**
76
+ * Admin AJAX Callbacks
77
+ *
78
+ * @since unknown
79
+ *
80
+ * @param array $pods_admin_ajax_actions Array of actions to handle
81
+ */
82
+ $pods_admin_ajax_actions = apply_filters( 'pods_admin_ajax_actions', $pods_admin_ajax_actions );
83
+
84
+ if ( in_array( pods_var( 'action', 'get' ), $pods_admin_ajax_actions ) || in_array( pods_var( 'action', 'post' ), $pods_admin_ajax_actions ) ) {
85
+ foreach ( $_POST as $key => $value ) {
86
+ if ( 'action' == $key || 0 === strpos( $key, '_podsfix_' ) )
87
+ continue;
88
+
89
+ unset( $_POST[ $key ] );
90
+
91
+ $_POST[ '_podsfix_' . $key ] = $value;
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Attach requirements to admin header
99
+ *
100
+ * @since 2.0
101
+ */
102
+ public function admin_head () {
103
+ wp_register_style( 'pods-admin', PODS_URL . 'ui/css/pods-admin.css', array(), PODS_VERSION );
104
+
105
+ wp_register_style( 'pods-font', PODS_URL . 'ui/css/pods-font.css', array(), PODS_VERSION );
106
+
107
+ wp_register_script( 'pods-floatmenu', PODS_URL . 'ui/js/floatmenu.js', array(), PODS_VERSION );
108
+
109
+ wp_register_script( 'pods-admin-importer', PODS_URL . 'ui/js/admin-importer.js', array(), PODS_VERSION );
110
+
111
+ wp_register_style( 'pods-manage', PODS_URL . 'ui/css/pods-manage.css', array(), PODS_VERSION );
112
+
113
+ wp_register_style( 'pods-wizard', PODS_URL . 'ui/css/pods-wizard.css', array(), PODS_VERSION );
114
+
115
+ wp_register_script( 'pods-upgrade', PODS_URL . 'ui/js/jquery.pods.upgrade.js', array(), PODS_VERSION );
116
+
117
+ wp_register_script( 'pods-migrate', PODS_URL . 'ui/js/jquery.pods.migrate.js', array(), PODS_VERSION );
118
+
119
+ if ( isset( $_GET[ 'page' ] ) ) {
120
+ $page = $_GET[ 'page' ];
121
+ if ( 'pods' == $page || ( false !== strpos( $page, 'pods-' ) && 0 === strpos( $page, 'pods-' ) ) ) {
122
+ ?>
123
+ <script type="text/javascript">
124
+ var PODS_URL = "<?php echo esc_js( PODS_URL ); ?>";
125
+ </script>
126
+ <?php
127
+ wp_enqueue_script( 'jquery' );
128
+ wp_enqueue_script( 'jquery-ui-core' );
129
+ wp_enqueue_script( 'jquery-ui-sortable' );
130
+
131
+ wp_enqueue_style( 'jquery-ui' );
132
+
133
+ wp_enqueue_script( 'pods-floatmenu' );
134
+
135
+ wp_enqueue_style( 'jquery-qtip2' );
136
+ wp_enqueue_script( 'jquery-qtip2' );
137
+ wp_enqueue_script( 'pods-qtip-init' );
138
+
139
+ wp_enqueue_script( 'pods' );
140
 
141
+ if ( 0 === strpos( $page, 'pods-manage-' ) || 0 === strpos( $page, 'pods-add-new-' ) )
142
+ wp_enqueue_script( 'post' );
143
+ elseif ( 0 === strpos( $page, 'pods-settings-' ) ) {
144
+ wp_enqueue_script( 'post' );
145
+ wp_enqueue_style( 'pods-admin' );
146
+ }
147
+ else
148
+ wp_enqueue_style( 'pods-admin' );
149
+
150
+ if ( 'pods-advanced' == $page ) {
151
+ wp_register_style( 'pods-advanced', PODS_URL . 'ui/css/pods-advanced.css', array(), '1.0' );
152
+ wp_enqueue_style( 'pods-advanced' );
153
+
154
+ wp_enqueue_script( 'jquery-ui-effects-core', PODS_URL . 'ui/js/jquery-ui/jquery.effects.core.js', array( 'jquery' ), '1.8.8' );
155
+ wp_enqueue_script( 'jquery-ui-effects-fade', PODS_URL . 'ui/js/jquery-ui/jquery.effects.fade.js', array( 'jquery' ), '1.8.8' );
156
+ wp_enqueue_script( 'jquery-ui-dialog' );
157
+
158
+ wp_register_script( 'pods-advanced', PODS_URL . 'ui/js/advanced.js', array(), PODS_VERSION );
159
+ wp_enqueue_script( 'pods-advanced' );
160
+ }
161
+ elseif ( 'pods-packages' == $page )
162
+ wp_enqueue_style( 'pods-wizard' );
163
+ elseif ( 'pods-wizard' == $page || 'pods-upgrade' == $page || ( in_array( $page, array( 'pods', 'pods-add-new' ) ) && in_array( pods_var( 'action', 'get', 'manage' ), array( 'add', 'manage' ) ) ) ) {
164
+ wp_enqueue_style( 'pods-wizard' );
165
+
166
+ if ( 'pods-upgrade' == $page )
167
+ wp_enqueue_script( 'pods-upgrade' );
168
+ }
169
+ }
170
+ }
171
 
172
+ wp_enqueue_style( 'pods-font' );
173
+ }
174
 
175
+ /**
176
+ * Build the admin menus
177
+ *
178
+ * @since 2.0
179
+ */
180
+ public function admin_menu () {
181
+ $advanced_content_types = PodsMeta::$advanced_content_types;
182
+ $taxonomies = PodsMeta::$taxonomies;
183
+ $settings = PodsMeta::$settings;
 
 
 
 
 
 
 
 
 
184
 
185
+ $all_pods = pods_api()->load_pods( array( 'count' => true ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
 
187
+ if ( !PodsInit::$upgrade_needed || ( pods_is_admin() && 1 == pods_var( 'pods_upgrade_bypass' ) ) ) {
188
+ $submenu_items = array();
189
 
190
+ if ( !empty( $advanced_content_types ) ) {
191
+ $submenu = array();
 
 
 
 
192
 
193
+ $pods_pages = 0;
 
 
 
 
 
194
 
195
+ foreach ( (array) $advanced_content_types as $pod ) {
196
+ if ( !isset( $pod[ 'name' ] ) || !isset( $pod[ 'options' ] ) || empty( $pod[ 'fields' ] ) )
197
+ continue;
198
+ elseif ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ], 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) )
199
+ continue;
200
 
201
+ if ( 1 == pods_var( 'show_in_menu', $pod[ 'options' ], 0 ) ) {
202
+ $page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true );
203
+ $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
204
 
205
+ $menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true );
206
+ $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
207
 
208
+ $singular_label = pods_var_raw( 'label_singular', $pod[ 'options' ], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ), null, true );
209
+ $plural_label = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true );
210
 
211
+ $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'objects' );
212
+ $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
 
 
 
 
 
 
 
 
 
 
 
213
 
214
+ $menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true );
215
+ $menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true );
216
 
217
+ if ( empty( $menu_position ) )
218
+ $menu_position = null;
219
 
220
+ $parent_page = null;
221
 
222
+ if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) ) {
223
+ if ( !empty( $menu_location_custom ) ) {
224
+ if ( !isset( $submenu_items[ $menu_location_custom ] ) )
225
+ $submenu_items[ $menu_location_custom ] = array();
 
226
 
227
+ $submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', 'pods-manage-' . $pod[ 'name' ], array( $this, 'admin_content' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
 
229
+ continue;
230
+ }
231
+ else {
232
+ $pods_pages++;
 
 
 
 
 
 
 
 
 
233
 
234
+ $parent_page = $page = 'pods-manage-' . $pod[ 'name' ];
 
 
235
 
236
+ if ( empty( $menu_position ) )
237
+ $menu_position = null;
238
+ add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
 
240
+ $all_title = $plural_label;
241
+ $all_label = __( 'All', 'pods' ) . ' ' . $plural_label;
242
 
243
+ if ( $page == pods_var( 'page', 'get' ) ) {
244
+ if ( 'edit' == pods_var( 'action', 'get', 'manage' ) )
245
+ $all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label;
246
+ elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) )
247
+ $all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
248
+ }
249
 
250
+ add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) );
251
+ }
252
+ }
253
 
254
+ if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ] ) ) ) {
255
+ $page = 'pods-add-new-' . $pod[ 'name' ];
256
 
257
+ if ( null === $parent_page ) {
258
+ $pods_pages++;
259
 
260
+ $parent_page = $page;
 
261
 
262
+ if ( empty( $menu_position ) )
263
+ $menu_position = null;
264
+ add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
265
+ }
266
 
267
+ $add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
268
+ $add_label = __( 'Add New', 'pods' );
 
269
 
270
+ add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) );
271
+ }
272
+ }
273
+ else
274
+ $submenu[] = $pod;
275
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
 
277
+ $submenu = apply_filters( 'pods_admin_menu_secondary_content', $submenu );
 
 
 
 
 
 
 
 
 
 
278
 
279
+ if ( !empty( $submenu ) && ( !defined( 'PODS_DISABLE_CONTENT_MENU' ) || !PODS_DISABLE_CONTENT_MENU ) ) {
280
+ $parent_page = null;
 
 
281
 
282
+ foreach ( $submenu as $item ) {
283
+ $singular_label = pods_var_raw( 'label_singular', $item[ 'options' ], pods_var_raw( 'label', $item, ucwords( str_replace( '_', ' ', $item[ 'name' ] ) ), null, true ), null, true );
284
+ $plural_label = pods_var_raw( 'label', $item, ucwords( str_replace( '_', ' ', $item[ 'name' ] ) ), null, true );
285
 
286
+ if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $item[ 'name' ], 'pods_delete_' . $item[ 'name' ] ) ) ) {
287
+ $page = 'pods-manage-' . $item[ 'name' ];
 
288
 
289
+ if ( null === $parent_page ) {
290
+ $parent_page = $page;
291
 
292
+ add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' );
293
+ }
294
 
295
+ $all_title = $plural_label;
296
+ $all_label = __( 'Manage', 'pods' ) . ' ' . $plural_label;
 
297
 
298
+ if ( $page == pods_var( 'page', 'get' ) ) {
299
+ if ( 'edit' == pods_var( 'action', 'get', 'manage' ) )
300
+ $all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label;
301
+ elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) )
302
+ $all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
303
+ }
304
 
305
+ add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) );
306
+ }
307
+ elseif ( current_user_can( 'pods_add_' . $item[ 'name' ] ) ) {
308
+ $page = 'pods-add-new-' . $item[ 'name' ];
309
 
310
+ if ( null === $parent_page ) {
311
+ $parent_page = $page;
 
 
 
 
 
 
 
312
 
313
+ add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' );
314
+ }
 
 
 
 
 
 
 
 
315
 
316
+ $add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
317
+ $add_label = __( 'Manage', 'pods' ) . ' ' . $plural_label;
318
+
319
+ add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) );
320
+ }
321
+ }
322
+ }
323
+ }
324
+
325
+ if ( !empty( $taxonomies ) ) {
326
+ foreach ( (array) $taxonomies as $pod ) {
327
+ // Default taxonomy capability
328
+ $capability = 'manage_categories';
329
+
330
+ if ( ! empty( $pod[ 'options' ][ 'capability_type' ] ) ) {
331
+ if ( 'custom' == $pod[ 'options' ][ 'capability_type' ] && ! empty( $pod[ 'options' ][ 'capability_type_custom' ] ) ) {
332
+ $capability = 'manage_' . (string) $pod[ 'options' ][ 'capability_type_custom' ] . '_terms';
333
+ }
334
+ }
335
+
336
+ if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ], $capability ) ) )
337
+ continue;
338
+
339
+ // Check UI settings
340
+ if ( 1 != pods_var( 'show_ui', $pod[ 'options' ], 0 ) || 1 != pods_var( 'show_in_menu', $pod[ 'options' ], 0 ) )
341
+ continue;
342
+
343
+ $page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true );
344
+ $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
345
+
346
+ $menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true );
347
+ $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
348
+
349
+ $menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true );
350
+ $menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true );
351
+
352
+ if ( empty( $menu_position ) )
353
+ $menu_position = null;
354
+
355
+ $menu_slug = 'edit-tags.php?taxonomy=' . $pod[ 'name' ];
356
+ $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'default' );
357
+ $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
358
+
359
+ if ( 'default' == $menu_location )
360
+ continue;
361
+
362
+ $taxonomy_data = get_taxonomy( $pod[ 'name' ] );
363
+
364
+ foreach ( (array) $taxonomy_data->object_type as $post_type ) {
365
+ if ( 'post' == $post_type )
366
+ remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . $pod[ 'name' ] );
367
+ elseif ( 'attachment' == $post_type )
368
+ remove_submenu_page( 'upload.php', 'edit-tags.php?taxonomy=' . $pod[ 'name' ] . '&amp;post_type=' . $post_type );
369
+ else
370
+ remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . $pod[ 'name' ] . '&amp;post_type=' . $post_type );
371
+ }
372
+
373
+ if ( 'settings' == $menu_location )
374
+ add_options_page( $page_title, $menu_label, 'read', $menu_slug );
375
+ elseif ( 'appearances' == $menu_location )
376
+ add_theme_page( $page_title, $menu_label, 'read', $menu_slug );
377
+ elseif ( 'objects' == $menu_location ) {
378
+ if ( empty( $menu_position ) )
379
+ $menu_position = null;
380
+ add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position );
381
+ }
382
+ elseif ( 'top' == $menu_location )
383
+ add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position );
384
+ elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) {
385
+ if ( !isset( $submenu_items[ $menu_location_custom ] ) )
386
+ $submenu_items[ $menu_location_custom ] = array();
387
+
388
+ $submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', $menu_slug, '' );
389
+ }
390
+ }
391
+ }
392
+
393
+ if ( !empty( $settings ) ) {
394
+ foreach ( (array) $settings as $pod ) {
395
+ if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ] ) ) )
396
+ continue;
397
+
398
+ $page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true );
399
+ $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
400
+
401
+ $menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true );
402
+ $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
403
+
404
+ $menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true );
405
+ $menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true );
406
+
407
+ if ( empty( $menu_position ) )
408
+ $menu_position = null;
409
+
410
+ $menu_slug = 'pods-settings-' . $pod[ 'name' ];
411
+ $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'settings' );
412
+ $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
413
+
414
+ if ( 'settings' == $menu_location )
415
+ add_options_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) );
416
+ elseif ( 'appearances' == $menu_location )
417
+ add_theme_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) );
418
+ elseif ( 'objects' == $menu_location ) {
419
+ if ( empty( $menu_position ) )
420
+ $menu_position = null;
421
+ add_menu_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon, $menu_position );
422
+ }
423
+ elseif ( 'top' == $menu_location )
424
+ add_menu_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon, $menu_position );
425
+ elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) {
426
+ if ( !isset( $submenu_items[ $menu_location_custom ] ) )
427
+ $submenu_items[ $menu_location_custom ] = array();
428
+
429
+ $submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) );
430
+ }
431
+ }
432
+ }
433
+
434
+ foreach ( $submenu_items as $items ) {
435
+ foreach ( $items as $item ) {
436
+ call_user_func_array( 'add_submenu_page', $item );
437
+ }
438
+ }
439
+
440
+ $admin_menus = array(
441
+ 'pods' => array(
442
+ 'label' => __( 'Edit Pods', 'pods' ),
443
+ 'function' => array( $this, 'admin_setup' ),
444
+ 'access' => 'pods'
445
+ ),
446
+ 'pods-add-new' => array(
447
+ 'label' => __( 'Add New', 'pods' ),
448
+ 'function' => array( $this, 'admin_setup' ),
449
+ 'access' => 'pods'
450
+ ),
451
+ 'pods-components' => array(
452
+ 'label' => __( 'Components', 'pods' ),
453
+ 'function' => array( $this, 'admin_components' ),
454
+ 'access' => 'pods_components'
455
+ ),
456
+ 'pods-settings' => array(
457
+ 'label' => __( 'Settings', 'pods' ),
458
+ 'function' => array( $this, 'admin_settings' ),
459
+ 'access' => 'pods_settings'
460
+ ),
461
+ 'pods-help' => array(
462
+ 'label' => __( 'Help', 'pods' ),
463
+ 'function' => array( $this, 'admin_help' )
464
+ )
465
+ );
466
+
467
+ if ( empty( $all_pods ) )
468
+ unset( $admin_menus[ 'pods' ] );
469
+
470
+ add_filter( 'parent_file' , array( $this, 'parent_file' ) );
471
+ }
472
+ else {
473
+ $admin_menus = array(
474
+ 'pods-upgrade' => array(
475
+ 'label' => __( 'Upgrade', 'pods' ),
476
+ 'function' => array( $this, 'admin_upgrade' ),
477
+ 'access' => 'manage_options'
478
+ ),
479
+ 'pods-settings' => array(
480
+ 'label' => __( 'Settings', 'pods' ),
481
+ 'function' => array( $this, 'admin_settings' ),
482
+ 'access' => 'pods_settings'
483
+ ),
484
+ 'pods-help' => array(
485
+ 'label' => __( 'Help', 'pods' ),
486
+ 'function' => array( $this, 'admin_help' )
487
+ )
488
+ );
489
+
490
+ add_action( 'admin_notices', array( $this, 'upgrade_notice' ) );
491
+ }
492
 
493
+ /**
494
+ * Add or change Pods Admin menu items
495
+ *
496
+ * @params array $admin_menus The submenu items in Pods Admin menu.
497
+ *
498
+ * @since unknown
499
+ */
500
+ $admin_menus = apply_filters( 'pods_admin_menu', $admin_menus );
501
 
502
+ $parent = false;
503
+
504
+ // PODS_LIGHT disables all Pods components so remove the components menu
505
+ if ( defined( 'PODS_LIGHT' ) && true == PODS_LIGHT ) {
506
+ unset( $admin_menus['pods-components'] );
507
+ }
508
+
509
+ if ( !empty( $admin_menus ) && ( !defined( 'PODS_DISABLE_ADMIN_MENU' ) || !PODS_DISABLE_ADMIN_MENU ) ) {
510
+ foreach ( $admin_menus as $page => $menu_item ) {
511
+ if ( !pods_is_admin( pods_var_raw( 'access', $menu_item ) ) )
512
+ continue;
513
+
514
+ // Don't just show the help page
515
+ if ( false === $parent && 'pods-help' == $page )
516
+ continue;
517
+
518
+ if ( !isset( $menu_item[ 'label' ] ) )
519
+ $menu_item[ 'label' ] = $page;
520
+
521
+ if ( false === $parent ) {
522
+ $parent = $page;
523
+
524
+ $menu = __( 'Pods Admin', 'pods' );
525
+
526
+ if ( 'pods-upgrade' == $parent )
527
+ $menu = __( 'Pods Upgrade', 'pods' );
528
+
529
+ add_menu_page( $menu, $menu, 'read', $parent, null, 'dashicons-pods' );
530
+ }
531
+
532
+ add_submenu_page( $parent, $menu_item[ 'label' ], $menu_item[ 'label' ], 'read', $page, $menu_item[ 'function' ] );
533
+
534
+ if ( 'pods-components' == $page && is_object( PodsInit::$components ) )
535
+ PodsInit::$components->menu( $parent );
536
+ }
537
+ }
538
+ }
539
+
540
+ /**
541
+ * Set the correct parent_file to highlight the correct top level menu
542
+ *
543
+ * @param $parent_file The parent file
544
+ *
545
+ * @return mixed|string
546
+ *
547
+ * @since unknown
548
+ */
549
+ public function parent_file ( $parent_file ) {
550
+ global $current_screen;
551
+
552
+ if ( isset( $current_screen ) && ! empty( $current_screen->taxonomy ) ) {
553
+ $taxonomies = PodsMeta::$taxonomies;
554
+ if ( !empty( $taxonomies ) ) {
555
+ foreach ( (array) $taxonomies as $pod ) {
556
+ if ( $current_screen->taxonomy !== $pod[ 'name' ] )
557
+ continue;
558
+
559
+ $menu_slug = 'edit-tags.php?taxonomy=' . $pod[ 'name' ];
560
+ $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'default' );
561
+ $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
562
+
563
+ if ( 'settings' == $menu_location )
564
+ $parent_file = 'options-general.php';
565
+ elseif ( 'appearances' == $menu_location )
566
+ $parent_file = 'themes.php';
567
+ elseif ( 'objects' == $menu_location )
568
+ $parent_file = $menu_slug;
569
+ elseif ( 'top' == $menu_location )
570
+ $parent_file = $menu_slug;
571
+ elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) {
572
+ $parent_file = $menu_location_custom;
573
+ }
574
+
575
+ break;
576
+ }
577
+ }
578
+ }
579
+
580
+ if ( isset( $current_screen ) && ! empty( $current_screen->post_type ) && is_object( PodsInit::$components ) ) {
581
+ global $submenu_file;
582
+ $components = PodsInit::$components->components;
583
+ foreach ( $components as $component => $component_data ) {
584
+ if ( ! empty( $component_data[ 'MenuPage' ] ) && $parent_file === $component_data[ 'MenuPage' ] ) {
585
+ $parent_file = 'pods';
586
+ $submenu_file = $component_data[ 'MenuPage' ];
587
+ }
588
+ }
589
+ }
590
+
591
+ return $parent_file;
592
+ }
593
+
594
+ public function upgrade_notice () {
595
+ echo '<div class="error fade"><p>';
596
+ echo sprintf(
597
+ __( '<strong>NOTICE:</strong> Pods %s requires your action to complete the upgrade. Please run the <a href="%s">Upgrade Wizard</a>.', 'pods' ),
598
+ esc_html( PODS_VERSION ),
599
+ esc_url( admin_url( 'admin.php?page=pods-upgrade' ) )
600
+ );
601
+ echo '</p></div>';
602
+ }
603
+
604
+ /**
605
+ * Create PodsUI content for the administration pages
606
+ */
607
+ public function admin_content () {
608
+ $pod_name = str_replace( array( 'pods-manage-', 'pods-add-new-' ), '', $_GET[ 'page' ] );
609
+
610
+ $pod = pods( $pod_name, pods_var( 'id', 'get', null, null, true ) );
611
+
612
+ if ( false !== strpos( $_GET[ 'page' ], 'pods-add-new-' ) )
613
+ $_GET[ 'action' ] = pods_var( 'action', 'get', 'add' );
614
+
615
+ $pod->ui();
616
+ }
617
+
618
+ /**
619
+ * Create PodsUI content for the settings administration pages
620
+ */
621
+ public function admin_content_settings () {
622
+ $pod_name = str_replace( 'pods-settings-', '', $_GET[ 'page' ] );
623
+
624
+ $pod = pods( $pod_name );
625
+
626
+ if ( 'custom' != pods_var( 'ui_style', $pod->pod_data[ 'options' ], 'settings', null, true ) ) {
627
+ $actions_disabled = array(
628
+ 'manage' => 'manage',
629
+ 'add' => 'add',
630
+ 'delete' => 'delete',
631
+ 'duplicate' => 'duplicate',
632
+ 'view' => 'view',
633
+ 'export' => 'export'
634
+ );
635
+
636
+ $_GET[ 'action' ] = 'edit';
637
+
638
+ $page_title = pods_var_raw( 'label', $pod->pod_data, ucwords( str_replace( '_', ' ', $pod->pod_data[ 'name' ] ) ), null, true );
639
+
640
+ $ui = array(
641
+ 'pod' => $pod,
642
+ 'fields' => array(
643
+ 'edit' => $pod->pod_data[ 'fields' ]
644
+ ),
645
+ 'header' => array(
646
+ 'edit' => $page_title
647
+ ),
648
+ 'label' => array(
649
+ 'edit' => __( 'Save Changes', 'pods' )
650
+ ),
651
+ 'style' => pods_var( 'ui_style', $pod->pod_data[ 'options' ], 'settings', null, true ),
652
+ 'icon' => pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod->pod_data[ 'options' ] ), true ),
653
+ 'actions_disabled' => $actions_disabled
654
+ );
655
+
656
+ $ui = apply_filters( 'pods_admin_ui_' . $pod->pod, apply_filters( 'pods_admin_ui', $ui, $pod->pod, $pod ), $pod->pod, $pod );
657
+
658
+ // Force disabled actions, do not pass go, do not collect $two_hundred
659
+ $ui[ 'actions_disabled' ] = $actions_disabled;
660
+
661
+ pods_ui( $ui );
662
+ }
663
+ else {
664
+ do_action( 'pods_admin_ui_custom', $pod );
665
+ do_action( 'pods_admin_ui_custom_' . $pod->pod, $pod );
666
+ }
667
+ }
668
+
669
+ /**
670
+ * Add media button for Pods shortcode
671
+ *
672
+ * @param $context
673
+ *
674
+ * @return string
675
+ */
676
+ public function media_button ( $context = null ) {
677
+ // If shortcodes are disabled don't show the button
678
+ if ( defined( 'PODS_DISABLE_SHORTCODE' ) && PODS_DISABLE_SHORTCODE ) {
679
+ return '';
680
+ }
681
 
682
+ /**
683
+ * Filter to remove Pods shortcode button from the post editor.
684
+ *
685
+ * @param bool. Set to false to block the shortcode button from appearing.
686
+ * @param string $context
687
+ *
688
+ * @since 2.3.19
689
+ */
690
+ if ( !apply_filters( 'pods_admin_media_button', true, $context ) ) {
691
+ return '';
692
+ }
693
 
694
+ $current_page = basename( $_SERVER[ 'PHP_SELF' ] );
695
+ $current_page = explode( '?', $current_page );
696
+ $current_page = explode( '#', $current_page[ 0 ] );
697
+ $current_page = $current_page[ 0 ];
698
+
699
+ // Only show the button on post type pages
700
+ if ( !in_array( $current_page, array( 'post-new.php', 'post.php' ) ) )
701
+ return '';
702
+
703
+ add_action( 'admin_footer', array( $this, 'mce_popup' ) );
704
+
705
+ echo '<a href="#TB_inline?width=640&inlineId=pods_shortcode_form" class="thickbox button" id="add_pod_button" title="Pods Shortcode"><img style="padding: 0px 6px 0px 0px; margin: -3px 0px 0px;" src="' . PODS_URL . 'ui/images/icon16.png" alt="' . __('Pods Shortcode' ,'pods') . '" />' . __('Pods Shortcode' ,'pods') . '</a>';
706
+ }
707
+
708
+ /**
709
+ * Enqueue assets for Media Library Popup
710
+ */
711
+ public function register_media_assets () {
712
+ if ( 'pods_media_attachment' == pods_var( 'inlineId', 'get' ) )
713
+ wp_enqueue_style( 'pods-attach' );
714
+ }
715
+
716
+ /**
717
+ * Output Pods shortcode popup window
718
+ */
719
+ public function mce_popup () {
720
+ pods_view( PODS_DIR . 'ui/admin/shortcode.php', compact( array_keys( get_defined_vars() ) ) );
721
+ }
722
+
723
+ /**
724
+ * Handle main Pods Setup area for managing Pods and Fields
725
+ */
726
+ public function admin_setup () {
727
+ $pods = pods_api()->load_pods( array( 'fields' => false ) );
728
+
729
+ $view = pods_var( 'view', 'get', 'all', null, true );
730
+
731
+ if ( empty( $pods ) && !isset( $_GET[ 'action' ] ) )
732
+ $_GET[ 'action' ] = 'add';
733
+
734
+ if ( 'pods-add-new' == $_GET[ 'page' ] ) {
735
+ if ( isset( $_GET[ 'action' ] ) && 'add' != $_GET[ 'action' ] )
736
+ pods_redirect( pods_query_arg( array( 'page' => 'pods', 'action' => $_GET[ 'action' ] ) ) );
737
+ else
738
+ $_GET[ 'action' ] = 'add';
739
+ }
740
+ elseif ( isset( $_GET[ 'action' ] ) && 'add' == $_GET[ 'action' ] )
741
+ pods_redirect( pods_query_arg( array( 'page' => 'pods-add-new', 'action' => '' ) ) );
742
+
743
+ $types = array(
744
+ 'post_type' => __( 'Post Type (extended)', 'pods' ),
745
+ 'taxonomy' => __( 'Taxonomy (extended)', 'pods' ),
746
+ 'cpt' => __( 'Custom Post Type', 'pods' ),
747
+ 'ct' => __( 'Custom Taxonomy', 'pods' ),
748
+ 'user' => __( 'User (extended)', 'pods' ),
749
+ 'media' => __( 'Media (extended)', 'pods' ),
750
+ 'comment' => __( 'Comments (extended)', 'pods' ),
751
+ 'pod' => __( 'Advanced Content Type', 'pods' ),
752
+ 'settings' => __( 'Custom Settings Page', 'pods' )
753
+ );
754
+
755
+ $row = false;
756
+
757
+ $pod_types_found = array();
758
+
759
+ $fields = array(
760
+ 'label' => array( 'label' => __( 'Label', 'pods' ) ),
761
+ 'name' => array( 'label' => __( 'Name', 'pods' ) ),
762
+ 'type' => array( 'label' => __( 'Type', 'pods' ) ),
763
+ 'storage' => array(
764
+ 'label' => __( 'Storage Type', 'pods' ),
765
+ 'width' => '10%'
766
+ ),
767
+ 'field_count' => array(
768
+ 'label' => __( 'Number of Fields', 'pods' ),
769
+ 'width' => '8%'
770
+ )
771
+ );
772
+
773
+ $total_fields = 0;
774
+
775
+ foreach ( $pods as $k => $pod ) {
776
+ if ( isset( $types[ $pod[ 'type' ] ] ) ) {
777
+ if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) ) {
778
+ if ( empty( $pod[ 'object' ] ) ) {
779
+ if ( 'post_type' == $pod[ 'type' ] )
780
+ $pod[ 'type' ] = 'cpt';
781
+ else
782
+ $pod[ 'type' ] = 'ct';
783
+ }
784
+ }
785
+
786
+ if ( !isset( $pod_types_found[ $pod[ 'type' ] ] ) )
787
+ $pod_types_found[ $pod[ 'type' ] ] = 1;
788
+ else
789
+ $pod_types_found[ $pod[ 'type' ] ]++;
790
+
791
+ if ( 'all' != $view && $view != $pod[ 'type' ] ) {
792
+ unset( $pods[ $k ] );
793
+
794
+ continue;
795
+ }
796
+
797
+ $pod[ 'real_type' ] = $pod[ 'type' ];
798
+ $pod[ 'type' ] = $types[ $pod[ 'type' ] ];
799
+ }
800
+ elseif ( 'all' != $view )
801
+ continue;
802
+
803
+ $pod[ 'storage' ] = ucwords( $pod[ 'storage' ] );
804
+
805
+ if ( $pod[ 'id' ] == pods_var( 'id' ) && 'delete' != pods_var( 'action' ) )
806
+ $row = $pod;
807
+
808
+ $pod = array(
809
+ 'id' => $pod[ 'id' ],
810
+ 'label' => pods_var_raw( 'label', $pod ),
811
+ 'name' => pods_var_raw( 'name', $pod ),
812
+ 'object' => pods_var_raw( 'object', $pod ),
813
+ 'type' => pods_var_raw( 'type', $pod ),
814
+ 'real_type' => pods_var_raw( 'real_type', $pod ),
815
+ 'storage' => pods_var_raw( 'storage', $pod ),
816
+ 'field_count' => count( $pod[ 'fields' ] )
817
+ );
818
+
819
+ $total_fields += $pod[ 'field_count' ];
820
+
821
+ $pods[ $k ] = $pod;
822
+ }
823
+
824
+ if ( false === $row && 0 < pods_var( 'id' ) && 'delete' != pods_var( 'action' ) ) {
825
+ pods_message( 'Pod not found', 'error' );
826
+
827
+ unset( $_GET[ 'id' ] );
828
+ unset( $_GET[ 'action' ] );
829
+ }
830
+
831
+ $ui = array(
832
+ 'data' => $pods,
833
+ 'row' => $row,
834
+ 'total' => count( $pods ),
835
+ 'total_found' => count( $pods ),
836
+ 'items' => 'Pods',
837
+ 'item' => 'Pod',
838
+ 'fields' => array(
839
+ 'manage' => $fields
840
+ ),
841
+ 'actions_disabled' => array( 'view', 'export' ),
842
+ 'actions_custom' => array(
843
+ 'add' => array( $this, 'admin_setup_add' ),
844
+ 'edit' => array( $this, 'admin_setup_edit' ),
845
+ 'duplicate' => array(
846
+ 'callback' => array( $this, 'admin_setup_duplicate' ),
847
+ 'restrict_callback' => array( $this, 'admin_setup_duplicate_restrict' )
848
+ ),
849
+ 'reset' => array(
850
+ 'label' => __( 'Delete All Items', 'pods' ),
851
+ 'confirm' => __( 'Are you sure you want to delete all items from this Pod? If this is an extended Pod, it will remove the original items extended too.', 'pods' ),
852
+ 'callback' => array( $this, 'admin_setup_reset' ),
853
+ 'restrict_callback' => array( $this, 'admin_setup_reset_restrict' ),
854
+ 'nonce' => true
855
+ ),
856
+ 'delete' => array( $this, 'admin_setup_delete' )
857
+ ),
858
+ 'action_links' => array(
859
+ 'add' => pods_query_arg( array( 'page' => 'pods-add-new', 'action' => '', 'id' => '', 'do' => '' ) )
860
+ ),
861
+ 'search' => false,
862
+ 'searchable' => false,
863
+ 'sortable' => true,
864
+ 'pagination' => false,
865
+ 'extra' => array(
866
+ 'total' => ', ' . number_format_i18n( $total_fields ) . ' ' . _n( 'field', 'fields', $total_fields, 'pods' )
867
+ )
868
+ );
869
+
870
+ if ( 1 < count( $pod_types_found ) ) {
871
+ $ui[ 'views' ] = array( 'all' => __( 'All', 'pods' ) );
872
+ $ui[ 'view' ] = $view;
873
+ $ui[ 'heading' ] = array( 'views' => __( 'Type', 'pods' ) );
874
+ $ui[ 'filters_enhanced' ] = true;
875
+
876
+ foreach ( $pod_types_found as $pod_type => $number_found ) {
877
+ $ui[ 'views' ][ $pod_type ] = $types[ $pod_type ];
878
+ }
879
+ }
880
+
881
+ pods_ui( $ui );
882
+ }
883
+
884
+ /**
885
+ * Get the add page of an object
886
+ *
887
+ * @param $obj
888
+ */
889
+ public function admin_setup_add ( $obj ) {
890
+ pods_view( PODS_DIR . 'ui/admin/setup-add.php', compact( array_keys( get_defined_vars() ) ) );
891
+ }
892
+
893
+ /**
894
+ * Get the edit page of an object
895
+ *
896
+ * @param $duplicate
897
+ * @param $obj
898
+ */
899
+ public function admin_setup_edit ( $duplicate, $obj ) {
900
+ pods_view( PODS_DIR . 'ui/admin/setup-edit.php', compact( array_keys( get_defined_vars() ) ) );
901
+ }
902
+
903
+ /**
904
+ * Get list of Pod option tabs
905
+ *
906
+ * @return array
907
+ */
908
+ public function admin_setup_edit_tabs ( $pod ) {
909
+ $fields = true;
910
+ $labels = false;
911
+ $admin_ui = false;
912
+ $advanced = false;
913
+
914
+ if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) {
915
+ $labels = true;
916
+ $admin_ui = true;
917
+ $advanced = true;
918
+ }
919
+ elseif ( 'taxonomy' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) {
920
+ $labels = true;
921
+ $admin_ui = true;
922
+ $advanced = true;
923
+ }
924
+ elseif ( 'pod' == pods_var( 'type', $pod ) ) {
925
+ $labels = true;
926
+ $admin_ui = true;
927
+ $advanced = true;
928
+ }
929
+ elseif ( 'settings' == pods_var( 'type', $pod ) ) {
930
+ $labels = true;
931
+ $admin_ui = true;
932
+ }
933
+
934
+ if ( ! function_exists( 'get_term_meta' ) && 'none' == pods_var( 'storage', $pod, 'none', null, true ) && 'taxonomy' == pods_var( 'type', $pod ) )
935
+ $fields = false;
936
+
937
+ $tabs = array();
938
+
939
+ if ( $fields )
940
+ $tabs[ 'manage-fields' ] = __( 'Manage Fields', 'pods' );
941
+
942
+ if ( $labels )
943
+ $tabs[ 'labels' ] = __( 'Labels', 'pods' );
944
+
945
+ if ( $admin_ui )
946
+ $tabs[ 'admin-ui' ] = __( 'Admin UI', 'pods' );
947
+
948
+ if ( $advanced )
949
+ $tabs[ 'advanced' ] = __( 'Advanced Options', 'pods' );
950
+
951
+ if ( 'taxonomy' == pods_var( 'type', $pod ) && !$fields )
952
+ $tabs[ 'extra-fields' ] = __( 'Extra Fields', 'pods' );
953
 
954
+ $addtl_args = compact( array( 'fields', 'labels', 'admin_ui', 'advanced' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
955
 
956
+ /**
957
+ * Add or modify tabs in Pods editor for a specific Pod
958
+ *
959
+ * @params array $tabs Tabs to set.
960
+ * @params object $pod Current Pods object
961
+ * @params array $addtl_args Additional args.
962
+ *
963
+ * @since unknown
964
+ */
965
+ $tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod[ 'type' ] . '_' . $pod[ 'name' ], $tabs, $pod, $addtl_args );
 
 
 
 
 
 
 
 
966
 
967
+ /**
968
+ * Add or modify tabs for any Pod in Pods editor of a specific post type.
969
+ */
970
+ $tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod[ 'type' ], $tabs, $pod, $addtl_args );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
971
 
972
+ /**
973
+ * Add or modify tabs in Pods editor for all pods.
974
+ */
975
+ $tabs = apply_filters( 'pods_admin_setup_edit_tabs', $tabs, $pod, $addtl_args );
976
 
977
+ return $tabs;
978
+ }
979
+
980
+ /**
981
+ * Get list of Pod options
982
+ *
983
+ * @return array
984
+ */
985
+ public function admin_setup_edit_options ( $pod ) {
986
+ $options = array();
987
+
988
+ // @todo fill this in
989
+ $options[ 'labels' ] = array(
990
+ 'temporary' => 'This has the fields hardcoded' // :(
991
+ );
992
+
993
+ if ( 'post_type' == $pod[ 'type' ] ) {
994
+ $options[ 'admin-ui' ] = array(
995
+ 'description' => array(
996
+ 'label' => __( 'Post Type Description', 'pods' ),
997
+ 'help' => __( 'A short descriptive summary of what the post type is.', 'pods' ),
998
+ 'type' => 'text',
999
+ 'default' => ''
1000
+ ),
1001
+ 'show_ui' => array(
1002
+ 'label' => __( 'Show Admin UI', 'pods' ),
1003
+ 'help' => __( 'Whether to generate a default UI for managing this post type in the admin.', 'pods' ),
1004
+ 'type' => 'boolean',
1005
+ 'default' => pods_var_raw( 'public', $pod, true ),
1006
+ 'boolean_yes_label' => ''
1007
+ ),
1008
+ 'show_in_menu' => array(
1009
+ 'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
1010
+ 'help' => __( 'Whether to show the post type in the admin menu.', 'pods' ),
1011
+ 'type' => 'boolean',
1012
+ 'default' => pods_var_raw( 'public', $pod, true ),
1013
+ 'dependency' => true,
1014
+ 'boolean_yes_label' => ''
1015
+ ),
1016
+ 'menu_location_custom' => array(
1017
+ 'label' => __( 'Parent Menu ID (optional)', 'pods' ),
1018
+ 'help' => __( 'help', 'pods' ),
1019
+ 'type' => 'text',
1020
+ 'depends-on' => array( 'show_in_menu' => true )
1021
+ ),
1022
+ 'menu_name' => array(
1023
+ 'label' => __( 'Menu Name', 'pods' ),
1024
+ 'help' => __( 'help', 'pods' ),
1025
+ 'type' => 'text',
1026
+ 'default' => '',
1027
+ 'depends-on' => array( 'show_in_menu' => true )
1028
+ ),
1029
+ 'menu_position' => array(
1030
+ 'label' => __( 'Menu Position', 'pods' ),
1031
+ 'help' => __( 'help', 'pods' ),
1032
+ 'type' => 'number',
1033
+ 'number_decimals' => 2,
1034
+ 'number_format' => '9999.99',
1035
+ 'number_format_soft' => 1,
1036
+ 'default' => 0,
1037
+ 'depends-on' => array( 'show_in_menu' => true )
1038
+ ),
1039
+ 'menu_icon' => array(
1040
+ 'label' => __( 'Menu Icon', 'pods' ),
1041
+ 'help' => __( 'URL or Dashicon name for the menu icon. You may specify the path to the icon using one of the <a href="http://pods.io/docs/build/special-magic-tags/#site-tags" target="_blank">site tag</a> type <a href="http://pods.io/docs/build/special-magic-tags/" target="_blank">special magic tags</a>. For example, for a file in your theme directory, use "{@template-url}/path/to/image.png". You may also use the name of a <a href="https://developer.wordpress.org/resource/dashicons/" target="_blank">Dashicon</a>. For example, to use the empty star icon, use "dashicons-star-empty".', 'pods' ),
1042
+ 'type' => 'text',
1043
+ 'default' => '',
1044
+ 'depends-on' => array( 'show_in_menu' => true )
1045
+ ),
1046
+ 'show_in_nav_menus' => array(
1047
+ 'label' => __( 'Show in Navigation Menus', 'pods' ),
1048
+ 'help' => __( 'help', 'pods' ),
1049
+ 'type' => 'boolean',
1050
+ 'default' => true,
1051
+ 'boolean_yes_label' => ''
1052
+ ),
1053
+ 'show_in_admin_bar' => array(
1054
+ 'label' => __( 'Show in Admin Bar "New" Menu', 'pods' ),
1055
+ 'help' => __( 'help', 'pods' ),
1056
+ 'type' => 'boolean',
1057
+ 'default' => true,
1058
+ 'boolean_yes_label' => ''
1059
+ )
1060
+ );
1061
+
1062
+ $options[ 'advanced' ] = array(
1063
+ 'public' => array(
1064
+ 'label' => __( 'Public', 'pods' ),
1065
+ 'help' => __( 'help', 'pods' ),
1066
+ 'type' => 'boolean',
1067
+ 'default' => true,
1068
+ 'boolean_yes_label' => ''
1069
+ ),
1070
+ 'publicly_queryable' => array(
1071
+ 'label' => __( 'Publicly Queryable', 'pods' ),
1072
+ 'help' => __( 'help', 'pods' ),
1073
+ 'type' => 'boolean',
1074
+ 'default' => pods_var_raw( 'public', $pod, true ),
1075
+ 'boolean_yes_label' => ''
1076
+ ),
1077
+ 'exclude_from_search' => array(
1078
+ 'label' => __( 'Exclude from Search', 'pods' ),
1079
+ 'help' => __( 'help', 'pods' ),
1080
+ 'type' => 'boolean',
1081
+ 'default' => !pods_var_raw( 'public', $pod, true ),
1082
+ 'boolean_yes_label' => ''
1083
+ ),
1084
+ 'capability_type' => array(
1085
+ 'label' => __( 'User Capability', 'pods' ),
1086
+ 'help' => __( 'Uses these capabilties for access to this post type: edit_{capability}, read_{capability}, and delete_{capability}', 'pods' ),
1087
+ 'type' => 'pick',
1088
+ 'default' => 'post',
1089
+ 'data' => array(
1090
+ 'post' => 'post',
1091
+ 'page' => 'page',
1092
+ 'custom' => __( 'Custom Capability', 'pods' )
1093
+ ),
1094
+ 'dependency' => true
1095
+ ),
1096
+ 'capability_type_custom' => array(
1097
+ 'label' => __( 'Custom User Capability', 'pods' ),
1098
+ 'help' => __( 'help', 'pods' ),
1099
+ 'type' => 'text',
1100
+ 'default' => pods_var_raw( 'name', $pod ),
1101
+ 'depends-on' => array( 'capability_type' => 'custom' )
1102
+ ),
1103
+ 'capability_type_extra' => array(
1104
+ 'label' => __( 'Additional User Capabilities', 'pods' ),
1105
+ 'help' => __( 'Enables additional capabilities for this Post Type including: delete_{capability}s, delete_private_{capability}s, delete_published_{capability}s, delete_others_{capability}s, edit_private_{capability}s, and edit_published_{capability}s', 'pods' ),
1106
+ 'type' => 'boolean',
1107
+ 'default' => true,
1108
+ 'boolean_yes_label' => ''
1109
+ ),
1110
+ 'has_archive' => array(
1111
+ 'label' => __( 'Enable Archive Page', 'pods' ),
1112
+ 'help' => __( 'If enabled, creates an archive page with list of of items in this custom post type. Functions like a category page for posts. Can be controlled with a template in your theme called "archive-{$post-type}.php".', 'pods' ),
1113
+ 'type' => 'boolean',
1114
+ 'default' => false,
1115
+ 'dependency' => true,
1116
+ 'boolean_yes_label' => ''
1117
+ ),
1118
+ 'has_archive_slug' => array(
1119
+ 'label' => __( 'Archive Page Slug Override', 'pods' ),
1120
+ 'help' => __( 'If archive page is enabled, you can override the slug used by WordPress, which defaults to the name of the post type.', 'pods' ),
1121
+ 'type' => 'text',
1122
+ 'default' => '',
1123
+ 'depends-on' => array( 'has_archive' => true )
1124
+ ),
1125
+ 'hierarchical' => array(
1126
+ 'label' => __( 'Hierarchical', 'pods' ),
1127
+ 'help' => __( 'Allows for parent/ child relationships between items, just like with Pages. Note: To edit relationships in the post editor, you must enable "Page Attributes" in the "Supports" section below.', 'pods' ),
1128
+ 'type' => 'boolean',
1129
+ 'default' => false,
1130
+ 'dependency' => true,
1131
+ 'boolean_yes_label' => ''
1132
+ ),
1133
+ 'label_parent_item_colon' => array(
1134
+ 'label' => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1135
+ 'help' => __( 'help', 'pods' ),
1136
+ 'type' => 'text',
1137
+ 'default' => '',
1138
+ 'depends-on' => array( 'hierarchical' => true )
1139
+ ),
1140
+ 'label_parent' => array(
1141
+ 'label' => __( '<strong>Label: </strong> Parent', 'pods' ),
1142
+ 'help' => __( 'help', 'pods' ),
1143
+ 'type' => 'text',
1144
+ 'default' => '',
1145
+ 'depends-on' => array( 'hierarchical' => true )
1146
+ ),
1147
+ 'rewrite' => array(
1148
+ 'label' => __( 'Rewrite', 'pods' ),
1149
+ 'help' => __( 'Allows you to use pretty permalinks, if set in WordPress Settings->Permalinks. If not enabled, your links will be in the form of "example.com/?pod_name=post_slug" regardless of your permalink settings.', 'pods' ),
1150
+ 'type' => 'boolean',
1151
+ 'default' => true,
1152
+ 'dependency' => true,
1153
+ 'boolean_yes_label' => ''
1154
+ ),
1155
+ 'rewrite_custom_slug' => array(
1156
+ 'label' => __( 'Custom Rewrite Slug', 'pods' ),
1157
+ 'help' => __( 'Changes the first segment of the URL, which by default is the name of the Pod. For example, if your Pod is called "foo", if this field is left blank, your link will be "example.com/foo/post_slug", but if you were to enter "bar" your link will be "example.com/bar/post_slug".', 'pods' ),
1158
+ 'type' => 'text',
1159
+ 'default' => '',
1160
+ 'depends-on' => array( 'rewrite' => true )
1161
+ ),
1162
+ 'rewrite_with_front' => array(
1163
+ 'label' => __( 'Rewrite with Front', 'pods' ),
1164
+ 'help' => __( 'Allows permalinks to be prepended with your front base (example: if your permalink structure is /blog/, then your links will be: Unchecked->/news/, Checked->/blog/news/)', 'pods' ),
1165
+ 'type' => 'boolean',
1166
+ 'default' => true,
1167
+ 'depends-on' => array( 'rewrite' => true ),
1168
+ 'boolean_yes_label' => ''
1169
+ ),
1170
+ 'rewrite_feeds' => array(
1171
+ 'label' => __( 'Rewrite Feeds', 'pods' ),
1172
+ 'help' => __( 'help', 'pods' ),
1173
+ 'type' => 'boolean',
1174
+ 'default' => false,
1175
+ 'depends-on' => array( 'rewrite' => true ),
1176
+ 'boolean_yes_label' => ''
1177
+ ),
1178
+ 'rewrite_pages' => array(
1179
+ 'label' => __( 'Rewrite Pages', 'pods' ),
1180
+ 'help' => __( 'help', 'pods' ),
1181
+ 'type' => 'boolean',
1182
+ 'default' => true,
1183
+ 'depends-on' => array( 'rewrite' => true ),
1184
+ 'boolean_yes_label' => ''
1185
+ ),
1186
+ 'query_var' => array(
1187
+ 'label' => __( 'Query Var', 'pods' ),
1188
+ 'help' => __( 'The Query Var is used in the URL and underneath the WordPress Rewrite API to tell WordPress what page or post type you are on. For a list of reserved Query Vars, read <a href="http://codex.wordpress.org/WordPress_Query_Vars">WordPress Query Vars</a> from the WordPress Codex.', 'pods' ),
1189
+ 'type' => 'boolean',
1190
+ 'default' => true,
1191
+ 'boolean_yes_label' => ''
1192
+ ),
1193
+ 'can_export' => array(
1194
+ 'label' => __( 'Exportable', 'pods' ),
1195
+ 'help' => __( 'help', 'pods' ),
1196
+ 'type' => 'boolean',
1197
+ 'default' => true,
1198
+ 'boolean_yes_label' => ''
1199
+ ),
1200
+ 'default_status' => array(
1201
+ 'label' => __( 'Default Status', 'pods' ),
1202
+ 'help' => __( 'help', 'pods' ),
1203
+ 'type' => 'pick',
1204
+ 'pick_object' => 'post-status',
1205
+ 'default' => apply_filters( 'pods_api_default_status_' . pods_var_raw( 'name', $pod, 'post_type', null, true ), 'draft', $pod )
1206
+ )
1207
+ );
1208
+ }
1209
+ elseif ( 'taxonomy' == $pod[ 'type' ] ) {
1210
+ $options[ 'admin-ui' ] = array(
1211
+ 'show_ui' => array(
1212
+ 'label' => __( 'Show Admin UI', 'pods' ),
1213
+ 'help' => __( 'Whether to generate a default UI for managing this taxonomy.', 'pods' ),
1214
+ 'type' => 'boolean',
1215
+ 'default' => pods_var_raw( 'public', $pod, true ),
1216
+ 'dependency' => true,
1217
+ 'boolean_yes_label' => ''
1218
+ ),
1219
+ 'show_in_menu' => array(
1220
+ 'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
1221
+ 'help' => __( 'Whether to show the taxonomy in the admin menu.', 'pods' ),
1222
+ 'type' => 'boolean',
1223
+ 'default' => pods_var_raw( 'public', $pod, true ),
1224
+ 'dependency' => true,
1225
+ 'depends-on' => array( 'show_ui' => true ),
1226
+ 'boolean_yes_label' => ''
1227
+ ),
1228
+ 'menu_name' => array(
1229
+ 'label' => __( 'Menu Name', 'pods' ),
1230
+ 'help' => __( 'help', 'pods' ),
1231
+ 'type' => 'text',
1232
+ 'default' => '',
1233
+ 'depends-on' => array( 'show_ui' => true )
1234
+ ),
1235
+ 'menu_location' => array(
1236
+ 'label' => __( 'Menu Location', 'pods' ),
1237
+ 'help' => __( 'help', 'pods' ),
1238
+ 'type' => 'pick',
1239
+ 'default' => 'default',
1240
+ 'depends-on' => array( 'show_ui' => true ),
1241
+ 'data' => array(
1242
+ 'default' => __( 'Default - Add to associated Post Type(s) menus', 'pods' ),
1243
+ 'settings' => __( 'Add to Settings menu', 'pods' ),
1244
+ 'appearances' => __( 'Add to Appearances menu', 'pods' ),
1245
+ 'objects' => __( 'Make a top-level menu item', 'pods' ),
1246
+ 'top' => __( 'Make a new top-level menu item below Settings', 'pods' ),
1247
+ 'submenu' => __( 'Add a submenu item to another menu', 'pods' )
1248
+ ),
1249
+ 'dependency' => true
1250
+ ),
1251
+ 'menu_location_custom' => array(
1252
+ 'label' => __( 'Custom Menu Location', 'pods' ),
1253
+ 'help' => __( 'help', 'pods' ),
1254
+ 'type' => 'text',
1255
+ 'depends-on' => array( 'menu_location' => 'submenu' )
1256
+ ),
1257
+ 'menu_position' => array(
1258
+ 'label' => __( 'Menu Position', 'pods' ),
1259
+ 'help' => __( 'help', 'pods' ),
1260
+ 'type' => 'number',
1261
+ 'number_decimals' => 2,
1262
+ 'number_format' => '9999.99',
1263
+ 'number_format_soft' => 1,
1264
+ 'default' => 0,
1265
+ 'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) )
1266
+ ),
1267
+ 'menu_icon' => array(
1268
+ 'label' => __( 'Menu Icon URL', 'pods' ),
1269
+ 'help' => __( 'help', 'pods' ),
1270
+ 'type' => 'text',
1271
+ 'default' => '',
1272
+ 'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) )
1273
+ ),
1274
+ 'show_in_nav_menus' => array(
1275
+ 'label' => __( 'Show in Navigation Menus', 'pods' ),
1276
+ 'help' => __( 'help', 'pods' ),
1277
+ 'type' => 'boolean',
1278
+ 'default' => pods_var_raw( 'public', $pod, true ),
1279
+ 'boolean_yes_label' => ''
1280
+ ),
1281
+ 'show_tagcloud' => array(
1282
+ 'label' => __( 'Allow in Tagcloud Widget', 'pods' ),
1283
+ 'help' => __( 'help', 'pods' ),
1284
+ 'type' => 'boolean',
1285
+ 'default' => pods_var_raw( 'show_ui', $pod, pods_var_raw( 'public', $pod, true ) ),
1286
+ 'boolean_yes_label' => ''
1287
+ )
1288
+ );
1289
+
1290
+ if ( pods_version_check( 'wp', '3.5' ) ) {
1291
+ $options[ 'admin-ui' ][ 'show_admin_column' ] = array(
1292
+ 'label' => __( 'Show Taxonomy column on Post Types', 'pods' ),
1293
+ 'help' => __( 'Whether to add a column for this taxonomy on the associated post types manage screens', 'pods' ),
1294
+ 'type' => 'boolean',
1295
+ 'default' => false,
1296
+ 'boolean_yes_label' => ''
1297
+ );
1298
+ }
1299
 
1300
+ // Integration for Single Value Taxonomy UI
1301
+ if ( function_exists( 'tax_single_value_meta_box' ) ) {
1302
+ $options[ 'admin-ui' ][ 'single_value' ] = array(
1303
+ 'label' => __( 'Single Value Taxonomy', 'pods' ),
1304
+ 'help' => __( 'Use a drop-down for the input instead of the WordPress default', 'pods' ),
1305
+ 'type' => 'boolean',
1306
+ 'default' => false,
1307
+ 'boolean_yes_label' => ''
1308
+ );
1309
+
1310
+ $options[ 'admin-ui' ][ 'single_value_required' ] = array(
1311
+ 'label' => __( 'Single Value Taxonomy - Required', 'pods' ),
1312
+ 'help' => __( 'A term will be selected by default in the Post Editor, not optional', 'pods' ),
1313
+ 'type' => 'boolean',
1314
+ 'default' => false,
1315
+ 'boolean_yes_label' => ''
1316
+ );
1317
  }
1318
 
1319
+ $options[ 'advanced' ] = array(
1320
+ 'public' => array(
1321
+ 'label' => __( 'Public', 'pods' ),
1322
+ 'help' => __( 'help', 'pods' ),
1323
+ 'type' => 'boolean',
1324
+ 'default' => true,
1325
+ 'boolean_yes_label' => ''
1326
+ ),
1327
+ 'hierarchical' => array(
1328
+ 'label' => __( 'Hierarchical', 'pods' ),
1329
+ 'help' => __( 'help', 'pods' ),
1330
+ 'type' => 'boolean',
1331
+ 'default' => true,
1332
+ 'dependency' => true,
1333
+ 'boolean_yes_label' => ''
1334
+ ),
1335
+ 'label_parent_item_colon' => array(
1336
+ 'label' => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1337
+ 'help' => __( 'help', 'pods' ),
1338
+ 'type' => 'text',
1339
+ 'default' => '',
1340
+ 'depends-on' => array( 'hierarchical' => true )
1341
+ ),
1342
+ 'label_parent' => array(
1343
+ 'label' => __( '<strong>Label: </strong> Parent', 'pods' ),
1344
+ 'help' => __( 'help', 'pods' ),
1345
+ 'type' => 'text',
1346
+ 'default' => '',
1347
+ 'depends-on' => array( 'hierarchical' => true )
1348
+ ),
1349
+ 'label_no_terms' => array(
1350
+ 'label' => __( '<strong>Label: </strong> No <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1351
+ 'help' => __( 'help', 'pods' ),
1352
+ 'type' => 'text',
1353
+ 'default' => '',
1354
+ 'depends-on' => array( 'hierarchical' => true )
1355
+ ),
1356
+ 'rewrite' => array(
1357
+ 'label' => __( 'Rewrite', 'pods' ),
1358
+ 'help' => __( 'help', 'pods' ),
1359
+ 'type' => 'boolean',
1360
+ 'default' => true,
1361
+ 'dependency' => true,
1362
+ 'boolean_yes_label' => ''
1363
+ ),
1364
+ 'rewrite_custom_slug' => array(
1365
+ 'label' => __( 'Custom Rewrite Slug', 'pods' ),
1366
+ 'help' => __( 'help', 'pods' ),
1367
+ 'type' => 'text',
1368
+ 'default' => '',
1369
+ 'depends-on' => array( 'rewrite' => true )
1370
+ ),
1371
+ 'rewrite_with_front' => array(
1372
+ 'label' => __( 'Allow Front Prepend', 'pods' ),
1373
+ 'help' => __( 'Allows permalinks to be prepended with front base (example: if your permalink structure is /blog/, then your links will be: Checked->/news/, Unchecked->/blog/news/)', 'pods' ),
1374
+ 'type' => 'boolean',
1375
+ 'default' => true,
1376
+ 'boolean_yes_label' => '',
1377
+ 'depends-on' => array( 'rewrite' => true )
1378
+ ),
1379
+ 'rewrite_hierarchical' => array(
1380
+ 'label' => __( 'Hierarchical Permalinks', 'pods' ),
1381
+ 'help' => __( 'help', 'pods' ),
1382
+ 'type' => 'boolean',
1383
+ 'default' => true,
1384
+ 'boolean_yes_label' => '',
1385
+ 'depends-on' => array( 'rewrite' => true )
1386
+ ),
1387
+ 'capability_type' => array(
1388
+ 'label' => __( 'User Capability', 'pods' ),
1389
+ 'help' => __( 'Uses WordPress term capabilities by default', 'pods' ),
1390
+ 'type' => 'pick',
1391
+ 'default' => 'default',
1392
+ 'data' => array(
1393
+ 'default' => 'Default',
1394
+ 'custom' => __( 'Custom Capability', 'pods' )
1395
+ ),
1396
+ 'dependency' => true
1397
+ ),
1398
+ 'capability_type_custom' => array(
1399
+ 'label' => __( 'Custom User Capability', 'pods' ),
1400
+ 'help' => __( 'Enables additional capabilities for this Taxonomy including: manage_{capability}_terms, edit_{capability}_terms, assign_{capability}_terms, and delete_{capability}_terms', 'pods' ),
1401
+ 'type' => 'text',
1402
+ 'default' => pods_v( 'name', $pod ),
1403
+ 'depends-on' => array( 'capability_type' => 'custom' )
1404
+ ),
1405
+ 'query_var' => array(
1406
+ 'label' => __( 'Query Var', 'pods' ),
1407
+ 'help' => __( 'help', 'pods' ),
1408
+ 'type' => 'boolean',
1409
+ 'default' => false,
1410
+ 'boolean_yes_label' => ''
1411
+ ),
1412
+ 'query_var' => array(
1413
+ 'label' => __( 'Query Var', 'pods' ),
1414
+ 'help' => __( 'help', 'pods' ),
1415
+ 'type' => 'boolean',
1416
+ 'default' => false,
1417
+ 'dependency' => true,
1418
+ 'boolean_yes_label' => ''
1419
+ ),
1420
+ 'query_var_string' => array(
1421
+ 'label' => __( 'Custom Query Var Name', 'pods' ),
1422
+ 'help' => __( 'help', 'pods' ),
1423
+ 'type' => 'text',
1424
+ 'default' => '',
1425
+ 'depends-on' => array( 'query_var' => true )
1426
+ ),
1427
+ 'sort' => array(
1428
+ 'label' => __( 'Remember order saved on Post Types', 'pods' ),
1429
+ 'help' => __( 'help', 'pods' ),
1430
+ 'type' => 'boolean',
1431
+ 'default' => false,
1432
+ 'boolean_yes_label' => ''
1433
+ ),
1434
+ 'update_count_callback' => array(
1435
+ 'label' => __( 'Function to call when updating counts', 'pods' ),
1436
+ 'help' => __( 'help', 'pods' ),
1437
+ 'type' => 'text',
1438
+ 'default' => ''
1439
+ ),
1440
+ );
1441
+ }
1442
+ elseif ( 'settings' == $pod[ 'type' ] ) {
1443
+ $options[ 'admin-ui' ] = array(
1444
+ 'ui_style' => array(
1445
+ 'label' => __( 'Admin UI Style', 'pods' ),
1446
+ 'help' => __( 'help', 'pods' ),
1447
+ 'type' => 'pick',
1448
+ 'default' => 'settings',
1449
+ 'data' => array(
1450
+ 'settings' => __( 'Normal Settings Form', 'pods' ),
1451
+ 'post_type' => __( 'Post Type UI', 'pods' ),
1452
+ 'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' )
1453
+ ),
1454
+ 'dependency' => true
1455
+ ),
1456
+ 'menu_location' => array(
1457
+ 'label' => __( 'Menu Location', 'pods' ),
1458
+ 'help' => __( 'help', 'pods' ),
1459
+ 'type' => 'pick',
1460
+ 'default' => 'settings',
1461
+ 'data' => array(
1462
+ 'settings' => __( 'Add to Settings menu', 'pods' ),
1463
+ 'appearances' => __( 'Add to Appearances menu', 'pods' ),
1464
+ 'top' => __( 'Make a new top-level menu item below Settings', 'pods' ),
1465
+ 'submenu' => __( 'Add a submenu item to another menu', 'pods' )
1466
+ ),
1467
+ 'dependency' => true
1468
+ ),
1469
+ 'menu_location_custom' => array(
1470
+ 'label' => __( 'Custom Menu Location', 'pods' ),
1471
+ 'help' => __( 'help', 'pods' ),
1472
+ 'type' => 'text',
1473
+ 'depends-on' => array( 'menu_location' => 'submenu' )
1474
+ ),
1475
+ 'menu_position' => array(
1476
+ 'label' => __( 'Menu Position', 'pods' ),
1477
+ 'help' => __( 'help', 'pods' ),
1478
+ 'type' => 'number',
1479
+ 'number_decimals' => 2,
1480
+ 'number_format' => '9999.99',
1481
+ 'number_format_soft' => 1,
1482
+ 'default' => 0,
1483
+ 'depends-on' => array( 'menu_location' => 'top' )
1484
+ ),
1485
+ 'menu_icon' => array(
1486
+ 'label' => __( 'Menu Icon URL', 'pods' ),
1487
+ 'help' => __( 'help', 'pods' ),
1488
+ 'type' => 'text',
1489
+ 'default' => '',
1490
+ 'depends-on' => array( 'menu_location' => 'top' )
1491
+ )
1492
+ );
1493
+
1494
+ // @todo fill this in
1495
+ $options[ 'advanced' ] = array(
1496
+ 'temporary' => 'This type has the fields hardcoded' // :(
1497
+ );
1498
+ }
1499
+ elseif ( 'pod' == $pod[ 'type' ] ) {
1500
+ $options[ 'admin-ui' ] = array(
1501
+ 'ui_style' => array(
1502
+ 'label' => __( 'Admin UI Style', 'pods' ),
1503
+ 'help' => __( 'help', 'pods' ),
1504
+ 'type' => 'pick',
1505
+ 'default' => 'settings',
1506
+ 'data' => array(
1507
+ 'post_type' => __( 'Normal (Looks like the Post Type UI)', 'pods' ),
1508
+ 'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' )
1509
+ ),
1510
+ 'dependency' => true
1511
+ ),
1512
+ 'show_in_menu' => array(
1513
+ 'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
1514
+ 'help' => __( 'help', 'pods' ),
1515
+ 'type' => 'boolean',
1516
+ 'default' => false,
1517
+ 'boolean_yes_label' => '',
1518
+ 'dependency' => true
1519
+ ),
1520
+ 'menu_location_custom' => array(
1521
+ 'label' => __( 'Parent Menu ID (optional)', 'pods' ),
1522
+ 'help' => __( 'help', 'pods' ),
1523
+ 'type' => 'text',
1524
+ 'depends-on' => array( 'show_in_menu' => true )
1525
+ ),
1526
+ 'menu_position' => array(
1527
+ 'label' => __( 'Menu Position', 'pods' ),
1528
+ 'help' => __( 'help', 'pods' ),
1529
+ 'type' => 'number',
1530
+ 'number_decimals' => 2,
1531
+ 'number_format' => '9999.99',
1532
+ 'number_format_soft' => 1,
1533
+ 'default' => 0,
1534
+ 'depends-on' => array( 'show_in_menu' => true )
1535
+ ),
1536
+ 'menu_icon' => array(
1537
+ 'label' => __( 'Menu Icon URL', 'pods' ),
1538
+ 'help' => __( 'This is the icon shown to the left of the menu text for this content type.', 'pods' ),
1539
+ 'type' => 'text',
1540
+ 'default' => '',
1541
+ 'depends-on' => array( 'show_in_menu' => true )
1542
+ ),
1543
+ 'ui_icon' => array(
1544
+ 'label' => __( 'Header Icon', 'pods' ),
1545
+ 'help' => __( 'This is the icon shown to the left of the heading text at the top of the manage pages for this content type.', 'pods' ),
1546
+ 'type' => 'file',
1547
+ 'default' => '',
1548
+ 'file_edit_title' => 0,
1549
+ 'depends-on' => array( 'show_in_menu' => true )
1550
+ ),
1551
+ 'ui_actions_enabled' => array(
1552
+ 'label' => __( 'Actions Available', 'pods' ),
1553
+ 'help' => __( 'help', 'pods' ),
1554
+ 'type' => 'pick',
1555
+ 'default' => ( 1 == pods_var( 'ui_export', $pod ) ? array( 'add', 'edit', 'duplicate', 'delete', 'export' ) : array( 'add', 'edit', 'duplicate', 'delete' ) ),
1556
+ 'data' => array(
1557
+ 'add' => __( 'Add New', 'pods' ),
1558
+ 'edit' => __( 'Edit', 'pods' ),
1559
+ 'duplicate' => __( 'Duplicate', 'pods' ),
1560
+ 'delete' => __( 'Delete', 'pods' ),
1561
+ 'reorder' => __( 'Reorder', 'pods' ),
1562
+ 'export' => __( 'Export', 'pods' )
1563
+ ),
1564
+ 'pick_format_type' => 'multi',
1565
+ 'dependency' => true
1566
+ ),
1567
+ 'ui_reorder_field' => array(
1568
+ 'label' => __( 'Reorder Field', 'pods' ),
1569
+ 'help' => __( 'This is the field that will be reordered on, it should be numeric.', 'pods' ),
1570
+ 'type' => 'text',
1571
+ 'default' => 'menu_order',
1572
+ 'depends-on' => array( 'ui_actions_enabled' => 'reorder' )
1573
+ ),
1574
+ 'ui_fields_manage' => array(
1575
+ 'label' => __( 'Admin Table Columns', 'pods' ),
1576
+ 'help' => __( 'help', 'pods' ),
1577
+ 'type' => 'pick',
1578
+ 'default' => array(),
1579
+ 'data' => array(),
1580
+ 'pick_format_type' => 'multi'
1581
+ ),
1582
+ 'ui_filters' => array(
1583
+ 'label' => __( 'Search Filters', 'pods' ),
1584
+ 'help' => __( 'help', 'pods' ),
1585
+ 'type' => 'pick',
1586
+ 'default' => array(),
1587
+ 'data' => array(),
1588
+ 'pick_format_type' => 'multi'
1589
+ )
1590
+ );
1591
+
1592
+ if ( !empty( $pod[ 'fields' ] ) ) {
1593
+ if ( isset( $pod[ 'fields' ][ pods_var_raw( 'pod_index', $pod, 'name' ) ] ) )
1594
+ $options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'default' ][] = pods_var_raw( 'pod_index', $pod, 'name' );
1595
+
1596
+ if ( isset( $pod[ 'fields' ][ 'modified' ] ) )
1597
+ $options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'default' ][] = 'modified';
1598
+
1599
+ foreach ( $pod[ 'fields' ] as $field ) {
1600
+ $type = '';
1601
+
1602
+ if ( isset( $field_types[ $field[ 'type' ] ] ) )
1603
+ $type = ' <small>(' . $field_types[ $field[ 'type' ] ][ 'label' ] . ')</small>';
1604
+
1605
+ $options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'data' ][ $field[ 'name' ] ] = $field[ 'label' ] . $type;
1606
+ $options[ 'admin-ui' ][ 'ui_filters' ][ 'data' ][ $field[ 'name' ] ] = $field[ 'label' ] . $type;
1607
+ }
1608
+
1609
+ $options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'data' ][ 'id' ] = 'ID';
1610
+ }
1611
+ else {
1612
+ unset( $options[ 'admin-ui' ][ 'ui_fields_manage' ] );
1613
+ unset( $options[ 'admin-ui' ][ 'ui_filters' ] );
1614
+ }
1615
+
1616
+ // @todo fill this in
1617
+ $options[ 'advanced' ] = array(
1618
+ 'temporary' => 'This type has the fields hardcoded' // :(
1619
+ );
1620
+ }
1621
 
1622
  /**
1623
+ * Add admin fields to the Pods editor for a specific Pod
1624
  *
1625
+ * @params array $options The Options fields
1626
+ * @params object $pod Current Pods object
1627
  *
1628
+ * @since unkown
1629
  */
1630
+ $options = apply_filters( 'pods_admin_setup_edit_options_' . $pod[ 'type' ] . '_' . $pod[ 'name' ], $options, $pod );
1631
 
1632
+ /**
1633
+ * Add admin fields to the Pods editor for any Pod of a specific content type.
1634
+ */
1635
+ $options = apply_filters( 'pods_admin_setup_edit_options_' . $pod[ 'type' ], $options, $pod );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1636
 
1637
+ /**
1638
+ * Add admin fields to the Pods editor for all Pods
1639
+ */
1640
+ $options = apply_filters( 'pods_admin_setup_edit_options', $options, $pod );
1641
 
1642
+ return $options;
1643
+ }
1644
+
1645
+ /**
1646
+ * Get list of Pod field option tabs
1647
+ *
1648
+ * @return array
1649
+ */
1650
+ public function admin_setup_edit_field_tabs ( $pod ) {
1651
+ $core_tabs = array(
1652
+ 'basic' => __( 'Basic', 'pods' ),
1653
+ 'additional-field' => __( 'Additional Field Options', 'pods' ),
1654
+ 'advanced' => __( 'Advanced', 'pods' )
1655
+ );
1656
+
1657
+ /**
1658
+ * Field option tabs
1659
+ *
1660
+ * Use to add new tabs, default tabs are added after this filter (IE you can't remove/modify them with this, kthanksbye).
1661
+ *
1662
+ * @since unknown
1663
+ *
1664
+ * @param array $tabs Tabs to add, starts empty
1665
+ * @param object|Pod Current Pods object
1666
+ */
1667
+ $tabs = apply_filters( 'pods_admin_setup_edit_field_tabs', array(), $pod );
1668
+
1669
+ $tabs = array_merge( $core_tabs, $tabs );
1670
+
1671
+ return $tabs;
1672
+ }
1673
+
1674
+ /**
1675
+ * Get list of Pod field options
1676
+ *
1677
+ * @return array
1678
+ */
1679
+ public function admin_setup_edit_field_options ( $pod ) {
1680
+ $options = array();
1681
+
1682
+ $options[ 'additional-field' ] = array();
1683
+
1684
+ $field_types = PodsForm::field_types();
1685
+
1686
+ foreach ( $field_types as $type => $field_type_data ) {
1687
+ /**
1688
+ * @var $field_type PodsField
1689
+ */
1690
+ $field_type = PodsForm::field_loader( $type, $field_type_data[ 'file' ] );
1691
+
1692
+ $field_type_vars = get_class_vars( get_class( $field_type ) );
1693
+
1694
+ if ( !isset( $field_type_vars[ 'pod_types' ] ) )
1695
+ $field_type_vars[ 'pod_types' ] = true;
1696
+
1697
+ $options[ 'additional-field' ][ $type ] = array();
1698
+
1699
+ // Only show supported field types
1700
+ if ( true !== $field_type_vars[ 'pod_types' ] ) {
1701
+ if ( empty( $field_type_vars[ 'pod_types' ] ) )
1702
+ continue;
1703
+ elseif ( is_array( $field_type_vars[ 'pod_types' ] ) && !in_array( pods_var( 'type', $pod ), $field_type_vars[ 'pod_types' ] ) )
1704
+ continue;
1705
+ elseif ( !is_array( $field_type_vars[ 'pod_types' ] ) && pods_var( 'type', $pod ) != $field_type_vars[ 'pod_types' ] )
1706
+ continue;
1707
+ }
1708
+
1709
+ $options[ 'additional-field' ][ $type ] = PodsForm::ui_options( $type );
1710
+ }
1711
+
1712
+ $input_helpers = array(
1713
+ '' => '-- Select --'
1714
+ );
1715
+
1716
+ if ( class_exists( 'Pods_Helpers' ) ) {
1717
+ $helpers = pods_api()->load_helpers( array( 'options' => array( 'helper_type' => 'input' ) ) );
1718
+
1719
+ foreach ( $helpers as $helper ) {
1720
+ $input_helpers[ $helper[ 'name' ] ] = $helper[ 'name' ];
1721
+ }
1722
+ }
1723
+
1724
+ $options[ 'advanced' ] = array(
1725
+ __( 'Visual', 'pods' ) => array(
1726
+ 'class' => array(
1727
+ 'name' => 'class',
1728
+ 'label' => __( 'Additional CSS Classes', 'pods' ),
1729
+ 'help' => __( 'help', 'pods' ),
1730
+ 'type' => 'text',
1731
+ 'default' => ''
1732
+ ),
1733
+ 'input_helper' => array(
1734
+ 'name' => 'input_helper',
1735
+ 'label' => __( 'Input Helper', 'pods' ),
1736
+ 'help' => __( 'help', 'pods' ),
1737
+ 'type' => 'pick',
1738
+ 'default' => '',
1739
+ 'data' => $input_helpers
1740
+ )
1741
+ ),
1742
+ __( 'Values', 'pods' ) => array(
1743
+ 'default_value' => array(
1744
+ 'name' => 'default_value',
1745
+ 'label' => __( 'Default Value', 'pods' ),
1746
+ 'help' => __( 'help', 'pods' ),
1747
+ 'type' => 'text',
1748
+ 'default' => '',
1749
+ 'options' => array(
1750
+ 'text_max_length' => -1
1751
+ )
1752
+ ),
1753
+ 'default_value_parameter' => array(
1754
+ 'name' => 'default_value_parameter',
1755
+ 'label' => __( 'Set Default Value via Parameter', 'pods' ),
1756
+ 'help' => __( 'help', 'pods' ),
1757
+ 'type' => 'text',
1758
+ 'default' => ''
1759
+ )
1760
+ ),
1761
+ __( 'Visibility', 'pods' ) => array(
1762
+ 'restrict_access' => array(
1763
+ 'name' => 'restrict_access',
1764
+ 'label' => __( 'Restrict Access', 'pods' ),
1765
+ 'group' => array(
1766
+ 'admin_only' => array(
1767
+ 'name' => 'admin_only',
1768
+ 'label' => __( 'Restrict access to Admins?', 'pods' ),
1769
+ 'default' => 0,
1770
+ 'type' => 'boolean',
1771
+ 'dependency' => true,
1772
+ 'help' => __( 'This field will only be able to be edited by users with the ability to manage_options or delete_users, or super admins of a WordPress Multisite network', 'pods' )
1773
+ ),
1774
+ 'restrict_role' => array(
1775
+ 'name' => 'restrict_role',
1776
+ 'label' => __( 'Restrict access by Role?', 'pods' ),
1777
+ 'default' => 0,
1778
+ 'type' => 'boolean',
1779
+ 'dependency' => true
1780
+ ),
1781
+ 'restrict_capability' => array(
1782
+ 'name' => 'restrict_capability',
1783
+ 'label' => __( 'Restrict access by Capability?', 'pods' ),
1784
+ 'default' => 0,
1785
+ 'type' => 'boolean',
1786
+ 'dependency' => true
1787
+ ),
1788
+ 'hidden' => array(
1789
+ 'name' => 'hidden',
1790
+ 'label' => __( 'Hide field from UI', 'pods' ),
1791
+ 'default' => 0,
1792
+ 'type' => 'boolean',
1793
+ 'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be hidden. If no access restrictions are set, this field will always be hidden.', 'pods' )
1794
+ ),
1795
+ 'read_only' => array(
1796
+ 'name' => 'read_only',
1797
+ 'label' => __( 'Make field "Read Only" in UI', 'pods' ),
1798
+ 'default' => 0,
1799
+ 'type' => 'boolean',
1800
+ 'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be read only. If no access restrictions are set, this field will always be read only.', 'pods' ),
1801
+ 'depends-on' => array(
1802
+ 'type' => array(
1803
+ 'boolean',
1804
+ 'color',
1805
+ 'currency',
1806
+ 'date',
1807
+ 'datetime',
1808
+ 'email',
1809
+ 'number',
1810
+ 'paragraph',
1811
+ 'password',
1812
+ 'phone',
1813
+ 'slug',
1814
+ 'text',
1815
+ 'time',
1816
+ 'website'
1817
+ )
1818
+ )
1819
+ )
1820
+ )
1821
+ ),
1822
+ 'roles_allowed' => array(
1823
+ 'name' => 'roles_allowed',
1824
+ 'label' => __( 'Role(s) Allowed', 'pods' ),
1825
+ 'help' => __( 'help', 'pods' ),
1826
+ 'type' => 'pick',
1827
+ 'pick_object' => 'role',
1828
+ 'pick_format_type' => 'multi',
1829
+ 'default' => 'administrator',
1830
+ 'depends-on' => array(
1831
+ 'restrict_role' => true
1832
+ )
1833
+ ),
1834
+ 'capability_allowed' => array(
1835
+ 'name' => 'capability_allowed',
1836
+ 'label' => __( 'Capability Allowed', 'pods' ),
1837
+ 'help' => __( 'Comma-separated list of cababilities, for example add_podname_item, please see the Roles and Capabilities component for the complete list and a way to add your own.', 'pods' ),
1838
+ 'type' => 'text',
1839
+ 'default' => '',
1840
+ 'depends-on' => array(
1841
+ 'restrict_capability' => true
1842
+ )
1843
+ )
1844
+ /*,
1845
+ 'search' => array(
1846
+ 'label' => __( 'Include in searches', 'pods' ),
1847
+ 'help' => __( 'help', 'pods' ),
1848
+ 'default' => 1,
1849
+ 'type' => 'boolean',
1850
+ )*/
1851
+ )
1852
+ /*,
1853
+ __( 'Validation', 'pods' ) => array(
1854
+ 'regex_validation' => array(
1855
+ 'label' => __( 'RegEx Validation', 'pods' ),
1856
+ 'help' => __( 'help', 'pods' ),
1857
+ 'type' => 'text',
1858
+ 'default' => ''
1859
+ ),
1860
+ 'message_regex' => array(
1861
+ 'label' => __( 'Message if field does not pass RegEx', 'pods' ),
1862
+ 'help' => __( 'help', 'pods' ),
1863
+ 'type' => 'text',
1864
+ 'default' => ''
1865
+ ),
1866
+ 'message_required' => array(
1867
+ 'label' => __( 'Message if field is blank', 'pods' ),
1868
+ 'help' => __( 'help', 'pods' ),
1869
+ 'type' => 'text',
1870
+ 'default' => '',
1871
+ 'depends-on' => array( 'required' => true )
1872
+ ),
1873
+ 'message_unique' => array(
1874
+ 'label' => __( 'Message if field is not unique', 'pods' ),
1875
+ 'help' => __( 'help', 'pods' ),
1876
+ 'type' => 'text',
1877
+ 'default' => '',
1878
+ 'depends-on' => array( 'unique' => true )
1879
+ )
1880
+ )*/
1881
+ );
1882
+
1883
+ if ( !class_exists( 'Pods_Helpers' ) )
1884
+ unset( $options[ 'advanced' ][ 'input_helper' ] );
1885
+
1886
+ /**
1887
+ * Modify tabs and their contents for field options
1888
+ *
1889
+ * @since unknown
1890
+ *
1891
+ * @param array $options Tabs, indexed by label
1892
+ * @param object|Pods Pods object for the Pod this UI is for.
1893
+ */
1894
+ $options = apply_filters( 'pods_admin_setup_edit_field_options', $options, $pod );
1895
+
1896
+ return $options;
1897
+ }
1898
+
1899
+ /**
1900
+ * Duplicate a pod
1901
+ *
1902
+ * @param $id
1903
+ * @param $obj
1904
+ *
1905
+ * @return mixed
1906
+ */
1907
+ public function admin_setup_duplicate ( $obj ) {
1908
+ $new_id = pods_api()->duplicate_pod( array( 'id' => $obj->id ) );
1909
+
1910
+ if ( 0 < $new_id )
1911
+ pods_redirect( pods_query_arg( array( 'action' => 'edit', 'id' => $new_id, 'do' => 'duplicate' ) ) );
1912
+ }
1913
 
1914
  /**
1915
+ * Restrict Duplicate action to custom types, not extended
 
 
1916
  *
1917
+ * @param bool $restricted
1918
+ * @param array $restrict
1919
+ * @param string $action
1920
+ * @param array $row
1921
+ * @param PodsUI $obj
1922
  *
1923
+ * @since 2.3.10
1924
+ *
1925
+ * @return bool
1926
  */
1927
+ public function admin_setup_duplicate_restrict( $restricted, $restrict, $action, $row, $obj ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1928
 
1929
+ if ( in_array( $row[ 'real_type' ], array( 'user', 'media', 'comment' ) ) ) {
1930
+ $restricted = true;
1931
+ }
 
1932
 
1933
+ return $restricted;
 
1934
 
1935
+ }
1936
 
1937
+ /**
1938
+ * Reset a pod
1939
+ *
1940
+ * @param $obj
1941
+ *
1942
+ * @return mixed
1943
+ */
1944
+ public function admin_setup_reset ( $obj, $id ) {
1945
+ $pod = pods_api()->load_pod( array( 'id' => $id ), false );
1946
 
1947
+ if ( empty( $pod ) )
1948
+ return $obj->error( __( 'Pod not found.', 'pods' ) );
 
 
 
1949
 
1950
+ pods_api()->reset_pod( array( 'id' => $id ) );
 
1951
 
1952
+ $obj->message( __( 'Pod reset successfully.', 'pods' ) );
 
 
 
1953
 
1954
+ $obj->manage();
1955
+ }
 
 
 
1956
 
1957
  /**
1958
+ * Restrict Reset action from users and media
1959
+ *
1960
+ * @param bool $restricted
1961
+ * @param array $restrict
1962
+ * @param string $action
1963
+ * @param array $row
1964
+ * @param PodsUI $obj
1965
+ *
1966
+ * @since 2.3.10
1967
  */
1968
+ public function admin_setup_reset_restrict( $restricted, $restrict, $action, $row, $obj ) {
 
 
 
 
 
1969
 
1970
+ if ( in_array( $row[ 'real_type' ], array( 'user', 'media' ) ) ) {
1971
+ $restricted = true;
 
 
1972
  }
1973
 
1974
+ return $restricted;
1975
+
1976
  }
1977
 
1978
+ /**
1979
+ * Delete a pod
1980
+ *
1981
+ * @param $id
1982
+ * @param $obj
1983
+ *
1984
+ * @return mixed
1985
+ */
1986
+ public function admin_setup_delete ( $id, $obj ) {
1987
+ $pod = pods_api()->load_pod( array( 'id' => $id ), false );
1988
 
1989
+ if ( empty( $pod ) )
1990
+ return $obj->error( __( 'Pod not found.', 'pods' ) );
1991
 
1992
+ pods_api()->delete_pod( array( 'id' => $id ) );
1993
 
1994
+ unset( $obj->data[ $pod[ 'id' ] ] );
 
 
 
 
 
 
 
 
1995
 
1996
+ $obj->total = count( $obj->data );
1997
+ $obj->total_found = count( $obj->data );
1998
+
1999
+ $obj->message( __( 'Pod deleted successfully.', 'pods' ) );
2000
+ }
2001
+
2002
+ /**
2003
+ * Get advanced administration view.
2004
+ */
2005
+ public function admin_advanced () {
2006
+ pods_view( PODS_DIR . 'ui/admin/advanced.php', compact( array_keys( get_defined_vars() ) ) );
2007
+ }
2008
+
2009
+ /**
2010
+ * Get settings administration view
2011
+ */
2012
+ public function admin_settings () {
2013
+ pods_view( PODS_DIR . 'ui/admin/settings.php', compact( array_keys( get_defined_vars() ) ) );
2014
+ }
2015
+
2016
+ /**
2017
+ * Get components administration UI
2018
+ */
2019
+ public function admin_components () {
2020
+ if ( ! is_object( PodsInit::$components ) )
2021
+ return;
2022
+
2023
+ $components = PodsInit::$components->components;
2024
+
2025
+ $view = pods_var( 'view', 'get', 'all', null, true );
2026
+
2027
+ $recommended = array(
2028
+ 'advanced-relationships',
2029
+ 'advanced-content-types',
2030
+ 'migrate-packages',
2031
+ 'roles-and-capabilities',
2032
+ 'pages',
2033
+ 'table-storage',
2034
+ 'templates'
2035
+ );
2036
+
2037
+ foreach ( $components as $component => &$component_data ) {
2038
+ if ( !in_array( $view, array( 'all', 'recommended', 'dev' ) ) && ( !isset( $component_data[ 'Category' ] ) || $view != sanitize_title( $component_data[ 'Category' ] ) ) ) {
2039
+ unset( $components[ $component ] );
2040
+
2041
+ continue;
2042
+ }
2043
+ elseif ( 'recommended' == $view && !in_array( $component_data[ 'ID' ], $recommended ) ) {
2044
+ unset( $components[ $component ] );
2045
+
2046
+ continue;
2047
+ }
2048
+ elseif ( 'dev' == $view && pods_developer() && !pods_var_raw( 'DeveloperMode', $component_data, false ) ) {
2049
+ unset( $components[ $component ] );
2050
+
2051
+ continue;
2052
+ }
2053
+ elseif ( pods_var_raw( 'DeveloperMode', $component_data, false ) && !pods_developer() ) {
2054
+ unset( $components[ $component ] );
2055
+
2056
+ continue;
2057
+ }
2058
+ elseif ( !pods_var_raw( 'TablelessMode', $component_data, false ) && pods_tableless() ) {
2059
+ unset( $components[ $component ] );
2060
+
2061
+ continue;
2062
+ }
2063
+
2064
+ $component_data[ 'Name' ] = strip_tags( $component_data[ 'Name' ] );
2065
+
2066
+ if ( pods_var_raw( 'DeveloperMode', $component_data, false ) )
2067
+ $component_data[ 'Name' ] .= ' <em style="font-weight: normal; color:#333;">(Developer Preview)</em>';
2068
+
2069
+ $meta = array();
2070
+
2071
+ if ( !empty( $component_data[ 'Version' ] ) )
2072
+ $meta[] = 'Version ' . $component_data[ 'Version' ];
2073
+
2074
+ if ( empty( $component_data[ 'Author' ] ) ) {
2075
+ $component_data[ 'Author' ] = 'Pods Framework Team';
2076
+ $component_data[ 'AuthorURI' ] = 'http://pods.io/';
2077
+ }
2078
+
2079
+ if ( !empty( $component_data[ 'AuthorURI' ] ) )
2080
+ $component_data[ 'Author' ] = '<a href="' . $component_data[ 'AuthorURI' ] . '">' . $component_data[ 'Author' ] . '</a>';
2081
+
2082
+ $meta[] = sprintf( __( 'by %s', 'pods' ), $component_data[ 'Author' ] );
2083
+
2084
+ if ( !empty( $component_data[ 'URI' ] ) )
2085
+ $meta[] = '<a href="' . $component_data[ 'URI' ] . '">' . __( 'Visit component site', 'pods' ) . '</a>';
2086
+
2087
+ $component_data[ 'Description' ] = wpautop( trim( make_clickable( strip_tags( $component_data[ 'Description' ], 'em,strong' ) ) ) );
2088
+
2089
+ if ( !empty( $meta ) )
2090
+ $component_data[ 'Description' ] .= '<div class="pods-component-meta" ' . ( !empty( $component_data[ 'Description' ] ) ? ' style="padding:8px 0 4px;"' : '' ) . '>' . implode( '&nbsp;&nbsp;|&nbsp;&nbsp;', $meta ) . '</div>';
2091
+
2092
+ $component_data = array(
2093
+ 'id' => $component_data[ 'ID' ],
2094
+ 'name' => $component_data[ 'Name' ],
2095
+ 'category' => $component_data[ 'Category' ],
2096
+ 'version' => '',
2097
+ 'description' => $component_data[ 'Description' ],
2098
+ 'mustuse' => pods_var_raw( 'MustUse', $component_data, false ),
2099
+ 'toggle' => 0
2100
+ );
2101
+
2102
+ if ( !empty( $component_data[ 'category' ] ) ) {
2103
+ $category_url = pods_query_arg( array( 'view' => sanitize_title( $component_data[ 'category' ] ), 'pg' => '', 'page' => $_GET[ 'page' ] ) );
2104
+
2105
+ $component_data[ 'category' ] = '<a href="' . esc_url( $category_url ) . '">' . $component_data[ 'category' ] . '</a>';
2106
+ }
2107
+
2108
+ if ( isset( PodsInit::$components->settings[ 'components' ][ $component_data[ 'id' ] ] ) && 0 != PodsInit::$components->settings[ 'components' ][ $component_data[ 'id' ] ] )
2109
+ $component_data[ 'toggle' ] = 1;
2110
+ elseif ( $component_data[ 'mustuse' ] )
2111
+ $component_data[ 'toggle' ] = 1;
2112
+ }
2113
+
2114
+ $ui = array(
2115
+ 'data' => $components,
2116
+ 'total' => count( $components ),
2117
+ 'total_found' => count( $components ),
2118
+ 'items' => 'Components',
2119
+ 'item' => 'Component',
2120
+ 'fields' => array(
2121
+ 'manage' => array(
2122
+ 'name' => array(
2123
+ 'label' => __( 'Name', 'pods' ),
2124
+ 'width' => '30%',
2125
+ 'type' => 'text',
2126
+ 'options' => array(
2127
+ 'text_allow_html' => true
2128
+ )
2129
+ ),
2130
+ 'category' => array(
2131
+ 'label' => __( 'Category', 'pods' ),
2132
+ 'width' => '10%',
2133
+ 'type' => 'text',
2134
+ 'options' => array(
2135
+ 'text_allow_html' => true
2136
+ )
2137
+ ),
2138
+ 'description' => array(
2139
+ 'label' => __( 'Description', 'pods' ),
2140
+ 'width' => '60%',
2141
+ 'type' => 'text',
2142
+ 'options' => array(
2143
+ 'text_allow_html' => true,
2144
+ 'text_allowed_html_tags' => 'strong em a ul ol li b i br div'
2145
+ )
2146
+ )
2147
+ )
2148
+ ),
2149
+ 'actions_disabled' => array( 'duplicate', 'view', 'export', 'add', 'edit', 'delete' ),
2150
+ 'actions_custom' => array(
2151
+ 'toggle' => array(
2152
+ 'callback' => array( $this, 'admin_components_toggle' ),
2153
+ 'nonce' => true
2154
+ )
2155
+ ),
2156
+ 'filters_enhanced' => true,
2157
+ 'views' => array(
2158
+ 'all' => __( 'All', 'pods' ),
2159
+ //'recommended' => __( 'Recommended', 'pods' ),
2160
+ 'field-types' => __( 'Field Types', 'pods' ),
2161
+ 'tools' => __( 'Tools', 'pods' ),
2162
+ 'integration' => __( 'Integration', 'pods' ),
2163
+ 'migration' => __( 'Migration', 'pods' ),
2164
+ 'advanced' => __( 'Advanced', 'pods' )
2165
+ ),
2166
+ 'view' => $view,
2167
+ 'heading' => array(
2168
+ 'views' => __( 'Category', 'pods' )
2169
+ ),
2170
+ 'search' => false,
2171
+ 'searchable' => false,
2172
+ 'sortable' => false,
2173
+ 'pagination' => false
2174
+ );
2175
+
2176
+ if ( pods_developer() )
2177
+ $ui[ 'views' ][ 'dev' ] = __( 'Developer Preview', 'pods' );
2178
+
2179
+ pods_ui( $ui );
2180
+ }
2181
+
2182
+ /**
2183
+ * Toggle a component on or off
2184
+ *
2185
+ * @param PodsUI $ui
2186
+ *
2187
+ * @return bool
2188
+ */
2189
+ public function admin_components_toggle ( PodsUI $ui ) {
2190
+ $component = $_GET[ 'id' ];
2191
+
2192
+ if ( !empty( PodsInit::$components->components[ $component ][ 'PluginDependency' ] ) ) {
2193
+ $dependency = explode( '|', PodsInit::$components->components[ $component ][ 'PluginDependency' ] );
2194
+
2195
+ if ( !pods_is_plugin_active( $dependency[ 1 ] ) ) {
2196
+ $website = 'http://wordpress.org/extend/plugins/' . dirname( $dependency[ 1 ] ) . '/';
2197
+
2198
+ if ( isset( $dependency[ 2 ] ) )
2199
+ $website = $dependency[ 2 ];
2200
+
2201
+ if ( !empty( $website ) )
2202
+ $website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $website . '" target="_blank">' . $website . '</a>' );
2203
+
2204
+ $message = sprintf( __( 'The %s component requires that you have the <strong>%s</strong> plugin installed and activated.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ], $dependency[ 0 ] ) . $website;
2205
+
2206
+ $ui->error( $message );
2207
+
2208
+ $ui->manage();
2209
+
2210
+ return;
2211
+ }
2212
+ }
2213
+
2214
+ if ( !empty( PodsInit::$components->components[ $component ][ 'ThemeDependency' ] ) ) {
2215
+ $dependency = explode( '|', PodsInit::$components->components[ $component ][ 'ThemeDependency' ] );
2216
+
2217
+ if ( strtolower( $dependency[ 1 ] ) != strtolower( get_template() ) && strtolower( $dependency[ 1 ] ) != strtolower( get_stylesheet() ) ) {
2218
+ $website = '';
2219
+
2220
+ if ( isset( $dependency[ 2 ] ) )
2221
+ $website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $dependency[ 2 ] . '" target="_blank">' . $dependency[ 2 ] . '</a>' );
2222
+
2223
+ $message = sprintf( __( 'The %s component requires that you have the <strong>%s</strong> theme installed and activated.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ], $dependency[ 0 ] ) . $website;
2224
+
2225
+ $ui->error( $message );
2226
+
2227
+ $ui->manage();
2228
+
2229
+ return;
2230
+ }
2231
+ }
2232
+
2233
+ if ( !empty( PodsInit::$components->components[ $component ][ 'MustUse' ] ) ) {
2234
+ $message = sprintf( __( 'The %s component can not be disabled from here. You must deactivate the plugin or theme that added it.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ] );
2235
+
2236
+ $ui->error( $message );
2237
+
2238
+ $ui->manage();
2239
+
2240
+ return;
2241
+ }
2242
+
2243
+ if ( '1' == pods_v( 'toggled' ) ) {
2244
+ $toggle = PodsInit::$components->toggle( $component );
2245
+
2246
+ if ( true === $toggle )
2247
+ $ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component enabled', 'pods' ) );
2248
+ elseif ( false === $toggle )
2249
+ $ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component disabled', 'pods' ) );
2250
+
2251
+ $components = PodsInit::$components->components;
2252
+
2253
+ foreach ( $components as $component => &$component_data ) {
2254
+ $toggle = 0;
2255
+
2256
+ if ( isset( PodsInit::$components->settings[ 'components' ][ $component_data[ 'ID' ] ] ) ) {
2257
+ if ( 0 != PodsInit::$components->settings[ 'components' ][ $component_data[ 'ID' ] ] )
2258
+ $toggle = 1;
2259
+ }
2260
+ if ( true === $component_data[ 'DeveloperMode' ] ) {
2261
+ if ( !pods_developer() ) {
2262
+ unset( $components[ $component ] );
2263
+ continue;
2264
+ }
2265
+ }
2266
+
2267
+ $component_data = array(
2268
+ 'id' => $component_data[ 'ID' ],
2269
+ 'name' => $component_data[ 'Name' ],
2270
+ 'description' => make_clickable( $component_data[ 'Description' ] ),
2271
+ 'version' => $component_data[ 'Version' ],
2272
+ 'author' => $component_data[ 'Author' ],
2273
+ 'toggle' => $toggle
2274
+ );
2275
+ }
2276
+
2277
+ $ui->data = $components;
2278
+
2279
+ pods_transient_clear( 'pods_components' );
2280
+
2281
+ $url = pods_query_arg( array( 'toggled' => null ) );
2282
+
2283
+ pods_redirect( $url );
2284
+ }
2285
+ elseif ( 1 == pods_var( 'toggle' ) )
2286
+ $ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component enabled', 'pods' ) );
2287
+ else
2288
+ $ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component disabled', 'pods' ) );
2289
+
2290
+ $ui->manage();
2291
+ }
2292
+
2293
+ /**
2294
+ * Get the admin upgrade page
2295
+ */
2296
+ public function admin_upgrade () {
2297
+ foreach ( PodsInit::$upgrades as $old_version => $new_version ) {
2298
+ if ( version_compare( $old_version, PodsInit::$version_last, '<=' ) && version_compare( PodsInit::$version_last, $new_version, '<' ) ) {
2299
+ $new_version = str_replace( '.', '_', $new_version );
2300
+
2301
+ pods_view( PODS_DIR . 'ui/admin/upgrade/upgrade_' . $new_version . '.php', compact( array_keys( get_defined_vars() ) ) );
2302
+
2303
+ break;
2304
+ }
2305
+ }
2306
+ }
2307
+
2308
+ /**
2309
+ * Get the admin help page
2310
+ */
2311
+ public function admin_help () {
2312
+ pods_view( PODS_DIR . 'ui/admin/help.php', compact( array_keys( get_defined_vars() ) ) );
2313
+ }
2314
+
2315
+ /**
2316
+ * Add pods specific capabilities.
2317
+ *
2318
+ * @param $capabilities List of extra capabilities to add
2319
+ *
2320
+ * @return array
2321
+ */
2322
+ public function admin_capabilities ( $capabilities ) {
2323
+ $pods = pods_api()->load_pods( array( 'type' => array( 'settings', 'post_type', 'taxonomy' ), 'fields' => false, 'table_info' => false ) );
2324
+ $other_pods = pods_api()->load_pods( array( 'type' => array( 'pod', 'table' ), 'table_info' => false ) );
2325
+
2326
+ $pods = array_merge( $pods, $other_pods );
2327
+
2328
+ $capabilities[] = 'pods';
2329
+ $capabilities[] = 'pods_content';
2330
+ $capabilities[] = 'pods_settings';
2331
+ $capabilities[] = 'pods_components';
2332
+
2333
+ foreach ( $pods as $pod ) {
2334
+ if ( 'settings' == $pod[ 'type' ] ) {
2335
+ $capabilities[] = 'pods_edit_' . $pod[ 'name' ];
2336
+ }
2337
+ elseif ( 'post_type' == $pod[ 'type' ] ) {
2338
+ $capability_type = pods_var( 'capability_type_custom', $pod[ 'options' ], pods_var_raw( 'name', $pod ) );
2339
+
2340
+ if ( 'custom' == pods_var( 'capability_type', $pod[ 'options' ] ) && 0 < strlen( $capability_type ) ) {
2341
+ $capabilities[] = 'read_' . $capability_type;
2342
+ $capabilities[] = 'edit_' . $capability_type;
2343
+ $capabilities[] = 'delete_' . $capability_type;
2344
+
2345
+ if ( 1 == pods_var( 'capability_type_extra', $pod[ 'options' ], 1 ) ) {
2346
+ $capability_type_plural = $capability_type . 's';
2347
+
2348
+ $capabilities[] = 'read_private_' . $capability_type_plural;
2349
+ $capabilities[] = 'edit_' . $capability_type_plural;
2350
+ $capabilities[] = 'edit_others_' . $capability_type_plural;
2351
+ $capabilities[] = 'edit_private_' . $capability_type_plural;
2352
+ $capabilities[] = 'edit_published_' . $capability_type_plural;
2353
+ $capabilities[] = 'publish_' . $capability_type_plural;
2354
+ $capabilities[] = 'delete_' . $capability_type_plural;
2355
+ $capabilities[] = 'delete_private_' . $capability_type_plural;
2356
+ $capabilities[] = 'delete_published_' . $capability_type_plural;
2357
+ $capabilities[] = 'delete_others_' . $capability_type_plural;
2358
+ }
2359
+ }
2360
+ }
2361
+ elseif ( 'taxonomy' == $pod[ 'type' ] ) {
2362
+ if ( 'custom' == pods_var( 'capability_type', $pod[ 'options' ], 'terms' ) ) {
2363
+ $capability_type = pods_var( 'capability_type_custom', $pod[ 'options' ], pods_var_raw( 'name', $pod ) . 's' );
2364
+
2365
+ $capability_type .= '_term';
2366
+ $capability_type_plural = $capability_type . 's';
2367
+
2368
+ // Singular
2369
+ $capabilities[] = 'edit_' . $capability_type;
2370
+ $capabilities[] = 'delete_' . $capability_type;
2371
+ $capabilities[] = 'assign_' . $capability_type;
2372
+ // Plural
2373
+ $capabilities[] = 'manage_' . $capability_type_plural;
2374
+ $capabilities[] = 'edit_' . $capability_type_plural;
2375
+ $capabilities[] = 'delete_' . $capability_type_plural;
2376
+ $capabilities[] = 'assign_' . $capability_type_plural;
2377
+ }
2378
+ }
2379
+ else {
2380
+ $capabilities[] = 'pods_add_' . $pod[ 'name' ];
2381
+ $capabilities[] = 'pods_edit_' . $pod[ 'name' ];
2382
+
2383
+ if ( isset( $pod[ 'fields' ][ 'author' ] ) && 'pick' == $pod[ 'fields' ][ 'author' ][ 'type' ] && 'user' == $pod[ 'fields' ][ 'author' ][ 'pick_object' ] )
2384
+ $capabilities[] = 'pods_edit_others_' . $pod[ 'name' ];
2385
+
2386
+ $capabilities[] = 'pods_delete_' . $pod[ 'name' ];
2387
+
2388
+ if ( isset( $pod[ 'fields' ][ 'author' ] ) && 'pick' == $pod[ 'fields' ][ 'author' ][ 'type' ] && 'user' == $pod[ 'fields' ][ 'author' ][ 'pick_object' ] )
2389
+ $capabilities[] = 'pods_delete_others_' . $pod[ 'name' ];
2390
+
2391
+ $actions_enabled = pods_var_raw( 'ui_actions_enabled', $pod[ 'options' ] );
2392
+
2393
+ if ( !empty( $actions_enabled ) )
2394
+ $actions_enabled = (array) $actions_enabled;
2395
+ else
2396
+ $actions_enabled = array();
2397
+
2398
+ $available_actions = array(
2399
+ 'add',
2400
+ 'edit',
2401
+ 'duplicate',
2402
+ 'delete',
2403
+ 'reorder',
2404
+ 'export'
2405
+ );
2406
+
2407
+ if ( !empty( $actions_enabled ) ) {
2408
+ $actions_disabled = array(
2409
+ 'view' => 'view'
2410
+ );
2411
+
2412
+ foreach ( $available_actions as $action ) {
2413
+ if ( !in_array( $action, $actions_enabled ) )
2414
+ $actions_disabled[ $action ] = $action;
2415
+ }
2416
+
2417
+ if ( !in_array( 'export', $actions_disabled ) )
2418
+ $capabilities[] = 'pods_export_' . $pod[ 'name' ];
2419
+
2420
+ if ( !in_array( 'reorder', $actions_disabled ) )
2421
+ $capabilities[] = 'pods_reorder_' . $pod[ 'name' ];
2422
+ }
2423
+ elseif ( 1 == pods_var( 'ui_export', $pod[ 'options' ], 0 ) )
2424
+ $capabilities[] = 'pods_export_' . $pod[ 'name' ];
2425
+ }
2426
+ }
2427
+
2428
+ return $capabilities;
2429
+ }
2430
+
2431
+ /**
2432
+ * Handle ajax calls for the administration
2433
+ */
2434
+ public function admin_ajax () {
2435
+ if ( false === headers_sent() ) {
2436
+ pods_session_start();
2437
 
2438
+ header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) );
2439
+ }
2440
 
2441
+ // Sanitize input
2442
+ $params = pods_unslash( (array) $_POST );
2443
+
2444
+ foreach ( $params as $key => $value ) {
2445
+ if ( 'action' == $key )
2446
+ continue;
 
 
 
 
 
 
 
 
 
2447
 
2448
+ // Fixup $_POST data
2449
+ $_POST[ str_replace( '_podsfix_', '', $key ) ] = $_POST[ $key ];
2450
 
2451
+ // Fixup $params with unslashed data
2452
+ $params[ str_replace( '_podsfix_', '', $key ) ] = $value;
2453
 
2454
+ // Unset the _podsfix_* keys
2455
+ unset( $params[ $key ] );
2456
+ }
2457
 
2458
+ $params = (object) $params;
2459
+
2460
+ $methods = array(
2461
+ 'add_pod' => array( 'priv' => true ),
2462
+ 'save_pod' => array( 'priv' => true ),
2463
+ 'load_sister_fields' => array( 'priv' => true ),
2464
+ 'process_form' => array( 'custom_nonce' => true ), // priv handled through nonce
2465
+ 'upgrade' => array( 'priv' => true ),
2466
+ 'migrate' => array( 'priv' => true )
2467
+ );
2468
+
2469
+ /**
2470
+ * AJAX Callbacks in field editor
2471
+ *
2472
+ * @since unknown
2473
+ *
2474
+ * @param array $method Callback method map
2475
+ * @param object|PodsAdmin Class object
2476
+ */
2477
+ $methods = apply_filters( 'pods_admin_ajax_methods', $methods, $this );
2478
+
2479
+ if ( !isset( $params->method ) || !isset( $methods[ $params->method ] ) )
2480
+ pods_error( 'Invalid AJAX request', $this );
2481
+
2482
+ $defaults = array(
2483
+ 'priv' => null,
2484
+ 'name' => $params->method,
2485
+ 'custom_nonce' => null
2486
+ );
2487
+
2488
+ $method = (object) array_merge( $defaults, (array) $methods[ $params->method ] );
2489
+
2490
+ if ( true !== $method->custom_nonce && ( !isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, 'pods-' . $params->method ) ) )
2491
+ pods_error( __( 'Unauthorized request', 'pods' ), $this );
2492
+
2493
+ // Cleaning up $params
2494
+ unset( $params->action );
2495
+ unset( $params->method );
2496
+
2497
+ if ( true !== $method->custom_nonce )
2498
+ unset( $params->_wpnonce );
2499
+
2500
+ // Check permissions (convert to array to support multiple)
2501
+ if ( !empty( $method->priv ) && !pods_is_admin( array( 'pods' ) ) && true !== $method->priv && !pods_is_admin( $method->priv ) )
2502
+ pods_error( __( 'Access denied', 'pods' ), $this );
2503
+
2504
+ $params->method = $method->name;
2505
+
2506
+ $params = apply_filters( 'pods_api_' . $method->name, $params, $method );
2507
+
2508
+ $api = pods_api();
2509
+
2510
+ $api->display_errors = false;
2511
+
2512
+ if ( 'upgrade' == $method->name )
2513
+ $output = (string) pods_upgrade( $params->version )->ajax( $params );
2514
+ elseif ( 'migrate' == $method->name )
2515
+ $output = (string) apply_filters( 'pods_api_migrate_run', $params );
2516
+ else {
2517
+ if ( !method_exists( $api, $method->name ) )
2518
+ pods_error( 'API method does not exist', $this );
2519
+ elseif ( 'save_pod' == $method->name ) {
2520
+ if ( isset( $params->field_data_json ) && is_array( $params->field_data_json ) ) {
2521
+ $params->fields = $params->field_data_json;
2522
+
2523
+ unset( $params->field_data_json );
2524
+
2525
+ foreach ( $params->fields as $k => $v ) {
2526
+ if ( empty( $v ) )
2527
+ unset( $params->fields[ $k ] );
2528
+ elseif ( !is_array( $v ) )
2529
+ $params->fields[ $k ] = (array) @json_decode( $v, true );
2530
+ }
2531
+ }
2532
+ }
2533
+
2534
+ // Dynamically call the API method
2535
+ $params = (array) $params;
2536
+
2537
+ $output = call_user_func( array( $api, $method->name ), $params );
2538
+ }
2539
+
2540
+ // Output in json format
2541
+ if ( false !== $output ) {
2542
+
2543
+ /**
2544
+ * Pods Admin AJAX request was successful
2545
+ *
2546
+ * @since 2.6.8
2547
+ *
2548
+ * @param array $params AJAX parameters
2549
+ * @param array|object|string $output Output for AJAX request
2550
+ */
2551
+ do_action( "pods_admin_ajax_success_{$method->name}", $params, $output );
2552
+
2553
+ if ( is_array( $output ) || is_object( $output ) )
2554
+ wp_send_json( $output );
2555
+ else
2556
+ echo $output;
2557
+ }
2558
+ else
2559
+ pods_error( 'There was a problem with your request.' );
2560
+
2561
+ die(); // KBAI!
2562
+ }
2563
 
2564
  /**
2565
+ * Profiles the Pods configuration
2566
  *
2567
+ * @param null|string|array $pod. Optional. Which Pod(s) to get configuration for. Can be a the name of one Pod, or an array of names of Pods, or null, which is the default, to profile all Pods.
2568
+ * @param bool $full_field_info Optional. If true all info about each field is returned. If false, which is the default only name and type, will be returned.
2569
  *
2570
+ * @return array
2571
+ *
2572
+ * @since 3.0.0
2573
  */
2574
+ function configuration( $pod = null, $full_field_info = false ){
2575
+ $api = pods_api();
2576
 
2577
+ if ( is_null( $pod ) ) {
2578
+ $the_pods = $api->load_pods();
 
2579
  }
2580
+ elseif( is_array( $pod ) ) {
2581
+ foreach ( $pod as $p ) {
2582
+ $the_pods[] = $api->load_pod( $p );
2583
+ }
 
 
 
 
 
 
 
2584
  }
2585
+ else {
2586
+ $the_pods[] = $api->load_pod( $pod );
 
 
 
 
 
 
 
 
 
 
 
 
2587
  }
2588
 
2589
+ foreach( $the_pods as $pod ) {
2590
+ $configuration[ $pod[ 'name' ] ] = array(
2591
+ 'name' => $pod['name'],
2592
+ 'ID' => $pod[ 'id' ],
2593
+ 'storage' => $pod[ 'storage' ],
2594
+ 'fields' => $pod[ 'fields' ],
2595
+ );
 
 
 
 
 
2596
  }
 
 
 
 
 
 
 
 
 
2597
 
2598
+ if ( ! $full_field_info ) {
2599
+ foreach ( $the_pods as $pod ) {
2600
+ $fields = $configuration[ $pod['name'] ][ 'fields' ];
2601
+ unset( $configuration[ $pod['name'] ][ 'fields' ] );
2602
+ foreach ( $fields as $field ) {
2603
+ $info = array (
2604
+ 'name' => $field[ 'name' ],
2605
+ 'type' => $field[ 'type' ],
2606
+ );
 
 
 
 
 
2607
 
2608
+ if ( $info[ 'type' ] === 'pick' ) {
2609
+ $info[ 'pick_object' ] = $field[ 'pick_object' ];
2610
+ if ( isset ( $field[ 'pick_val' ] ) && $field[ 'pick_val' ] !== '' ) {
2611
+ $info[ 'pick_val' ] = $field[ 'pick_val' ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2612
  }
2613
  }
 
2614
 
2615
+ if ( is_array( $info ) ) {
2616
+ $configuration[ $pod[ 'name' ] ][ 'fields' ][ $field[ 'name' ] ] = $info;
2617
+ }
 
 
2618
 
2619
+ unset( $info );
 
2620
 
 
2621
  }
2622
 
 
 
 
 
 
 
 
 
 
 
 
2623
  }
2624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2625
  }
2626
 
2627
+ if ( is_array ( $configuration ) ) {
2628
+ return $configuration;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2629
 
2630
+ }
 
2631
 
 
2632
  }
2633