Pods – Custom Content Types and Fields - Version 2.7.1

Version Description

  • December 8th 2017 =

  • Fix table join logic for taxonomies when renaming meta fields #4613 @sc0ttkclark

  • Fix Pods Form submit errors and 404s #4618 @pglewis

  • Fix dashicons style conflicts with Pods Form #4626 @nicdford

  • Roll-back minimum version requirement for MySQL from 5.5 to 5.1 #4634 @sc0ttkclark

Download this release

Release Info

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

Code changes from version 2.6.11 to 2.7.1

Files changed (93) hide show
  1. CODEOWNERS +0 -8
  2. classes/Pods.php +168 -44
  3. classes/PodsAPI.php +309 -337
  4. classes/PodsAdmin.php +466 -96
  5. classes/PodsData.php +74 -15
  6. classes/PodsField.php +630 -343
  7. classes/PodsForm.php +153 -60
  8. classes/PodsI18n.php +510 -0
  9. classes/PodsInit.php +363 -202
  10. classes/PodsMeta.php +375 -192
  11. classes/PodsRESTFields.php +51 -38
  12. classes/PodsRESTHandlers.php +63 -136
  13. classes/PodsUI.php +329 -176
  14. classes/cli/PodsAPI_CLI_Command.php +235 -0
  15. classes/cli/Pods_CLI_Command.php +141 -0
  16. classes/fields/avatar.php +159 -358
  17. classes/fields/boolean.php +17 -0
  18. classes/fields/color.php +1 -7
  19. classes/fields/comment.php +19 -0
  20. classes/fields/currency.php +102 -350
  21. classes/fields/date.php +184 -331
  22. classes/fields/datetime.php +874 -405
  23. classes/fields/email.php +10 -1
  24. classes/fields/file.php +1073 -822
  25. classes/fields/link.php +406 -0
  26. classes/fields/number.php +234 -250
  27. classes/fields/oembed.php +578 -0
  28. classes/fields/paragraph.php +10 -1
  29. classes/fields/password.php +10 -1
  30. classes/fields/phone.php +10 -1
  31. classes/fields/pick.php +2998 -2098
  32. classes/fields/slug.php +21 -0
  33. classes/fields/text.php +10 -1
  34. classes/fields/time.php +225 -344
  35. classes/fields/website.php +513 -368
  36. components/Helpers.php +58 -5
  37. components/I18n/I18n-polylang.php +44 -0
  38. components/I18n/I18n-wpml.php +50 -0
  39. components/I18n/I18n.php +897 -0
  40. components/I18n/pods-admin-i18n.js +158 -0
  41. components/Migrate-Packages/ui/wizard.php +1 -1
  42. components/Pages.php +3 -3
  43. components/Roles/Roles.php +2 -2
  44. components/Roles/ui/edit.php +181 -178
  45. components/Templates/Templates.php +3 -3
  46. components/Templates/includes/functions-view_template.php +184 -79
  47. includes/classes.php +13 -4
  48. includes/data.php +5 -28
  49. includes/general.php +180 -120
  50. init.php +84 -77
  51. readme.txt +59 -7
  52. ui/admin/components-admin.php +14 -10
  53. ui/admin/field-option.php +18 -14
  54. ui/admin/form-settings.php +11 -9
  55. ui/admin/form.php +23 -19
  56. ui/admin/help.php +5 -5
  57. ui/admin/settings-reset.php +1 -1
  58. ui/admin/settings-tools.php +2 -2
  59. ui/admin/settings.php +2 -2
  60. ui/admin/setup-add.php +51 -37
  61. ui/admin/setup-edit-field-fluid.php +22 -22
  62. ui/admin/setup-edit-field.php +19 -19
  63. ui/admin/setup-edit.php +189 -254
  64. ui/admin/widgets/list.php +1 -1
  65. ui/admin/widgets/single.php +1 -1
  66. ui/fields/cleditor.php +1 -1
  67. ui/fields/codemirror.php +3 -1
  68. ui/fields/date.php +86 -96
  69. ui/fields/datetime.php +123 -158
  70. ui/fields/link.php +75 -0
  71. ui/fields/oembed.php +77 -0
  72. ui/fields/slider.php +1 -1
  73. ui/fields/text.php +1 -0
  74. ui/fields/time.php +88 -103
  75. ui/fields/website.php +4 -3
  76. ui/front/form.php +26 -15
  77. ui/front/view.php +1 -1
  78. ui/images/smoothness/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  79. ui/images/smoothness/ui-bg_flat_75_ffffff_40x100.png +0 -0
  80. ui/images/smoothness/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  81. ui/images/smoothness/ui-bg_glass_65_ffffff_1x400.png +0 -0
  82. ui/images/smoothness/ui-bg_glass_75_dadada_1x400.png +0 -0
  83. ui/images/smoothness/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  84. ui/images/smoothness/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  85. ui/images/smoothness/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  86. ui/images/smoothness/ui-icons_222222_256x240.png +0 -0
  87. ui/images/smoothness/ui-icons_2e83ff_256x240.png +0 -0
  88. ui/images/smoothness/ui-icons_454545_256x240.png +0 -0
  89. ui/images/smoothness/ui-icons_888888_256x240.png +0 -0
  90. ui/images/smoothness/ui-icons_cd0a0a_256x240.png +0 -0
  91. ui/js/floatmenu.js +37 -15
  92. ui/js/jquery.pods.attach.js +4 -3
  93. ui/js/jquery.pods.js +25 -7
CODEOWNERS DELETED
@@ -1,8 +0,0 @@
1
- # These owners will be the default owners for everything in the repo.
2
- * @sc0ttkclark @pglewis
3
-
4
- # These owners will be the default owners for JS files in the repo.
5
- # *.js @exampleuser
6
-
7
- # These owners will be the default owners for PHP files in the repo.
8
- # *.php @exampleuser
 
 
 
 
 
 
 
 
classes/Pods.php CHANGED
@@ -177,7 +177,7 @@ class Pods implements Iterator {
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 ) {
@@ -420,7 +420,7 @@ class Pods implements Iterator {
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 );
@@ -559,7 +559,7 @@ class Pods implements Iterator {
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(
@@ -615,7 +615,7 @@ class Pods implements Iterator {
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(
@@ -653,7 +653,7 @@ class Pods implements Iterator {
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
 
@@ -692,17 +692,17 @@ class Pods implements Iterator {
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
@@ -1153,7 +1153,7 @@ class Pods implements Iterator {
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' ];
@@ -1269,6 +1269,13 @@ class Pods implements Iterator {
1269
  */
1270
  $related_obj = false;
1271
 
 
 
 
 
 
 
 
1272
  if ( 'pod' == $object_type )
1273
  $related_obj = pods( $object, null, false );
1274
  elseif ( !empty( $table[ 'pod' ] ) )
@@ -1287,8 +1294,12 @@ class Pods implements Iterator {
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`';
@@ -1302,14 +1313,34 @@ class Pods implements Iterator {
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
 
@@ -1417,7 +1448,7 @@ class Pods implements Iterator {
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 {
@@ -1540,7 +1571,7 @@ class Pods implements Iterator {
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
@@ -2141,7 +2172,7 @@ class Pods implements Iterator {
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
 
@@ -2358,7 +2389,7 @@ class Pods implements Iterator {
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
  /**
@@ -2389,7 +2420,7 @@ class Pods implements Iterator {
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
  /**
@@ -2416,7 +2447,7 @@ class Pods implements Iterator {
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 );
@@ -2437,7 +2468,7 @@ class Pods implements Iterator {
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
  /**
@@ -2547,7 +2578,7 @@ class Pods implements Iterator {
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 )
@@ -2836,7 +2867,7 @@ class Pods implements Iterator {
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 )
@@ -2908,7 +2939,7 @@ class Pods implements Iterator {
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 )
@@ -2959,7 +2990,7 @@ class Pods implements Iterator {
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 )
@@ -3006,7 +3037,7 @@ class Pods implements Iterator {
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(
@@ -3014,7 +3045,8 @@ class Pods implements Iterator {
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' ] ) ) )
@@ -3079,7 +3111,7 @@ class Pods implements Iterator {
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
 
@@ -3155,7 +3187,7 @@ class Pods implements Iterator {
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(
@@ -3278,12 +3310,65 @@ class Pods implements Iterator {
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
  }
@@ -3300,7 +3385,7 @@ class Pods implements Iterator {
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;
@@ -3373,7 +3458,7 @@ class Pods implements Iterator {
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(
@@ -3586,6 +3671,22 @@ class Pods implements Iterator {
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
 
@@ -3822,7 +3923,8 @@ class Pods implements Iterator {
3822
  'duplicate' => $this->pod_data[ 'fields' ]
3823
  ),
3824
  'icon' => $icon,
3825
- 'actions_disabled' => $actions_disabled
 
3826
  );
3827
 
3828
  if ( !empty( $filters ) ) {
@@ -3842,12 +3944,17 @@ class Pods implements Iterator {
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
 
@@ -3968,4 +4075,21 @@ class Pods implements Iterator {
3968
  pods_deprecated( "Pods::{$name}", '2.0' );
3969
  }
3970
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3971
  }
177
  *
178
  * @license http://www.gnu.org/licenses/gpl-2.0.html
179
  * @since 1.0.0
180
+ * @link https://pods.io/docs/pods/
181
  */
182
  public function __construct ( $pod = null, $id = null ) {
183
  if ( null === $pod ) {
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 https://pods.io/docs/data/
424
  */
425
  public function data () {
426
  do_action( 'pods_pods_data', $this );
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 https://pods.io/docs/display/
563
  */
564
  public function display ( $name, $single = null ) {
565
  $defaults = array(
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 https://pods.io/docs/display/
619
  */
620
  public function raw ( $name, $single = null ) {
621
  $defaults = array(
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 https://pods.io/docs/field/
657
  */
658
  public function field ( $name, $single = null, $raw = false ) {
659
 
692
  }
693
  elseif ( null === $params->output ) {
694
  /**
695
+ * Override the way related fields are output
696
  *
697
+ * @param string $output How to output related fields. Default is 'arrays'. Options: ids|names|objects|arrays|pods|find
698
+ * @param array|object $row Current row being outputted.
699
+ * @param array $params Params array passed to field().
700
+ * @param 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' ), true ) )
706
  $params->output .= 's';
707
 
708
  // Support old $orderby variable
1153
  }
1154
 
1155
  // Tableless handler
1156
+ if ( $field_exists && ( !in_array( $all_fields[ $pod ][ $field ][ 'type' ], array( 'pick', 'taxonomy', 'comment' ) ) || !$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' ];
1269
  */
1270
  $related_obj = false;
1271
 
1272
+ // Check if we can return the full object/array or if we need to traverse into it
1273
+ $is_field_output_full = false;
1274
+
1275
+ if ( false !== $field_exists && ( in_array( $last_type, $tableless_field_types ) && !$simple ) ) {
1276
+ $is_field_output_full = true;
1277
+ }
1278
+
1279
  if ( 'pod' == $object_type )
1280
  $related_obj = pods( $object, null, false );
1281
  elseif ( !empty( $table[ 'pod' ] ) )
1294
  'expires' => 180 // @todo This could potentially cause issues if someone changes the data within this time and persistent storage is used
1295
  );
1296
 
1297
+ if ( ! empty( $table['where_default'] ) ) {
1298
+ $sql['where_default'] = $table['where_default'];
1299
+ }
1300
+
1301
  // Output types
1302
+ if ( in_array( $params->output, array( 'ids', 'objects', 'pods' ), true ) )
1303
  $sql[ 'select' ] = '`t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`';
1304
  elseif ( 'names' == $params->output && !empty( $table[ 'field_index' ] ) )
1305
  $sql[ 'select' ] = '`t`.`' . $table[ 'field_index' ] . '` AS `pod_item_index`, `t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`';
1313
  $sql[ 'where' ] = array_merge( (array) $where, (array) $params->params['where' ] );
1314
  }
1315
 
1316
+ $item_data = array();
1317
+
1318
  if ( empty( $related_obj ) ) {
1319
+ if ( ! is_object( $this->alt_data ) ) {
1320
  $this->alt_data = pods_data( null, 0, true, true );
1321
+ }
1322
 
1323
  $item_data = $this->alt_data->select( $sql );
1324
+ } else {
1325
+ // Support 'find' output ordering
1326
+ if ( 'find' === $params->output && $is_field_output_full && empty( $sql['orderby'] ) && $ids ) {
1327
+ // Handle default orderby for ordering by the IDs
1328
+ $order_ids = implode( ', ', array_map( 'absint', $ids ) );
1329
+
1330
+ $sql['orderby'] = 'FIELD( `t`.`' . $table[ 'field_id' ] . '`, ' . $order_ids . ' )';
1331
+ }
1332
+
1333
+ $related_obj->find( $sql );
1334
+
1335
+ // Support 'find' output
1336
+ if ( 'find' === $params->output && $is_field_output_full ) {
1337
+ $data = $related_obj;
1338
+
1339
+ $is_field_output_full = true;
1340
+ } else {
1341
+ $item_data = $related_obj->data();
1342
+ }
1343
  }
 
 
1344
 
1345
  $items = array();
1346
 
1448
  }
1449
 
1450
  // Return entire array
1451
+ if ( $is_field_output_full )
1452
  $value = $data;
1453
  // Return an array of single column values
1454
  else {
1571
 
1572
  $value = PodsForm::field_method( 'pick', 'simple_value', $field, $value, $last_options, $all_fields[ $pod ], 0, true );
1573
  }
1574
+ elseif ( false === $params->in_form && !empty( $value ) && is_array( $value ) )
1575
  $value = array_values( $value );
1576
 
1577
  // Return a single column value
2172
  *
2173
  * @return \Pods The pod object
2174
  * @since 2.0
2175
+ * @link https://pods.io/docs/find/
2176
  */
2177
  public function find ( $params = null, $limit = 15, $where = null, $sql = null ) {
2178
 
2389
  * @return array An array of fields from the row
2390
  *
2391
  * @since 2.0
2392
+ * @link https://pods.io/docs/fetch/
2393
  */
2394
  public function fetch ( $id = null, $explicit_set = true ) {
2395
  /**
2420
  * @return \Pods The pod object
2421
  *
2422
  * @since 2.0
2423
+ * @link https://pods.io/docs/reset/
2424
  */
2425
  public function reset ( $row = null ) {
2426
  /**
2447
  *
2448
  * @return int Number of rows returned by find(), based on the 'limit' parameter set
2449
  * @since 2.0
2450
+ * @link https://pods.io/docs/total/
2451
  */
2452
  public function total () {
2453
  do_action( 'pods_pods_total', $this );
2468
  *
2469
  * @return int Number of rows returned by find(), regardless of the 'limit' parameter
2470
  * @since 2.0
2471
+ * @link https://pods.io/docs/total-found/
2472
  */
2473
  public function total_found () {
2474
  /**
2578
  * @return int The item ID
2579
  *
2580
  * @since 2.0
2581
+ * @link https://pods.io/docs/add/
2582
  */
2583
  public function add ( $data = null, $value = null ) {
2584
  if ( null !== $value )
2867
  * @return int The item ID
2868
  *
2869
  * @since 2.0
2870
+ * @link https://pods.io/docs/save/
2871
  */
2872
  public function save ( $data = null, $value = null, $id = null, $params = null ) {
2873
  if ( null !== $value )
2939
  * @return bool Whether the item was successfully deleted
2940
  *
2941
  * @since 2.0
2942
+ * @link https://pods.io/docs/delete/
2943
  */
2944
  public function delete ( $id = null ) {
2945
  if ( null === $id )
2990
  * @return int|bool ID of the new pod item
2991
  *
2992
  * @since 2.0
2993
+ * @link https://pods.io/docs/duplicate/
2994
  */
2995
  public function duplicate ( $id = null ) {
2996
  if ( null === $id )
3037
  * @return array|bool Data array of the exported pod item
3038
  *
3039
  * @since 2.0
3040
+ * @link https://pods.io/docs/export/
3041
  */
3042
  public function export ( $fields = null, $id = null, $format = null ) {
3043
  $params = array(
3045
  'id' => $id,
3046
  'fields' => null,
3047
  'depth' => 2,
3048
+ 'flatten' => false,
3049
+ 'context' => null,
3050
  );
3051
 
3052
  if ( is_array( $fields ) && ( isset( $fields[ 'fields' ] ) || isset( $fields[ 'depth' ] ) ) )
3111
  *
3112
  * @return string Pagination HTML
3113
  * @since 2.0
3114
+ * @link https://pods.io/docs/pagination/
3115
  */
3116
  public function pagination( $params = null ) {
3117
 
3187
  * @return string Filters HTML
3188
  *
3189
  * @since 2.0
3190
+ * @link https://pods.io/docs/filters/
3191
  */
3192
  public function filters ( $params = null ) {
3193
  $defaults = array(
3310
  if ( is_array( $helper ) )
3311
  $params = array_merge( $params, $helper );
3312
 
3313
+ if ( class_exists( 'Pods_Helpers' ) ) {
3314
  $value = Pods_Helpers::helper( $params, $this );
3315
+ } elseif ( function_exists( $params['helper'] ) ) {
3316
+ $disallowed = array(
3317
+ 'system',
3318
+ 'exec',
3319
+ 'popen',
3320
+ 'eval',
3321
+ 'preg_replace',
3322
+ 'create_function',
3323
+ 'include',
3324
+ 'include_once',
3325
+ 'require',
3326
+ 'require_once',
3327
+ );
3328
+
3329
+ $allowed = array();
3330
+
3331
+ /**
3332
+ * Allows adjusting the disallowed callbacks as needed.
3333
+ *
3334
+ * @param array $disallowed List of callbacks not allowed.
3335
+ * @param array $params Parameters used by Pods::helper() method.
3336
+ *
3337
+ * @since 2.7
3338
+ */
3339
+ $disallowed = apply_filters( 'pods_helper_disallowed_callbacks', $disallowed, $params );
3340
+
3341
+ /**
3342
+ * Allows adjusting the allowed allowed callbacks as needed.
3343
+ *
3344
+ * @param array $allowed List of callbacks explicitly allowed.
3345
+ * @param array $params Parameters used by Pods::helper() method.
3346
+ *
3347
+ * @since 2.7
3348
+ */
3349
+ $allowed = apply_filters( 'pods_helper_allowed_callbacks', $allowed, $params );
3350
+
3351
+ // Clean up helper callback (if string)
3352
+ if ( is_string( $params['helper'] ) ) {
3353
+ $params['helper'] = strip_tags( str_replace( array( '`', chr( 96 ) ), "'", $params['helper'] ) );
3354
+ }
3355
+
3356
+ $is_allowed = false;
3357
+
3358
+ if ( ! empty( $allowed ) ) {
3359
+ if ( in_array( $params['helper'], $allowed, true ) ) {
3360
+ $is_allowed = true;
3361
+ }
3362
+ } elseif ( ! in_array( $params['helper'], $disallowed, true ) ) {
3363
+ $is_allowed = true;
3364
+ }
3365
+
3366
+ if ( $is_allowed ) {
3367
+ $value = call_user_func( $params['helper'], $value );
3368
+ }
3369
+ } else {
3370
+ $value = apply_filters( $params['helper'], $value );
3371
+ }
3372
 
3373
  return $value;
3374
  }
3385
  * @return mixed Template output
3386
  *
3387
  * @since 2.0
3388
+ * @link https://pods.io/docs/template/
3389
  */
3390
  public function template ( $template_name, $code = null, $deprecated = false ) {
3391
  $out = null;
3458
  *
3459
  * @return bool|mixed
3460
  * @since 2.0
3461
+ * @link https://pods.io/docs/form/
3462
  */
3463
  public function form ( $params = null, $label = null, $thank_you = null ) {
3464
  $defaults = array(
3671
  * @since 2.0
3672
  */
3673
  public function do_magic_tags ( $code ) {
3674
+
3675
+ /**
3676
+ * Filters the Pods magic tags content before the default function.
3677
+ * Allows complete replacement of the Pods magic tag engine.
3678
+ *
3679
+ * @param null $pre Default is null which processes magic tags normally. Return any other value to override.
3680
+ * @param string $code The content to evaluate
3681
+ * @param Pods $pods The Pods Object
3682
+ *
3683
+ * @since 2.7
3684
+ */
3685
+ $pre = apply_filters( 'pods_pre_do_magic_tags', null, $code, $this );
3686
+ if ( null !== $pre ) {
3687
+ return $pre;
3688
+ }
3689
+
3690
  return preg_replace_callback( '/({@(.*?)})/m', array( $this, 'process_magic_tags' ), $code );
3691
  }
3692
 
3923
  'duplicate' => $this->pod_data[ 'fields' ]
3924
  ),
3925
  'icon' => $icon,
3926
+ 'actions_disabled' => $actions_disabled,
3927
+ 'actions_bulk' => array(),
3928
  );
3929
 
3930
  if ( !empty( $filters ) ) {
3944
  if ( !empty( $author_restrict ) )
3945
  $ui[ 'restrict' ] = array( 'author_restrict' => $author_restrict );
3946
 
3947
+ if ( ! in_array( 'export', $ui[ 'actions_disabled' ] ) ) {
3948
+ $ui['actions_bulk']['export'] = array(
3949
+ 'label' => __( 'Export', 'pods' )
3950
+ // callback not needed, Pods has this built-in for export
3951
+ );
3952
+ }
3953
+
3954
  if ( !in_array( 'delete', $ui[ 'actions_disabled' ] ) ) {
3955
+ $ui['actions_bulk']['delete'] = array(
3956
+ 'label' => __( 'Delete', 'pods' )
3957
+ // callback not needed, Pods has this built-in for delete
 
 
3958
  );
3959
  }
3960
 
4075
  pods_deprecated( "Pods::{$name}", '2.0' );
4076
  }
4077
  }
4078
+
4079
+ /**
4080
+ * Handle casting a Pods() object to string
4081
+ *
4082
+ * @return string Pod type and name in CURIE notation
4083
+ */
4084
+ public function __toString() {
4085
+
4086
+ $string = '';
4087
+
4088
+ if ( ! empty( $this->pod_data ) ) {
4089
+ $string = sprintf( '%s:%s', $this->pod_data['type'], $this->pod_data['name'] );
4090
+ }
4091
+
4092
+ return $string;
4093
+
4094
+ }
4095
  }
classes/PodsAPI.php CHANGED
@@ -641,15 +641,15 @@ class PodsAPI {
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 )
@@ -1073,6 +1073,18 @@ class PodsAPI {
1073
  'type' => 'number',
1074
  'alias' => array(),
1075
  'hidden' => true
 
 
 
 
 
 
 
 
 
 
 
 
1076
  )
1077
  );
1078
 
@@ -2664,9 +2676,17 @@ class PodsAPI {
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
@@ -3288,6 +3308,10 @@ class PodsAPI {
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 );
@@ -3347,10 +3371,6 @@ class PodsAPI {
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' ];
@@ -3405,6 +3425,7 @@ class PodsAPI {
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
  }
@@ -3532,55 +3553,58 @@ class PodsAPI {
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
 
@@ -3722,7 +3746,7 @@ class PodsAPI {
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
  *
@@ -3830,19 +3854,23 @@ class PodsAPI {
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)
@@ -3902,30 +3930,92 @@ class PodsAPI {
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
 
@@ -4248,7 +4338,8 @@ class PodsAPI {
4248
 
4249
  $save_params = array(
4250
  'pod' => $params->pod,
4251
- 'data' => array()
 
4252
  );
4253
 
4254
  $ignore_fields = array(
@@ -4343,31 +4434,38 @@ class PodsAPI {
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
  }
@@ -4376,23 +4474,51 @@ class PodsAPI {
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(
@@ -4402,6 +4528,22 @@ class PodsAPI {
4402
  }
4403
 
4404
  if ( isset( $pod->fields[ $field[ 'name' ] ] ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4405
  $field = $pod->fields[ $field[ 'name' ] ];
4406
  $field[ 'lookup_name' ] = $field[ 'name' ];
4407
 
@@ -4462,9 +4604,17 @@ class PodsAPI {
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
 
@@ -5345,6 +5495,10 @@ class PodsAPI {
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 ) ) )
@@ -5413,7 +5567,7 @@ class PodsAPI {
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'] ) ) {
@@ -5547,7 +5701,7 @@ class PodsAPI {
5547
  return false;
5548
  }
5549
 
5550
- if ( is_array( $pod ) )
5551
  $pod = $pod[ 0 ];
5552
 
5553
  $_pod = get_object_vars( $pod );
@@ -5716,7 +5870,7 @@ class PodsAPI {
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'] ) ) {
@@ -5951,9 +6105,15 @@ class PodsAPI {
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() ) {
@@ -6091,7 +6251,7 @@ class PodsAPI {
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
 
@@ -6243,6 +6403,7 @@ class PodsAPI {
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
@@ -6286,6 +6447,12 @@ class PodsAPI {
6286
  else
6287
  $params->type = (array) $params->type;
6288
 
 
 
 
 
 
 
6289
  $fields = array();
6290
 
6291
  if ( !empty( $params->pod ) || !empty( $params->pod_id ) ) {
@@ -6298,7 +6465,9 @@ class PodsAPI {
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 ) )
@@ -6801,6 +6970,9 @@ class PodsAPI {
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
 
@@ -6988,7 +7160,7 @@ class PodsAPI {
6988
  * @param array $field Field data array
6989
  * @param array $pod Pod data array
6990
  *
6991
- * @return array
6992
  *
6993
  * @since 2.0
6994
  *
@@ -7000,13 +7172,12 @@ class PodsAPI {
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 ];
@@ -7043,8 +7214,18 @@ class PodsAPI {
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;
@@ -7405,7 +7586,7 @@ class PodsAPI {
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;
@@ -7518,7 +7699,7 @@ class PodsAPI {
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'] ) ) {
@@ -7615,7 +7796,9 @@ class PodsAPI {
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
 
@@ -8088,7 +8271,7 @@ class PodsAPI {
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;
@@ -8099,7 +8282,7 @@ class PodsAPI {
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;
@@ -8110,7 +8293,7 @@ class PodsAPI {
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;
@@ -8118,7 +8301,7 @@ class PodsAPI {
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;
@@ -8131,7 +8314,7 @@ class PodsAPI {
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;
@@ -8336,237 +8519,26 @@ class PodsAPI {
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
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 ( 1 < 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 )
1073
  'type' => 'number',
1074
  'alias' => array(),
1075
  'hidden' => true
1076
+ ),
1077
+ 'comments' => array(
1078
+ 'name' => 'comments',
1079
+ 'label' => 'Comments',
1080
+ 'type' => 'comment',
1081
+ 'pick_object' => 'comment',
1082
+ 'pick_val' => 'comment',
1083
+ 'alias' => array(),
1084
+ 'hidden' => true,
1085
+ 'options' => array(
1086
+ 'comment_format_type' => 'multi'
1087
+ )
1088
  )
1089
  );
1090
 
2676
  if ( !empty( $pod[ 'field_type' ] ) )
2677
  $prepare[] = $pod[ 'name' ];
2678
 
2679
+ $join_table = $pod['table'];
2680
+
2681
+ // Taxonomies are the odd type out, terrible I know
2682
+ if ( 'taxonomy' === $pod['type'] ) {
2683
+ // wp_term_taxonomy has the 'taxonomy' field we need to limit by
2684
+ $join_table = $wpdb->term_taxonomy;
2685
+ }
2686
+
2687
  pods_query( "
2688
  UPDATE `{$pod[ 'meta_table' ]}` AS `m`
2689
+ LEFT JOIN `{$join_table}` AS `t`
2690
  ON `t`.`{$pod[ 'field_id' ]}` = `m`.`{$pod[ 'meta_field_id' ]}`
2691
  SET
2692
  `m`.`{$pod[ 'meta_field_index' ]}` = %s
3308
  'changed_fields'
3309
  );
3310
 
3311
+ if ( $track_changed_fields ) {
3312
+ self::handle_changed_fields( $params->pod, $params->id, 'set' );
3313
+ }
3314
+
3315
  if ( false === $bypass_helpers ) {
3316
  // Plugin hooks
3317
  $hooked = $this->do_hook( 'pre_save_pod_item', compact( $pieces ), $is_new_item, $params->id );
3371
  }
3372
  }
3373
 
 
 
 
 
3374
  $table_data = $table_formats = $update_values = $rel_fields = $rel_field_ids = array();
3375
 
3376
  $object_type = $pod[ 'type' ];
3425
  $field_data[ 'value' ] = $value;
3426
 
3427
  if ( isset( $object_fields[ $field ] ) ) {
3428
+ // @todo Eventually support 'comment' field type saving here too
3429
  if ( 'taxonomy' == $object_fields[ $field ][ 'type' ] ) {
3430
  $post_term_data[ $field ] = $value;
3431
  }
3553
  $object_data[ $object_name_field ] = $object_name;
3554
  }
3555
 
3556
+ if ( ! in_array( $pod['type'], array( 'pod', 'table', '' ) ) ) {
3557
+ $meta_fields = array();
 
3558
 
3559
+ if ( 'meta' === $pod['storage'] || 'settings' === $pod['type'] || ( 'taxonomy' === $pod['type'] && 'none' === $pod['storage'] ) ) {
3560
+ $meta_fields = $object_meta;
3561
+ }
3562
+
3563
+ if ( $allow_custom_fields && ! empty( $custom_data ) ) {
3564
+ $meta_fields = array_merge( $custom_data, $meta_fields );
3565
+ }
3566
+
3567
+ $fields_to_send = array_flip( array_keys( $meta_fields ) );
3568
 
3569
  foreach ( $fields_to_send as $field => $field_data ) {
3570
  if ( isset( $object_fields[ $field ] ) ) {
3571
  $field_data = $object_fields[ $field ];
3572
+ } elseif ( isset( $fields[ $field ] ) ) {
 
3573
  $field_data = $fields[ $field ];
3574
+ } else {
 
3575
  unset( $fields_to_send[ $field ] );
3576
  }
3577
 
3578
  $fields_to_send[ $field ] = $field_data;
3579
  }
3580
 
3581
+ $params->id = $this->save_wp_object( $object_type, $object_data, $meta_fields, false, true, $fields_to_send );
3582
 
3583
+ if ( ! empty( $params->id ) && 'settings' === $pod['type'] ) {
3584
+ $params->id = $pod['id'];
3585
+ }
3586
+ }
 
 
 
3587
 
3588
+ if ( 'table' == $pod['storage'] ) {
3589
+ // Every row should have an id set here, otherwise Pods with nothing
3590
+ // but relationship fields won't get properly ID'd
3591
+ if ( empty( $params->id ) ) {
3592
+ $params->id = 0;
3593
+ }
3594
 
3595
+ $table_data = array( 'id' => $params->id ) + $table_data;
3596
+ array_unshift( $table_formats, '%d' );
3597
 
3598
+ if ( ! empty( $table_data ) ) {
3599
+ $sql = pods_data()->insert_on_duplicate( "@wp_pods_{$params->pod}", $table_data, $table_formats );
3600
 
3601
+ $id = pods_query( $sql, 'Cannot add/save table row' );
3602
 
3603
+ if ( empty( $params->id ) ) {
3604
+ $params->id = $id;
3605
+ }
3606
+ }
3607
+ }
3608
 
3609
  $params->id = (int) $params->id;
3610
 
3746
  *
3747
  * @param array $tag_data Fields for creating new item.
3748
  * @param int $v Field ID of tag.
3749
+ * @param Pods $search_data Search object for tag.
3750
  * @param string $field Table info for field.
3751
  * @param array $pieces Field array.
3752
  *
3854
  }
3855
 
3856
  if ( false === $bypass_helpers ) {
3857
+ if ( $track_changed_fields ) {
3858
+ $changed_fields = self::handle_changed_fields( $params->pod, $params->id, 'get' );
3859
+ }
3860
+
3861
+ $compact_pieces = compact( $pieces );
3862
 
3863
  // Plugin hooks
3864
+ $this->do_hook( 'post_save_pod_item', $compact_pieces, $is_new_item, $params->id );
3865
+ $this->do_hook( "post_save_pod_item_{$params->pod}", $compact_pieces, $is_new_item, $params->id );
3866
 
3867
  if ( $is_new_item ) {
3868
+ $this->do_hook( 'post_create_pod_item', $compact_pieces, $params->id );
3869
+ $this->do_hook( "post_create_pod_item_{$params->pod}", $compact_pieces, $params->id );
3870
  }
3871
  else {
3872
+ $this->do_hook( 'post_edit_pod_item', $compact_pieces, $params->id );
3873
+ $this->do_hook( "post_edit_pod_item_{$params->pod}", $compact_pieces, $params->id );
3874
  }
3875
 
3876
  // Call any post-save helpers (if not bypassed)
3930
  }
3931
 
3932
  /**
3933
+ *Handle tracking changed fields or get them
3934
  *
3935
+ * @param string $pod
3936
+ * @param int $id
3937
+ * @param string $mode
3938
  *
3939
+ * @return array List of changed fields (if $mode = 'get')
3940
  */
3941
+ public static function handle_changed_fields( $pod, $id, $mode = 'set' ) {
3942
 
3943
+ static $changed_pods_cache = array();
3944
+ static $old_fields_cache = array();
3945
+ static $changed_fields_cache = array();
3946
 
3947
+ $cache_key = $pod . '|' . $id;
3948
 
3949
+ $export_params = array(
3950
+ 'depth' => 1,
3951
+ );
3952
+
3953
+ if ( in_array( $mode, array( 'set', 'reset' ), true ) ) {
3954
+ if ( isset( $changed_fields_cache[ $cache_key ] ) ) {
3955
+ unset( $changed_fields_cache[ $cache_key ] );
3956
+ }
3957
 
3958
+ if ( empty( $old_fields_cache[ $cache_key ] ) || 'reset' === $mode ) {
3959
+ $old_fields_cache[ $cache_key ] = array();
3960
+
3961
+ if ( ! empty( $id ) ) {
3962
+ if ( ! isset( $changed_pods_cache[ $pod ] ) ) {
3963
+ $changed_pods_cache[ $pod ] = pods( $pod );
3964
+ }
3965
+
3966
+ if ( $changed_pods_cache[ $pod ] && $changed_pods_cache[ $pod ]->valid() ) {
3967
+ $changed_pods_cache[ $pod ]->fetch( $id );
3968
+
3969
+ $old_fields_cache[ $cache_key ] = $changed_pods_cache[ $pod ]->export( $export_params );
3970
+ }
3971
  }
3972
  }
3973
  }
3974
 
3975
+ $changed_fields = array();
3976
+
3977
+ if ( isset( $changed_fields_cache[ $cache_key ] ) ) {
3978
+ $changed_fields = $changed_fields_cache[ $cache_key ];
3979
+ } elseif ( isset( $old_fields_cache[ $cache_key ] ) ) {
3980
+ $old_fields = $old_fields_cache[ $cache_key ];
3981
+
3982
+ if ( 'get' === $mode ) {
3983
+ $changed_fields_cache[ $cache_key ] = array();
3984
+
3985
+ if ( ! empty( $changed_pods_cache[ $pod ] ) ) {
3986
+ if ( $id != $changed_pods_cache[ $pod ]->id() ) {
3987
+ $changed_pods_cache[ $pod ]->fetch( $id );
3988
+ }
3989
+
3990
+ $new_fields = $changed_pods_cache[ $pod ]->export( $export_params );
3991
+
3992
+ foreach ( $new_fields as $field => $value ) {
3993
+ if ( ! isset( $old_fields[ $field ] ) || $value != $old_fields[ $field ] ) {
3994
+ $changed_fields[ $field ] = $value;
3995
+ }
3996
+ }
3997
+
3998
+ $changed_fields_cache[ $cache_key ] = $changed_fields;
3999
+ }
4000
+ }
4001
+ }
4002
+
4003
+ return $changed_fields;
4004
+
4005
+ }
4006
+
4007
+ /**
4008
+ * Get the fields that have changed during a save
4009
+ *
4010
+ * @param array $pieces Pieces array from save_pod_item
4011
+ *
4012
+ * @return array Array of fields and values that have changed
4013
+ *
4014
+ * @deprecated Use PodsAPI::handle_changed_fields
4015
+ */
4016
+ public function get_changed_fields( $pieces ) {
4017
+
4018
+ return self::handle_changed_fields( $pieces['params']->pod, $pieces['params']->id, 'get' );
4019
 
4020
  }
4021
 
4338
 
4339
  $save_params = array(
4340
  'pod' => $params->pod,
4341
+ 'data' => array(),
4342
+ 'is_new_item' => true,
4343
  );
4344
 
4345
  $ignore_fields = array(
4434
  * @since 1.12
4435
  */
4436
  public function export_pod_item ( $params, $pod = null ) {
 
 
 
4437
 
4438
+ if ( ! is_object( $pod ) || 'Pods' != get_class( $pod ) ) {
4439
+ if ( empty( $params ) ) {
4440
+ return false;
4441
+ }
4442
+
4443
+ if ( is_object( $params ) ) {
4444
+ $params = get_object_vars( (object) $params );
4445
+ }
4446
 
4447
+ $params = pods_sanitize( $params );
4448
 
4449
+ $pod = pods( $params['pod'], $params['id'], false );
 
 
4450
 
4451
+ if ( empty( $pod ) ) {
4452
+ return false;
4453
+ }
4454
+ }
4455
 
4456
+ $params['fields'] = (array) pods_v( 'fields', $params, array(), true );
4457
+ $params['depth'] = (int) pods_v( 'depth', $params, 2, true );
4458
+ $params['object_fields'] = (array) pods_v( 'object_fields', $pod->pod_data, array(), true );
4459
+ $params['flatten'] = (boolean) pods_v( 'flatten', $params, false, true );
4460
+ $params['context'] = pods_v( 'context', $params, null, true );
4461
+
4462
+ if ( empty( $params['fields'] ) ) {
4463
+ $params['fields'] = array_merge( $pod->fields, $params['object_fields'] );
4464
  }
4465
 
4466
+ $data = $this->export_pod_item_level( $pod, $params );
4467
 
4468
+ $data = $this->do_hook( 'export_pod_item', $data, $pod->pod, $pod->id(), $pod, $params['fields'], $params['depth'], $params['flatten'], $params );
4469
 
4470
  return $data;
4471
  }
4474
  * Export a pod item by depth level
4475
  *
4476
  * @param Pods $pod Pods object
4477
+ * @param array $params Export params
 
 
 
4478
  *
4479
  * @return array Data array
4480
  *
4481
  * @since 2.3
4482
  */
4483
+ private function export_pod_item_level ( $pod, $params ) {
4484
+ $fields = $params['fields'];
4485
+ $depth = $params['depth'];
4486
+ $flatten = $params['flatten'];
4487
+ $current_depth = pods_v( 'current_depth', $params, 1, true );
4488
+ $context = $params['context'];
4489
+
4490
  $tableless_field_types = PodsForm::tableless_field_types();
4491
  $simple_tableless_objects = PodsForm::simple_tableless_objects();
4492
 
4493
+ $object_fields = (array) pods_v( 'object_fields', $pod->pod_data, array(), true );
4494
 
4495
  $export_fields = array();
4496
 
4497
+ $pod_type = $pod->pod_data['type'];
4498
+
4499
+ if ( 'post_type' === $pod_type ) {
4500
+ $pod_type = 'post';
4501
+ } elseif ( 'taxonomy' === $pod_type ) {
4502
+ $pod_type = 'term';
4503
+ }
4504
+
4505
+ $registered_meta_keys = false;
4506
+
4507
+ if ( function_exists( 'get_registered_meta_keys' ) ) {
4508
+ $registered_meta_keys = get_registered_meta_keys( $pod_type );
4509
+ }
4510
+
4511
+ $show_in_rest = false;
4512
+
4513
+ // If in rest, check if this pod can be exposed
4514
+ if ( 'rest' === $context ) {
4515
+ $read_all = (int) pods_v( 'read_all', $pod->pod_data['options'], 0 );
4516
+
4517
+ if ( 1 === $read_all ) {
4518
+ $show_in_rest = true;
4519
+ }
4520
+ }
4521
+
4522
  foreach ( $fields as $k => $field ) {
4523
  if ( !is_array( $field ) ) {
4524
  $field = array(
4528
  }
4529
 
4530
  if ( isset( $pod->fields[ $field[ 'name' ] ] ) ) {
4531
+ // If in rest, check if this field can be exposed
4532
+ if ( 'rest' === $context && false === $show_in_rest ) {
4533
+ $show_in_rest = PodsRESTFields::field_allowed_to_extend( $field[ 'name' ], $pod, 'read' );
4534
+
4535
+ if ( false === $show_in_rest ) {
4536
+ // Fallback to checking $registered_meta_keys
4537
+ if ( false !== $registered_meta_keys ) {
4538
+ if ( ! isset( $registered_meta_keys[ $field['name'] ] ) ) {
4539
+ continue;
4540
+ } elseif ( empty( $registered_meta_keys[ $field['name'] ]['show_in_rest'] ) ) {
4541
+ continue;
4542
+ }
4543
+ }
4544
+ }
4545
+ }
4546
+
4547
  $field = $pod->fields[ $field[ 'name' ] ];
4548
  $field[ 'lookup_name' ] = $field[ 'name' ];
4549
 
4604
 
4605
  foreach ( $related_ids as $related_id ) {
4606
  if ( $related_pod->fetch( $related_id ) ) {
4607
+ $related_params = array(
4608
+ 'fields' => $related_fields,
4609
+ 'depth' => $depth,
4610
+ 'flatten' => $flatten,
4611
+ 'current_depth' => $current_depth + 1,
4612
+ 'context' => $context,
4613
+ );
4614
+
4615
+ $related_item = $this->export_pod_item_level( $related_pod, $related_params );
4616
 
4617
+ $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 ), $params );
4618
  }
4619
  }
4620
 
5495
  'post_type' => '_pods_pod',
5496
  'posts_per_page' => 1
5497
  ) );
5498
+
5499
+ if ( is_array( $pod ) && ! empty( $pod[0] ) ) {
5500
+ $pod = $pod[0];
5501
+ }
5502
  }
5503
 
5504
  if ( !empty( $pod ) && ( empty( $type ) || $type == get_post_meta( $pod->ID, 'type', true ) ) )
5567
  $bypass_cache = false;
5568
 
5569
  // Get current language data
5570
+ $lang_data = PodsInit::$i18n->get_current_language_data();
5571
 
5572
  if ( $lang_data ) {
5573
  if ( ! empty( $lang_data['language'] ) ) {
5701
  return false;
5702
  }
5703
 
5704
+ if ( is_array( $pod ) && ! empty( $pod[0] ) )
5705
  $pod = $pod[ 0 ];
5706
 
5707
  $_pod = get_object_vars( $pod );
5870
  $current_language = false;
5871
 
5872
  // Get current language data
5873
+ $lang_data = PodsInit::$i18n->get_current_language_data();
5874
 
5875
  if ( $lang_data ) {
5876
  if ( ! empty( $lang_data['language'] ) ) {
6105
  }
6106
  }
6107
 
6108
+ if ( ( ! function_exists( 'pll_current_language' ) || ! empty( $params->refresh ) ) &&
6109
+ ! empty( $cache_key ) && ( 'pods' !== $cache_key || empty( $meta_query ) ) &&
6110
+ $limit < 1 &&
6111
+ ( empty( $orderby ) || 'menu_order title' === $orderby ) &&
6112
+ empty( $ids )
6113
+ ) {
6114
+ $total_pods = (int) ( is_array( $the_pods ) ) ? count( $the_pods ) : $the_pods;
6115
  // Too many Pods can cause issues with the DB when caching is not enabled
6116
+ if ( 15 < $total_pods || 75 < (int) $total_fields ) {
6117
  pods_transient_clear( $cache_key );
6118
 
6119
  if ( pods_api_cache() ) {
6251
  'post_parent' => $params->pod_id
6252
  ) );
6253
 
6254
+ if ( empty( $field ) || empty( $field[0] ) ) {
6255
  if ( $strict )
6256
  return pods_error( __( 'Field not found', 'pods' ), $this );
6257
 
6403
  * $params['type'] array The field types
6404
  * $params['options'] array Field Option(s) key=>value array to filter by
6405
  * $params['where'] string WHERE clause of query
6406
+ * $params['object_fields'] bool Whether to include the object fields for WP objects, default true
6407
  *
6408
  * @param array $params An associative array of parameters
6409
  * @param bool $strict Whether to require a field exist or not when loading the info
6447
  else
6448
  $params->type = (array) $params->type;
6449
 
6450
+ if ( ! isset( $params->object_fields ) ) {
6451
+ $params->object_fields = true;
6452
+ } else {
6453
+ $params->object_fields = (boolean) $params->object_fields;
6454
+ }
6455
+
6456
  $fields = array();
6457
 
6458
  if ( !empty( $params->pod ) || !empty( $params->pod_id ) ) {
6465
  return $fields;
6466
  }
6467
 
6468
+ if ( $params->object_fields && ! empty( $pod['object_fields'] ) ) {
6469
+ $pod[ 'fields' ] = array_merge( $pod['object_fields'], $pod[ 'fields' ] );
6470
+ }
6471
 
6472
  foreach ( $pod[ 'fields' ] as $field ) {
6473
  if ( empty( $params->name ) && empty( $params->id ) && empty( $params->type ) )
6970
  $params->related_pod = pods_str_replace( 'taxonomy-', '', $params->related_pod, 1 );
6971
  $type = 'taxonomy';
6972
  }
6973
+ elseif ( 'comment' === $params->related_pod ) {
6974
+ $type = $params->related_pod;
6975
+ }
6976
 
6977
  $related_pod = $this->load_pod( array( 'name' => $params->related_pod, 'table_info' => false ), false );
6978
 
7160
  * @param array $field Field data array
7161
  * @param array $pod Pod data array
7162
  *
7163
+ * @return int[]
7164
  *
7165
  * @since 2.0
7166
  *
7172
  if ( !is_array( $ids ) )
7173
  $ids = explode( ',', $ids );
7174
 
7175
+ $ids = array_map( 'absint', $ids );
 
 
7176
 
7177
  $ids = array_unique( array_filter( $ids ) );
7178
 
7179
  $idstring = implode( ',', $ids );
7180
+
7181
  if ( 0 != $pod_id && 0 != $field_id && isset( self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ] ) ) {
7182
  // Check cache first, no point in running the same query multiple times
7183
  return self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ];
7214
  if ( !is_wp_error( $related ) ) {
7215
  $related_ids = $related;
7216
  }
7217
+ } elseif ( 'comment' == $field_type ) {
7218
+ $comment_args = array(
7219
+ 'post__in' => $ids,
7220
+ 'fields' => 'ids',
7221
+ );
7222
+
7223
+ $related = get_comments( $comment_args );
7224
+
7225
+ if ( ! is_wp_error( $related ) ) {
7226
+ $related_ids = $related;
7227
+ }
7228
+ } elseif ( !pods_tableless() ) {
7229
  $ids = implode( ', ', $ids );
7230
 
7231
  $field_id = (int) $field_id;
7586
  )
7587
  ) );
7588
 
7589
+ if ( !empty( $slug_field[0] ) ) {
7590
  $slug_field = $slug_field[ 0 ];
7591
 
7592
  $info[ 'field_slug' ] = $info[ 'pod_field_slug' ] = $slug_field->post_name;
7699
  $current_language_t_id = $current_language_tt_id = 0;
7700
 
7701
  // Get current language data
7702
+ $lang_data = PodsInit::$i18n->get_current_language_data();
7703
 
7704
  if ( $lang_data ) {
7705
  if ( ! empty( $lang_data['language'] ) ) {
7796
  $post_status = array( 'publish' );
7797
 
7798
  // Pick field post_status option
7799
+ if ( ! empty( $field['options']['pick_post_status'] ) ) {
7800
+ $post_status = (array) $field['options']['pick_post_status'];
7801
+ } elseif ( ! empty( $field['pick_post_status'] ) ) {
7802
  $post_status = (array) $field['pick_post_status'];
7803
  }
7804
 
8271
  if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
8272
  $where = "`tt`.`term_id` = " . pods_absint( $pick_value );
8273
 
8274
+ $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 );
8275
 
8276
  if ( !empty( $result ) )
8277
  $pick_values[] = $result[ 0 ]->id;
8282
  if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
8283
  $where = "`ID` = " . pods_absint( $pick_value );
8284
 
8285
+ $result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = '{$pick_val}' AND {$where} ORDER BY `ID` LIMIT 1", $this );
8286
 
8287
  if ( !empty( $result ) )
8288
  $pick_values[] = $result[ 0 ]->id;
8293
  if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
8294
  $where = "`ID` = " . pods_absint( $pick_value );
8295
 
8296
+ $result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->users}` WHERE {$where} ORDER BY `ID` LIMIT 1", $this );
8297
 
8298
  if ( !empty( $result ) )
8299
  $pick_values[] = $result[ 0 ]->id;
8301
  elseif ( in_array( 'comment', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
8302
  $where = "`comment_ID` = " . pods_absint( $pick_value );
8303
 
8304
+ $result = pods_query( "SELECT `comment_ID` AS `id` FROM `{$wpdb->comments}` WHERE {$where} ORDER BY `ID` LIMIT 1", $this );
8305
 
8306
  if ( !empty( $result ) )
8307
  $pick_values[] = $result[ 0 ]->id;
8314
  if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
8315
  $where = "`" . $related_pod[ 'field_id' ] . "` = " . pods_absint( $pick_value );
8316
 
8317
+ $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 );
8318
 
8319
  if ( !empty( $result ) )
8320
  $pick_values[] = $result[ 0 ]->id;
8519
 
8520
  $id = $this->save_pod_item( $params );
8521
 
8522
+ /**
8523
+ * Fires after the form has been processed and save_pod_item has run.
8524
+ *
8525
+ * @param int $id Item ID.
8526
+ * @param array $params save_pod_item parameters.
8527
+ * @param null|Pods $obj Pod object (if set).
8528
+ */
8529
+ do_action( 'pods_api_processed_form', $id, $params, $obj );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8530
 
8531
+ // Always return $id for AJAX requests.
8532
+ if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
8533
+ if ( 0 < $id && ! empty( $thank_you ) ) {
8534
+ $thank_you = str_replace( 'X_ID_X', $id, $thank_you );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8535
 
8536
+ pods_redirect( $thank_you, 302, false );
 
 
 
 
 
 
 
8537
  }
8538
  }
8539
 
8540
+ return $id;
8541
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8542
 
8543
  /**
8544
  * Handle filters / actions for the class
classes/PodsAdmin.php CHANGED
@@ -100,18 +100,10 @@ class PodsAdmin {
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 );
@@ -128,11 +120,8 @@ class PodsAdmin {
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
 
@@ -142,34 +131,28 @@ class PodsAdmin {
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
  /**
@@ -198,21 +181,24 @@ class PodsAdmin {
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;
@@ -238,13 +224,13 @@ class PodsAdmin {
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' ) );
@@ -264,8 +250,8 @@ class PodsAdmin {
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
  }
@@ -636,6 +622,7 @@ class PodsAdmin {
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,
@@ -710,7 +697,7 @@ class PodsAdmin {
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
  /**
@@ -985,10 +972,360 @@ class PodsAdmin {
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(
@@ -1038,7 +1375,7 @@ class PodsAdmin {
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 )
@@ -1055,7 +1392,15 @@ class PodsAdmin {
1055
  'help' => __( 'help', 'pods' ),
1056
  'type' => 'boolean',
1057
  'default' => true,
 
1058
  'boolean_yes_label' => ''
 
 
 
 
 
 
 
1059
  )
1060
  );
1061
 
@@ -1240,11 +1585,11 @@ class PodsAdmin {
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
  ),
@@ -1284,18 +1629,31 @@ class PodsAdmin {
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' ) ) {
@@ -1459,10 +1817,10 @@ class PodsAdmin {
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
  ),
@@ -1707,6 +2065,19 @@ class PodsAdmin {
1707
  }
1708
 
1709
  $options[ 'additional-field' ][ $type ] = PodsForm::ui_options( $type );
 
 
 
 
 
 
 
 
 
 
 
 
 
1710
  }
1711
 
1712
  $input_helpers = array(
@@ -2069,11 +2440,11 @@ class PodsAdmin {
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' ] ) )
@@ -2115,8 +2486,8 @@ class PodsAdmin {
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(
@@ -2649,32 +3020,33 @@ class PodsAdmin {
2649
 
2650
  }
2651
 
2652
- /**
2653
- * Check if Pod type <em>could</em> extend core REST API response
2654
- *
2655
- * @since 2.5.6
2656
- *
2657
- * @access protected
2658
- *
2659
- * @param array $pod
2660
- *
2661
- * @return bool
2662
- */
2663
- protected function restable_pod( $pod ) {
2664
- $type = $pod[ 'type' ];
2665
- if( in_array( $type, array(
2666
- 'post_type',
2667
- 'user',
2668
- 'taxonomy'
2669
- )
2670
- )
2671
- ) {
2672
- return true;
2673
 
2674
- }
2675
 
2676
- }
 
 
 
 
 
2677
 
 
 
 
 
 
2678
 
2679
  /**
2680
  * Add a rest api tab.
@@ -2708,8 +3080,8 @@ class PodsAdmin {
2708
  if ( ! function_exists( 'register_rest_field' ) ) {
2709
  $options[ 'rest-api' ] = array(
2710
  'no_dependencies' => array(
2711
- 'label' => __( sprintf( 'Pods REST API support requires WordPress 4.3.1 or later and the %s or later.', '<a href="http://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank">WordPress REST API 2.0-beta9</a>' ), 'pods' ),
2712
- 'help' => __( sprintf( 'See %s for more information.', '<a href="http://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank">http://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/</a>'), 'pods' ),
2713
  'type' => 'html',
2714
  ),
2715
  );
@@ -2723,23 +3095,21 @@ class PodsAdmin {
2723
  'dependency' => true,
2724
  ),
2725
  'rest_base' => array(
2726
- 'label' => __( 'REST Base', 'pods' ),
2727
- 'help' => __( 'This will form the url for the route.', 'pods' ),
2728
  'type' => 'text',
2729
- 'default' => pods_v( 'name', $pod ),
2730
- 'boolean_yes_label' => '',
2731
  'depends-on' => array( 'rest_enable' => true ),
2732
  ),
2733
  'read_all' => array(
2734
- 'label' => __( 'Show All Fields?', 'pods' ),
2735
  'help' => __( 'Show all fields in REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ),
2736
  'type' => 'boolean',
2737
  'default' => '',
2738
- 'boolean_yes_label' => '',
2739
  'depends-on' => array( 'rest_enable' => true ),
2740
  ),
2741
  'write_all' => array(
2742
- 'label' => __( 'Allow All Fields To Be Updated?', 'pods' ),
2743
  'help' => __( 'Allow all fields to be updated via the REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ),
2744
  'type' => 'boolean',
2745
  'default' => pods_v( 'name', $pod ),
@@ -2753,7 +3123,7 @@ class PodsAdmin {
2753
  $options[ 'rest-api' ] = array(
2754
  'not_restable' => array(
2755
  'label' => __( 'Pods REST API support covers post type, taxonomy and user Pods.', 'pods' ),
2756
- 'help' => __( sprintf( 'See %s for more information.', '<a href="http://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank">http://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/"</a>'), 'pods' ),
2757
  'type' => 'html',
2758
  ),
2759
  );
100
  * @since 2.0
101
  */
102
  public function admin_head () {
 
 
 
 
103
  wp_register_script( 'pods-floatmenu', PODS_URL . 'ui/js/floatmenu.js', array(), PODS_VERSION );
104
 
105
  wp_register_script( 'pods-admin-importer', PODS_URL . 'ui/js/admin-importer.js', array(), PODS_VERSION );
106
 
 
 
 
 
107
  wp_register_script( 'pods-upgrade', PODS_URL . 'ui/js/jquery.pods.upgrade.js', array(), PODS_VERSION );
108
 
109
  wp_register_script( 'pods-migrate', PODS_URL . 'ui/js/jquery.pods.migrate.js', array(), PODS_VERSION );
120
  wp_enqueue_script( 'jquery-ui-core' );
121
  wp_enqueue_script( 'jquery-ui-sortable' );
122
 
 
 
123
  wp_enqueue_script( 'pods-floatmenu' );
124
 
 
125
  wp_enqueue_script( 'jquery-qtip2' );
126
  wp_enqueue_script( 'pods-qtip-init' );
127
 
131
  wp_enqueue_script( 'post' );
132
  elseif ( 0 === strpos( $page, 'pods-settings-' ) ) {
133
  wp_enqueue_script( 'post' );
 
134
  }
 
 
135
 
136
  if ( 'pods-advanced' == $page ) {
137
+ wp_register_script( 'pods-advanced', PODS_URL . 'ui/js/advanced.js', array(), PODS_VERSION );
 
 
138
  wp_enqueue_script( 'jquery-ui-effects-core', PODS_URL . 'ui/js/jquery-ui/jquery.effects.core.js', array( 'jquery' ), '1.8.8' );
139
  wp_enqueue_script( 'jquery-ui-effects-fade', PODS_URL . 'ui/js/jquery-ui/jquery.effects.fade.js', array( 'jquery' ), '1.8.8' );
140
  wp_enqueue_script( 'jquery-ui-dialog' );
 
 
141
  wp_enqueue_script( 'pods-advanced' );
142
+ } elseif ( 'pods-packages' == $page ) {
 
143
  wp_enqueue_style( 'pods-wizard' );
144
+ } 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' ) ) ) ) {
145
  wp_enqueue_style( 'pods-wizard' );
146
 
147
+ if ( 'pods-upgrade' == $page ) {
148
  wp_enqueue_script( 'pods-upgrade' );
149
+ }
150
  }
151
  }
152
  }
153
 
154
+ // New Styles Enqueue
155
+ wp_enqueue_style( 'pods-styles' );
156
  }
157
 
158
  /**
181
  elseif ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ], 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) )
182
  continue;
183
 
184
+ $pod = apply_filters( 'pods_advanced_content_type_pod_data_' . $pod['name'], $pod, $pod['name'] );
185
+ $pod = apply_filters( 'pods_advanced_content_type_pod_data', $pod, $pod['name'] );
186
+
187
  if ( 1 == pods_var( 'show_in_menu', $pod[ 'options' ], 0 ) ) {
188
+ $page_title = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), true );
189
  $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
190
 
191
+ $menu_label = pods_v( 'menu_name', $pod[ 'options' ], $page_title, true );
192
  $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
193
 
194
+ $singular_label = pods_v( 'label_singular', $pod[ 'options' ], pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), true ), true );
195
+ $plural_label = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), true );
196
 
197
  $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'objects' );
198
  $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
199
 
200
+ $menu_position = pods_v( 'menu_position', $pod[ 'options' ], '', true );
201
+ $menu_icon = pods_evaluate_tags( pods_v( 'menu_icon', $pod[ 'options' ], '', true ), true );
202
 
203
  if ( empty( $menu_position ) )
204
  $menu_position = null;
224
  add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
225
 
226
  $all_title = $plural_label;
227
+ $all_label = pods_v( 'label_all_items', $pod[ 'options' ], __( 'All', 'pods' ) . ' ' . $plural_label );
228
 
229
  if ( $page == pods_var( 'page', 'get' ) ) {
230
  if ( 'edit' == pods_var( 'action', 'get', 'manage' ) )
231
+ $all_title = pods_v( 'label_edit_item', $pod[ 'options' ], __( 'Edit', 'pods' ) . ' ' . $singular_label );
232
  elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) )
233
+ $all_title = pods_v( 'label_add_new_item', $pod[ 'options' ], __( 'Add New', 'pods' ) . ' ' . $singular_label );
234
  }
235
 
236
  add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) );
250
  add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
251
  }
252
 
253
+ $add_title = pods_v( 'label_add_new_item', $pod[ 'options' ], __( 'Add New', 'pods' ) . ' ' . $singular_label );
254
+ $add_label = pods_v( 'label_add_new', $pod[ 'options' ], __( 'Add New', 'pods' ) );
255
 
256
  add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) );
257
  }
622
  $_GET[ 'action' ] = 'edit';
623
 
624
  $page_title = pods_var_raw( 'label', $pod->pod_data, ucwords( str_replace( '_', ' ', $pod->pod_data[ 'name' ] ) ), null, true );
625
+ $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod->pod_data );
626
 
627
  $ui = array(
628
  'pod' => $pod,
697
  */
698
  public function register_media_assets () {
699
  if ( 'pods_media_attachment' == pods_var( 'inlineId', 'get' ) )
700
+ wp_enqueue_style( 'pods-styles' );
701
  }
702
 
703
  /**
972
  public function admin_setup_edit_options ( $pod ) {
973
  $options = array();
974
 
975
+ if ( strlen( pods_v_sanitized( 'object', $pod ) ) < 1 && 'settings' != pods_v_sanitized( 'type', $pod ) ) {
976
+
977
+ $labels = array(
978
+ 'label' => array(
979
+ 'label' => __( 'Label', 'pods' ),
980
+ 'help' =>__( 'help', 'pods' ),
981
+ 'type' => 'text',
982
+ 'default' => str_replace( '_', ' ', pods_v( 'name', $pod ) ),
983
+ 'text_max_length' => 30
984
+ ),
985
+ 'label_singular' => array(
986
+ 'label' => __( 'Singular Label', 'pods' ),
987
+ 'help' =>__( 'help', 'pods' ),
988
+ 'type' => 'text',
989
+ 'default' => pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', pods_v( 'name', $pod ) ) ) ),
990
+ 'text_max_length' => 30
991
+ ),
992
+ 'label_add_new' => array(
993
+ 'label' => __( 'Add New', 'pods' ),
994
+ 'help' =>__( 'help', 'pods' ),
995
+ 'type' => 'text',
996
+ 'default' => '',
997
+ 'object_type' => array( 'post_type', 'pod' )
998
+ ),
999
+ 'label_add_new_item' => array(
1000
+ 'label' => __( 'Add new <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1001
+ 'help' =>__( 'help', 'pods' ),
1002
+ 'type' => 'text',
1003
+ 'default' => '',
1004
+ ),
1005
+ 'label_new_item' => array(
1006
+ 'label' => __( 'New <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1007
+ 'help' =>__( 'help', 'pods' ),
1008
+ 'type' => 'text',
1009
+ 'default' => '',
1010
+ 'object_type' => array( 'post_type', 'pod' )
1011
+ ),
1012
+ 'label_new_item_name' => array(
1013
+ 'label' => __( 'New <span class="pods-slugged" data-sluggable="label_singular">Item</span> Name', 'pods' ),
1014
+ 'help' =>__( 'help', 'pods' ),
1015
+ 'type' => 'text',
1016
+ 'default' => '',
1017
+ 'object_type' => array( 'taxonomy' )
1018
+ ),
1019
+ 'label_edit' => array(
1020
+ 'label' => __( 'Edit', 'pods' ),
1021
+ 'help' =>__( 'help', 'pods' ),
1022
+ 'type' => 'text',
1023
+ 'default' => '',
1024
+ 'object_type' => array( 'pod' )
1025
+ ),
1026
+ 'label_edit_item' => array(
1027
+ 'label' => __( 'Edit <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1028
+ 'help' =>__( 'help', 'pods' ),
1029
+ 'type' => 'text',
1030
+ 'default' => '',
1031
+ ),
1032
+ 'label_update_item' => array(
1033
+ 'label' => __( 'Update <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1034
+ 'help' =>__( 'help', 'pods' ),
1035
+ 'type' => 'text',
1036
+ 'default' => '',
1037
+ 'object_type' => array( 'taxonomy', 'pod' )
1038
+ ),
1039
+ 'label_duplicate' => array(
1040
+ 'label' => __( 'Duplicate', 'pods' ),
1041
+ 'help' =>__( 'help', 'pods' ),
1042
+ 'type' => 'text',
1043
+ 'default' => '',
1044
+ 'object_type' => array( 'pod' )
1045
+ ),
1046
+ 'label_duplicate_item' => array(
1047
+ 'label' => __( 'Duplicate <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1048
+ 'help' =>__( 'help', 'pods' ),
1049
+ 'type' => 'text',
1050
+ 'default' => '',
1051
+ 'object_type' => array( 'pod' )
1052
+ ),
1053
+ 'label_delete_item' => array(
1054
+ 'label' => __( 'Delete <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1055
+ 'help' =>__( 'help', 'pods' ),
1056
+ 'type' => 'text',
1057
+ 'default' => '',
1058
+ 'object_type' => array( 'pod' )
1059
+ ),
1060
+ 'label_view' => array(
1061
+ 'label' => __( 'View', 'pods' ),
1062
+ 'help' =>__( 'help', 'pods' ),
1063
+ 'type' => 'text',
1064
+ 'default' => '',
1065
+ 'object_type' => array( 'pod' )
1066
+ ),
1067
+ 'label_view_item' => array(
1068
+ 'label' => __( 'View <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1069
+ 'help' =>__( 'help', 'pods' ),
1070
+ 'type' => 'text',
1071
+ 'default' => '',
1072
+ ),
1073
+ 'label_view_items' => array(
1074
+ 'label' => __( 'View <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1075
+ 'help' =>__( 'help', 'pods' ),
1076
+ 'type' => 'text',
1077
+ 'default' => '',
1078
+ 'object_type' => array( 'post_type' )
1079
+ ),
1080
+ 'label_back_to_manage' => array(
1081
+ 'label' => __( 'Back to Manage', 'pods' ),
1082
+ 'help' =>__( 'help', 'pods' ),
1083
+ 'type' => 'text',
1084
+ 'default' => '',
1085
+ 'object_type' => array( 'pod' )
1086
+ ),
1087
+ 'label_manage' => array(
1088
+ 'label' => __( 'Manage', 'pods' ),
1089
+ 'help' =>__( 'help', 'pods' ),
1090
+ 'type' => 'text',
1091
+ 'default' => '',
1092
+ 'object_type' => array( 'pod' )
1093
+ ),
1094
+ 'label_manage_items' => array(
1095
+ 'label' => __( 'Manage <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1096
+ 'help' =>__( 'help', 'pods' ),
1097
+ 'type' => 'text',
1098
+ 'default' => '',
1099
+ 'object_type' => array( 'pod' )
1100
+ ),
1101
+ 'label_reorder' => array(
1102
+ 'label' => __( 'Reorder', 'pods' ),
1103
+ 'help' =>__( 'help', 'pods' ),
1104
+ 'type' => 'text',
1105
+ 'default' => '',
1106
+ 'object_type' => array( 'pod' )
1107
+ ),
1108
+ 'label_reorder_items' => array(
1109
+ 'label' => __( 'Reorder <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1110
+ 'help' =>__( 'help', 'pods' ),
1111
+ 'type' => 'text',
1112
+ 'default' => '',
1113
+ 'object_type' => array( 'pod' )
1114
+ ),
1115
+ 'label_all_items' => array(
1116
+ 'label' => __( 'All <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1117
+ 'help' =>__( 'help', 'pods' ),
1118
+ 'type' => 'text',
1119
+ 'default' => '',
1120
+ ),
1121
+ 'label_search' => array(
1122
+ 'label' => __( 'Search', 'pods' ),
1123
+ 'help' =>__( 'help', 'pods' ),
1124
+ 'type' => 'text',
1125
+ 'default' => '',
1126
+ 'object_type' => array( 'pod' )
1127
+ ),
1128
+ 'label_search_items' => array(
1129
+ 'label' => __( 'Search <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1130
+ 'help' =>__( 'help', 'pods' ),
1131
+ 'type' => 'text',
1132
+ 'default' => '',
1133
+ ),
1134
+ 'label_popular_items' => array(
1135
+ 'label' => __( 'Popular <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
1136
+ 'help' =>__( 'help', 'pods' ),
1137
+ 'type' => 'text',
1138
+ 'default' => '',
1139
+ 'object_type' => array( 'taxonomy' )
1140
+ ),
1141
+ // @todo Why was label_parent added previously? Can't find it in WP
1142
+ 'label_parent' => array(
1143
+ 'label' => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1144
+ 'help' =>__( 'help', 'pods' ),
1145
+ 'type' => 'text',
1146
+ 'default' => '',
1147
+ 'object_type' => array( 'post_type', 'pod' )
1148
+ ),
1149
+ 'label_parent_item' => array(
1150
+ 'label' => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1151
+ 'help' =>__( 'help', 'pods' ),
1152
+ 'type' => 'text',
1153
+ 'default' => '',
1154
+ 'object_type' => array( 'taxonomy' )
1155
+ ),
1156
+ 'label_parent_item_colon' => array(
1157
+ 'label' => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>:', 'pods' ),
1158
+ 'help' =>__( 'help', 'pods' ),
1159
+ 'type' => 'text',
1160
+ 'default' => '',
1161
+ ),
1162
+ 'label_not_found' => array(
1163
+ 'label' => __( 'Not Found', 'pods' ),
1164
+ 'help' =>__( 'help', 'pods' ),
1165
+ 'type' => 'text',
1166
+ 'default' => '',
1167
+ ),
1168
+ 'label_no_items_found' => array(
1169
+ 'label' => __( 'No <span class="pods-slugged" data-sluggable="label_singular">Item</span> Found', 'pods' ),
1170
+ 'help' =>__( 'help', 'pods' ),
1171
+ 'type' => 'text',
1172
+ 'default' => '',
1173
+ 'object_type' => array( 'pod' )
1174
+ ),
1175
+ 'label_not_found_in_trash' => array(
1176
+ 'label' => __( 'Not Found in Trash', 'pods' ),
1177
+ 'help' =>__( 'help', 'pods' ),
1178
+ 'type' => 'text',
1179
+ 'default' => '',
1180
+ 'object_type' => array( 'post_type', 'pod' )
1181
+ ),
1182
+ 'label_archives' => array(
1183
+ 'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Archives', 'pods' ),
1184
+ 'help' =>__( 'help', 'pods' ),
1185
+ 'type' => 'text',
1186
+ 'default' => '',
1187
+ 'object_type' => array( 'post_type' )
1188
+ ),
1189
+ 'label_attributes' => array(
1190
+ 'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Attributes', 'pods' ),
1191
+ 'help' =>__( 'help', 'pods' ),
1192
+ 'type' => 'text',
1193
+ 'default' => '',
1194
+ 'object_type' => array( 'post_type' )
1195
+ ),
1196
+ 'label_insert_into_item' => array(
1197
+ 'label' => __( 'Insert into <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1198
+ 'help' =>__( 'help', 'pods' ),
1199
+ 'type' => 'text',
1200
+ 'default' => '',
1201
+ 'object_type' => array( 'post_type' )
1202
+ ),
1203
+ 'label_uploaded_to_this_item' => array(
1204
+ 'label' => __( 'Uploaded to this <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
1205
+ 'help' =>__( 'help', 'pods' ),
1206
+ 'type' => 'text',
1207
+ 'default' => '',
1208
+ 'object_type' => array( 'post_type' )
1209
+ ),
1210
+ 'label_featured_image' => array(
1211
+ 'label' => __( 'Featured Image', 'pods' ),
1212
+ 'help' =>__( 'help', 'pods' ),
1213
+ 'type' => 'text',
1214
+ 'default' => '',
1215
+ //'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
1216
+ 'object_type' => array( 'post_type' )
1217
+ ),
1218
+ 'label_set_featured_image' => array(
1219
+ 'label' => __( 'Set featured Image', 'pods' ),
1220
+ 'help' =>__( 'help', 'pods' ),
1221
+ 'type' => 'text',
1222
+ 'default' => '',
1223
+ //'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
1224
+ 'object_type' => array( 'post_type' )
1225
+ ),
1226
+ 'label_remove_featured_image' => array(
1227
+ 'label' => __( 'Remove featured Image', 'pods' ),
1228
+ 'help' =>__( 'help', 'pods' ),
1229
+ 'type' => 'text',
1230
+ 'default' => '',
1231
+ //'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
1232
+ 'object_type' => array( 'post_type' )
1233
+ ),
1234
+ 'label_use_featured_image' => array(
1235
+ 'label' => __( 'Use as featured Image', 'pods' ),
1236
+ 'help' =>__( 'help', 'pods' ),
1237
+ 'type' => 'text',
1238
+ 'default' => '',
1239
+ //'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
1240
+ 'object_type' => array( 'post_type' )
1241
+ ),
1242
+ 'label_filter_items_list' => array(
1243
+ 'label' => __( 'Filter <span class="pods-slugged" data-sluggable="label">Items</span> lists', 'pods' ),
1244
+ 'help' =>__( 'help', 'pods' ),
1245
+ 'type' => 'text',
1246
+ 'default' => '',
1247
+ 'object_type' => array( 'post_type' )
1248
+ ),
1249
+ 'label_items_list_navigation' => array(
1250
+ 'label' => __( '<span class="pods-slugged" data-sluggable="label">Items</span> list navigation', 'pods' ),
1251
+ 'help' =>__( 'help', 'pods' ),
1252
+ 'type' => 'text',
1253
+ 'default' => '',
1254
+ 'object_type' => array( 'post_type', 'taxonomy' )
1255
+ ),
1256
+ 'label_items_list' => array(
1257
+ 'label' => __( '<span class="pods-slugged" data-sluggable="label">Items</span> list', 'pods' ),
1258
+ 'help' =>__( 'help', 'pods' ),
1259
+ 'type' => 'text',
1260
+ 'default' => '',
1261
+ 'object_type' => array( 'post_type', 'taxonomy' )
1262
+ ),
1263
+ 'label_separate_items_with_commas' => array(
1264
+ 'label' => __( 'Separate <span class="pods-slugged-lower" data-sluggable="label">items</span> with commas', 'pods' ),
1265
+ 'help' =>__( 'help', 'pods' ),
1266
+ 'type' => 'text',
1267
+ 'default' => '',
1268
+ 'object_type' => array( 'taxonomy' )
1269
+ ),
1270
+ 'label_add_or_remove_items' => array(
1271
+ 'label' => __( 'Add or remove <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ),
1272
+ 'help' =>__( 'help', 'pods' ),
1273
+ 'type' => 'text',
1274
+ 'default' => '',
1275
+ 'object_type' => array( 'taxonomy' )
1276
+ ),
1277
+ 'label_choose_from_the_most_used' => array(
1278
+ 'label' => __( 'Choose from the most used <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ),
1279
+ 'help' =>__( 'help', 'pods' ),
1280
+ 'type' => 'text',
1281
+ 'default' => '',
1282
+ 'object_type' => array( 'taxonomy' )
1283
+ ),
1284
+ 'label_no_terms' => array(
1285
+ 'label' => __( 'No <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ),
1286
+ 'help' =>__( 'help', 'pods' ),
1287
+ 'type' => 'text',
1288
+ 'default' => '',
1289
+ 'object_type' => array( 'taxonomy' )
1290
+ ),
1291
+ );
1292
+
1293
+ $options[ 'labels' ] = array();
1294
+
1295
+ /**
1296
+ * Filter through all labels if they have an object_type set and match it against the current object type
1297
+ */
1298
+ foreach ( $labels as $label => $labeldata ) {
1299
+ if ( array_key_exists( 'object_type', $labeldata ) ) {
1300
+ if ( in_array( pods_v_sanitized( 'type', $pod ), $labeldata[ 'object_type' ] ) ) {
1301
+ // Do not add the object_type to the actual label data
1302
+ unset( $labeldata[ 'object_type' ] );
1303
+ $options[ 'labels' ][ $label ] = $labeldata;
1304
+ }
1305
+ } else {
1306
+ $options[ 'labels' ][ $label ] = $labeldata;
1307
+ }
1308
+ }
1309
+
1310
+ } elseif ( 'settings' == pods_v_sanitized( 'type', $pod ) ) {
1311
+
1312
+ $options[ 'labels' ] = array(
1313
+ 'label' => array(
1314
+ 'label' => __( 'Page Title', 'pods' ),
1315
+ 'help' =>__( 'help', 'pods' ),
1316
+ 'type' => 'text',
1317
+ 'default' => str_replace( '_', ' ', pods_v( 'name', $pod ) ),
1318
+ 'text_max_length' => 30
1319
+ ),
1320
+ 'menu_name' => array(
1321
+ 'label' => __( 'Menu Name', 'pods' ),
1322
+ 'help' =>__( 'help', 'pods' ),
1323
+ 'type' => 'text',
1324
+ 'default' => pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', pods_v( 'name', $pod ) ) ) ),
1325
+ 'text_max_length' => 30
1326
+ ),
1327
+ );
1328
+ }
1329
 
1330
  if ( 'post_type' == $pod[ 'type' ] ) {
1331
  $options[ 'admin-ui' ] = array(
1375
  ),
1376
  'menu_icon' => array(
1377
  'label' => __( 'Menu Icon', 'pods' ),
1378
+ '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">site tag</a> type <a href="https://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' ),
1379
  'type' => 'text',
1380
  'default' => '',
1381
  'depends-on' => array( 'show_in_menu' => true )
1392
  'help' => __( 'help', 'pods' ),
1393
  'type' => 'boolean',
1394
  'default' => true,
1395
+ 'dependency' => true,
1396
  'boolean_yes_label' => ''
1397
+ ),
1398
+ 'name_admin_bar' => array(
1399
+ 'label' => __( 'Admin bar name', 'pods' ),
1400
+ 'help' =>__( 'Defaults to singular name', 'pods' ),
1401
+ 'type' => 'text',
1402
+ 'default' => '',
1403
+ 'depends-on' => array( 'show_in_admin_bar' => true )
1404
  )
1405
  );
1406
 
1585
  'depends-on' => array( 'show_ui' => true ),
1586
  'data' => array(
1587
  'default' => __( 'Default - Add to associated Post Type(s) menus', 'pods' ),
1588
+ 'settings' => __( 'Add a submenu item to Settings menu', 'pods' ),
1589
+ 'appearances' => __( 'Add a submenu item to Appearances menu', 'pods' ),
1590
+ 'submenu' => __( 'Add a submenu item to another menu', 'pods' ),
1591
+ 'objects' => __( 'Make a new menu item', 'pods' ),
1592
+ 'top' => __( 'Make a new menu item below Settings', 'pods' )
1593
  ),
1594
  'dependency' => true
1595
  ),
1629
  'type' => 'boolean',
1630
  'default' => pods_var_raw( 'show_ui', $pod, pods_var_raw( 'public', $pod, true ) ),
1631
  'boolean_yes_label' => ''
1632
+ ),
1633
+ // @todo check https://core.trac.wordpress.org/ticket/36964
1634
+ 'show_tagcloud_in_edit' => array(
1635
+ 'label' => __( 'Allow Tagcloud on term edit pages', 'pods' ),
1636
+ 'help' => __( 'help', 'pods' ),
1637
+ 'type' => 'boolean',
1638
+ 'default' => pods_var_raw( 'show_ui', $pod, pods_var_raw( 'show_tagcloud', $pod, true ) ),
1639
+ 'boolean_yes_label' => ''
1640
+ ),
1641
+ 'show_in_quick_edit' => array(
1642
+ 'label' => __( 'Allow in quick/bulk edit panel', 'pods' ),
1643
+ 'help' => __( 'help', 'pods' ),
1644
+ 'type' => 'boolean',
1645
+ 'default' => pods_var_raw( 'show_ui', $pod, pods_var_raw( 'public', $pod, true ) ),
1646
+ 'boolean_yes_label' => ''
1647
  )
1648
  );
1649
 
1650
+ $options[ 'admin-ui' ][ 'show_admin_column' ] = array(
1651
+ 'label' => __( 'Show Taxonomy column on Post Types', 'pods' ),
1652
+ 'help' => __( 'Whether to add a column for this taxonomy on the associated post types manage screens', 'pods' ),
1653
+ 'type' => 'boolean',
1654
+ 'default' => false,
1655
+ 'boolean_yes_label' => ''
1656
+ );
 
 
1657
 
1658
  // Integration for Single Value Taxonomy UI
1659
  if ( function_exists( 'tax_single_value_meta_box' ) ) {
1817
  'type' => 'pick',
1818
  'default' => 'settings',
1819
  'data' => array(
1820
+ 'settings' => __( 'Add a submenu item to Settings menu', 'pods' ),
1821
+ 'appearances' => __( 'Add a submenu item to Appearances menu', 'pods' ),
1822
+ 'submenu' => __( 'Add a submenu item to another menu', 'pods' ),
1823
+ 'top' => __( 'Make a new menu item below Settings', 'pods' )
1824
  ),
1825
  'dependency' => true
1826
  ),
2065
  }
2066
 
2067
  $options[ 'additional-field' ][ $type ] = PodsForm::ui_options( $type );
2068
+
2069
+ /**
2070
+ * Modify Additional Field Options tab
2071
+ *
2072
+ * @since 2.7
2073
+ *
2074
+ * @param array $options Additional field type options
2075
+ * @param string $type Field type
2076
+ * @param array $options Tabs, indexed by label
2077
+ * @param object|Pods Pods object for the Pod this UI is for.
2078
+ */
2079
+ $options[ 'additional-field' ][ $type ] = apply_filters( 'pods_admin_setup_edit_' . $type . '_additional_field_options', $options[ 'additional-field' ][ $type ], $type, $options, $pod );
2080
+ $options[ 'additional-field' ][ $type ] = apply_filters( 'pods_admin_setup_edit_additional_field_options', $options[ 'additional-field' ][ $type ], $type, $options, $pod );
2081
  }
2082
 
2083
  $input_helpers = array(
2440
  $meta = array();
2441
 
2442
  if ( !empty( $component_data[ 'Version' ] ) )
2443
+ $meta[] = sprintf( __( 'Version %s', 'pods' ), $component_data[ 'Version' ] );
2444
 
2445
  if ( empty( $component_data[ 'Author' ] ) ) {
2446
  $component_data[ 'Author' ] = 'Pods Framework Team';
2447
+ $component_data[ 'AuthorURI' ] = 'https://pods.io/';
2448
  }
2449
 
2450
  if ( !empty( $component_data[ 'AuthorURI' ] ) )
2486
  'data' => $components,
2487
  'total' => count( $components ),
2488
  'total_found' => count( $components ),
2489
+ 'items' => __( 'Components', 'pods' ),
2490
+ 'item' => __( 'Component', 'pods' ),
2491
  'fields' => array(
2492
  'manage' => array(
2493
  'name' => array(
3020
 
3021
  }
3022
 
3023
+ /**
3024
+ * Check if Pod type <em>could</em> extend core REST API response
3025
+ *
3026
+ * @since 2.5.6
3027
+ *
3028
+ * @access protected
3029
+ *
3030
+ * @param array $pod
3031
+ *
3032
+ * @return bool
3033
+ */
3034
+ protected function restable_pod( $pod ) {
 
 
 
 
 
 
 
 
 
3035
 
3036
+ $type = $pod['type'];
3037
 
3038
+ $restable_types = array(
3039
+ 'post_type',
3040
+ 'user',
3041
+ 'taxonomy',
3042
+ 'media',
3043
+ );
3044
 
3045
+ if ( in_array( $type, $restable_types, true ) ) {
3046
+ return true;
3047
+ }
3048
+
3049
+ }
3050
 
3051
  /**
3052
  * Add a rest api tab.
3080
  if ( ! function_exists( 'register_rest_field' ) ) {
3081
  $options[ 'rest-api' ] = array(
3082
  'no_dependencies' => array(
3083
+ 'label' => __( sprintf( 'Pods REST API support requires WordPress 4.3.1 or later and the %s or later.', '<a href="https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank">WordPress REST API 2.0-beta9</a>' ), 'pods' ),
3084
+ 'help' => __( sprintf( 'See %s for more information.', '<a href="https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank">https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/</a>'), 'pods' ),
3085
  'type' => 'html',
3086
  ),
3087
  );
3095
  'dependency' => true,
3096
  ),
3097
  'rest_base' => array(
3098
+ 'label' => __( 'REST Base (if any)', 'pods' ),
3099
+ 'help' => __( 'This will form the url for the route. Default / empty value here will use the pod name.', 'pods' ),
3100
  'type' => 'text',
3101
+ 'default' => '',
 
3102
  'depends-on' => array( 'rest_enable' => true ),
3103
  ),
3104
  'read_all' => array(
3105
+ 'label' => __( 'Show All Fields (read-only)', 'pods' ),
3106
  'help' => __( 'Show all fields in REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ),
3107
  'type' => 'boolean',
3108
  'default' => '',
 
3109
  'depends-on' => array( 'rest_enable' => true ),
3110
  ),
3111
  'write_all' => array(
3112
+ 'label' => __( 'Allow All Fields To Be Updated', 'pods' ),
3113
  'help' => __( 'Allow all fields to be updated via the REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ),
3114
  'type' => 'boolean',
3115
  'default' => pods_v( 'name', $pod ),
3123
  $options[ 'rest-api' ] = array(
3124
  'not_restable' => array(
3125
  'label' => __( 'Pods REST API support covers post type, taxonomy and user Pods.', 'pods' ),
3126
+ 'help' => __( sprintf( 'See %s for more information.', '<a href="https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank">https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/"</a>'), 'pods' ),
3127
  'type' => 'html',
3128
  ),
3129
  );
classes/PodsData.php CHANGED
@@ -631,7 +631,15 @@ class PodsData {
631
 
632
  $cache_key = $results = false;
633
 
634
- $params = apply_filters( 'pods_data_pre_select_params', $params );
 
 
 
 
 
 
 
 
635
 
636
  // Debug purposes
637
  if ( 1 == pods_v( 'pods_debug_params', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
@@ -666,6 +674,15 @@ class PodsData {
666
  pods_view_set( $cache_key, $results, pods_v( 'expires', $params, 0, false ), pods_v( 'cache_mode', $params, 'cache', true ), 'pods_data_select' );
667
  }
668
 
 
 
 
 
 
 
 
 
 
669
  $results = apply_filters( 'pods_data_select', $results, $params, $this );
670
 
671
  $this->data = $results;
@@ -738,6 +755,7 @@ class PodsData {
738
  'table' => null,
739
  'join' => null,
740
  'where' => null,
 
741
  'groupby' => null,
742
  'having' => null,
743
  'orderby' => null,
@@ -849,12 +867,15 @@ class PodsData {
849
  $params->join = $this->join;
850
 
851
  $params->where_defaulted = false;
852
- $params->where_default = $this->where_default;
 
 
 
853
 
854
  if ( false === $params->strict ) {
855
  // Set default where
856
- if ( !empty( $this->where_default ) && empty( $params->where ) ) {
857
- $params->where = array_values( (array) $this->where_default );
858
 
859
  $params->where_defaulted = true;
860
  }
@@ -2532,10 +2553,10 @@ class PodsData {
2532
  }
2533
  }
2534
 
2535
- // Single array handling
2536
- if ( 1 == count( $field_value ) && $field_compare == 'ALL' ) {
2537
- $field_compare = '=';
2538
- }
2539
  // Empty array handling
2540
  elseif ( empty( $field_value ) && in_array( $field_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
2541
  $field_compare = 'EXISTS';
@@ -2803,9 +2824,7 @@ class PodsData {
2803
 
2804
  $traverse = $pod_data[ 'fields' ][ $field ];
2805
 
2806
- if ( 'taxonomy' == $traverse[ 'type' ] )
2807
- $traverse[ 'table_info' ] = $this->api->get_table_info( $traverse[ 'type' ], $traverse[ 'name' ] );
2808
- elseif ( in_array( $traverse[ 'type' ], $file_field_types ) )
2809
  $traverse[ 'table_info' ] = $this->api->get_table_info( 'post_type', 'attachment' );
2810
  elseif ( !in_array( $traverse[ 'type' ], $tableless_field_types ) )
2811
  $traverse[ 'table_info' ] = $this->api->get_table_info( $pod_data[ 'type' ], $pod_data[ 'name' ], $pod_data[ 'name' ], $pod_data );
@@ -2922,8 +2941,39 @@ class PodsData {
2922
  $joined_id = $table_info[ 'field_id' ];
2923
  $joined_index = $table_info[ 'field_index' ];
2924
  }
2925
- }
2926
- elseif ( in_array( $traverse[ 'type' ], $tableless_field_types ) && ( 'pick' != $traverse[ 'type' ] || !in_array( pods_v( 'pick_object', $traverse ), $simple_tableless_objects ) ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2927
  if ( pods_tableless() ) {
2928
  $the_join = "
2929
  LEFT JOIN `{$table_info[ 'meta_table' ]}` AS `{$rel_alias}` ON
@@ -2968,8 +3018,7 @@ class PodsData {
2968
  `{$field_joined}`.`{$table_info[ 'field_id' ]}` = `{$rel_alias}`.`related_item_id`
2969
  ";
2970
  }
2971
- }
2972
- elseif ( 'meta' == $pod_data[ 'storage' ] ) {
2973
  if (
2974
  ( $traverse_recurse[ 'depth' ] + 2 ) == count( $traverse_recurse[ 'fields' ] )
2975
  && ( 'pick' != $traverse[ 'type' ] || !in_array( pods_var( 'pick_object', $traverse ), $simple_tableless_objects ) )
@@ -3089,6 +3138,16 @@ class PodsData {
3089
  if ( empty( $sql ) )
3090
  $sql = $this->sql;
3091
 
 
 
 
 
 
 
 
 
 
 
3092
  $sql = str_replace( array( '@wp_users', '@wp_' ), array( $wpdb->users, $wpdb->prefix ), $sql );
3093
 
3094
  $sql = str_replace( '{prefix}', '@wp_', $sql );
631
 
632
  $cache_key = $results = false;
633
 
634
+ /**
635
+ * Filter select parameters before the query
636
+ *
637
+ * @param array|object $params
638
+ * @param PodsData|object $this The current PodsData class instance.
639
+ *
640
+ * @since unknown
641
+ */
642
+ $params = apply_filters( 'pods_data_pre_select_params', $params, $this );
643
 
644
  // Debug purposes
645
  if ( 1 == pods_v( 'pods_debug_params', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
674
  pods_view_set( $cache_key, $results, pods_v( 'expires', $params, 0, false ), pods_v( 'cache_mode', $params, 'cache', true ), 'pods_data_select' );
675
  }
676
 
677
+ /**
678
+ * Filter results of Pods Query
679
+ *
680
+ * @param array $results
681
+ * @param array|object $params
682
+ * @param PodsData|object $this The current PodsData class instance.
683
+ *
684
+ * @since unknown
685
+ */
686
  $results = apply_filters( 'pods_data_select', $results, $params, $this );
687
 
688
  $this->data = $results;
755
  'table' => null,
756
  'join' => null,
757
  'where' => null,
758
+ 'where_default' => null,
759
  'groupby' => null,
760
  'having' => null,
761
  'orderby' => null,
867
  $params->join = $this->join;
868
 
869
  $params->where_defaulted = false;
870
+
871
+ if ( empty( $params->where_default ) && false !== $params->where_default ) {
872
+ $params->where_default = $this->where_default;
873
+ }
874
 
875
  if ( false === $params->strict ) {
876
  // Set default where
877
+ if ( !empty( $params->where_default ) && empty( $params->where ) ) {
878
+ $params->where = array_values( (array) $params->where_default );
879
 
880
  $params->where_defaulted = true;
881
  }
2553
  }
2554
  }
2555
 
2556
+ // Single array handling
2557
+ if ( 1 == count( (array) $field_value ) && $field_compare == 'ALL' ) {
2558
+ $field_compare = '=';
2559
+ }
2560
  // Empty array handling
2561
  elseif ( empty( $field_value ) && in_array( $field_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
2562
  $field_compare = 'EXISTS';
2824
 
2825
  $traverse = $pod_data[ 'fields' ][ $field ];
2826
 
2827
+ if ( in_array( $traverse[ 'type' ], $file_field_types ) )
 
 
2828
  $traverse[ 'table_info' ] = $this->api->get_table_info( 'post_type', 'attachment' );
2829
  elseif ( !in_array( $traverse[ 'type' ], $tableless_field_types ) )
2830
  $traverse[ 'table_info' ] = $this->api->get_table_info( $pod_data[ 'type' ], $pod_data[ 'name' ], $pod_data[ 'name' ], $pod_data );
2941
  $joined_id = $table_info[ 'field_id' ];
2942
  $joined_index = $table_info[ 'field_index' ];
2943
  }
2944
+ } elseif ( 'comment' == $traverse[ 'type' ] ) {
2945
+ if ( pods_tableless() ) {
2946
+ $the_join = "
2947
+ LEFT JOIN `{$table_info[ 'meta_table' ]}` AS `{$rel_alias}` ON
2948
+ `{$rel_alias}`.`{$table_info[ 'meta_field_index' ]}` = '{$traverse[ 'name' ]}'
2949
+ AND `{$rel_alias}`.`{$table_info[ 'meta_field_id' ]}` = `{$traverse_recurse[ 'joined' ]}`.`{$traverse_recurse[ 'joined_id' ]}`
2950
+
2951
+ LEFT JOIN `{$table_info[ 'meta_table' ]}` AS `{$field_joined}` ON
2952
+ `{$field_joined}`.`{$table_info[ 'meta_field_index' ]}` = '{$traverse[ 'name' ]}'
2953
+ AND `{$field_joined}`.`{$table_info[ 'meta_field_id' ]}` = CONVERT( `{$rel_alias}`.`{$table_info[ 'meta_field_value' ]}`, SIGNED )
2954
+ ";
2955
+
2956
+ $joined_id = $table_info[ 'meta_field_id' ];
2957
+ $joined_index = $table_info[ 'meta_field_index' ];
2958
+ } elseif ( $meta_data_table ) {
2959
+ $the_join = "
2960
+ LEFT JOIN `{$table_info[ 'pod_table' ]}` AS `{$field_joined}` ON
2961
+ `{$field_joined}`.`{$table_info[ 'pod_field_id' ]}` = `{$traverse_recurse[ 'rel_alias' ]}`.`{$traverse_recurse[ 'joined_id' ]}`
2962
+ ";
2963
+ }
2964
+ else {
2965
+ $the_join = "
2966
+ LEFT JOIN `{$wpdb->comments}` AS `{$field_joined}` ON
2967
+ `{$field_joined}`.`comment_post_ID` = `{$traverse_recurse[ 'joined' ]}`.`ID`
2968
+ ";
2969
+
2970
+ // Override $rel_alias
2971
+ $rel_alias = $field_joined;
2972
+
2973
+ $joined_id = $table_info[ 'field_id' ];
2974
+ $joined_index = $table_info[ 'field_index' ];
2975
+ }
2976
+ } elseif ( in_array( $traverse[ 'type' ], $tableless_field_types ) && ( 'pick' != $traverse[ 'type' ] || !in_array( pods_v( 'pick_object', $traverse ), $simple_tableless_objects ) ) ) {
2977
  if ( pods_tableless() ) {
2978
  $the_join = "
2979
  LEFT JOIN `{$table_info[ 'meta_table' ]}` AS `{$rel_alias}` ON
3018
  `{$field_joined}`.`{$table_info[ 'field_id' ]}` = `{$rel_alias}`.`related_item_id`
3019
  ";
3020
  }
3021
+ } elseif ( 'meta' == $pod_data[ 'storage' ] ) {
 
3022
  if (
3023
  ( $traverse_recurse[ 'depth' ] + 2 ) == count( $traverse_recurse[ 'fields' ] )
3024
  && ( 'pick' != $traverse[ 'type' ] || !in_array( pods_var( 'pick_object', $traverse ), $simple_tableless_objects ) )
3138
  if ( empty( $sql ) )
3139
  $sql = $this->sql;
3140
 
3141
+ /**
3142
+ * Allow SQL query to be manipulated.
3143
+ *
3144
+ * @param string $sql SQL Query string
3145
+ * @param PodsData $pods_data PodsData object
3146
+ *
3147
+ * @since 2.7
3148
+ */
3149
+ $sql = apply_filters( 'pods_data_get_sql', $sql, $this );
3150
+
3151
  $sql = str_replace( array( '@wp_users', '@wp_' ), array( $wpdb->users, $wpdb->prefix ), $sql );
3152
 
3153
  $sql = str_replace( '{prefix}', '@wp_', $sql );
classes/PodsField.php CHANGED
@@ -1,78 +1,83 @@
1
  <?php
 
2
  /**
 
 
3
  * @package Pods
4
  */
5
  class PodsField {
6
 
7
- /**
8
- * Whether this field is running under 1.x deprecated forms
9
- *
10
- * @var bool
11
- * @since 2.0
12
- */
13
- public static $deprecated = false;
14
-
15
- /**
16
- * Field Type Identifier
17
- *
18
- * @var string
19
- * @since 2.0
20
- */
21
- public static $type = 'text';
22
-
23
- /**
24
- * Field Type Label
25
- *
26
- * @var string
27
- * @since 2.0
28
- */
29
- public static $label = 'Unknown';
30
-
31
- /**
32
- * Field Type Preparation
33
- *
34
- * @var string
35
- * @since 2.0
36
- */
37
- public static $prepare = '%s';
38
-
39
- /**
40
- * Pod Types supported on (true for all, false for none, or give array of specific types supported)
41
- *
42
- * @var array|bool
43
- * @since 2.1
44
- */
45
- public static $pod_types = true;
46
-
47
- /**
48
- * API caching for fields that need it during validate/save
49
- *
50
- * @var \PodsAPI
51
- * @since 2.3
52
- */
53
- private static $api = false;
54
-
55
- /**
56
- * Do things like register/enqueue scripts and stylesheets
57
- *
58
- * @return \PodsField
59
- *
60
- * @since 2.0
61
- */
62
- public function __construct () {
63
-
64
- }
65
-
66
- /**
67
- * Add options and set defaults for field type, shows in admin area
68
- *
69
- * @return array $options
70
- *
71
- * @since 2.0
72
- * @see PodsField::ui_options
73
- */
74
- public function options () {
75
- $options = array( /*
 
 
76
  'option_name' => array(
77
  'label' => 'Option Label',
78
  'depends-on' => array( 'another_option' => 'specific-value' ),
@@ -107,278 +112,560 @@ class PodsField {
107
  'type' => 'boolean'
108
  )
109
  )
110
- ) */
111
- );
112
-
113
- return $options;
114
- }
115
-
116
- /**
117
- * Options for the Admin area, defaults to $this->options()
118
- *
119
- * @return array $options
120
- *
121
- * @since 2.0
122
- * @see PodsField::options
123
- */
124
- public function ui_options () {
125
- return $this->options();
126
- }
127
-
128
- /**
129
- * Define the current field's schema for DB table storage
130
- *
131
- * @param array $options
132
- *
133
- * @return string
134
- * @since 2.0
135
- */
136
- public function schema ( $options = null ) {
137
- $schema = 'VARCHAR(255)';
138
-
139
- return $schema;
140
- }
141
-
142
- /**
143
- * Define the current field's preparation for sprintf
144
- *
145
- * @param array $options
146
- *
147
- * @return array
148
- * @since 2.0
149
- */
150
- public function prepare ( $options = null ) {
151
- $format = self::$prepare;
152
-
153
- return $format;
154
- }
155
-
156
- /**
157
- * Change the value of the field
158
- *
159
- * @param mixed $value
160
- * @param string $name
161
- * @param array $options
162
- * @param array $pod
163
- * @param int $id
164
- *
165
- * @return mixed|null|string
166
- * @since 2.3
167
- */
168
- public function value ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
169
- return $value;
170
- }
171
-
172
- /**
173
- * Change the way the value of the field is displayed with Pods::get
174
- *
175
- * @param mixed $value
176
- * @param string $name
177
- * @param array $options
178
- * @param array $pod
179
- * @param int $id
180
- *
181
- * @return mixed|null|string
182
- * @since 2.0
183
- */
184
- public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
185
- return $value;
186
- }
187
-
188
- /**
189
- * Customize output of the form field
190
- *
191
- * @param string $name
192
- * @param mixed $value
193
- * @param array $options
194
- * @param array $pod
195
- * @param int $id
196
- *
197
- * @return void
198
- *
199
- * @since 2.0
200
- */
201
- public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
202
- $options = (array) $options;
203
- $form_field_type = PodsForm::$field_type;
204
-
205
- if ( is_array( $value ) )
206
- $value = implode( ' ', $value );
207
-
208
- pods_view( PODS_DIR . 'ui/fields/text.php', compact( array_keys( get_defined_vars() ) ) );
209
- }
210
-
211
- /**
212
- * Get the data from the field
213
- *
214
- * @param string $name The name of the field
215
- * @param string|array $value The value of the field
216
- * @param array $options
217
- * @param array $pod
218
- * @param int $id
219
- * @param boolean $in_form
220
- *
221
- * @return array Array of possible field data
222
- *
223
- * @since 2.0
224
- */
225
- public function data ( $name, $value = null, $options = null, $pod = null, $id = null, $in_form = true ) {
226
- return (array) $value;
227
- }
228
-
229
- /**
230
- * Build regex necessary for JS validation
231
- *
232
- * @param mixed $value
233
- * @param string $name
234
- * @param array $options
235
- * @param string $pod
236
- * @param int $id
237
- *
238
- * @return bool
239
- * @since 2.0
240
- */
241
- public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
242
- return false;
243
- }
244
-
245
- /**
246
- * Validate a value before it's saved
247
- *
248
- * @param mixed $value
249
- * @param string $name
250
- * @param array $options
251
- * @param array $fields
252
- * @param array $pod
253
- * @param int $id
254
- * @param array $params
255
- *
256
- * @return bool
257
- * @since 2.0
258
- */
259
- public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
260
- return true;
261
- }
262
-
263
- /**
264
- * Change the value or perform actions after validation but before saving to the DB
265
- *
266
- * @param mixed $value
267
- * @param int $id
268
- * @param string $name
269
- * @param array $options
270
- * @param array $fields
271
- * @param array $pod
272
- * @param object $params
273
- *
274
- * @return mixed
275
- * @since 2.0
276
- */
277
- public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
278
- return $value;
279
- }
280
-
281
- /**
282
- * Save the value to the DB
283
- *
284
- * @param mixed $value
285
- * @param int $id
286
- * @param string $name
287
- * @param array $options
288
- * @param array $fields
289
- * @param array $pod
290
- * @param object $params
291
- *
292
- * @return bool|void Whether the value was saved
293
- *
294
- * @since 2.3
295
- */
296
- public function save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
297
- return null;
298
- }
299
-
300
- /**
301
- * Perform actions after saving to the DB
302
- *
303
- * @param mixed $value
304
- * @param int $id
305
- * @param string $name
306
- * @param array $options
307
- * @param array $fields
308
- * @param array $pod
309
- * @param object $params
310
- *
311
- * @since void
312
- *
313
- * @since 2.0
314
- */
315
- public function post_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
316
-
317
- }
318
-
319
- /**
320
- * Perform actions before deleting from the DB
321
- *
322
- * @param int $id
323
- * @param string $name
324
- * @param null $options
325
- * @param string $pod
326
- *
327
- * @since void
328
- *
329
- * @since 2.0
330
- */
331
- public function pre_delete ( $id = null, $name = null, $options = null, $pod = null ) {
332
-
333
- }
334
-
335
- /**
336
- * Delete the value from the DB
337
- *
338
- * @param int $id
339
- * @param string $name
340
- * @param array $options
341
- * @param array $pod
342
- *
343
- * @since void
344
- *
345
- * @since 2.3
346
- */
347
- public function delete ( $id = null, $name = null, $options = null, $pod = null ) {
348
-
349
- }
350
-
351
- /**
352
- * Perform actions after deleting from the DB
353
- *
354
- * @param int $id
355
- * @param string $name
356
- * @param array $options
357
- * @param array $pod
358
- *
359
- * @since void
360
- *
361
- * @since 2.0
362
- */
363
- public function post_delete ( $id = null, $name = null, $options = null, $pod = null ) {
364
-
365
- }
366
-
367
- /**
368
- * Customize the Pods UI manage table column output
369
- *
370
- * @param int $id
371
- * @param mixed $value
372
- * @param string $name
373
- * @param array $options
374
- * @param array $fields
375
- * @param array $pod
376
- *
377
- * @since string Value to be shown in the UI
378
- *
379
- * @since 2.0
380
- */
381
- public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
382
- return $value;
383
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
  }
1
  <?php
2
+
3
  /**
4
+ * Pods Field class for common type-specific methods.
5
+ *
6
  * @package Pods
7
  */
8
  class PodsField {
9
 
10
+ /**
11
+ * Whether this field is running under 1.x deprecated forms
12
+ *
13
+ * @var bool
14
+ * @since 2.0
15
+ */
16
+ public static $deprecated = false;
17
+
18
+ /**
19
+ * Field Type Identifier
20
+ *
21
+ * @var string
22
+ * @since 2.0
23
+ */
24
+ public static $type = 'text';
25
+
26
+ /**
27
+ * Field Type Label
28
+ *
29
+ * @var string
30
+ * @since 2.0
31
+ */
32
+ public static $label = 'Unknown';
33
+
34
+ /**
35
+ * Field Type Preparation
36
+ *
37
+ * @var string
38
+ * @since 2.0
39
+ */
40
+ public static $prepare = '%s';
41
+
42
+ /**
43
+ * Pod Types supported on (true for all, false for none, or give array of specific types supported)
44
+ *
45
+ * @var array|bool
46
+ * @since 2.1
47
+ */
48
+ public static $pod_types = true;
49
+
50
+ /**
51
+ * API caching for fields that need it during validate/save
52
+ *
53
+ * @var \PodsAPI
54
+ * @since 2.3
55
+ */
56
+ private static $api = false;
57
+
58
+ /**
59
+ * Do things like register/enqueue scripts and stylesheets
60
+ *
61
+ * @since 2.0
62
+ */
63
+ public function __construct() {
64
+
65
+ // Subclasses utilize this method if needed.
66
+
67
+ }
68
+
69
+ /**
70
+ * Add options and set defaults for field type, shows in admin area
71
+ *
72
+ * @return array $options
73
+ *
74
+ * @since 2.0
75
+ * @see PodsField::ui_options
76
+ */
77
+ public function options() {
78
+
79
+ $options = array(
80
+ /*
81
  'option_name' => array(
82
  'label' => 'Option Label',
83
  'depends-on' => array( 'another_option' => 'specific-value' ),
112
  'type' => 'boolean'
113
  )
114
  )
115
+ )
116
+ */
117
+ );
118
+
119
+ return $options;
120
+
121
+ }
122
+
123
+ /**
124
+ * Options for the Admin area, defaults to $this->options()
125
+ *
126
+ * @return array $options
127
+ *
128
+ * @since 2.0
129
+ * @see PodsField::options
130
+ */
131
+ public function ui_options() {
132
+
133
+ return $this->options();
134
+
135
+ }
136
+
137
+ /**
138
+ * Define the current field's schema for DB table storage
139
+ *
140
+ * @param array|null $options
141
+ *
142
+ * @return string
143
+ *
144
+ * @since 2.0
145
+ */
146
+ public function schema( $options = null ) {
147
+
148
+ $schema = 'VARCHAR(255)';
149
+
150
+ return $schema;
151
+
152
+ }
153
+
154
+ /**
155
+ * Define the current field's preparation for sprintf
156
+ *
157
+ * @param array|null $options
158
+ *
159
+ * @return string
160
+ *
161
+ * @since 2.0
162
+ */
163
+ public function prepare( $options = null ) {
164
+
165
+ $format = self::$prepare;
166
+
167
+ return $format;
168
+
169
+ }
170
+
171
+ /**
172
+ * Check if the field is empty.
173
+ *
174
+ * @param mixed $value
175
+ *
176
+ * @return bool
177
+ *
178
+ * @since 2.7
179
+ */
180
+ public function is_empty( $value ) {
181
+
182
+ $is_empty = false;
183
+
184
+ if ( is_string( $value ) ) {
185
+ $value = trim( $value );
186
+ }
187
+
188
+ if ( empty( $value ) ) {
189
+ $is_empty = true;
190
+ }
191
+
192
+ return $is_empty;
193
+
194
+ }
195
+
196
+ /**
197
+ * Change the value of the field
198
+ *
199
+ * @param mixed|null $value
200
+ * @param string|null $name
201
+ * @param array|null $options
202
+ * @param array|null $pod
203
+ * @param int|null $id
204
+ *
205
+ * @return mixed|null|string
206
+ *
207
+ * @since 2.3
208
+ */
209
+ public function value( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
210
+
211
+ return $value;
212
+
213
+ }
214
+
215
+ /**
216
+ * Change the way the value of the field is displayed with Pods::get
217
+ *
218
+ * @param mixed|null $value
219
+ * @param string|null $name
220
+ * @param array|null $options
221
+ * @param array|null $pod
222
+ * @param int|null $id
223
+ *
224
+ * @return mixed|null|string
225
+ *
226
+ * @since 2.0
227
+ */
228
+ public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
229
+
230
+ return $value;
231
+
232
+ }
233
+
234
+ /**
235
+ * Customize output of the form field
236
+ *
237
+ * @param string $name
238
+ * @param mixed|null $value
239
+ * @param array|null $options
240
+ * @param array|null $pod
241
+ * @param int|null $id
242
+ *
243
+ * @since 2.0
244
+ */
245
+ public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
246
+
247
+ $options = (array) $options;
248
+
249
+ $form_field_type = PodsForm::$field_type;
250
+
251
+ if ( is_array( $value ) ) {
252
+ $value = implode( ' ', $value );
253
+ }
254
+
255
+ pods_view( PODS_DIR . 'ui/fields/text.php', compact( array_keys( get_defined_vars() ) ) );
256
+
257
+ return;
258
+
259
+ // @todo Eventually use this code
260
+ $options = (array) $options;
261
+
262
+ $type = pods_v( 'type', $options, static::$type );
263
+
264
+ $args = compact( array_keys( get_defined_vars() ) );
265
+ $args = (object) $args;
266
+
267
+ $this->render_input_script( $args );
268
+
269
+ }
270
+
271
+ /**
272
+ * Render input script for Pods DFV
273
+ *
274
+ * @param array|object $args {
275
+ * Field information arguments.
276
+ *
277
+ * @type string $name Field name
278
+ * @type string $type Field type
279
+ * @type array $options Field options
280
+ * @type mixed $value Current value
281
+ * @type array $pod Pod information
282
+ * @type int|string $id Current item ID
283
+ * }
284
+ */
285
+ public function render_input_script( $args ) {
286
+
287
+ if ( is_array( $args ) ) {
288
+ $args = (object) $args;
289
+ }
290
+
291
+ $script_content = json_encode( $this->build_dfv_field_data( $args ), JSON_HEX_TAG );
292
+ ?>
293
+ <div class="pods-form-ui-field pods-dfv-field">
294
+ <script type="application/json" class="pods-dfv-field-data"><?php echo $script_content ?></script>
295
+ </div>
296
+ <?php
297
+
298
+ }
299
+
300
+ /**
301
+ * Build field data for Pods DFV
302
+ *
303
+ * @param object $args {
304
+ * Field information arguments.
305
+ *
306
+ * @type string $name Field name
307
+ * @type string $type Pod field type
308
+ * @type string $form_field_type HTML field type
309
+ * @type array $options Field options
310
+ * @type mixed $value Current value
311
+ * @type array $pod Pod information
312
+ * @type int|string $id Current item ID
313
+ * }
314
+ *
315
+ * @return array
316
+ */
317
+ public function build_dfv_field_data( $args ) {
318
+
319
+ // Handle DFV options.
320
+ $args->options = $this->build_dfv_field_options( $args->options, $args );
321
+
322
+ // Handle DFV attributes.
323
+ $attributes = PodsForm::merge_attributes( array(), $args->name, $args->type, $args->options );
324
+ $attributes = $this->build_dfv_field_attributes( $attributes, $args );
325
+ $attributes = array_map( 'esc_attr', $attributes );
326
+
327
+ // Build DFV field data.
328
+ $data = array(
329
+ 'htmlAttr' => array(
330
+ 'id' => $attributes['id'],
331
+ 'class' => $attributes['class'],
332
+ 'name' => $attributes['name'],
333
+ 'name_clean' => $attributes['data-name-clean'],
334
+ ),
335
+ 'fieldType' => $args->type,
336
+ 'fieldItemData' => $this->build_dfv_field_item_data( $args ),
337
+ 'fieldConfig' => $this->build_dfv_field_config( $args ),
338
+ );
339
+
340
+ /**
341
+ * Filter Pods DFV field data to further customize functionality.
342
+ *
343
+ * @since 2.7
344
+ *
345
+ * @param array $data DFV field data
346
+ * @param object $args {
347
+ * Field information arguments.
348
+ *
349
+ * @type string $name Field name
350
+ * @type string $type Pod field type
351
+ * @type string $form_field_type HTML field type
352
+ * @type array $options Field options
353
+ * @type mixed $value Current value
354
+ * @type array $pod Pod information
355
+ * @type int|string $id Current item ID
356
+ * }
357
+ * @param array $attributes HTML attributes
358
+ */
359
+ $data = apply_filters( 'pods_field_dfv_data', $data, $args, $attributes );
360
+
361
+ return $data;
362
+
363
+ }
364
+
365
+ /**
366
+ * Build field options and handle any validation/customization for Pods DFV
367
+ *
368
+ * @param array $options
369
+ * @param object $args {
370
+ * Field information arguments.
371
+ *
372
+ * @type string $name Field name
373
+ * @type string $type Field type
374
+ * @type array $options Field options
375
+ * @type mixed $value Current value
376
+ * @type array $pod Pod information
377
+ * @type int|string $id Current item ID
378
+ * }
379
+ *
380
+ * @return array
381
+ */
382
+ public function build_dfv_field_options( $options, $args ) {
383
+
384
+ return $options;
385
+
386
+ }
387
+
388
+ /**
389
+ * Build field HTML attributes for Pods DFV.
390
+ *
391
+ * @param array $attributes Default HTML attributes from field and PodsForm::merge_attributes.
392
+ * @param object $args {
393
+ * Field information arguments.
394
+ *
395
+ * @type string $name Field name
396
+ * @type string $type Field type
397
+ * @type array $options Field options
398
+ * @type mixed $value Current value
399
+ * @type array $pod Pod information
400
+ * @type int|string $id Current item ID
401
+ * }
402
+ *
403
+ * @return array
404
+ */
405
+ public function build_dfv_field_attributes( $attributes, $args ) {
406
+
407
+ return $attributes;
408
+
409
+ }
410
+
411
+ /**
412
+ * Build field config for Pods DFV using field options.
413
+ *
414
+ * This is for customizing the options and adding output-specific config values.
415
+ *
416
+ * @param object $args {
417
+ * Field information arguments.
418
+ *
419
+ * @type string $name Field name
420
+ * @type string $type Field type
421
+ * @type array $options Field options
422
+ * @type mixed $value Current value
423
+ * @type array $pod Pod information
424
+ * @type int|string $id Current item ID
425
+ * }
426
+ *
427
+ * @return array
428
+ */
429
+ public function build_dfv_field_config( $args ) {
430
+
431
+ $config = $args->options;
432
+
433
+ unset( $config['data'] );
434
+
435
+ $config['item_id'] = (int) $args->id;
436
+
437
+ return $config;
438
+
439
+ }
440
+
441
+ /**
442
+ * Build array of item data for Pods DFV
443
+ *
444
+ * @param object $args {
445
+ * Field information arguments.
446
+ *
447
+ * @type string $name Field name
448
+ * @type string $type Field type
449
+ * @type array $options Field options
450
+ * @type mixed $value Current value
451
+ * @type array $pod Pod information
452
+ * @type int|string $id Current item ID
453
+ * }
454
+ *
455
+ * @return array
456
+ */
457
+ public function build_dfv_field_item_data( $args ) {
458
+
459
+ $data = array();
460
+
461
+ if ( ! empty( $args->options['data'] ) && is_array( $args->options['data'] ) ) {
462
+ $data = $args->options['data'];
463
+ }
464
+
465
+ return $data;
466
+
467
+ }
468
+
469
+ /**
470
+ * Get the data from the field
471
+ *
472
+ * @param string $name The name of the field
473
+ * @param string|array|null $value The value of the field
474
+ * @param array|null $options
475
+ * @param array|null $pod
476
+ * @param int|null $id
477
+ * @param boolean $in_form
478
+ *
479
+ * @return array Array of possible field data
480
+ *
481
+ * @since 2.0
482
+ */
483
+ public function data( $name, $value = null, $options = null, $pod = null, $id = null, $in_form = true ) {
484
+
485
+ return (array) $value;
486
+
487
+ }
488
+
489
+ /**
490
+ * Build regex necessary for JS validation
491
+ *
492
+ * @param mixed|null $value
493
+ * @param string|null $name
494
+ * @param array|null $options
495
+ * @param string|null $pod
496
+ * @param int|null $id
497
+ *
498
+ * @return bool
499
+ *
500
+ * @since 2.0
501
+ */
502
+ public function regex( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
503
+
504
+ return false;
505
+
506
+ }
507
+
508
+ /**
509
+ * Validate a value before it's saved
510
+ *
511
+ * @param mixed $value
512
+ * @param string|null $name
513
+ * @param array|null $options
514
+ * @param array|null $fields
515
+ * @param array|null $pod
516
+ * @param int|null $id
517
+ * @param array|null $params
518
+ *
519
+ * @return bool
520
+ *
521
+ * @since 2.0
522
+ */
523
+ public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
524
+
525
+ return true;
526
+
527
+ }
528
+
529
+ /**
530
+ * Change the value or perform actions after validation but before saving to the DB
531
+ *
532
+ * @param mixed $value
533
+ * @param int|null $id
534
+ * @param string|null $name
535
+ * @param array|null $options
536
+ * @param array|null $fields
537
+ * @param array|null $pod
538
+ * @param object|null $params
539
+ *
540
+ * @return mixed
541
+ *
542
+ * @since 2.0
543
+ */
544
+ public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
545
+
546
+ return $value;
547
+
548
+ }
549
+
550
+ /**
551
+ * Save the value to the DB
552
+ *
553
+ * @param mixed $value
554
+ * @param int|null $id
555
+ * @param string|null $name
556
+ * @param array|null $options
557
+ * @param array|null $fields
558
+ * @param array|null $pod
559
+ * @param object|null $params
560
+ *
561
+ * @return bool|null Whether the value was saved, returning null means no save needed to occur
562
+ *
563
+ * @since 2.3
564
+ */
565
+ public function save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
566
+
567
+ return null;
568
+
569
+ }
570
+
571
+ /**
572
+ * Perform actions after saving to the DB
573
+ *
574
+ * @param mixed $value
575
+ * @param int|null $id
576
+ * @param string|null $name
577
+ * @param array|null $options
578
+ * @param array|null $fields
579
+ * @param array|null $pod
580
+ * @param object|null $params
581
+ *
582
+ * @since 2.0
583
+ */
584
+ public function post_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
585
+
586
+ // Subclasses utilize this method if needed.
587
+
588
+ }
589
+
590
+ /**
591
+ * Perform actions before deleting from the DB
592
+ *
593
+ * @param int|null $id
594
+ * @param string|null $name
595
+ * @param array|null $options
596
+ * @param string|null $pod
597
+ *
598
+ * @since 2.0
599
+ */
600
+ public function pre_delete( $id = null, $name = null, $options = null, $pod = null ) {
601
+
602
+ // Subclasses utilize this method if needed.
603
+
604
+ }
605
+
606
+ /**
607
+ * Delete the value from the DB
608
+ *
609
+ * @param int|null $id
610
+ * @param string|null $name
611
+ * @param array|null $options
612
+ * @param array|null $pod
613
+ *
614
+ * @since 2.3
615
+ */
616
+ public function delete( $id = null, $name = null, $options = null, $pod = null ) {
617
+
618
+ // Subclasses utilize this method if needed.
619
+
620
+ }
621
+
622
+ /**
623
+ * Perform actions after deleting from the DB
624
+ *
625
+ * @param int|null $id
626
+ * @param string|null $name
627
+ * @param array|null $options
628
+ * @param array|null $pod
629
+ *
630
+ * @since 2.0
631
+ */
632
+ public function post_delete( $id = null, $name = null, $options = null, $pod = null ) {
633
+
634
+ // Subclasses utilize this method if needed.
635
+
636
+ }
637
+
638
+ /**
639
+ * Customize the Pods UI manage table column output
640
+ *
641
+ * @param int $id
642
+ * @param mixed $value
643
+ * @param string|null $name
644
+ * @param array|null $options
645
+ * @param array|null $fields
646
+ * @param array|null $pod
647
+ *
648
+ * @return string Value to be shown in the UI
649
+ *
650
+ * @since 2.0
651
+ */
652
+ public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
653
+
654
+ return $value;
655
+
656
+ }
657
+
658
+ /**
659
+ * Placeholder function to allow var_export() use with classes
660
+ *
661
+ * @param array $properties
662
+ *
663
+ * @return object|void
664
+ */
665
+ public static function __set_state( $properties ) {
666
+
667
+ return;
668
+
669
+ }
670
+
671
  }
classes/PodsForm.php CHANGED
@@ -142,7 +142,7 @@ class PodsForm {
142
 
143
  $name_more_clean = self::clean( $name, true );
144
 
145
- if ( isset( $options[ 'description' ] ) && !empty( $options[ 'description' ] ) )
146
  $message = $options[ 'description' ];
147
  elseif ( empty( $message ) )
148
  return '';
@@ -153,7 +153,7 @@ class PodsForm {
153
 
154
  $type = 'comment';
155
  $attributes = array();
156
- $attributes[ 'class' ] = 'pods-form-ui-' . $type . ' pods-form-ui-' . $type . '-' . $name_more_clean;
157
  $attributes = self::merge_attributes( $attributes, $name, $type, $options, false );
158
 
159
  pods_view( PODS_DIR . 'ui/fields/_comment.php', compact( array_keys( get_defined_vars() ) ) );
@@ -211,25 +211,70 @@ class PodsForm {
211
 
212
  $helper = false;
213
 
214
- if ( 0 < strlen( pods_v( 'input_helper', $options ) ) )
215
- $helper = pods_api()->load_helper( array( 'name' => $options[ 'input_helper' ] ) );
 
 
 
 
 
 
 
 
216
 
217
- if ( ( !isset( $options[ 'data' ] ) || empty( $options[ 'data' ] ) ) && is_object( self::$loaded[ $type ] ) && method_exists( self::$loaded[ $type ], 'data' ) )
218
- $data = $options[ 'data' ] = self::$loaded[ $type ]->data( $name, $value, $options, $pod, $id, true );
 
 
219
 
220
- if ( true === apply_filters( 'pods_form_ui_field_' . $type . '_override', false, $name, $value, $options, $pod, $id ) )
221
- do_action( 'pods_form_ui_field_' . $type, $name, $value, $options, $pod, $id );
222
- elseif ( !empty( $helper ) && 0 < strlen( pods_v( 'code', $helper ) ) && false === strpos( $helper[ 'code' ], '$this->' ) && ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) )
223
- eval( '?>' . $helper[ 'code' ] );
224
- elseif ( method_exists( get_class(), 'field_' . $type ) )
225
- echo call_user_func( array( get_class(), 'field_' . $type ), $name, $value, $options );
226
- elseif ( is_object( self::$loaded[ $type ] ) && method_exists( self::$loaded[ $type ], 'input' ) )
227
- self::$loaded[ $type ]->input( $name, $value, $options, $pod, $id );
228
- else
229
- do_action( 'pods_form_ui_field_' . $type, $name, $value, $options, $pod, $id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
 
231
  $output = ob_get_clean();
232
 
 
 
 
 
 
233
  return apply_filters( 'pods_form_ui_field_' . $type, $output, $name, $value, $options, $pod, $id );
234
  }
235
 
@@ -433,8 +478,8 @@ class PodsForm {
433
  if ( 0 < strlen( pods_v( 'label', $options, '' ) ) )
434
  $_attributes[ 'data-label' ] = strip_tags( pods_v( 'label', $options ) );
435
 
436
- $_attributes['id'] = 'pods-form-ui-' . $name_clean . ( self::$form_counter > 1 ? '-' . self::$form_counter : '' );
437
- $_attributes[ 'class' ] = 'pods-form-ui-field-type-' . $type . ' pods-form-ui-field-name-' . $name_more_clean;
438
 
439
  if ( isset( $options[ 'dependency' ] ) && false !== $options[ 'dependency' ] )
440
  $_attributes[ 'class' ] .= ' pods-dependent-toggle';
@@ -467,23 +512,22 @@ class PodsForm {
467
  $attributes[ 'class' ] = $classes;
468
  }
469
 
470
- if ( isset( $options[ 'placeholder' ] ) && !empty( $options[ 'placeholder' ] ) ) {
471
- if ( is_array( $options[ 'placeholder' ] ) )
472
- $options[ 'placeholder' ] = implode( ' ', $options[ 'placeholder' ] );
473
 
474
- $options[ 'placeholder' ] = (string) $options[ 'placeholder' ];
475
- $attributes[ 'placeholder' ] = trim( $options[ 'placeholder' ] );
476
- }
477
 
478
- if ( 1 == pods_v( 'required', $options, 0 ) )
479
  $attributes[ 'class' ] .= ' pods-validate pods-validate-required';
480
 
481
- $max_length = (int) pods_var( 'maxlength', $options, pods_v( $type . '_max_length', $options, 0 ), null, true );
482
 
483
  if ( 0 < $max_length )
484
  $attributes[ 'maxlength' ] = $max_length;
485
 
486
  $attributes = (array) apply_filters( 'pods_form_ui_field_' . $type . '_merge_attributes', $attributes, $name, $options );
 
487
  return $attributes;
488
  }
489
 
@@ -781,54 +825,71 @@ class PodsForm {
781
  * @param array $options array( 'depends-on' => ..., 'excludes-on' => ...)
782
  * @param string $prefix
783
  *
784
- * @return string
785
  * @static
786
  * @since 2.0
787
  */
788
  public static function dependencies( $options, $prefix = '' ) {
789
  $options = (array) $options;
 
 
790
 
791
- $depends_on = $excludes_on = array();
792
- if ( isset( $options[ 'depends-on' ] ) )
793
  $depends_on = (array) $options[ 'depends-on' ];
794
 
795
- if ( isset( $options[ 'excludes-on' ] ) )
796
- $excludes_on = (array) $options[ 'excludes-on' ];
 
 
 
 
 
 
797
 
798
- $classes = array();
 
 
 
 
 
 
799
 
800
- if ( !empty( $depends_on ) ) {
801
- $classes[] = 'pods-depends-on';
802
 
803
- foreach ( $depends_on as $depends => $on ) {
804
- $classes[] = 'pods-depends-on-' . $prefix . self::clean( $depends, true );
 
 
 
805
 
806
- if ( !is_bool( $on ) ) {
807
  $on = (array) $on;
808
 
809
  foreach ( $on as $o ) {
810
- $classes[] = 'pods-depends-on-' . $prefix . self::clean( $depends, true ) . '-' . self::clean( $o, true );
811
  }
812
  }
813
  }
814
  }
815
 
816
- if ( !empty( $excludes_on ) ) {
817
- $classes[] = 'pods-excludes-on';
818
- foreach ( $excludes_on as $excludes => $on ) {
819
- $classes[] = 'pods-excludes-on-' . $prefix . self::clean( $excludes, true );
820
 
821
- $on = (array) $on;
 
822
 
823
- foreach ( $on as $o ) {
824
- $classes[] = 'pods-excludes-on-' . $prefix . self::clean( $excludes, true ) . '-' . self::clean( $o, true );
 
 
 
825
  }
826
  }
827
  }
828
 
829
  $classes = implode( ' ', $classes );
830
 
831
- return $classes;
832
  }
833
 
834
  /**
@@ -891,15 +952,38 @@ class PodsForm {
891
 
892
  $tableless_field_types = self::tableless_field_types();
893
 
894
- if ( method_exists( self::$loaded[ $type ], 'display' ) ) {
895
- if ( is_array( $value ) && !in_array( $type, $tableless_field_types ) ) {
896
- foreach ( $value as $k => $display_value ) {
897
- $value[ $k ] = call_user_func_array( array( self::$loaded[ $type ], 'display' ), array( $display_value, $name, $options, $pod, $id, $traverse ) );
898
- }
899
- }
900
- else
901
- $value = call_user_func_array( array( self::$loaded[ $type ], 'display' ), array( $value, $name, $options, $pod, $id, $traverse ) );
902
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
903
 
904
  $value = apply_filters( 'pods_form_display_' . $type, $value, $name, $options, $pod, $id, $traverse );
905
 
@@ -1165,10 +1249,11 @@ class PodsForm {
1165
  $field_types = self::field_types();
1166
 
1167
  foreach ( $field_types as $field_type => $field_type_data ) {
1168
- $has_ajax = self::field_method( $field_type_data[ 'type' ], 'admin_init' );
1169
 
1170
- if ( false !== $has_ajax )
1171
- $admin_field_types[] = $field_type;
 
1172
  }
1173
 
1174
  pods_transient_set( 'pods_form_admin_init_field_types', $admin_field_types );
@@ -1316,6 +1401,7 @@ class PodsForm {
1316
  $field_types = array(
1317
  'text',
1318
  'website',
 
1319
  'phone',
1320
  'email',
1321
  'password',
@@ -1329,10 +1415,11 @@ class PodsForm {
1329
  'currency',
1330
  'file',
1331
  'avatar',
 
1332
  'pick',
1333
  'boolean',
1334
  'color',
1335
- 'slug'
1336
  );
1337
 
1338
  $field_types = array_merge( $field_types, array_keys( self::$field_types ) );
@@ -1384,7 +1471,13 @@ class PodsForm {
1384
  static $field_types = null;
1385
 
1386
  if ( null === $field_types ) {
1387
- $field_types = array( 'pick', 'file', 'avatar', 'taxonomy' );
 
 
 
 
 
 
1388
 
1389
  $field_types = apply_filters( 'pods_tableless_field_types', $field_types );
1390
  }
142
 
143
  $name_more_clean = self::clean( $name, true );
144
 
145
+ if ( ! empty( $options[ 'description' ] ) )
146
  $message = $options[ 'description' ];
147
  elseif ( empty( $message ) )
148
  return '';
153
 
154
  $type = 'comment';
155
  $attributes = array();
156
+ $attributes[ 'class' ] = 'description pods-form-ui-' . $type . ' pods-form-ui-' . $type . '-' . $name_more_clean;
157
  $attributes = self::merge_attributes( $attributes, $name, $type, $options, false );
158
 
159
  pods_view( PODS_DIR . 'ui/fields/_comment.php', compact( array_keys( get_defined_vars() ) ) );
211
 
212
  $helper = false;
213
 
214
+ /**
215
+ * Input helpers are deprecated and not guaranteed to work properly.
216
+ *
217
+ * They will be entirely removed in Pods 3.0.
218
+ *
219
+ * @deprecated 2.7
220
+ */
221
+ if ( 0 < strlen( pods_v( 'input_helper', $options ) ) ) {
222
+ $helper = pods_api()->load_helper( array( 'name' => $options['input_helper'] ) );
223
+ }
224
 
225
+ // @todo Move into DFV field method or PodsObject later
226
+ if ( ( ! isset( $options['data'] ) || empty( $options['data'] ) ) && is_object( self::$loaded[ $type ] ) && method_exists( self::$loaded[ $type ], 'data' ) ) {
227
+ $data = $options['data'] = self::$loaded[ $type ]->data( $name, $value, $options, $pod, $id, true );
228
+ }
229
 
230
+ /**
231
+ * pods_form_ui_field_{$type}_override filter leaves too much to be done by developer.
232
+ *
233
+ * It will be replaced in Pods 3.0 with better documentation.
234
+ *
235
+ * @deprecated 2.7
236
+ */
237
+ if ( true === apply_filters( 'pods_form_ui_field_' . $type . '_override', false, $name, $value, $options, $pod, $id ) ) {
238
+ /**
239
+ * pods_form_ui_field_{$type} action leaves too much to be done by developer.
240
+ *
241
+ * It will be replaced in Pods 3.0 with better documentation.
242
+ *
243
+ * @deprecated 2.7
244
+ */
245
+ do_action( 'pods_form_ui_field_' . $type, $name, $value, $options, $pod, $id );
246
+ } elseif ( ! empty( $helper ) && 0 < strlen( pods_v( 'code', $helper ) ) && false === strpos( $helper['code'], '$this->' ) && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) {
247
+ /**
248
+ * Input helpers are deprecated and not guaranteed to work properly.
249
+ *
250
+ * They will be entirely removed in Pods 3.0.
251
+ *
252
+ * @deprecated 2.7
253
+ */
254
+ eval( '?>' . $helper['code'] );
255
+ } elseif ( method_exists( get_class(), 'field_' . $type ) ) {
256
+ // @todo Move these custom field methods into real/faux field classes
257
+ echo call_user_func( array( get_class(), 'field_' . $type ), $name, $value, $options );
258
+ } elseif ( is_object( self::$loaded[ $type ] ) && method_exists( self::$loaded[ $type ], 'input' ) ) {
259
+ self::$loaded[ $type ]->input( $name, $value, $options, $pod, $id );
260
+ } else {
261
+ /**
262
+ * pods_form_ui_field_{$type} action leaves too much to be done by developer.
263
+ *
264
+ * It will be replaced in Pods 3.0 with better documentation.
265
+ *
266
+ * @deprecated 2.7
267
+ */
268
+ do_action( 'pods_form_ui_field_' . $type, $name, $value, $options, $pod, $id );
269
+ }
270
 
271
  $output = ob_get_clean();
272
 
273
+ /**
274
+ * pods_form_ui_field_{$type} filter will remain supported.
275
+ *
276
+ * It is not intended for replacing but augmenting input markup.
277
+ */
278
  return apply_filters( 'pods_form_ui_field_' . $type, $output, $name, $value, $options, $pod, $id );
279
  }
280
 
478
  if ( 0 < strlen( pods_v( 'label', $options, '' ) ) )
479
  $_attributes[ 'data-label' ] = strip_tags( pods_v( 'label', $options ) );
480
 
481
+ $_attributes['id'] = 'pods-form-ui-' . $name_clean . ( self::$form_counter > 1 ? '-' . self::$form_counter : '' );
482
+ $_attributes['class'] = 'pods-form-ui-field pods-form-ui-field-type-' . $type . ' pods-form-ui-field-name-' . $name_more_clean;
483
 
484
  if ( isset( $options[ 'dependency' ] ) && false !== $options[ 'dependency' ] )
485
  $_attributes[ 'class' ] .= ' pods-dependent-toggle';
512
  $attributes[ 'class' ] = $classes;
513
  }
514
 
515
+ $placeholder = trim( pods_v( 'placeholder', $options, pods_v( $type . '_placeholder', $options ) ) );
 
 
516
 
517
+ if ( ! empty( $placeholder ) ) {
518
+ $attributes['placeholder'] = $placeholder;
519
+ }
520
 
521
+ if ( 1 === (int) pods_v( 'required', $options, 0 ) )
522
  $attributes[ 'class' ] .= ' pods-validate pods-validate-required';
523
 
524
+ $max_length = (int) pods_v( 'maxlength', $options, pods_v( $type . '_max_length', $options, 0 ) );
525
 
526
  if ( 0 < $max_length )
527
  $attributes[ 'maxlength' ] = $max_length;
528
 
529
  $attributes = (array) apply_filters( 'pods_form_ui_field_' . $type . '_merge_attributes', $attributes, $name, $options );
530
+
531
  return $attributes;
532
  }
533
 
825
  * @param array $options array( 'depends-on' => ..., 'excludes-on' => ...)
826
  * @param string $prefix
827
  *
828
+ * @return array
829
  * @static
830
  * @since 2.0
831
  */
832
  public static function dependencies( $options, $prefix = '' ) {
833
  $options = (array) $options;
834
+ $classes = $data = array();
835
+ $depends_on = $excludes_on = $wildcard_on = array();
836
 
837
+ if ( isset( $options[ 'depends-on' ] ) ) {
 
838
  $depends_on = (array) $options[ 'depends-on' ];
839
 
840
+ if ( ! empty( $depends_on ) ) {
841
+ $classes[] = 'pods-depends-on';
842
+
843
+ foreach ( $depends_on as $depends => $on ) {
844
+ $classes[] = 'pods-depends-on-' . $prefix . self::clean( $depends, true );
845
+
846
+ if ( ! is_bool( $on ) ) {
847
+ $on = (array) $on;
848
 
849
+ foreach ( $on as $o ) {
850
+ $classes[] = 'pods-depends-on-' . $prefix . self::clean( $depends, true ) . '-' . self::clean( $o, true );
851
+ }
852
+ }
853
+ }
854
+ }
855
+ }
856
 
857
+ if ( isset( $options[ 'excludes-on' ] ) ) {
858
+ $excludes_on = (array) $options[ 'excludes-on' ];
859
 
860
+ if ( ! empty( $excludes_on ) ) {
861
+ $classes[] = 'pods-excludes-on';
862
+
863
+ foreach ( $excludes_on as $excludes => $on ) {
864
+ $classes[] = 'pods-excludes-on-' . $prefix . self::clean( $excludes, true );
865
 
 
866
  $on = (array) $on;
867
 
868
  foreach ( $on as $o ) {
869
+ $classes[] = 'pods-excludes-on-' . $prefix . self::clean( $excludes, true ) . '-' . self::clean( $o, true );
870
  }
871
  }
872
  }
873
  }
874
 
875
+ if ( isset( $options[ 'wildcard-on' ] ) ) {
876
+ $wildcard_on = (array) $options[ 'wildcard-on' ];
 
 
877
 
878
+ if ( ! empty( $wildcard_on ) ) {
879
+ $classes[] = 'pods-wildcard-on';
880
 
881
+ // Add the appropriate classes and data attribs per value dependency
882
+ foreach ( $wildcard_on as $target => $wildcards ) {
883
+ $target = $prefix . self::clean( $target, true );
884
+ $classes[] = 'pods-wildcard-on-' . $target;
885
+ $data[ 'pods-wildcard-' . $target ] = $wildcards;
886
  }
887
  }
888
  }
889
 
890
  $classes = implode( ' ', $classes );
891
 
892
+ return array( 'classes' => $classes, 'data' => $data );
893
  }
894
 
895
  /**
952
 
953
  $tableless_field_types = self::tableless_field_types();
954
 
955
+ if ( method_exists( self::$loaded[ $type ], 'display_list' ) ) {
956
+ $value = call_user_func_array( array( self::$loaded[ $type ], 'display_list' ), array(
957
+ $value,
958
+ $name,
959
+ $options,
960
+ $pod,
961
+ $id,
962
+ $traverse
963
+ ) );
964
+ } elseif ( method_exists( self::$loaded[ $type ], 'display' ) ) {
965
+ if ( is_array( $value ) && ! in_array( $type, $tableless_field_types ) ) {
966
+ foreach ( $value as $k => $display_value ) {
967
+ $value[ $k ] = call_user_func_array( array( self::$loaded[ $type ], 'display' ), array(
968
+ $display_value,
969
+ $name,
970
+ $options,
971
+ $pod,
972
+ $id,
973
+ $traverse
974
+ ) );
975
+ }
976
+ } else {
977
+ $value = call_user_func_array( array( self::$loaded[ $type ], 'display' ), array(
978
+ $value,
979
+ $name,
980
+ $options,
981
+ $pod,
982
+ $id,
983
+ $traverse
984
+ ) );
985
+ }
986
+ }
987
 
988
  $value = apply_filters( 'pods_form_display_' . $type, $value, $name, $options, $pod, $id, $traverse );
989
 
1249
  $field_types = self::field_types();
1250
 
1251
  foreach ( $field_types as $field_type => $field_type_data ) {
1252
+ $has_admin_init = self::field_method( $field_type_data[ 'type' ], 'admin_init' );
1253
 
1254
+ if ( false !== $has_admin_init ) {
1255
+ $admin_field_types[] = $field_type;
1256
+ }
1257
  }
1258
 
1259
  pods_transient_set( 'pods_form_admin_init_field_types', $admin_field_types );
1401
  $field_types = array(
1402
  'text',
1403
  'website',
1404
+ //'link',
1405
  'phone',
1406
  'email',
1407
  'password',
1415
  'currency',
1416
  'file',
1417
  'avatar',
1418
+ 'oembed',
1419
  'pick',
1420
  'boolean',
1421
  'color',
1422
+ 'slug',
1423
  );
1424
 
1425
  $field_types = array_merge( $field_types, array_keys( self::$field_types ) );
1471
  static $field_types = null;
1472
 
1473
  if ( null === $field_types ) {
1474
+ $field_types = array(
1475
+ 'pick',
1476
+ 'file',
1477
+ 'avatar',
1478
+ 'taxonomy',
1479
+ 'comment',
1480
+ );
1481
 
1482
  $field_types = apply_filters( 'pods_tableless_field_types', $field_types );
1483
  }
classes/PodsI18n.php ADDED
@@ -0,0 +1,510 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Pods
4
+ * @since 2.7
5
+ */
6
+ final class PodsI18n {
7
+
8
+ /**
9
+ * @var PodsI18n Singleton instance
10
+ */
11
+ private static $instance = null;
12
+
13
+ /**
14
+ * @var array Key/value pairs with label/translation
15
+ */
16
+ private static $strings = array();
17
+
18
+ /**
19
+ * @var mixed Current language locale
20
+ */
21
+ private static $current_language = null;
22
+
23
+ /**
24
+ * @var mixed Current language data
25
+ */
26
+ private static $current_language_data = null;
27
+
28
+ /**
29
+ * Singleton handling for a basic pods_i18n() request
30
+ *
31
+ * @since 2.7
32
+ */
33
+ private function __construct() {
34
+ self::$instance = $this;
35
+
36
+ // Hook all enqueue scripts actions
37
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
38
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
39
+ add_action( 'login_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
40
+
41
+ // Polylang
42
+ add_filter( 'pll_get_post_types', array( $this, 'pll_get_post_types' ), 10, 2 );
43
+ }
44
+
45
+ /**
46
+ * Singleton handling for a basic pods_i18n() request
47
+ *
48
+ * @return \PodsI18n
49
+ *
50
+ * @since 2.7
51
+ */
52
+ public static function get_instance() {
53
+
54
+ // Initialize if the class hasn't been setup yet for some reason
55
+ if ( ! is_object( self::$instance ) ) {
56
+ self::$instance = new self();
57
+ }
58
+
59
+ return self::$instance;
60
+ }
61
+
62
+ /**
63
+ * @since 2.7
64
+ */
65
+ public function enqueue_scripts() {
66
+
67
+ // Register our i18n script for JS
68
+ wp_register_script( 'sprintf', PODS_URL. 'ui/js/sprintf/sprintf.min.js', array(), '1.1.0', true );
69
+ wp_register_script( 'pods-i18n', PODS_URL . 'ui/js/pods-i18n.js', array( 'sprintf' ), PODS_VERSION, true );
70
+
71
+ self::localize_assets();
72
+ }
73
+
74
+ /**
75
+ * Localize assets:
76
+ * * Build localizations strings from the defaults and those provided via filter
77
+ * * Provide a global JavaScript object with the assembled localization strings via `wp_localize_script`
78
+ *
79
+ * @since 2.7
80
+ */
81
+ private static function localize_assets() {
82
+
83
+ /**
84
+ * Add strings to the localization
85
+ * Setting the key of your string to the original (non translated) value is mandatory
86
+ * Note: Existing keys in this class will overwrite the ones of this filter!
87
+ *
88
+ * @since 2.7
89
+ * @see default_strings()
90
+ *
91
+ * @param array
92
+ *
93
+ * @return array format: 'Untranslated string' => 'Translated string with use of WP translate functions'
94
+ */
95
+ $strings_extra = apply_filters( 'pods_localized_strings', array() );
96
+
97
+ self::$strings = array_merge( $strings_extra, self::default_strings() );
98
+
99
+ foreach ( self::$strings as $key => $str ) {
100
+ self::register( $key, $str );
101
+ }
102
+
103
+ // Some other stuff we need to pass through
104
+ $i18n_base = array(
105
+ 'debug' => ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG == true ) ? true : false,
106
+ );
107
+ // Add localization to our i18n script
108
+ wp_localize_script( 'pods-i18n', 'podsLocalizedStrings', array_merge( self::$strings, $i18n_base ) );
109
+ }
110
+
111
+ /**
112
+ * Register function that creates the references and combines these with the translated strings
113
+ *
114
+ * @param string $string_key
115
+ * @param string $translation
116
+ *
117
+ * @since 2.7
118
+ */
119
+ private static function register( $string_key, $translation ) {
120
+
121
+ /**
122
+ * Converts string into reference object variable
123
+ * Uses the same logic as JS to create the same references
124
+ */
125
+ $ref = '__' . $string_key;
126
+
127
+ // Add it to the strings localized
128
+ self::$strings[ $ref ] = $translation;
129
+
130
+ // Remove the old key
131
+ unset( self::$strings[ $string_key ] );
132
+ }
133
+
134
+ /**
135
+ * Register our labels to use in JS
136
+ * We need to register them as normal string to convert to JS references
137
+ * And we need to register the translations to attach to these references, these may not be variables!
138
+ *
139
+ * @return array Key/value pairs with label/translation
140
+ *
141
+ * @since 2.7
142
+ */
143
+ private static function default_strings() {
144
+
145
+ return array(
146
+
147
+ '%s is required.' =>
148
+ __( '%s is required.', 'pods' ),
149
+
150
+ 'This field is required.' =>
151
+ __( 'This field is required.', 'pods' ),
152
+
153
+ 'Add' =>
154
+ __( 'Add', 'pods' ),
155
+
156
+ 'Add New' =>
157
+ __( 'Add New', 'pods' ),
158
+
159
+ 'Add New Record' =>
160
+ __( 'Add New Record', 'pods' ),
161
+
162
+ 'Added!' =>
163
+ __( 'Added!', 'pods' ),
164
+
165
+ 'Added! Choose another or <a href="#">close this box</a>' =>
166
+ __( 'Added! Choose another or <a href="#">close this box</a>', 'pods' ),
167
+
168
+ 'Copy' =>
169
+ __( 'Copy', 'pods' ),
170
+
171
+ 'Reorder' =>
172
+ __( 'Reorder', 'pods' ),
173
+
174
+ 'Remove' =>
175
+ __( 'Remove', 'pods' ),
176
+
177
+ 'Deselect' =>
178
+ __( 'Deselect', 'pods' ),
179
+
180
+ 'Download' =>
181
+ __( 'Download', 'pods' ),
182
+
183
+ 'View' =>
184
+ __( 'View', 'pods' ),
185
+
186
+ 'Edit' =>
187
+ __( 'Edit', 'pods' ),
188
+
189
+ 'Search' =>
190
+ __( 'Search', 'pods' ),
191
+
192
+ 'Navigating away from this page will discard any changes you have made.' =>
193
+ __( 'Navigating away from this page will discard any changes you have made.', 'pods' ),
194
+
195
+ 'Some fields have changes that were not saved yet, please save them or cancel the changes before saving the Pod.' =>
196
+ __( 'Some fields have changes that were not saved yet, please save them or cancel the changes before saving the Pod.', 'pods' ),
197
+
198
+ 'Unable to process request, please try again.' =>
199
+ __( 'Unable to process request, please try again.', 'pods' ),
200
+
201
+ 'Error uploading file: ' =>
202
+ __( 'Error uploading file: ', 'pods' ),
203
+
204
+ 'Allowed Files' =>
205
+ __( 'Allowed Files', 'pods' ),
206
+
207
+ 'The Title' =>
208
+ __( 'The Title', 'pods' ),
209
+
210
+ 'Select from existing' =>
211
+ __( 'Select from existing', 'pods' ),
212
+
213
+ 'You can only select' =>
214
+ __( 'You can only select', 'pods' ),
215
+
216
+ '%s item' =>
217
+ __( '%s item', 'pods' ),
218
+
219
+ '%s items' =>
220
+ __( '%s items', 'pods' ),
221
+
222
+ 'Icon' =>
223
+ __( 'Icon', 'pods' ),
224
+
225
+ );
226
+
227
+ }
228
+
229
+ /**
230
+ * Get current locale information from Multilingual plugins
231
+ *
232
+ * @since 2.7
233
+ *
234
+ * @param array $args (optional) {
235
+ * @type bool $refresh Rerun get_current_language() logic?
236
+ * }
237
+ *
238
+ * @return string
239
+ */
240
+ public function get_current_language( $args = array() ) {
241
+
242
+ $args = wp_parse_args( $args, array(
243
+ 'refresh' => false,
244
+ ) );
245
+
246
+ if ( ! $args['refresh'] && ! empty( self::$current_language ) ) {
247
+ return self::$current_language;
248
+ }
249
+
250
+ $this->get_current_language_data( $args );
251
+ return self::$current_language;
252
+ }
253
+
254
+ /**
255
+ * Get current language information from Multilingual plugins
256
+ *
257
+ * @since 2.6.6
258
+ * @since 2.7 Moved to this class from PodsAPI
259
+ *
260
+ * @param array $args (optional) {
261
+ * @type bool $refresh Rerun logic?
262
+ * }
263
+ *
264
+ * @return array
265
+ */
266
+ public function get_current_language_data( $args = array() ) {
267
+
268
+ $args = wp_parse_args( $args, array(
269
+ 'refresh' => false,
270
+ ) );
271
+
272
+ if ( ! $args['refresh'] && ! empty( self::$current_language_data ) ) {
273
+ return self::$current_language_data;
274
+ }
275
+
276
+ /**
277
+ * @var $sitepress SitePress object
278
+ * @var $polylang Polylang object
279
+ */
280
+ /*
281
+ * @todo wpml-comp Remove global object usage
282
+ */
283
+ global $sitepress, $polylang;
284
+
285
+ $lang_data = false;
286
+ $translator = false;
287
+ $current_language = false;
288
+
289
+ // Multilingual support
290
+ if ( did_action( 'wpml_loaded' ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
291
+ // WPML support
292
+ $translator = 'WPML';
293
+
294
+ // Get the global current language (if set)
295
+ $wpml_language = apply_filters( 'wpml_current_language', null );
296
+ $current_language = ( $wpml_language != 'all' ) ? $wpml_language : '';
297
+
298
+ } elseif ( ( function_exists( 'PLL' ) || is_object( $polylang ) ) && function_exists( 'pll_current_language' ) ) {
299
+ // Polylang support
300
+ $translator = 'PLL';
301
+
302
+ // Get the global current language (if set)
303
+ $current_language = pll_current_language( 'slug' );
304
+ }
305
+
306
+ /**
307
+ * Admin functions that overwrite the current language
308
+ *
309
+ * @since 2.6.6
310
+ */
311
+ if ( is_admin() && ! empty( $translator ) ) {
312
+ if ( $translator == 'PLL' ) {
313
+ /**
314
+ * Polylang support
315
+ * Get the current user's preferred language.
316
+ * This is a user meta setting that will overwrite the language returned from pll_current_language()
317
+ * @see polylang/admin/admin-base.php -> init_user()
318
+ */
319
+ $current_language = get_user_meta( get_current_user_id(), 'pll_filter_content', true );
320
+ }
321
+
322
+ // Get current language based on the object language if available
323
+ if ( function_exists( 'get_current_screen' ) ) {
324
+ $current_screen = get_current_screen();
325
+
326
+ /**
327
+ * Overwrite the current language if needed for post types
328
+ */
329
+ if ( isset( $current_screen->base ) && ( $current_screen->base == 'post' || $current_screen->base == 'edit' ) ) {
330
+ if ( ! empty( $_GET['post'] ) ) {
331
+ /**
332
+ * WPML support
333
+ * In WPML the current language is always set to default on an edit screen
334
+ * We need to overwrite this when the current object is not-translatable to enable relationships with different languages
335
+ */
336
+ if ( $translator == 'WPML'
337
+ && ! apply_filters( 'wpml_is_translated_post_type', false, ( get_post_type( $_GET['post'] ) ) )
338
+ ) {
339
+ // Overwrite the current language to nothing if this is a NOT-translatable post_type
340
+ $current_language = '';
341
+ }
342
+
343
+ /**
344
+ * Polylang support (1.5.4+)
345
+ * In polylang the preferred language could be anything.
346
+ * We only want the related objects if they are not translatable OR the same language as the current object
347
+ */
348
+ if ( $translator == 'PLL'
349
+ && function_exists( 'pll_get_post_language' )
350
+ && pll_is_translated_post_type( get_post_type( $_GET['post'] ) )
351
+ ) {
352
+ // Overwrite the current language if this is a translatable post_type
353
+ $current_language = pll_get_post_language( (int) $_GET['post'] );
354
+ }
355
+ }
356
+
357
+ /**
358
+ * Polylang support (1.0.1+)
359
+ * In polylang the preferred language could be anything.
360
+ * 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
361
+ */
362
+ if ( $translator == 'PLL'
363
+ && ! empty( $_GET['new_lang'] )
364
+ && ! empty( $_GET['post_type'] )
365
+ && pll_is_translated_post_type( sanitize_text_field( $_GET['post_type'] ) )
366
+ ) {
367
+ $current_language = $_GET['new_lang'];
368
+ }
369
+
370
+ /**
371
+ * Overwrite the current language if needed for taxonomies
372
+ */
373
+ } elseif ( isset( $current_screen->base ) && ( $current_screen->base == 'term' || $current_screen->base == 'edit-tags' ) ) {
374
+ // @todo MAYBE: Similar function like get_post_type for taxonomies so we don't need to check for $_GET['taxonomy']
375
+ if ( ! empty( $_GET['taxonomy'] ) ) {
376
+ /*
377
+ * @todo wpml-comp API call for taxonomy needed!
378
+ * Suggested API call:
379
+ * add_filter( 'wpml_is_translated_taxonomy', $_GET['taxonomy'], 10, 2 );
380
+ */
381
+ /**
382
+ * WPML support
383
+ * In WPML the current language is always set to default on an edit screen
384
+ * We need to overwrite this when the current object is not-translatable to enable relationships with different languages
385
+ */
386
+ if ( $translator == 'WPML'
387
+ && method_exists( $sitepress, 'is_translated_taxonomy')
388
+ && ! $sitepress->is_translated_taxonomy( $_GET['taxonomy'] )
389
+ ) {
390
+ // Overwrite the current language to nothing if this is a NOT-translatable taxonomy
391
+ $current_language = '';
392
+ }
393
+
394
+ /**
395
+ * Polylang support (1.5.4+)
396
+ * In polylang the preferred language could be anything.
397
+ * We only want the related objects if they are not translatable OR the same language as the current object
398
+ */
399
+ if ( $translator == 'PLL'
400
+ && ! empty( $_GET['tag_ID'] )
401
+ && function_exists( 'pll_get_term_language' )
402
+ && pll_is_translated_taxonomy( sanitize_text_field( $_GET['taxonomy'] ) )
403
+ ) {
404
+ // Overwrite the current language if this is a translatable taxonomy
405
+ $current_language = pll_get_term_language( (int) $_GET['tag_ID'] );
406
+ }
407
+ }
408
+
409
+ /**
410
+ * Polylang support (1.0.1+)
411
+ * In polylang the preferred language could be anything.
412
+ * 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
413
+ */
414
+ if ( $translator == 'PLL'
415
+ && ! empty( $_GET['new_lang'] )
416
+ && ! empty( $_GET['taxonomy'] )
417
+ && pll_is_translated_taxonomy( sanitize_text_field( $_GET['taxonomy'] ) )
418
+ ) {
419
+ $current_language = $_GET['new_lang'];
420
+ }
421
+ }
422
+ }
423
+ }
424
+
425
+ $current_language = pods_sanitize( sanitize_text_field( $current_language ) );
426
+
427
+ if ( ! empty( $current_language ) ) {
428
+ // We need to return language data
429
+ $lang_data = array(
430
+ 'language' => $current_language,
431
+ 't_id' => 0,
432
+ 'tt_id' => 0,
433
+ 'term' => null,
434
+ );
435
+
436
+ /**
437
+ * Polylang support
438
+ * Get the language taxonomy object for the current language
439
+ */
440
+ if ( $translator == 'PLL' ) {
441
+ $current_language_t = false;
442
+
443
+ // Get the language term object
444
+ if ( function_exists( 'PLL' ) && isset( PLL()->model ) && method_exists( PLL()->model, 'get_language' ) ) {
445
+ // Polylang 1.8 and newer
446
+ $current_language_t = PLL()->model->get_language( $current_language );
447
+ } elseif ( is_object( $polylang ) && isset( $polylang->model ) && method_exists( $polylang->model, 'get_language' ) ) {
448
+ // Polylang 1.2 - 1.7.x
449
+ $current_language_t = $polylang->model->get_language( $current_language );
450
+ } elseif ( is_object( $polylang ) && method_exists( $polylang, 'get_language' ) ) {
451
+ // Polylang 1.1.x and older
452
+ $current_language_t = $polylang->get_language( $current_language );
453
+ }
454
+
455
+ // If the language object exists, add it!
456
+ if ( $current_language_t && ! empty( $current_language_t->term_id ) ) {
457
+ $lang_data['t_id'] = (int) $current_language_t->term_id;
458
+ $lang_data['tt_id'] = (int) $current_language_t->term_taxonomy_id;
459
+ $lang_data['tl_t_id'] = (int) $current_language_t->tl_term_id;
460
+ $lang_data['tl_tt_id'] = (int) $current_language_t->tl_term_taxonomy_id;
461
+ $lang_data['term'] = $current_language_t;
462
+ }
463
+ }
464
+ }
465
+
466
+ /**
467
+ * Override language data used by Pods.
468
+ *
469
+ * @since 2.6.6
470
+ *
471
+ * @param array|false $lang_data {
472
+ * Language data
473
+ *
474
+ * @type string $language Language slug
475
+ * @type int $t_id Language term_id
476
+ * @type int $tt_id Language term_taxonomy_id
477
+ * @type WP_Term $term Language term object
478
+ * }
479
+ * @param string|boolean $translator Language plugin used
480
+ */
481
+ $lang_data = apply_filters( 'pods_get_current_language', $lang_data, $translator );
482
+
483
+ self::$current_language = $lang_data['language'];
484
+ self::$current_language_data = $lang_data;
485
+
486
+ return $lang_data;
487
+
488
+ }
489
+
490
+ /**
491
+ * Add Pods templates to possible i18n enabled post-types (polylang settings).
492
+ *
493
+ * @since 2.7
494
+ *
495
+ * @param array $post_types
496
+ * @param bool $is_settings
497
+ *
498
+ * @return array mixed
499
+ */
500
+ public function pll_get_post_types( $post_types, $is_settings = false ) {
501
+ if ( $is_settings ) {
502
+ $post_types['_pods_template'] = '_pods_template';
503
+ }/* else {
504
+ // Force enable this post type for translation.
505
+ $post_types['_pods_template'] = '_pods_template';
506
+ }*/
507
+ return $post_types;
508
+ }
509
+
510
+ }
classes/PodsInit.php CHANGED
@@ -29,6 +29,11 @@ class PodsInit {
29
  */
30
  static $meta;
31
 
 
 
 
 
 
32
  /**
33
  * @var PodsAdmin
34
  */
@@ -169,6 +174,15 @@ class PodsInit {
169
  self::$meta = pods_meta()->core();
170
  }
171
 
 
 
 
 
 
 
 
 
 
172
  /**
173
  * Set up the Pods core
174
  */
@@ -237,32 +251,24 @@ class PodsInit {
237
  */
238
  public function register_assets() {
239
 
240
- if ( ! wp_style_is( 'jquery-ui', 'registered' ) ) {
241
- wp_register_style( 'jquery-ui', PODS_URL . 'ui/css/smoothness/jquery-ui.custom.css', array(), '1.8.16' );
242
- }
243
 
244
  wp_register_script( 'pods-json', PODS_URL . 'ui/js/jquery.json.js', array( 'jquery' ), '2.3' );
245
 
246
- if ( ! wp_style_is( 'jquery-qtip2', 'registered' ) ) {
247
- wp_register_style( 'jquery-qtip2', PODS_URL . 'ui/css/jquery.qtip.min.css', array(), '2.2' );
248
- }
249
-
250
  if ( ! wp_script_is( 'jquery-qtip2', 'registered' ) ) {
251
  wp_register_script( 'jquery-qtip2', PODS_URL . 'ui/js/jquery.qtip.min.js', array( 'jquery' ), '2.2' );
252
  }
253
 
254
  wp_register_script( 'pods', PODS_URL . 'ui/js/jquery.pods.js', array(
255
  'jquery',
 
 
256
  'pods-json',
257
  'jquery-qtip2'
258
- ), PODS_VERSION );
259
 
260
- wp_register_style( 'pods-form', PODS_URL . 'ui/css/pods-form.css', array(), PODS_VERSION );
261
-
262
- wp_register_style( 'pods-cleditor', PODS_URL . 'ui/css/jquery.cleditor.css', array(), '1.3.0' );
263
  wp_register_script( 'pods-cleditor', PODS_URL . 'ui/js/jquery.cleditor.min.js', array( 'jquery' ), '1.3.0' );
264
 
265
- wp_register_style( 'pods-codemirror', PODS_URL . 'ui/css/codemirror.css', array(), '4.8' );
266
  wp_register_script( 'pods-codemirror', PODS_URL . 'ui/js/codemirror.js', array(), '4.8', true );
267
  wp_register_script( 'pods-codemirror-loadmode', PODS_URL . 'ui/js/codemirror/addon/mode/loadmode.js', array( 'pods-codemirror' ), '4.8', true );
268
  wp_register_script( 'pods-codemirror-overlay', PODS_URL . 'ui/js/codemirror/addon/mode/overlay.js', array( 'pods-codemirror' ), '4.8', true );
@@ -271,24 +277,26 @@ class PodsInit {
271
  wp_register_script( 'pods-codemirror-mode-html', PODS_URL . 'ui/js/codemirror/mode/htmlmixed/htmlmixed.js', array( 'pods-codemirror' ), '4.8', true );
272
  wp_register_script( 'pods-codemirror-mode-css', PODS_URL . 'ui/js/codemirror/mode/css/css.js', array( 'pods-codemirror' ), '4.8', true );
273
 
274
- if ( ! wp_style_is( 'jquery-ui-timepicker', 'registered' ) ) {
275
- wp_register_style( 'jquery-ui-timepicker', PODS_URL . 'ui/css/jquery.ui.timepicker.css', array(), '1.1.1' );
 
276
  }
277
 
278
  if ( ! wp_script_is( 'jquery-ui-timepicker', 'registered' ) ) {
279
- wp_register_script( 'jquery-ui-timepicker', PODS_URL . 'ui/js/jquery.ui.timepicker.min.js', array(
280
  'jquery',
281
  'jquery-ui-core',
282
  'jquery-ui-datepicker',
283
- 'jquery-ui-slider'
284
- ), '1.1.1' );
 
 
 
 
285
  }
286
 
287
- wp_register_style( 'pods-attach', PODS_URL . 'ui/css/jquery.pods.attach.css', array(), PODS_VERSION );
288
- wp_register_script( 'pods-attach', PODS_URL . 'ui/js/jquery.pods.attach.js', array(), PODS_VERSION );
289
-
290
- wp_register_style( 'pods-select2', PODS_URL . 'ui/js/select2/select2.css', array(), '3.3.1' );
291
- wp_register_script( 'pods-select2', PODS_URL . 'ui/js/select2/select2.min.js', array( 'jquery' ), '3.3.1' );
292
 
293
  $register_handlebars = apply_filters( 'pods_script_register_handlebars', true );
294
 
@@ -305,6 +313,45 @@ class PodsInit {
305
  wp_register_script( 'pods-handlebars', PODS_URL . 'ui/js/handlebars.js', array(), '1.0.0.beta.6' );
306
  }
307
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  }
309
 
310
  /**
@@ -366,6 +413,9 @@ class PodsInit {
366
  return;
367
  }
368
 
 
 
 
369
  $post_types = PodsMeta::$post_types;
370
  $taxonomies = PodsMeta::$taxonomies;
371
 
@@ -411,59 +461,75 @@ class PodsInit {
411
  $post_format_post_types = array();
412
 
413
  foreach ( $post_types as $post_type ) {
414
- // Post Type exists already
415
  if ( isset( $pods_cpt_ct['post_types'][ $post_type['name'] ] ) ) {
 
416
  continue;
417
  } elseif ( ! empty( $post_type['object'] ) && isset( $existing_post_types[ $post_type['object'] ] ) ) {
 
 
418
  continue;
419
  } elseif ( ! $force && isset( $existing_post_types[ $post_type['name'] ] ) ) {
 
420
  continue;
421
  }
422
 
423
  $post_type['options']['name'] = $post_type['name'];
424
  $post_type = array_merge( $post_type, (array) $post_type['options'] );
425
 
426
- $post_type_name = pods_var( 'name', $post_type );
427
 
428
  // Labels
429
- $cpt_label = esc_html( pods_var_raw( 'label', $post_type, ucwords( str_replace( '_', ' ', pods_var_raw( 'name', $post_type ) ) ), null, true ) );
430
- $cpt_singular = esc_html( pods_var_raw( 'label_singular', $post_type, ucwords( str_replace( '_', ' ', pods_var_raw( 'label', $post_type, $post_type_name, null, true ) ) ), null, true ) );
431
-
432
- $cpt_labels = array();
433
- $cpt_labels['name'] = $cpt_label;
434
- $cpt_labels['singular_name'] = $cpt_singular;
435
- $cpt_labels['menu_name'] = pods_var_raw( 'menu_name', $post_type, '', null, true );
436
- $cpt_labels['add_new'] = pods_var_raw( 'label_add_new', $post_type, '', null, true );
437
- $cpt_labels['add_new_item'] = pods_var_raw( 'label_add_new_item', $post_type, '', null, true );
438
- $cpt_labels['new_item'] = pods_var_raw( 'label_new_item', $post_type, '', null, true );
439
- $cpt_labels['edit'] = pods_var_raw( 'label_edit', $post_type, '', null, true );
440
- $cpt_labels['edit_item'] = pods_var_raw( 'label_edit_item', $post_type, '', null, true );
441
- $cpt_labels['view'] = pods_var_raw( 'label_view', $post_type, '', null, true );
442
- $cpt_labels['view_item'] = pods_var_raw( 'label_view_item', $post_type, '', null, true );
443
- $cpt_labels['all_items'] = pods_var_raw( 'label_all_items', $post_type, '', null, true );
444
- $cpt_labels['search_items'] = pods_var_raw( 'label_search_items', $post_type, '', null, true );
445
- $cpt_labels['not_found'] = pods_var_raw( 'label_not_found', $post_type, '', null, true );
446
- $cpt_labels['not_found_in_trash'] = pods_var_raw( 'label_not_found_in_trash', $post_type, '', null, true );
447
- $cpt_labels['parent'] = pods_var_raw( 'label_parent', $post_type, '', null, true );
448
- $cpt_labels['parent_item_colon'] = pods_var_raw( 'label_parent_item_colon', $post_type, '', null, true );
 
 
 
 
 
 
 
 
 
 
 
 
 
449
 
450
  // Supported
451
  $cpt_supported = array(
452
- 'title' => (boolean) pods_var( 'supports_title', $post_type, false ),
453
- 'editor' => (boolean) pods_var( 'supports_editor', $post_type, false ),
454
- 'author' => (boolean) pods_var( 'supports_author', $post_type, false ),
455
- 'thumbnail' => (boolean) pods_var( 'supports_thumbnail', $post_type, false ),
456
- 'excerpt' => (boolean) pods_var( 'supports_excerpt', $post_type, false ),
457
- 'trackbacks' => (boolean) pods_var( 'supports_trackbacks', $post_type, false ),
458
- 'custom-fields' => (boolean) pods_var( 'supports_custom_fields', $post_type, false ),
459
- 'comments' => (boolean) pods_var( 'supports_comments', $post_type, false ),
460
- 'revisions' => (boolean) pods_var( 'supports_revisions', $post_type, false ),
461
- 'page-attributes' => (boolean) pods_var( 'supports_page_attributes', $post_type, false ),
462
- 'post-formats' => (boolean) pods_var( 'supports_post_formats', $post_type, false )
463
  );
464
 
465
  // Custom Supported
466
- $cpt_supported_custom = pods_var( 'supports_custom', $post_type, '' );
467
 
468
  if ( ! empty( $cpt_supported_custom ) ) {
469
  $cpt_supported_custom = explode( ',', $cpt_supported_custom );
@@ -492,13 +558,8 @@ class PodsInit {
492
  $cpt_supported['supports_jetpack_markdown'] = (boolean) pods_var( 'supports_jetpack_markdown', $post_type, false );
493
  }
494
 
495
- // WP needs something, if this was empty and none were enabled, it would show title+editor pre 3.5 :(
496
  $cpt_supports = array();
497
 
498
- if ( ! pods_version_check( 'wp', '3.5' ) ) {
499
- $cpt_supports = array( '_bug_fix_pre_35' );
500
- }
501
-
502
  foreach ( $cpt_supported as $cpt_support => $supported ) {
503
  if ( true === $supported ) {
504
  $cpt_supports[] = $cpt_support;
@@ -509,7 +570,7 @@ class PodsInit {
509
  }
510
  }
511
 
512
- if ( empty( $cpt_supports ) && pods_version_check( 'wp', '3.5' ) ) {
513
  $cpt_supports = false;
514
  }
515
 
@@ -571,6 +632,17 @@ class PodsInit {
571
  'can_export' => (boolean) pods_var( 'can_export', $post_type, true )
572
  );
573
 
 
 
 
 
 
 
 
 
 
 
 
574
  // YARPP doesn't use 'supports' array option (yet)
575
  if ( ! empty( $cpt_supports['yarpp_support'] ) ) {
576
  $pods_post_types[ $post_type_name ]['yarpp_support'] = true;
@@ -622,12 +694,15 @@ class PodsInit {
622
  }
623
 
624
  foreach ( $taxonomies as $taxonomy ) {
625
- // Taxonomy Type exists already
626
  if ( isset( $pods_cpt_ct['taxonomies'][ $taxonomy['name'] ] ) ) {
 
627
  continue;
628
  } elseif ( ! empty( $taxonomy['object'] ) && isset( $existing_taxonomies[ $taxonomy['object'] ] ) ) {
 
 
629
  continue;
630
  } elseif ( ! $force && isset( $existing_taxonomies[ $taxonomy['name'] ] ) ) {
 
631
  continue;
632
  }
633
 
@@ -637,25 +712,30 @@ class PodsInit {
637
  $taxonomy_name = pods_var( 'name', $taxonomy );
638
 
639
  // Labels
640
- $ct_label = esc_html( pods_var_raw( 'label', $taxonomy, ucwords( str_replace( '_', ' ', pods_var_raw( 'name', $taxonomy ) ) ), null, true ) );
641
- $ct_singular = esc_html( pods_var_raw( 'label_singular', $taxonomy, ucwords( str_replace( '_', ' ', pods_var_raw( 'label', $taxonomy, pods_var_raw( 'name', $taxonomy ), null, true ) ) ), null, true ) );
642
 
643
  $ct_labels = array();
644
  $ct_labels['name'] = $ct_label;
645
  $ct_labels['singular_name'] = $ct_singular;
646
- $ct_labels['menu_name'] = pods_var_raw( 'menu_name', $taxonomy, '', null, true );
647
- $ct_labels['search_items'] = pods_var_raw( 'label_search_items', $taxonomy, '', null, true );
648
- $ct_labels['popular_items'] = pods_var_raw( 'label_popular_items', $taxonomy, '', null, true );
649
- $ct_labels['all_items'] = pods_var_raw( 'label_all_items', $taxonomy, '', null, true );
650
- $ct_labels['parent_item'] = pods_var_raw( 'label_parent_item', $taxonomy, '', null, true );
651
- $ct_labels['parent_item_colon'] = pods_var_raw( 'label_parent_item_colon', $taxonomy, '', null, true );
652
- $ct_labels['edit_item'] = pods_var_raw( 'label_edit_item', $taxonomy, '', null, true );
653
- $ct_labels['update_item'] = pods_var_raw( 'label_update_item', $taxonomy, '', null, true );
654
- $ct_labels['add_new_item'] = pods_var_raw( 'label_add_new_item', $taxonomy, '', null, true );
655
- $ct_labels['new_item_name'] = pods_var_raw( 'label_new_item_name', $taxonomy, '', null, true );
656
- $ct_labels['separate_items_with_commas'] = pods_var_raw( 'label_separate_items_with_commas', $taxonomy, '', null, true );
657
- $ct_labels['add_or_remove_items'] = pods_var_raw( 'label_add_or_remove_items', $taxonomy, '', null, true );
658
- $ct_labels['choose_from_most_used'] = pods_var_raw( 'label_choose_from_the_most_used', $taxonomy, '', null, true );
 
 
 
 
 
659
 
660
  // Rewrite
661
  $ct_rewrite = (boolean) pods_var( 'rewrite', $taxonomy, true );
@@ -700,10 +780,12 @@ class PodsInit {
700
  'label' => $ct_label,
701
  'labels' => $ct_labels,
702
  'public' => (boolean) pods_var( 'public', $taxonomy, true ),
703
- 'show_in_nav_menus' => (boolean) pods_var( 'show_in_nav_menus', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
704
  'show_ui' => (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
705
  'show_in_menu' => (boolean) pods_var( 'show_in_menu', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
 
706
  'show_tagcloud' => (boolean) pods_var( 'show_tagcloud', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ),
 
 
707
  'hierarchical' => (boolean) pods_var( 'hierarchical', $taxonomy, false ),
708
  //'capability_type' => $capability_type,
709
  'capabilities' => $tax_capabilities,
@@ -712,7 +794,7 @@ class PodsInit {
712
  'query_var' => ( false !== (boolean) pods_var( 'query_var', $taxonomy, true ) ? pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true ) : false ),
713
  'rewrite' => $ct_rewrite,
714
  'show_admin_column' => (boolean) pods_var( 'show_admin_column', $taxonomy, false ),
715
- 'sort' => (boolean) pods_var( 'sort', $taxonomy, false )
716
  );
717
 
718
  if ( is_array( $ct_rewrite ) && ! $pods_taxonomies[ $taxonomy_name ]['query_var'] ) {
@@ -724,6 +806,17 @@ class PodsInit {
724
  $pods_taxonomies[ $taxonomy_name ]['query_var'] = 'taxonomy_' . $pods_taxonomies[ $taxonomy_name ]['query_var'];
725
  }
726
 
 
 
 
 
 
 
 
 
 
 
 
727
  // Integration for Single Value Taxonomy UI
728
  if ( function_exists( 'tax_single_value_meta_box' ) ) {
729
  $pods_taxonomies[ $taxonomy_name ]['single_value'] = (boolean) pods_var( 'single_value', $taxonomy, false );
@@ -797,11 +890,17 @@ class PodsInit {
797
  $ct_post_types = $options['post_types'];
798
  $options = $options['options'];
799
 
800
- $options = apply_filters( 'pods_register_taxonomy_' . $taxonomy, $options, $taxonomy );
801
- $options = apply_filters( 'pods_register_taxonomy', $options, $taxonomy );
802
-
803
  $options = self::object_label_fix( $options, 'taxonomy' );
804
 
 
 
 
 
 
 
 
 
 
805
  // Max length for taxonomies are 32 characters
806
  $taxonomy = substr( $taxonomy, 0, 32 );
807
 
@@ -810,12 +909,34 @@ class PodsInit {
810
  $options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL taxonomy slug', 'pods' );
811
  }
812
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
813
  if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
814
- pods_debug( array( $taxonomy, $ct_post_types, $options ) );
815
  }
816
 
817
  register_taxonomy( $taxonomy, $ct_post_types, $options );
818
 
 
 
 
 
819
  if ( ! isset( self::$content_types_registered['taxonomies'] ) ) {
820
  self::$content_types_registered['taxonomies'] = array();
821
  }
@@ -828,9 +949,6 @@ class PodsInit {
828
  continue;
829
  }
830
 
831
- $options = apply_filters( 'pods_register_post_type_' . $post_type, $options, $post_type );
832
- $options = apply_filters( 'pods_register_post_type', $options, $post_type );
833
-
834
  $options = self::object_label_fix( $options, 'post_type' );
835
 
836
  // Max length for post types are 20 characters
@@ -841,8 +959,24 @@ class PodsInit {
841
  $options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL slug', 'pods' );
842
  }
843
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
844
  if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
845
- pods_debug( array( $post_type, $options ) );
846
  }
847
 
848
  register_post_type( $post_type, $options );
@@ -852,6 +986,10 @@ class PodsInit {
852
  register_taxonomy_for_object_type( 'post_format', $post_type );
853
  }
854
 
 
 
 
 
855
  if ( ! isset( self::$content_types_registered['post_types'] ) ) {
856
  self::$content_types_registered['post_types'] = array();
857
  }
@@ -859,6 +997,94 @@ class PodsInit {
859
  self::$content_types_registered['post_types'][] = $post_type;
860
  }
861
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
862
  }
863
 
864
  /**
@@ -965,8 +1191,8 @@ class PodsInit {
965
  $args['labels'] = array();
966
  }
967
 
968
- $label = pods_var_raw( 'name', $args['labels'], pods_var_raw( 'label', $args, __( 'Items', 'pods' ), null, true ), null, true );
969
- $singular_label = pods_var_raw( 'singular_name', $args['labels'], pods_var_raw( 'label_singular', $args, __( 'Item', 'pods' ), null, true ), null, true );
970
 
971
  $labels = $args['labels'];
972
 
@@ -974,47 +1200,52 @@ class PodsInit {
974
  $labels['singular_name'] = $singular_label;
975
 
976
  if ( 'post_type' == $type ) {
977
- $labels['menu_name'] = pods_var_raw( 'menu_name', $labels, $label, null, true );
978
- $labels['add_new'] = pods_var_raw( 'add_new', $labels, __( 'Add New', 'pods' ), null, true );
979
- $labels['add_new_item'] = pods_var_raw( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), null, true );
980
- $labels['new_item'] = pods_var_raw( 'new_item', $labels, sprintf( __( 'New %s', 'pods' ), $singular_label ), null, true );
981
- $labels['edit'] = pods_var_raw( 'edit', $labels, __( 'Edit', 'pods' ), null, true );
982
- $labels['edit_item'] = pods_var_raw( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), null, true );
983
- $labels['view'] = pods_var_raw( 'view', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), null, true );
984
- $labels['view_item'] = pods_var_raw( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), null, true );
985
- $labels['all_items'] = pods_var_raw( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), null, true );
986
- $labels['search_items'] = pods_var_raw( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), null, true );
987
- $labels['not_found'] = pods_var_raw( 'not_found', $labels, sprintf( __( 'No %s Found', 'pods' ), $label ), null, true );
988
- $labels['not_found_in_trash'] = pods_var_raw( 'not_found_in_trash', $labels, sprintf( __( 'No %s Found in Trash', 'pods' ), $label ), null, true );
989
- $labels['parent'] = pods_var_raw( 'parent', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), null, true );
990
- $labels['parent_item_colon'] = pods_var_raw( 'parent_item_colon', $labels, sprintf( __( 'Parent %s:', 'pods' ), $singular_label ), null, true );
991
- $labels['feature_image'] = pods_var_raw( 'feature_image', $labels, __( 'Featured Image', 'pods' ), null, true );
992
- $labels['set_featured_image'] = pods_var_raw( 'set_featured_image', $labels, __( 'Set featured image', 'pods' ), null, true );
993
- $labels['remove_featured_image'] = pods_var_raw( 'remove_featured_image', $labels, __( 'Remove featured image', 'pods' ), null, true );
994
- $labels['use_featured_image'] = pods_var_raw( 'use_featured_image', $labels, __( 'Use as featured image', 'pods' ), null, true );
995
- $labels['archives'] = pods_var_raw( 'archives', $labels, sprintf( __( '%s Archives', 'pods' ), $singular_label ), null, true );
996
- $labels['insert_into_item'] = pods_var_raw( 'insert_into_item', $labels, sprintf( __( 'Insert into %s', 'pods' ), $singular_label ), null, true );
997
- $labels['uploaded_to_this_item'] = pods_var_raw( 'uploaded_to_this_item', $labels, sprintf( __( 'Uploaded to this %s', 'pods' ), $singular_label ), null, true );
998
- $labels['filter_items_list'] = pods_var_raw( 'filter_items_list', $labels, sprintf( __( 'Filter %s lists', 'pods' ), $label ), null, true );
999
- $labels['items_list_navigation'] = pods_var_raw( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), null, true );
1000
- $labels['items_list'] = pods_var_raw( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), null, true );
 
 
 
1001
  } elseif ( 'taxonomy' == $type ) {
1002
- $labels['menu_name'] = pods_var_raw( 'menu_name', $labels, $label, null, true );
1003
- $labels['search_items'] = pods_var_raw( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), null, true );
1004
- $labels['popular_items'] = pods_var_raw( 'popular_items', $labels, sprintf( __( 'Popular %s', 'pods' ), $label ), null, true );
1005
- $labels['all_items'] = pods_var_raw( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), null, true );
1006
- $labels['parent_item'] = pods_var_raw( 'parent_item', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), null, true );
1007
- $labels['parent_item_colon'] = pods_var_raw( 'parent_item_colon', $labels, sprintf( __( 'Parent %s :', 'pods' ), $singular_label ), null, true );
1008
- $labels['edit_item'] = pods_var_raw( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), null, true );
1009
- $labels['update_item'] = pods_var_raw( 'update_item', $labels, sprintf( __( 'Update %s', 'pods' ), $singular_label ), null, true );
1010
- $labels['add_new_item'] = pods_var_raw( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), null, true );
1011
- $labels['new_item_name'] = pods_var_raw( 'new_item_name', $labels, sprintf( __( 'New %s Name', 'pods' ), $singular_label ), null, true );
1012
- $labels['separate_items_with_commas'] = pods_var_raw( 'separate_items_with_commas', $labels, sprintf( __( 'Separate %s with commas', 'pods' ), $label ), null, true );
1013
- $labels['add_or_remove_items'] = pods_var_raw( 'add_or_remove_items', $labels, sprintf( __( 'Add or remove %s', 'pods' ), $label ), null, true );
1014
- $labels['choose_from_most_used'] = pods_var_raw( 'choose_from_most_used', $labels, sprintf( __( 'Choose from the most used %s', 'pods' ), $label ), null, true );
1015
- $labels['no_terms'] = pods_var_raw( 'no_terms', $labels, sprintf( __( 'No %s', 'pods' ), $label ), null, true );
1016
- $labels['items_list_navigation'] = pods_var_raw( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), null, true );
1017
- $labels['items_list'] = pods_var_raw( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), null, true );
 
 
1018
  }
1019
 
1020
  $args['labels'] = $labels;
@@ -1291,6 +1522,8 @@ class PodsInit {
1291
 
1292
  $ran = true;
1293
 
 
 
1294
  if ( ! did_action( 'plugins_loaded' ) ) {
1295
  add_action( 'plugins_loaded', array( $this, 'load_components' ), 11 );
1296
  } else {
@@ -1305,7 +1538,6 @@ class PodsInit {
1305
 
1306
  if ( ! did_action( 'init' ) ) {
1307
  add_action( 'init', array( $this, 'core' ), 11 );
1308
- add_action( 'init', array( $this, 'add_rest_support' ), 12 );
1309
  add_action( 'init', array( $this, 'setup_content_types' ), 11 );
1310
 
1311
  if ( is_admin() ) {
@@ -1313,7 +1545,6 @@ class PodsInit {
1313
  }
1314
  } else {
1315
  $this->core();
1316
- $this->add_rest_support();
1317
  $this->setup_content_types();
1318
 
1319
  if ( is_admin() ) {
@@ -1512,74 +1743,4 @@ class PodsInit {
1512
  }
1513
 
1514
  }
1515
-
1516
- /**
1517
- * Add REST API support to post type and taxonomy objects.
1518
- *
1519
- * @uses "init"
1520
- *
1521
- * @since 2.5.6
1522
- */
1523
- public function add_rest_support() {
1524
-
1525
- if ( empty( self::$version ) ) {
1526
- return;
1527
- }
1528
-
1529
- static $rest_support_added;
1530
-
1531
- if ( ! function_exists( 'register_rest_field' ) ) {
1532
- return;
1533
- }
1534
-
1535
- include_once( PODS_DIR . 'classes/PodsRESTFields.php' );
1536
- include_once( PODS_DIR . 'classes/PodsRESTHandlers.php' );
1537
-
1538
- $rest_bases = pods_transient_get( 'pods_rest_bases' );
1539
-
1540
- if ( empty( $rest_bases ) ) {
1541
- $pods = pods_api()->load_pods( array( 'type' => array( 'post_type', 'taxonomy', 'user', 'media', 'comment' ), 'fields' => false, 'table_info' => false ) );
1542
-
1543
- $rest_bases = array();
1544
-
1545
- if ( ! empty( $pods ) && is_array( $pods ) ) {
1546
- foreach ( $pods as $pod ) {
1547
- $type = $pod['type'];
1548
-
1549
- if ( in_array( $type, array( 'post_type', 'taxonomy', 'user', 'media', 'comment' ) ) ) {
1550
- if ( $pod && PodsRESTHandlers::pod_extends_core_route( $pod ) ) {
1551
- $rest_bases[ $pod['name'] ] = array(
1552
- 'type' => $type,
1553
- 'base' => sanitize_title( pods_v( 'rest_base', $pod['options'], $pod['name'] ) ),
1554
- );
1555
- }
1556
- }
1557
- }
1558
- }
1559
-
1560
- if ( empty( $rest_bases ) ) {
1561
- $rest_bases = 'none';
1562
- }
1563
-
1564
- pods_transient_set( 'pods_rest_bases', $rest_bases );
1565
- }
1566
-
1567
- if ( empty( $rest_support_added ) && ! empty( $rest_bases ) && 'none' !== $rest_bases ) {
1568
- foreach ( $rest_bases as $pod_name => $pod_info ) {
1569
- $pod_type = $pod_info['type'];
1570
- $rest_base = $pod_info['base'];
1571
-
1572
- if ( 'post_type' == $pod_type ) {
1573
- PodsRESTHandlers::post_type_rest_support( $pod_name, $rest_base );
1574
- } elseif ( 'taxonomy' == $pod_type ) {
1575
- PodsRESTHandlers::taxonomy_rest_support( $pod_name, $rest_base );
1576
- }
1577
-
1578
- new PodsRESTFields( $pod_name );
1579
- }
1580
-
1581
- $rest_support_added = true;
1582
- }
1583
-
1584
- }
1585
  }
29
  */
30
  static $meta;
31
 
32
+ /**
33
+ * @var PodsI18n
34
+ */
35
+ static $i18n;
36
+
37
  /**
38
  * @var PodsAdmin
39
  */
174
  self::$meta = pods_meta()->core();
175
  }
176
 
177
+ /**
178
+ *
179
+ */
180
+ public function load_i18n() {
181
+
182
+ self::$i18n = pods_i18n();
183
+ }
184
+
185
+
186
  /**
187
  * Set up the Pods core
188
  */
251
  */
252
  public function register_assets() {
253
 
254
+ $maybe_min = SCRIPT_DEBUG ? '' : '.min';
 
 
255
 
256
  wp_register_script( 'pods-json', PODS_URL . 'ui/js/jquery.json.js', array( 'jquery' ), '2.3' );
257
 
 
 
 
 
258
  if ( ! wp_script_is( 'jquery-qtip2', 'registered' ) ) {
259
  wp_register_script( 'jquery-qtip2', PODS_URL . 'ui/js/jquery.qtip.min.js', array( 'jquery' ), '2.2' );
260
  }
261
 
262
  wp_register_script( 'pods', PODS_URL . 'ui/js/jquery.pods.js', array(
263
  'jquery',
264
+ 'pods-dfv',
265
+ 'pods-i18n',
266
  'pods-json',
267
  'jquery-qtip2'
268
+ ), PODS_VERSION, true );
269
 
 
 
 
270
  wp_register_script( 'pods-cleditor', PODS_URL . 'ui/js/jquery.cleditor.min.js', array( 'jquery' ), '1.3.0' );
271
 
 
272
  wp_register_script( 'pods-codemirror', PODS_URL . 'ui/js/codemirror.js', array(), '4.8', true );
273
  wp_register_script( 'pods-codemirror-loadmode', PODS_URL . 'ui/js/codemirror/addon/mode/loadmode.js', array( 'pods-codemirror' ), '4.8', true );
274
  wp_register_script( 'pods-codemirror-overlay', PODS_URL . 'ui/js/codemirror/addon/mode/overlay.js', array( 'pods-codemirror' ), '4.8', true );
277
  wp_register_script( 'pods-codemirror-mode-html', PODS_URL . 'ui/js/codemirror/mode/htmlmixed/htmlmixed.js', array( 'pods-codemirror' ), '4.8', true );
278
  wp_register_script( 'pods-codemirror-mode-css', PODS_URL . 'ui/js/codemirror/mode/css/css.js', array( 'pods-codemirror' ), '4.8', true );
279
 
280
+ if ( ! wp_script_is( 'jquery-ui-slideraccess', 'registered' ) ) {
281
+ // No need to add dependencies. All managed by jquery-ui-timepicker.
282
+ wp_register_script( 'jquery-ui-slideraccess', PODS_URL . 'ui/js/timepicker/jquery-ui-sliderAccess.js', array(), '0.3' );
283
  }
284
 
285
  if ( ! wp_script_is( 'jquery-ui-timepicker', 'registered' ) ) {
286
+ wp_register_script( 'jquery-ui-timepicker', PODS_URL . 'ui/js/timepicker/jquery-ui-timepicker-addon.min.js', array(
287
  'jquery',
288
  'jquery-ui-core',
289
  'jquery-ui-datepicker',
290
+ 'jquery-ui-slider',
291
+ 'jquery-ui-slideraccess',
292
+ ), '1.6.3' );
293
+ }
294
+ if ( ! wp_style_is( 'jquery-ui-timepicker', 'registered' ) ) {
295
+ wp_register_style( 'jquery-ui-timepicker', PODS_URL . 'ui/js/timepicker/jquery-ui-timepicker-addon.min.css', array(), '1.6.3' );
296
  }
297
 
298
+ wp_register_script( 'pods-select2', PODS_URL . "ui/js/selectWoo/selectWoo{$maybe_min}.js", array( 'jquery', 'pods-i18n' ), '1.0.1' );
299
+ wp_register_style( 'pods-select2', PODS_URL . "ui/js/selectWoo/selectWoo{$maybe_min}.css", array(), '1.0.1' );
 
 
 
300
 
301
  $register_handlebars = apply_filters( 'pods_script_register_handlebars', true );
302
 
313
  wp_register_script( 'pods-handlebars', PODS_URL . 'ui/js/handlebars.js', array(), '1.0.0.beta.6' );
314
  }
315
 
316
+ // Marionette dependencies for MV fields
317
+ wp_register_script( 'backbone.radio', PODS_URL . 'ui/js/marionette/backbone.radio.js', array( 'backbone' ), '2.0.0', true );
318
+ wp_register_script( 'marionette', PODS_URL . 'ui/js/marionette/backbone.marionette.js', array( 'backbone', 'backbone.radio' ), '3.1.0', true );
319
+
320
+ // MV stuff
321
+ wp_register_script(
322
+ 'pods-dfv',
323
+ PODS_URL . 'ui/js/pods-dfv/pods-dfv.min.js',
324
+ array(
325
+ 'jquery',
326
+ 'jquery-ui-core',
327
+ 'jquery-ui-sortable',
328
+ 'pods-i18n',
329
+ 'marionette',
330
+ 'media-views',
331
+ 'media-models'
332
+ ),
333
+ PODS_VERSION,
334
+ true
335
+ );
336
+
337
+ // Check if Pod is a Modal Window
338
+ if ( pods_is_modal_window() ) {
339
+
340
+ function add_classes_to_body_class( $classes ) {
341
+ $classes .= 'pods-modal-window';
342
+
343
+ return $classes;
344
+ }
345
+
346
+ add_filter( 'body_class', 'add_classes_to_body_class' );
347
+ add_filter( 'admin_body_class', 'add_classes_to_body_class' );
348
+ }
349
+
350
+ // As of 2.7 we combine styles to just three .css files
351
+ wp_register_style( 'pods-styles', PODS_URL . 'ui/styles/dist/pods.css', array(), PODS_VERSION );
352
+ wp_register_style( 'pods-wizard', PODS_URL . 'ui/styles/dist/pods-wizard.css', array(), PODS_VERSION );
353
+ wp_register_style( 'pods-form', PODS_URL . 'ui/styles/dist/pods-form.css', array(), PODS_VERSION );
354
+
355
  }
356
 
357
  /**
413
  return;
414
  }
415
 
416
+ require_once( PODS_DIR . 'classes/PodsRESTHandlers.php' );
417
+ require_once( PODS_DIR . 'classes/PodsRESTFields.php' );
418
+
419
  $post_types = PodsMeta::$post_types;
420
  $taxonomies = PodsMeta::$taxonomies;
421
 
461
  $post_format_post_types = array();
462
 
463
  foreach ( $post_types as $post_type ) {
 
464
  if ( isset( $pods_cpt_ct['post_types'][ $post_type['name'] ] ) ) {
465
+ // Post type was setup already
466
  continue;
467
  } elseif ( ! empty( $post_type['object'] ) && isset( $existing_post_types[ $post_type['object'] ] ) ) {
468
+ // Post type exists already
469
+
470
  continue;
471
  } elseif ( ! $force && isset( $existing_post_types[ $post_type['name'] ] ) ) {
472
+ // Post type was setup and exists already, but we aren't forcing it to be setup again
473
  continue;
474
  }
475
 
476
  $post_type['options']['name'] = $post_type['name'];
477
  $post_type = array_merge( $post_type, (array) $post_type['options'] );
478
 
479
+ $post_type_name = pods_v_sanitized( 'name', $post_type );
480
 
481
  // Labels
482
+ $cpt_label = esc_html( pods_v( 'label', $post_type, ucwords( str_replace( '_', ' ', pods_v( 'name', $post_type ) ) ), true ) );
483
+ $cpt_singular = esc_html( pods_v( 'label_singular', $post_type, ucwords( str_replace( '_', ' ', pods_v( 'label', $post_type, $post_type_name, null, true ) ) ), true ) );
484
+
485
+ $cpt_labels = array();
486
+ $cpt_labels['name'] = $cpt_label;
487
+ $cpt_labels['singular_name'] = $cpt_singular;
488
+ $cpt_labels['menu_name'] = pods_v( 'menu_name', $post_type, '', true );
489
+ $cpt_labels['name_admin_bar'] = pods_v( 'name_admin_bar', $post_type, '', true );
490
+ $cpt_labels['add_new'] = pods_v( 'label_add_new', $post_type, '', true );
491
+ $cpt_labels['add_new_item'] = pods_v( 'label_add_new_item', $post_type, '', true );
492
+ $cpt_labels['new_item'] = pods_v( 'label_new_item', $post_type, '', true );
493
+ $cpt_labels['edit'] = pods_v( 'label_edit', $post_type, '', true );
494
+ $cpt_labels['edit_item'] = pods_v( 'label_edit_item', $post_type, '', true );
495
+ $cpt_labels['view'] = pods_v( 'label_view', $post_type, '', true );
496
+ $cpt_labels['view_item'] = pods_v( 'label_view_item', $post_type, '', true );
497
+ $cpt_labels['view_items'] = pods_v( 'label_view_items', $post_type, '', true );
498
+ $cpt_labels['all_items'] = pods_v( 'label_all_items', $post_type, '', true );
499
+ $cpt_labels['search_items'] = pods_v( 'label_search_items', $post_type, '', true );
500
+ $cpt_labels['not_found'] = pods_v( 'label_not_found', $post_type, '', true );
501
+ $cpt_labels['not_found_in_trash'] = pods_v( 'label_not_found_in_trash', $post_type, '', true );
502
+ $cpt_labels['parent'] = pods_v( 'label_parent', $post_type, '', true );
503
+ $cpt_labels['parent_item_colon'] = pods_v( 'label_parent_item_colon', $post_type, '', true );
504
+ $cpt_labels['archives'] = pods_v( 'label_archives', $post_type, '', true );
505
+ $cpt_labels['attributes'] = pods_v( 'label_attributes', $post_type, '', true );
506
+ $cpt_labels['insert_into_item'] = pods_v( 'label_insert_into_item', $post_type, '', true );
507
+ $cpt_labels['uploaded_to_this_item'] = pods_v( 'label_uploaded_to_this_item', $post_type, '', true );
508
+ $cpt_labels['featured_image'] = pods_v( 'label_featured_image', $post_type, '', true );
509
+ $cpt_labels['set_featured_image'] = pods_v( 'label_set_featured_image', $post_type, '', true );
510
+ $cpt_labels['remove_featured_image'] = pods_v( 'label_remove_featured_image', $post_type, '', true );
511
+ $cpt_labels['use_featured_image'] = pods_v( 'label_use_featured_image', $post_type, '', true );
512
+ $cpt_labels['filter_items_list'] = pods_v( 'label_filter_items_list', $post_type, '', true );
513
+ $cpt_labels['items_list_navigation'] = pods_v( 'label_items_list_navigation', $post_type, '', true );
514
+ $cpt_labels['items_list'] = pods_v( 'label_items_list', $post_type, '', true );
515
 
516
  // Supported
517
  $cpt_supported = array(
518
+ 'title' => (boolean) pods_v( 'supports_title', $post_type, false ),
519
+ 'editor' => (boolean) pods_v( 'supports_editor', $post_type, false ),
520
+ 'author' => (boolean) pods_v( 'supports_author', $post_type, false ),
521
+ 'thumbnail' => (boolean) pods_v( 'supports_thumbnail', $post_type, false ),
522
+ 'excerpt' => (boolean) pods_v( 'supports_excerpt', $post_type, false ),
523
+ 'trackbacks' => (boolean) pods_v( 'supports_trackbacks', $post_type, false ),
524
+ 'custom-fields' => (boolean) pods_v( 'supports_custom_fields', $post_type, false ),
525
+ 'comments' => (boolean) pods_v( 'supports_comments', $post_type, false ),
526
+ 'revisions' => (boolean) pods_v( 'supports_revisions', $post_type, false ),
527
+ 'page-attributes' => (boolean) pods_v( 'supports_page_attributes', $post_type, false ),
528
+ 'post-formats' => (boolean) pods_v( 'supports_post_formats', $post_type, false )
529
  );
530
 
531
  // Custom Supported
532
+ $cpt_supported_custom = pods_v_sanitized( 'supports_custom', $post_type, '' );
533
 
534
  if ( ! empty( $cpt_supported_custom ) ) {
535
  $cpt_supported_custom = explode( ',', $cpt_supported_custom );
558
  $cpt_supported['supports_jetpack_markdown'] = (boolean) pods_var( 'supports_jetpack_markdown', $post_type, false );
559
  }
560
 
 
561
  $cpt_supports = array();
562
 
 
 
 
 
563
  foreach ( $cpt_supported as $cpt_support => $supported ) {
564
  if ( true === $supported ) {
565
  $cpt_supports[] = $cpt_support;
570
  }
571
  }
572
 
573
+ if ( empty( $cpt_supports ) ) {
574
  $cpt_supports = false;
575
  }
576
 
632
  'can_export' => (boolean) pods_var( 'can_export', $post_type, true )
633
  );
634
 
635
+ // REST API
636
+ $rest_enabled = (boolean) pods_v( 'rest_enable', $post_type, false );
637
+
638
+ if ( $rest_enabled ) {
639
+ $rest_base = sanitize_title( pods_v( 'rest_base', $post_type, $post_type_name ) );
640
+
641
+ $pods_post_types[ $post_type_name ]['show_in_rest'] = true;
642
+ $pods_post_types[ $post_type_name ]['rest_base'] = $rest_base;
643
+ $pods_post_types[ $post_type_name ]['rest_controller_class'] = 'WP_REST_Posts_Controller';
644
+ }
645
+
646
  // YARPP doesn't use 'supports' array option (yet)
647
  if ( ! empty( $cpt_supports['yarpp_support'] ) ) {
648
  $pods_post_types[ $post_type_name ]['yarpp_support'] = true;
694
  }
695
 
696
  foreach ( $taxonomies as $taxonomy ) {
 
697
  if ( isset( $pods_cpt_ct['taxonomies'][ $taxonomy['name'] ] ) ) {
698
+ // Taxonomy was setup already
699
  continue;
700
  } elseif ( ! empty( $taxonomy['object'] ) && isset( $existing_taxonomies[ $taxonomy['object'] ] ) ) {
701
+ // Taxonomy exists already
702
+
703
  continue;
704
  } elseif ( ! $force && isset( $existing_taxonomies[ $taxonomy['name'] ] ) ) {
705
+ // Taxonomy was setup and exists already, but we aren't forcing it to be setup again
706
  continue;
707
  }
708
 
712
  $taxonomy_name = pods_var( 'name', $taxonomy );
713
 
714
  // Labels
715
+ $ct_label = esc_html( pods_v( 'label', $taxonomy, ucwords( str_replace( '_', ' ', pods_v( 'name', $taxonomy ) ) ), true ) );
716
+ $ct_singular = esc_html( pods_v( 'label_singular', $taxonomy, ucwords( str_replace( '_', ' ', pods_v( 'label', $taxonomy, pods_v( 'name', $taxonomy ), null, true ) ) ), true ) );
717
 
718
  $ct_labels = array();
719
  $ct_labels['name'] = $ct_label;
720
  $ct_labels['singular_name'] = $ct_singular;
721
+ $ct_labels['menu_name'] = pods_v( 'menu_name', $taxonomy, '', true );
722
+ $ct_labels['search_items'] = pods_v( 'label_search_items', $taxonomy, '', true );
723
+ $ct_labels['popular_items'] = pods_v( 'label_popular_items', $taxonomy, '', true );
724
+ $ct_labels['all_items'] = pods_v( 'label_all_items', $taxonomy, '', true );
725
+ $ct_labels['parent_item'] = pods_v( 'label_parent_item', $taxonomy, '', true );
726
+ $ct_labels['parent_item_colon'] = pods_v( 'label_parent_item_colon', $taxonomy, '', true );
727
+ $ct_labels['edit_item'] = pods_v( 'label_edit_item', $taxonomy, '', true );
728
+ $ct_labels['update_item'] = pods_v( 'label_update_item', $taxonomy, '', true );
729
+ $ct_labels['view_item'] = pods_v( 'label_view_item', $taxonomy, '', true );
730
+ $ct_labels['add_new_item'] = pods_v( 'label_add_new_item', $taxonomy, '', true );
731
+ $ct_labels['new_item_name'] = pods_v( 'label_new_item_name', $taxonomy, '', true );
732
+ $ct_labels['separate_items_with_commas'] = pods_v( 'label_separate_items_with_commas', $taxonomy, '', true );
733
+ $ct_labels['add_or_remove_items'] = pods_v( 'label_add_or_remove_items', $taxonomy, '', true );
734
+ $ct_labels['choose_from_most_used'] = pods_v( 'label_choose_from_the_most_used', $taxonomy, '', true );
735
+ $ct_labels['not_found'] = pods_v( 'label_not_found', $taxonomy, '', true );
736
+ $ct_labels['no_terms'] = pods_v( 'label_no_terms', $taxonomy, '', true );
737
+ $ct_labels['items_list'] = pods_v( 'label_items_list', $taxonomy, '', true );
738
+ $ct_labels['items_list_navigation'] = pods_v( 'label_items_list_navigation', $taxonomy, '', true );
739
 
740
  // Rewrite
741
  $ct_rewrite = (boolean) pods_var( 'rewrite', $taxonomy, true );
780
  'label' => $ct_label,
781
  'labels' => $ct_labels,
782
  'public' => (boolean) pods_var( 'public', $taxonomy, true ),
 
783
  'show_ui' => (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
784
  'show_in_menu' => (boolean) pods_var( 'show_in_menu', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
785
+ 'show_in_nav_menus' => (boolean) pods_var( 'show_in_nav_menus', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ),
786
  'show_tagcloud' => (boolean) pods_var( 'show_tagcloud', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ),
787
+ 'show_tagcloud_in_edit' => (boolean) pods_var( 'show_tagcloud_in_edit', $taxonomy, (boolean) pods_var( 'show_tagcloud', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ) ),
788
+ 'show_in_quick_edit' => (boolean) pods_var( 'show_in_quick_edit', $taxonomy, (boolean) pods_var( 'show_ui', $taxonomy, (boolean) pods_var( 'public', $taxonomy, true ) ) ),
789
  'hierarchical' => (boolean) pods_var( 'hierarchical', $taxonomy, false ),
790
  //'capability_type' => $capability_type,
791
  'capabilities' => $tax_capabilities,
794
  'query_var' => ( false !== (boolean) pods_var( 'query_var', $taxonomy, true ) ? pods_var( 'query_var_string', $taxonomy, $taxonomy_name, null, true ) : false ),
795
  'rewrite' => $ct_rewrite,
796
  'show_admin_column' => (boolean) pods_var( 'show_admin_column', $taxonomy, false ),
797
+ 'sort' => (boolean) pods_var( 'sort', $taxonomy, false ),
798
  );
799
 
800
  if ( is_array( $ct_rewrite ) && ! $pods_taxonomies[ $taxonomy_name ]['query_var'] ) {
806
  $pods_taxonomies[ $taxonomy_name ]['query_var'] = 'taxonomy_' . $pods_taxonomies[ $taxonomy_name ]['query_var'];
807
  }
808
 
809
+ // REST API
810
+ $rest_enabled = (boolean) pods_v( 'rest_enable', $taxonomy, false );
811
+
812
+ if ( $rest_enabled ) {
813
+ $rest_base = sanitize_title( pods_v( 'rest_base', $taxonomy, $taxonomy_name ) );
814
+
815
+ $pods_taxonomies[ $taxonomy_name ]['show_in_rest'] = true;
816
+ $pods_taxonomies[ $taxonomy_name ]['rest_base'] = $rest_base;
817
+ $pods_taxonomies[ $taxonomy_name ]['rest_controller_class'] = 'WP_REST_Terms_Controller';
818
+ }
819
+
820
  // Integration for Single Value Taxonomy UI
821
  if ( function_exists( 'tax_single_value_meta_box' ) ) {
822
  $pods_taxonomies[ $taxonomy_name ]['single_value'] = (boolean) pods_var( 'single_value', $taxonomy, false );
890
  $ct_post_types = $options['post_types'];
891
  $options = $options['options'];
892
 
 
 
 
893
  $options = self::object_label_fix( $options, 'taxonomy' );
894
 
895
+ /**
896
+ * Hide tagcloud compatibility
897
+ * @todo check https://core.trac.wordpress.org/ticket/36964
898
+ * @see wp-admin/edit-tags.php L389
899
+ */
900
+ if ( true != (boolean) pods_var( 'show_tagcloud_in_edit', $options, (boolean) pods_var( 'show_tagcloud', $options, true ) ) ) {
901
+ $options['labels']['popular_items'] = null;
902
+ }
903
+
904
  // Max length for taxonomies are 32 characters
905
  $taxonomy = substr( $taxonomy, 0, 32 );
906
 
909
  $options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL taxonomy slug', 'pods' );
910
  }
911
 
912
+ /**
913
+ * Allow filtering of taxonomy options per taxonomy.
914
+ *
915
+ * @param array $options Taxonomy options
916
+ * @param string $taxonomy Taxonomy name
917
+ * @param array $ct_post_types Associated Post Types
918
+ */
919
+ $options = apply_filters( 'pods_register_taxonomy_' . $taxonomy, $options, $taxonomy, $ct_post_types );
920
+
921
+ /**
922
+ * Allow filtering of taxonomy options.
923
+ *
924
+ * @param array $options Taxonomy options
925
+ * @param string $taxonomy Taxonomy name
926
+ * @param array $ct_post_types Associated post types
927
+ */
928
+ $options = apply_filters( 'pods_register_taxonomy', $options, $taxonomy, $ct_post_types );
929
+
930
  if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
931
+ pods_debug( array( 'register_taxonomy', compact( 'taxonomy', 'ct_post_types', 'options' ) ) );
932
  }
933
 
934
  register_taxonomy( $taxonomy, $ct_post_types, $options );
935
 
936
+ if ( ! empty( $options['show_in_rest'] ) ) {
937
+ new PodsRESTFields( $taxonomy );
938
+ }
939
+
940
  if ( ! isset( self::$content_types_registered['taxonomies'] ) ) {
941
  self::$content_types_registered['taxonomies'] = array();
942
  }
949
  continue;
950
  }
951
 
 
 
 
952
  $options = self::object_label_fix( $options, 'post_type' );
953
 
954
  // Max length for post types are 20 characters
959
  $options['rewrite']['slug'] = _x( $options['rewrite']['slug'], 'URL slug', 'pods' );
960
  }
961
 
962
+ /**
963
+ * Allow filtering of post type options per post type.
964
+ *
965
+ * @param array $options Post type options
966
+ * @param string $post_type Post type name
967
+ */
968
+ $options = apply_filters( 'pods_register_post_type_' . $post_type, $options, $post_type );
969
+
970
+ /**
971
+ * Allow filtering of post type options.
972
+ *
973
+ * @param array $options Post type options
974
+ * @param string $post_type Post type name
975
+ */
976
+ $options = apply_filters( 'pods_register_post_type', $options, $post_type );
977
+
978
  if ( 1 == pods_var( 'pods_debug_register', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
979
+ pods_debug( array( 'register_post_type', compact( 'post_type', 'options' ) ) );
980
  }
981
 
982
  register_post_type( $post_type, $options );
986
  register_taxonomy_for_object_type( 'post_format', $post_type );
987
  }
988
 
989
+ if ( ! empty( $options['show_in_rest'] ) ) {
990
+ new PodsRESTFields( $post_type );
991
+ }
992
+
993
  if ( ! isset( self::$content_types_registered['post_types'] ) ) {
994
  self::$content_types_registered['post_types'] = array();
995
  }
997
  self::$content_types_registered['post_types'][] = $post_type;
998
  }
999
 
1000
+ // Handle existing post types / taxonomies settings (just REST for now)
1001
+ global $wp_post_types, $wp_taxonomies;
1002
+
1003
+ $post_type_names = wp_list_pluck( $post_types, 'name', 'id' );
1004
+ $taxonomy_names = wp_list_pluck( $taxonomies, 'name', 'id' );
1005
+
1006
+ foreach ( $existing_post_types as $post_type_name => $post_type_name_again ) {
1007
+ if ( isset( self::$content_types_registered['post_types'] ) && in_array( $post_type_name, self::$content_types_registered['post_types'] ) ) {
1008
+ // Post type already registered / setup by Pods
1009
+ continue;
1010
+ }
1011
+
1012
+ $pod_id = array_search( $post_type_name, $post_type_names, true );
1013
+
1014
+ if ( ! $pod_id ) {
1015
+ // Post type not a pod
1016
+ continue;
1017
+ }
1018
+
1019
+ $pod = $post_types[ $pod_id ];
1020
+
1021
+ // REST API
1022
+ $rest_enabled = (boolean) pods_v( 'rest_enable', $pod['options'], false );
1023
+
1024
+ if ( $rest_enabled ) {
1025
+ if ( empty( $wp_post_types[ $post_type_name ]->show_in_rest ) ) {
1026
+ $rest_base = sanitize_title( pods_v( 'rest_base', $pod['options'], pods_v( 'rest_base', $wp_post_types[ $post_type_name ] ), true ) );
1027
+
1028
+ $wp_post_types[ $post_type_name ]->show_in_rest = true;
1029
+ $wp_post_types[ $post_type_name ]->rest_base = $rest_base;
1030
+ $wp_post_types[ $post_type_name ]->rest_controller_class = 'WP_REST_Posts_Controller';
1031
+ }
1032
+
1033
+ new PodsRESTFields( $post_type_name );
1034
+ }
1035
+ }
1036
+
1037
+ foreach ( $existing_taxonomies as $taxonomy_name => $taxonomy_name_again ) {
1038
+ if ( isset( self::$content_types_registered['taxonomies'] ) && in_array( $taxonomy_name, self::$content_types_registered['taxonomies'] ) ) {
1039
+ // Taxonomy already registered / setup by Pods
1040
+ continue;
1041
+ }
1042
+
1043
+ $pod_id = array_search( $taxonomy_name, $taxonomy_names, true );
1044
+
1045
+ if ( ! $pod_id ) {
1046
+ // Taxonomy not a pod
1047
+ continue;
1048
+ }
1049
+
1050
+ $pod = $taxonomies[ $pod_id ];
1051
+
1052
+ // REST API
1053
+ $rest_enabled = (boolean) pods_v( 'rest_enable', $pod['options'], false );
1054
+
1055
+ if ( $rest_enabled ) {
1056
+ if ( empty( $wp_taxonomies[ $taxonomy_name ]->show_in_rest ) ) {
1057
+ $rest_base = sanitize_title( pods_v( 'rest_base', $pod['options'], pods_v( 'rest_base', $wp_taxonomies[ $taxonomy_name ] ), true ) );
1058
+
1059
+ $wp_taxonomies[ $taxonomy_name ]->show_in_rest = true;
1060
+ $wp_taxonomies[ $taxonomy_name ]->rest_base = $rest_base;
1061
+ $wp_taxonomies[ $taxonomy_name ]->rest_controller_class = 'WP_REST_Terms_Controller';
1062
+ }
1063
+
1064
+ new PodsRESTFields( $taxonomy_name );
1065
+ }
1066
+ }
1067
+
1068
+ if ( ! empty( PodsMeta::$user ) ) {
1069
+ $pod = current( PodsMeta::$user );
1070
+
1071
+ $rest_enabled = (boolean) pods_v( 'rest_enable', $pod['options'], false );
1072
+
1073
+ if ( $rest_enabled ) {
1074
+ new PodsRESTFields( $pod['name'] );
1075
+ }
1076
+ }
1077
+
1078
+ if ( ! empty( PodsMeta::$media ) ) {
1079
+ $pod = current( PodsMeta::$media );
1080
+
1081
+ $rest_enabled = (boolean) pods_v( 'rest_enable', $pod['options'], false );
1082
+
1083
+ if ( $rest_enabled ) {
1084
+ new PodsRESTFields( $pod['name'] );
1085
+ }
1086
+ }
1087
+
1088
  }
1089
 
1090
  /**
1191
  $args['labels'] = array();
1192
  }
1193
 
1194
+ $label = pods_v( 'name', $args['labels'], pods_v( 'label', $args, __( 'Items', 'pods' ), true ), true );
1195
+ $singular_label = pods_v( 'singular_name', $args['labels'], pods_v( 'label_singular', $args, __( 'Item', 'pods' ), true ), true );
1196
 
1197
  $labels = $args['labels'];
1198
 
1200
  $labels['singular_name'] = $singular_label;
1201
 
1202
  if ( 'post_type' == $type ) {
1203
+ $labels['menu_name'] = pods_v( 'menu_name', $labels, $label, true );
1204
+ $labels['name_admin_bar'] = pods_v( 'name_admin_bar', $labels, $singular_label, true );
1205
+ $labels['add_new'] = pods_v( 'add_new', $labels, __( 'Add New', 'pods' ), true );
1206
+ $labels['add_new_item'] = pods_v( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), true );
1207
+ $labels['new_item'] = pods_v( 'new_item', $labels, sprintf( __( 'New %s', 'pods' ), $singular_label ), true );
1208
+ $labels['edit'] = pods_v( 'edit', $labels, __( 'Edit', 'pods' ), true );
1209
+ $labels['edit_item'] = pods_v( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), true );
1210
+ $labels['view'] = pods_v( 'view', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true );
1211
+ $labels['view_item'] = pods_v( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true );
1212
+ $labels['view_items'] = pods_v( 'view_items', $labels, sprintf( __( 'View %s', 'pods' ), $label ), true );
1213
+ $labels['all_items'] = pods_v( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), true );
1214
+ $labels['search_items'] = pods_v( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), true );
1215
+ $labels['not_found'] = pods_v( 'not_found', $labels, sprintf( __( 'No %s Found', 'pods' ), $label ), true );
1216
+ $labels['not_found_in_trash'] = pods_v( 'not_found_in_trash', $labels, sprintf( __( 'No %s Found in Trash', 'pods' ), $label ), true );
1217
+ $labels['parent'] = pods_v( 'parent', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), true );
1218
+ $labels['parent_item_colon'] = pods_v( 'parent_item_colon', $labels, sprintf( __( 'Parent %s:', 'pods' ), $singular_label ), true );
1219
+ $labels['featured_image'] = pods_v( 'featured_image', $labels, __( 'Featured Image', 'pods' ), true );
1220
+ $labels['set_featured_image'] = pods_v( 'set_featured_image', $labels, __( 'Set featured image', 'pods' ), true );
1221
+ $labels['remove_featured_image'] = pods_v( 'remove_featured_image', $labels, __( 'Remove featured image', 'pods' ), true );
1222
+ $labels['use_featured_image'] = pods_v( 'use_featured_image', $labels, __( 'Use as featured image', 'pods' ), true );
1223
+ $labels['archives'] = pods_v( 'archives', $labels, sprintf( __( '%s Archives', 'pods' ), $singular_label ), true );
1224
+ $labels['attributes'] = pods_v( 'attributes', $labels, sprintf( __( '%s Attributes', 'pods' ), $singular_label ), true );
1225
+ $labels['insert_into_item'] = pods_v( 'insert_into_item', $labels, sprintf( __( 'Insert into %s', 'pods' ), $singular_label ), true );
1226
+ $labels['uploaded_to_this_item'] = pods_v( 'uploaded_to_this_item', $labels, sprintf( __( 'Uploaded to this %s', 'pods' ), $singular_label ), true );
1227
+ $labels['filter_items_list'] = pods_v( 'filter_items_list', $labels, sprintf( __( 'Filter %s lists', 'pods' ), $label ), true );
1228
+ $labels['items_list_navigation'] = pods_v( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), true );
1229
+ $labels['items_list'] = pods_v( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), true );
1230
  } elseif ( 'taxonomy' == $type ) {
1231
+ $labels['menu_name'] = pods_v( 'menu_name', $labels, $label, true );
1232
+ $labels['search_items'] = pods_v( 'search_items', $labels, sprintf( __( 'Search %s', 'pods' ), $label ), true );
1233
+ $labels['popular_items'] = pods_v( 'popular_items', $labels, sprintf( __( 'Popular %s', 'pods' ), $label ), true );
1234
+ $labels['all_items'] = pods_v( 'all_items', $labels, sprintf( __( 'All %s', 'pods' ), $label ), true );
1235
+ $labels['parent_item'] = pods_v( 'parent_item', $labels, sprintf( __( 'Parent %s', 'pods' ), $singular_label ), true );
1236
+ $labels['parent_item_colon'] = pods_v( 'parent_item_colon', $labels, sprintf( __( 'Parent %s :', 'pods' ), $singular_label ), true );
1237
+ $labels['edit_item'] = pods_v( 'edit_item', $labels, sprintf( __( 'Edit %s', 'pods' ), $singular_label ), true );
1238
+ $labels['view_item'] = pods_v( 'view_item', $labels, sprintf( __( 'View %s', 'pods' ), $singular_label ), true );
1239
+ $labels['update_item'] = pods_v( 'update_item', $labels, sprintf( __( 'Update %s', 'pods' ), $singular_label ), true );
1240
+ $labels['add_new_item'] = pods_v( 'add_new_item', $labels, sprintf( __( 'Add New %s', 'pods' ), $singular_label ), true );
1241
+ $labels['new_item_name'] = pods_v( 'new_item_name', $labels, sprintf( __( 'New %s Name', 'pods' ), $singular_label ), true );
1242
+ $labels['separate_items_with_commas'] = pods_v( 'separate_items_with_commas', $labels, sprintf( __( 'Separate %s with commas', 'pods' ), $label ), true );
1243
+ $labels['add_or_remove_items'] = pods_v( 'add_or_remove_items', $labels, sprintf( __( 'Add or remove %s', 'pods' ), $label ), true );
1244
+ $labels['choose_from_most_used'] = pods_v( 'choose_from_most_used', $labels, sprintf( __( 'Choose from the most used %s', 'pods' ), $label ), true );
1245
+ $labels['not_found'] = pods_v( 'not_found', $labels, sprintf( __( 'No %s found.', 'pods' ), $label ), true );
1246
+ $labels['no_terms'] = pods_v( 'no_terms', $labels, sprintf( __( 'No %s', 'pods' ), $label ), true );
1247
+ $labels['items_list_navigation'] = pods_v( 'items_list_navigation', $labels, sprintf( __( '%s navigation', 'pods' ), $label ), true );
1248
+ $labels['items_list'] = pods_v( 'items_list', $labels, sprintf( __( '%s list', 'pods' ), $label ), true );
1249
  }
1250
 
1251
  $args['labels'] = $labels;
1522
 
1523
  $ran = true;
1524
 
1525
+ $this->load_i18n();
1526
+
1527
  if ( ! did_action( 'plugins_loaded' ) ) {
1528
  add_action( 'plugins_loaded', array( $this, 'load_components' ), 11 );
1529
  } else {
1538
 
1539
  if ( ! did_action( 'init' ) ) {
1540
  add_action( 'init', array( $this, 'core' ), 11 );
 
1541
  add_action( 'init', array( $this, 'setup_content_types' ), 11 );
1542
 
1543
  if ( is_admin() ) {
1545
  }
1546
  } else {
1547
  $this->core();
 
1548
  $this->setup_content_types();
1549
 
1550
  if ( is_admin() ) {
1743
  }
1744
 
1745
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1746
  }
classes/PodsMeta.php CHANGED
@@ -136,6 +136,7 @@ class PodsMeta {
136
  add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) );
137
  add_action( 'transition_post_status', array( $this, 'save_post_detect_new' ), 10, 3 );
138
  add_action( 'save_post', array( $this, 'save_post' ), 10, 3 );
 
139
 
140
  if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
141
  // Handle *_post_meta
@@ -176,6 +177,7 @@ class PodsMeta {
176
  // Handle Term Editor
177
  add_action( 'edited_term', array( $this, 'save_taxonomy' ), 10, 3 );
178
  add_action( 'create_term', array( $this, 'save_taxonomy' ), 10, 3 );
 
179
 
180
  if ( apply_filters( 'pods_meta_handler', true, 'term' ) ) {
181
  // Handle *_term_meta
@@ -208,22 +210,21 @@ class PodsMeta {
208
  add_action( 'delete_term_taxonomy', array( $this, 'delete_taxonomy' ), 10, 1 );
209
 
210
  if ( !empty( self::$media ) ) {
211
- if ( pods_version_check( 'wp', '3.5' ) ) {
212
- add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) );
213
- add_action( 'wp_ajax_save-attachment-compat', array( $this, 'save_media_ajax' ), 0 );
214
- }
215
 
216
  add_filter( 'attachment_fields_to_edit', array( $this, 'meta_media' ), 10, 2 );
217
 
218
  add_filter( 'attachment_fields_to_save', array( $this, 'save_media' ), 10, 2 );
219
  add_filter( 'wp_update_attachment_metadata', array( $this, 'save_media' ), 10, 2 );
 
220
 
221
  if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
222
  // Handle *_post_meta
223
  if ( !has_filter( 'get_post_metadata', array( $this, 'get_post_meta' ) ) ) {
224
- if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
225
- add_filter( 'get_post_metadata', array( $this, 'get_post_meta' ), 10, 4 );
226
- }
227
 
228
  if ( !pods_tableless() ) {
229
  add_filter( 'add_post_metadata', array( $this, 'add_post_meta' ), 10, 5 );
@@ -243,6 +244,7 @@ class PodsMeta {
243
  add_action( 'edit_user_profile', array( $this, 'meta_user' ) );
244
  add_action( 'user_register', array( $this, 'save_user' ) );
245
  add_action( 'profile_update', array( $this, 'save_user' ), 10, 2 );
 
246
 
247
  if ( apply_filters( 'pods_meta_handler', true, 'user' ) ) {
248
  // Handle *_user_meta
@@ -269,6 +271,7 @@ class PodsMeta {
269
  add_filter( 'pre_comment_approved', array( $this, 'validate_comment' ), 10, 2 );
270
  add_action( 'comment_post', array( $this, 'save_comment' ) );
271
  add_action( 'edit_comment', array( $this, 'save_comment' ) );
 
272
 
273
  if ( apply_filters( 'pods_meta_handler', true, 'comment' ) ) {
274
  // Handle *_comment_meta
@@ -412,170 +415,199 @@ class PodsMeta {
412
  return false;
413
  }
414
 
415
- public function integrations () {
416
- // Codepress Admin Columns 2.x
417
- add_filter( 'cac/storage_model/meta_keys', array( $this, 'cpac_meta_keys' ), 10, 2 );
418
- add_filter( 'cac/post_types', array( $this, 'cpac_post_types' ), 10, 1 );
419
- add_filter( 'cac/column/meta/value', array( $this, 'cpac_meta_value' ), 10, 3 );
420
- }
421
-
422
-
423
- public function cpac_meta_keys ( $meta_fields, $storage_model ) {
424
- $object_type = 'post_type';
425
- $object = $storage_model->key;
426
-
427
- if ( in_array( $storage_model->key, array( 'wp-links', 'link' ) ) ) {
428
- $object_type = $object = 'link';
429
- }
430
- elseif ( in_array( $storage_model->key, array( 'wp-media', 'media' ) ) ) {
431
- $object_type = $object = 'media';
432
- }
433
- elseif ( in_array( $storage_model->key, array( 'wp-users', 'user' ) ) ) {
434
- $object_type = $object = 'user';
435
- }
436
- elseif ( in_array( $storage_model->key, array( 'wp-comments', 'comment' ) ) ) {
437
- $object_type = $object = 'comment';
438
- }
439
- elseif ( 'taxonomy' === $storage_model->type ) {
440
- $object_type = 'taxonomy';
441
- $object = $storage_model->taxonomy;
442
- }
443
-
444
- if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $object )
445
- self::$current_pod_data = pods_api()->load_pod( array( 'name' => $object ), false );
446
-
447
- $pod = self::$current_pod_data;
448
-
449
- // Add Pods fields
450
- if ( !empty( $pod ) && $object_type == $pod[ 'type' ] ) {
451
- foreach ( $pod[ 'fields' ] as $field => $field_data ) {
452
- if ( !is_array( $meta_fields ) )
453
- $meta_fields = array();
454
-
455
- if ( !in_array( $field, $meta_fields ) )
456
- $meta_fields[] = $field;
457
- }
458
- }
459
-
460
- // Remove internal Pods fields
461
- if ( is_array( $meta_fields ) ) {
462
- foreach ( $meta_fields as $k => $meta_field ) {
463
- if ( 0 === strpos( $meta_field, '_pods_' ) )
464
- unset( $meta_fields[ $k ] );
465
- }
466
- }
467
-
468
- return $meta_fields;
469
- }
470
-
471
- public function cpac_post_types ( $post_types ) {
472
- // Remove internal Pods post types
473
- foreach ( $post_types as $post_type => $post_type_name ) {
474
- if ( 0 === strpos( $post_type, '_pods_' ) || 0 === strpos( $post_type_name, '_pods_' ) )
475
- unset( $post_types[ $post_type ] );
476
- }
477
-
478
- return $post_types;
479
- }
480
 
481
- public function cpac_meta_value ( $meta, $id, $obj ) {
482
- $tableless_field_types = PodsForm::tableless_field_types();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
483
 
484
- $object_type = 'post_type';
485
- $object = $obj->storage_model->key;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
 
487
- if ( in_array( $obj->storage_model->type, array( 'wp-links', 'link' ) ) ) {
488
- $object_type = $object = 'link';
489
- }
490
- elseif ( in_array( $obj->storage_model->type, array( 'wp-media', 'media' ) ) ) {
491
- $object_type = $object = 'media';
492
- }
493
- elseif ( in_array( $obj->storage_model->type, array( 'wp-users', 'user' ) ) ) {
494
- $object_type = $object = 'user';
495
- }
496
- elseif ( in_array( $obj->storage_model->type, array( 'wp-comments', 'comment' ) ) ) {
497
- $object_type = $object = 'comment';
498
- }
499
- elseif ( 'taxonomy' === $obj->storage_model->type ) {
500
- $object_type = 'taxonomy';
501
- $object = $obj->storage_model->taxonomy;
502
- }
503
 
504
- $field = substr( $obj->get_option( 'field' ), 0, 10 ) == "cpachidden" ? str_replace( 'cpachidden', '', $obj->get_option( 'field' ) ) : $obj->get_option( 'field' );
505
- $field_type = $obj->get_option( 'field_type' );
506
 
507
- if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $object )
508
- self::$current_pod_data = pods_api()->load_pod( array( 'name' => $object ), false );
 
 
 
509
 
510
- $pod = self::$current_pod_data;
 
 
 
511
 
512
- // Add Pods fields
513
- if ( !empty( $pod ) && isset( $pod[ 'fields' ][ $field ] ) ) {
514
- if ( in_array( $pod[ 'type' ], array( 'post_type', 'media', 'taxonomy', 'user', 'comment', 'media' ) ) && ( !empty( $field_type ) || in_array( $pod[ 'fields' ][ $field ][ 'type' ], $tableless_field_types ) ) ) {
515
- $metadata_type = $pod['type'];
 
 
 
516
 
517
- if ( in_array( $metadata_type, array( 'post_type', 'media' ) ) ) {
518
- $metadata_type = 'post';
519
- } elseif ( 'taxonomy' == $metadata_type ) {
520
- $metadata_type = 'term';
521
- }
522
 
523
- if ( 'term' == $metadata_type && ! function_exists( 'get_term_meta' ) ) {
524
- $podterms = pods( $pod['name'], $id );
 
 
 
 
 
525
 
526
- $meta = $podterms->field( $field );
527
- } else {
528
- $meta = get_metadata( $metadata_type, $id, $field, true );
529
- }
530
- }
531
- elseif ( 'taxonomy' == $pod['type'] ) {
532
- $podterms = pods( $pod['name'], $id );
533
 
534
- $meta = $podterms->field( $field );
535
- }
536
 
537
- $meta = PodsForm::field_method( $pod[ 'fields' ][ $field ][ 'type' ], 'ui', $id, $meta, $field, array_merge( $pod[ 'fields' ][ $field ], $pod[ 'fields' ][ $field ][ 'options' ] ), $pod[ 'fields' ], $pod );
538
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
539
 
540
- return $meta;
541
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
542
 
543
- public function cpac_meta_values ( $meta, $field_type, $field, $type, $id ) {
544
- $tableless_field_types = PodsForm::tableless_field_types();
545
 
546
- $object = $type;
 
547
 
548
- if ( 'wp-media' == $type )
549
- $object = 'media';
550
- elseif ( 'wp-users' == $type )
551
- $object = 'user';
552
- elseif ( 'wp-comments' == $type )
553
- $object = 'comment';
554
 
555
- if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $object )
556
- self::$current_pod_data = pods_api()->load_pod( array( 'name' => $object ), false );
 
 
557
 
558
- $pod = self::$current_pod_data;
 
 
 
 
559
 
560
- // Add Pods fields
561
- if ( !empty( $pod ) && isset( $pod[ 'fields' ][ $field ] ) ) {
562
- if ( in_array( $pod[ 'type' ], array( 'post_type', 'user', 'taxonomy', 'comment', 'media' ) ) && ( !empty( $field_type ) || in_array( $pod[ 'fields' ][ $field ][ 'type' ], $tableless_field_types ) ) ) {
563
- $metadata_type = $pod['type'];
564
 
565
- if ( in_array( $metadata_type, array( 'post_type', 'media' ) ) ) {
566
- $metadata_type = 'post';
567
- } elseif ( 'taxonomy' == $metadata_type ) {
568
- $metadata_type = 'term';
569
- }
 
 
570
 
571
- $meta = get_metadata( $metadata_type, $id, $field, true );
572
- }
573
 
574
- $meta = PodsForm::field_method( $pod[ 'fields' ][ $field ][ 'type' ], 'ui', $id, $meta, $field, array_merge( $pod[ 'fields' ][ $field ], $pod[ 'fields' ][ $field ][ 'options' ] ), $pod[ 'fields' ], $pod );
575
- }
576
 
577
- return $meta;
578
- }
579
 
580
  /**
581
  * Add a meta group of fields to add/edit forms
@@ -593,7 +625,7 @@ class PodsMeta {
593
  public function group_add ( $pod, $label, $fields, $context = 'normal', $priority = 'default' ) {
594
  if ( is_array( $pod ) && !empty( $pod ) && !isset( $pod[ 'name' ] ) ) {
595
  foreach ( $pod as $p ) {
596
- $this->group_add( $pod, $label, $fields, $context, $priority );
597
  }
598
 
599
  return true;
@@ -721,10 +753,8 @@ class PodsMeta {
721
  }
722
  elseif ( 'media' == $pod[ 'type' ] ) {
723
  if ( !has_filter( 'wp_update_attachment_metadata', array( $this, 'save_media' ), 10, 2 ) ) {
724
- if ( pods_version_check( 'wp', '3.5' ) ) {
725
- add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) );
726
- add_action( 'wp_ajax_save-attachment-compat', array( $this, 'save_media_ajax' ), 0 );
727
- }
728
 
729
  add_filter( 'attachment_fields_to_edit', array( $this, 'meta_media' ), 10, 2 );
730
 
@@ -1052,11 +1082,13 @@ class PodsMeta {
1052
  );
1053
  }
1054
  else {
1055
- $depends = PodsForm::dependencies( $field, 'pods-meta-' );
 
 
1056
 
1057
  do_action( 'pods_meta_' . __FUNCTION__ . '_' . $field[ 'name' ], $post, $field, $pod );
1058
  ?>
1059
- <tr class="form-field pods-field pods-field-input <?php echo esc_attr( 'pods-form-ui-row-type-' . $field[ 'type' ] . ' pods-form-ui-row-name-' . PodsForm::clean( $field[ 'name' ], true ) ); ?> <?php echo esc_attr( $depends ); ?>">
1060
  <th scope="row" valign="top"><?php echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); ?></th>
1061
  <td>
1062
  <?php
@@ -1064,10 +1096,10 @@ class PodsMeta {
1064
  if ( isset( $field[ 'help' ] ) )
1065
  unset( $field[ 'help' ] );
1066
  ?>
1067
- <div class="pods-submittable-fields">
1068
  <?php echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ); ?>
1069
  <?php echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ); ?>
1070
- </div>
1071
  </td>
1072
  </tr>
1073
  <?php
@@ -1199,6 +1231,16 @@ class PodsMeta {
1199
  $pod = self::$current_pod;
1200
  $data = array();
1201
 
 
 
 
 
 
 
 
 
 
 
1202
  if ( false !== $nonced && ! empty( $groups ) ) {
1203
  foreach ( $groups as $group ) {
1204
  if ( empty( $group['fields'] ) ) {
@@ -1236,7 +1278,7 @@ class PodsMeta {
1236
  // Fix for Pods doing it's own sanitizing
1237
  $data = pods_unslash( (array) $data );
1238
 
1239
- $pod->save( $data, null, null, array( 'is_new_item' => $is_new_item ) );
1240
  } elseif ( ! empty( $id ) ) {
1241
  foreach ( $data as $field => $value ) {
1242
  update_post_meta( $id, $field, $value );
@@ -1258,6 +1300,29 @@ class PodsMeta {
1258
 
1259
  }
1260
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1261
  /**
1262
  * @param $form_fields
1263
  * @param $post
@@ -1271,6 +1336,7 @@ class PodsMeta {
1271
  return $form_fields;
1272
 
1273
  wp_enqueue_style( 'pods-form' );
 
1274
 
1275
  $id = null;
1276
 
@@ -1382,6 +1448,15 @@ class PodsMeta {
1382
  }
1383
  }
1384
 
 
 
 
 
 
 
 
 
 
1385
  do_action( 'pods_meta_save_pre_media', $data, $pod, $id, $groups, $post, $attachment );
1386
 
1387
  if ( !empty( $pod ) ) {
@@ -1442,6 +1517,7 @@ class PodsMeta {
1442
  */
1443
  public function meta_taxonomy ( $tag, $taxonomy = null ) {
1444
  wp_enqueue_style( 'pods-form' );
 
1445
 
1446
  do_action( 'pods_meta_' . __FUNCTION__, $tag, $taxonomy );
1447
 
@@ -1552,42 +1628,54 @@ class PodsMeta {
1552
  $has_fields = false;
1553
 
1554
  foreach ( $groups as $group ) {
1555
- if ( empty( $group[ 'fields' ] ) )
1556
- continue;
 
1557
 
1558
- if ( null === $term ) {
1559
- $term = get_term( $term_id, $taxonomy );
1560
 
1561
- $data = array(
1562
- 'name' => $term->name
1563
- );
1564
- }
1565
 
1566
- $has_fields = true;
1567
 
1568
- if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
1569
- if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
1570
- self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
1571
- elseif ( self::$current_pod->id() != $id )
1572
- self::$current_pod->fetch( $id );
1573
-
1574
- $pod = self::$current_pod;
1575
- }
1576
 
1577
- foreach ( $group[ 'fields' ] as $field ) {
 
1578
 
1579
- if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
1580
- if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
1581
- continue;
1582
- }
 
 
1583
 
1584
- $data[ $field[ 'name' ] ] = '';
1585
 
1586
- if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
1587
- $data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
1588
- }
 
1589
  }
1590
 
 
 
 
 
 
 
 
 
 
1591
  if ( !$has_fields ) {
1592
  return $term_id;
1593
  }
@@ -1622,11 +1710,31 @@ class PodsMeta {
1622
  return $term_id;
1623
  }
1624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1625
  /**
1626
  * @param $user_id
1627
  */
1628
  public function meta_user ( $user_id ) {
1629
  wp_enqueue_style( 'pods-form' );
 
1630
 
1631
  do_action( 'pods_meta_' . __FUNCTION__, $user_id );
1632
 
@@ -1754,6 +1862,15 @@ class PodsMeta {
1754
  $pod = self::$current_pod;
1755
  $data = array();
1756
 
 
 
 
 
 
 
 
 
 
1757
  if ( false !== $nonced && ! empty( $groups ) ) {
1758
  foreach ( $groups as $group ) {
1759
  if ( empty( $group['fields'] ) ) {
@@ -1809,12 +1926,39 @@ class PodsMeta {
1809
 
1810
  }
1811
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1812
  /**
1813
  * @param $commenter
1814
  * @param $user_identity
1815
  */
1816
  public function meta_comment_new_logged_in ( $commenter, $user_identity ) {
1817
  wp_enqueue_style( 'pods-form' );
 
1818
 
1819
  do_action( 'pods_meta_' . __FUNCTION__, $commenter, $user_identity );
1820
 
@@ -1881,6 +2025,7 @@ class PodsMeta {
1881
  */
1882
  public function meta_comment_new ( $form_fields ) {
1883
  wp_enqueue_style( 'pods-form' );
 
1884
 
1885
  $groups = $this->groups_get( 'comment', 'comment' );
1886
 
@@ -2006,6 +2151,7 @@ class PodsMeta {
2006
  */
2007
  public function meta_comment ( $comment, $metabox ) {
2008
  wp_enqueue_style( 'pods-form' );
 
2009
 
2010
  do_action( 'pods_meta_' . __FUNCTION__, $comment, $metabox );
2011
 
@@ -2172,6 +2318,15 @@ class PodsMeta {
2172
  }
2173
  }
2174
 
 
 
 
 
 
 
 
 
 
2175
  do_action( 'pods_meta_save_pre_comment', $data, $pod, $id, $groups );
2176
 
2177
  if ( !empty( $pod ) ) {
@@ -2195,6 +2350,30 @@ class PodsMeta {
2195
  return $comment_id;
2196
  }
2197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2198
  /**
2199
  * All *_*_meta filter handler aliases
2200
  *
@@ -2572,17 +2751,17 @@ class PodsMeta {
2572
  $object_name = $object->post_type;
2573
  }
2574
  elseif ( 'taxonomy' == $object_type ) {
2575
- if ( pods_version_check( 'wp', '4.4' ) ) {
2576
- $object = get_term( $object_id );
2577
 
2578
- if ( !is_object( $object ) || !isset( $object->taxonomy ) )
2579
- return false;
 
2580
 
2581
- $object_name = $object->taxonomy;
2582
- } elseif ( empty( $aux ) ) {
2583
- $object_name = $wpdb->get_var( $wpdb->prepare( "SELECT `taxonomy` FROM `{$wpdb->term_taxonomy}` WHERE `term_id` = %d", $object_id ) );
2584
  } else {
2585
- $object_name = $aux;
2586
  }
2587
  }
2588
  elseif ( 'settings' == $object_type )
@@ -2650,6 +2829,10 @@ class PodsMeta {
2650
  $single = false;
2651
  }
2652
 
 
 
 
 
2653
  $object = $this->get_object( $object_type, $object_id );
2654
 
2655
  if ( empty( $object_id ) || empty( $object ) )
136
  add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) );
137
  add_action( 'transition_post_status', array( $this, 'save_post_detect_new' ), 10, 3 );
138
  add_action( 'save_post', array( $this, 'save_post' ), 10, 3 );
139
+ add_filter( 'wp_insert_post_data', array( $this, 'save_post_track_changed_fields' ), 10, 2 );
140
 
141
  if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
142
  // Handle *_post_meta
177
  // Handle Term Editor
178
  add_action( 'edited_term', array( $this, 'save_taxonomy' ), 10, 3 );
179
  add_action( 'create_term', array( $this, 'save_taxonomy' ), 10, 3 );
180
+ add_action( 'edit_terms', array( $this, 'save_taxonomy_track_changed_fields' ), 10, 2 );
181
 
182
  if ( apply_filters( 'pods_meta_handler', true, 'term' ) ) {
183
  // Handle *_term_meta
210
  add_action( 'delete_term_taxonomy', array( $this, 'delete_taxonomy' ), 10, 1 );
211
 
212
  if ( !empty( self::$media ) ) {
213
+ add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) );
214
+ add_action( 'wp_ajax_save-attachment-compat', array( $this, 'save_media_ajax' ), 0 );
 
 
215
 
216
  add_filter( 'attachment_fields_to_edit', array( $this, 'meta_media' ), 10, 2 );
217
 
218
  add_filter( 'attachment_fields_to_save', array( $this, 'save_media' ), 10, 2 );
219
  add_filter( 'wp_update_attachment_metadata', array( $this, 'save_media' ), 10, 2 );
220
+ add_filter( 'wp_insert_attachment_data', array( $this, 'save_post_track_changed_fields' ), 10, 2 );
221
 
222
  if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
223
  // Handle *_post_meta
224
  if ( !has_filter( 'get_post_metadata', array( $this, 'get_post_meta' ) ) ) {
225
+ if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
226
+ add_filter( 'get_post_metadata', array( $this, 'get_post_meta' ), 10, 4 );
227
+ }
228
 
229
  if ( !pods_tableless() ) {
230
  add_filter( 'add_post_metadata', array( $this, 'add_post_meta' ), 10, 5 );
244
  add_action( 'edit_user_profile', array( $this, 'meta_user' ) );
245
  add_action( 'user_register', array( $this, 'save_user' ) );
246
  add_action( 'profile_update', array( $this, 'save_user' ), 10, 2 );
247
+ add_filter( 'pre_user_login', array( $this, 'save_user_track_changed_fields' ));
248
 
249
  if ( apply_filters( 'pods_meta_handler', true, 'user' ) ) {
250
  // Handle *_user_meta
271
  add_filter( 'pre_comment_approved', array( $this, 'validate_comment' ), 10, 2 );
272
  add_action( 'comment_post', array( $this, 'save_comment' ) );
273
  add_action( 'edit_comment', array( $this, 'save_comment' ) );
274
+ add_action( 'wp_update_comment_data', array( $this, 'save_comment_track_changed_fields' ), 10, 3 );
275
 
276
  if ( apply_filters( 'pods_meta_handler', true, 'comment' ) ) {
277
  // Handle *_comment_meta
415
  return false;
416
  }
417
 
418
+ public function integrations () {
419
+
420
+ // `ac_is_version_gte` is since AC 3.0+
421
+ if ( ! function_exists( 'ac_is_version_gte' ) ) {
422
+ // Codepress Admin Columns < 2.x
423
+ add_filter( 'cac/storage_model/meta_keys', array( $this, 'cpac_meta_keys' ), 10, 2 );
424
+ add_filter( 'cac/post_types', array( $this, 'cpac_post_types' ), 10, 1 );
425
+ add_filter( 'cac/column/meta/value', array( $this, 'cpac_meta_value' ), 10, 3 );
426
+ } else {
427
+ // Codepress Admin Columns 3.x +
428
+ add_filter( 'ac/column/custom_field/meta_keys', array( $this, 'cpac_meta_keys' ), 10, 2 );
429
+ add_filter( 'ac/post_types', array( $this, 'cpac_post_types' ), 10, 1 );
430
+ add_filter( 'ac/column/value', array( $this, 'cpac_meta_value' ), 10, 3 );
431
+ }
432
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
433
 
434
+ /**
435
+ * Admin Columns: Remove internal meta keys + add existing (public) Pod field keys.
436
+ *
437
+ * @param array $meta_fields
438
+ * @param \AC_Settings_Column_CustomField $storage_model
439
+ *
440
+ * @return array
441
+ */
442
+ public function cpac_meta_keys ( $meta_fields, $storage_model ) {
443
+ $object_type = 'post_type';
444
+ $object = null;
445
+ $obj = null;
446
+
447
+ if ( ! method_exists( $storage_model, 'get_column' ) ) {
448
+ // Codepress Admin Columns < 2.x
449
+ $object = $storage_model->key;
450
+ $type = $storage_model->type;
451
+ } else {
452
+ // Codepress Admin Columns 3.x +
453
+ $obj = $storage_model->get_column();
454
+ $object = $obj->get_list_screen()->get_key();
455
+ $type = $obj->get_list_screen()->get_meta_type();
456
+ }
457
 
458
+ if ( in_array( $type, array( 'wp-links', 'link' ), true ) ) {
459
+ $object_type = $object = 'link';
460
+ }
461
+ elseif ( in_array( $type, array( 'wp-media', 'media' ), true ) ) {
462
+ $object_type = $object = 'media';
463
+ }
464
+ elseif ( in_array( $type, array( 'wp-users', 'user' ), true ) ) {
465
+ $object_type = $object = 'user';
466
+ }
467
+ elseif ( in_array( $type, array( 'wp-comments', 'comment' ), true ) ) {
468
+ $object_type = $object = 'comment';
469
+ }
470
+ elseif ( 'taxonomy' === $type ) {
471
+ $object_type = 'taxonomy';
472
+ if ( ! $obj ) {
473
+ // Codepress Admin Columns < 2.x
474
+ $object = $storage_model->taxonomy;
475
+ } else {
476
+ // Codepress Admin Columns 3.x +
477
+ $object = $obj->get_taxonomy();
478
+ }
479
+ }
480
 
481
+ if ( empty( self::$current_pod_data ) || !is_object( self::$current_pod_data ) || self::$current_pod_data[ 'name' ] != $object )
482
+ self::$current_pod_data = pods_api()->load_pod( array( 'name' => $object ), false );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
483
 
484
+ $pod = self::$current_pod_data;
 
485
 
486
+ // Add Pods fields
487
+ if ( !empty( $pod ) && $object_type == $pod[ 'type' ] ) {
488
+ foreach ( $pod[ 'fields' ] as $field => $field_data ) {
489
+ if ( !is_array( $meta_fields ) )
490
+ $meta_fields = array();
491
 
492
+ if ( !in_array( $field, $meta_fields ) )
493
+ $meta_fields[] = $field;
494
+ }
495
+ }
496
 
497
+ // Remove internal Pods fields
498
+ if ( is_array( $meta_fields ) ) {
499
+ foreach ( $meta_fields as $k => $meta_field ) {
500
+ if ( 0 === strpos( $meta_field, '_pods_' ) )
501
+ unset( $meta_fields[ $k ] );
502
+ }
503
+ }
504
 
505
+ return $meta_fields;
506
+ }
 
 
 
507
 
508
+ /**
509
+ * Admin Columns: Remove internal Pods post types.
510
+ *
511
+ * @param array $post_types
512
+ * @return array
513
+ */
514
+ public function cpac_post_types ( $post_types ) {
515
 
516
+ foreach ( $post_types as $post_type => $post_type_name ) {
517
+ if ( 0 === strpos( $post_type, '_pods_' ) || 0 === strpos( $post_type_name, '_pods_' ) )
518
+ unset( $post_types[ $post_type ] );
519
+ }
 
 
 
520
 
521
+ return $post_types;
522
+ }
523
 
524
+ /**
525
+ * Admin Columns: For custom field column types.
526
+ *
527
+ * @param mixed $meta
528
+ * @param int $id
529
+ * @param \AC_Column $obj
530
+ *
531
+ * @return mixed
532
+ */
533
+ public function cpac_meta_value ( $meta, $id, $obj ) {
534
+ $tableless_field_types = PodsForm::tableless_field_types();
535
+
536
+ $object_type = 'post_type';
537
+ $object = null;
538
+ $type = null;
539
+
540
+ if ( ! method_exists( $obj, 'get_list_screen' ) ) {
541
+ // Codepress Admin Columns < 2.x
542
+ $object = $obj->storage_model->key;
543
+ $type = $obj->storage_model->type;
544
+ } else {
545
+ // Codepress Admin Columns 3.x +
546
+ $object = $obj->get_list_screen()->get_key();
547
+ $type = $obj->get_list_screen()->get_meta_type();
548
+ }
549
 
550
+ if ( in_array( $type, array( 'wp-links', 'link' ), true ) ) {
551
+ $object_type = $object = 'link';
552
+ }
553
+ elseif ( in_array( $type, array( 'wp-media', 'media' ), true ) ) {
554
+ $object_type = $object = 'media';
555
+ }
556
+ elseif ( in_array( $type, array( 'wp-users', 'user' ), true ) ) {
557
+ $object_type = $object = 'user';
558
+ }
559
+ elseif ( in_array( $type, array( 'wp-comments', 'comment' ), true ) ) {
560
+ $object_type = $object = 'comment';
561
+ }
562
+ elseif ( 'taxonomy' === $type ) {
563
+ $object_type = 'taxonomy';
564
+ if ( ! method_exists( $obj, 'get_taxonomy' ) ) {
565
+ // Codepress Admin Columns < 2.x
566
+ $object = $obj->storage_model->taxonomy;
567
+ } else {
568
+ // Codepress Admin Columns 3.x +
569
+ $object = $obj->get_taxonomy();
570
+ }
571
+ }
572
 
573
+ $field = ( "cpachidden" === substr( $obj->get_option( 'field' ), 0, 10 ) ) ? str_replace( 'cpachidden', '', $obj->get_option( 'field' ) ) : $obj->get_option( 'field' );
574
+ $field_type = $obj->get_option( 'field_type' );
575
 
576
+ if ( empty( self::$current_pod_data ) || ! is_object( self::$current_pod_data ) || self::$current_pod_data['name'] !== $object )
577
+ self::$current_pod_data = pods_api()->load_pod( array( 'name' => $object ), false );
578
 
579
+ $pod = self::$current_pod_data;
 
 
 
 
 
580
 
581
+ // Add Pods fields
582
+ if ( !empty( $pod ) && isset( $pod['fields'][ $field ] ) ) {
583
+ if ( in_array( $pod['type'], array( 'post_type', 'media', 'taxonomy', 'user', 'comment', 'media' ), true ) && ( ! empty( $field_type ) || in_array( $pod['fields'][ $field ]['type'], $tableless_field_types, true ) ) ) {
584
+ $metadata_type = $pod['type'];
585
 
586
+ if ( in_array( $metadata_type, array( 'post_type', 'media' ), true ) ) {
587
+ $metadata_type = 'post';
588
+ } elseif ( 'taxonomy' === $metadata_type ) {
589
+ $metadata_type = 'term';
590
+ }
591
 
592
+ if ( 'term' === $metadata_type && ! function_exists( 'get_term_meta' ) ) {
593
+ $podterms = pods( $pod['name'], $id );
 
 
594
 
595
+ $meta = $podterms->field( $field );
596
+ } else {
597
+ $meta = get_metadata( $metadata_type, $id, $field, ( 'array' !== $field_type ) );
598
+ }
599
+ }
600
+ elseif ( 'taxonomy' === $pod['type'] ) {
601
+ $podterms = pods( $pod['name'], $id );
602
 
603
+ $meta = $podterms->field( $field );
604
+ }
605
 
606
+ $meta = PodsForm::field_method( $pod['fields'][ $field ]['type'], 'ui', $id, $meta, $field, array_merge( $pod['fields'][ $field ], $pod['fields'][ $field ]['options'] ), $pod['fields'], $pod );
607
+ }
608
 
609
+ return $meta;
610
+ }
611
 
612
  /**
613
  * Add a meta group of fields to add/edit forms
625
  public function group_add ( $pod, $label, $fields, $context = 'normal', $priority = 'default' ) {
626
  if ( is_array( $pod ) && !empty( $pod ) && !isset( $pod[ 'name' ] ) ) {
627
  foreach ( $pod as $p ) {
628
+ $this->group_add( $p, $label, $fields, $context, $priority );
629
  }
630
 
631
  return true;
753
  }
754
  elseif ( 'media' == $pod[ 'type' ] ) {
755
  if ( !has_filter( 'wp_update_attachment_metadata', array( $this, 'save_media' ), 10, 2 ) ) {
756
+ add_action( 'add_meta_boxes', array( $this, 'meta_post_add' ) );
757
+ add_action( 'wp_ajax_save-attachment-compat', array( $this, 'save_media_ajax' ), 0 );
 
 
758
 
759
  add_filter( 'attachment_fields_to_edit', array( $this, 'meta_media' ), 10, 2 );
760
 
1082
  );
1083
  }
1084
  else {
1085
+ $dep_options = PodsForm::dependencies( $field, 'pods-meta-' );
1086
+ $dep_classes = $dep_options[ 'classes' ];
1087
+ $dep_data = $dep_options[ 'data' ];
1088
 
1089
  do_action( 'pods_meta_' . __FUNCTION__ . '_' . $field[ 'name' ], $post, $field, $pod );
1090
  ?>
1091
+ <tr class="form-field pods-field pods-field-input <?php echo esc_attr( 'pods-form-ui-row-type-' . $field[ 'type' ] . ' pods-form-ui-row-name-' . PodsForm::clean( $field[ 'name' ], true ) ); ?> <?php echo esc_attr( $dep_classes ); ?>" <?php PodsForm::data( $dep_data ); ?>">
1092
  <th scope="row" valign="top"><?php echo PodsForm::label( 'pods_meta_' . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); ?></th>
1093
  <td>
1094
  <?php
1096
  if ( isset( $field[ 'help' ] ) )
1097
  unset( $field[ 'help' ] );
1098
  ?>
1099
+ <div class="pods-submittable-fields">
1100
  <?php echo PodsForm::field( 'pods_meta_' . $field[ 'name' ], $value, $field[ 'type' ], $field, $pod, $id ); ?>
1101
  <?php echo PodsForm::comment( 'pods_meta_' . $field[ 'name' ], $field[ 'description' ], $field ); ?>
1102
+ </div>
1103
  </td>
1104
  </tr>
1105
  <?php
1231
  $pod = self::$current_pod;
1232
  $data = array();
1233
 
1234
+ if ( $pod ) {
1235
+ $rest_enable = (boolean) pods_v( 'rest_enable', $pod->pod_data['options'], false );
1236
+
1237
+ // Block REST API saves, we handle those separately in PodsRESTHandlers
1238
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST && $rest_enable ) {
1239
+ return;
1240
+ }
1241
+ }
1242
+ // The following code will run for all post_types (not just Pods)
1243
+
1244
  if ( false !== $nonced && ! empty( $groups ) ) {
1245
  foreach ( $groups as $group ) {
1246
  if ( empty( $group['fields'] ) ) {
1278
  // Fix for Pods doing it's own sanitizing
1279
  $data = pods_unslash( (array) $data );
1280
 
1281
+ $pod->save( $data, null, null, array( 'is_new_item' => $is_new_item, 'podsmeta' => true ) );
1282
  } elseif ( ! empty( $id ) ) {
1283
  foreach ( $data as $field => $value ) {
1284
  update_post_meta( $id, $field, $value );
1300
 
1301
  }
1302
 
1303
+ /**
1304
+ * Track changed fields before save for posts.
1305
+ *
1306
+ * @param array $data
1307
+ * @param array $postarr
1308
+ *
1309
+ * @return array
1310
+ */
1311
+ public function save_post_track_changed_fields( $data, $postarr ) {
1312
+
1313
+ $no_conflict = pods_no_conflict_check( 'post' );
1314
+
1315
+ if ( ! $no_conflict && ! empty( $data['post_type'] ) && ! empty( $postarr['ID'] ) ) {
1316
+ $pod = $data['post_type'];
1317
+ $id = $postarr['ID'];
1318
+
1319
+ PodsAPI::handle_changed_fields( $pod, $id, 'reset' );
1320
+ }
1321
+
1322
+ return $data;
1323
+
1324
+ }
1325
+
1326
  /**
1327
  * @param $form_fields
1328
  * @param $post
1336
  return $form_fields;
1337
 
1338
  wp_enqueue_style( 'pods-form' );
1339
+ wp_enqueue_script( 'pods' );
1340
 
1341
  $id = null;
1342
 
1448
  }
1449
  }
1450
 
1451
+ if ( $pod ) {
1452
+ $rest_enable = (boolean) pods_v( 'rest_enable', $pod->pod_data['options'], false );
1453
+
1454
+ // Block REST API saves, we handle those separately in PodsRESTHandlers
1455
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST && $rest_enable ) {
1456
+ return $post;
1457
+ }
1458
+ }
1459
+
1460
  do_action( 'pods_meta_save_pre_media', $data, $pod, $id, $groups, $post, $attachment );
1461
 
1462
  if ( !empty( $pod ) ) {
1517
  */
1518
  public function meta_taxonomy ( $tag, $taxonomy = null ) {
1519
  wp_enqueue_style( 'pods-form' );
1520
+ wp_enqueue_script( 'pods' );
1521
 
1522
  do_action( 'pods_meta_' . __FUNCTION__, $tag, $taxonomy );
1523
 
1628
  $has_fields = false;
1629
 
1630
  foreach ( $groups as $group ) {
1631
+ if ( empty( $group['fields'] ) ) {
1632
+ continue;
1633
+ }
1634
 
1635
+ if ( null === $term ) {
1636
+ $term = get_term( $term_id, $taxonomy );
1637
 
1638
+ $data = array(
1639
+ 'name' => $term->name
1640
+ );
1641
+ }
1642
 
1643
+ $has_fields = true;
1644
 
1645
+ if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
1646
+ if ( ! is_object( self::$current_pod ) || self::$current_pod->pod != $group['pod']['name'] ) {
1647
+ self::$current_pod = pods( $group['pod']['name'], $id, true );
1648
+ } elseif ( self::$current_pod->id() != $id ) {
1649
+ self::$current_pod->fetch( $id );
1650
+ }
 
 
1651
 
1652
+ $pod = self::$current_pod;
1653
+ }
1654
 
1655
+ foreach ( $group['fields'] as $field ) {
1656
+ if ( false === PodsForm::permission( $field['type'], $field['name'], $field, $group['fields'], $pod, $id ) ) {
1657
+ if ( ! pods_var( 'hidden', $field['options'], false ) ) {
1658
+ continue;
1659
+ }
1660
+ }
1661
 
1662
+ $data[ $field['name'] ] = '';
1663
 
1664
+ if ( isset( $_POST[ 'pods_meta_' . $field['name'] ] ) ) {
1665
+ $data[ $field['name'] ] = $_POST[ 'pods_meta_' . $field['name'] ];
1666
+ }
1667
+ }
1668
  }
1669
 
1670
+ if ( $pod ) {
1671
+ $rest_enable = (boolean) pods_v( 'rest_enable', $pod->pod_data['options'], false );
1672
+
1673
+ // Block REST API saves, we handle those separately in PodsRESTHandlers
1674
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST && $rest_enable ) {
1675
+ return $term_id;
1676
+ }
1677
+ }
1678
+
1679
  if ( !$has_fields ) {
1680
  return $term_id;
1681
  }
1710
  return $term_id;
1711
  }
1712
 
1713
+ /**
1714
+ * Track changed fields before save for terms.
1715
+ *
1716
+ * @param int $term_id
1717
+ * @param string $taxonomy
1718
+ */
1719
+ public function save_taxonomy_track_changed_fields( $term_id, $taxonomy ) {
1720
+
1721
+ $no_conflict = pods_no_conflict_check( 'term' );
1722
+
1723
+ if ( ! $no_conflict ) {
1724
+ $pod = $taxonomy;
1725
+ $id = $term_id;
1726
+
1727
+ PodsAPI::handle_changed_fields( $pod, $id, 'reset' );
1728
+ }
1729
+
1730
+ }
1731
+
1732
  /**
1733
  * @param $user_id
1734
  */
1735
  public function meta_user ( $user_id ) {
1736
  wp_enqueue_style( 'pods-form' );
1737
+ wp_enqueue_script( 'pods' );
1738
 
1739
  do_action( 'pods_meta_' . __FUNCTION__, $user_id );
1740
 
1862
  $pod = self::$current_pod;
1863
  $data = array();
1864
 
1865
+ if ( $pod ) {
1866
+ $rest_enable = (boolean) pods_v( 'rest_enable', $pod->pod_data['options'], false );
1867
+
1868
+ // Block REST API saves, we handle those separately in PodsRESTHandlers
1869
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST && $rest_enable ) {
1870
+ return;
1871
+ }
1872
+ }
1873
+
1874
  if ( false !== $nonced && ! empty( $groups ) ) {
1875
  foreach ( $groups as $group ) {
1876
  if ( empty( $group['fields'] ) ) {
1926
 
1927
  }
1928
 
1929
+ /**
1930
+ * Track changed fields before save for users.
1931
+ *
1932
+ * @param string $user_login
1933
+ *
1934
+ * @return string
1935
+ */
1936
+ public function save_user_track_changed_fields( $user_login ) {
1937
+
1938
+ $no_conflict = pods_no_conflict_check( 'user' );
1939
+
1940
+ if ( ! $no_conflict ) {
1941
+ $user = get_user_by( 'login', $user_login );
1942
+
1943
+ if ( $user && ! is_wp_error( $user ) ) {
1944
+ $pod = 'user';
1945
+ $id = $user->ID;
1946
+
1947
+ PodsAPI::handle_changed_fields( $pod, $id, 'reset' );
1948
+ }
1949
+ }
1950
+
1951
+ return $user_login;
1952
+
1953
+ }
1954
+
1955
  /**
1956
  * @param $commenter
1957
  * @param $user_identity
1958
  */
1959
  public function meta_comment_new_logged_in ( $commenter, $user_identity ) {
1960
  wp_enqueue_style( 'pods-form' );
1961
+ wp_enqueue_script( 'pods' );
1962
 
1963
  do_action( 'pods_meta_' . __FUNCTION__, $commenter, $user_identity );
1964
 
2025
  */
2026
  public function meta_comment_new ( $form_fields ) {
2027
  wp_enqueue_style( 'pods-form' );
2028
+ wp_enqueue_script( 'pods' );
2029
 
2030
  $groups = $this->groups_get( 'comment', 'comment' );
2031
 
2151
  */
2152
  public function meta_comment ( $comment, $metabox ) {
2153
  wp_enqueue_style( 'pods-form' );
2154
+ wp_enqueue_script( 'pods' );
2155
 
2156
  do_action( 'pods_meta_' . __FUNCTION__, $comment, $metabox );
2157
 
2318
  }
2319
  }
2320
 
2321
+ if ( $pod ) {
2322
+ $rest_enable = (boolean) pods_v( 'rest_enable', $pod->pod_data['options'], false );
2323
+
2324
+ // Block REST API saves, we handle those separately in PodsRESTHandlers
2325
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST && $rest_enable ) {
2326
+ return $comment_id;
2327
+ }
2328
+ }
2329
+
2330
  do_action( 'pods_meta_save_pre_comment', $data, $pod, $id, $groups );
2331
 
2332
  if ( !empty( $pod ) ) {
2350
  return $comment_id;
2351
  }
2352
 
2353
+ /**
2354
+ * Track changed fields before save for comments.
2355
+ *
2356
+ * @param array $data The new, processed comment data.
2357
+ * @param array $comment The old, unslashed comment data.
2358
+ * @param array $commentarr The new, raw comment data.
2359
+ *
2360
+ * @return array
2361
+ */
2362
+ public function save_comment_track_changed_fields( $data, $comment, $commentarr ) {
2363
+
2364
+ $no_conflict = pods_no_conflict_check( 'user' );
2365
+
2366
+ if ( ! $no_conflict && ! empty( $comment['comment_type'] ) && ! empty( $comment['comment_ID'] ) ) {
2367
+ $pod = $comment['comment_type'];
2368
+ $id = $comment['comment_ID'];
2369
+
2370
+ PodsAPI::handle_changed_fields( $pod, $id, 'reset' );
2371
+ }
2372
+
2373
+ return $data;
2374
+
2375
+ }
2376
+
2377
  /**
2378
  * All *_*_meta filter handler aliases
2379
  *
2751
  $object_name = $object->post_type;
2752
  }
2753
  elseif ( 'taxonomy' == $object_type ) {
2754
+ $object = get_term( $object_id );
 
2755
 
2756
+ if ( !is_object( $object ) || !isset( $object->taxonomy ) ){
2757
+ return false;
2758
+ }
2759
 
2760
+ $object_name = $object->taxonomy;
2761
+ if ( empty( $aux ) ) {
2762
+ $object_name = $wpdb->get_var( $wpdb->prepare( "SELECT `taxonomy` FROM `{$wpdb->term_taxonomy}` WHERE `term_id` = %d", $object_id ) );
2763
  } else {
2764
+ $object_name = $aux;
2765
  }
2766
  }
2767
  elseif ( 'settings' == $object_type )
2829
  $single = false;
2830
  }
2831
 
2832
+ if ( 'user' === $object_type && 'locale' === $meta_key ) {
2833
+ return $_null; // don't interfere with locale
2834
+ }
2835
+
2836
  $object = $this->get_object( $object_type, $object_id );
2837
 
2838
  if ( empty( $object_id ) || empty( $object ) )
classes/PodsRESTFields.php CHANGED
@@ -53,12 +53,21 @@ class PodsRESTFields {
53
  private function set_pod( $pod ) {
54
 
55
  if ( is_string( $pod ) ) {
56
- $this->set_pod( pods( $pod, null, true ) );
57
 
 
58
  } else {
59
  $type = $pod->pod_data['type'];
60
 
61
- if ( in_array( $type, array( 'post_type', 'user', 'taxonomy', 'media', 'comment' ) ) ) {
 
 
 
 
 
 
 
 
62
  $this->pod = $pod;
63
  } else {
64
  $this->pod = false;
@@ -78,6 +87,20 @@ class PodsRESTFields {
78
 
79
  $fields = $this->pod->fields();
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  foreach ( $fields as $field_name => $field ) {
82
  $read = self::field_allowed_to_extend( $field_name, $this->pod, 'read' );
83
  $write = self::field_allowed_to_extend( $field_name, $this->pod, 'write' );
@@ -94,46 +117,30 @@ class PodsRESTFields {
94
  *
95
  * @access protected
96
  *
97
- * @param string $field_name Name of fields.
98
- * @param bool|string|array $read Allowing reading?
99
- * @param bool|string|array $write Allow writing?
100
  */
101
  protected function register( $field_name, $read, $write ) {
102
 
103
  $args = array();
104
 
105
- switch ( $read ) {
106
- case true === $read :
107
- $args['get_callback'] = array( 'PodsRESTHandlers', 'get_handler' );
108
- break;
109
- case is_callable( $read ) :
110
- $args['get_callback'] = $read;
111
- $read = true;
112
- break;
113
  }
114
 
115
- switch ( $write ) {
116
- case true === $write :
117
- $args['update_callback'] = array( 'PodsRESTHandlers', 'write_handler' );
118
- break;
119
- case is_callable( $write ) :
120
- $args['update_callback'] = $write;
121
- $write = true;
122
- break;
123
  }
124
 
125
  $object_type = $this->pod->pod;
126
 
127
- if ( 'media' == $object_type ) {
128
  $object_type = 'attachment';
129
  }
130
 
131
  if ( $read || $write ) {
132
- if ( function_exists( 'register_rest_field' ) ) {
133
- register_rest_field( $object_type, $field_name, $args );
134
- } elseif ( function_exists( 'register_api_field' ) ) {
135
- register_api_field( $object_type, $field_name, $args );
136
- }
137
  }
138
 
139
  }
@@ -143,9 +150,9 @@ class PodsRESTFields {
143
  *
144
  * @since 2.5.6
145
  *
146
- * @param string $field_name The field name.
147
- * @param object|Pods $pod Pods object.
148
- * @param string $mode Are we checking read or write?
149
  *
150
  * @return bool If supports, true, else false.
151
  */
@@ -154,19 +161,25 @@ class PodsRESTFields {
154
  $allowed = false;
155
 
156
  if ( is_object( $pod ) ) {
157
- $fields = $pod->fields();
158
 
159
- if ( array_key_exists( $field_name, $fields ) ) {
160
  $pod_options = $pod->pod_data['options'];
161
 
162
- if ( 'read' === $mode && pods_v( 'read_all', $pod_options, false ) ) {
 
 
 
163
  $allowed = true;
164
- } elseif ( 'write' === $mode && pods_v( 'write_all', $pod_options, false ) ) {
165
  $allowed = true;
166
- } elseif ( isset( $fields[ $field_name ] ) ) {
167
- if ( 'read' === $mode && 1 == (int) $pod->fields( $field_name, 'rest_read' ) ) {
 
 
 
168
  $allowed = true;
169
- } elseif ( 'write' === $mode && 1 == (int) $pod->fields( $field_name, 'rest_write' ) ) {
170
  $allowed = true;
171
  }
172
  }
@@ -177,4 +190,4 @@ class PodsRESTFields {
177
 
178
  }
179
 
180
- }
53
  private function set_pod( $pod ) {
54
 
55
  if ( is_string( $pod ) ) {
56
+ $pod = pods( $pod, null, true );
57
 
58
+ $this->set_pod( $pod );
59
  } else {
60
  $type = $pod->pod_data['type'];
61
 
62
+ $supported_pod_types = array(
63
+ 'post_type',
64
+ 'taxonomy',
65
+ 'media',
66
+ 'user',
67
+ 'comment',
68
+ );
69
+
70
+ if ( in_array( $type, $supported_pod_types, true ) ) {
71
  $this->pod = $pod;
72
  } else {
73
  $this->pod = false;
87
 
88
  $fields = $this->pod->fields();
89
 
90
+ $rest_hook_name = $this->pod->pod_data['name'];
91
+
92
+ if ( 'media' === $rest_hook_name ) {
93
+ $rest_hook_name = 'attachment';
94
+ } elseif ( 'comment' === $this->pod->pod_data['type'] ) {
95
+ $rest_hook_name = 'comment';
96
+ }
97
+
98
+ $rest_hook_name = 'rest_insert_' . $rest_hook_name;
99
+
100
+ if ( ! has_action( $rest_hook_name, array( 'PodsRESTHandlers', 'save_handler' ) ) ) {
101
+ add_action( $rest_hook_name, array( 'PodsRESTHandlers', 'save_handler' ), 10, 3 );
102
+ }
103
+
104
  foreach ( $fields as $field_name => $field ) {
105
  $read = self::field_allowed_to_extend( $field_name, $this->pod, 'read' );
106
  $write = self::field_allowed_to_extend( $field_name, $this->pod, 'write' );
117
  *
118
  * @access protected
119
  *
120
+ * @param string $field_name Name of field
121
+ * @param bool $read Field allows REST API read access
122
+ * @param bool $write Field allows REST API write access
123
  */
124
  protected function register( $field_name, $read, $write ) {
125
 
126
  $args = array();
127
 
128
+ if ( $read ) {
129
+ $args['get_callback'] = array( 'PodsRESTHandlers', 'get_handler' );
 
 
 
 
 
 
130
  }
131
 
132
+ if ( $write ) {
133
+ $args['pods_update'] = true;
 
 
 
 
 
 
134
  }
135
 
136
  $object_type = $this->pod->pod;
137
 
138
+ if ( 'media' === $object_type ) {
139
  $object_type = 'attachment';
140
  }
141
 
142
  if ( $read || $write ) {
143
+ register_rest_field( $object_type, $field_name, $args );
 
 
 
 
144
  }
145
 
146
  }
150
  *
151
  * @since 2.5.6
152
  *
153
+ * @param string $field_name The field name.
154
+ * @param Pods $pod Pods object.
155
+ * @param string $mode Are we checking read or write?
156
  *
157
  * @return bool If supports, true, else false.
158
  */
161
  $allowed = false;
162
 
163
  if ( is_object( $pod ) ) {
164
+ $field = $pod->fields( $field_name );
165
 
166
+ if ( $field ) {
167
  $pod_options = $pod->pod_data['options'];
168
 
169
+ $read_all = (int) pods_v( 'read_all', $pod_options, 0 );
170
+ $write_all = (int) pods_v( 'write_all', $pod_options, 0 );
171
+
172
+ if ( 'read' === $mode && 1 === $read_all ) {
173
  $allowed = true;
174
+ } elseif ( 'write' === $mode && 1 === $write_all ) {
175
  $allowed = true;
176
+ } else {
177
+ $rest_read = (int) $pod->fields( $field_name, 'rest_read' );
178
+ $rest_write = (int) $pod->fields( $field_name, 'rest_write' );
179
+
180
+ if ( 'read' === $mode && 1 === $rest_read ) {
181
  $allowed = true;
182
+ } elseif ( 'write' === $mode && 1 === $rest_write ) {
183
  $allowed = true;
184
  }
185
  }
190
 
191
  }
192
 
193
+ }
classes/PodsRESTHandlers.php CHANGED
@@ -30,11 +30,11 @@ class PodsRESTHandlers {
30
  */
31
  protected static function get_pod( $pod_name, $id ) {
32
 
33
- if ( ! self::$pod || self::$pod->pod != $pod_name ) {
34
  self::$pod = pods( $pod_name, $id, true );
35
  }
36
 
37
- if ( self::$pod && self::$pod->id != $id ) {
38
  self::$pod->fetch( $id );
39
  }
40
 
@@ -73,7 +73,7 @@ class PodsRESTHandlers {
73
  */
74
 
75
  if ( empty( $pod_name ) ) {
76
- if ( 'attachment' == $object_type ) {
77
  $pod_name = 'media';
78
  } else {
79
  $pod_name = $object_type;
@@ -108,10 +108,24 @@ class PodsRESTHandlers {
108
 
109
  $field_data = $pod->fields( $field_name );
110
 
111
- if ( 'pick' == pods_v( 'type', $field_data ) ) {
112
  $output_type = pods_v( 'rest_pick_response', $field_data['options'], 'array' );
113
 
114
- if ( 'array' == $output_type ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  $related_pod_items = $pod->field( $field_name, array( 'output' => 'pod' ) );
116
 
117
  if ( $related_pod_items ) {
@@ -171,8 +185,9 @@ class PodsRESTHandlers {
171
  $depth = apply_filters( 'pods_rest_api_depth_for_relationship_response', $depth, $field_name, $pod, $related_pod, $id, $request );
172
 
173
  $params = array(
174
- 'fields' => $fields,
175
- 'depth' => $depth,
 
176
  );
177
 
178
  $items[] = $related_pod->export( $params );
@@ -198,158 +213,70 @@ class PodsRESTHandlers {
198
  }
199
 
200
  /**
201
- * Handler for updating custom field data.
202
  *
203
- * @since 2.5.6
204
- *
205
- * @param mixed $value Value to write
206
- * @param object $object The object from the response
207
- * @param string $field_name Name of field
208
- * @param WP_REST_Request $request Current request
209
- * @param string $object_type Type of object
210
- *
211
- * @return bool|int
212
  */
213
- public static function write_handler( $value, $object, $field_name, $request, $object_type ) {
214
-
215
- $pod_name = pods_v( 'type', $object );
216
-
217
- /**
218
- * If $pod_name in the line above is empty then the route invoked
219
- * may be for a taxonomy, so lets try and check for that
220
- *
221
- */
222
- if ( empty( $pod_name ) ) {
223
- $pod_name = pods_v( 'taxonomy', $object );
224
- }
225
 
226
- /**
227
- * $pod_name is still empty, so check lets check $object_type
228
- *
229
- */
230
 
231
- if ( empty( $pod_name ) ) {
232
- if ( 'attachment' == $object_type ) {
233
  $pod_name = 'media';
234
- } else {
235
- $pod_name = $object_type;
236
  }
237
- }
238
-
239
- /**
240
- * Filter the pod name
241
- *
242
- * @since 2.6.7
243
- *
244
- * @param array $pod_name Pod name
245
- * @param Pods $object Rest object
246
- * @param string $field_name Name of the field
247
- * @param WP_REST_Request $request Current request
248
- * @param string $object_type Rest Object type
249
- */
250
- $pod_name = apply_filters( 'pods_rest_api_pod_name', $pod_name, $object, $field_name, $request, $object_type );
251
 
252
- $id = pods_v( 'id', $object );
 
 
253
 
254
- if ( empty( $id ) ) {
255
- $id = pods_v( 'ID', $object );
256
- }
257
- $pod = self::get_pod( $pod_name, $id );
258
 
259
- if ( $pod && PodsRESTFields::field_allowed_to_extend( $field_name, $pod, 'write' ) ) {
260
- $pod->save( $field_name, $value, $id );
 
261
 
262
- return $pod->field( $field_name );
 
 
 
263
  }
264
 
265
- return false;
266
-
267
- }
268
 
269
- /**
270
- * Add REST API support to a post type
271
- *
272
- * @since 2.5.6
273
- *
274
- * @param string $post_type_name Name of post type
275
- * @param bool|false $rest_base Optional. Base url segment. If not set, post type name is used
276
- * @param string $controller Optional, controller class for route. If not set "WP_REST_Posts_Controller" is
277
- * used.
278
- */
279
- public static function post_type_rest_support( $post_type_name, $rest_base = false, $controller = 'WP_REST_Posts_Controller' ) {
280
 
281
- global $wp_post_types;
282
 
283
- // Only add support for post types that exist
284
- if ( isset( $wp_post_types[ $post_type_name ] ) ) {
285
- // Only add support if REST base not already set
286
- if ( empty( $wp_post_types[ $post_type_name ]->rest_base ) ) {
287
- if ( ! $rest_base ) {
288
- $rest_base = $post_type_name;
289
- }
290
 
291
- $wp_post_types[ $post_type_name ]->show_in_rest = true;
292
- $wp_post_types[ $post_type_name ]->rest_base = $rest_base;
293
- $wp_post_types[ $post_type_name ]->rest_controller_class = $controller;
294
- }
295
- }
296
 
297
- }
 
 
298
 
299
- /**
300
- * Add REST API support to an already registered taxonomy.
301
- *
302
- * @since 2.5.6
303
- *
304
- * @param string $taxonomy_name Taxonomy name.
305
- * @param bool|false $rest_base Optional. Base url segment. If not set, taxonomy name is used.
306
- * @param string $controller Optional, controller class for route. If not set "WP_REST_Terms_Controller" is
307
- * used.
308
- */
309
- public static function taxonomy_rest_support( $taxonomy_name, $rest_base = false, $controller = 'WP_REST_Terms_Controller' ) {
310
-
311
- /** As of WordPress 4.7: https://make.wordpress.org/core/2016/10/29/wp_taxonomy-in-4-7/ */
312
- /** @var WP_Taxonomy[] $wp_taxonomies */
313
- global $wp_taxonomies;
314
-
315
- // Only add support for taxonomies that exist
316
- if ( isset( $wp_taxonomies[ $taxonomy_name ] ) ) {
317
- // Only add support if REST base not already set
318
- if ( empty( $wp_taxonomies[ $taxonomy_name ]->rest_base ) ) {
319
- if ( ! $rest_base ) {
320
- $rest_base = $taxonomy_name;
321
  }
322
 
323
- $wp_taxonomies[ $taxonomy_name ]->show_in_rest = true;
324
- $wp_taxonomies[ $taxonomy_name ]->rest_base = $rest_base;
325
- $wp_taxonomies[ $taxonomy_name ]->rest_controller_class = $controller;
326
  }
327
 
 
 
 
328
  }
329
- }
330
-
331
- /**
332
- * Check if a Pod supports extending core REST response.
333
- *
334
- * @since 2.5.6
335
- *
336
- * @param array|Pods $pod Pod object or the pod_data array
337
- *
338
- * @return bool
339
- */
340
- public static function pod_extends_core_route( $pod ) {
341
-
342
- $enabled = false;
343
-
344
- if ( is_object( $pod ) ) {
345
- $pod = $pod->pod_data;
346
- }
347
-
348
- if ( is_array( $pod ) ) {
349
- $enabled = (boolean) pods_v( 'rest_enable', $pod['options'], false );
350
- }
351
-
352
- return $enabled;
353
 
354
  }
355
 
30
  */
31
  protected static function get_pod( $pod_name, $id ) {
32
 
33
+ if ( ! self::$pod || self::$pod->pod !== $pod_name ) {
34
  self::$pod = pods( $pod_name, $id, true );
35
  }
36
 
37
+ if ( self::$pod && (int) self::$pod->id !== (int) $id ) {
38
  self::$pod->fetch( $id );
39
  }
40
 
73
  */
74
 
75
  if ( empty( $pod_name ) ) {
76
+ if ( 'attachment' === $object_type ) {
77
  $pod_name = 'media';
78
  } else {
79
  $pod_name = $object_type;
108
 
109
  $field_data = $pod->fields( $field_name );
110
 
111
+ if ( 'pick' === pods_v( 'type', $field_data ) ) {
112
  $output_type = pods_v( 'rest_pick_response', $field_data['options'], 'array' );
113
 
114
+ /**
115
+ * What output type to use for a related field REST response.
116
+ *
117
+ * @since 2.7
118
+ *
119
+ * @param string $output_type The pick response output type.
120
+ * @param string $field_name The name of the field
121
+ * @param array $field_data The field data
122
+ * @param object|Pods $pod The Pods object for Pod relationship is from.
123
+ * @param int $id Current item ID
124
+ * @param object|WP_REST_Request Current request object.
125
+ */
126
+ $output_type = apply_filters( 'pods_rest_api_output_type_for_relationship_response', $output_type, $field_name, $field_data, $pod, $id, $request );
127
+
128
+ if ( 'array' === $output_type ) {
129
  $related_pod_items = $pod->field( $field_name, array( 'output' => 'pod' ) );
130
 
131
  if ( $related_pod_items ) {
185
  $depth = apply_filters( 'pods_rest_api_depth_for_relationship_response', $depth, $field_name, $pod, $related_pod, $id, $request );
186
 
187
  $params = array(
188
+ 'fields' => $fields,
189
+ 'depth' => $depth,
190
+ 'context' => 'rest',
191
  );
192
 
193
  $items[] = $related_pod->export( $params );
213
  }
214
 
215
  /**
216
+ * Handle saving of Pod fields from REST API write requests.
217
  *
218
+ * @param WP_Post|WP_Term|WP_User|WP_Comment $object Inserted or updated object.
219
+ * @param WP_REST_Request $request Request object.
220
+ * @param bool $creating True when creating an item, false when updating.
 
 
 
 
 
 
221
  */
222
+ public static function save_handler( $object, $request, $creating ) {
 
 
 
 
 
 
 
 
 
 
 
223
 
224
+ if ( is_a( $object, 'WP_Post' ) ) {
225
+ $pod_name = $object->post_type;
 
 
226
 
227
+ if ( 'attachment' === $pod_name ) {
 
228
  $pod_name = 'media';
 
 
229
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
 
231
+ $id = $object->ID;
232
+ } elseif ( is_a( $object, 'WP_Term' ) ) {
233
+ $pod_name = $object->taxonomy;
234
 
235
+ $id = $object->term_id;
236
+ } elseif ( is_a( $object, 'WP_User' ) ) {
237
+ $pod_name = 'user';
 
238
 
239
+ $id = $object->ID;
240
+ } elseif ( is_a( $object, 'WP_Comment' ) ) {
241
+ $pod_name = 'comment';
242
 
243
+ $id = $object->comment_ID;
244
+ } else {
245
+ // Not a supported object
246
+ return;
247
  }
248
 
249
+ $pod = self::get_pod( $pod_name, $id );
 
 
250
 
251
+ global $wp_rest_additional_fields;
 
 
 
 
 
 
 
 
 
 
252
 
253
+ $rest_enable = (boolean) pods_v( 'rest_enable', $pod->pod_data['options'], false );
254
 
255
+ if ( $pod && $rest_enable && ! empty( $wp_rest_additional_fields[ $pod_name ] ) ) {
256
+ $fields = $pod->fields();
 
 
 
 
 
257
 
258
+ $save_fields = array();
 
 
 
 
259
 
260
+ $params = array(
261
+ 'is_new_item' => $creating,
262
+ );
263
 
264
+ foreach ( $fields as $field_name => $field ) {
265
+ if ( empty( $wp_rest_additional_fields[ $pod_name ][ $field_name ]['pods_update'] ) ) {
266
+ continue;
267
+ } elseif ( ! isset( $request[ $field_name ] ) ) {
268
+ continue;
269
+ } elseif ( ! PodsRESTFields::field_allowed_to_extend( $field_name, $pod, 'write' ) ) {
270
+ continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  }
272
 
273
+ $save_fields[ $field_name ] = $request[ $field_name ];
 
 
274
  }
275
 
276
+ if ( ! empty( $save_fields ) || $creating ) {
277
+ $pod->save( $save_fields, null, null, $params );
278
+ }
279
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
 
281
  }
282
 
classes/PodsUI.php CHANGED
@@ -487,6 +487,7 @@ class PodsUI {
487
  $this->pods_data = pods_data( $this->pod );
488
 
489
  $options = $this->do_hook( 'pre_init', $options );
 
490
  $this->setup( $options );
491
 
492
  if ( is_object( $this->pods_data ) && is_object( $this->pod ) && 0 < $this->id ) {
@@ -502,6 +503,16 @@ class PodsUI {
502
  return false;
503
  }
504
 
 
 
 
 
 
 
 
 
 
 
505
  $this->go();
506
  }
507
 
@@ -914,43 +925,53 @@ class PodsUI {
914
  $item = __( 'Item', 'pods' );
915
  $items = __( 'Items', 'pods' );
916
 
 
 
 
 
917
  if ( is_object( $this->pod ) ) {
918
- $item = pods_var_raw( 'label_singular', $this->pod->pod_data[ 'options' ], pods_var_raw( 'label', $this->pod->pod_data, $item, null, true ), null, true );
919
- $items = pods_var_raw( 'label', $this->pod->pod_data, $items, null, true );
 
 
 
 
 
 
920
  }
921
 
922
  $options->validate( 'item', $item );
923
  $options->validate( 'items', $items );
924
 
925
  $options->validate( 'heading', array(
926
- 'manage' => __( 'Manage', 'pods' ),
927
- 'add' => __( 'Add New', 'pods' ),
928
- 'edit' => __( 'Edit', 'pods' ),
929
- 'duplicate' => __( 'Duplicate', 'pods' ),
930
- 'view' => __( 'View', 'pods' ),
931
- 'reorder' => __( 'Reorder', 'pods' ),
932
- 'search' => __( 'Search', 'pods' ),
933
- 'views' => __( 'View', 'pods' )
934
  ), 'array_merge' );
935
 
936
  $options->validate( 'header', array(
937
- 'manage' => sprintf( __( 'Manage %s', 'pods' ), $options->items ),
938
- 'add' => sprintf( __( 'Add New %s', 'pods' ), $options->item ),
939
- 'edit' => sprintf( __( 'Edit %s', 'pods' ), $options->item ),
940
- 'duplicate' => sprintf( __( 'Duplicate %s', 'pods' ), $options->item ),
941
- 'view' => sprintf( __( 'View %s', 'pods' ), $options->item ),
942
- 'reorder' => sprintf( __( 'Reorder %s', 'pods' ), $options->items ),
943
- 'search' => sprintf( __( 'Search %s', 'pods' ), $options->items )
944
  ), 'array_merge' );
945
 
946
  $options->validate( 'label', array(
947
- 'add' => sprintf( __( 'Save New %s', 'pods' ), $options->item ),
948
- 'add_new' => __( 'Add New', 'pods' ),
949
- 'edit' => sprintf( __( 'Save %s', 'pods' ), $options->item ),
950
- 'duplicate' => sprintf( __( 'Save New %s', 'pods' ), $options->item ),
951
- 'delete' => sprintf( __( 'Delete this %s', 'pods' ), $options->item ),
952
- 'view' => sprintf( __( 'View %s', 'pods' ), $options->item ),
953
- 'reorder' => sprintf( __( 'Reorder %s', 'pods' ), $options->items )
954
  ), 'array_merge' );
955
 
956
  $options->validate( 'fields', array(
@@ -1418,6 +1439,10 @@ class PodsUI {
1418
  if ( false !== $this->callback_action( 'add' ) ) {
1419
  return null;
1420
  }
 
 
 
 
1421
  ?>
1422
  <div class="wrap pods-ui">
1423
  <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div>
@@ -1425,13 +1450,15 @@ class PodsUI {
1425
  <?php
1426
  echo wp_kses_post( $this->header[ 'add' ] );
1427
 
1428
- $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
 
1429
 
1430
- if ( !empty( $this->action_links[ 'manage' ] ) ) {
1431
- $link = $this->action_links[ 'manage' ];
1432
- }
1433
  ?>
1434
- <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>
 
1435
  </h2>
1436
 
1437
  <?php $this->form( true ); ?>
@@ -1457,6 +1484,10 @@ class PodsUI {
1457
  elseif ( false !== $this->callback_action( 'edit', $duplicate ) ) {
1458
  return null;
1459
  }
 
 
 
 
1460
  ?>
1461
  <div class="wrap pods-ui">
1462
  <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div>
@@ -1464,7 +1495,7 @@ class PodsUI {
1464
  <?php
1465
  echo wp_kses_post( $this->do_template( $duplicate ? $this->header[ 'duplicate' ] : $this->header[ 'edit' ] ) );
1466
 
1467
- if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
1468
  $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num = '' ), self::$allowed, $this->exclusion() );
1469
 
1470
  if ( !empty( $this->action_links[ 'add' ] ) )
@@ -1473,7 +1504,7 @@ class PodsUI {
1473
  <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->heading[ 'add' ] ); ?></a>
1474
  <?php
1475
  }
1476
- elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) ) {
1477
  $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
1478
 
1479
  if ( !empty( $this->action_links[ 'manage' ] ) )
@@ -1551,6 +1582,8 @@ class PodsUI {
1551
  $alt_vars[ 'action' ] = 'manage';
1552
  unset( $alt_vars[ 'id' ] );
1553
  }
 
 
1554
  }
1555
 
1556
  $fields = array();
@@ -1742,7 +1775,7 @@ class PodsUI {
1742
  <?php
1743
  echo wp_kses_post( $this->do_template( $this->header[ 'view' ] ) );
1744
 
1745
- if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
1746
  $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num = '' ), self::$allowed, $this->exclusion() );
1747
 
1748
  if ( !empty( $this->action_links[ 'add' ] ) ) {
@@ -1752,7 +1785,7 @@ class PodsUI {
1752
  <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->heading[ 'add' ] ); ?></a>
1753
  <?php
1754
  }
1755
- elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) ) {
1756
  $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
1757
 
1758
  if ( !empty( $this->action_links[ 'manage' ] ) ) {
@@ -1973,9 +2006,108 @@ class PodsUI {
1973
  $this->manage();
1974
  }
1975
 
 
 
 
 
 
 
 
 
 
 
1976
 
1977
- public function export( ) {
1978
- $export_type = pods_var( 'export_type', 'get', 'csv' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1979
 
1980
  $type = 'sv'; // covers csv + tsv
1981
 
@@ -1984,23 +2116,22 @@ class PodsUI {
1984
 
1985
  $delimiter = ',';
1986
 
1987
- if ( 'tsv' == $export_type )
1988
- $delimiter = "\t";
1989
-
1990
- $columns = array();
1991
 
1992
- if ( empty( $this->fields[ 'export' ] ) ) {
1993
- $this->fields[ 'export' ] = $this->pod->fields;
 
1994
 
1995
- $columns = array(
1996
- $this->pod->pod_data[ 'field_id' ] => 'ID'
1997
- );
1998
- }
1999
 
2000
  if ( ! empty( $this->fields['export'] ) ) {
2001
- foreach ( $this->fields[ 'export' ] as $field ) {
2002
- $columns[ $field[ 'name' ] ] = $field[ 'label' ];
2003
- }
2004
  }
2005
 
2006
  $params = array(
@@ -2172,7 +2303,7 @@ class PodsUI {
2172
  if ( $params->full )
2173
  $find_params[ 'limit' ] = -1;
2174
 
2175
- $find_params = apply_filters('pods_ui_get_params', $find_params, $this->pod->pod, $this);
2176
 
2177
  /**
2178
  * Filter Pods::find() parameters to make it more easily extended by plugins and developers.
@@ -2361,7 +2492,7 @@ class PodsUI {
2361
  return null;
2362
  }
2363
 
2364
- if ( !empty( $this->action_bulk ) && !empty( $this->actions_bulk ) && isset( $this->actions_bulk[ $this->action_bulk ] ) && !in_array( $this->action_bulk, $this->actions_disabled ) && !empty( $this->bulk ) ) {
2365
  if ( empty( $_REQUEST[ '_wpnonce' . $this->num ] ) || false === wp_verify_nonce( $_REQUEST[ '_wpnonce' . $this->num ], 'pods-ui-action-bulk' ) ) {
2366
  pods_message( __( 'Invalid bulk request, please try again.', 'pods' ) );
2367
  }
@@ -2369,7 +2500,14 @@ class PodsUI {
2369
  return null;
2370
  }
2371
  elseif ( 'delete' == $this->action_bulk ) {
2372
- return $this->delete_bulk();
 
 
 
 
 
 
 
2373
  }
2374
  }
2375
 
@@ -2385,18 +2523,21 @@ class PodsUI {
2385
  if ( true === $reorder ) {
2386
  echo wp_kses_post( $this->header[ 'reorder' ] );
2387
 
2388
- $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
 
2389
 
2390
- if ( !empty( $this->action_links[ 'manage' ] ) )
2391
- $link = $this->action_links[ 'manage' ];
 
2392
  ?>
2393
  <small>(<a href="<?php echo esc_url( $link ); ?>">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>)</small>
2394
  <?php
 
2395
  }
2396
  else
2397
  echo wp_kses_post( $this->header[ 'manage' ] );
2398
 
2399
- if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
2400
  $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num => '' ), self::$allowed, $this->exclusion() );
2401
 
2402
  if ( !empty( $this->action_links[ 'add' ] ) )
@@ -2405,7 +2546,7 @@ class PodsUI {
2405
  <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->label[ 'add_new' ] ); ?></a>
2406
  <?php
2407
  }
2408
- if ( !in_array( 'reorder', $this->actions_disabled ) && !in_array( 'reorder', $this->actions_hidden ) && false !== $this->reorder[ 'on' ] ) {
2409
  $link = pods_query_arg( array( 'action' . $this->num => 'reorder' ), self::$allowed, $this->exclusion() );
2410
 
2411
  if ( !empty( $this->action_links[ 'reorder' ] ) )
@@ -2700,14 +2841,7 @@ class PodsUI {
2700
  elseif ( !in_array( 'export', $this->actions_disabled ) && !in_array( 'export', $this->actions_hidden ) ) {
2701
  ?>
2702
  <div class="alignleft actions">
2703
- <strong><?php _e( 'Export', 'pods' ); ?>:</strong>
2704
- <?php
2705
- foreach ( $this->export[ 'formats' ] as $format => $separator ) {
2706
- ?>
2707
- <input type="button" value=" <?php echo esc_attr( strtoupper( $format ) ); ?> " class="button" onclick="document.location='<?php echo pods_slash( pods_query_arg( array( 'action' . $this->num => 'export', 'export_type' . $this->num => $format, '_wpnonce' => wp_create_nonce( 'pods-ui-action-export' ) ), self::$allowed, $this->exclusion() ) ); ?>';" />
2708
- <?php
2709
- }
2710
- ?>
2711
  </div>
2712
  <?php
2713
  }
@@ -2756,7 +2890,7 @@ class PodsUI {
2756
  include_once ABSPATH . 'wp-admin/includes/template.php';
2757
 
2758
  wp_enqueue_script( 'thickbox' );
2759
- wp_enqueue_style( 'pods-ui-list-table', PODS_URL . 'ui/css/pods-ui-list-table.css', array( 'thickbox' ), PODS_VERSION );
2760
 
2761
  $filters = $this->filters;
2762
 
@@ -2981,7 +3115,7 @@ class PodsUI {
2981
  public function filters_popup () {
2982
  $filters = $this->filters;
2983
  ?>
2984
- <div id="pods-ui-posts-filter-popup" class="hidden">
2985
  <form action="" method="get" class="pods-ui-posts-filter-popup">
2986
  <h2><?php _e( 'Advanced Filters', 'pods' ); ?></h2>
2987
 
@@ -3046,14 +3180,14 @@ class PodsUI {
3046
  if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
3047
  $end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' );
3048
  ?>
3049
- <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? '' : ' hidden' ); ?>">+</span>
3050
- <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3051
 
3052
  <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_start">
3053
  <?php echo esc_html( $filter_field[ 'label' ] ); ?>
3054
  </label>
3055
 
3056
- <span class="pods-ui-posts-filter<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? ' hidden' : '' ); ?>">
3057
  <?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field[ 'type' ], $filter_field ); ?>
3058
 
3059
  <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_end">to</label>
@@ -3078,14 +3212,14 @@ class PodsUI {
3078
 
3079
  $options = array_merge( $filter_field, $filter_field[ 'options' ] );
3080
  ?>
3081
- <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
3082
- <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3083
 
3084
  <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3085
  <?php echo esc_html( $filter_field[ 'label' ] ); ?>
3086
  </label>
3087
 
3088
- <span class="pods-ui-posts-filter<?php echo esc_attr( strlen( $value ) < 1 ? ' hidden' : '' ); ?>">
3089
  <?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
3090
  </span>
3091
  <?php
@@ -3113,14 +3247,14 @@ class PodsUI {
3113
 
3114
  $options = array_merge( $filter_field, $filter_field[ 'options' ] );
3115
  ?>
3116
- <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
3117
- <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3118
 
3119
  <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3120
  <?php echo esc_html( $filter_field[ 'label' ] ); ?>
3121
  </label>
3122
 
3123
- <span class="pods-ui-posts-filter<?php echo esc_attr( strlen( $value ) < 1 ? ' hidden' : '' ); ?>">
3124
  <?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
3125
  </span>
3126
  <?php
@@ -3138,14 +3272,14 @@ class PodsUI {
3138
  if ( empty( $options[ 'input_helper' ] ) && isset( $filter_field[ 'options' ] ) && isset( $filter_field[ 'options' ][ 'input_helper' ] ) )
3139
  $options[ 'input_helper' ] = $filter_field[ 'options' ][ 'input_helper' ];
3140
  ?>
3141
- <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
3142
- <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3143
 
3144
  <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3145
  <?php echo esc_html( $filter_field[ 'label' ] ); ?>
3146
  </label>
3147
 
3148
- <span class="pods-ui-posts-filter<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>">
3149
  <?php echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options ); ?>
3150
  </span>
3151
  <?php
@@ -3172,14 +3306,14 @@ class PodsUI {
3172
  <script type="text/javascript">
3173
  jQuery( function () {
3174
  jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-on', function ( e ) {
3175
- jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'hidden' );
3176
 
3177
  jQuery( this ).hide();
3178
  jQuery( this ).parent().find( '.toggle-off' ).show();
3179
  } );
3180
 
3181
  jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-off', function ( e ) {
3182
- jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'hidden' );
3183
  jQuery( this ).parent().find( 'select, input' ).val( '' );
3184
 
3185
  jQuery( this ).hide();
@@ -3187,14 +3321,14 @@ class PodsUI {
3187
  } );
3188
 
3189
  jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggled label', function ( e ) {
3190
- if ( jQuery( this ).parent().find( '.pods-ui-posts-filter' ).hasClass( 'hidden' ) ) {
3191
- jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'hidden' );
3192
 
3193
  jQuery( this ).parent().find( '.toggle-on' ).hide();
3194
  jQuery( this ).parent().find( '.toggle-off' ).show();
3195
  }
3196
  else {
3197
- jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'hidden' );
3198
  jQuery( this ).parent().find( 'select, input' ).val( '' );
3199
 
3200
  jQuery( this ).parent().find( '.toggle-on' ).show();
@@ -3218,7 +3352,7 @@ class PodsUI {
3218
 
3219
  if ( empty( $this->data ) ) {
3220
  ?>
3221
- <p><?php echo sprintf( __( 'No %s found', 'pods' ), $this->items ); ?></p>
3222
  <?php
3223
  return false;
3224
  }
@@ -3515,6 +3649,10 @@ class PodsUI {
3515
 
3516
  $row_value = $this->do_hook( 'field_value', $row_value, $field, $attributes, $row );
3517
 
 
 
 
 
3518
  if ( 'title' === $attributes[ 'field_id' ] ) {
3519
  $default_action = $this->do_hook( 'default_action', 'edit', $row );
3520
 
@@ -3558,96 +3696,8 @@ class PodsUI {
3558
 
3559
  if ( true !== $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder[ 'on' ] ) {
3560
  $toggle = false;
3561
- $actions = array();
3562
-
3563
- if ( !in_array( 'view', $this->actions_disabled ) && !in_array( 'view', $this->actions_hidden ) ) {
3564
- $link = pods_query_arg( array( 'action' . $this->num => 'view', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3565
-
3566
- if ( !empty( $this->action_links[ 'view' ] ) )
3567
- $link = $this->do_template( $this->action_links[ 'view' ], $row );
3568
-
3569
- $actions[ 'view' ] = '<span class="view"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'View this item', 'pods' ) . '">' . __( 'View', 'pods' ) . '</a></span>';
3570
- }
3571
-
3572
- if ( !in_array( 'edit', $this->actions_disabled ) && !in_array( 'edit', $this->actions_hidden ) && !$this->restricted( 'edit', $row ) ) {
3573
- $link = pods_query_arg( array( 'action' . $this->num => 'edit', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3574
-
3575
- if ( !empty( $this->action_links[ 'edit' ] ) )
3576
- $link = $this->do_template( $this->action_links[ 'edit' ], $row );
3577
-
3578
- $actions[ 'edit' ] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Edit this item', 'pods' ) . '">' . __( 'Edit', 'pods' ) . '</a></span>';
3579
- }
3580
-
3581
- if ( !in_array( 'duplicate', $this->actions_disabled ) && !in_array( 'duplicate', $this->actions_hidden ) && !$this->restricted( 'edit', $row ) ) {
3582
- $link = pods_query_arg( array( 'action' . $this->num => 'duplicate', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3583
-
3584
- if ( !empty( $this->action_links[ 'duplicate' ] ) )
3585
- $link = $this->do_template( $this->action_links[ 'duplicate' ], $row );
3586
-
3587
- $actions[ 'duplicate' ] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Duplicate this item', 'pods' ) . '">' . __( 'Duplicate', 'pods' ) . '</a></span>';
3588
- }
3589
-
3590
- if ( !in_array( 'delete', $this->actions_disabled ) && !in_array( 'delete', $this->actions_hidden ) && !$this->restricted( 'delete', $row ) ) {
3591
- $link = pods_query_arg( array( 'action' . $this->num => 'delete', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ], '_wpnonce' => wp_create_nonce( 'pods-ui-action-delete' ) ), self::$allowed, $this->exclusion() );
3592
-
3593
- if ( !empty( $this->action_links[ 'delete' ] ) ) {
3594
- $link = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'pods-ui-action-delete' ) ), $this->do_template( $this->action_links[ 'delete' ], $row ) );
3595
- }
3596
-
3597
- $actions[ 'delete' ] = '<span class="delete"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Delete this item', 'pods' ) . '" class="submitdelete" onclick="if(confirm(\'' . esc_attr__( 'You are about to permanently delete this item\n Choose \\\'Cancel\\\' to stop, \\\'OK\\\' to delete.', 'pods' ) . '\')){return true;}return false;">' . __( 'Delete', 'pods' ) . '</a></span>';
3598
- }
3599
-
3600
- if ( is_array( $this->actions_custom ) ) {
3601
- foreach ( $this->actions_custom as $custom_action => $custom_data ) {
3602
- if ( 'add' != $custom_action && is_array( $custom_data ) && ( isset( $custom_data[ 'link' ] ) || isset( $custom_data[ 'callback' ] ) ) && !in_array( $custom_action, $this->actions_disabled ) && !in_array( $custom_action, $this->actions_hidden ) ) {
3603
- if ( !in_array( $custom_action, array( 'add', 'view', 'edit', 'duplicate', 'delete', 'save', 'export', 'reorder', 'manage', 'table' ) ) ) {
3604
- if ( 'toggle' == $custom_action ) {
3605
- $toggle = true;
3606
- $toggle_labels = array(
3607
- __( 'Enable', 'pods' ),
3608
- __( 'Disable', 'pods' )
3609
- );
3610
-
3611
- $custom_data[ 'label' ] = ( $row[ 'toggle' ] ? $toggle_labels[ 1 ] : $toggle_labels[ 0 ] );
3612
- }
3613
-
3614
- if ( !isset( $custom_data[ 'label' ] ) )
3615
- $custom_data[ 'label' ] = ucwords( str_replace( '_', ' ', $custom_action ) );
3616
-
3617
- if ( !isset( $custom_data[ 'link' ] ) ) {
3618
- $vars = array(
3619
- 'action' => $custom_action,
3620
- 'id' => $row[ $this->sql[ 'field_id' ] ],
3621
- '_wpnonce' => wp_create_nonce( 'pods-ui-action-' . $custom_action )
3622
- );
3623
-
3624
- if ( 'toggle' == $custom_action ) {
3625
- $vars[ 'toggle' ] = (int) ( !$row[ 'toggle' ] );
3626
- $vars[ 'toggled' ] = 1;
3627
- }
3628
-
3629
- $custom_data[ 'link' ] = pods_query_arg( $vars, self::$allowed, $this->exclusion() );
3630
-
3631
- if ( isset( $this->action_links[ $custom_action ] ) && !empty( $this->action_links[ $custom_action ] ) ) {
3632
- $custom_data[ 'link' ] = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'pods-ui-action-' . $custom_action ) ), $this->do_template( $this->action_links[ $custom_action ], $row ) );
3633
- }
3634
- }
3635
-
3636
- $confirm = '';
3637
-
3638
- if ( isset( $custom_data[ 'confirm' ] ) )
3639
- $confirm = ' onclick="if(confirm(\'' . esc_js( $custom_data[ 'confirm' ] ) . '\')){return true;}return false;"';
3640
-
3641
- if ( $this->restricted( $custom_action, $row ) ) {
3642
- continue;
3643
- }
3644
-
3645
- $actions[ $custom_action ] = '<span class="edit action-' . esc_attr( $custom_action ) . '"><a href="' . esc_url( $this->do_template( $custom_data[ 'link' ], $row ) ) . '" title="' . esc_attr( $custom_data[ 'label' ] ) . ' this item"' . $confirm . '>' . $custom_data[ 'label' ] . '</a></span>';
3646
- }
3647
- }
3648
- }
3649
- }
3650
 
 
3651
  $actions = $this->do_hook( 'row_actions', $actions, $row[ $this->sql[ 'field_id' ] ] );
3652
 
3653
  if ( !empty( $actions ) ) {
@@ -3669,7 +3719,7 @@ class PodsUI {
3669
  <input type="hidden" name="order[]" value="<?php echo esc_attr( $row[ $this->sql[ 'field_id' ] ] ); ?>" />
3670
  <?php
3671
  }
3672
- ?>
3673
  </td>
3674
  <?php
3675
  }
@@ -3739,6 +3789,109 @@ class PodsUI {
3739
  <?php
3740
  }
3741
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3742
  /**
3743
  *
3744
  */
@@ -3786,7 +3939,7 @@ class PodsUI {
3786
  $this->do_hook( 'screen_meta_pre' );
3787
  if ( 0 < strlen( $screen_html ) ) {
3788
  ?>
3789
- <div id="screen-options-wrap" class="hidden">
3790
  <form id="adv-settings" action="" method="post">
3791
  <?php
3792
  echo $screen_html;
@@ -3841,7 +3994,7 @@ class PodsUI {
3841
  }
3842
  if ( 0 < strlen( $help_html ) ) {
3843
  ?>
3844
- <div id="contextual-help-wrap" class="hidden">
3845
  <div class="metabox-prefs">
3846
  <?php echo $help_html; ?>
3847
  </div>
487
  $this->pods_data = pods_data( $this->pod );
488
 
489
  $options = $this->do_hook( 'pre_init', $options );
490
+
491
  $this->setup( $options );
492
 
493
  if ( is_object( $this->pods_data ) && is_object( $this->pod ) && 0 < $this->id ) {
503
  return false;
504
  }
505
 
506
+ // Assign pod labels
507
+ // @todo This is also done in setup(), maybe a better / more central way?
508
+ if ( is_object( $this->pod ) && ! empty( $this->pod->pod_data[ 'options' ] ) ) {
509
+ $pod_options = $this->pod->pod_data[ 'options' ];
510
+ $pod_options = apply_filters( 'pods_advanced_content_type_pod_data_' . $this->pod->pod_data[ 'name' ], $pod_options, $this->pod->pod_data[ 'name' ] );
511
+ $pod_options = apply_filters( 'pods_advanced_content_type_pod_data', $pod_options, $this->pod->pod_data[ 'name' ] );
512
+
513
+ $this->label = array_merge( $this->label, $pod_options );
514
+ }
515
+
516
  $this->go();
517
  }
518
 
925
  $item = __( 'Item', 'pods' );
926
  $items = __( 'Items', 'pods' );
927
 
928
+ if ( ! is_array( $this->label ) ) {
929
+ $this->label = (array) $this->label;
930
+ }
931
+
932
  if ( is_object( $this->pod ) ) {
933
+ $pod_data = $this->pod->pod_data;
934
+ $pod_data = apply_filters( 'pods_advanced_content_type_pod_data_' . $this->pod->pod_data[ 'name' ], $pod_data, $this->pod->pod_data[ 'name' ] );
935
+ $pod_data = apply_filters( 'pods_advanced_content_type_pod_data', $pod_data, $this->pod->pod_data[ 'name' ] );
936
+
937
+ $this->label = array_merge( $this->label, $pod_data['options'] );
938
+
939
+ $item = pods_v( 'label_singular', $pod_data['options'], pods_v( 'label', $pod_data, $item, true ), true );
940
+ $items = pods_v( 'label', $pod_data, $items, true );
941
  }
942
 
943
  $options->validate( 'item', $item );
944
  $options->validate( 'items', $items );
945
 
946
  $options->validate( 'heading', array(
947
+ 'manage' => pods_v( 'label_manage', $this->label, __( 'Manage', 'pods' ) ),
948
+ 'add' => pods_v( 'label_add_new', $this->label, __( 'Add New', 'pods' ) ),
949
+ 'edit' => pods_v( 'label_edit', $this->label, __( 'Edit', 'pods' ) ),
950
+ 'duplicate' => pods_v( 'label_duplicate', $this->label, __( 'Duplicate', 'pods' ) ),
951
+ 'view' => pods_v( 'label_view', $this->label, __( 'View', 'pods' ) ),
952
+ 'reorder' => pods_v( 'label_reorder', $this->label, __( 'Reorder', 'pods' ) ),
953
+ 'search' => pods_v( 'label_search', $this->label, __( 'Search', 'pods' ) ),
954
+ 'views' => pods_v( 'label_view', $this->label, __( 'View', 'pods' ) )
955
  ), 'array_merge' );
956
 
957
  $options->validate( 'header', array(
958
+ 'manage' => pods_v( 'label_manage_items', $this->label, sprintf( __( 'Manage %s', 'pods' ), $options->items ) ),
959
+ 'add' => pods_v( 'label_add_new_item', $this->label, sprintf( __( 'Add New %s', 'pods' ), $options->item ) ),
960
+ 'edit' => pods_v( 'label_edit_item', $this->label, sprintf( __( 'Edit %s', 'pods' ), $options->item ) ),
961
+ 'duplicate' => pods_v( 'label_duplicate_item', $this->label, sprintf( __( 'Duplicate %s', 'pods' ), $options->item ) ),
962
+ 'view' => pods_v( 'label_view_item', $this->label, sprintf( __( 'View %s', 'pods' ), $options->item ) ),
963
+ 'reorder' => pods_v( 'label_reorder_items', $this->label, sprintf( __( 'Reorder %s', 'pods' ), $options->items ) ),
964
+ 'search' => pods_v( 'label_search_items', $this->label, sprintf( __( 'Search %s', 'pods' ), $options->items ) )
965
  ), 'array_merge' );
966
 
967
  $options->validate( 'label', array(
968
+ 'add' => pods_v( 'label_add_new_item', $this->label, sprintf( __( 'Add New %s', 'pods' ), $options->item ) ),
969
+ 'add_new' => pods_v( 'label_add_new', $this->label, __( 'Add New', 'pods' ) ),
970
+ 'edit' => pods_v( 'label_update_item', $this->label, sprintf( __( 'Update %s', 'pods' ), $options->item ) ),
971
+ 'duplicate' => pods_v( 'label_duplicate_item', $this->label, sprintf( __( 'Duplicate %s', 'pods' ), $options->item ) ),
972
+ 'delete' => pods_v( 'label_delete_item', $this->label, sprintf( __( 'Delete this %s', 'pods' ), $options->item ) ),
973
+ 'view' => pods_v( 'label_view_item', $this->label, sprintf( __( 'View %s', 'pods' ), $options->item ) ),
974
+ 'reorder' => pods_v( 'label_reorder_items', $this->label, sprintf( __( 'Reorder %s', 'pods' ), $options->items ) )
975
  ), 'array_merge' );
976
 
977
  $options->validate( 'fields', array(
1439
  if ( false !== $this->callback_action( 'add' ) ) {
1440
  return null;
1441
  }
1442
+
1443
+ if ( $this->restricted( $this->action ) ) {
1444
+ return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1445
+ }
1446
  ?>
1447
  <div class="wrap pods-ui">
1448
  <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div>
1450
  <?php
1451
  echo wp_kses_post( $this->header[ 'add' ] );
1452
 
1453
+ if ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) && ! $this->restricted( 'manage' ) ) {
1454
+ $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
1455
 
1456
+ if ( !empty( $this->action_links[ 'manage' ] ) ) {
1457
+ $link = $this->action_links[ 'manage' ];
1458
+ }
1459
  ?>
1460
+ <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>
1461
+ <?php } ?>
1462
  </h2>
1463
 
1464
  <?php $this->form( true ); ?>
1484
  elseif ( false !== $this->callback_action( 'edit', $duplicate ) ) {
1485
  return null;
1486
  }
1487
+
1488
+ if ( $this->restricted( $this->action ) ) {
1489
+ return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1490
+ }
1491
  ?>
1492
  <div class="wrap pods-ui">
1493
  <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div>
1495
  <?php
1496
  echo wp_kses_post( $this->do_template( $duplicate ? $this->header[ 'duplicate' ] : $this->header[ 'edit' ] ) );
1497
 
1498
+ if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) && ! $this->restricted( 'add' ) ) {
1499
  $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num = '' ), self::$allowed, $this->exclusion() );
1500
 
1501
  if ( !empty( $this->action_links[ 'add' ] ) )
1504
  <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->heading[ 'add' ] ); ?></a>
1505
  <?php
1506
  }
1507
+ elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) && ! $this->restricted( 'manage' ) ) {
1508
  $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
1509
 
1510
  if ( !empty( $this->action_links[ 'manage' ] ) )
1582
  $alt_vars[ 'action' ] = 'manage';
1583
  unset( $alt_vars[ 'id' ] );
1584
  }
1585
+ } elseif ( $this->restricted( $this->action, $this->row ) ) {
1586
+ return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1587
  }
1588
 
1589
  $fields = array();
1775
  <?php
1776
  echo wp_kses_post( $this->do_template( $this->header[ 'view' ] ) );
1777
 
1778
+ if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) && ! $this->restricted( 'add' ) ) {
1779
  $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num = '' ), self::$allowed, $this->exclusion() );
1780
 
1781
  if ( !empty( $this->action_links[ 'add' ] ) ) {
1785
  <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->heading[ 'add' ] ); ?></a>
1786
  <?php
1787
  }
1788
+ elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) && ! $this->restricted( 'manage' ) ) {
1789
  $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
1790
 
1791
  if ( !empty( $this->action_links[ 'manage' ] ) ) {
2006
  $this->manage();
2007
  }
2008
 
2009
+ /**
2010
+ * Callback for exporting items in bulk
2011
+ */
2012
+ public function export_bulk() {
2013
+
2014
+ if ( ! empty( $_POST['bulk_export_type'] ) ) {
2015
+ if ( ! empty( $_POST['bulk_export_fields'] ) ) {
2016
+ $export_fields = $_POST['bulk_export_fields'];
2017
+
2018
+ $this->fields['export '] = array();
2019
 
2020
+ if ( $this->pod ) {
2021
+ $fields = $this->pod->fields();
2022
+
2023
+ foreach ( $fields as $field ) {
2024
+ if ( in_array( $field['name'], $export_fields ) ) {
2025
+ $this->fields['export'][] = $field;
2026
+ }
2027
+ }
2028
+ }
2029
+ }
2030
+
2031
+ // Set up where clause so that export function finds it
2032
+ if ( ! empty( $_POST['action_bulk_ids'] ) ) {
2033
+ $ids = (array) explode( ',', $_POST['action_bulk_ids'] );
2034
+ $ids = array_map( 'absint', $ids );
2035
+ $ids = array_filter( $ids );
2036
+
2037
+ if ( ! empty( $ids ) ) {
2038
+ $ids = implode( ', ', $ids );
2039
+
2040
+ $this->where = array(
2041
+ 'manage' => '`' . pods_sanitize( $this->sql['field_id'] ) . '` IN ( ' . $ids . ' )',
2042
+ );
2043
+ }
2044
+ }
2045
+
2046
+ $this->export( $_POST['bulk_export_type'] );
2047
+
2048
+ // Cleanup since export function calls get_data before returning
2049
+ $this->action_bulk = '';
2050
+ $this->where = array();
2051
+ $this->data = false;
2052
+
2053
+ $_GET['action_bulk_ids'] = '';
2054
+
2055
+ $this->manage();
2056
+ } else {
2057
+ $this->export_fields_form();
2058
+ }
2059
+
2060
+ }
2061
+
2062
+ /**
2063
+ * Select the pods fields to be exported
2064
+ */
2065
+ public function export_fields_form() {
2066
+
2067
+ ?>
2068
+ <div class="wrap pods-admin pods-ui">
2069
+ <h2><?php echo __( 'Choose Export Fields', 'pods' ); ?></h2>
2070
+
2071
+ <form method="post" id="pods_admin_ui_export_form">
2072
+ <?php
2073
+ // Avoid a bunch of inputs if there's a lot selected
2074
+ if ( ! empty( $_REQUEST['action_bulk_ids'] ) ) {
2075
+ $_GET['action_bulk_ids'] = implode( ',', (array) $_REQUEST['action_bulk_ids'] );
2076
+ }
2077
+
2078
+ $this->hidden_vars();
2079
+ ?>
2080
+
2081
+ <ul>
2082
+ <?php foreach ( $this->pod->fields() as $field_name => $field ) { ?>
2083
+ <li>
2084
+ <label for="bulk_export_fields_<?php echo esc_attr( $field['name'] ); ?>">
2085
+ <input type="checkbox" name="bulk_export_fields[]" id="bulk_export_fields_<?php echo esc_attr( $field['name'] ); ?>" value="<?php echo esc_attr( $field['name'] ); ?>" />
2086
+ <?php echo esc_html( $field['label'] ); ?>
2087
+ </label>
2088
+ </li>
2089
+ <?php } ?>
2090
+ </ul>
2091
+
2092
+ <p class="submit">
2093
+ <?php _e( 'Export as:', 'pods' ); ?>&nbsp;&nbsp;
2094
+ <?php foreach ( $this->export[ 'formats' ] as $format => $separator ) { ?>
2095
+ <input type="submit" id="export_type_<?php echo esc_attr( strtoupper( $format ) ); ?>" value=" <?php echo esc_attr( strtoupper( $format ) ); ?> " name="bulk_export_type" class="button-primary" />
2096
+ <?php } ?>
2097
+ </p>
2098
+ </form>
2099
+ </div>
2100
+ <?php
2101
+
2102
+ }
2103
+
2104
+ public function export( $export_type = null ) {
2105
+
2106
+ if ( empty( $export_type ) ) {
2107
+ $export_type = pods_var( 'export_type', 'get', 'csv' );
2108
+ }
2109
+
2110
+ $export_type = trim( strtolower( $export_type ) );
2111
 
2112
  $type = 'sv'; // covers csv + tsv
2113
 
2116
 
2117
  $delimiter = ',';
2118
 
2119
+ if ( ! empty( $this->export['formats'][ $export_type ] ) ) {
2120
+ $delimiter = $this->export['formats'][ $export_type ];
2121
+ }
 
2122
 
2123
+ $columns = array(
2124
+ $this->sql['field_id'] => 'ID',
2125
+ );
2126
 
2127
+ if ( empty( $this->fields['export'] ) && $this->pod && ! empty( $this->pod->fields ) ) {
2128
+ $this->fields['export'] = $this->pod->fields;
2129
+ }
 
2130
 
2131
  if ( ! empty( $this->fields['export'] ) ) {
2132
+ foreach ( $this->fields['export'] as $field ) {
2133
+ $columns[ $field['name'] ] = $field['label'];
2134
+ }
2135
  }
2136
 
2137
  $params = array(
2303
  if ( $params->full )
2304
  $find_params[ 'limit' ] = -1;
2305
 
2306
+ $find_params = apply_filters('pods_ui_get_params', $find_params, ( is_object( $this->pod ) ? $this->pod->pod : null ), $this);
2307
 
2308
  /**
2309
  * Filter Pods::find() parameters to make it more easily extended by plugins and developers.
2492
  return null;
2493
  }
2494
 
2495
+ if ( !empty( $this->action_bulk ) && !empty( $this->actions_bulk ) && isset( $this->actions_bulk[ $this->action_bulk ] ) && !in_array( $this->action_bulk, $this->actions_disabled ) && ( ! empty( $this->bulk ) || 'export' == $this->action_bulk ) ) {
2496
  if ( empty( $_REQUEST[ '_wpnonce' . $this->num ] ) || false === wp_verify_nonce( $_REQUEST[ '_wpnonce' . $this->num ], 'pods-ui-action-bulk' ) ) {
2497
  pods_message( __( 'Invalid bulk request, please try again.', 'pods' ) );
2498
  }
2500
  return null;
2501
  }
2502
  elseif ( 'delete' == $this->action_bulk ) {
2503
+ $this->delete_bulk();
2504
+
2505
+ return;
2506
+ }
2507
+ elseif ( 'export' == $this->action_bulk ) {
2508
+ $this->export_bulk();
2509
+
2510
+ return;
2511
  }
2512
  }
2513
 
2523
  if ( true === $reorder ) {
2524
  echo wp_kses_post( $this->header[ 'reorder' ] );
2525
 
2526
+ if ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) && ! $this->restricted( 'manage' ) ) {
2527
+ $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
2528
 
2529
+ if ( !empty( $this->action_links[ 'manage' ] ) ) {
2530
+ $link = $this->action_links[ 'manage' ];
2531
+ }
2532
  ?>
2533
  <small>(<a href="<?php echo esc_url( $link ); ?>">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>)</small>
2534
  <?php
2535
+ }
2536
  }
2537
  else
2538
  echo wp_kses_post( $this->header[ 'manage' ] );
2539
 
2540
+ if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) && ! $this->restricted( 'add' ) ) {
2541
  $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num => '' ), self::$allowed, $this->exclusion() );
2542
 
2543
  if ( !empty( $this->action_links[ 'add' ] ) )
2546
  <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->label[ 'add_new' ] ); ?></a>
2547
  <?php
2548
  }
2549
+ if ( !in_array( 'reorder', $this->actions_disabled ) && !in_array( 'reorder', $this->actions_hidden ) && false !== $this->reorder[ 'on' ] && ! $this->restricted( 'reorder' ) ) {
2550
  $link = pods_query_arg( array( 'action' . $this->num => 'reorder' ), self::$allowed, $this->exclusion() );
2551
 
2552
  if ( !empty( $this->action_links[ 'reorder' ] ) )
2841
  elseif ( !in_array( 'export', $this->actions_disabled ) && !in_array( 'export', $this->actions_hidden ) ) {
2842
  ?>
2843
  <div class="alignleft actions">
2844
+ <input type="button" value="<?php echo esc_attr( sprintf( __( 'Export all %s', 'pods' ), $this->items ) ); ?>" class="button" onclick="document.location='<?php echo pods_slash( pods_query_arg( array( 'action_bulk' . $this->num => 'export', '_wpnonce' => wp_create_nonce( 'pods-ui-action-bulk' ) ), self::$allowed, $this->exclusion() ) ); ?>';" />
 
 
 
 
 
 
 
2845
  </div>
2846
  <?php
2847
  }
2890
  include_once ABSPATH . 'wp-admin/includes/template.php';
2891
 
2892
  wp_enqueue_script( 'thickbox' );
2893
+ wp_enqueue_style( 'pods-styles' );
2894
 
2895
  $filters = $this->filters;
2896
 
3115
  public function filters_popup () {
3116
  $filters = $this->filters;
3117
  ?>
3118
+ <div id="pods-ui-posts-filter-popup" class="pods-hidden">
3119
  <form action="" method="get" class="pods-ui-posts-filter-popup">
3120
  <h2><?php _e( 'Advanced Filters', 'pods' ); ?></h2>
3121
 
3180
  if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
3181
  $end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' );
3182
  ?>
3183
+ <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? '' : ' pods-hidden' ); ?>">+</span>
3184
+ <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? ' pods-hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3185
 
3186
  <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_start">
3187
  <?php echo esc_html( $filter_field[ 'label' ] ); ?>
3188
  </label>
3189
 
3190
+ <span class="pods-ui-posts-filter<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? ' pods-hidden' : '' ); ?>">
3191
  <?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field[ 'type' ], $filter_field ); ?>
3192
 
3193
  <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_end">to</label>
3212
 
3213
  $options = array_merge( $filter_field, $filter_field[ 'options' ] );
3214
  ?>
3215
+ <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' pods-hidden' ); ?>">+</span>
3216
+ <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' pods-hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3217
 
3218
  <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3219
  <?php echo esc_html( $filter_field[ 'label' ] ); ?>
3220
  </label>
3221
 
3222
+ <span class="pods-ui-posts-filter<?php echo esc_attr( strlen( $value ) < 1 ? ' pods-hidden' : '' ); ?>">
3223
  <?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
3224
  </span>
3225
  <?php
3247
 
3248
  $options = array_merge( $filter_field, $filter_field[ 'options' ] );
3249
  ?>
3250
+ <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' pods-hidden' ); ?>">+</span>
3251
+ <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' pods-hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3252
 
3253
  <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3254
  <?php echo esc_html( $filter_field[ 'label' ] ); ?>
3255
  </label>
3256
 
3257
+ <span class="pods-ui-posts-filter<?php echo esc_attr( strlen( $value ) < 1 ? ' pods-hidden' : '' ); ?>">
3258
  <?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
3259
  </span>
3260
  <?php
3272
  if ( empty( $options[ 'input_helper' ] ) && isset( $filter_field[ 'options' ] ) && isset( $filter_field[ 'options' ][ 'input_helper' ] ) )
3273
  $options[ 'input_helper' ] = $filter_field[ 'options' ][ 'input_helper' ];
3274
  ?>
3275
+ <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' pods-hidden' ); ?>">+</span>
3276
+ <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' pods-hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3277
 
3278
  <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3279
  <?php echo esc_html( $filter_field[ 'label' ] ); ?>
3280
  </label>
3281
 
3282
+ <span class="pods-ui-posts-filter<?php echo esc_attr( empty( $value ) ? ' pods-hidden' : '' ); ?>">
3283
  <?php echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options ); ?>
3284
  </span>
3285
  <?php
3306
  <script type="text/javascript">
3307
  jQuery( function () {
3308
  jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-on', function ( e ) {
3309
+ jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'pods-hidden' );
3310
 
3311
  jQuery( this ).hide();
3312
  jQuery( this ).parent().find( '.toggle-off' ).show();
3313
  } );
3314
 
3315
  jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-off', function ( e ) {
3316
+ jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'pods-hidden' );
3317
  jQuery( this ).parent().find( 'select, input' ).val( '' );
3318
 
3319
  jQuery( this ).hide();
3321
  } );
3322
 
3323
  jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggled label', function ( e ) {
3324
+ if ( jQuery( this ).parent().find( '.pods-ui-posts-filter' ).hasClass( 'pods-hidden' ) ) {
3325
+ jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'pods-hidden' );
3326
 
3327
  jQuery( this ).parent().find( '.toggle-on' ).hide();
3328
  jQuery( this ).parent().find( '.toggle-off' ).show();
3329
  }
3330
  else {
3331
+ jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'pods-hidden' );
3332
  jQuery( this ).parent().find( 'select, input' ).val( '' );
3333
 
3334
  jQuery( this ).parent().find( '.toggle-on' ).show();
3352
 
3353
  if ( empty( $this->data ) ) {
3354
  ?>
3355
+ <p><?php echo pods_v( 'label_no_items_found', $this->label, sprintf( __( 'No %s found', 'pods' ), $this->items ) ); ?></p>
3356
  <?php
3357
  return false;
3358
  }
3649
 
3650
  $row_value = $this->do_hook( 'field_value', $row_value, $field, $attributes, $row );
3651
 
3652
+ if ( !empty( $attributes[ 'custom_display_formatted' ] ) && is_callable( $attributes[ 'custom_display_formatted' ] ) ) {
3653
+ $row_value = call_user_func_array( $attributes[ 'custom_display_formatted' ], array( $row, &$this, $row_value, $field, $attributes ) );
3654
+ }
3655
+
3656
  if ( 'title' === $attributes[ 'field_id' ] ) {
3657
  $default_action = $this->do_hook( 'default_action', 'edit', $row );
3658
 
3696
 
3697
  if ( true !== $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder[ 'on' ] ) {
3698
  $toggle = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3699
 
3700
+ $actions = $this->get_actions( $row );
3701
  $actions = $this->do_hook( 'row_actions', $actions, $row[ $this->sql[ 'field_id' ] ] );
3702
 
3703
  if ( !empty( $actions ) ) {
3719
  <input type="hidden" name="order[]" value="<?php echo esc_attr( $row[ $this->sql[ 'field_id' ] ] ); ?>" />
3720
  <?php
3721
  }
3722
+ ?><button type="button" class="toggle-row"><span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'pods' ); ?></span></button>
3723
  </td>
3724
  <?php
3725
  }
3789
  <?php
3790
  }
3791
 
3792
+ /**
3793
+ * Get actions for row.
3794
+ *
3795
+ * @param array $row
3796
+ *
3797
+ * @return array
3798
+ */
3799
+ public function get_actions( $row ) {
3800
+
3801
+ $actions = array();
3802
+
3803
+ if ( !in_array( 'view', $this->actions_disabled ) && !in_array( 'view', $this->actions_hidden ) ) {
3804
+ $link = pods_query_arg( array( 'action' . $this->num => 'view', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3805
+
3806
+ if ( !empty( $this->action_links[ 'view' ] ) )
3807
+ $link = $this->do_template( $this->action_links[ 'view' ], $row );
3808
+
3809
+ $actions[ 'view' ] = '<span class="view"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'View this item', 'pods' ) . '">' . __( 'View', 'pods' ) . '</a></span>';
3810
+ }
3811
+
3812
+ if ( !in_array( 'edit', $this->actions_disabled ) && !in_array( 'edit', $this->actions_hidden ) && !$this->restricted( 'edit', $row ) ) {
3813
+ $link = pods_query_arg( array( 'action' . $this->num => 'edit', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3814
+
3815
+ if ( !empty( $this->action_links[ 'edit' ] ) )
3816
+ $link = $this->do_template( $this->action_links[ 'edit' ], $row );
3817
+
3818
+ $actions[ 'edit' ] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Edit this item', 'pods' ) . '">' . __( 'Edit', 'pods' ) . '</a></span>';
3819
+ }
3820
+
3821
+ if ( !in_array( 'duplicate', $this->actions_disabled ) && !in_array( 'duplicate', $this->actions_hidden ) && !$this->restricted( 'edit', $row ) ) {
3822
+ $link = pods_query_arg( array( 'action' . $this->num => 'duplicate', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3823
+
3824
+ if ( !empty( $this->action_links[ 'duplicate' ] ) )
3825
+ $link = $this->do_template( $this->action_links[ 'duplicate' ], $row );
3826
+
3827
+ $actions[ 'duplicate' ] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Duplicate this item', 'pods' ) . '">' . __( 'Duplicate', 'pods' ) . '</a></span>';
3828
+ }
3829
+
3830
+ if ( !in_array( 'delete', $this->actions_disabled ) && !in_array( 'delete', $this->actions_hidden ) && !$this->restricted( 'delete', $row ) ) {
3831
+ $link = pods_query_arg( array( 'action' . $this->num => 'delete', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ], '_wpnonce' => wp_create_nonce( 'pods-ui-action-delete' ) ), self::$allowed, $this->exclusion() );
3832
+
3833
+ if ( !empty( $this->action_links[ 'delete' ] ) ) {
3834
+ $link = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'pods-ui-action-delete' ) ), $this->do_template( $this->action_links[ 'delete' ], $row ) );
3835
+ }
3836
+
3837
+ $actions[ 'delete' ] = '<span class="delete"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Delete this item', 'pods' ) . '" class="submitdelete" onclick="if(confirm(\'' . esc_attr__( 'You are about to permanently delete this item\n Choose \\\'Cancel\\\' to stop, \\\'OK\\\' to delete.', 'pods' ) . '\')){return true;}return false;">' . __( 'Delete', 'pods' ) . '</a></span>';
3838
+ }
3839
+
3840
+ if ( is_array( $this->actions_custom ) ) {
3841
+ foreach ( $this->actions_custom as $custom_action => $custom_data ) {
3842
+ if ( 'add' !== $custom_action && is_array( $custom_data ) && ( isset( $custom_data[ 'link' ] ) || isset( $custom_data[ 'callback' ] ) ) && !in_array( $custom_action, $this->actions_disabled ) && !in_array( $custom_action, $this->actions_hidden ) ) {
3843
+ if ( !in_array( $custom_action, array( 'add', 'view', 'edit', 'duplicate', 'delete', 'save', 'export', 'reorder', 'manage', 'table' ) ) ) {
3844
+ if ( 'toggle' === $custom_action ) {
3845
+ $toggle = true;
3846
+ $toggle_labels = array(
3847
+ __( 'Enable', 'pods' ),
3848
+ __( 'Disable', 'pods' )
3849
+ );
3850
+
3851
+ $custom_data[ 'label' ] = ( $row[ 'toggle' ] ? $toggle_labels[ 1 ] : $toggle_labels[ 0 ] );
3852
+ }
3853
+
3854
+ if ( !isset( $custom_data[ 'label' ] ) )
3855
+ $custom_data[ 'label' ] = ucwords( str_replace( '_', ' ', $custom_action ) );
3856
+
3857
+ if ( !isset( $custom_data[ 'link' ] ) ) {
3858
+ $vars = array(
3859
+ 'action' => $custom_action,
3860
+ 'id' => $row[ $this->sql[ 'field_id' ] ],
3861
+ '_wpnonce' => wp_create_nonce( 'pods-ui-action-' . $custom_action )
3862
+ );
3863
+
3864
+ if ( 'toggle' === $custom_action ) {
3865
+ $vars[ 'toggle' ] = (int) ( !$row[ 'toggle' ] );
3866
+ $vars[ 'toggled' ] = 1;
3867
+ }
3868
+
3869
+ $custom_data[ 'link' ] = pods_query_arg( $vars, self::$allowed, $this->exclusion() );
3870
+
3871
+ if ( isset( $this->action_links[ $custom_action ] ) && !empty( $this->action_links[ $custom_action ] ) ) {
3872
+ $custom_data[ 'link' ] = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'pods-ui-action-' . $custom_action ) ), $this->do_template( $this->action_links[ $custom_action ], $row ) );
3873
+ }
3874
+ }
3875
+
3876
+ $confirm = '';
3877
+
3878
+ if ( isset( $custom_data[ 'confirm' ] ) )
3879
+ $confirm = ' onclick="if(confirm(\'' . esc_js( $custom_data[ 'confirm' ] ) . '\')){return true;}return false;"';
3880
+
3881
+ if ( $this->restricted( $custom_action, $row ) ) {
3882
+ continue;
3883
+ }
3884
+
3885
+ $actions[ $custom_action ] = '<span class="edit action-' . esc_attr( $custom_action ) . '"><a href="' . esc_url( $this->do_template( $custom_data[ 'link' ], $row ) ) . '" title="' . esc_attr( $custom_data[ 'label' ] ) . ' this item"' . $confirm . '>' . $custom_data[ 'label' ] . '</a></span>';
3886
+ }
3887
+ }
3888
+ }
3889
+ }
3890
+
3891
+ return $actions;
3892
+
3893
+ }
3894
+
3895
  /**
3896
  *
3897
  */
3939
  $this->do_hook( 'screen_meta_pre' );
3940
  if ( 0 < strlen( $screen_html ) ) {
3941
  ?>
3942
+ <div id="screen-options-wrap" class="pods-hidden">
3943
  <form id="adv-settings" action="" method="post">
3944
  <?php
3945
  echo $screen_html;
3994
  }
3995
  if ( 0 < strlen( $help_html ) ) {
3996
  ?>
3997
+ <div id="contextual-help-wrap" class="pods-hidden">
3998
  <div class="metabox-prefs">
3999
  <?php echo $help_html; ?>
4000
  </div>
classes/cli/PodsAPI_CLI_Command.php ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Implements PodsAPI command for WP-CLI
4
+ */
5
+ class PodsAPI_CLI_Command extends WP_CLI_Command {
6
+
7
+ /**
8
+ *
9
+ *
10
+ * @synopsis --name=<name> --type=<type> --<field>=<value>
11
+ * @subcommand add-pod
12
+ */
13
+ function add_pod( $args, $assoc_args ) {
14
+
15
+ if ( isset( $assoc_args['id'] ) ) {
16
+ unset( $assoc_args['id'] );
17
+ }
18
+
19
+ $id = pods_api()->save_pod( $assoc_args );
20
+
21
+ if ( 0 < $id ) {
22
+ WP_CLI::success( __( 'Pod added', 'pods' ) );
23
+ WP_CLI::line( "ID: {$id}" );
24
+ } else {
25
+ WP_CLI::error( __( 'Error adding pod', 'pods' ) );
26
+ }
27
+
28
+ }
29
+
30
+ /**
31
+ *
32
+ *
33
+ * @synopsis --<field>=<value>
34
+ * @subcommand save-pod
35
+ */
36
+ function save_pod( $args, $assoc_args ) {
37
+
38
+ $id = pods_api()->save_pod( $assoc_args );
39
+
40
+ if ( 0 < $id ) {
41
+ WP_CLI::success( __( 'Pod saved', 'pods' ) );
42
+ WP_CLI::line( "ID: {$id}" );
43
+ } else {
44
+ WP_CLI::error( __( 'Error saving pod', 'pods' ) );
45
+ }
46
+
47
+ }
48
+
49
+ /**
50
+ *
51
+ *
52
+ * @synopsis --<field>=<value>
53
+ * @subcommand duplicate-pod
54
+ */
55
+ function duplicate_pod( $args, $assoc_args ) {
56
+
57
+ $id = pods_api()->duplicate_pod( $assoc_args );
58
+
59
+ if ( 0 < $id ) {
60
+ WP_CLI::success( __( 'Pod duplicated', 'pods' ) );
61
+ WP_CLI::line( "New ID: {$id}" );
62
+ } else {
63
+ WP_CLI::error( __( 'Error duplicating pod', 'pods' ) );
64
+ }
65
+
66
+ }
67
+
68
+ /**
69
+ *
70
+ *
71
+ * @synopsis --<field>=<value>
72
+ * @subcommand reset-pod
73
+ */
74
+ function reset_pod( $args, $assoc_args ) {
75
+
76
+ $reset = pods_api()->reset_pod( $assoc_args );
77
+
78
+ if ( $reset ) {
79
+ WP_CLI::success( __( 'Pod content reset', 'pods' ) );
80
+ } else {
81
+ WP_CLI::error( __( 'Error resetting pod', 'pods' ) );
82
+ }
83
+
84
+ }
85
+
86
+ /**
87
+ *
88
+ *
89
+ * @synopsis --<field>=<value>
90
+ * @subcommand delete-pod
91
+ */
92
+ function delete_pod( $args, $assoc_args ) {
93
+
94
+ $deleted = pods_api()->delete_pod( $assoc_args );
95
+
96
+ if ( $deleted ) {
97
+ WP_CLI::success( __( 'Pod deleted', 'pods' ) );
98
+ } else {
99
+ WP_CLI::error( __( 'Error deleting pod', 'pods' ) );
100
+ }
101
+
102
+ }
103
+
104
+ /**
105
+ * Activate a component
106
+ *
107
+ * @synopsis --component=<component>
108
+ * @subcommand activate-component
109
+ */
110
+ function activate_component( $args, $assoc_args ) {
111
+
112
+ if ( ! class_exists( 'PodsInit' ) ) {
113
+ WP_CLI::error( __( 'PodsInit not available', 'pods' ) );
114
+
115
+ return;
116
+ }
117
+
118
+ $component = $assoc_args['component'];
119
+
120
+ $active = PodsInit::$components->is_component_active( $component );
121
+
122
+ if ( $active ) {
123
+ WP_CLI::error( sprintf( __( 'Component %s is already active', 'pods' ), $component ) );
124
+ } else {
125
+ PodsInit::$components->activate_component( $component );
126
+
127
+ WP_CLI::success( __( 'Component activated', 'pods' ) );
128
+ }
129
+
130
+ }
131
+
132
+ /**
133
+ * Deactivate a component
134
+ *
135
+ * @synopsis --component=<component>
136
+ * @subcommand deactivate-component
137
+ */
138
+ function deactivate_component( $args, $assoc_args ) {
139
+
140
+ if ( ! class_exists( 'PodsInit' ) ) {
141
+ WP_CLI::error( __( 'PodsInit not available', 'pods' ) );
142
+
143
+ return;
144
+ }
145
+
146
+ $component = $assoc_args['component'];
147
+
148
+ $active = PodsInit::$components->is_component_active( $component );
149
+
150
+ if ( ! $active ) {
151
+ WP_CLI::error( sprintf( __( 'Component %s is already not active', 'pods' ), $component ) );
152
+ } else {
153
+ PodsInit::$components->deactivate_component( $component );
154
+
155
+ WP_CLI::success( __( 'Component deactivated', 'pods' ) );
156
+ }
157
+
158
+ }
159
+
160
+ /**
161
+ * Clear pods cache
162
+ *
163
+ * @subcommand clear-cache
164
+ */
165
+ function clear_cache() {
166
+
167
+ pods_api()->cache_flush_pods();
168
+
169
+ WP_CLI::success( __( 'Pod cache cleared', 'pods' ) );
170
+ }
171
+
172
+ /**
173
+ *
174
+ *
175
+ * @synopsis --pod=<pod> --file=<file>
176
+ * @subcommand export-pod
177
+ */
178
+ /*function export_pod ( $args, $assoc_args ) {
179
+ $data = pods_api()->load_pod( array( 'name' => $assoc_args[ 'pod' ] ) );
180
+
181
+ if ( !empty( $data ) ) {
182
+ $data = json_encode( $data );
183
+
184
+ // @todo write to file
185
+ }
186
+
187
+ // @todo success message
188
+ }*/
189
+
190
+ /**
191
+ *
192
+ *
193
+ * @synopsis --file=<file>
194
+ * @subcommand import-pod
195
+ */
196
+ /*function import_pod ( $args, $assoc_args ) {
197
+ $data = ''; // @todo get data from file
198
+
199
+ $package = array();
200
+
201
+ if ( !empty( $data ) )
202
+ $package = @json_decode( $data, true );
203
+
204
+ if ( is_array( $package ) && !empty( $package ) ) {
205
+ $api = pods_api();
206
+
207
+ if ( isset( $package[ 'id' ] ) )
208
+ unset( $package[ 'id' ] );
209
+
210
+ $try = 1;
211
+ $check_name = $package[ 'name' ];
212
+
213
+ while ( $api->load_pod( array( 'name' => $check_name, 'table_info' => false ), false ) ) {
214
+ $try++;
215
+ $check_name = $package[ 'name' ] . $try;
216
+ }
217
+
218
+ $package[ 'name' ] = $check_name;
219
+
220
+ $id = $api->save_pod( $package );
221
+
222
+ if ( 0 < $id ) {
223
+ WP_CLI::success( __( 'Pod imported', 'pods' ) );
224
+ WP_CLI::line( "ID: {$id}" );
225
+ }
226
+ else
227
+ WP_CLI::error( __( 'Error importing pod', 'pods' ) );
228
+ }
229
+ else
230
+ WP_CLI::error( __( 'Invalid package, Pod not imported', 'pods' ) );
231
+ }*/
232
+
233
+ }
234
+
235
+ WP_CLI::add_command( 'pods-api', 'PodsAPI_CLI_Command' );
classes/cli/Pods_CLI_Command.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Implements Pods command for WP-CLI
4
+ */
5
+ class Pods_CLI_Command extends WP_CLI_Command {
6
+
7
+ /**
8
+ *
9
+ *
10
+ * @synopsis --pod=<pod> --<field>=<value>
11
+ */
12
+ function add( $args, $assoc_args ) {
13
+
14
+ $pod = $assoc_args['pod'];
15
+ $item = pods_var_raw( 'item', $assoc_args );
16
+
17
+ unset( $assoc_args['pod'] );
18
+
19
+ if ( isset( $assoc_args['item'] ) ) {
20
+ unset( $assoc_args['item'] );
21
+ }
22
+
23
+ if ( ! empty( $assoc_args ) ) {
24
+ $id = pods( $pod, $item )->save( $assoc_args );
25
+
26
+ if ( 0 < $id ) {
27
+ WP_CLI::success( __( 'Pod item added', 'pods' ) );
28
+ WP_CLI::line( "ID: {$id}" );
29
+ } else {
30
+ WP_CLI::error( __( 'Error saving pod item', 'pods' ) );
31
+ }
32
+ } else {
33
+ WP_CLI::error( __( 'No data sent for saving', 'pods' ) );
34
+ }
35
+
36
+ }
37
+
38
+ /**
39
+ *
40
+ *
41
+ * @synopsis --pod=<pod> [--item=<item>] --<field>=<value>
42
+ */
43
+ function save( $args, $assoc_args ) {
44
+
45
+ $pod = $assoc_args['pod'];
46
+ $item = pods_var_raw( 'item', $assoc_args );
47
+
48
+ unset( $assoc_args['pod'] );
49
+
50
+ if ( isset( $assoc_args['item'] ) ) {
51
+ unset( $assoc_args['item'] );
52
+ }
53
+
54
+ if ( ! empty( $assoc_args ) ) {
55
+ $id = pods( $pod, $item )->save( $assoc_args );
56
+
57
+ if ( 0 < $id ) {
58
+ WP_CLI::success( __( 'Pod item saved', 'pods' ) );
59
+ WP_CLI::line( "ID: {$id}" );
60
+ } else {
61
+ WP_CLI::error( __( 'Error saving pod item', 'pods' ) );
62
+ }
63
+ } else {
64
+ WP_CLI::error( __( 'No data sent for saving', 'pods' ) );
65
+ }
66
+
67
+ }
68
+
69
+ /**
70
+ *
71
+ *
72
+ * @synopsis --pod=<pod> --item=<item>
73
+ */
74
+ function duplicate( $args, $assoc_args ) {
75
+
76
+ $id = pods( $assoc_args['pod'], $assoc_args['item'] )->duplicate();
77
+
78
+ if ( 0 < $id ) {
79
+ WP_CLI::success( __( 'Pod item duplicated', 'pods' ) );
80
+ WP_CLI::line( "New ID: {$id}" );
81
+ } else {
82
+ WP_CLI::error( __( 'Error duplicating pod item', 'pods' ) );
83
+ }
84
+
85
+ }
86
+
87
+ /**
88
+ *
89
+ *
90
+ * @synopsis --pod=<pod> --item=<item>
91
+ */
92
+ function delete( $args, $assoc_args ) {
93
+
94
+ $deleted = pods( $assoc_args['pod'], $assoc_args['item'] )->delete();
95
+
96
+ if ( $deleted ) {
97
+ WP_CLI::success( __( 'Pod item deleted', 'pods' ) );
98
+ } else {
99
+ WP_CLI::error( __( 'Error deleting pod item', 'pods' ) );
100
+ }
101
+
102
+ }
103
+
104
+ /**
105
+ *
106
+ *
107
+ * @synopsis --pod=<pod> --file=<file> [--item=<item>] [--format=<format>] [--fields=<fields>] [--depth=<depth>]
108
+ */
109
+ /*function export ( $args, $assoc_args ) {
110
+
111
+ $params = array(
112
+ 'fields' => pods_var_raw( 'fields', $assoc_args ),
113
+ 'depth' => pods_var_raw( 'depth', $assoc_args )
114
+ );
115
+
116
+ $data = pods( $assoc_args[ 'pod' ], $assoc_args[ 'item' ] )->export( $params, null, pods_var_raw( 'format', $assoc_args ) );
117
+
118
+ // @todo write to file
119
+
120
+ // @todo success message
121
+
122
+ }*/
123
+
124
+ /**
125
+ *
126
+ *
127
+ * @synopsis --pod=<pod> --file=<file> [--format=<format>] [--numeric-mode=<numeric_mode>]
128
+ */
129
+ /*function import ( $args, $assoc_args ) {
130
+
131
+ $data = array(); // @todo get data from file
132
+
133
+ $ids = pods_api( $assoc_args[ 'pod' ] )->import( $data, (boolean) pods_var_raw( 'numeric_mode', $assoc_args, false, null, true ), pods_var_raw( 'format', $assoc_args ) );
134
+
135
+ // @todo success message
136
+
137
+ }*/
138
+
139
+ }
140
+
141
+ WP_CLI::add_command( 'pods', 'Pods_CLI_Command' );
classes/fields/avatar.php CHANGED
@@ -1,377 +1,178 @@
1
  <?php
 
 
2
  /**
3
  * @package Pods\Fields
4
  */
5
- class PodsField_Avatar extends PodsField {
6
-
7
- /**
8
- * Field Type Group
9
- *
10
- * @var string
11
- * @since 2.0
12
- */
13
- public static $group = 'Relationships / Media';
14
-
15
- /**
16
- * Field Type Identifier
17
- *
18
- * @var string
19
- * @since 2.0
20
- */
21
- public static $type = 'avatar';
22
-
23
- /**
24
- * Field Type Label
25
- *
26
- * @var string
27
- * @since 2.0
28
- */
29
- public static $label = 'Avatar';
30
-
31
- /**
32
- * Pod Types supported on (true for all, false for none, or give array of specific types supported)
33
- *
34
- * @var array|bool
35
- * @since 2.1
36
- */
37
- public static $pod_types = array( 'user' );
38
-
39
- /**
40
- * Do things like register/enqueue scripts and stylesheets
41
- *
42
- * @since 2.0
43
- */
44
- public function __construct () {
45
- self::$label = __( 'Avatar', 'pods' );
46
- }
47
-
48
- /**
49
- * Add options and set defaults to
50
- *
51
- * @param array $options
52
- *
53
- * @since 2.0
54
- */
55
- public function options () {
56
- $sizes = get_intermediate_image_sizes();
57
-
58
- $image_sizes = array();
59
-
60
- foreach ( $sizes as $size ) {
61
- $image_sizes[ $size ] = ucwords( str_replace( '-', ' ', $size ) );
62
- }
63
-
64
- $options = array(
65
- self::$type . '_uploader' => array(
66
- 'label' => __( 'Avatar Uploader', 'pods' ),
67
- 'default' => 'attachment',
68
- 'type' => 'pick',
69
- 'data' => apply_filters(
70
- 'pods_form_ui_field_avatar_uploader_options',
71
- array(
72
- 'attachment' => __( 'Attachments (WP Media Library)', 'pods' ),
73
- 'plupload' => __( 'Plupload', 'pods' )
74
- )
75
- ),
76
- 'dependency' => true
77
- ),
78
- self::$type . '_attachment_tab' => array(
79
- 'label' => __( 'Attachments Default Tab', 'pods' ),
80
- 'depends-on' => array( self::$type . '_uploader' => 'attachment' ),
81
- 'default' => 'upload',
82
- 'type' => 'pick',
83
- 'data' => array(
84
- // keys MUST match WP's router names
85
- 'upload' => __( 'Upload File', 'pods' ),
86
- 'browse' => __( 'Media Library', 'pods' )
87
- )
88
- ),
89
- self::$type . '_restrict_filesize' => array(
90
- 'label' => __( 'Restrict File Size', 'pods' ),
91
- 'depends-on' => array( self::$type . '_uploader' => 'plupload' ),
92
- 'default' => '10MB',
93
- 'type' => 'text'
94
- ),
95
- self::$type . '_add_button' => array(
96
- 'label' => __( 'Add Button Text', 'pods' ),
97
- 'default' => __( 'Add File', 'pods' ),
98
- 'type' => 'text'
99
- ),
100
- self::$type . '_modal_title' => array(
101
- 'label' => __( 'Modal Title', 'pods' ),
102
- 'depends-on' => array( self::$type . '_uploader' => 'attachment' ),
103
- 'default' => __( 'Attach a file', 'pods' ),
104
- 'type' => 'text'
105
- ),
106
- self::$type . '_modal_add_button' => array(
107
- 'label' => __( 'Modal Add Button Text', 'pods' ),
108
- 'depends-on' => array( self::$type . '_uploader' => 'attachment' ),
109
- 'default' => __( 'Add File', 'pods' ),
110
- 'type' => 'text'
111
- )
112
- );
113
-
114
- if ( !pods_version_check( 'wp', '3.5' ) ) {
115
- unset( $options[ self::$type . '_modal_title' ] );
116
- unset( $options[ self::$type . '_modal_add_button' ] );
117
-
118
- $options[ self::$type . '_attachment_tab' ][ 'default' ] = 'type';
119
- $options[ self::$type . '_attachment_tab' ][ 'data' ] = array(
120
- 'type' => __( 'Upload File', 'pods' ),
121
- 'library' => __( 'Media Library', 'pods' )
122
- );
123
- }
124
-
125
- return $options;
126
- }
127
-
128
- /**
129
- * Define the current field's schema for DB table storage
130
- *
131
- * @param array $options
132
- *
133
- * @return array
134
- * @since 2.0
135
- */
136
- public function schema ( $options = null ) {
137
- $schema = false;
138
-
139
- return $schema;
140
- }
141
-
142
- /**
143
- * Change the way the value of the field is displayed with Pods::get
144
- *
145
- * @param mixed $value
146
- * @param string $name
147
- * @param array $options
148
- * @param array $pod
149
- * @param int $id
150
- *
151
- * @return mixed|null
152
- * @since 2.0
153
- */
154
- public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
155
- return $value;
156
- }
157
-
158
- /**
159
- * Customize output of the form field
160
- *
161
- * @param string $name
162
- * @param mixed $value
163
- * @param array $options
164
- * @param array $pod
165
- * @param int $id
166
- *
167
- * @since 2.0
168
- */
169
- public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
170
- $options = (array) $options;
171
- $form_field_type = PodsForm::$field_type;
172
-
173
- if ( !is_admin() ) {
174
- include_once( ABSPATH . '/wp-admin/includes/template.php' );
175
-
176
- if ( is_multisite() )
177
- include_once( ABSPATH . '/wp-admin/includes/ms.php' );
178
- }
179
-
180
- if ( ( ( defined( 'PODS_DISABLE_FILE_UPLOAD' ) && true === PODS_DISABLE_FILE_UPLOAD )
181
- || ( defined( 'PODS_UPLOAD_REQUIRE_LOGIN' ) && is_bool( PODS_UPLOAD_REQUIRE_LOGIN ) && true === PODS_UPLOAD_REQUIRE_LOGIN && !is_user_logged_in() )
182
- || ( defined( 'PODS_UPLOAD_REQUIRE_LOGIN' ) && !is_bool( PODS_UPLOAD_REQUIRE_LOGIN ) && ( !is_user_logged_in() || !current_user_can( PODS_UPLOAD_REQUIRE_LOGIN ) ) ) )
183
- && ( ( defined( 'PODS_DISABLE_FILE_BROWSER' ) && true === PODS_DISABLE_FILE_BROWSER )
184
- || ( defined( 'PODS_FILES_REQUIRE_LOGIN' ) && is_bool( PODS_FILES_REQUIRE_LOGIN ) && true === PODS_FILES_REQUIRE_LOGIN && !is_user_logged_in() )
185
- || ( defined( 'PODS_FILES_REQUIRE_LOGIN' ) && !is_bool( PODS_FILES_REQUIRE_LOGIN ) && ( !is_user_logged_in() || !current_user_can( PODS_FILES_REQUIRE_LOGIN ) ) ) )
186
- ) {
187
- ?>
188
- <p>You do not have access to upload / browse files. Contact your website admin to resolve.</p>
189
- <?php
190
- return;
191
- }
192
-
193
- if ( 'plupload' == pods_v( self::$type . '_uploader', $options ) )
194
- $field_type = 'plupload';
195
- elseif ( 'attachment' == pods_v( self::$type . '_uploader', $options ) ) {
196
- if ( !pods_version_check( 'wp', '3.5' ) || !is_admin() ) // @todo test frontend media modal
197
- $field_type = 'attachment';
198
- else
199
- $field_type = 'media';
200
- }
201
- else {
202
- // Support custom File Uploader integration
203
- do_action( 'pods_form_ui_field_avatar_uploader_' . pods_v( self::$type . '_uploader', $options ), $name, $value, $options, $pod, $id );
204
- do_action( 'pods_form_ui_field_avatar_uploader', pods_v( self::$type . '_uploader', $options ), $name, $value, $options, $pod, $id );
205
- return;
206
- }
207
-
208
- pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
209
- }
210
-
211
- /**
212
- * Build regex necessary for JS validation
213
- *
214
- * @param mixed $value
215
- * @param string $name
216
- * @param array $options
217
- * @param string $pod
218
- * @param int $id
219
- *
220
- * @return bool
221
- * @since 2.0
222
- */
223
- public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
224
- return false;
225
- }
226
-
227
- /**
228
- * Validate a value before it's saved
229
- *
230
- * @param mixed $value
231
- * @param string $name
232
- * @param array $options
233
- * @param array $fields
234
- * @param array $pod
235
- * @param int $id
236
- * @param null $params
237
- *
238
- * @return bool
239
- * @since 2.0
240
- */
241
- public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
242
- // check file size
243
- // check file extensions
244
- return true;
245
- }
246
-
247
- /**
248
- * Change the value or perform actions after validation but before saving to the DB
249
- *
250
- * @param mixed $value
251
- * @param int $id
252
- * @param string $name
253
- * @param array $options
254
- * @param array $fields
255
- * @param array $pod
256
- * @param object $params
257
- *
258
- * @return mixed
259
- * @since 2.0
260
- */
261
- public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
262
- return $value;
263
- }
264
-
265
- /**
266
- * Customize the Pods UI manage table column output
267
- *
268
- * @param int $id
269
- * @param mixed $value
270
- * @param string $name
271
- * @param array $options
272
- * @param array $fields
273
- * @param array $pod
274
- *
275
- * @return mixed|void
276
- * @since 2.0
277
- */
278
- public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
279
- if ( empty( $value ) )
280
- return;
281
-
282
- if ( !empty( $value ) && isset( $value[ 'ID' ] ) )
283
- $value = array( $value );
284
-
285
- foreach ( $value as $v ) {
286
- echo pods_image( $v, 'thumbnail' );
287
- }
288
- }
289
-
290
- /**
291
- * Take over the avatar served from WordPress
292
- *
293
- * @param string $avatar Default Avatar Image output from WordPress
294
- * @param int|string|object $id_or_email A user ID, email address, or comment object
295
- * @param int $size Size of the avatar image
296
- * @param string $default URL to a default image to use if no avatar is available
297
- * @param string $alt Alternate text to use in image tag. Defaults to blank
298
- * @return string <img> tag for the user's avatar
299
- */
300
- public function get_avatar ( $avatar, $id_or_email, $size, $default = '', $alt ='' ) {
301
- // Don't replace for the Avatars section of the Discussion settings page
302
- if ( is_admin() ) {
303
- $current_screen = get_current_screen();
304
- if ( ! is_null( $current_screen ) && 'options-discussion' == $current_screen->id && 32 == $size ) {
305
- return $avatar;
306
- }
307
- }
308
-
309
- $_user_ID = 0;
310
-
311
- if ( is_numeric( $id_or_email ) && 0 < $id_or_email )
312
- $_user_ID = (int) $id_or_email;
313
- elseif ( is_object( $id_or_email ) && isset( $id_or_email->user_id ) && 0 < $id_or_email->user_id )
314
- $_user_ID = (int) $id_or_email->user_id;
315
- elseif ( is_object( $id_or_email ) && isset( $id_or_email->ID ) && isset( $id_or_email->user_login ) && 0 < $id_or_email->ID )
316
- $_user_ID = (int) $id_or_email->ID;
317
- elseif ( !is_object( $id_or_email ) && false !== strpos( $id_or_email, '@' ) ) {
318
- $_user = get_user_by( 'email', $id_or_email );
319
-
320
- if ( !empty( $_user ) )
321
- $_user_ID = (int) $_user->ID;
322
- }
323
-
324
- // Include PodsMeta if not already included
325
  pods_meta();
326
 
327
- if ( 0 < $_user_ID && !empty( PodsMeta::$user ) ) {
328
- $avatar_cached = pods_cache_get( $_user_ID . '-' . $size, 'pods_avatars' );
 
 
 
 
 
 
 
329
 
330
- if ( !empty( $avatar_cached ) )
331
- $avatar = $avatar_cached;
332
- else {
333
- $avatar_field = pods_transient_get( 'pods_avatar_field' );
334
 
335
- $user = current( PodsMeta::$user );
336
 
337
- if ( empty( $avatar_field ) ) {
338
- foreach ( $user[ 'fields' ] as $field ) {
339
- if ( 'avatar' == $field[ 'type' ] ) {
340
- $avatar_field = $field[ 'name' ];
 
 
341
 
342
- pods_transient_set( 'pods_avatar_field', $avatar_field );
 
343
 
344
- break;
345
- }
346
- }
347
- }
348
- elseif ( !isset( $user[ 'fields' ][ $avatar_field ] ) )
349
- $avatar_field = false;
350
 
351
- if ( !empty( $avatar_field ) ) {
352
- $user_avatar = get_user_meta( $_user_ID, $avatar_field . '.ID', true );
 
353
 
354
- if ( !empty( $user_avatar ) ) {
355
- $attributes = array(
356
- 'alt' => '',
357
- 'class' => 'avatar avatar-' . $size . ' photo'
358
- );
359
 
360
- if ( !empty( $alt ) )
361
- $attributes[ 'alt' ] = $alt;
362
 
363
- $user_avatar = pods_image( $user_avatar, array( $size, $size ), 0, $attributes );
 
 
 
 
 
364
 
365
- if ( !empty( $user_avatar ) ) {
366
- $avatar = $user_avatar;
367
 
368
- pods_cache_set( $_user_ID . '-' . $size, $avatar, 'pods_avatars' );
369
- }
370
- }
371
- }
372
- }
373
- }
374
 
375
- return $avatar;
376
- }
377
  }
1
  <?php
2
+ require_once( PODS_DIR . 'classes/fields/file.php' );
3
+
4
  /**
5
  * @package Pods\Fields
6
  */
7
+ class PodsField_Avatar extends PodsField_File {
8
+
9
+ /**
10
+ * Field Type Group
11
+ *
12
+ * @var string
13
+ * @since 2.0
14
+ */
15
+ public static $group = 'Relationships / Media';
16
+
17
+ /**
18
+ * Field Type Identifier
19
+ *
20
+ * @var string
21
+ * @since 2.0
22
+ */
23
+ public static $type = 'avatar';
24
+
25
+ /**
26
+ * Field Type Label
27
+ *
28
+ * @var string
29
+ * @since 2.0
30
+ */
31
+ public static $label = 'Avatar';
32
+
33
+ /**
34
+ * Pod Types supported on (true for all, false for none, or give array of specific types supported)
35
+ *
36
+ * @var array|bool
37
+ * @since 2.1
38
+ */
39
+ public static $pod_types = array( 'user' );
40
+
41
+ /**
42
+ * {@inheritdoc}
43
+ */
44
+ public function __construct() {
45
+
46
+ self::$label = __( 'Avatar', 'pods' );
47
+ }
48
+
49
+ /**
50
+ * {@inheritdoc}
51
+ */
52
+ public function options() {
53
+
54
+ $options = parent::options();
55
+
56
+ unset( $options[ self::$type . '_type' ] );
57
+ unset( $options[ self::$type . '_allowed_extensions' ] );
58
+ unset( $options[ self::$type . '_field_template' ] );
59
+ unset( $options[ self::$type . '_wp_gallery_output' ] );
60
+ unset( $options[ self::$type . '_wp_gallery_link' ] );
61
+ unset( $options[ self::$type . '_wp_gallery_columns' ] );
62
+ unset( $options[ self::$type . '_wp_gallery_random_sort' ] );
63
+ unset( $options[ self::$type . '_wp_gallery_size' ] );
64
+
65
+ return $options;
66
+
67
+ }
68
+
69
+ /**
70
+ * {@inheritdoc}
71
+ */
72
+ public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
73
+
74
+ $options = (array) $options;
75
+
76
+ $options[ self::$type . '_type' ] = 'images';
77
+ $options[ self::$type . '_field_template' ] = 'rows';
78
+ $options[ self::$type . '_wp_gallery_output' ] = 0;
79
+
80
+ parent::input( $name, $value, $options, $pod, $id );
81
+
82
+ }
83
+
84
+ /**
85
+ * Take over the avatar served from WordPress
86
+ *
87
+ * @param string $avatar Default Avatar Image output from WordPress.
88
+ * @param int|string|object $id_or_email A user ID, email address, or comment object.
89
+ * @param int $size Size of the avatar image.
90
+ * @param string $default URL to a default image to use if no avatar is available.
91
+ * @param string $alt Alternate text to use in image tag. Defaults to blank.
92
+ *
93
+ * @return string <img> tag for the user's avatar
94
+ */
95
+ public function get_avatar( $avatar, $id_or_email, $size, $default = '', $alt = '' ) {
96
+
97
+ // Don't replace for the Avatars section of the Discussion settings page.
98
+ if ( is_admin() ) {
99
+ $current_screen = get_current_screen();
100
+
101
+ if ( ! is_null( $current_screen ) && 'options-discussion' === $current_screen->id && 32 === $size ) {
102
+ return $avatar;
103
+ }
104
+ }
105
+
106
+ $user_id = 0;
107
+
108
+ if ( is_numeric( $id_or_email ) && 0 < $id_or_email ) {
109
+ $user_id = (int) $id_or_email;
110
+ } elseif ( is_object( $id_or_email ) && isset( $id_or_email->user_id ) && 0 < $id_or_email->user_id ) {
111
+ $user_id = (int) $id_or_email->user_id;
112
+ } elseif ( is_object( $id_or_email ) && isset( $id_or_email->ID ) && isset( $id_or_email->user_login ) && 0 < $id_or_email->ID ) {
113
+ $user_id = (int) $id_or_email->ID;
114
+ } elseif ( ! is_object( $id_or_email ) && false !== strpos( $id_or_email, '@' ) ) {
115
+ $_user = get_user_by( 'email', $id_or_email );
116
+
117
+ if ( ! empty( $_user ) ) {
118
+ $user_id = (int) $_user->ID;
119
+ }
120
+ }
121
+
122
+ // Include PodsMeta if not already included.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  pods_meta();
124
 
125
+ if ( 0 < $user_id && ! empty( PodsMeta::$user ) ) {
126
+ $avatar_cached = pods_cache_get( $user_id . '-' . $size, 'pods_avatars' );
127
+
128
+ if ( ! empty( $avatar_cached ) ) {
129
+ $avatar = $avatar_cached;
130
+ } else {
131
+ $avatar_field = pods_transient_get( 'pods_avatar_field' );
132
+
133
+ $user = current( PodsMeta::$user );
134
 
135
+ if ( empty( $avatar_field ) ) {
136
+ foreach ( $user['fields'] as $field ) {
137
+ if ( 'avatar' === $field['type'] ) {
138
+ $avatar_field = $field['name'];
139
 
140
+ pods_transient_set( 'pods_avatar_field', $avatar_field );
141
 
142
+ break;
143
+ }
144
+ }
145
+ } elseif ( ! isset( $user['fields'][ $avatar_field ] ) ) {
146
+ $avatar_field = false;
147
+ }
148
 
149
+ if ( ! empty( $avatar_field ) ) {
150
+ $user_avatar = get_user_meta( $user_id, $avatar_field . '.ID', true );
151
 
152
+ if ( ! empty( $user_avatar ) ) {
153
+ $attributes = array(
154
+ 'alt' => '',
155
+ 'class' => 'avatar avatar-' . $size . ' photo',
156
+ );
 
157
 
158
+ if ( ! empty( $alt ) ) {
159
+ $attributes['alt'] = $alt;
160
+ }
161
 
162
+ $user_avatar = pods_image( $user_avatar, array( $size, $size ), 0, $attributes );
 
 
 
 
163
 
164
+ if ( ! empty( $user_avatar ) ) {
165
+ $avatar = $user_avatar;
166
 
167
+ pods_cache_set( $user_id . '-' . $size, $avatar, 'pods_avatars' );
168
+ }
169
+ }
170
+ }
171
+ }
172
+ }
173
 
174
+ return $avatar;
 
175
 
176
+ }
 
 
 
 
 
177
 
 
 
178
  }
classes/fields/boolean.php CHANGED
@@ -87,6 +87,23 @@ class PodsField_Boolean extends PodsField {
87
  return $schema;
88
  }
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  /**
91
  * Change the way the value of the field is displayed with Pods::get
92
  *
87
  return $schema;
88
  }
89
 
90
+ /**
91
+ * {@inheritdoc}
92
+ */
93
+ public function is_empty( $value = null ) {
94
+
95
+ $is_empty = false;
96
+
97
+ $value = filter_var( $value, FILTER_VALIDATE_BOOLEAN );
98
+
99
+ if ( ! $value ) {
100
+ $is_empty = true;
101
+ }
102
+
103
+ return $is_empty;
104
+
105
+ }
106
+
107
  /**
108
  * Change the way the value of the field is displayed with Pods::get
109
  *
classes/fields/color.php CHANGED
@@ -108,13 +108,7 @@ class PodsField_Color extends PodsField {
108
  $value = implode( ' ', $value );
109
 
110
  // WP Color Picker for 3.5+
111
- if ( pods_version_check( 'wp', '3.5' ) ) {
112
- $field_type = 'color';
113
- }
114
- // Farbtastic for below 3.5
115
- else {
116
- $field_type = 'farbtastic';
117
- }
118
 
119
  if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) {
120
  if ( pods_v( 'read_only', $options, false ) ) {
108
  $value = implode( ' ', $value );
109
 
110
  // WP Color Picker for 3.5+
111
+ $field_type = 'color';
 
 
 
 
 
 
112
 
113
  if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) {
114
  if ( pods_v( 'read_only', $options, false ) ) {
classes/fields/comment.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once( PODS_DIR . 'classes/fields/pick.php' );
3
+
4
+ /**
5
+ * @package Pods\Fields
6
+ */
7
+ class PodsField_Comment extends PodsField_Pick {
8
+
9
+ /**
10
+ * Setup related objects list
11
+ *
12
+ * @since 2.0
13
+ */
14
+ public function __construct () {
15
+ parent::__construct();
16
+ // this field type just maps to the relationship field
17
+ }
18
+
19
+ }
classes/fields/currency.php CHANGED
@@ -1,9 +1,10 @@
1
  <?php
 
2
 
3
  /**
4
  * @package Pods\Fields
5
  */
6
- class PodsField_Currency extends PodsField {
7
 
8
  /**
9
  * Field Type Group
@@ -52,7 +53,7 @@ class PodsField_Currency extends PodsField {
52
  */
53
  public function __construct() {
54
  self::$label = __( 'Currency', 'pods' );
55
- self::data_currencies();
56
  }
57
 
58
  /**
@@ -65,7 +66,7 @@ class PodsField_Currency extends PodsField {
65
  public function options() {
66
 
67
  $currency_options = array();
68
- foreach ( self::$currencies as $key => $value ) {
69
  $currency = $value['label'];
70
  if ( $value['label'] != $value['name'] ) {
71
  $currency .= ': ' . $value['name'];
@@ -75,7 +76,7 @@ class PodsField_Currency extends PodsField {
75
  }
76
 
77
  $options = array(
78
- self::$type . '_repeatable' => array(
79
  'label' => __( 'Repeatable Field', 'pods' ),
80
  'default' => 0,
81
  'type' => 'boolean',
@@ -84,7 +85,7 @@ class PodsField_Currency extends PodsField {
84
  'dependency' => true,
85
  'developer_mode' => true
86
  ),
87
- self::$type . '_format_type' => array(
88
  'label' => __( 'Input Type', 'pods' ),
89
  'default' => 'number',
90
  'type' => 'pick',
@@ -94,13 +95,14 @@ class PodsField_Currency extends PodsField {
94
  ),
95
  'dependency' => true
96
  ),
97
- self::$type . '_format_sign' => array(
98
  'label' => __( 'Currency Sign', 'pods' ),
99
  'default' => apply_filters( 'pods_form_ui_field_number_currency_default', 'usd' ),
100
  'type' => 'pick',
 
101
  'data' => apply_filters( 'pods_form_ui_field_number_currency_options', $currency_options )
102
  ),
103
- self::$type . '_format_placement' => array(
104
  'label' => __( 'Currency Placement', 'pods' ),
105
  'default' => apply_filters( 'pods_form_ui_field_number_currency_placement_default', 'before' ),
106
  'type' => 'pick',
@@ -111,7 +113,7 @@ class PodsField_Currency extends PodsField {
111
  'beforeaftercode' => __( 'Before with Currency Code after (ex. $100 USD)', 'pods' )
112
  )
113
  ),
114
- self::$type . '_format' => array(
115
  'label' => __( 'Format', 'pods' ),
116
  'default' => apply_filters( 'pods_form_ui_field_number_currency_format_default', 'i18n' ),
117
  'type' => 'pick',
@@ -125,12 +127,12 @@ class PodsField_Currency extends PodsField {
125
  '9999,99' => '1234,00'
126
  )
127
  ),
128
- self::$type . '_decimals' => array(
129
  'label' => __( 'Decimals', 'pods' ),
130
  'default' => 2,
131
  'type' => 'number'
132
  ),
133
- self::$type . '_decimal_handling' => array(
134
  'label' => __( 'Decimal handling when zero', 'pods' ),
135
  'default' => 'none',
136
  'type' => 'pick',
@@ -140,32 +142,41 @@ class PodsField_Currency extends PodsField {
140
  'dash' => __( 'Convert to dash', 'pods' ) . ' (-)',
141
  )
142
  ),
143
- self::$type . '_step' => array(
144
  'label' => __( 'Slider Increment (Step)', 'pods' ),
145
- 'depends-on' => array( self::$type . '_format_type' => 'slider' ),
146
  'default' => 1,
147
  'type' => 'text'
148
  ),
149
- self::$type . '_min' => array(
150
  'label' => __( 'Minimum Number', 'pods' ),
151
- 'depends-on' => array( self::$type . '_format_type' => 'slider' ),
152
  'default' => 0,
153
  'type' => 'text'
154
  ),
155
- self::$type . '_max' => array(
156
  'label' => __( 'Maximum Number', 'pods' ),
157
- 'depends-on' => array( self::$type . '_format_type' => 'slider' ),
158
  'default' => 1000,
159
  'type' => 'text'
160
  ),
161
- self::$type . '_max_length' => array(
162
  'label' => __( 'Maximum Length', 'pods' ),
163
  'default' => 12,
164
  'type' => 'number',
165
  'help' => __( 'Set to -1 for no limit', 'pods' )
166
- )
 
 
 
 
 
 
 
 
 
167
  /*,
168
- self::$type . '_size' => array(
169
  'label' => __( 'Field Size', 'pods' ),
170
  'default' => 'medium',
171
  'type' => 'pick',
@@ -181,83 +192,6 @@ class PodsField_Currency extends PodsField {
181
 
182
  }
183
 
184
- /**
185
- * Define the current field's schema for DB table storage
186
- *
187
- * @param array $options
188
- *
189
- * @return string
190
- * @since 2.0
191
- */
192
- public function schema( $options = null ) {
193
-
194
- $length = (int) pods_v( self::$type . '_max_length', $options, 12, true );
195
-
196
- if ( $length < 1 || 64 < $length ) {
197
- $length = 64;
198
- }
199
-
200
- $decimals = (int) pods_v( self::$type . '_decimals', $options, 2, true );
201
-
202
- if ( $decimals < 1 ) {
203
- $decimals = 0;
204
- }
205
- elseif ( 30 < $decimals ) {
206
- $decimals = 30;
207
- }
208
-
209
- if ( $length < $decimals ) {
210
- $decimals = $length;
211
- }
212
-
213
- $schema = 'DECIMAL(' . $length . ',' . $decimals . ')';
214
-
215
- return $schema;
216
-
217
- }
218
-
219
- /**
220
- * Define the current field's preparation for sprintf
221
- *
222
- * @param array $options
223
- *
224
- * @return string
225
- * @since 2.0
226
- */
227
- public function prepare( $options = null ) {
228
-
229
- $format = self::$prepare;
230
-
231
- $length = (int) pods_v( self::$type . '_max_length', $options, 12, true );
232
-
233
- if ( $length < 1 || 64 < $length ) {
234
- $length = 64;
235
- }
236
-
237
- $decimals = (int) pods_v( self::$type . '_decimals', $options, 2, true );
238
-
239
- if ( $decimals < 1 ) {
240
- $decimals = 0;
241
- }
242
- elseif ( 30 < $decimals ) {
243
- $decimals = 30;
244
- }
245
-
246
- if ( $length < $decimals ) {
247
- $decimals = $length;
248
- }
249
-
250
- if ( 0 < $decimals ) {
251
- $format = '%F';
252
- }
253
- else {
254
- $format = '%d';
255
- }
256
-
257
- return $format;
258
-
259
- }
260
-
261
  /**
262
  * Change the way the value of the field is displayed with Pods::get
263
  *
@@ -276,14 +210,14 @@ class PodsField_Currency extends PodsField {
276
 
277
  $currency = 'usd';
278
 
279
- if ( isset( self::$currencies[ pods_v( self::$type . '_format_sign', $options, -1 ) ] ) ) {
280
- $currency = pods_v( self::$type . '_format_sign', $options );
281
  }
282
 
283
- $currency_sign = self::$currencies[ $currency ]['sign'];
284
- $currency_label = self::$currencies[ $currency ]['label'];
285
 
286
- $placement = pods_v( self::$type . '_format_placement', $options, 'before', true );
287
 
288
  // Currency placement policy
289
  // Single sign currencies: 100$, £100
@@ -308,57 +242,6 @@ class PodsField_Currency extends PodsField {
308
 
309
  }
310
 
311
- /**
312
- * Customize output of the form field
313
- *
314
- * @param string $name
315
- * @param mixed $value
316
- * @param array $options
317
- * @param array $pod
318
- * @param int $id
319
- *
320
- * @since 2.0
321
- */
322
- public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
323
-
324
- $options = (array) $options;
325
- $form_field_type = PodsForm::$field_type;
326
-
327
- if ( is_array( $value ) ) {
328
- $value = implode( '', $value );
329
- }
330
-
331
- if ( 'slider' == pods_v( self::$type . '_format_type', $options, 'number' ) ) {
332
- $field_type = 'slider';
333
- }
334
- else {
335
- $field_type = 'currency';
336
- }
337
-
338
- if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) {
339
- if ( pods_v( 'read_only', $options, false ) ) {
340
- $options[ 'readonly' ] = true;
341
-
342
- $field_type = 'text';
343
-
344
- $value = $this->format( $value, $name, $options, $pod, $id );
345
- }
346
- else {
347
- return;
348
- }
349
- }
350
- elseif ( !pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) {
351
- $options[ 'readonly' ] = true;
352
-
353
- $field_type = 'text';
354
-
355
- $value = $this->format( $value, $name, $options, $pod, $id );
356
- }
357
-
358
- pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
359
-
360
- }
361
-
362
  /**
363
  * Build regex necessary for JS validation
364
  *
@@ -373,44 +256,17 @@ class PodsField_Currency extends PodsField {
373
  */
374
  public function regex( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
375
 
376
- global $wp_locale;
377
-
378
- if ( '9.999,99' == pods_v( self::$type . '_format', $options ) ) {
379
- $thousands = '.';
380
- $dot = ',';
381
- }
382
- elseif ( '9,999.99' == pods_v( self::$type . '_format', $options ) ) {
383
- $thousands = ',';
384
- $dot = '.';
385
- }
386
- elseif ( '9\'999.99' == pods_v( self::$type . '_format', $options ) ) {
387
- $thousands = '\'';
388
- $dot = '.';
389
- }
390
- elseif ( '9 999,99' == pods_v( self::$type . '_format', $options ) ) {
391
- $thousands = ' ';
392
- $dot = ',';
393
- }
394
- elseif ( '9999.99' == pods_v( self::$type . '_format', $options ) ) {
395
- $thousands = '';
396
- $dot = '.';
397
- }
398
- elseif ( '9999,99' == pods_v( self::$type . '_format', $options ) ) {
399
- $thousands = '';
400
- $dot = ',';
401
- }
402
- else {
403
- $thousands = $wp_locale->number_format[ 'thousands_sep' ];
404
- $dot = $wp_locale->number_format[ 'decimal_point' ];
405
- }
406
 
407
  $currency = 'usd';
408
 
409
- if ( isset( self::$currencies[ pods_v( self::$type . '_format_sign', $options, -1 ) ] ) ) {
410
- $currency = pods_v( self::$type . '_format_sign', $options );
411
  }
412
 
413
- $currency_sign = self::$currencies[ $currency ]['sign'];
414
 
415
  return '\-*\\' . $currency_sign . '*[0-9\\' . implode( '\\', array_filter( array( $dot, $thousands ) ) ) . ']+';
416
 
@@ -432,45 +288,18 @@ class PodsField_Currency extends PodsField {
432
  */
433
  public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
434
 
435
- global $wp_locale;
436
-
437
- if ( '9.999,99' == pods_v( self::$type . '_format', $options ) ) {
438
- $thousands = '.';
439
- $dot = ',';
440
- }
441
- elseif ( '9,999.99' == pods_v( self::$type . '_format', $options ) ) {
442
- $thousands = ',';
443
- $dot = '.';
444
- }
445
- elseif ( '9\'999.99' == pods_v( self::$type . '_format', $options ) ) {
446
- $thousands = '\'';
447
- $dot = '.';
448
- }
449
- elseif ( '9 999,99' == pods_v( self::$type . '_format', $options ) ) {
450
- $thousands = ' ';
451
- $dot = ',';
452
- }
453
- elseif ( '9999.99' == pods_v( self::$type . '_format', $options ) ) {
454
- $thousands = ',';
455
- $dot = '.';
456
- }
457
- elseif ( '9999,99' == pods_v( self::$type . '_format', $options ) ) {
458
- $thousands = '.';
459
- $dot = ',';
460
- }
461
- else {
462
- $thousands = $wp_locale->number_format[ 'thousands_sep' ];
463
- $dot = $wp_locale->number_format[ 'decimal_point' ];
464
- }
465
 
466
  $currency = 'usd';
467
 
468
- if ( isset( self::$currencies[ pods_v( self::$type . '_format_sign', $options, -1 ) ] ) ) {
469
- $currency = pods_v( self::$type . '_format_sign', $options );
470
  }
471
 
472
- $currency_sign = self::$currencies[ $currency ]['sign'];
473
- $currency_entity = self::$currencies[ $currency ]['entity'];
474
 
475
  // Remove currency and thousands symbols
476
  $check = str_replace(
@@ -517,45 +346,19 @@ class PodsField_Currency extends PodsField {
517
  */
518
  public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
519
 
520
- global $wp_locale;
521
-
522
- if ( '9.999,99' == pods_v( self::$type . '_format', $options ) ) {
523
- $thousands = '.';
524
- $dot = ',';
525
- }
526
- elseif ( '9,999.99' == pods_v( self::$type . '_format', $options ) ) {
527
- $thousands = ',';
528
- $dot = '.';
529
- }
530
- elseif ( '9\'999.99' == pods_v( self::$type . '_format', $options ) ) {
531
- $thousands = '\'';
532
- $dot = '.';
533
- }
534
- elseif ( '9 999,99' == pods_v( self::$type . '_format', $options ) ) {
535
- $thousands = ' ';
536
- $dot = ',';
537
- }
538
- elseif ( '9999.99' == pods_v( self::$type . '_format', $options ) ) {
539
- $thousands = ',';
540
- $dot = '.';
541
- }
542
- elseif ( '9999,99' == pods_v( self::$type . '_format', $options ) ) {
543
- $thousands = '.';
544
- $dot = ',';
545
- }
546
- else {
547
- $thousands = $wp_locale->number_format[ 'thousands_sep' ];
548
- $dot = $wp_locale->number_format[ 'decimal_point' ];
549
- }
550
 
551
  $currency = 'usd';
552
 
553
- if ( isset( self::$currencies[ pods_v( self::$type . '_format_sign', $options, -1 ) ] ) ) {
554
- $currency = pods_v( self::$type . '_format_sign', $options );
555
  }
556
 
557
- $currency_sign = self::$currencies[ $currency ]['sign'];
558
- $currency_entity = self::$currencies[ $currency ]['entity'];
559
 
560
  // Convert decimal type for numeric type
561
  $value = str_replace(
@@ -576,50 +379,12 @@ class PodsField_Currency extends PodsField {
576
 
577
  $value = preg_replace( '/[^0-9\.\-]/', '', $value );
578
 
579
- $length = (int) pods_v( self::$type . '_max_length', $options, 12, true );
580
-
581
- if ( $length < 1 || 64 < $length ) {
582
- $length = 64;
583
- }
584
-
585
- $decimals = (int) pods_v( self::$type . '_decimals', $options, 2, true );
586
-
587
- if ( $decimals < 1 ) {
588
- $decimals = 0;
589
- }
590
- elseif ( 30 < $decimals ) {
591
- $decimals = 30;
592
- }
593
-
594
- if ( $length < $decimals ) {
595
- $decimals = $length;
596
- }
597
-
598
  $value = number_format( (float) $value, $decimals, '.', '' );
599
 
600
  return $value;
601
 
602
  }
603
 
604
- /**
605
- * Customize the Pods UI manage table column output
606
- *
607
- * @param int $id
608
- * @param mixed $value
609
- * @param string $name
610
- * @param array $options
611
- * @param array $fields
612
- * @param array $pod
613
- *
614
- * @return mixed|null|string
615
- * @since 2.0
616
- */
617
- public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
618
-
619
- return $this->display( $value, $name, $options, $pod, $id );
620
-
621
- }
622
-
623
  /**
624
  * Reformat a number to the way the value of the field is displayed
625
  *
@@ -634,62 +399,17 @@ class PodsField_Currency extends PodsField {
634
  */
635
  public function format( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
636
 
637
- global $wp_locale;
638
-
639
  if ( null === $value ) {
640
  // Don't enforce a default value here
641
  return null;
642
  }
643
 
644
- if ( '9.999,99' == pods_v( self::$type . '_format', $options ) ) {
645
- $thousands = '.';
646
- $dot = ',';
647
- }
648
- elseif ( '9,999.99' == pods_v( self::$type . '_format', $options ) ) {
649
- $thousands = ',';
650
- $dot = '.';
651
- }
652
- elseif ( '9\'999.99' == pods_v( self::$type . '_format', $options ) ) {
653
- $thousands = '\'';
654
- $dot = '.';
655
- }
656
- elseif ( '9 999,99' == pods_v( self::$type . '_format', $options ) ) {
657
- $thousands = ' ';
658
- $dot = ',';
659
- }
660
- elseif ( '9999.99' == pods_v( self::$type . '_format', $options ) ) {
661
- $thousands = '';
662
- $dot = '.';
663
- }
664
- elseif ( '9999,99' == pods_v( self::$type . '_format', $options ) ) {
665
- $thousands = '';
666
- $dot = ',';
667
- }
668
- else {
669
- $thousands = $wp_locale->number_format[ 'thousands_sep' ];
670
- $dot = $wp_locale->number_format[ 'decimal_point' ];
671
- }
672
-
673
- $length = (int) pods_v( self::$type . '_max_length', $options, 12, true );
674
-
675
- if ( $length < 1 || 64 < $length ) {
676
- $length = 64;
677
- }
678
-
679
- $decimals = (int) pods_v( self::$type . '_decimals', $options, 2 );
680
 
681
- if ( $decimals < 1 ) {
682
- $decimals = 0;
683
- }
684
- elseif ( 30 < $decimals ) {
685
- $decimals = 30;
686
- }
687
-
688
- if ( $length < $decimals ) {
689
- $decimals = $length;
690
- }
691
-
692
- if ( 'i18n' == pods_v( self::$type . '_format', $options ) ) {
693
  $value = number_format_i18n( (float) $value, $decimals );
694
  }
695
  else {
@@ -697,7 +417,7 @@ class PodsField_Currency extends PodsField {
697
  }
698
 
699
  // Additional output handling for decimals
700
- $decimal_handling = pods_v( self::$type . '_decimal_handling', $options, 'none' ) ;
701
  if ( 'none' !== $decimal_handling ) {
702
  $value_parts = explode( $dot, $value );
703
  if ( 'remove' === $decimal_handling ) {
@@ -721,8 +441,8 @@ class PodsField_Currency extends PodsField {
721
  public static function data_currencies() {
722
 
723
  // If it's already done, do not redo the filter
724
- if ( ! empty( self::$currencies ) ) {
725
- return self::$currencies;
726
  }
727
 
728
  $default_currencies = array(
@@ -928,15 +648,15 @@ class PodsField_Currency extends PodsField {
928
  * }
929
  * @return array
930
  */
931
- self::$currencies = apply_filters( 'pods_form_ui_field_currency_currencies', $default_currencies );
932
 
933
  // Sort the currencies
934
- ksort( self::$currencies );
935
 
936
  // Backwards compatibility
937
- foreach ( self::$currencies as $key => $value ) {
938
  if ( is_string( $value ) ) {
939
- self::$currencies[ $key ] = array(
940
  'label' => strtoupper( $key ),
941
  'name' => strtoupper( $key ),
942
  'sign' => $value,
@@ -958,10 +678,42 @@ class PodsField_Currency extends PodsField {
958
  }
959
  } else {
960
  // Invalid
961
- unset( self::$currencies[ $key ] );
962
  }
963
  }
964
 
965
- return self::$currencies;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
966
  }
967
  }
1
  <?php
2
+ require_once( PODS_DIR . 'classes/fields/number.php' );
3
 
4
  /**
5
  * @package Pods\Fields
6
  */
7
+ class PodsField_Currency extends PodsField_Number {
8
 
9
  /**
10
  * Field Type Group
53
  */
54
  public function __construct() {
55
  self::$label = __( 'Currency', 'pods' );
56
+ static::data_currencies();
57
  }
58
 
59
  /**
66
  public function options() {
67
 
68
  $currency_options = array();
69
+ foreach ( static::$currencies as $key => $value ) {
70
  $currency = $value['label'];
71
  if ( $value['label'] != $value['name'] ) {
72
  $currency .= ': ' . $value['name'];
76
  }
77
 
78
  $options = array(
79
+ static::$type . '_repeatable' => array(
80
  'label' => __( 'Repeatable Field', 'pods' ),
81
  'default' => 0,
82
  'type' => 'boolean',
85
  'dependency' => true,
86
  'developer_mode' => true
87
  ),
88
+ static::$type . '_format_type' => array(
89
  'label' => __( 'Input Type', 'pods' ),
90
  'default' => 'number',
91
  'type' => 'pick',
95
  ),
96
  'dependency' => true
97
  ),
98
+ static::$type . '_format_sign' => array(
99
  'label' => __( 'Currency Sign', 'pods' ),
100
  'default' => apply_filters( 'pods_form_ui_field_number_currency_default', 'usd' ),
101
  'type' => 'pick',
102
+ //'pick_format_single' => 'autocomplete',
103
  'data' => apply_filters( 'pods_form_ui_field_number_currency_options', $currency_options )
104
  ),
105
+ static::$type . '_format_placement' => array(
106
  'label' => __( 'Currency Placement', 'pods' ),
107
  'default' => apply_filters( 'pods_form_ui_field_number_currency_placement_default', 'before' ),
108
  'type' => 'pick',
113
  'beforeaftercode' => __( 'Before with Currency Code after (ex. $100 USD)', 'pods' )
114
  )
115
  ),
116
+ static::$type . '_format' => array(
117
  'label' => __( 'Format', 'pods' ),
118
  'default' => apply_filters( 'pods_form_ui_field_number_currency_format_default', 'i18n' ),
119
  'type' => 'pick',
127
  '9999,99' => '1234,00'
128
  )
129
  ),
130
+ static::$type . '_decimals' => array(
131
  'label' => __( 'Decimals', 'pods' ),
132
  'default' => 2,
133
  'type' => 'number'
134
  ),
135
+ static::$type . '_decimal_handling' => array(
136
  'label' => __( 'Decimal handling when zero', 'pods' ),
137
  'default' => 'none',
138
  'type' => 'pick',
142
  'dash' => __( 'Convert to dash', 'pods' ) . ' (-)',
143
  )
144
  ),
145
+ static::$type . '_step' => array(
146
  'label' => __( 'Slider Increment (Step)', 'pods' ),
147
+ 'depends-on' => array( static::$type . '_format_type' => 'slider' ),
148
  'default' => 1,
149
  'type' => 'text'
150
  ),
151
+ static::$type . '_min' => array(
152
  'label' => __( 'Minimum Number', 'pods' ),
153
+ 'depends-on' => array( static::$type . '_format_type' => 'slider' ),
154
  'default' => 0,
155
  'type' => 'text'
156
  ),
157
+ static::$type . '_max' => array(
158
  'label' => __( 'Maximum Number', 'pods' ),
159
+ 'depends-on' => array( static::$type . '_format_type' => 'slider' ),
160
  'default' => 1000,
161
  'type' => 'text'
162
  ),
163
+ static::$type . '_max_length' => array(
164
  'label' => __( 'Maximum Length', 'pods' ),
165
  'default' => 12,
166
  'type' => 'number',
167
  'help' => __( 'Set to -1 for no limit', 'pods' )
168
+ ),
169
+ static::$type . '_placeholder' => array(
170
+ 'label' => __( 'HTML Placeholder', 'pods' ),
171
+ 'default' => '',
172
+ 'type' => 'text',
173
+ 'help' => array(
174
+ __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
175
+ 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
176
+ ),
177
+ ),
178
  /*,
179
+ static::$type . '_size' => array(
180
  'label' => __( 'Field Size', 'pods' ),
181
  'default' => 'medium',
182
  'type' => 'pick',
192
 
193
  }
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  /**
196
  * Change the way the value of the field is displayed with Pods::get
197
  *
210
 
211
  $currency = 'usd';
212
 
213
+ if ( isset( static::$currencies[ pods_v( static::$type . '_format_sign', $options, -1 ) ] ) ) {
214
+ $currency = pods_v( static::$type . '_format_sign', $options );
215
  }
216
 
217
+ $currency_sign = static::$currencies[ $currency ]['sign'];
218
+ $currency_label = static::$currencies[ $currency ]['label'];
219
 
220
+ $placement = pods_v( static::$type . '_format_placement', $options, 'before', true );
221
 
222
  // Currency placement policy
223
  // Single sign currencies: 100$, £100
242
 
243
  }
244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  /**
246
  * Build regex necessary for JS validation
247
  *
256
  */
257
  public function regex( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
258
 
259
+ $format_args = $this->get_number_format_args( $options );
260
+ $thousands = $format_args['thousands'];
261
+ $dot = $format_args['dot'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
 
263
  $currency = 'usd';
264
 
265
+ if ( isset( static::$currencies[ pods_v( static::$type . '_format_sign', $options, -1 ) ] ) ) {
266
+ $currency = pods_v( static::$type . '_format_sign', $options );
267
  }
268
 
269
+ $currency_sign = static::$currencies[ $currency ]['sign'];
270
 
271
  return '\-*\\' . $currency_sign . '*[0-9\\' . implode( '\\', array_filter( array( $dot, $thousands ) ) ) . ']+';
272
 
288
  */
289
  public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
290
 
291
+ $format_args = $this->get_number_format_args( $options );
292
+ $thousands = $format_args['thousands'];
293
+ $dot = $format_args['dot'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
 
295
  $currency = 'usd';
296
 
297
+ if ( isset( static::$currencies[ pods_v( static::$type . '_format_sign', $options, -1 ) ] ) ) {
298
+ $currency = pods_v( static::$type . '_format_sign', $options );
299
  }
300
 
301
+ $currency_sign = static::$currencies[ $currency ]['sign'];
302
+ $currency_entity = static::$currencies[ $currency ]['entity'];
303
 
304
  // Remove currency and thousands symbols
305
  $check = str_replace(
346
  */
347
  public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
348
 
349
+ $format_args = $this->get_number_format_args( $options );
350
+ $thousands = $format_args['thousands'];
351
+ $dot = $format_args['dot'];
352
+ $decimals = $format_args['decimals'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
 
354
  $currency = 'usd';
355
 
356
+ if ( isset( static::$currencies[ pods_v( static::$type . '_format_sign', $options, -1 ) ] ) ) {
357
+ $currency = pods_v( static::$type . '_format_sign', $options );
358
  }
359
 
360
+ $currency_sign = static::$currencies[ $currency ]['sign'];
361
+ $currency_entity = static::$currencies[ $currency ]['entity'];
362
 
363
  // Convert decimal type for numeric type
364
  $value = str_replace(
379
 
380
  $value = preg_replace( '/[^0-9\.\-]/', '', $value );
381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
382
  $value = number_format( (float) $value, $decimals, '.', '' );
383
 
384
  return $value;
385
 
386
  }
387
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
388
  /**
389
  * Reformat a number to the way the value of the field is displayed
390
  *
399
  */
400
  public function format( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
401
 
 
 
402
  if ( null === $value ) {
403
  // Don't enforce a default value here
404
  return null;
405
  }
406
 
407
+ $format_args = $this->get_number_format_args( $options );
408
+ $thousands = $format_args['thousands'];
409
+ $dot = $format_args['dot'];
410
+ $decimals = $format_args['decimals'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
 
412
+ if ( 'i18n' == pods_v( static::$type . '_format', $options ) ) {
 
 
 
 
 
 
 
 
 
 
 
413
  $value = number_format_i18n( (float) $value, $decimals );
414
  }
415
  else {
417
  }
418
 
419
  // Additional output handling for decimals
420
+ $decimal_handling = pods_v( static::$type . '_decimal_handling', $options, 'none' ) ;
421
  if ( 'none' !== $decimal_handling ) {
422
  $value_parts = explode( $dot, $value );
423
  if ( 'remove' === $decimal_handling ) {
441
  public static function data_currencies() {
442
 
443
  // If it's already done, do not redo the filter
444
+ if ( ! empty( static::$currencies ) ) {
445
+ return static::$currencies;
446
  }
447
 
448
  $default_currencies = array(
648
  * }
649
  * @return array
650
  */
651
+ static::$currencies = apply_filters( 'pods_form_ui_field_currency_currencies', $default_currencies );
652
 
653
  // Sort the currencies
654
+ ksort( static::$currencies );
655
 
656
  // Backwards compatibility
657
+ foreach ( static::$currencies as $key => $value ) {
658
  if ( is_string( $value ) ) {
659
+ static::$currencies[ $key ] = array(
660
  'label' => strtoupper( $key ),
661
  'name' => strtoupper( $key ),
662
  'sign' => $value,
678
  }
679
  } else {
680
  // Invalid
681
+ unset( static::$currencies[ $key ] );
682
  }
683
  }
684
 
685
+ return static::$currencies;
686
+ }
687
+
688
+ /**
689
+ * Get the max allowed decimals.
690
+ * Overwrites the default value of Number field. 2 decimals instead of 0.
691
+ *
692
+ * @since 2.7
693
+ * @param array $options
694
+ * @return int
695
+ */
696
+ public function get_max_decimals( $options ) {
697
+
698
+ $length = (int) pods_v( static::$type . '_max_length', $options, 12, true );
699
+
700
+ if ( $length < 1 || 64 < $length ) {
701
+ $length = 64;
702
+ }
703
+
704
+ $decimals = (int) pods_v( static::$type . '_decimals', $options, 2 );
705
+
706
+ if ( $decimals < 1 ) {
707
+ $decimals = 0;
708
+ }
709
+ elseif ( 30 < $decimals ) {
710
+ $decimals = 30;
711
+ }
712
+
713
+ if ( $length < $decimals ) {
714
+ $decimals = $length;
715
+ }
716
+
717
+ return $decimals;
718
  }
719
  }
classes/fields/date.php CHANGED
@@ -1,336 +1,189 @@
1
  <?php
 
2
  /**
3
  * @package Pods\Fields
4
  */
5
- class PodsField_Date extends PodsField {
6
-
7
- /**
8
- * Field Type Group
9
- *
10
- * @var string
11
- * @since 2.0
12
- */
13
- public static $group = 'Date / Time';
14
-
15
- /**
16
- * Field Type Identifier
17
- *
18
- * @var string
19
- * @since 2.0
20
- */
21
- public static $type = 'date';
22
-
23
- /**
24
- * Field Type Label
25
- *
26
- * @var string
27
- * @since 2.0
28
- */
29
- public static $label = 'Date';
30
-
31
- /**
32
- * Field Type Preparation
33
- *
34
- * @var string
35
- * @since 2.0
36
- */
37
- public static $prepare = '%s';
38
-
39
- /**
40
- * Do things like register/enqueue scripts and stylesheets
41
- *
42
- * @since 2.0
43
- */
44
- public function __construct () {
45
- self::$label = __( 'Date', 'pods' );
46
- }
47
-
48
- /**
49
- * Add options and set defaults to
50
- *
51
- * @return array
52
- *
53
- * @since 2.0
54
- */
55
- public function options () {
56
- $options = array(
57
- self::$type . '_repeatable' => array(
58
- 'label' => __( 'Repeatable Field', 'pods' ),
59
- 'default' => 0,
60
- 'type' => 'boolean',
61
- 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
62
- 'boolean_yes_label' => '',
63
- 'dependency' => true,
64
- 'developer_mode' => true
65
- ),
66
- self::$type . '_format' => array(
67
- 'label' => __( 'Date Format', 'pods' ),
68
- 'default' => 'mdy',
69
- 'type' => 'pick',
70
- 'data' => array(
71
- 'mdy' => date_i18n( 'm/d/Y' ),
72
- 'mdy_dash' => date_i18n( 'm-d-Y' ),
73
- 'mdy_dot' => date_i18n( 'm.d.Y' ),
74
- 'ymd_slash' => date_i18n( 'Y/m/d' ),
75
- 'ymd_dash' => date_i18n( 'Y-m-d' ),
76
- 'ymd_dot' => date_i18n( 'Y.m.d' ),
77
- 'fjy' => date_i18n( 'F j, Y' ),
78
- 'fjsy' => date_i18n( 'F jS, Y' ),
79
- 'y' => date_i18n( 'Y' )
80
- )
81
- ),
82
- self::$type . '_allow_empty' => array(
83
- 'label' => __( 'Allow empty value?', 'pods' ),
84
- 'default' => 1,
85
- 'type' => 'boolean'
86
- ),
87
- self::$type . '_html5' => array(
88
- 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
89
- 'default' => apply_filters( 'pods_form_ui_field_html5', 0, self::$type ),
90
- 'type' => 'boolean'
91
- )
92
- );
93
-
94
- // Check if PHP DateTime::createFromFormat exists for additional supported formats
95
- if ( method_exists( 'DateTime', 'createFromFormat' ) || apply_filters( 'pods_form_ui_field_datetime_custom_formatter', false ) ) {
96
- $options[ self::$type . '_format' ][ 'data' ] = array_merge(
97
- $options[ self::$type . '_format' ][ 'data' ],
98
- array(
99
- 'dmy' => date_i18n( 'd/m/Y' ),
100
- 'dmy_dash' => date_i18n( 'd-m-Y' ),
101
- 'dmy_dot' => date_i18n( 'd.m.Y' ),
102
- 'dMy' => date_i18n( 'd/M/Y' ),
103
- 'dMy_dash' => date_i18n( 'd-M-Y' )
104
- )
105
- );
106
- }
107
-
108
- $options[ self::$type . '_format' ][ 'data' ] = apply_filters( 'pods_form_ui_field_date_format_options', $options[ self::$type . '_format' ][ 'data' ] );
109
- $options[ self::$type . '_format' ][ 'default' ] = apply_filters( 'pods_form_ui_field_date_format_default', $options[ self::$type . '_format' ][ 'default' ] );
110
-
111
- return $options;
112
- }
113
-
114
- /**
115
- * Define the current field's schema for DB table storage
116
- *
117
- * @param array $options
118
- *
119
- * @return array
120
- * @since 2.0
121
- */
122
- public function schema ( $options = null ) {
123
- $schema = 'DATE NOT NULL default "0000-00-00"';
124
-
125
- return $schema;
126
- }
127
-
128
- /**
129
- * Change the way the value of the field is displayed with Pods::get
130
- *
131
- * @param mixed $value
132
- * @param string $name
133
- * @param array $options
134
- * @param array $pod
135
- * @param int $id
136
- *
137
- * @return mixed|null|string
138
- * @since 2.0
139
- */
140
- public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
141
- $format = $this->format( $options );
142
-
143
- if ( !empty( $value ) && !in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
144
- $date = $this->createFromFormat( 'Y-m-d', (string) $value );
145
- $date_local = $this->createFromFormat( $format, (string) $value );
146
-
147
- if ( false !== $date )
148
- $value = $date->format( $format );
149
- elseif ( false !== $date_local )
150
- $value = $date_local->format( $format );
151
- else
152
- $value = date_i18n( $format, strtotime( (string) $value ) );
153
- }
154
- elseif ( 0 == pods_var( self::$type . '_allow_empty', $options, 1 ) )
155
- $value = date_i18n( $format );
156
- else
157
- $value = '';
158
-
159
- return $value;
160
- }
161
-
162
- /**
163
- * Customize output of the form field
164
- *
165
- * @param string $name
166
- * @param mixed $value
167
- * @param array $options
168
- * @param array $pod
169
- * @param int $id
170
- *
171
- * @since 2.0
172
- */
173
- public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
174
- $options = (array) $options;
175
- $form_field_type = PodsForm::$field_type;
176
-
177
- if ( is_array( $value ) )
178
- $value = implode( ' ', $value );
179
-
180
- // Format Value
181
- $value = $this->display( $value, $name, $options, null, $pod, $id );
182
-
183
- $field_type = 'date';
184
-
185
- if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) {
186
- if ( pods_var( 'read_only', $options, false ) ) {
187
- $options[ 'readonly' ] = true;
188
-
189
- $field_type = 'text';
190
- }
191
- else
192
- return;
193
- }
194
- elseif ( !pods_has_permissions( $options ) && pods_var( 'read_only', $options, false ) ) {
195
- $options[ 'readonly' ] = true;
196
-
197
- $field_type = 'text';
198
- }
199
-
200
- pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
201
- }
202
-
203
- /**
204
- * Change the value or perform actions after validation but before saving to the DB
205
- *
206
- * @param mixed $value
207
- * @param int $id
208
- * @param string $name
209
- * @param array $options
210
- * @param array $fields
211
- * @param array $pod
212
- * @param object $params
213
- *
214
- * @return mixed|string
215
- * @since 2.0
216
- */
217
- public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
218
- $format = $this->format( $options );
219
-
220
- if ( !empty( $value ) && ( 0 == pods_var( self::$type . '_allow_empty', $options, 1 ) || !in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) )
221
- $value = $this->convert_date( $value, 'Y-m-d', $format );
222
- elseif ( 1 == pods_var( self::$type . '_allow_empty', $options, 1 ) )
223
- $value = '0000-00-00';
224
- else
225
- $value = date_i18n( 'Y-m-d' );
226
-
227
- return $value;
228
- }
229
-
230
- /**
231
- * Customize the Pods UI manage table column output
232
- *
233
- * @param int $id
234
- * @param mixed $value
235
- * @param string $name
236
- * @param array $options
237
- * @param array $fields
238
- * @param array $pod
239
- *
240
- * @return mixed|null|string
241
- * @since 2.0
242
- */
243
- public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
244
- $value = $this->display( $value, $name, $options, $pod, $id );
245
-
246
- if ( 1 == pods_var( self::$type . '_allow_empty', $options, 1 ) && ( empty( $value ) || in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) )
247
- $value = false;
248
-
249
- return $value;
250
- }
251
-
252
- /**
253
- * Build date/time format string based on options
254
- *
255
- * @param $options
256
- *
257
- * @return string
258
- * @since 2.0
259
- */
260
- public function format ( $options ) {
261
- $date_format = array(
262
- 'mdy' => 'm/d/Y',
263
- 'mdy_dash' => 'm-d-Y',
264
- 'mdy_dot' => 'm.d.Y',
265
- 'dmy' => 'd/m/Y',
266
- 'dmy_dash' => 'd-m-Y',
267
- 'dmy_dot' => 'd.m.Y',
268
- 'ymd_slash' => 'Y/m/d',
269
- 'ymd_dash' => 'Y-m-d',
270
- 'ymd_dot' => 'Y.m.d',
271
- 'dMy' => 'd/M/Y',
272
- 'dMy_dash' => 'd-M-Y',
273
- 'fjy' => 'F j, Y',
274
- 'fjsy' => 'F jS, Y',
275
- 'y' => 'Y'
276
- );
277
-
278
- $date_format = apply_filters( 'pods_form_ui_field_date_formats', $date_format );
279
-
280
- $format = $date_format[ pods_var( self::$type . '_format', $options, 'ymd_dash', null, true ) ];
281
-
282
- return $format;
283
- }
284
-
285
- /**
286
- * @param $format
287
- * @param $date
288
- *
289
- * @return DateTime
290
- */
291
- public function createFromFormat ( $format, $date ) {
292
- $datetime = false;
293
-
294
- if ( method_exists( 'DateTime', 'createFromFormat' ) ) {
295
- $timezone = get_option( 'timezone_string' );
296
-
297
- if ( empty( $timezone ) )
298
- $timezone = timezone_name_from_abbr( '', get_option( 'gmt_offset' ) * HOUR_IN_SECONDS, 0 );
299
-
300
- if ( !empty( $timezone ) ) {
301
- $datetimezone = new DateTimeZone( $timezone );
302
-
303
- $datetime = DateTime::createFromFormat( $format, (string) $date, $datetimezone );
304
- }
305
- }
306
-
307
- if ( false === $datetime )
308
- $datetime = new DateTime( date_i18n( 'Y-m-d', strtotime( (string) $date ) ) );
309
-
310
- return apply_filters( 'pods_form_ui_field_date_formatter', $datetime, $format, $date );
311
- }
312
-
313
- /**
314
- * Convert a date from one format to another
315
- *
316
- * @param $value
317
- * @param $new_format
318
- * @param string $original_format
319
- *
320
- * @return string
321
- */
322
- public function convert_date ( $value, $new_format, $original_format = 'Y-m-d' ) {
323
- if ( !empty( $value ) && !in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
324
- $date = $this->createFromFormat( $original_format, (string) $value );
325
-
326
- if ( false !== $date )
327
- $value = $date->format( $new_format );
328
- else
329
- $value = date_i18n( $new_format, strtotime( (string) $value ) );
330
- }
331
- else
332
- $value = date_i18n( $new_format );
333
-
334
- return $value;
335
- }
336
  }
1
  <?php
2
+ require_once( PODS_DIR . 'classes/fields/datetime.php' );
3
  /**
4
  * @package Pods\Fields
5
  */
6
+ class PodsField_Date extends PodsField_DateTime {
7
+
8
+ /**
9
+ * Field Type Group
10
+ *
11
+ * @var string
12
+ * @since 2.0
13
+ */
14
+ public static $group = 'Date / Time';
15
+
16
+ /**
17
+ * Field Type Identifier
18
+ *
19
+ * @var string
20
+ * @since 2.0
21
+ */
22
+ public static $type = 'date';
23
+
24
+ /**
25
+ * Field Type Label
26
+ *
27
+ * @var string
28
+ * @since 2.0
29
+ */
30
+ public static $label = 'Date';
31
+
32
+ /**
33
+ * Field Type Preparation
34
+ *
35
+ * @var string
36
+ * @since 2.0
37
+ */
38
+ public static $prepare = '%s';
39
+
40
+ /**
41
+ * Storage format.
42
+ *
43
+ * @var string
44
+ * @since 2.7
45
+ */
46
+ public static $storage_format = 'Y-m-d';
47
+
48
+ /**
49
+ * The default empty value (database)
50
+ *
51
+ * @var string
52
+ * @since 2.7
53
+ */
54
+ public static $empty_value = '0000-00-00';
55
+
56
+ /**
57
+ * Do things like register/enqueue scripts and stylesheets
58
+ *
59
+ * @since 2.0
60
+ */
61
+ public function __construct () {
62
+ static::$label = __( 'Date', 'pods' );
63
+ }
64
+
65
+ /**
66
+ * Add options and set defaults to
67
+ *
68
+ * @return array
69
+ *
70
+ * @since 2.0
71
+ */
72
+ public function options () {
73
+ $options = array(
74
+ static::$type . '_repeatable' => array(
75
+ 'label' => __( 'Repeatable Field', 'pods' ),
76
+ 'default' => 0,
77
+ 'type' => 'boolean',
78
+ 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
79
+ 'boolean_yes_label' => '',
80
+ 'dependency' => true,
81
+ 'developer_mode' => true
82
+ ),
83
+ static::$type . '_type' => array(
84
+ 'label' => __( 'Date Format Type', 'pods' ),
85
+ 'default' => 'format', // Backwards compatibility
86
+ 'type' => 'pick',
87
+ 'help' => __( 'WordPress Default is the format used in Settings, General under "Date Format".', 'pods' ) . '<br>'
88
+ . __( 'Predefined Format will allow you to select from a list of commonly used date formats.', 'pods' ) . '<br>'
89
+ . __( 'Custom will allow you to enter your own using PHP Date/Time Strings.', 'pods' ),
90
+ 'data' => array(
91
+ 'wp' => __( 'WordPress default', 'pods' ) . ': ' . date_i18n( get_option( 'date_format' ) ),
92
+ 'format' => __( 'Predefined format', 'pods' ),
93
+ 'custom' => __( 'Custom format', 'pods' ),
94
+ ),
95
+ 'dependency' => true
96
+ ),
97
+ static::$type . '_format_custom' => array(
98
+ 'label' => __( 'Date format for display', 'pods' ),
99
+ 'depends-on' => array( static::$type . '_type' => 'custom' ),
100
+ 'default' => '',
101
+ 'type' => 'text',
102
+ 'help' => '<a href="http://php.net/manual/function.date.php" target="_blank">' . __( 'PHP date documentation', 'pods' ) . '</a>',
103
+ ),
104
+ static::$type . '_format_custom_js' => array(
105
+ 'label' => __( 'Date format for input', 'pods' ),
106
+ 'depends-on' => array( static::$type . '_type' => 'custom' ),
107
+ 'default' => '',
108
+ 'type' => 'text',
109
+ 'help' => '<a href="https://api.jqueryui.com/datepicker/" target="_blank">' . __( 'jQuery UI datepicker documentation', 'pods' ) . '</a>'
110
+ . '<br>' . __( 'Leave empty to auto-generate from PHP format.', 'pods' ),
111
+ ),
112
+ static::$type . '_format' => array(
113
+ 'label' => __( 'Date Format', 'pods' ),
114
+ 'depends-on' => array( static::$type . '_type' => 'format' ),
115
+ 'default' => 'mdy',
116
+ 'type' => 'pick',
117
+ 'data' => array(
118
+ 'mdy' => date_i18n( 'm/d/Y' ),
119
+ 'mdy_dash' => date_i18n( 'm-d-Y' ),
120
+ 'mdy_dot' => date_i18n( 'm.d.Y' ),
121
+ 'ymd_slash' => date_i18n( 'Y/m/d' ),
122
+ 'ymd_dash' => date_i18n( 'Y-m-d' ),
123
+ 'ymd_dot' => date_i18n( 'Y.m.d' ),
124
+ 'fjy' => date_i18n( 'F j, Y' ),
125
+ 'fjsy' => date_i18n( 'F jS, Y' ),
126
+ 'y' => date_i18n( 'Y' ),
127
+ ),
128
+ 'dependency' => true,
129
+ ),
130
+ static::$type . '_allow_empty' => array(
131
+ 'label' => __( 'Allow empty value?', 'pods' ),
132
+ 'default' => 1,
133
+ 'type' => 'boolean'
134
+ ),
135
+ static::$type . '_html5' => array(
136
+ 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
137
+ 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
138
+ 'type' => 'boolean'
139
+ )
140
+ );
141
+
142
+ // Check if PHP DateTime::createFromFormat exists for additional supported formats
143
+ if ( method_exists( 'DateTime', 'createFromFormat' ) || apply_filters( 'pods_form_ui_field_datetime_custom_formatter', false ) ) {
144
+ $options[ static::$type . '_format' ][ 'data' ] = array_merge(
145
+ $options[ static::$type . '_format' ][ 'data' ],
146
+ array(
147
+ 'dmy' => date_i18n( 'd/m/Y' ),
148
+ 'dmy_dash' => date_i18n( 'd-m-Y' ),
149
+ 'dmy_dot' => date_i18n( 'd.m.Y' ),
150
+ 'dMy' => date_i18n( 'd/M/Y' ),
151
+ 'dMy_dash' => date_i18n( 'd-M-Y' )
152
+ )
153
+ );
154
+ }
155
+
156
+ $options[ static::$type . '_format' ][ 'data' ] = apply_filters( 'pods_form_ui_field_date_format_options', $options[ static::$type . '_format' ][ 'data' ] );
157
+ $options[ static::$type . '_format' ][ 'default' ] = apply_filters( 'pods_form_ui_field_date_format_default', $options[ static::$type . '_format' ][ 'default' ] );
158
+
159
+ return $options;
160
+ }
161
+
162
+ /**
163
+ * Define the current field's schema for DB table storage
164
+ *
165
+ * @param array $options
166
+ *
167
+ * @return string
168
+ * @since 2.0
169
+ */
170
+ public function schema ( $options = null ) {
171
+ $schema = 'DATE NOT NULL default "0000-00-00"';
172
+
173
+ return $schema;
174
+ }
175
+
176
+ /**
177
+ * Build date/time format string based on options
178
+ *
179
+ * @param array $options
180
+ * @param bool $js Return format for jQuery UI?
181
+ *
182
+ * @return string
183
+ * @since 2.0
184
+ */
185
+ public function format ( $options, $js = false ) {
186
+ // @see datetime field.
187
+ return $this->format_date( $options, $js );
188
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  }
classes/fields/datetime.php CHANGED
@@ -4,410 +4,879 @@
4
  */
5
  class PodsField_DateTime extends PodsField {
6
 
7
- /**
8
- * Field Type Group
9
- *
10
- * @var string
11
- * @since 2.0
12
- */
13
- public static $group = 'Date / Time';
14
-
15
- /**
16
- * Field Type Identifier
17
- *
18
- * @var string
19
- * @since 2.0
20
- */
21
- public static $type = 'datetime';
22
-
23
- /**
24
- * Field Type Label
25
- *
26
- * @var string
27
- * @since 2.0
28
- */
29
- public static $label = 'Date / Time';
30
-
31
- /**
32
- * Field Type Preparation
33
- *
34
- * @var string
35
- * @since 2.0
36
- */
37
- public static $prepare = '%s';
38
-
39
- /**
40
- * Do things like register/enqueue scripts and stylesheets
41
- *
42
- * @since 2.0
43
- */
44
- public function __construct () {
45
- self::$label = __( 'Date / Time', 'pods' );
46
- }
47
-
48
- /**
49
- * Add options and set defaults to
50
- *
51
- * @return array
52
- *
53
- * @since 2.0
54
- */
55
- public function options () {
56
- $options = array(
57
- self::$type . '_repeatable' => array(
58
- 'label' => __( 'Repeatable Field', 'pods' ),
59
- 'default' => 0,
60
- 'type' => 'boolean',
61
- 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
62
- 'boolean_yes_label' => '',
63
- 'dependency' => true,
64
- 'developer_mode' => true
65
- ),
66
- self::$type . '_format' => array(
67
- 'label' => __( 'Date Format', 'pods' ),
68
- 'default' => 'mdy',
69
- 'type' => 'pick',
70
- 'data' => array(
71
- 'mdy' => date_i18n( 'm/d/Y' ),
72
- 'mdy_dash' => date_i18n( 'm-d-Y' ),
73
- 'mdy_dot' => date_i18n( 'm.d.Y' ),
74
- 'ymd_slash' => date_i18n( 'Y/m/d' ),
75
- 'ymd_dash' => date_i18n( 'Y-m-d' ),
76
- 'ymd_dot' => date_i18n( 'Y.m.d' ),
77
- 'fjy' => date_i18n( 'F j, Y' ),
78
- 'fjsy' => date_i18n( 'F jS, Y' ),
79
- 'c' => date_i18n( 'c' )
80
- ),
81
- 'dependency' => true
82
- ),
83
- self::$type . '_time_type' => array(
84
- 'label' => __( 'Time Format Type', 'pods' ),
85
- 'excludes-on' => array( self::$type . '_format' => 'c' ),
86
- 'default' => '12',
87
- 'type' => 'pick',
88
- 'data' => array(
89
- '12' => __( '12 hour', 'pods' ),
90
- '24' => __( '24 hour', 'pods' )
91
- ),
92
- 'dependency' => true
93
- ),
94
- self::$type . '_time_format' => array(
95
- 'label' => __( 'Time Format', 'pods' ),
96
- 'depends-on' => array( self::$type . '_time_type' => '12' ),
97
- 'excludes-on' => array( self::$type . '_format' => 'c' ),
98
- 'default' => 'h_mma',
99
- 'type' => 'pick',
100
- 'data' => array(
101
- 'h_mm_A' => date_i18n( 'g:i A' ),
102
- 'h_mm_ss_A' => date_i18n( 'g:i:s A' ),
103
- 'hh_mm_A' => date_i18n( 'h:i A' ),
104
- 'hh_mm_ss_A' => date_i18n( 'h:i:s A' ),
105
- 'h_mma' => date_i18n( 'g:ia' ),
106
- 'hh_mma' => date_i18n( 'h:ia' ),
107
- 'h_mm' => date_i18n( 'g:i' ),
108
- 'h_mm_ss' => date_i18n( 'g:i:s' ),
109
- 'hh_mm' => date_i18n( 'h:i' ),
110
- 'hh_mm_ss' => date_i18n( 'h:i:s' )
111
- )
112
- ),
113
- self::$type . '_time_format_24' => array(
114
- 'label' => __( 'Time Format', 'pods' ),
115
- 'depends-on' => array( self::$type . '_time_type' => '24' ),
116
- 'default' => 'hh_mm',
117
- 'type' => 'pick',
118
- 'data' => array(
119
- 'hh_mm' => date_i18n( 'H:i' ),
120
- 'hh_mm_ss' => date_i18n( 'H:i:s' )
121
- )
122
- ),
123
- self::$type . '_allow_empty' => array(
124
- 'label' => __( 'Allow empty value?', 'pods' ),
125
- 'default' => 1,
126
- 'type' => 'boolean'
127
- ),
128
- self::$type . '_html5' => array(
129
- 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
130
- 'default' => apply_filters( 'pods_form_ui_field_html5', 0, self::$type ),
131
- 'type' => 'boolean'
132
- )
133
- );
134
-
135
- // Check if PHP DateTime::createFromFormat exists for additional supported formats
136
- if ( method_exists( 'DateTime', 'createFromFormat' ) || apply_filters( 'pods_form_ui_field_datetime_custom_formatter', false ) ) {
137
- $options[ self::$type . '_format' ][ 'data' ] = array_merge(
138
- $options[ self::$type . '_format' ][ 'data' ],
139
- array(
140
- 'dmy' => date_i18n( 'd/m/Y' ),
141
- 'dmy_dash' => date_i18n( 'd-m-Y' ),
142
- 'dmy_dot' => date_i18n( 'd.m.Y' ),
143
- 'dMy' => date_i18n( 'd/M/Y' ),
144
- 'dMy_dash' => date_i18n( 'd-M-Y' )
145
- )
146
- );
147
- }
148
-
149
- $options[ self::$type . '_format' ][ 'data' ] = apply_filters( 'pods_form_ui_field_date_format_options', $options[ self::$type . '_format' ][ 'data' ] );
150
- $options[ self::$type . '_format' ][ 'default' ] = apply_filters( 'pods_form_ui_field_date_format_default', $options[ self::$type . '_format' ][ 'default' ] );
151
-
152
- $options[ self::$type . '_time_type' ][ 'default' ] = apply_filters( 'pods_form_ui_field_time_format_type_default', $options[ self::$type . '_time_type' ][ 'default' ] );
153
- $options[ self::$type . '_time_format' ][ 'data' ] = apply_filters( 'pods_form_ui_field_time_format_options', $options[ self::$type . '_time_format' ][ 'data' ] );
154
- $options[ self::$type . '_time_format' ][ 'default' ] = apply_filters( 'pods_form_ui_field_time_format_default', $options[ self::$type . '_time_format' ][ 'default' ] );
155
- $options[ self::$type . '_time_format_24' ][ 'data' ] = apply_filters( 'pods_form_ui_field_time_format_24_options', $options[ self::$type . '_time_format_24' ][ 'data' ] );
156
- $options[ self::$type . '_time_format_24' ][ 'default' ] = apply_filters( 'pods_form_ui_field_time_format_24_default', $options[ self::$type . '_time_format_24' ][ 'default' ] );
157
-
158
- return $options;
159
- }
160
-
161
- /**
162
- * Define the current field's schema for DB table storage
163
- *
164
- * @param array $options
165
- *
166
- * @return array
167
- * @since 2.0
168
- */
169
- public function schema ( $options = null ) {
170
- $schema = 'DATETIME NOT NULL default "0000-00-00 00:00:00"';
171
-
172
- return $schema;
173
- }
174
-
175
- /**
176
- * Change the way the value of the field is displayed with Pods::get
177
- *
178
- * @param mixed $value
179
- * @param string $name
180
- * @param array $options
181
- * @param array $pod
182
- * @param int $id
183
- *
184
- * @return mixed|null|string
185
- * @since 2.0
186
- */
187
- public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
188
- $format = $this->format( $options );
189
-
190
- if ( !empty( $value ) && !in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
191
- $date = $this->createFromFormat( 'Y-m-d H:i:s', (string) $value );
192
- $date_local = $this->createFromFormat( $format, (string) $value );
193
-
194
- if ( false !== $date )
195
- $value = $date->format( $format );
196
- elseif ( false !== $date_local )
197
- $value = $date_local->format( $format );
198
- else
199
- $value = date_i18n( $format, strtotime( (string) $value ) );
200
- }
201
- elseif ( 0 == pods_var( self::$type . '_allow_empty', $options, 1 ) )
202
- $value = date_i18n( $format );
203
- else
204
- $value = '';
205
-
206
- return $value;
207
- }
208
-
209
- /**
210
- * Customize output of the form field
211
- *
212
- * @param string $name
213
- * @param mixed $value
214
- * @param array $options
215
- * @param array $pod
216
- * @param int $id
217
- *
218
- * @since 2.0
219
- */
220
- public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
221
- $options = (array) $options;
222
- $form_field_type = PodsForm::$field_type;
223
-
224
- if ( is_array( $value ) )
225
- $value = implode( ' ', $value );
226
-
227
- // Format Value
228
- $value = $this->display( $value, $name, $options, null, $pod, $id );
229
-
230
- $field_type = 'datetime';
231
-
232
- if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) {
233
- if ( pods_var( 'read_only', $options, false ) ) {
234
- $options[ 'readonly' ] = true;
235
-
236
- $field_type = 'text';
237
- }
238
- else
239
- return;
240
- }
241
- elseif ( !pods_has_permissions( $options ) && pods_var( 'read_only', $options, false ) ) {
242
- $options[ 'readonly' ] = true;
243
-
244
- $field_type = 'text';
245
- }
246
-
247
- pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
248
- }
249
-
250
- /**
251
- * Change the value or perform actions after validation but before saving to the DB
252
- *
253
- * @param mixed $value
254
- * @param int $id
255
- * @param string $name
256
- * @param array $options
257
- * @param array $fields
258
- * @param array $pod
259
- * @param object $params
260
- *
261
- * @return mixed|string
262
- * @since 2.0
263
- */
264
- public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
265
- $format = $this->format( $options );
266
-
267
- if ( !empty( $value ) && ( 0 == pods_var( self::$type . '_allow_empty', $options, 1 ) || !in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) )
268
- $value = $this->convert_date( $value, 'Y-m-d H:i:s', $format );
269
- elseif ( 1 == pods_var( self::$type . '_allow_empty', $options, 1 ) )
270
- $value = '0000-00-00 00:00:00';
271
- else
272
- $value = current_time( 'mysql' );
273
-
274
- return $value;
275
- }
276
-
277
- /**
278
- * Customize the Pods UI manage table column output
279
- *
280
- * @param int $id
281
- * @param mixed $value
282
- * @param string $name
283
- * @param array $options
284
- * @param array $fields
285
- * @param array $pod
286
- *
287
- * @return mixed|null|string
288
- * @since 2.0
289
- */
290
- public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
291
- $value = $this->display( $value, $name, $options, $pod, $id );
292
-
293
- if ( 1 == pods_var( self::$type . '_allow_empty', $options, 1 ) && ( empty( $value ) || in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) )
294
- $value = false;
295
-
296
- return $value;
297
- }
298
-
299
- /**
300
- * Build date/time format string based on options
301
- *
302
- * @param $options
303
- *
304
- * @return string
305
- * @since 2.0
306
- */
307
- public function format ( $options ) {
308
- $date_format = array(
309
- 'mdy' => 'm/d/Y',
310
- 'mdy_dash' => 'm-d-Y',
311
- 'mdy_dot' => 'm.d.Y',
312
- 'dmy' => 'd/m/Y',
313
- 'dmy_dash' => 'd-m-Y',
314
- 'dmy_dot' => 'd.m.Y',
315
- 'ymd_slash' => 'Y/m/d',
316
- 'ymd_dash' => 'Y-m-d',
317
- 'ymd_dot' => 'Y.m.d',
318
- 'dMy' => 'd/M/Y',
319
- 'dMy_dash' => 'd-M-Y',
320
- 'fjy' => 'F j, Y',
321
- 'fjsy' => 'F jS, Y',
322
- 'c' => 'c'
323
- );
324
-
325
- $time_format = array(
326
- 'h_mm_A' => 'g:i A',
327
- 'h_mm_ss_A' => 'g:i:s A',
328
- 'hh_mm_A' => 'h:i A',
329
- 'hh_mm_ss_A' => 'h:i:s A',
330
- 'h_mma' => 'g:ia',
331
- 'hh_mma' => 'h:ia',
332
- 'h_mm' => 'g:i',
333
- 'h_mm_ss' => 'g:i:s',
334
- 'hh_mm' => 'h:i',
335
- 'hh_mm_ss' => 'h:i:s'
336
- );
337
-
338
- $time_format_24 = array(
339
- 'hh_mm' => 'H:i',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  'hh_mm_ss' => 'H:i:s'
341
- );
342
-
343
- $date_format = apply_filters( 'pods_form_ui_field_date_formats', $date_format );
344
-
345
- $time_format = apply_filters( 'pods_form_ui_field_time_formats', $time_format );
346
- $time_format_24 = apply_filters( 'pods_form_ui_field_time_formats_24', $time_format_24 );
347
-
348
- $format_value = pods_var( self::$type . '_format', $options, 'ymd_dash', null, true );
349
-
350
- $format = $date_format[ $format_value ];
351
-
352
- if ( 'c' != $format_value ) {
353
- if ( 12 == pods_var( self::$type . '_time_type', $options ) )
354
- $format .= ' ' . $time_format[ pods_var( self::$type . '_time_format', $options, 'hh_mm', null, true ) ];
355
- else
356
- $format .= ' ' . $time_format_24[ pods_var( self::$type . '_time_format_24', $options, 'hh_mm', null, true ) ];
357
- }
358
-
359
- return $format;
360
- }
361
-
362
- /**
363
- * @param $format
364
- * @param $date
365
- *
366
- * @return DateTime
367
- */
368
- public function createFromFormat ( $format, $date ) {
369
- $datetime = false;
370
-
371
- if ( method_exists( 'DateTime', 'createFromFormat' ) ) {
372
- $timezone = get_option( 'timezone_string' );
373
-
374
- if ( empty( $timezone ) )
375
- $timezone = timezone_name_from_abbr( '', get_option( 'gmt_offset' ) * HOUR_IN_SECONDS, 0 );
376
-
377
- if ( !empty( $timezone ) ) {
378
- $datetimezone = new DateTimeZone( $timezone );
379
-
380
- $datetime = DateTime::createFromFormat( $format, (string) $date, $datetimezone );
381
- }
382
- }
383
-
384
- if ( false === $datetime )
385
- $datetime = new DateTime( date_i18n( 'Y-m-d H:i:s', strtotime( (string) $date ) ) );
386
-
387
- return apply_filters( 'pods_form_ui_field_datetime_formatter', $datetime, $format, $date );
388
- }
389
-
390
- /**
391
- * Convert a date from one format to another
392
- *
393
- * @param $value
394
- * @param $new_format
395
- * @param string $original_format
396
- *
397
- * @return string
398
- */
399
- public function convert_date ( $value, $new_format, $original_format = 'Y-m-d H:i:s' ) {
400
- if ( !empty( $value ) && !in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
401
- $date = $this->createFromFormat( $original_format, (string) $value );
402
-
403
- if ( false !== $date )
404
- $value = $date->format( $new_format );
405
- else
406
- $value = date_i18n( $new_format, strtotime( (string) $value ) );
407
- }
408
- else
409
- $value = date_i18n( $new_format );
410
-
411
- return $value;
412
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  }
4
  */
5
  class PodsField_DateTime extends PodsField {
6
 
7
+ /**
8
+ * Field Type Group
9
+ *
10
+ * @var string
11
+ * @since 2.0
12
+ */
13
+ public static $group = 'Date / Time';
14
+
15
+ /**
16
+ * Field Type Identifier
17
+ *
18
+ * @var string
19
+ * @since 2.0
20
+ */
21
+ public static $type = 'datetime';
22
+
23
+ /**
24
+ * Field Type Label
25
+ *
26
+ * @var string
27
+ * @since 2.0
28
+ */
29
+ public static $label = 'Date / Time';
30
+
31
+ /**
32
+ * Field Type Preparation
33
+ *
34
+ * @var string
35
+ * @since 2.0
36
+ */
37
+ public static $prepare = '%s';
38
+
39
+ /**
40
+ * Storage format.
41
+ *
42
+ * @var string
43
+ * @since 2.7
44
+ */
45
+ public static $storage_format = 'Y-m-d H:i:s';
46
+
47
+ /**
48
+ * The default empty value (database)
49
+ *
50
+ * @var string
51
+ * @since 2.7
52
+ */
53
+ public static $empty_value = '0000-00-00 00:00:00';
54
+
55
+ /**
56
+ * Do things like register/enqueue scripts and stylesheets
57
+ *
58
+ * @since 2.0
59
+ */
60
+ public function __construct () {
61
+ static::$label = __( 'Date / Time', 'pods' );
62
+ }
63
+
64
+ /**
65
+ * Add options and set defaults to
66
+ *
67
+ * @return array
68
+ *
69
+ * @since 2.0
70
+ */
71
+ public function options () {
72
+ $options = array(
73
+ static::$type . '_repeatable' => array(
74
+ 'label' => __( 'Repeatable Field', 'pods' ),
75
+ 'default' => 0,
76
+ 'type' => 'boolean',
77
+ 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
78
+ 'boolean_yes_label' => '',
79
+ 'dependency' => true,
80
+ 'developer_mode' => true
81
+ ),
82
+ static::$type . '_type' => array(
83
+ 'label' => __( 'Date Format Type', 'pods' ),
84
+ 'default' => 'format', // Backwards compatibility
85
+ 'type' => 'pick',
86
+ 'help' => __( 'WordPress Default is the format used in Settings, General under "Date Format".', 'pods' ) . '<br>'
87
+ . __( 'Predefined Format will allow you to select from a list of commonly used date formats.', 'pods' ) . '<br>'
88
+ . __( 'Custom will allow you to enter your own using PHP Date/Time Strings.', 'pods' ),
89
+ 'data' => array(
90
+ 'wp' => __( 'WordPress default', 'pods' ) . ': '. date_i18n( get_option( 'date_format' ) ),
91
+ 'format' => __( 'Predefined format', 'pods' ),
92
+ 'custom' => __( 'Custom format', 'pods' ),
93
+ ),
94
+ 'dependency' => true
95
+ ),
96
+ static::$type . '_format_custom' => array(
97
+ 'label' => __( 'Date format for display', 'pods' ),
98
+ 'depends-on' => array( static::$type . '_type' => 'custom' ),
99
+ 'default' => '',
100
+ 'type' => 'text',
101
+ 'help' => '<a href="http://php.net/manual/function.date.php" target="_blank">' . __( 'PHP date documentation', 'pods' ) . '</a>',
102
+ ),
103
+ static::$type . '_format_custom_js' => array(
104
+ 'label' => __( 'Date format for input', 'pods' ),
105
+ 'depends-on' => array( static::$type . '_type' => 'custom' ),
106
+ 'default' => '',
107
+ 'type' => 'text',
108
+ 'help' => '<a href="https://api.jqueryui.com/datepicker/" target="_blank">' . __( 'jQuery UI datepicker documentation', 'pods' ) . '</a>'
109
+ . '<br>' . __( 'Leave empty to auto-generate from PHP format.', 'pods' ),
110
+ ),
111
+ static::$type . '_format' => array(
112
+ 'label' => __( 'Date Format', 'pods' ),
113
+ 'depends-on' => array( static::$type . '_type' => 'format' ),
114
+ 'default' => 'mdy',
115
+ 'type' => 'pick',
116
+ 'data' => array(
117
+ 'mdy' => date_i18n( 'm/d/Y' ),
118
+ 'mdy_dash' => date_i18n( 'm-d-Y' ),
119
+ 'mdy_dot' => date_i18n( 'm.d.Y' ),
120
+ 'ymd_slash' => date_i18n( 'Y/m/d' ),
121
+ 'ymd_dash' => date_i18n( 'Y-m-d' ),
122
+ 'ymd_dot' => date_i18n( 'Y.m.d' ),
123
+ 'fjy' => date_i18n( 'F j, Y' ),
124
+ 'fjsy' => date_i18n( 'F jS, Y' ),
125
+ 'c' => date_i18n( 'c' ),
126
+ ),
127
+ 'dependency' => true
128
+ ),
129
+ static::$type . '_time_type' => array(
130
+ 'label' => __( 'Time Format Type', 'pods' ),
131
+ 'excludes-on' => array( static::$type . '_format' => 'c' ),
132
+ 'default' => '12', // Backwards compatibility
133
+ 'type' => 'pick',
134
+ 'help' => __( 'WordPress Default is the format used in Settings, General under "Time Format".', 'pods' ) . '<br>'
135
+ . __( '12/24 hour will allow you to select from a list of commonly used time formats.', 'pods' ) . '<br>'
136
+ . __( 'Custom will allow you to enter your own using PHP Date/Time Strings.', 'pods' ),
137
+ 'data' => array(
138
+ 'wp' => __( 'WordPress default', 'pods' ) . ': ' . date_i18n( get_option( 'time_format' ) ),
139
+ '12' => __( '12 hour', 'pods' ),
140
+ '24' => __( '24 hour', 'pods' ),
141
+ 'custom' => __( 'Custom', 'pods' ),
142
+ ),
143
+ 'dependency' => true
144
+ ),
145
+ static::$type . '_time_format_custom' => array(
146
+ 'label' => __( 'Time format', 'pods' ),
147
+ 'depends-on' => array( static::$type . '_time_type' => 'custom' ),
148
+ 'excludes-on' => array( static::$type . '_format' => 'c' ),
149
+ 'default' => '',
150
+ 'type' => 'text',
151
+ 'help' => '<a href="http://php.net/manual/function.date.php" target="_blank">' . __( 'PHP date documentation', 'pods' ) . '</a>',
152
+ ),
153
+ static::$type . '_time_format_custom_js' => array(
154
+ 'label' => __( 'Time format field input', 'pods' ),
155
+ 'depends-on' => array( static::$type . '_time_type' => 'custom' ),
156
+ 'excludes-on' => array( static::$type . '_format' => 'c' ),
157
+ 'default' => '',
158
+ 'type' => 'text',
159
+ 'help' => '<a href="http://trentrichardson.com/examples/timepicker/#tp-formatting" target="_blank">' . __( 'jQuery UI timepicker documentation', 'pods' ) . '</a>'
160
+ . '<br>' . __( 'Leave empty to auto-generate from PHP format.', 'pods' ),
161
+ ),
162
+ static::$type . '_time_format' => array(
163
+ 'label' => __( 'Time Format', 'pods' ),
164
+ 'depends-on' => array( static::$type . '_time_type' => '12' ),
165
+ 'excludes-on' => array( static::$type . '_format' => 'c' ),
166
+ 'default' => 'h_mma',
167
+ 'type' => 'pick',
168
+ 'data' => array(
169
+ 'h_mm_A' => date_i18n( 'g:i A' ),
170
+ 'h_mm_ss_A' => date_i18n( 'g:i:s A' ),
171
+ 'hh_mm_A' => date_i18n( 'h:i A' ),
172
+ 'hh_mm_ss_A' => date_i18n( 'h:i:s A' ),
173
+ 'h_mma' => date_i18n( 'g:ia' ),
174
+ 'hh_mma' => date_i18n( 'h:ia' ),
175
+ 'h_mm' => date_i18n( 'g:i' ),
176
+ 'h_mm_ss' => date_i18n( 'g:i:s' ),
177
+ 'hh_mm' => date_i18n( 'h:i' ),
178
+ 'hh_mm_ss' => date_i18n( 'h:i:s' ),
179
+ )
180
+ ),
181
+ static::$type . '_time_format_24' => array(
182
+ 'label' => __( 'Time Format', 'pods' ),
183
+ 'depends-on' => array( static::$type . '_time_type' => '24' ),
184
+ 'excludes-on' => array( static::$type . '_format' => 'c' ),
185
+ 'default' => 'hh_mm',
186
+ 'type' => 'pick',
187
+ 'data' => array(
188
+ 'hh_mm' => date_i18n( 'H:i' ),
189
+ 'hh_mm_ss' => date_i18n( 'H:i:s' )
190
+ )
191
+ ),
192
+ static::$type . '_allow_empty' => array(
193
+ 'label' => __( 'Allow empty value?', 'pods' ),
194
+ 'default' => 1,
195
+ 'type' => 'boolean'
196
+ ),
197
+ static::$type . '_html5' => array(
198
+ 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
199
+ 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
200
+ 'type' => 'boolean'
201
+ )
202
+ );
203
+
204
+ // Check if PHP DateTime::createFromFormat exists for additional supported formats
205
+ if ( method_exists( 'DateTime', 'createFromFormat' ) || apply_filters( 'pods_form_ui_field_datetime_custom_formatter', false ) ) {
206
+ $options[ static::$type . '_format' ][ 'data' ] = array_merge(
207
+ $options[ static::$type . '_format' ][ 'data' ],
208
+ array(
209
+ 'dmy' => date_i18n( 'd/m/Y' ),
210
+ 'dmy_dash' => date_i18n( 'd-m-Y' ),
211
+ 'dmy_dot' => date_i18n( 'd.m.Y' ),
212
+ 'dMy' => date_i18n( 'd/M/Y' ),
213
+ 'dMy_dash' => date_i18n( 'd-M-Y' )
214
+ )
215
+ );
216
+ }
217
+
218
+ $options[ static::$type . '_format' ][ 'data' ] = apply_filters( 'pods_form_ui_field_date_format_options', $options[ static::$type . '_format' ][ 'data' ] );
219
+ $options[ static::$type . '_format' ][ 'default' ] = apply_filters( 'pods_form_ui_field_date_format_default', $options[ static::$type . '_format' ][ 'default' ] );
220
+
221
+ $options[ static::$type . '_time_type' ][ 'default' ] = apply_filters( 'pods_form_ui_field_time_format_type_default', $options[ static::$type . '_time_type' ][ 'default' ] );
222
+ $options[ static::$type . '_time_format' ][ 'data' ] = apply_filters( 'pods_form_ui_field_time_format_options', $options[ static::$type . '_time_format' ][ 'data' ] );
223
+ $options[ static::$type . '_time_format' ][ 'default' ] = apply_filters( 'pods_form_ui_field_time_format_default', $options[ static::$type . '_time_format' ][ 'default' ] );
224
+ $options[ static::$type . '_time_format_24' ][ 'data' ] = apply_filters( 'pods_form_ui_field_time_format_24_options', $options[ static::$type . '_time_format_24' ][ 'data' ] );
225
+ $options[ static::$type . '_time_format_24' ][ 'default' ] = apply_filters( 'pods_form_ui_field_time_format_24_default', $options[ static::$type . '_time_format_24' ][ 'default' ] );
226
+
227
+ return $options;
228
+ }
229
+
230
+ /**
231
+ * Define the current field's schema for DB table storage
232
+ *
233
+ * @param array $options
234
+ *
235
+ * @return string
236
+ * @since 2.0
237
+ */
238
+ public function schema ( $options = null ) {
239
+ $schema = 'DATETIME NOT NULL default "0000-00-00 00:00:00"';
240
+
241
+ return $schema;
242
+ }
243
+
244
+ /**
245
+ * {@inheritdoc}
246
+ */
247
+ public function is_empty( $value = null ) {
248
+
249
+ $is_empty = false;
250
+
251
+ $value = trim( $value );
252
+
253
+ if ( empty( $value ) || in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
254
+ $is_empty = true;
255
+ }
256
+
257
+ return $is_empty;
258
+
259
+ }
260
+
261
+ /**
262
+ * Change the way the value of the field is displayed with Pods::get
263
+ *
264
+ * @param mixed $value
265
+ * @param string $name
266
+ * @param array $options
267
+ * @param array $pod
268
+ * @param int $id
269
+ *
270
+ * @return mixed|null|string
271
+ * @since 2.0
272
+ */
273
+ public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
274
+
275
+ $value = $this->format_value_display( $value, $options, false );
276
+
277
+ return $value;
278
+ }
279
+
280
+ /**
281
+ * Customize output of the form field
282
+ *
283
+ * @param string $name
284
+ * @param mixed $value
285
+ * @param array $options
286
+ * @param array $pod
287
+ * @param int $id
288
+ *
289
+ * @since 2.0
290
+ */
291
+ public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
292
+ $options = (array) $options;
293
+ $form_field_type = PodsForm::$field_type;
294
+
295
+ if ( is_array( $value ) )
296
+ $value = implode( ' ', $value );
297
+
298
+ // Format Value
299
+ $value = $this->format_value_display( $value, $options, true );
300
+
301
+ $field_type = static::$type;
302
+
303
+ if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( static::$type, $options[ 'name' ], $options, null, $pod, $id ) ) {
304
+ if ( pods_v( 'read_only', $options, false ) ) {
305
+ $options[ 'readonly' ] = true;
306
+
307
+ $field_type = 'text';
308
+ }
309
+ else
310
+ return;
311
+ }
312
+ elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) {
313
+ $options[ 'readonly' ] = true;
314
+
315
+ $field_type = 'text';
316
+ }
317
+
318
+ pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
319
+ }
320
+
321
+ /**
322
+ * {@inheritdoc}
323
+ */
324
+ public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
325
+
326
+ if ( ! empty( $value ) && ( 0 == pods_v( static::$type . '_allow_empty', $options, 1 ) || ! in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) ) {
327
+ $js = true;
328
+
329
+ if ( 'custom' !== pods_v( static::$type . '_type', $options, 'format' ) ) {
330
+ $js = false;
331
+ }
332
+
333
+ $format = $this->format( $options, $js );
334
+
335
+ if ( $js ) {
336
+ $format = $this->convert_format( $format, array( 'source' => 'jquery_ui' ) );
337
+ }
338
+
339
+ $check = $this->convert_date( $value, static::$storage_format, $format, true );
340
+
341
+ if ( false === $check ) {
342
+ $label = pods_var( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) );
343
+
344
+ return sprintf( esc_html__( '%1$s was not provided in a recognizable format: "%2$s"', 'pods' ), $label, $value );
345
+ }
346
+ }
347
+
348
+ return true;
349
+
350
+ }
351
+
352
+ /**
353
+ * Change the value or perform actions after validation but before saving to the DB
354
+ *
355
+ * @param mixed $value
356
+ * @param int $id
357
+ * @param string $name
358
+ * @param array $options
359
+ * @param array $fields
360
+ * @param array $pod
361
+ * @param object $params
362
+ *
363
+ * @return mixed|string
364
+ * @since 2.0
365
+ */
366
+ public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
367
+ $js = true;
368
+ if ( 'custom' !== pods_v( static::$type . '_type', $options, 'format' ) ) {
369
+ $js = false;
370
+ }
371
+ $format = $this->format( $options, $js );
372
+ if ( $js ) {
373
+ $format = $this->convert_format( $format, array( 'source' => 'jquery_ui' ) );
374
+ }
375
+
376
+ if ( ! empty( $value ) && ( 0 == pods_v( static::$type . '_allow_empty', $options, 1 ) || ! in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) )
377
+ $value = $this->convert_date( $value, static::$storage_format, $format );
378
+ elseif ( 1 == pods_v( static::$type . '_allow_empty', $options, 1 ) )
379
+ $value = static::$empty_value;
380
+ else
381
+ $value = date_i18n( static::$storage_format );
382
+
383
+ return $value;
384
+ }
385
+
386
+ /**
387
+ * Customize the Pods UI manage table column output
388
+ *
389
+ * @param int $id
390
+ * @param mixed $value
391
+ * @param string $name
392
+ * @param array $options
393
+ * @param array $fields
394
+ * @param array $pod
395
+ *
396
+ * @return mixed|null|string
397
+ * @since 2.0
398
+ */
399
+ public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
400
+ $value = $this->display( $value, $name, $options, $pod, $id );
401
+
402
+ if ( 1 == pods_v( static::$type . '_allow_empty', $options, 1 ) && ( empty( $value ) || in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) )
403
+ $value = false;
404
+
405
+ return $value;
406
+ }
407
+
408
+ /**
409
+ * Convert value to the correct format for display.
410
+ *
411
+ * @param string $value
412
+ * @param array $options
413
+ * @param bool $js Return formatted from jQuery UI format? (only for custom formats).
414
+ * @return string
415
+ * @since 2.7
416
+ */
417
+ public function format_value_display( $value, $options, $js = false ) {
418
+ if ( 'custom' !== pods_v( static::$type . '_type', $options, 'format' ) ) {
419
+ $js = false;
420
+ }
421
+ $format = $this->format( $options, $js );
422
+ if ( $js ) {
423
+ $format = $this->convert_format( $format, array( 'source' => 'jquery_ui' ) );
424
+ }
425
+
426
+ if ( ! empty( $value ) && ! in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
427
+ // Try default storage format.
428
+ $date = $this->createFromFormat( static::$storage_format, (string) $value );
429
+ // Try field format.
430
+ $date_local = $this->createFromFormat( $format, (string) $value );
431
+
432
+ if ( $date instanceof DateTime )
433
+ $value = $date->format( $format );
434
+ elseif ( $date_local instanceof DateTime )
435
+ $value = $date_local->format( $format );
436
+ else
437
+ $value = date_i18n( $format, strtotime( (string) $value ) );
438
+ }
439
+ elseif ( 0 == pods_v( static::$type . '_allow_empty', $options, 1 ) )
440
+ $value = date_i18n( $format );
441
+ else
442
+ $value = '';
443
+
444
+ return $value;
445
+ }
446
+
447
+ /**
448
+ * Build date/time format string based on options
449
+ *
450
+ * @param array $options
451
+ * @param bool $js Return format for jQuery UI?
452
+ *
453
+ * @return string
454
+ * @since 2.0
455
+ */
456
+ public function format ( $options, $js = false ) {
457
+
458
+ $format = $this->format_date( $options, $js );
459
+
460
+ $type = pods_v( static::$type . '_type', $options, 'format' );
461
+
462
+ if ( 'format' !== $type || 'c' !== pods_v( static::$type . '_format', $options, '' ) ) {
463
+ $format .= ' ' . $this->format_time( $options, $js );
464
+ }
465
+
466
+ return $format;
467
+ }
468
+
469
+ /**
470
+ * Build date format string based on options
471
+ *
472
+ * @since 2.7
473
+ *
474
+ * @param array $options
475
+ * @param bool $js Return format for jQuery UI?
476
+ * @return string
477
+ */
478
+ public function format_date( $options, $js = false ) {
479
+
480
+ switch ( (string) pods_v( static::$type . '_type', $options, 'format', true ) ) {
481
+ case 'wp':
482
+ $format = get_option( 'date_format' );
483
+ if ( $js ) {
484
+ $format = $this->convert_format( $format, array( 'source' => 'php' ) );
485
+ }
486
+ break;
487
+ case 'custom':
488
+ if ( ! $js ) {
489
+ $format = pods_v( static::$type . '_format_custom', $options, '' );
490
+ } else {
491
+ $format = pods_v( static::$type . '_format_custom_js', $options, '' );
492
+ if ( empty( $format ) ) {
493
+ $format = pods_v( static::$type . '_format_custom', $options, '' );
494
+ $format = $this->convert_format( $format, array( 'source' => 'php' ) );
495
+ }
496
+ }
497
+ break;
498
+ default:
499
+ $date_format = $this->get_date_formats( $js );
500
+ $format = $date_format[ pods_v( static::$type . '_format', $options, 'ymd_dash', true ) ];
501
+ break;
502
+ }
503
+
504
+ return $format;
505
+ }
506
+
507
+ /**
508
+ * Build time format string based on options
509
+ *
510
+ * @since 2.7
511
+ *
512
+ * @param array $options
513
+ * @param bool $js Return format for jQuery UI?
514
+ * @return string
515
+ */
516
+ public function format_time( $options, $js = false ) {
517
+
518
+ switch ( (string) pods_v( static::$type . '_time_type', $options, '12', true ) ) {
519
+ case '12':
520
+ $time_format = $this->get_time_formats( $js );
521
+ $format = $time_format[ pods_v( static::$type . '_time_format', $options, 'hh_mm', true ) ];
522
+ break;
523
+ case '24':
524
+ $time_format_24 = $this->get_time_formats_24( $js );
525
+ $format = $time_format_24[ pods_v( static::$type . '_time_format_24', $options, 'hh_mm', true ) ];
526
+ break;
527
+ case 'custom':
528
+ if ( ! $js ) {
529
+ $format = pods_v( static::$type . '_time_format_custom', $options, '' );
530
+ } else {
531
+ $format = pods_v( static::$type . '_time_format_custom_js', $options, '' );
532
+ if ( empty( $format ) ) {
533
+ $format = pods_v( static::$type . '_time_format_custom', $options, '' );
534
+ $format = $this->convert_format( $format, array( 'source' => 'php' ) );
535
+ }
536
+ }
537
+ break;
538
+ default:
539
+ $format = get_option( 'time_format' );
540
+ if ( $js ) {
541
+ $format = $this->convert_format( $format, array( 'source' => 'php' ) );
542
+ }
543
+ break;
544
+ }
545
+
546
+ return $format;
547
+ }
548
+
549
+ /**
550
+ * Get the date formats.
551
+ *
552
+ * @since 2.7
553
+ *
554
+ * @param bool $js Return formats for jQuery UI?
555
+ * @return array
556
+ */
557
+ public function get_date_formats( $js = false ) {
558
+ $date_format = array(
559
+ 'mdy' => 'm/d/Y',
560
+ 'mdy_dash' => 'm-d-Y',
561
+ 'mdy_dot' => 'm.d.Y',
562
+ 'dmy' => 'd/m/Y',
563
+ 'dmy_dash' => 'd-m-Y',
564
+ 'dmy_dot' => 'd.m.Y',
565
+ 'ymd_slash' => 'Y/m/d',
566
+ 'ymd_dash' => 'Y-m-d',
567
+ 'ymd_dot' => 'Y.m.d',
568
+ 'dMy' => 'd/M/Y',
569
+ 'dMy_dash' => 'd-M-Y',
570
+ 'fjy' => 'F j, Y',
571
+ 'fjsy' => 'F jS, Y',
572
+ 'y' => 'Y',
573
+ );
574
+ $filter = 'pods_form_ui_field_date_formats';
575
+ if ( $js ) {
576
+ // @todo Method parameters? (Not supported by array_map)
577
+ $date_format = array_map( array( $this, 'convert_format' ), $date_format );
578
+ $filter = 'pods_form_ui_field_date_js_formats';
579
+ }
580
+ return apply_filters( $filter, $date_format );
581
+ }
582
+
583
+ /**
584
+ * Get the time formats.
585
+ *
586
+ * @since 2.7
587
+ *
588
+ * @param bool $js Return formats for jQuery UI?
589
+ * @return array
590
+ */
591
+ public function get_time_formats( $js = false ) {
592
+ $time_format = array(
593
+ 'h_mm_A' => 'g:i A',
594
+ 'h_mm_ss_A' => 'g:i:s A',
595
+ 'hh_mm_A' => 'h:i A',
596
+ 'hh_mm_ss_A' => 'h:i:s A',
597
+ 'h_mma' => 'g:ia',
598
+ 'hh_mma' => 'h:ia',
599
+ 'h_mm' => 'g:i',
600
+ 'h_mm_ss' => 'g:i:s',
601
+ 'hh_mm' => 'h:i',
602
+ 'hh_mm_ss' => 'h:i:s',
603
+ );
604
+ $filter = 'pods_form_ui_field_time_formats';
605
+ if ( $js ) {
606
+ // @todo Method parameters? (Not supported by array_map)
607
+ $time_format = array_map( array( $this, 'convert_format' ), $time_format );
608
+ $filter = 'pods_form_ui_field_time_js_formats';
609
+ }
610
+ return apply_filters( $filter, $time_format );
611
+ }
612
+
613
+ /**
614
+ * Get the time formats.
615
+ *
616
+ * @since 2.7
617
+ *
618
+ * @param bool $js Return formats for jQuery UI?
619
+ * @return array
620
+ */
621
+ public function get_time_formats_24( $js = false ) {
622
+ $time_format_24 = array(
623
+ 'hh_mm' => 'H:i',
624
  'hh_mm_ss' => 'H:i:s'
625
+ );
626
+ $filter = 'pods_form_ui_field_time_formats_24';
627
+ if ( $js ) {
628
+ // @todo Method parameters? (Not supported by array_map)
629
+ $time_format_24 = array_map( array( $this, 'convert_format' ), $time_format_24 );
630
+ $filter = 'pods_form_ui_field_time_js_formats_24';
631
+ }
632
+ return apply_filters( $filter, $time_format_24 );
633
+ }
634
+
635
+ /**
636
+ * @param string $format
637
+ * @param string $date Defaults to time() if empty.
638
+ * @param boolean $return_timestamp Whether to return the strtotime() or createFromFormat result or not
639
+ *
640
+ * @return DateTime|null|int|false
641
+ */
642
+ public function createFromFormat ( $format, $date, $return_timestamp = false ) {
643
+ $datetime = null;
644
+
645
+ if ( method_exists( 'DateTime', 'createFromFormat' ) ) {
646
+ $timezone = get_option( 'timezone_string' );
647
+
648
+ if ( empty( $timezone ) )
649
+ $timezone = timezone_name_from_abbr( '', get_option( 'gmt_offset' ) * HOUR_IN_SECONDS, 0 );
650
+
651
+ if ( !empty( $timezone ) ) {
652
+ $datetimezone = new DateTimeZone( $timezone );
653
+
654
+ $datetime = DateTime::createFromFormat( $format, (string) $date, $datetimezone );
655
+
656
+ if ( false === $datetime ) {
657
+ $datetime = DateTime::createFromFormat( static::$storage_format, (string) $date, $datetimezone );
658
+ }
659
+
660
+ if ( false !== $datetime && $return_timestamp ) {
661
+ return $datetime;
662
+ }
663
+ }
664
+ }
665
+
666
+ if ( in_array( $datetime, array( null, false ), true ) ) {
667
+ if ( empty( $date ) ) {
668
+ $timestamp = time();
669
+ } else {
670
+ $timestamp = strtotime( (string) $date );
671
+
672
+ if ( $return_timestamp ) {
673
+ return $timestamp;
674
+ }
675
+ }
676
+ if ( $timestamp ) {
677
+ $datetime = new DateTime( date_i18n( static::$storage_format, $timestamp ) );
678
+ }
679
+ }
680
+
681
+ return apply_filters( 'pods_form_ui_field_datetime_formatter', $datetime, $format, $date );
682
+ }
683
+
684
+ /**
685
+ * Convert a date from one format to another
686
+ *
687
+ * @param $value
688
+ * @param $new_format
689
+ * @param string $original_format
690
+ * @param boolean $return_timestamp Whether to return the strtotime() or createFromFormat result or not
691
+ *
692
+ * @return string|int|boolean|DateTime
693
+ */
694
+ public function convert_date ( $value, $new_format, $original_format = '', $return_timestamp = false ) {
695
+ if ( empty( $original_format ) ) {
696
+ $original_format = static::$storage_format;
697
+ }
698
+
699
+ $date = '';
700
+
701
+ if ( ! empty( $value ) && ! in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
702
+ $date = $this->createFromFormat( $original_format, (string) $value, $return_timestamp );
703
+
704
+ if ( $date instanceof DateTime ) {
705
+ $value = $date->format( $new_format );
706
+ } elseif ( false !== $date ) {
707
+ $date = strtotime( (string) $value );
708
+
709
+ $value = date_i18n( $new_format, $date );
710
+ }
711
+ } else {
712
+ $value = date_i18n( $new_format );
713
+ }
714
+
715
+ // Return timestamp conversion result instead
716
+ if ( $return_timestamp ) {
717
+ return $date;
718
+ }
719
+
720
+ return $value;
721
+ }
722
+
723
+ /**
724
+ * Matches each symbol of PHP date format standard with jQuery equivalent codeword.
725
+ *
726
+ * @link http://stackoverflow.com/questions/16702398/convert-a-php-date-format-to-a-jqueryui-datepicker-date-format
727
+ * @link https://api.jqueryui.com/datepicker/
728
+ * @link http://trentrichardson.com/examples/timepicker/
729
+ *
730
+ * @since 2.7
731
+ *
732
+ * @param string $source_format
733
+ * @param array $args
734
+ * @return string
735
+ */
736
+ public function convert_format( $source_format, $args = array() ) {
737
+ // @todo Improve source/target logic.
738
+ $args = array_merge( array(
739
+ 'source' => 'php', // 'jquery_ui' for reverse.
740
+ ), $args );
741
+
742
+ // Keep keys and values sorted by string length.
743
+ $symbols = array(
744
+ // Day
745
+ 'd' => 'dd',
746
+ 'l' => 'DD',
747
+ 'D' => 'D',
748
+ 'j' => 'd',
749
+ 'N' => '',
750
+ 'S' => '',
751
+ 'w' => '',
752
+ 'z' => 'o',
753
+ // Week
754
+ 'W' => '',
755
+ // Month
756
+ 'F' => 'MM',
757
+ 'm' => 'mm',
758
+ 'M' => 'M',
759
+ 'n' => 'm',
760
+ 't' => '',
761
+ // Year
762
+ 'L' => '',
763
+ 'o' => '',
764
+ 'Y' => 'yy',
765
+ 'y' => 'y',
766
+ // AM/PM
767
+ 'a' => 'tt',
768
+ 'A' => 'TT',
769
+ // Swatch internet time (not supported)
770
+ 'B' => '',
771
+ // Hour
772
+ 'h' => 'hh',
773
+ 'H' => 'HH',
774
+ 'g' => 'h',
775
+ 'G' => 'H',
776
+ // Minute
777
+ 'i' => 'mm',
778
+ // Second
779
+ 's' => 'ss',
780
+ // Microsecond
781
+ 'u' => 'c',
782
+ );
783
+ if ( version_compare( PHP_VERSION, '7.0.0' ) >= 0 ) {
784
+ // Millisecond
785
+ $symbols['v'] = 'l';
786
+ }
787
+ if ( 'jquery_ui' === $args[ 'source' ] ) {
788
+ // Remove empty values.
789
+ $symbols = array_filter( $symbols );
790
+ $symbols = array_flip( $symbols );
791
+ }
792
+ $new_format = "";
793
+ $escaping = false;
794
+ for( $i = 0; $i < strlen( $source_format ); $i++ ) {
795
+ $char = $source_format[ $i ];
796
+ // PHP date format escaping character
797
+ // @todo Do we want to support non-format characters?
798
+ if( $char === '\\' ) {
799
+ $i++;
800
+ if( $escaping ) {
801
+ $new_format .= $source_format[ $i ];
802
+ }
803
+ else {
804
+ $new_format .= '\'' . $source_format[ $i ];
805
+ }
806
+ $escaping = true;
807
+ } else {
808
+ if( $escaping ) {
809
+ $new_format .= "'"; $escaping = false;
810
+ }
811
+ // Support 2 characters.
812
+ if ( isset( $source_format[ $i + 1 ] ) && isset( $symbols[ $char . $source_format[ $i + 1 ] ] ) ) {
813
+ $new_format .= $symbols[ $char . $source_format[ $i + 1 ] ];
814
+ $i++;
815
+ }
816
+ elseif ( isset ( $symbols[ $char ] ) ) {
817
+ $new_format .= $symbols[ $char ];
818
+ }
819
+ else {
820
+ $new_format .= $char;
821
+ }
822
+ }
823
+ }
824
+ return $new_format;
825
+ }
826
+
827
+ /**
828
+ * Enqueue the i18n files for jquery date/timepicker
829
+ *
830
+ * @since 2.7
831
+ */
832
+ public function enqueue_jquery_ui_i18n() {
833
+ static $done = array();
834
+
835
+ $types = array();
836
+ switch ( static::$type ) {
837
+ case 'time':
838
+ $types[] = 'time';
839
+ break;
840
+ case 'date':
841
+ $types[] = 'date';
842
+ break;
843
+ case 'datetime':
844
+ $types[] = 'time';
845
+ $types[] = 'date';
846
+ break;
847
+ }
848
+
849
+ if ( in_array( 'date', $types, true ) && ! in_array( 'date', $done, true ) ) {
850
+
851
+ if ( function_exists( 'wp_localize_jquery_ui_datepicker' ) ) {
852
+ wp_localize_jquery_ui_datepicker();
853
+ }
854
+
855
+ $done[] = 'date';
856
+ }
857
+
858
+ if ( in_array( 'time', $types, true ) && ! in_array( 'time', $done, true ) ) {
859
+
860
+ $locale = str_replace( '_', '-', get_locale() );
861
+
862
+ // Local files.
863
+ if ( ! file_exists( PODS_DIR . 'ui/js/timepicker/i18n/jquery-ui-timepicker-' . $locale . '.js' ) ) {
864
+ // Fallback to the base language (non-region specific).
865
+ $locale = substr( $locale, 0, strpos( $locale, '-' ) );
866
+ }
867
+
868
+ if ( ! wp_script_is( 'jquery-ui-timepicker-i18n-' . $locale, 'registered' ) &&
869
+ file_exists( PODS_DIR . 'ui/js/timepicker/i18n/jquery-ui-timepicker-' . $locale . '.js' )
870
+ ) {
871
+ wp_enqueue_script(
872
+ 'jquery-ui-timepicker-i18n-' . $locale,
873
+ PODS_URL . 'ui/js/timepicker/i18n/jquery-ui-timepicker-' . $locale . '.js',
874
+ array( 'jquery-ui-timepicker' ),
875
+ '1.6.3'
876
+ );
877
+ }
878
+
879
+ $done[] = 'time';
880
+ }
881
+ }
882
  }
classes/fields/email.php CHANGED
@@ -73,7 +73,16 @@ class PodsField_Email extends PodsField {
73
  'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
74
  'default' => apply_filters( 'pods_form_ui_field_html5', 0, self::$type ),
75
  'type' => 'boolean'
76
- )/*,
 
 
 
 
 
 
 
 
 
77
  self::$type . '_size' => array(
78
  'label' => __( 'Field Size', 'pods' ),
79
  'default' => 'medium',
73
  'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
74
  'default' => apply_filters( 'pods_form_ui_field_html5', 0, self::$type ),
75
  'type' => 'boolean'
76
+ ),
77
+ self::$type . '_placeholder' => array(
78
+ 'label' => __( 'HTML Placeholder', 'pods' ),
79
+ 'default' => '',
80
+ 'type' => 'text',
81
+ 'help' => array(
82
+ __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
83
+ 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
84
+ ),
85
+ ),/*,
86
  self::$type . '_size' => array(
87
  'label' => __( 'Field Size', 'pods' ),
88
  'default' => 'medium',
classes/fields/file.php CHANGED
@@ -1,552 +1,754 @@
1
  <?php
 
2
  /**
3
  * @package Pods\Fields
4
  */
5
  class PodsField_File extends PodsField {
6
 
7
- /**
8
- * Field Type Group
9
- *
10
- * @var string
11
- * @since 2.0
12
- */
13
- public static $group = 'Relationships / Media';
14
-
15
- /**
16
- * Field Type Identifier
17
- *
18
- * @var string
19
- * @since 2.0
20
- */
21
- public static $type = 'file';
22
-
23
- /**
24
- * Field Type Label
25
- *
26
- * @var string
27
- * @since 2.0
28
- */
29
- public static $label = 'File / Image / Video';
30
-
31
- /**
32
- * API caching for fields that need it during validate/save
33
- *
34
- * @var \PodsAPI
35
- * @since 2.3
36
- */
37
- protected static $api = false;
38
-
39
- /**
40
- * Do things like register/enqueue scripts and stylesheets
41
- *
42
- * @since 2.0
43
- */
44
- public function __construct () {
45
- self::$label = __( 'File / Image / Video', 'pods' );
46
- }
47
-
48
- /**
49
- * Add admin_init actions
50
- *
51
- * @since 2.3
52
- */
53
- public function admin_init() {
54
- // AJAX for Uploads
55
- add_action( 'wp_ajax_pods_upload', array( $this, 'admin_ajax_upload' ) );
56
- add_action( 'wp_ajax_nopriv_pods_upload', array( $this, 'admin_ajax_upload' ) );
57
- }
58
-
59
- /**
60
- * Add options and set defaults to
61
- *
62
- * @param array $options
63
- *
64
- * @since 2.0
65
- */
66
- public function options () {
67
- $sizes = get_intermediate_image_sizes();
68
-
69
- $image_sizes = array();
70
-
71
- foreach ( $sizes as $size ) {
72
- $image_sizes[ $size ] = ucwords( str_replace( '-', ' ', $size ) );
73
- }
74
-
75
- $options = array(
76
- self::$type . '_format_type' => array(
77
- 'label' => __( 'Upload Limit', 'pods' ),
78
- 'default' => 'single',
79
- 'type' => 'pick',
80
- 'data' => array(
81
- 'single' => __( 'Single File', 'pods' ),
82
- 'multi' => __( 'Multiple Files', 'pods' )
83
- ),
84
- 'dependency' => true
85
- ),
86
- self::$type . '_uploader' => array(
87
- 'label' => __( 'File Uploader', 'pods' ),
88
- 'default' => 'attachment',
89
- 'type' => 'pick',
90
- 'data' => apply_filters(
91
- 'pods_form_ui_field_file_uploader_options',
92
- array(
93
- 'attachment' => __( 'Attachments (WP Media Library)', 'pods' ),
94
- 'plupload' => __( 'Plupload', 'pods' )
95
- )
96
- ),
97
- 'dependency' => true
98
- ),
99
- self::$type . '_attachment_tab' => array(
100
- 'label' => __( 'Attachments Default Tab', 'pods' ),
101
- 'depends-on' => array( self::$type . '_uploader' => 'attachment' ),
102
- 'default' => 'upload',
103
- 'type' => 'pick',
104
- 'data' => array(
105
- // keys MUST match WP's router names
106
- 'upload' => __( 'Upload File', 'pods' ),
107
- 'browse' => __( 'Media Library', 'pods' )
108
- )
109
- ),
110
- self::$type . '_edit_title' => array(
111
- 'label' => __( 'Editable Title', 'pods' ),
112
- 'default' => 1,
113
- 'type' => 'boolean'
114
- ),
115
- self::$type . '_linked' => array(
116
- 'label' => __( 'Link to File in editor', 'pods' ),
117
- 'default' => 0,
118
- 'type' => 'boolean'
119
- ),
120
- self::$type . '_limit' => array(
121
- 'label' => __( 'Max Number of Files', 'pods' ),
122
- 'depends-on' => array( self::$type . '_format_type' => 'multi' ),
123
- 'default' => 0,
124
- 'type' => 'number'
125
- ),
126
- self::$type . '_restrict_filesize' => array(
127
- 'label' => __( 'Restrict File Size', 'pods' ),
128
- 'depends-on' => array( self::$type . '_uploader' => 'plupload' ),
129
- 'default' => '10MB',
130
- 'type' => 'text'
131
- ),
132
- self::$type . '_type' => array(
133
- 'label' => __( 'Restrict File Types', 'pods' ),
134
- 'default' => apply_filters( 'pods_form_ui_field_file_type_default', 'images' ),
135
- 'type' => 'pick',
136
- 'data' => apply_filters(
137
- 'pods_form_ui_field_file_type_options',
138
- array(
139
- 'images' => __( 'Images (jpg, jpeg, png, gif)', 'pods' ),
140
- 'video' => __( 'Video (mpg, mov, flv, mp4, etc..)', 'pods' ),
141
- 'audio' => __( 'Audio (mp3, m4a, wav, wma, etc..)', 'pods' ),
142
- 'text' => __( 'Text (txt, csv, tsv, rtx, etc..)', 'pods' ),
143
- 'any' => __( 'Any Type (no restriction)', 'pods' ),
144
- 'other' => __( 'Other (customize allowed extensions)', 'pods' )
145
- )
146
- ),
147
- 'dependency' => true
148
- ),
149
- self::$type . '_allowed_extensions' => array(
150
- 'label' => __( 'Allowed File Extensions', 'pods' ),
151
- 'description' => __( 'Separate file extensions with a comma (ex. jpg,png,mp4,mov)', 'pods' ),
152
- 'depends-on' => array( self::$type . '_type' => 'other' ),
153
- 'default' => apply_filters( 'pods_form_ui_field_file_extensions_default', '' ),
154
- 'type' => 'text'
155
- ),/*
156
- self::$type . '_field_template' => array(
157
- 'label' => __( 'Field template', 'pods' ),
158
- 'default' => apply_filters( 'pods_form_ui_field_file_template_default', 'rows' ),
159
- 'depends-on' => array( self::$type . '_type' => 'images' ),
160
- 'type' => 'pick',
161
- 'data' => apply_filters(
162
- 'pods_form_ui_field_file_type_templates',
163
- array(
164
- 'rows' => __( 'Rows', 'pods' ),
165
- 'tiles' => __( 'Tiles', 'pods' ),
166
- )
167
- ),
168
- 'dependency' => true
169
- ),
170
- self::$type . '_image_size' => array(
171
  'label' => __( 'Excluded Image Sizes', 'pods' ),
172
  'description' => __( 'Image sizes not to generate when processing the image', 'pods' ),
173
- 'depends-on' => array( self::$type . '_type' => 'images' ),
174
  'default' => 'images',
175
  'type' => 'pick',
176
  'pick_format_type' => 'multi',
177
  'pick_format_multi' => 'checkbox',
178
  'data' => apply_filters(
179
- 'pods_form_ui_field_file_image_size_options',
180
  $image_sizes
181
  )
182
- ),*/
183
- self::$type . '_add_button' => array(
184
- 'label' => __( 'Add Button Text', 'pods' ),
185
- 'default' => __( 'Add File', 'pods' ),
186
- 'type' => 'text'
187
- ),
188
- self::$type . '_modal_title' => array(
189
- 'label' => __( 'Modal Title', 'pods' ),
190
- 'depends-on' => array( self::$type . '_uploader' => 'attachment' ),
191
- 'default' => __( 'Attach a file', 'pods' ),
192
- 'type' => 'text'
193
- ),
194
- self::$type . '_modal_add_button' => array(
195
- 'label' => __( 'Modal Add Button Text', 'pods' ),
196
- 'depends-on' => array( self::$type . '_uploader' => 'attachment' ),
197
- 'default' => __( 'Add File', 'pods' ),
198
- 'type' => 'text'
199
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
 
201
- /* WP GALLERY OUTPUT */
202
- self::$type . '_wp_gallery_output' => array(
203
- 'label' => __( 'Output as a WP Gallery', 'pods' ),
204
- 'help' => sprintf(
205
- __( '<a href="%s" target="_blank">Click here for more info</a>', 'pods' ),
206
- 'https://codex.wordpress.org/The_WordPress_Gallery'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  ),
208
- 'depends-on' => array( self::$type . '_type' => 'images' ),
209
- 'dependency' => true,
210
- 'type' => 'boolean'
211
- ),
212
- self::$type . '_wp_gallery_link' => array(
213
- 'label' => __( 'Gallery image links', 'pods' ),
214
- 'depends-on' => array( self::$type . '_wp_gallery_output' => 1 ),
215
- 'type' => 'pick',
216
- 'data' => array(
217
- 'post' => __( 'Attachment Page', 'pods' ),
218
- 'file' => __( 'Media File', 'pods' ),
219
- 'none' => __( 'None', 'pods' )
220
- )
221
- ),
222
- self::$type . '_wp_gallery_columns' => array(
223
- 'label' => __( 'Gallery image columns', 'pods' ),
224
- 'depends-on' => array( self::$type . '_wp_gallery_output' => 1 ),
225
- 'type' => 'pick',
226
- 'data' => array(
227
- '1' => 1,
228
- '2' => 2,
229
- '3' => 3,
230
- '4' => 4,
231
- '5' => 5,
232
- '6' => 6,
233
- '7' => 7,
234
- '8' => 8,
235
- '9' => 9,
236
- )
237
- ),
238
- self::$type . '_wp_gallery_random_sort' => array(
239
- 'label' => __( 'Gallery randomized order', 'pods' ),
240
- 'depends-on' => array( self::$type . '_wp_gallery_output' => 1 ),
241
- 'type' => 'boolean'
242
- ),
243
- self::$type . '_wp_gallery_size' => array(
244
- 'label' => __( 'Gallery image size', 'pods' ),
245
- 'depends-on' => array( self::$type . '_wp_gallery_output' => 1 ),
246
- 'type' => 'pick',
247
- 'data' => $this->data_image_sizes(),
248
- )
249
- );
250
-
251
- if ( !pods_version_check( 'wp', '3.5' ) ) {
252
- unset( $options[ self::$type . '_linked' ] );
253
- unset( $options[ self::$type . '_modal_title' ] );
254
- unset( $options[ self::$type . '_modal_add_button' ] );
255
-
256
- $options[ self::$type . '_attachment_tab' ][ 'default' ] = 'type';
257
- $options[ self::$type . '_attachment_tab' ][ 'data' ] = array(
258
- 'type' => __( 'Upload File', 'pods' ),
259
- 'library' => __( 'Media Library', 'pods' )
260
- );
261
- }
262
-
263
- return $options;
264
- }
265
-
266
- /**
267
- * Define the current field's schema for DB table storage
268
- *
269
- * @param array $options
270
- *
271
- * @return array
272
- * @since 2.0
273
- */
274
- public function schema ( $options = null ) {
275
- $schema = false;
276
-
277
- return $schema;
278
- }
279
-
280
- /**
281
- * Change the way the value of the field is displayed with Pods::get
282
- *
283
- * @param mixed $value
284
- * @param string $name
285
- * @param array $options
286
- * @param array $pod
287
- * @param int $id
288
- *
289
- * @return mixed|null
290
- * @since 2.0
291
- */
292
- public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
293
- if ( ! empty( $options[ self::$type . '_wp_gallery_output' ] ) ) {
294
- return $this->do_wp_gallery( $value, $options );
295
- }
296
-
297
- if ( is_array( $value ) && !empty( $value ) ) {
298
- if ( isset( $value[ 'ID' ] ) )
299
- $value = wp_get_attachment_url( $value[ 'ID' ] );
300
- else {
301
- $attachments = $value;
302
- $value = array();
303
-
304
- foreach ( $attachments as $v ) {
305
- if ( !is_array( $v ) )
306
- $value[] = $v;
307
- elseif ( isset( $v[ 'ID' ] ) )
308
- $value[] = wp_get_attachment_url( $v[ 'ID' ] );
309
- }
310
-
311
- $value = implode( ' ', $value );
312
- }
313
- }
314
-
315
- return $value;
316
- }
317
-
318
- /**
319
- * Customize output of the form field
320
- *
321
- * @param string $name
322
- * @param mixed $value
323
- * @param array $options
324
- * @param array $pod
325
- * @param int $id
326
- *
327
- * @since 2.0
328
- */
329
- public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
330
- $options = (array) $options;
331
- $form_field_type = PodsForm::$field_type;
332
-
333
- if ( !is_admin() ) {
334
- include_once( ABSPATH . '/wp-admin/includes/template.php' );
335
-
336
- if ( is_multisite() )
337
- include_once( ABSPATH . '/wp-admin/includes/ms.php' );
338
- }
339
-
340
- if ( ( ( defined( 'PODS_DISABLE_FILE_UPLOAD' ) && true === PODS_DISABLE_FILE_UPLOAD )
341
- || ( defined( 'PODS_UPLOAD_REQUIRE_LOGIN' ) && is_bool( PODS_UPLOAD_REQUIRE_LOGIN ) && true === PODS_UPLOAD_REQUIRE_LOGIN && !is_user_logged_in() )
342
- || ( defined( 'PODS_UPLOAD_REQUIRE_LOGIN' ) && !is_bool( PODS_UPLOAD_REQUIRE_LOGIN ) && ( !is_user_logged_in() || !current_user_can( PODS_UPLOAD_REQUIRE_LOGIN ) ) ) )
343
- && ( ( defined( 'PODS_DISABLE_FILE_BROWSER' ) && true === PODS_DISABLE_FILE_BROWSER )
344
- || ( defined( 'PODS_FILES_REQUIRE_LOGIN' ) && is_bool( PODS_FILES_REQUIRE_LOGIN ) && true === PODS_FILES_REQUIRE_LOGIN && !is_user_logged_in() )
345
- || ( defined( 'PODS_FILES_REQUIRE_LOGIN' ) && !is_bool( PODS_FILES_REQUIRE_LOGIN ) && ( !is_user_logged_in() || !current_user_can( PODS_FILES_REQUIRE_LOGIN ) ) ) )
346
- ) {
347
- ?>
348
- <p>You do not have access to upload / browse files. Contact your website admin to resolve.</p>
349
- <?php
350
- return;
351
- }
352
-
353
- // Use plupload if attachment isn't available
354
- if ( 'attachment' == pods_var( self::$type . '_uploader', $options ) && ( !is_user_logged_in() || ( !current_user_can( 'upload_files' ) && !current_user_can( 'edit_files' ) ) ) )
355
- $field_type = 'plupload';
356
- elseif ( 'plupload' == pods_var( self::$type . '_uploader', $options ) )
357
- $field_type = 'plupload';
358
- elseif ( 'attachment' == pods_var( self::$type . '_uploader', $options ) ) {
359
- if ( !pods_version_check( 'wp', '3.5' ) || !is_admin() ) // @todo test frontend media modal
360
- $field_type = 'attachment';
361
- else
362
- $field_type = 'media';
363
- }
364
- else {
365
- // Support custom File Uploader integration
366
- do_action( 'pods_form_ui_field_file_uploader_' . pods_var( self::$type . '_uploader', $options ), $name, $value, $options, $pod, $id );
367
- do_action( 'pods_form_ui_field_file_uploader', pods_var( self::$type . '_uploader', $options ), $name, $value, $options, $pod, $id );
368
- return;
369
- }
370
-
371
- pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
372
- }
373
-
374
- /**
375
- * Build regex necessary for JS validation
376
- *
377
- * @param mixed $value
378
- * @param string $name
379
- * @param array $options
380
- * @param string $pod
381
- * @param int $id
382
- *
383
- * @return bool
384
- * @since 2.0
385
- */
386
- public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
387
- return false;
388
- }
389
-
390
- /**
391
- * Validate a value before it's saved
392
- *
393
- * @param mixed $value
394
- * @param string $name
395
- * @param array $options
396
- * @param array $fields
397
- * @param array $pod
398
- * @param int $id
399
- * @param null $params
400
- *
401
- * @return bool
402
- * @since 2.0
403
- */
404
- public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
405
- // check file size
406
- // check file extensions
407
- return true;
408
- }
409
-
410
- /**
411
- * Change the value or perform actions after validation but before saving to the DB
412
- *
413
- * @param mixed $value
414
- * @param int $id
415
- * @param string $name
416
- * @param array $options
417
- * @param array $fields
418
- * @param array $pod
419
- * @param object $params
420
- *
421
- * @return mixed
422
- * @since 2.0
423
- */
424
- public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
425
- return $value;
426
- }
427
-
428
- /**
429
- * Save the value to the DB
430
- *
431
- * @param mixed $value
432
- * @param int $id
433
- * @param string $name
434
- * @param array $options
435
- * @param array $fields
436
- * @param array $pod
437
- * @param object $params
438
- *
439
- * @since 2.3
440
- */
441
- public function save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
442
- if ( empty( self::$api ) )
443
- self::$api = pods_api();
444
-
445
- // File title / field handling
446
- foreach ( $value as $id ) {
447
- $title = false;
448
-
449
- if ( is_array( $id ) ) {
450
- if ( isset( $id[ 'title' ] ) && 0 < strlen( trim( $id[ 'title' ] ) ) )
451
- $title = trim( $id[ 'title' ] );
452
-
453
- if ( isset( $id[ 'id' ] ) )
454
- $id = (int) $id[ 'id' ];
455
- else
456
- $id = 0;
457
- }
458
-
459
- if ( empty( $id ) )
460
- continue;
461
-
462
- $attachment_data = array();
463
-
464
- // Update the title if set
465
- if ( false !== $title && 1 == pods_var( self::$type . '_edit_title', $options, 0 ) ) {
466
- $attachment_data['post_title'] = $title;
467
- }
468
-
469
- // Update attachment parent if it's not set yet and we're updating a post
470
- if ( ! empty( $params->id ) && ! empty( $pod['type'] ) && 'post_type' == $pod['type'] ) {
471
- $attachment = get_post( $id );
472
- if ( isset( $attachment->post_parent ) && 0 === (int) $attachment->post_parent ) {
473
- $attachment_data['post_parent'] = (int) $params->id;
474
- }
475
- }
476
-
477
- // Update the attachment if it the data array is not still empty
478
- if ( ! empty( $attachment_data ) ) {
479
- $attachment_data['ID'] = $id;
480
- self::$api->save_wp_object( 'media', $attachment_data );
481
- }
482
- }
483
- }
484
-
485
- /**
486
- * Customize the Pods UI manage table column output
487
- *
488
- * @param int $id
489
- * @param mixed $value
490
- * @param string $name
491
- * @param array $options
492
- * @param array $fields
493
- * @param array $pod
494
- *
495
- * @return mixed|void
496
- * @since 2.0
497
- */
498
- public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
499
- if ( empty( $value ) )
500
- return;
501
-
502
- if ( !empty( $value ) && isset( $value[ 'ID' ] ) )
503
- $value = array( $value );
504
-
505
- $image_size = apply_filters( 'pods_form_ui_field_file_ui_image_size', 'thumbnail', $id, $value, $name, $options, $pod );
506
-
507
- return $this->images( $id, $value, $name, $options, $pod, $image_size );
508
- }
509
-
510
- /**
511
- * Return image(s) markup
512
- *
513
- * @param int $id
514
- * @param mixed $value
515
- * @param string $name
516
- * @param array $options
517
- * @param array $pod
518
- * @param string $image_size
519
- *
520
- * @return string
521
- * @since 2.3
522
- */
523
- public function images ( $id, $value, $name = null, $options = null, $pod = null, $image_size = null ) {
524
- $images = '';
525
-
526
- if ( empty( $value ) || !is_array( $value ) )
527
- return $images;
528
-
529
- foreach ( $value as $v ) {
530
- $images .= pods_image( $v, $image_size );
531
- }
532
-
533
- return $images;
534
- }
535
 
536
  /**
537
  * Data callback for Image Sizes
538
  *
539
- * @param string $name The name of the field
540
- * @param string|array $value The value of the field
541
- * @param array $options Field options
542
- * @param array $pod Pod data
543
- * @param int $id Item ID
544
  *
545
  * @return array
546
  *
547
  * @since 2.3
548
  */
549
- public function data_image_sizes ( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
 
550
  $data = array();
551
 
552
  $image_sizes = get_intermediate_image_sizes();
@@ -556,392 +758,441 @@ class PodsField_File extends PodsField {
556
  }
557
 
558
  return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
 
559
  }
560
 
561
  /**
562
  * Create a WP Gallery from the passed values (need to be attachments)
563
  *
564
  * @since 2.7
565
- * @param string|array $value The value(s)
566
- * @param array $options The field options
 
 
567
  * @return string
568
  */
569
  public function do_wp_gallery( $value, $options ) {
570
- $args = array();
571
- if ( ! empty( $options[ self::$type . '_wp_gallery_columns' ] ) ) {
572
- $args['columns'] = $options[ self::$type . '_wp_gallery_columns' ];
 
 
573
  }
574
- if ( ! empty( $options[ self::$type . '_wp_gallery_random_sort' ] ) ) {
575
- $args['orderby'] = 'rand';
 
576
  }
577
- if ( ! empty( $options[ self::$type . '_wp_gallery_link' ] ) ) {
578
- $args['link'] = $options[ self::$type . '_wp_gallery_link' ];
 
579
  }
580
- if ( ! empty( $options[ self::$type . '_wp_gallery_size' ] ) ) {
581
- $args['size'] = $options[ self::$type . '_wp_gallery_size' ];
 
582
  }
583
 
584
- if ( isset( $value[ 'ID' ] ) ) {
585
- $args['ids'] = $value[ 'ID' ];
586
  } else {
587
  $images = array();
 
588
  foreach ( $value as $v ) {
589
  if ( ! is_array( $v ) ) {
590
  $images[] = (int) $v;
591
- } elseif ( isset( $v[ 'ID' ] ) ) {
592
- $images[] = (int) $v[ 'ID' ];
593
  }
594
  }
595
- $args['ids'] = implode( ',', $images );
 
596
  }
597
 
598
  if ( is_callable( 'gallery_shortcode' ) ) {
599
- return gallery_shortcode( $args );
600
  } else {
601
  $shortcode = '[gallery';
602
- foreach ( $args as $key => $value ) {
603
- $shortcode .= ' ' . $key . '="' . $value . '"';
 
604
  }
 
605
  $shortcode .= ']';
 
606
  return do_shortcode( $shortcode );
607
  }
 
608
  }
609
 
610
- /**
611
- * Handle file row output for uploaders
612
- *
613
- * @param array $attributes
614
- * @param int $limit
615
- * @param bool $editable
616
- * @param int $id
617
- * @param string $icon
618
- * @param string $name
619
- *
620
- * @return string
621
- * @since 2.0
622
- */
623
- public function markup ( $attributes, $limit = 1, $editable = true, $id = null, $icon = null, $name = null, $linked = false, $link = null ) {
624
- // Preserve current file type
625
- $field_type = PodsForm::$field_type;
626
-
627
- ob_start();
628
-
629
- if ( empty( $id ) )
630
- $id = '{{id}}';
631
-
632
- if ( empty( $icon ) ) {
633
- $icon = '{{icon}}';
634
- }else{
635
- $icon = esc_url( $icon );
636
- }
637
-
638
-
639
- if ( empty( $name ) )
640
- $name = '{{name}}';
641
-
642
- if ( empty( $link ) )
643
- $link = '{{link}}';
644
-
645
- $editable = (boolean) $editable;
646
- $linked = (boolean) $linked;
647
- ?>
648
- <li class="pods-file hidden" id="pods-file-<?php echo esc_attr( $id ); ?>">
649
- <?php echo PodsForm::field( $attributes[ 'name' ] . '[' . $id . '][id]', $id, 'hidden' ); ?>
650
-
651
- <ul class="pods-file-meta media-item">
652
- <?php if ( 1 != $limit ) { ?>
653
- <li class="pods-file-col pods-file-handle">Handle</li>
654
- <?php } ?>
655
-
656
- <li class="pods-file-col pods-file-icon">
657
- <img class="pinkynail" src="<?php echo $icon; ?>" alt="Icon" />
658
- </li>
659
-
660
- <li class="pods-file-col pods-file-name">
661
- <?php
662
- if ( $editable )
663
- echo PodsForm::field( $attributes[ 'name' ] . '[' . $id . '][title]', $name, 'text' );
664
- else
665
- echo ( empty( $name ) ? '{{name}}' : $name );
666
- ?>
667
- </li>
668
-
669
- <li class="pods-file-col pods-file-delete"><a href="#delete">Delete</a></li>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
670
 
671
- <?php
672
- if ( $linked ) {
673
- ?>
674
- <li class="pods-file-col pods-file-download"><a href="<?php echo esc_url( $link ); ?>" target="_blank">Download</a></li>
675
- <?php
676
- }
677
- ?>
678
- </ul>
679
- </li>
680
- <?php
681
- PodsForm::$field_type = $field_type;
682
-
683
- return ob_get_clean();
684
- }
685
-
686
- /**
687
- * Handle plupload AJAX
688
- *
689
- * @since 2.3
690
- */
691
- public function admin_ajax_upload () {
692
  pods_session_start();
693
 
694
- // Sanitize input
695
- $params = pods_unslash( (array) $_POST );
 
 
 
 
 
 
 
696
 
697
- foreach ( $params as $key => $value ) {
698
- if ( 'action' == $key )
699
- continue;
700
 
701
- unset( $params[ $key ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
702
 
703
- $params[ str_replace( '_podsfix_', '', $key ) ] = $value;
704
- }
 
705
 
706
- $params = (object) $params;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
707
 
708
- $methods = array(
709
- 'upload',
710
- );
711
 
712
- if ( !isset( $params->method ) || !in_array( $params->method, $methods ) || !isset( $params->pod ) || !isset( $params->field ) || !isset( $params->uri ) || empty( $params->uri ) )
713
- pods_error( 'Invalid AJAX request', PodsInit::$admin );
714
- elseif ( !empty( $params->pod ) && empty( $params->field ) )
715
- pods_error( 'Invalid AJAX request', PodsInit::$admin );
716
- elseif ( empty( $params->pod ) && !current_user_can( 'upload_files' ) )
717
- pods_error( 'Invalid AJAX request', PodsInit::$admin );
718
 
719
- // Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead
720
- if ( is_ssl() && empty( $_COOKIE[ SECURE_AUTH_COOKIE ] ) && !empty( $_REQUEST[ 'auth_cookie' ] ) )
721
- $_COOKIE[ SECURE_AUTH_COOKIE ] = $_REQUEST[ 'auth_cookie' ];
722
- elseif ( empty( $_COOKIE[ AUTH_COOKIE ] ) && !empty( $_REQUEST[ 'auth_cookie' ] ) )
723
- $_COOKIE[ AUTH_COOKIE ] = $_REQUEST[ 'auth_cookie' ];
724
-
725
- if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) && !empty( $_REQUEST[ 'logged_in_cookie' ] ) )
726
- $_COOKIE[ LOGGED_IN_COOKIE ] = $_REQUEST[ 'logged_in_cookie' ];
727
-
728
- global $current_user;
729
- unset( $current_user );
730
-
731
- /**
732
- * Access Checking
733
- */
734
- $upload_disabled = false;
735
-
736
- if ( defined( 'PODS_DISABLE_FILE_UPLOAD' ) && true === PODS_DISABLE_FILE_UPLOAD )
737
- $upload_disabled = true;
738
- elseif ( defined( 'PODS_UPLOAD_REQUIRE_LOGIN' ) && is_bool( PODS_UPLOAD_REQUIRE_LOGIN ) && true === PODS_UPLOAD_REQUIRE_LOGIN && !is_user_logged_in() )
739
- $upload_disabled = true;
740
- elseif ( defined( 'PODS_UPLOAD_REQUIRE_LOGIN' ) && !is_bool( PODS_UPLOAD_REQUIRE_LOGIN ) && ( !is_user_logged_in() || !current_user_can( PODS_UPLOAD_REQUIRE_LOGIN ) ) )
741
- $upload_disabled = true;
742
-
743
- $uid = @session_id();
744
-
745
- if ( is_user_logged_in() )
746
- $uid = 'user_' . get_current_user_id();
747
 
748
- $nonce_check = 'pods_upload_' . (int) $params->pod . '_' . $uid . '_' . $params->uri . '_' . (int) $params->field;
749
-
750
- if ( true === $upload_disabled || !isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, $nonce_check ) )
751
- pods_error( __( 'Unauthorized request', 'pods' ), PodsInit::$admin );
752
-
753
- $pod = array();
754
- $field = array(
755
- 'type' => 'file',
756
- 'options' => array()
757
- );
758
 
759
- $api = pods_api();
760
-
761
- $api->display_errors = false;
 
 
762
 
763
- if ( !empty( $params->pod ) ) {
764
- $pod = $api->load_pod( array( 'id' => (int) $params->pod ) );
765
- $field = $api->load_field( array( 'id' => (int) $params->field ) );
766
-
767
- if ( empty( $pod ) || empty( $field ) || $pod[ 'id' ] != $field[ 'pod_id' ] || !isset( $pod[ 'fields' ][ $field[ 'name' ] ] ) )
768
- pods_error( __( 'Invalid field request', 'pods' ), PodsInit::$admin );
769
-
770
- if ( !in_array( $field[ 'type' ], PodsForm::file_field_types() ) )
771
- pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin );
772
- }
773
-
774
- $method = $params->method;
775
 
776
- // Cleaning up $params
777
- unset( $params->action );
778
- unset( $params->method );
779
- unset( $params->_wpnonce );
780
-
781
- $params->post_id = pods_var( 'post_id', $params, 0, null, true );
782
 
783
- /**
784
- * Upload a new file (advanced - returns URL and ID)
785
- */
786
- if ( 'upload' == $method ) {
787
- $file = $_FILES[ 'Filedata' ];
788
 
789
- $limit_size = pods_var( $field[ 'type' ] . '_restrict_filesize', $field[ 'options' ] );
 
 
790
 
791
- if ( !empty( $limit_size ) ) {
792
- if ( false !== stripos( $limit_size, 'MB' ) ) {
793
- $limit_size = (float) trim( str_ireplace( 'MB', '', $limit_size ) );
794
- $limit_size = $limit_size * 1025 * 1025; // convert to KB to B
795
- }
796
- elseif ( false !== stripos( $limit_size, 'KB' ) ) {
797
- $limit_size = (float) trim( str_ireplace( 'KB', '', $limit_size ) );
798
- $limit_size = $limit_size * 1025 * 1025; // convert to B
799
- }
800
- elseif ( false !== stripos( $limit_size, 'GB' ) ) {
801
- $limit_size = (float) trim( str_ireplace( 'GB', '', $limit_size ) );
802
- $limit_size = $limit_size * 1025 * 1025 * 1025; // convert to MB to KB to B
803
- }
804
- elseif ( false !== stripos( $limit_size, 'B' ) )
805
- $limit_size = (float) trim( str_ireplace( 'B', '', $limit_size ) );
806
- else
807
- $limit_size = wp_max_upload_size();
808
-
809
- if ( 0 < $limit_size && $limit_size < $file[ 'size' ] ) {
810
- $error = __( 'File size too large, max size is %s', 'pods' );
811
- $error = sprintf( $error, pods_var( $field[ 'type' ] . '_restrict_filesize', $field[ 'options' ] ) );
812
 
813
- pods_error( '<div style="color:#FF0000">Error: ' . $error . '</div>' );
814
- }
815
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
816
 
817
- $limit_file_type = pods_var( $field[ 'type' ] . '_type', $field[ 'options' ], 'images' );
 
 
818
 
819
- if ( 'images' == $limit_file_type )
820
- $limit_types = 'jpg,jpeg,png,gif';
821
- elseif ( 'video' == $limit_file_type )
822
- $limit_types = 'mpg,mov,flv,mp4';
823
- elseif ( 'audio' == $limit_file_type )
824
- $limit_types = 'mp3,m4a,wav,wma';
825
- elseif ( 'text' == $limit_file_type )
826
- $limit_types = 'txt,rtx,csv,tsv';
827
- elseif ( 'any' == $limit_file_type )
828
- $limit_types = '';
829
- else
830
- $limit_types = pods_var( $field[ 'type' ] . '_allowed_extensions', $field[ 'options' ], '', null, true );
831
 
832
- $limit_types = trim( str_replace( array( ' ', '.', "\n", "\t", ';' ), array( '', ',', ',', ',' ), $limit_types ), ',' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
833
 
834
- if ( pods_version_check( 'wp', '3.5' ) ) {
835
- $mime_types = wp_get_mime_types();
 
 
 
 
836
 
837
- if ( in_array( $limit_file_type, array( 'images', 'audio', 'video' ) ) ) {
838
- $new_limit_types = array();
839
 
840
- foreach ( $mime_types as $type => $mime ) {
841
- if ( 0 === strpos( $mime, $limit_file_type ) ) {
842
- $type = explode( '|', $type );
843
 
844
- $new_limit_types = array_merge( $new_limit_types, $type );
845
- }
846
- }
847
 
848
- if ( !empty( $new_limit_types ) )
849
- $limit_types = implode( ',', $new_limit_types );
850
- }
851
- elseif ( 'any' != $limit_file_type ) {
852
- $new_limit_types = array();
853
 
854
- $limit_types = explode( ',', $limit_types );
 
 
 
 
855
 
856
- foreach ( $limit_types as $k => $limit_type ) {
857
- $found = false;
858
 
859
- foreach ( $mime_types as $type => $mime ) {
860
- if ( 0 === strpos( $mime, $limit_type ) ) {
861
- $type = explode( '|', $type );
862
 
863
- foreach ( $type as $t ) {
864
- if ( !in_array( $t, $new_limit_types ) )
865
- $new_limit_types[] = $t;
866
- }
867
 
868
- $found = true;
869
- }
870
- }
 
 
871
 
872
- if ( !$found )
873
- $new_limit_types[] = $limit_type;
874
- }
875
 
876
- if ( !empty( $new_limit_types ) )
877
- $limit_types = implode( ',', $new_limit_types );
878
- }
879
- }
880
 
881
- $limit_types = explode( ',', $limit_types );
 
 
 
882
 
883
- $limit_types = array_filter( array_unique( $limit_types ) );
884
 
885
- if ( !empty( $limit_types ) ) {
886
- $ok = false;
887
 
888
- foreach ( $limit_types as $limit_type ) {
889
- $limit_type = '.' . trim( $limit_type, ' .' );
890
 
891
- $pos = ( strlen( $file[ 'name' ] ) - strlen( $limit_type ) );
 
892
 
893
- if ( $pos === stripos( $file[ 'name' ], $limit_type ) ) {
894
- $ok = true;
895
 
896
- break;
897
- }
898
- }
899
 
900
- if ( false === $ok ) {
901
- $error = __( 'File type not allowed, please use one of the following: %s', 'pods' );
902
- $error = sprintf( $error, '.' . implode( ', .', $limit_types ) );
903
 
904
- pods_error( '<div style="color:#FF0000">Error: ' . $error . '</div>' );
905
- }
906
- }
907
 
908
- $custom_handler = apply_filters( 'pods_upload_handle', null, 'Filedata', $params->post_id, $params, $field );
 
 
909
 
910
- if ( null === $custom_handler ) {
911
- $linked = pods_var( $field[ 'type' ] . '_linked', $field[ 'options' ], 0 );
912
 
913
- $attachment_id = media_handle_upload( 'Filedata', $params->post_id );
 
914
 
915
- if ( is_object( $attachment_id ) ) {
916
- $errors = array();
917
 
918
- foreach ( $attachment_id->errors[ 'upload_error' ] as $error_code => $error_message ) {
919
- $errors[] = '[' . $error_code . '] ' . $error_message;
920
- }
921
 
922
- pods_error( '<div style="color:#FF0000">Error: ' . implode( '</div><div>', $errors ) . '</div>' );
923
- }
924
- else {
925
- $attachment = get_post( $attachment_id, ARRAY_A );
926
 
927
- $attachment[ 'filename' ] = basename( $attachment[ 'guid' ] );
928
 
929
- $thumb = wp_get_attachment_image_src( $attachment[ 'ID' ], 'thumbnail', true );
930
- $attachment[ 'thumbnail' ] = $thumb[ 0 ];
931
 
932
- $attachment[ 'link' ] = '';
933
 
934
- if ( $linked ) {
935
- $attachment[ 'link' ] = wp_get_attachment_url( $attachment[ 'ID' ] );
936
  }
937
 
938
- $attachment = apply_filters( 'pods_upload_attachment', $attachment, $params->post_id );
 
 
 
 
939
 
940
- wp_send_json( $attachment );
941
- }
942
- }
943
- }
 
 
 
 
944
 
945
- die(); // KBAI!
946
- }
947
  }
1
  <?php
2
+
3
  /**
4
  * @package Pods\Fields
5
  */
6
  class PodsField_File extends PodsField {
7
 
8
+ /**
9
+ * Field Type Group
10
+ *
11
+ * @var string
12
+ * @since 2.0
13
+ */
14
+ public static $group = 'Relationships / Media';
15
+
16
+ /**
17
+ * Field Type Identifier
18
+ *
19
+ * @var string
20
+ * @since 2.0
21
+ */
22
+ public static $type = 'file';
23
+
24
+ /**
25
+ * Field Type Label
26
+ *
27
+ * @var string
28
+ * @since 2.0
29
+ */
30
+ public static $label = 'File / Image / Video';
31
+
32
+ /**
33
+ * API caching for fields that need it during validate/save
34
+ *
35
+ * @var \PodsAPI
36
+ * @since 2.3
37
+ */
38
+ protected static $api = false;
39
+
40
+ /**
41
+ * {@inheritdoc}
42
+ */
43
+ public function __construct() {
44
+
45
+ self::$label = __( 'File / Image / Video', 'pods' );
46
+
47
+ }
48
+
49
+ /**
50
+ * Add admin_init actions.
51
+ *
52
+ * @since 2.3
53
+ */
54
+ public function admin_init() {
55
+
56
+ // Hook into AJAX for Uploads.
57
+ add_action( 'wp_ajax_pods_upload', array( $this, 'admin_ajax_upload' ) );
58
+ add_action( 'wp_ajax_nopriv_pods_upload', array( $this, 'admin_ajax_upload' ) );
59
+
60
+ }
61
+
62
+ /**
63
+ * {@inheritdoc}
64
+ */
65
+ public function options() {
66
+
67
+ $sizes = get_intermediate_image_sizes();
68
+
69
+ $image_sizes = array();
70
+
71
+ foreach ( $sizes as $size ) {
72
+ $image_sizes[ $size ] = ucwords( str_replace( '-', ' ', $size ) );
73
+ }
74
+
75
+ $options = array(
76
+ static::$type . '_format_type' => array(
77
+ 'label' => __( 'Upload Limit', 'pods' ),
78
+ 'default' => 'single',
79
+ 'type' => 'pick',
80
+ 'data' => array(
81
+ 'single' => __( 'Single File', 'pods' ),
82
+ 'multi' => __( 'Multiple Files', 'pods' ),
83
+ ),
84
+ 'dependency' => true,
85
+ ),
86
+ static::$type . '_uploader' => array(
87
+ 'label' => __( 'File Uploader', 'pods' ),
88
+ 'default' => 'attachment',
89
+ 'type' => 'pick',
90
+ 'data' => apply_filters( 'pods_form_ui_field_' . static::$type . '_uploader_options', array(
91
+ 'attachment' => __( 'Upload and/or Select (Media Library)', 'pods' ),
92
+ 'plupload' => __( 'Upload only (Plupload)', 'pods' ),
93
+ )
94
+ ),
95
+ 'dependency' => true,
96
+ ),
97
+ static::$type . '_attachment_tab' => array(
98
+ 'label' => __( 'Attachments Default Tab', 'pods' ),
99
+ 'depends-on' => array( static::$type . '_uploader' => 'attachment' ),
100
+ 'default' => 'upload',
101
+ 'type' => 'pick',
102
+ 'data' => array(
103
+ // These keys must match WP media modal router names.
104
+ 'upload' => __( 'Upload File', 'pods' ),
105
+ 'browse' => __( 'Media Library', 'pods' ),
106
+ ),
107
+ ),
108
+ static::$type . '_edit_title' => array(
109
+ 'label' => __( 'Editable Title', 'pods' ),
110
+ 'default' => 1,
111
+ 'type' => 'boolean',
112
+ ),
113
+ static::$type . '_show_edit_link' => array(
114
+ 'label' => __( 'Show Edit Link', 'pods' ),
115
+ 'default' => 0,
116
+ 'type' => 'boolean',
117
+ ),
118
+ static::$type . '_linked' => array(
119
+ 'label' => __( 'Show Download Link', 'pods' ),
120
+ 'default' => 0,
121
+ 'type' => 'boolean',
122
+ ),
123
+ static::$type . '_limit' => array(
124
+ 'label' => __( 'Max Number of Files', 'pods' ),
125
+ 'depends-on' => array( static::$type . '_format_type' => 'multi' ),
126
+ 'default' => 0,
127
+ 'type' => 'number',
128
+ ),
129
+ static::$type . '_restrict_filesize' => array(
130
+ 'label' => __( 'Restrict File Size', 'pods' ),
131
+ 'help' => __( 'Valid size suffixes are: GB (gigabytes), MB (megabytes), KB (kilobytes), or B (bytes). Defaults to the <a href="https://developer.wordpress.org/reference/functions/wp_max_upload_size/">wp_max_upload_size</a> setting.', 'pods' ),
132
+ 'depends-on' => array( static::$type . '_uploader' => 'plupload' ),
133
+ 'default' => '10MB',
134
+ 'type' => 'text',
135
+ ),
136
+ static::$type . '_type' => array(
137
+ 'label' => __( 'Restrict File Types', 'pods' ),
138
+ 'default' => apply_filters( 'pods_form_ui_field_' . static::$type . '_type_default', 'images' ),
139
+ 'type' => 'pick',
140
+ 'data' => apply_filters( 'pods_form_ui_field_' . static::$type . '_type_options', array(
141
+ 'images' => __( 'Images (jpg, jpeg, png, gif)', 'pods' ),
142
+ 'video' => __( 'Video (mpg, mov, flv, mp4, etc..)', 'pods' ),
143
+ 'audio' => __( 'Audio (mp3, m4a, wav, wma, etc..)', 'pods' ),
144
+ 'text' => __( 'Text (txt, csv, tsv, rtx, etc..)', 'pods' ),
145
+ 'any' => __( 'Any Type (no restriction)', 'pods' ),
146
+ 'other' => __( 'Other (customize allowed extensions)', 'pods' ),
147
+ )
148
+ ),
149
+ 'dependency' => true,
150
+ ),
151
+ static::$type . '_allowed_extensions' => array(
152
+ 'label' => __( 'Allowed File Extensions', 'pods' ),
153
+ 'description' => __( 'Separate file extensions with a comma (ex. jpg,png,mp4,mov)', 'pods' ),
154
+ 'depends-on' => array( static::$type . '_type' => 'other' ),
155
+ 'default' => apply_filters( 'pods_form_ui_field_' . static::$type . '_extensions_default', '' ),
156
+ 'type' => 'text',
157
+ ),
158
+ static::$type . '_field_template' => array(
159
+ 'label' => __( 'List Style', 'pods' ),
160
+ 'help' => __( 'You can choose which style you would like the files to appear within the form.', 'pods' ),
161
+ 'depends-on' => array( static::$type . '_type' => 'images' ),
162
+ 'default' => apply_filters( 'pods_form_ui_field_' . static::$type . '_template_default', 'rows' ),
163
+ 'type' => 'pick',
164
+ 'data' => apply_filters( 'pods_form_ui_field_' . static::$type . '_type_templates', array(
165
+ 'rows' => __( 'Rows', 'pods' ),
166
+ 'tiles' => __( 'Tiles', 'pods' ),
167
+ )
168
+ ),
169
+ ),
170
+ /*
171
+ static::$type . '_image_size' => array(
172
  'label' => __( 'Excluded Image Sizes', 'pods' ),
173
  'description' => __( 'Image sizes not to generate when processing the image', 'pods' ),
174
+ 'depends-on' => array( static::$type . '_type' => 'images' ),
175
  'default' => 'images',
176
  'type' => 'pick',
177
  'pick_format_type' => 'multi',
178
  'pick_format_multi' => 'checkbox',
179
  'data' => apply_filters(
180
+ 'pods_form_ui_field_' . static::$type . '_image_size_options',
181
  $image_sizes
182
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  ),
184
+ */
185
+ static::$type . '_add_button' => array(
186
+ 'label' => __( 'Add Button Text', 'pods' ),
187
+ 'default' => __( 'Add File', 'pods' ),
188
+ 'type' => 'text',
189
+ ),
190
+ static::$type . '_modal_title' => array(
191
+ 'label' => __( 'Modal Title', 'pods' ),
192
+ 'depends-on' => array( static::$type . '_uploader' => 'attachment' ),
193
+ 'default' => __( 'Attach a file', 'pods' ),
194
+ 'type' => 'text',
195
+ ),
196
+ static::$type . '_modal_add_button' => array(
197
+ 'label' => __( 'Modal Add Button Text', 'pods' ),
198
+ 'depends-on' => array( static::$type . '_uploader' => 'attachment' ),
199
+ 'default' => __( 'Add File', 'pods' ),
200
+ 'type' => 'text',
201
+ ),
202
+
203
+ /* WP GALLERY OUTPUT */
204
+ static::$type . '_wp_gallery_output' => array(
205
+ 'label' => __( 'Output as a WP Gallery', 'pods' ),
206
+ 'help' => sprintf( __( '<a href="%s" target="_blank">Click here for more info</a>', 'pods' ), 'https://codex.wordpress.org/The_WordPress_Gallery' ),
207
+ 'depends-on' => array( static::$type . '_type' => 'images' ),
208
+ 'dependency' => true,
209
+ 'type' => 'boolean',
210
+ ),
211
+ static::$type . '_wp_gallery_link' => array(
212
+ 'label' => __( 'Gallery image links', 'pods' ),
213
+ 'depends-on' => array( static::$type . '_wp_gallery_output' => 1 ),
214
+ 'type' => 'pick',
215
+ 'data' => array(
216
+ 'post' => __( 'Attachment Page', 'pods' ),
217
+ 'file' => __( 'Media File', 'pods' ),
218
+ 'none' => __( 'None', 'pods' ),
219
+ ),
220
+ ),
221
+ static::$type . '_wp_gallery_columns' => array(
222
+ 'label' => __( 'Gallery image columns', 'pods' ),
223
+ 'depends-on' => array( static::$type . '_wp_gallery_output' => 1 ),
224
+ 'type' => 'pick',
225
+ 'data' => array(
226
+ '1' => 1,
227
+ '2' => 2,
228
+ '3' => 3,
229
+ '4' => 4,
230
+ '5' => 5,
231
+ '6' => 6,
232
+ '7' => 7,
233
+ '8' => 8,
234
+ '9' => 9,
235
+ ),
236
+ ),
237
+ static::$type . '_wp_gallery_random_sort' => array(
238
+ 'label' => __( 'Gallery randomized order', 'pods' ),
239
+ 'depends-on' => array( static::$type . '_wp_gallery_output' => 1 ),
240
+ 'type' => 'boolean',
241
+ ),
242
+ static::$type . '_wp_gallery_size' => array(
243
+ 'label' => __( 'Gallery image size', 'pods' ),
244
+ 'depends-on' => array( static::$type . '_wp_gallery_output' => 1 ),
245
+ 'type' => 'pick',
246
+ 'data' => $this->data_image_sizes(),
247
+ ),
248
+ );
249
+
250
+ return $options;
251
+
252
+ }
253
 
254
+ /**
255
+ * {@inheritdoc}
256
+ */
257
+ public function schema( $options = null ) {
258
+
259
+ $schema = false;
260
+
261
+ return $schema;
262
+
263
+ }
264
+
265
+ /**
266
+ * {@inheritdoc}
267
+ */
268
+ public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
269
+
270
+ if ( ! empty( $options[ static::$type . '_wp_gallery_output' ] ) ) {
271
+ return $this->do_wp_gallery( $value, $options );
272
+ }
273
+
274
+ if ( is_array( $value ) && ! empty( $value ) ) {
275
+ if ( isset( $value['ID'] ) ) {
276
+ $value = wp_get_attachment_url( $value['ID'] );
277
+ } else {
278
+ $attachments = $value;
279
+ $value = array();
280
+
281
+ foreach ( $attachments as $v ) {
282
+ if ( ! is_array( $v ) ) {
283
+ $value[] = $v;
284
+ } elseif ( isset( $v['ID'] ) ) {
285
+ $value[] = wp_get_attachment_url( $v['ID'] );
286
+ }
287
+ }
288
+
289
+ $value = implode( ' ', $value );
290
+ }
291
+ }
292
+
293
+ return $value;
294
+
295
+ }
296
+
297
+ /**
298
+ * {@inheritdoc}
299
+ */
300
+ public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
301
+
302
+ $options = (array) $options;
303
+
304
+ $type = pods_v( 'type', $options, static::$type );
305
+
306
+ $args = compact( array_keys( get_defined_vars() ) );
307
+ $args = (object) $args;
308
+
309
+ /**
310
+ * Access Checking
311
+ */
312
+ $is_user_logged_in = is_user_logged_in();
313
+
314
+ $file_upload_requirements = array(
315
+ 'disabled' => ( defined( 'PODS_DISABLE_FILE_UPLOAD' ) && true === PODS_DISABLE_FILE_UPLOAD ),
316
+ 'require_login' => ( defined( 'PODS_UPLOAD_REQUIRE_LOGIN' ) && true === PODS_UPLOAD_REQUIRE_LOGIN && ! $is_user_logged_in ),
317
+ 'require_login_cap' => ( defined( 'PODS_UPLOAD_REQUIRE_LOGIN' ) && is_string( PODS_UPLOAD_REQUIRE_LOGIN ) && ( ! $is_user_logged_in || ! current_user_can( PODS_UPLOAD_REQUIRE_LOGIN ) ) ),
318
+ );
319
+
320
+ $file_browser_requirements = array(
321
+ 'disabled' => ( defined( 'PODS_DISABLE_FILE_BROWSER' ) && true === PODS_DISABLE_FILE_BROWSER ),
322
+ 'require_login' => ( defined( 'PODS_FILES_REQUIRE_LOGIN' ) && true === PODS_FILES_REQUIRE_LOGIN && ! $is_user_logged_in ),
323
+ 'require_login_cap' => ( defined( 'PODS_FILES_REQUIRE_LOGIN' ) && is_string( PODS_FILES_REQUIRE_LOGIN ) && ( ! $is_user_logged_in || ! current_user_can( PODS_FILES_REQUIRE_LOGIN ) ) ),
324
+ );
325
+
326
+ $file_upload_requirements = array_filter( $file_upload_requirements );
327
+ $file_browser_requirements = array_filter( $file_browser_requirements );
328
+
329
+ if ( ! empty( $file_upload_requirements ) && ! empty( $file_browser_requirements ) ) {
330
+ ?>
331
+ <p><?php esc_html_e( 'You do not have access to upload / browse files. Contact your website admin to resolve.', 'pods' ); ?></p>
332
+ <?php
333
+
334
+ return;
335
+ }
336
+
337
+ wp_enqueue_script( 'pods-dfv' );
338
+ wp_enqueue_media(); // Ensure the media library is initialized
339
+
340
+ $this->render_input_script( $args );
341
+
342
+ return;
343
+
344
+ // @todo: we're short-circuiting for prototyping above. The actions below will need to be woven in somehow.
345
+ if ( ! in_array( pods_v( $form_field_type . '_uploader', $options ), array( 'attachment', 'plupload', 'media' ) ) ) {
346
+ // Support custom File Uploader integration
347
+ do_action( 'pods_form_ui_field_' . static::$type . '_uploader_' . pods_v( static::$type . '_uploader', $options ), $name, $value, $options, $pod, $id );
348
+ do_action( 'pods_form_ui_field_' . static::$type . '_uploader', pods_v( static::$type . '_uploader', $options ), $name, $value, $options, $pod, $id );
349
+
350
+ return;
351
+ }
352
+
353
+ }
354
+
355
+ /**
356
+ * {@inheritdoc}
357
+ */
358
+ public function build_dfv_field_options( $options, $args ) {
359
+
360
+ if ( ! is_admin() ) {
361
+ include_once( ABSPATH . '/wp-admin/includes/template.php' );
362
+
363
+ if ( is_multisite() ) {
364
+ include_once( ABSPATH . '/wp-admin/includes/ms.php' );
365
+ }
366
+ }
367
+
368
+ // Handle default template setting.
369
+ $file_field_template = pods_v( $args->type . '_field_template', $options, 'rows', true );
370
+
371
+ // Get which file types the field is limited to.
372
+ $limit_file_type = pods_v( $args->type . '_type', $options, 'images' );
373
+
374
+ // Non-image file types are forced to rows template right now.
375
+ if ( 'images' !== $limit_file_type ) {
376
+ $file_field_template = 'rows';
377
+ }
378
+
379
+ $options[ $args->type . '_field_template' ] = $file_field_template;
380
+
381
+ // Enforce limit.
382
+ $file_limit = 1;
383
+
384
+ if ( 'multi' === pods_v( $args->type . '_format_type', $options, 'single' ) ) {
385
+ $file_limit = (int) pods_v( $args->type . '_limit', $options, 0 );
386
+
387
+ if ( $file_limit < 0 ) {
388
+ $file_limit = 0;
389
+ }
390
+ }
391
+
392
+ $options[ $args->type . '_limit' ] = $file_limit;
393
+
394
+ // Build types and extensions to limit by.
395
+ if ( 'images' === $limit_file_type ) {
396
+ $limit_types = 'image';
397
+ $limit_extensions = 'jpg,jpeg,png,gif';
398
+ } elseif ( 'video' === $limit_file_type ) {
399
+ $limit_types = 'video';
400
+ $limit_extensions = 'mpg,mov,flv,mp4';
401
+ } elseif ( 'audio' === $limit_file_type ) {
402
+ $limit_types = 'audio';
403
+ $limit_extensions = 'mp3,m4a,wav,wma';
404
+ } elseif ( 'text' === $limit_file_type ) {
405
+ $limit_types = 'text';
406
+ $limit_extensions = 'txt,rtx,csv,tsv';
407
+ } elseif ( 'any' === $limit_file_type ) {
408
+ $limit_types = '';
409
+ $limit_extensions = '*';
410
+ } else {
411
+ $limit_types = $limit_extensions = pods_v( $args->type . '_allowed_extensions', $options, '', true );
412
+ }
413
+
414
+ // Find and replace certain characters to properly split by commas.
415
+ $find = array(
416
+ ' ',
417
+ '.',
418
+ "\n",
419
+ "\t",
420
+ ';',
421
+ );
422
+ $replace = array(
423
+ '',
424
+ ',',
425
+ ',',
426
+ ',',
427
+ );
428
+
429
+ $limit_types = trim( str_replace( $find, $replace, $limit_types ), ',' );
430
+ $limit_extensions = trim( str_replace( $find, $replace, $limit_extensions ), ',' );
431
+ $mime_types = wp_get_mime_types();
432
+
433
+ if ( ! in_array( $limit_file_type, array( 'images', 'video', 'audio', 'text', 'any' ), true ) ) {
434
+ $new_limit_types = array();
435
+
436
+ $limit_types = explode( ',', $limit_types );
437
+
438
+ foreach ( $limit_types as $k => $limit_type ) {
439
+ if ( isset( $mime_types[ $limit_type ] ) ) {
440
+ $mime = explode( '/', $mime_types[ $limit_type ] );
441
+ $mime = $mime[0];
442
+
443
+ if ( ! in_array( $mime, $new_limit_types, true ) ) {
444
+ $new_limit_types[] = $mime;
445
+ }
446
+ } else {
447
+ $found = false;
448
+
449
+ foreach ( $mime_types as $type => $mime ) {
450
+ if ( false !== strpos( $type, $limit_type ) ) {
451
+ $mime = explode( '/', $mime );
452
+ $mime = $mime[0];
453
+
454
+ if ( ! in_array( $mime, $new_limit_types, true ) ) {
455
+ $new_limit_types[] = $mime;
456
+ }
457
+
458
+ $found = true;
459
+ }
460
+ }
461
+
462
+ if ( ! $found ) {
463
+ $new_limit_types[] = $limit_type;
464
+ }
465
+ }
466
+ }
467
+
468
+ if ( ! empty( $new_limit_types ) ) {
469
+ $limit_types = implode( ',', $new_limit_types );
470
+ }
471
+ }
472
+
473
+ $options['limit_types'] = $limit_types;
474
+ $options['limit_extensions'] = $limit_extensions;
475
+
476
+ $is_user_logged_in = is_user_logged_in();
477
+
478
+ // @todo test frontend media modal
479
+ if ( empty( $options[ static::$type . '_uploader' ] ) || ! is_admin() || ! $is_user_logged_in
480
+ || ( ! current_user_can( 'upload_files' ) && ! current_user_can( 'edit_files' ) ) ) {
481
+ $options[ static::$type . '_uploader' ] = 'plupload';
482
+ }
483
+
484
+ // @todo: plupload specific options need accommodation
485
+ if ( 'plupload' === $options[ static::$type . '_uploader' ] ) {
486
+ wp_enqueue_script( 'plupload-all' );
487
+
488
+ if ( $is_user_logged_in ) {
489
+ $uid = 'user_' . get_current_user_id();
490
+ } else {
491
+ $uid = @session_id();
492
+ }
493
+
494
+ $pod_id = '0';
495
+
496
+ if ( is_object( $args->pod ) ) {
497
+ $pod_id = $args->pod->pod_id;
498
+ }
499
+
500
+ $uri_hash = wp_create_nonce( 'pods_uri_' . $_SERVER['REQUEST_URI'] );
501
+ $field_nonce = wp_create_nonce( 'pods_upload_' . $pod_id . '_' . $uid . '_' . $uri_hash . '_' . $options['id'] );
502
+
503
+ $options['plupload_init'] = array(
504
+ 'runtimes' => 'html5,silverlight,flash,html4',
505
+ 'url' => admin_url( 'admin-ajax.php?pods_ajax=1', 'relative' ),
506
+ 'file_data_name' => 'Filedata',
507
+ 'multiple_queues' => false,
508
+ 'max_file_size' => wp_max_upload_size() . 'b',
509
+ 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
510
+ 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
511
+ 'filters' => array(
512
+ array(
513
+ 'title' => __( 'Allowed Files', 'pods' ),
514
+ 'extensions' => '*',
515
+ ),
516
  ),
517
+ 'multipart' => true,
518
+ 'urlstream_upload' => true,
519
+ 'multipart_params' => array(
520
+ '_wpnonce' => $field_nonce,
521
+ 'action' => 'pods_upload',
522
+ 'method' => 'upload',
523
+ 'pod' => $pod_id,
524
+ 'field' => $options['id'],
525
+ 'uri' => $uri_hash,
526
+ ),
527
+ );
528
+ }
529
+
530
+ return $options;
531
+
532
+ }
533
+
534
+ /**
535
+ * {@inheritdoc}
536
+ */
537
+ public function build_dfv_field_attributes( $attributes, $args ) {
538
+
539
+ // Add template class.
540
+ $attributes['class'] .= ' pods-field-template-' . $args->options[ $args->type . '_field_template' ];
541
+
542
+ return $attributes;
543
+
544
+ }
545
+
546
+ /**
547
+ * {@inheritdoc}
548
+ */
549
+ public function build_dfv_field_item_data( $args ) {
550
+
551
+ $data = array();
552
+
553
+ $title_editable = (int) pods_v( $args->type . '_edit_title', $args->options, 0 );
554
+
555
+ $value = $args->value;
556
+
557
+ if ( empty( $value ) ) {
558
+ $value = array();
559
+ } else {
560
+ $value = (array) $value;
561
+ }
562
+
563
+ foreach ( $value as $id ) {
564
+ $attachment = get_post( $id );
565
+
566
+ if ( empty( $attachment ) ) {
567
+ continue;
568
+ }
569
+
570
+ $icon = '';
571
+
572
+ // @todo Add access check
573
+ $edit_link = get_edit_post_link( $attachment->ID, 'raw' );
574
+
575
+ $link = get_permalink( $attachment->ID );
576
+ $download = wp_get_attachment_url( $attachment->ID );
577
+
578
+ $thumb = wp_get_attachment_image_src( $id, 'thumbnail', true );
579
+
580
+ if ( ! empty( $thumb[0] ) ) {
581
+ $icon = $thumb[0];
582
+ }
583
+
584
+ $title = $attachment->post_title;
585
+
586
+ if ( 0 === $title_editable ) {
587
+ $title = basename( $attachment->guid );
588
+ }
589
+
590
+ $data[] = array(
591
+ 'id' => $id,
592
+ 'icon' => $icon,
593
+ 'name' => $title,
594
+ 'edit_link' => $edit_link,
595
+ 'link' => $link,
596
+ 'download' => $download,
597
+ );
598
+ }
599
+
600
+ return $data;
601
+
602
+ }
603
+
604
+ /**
605
+ * {@inheritdoc}
606
+ */
607
+ public function regex( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
608
+
609
+ return false;
610
+
611
+ }
612
+
613
+ /**
614
+ * {@inheritdoc}
615
+ */
616
+ public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
617
+
618
+ // @todo Check file size
619
+ // @todo Check file extensions
620
+
621
+ return true;
622
+
623
+ }
624
+
625
+ /**
626
+ * {@inheritdoc}
627
+ */
628
+ public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
629
+
630
+ return $value;
631
+
632
+ }
633
+
634
+ /**
635
+ * {@inheritdoc}
636
+ */
637
+ public function save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
638
+
639
+ if ( empty( self::$api ) ) {
640
+ self::$api = pods_api();
641
+ }
642
+
643
+ // Handle File title saving.
644
+ foreach ( $value as $id ) {
645
+ $title = false;
646
+
647
+ if ( is_array( $id ) ) {
648
+ if ( isset( $id['title'] ) && 0 < strlen( trim( $id['title'] ) ) ) {
649
+ $title = trim( $id['title'] );
650
+ }
651
+
652
+ if ( isset( $id['id'] ) ) {
653
+ $id = (int) $id['id'];
654
+ } else {
655
+ $id = 0;
656
+ }
657
+ }
658
+
659
+ if ( empty( $id ) ) {
660
+ continue;
661
+ }
662
+
663
+ $attachment_data = array();
664
+
665
+ // Update the title if set.
666
+ if ( false !== $title && 1 === (int) pods_v( static::$type . '_edit_title', $options, 0 ) ) {
667
+ $attachment_data['post_title'] = $title;
668
+ }
669
+
670
+ // Update attachment parent if it's not set yet and we're updating a post.
671
+ if ( ! empty( $params->id ) && ! empty( $pod['type'] ) && 'post_type' === $pod['type'] ) {
672
+ $attachment = get_post( $id );
673
+
674
+ if ( isset( $attachment->post_parent ) && 0 === (int) $attachment->post_parent ) {
675
+ $attachment_data['post_parent'] = (int) $params->id;
676
+ }
677
+ }
678
+
679
+ // Update the attachment if it the data array is not still empty.
680
+ if ( ! empty( $attachment_data ) ) {
681
+ $attachment_data['ID'] = $id;
682
+
683
+ self::$api->save_wp_object( 'media', $attachment_data );
684
+ }
685
+ }
686
+
687
+ }
688
+
689
+ /**
690
+ * {@inheritdoc}
691
+ */
692
+ public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
693
+
694
+ if ( empty( $value ) ) {
695
+ return;
696
+ }
697
+
698
+ if ( ! empty( $value ) && isset( $value['ID'] ) ) {
699
+ $value = array( $value );
700
+ }
701
+
702
+ $image_size = apply_filters( 'pods_form_ui_field_' . static::$type . '_ui_image_size', 'thumbnail', $id, $value, $name, $options, $pod );
703
+
704
+ return $this->images( $id, $value, $name, $options, $pod, $image_size );
705
+
706
+ }
707
+
708
+ /**
709
+ * Return image(s) markup
710
+ *
711
+ * @param int $id
712
+ * @param mixed $value
713
+ * @param string $name
714
+ * @param array $options
715
+ * @param array $pod
716
+ * @param string $image_size
717
+ *
718
+ * @return string
719
+ * @since 2.3
720
+ */
721
+ public function images( $id, $value, $name = null, $options = null, $pod = null, $image_size = null ) {
722
+
723
+ $images = '';
724
+
725
+ if ( empty( $value ) || ! is_array( $value ) ) {
726
+ return $images;
727
+ }
728
+
729
+ foreach ( $value as $v ) {
730
+ $images .= pods_image( $v, $image_size );
731
+ }
732
+
733
+ return $images;
734
+
735
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
736
 
737
  /**
738
  * Data callback for Image Sizes
739
  *
740
+ * @param string $name The name of the field
741
+ * @param string|array $value The value of the field
742
+ * @param array $options Field options
743
+ * @param array $pod Pod data
744
+ * @param int $id Item ID
745
  *
746
  * @return array
747
  *
748
  * @since 2.3
749
  */
750
+ public function data_image_sizes( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
751
+
752
  $data = array();
753
 
754
  $image_sizes = get_intermediate_image_sizes();
758
  }
759
 
760
  return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
761
+
762
  }
763
 
764
  /**
765
  * Create a WP Gallery from the passed values (need to be attachments)
766
  *
767
  * @since 2.7
768
+ *
769
+ * @param string|array $value The value(s)
770
+ * @param array $options The field options
771
+ *
772
  * @return string
773
  */
774
  public function do_wp_gallery( $value, $options ) {
775
+
776
+ $shortcode_args = array();
777
+
778
+ if ( ! empty( $options[ static::$type . '_wp_gallery_columns' ] ) ) {
779
+ $shortcode_args['columns'] = absint( $options[ static::$type . '_wp_gallery_columns' ] );
780
  }
781
+
782
+ if ( ! empty( $options[ static::$type . '_wp_gallery_random_sort' ] ) ) {
783
+ $shortcode_args['orderby'] = 'rand';
784
  }
785
+
786
+ if ( ! empty( $options[ static::$type . '_wp_gallery_link' ] ) ) {
787
+ $shortcode_args['link'] = $options[ static::$type . '_wp_gallery_link' ];
788
  }
789
+
790
+ if ( ! empty( $options[ static::$type . '_wp_gallery_size' ] ) ) {
791
+ $shortcode_args['size'] = $options[ static::$type . '_wp_gallery_size' ];
792
  }
793
 
794
+ if ( isset( $value['ID'] ) ) {
795
+ $shortcode_args['ids'] = $value['ID'];
796
  } else {
797
  $images = array();
798
+
799
  foreach ( $value as $v ) {
800
  if ( ! is_array( $v ) ) {
801
  $images[] = (int) $v;
802
+ } elseif ( isset( $v['ID'] ) ) {
803
+ $images[] = (int) $v['ID'];
804
  }
805
  }
806
+
807
+ $shortcode_args['ids'] = implode( ',', $images );
808
  }
809
 
810
  if ( is_callable( 'gallery_shortcode' ) ) {
811
+ return gallery_shortcode( $shortcode_args );
812
  } else {
813
  $shortcode = '[gallery';
814
+
815
+ foreach ( $shortcode_args as $key => $shortcode_arg ) {
816
+ $shortcode .= ' ' . esc_attr( $key ) . '="' . esc_attr( $shortcode_arg ) . '"';
817
  }
818
+
819
  $shortcode .= ']';
820
+
821
  return do_shortcode( $shortcode );
822
  }
823
+
824
  }
825
 
826
+ /**
827
+ * Handle file row output for uploaders
828
+ *
829
+ * @param array $attributes
830
+ * @param int $limit
831
+ * @param bool $editable
832
+ * @param int $id
833
+ * @param string $icon
834
+ * @param string $name
835
+ *
836
+ * @return string
837
+ * @since 2.0
838
+ *
839
+ * @deprecated 2.7
840
+ */
841
+ public function markup( $attributes, $limit = 1, $editable = true, $id = null, $icon = null, $name = null, $linked = false, $link = null ) {
842
+
843
+ _doing_it_wrong( 'PodsField_File::markup', esc_html__( 'This method has been deprecated and will be removed from Pods 3.0', 'pods' ), '2.7' );
844
+
845
+ // Preserve current file type.
846
+ $field_type = PodsForm::$field_type;
847
+
848
+ ob_start();
849
+
850
+ if ( empty( $id ) ) {
851
+ $id = '{{id}}';
852
+ }
853
+
854
+ if ( empty( $icon ) ) {
855
+ $icon = '{{icon}}';
856
+ } else {
857
+ $icon = esc_url( $icon );
858
+ }
859
+
860
+ if ( empty( $name ) ) {
861
+ $name = '{{name}}';
862
+ }
863
+
864
+ if ( empty( $link ) ) {
865
+ $link = '{{link}}';
866
+ }
867
+
868
+ $editable = (boolean) $editable;
869
+ $linked = (boolean) $linked;
870
+ ?>
871
+ <li class="pods-file hidden" id="pods-file-<?php echo esc_attr( $id ); ?>">
872
+ <?php echo PodsForm::field( $attributes['name'] . '[' . $id . '][id]', $id, 'hidden' ); ?>
873
+
874
+ <ul class="pods-file-meta media-item">
875
+ <?php if ( 1 != $limit ) { ?>
876
+ <li class="pods-file-col pods-file-handle">Handle</li>
877
+ <?php } ?>
878
+
879
+ <li class="pods-file-col pods-file-icon">
880
+ <img class="pinkynail" src="<?php echo $icon; ?>" alt="Icon" />
881
+ </li>
882
+
883
+ <li class="pods-file-col pods-file-name">
884
+ <?php
885
+ if ( $editable ) {
886
+ echo PodsForm::field( $attributes['name'] . '[' . $id . '][title]', $name, 'text' );
887
+ } else {
888
+ echo( empty( $name ) ? '{{name}}' : $name );
889
+ }
890
+ ?>
891
+ </li>
892
+
893
+ <li class="pods-file-col pods-file-actions">
894
+ <ul>
895
+ <li class="pods-file-col pods-file-delete"><a href="#delete">Delete</a></li>
896
+ <?php
897
+ if ( $linked ) {
898
+ ?>
899
+ <li class="pods-file-col pods-file-download">
900
+ <a href="<?php echo esc_url( $link ); ?>" target="_blank">Download</a></li>
901
+ <?php
902
+ }
903
+ ?>
904
+ </ul>
905
+ </li>
906
+ </ul>
907
+ </li>
908
+ <?php
909
+ PodsForm::$field_type = $field_type;
910
+
911
+ return ob_get_clean();
912
+
913
+ }
914
+
915
+ /**
916
+ * Handle AJAX plupload calls.
917
+ *
918
+ * @since 2.3
919
+ */
920
+ public function admin_ajax_upload() {
921
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
922
  pods_session_start();
923
 
924
+ // Sanitize input
925
+ $params = pods_unslash( (array) $_POST );
926
+
927
+ foreach ( $params as $key => $value ) {
928
+ if ( 'action' === $key ) {
929
+ continue;
930
+ }
931
+
932
+ unset( $params[ $key ] );
933
 
934
+ $params[ str_replace( '_podsfix_', '', $key ) ] = $value;
935
+ }
 
936
 
937
+ $params = (object) $params;
938
+
939
+ $methods = array(
940
+ 'upload',
941
+ );
942
+
943
+ if ( ! isset( $params->method ) || ! in_array( $params->method, $methods, true ) || ! isset( $params->pod ) || ! isset( $params->field ) || ! isset( $params->uri ) || empty( $params->uri ) ) {
944
+ pods_error( 'Invalid AJAX request', PodsInit::$admin );
945
+ } elseif ( ! empty( $params->pod ) && empty( $params->field ) ) {
946
+ pods_error( 'Invalid AJAX request', PodsInit::$admin );
947
+ } elseif ( empty( $params->pod ) && ! current_user_can( 'upload_files' ) ) {
948
+ pods_error( 'Invalid AJAX request', PodsInit::$admin );
949
+ }
950
+
951
+ // Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead
952
+ if ( is_ssl() && empty( $_COOKIE[ SECURE_AUTH_COOKIE ] ) && ! empty( $_REQUEST['auth_cookie'] ) ) {
953
+ $_COOKIE[ SECURE_AUTH_COOKIE ] = $_REQUEST['auth_cookie'];
954
+ } elseif ( empty( $_COOKIE[ AUTH_COOKIE ] ) && ! empty( $_REQUEST['auth_cookie'] ) ) {
955
+ $_COOKIE[ AUTH_COOKIE ] = $_REQUEST['auth_cookie'];
956
+ }
957
 
958
+ if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) && ! empty( $_REQUEST['logged_in_cookie'] ) ) {
959
+ $_COOKIE[ LOGGED_IN_COOKIE ] = $_REQUEST['logged_in_cookie'];
960
+ }
961
 
962
+ global $current_user;
963
+ unset( $current_user );
964
+
965
+ /**
966
+ * Access Checking
967
+ */
968
+ $upload_disabled = false;
969
+ $is_user_logged_in = is_user_logged_in();
970
+
971
+ if ( defined( 'PODS_DISABLE_FILE_UPLOAD' ) && true === PODS_DISABLE_FILE_UPLOAD ) {
972
+ $upload_disabled = true;
973
+ } elseif ( ! $is_user_logged_in ) {
974
+ if ( defined( 'PODS_UPLOAD_REQUIRE_LOGIN' ) && true === PODS_UPLOAD_REQUIRE_LOGIN ) {
975
+ $upload_disabled = true;
976
+ } elseif ( defined( 'PODS_UPLOAD_REQUIRE_LOGIN' ) && is_string( PODS_UPLOAD_REQUIRE_LOGIN ) && ! current_user_can( PODS_UPLOAD_REQUIRE_LOGIN ) ) {
977
+ $upload_disabled = true;
978
+ }
979
+ }
980
 
981
+ $uid = @session_id();
 
 
982
 
983
+ if ( $is_user_logged_in ) {
984
+ $uid = 'user_' . get_current_user_id();
985
+ }
 
 
 
986
 
987
+ $nonce_check = 'pods_upload_' . (int) $params->pod . '_' . $uid . '_' . $params->uri . '_' . (int) $params->field;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
988
 
989
+ if ( true === $upload_disabled || ! isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, $nonce_check ) ) {
990
+ pods_error( __( 'Unauthorized request', 'pods' ), PodsInit::$admin );
991
+ }
 
 
 
 
 
 
 
992
 
993
+ $pod = array();
994
+ $field = array(
995
+ 'type' => 'file',
996
+ 'options' => array()
997
+ );
998
 
999
+ if ( empty( self::$api ) ) {
1000
+ self::$api = pods_api();
1001
+ }
 
 
 
 
 
 
 
 
 
1002
 
1003
+ self::$api->display_errors = false;
 
 
 
 
 
1004
 
1005
+ if ( ! empty( $params->pod ) ) {
1006
+ $pod = self::$api->load_pod( array( 'id' => (int) $params->pod ) );
1007
+ $field = self::$api->load_field( array( 'id' => (int) $params->field ) );
 
 
1008
 
1009
+ if ( empty( $pod ) || empty( $field ) || $pod['id'] != $field['pod_id'] || ! isset( $pod['fields'][ $field['name'] ] ) ) {
1010
+ pods_error( __( 'Invalid field request', 'pods' ), PodsInit::$admin );
1011
+ }
1012
 
1013
+ if ( ! in_array( $field['type'], PodsForm::file_field_types(), true ) ) {
1014
+ pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin );
1015
+ }
1016
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1017
 
1018
+ $method = $params->method;
1019
+
1020
+ // Cleaning up $params
1021
+ unset( $params->action );
1022
+ unset( $params->method );
1023
+ unset( $params->_wpnonce );
1024
+
1025
+ $params->post_id = (int) pods_v( 'post_id', $params, 0 );
1026
+
1027
+ /**
1028
+ * Upload a new file (advanced - returns URL and ID)
1029
+ */
1030
+ if ( 'upload' === $method ) {
1031
+ $file = $_FILES['Filedata'];
1032
+
1033
+ $limit_size = pods_v( $field['type'] . '_restrict_filesize', $field['options'] );
1034
+
1035
+ if ( ! empty( $limit_size ) ) {
1036
+ if ( false !== stripos( $limit_size, 'GB' ) ) {
1037
+ $limit_size = (float) trim( str_ireplace( 'GB', '', $limit_size ) );
1038
+ $limit_size = $limit_size * 1025 * 1025 * 1025; // convert to MB to KB to B
1039
+ } elseif ( false !== stripos( $limit_size, 'MB' ) ) {
1040
+ $limit_size = (float) trim( str_ireplace( 'MB', '', $limit_size ) );
1041
+ $limit_size = $limit_size * 1025 * 1025; // convert to KB to B
1042
+ } elseif ( false !== stripos( $limit_size, 'KB' ) ) {
1043
+ $limit_size = (float) trim( str_ireplace( 'KB', '', $limit_size ) );
1044
+ $limit_size = $limit_size * 1025; // convert to B
1045
+ } elseif ( false !== stripos( $limit_size, 'B' ) ) {
1046
+ $limit_size = (float) trim( str_ireplace( 'B', '', $limit_size ) );
1047
+ } else {
1048
+ $limit_size = wp_max_upload_size();
1049
+ }
1050
 
1051
+ if ( 0 < $limit_size && $limit_size < $file['size'] ) {
1052
+ $error = __( 'File size too large, max size is %s', 'pods' );
1053
+ $error = sprintf( $error, pods_v( $field['type'] . '_restrict_filesize', $field['options'] ) );
1054
 
1055
+ pods_error( '<div style="color:#FF0000">Error: ' . $error . '</div>' );
1056
+ }
1057
+ }
 
 
 
 
 
 
 
 
 
1058
 
1059
+ $limit_file_type = pods_v( $field['type'] . '_type', $field['options'], 'images' );
1060
+
1061
+ if ( 'images' === $limit_file_type ) {
1062
+ $limit_types = 'jpg,jpeg,png,gif';
1063
+ } elseif ( 'video' === $limit_file_type ) {
1064
+ $limit_types = 'mpg,mov,flv,mp4';
1065
+ } elseif ( 'audio' === $limit_file_type ) {
1066
+ $limit_types = 'mp3,m4a,wav,wma';
1067
+ } elseif ( 'text' === $limit_file_type ) {
1068
+ $limit_types = 'txt,rtx,csv,tsv';
1069
+ } elseif ( 'any' === $limit_file_type ) {
1070
+ $limit_types = '';
1071
+ } else {
1072
+ $limit_types = pods_v( $field['type'] . '_allowed_extensions', $field['options'], '', true );
1073
+ }
1074
 
1075
+ $limit_types = trim( str_replace( array( ' ', '.', "\n", "\t", ';' ), array(
1076
+ '',
1077
+ ',',
1078
+ ',',
1079
+ ','
1080
+ ), $limit_types ), ',' );
1081
 
1082
+ $mime_types = wp_get_mime_types();
 
1083
 
1084
+ if ( in_array( $limit_file_type, array( 'images', 'audio', 'video' ), true ) ) {
1085
+ $new_limit_types = array();
 
1086
 
1087
+ foreach ( $mime_types as $type => $mime ) {
1088
+ if ( 0 === strpos( $mime, $limit_file_type ) ) {
1089
+ $type = explode( '|', $type );
1090
 
1091
+ $new_limit_types = array_merge( $new_limit_types, $type );
1092
+ }
1093
+ }
 
 
1094
 
1095
+ if ( ! empty( $new_limit_types ) ) {
1096
+ $limit_types = implode( ',', $new_limit_types );
1097
+ }
1098
+ } elseif ( 'any' != $limit_file_type ) {
1099
+ $new_limit_types = array();
1100
 
1101
+ $limit_types = explode( ',', $limit_types );
 
1102
 
1103
+ foreach ( $limit_types as $k => $limit_type ) {
1104
+ $found = false;
 
1105
 
1106
+ foreach ( $mime_types as $type => $mime ) {
1107
+ if ( 0 === strpos( $mime, $limit_type ) ) {
1108
+ $type = explode( '|', $type );
 
1109
 
1110
+ foreach ( $type as $t ) {
1111
+ if ( ! in_array( $t, $new_limit_types, true ) ) {
1112
+ $new_limit_types[] = $t;
1113
+ }
1114
+ }
1115
 
1116
+ $found = true;
1117
+ }
1118
+ }
1119
 
1120
+ if ( ! $found ) {
1121
+ $new_limit_types[] = $limit_type;
1122
+ }
1123
+ }
1124
 
1125
+ if ( ! empty( $new_limit_types ) ) {
1126
+ $limit_types = implode( ',', $new_limit_types );
1127
+ }
1128
+ }
1129
 
1130
+ $limit_types = explode( ',', $limit_types );
1131
 
1132
+ $limit_types = array_filter( array_unique( $limit_types ) );
 
1133
 
1134
+ if ( ! empty( $limit_types ) ) {
1135
+ $ok = false;
1136
 
1137
+ foreach ( $limit_types as $limit_type ) {
1138
+ $limit_type = '.' . trim( $limit_type, ' .' );
1139
 
1140
+ $pos = ( strlen( $file['name'] ) - strlen( $limit_type ) );
 
1141
 
1142
+ if ( $pos === stripos( $file['name'], $limit_type ) ) {
1143
+ $ok = true;
 
1144
 
1145
+ break;
1146
+ }
1147
+ }
1148
 
1149
+ if ( false === $ok ) {
1150
+ $error = __( 'File type not allowed, please use one of the following: %s', 'pods' );
1151
+ $error = sprintf( $error, '.' . implode( ', .', $limit_types ) );
1152
 
1153
+ pods_error( '<div style="color:#FF0000">Error: ' . $error . '</div>' );
1154
+ }
1155
+ }
1156
 
1157
+ $custom_handler = apply_filters( 'pods_upload_handle', null, 'Filedata', $params->post_id, $params, $field );
 
1158
 
1159
+ if ( null === $custom_handler ) {
1160
+ $attachment_id = media_handle_upload( 'Filedata', $params->post_id );
1161
 
1162
+ if ( is_object( $attachment_id ) ) {
1163
+ $errors = array();
1164
 
1165
+ foreach ( $attachment_id->errors['upload_error'] as $error_code => $error_message ) {
1166
+ $errors[] = '[' . $error_code . '] ' . $error_message;
1167
+ }
1168
 
1169
+ pods_error( '<div style="color:#FF0000">Error: ' . implode( '</div><div>', $errors ) . '</div>' );
1170
+ } else {
1171
+ $attachment = get_post( $attachment_id, ARRAY_A );
 
1172
 
1173
+ $attachment['filename'] = basename( $attachment['guid'] );
1174
 
1175
+ $thumb = wp_get_attachment_image_src( $attachment['ID'], 'thumbnail', true );
 
1176
 
1177
+ $attachment['thumbnail'] = '';
1178
 
1179
+ if ( ! empty( $thumb[0] ) ) {
1180
+ $attachment['thumbnail'] = $thumb[0];
1181
  }
1182
 
1183
+ $attachment['link'] = get_permalink( $attachment['ID'] );
1184
+ $attachment['edit_link'] = get_edit_post_link( $attachment['ID'] );
1185
+ $attachment['download'] = wp_get_attachment_url( $attachment['ID'] );
1186
+
1187
+ $attachment = apply_filters( 'pods_upload_attachment', $attachment, $params->post_id );
1188
 
1189
+ wp_send_json( $attachment );
1190
+ }
1191
+ }
1192
+ }
1193
+
1194
+ die(); // KBAI!
1195
+
1196
+ }
1197
 
 
 
1198
  }
classes/fields/link.php ADDED
@@ -0,0 +1,406 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once( PODS_DIR . 'classes/fields/website.php' );
3
+
4
+ /**
5
+ * @package Pods\Fields
6
+ */
7
+ class PodsField_Link extends PodsField_Website {
8
+
9
+ /**
10
+ * Field Type Group
11
+ *
12
+ * @var string
13
+ * @since 2.0
14
+ */
15
+ public static $group = 'Text';
16
+
17
+ /**
18
+ * Field Type Identifier
19
+ *
20
+ * @var string
21
+ * @since 2.0
22
+ */
23
+ public static $type = 'link';
24
+
25
+ /**
26
+ * Field Type Label
27
+ *
28
+ * @var string
29
+ * @since 2.0
30
+ */
31
+ public static $label = 'Link';
32
+
33
+ /**
34
+ * Field Type Preparation
35
+ *
36
+ * @var string
37
+ * @since 2.0
38
+ */
39
+ public static $prepare = '%s';
40
+
41
+ /**
42
+ * Do things like register/enqueue scripts and stylesheets
43
+ *
44
+ * @since 2.0
45
+ */
46
+ public function __construct() {
47
+ self::$label = __( 'Link', 'pods' );
48
+ }
49
+
50
+ /**
51
+ * Add options and set defaults to
52
+ *
53
+ * @param array $options
54
+ *
55
+ * @since 2.0
56
+ */
57
+ public function options() {
58
+
59
+ $options = array(
60
+ self::$type . '_format' => array(
61
+ 'label' => __( 'Format', 'pods' ),
62
+ 'default' => 'normal',
63
+ 'type' => 'pick',
64
+ 'data' => array(
65
+ 'none' => __( 'No URL format restrictions', 'pods' ),
66
+ 'normal' => __( 'http://example.com/', 'pods' ),
67
+ 'no-www' => __( 'http://example.com/ (remove www)', 'pods' ),
68
+ 'force-www' => __( 'http://www.example.com/ (force www if no sub-domain provided)', 'pods' ),
69
+ 'no-http' => __( 'example.com', 'pods' ),
70
+ 'no-http-no-www' => __( 'example.com (force removal of www)', 'pods' ),
71
+ 'no-http-force-www' => __( 'www.example.com (force www if no sub-domain provided)', 'pods' )
72
+ )
73
+ ),
74
+ self::$type . '_select_existing' => array(
75
+ 'label' => __( 'Enable Selecting from Existing Links?', 'pods' ),
76
+ 'default' => 1,
77
+ 'type' => 'boolean',
78
+ 'dependency' => true
79
+ ),
80
+ self::$type . '_new_window' => array(
81
+ 'label' => __( 'Open link in new window by default?', 'pods' ),
82
+ 'default' => apply_filters( 'pods_form_ui_field_link_new_window', 0, self::$type ),
83
+ 'type' => 'boolean',
84
+ 'dependency' => false
85
+ ),
86
+ 'output_options' => array(
87
+ 'label' => __( 'Link Text Output Options', 'pods' ),
88
+ 'group' => array(
89
+ self::$type . '_allow_shortcode' => array(
90
+ 'label' => __( 'Allow Shortcodes?', 'pods' ),
91
+ 'default' => 0,
92
+ 'type' => 'boolean',
93
+ 'dependency' => true
94
+ ),
95
+ self::$type . '_allow_html' => array(
96
+ 'label' => __( 'Allow HTML?', 'pods' ),
97
+ 'default' => 0,
98
+ 'type' => 'boolean',
99
+ 'dependency' => true
100
+ )
101
+ )
102
+ ),
103
+ self::$type . '_allowed_html_tags' => array(
104
+ 'label' => __( 'Allowed HTML Tags', 'pods' ),
105
+ 'depends-on' => array( self::$type . '_allow_html' => true ),
106
+ 'default' => 'strong em a ul ol li b i',
107
+ 'type' => 'text'
108
+ ),
109
+ /*self::$type . '_max_length' => array(
110
+ 'label' => __( 'Maximum Length', 'pods' ),
111
+ 'default' => 255,
112
+ 'type' => 'number',
113
+ 'help' => __( 'Set to -1 for no limit', 'pods' )
114
+ ),*/
115
+ self::$type . '_html5' => array(
116
+ 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
117
+ 'default' => apply_filters( 'pods_form_ui_field_html5', 0, self::$type ),
118
+ 'type' => 'boolean'
119
+ )/*,
120
+ self::$type . '_size' => array(
121
+ 'label' => __( 'Field Size', 'pods' ),
122
+ 'default' => 'medium',
123
+ 'type' => 'pick',
124
+ 'data' => array(
125
+ 'small' => __( 'Small', 'pods' ),
126
+ 'medium' => __( 'Medium', 'pods' ),
127
+ 'large' => __( 'Large', 'pods' )
128
+ )
129
+ )*/
130
+ );
131
+
132
+ return $options;
133
+
134
+ }
135
+
136
+ /**
137
+ * Define the current field's schema for DB table storage
138
+ *
139
+ * @param array $options
140
+ *
141
+ * @return string
142
+ * @since 2.0
143
+ */
144
+ public function schema( $options = null ) {
145
+
146
+ $schema = 'LONGTEXT';
147
+
148
+ return $schema;
149
+
150
+ }
151
+
152
+ /**
153
+ * Change the value of the field
154
+ *
155
+ * @param mixed $value
156
+ * @param string $name
157
+ * @param array $options
158
+ * @param array $pod
159
+ * @param int $id
160
+ *
161
+ * @return mixed|null|string
162
+ * @since 2.3
163
+ */
164
+ public function value( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
165
+
166
+ return $value;
167
+
168
+ }
169
+
170
+ /**
171
+ * Change the way the value of the field is displayed with Pods::get
172
+ *
173
+ * @param mixed $value
174
+ * @param string $name
175
+ * @param array $options
176
+ * @param array $pod
177
+ * @param int $id
178
+ *
179
+ * @return mixed|null|string
180
+ * @since 2.0
181
+ */
182
+ public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
183
+
184
+ // Validate for an array because display is also used for the get_post_meta filters along the function chain
185
+ if ( ! is_array( $value ) ) {
186
+ return $value;
187
+ }
188
+
189
+ // Ensure proper format
190
+ $value = $this->pre_save( $value, $id, $name, $options, null, $pod );
191
+
192
+ if ( ! empty( $value['text'] ) ) {
193
+ $value['text'] = $this->strip_html( $value['text'], $options );
194
+ }
195
+
196
+ if ( ! empty( $value['url'] ) ) {
197
+
198
+ $link = '<a href="%s"%s>%s</a>';
199
+
200
+ // Build the URL
201
+ $url = $this->build_url( parse_url( $value['url'] ) );
202
+
203
+ // Display URL as text by default. If text provided, use the text input
204
+ $text = $url;
205
+
206
+ if ( ! empty( $value['text'] ) ) {
207
+ $text = $value['text'];
208
+ }
209
+
210
+ $atts = '';
211
+
212
+ if ( ! empty( $value['target'] ) ||
213
+ ( ! isset( $value['target'] ) && 1 == pods_var( self::$type . '_new_window', $options ) )
214
+ ) {
215
+ // Possible support for other targets in future
216
+ $atts .= ' target="' . esc_attr( $value['target'] ) . '"';
217
+ }
218
+
219
+ // Do shortcodes if this is enabled
220
+ if ( 1 == pods_var( self::$type . '_allow_shortcode', $options ) ) {
221
+ $text = do_shortcode( $text );
222
+ }
223
+
224
+ // Return the value
225
+ $value = sprintf( $link, esc_url( $url ), $atts, $text );
226
+
227
+ } elseif ( ! empty( $value['text'] ) ) {
228
+ // No URL data found (probably database error), return text is this is available
229
+ $value = $value['text'];
230
+ }
231
+
232
+ // Return database value or display value if above conditions are met
233
+ return $value;
234
+
235
+ }
236
+
237
+ /**
238
+ * Change the way the a list of values of the field are displayed with Pods::field
239
+ *
240
+ * @param mixed|null $value
241
+ * @param string|null $name
242
+ * @param array|null $options
243
+ * @param array|null $pod
244
+ * @param int|null $id
245
+ *
246
+ * @return mixed|null|string
247
+ *
248
+ * @since 2.7
249
+ */
250
+ public function display_list( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
251
+
252
+ return call_user_func_array( array( $this, 'display' ), func_get_args() );
253
+
254
+ }
255
+
256
+ /**
257
+ * Customize output of the form field
258
+ *
259
+ * @param string $name
260
+ * @param mixed $value
261
+ * @param array $options
262
+ * @param array $pod
263
+ * @param int $id
264
+ *
265
+ * @since 2.0
266
+ */
267
+ public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
268
+
269
+ $options = (array) $options;
270
+ $form_field_type = PodsForm::$field_type;
271
+ $field_type = 'link';
272
+
273
+ // Ensure proper format
274
+ $value = $this->pre_save( $value, $id, $name, $options, null, $pod );
275
+
276
+ pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
277
+
278
+ }
279
+
280
+ /**
281
+ * Validate a value before it's saved
282
+ *
283
+ * @param mixed $value
284
+ * @param string $name
285
+ * @param array $options
286
+ * @param array $fields
287
+ * @param array $pod
288
+ * @param int $id
289
+ *
290
+ * @return bool|array
291
+ *
292
+ * @since 2.0
293
+ */
294
+ public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
295
+
296
+ $errors = array();
297
+
298
+ $label = strip_tags( pods_var_raw( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) ) );
299
+
300
+ $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
301
+
302
+ $check = $check['url'];
303
+
304
+ if ( is_array( $check ) ) {
305
+ $errors = $check;
306
+ } else {
307
+ if ( ! empty( $value['url'] ) && 0 < strlen( $value['url'] ) && strlen( $check ) < 1 ) {
308
+ if ( 1 == pods_var( 'required', $options ) ) {
309
+ $errors[] = sprintf( __( 'The %s field is required.', 'pods' ), $label );
310
+ } else {
311
+ $errors[] = sprintf( __( 'Invalid link provided for the field %s.', 'pods' ), $label );
312
+ }
313
+ }
314
+ }
315
+
316
+ if ( ! empty( $errors ) ) {
317
+ return $errors;
318
+ }
319
+
320
+ return true;
321
+
322
+ }
323
+
324
+ /**
325
+ * Change the value or perform actions after validation but before saving to the DB
326
+ *
327
+ * @param mixed $value
328
+ * @param int $id
329
+ * @param string $name
330
+ * @param array $options
331
+ * @param array $fields
332
+ * @param array $pod
333
+ * @param object $params
334
+ *
335
+ * @return array
336
+ *
337
+ * @since 2.0
338
+ */
339
+ public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
340
+
341
+ $options = (array) $options;
342
+
343
+ // Update from a single (non array) input field (like website) if the field updates
344
+ if ( is_string( $value ) ) {
345
+ $value = array( 'url' => $value );
346
+ }
347
+
348
+ $value = array_merge( array( 'url' => '', 'text' => '', 'target' => '' ), (array) $value );
349
+
350
+ // Start URL format
351
+ if ( ! empty( $value['url'] ) ) {
352
+ $value['url'] = $this->validate_url( $value['url'], $options );
353
+ }
354
+
355
+ // Start Title format
356
+ if ( ! empty( $value['text'] ) ) {
357
+ $value['text'] = $this->strip_html( $value['text'], $options );
358
+ }
359
+
360
+ // Start Target format
361
+ if ( ! empty( $value['target'] ) ) {
362
+ $value['target'] = $this->validate_target( $value['target'] );
363
+ } elseif ( ! isset( $value['target'] ) && 1 == pods_v( self::$type . '_new_window', $options, 0 ) ) {
364
+ $value['target'] = '_blank';
365
+ }
366
+
367
+ return $value;
368
+
369
+ }
370
+
371
+ /**
372
+ * Init the editor needed for WP Link modal to work
373
+ */
374
+ public function validate_link_modal() {
375
+
376
+ static $init;
377
+
378
+ if ( empty( $init ) ) {
379
+ if ( ! did_action( 'wp_enqueue_editor' ) ) {
380
+ add_action( 'shutdown', array( $this, 'add_link_modal' ) );
381
+ }
382
+ }
383
+
384
+ $init = true;
385
+
386
+ }
387
+
388
+ /**
389
+ * Echo the link modal code
390
+ */
391
+ public function add_link_modal() {
392
+
393
+ if ( ! class_exists( '_WP_Editors', false ) && file_exists( ABSPATH . WPINC . '/class-wp-editor.php' ) ) {
394
+ require_once( ABSPATH . WPINC . '/class-wp-editor.php' );
395
+ }
396
+
397
+ if ( class_exists( '_WP_Editors' ) && method_exists( '_WP_Editors', 'wp_link_dialog' ) ) {
398
+ _WP_Editors::wp_link_dialog();
399
+ } else {
400
+ echo '<div style="display:none;">';
401
+ wp_editor( '', 'pods-link-editor-hidden' );
402
+ echo '</div>';
403
+ }
404
+
405
+ }
406
+ }
classes/fields/number.php CHANGED
@@ -54,7 +54,7 @@ class PodsField_Number extends PodsField {
54
  */
55
  public function options () {
56
  $options = array(
57
- self::$type . '_repeatable' => array(
58
  'label' => __( 'Repeatable Field', 'pods' ),
59
  'default' => 0,
60
  'type' => 'boolean',
@@ -63,7 +63,7 @@ class PodsField_Number extends PodsField {
63
  'dependency' => true,
64
  'developer_mode' => true
65
  ),
66
- self::$type . '_format_type' => array(
67
  'label' => __( 'Input Type', 'pods' ),
68
  'default' => 'number',
69
  'type' => 'pick',
@@ -73,7 +73,7 @@ class PodsField_Number extends PodsField {
73
  ),
74
  'dependency' => true
75
  ),
76
- self::$type . '_format' => array(
77
  'label' => __( 'Format', 'pods' ),
78
  'default' => apply_filters( 'pods_form_ui_field_number_format_default', 'i18n' ),
79
  'type' => 'pick',
@@ -86,44 +86,53 @@ class PodsField_Number extends PodsField {
86
  '9999,99' => '1234,00'
87
  )
88
  ),
89
- self::$type . '_decimals' => array(
90
  'label' => __( 'Decimals', 'pods' ),
91
  'default' => 0,
92
  'type' => 'number',
93
  'dependency' => true
94
  ),
95
- self::$type . '_format_soft' => array(
96
  'label' => __( 'Soft format?', 'pods' ),
97
  'help' => __( 'Remove trailing decimals (0)', 'pods' ),
98
  'default' => 0,
99
  'type' => 'boolean',
100
- 'excludes-on' => array( self::$type . '_decimals' => 0 ),
101
  ),
102
- self::$type . '_step' => array(
103
  'label' => __( 'Slider Increment (Step)', 'pods' ),
104
- 'depends-on' => array( self::$type . '_format_type' => 'slider' ),
105
  'default' => 1,
106
  'type' => 'text'
107
  ),
108
- self::$type . '_min' => array(
109
  'label' => __( 'Minimum Number', 'pods' ),
110
- 'depends-on' => array( self::$type . '_format_type' => 'slider' ),
111
  'default' => 0,
112
  'type' => 'text'
113
  ),
114
- self::$type . '_max' => array(
115
  'label' => __( 'Maximum Number', 'pods' ),
116
- 'depends-on' => array( self::$type . '_format_type' => 'slider' ),
117
  'default' => 100,
118
  'type' => 'text'
119
  ),
120
- self::$type . '_max_length' => array(
121
  'label' => __( 'Maximum Length', 'pods' ),
122
  'default' => 12,
123
  'type' => 'number',
124
  'help' => __( 'Set to -1 for no limit', 'pods' )
125
- )/*,
126
- self::$type . '_size' => array(
 
 
 
 
 
 
 
 
 
127
  'label' => __( 'Field Size', 'pods' ),
128
  'default' => 'medium',
129
  'type' => 'pick',
@@ -137,68 +146,68 @@ class PodsField_Number extends PodsField {
137
  return $options;
138
  }
139
 
140
- /**
141
- * Define the current field's schema for DB table storage
142
- *
143
- * @param array $options
144
- *
145
- * @return array
146
- * @since 2.0
147
- */
148
- public function schema ( $options = null ) {
149
- $length = (int) pods_var( self::$type . '_max_length', $options, 12, null, true );
150
 
151
- if ( $length < 1 || 64 < $length )
152
- $length = 64;
153
 
154
- $decimals = (int) pods_var( self::$type . '_decimals', $options, 0, null, true );
 
 
155
 
156
- if ( $decimals < 1 )
157
- $decimals = 0;
158
- elseif ( 30 < $decimals )
159
- $decimals = 30;
160
 
161
- if ( $length < $decimals )
162
- $decimals = $length;
163
 
164
- $schema = 'DECIMAL(' . $length . ',' . $decimals . ')';
165
 
166
- return $schema;
167
- }
168
 
169
- /**
170
- * Define the current field's preparation for sprintf
171
- *
172
- * @param array $options
173
- *
174
- * @return array
175
- * @since 2.0
176
- */
177
- public function prepare ( $options = null ) {
178
- $format = self::$prepare;
 
179
 
180
- $length = (int) pods_var( self::$type . '_max_length', $options, 12, null, true );
181
 
182
- if ( $length < 1 || 64 < $length )
183
- $length = 64;
 
184
 
185
- $decimals = (int) pods_var( self::$type . '_decimals', $options, 0, null, true );
186
 
187
- if ( $decimals < 1 )
188
- $decimals = 0;
189
- elseif ( 30 < $decimals )
190
- $decimals = 30;
191
 
192
- if ( $length < $decimals )
193
- $decimals = $length;
 
 
194
 
195
- if ( 0 < $decimals )
196
- $format = '%F';
197
- else
198
- $format = '%d';
199
 
200
- return $format;
201
- }
 
 
 
 
 
 
 
202
 
203
  /**
204
  * Change the way the value of the field is displayed with Pods::get
@@ -218,50 +227,56 @@ class PodsField_Number extends PodsField {
218
  return $value;
219
  }
220
 
221
- /**
222
- * Customize output of the form field
223
- *
224
- * @param string $name
225
- * @param mixed $value
226
- * @param array $options
227
- * @param array $pod
228
- * @param int $id
229
- *
230
- * @since 2.0
231
- */
232
- public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
233
- $options = (array) $options;
234
- $form_field_type = PodsForm::$field_type;
235
-
236
- if ( is_array( $value ) )
237
- $value = implode( '', $value );
238
-
239
- if ( 'slider' == pods_var( self::$type . '_format_type', $options, 'number' ) )
240
- $field_type = 'slider';
241
- else
242
- $field_type = 'number';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
 
244
- if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) {
245
- if ( pods_var( 'read_only', $options, false ) ) {
246
- $options[ 'readonly' ] = true;
247
-
248
- $field_type = 'text';
249
-
250
- $value = $this->format( $value, $name, $options, $pod, $id );
251
- }
252
- else
253
- return;
254
- }
255
- elseif ( !pods_has_permissions( $options ) && pods_var( 'read_only', $options, false ) ) {
256
- $options[ 'readonly' ] = true;
257
-
258
- $field_type = 'text';
259
-
260
- $value = $this->format( $value, $name, $options, $pod, $id );
261
- }
262
-
263
- pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
264
- }
265
 
266
  /**
267
  * Build regex necessary for JS validation
@@ -276,32 +291,10 @@ class PodsField_Number extends PodsField {
276
  * @since 2.0
277
  */
278
  public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
279
- global $wp_locale;
280
 
281
- if ( '9.999,99' == pods_var( self::$type . '_format', $options ) ) {
282
- $thousands = '.';
283
- $dot = ',';
284
- }
285
- elseif ( '9,999.99' == pods_var( self::$type . '_format', $options ) ) {
286
- $thousands = ',';
287
- $dot = '.';
288
- }
289
- elseif ( '9 999,99' == pods_var( self::$type . '_format', $options ) ) {
290
- $thousands = ' ';
291
- $dot = ',';
292
- }
293
- elseif ( '9999.99' == pods_var( self::$type . '_format', $options ) ) {
294
- $thousands = '';
295
- $dot = '.';
296
- }
297
- elseif ( '9999,99' == pods_var( self::$type . '_format', $options ) ) {
298
- $thousands = '';
299
- $dot = ',';
300
- }
301
- else {
302
- $thousands = html_entity_decode( $wp_locale->number_format['thousands_sep'] );
303
- $dot = $wp_locale->number_format[ 'decimal_point' ];
304
- }
305
 
306
  return '\-*[0-9\\' . implode( '\\', array_filter( array( $dot, $thousands ) ) ) . ']+';
307
  }
@@ -321,35 +314,13 @@ class PodsField_Number extends PodsField {
321
  * @since 2.0
322
  */
323
  public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
324
- global $wp_locale;
325
 
326
- if ( '9.999,99' == pods_var( self::$type . '_format', $options ) ) {
327
- $thousands = '.';
328
- $dot = ',';
329
- }
330
- elseif ( '9,999.99' == pods_var( self::$type . '_format', $options ) ) {
331
- $thousands = ',';
332
- $dot = '.';
333
- }
334
- elseif ( '9 999,99' == pods_var( self::$type . '_format', $options ) ) {
335
- $thousands = ' ';
336
- $dot = ',';
337
- }
338
- elseif ( '9999.99' == pods_var( self::$type . '_format', $options ) ) {
339
- $thousands = ',';
340
- $dot = '.';
341
- }
342
- elseif ( '9999,99' == pods_var( self::$type . '_format', $options ) ) {
343
- $thousands = '.';
344
- $dot = ',';
345
- }
346
- else {
347
- $thousands = html_entity_decode( $wp_locale->number_format['thousands_sep'] );
348
- $dot = $wp_locale->number_format[ 'decimal_point' ];
349
- }
350
 
351
  $check = str_replace(
352
- array( $thousands, $dot, html_entity_decode($thousands) ),
353
  array( '', '.', '' ),
354
  $value
355
  );
@@ -357,10 +328,11 @@ class PodsField_Number extends PodsField {
357
 
358
  $check = preg_replace( '/[0-9\.\-\s]/', '', $check );
359
 
360
- $label = pods_var( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) );
361
 
362
- if ( 0 < strlen( $check ) )
363
- return sprintf( __( '%s is not numeric', 'pods' ), $label );
 
364
 
365
  return true;
366
  }
@@ -380,53 +352,17 @@ class PodsField_Number extends PodsField {
380
  * @since 2.0
381
  */
382
  public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
383
- global $wp_locale;
384
 
385
- if ( '9.999,99' == pods_var( self::$type . '_format', $options ) ) {
386
- $thousands = '.';
387
- $dot = ',';
388
- }
389
- elseif ( '9,999.99' == pods_var( self::$type . '_format', $options ) ) {
390
- $thousands = ',';
391
- $dot = '.';
392
- }
393
- elseif ( '9 999,99' == pods_var( self::$type . '_format', $options ) ) {
394
- $thousands = ' ';
395
- $dot = ',';
396
- }
397
- elseif ( '9999.99' == pods_var( self::$type . '_format', $options ) ) {
398
- $thousands = ',';
399
- $dot = '.';
400
- }
401
- elseif ( '9999,99' == pods_var( self::$type . '_format', $options ) ) {
402
- $thousands = '.';
403
- $dot = ',';
404
- }
405
- else {
406
- $thousands = html_entity_decode( $wp_locale->number_format['thousands_sep'] );
407
- $dot = $wp_locale->number_format[ 'decimal_point' ];
408
- }
409
 
410
  $value = str_replace( array( $thousands, $dot ), array( '', '.' ), $value );
411
- $value = trim( $value );
412
 
413
  $value = preg_replace( '/[^0-9\.\-]/', '', $value );
414
 
415
- $length = (int) pods_var( self::$type . '_max_length', $options, 12, null, true );
416
-
417
- if ( $length < 1 || 64 < $length )
418
- $length = 64;
419
-
420
- $decimals = (int) pods_var( self::$type . '_decimals', $options, 0, null, true );
421
-
422
- if ( $decimals < 1 )
423
- $decimals = 0;
424
- elseif ( 30 < $decimals )
425
- $decimals = 30;
426
-
427
- if ( $length < $decimals )
428
- $decimals = $length;
429
-
430
  $value = number_format( (float) $value, $decimals, '.', '' );
431
 
432
  return $value;
@@ -462,60 +398,26 @@ class PodsField_Number extends PodsField {
462
  * @since 2.0
463
  */
464
  public function format ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
465
- global $wp_locale;
466
-
467
- if ( null === $value ) {
468
- // Don't enforce a default value here
469
- return null;
470
- }
471
-
472
- if ( '9.999,99' == pods_var( self::$type . '_format', $options ) ) {
473
- $thousands = '.';
474
- $dot = ',';
475
- }
476
- elseif ( '9,999.99' == pods_var( self::$type . '_format', $options ) ) {
477
- $thousands = ',';
478
- $dot = '.';
479
- }
480
- elseif ( '9 999,99' == pods_var( self::$type . '_format', $options ) ) {
481
- $thousands = ' ';
482
- $dot = ',';
483
- }
484
- elseif ( '9999.99' == pods_var( self::$type . '_format', $options ) ) {
485
- $thousands = '';
486
- $dot = '.';
487
- }
488
- elseif ( '9999,99' == pods_var( self::$type . '_format', $options ) ) {
489
- $thousands = '';
490
- $dot = ',';
491
- }
492
- else {
493
- $thousands = $wp_locale->number_format[ 'thousands_sep' ];
494
- $dot = $wp_locale->number_format[ 'decimal_point' ];
495
- }
496
 
497
- $length = (int) pods_var( self::$type . '_max_length', $options, 12, null, true );
 
 
 
498
 
499
- if ( $length < 1 || 64 < $length )
500
- $length = 64;
 
 
501
 
502
- $decimals = (int) pods_var( self::$type . '_decimals', $options, 0, null, true );
503
-
504
- if ( $decimals < 1 )
505
- $decimals = 0;
506
- elseif ( 30 < $decimals )
507
- $decimals = 30;
508
-
509
- if ( $length < $decimals )
510
- $decimals = $length;
511
-
512
- if ( 'i18n' == pods_var( self::$type . '_format', $options ) )
513
- $value = number_format_i18n( (float) $value, $decimals );
514
- else
515
- $value = number_format( (float) $value, $decimals, $dot, $thousands );
516
 
517
  // Optionally remove trailing decimal zero's.
518
- if ( pods_v( self::$type . '_format_soft', $options, 0 ) ) {
519
  $parts = explode( $dot, $value );
520
  if ( isset( $parts[1] ) ) {
521
  $parts[1] = rtrim( $parts[1], '0' );
@@ -526,4 +428,86 @@ class PodsField_Number extends PodsField {
526
 
527
  return $value;
528
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
  }
54
  */
55
  public function options () {
56
  $options = array(
57
+ static::$type . '_repeatable' => array(
58
  'label' => __( 'Repeatable Field', 'pods' ),
59
  'default' => 0,
60
  'type' => 'boolean',
63
  'dependency' => true,
64
  'developer_mode' => true
65
  ),
66
+ static::$type . '_format_type' => array(
67
  'label' => __( 'Input Type', 'pods' ),
68
  'default' => 'number',
69
  'type' => 'pick',
73
  ),
74
  'dependency' => true
75
  ),
76
+ static::$type . '_format' => array(
77
  'label' => __( 'Format', 'pods' ),
78
  'default' => apply_filters( 'pods_form_ui_field_number_format_default', 'i18n' ),
79
  'type' => 'pick',
86
  '9999,99' => '1234,00'
87
  )
88
  ),
89
+ static::$type . '_decimals' => array(
90
  'label' => __( 'Decimals', 'pods' ),
91
  'default' => 0,
92
  'type' => 'number',
93
  'dependency' => true
94
  ),
95
+ static::$type . '_format_soft' => array(
96
  'label' => __( 'Soft format?', 'pods' ),
97
  'help' => __( 'Remove trailing decimals (0)', 'pods' ),
98
  'default' => 0,
99
  'type' => 'boolean',
100
+ 'excludes-on' => array( static::$type . '_decimals' => 0 ),
101
  ),
102
+ static::$type . '_step' => array(
103
  'label' => __( 'Slider Increment (Step)', 'pods' ),
104
+ 'depends-on' => array( static::$type . '_format_type' => 'slider' ),
105
  'default' => 1,
106
  'type' => 'text'
107
  ),
108
+ static::$type . '_min' => array(
109
  'label' => __( 'Minimum Number', 'pods' ),
110
+ 'depends-on' => array( static::$type . '_format_type' => 'slider' ),
111
  'default' => 0,
112
  'type' => 'text'
113
  ),
114
+ static::$type . '_max' => array(
115
  'label' => __( 'Maximum Number', 'pods' ),
116
+ 'depends-on' => array( static::$type . '_format_type' => 'slider' ),
117
  'default' => 100,
118
  'type' => 'text'
119
  ),
120
+ static::$type . '_max_length' => array(
121
  'label' => __( 'Maximum Length', 'pods' ),
122
  'default' => 12,
123
  'type' => 'number',
124
  'help' => __( 'Set to -1 for no limit', 'pods' )
125
+ ),
126
+ static::$type . '_placeholder' => array(
127
+ 'label' => __( 'HTML Placeholder', 'pods' ),
128
+ 'default' => '',
129
+ 'type' => 'text',
130
+ 'help' => array(
131
+ __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
132
+ 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
133
+ ),
134
+ ),/*,
135
+ static::$type . '_size' => array(
136
  'label' => __( 'Field Size', 'pods' ),
137
  'default' => 'medium',
138
  'type' => 'pick',
146
  return $options;
147
  }
148
 
149
+ /**
150
+ * Define the current field's schema for DB table storage
151
+ *
152
+ * @param array $options
153
+ *
154
+ * @return string
155
+ * @since 2.0
156
+ */
157
+ public function schema( $options = null ) {
 
158
 
159
+ $length = (int) pods_v( static::$type . '_max_length', $options, 12, true );
 
160
 
161
+ if ( $length < 1 || 64 < $length ) {
162
+ $length = 64;
163
+ }
164
 
165
+ $decimals = $this->get_max_decimals( $options );
 
 
 
166
 
167
+ $schema = 'DECIMAL(' . $length . ',' . $decimals . ')';
 
168
 
169
+ return $schema;
170
 
171
+ }
 
172
 
173
+ /**
174
+ * Define the current field's preparation for sprintf
175
+ *
176
+ * @param array $options
177
+ *
178
+ * @return string
179
+ * @since 2.0
180
+ */
181
+ public function prepare( $options = null ) {
182
+
183
+ $format = static::$prepare;
184
 
185
+ $decimals = $this->get_max_decimals( $options );
186
 
187
+ if ( 0 < $decimals ) {
188
+ $format = '%F';
189
+ }
190
 
191
+ return $format;
192
 
193
+ }
 
 
 
194
 
195
+ /**
196
+ * {@inheritdoc}
197
+ */
198
+ public function is_empty( $value = null ) {
199
 
200
+ $is_empty = false;
 
 
 
201
 
202
+ $value += 0;
203
+
204
+ if ( empty( $value ) ) {
205
+ $is_empty = true;
206
+ }
207
+
208
+ return $is_empty;
209
+
210
+ }
211
 
212
  /**
213
  * Change the way the value of the field is displayed with Pods::get
227
  return $value;
228
  }
229
 
230
+ /**
231
+ * Customize output of the form field
232
+ *
233
+ * @param string $name
234
+ * @param mixed $value
235
+ * @param array $options
236
+ * @param array $pod
237
+ * @param int $id
238
+ *
239
+ * @since 2.0
240
+ */
241
+ public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
242
+
243
+ $options = (array) $options;
244
+ $form_field_type = PodsForm::$field_type;
245
+
246
+ if ( is_array( $value ) ) {
247
+ $value = implode( '', $value );
248
+ }
249
+
250
+ if ( 'slider' == pods_v( static::$type . '_format_type', $options, 'number' ) ) {
251
+ $field_type = 'slider';
252
+ }
253
+ else {
254
+ $field_type = static::$type;
255
+ }
256
+
257
+ if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( static::$type, $options[ 'name' ], $options, null, $pod, $id ) ) {
258
+ if ( pods_v( 'read_only', $options, false ) ) {
259
+ $options[ 'readonly' ] = true;
260
+
261
+ $field_type = 'text';
262
+
263
+ $value = $this->format( $value, $name, $options, $pod, $id );
264
+ }
265
+ else {
266
+ return;
267
+ }
268
+ }
269
+ elseif ( !pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) {
270
+ $options[ 'readonly' ] = true;
271
+
272
+ $field_type = 'text';
273
+
274
+ $value = $this->format( $value, $name, $options, $pod, $id );
275
+ }
276
+
277
+ pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
278
 
279
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
 
281
  /**
282
  * Build regex necessary for JS validation
291
  * @since 2.0
292
  */
293
  public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
 
294
 
295
+ $format_args = $this->get_number_format_args( $options );
296
+ $thousands = $format_args['thousands'];
297
+ $dot = $format_args['dot'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
 
299
  return '\-*[0-9\\' . implode( '\\', array_filter( array( $dot, $thousands ) ) ) . ']+';
300
  }
314
  * @since 2.0
315
  */
316
  public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
 
317
 
318
+ $format_args = $this->get_number_format_args( $options );
319
+ $thousands = $format_args['thousands'];
320
+ $dot = $format_args['dot'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
 
322
  $check = str_replace(
323
+ array( $thousands, $dot, html_entity_decode( $thousands ) ),
324
  array( '', '.', '' ),
325
  $value
326
  );
328
 
329
  $check = preg_replace( '/[0-9\.\-\s]/', '', $check );
330
 
331
+ $label = pods_v( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) );
332
 
333
+ if ( 0 < strlen( $check ) ) {
334
+ return sprintf( __( '%s is not numeric', 'pods' ), $label );
335
+ }
336
 
337
  return true;
338
  }
352
  * @since 2.0
353
  */
354
  public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
 
355
 
356
+ $format_args = $this->get_number_format_args( $options );
357
+ $thousands = $format_args['thousands'];
358
+ $dot = $format_args['dot'];
359
+ $decimals = $format_args['decimals'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
 
361
  $value = str_replace( array( $thousands, $dot ), array( '', '.' ), $value );
362
+ $value = trim( $value );
363
 
364
  $value = preg_replace( '/[^0-9\.\-]/', '', $value );
365
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  $value = number_format( (float) $value, $decimals, '.', '' );
367
 
368
  return $value;
398
  * @since 2.0
399
  */
400
  public function format ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401
 
402
+ if ( null === $value ) {
403
+ // Don't enforce a default value here.
404
+ return null;
405
+ }
406
 
407
+ $format_args = $this->get_number_format_args( $options );
408
+ $thousands = $format_args['thousands'];
409
+ $dot = $format_args['dot'];
410
+ $decimals = $format_args['decimals'];
411
 
412
+ if ( 'i18n' == pods_v( static::$type . '_format', $options ) ) {
413
+ $value = number_format_i18n( (float) $value, $decimals );
414
+ }
415
+ else {
416
+ $value = number_format( (float) $value, $decimals, $dot, $thousands );
417
+ }
 
 
 
 
 
 
 
 
418
 
419
  // Optionally remove trailing decimal zero's.
420
+ if ( pods_v( static::$type . '_format_soft', $options, 0 ) ) {
421
  $parts = explode( $dot, $value );
422
  if ( isset( $parts[1] ) ) {
423
  $parts[1] = rtrim( $parts[1], '0' );
428
 
429
  return $value;
430
  }
431
+
432
+ /**
433
+ * Get the formatting arguments for numbers.
434
+ * @since 2.7
435
+ * @param array $options Field options.
436
+ * @return array {
437
+ * @type string $thousands
438
+ * @type string $dot
439
+ * @type int $decimals
440
+ * }
441
+ */
442
+ public function get_number_format_args( $options ) {
443
+ global $wp_locale;
444
+
445
+ if ( '9.999,99' == pods_v( static::$type . '_format', $options ) ) {
446
+ $thousands = '.';
447
+ $dot = ',';
448
+ }
449
+ elseif ( '9,999.99' == pods_v( static::$type . '_format', $options ) ) {
450
+ $thousands = ',';
451
+ $dot = '.';
452
+ }
453
+ elseif ( '9\'999.99' == pods_v( static::$type . '_format', $options ) ) {
454
+ $thousands = '\'';
455
+ $dot = '.';
456
+ }
457
+ elseif ( '9 999,99' == pods_v( static::$type . '_format', $options ) ) {
458
+ $thousands = ' ';
459
+ $dot = ',';
460
+ }
461
+ elseif ( '9999.99' == pods_v( static::$type . '_format', $options ) ) {
462
+ $thousands = '';
463
+ $dot = '.';
464
+ }
465
+ elseif ( '9999,99' == pods_v( static::$type . '_format', $options ) ) {
466
+ $thousands = '';
467
+ $dot = ',';
468
+ }
469
+ else {
470
+ $thousands = $wp_locale->number_format[ 'thousands_sep' ];
471
+ $dot = $wp_locale->number_format[ 'decimal_point' ];
472
+ }
473
+
474
+ $decimals = $this->get_max_decimals( $options );
475
+
476
+ return array(
477
+ 'thousands' => $thousands,
478
+ 'dot' => $dot,
479
+ 'decimals' => $decimals,
480
+ );
481
+ }
482
+
483
+ /**
484
+ * Get the max allowed decimals.
485
+ *
486
+ * @since 2.7
487
+ * @param array $options
488
+ * @return int
489
+ */
490
+ public function get_max_decimals( $options ) {
491
+
492
+ $length = (int) pods_v( static::$type . '_max_length', $options, 12, true );
493
+
494
+ if ( $length < 1 || 64 < $length ) {
495
+ $length = 64;
496
+ }
497
+
498
+ $decimals = (int) pods_v( static::$type . '_decimals', $options, 0 );
499
+
500
+ if ( $decimals < 1 ) {
501
+ $decimals = 0;
502
+ }
503
+ elseif ( 30 < $decimals ) {
504
+ $decimals = 30;
505
+ }
506
+
507
+ if ( $length < $decimals ) {
508
+ $decimals = $length;
509
+ }
510
+
511
+ return $decimals;
512
+ }
513
  }
classes/fields/oembed.php ADDED
@@ -0,0 +1,578 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Pods\Fields
4
+ */
5
+ class PodsField_OEmbed extends PodsField {
6
+
7
+ /**
8
+ * Field Type Group
9
+ *
10
+ * @var string
11
+ * @since 2.0
12
+ */
13
+ public static $group = 'Relationships / Media';
14
+
15
+ /**
16
+ * Field Type Identifier
17
+ *
18
+ * @var string
19
+ * @since 2.0
20
+ */
21
+ public static $type = 'oembed';
22
+
23
+ /**
24
+ * Field Type Label
25
+ *
26
+ * @var string
27
+ * @since 2.0
28
+ */
29
+ public static $label = 'oEmbed';
30
+
31
+ /**
32
+ * Field Type Preparation
33
+ *
34
+ * @var string
35
+ * @since 2.0
36
+ */
37
+ public static $prepare = '%s';
38
+
39
+ /**
40
+ * Available oEmbed providers
41
+ *
42
+ * @var array
43
+ * @since 2.7
44
+ */
45
+ private $providers = array();
46
+
47
+ /**
48
+ * Current embed width
49
+ *
50
+ * @var int
51
+ * @since 2.7
52
+ */
53
+ private $width = 0;
54
+
55
+ /**
56
+ * Current embed height
57
+ *
58
+ * @var int
59
+ * @since 2.7
60
+ */
61
+ private $height = 0;
62
+
63
+ /**
64
+ * Do things like register/enqueue scripts and stylesheets
65
+ *
66
+ * @since 2.0
67
+ */
68
+ public function __construct () {
69
+ self::$label = __( 'oEmbed', 'pods' );
70
+ }
71
+
72
+ /**
73
+ * Add admin_init actions
74
+ *
75
+ * @since 2.3
76
+ */
77
+ public function admin_init() {
78
+ // AJAX for Uploads
79
+ add_action( 'wp_ajax_oembed_update_preview', array( $this, 'admin_ajax_oembed_update_preview' ) );
80
+ }
81
+
82
+ /**
83
+ * Add options and set defaults to
84
+ *
85
+ * @return array
86
+ * @since 2.0
87
+ */
88
+ public function options () {
89
+
90
+ $options = array(
91
+ self::$type . '_repeatable' => array(
92
+ 'label' => __( 'Repeatable Field', 'pods' ),
93
+ 'default' => 0,
94
+ 'type' => 'boolean',
95
+ 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
96
+ 'boolean_yes_label' => '',
97
+ 'dependency' => true,
98
+ 'developer_mode' => true
99
+ ),
100
+ self::$type . '_width' => array(
101
+ 'label' => __( 'Embed Width', 'pods' ),
102
+ 'default' => 0,
103
+ 'type' => 'number',
104
+ 'help' => __( 'Optional width to use for this oEmbed. Leave as 0 (zero) to default to none.', 'pods' )
105
+ ),
106
+ self::$type . '_height' => array(
107
+ 'label' => __( 'Embed Height', 'pods' ),
108
+ 'default' => 0,
109
+ 'type' => 'number',
110
+ 'help' => __( 'Optional height to use for this oEmbed. Leave as 0 (zero) to default to none.', 'pods' )
111
+ ),
112
+ self::$type . '_show_preview' => array(
113
+ 'label' => __( 'Show preview', 'pods' ),
114
+ 'default' => 0,
115
+ 'type' => 'boolean'
116
+ ),
117
+ );
118
+
119
+ // Get all unique provider host names
120
+ $unique_providers = array();
121
+ foreach ( $this->get_providers() as $provider ) {
122
+ if ( ! in_array( $provider['host'], $unique_providers ) )
123
+ $unique_providers[] = $provider['host'];
124
+ }
125
+ sort($unique_providers);
126
+
127
+ // Only add the options if we have data
128
+ if ( ! empty( $unique_providers ) ) {
129
+ $options[ self::$type . '_restrict_providers' ] = array(
130
+ 'label' => __( 'Restrict to providers', 'pods' ),
131
+ 'help' => __( 'Restrict input to specific WordPress oEmbed compatible providers.', 'pods' ),
132
+ 'type' => 'boolean',
133
+ 'default' => 0,
134
+ 'dependency' => true,
135
+ );
136
+ $options[ self::$type . '_enable_providers' ] = array(
137
+ 'label' => __( 'Select enabled providers', 'pods' ),
138
+ 'depends-on' => array( self::$type . '_restrict_providers' => true ),
139
+ 'group' => array()
140
+ );
141
+ // Add all the oEmbed providers
142
+ foreach( $unique_providers as $provider ) {
143
+ $options[ self::$type . '_enable_providers' ]['group'][ self::$type . '_enabled_providers_' . tag_escape( $provider ) ] = array(
144
+ 'label' => $provider,
145
+ 'type' => 'boolean',
146
+ 'default' => 0,
147
+ );
148
+ }
149
+ }
150
+
151
+
152
+ return $options;
153
+ }
154
+
155
+ /**
156
+ * Define the current field's schema for DB table storage
157
+ *
158
+ * @param array $options
159
+ *
160
+ * @return array
161
+ * @since 2.0
162
+ */
163
+ public function schema ( $options = null ) {
164
+ $schema = 'LONGTEXT';
165
+
166
+ return $schema;
167
+ }
168
+
169
+ /**
170
+ * Change the way the value of the field is displayed with Pods::get
171
+ *
172
+ * @param mixed $value
173
+ * @param string $name
174
+ * @param array $options
175
+ * @param array $fields
176
+ * @param array $pod
177
+ * @param int $id
178
+ *
179
+ * @since 2.0
180
+ */
181
+ public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
182
+ $value = $this->pre_save( $value, $id, $name, $options, null, $pod );
183
+
184
+ $width = (int) pods_v( self::$type . '_width', $options );
185
+ $height = (int) pods_v( self::$type . '_height', $options );
186
+ $args = array();
187
+ if ( $width > 0 ) {
188
+ $args['width'] = $width;
189
+ }
190
+ if ( $height > 0 ) {
191
+ $args['height'] = $height;
192
+ }
193
+
194
+ $value = wp_oembed_get( $value, $args );
195
+
196
+ /**
197
+ * @var $embed WP_Embed
198
+ */
199
+ /*$embed = $GLOBALS[ 'wp_embed' ];
200
+
201
+ if ( 0 < $width && 0 < $height ) {
202
+ $this->width = $width;
203
+ $this->height = $height;
204
+
205
+ // Setup [embed] shortcodes with set width/height
206
+ $value = $this->autoembed( $value );
207
+
208
+ // Run [embed] shortcodes
209
+ $value = $embed->run_shortcode( $value );
210
+ } else {
211
+ // Autoembed URL normally
212
+ $value = $embed->autoembed( $value );
213
+ }*/
214
+ return $value;
215
+ }
216
+
217
+ /**
218
+ * Customize output of the form field
219
+ *
220
+ * @param string $name
221
+ * @param mixed $value
222
+ * @param array $options
223
+ * @param array $pod
224
+ * @param int $id
225
+ *
226
+ * @since 2.0
227
+ */
228
+ public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
229
+ $options = (array) $options;
230
+ $form_field_type = PodsForm::$field_type;
231
+
232
+ if ( is_array( $value ) )
233
+ $value = implode( ' ', $value );
234
+
235
+ if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) {
236
+ if ( pods_var( 'read_only', $options, false ) )
237
+ $options[ 'readonly' ] = true;
238
+ else
239
+ return;
240
+ }
241
+ elseif ( !pods_has_permissions( $options ) && pods_var( 'read_only', $options, false ) )
242
+ $options[ 'readonly' ] = true;
243
+
244
+ pods_view( PODS_DIR . 'ui/fields/oembed.php', compact( array_keys( get_defined_vars() ) ) );
245
+ }
246
+
247
+ /**
248
+ * Validate a value before it's saved
249
+ *
250
+ * @param mixed $value
251
+ * @param string $name
252
+ * @param array $options
253
+ * @param array $fields
254
+ * @param array $pod
255
+ * @param int $id
256
+ *
257
+ * @param null $params
258
+ * @return array|bool
259
+ * @since 2.0
260
+ */
261
+ public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
262
+ $errors = array();
263
+
264
+ $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
265
+
266
+ if ( is_array( $check ) )
267
+ $errors = $check;
268
+ else {
269
+ if ( 0 < strlen( $value ) && strlen( $check ) < 1 ) {
270
+ if ( 1 == (bool) pods_v( 'required', $options ) )
271
+ $errors[] = __( 'This field is required.', 'pods' );
272
+ }
273
+ }
274
+
275
+ if ( !empty( $errors ) )
276
+ return $errors;
277
+
278
+ return true;
279
+ }
280
+
281
+ /**
282
+ * Change the value or perform actions after validation but before saving to the DB
283
+ *
284
+ * @param mixed $value
285
+ * @param int $id
286
+ * @param string $name
287
+ * @param array $options
288
+ * @param array $fields
289
+ * @param array $pod
290
+ * @param object $params
291
+ *
292
+ * @return mixed|string
293
+ * @since 2.0
294
+ */
295
+ public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
296
+ $value = $this->strip_html( $value, $options );
297
+
298
+ // Only allow ONE URL
299
+ if ( ! empty( $value ) ) {
300
+ $value = explode( ' ', $value );
301
+ $value = esc_url( $value[0] );
302
+ }
303
+
304
+ if ( $this->validate_provider( $value, $options ) ) {
305
+ return $value;
306
+ } else {
307
+ return false;
308
+ }
309
+
310
+ }
311
+
312
+ /**
313
+ * Customize the Pods UI manage table column output
314
+ *
315
+ * @param int $id
316
+ * @param mixed $value
317
+ * @param string $name
318
+ * @param array $options
319
+ * @param array $fields
320
+ * @param array $pod
321
+ *
322
+ * @return mixed|string
323
+ * @since 2.0
324
+ */
325
+ public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
326
+ $value = $this->pre_save( $value, $id, $name, $options, $fields, $pod );
327
+
328
+ return $value;
329
+ }
330
+
331
+ /**
332
+ * Strip HTML based on options
333
+ *
334
+ * @param string $value
335
+ * @param array $options
336
+ *
337
+ * @return string
338
+ */
339
+ public function strip_html ( $value, $options = null ) {
340
+ if ( is_array( $value ) )
341
+ $value = @implode( ' ', $value );
342
+
343
+ $value = trim( $value );
344
+
345
+ // Strip HTML
346
+ $value = strip_tags( $value );
347
+
348
+ // Strip shortcodes
349
+ $value = strip_shortcodes( $value );
350
+
351
+ return $value;
352
+ }
353
+
354
+ /**
355
+ * Passes any unlinked URLs that are on their own line to {@link WP_Embed::shortcode()} for potential embedding.
356
+ *
357
+ * @see WP_Embed::autoembed()
358
+ * @see WP_Embed::autoembed_callback()
359
+ *
360
+ * @uses PodsField_OEmbed::autoembed_callback()
361
+ *
362
+ * @param string $content The content to be searched.
363
+ * @return string Potentially modified $content.
364
+ *
365
+ * @since 2.7
366
+ */
367
+ public function autoembed( $content ) {
368
+
369
+ // Replace line breaks from all HTML elements with placeholders.
370
+ $content = wp_replace_in_html_tags( $content, array( "\n" => '<!-- wp-line-break -->' ) );
371
+
372
+ // Find URLs that are on their own line.
373
+ $content = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
374
+
375
+ // Put the line breaks back.
376
+ return str_replace( '<!-- wp-line-break -->', "\n", $content );
377
+
378
+ }
379
+
380
+ /**
381
+ * Callback function for {@link WP_Embed::autoembed()}.
382
+ *
383
+ * @param array $match A regex match array.
384
+ * @return string The embed shortcode
385
+ *
386
+ * @since 2.7
387
+ */
388
+ public function autoembed_callback( $match ) {
389
+
390
+ $shortcode = '[embed width="' . $this->width . '" height="' . $this->height . '"]' . $match[2] . '[/embed]';
391
+
392
+ return $shortcode;
393
+
394
+ }
395
+
396
+ /**
397
+ * Get a list of available providers from the WP_oEmbed class
398
+ *
399
+ * @see wp-includes/class-oembed.php
400
+ * @return array $providers {
401
+ * Array of provider data with regex as key
402
+ *
403
+ * @type string URL for this provider
404
+ * @type int
405
+ * @type string Hostname for this provider
406
+ * }
407
+ *
408
+ * @since 2.7
409
+ */
410
+ public function get_providers() {
411
+
412
+ // Return class property if already set
413
+ if ( ! empty( $this->providers ) ) {
414
+ return $this->providers;
415
+ }
416
+
417
+ if ( file_exists( ABSPATH . WPINC . '/class-oembed.php' ) )
418
+ require_once( ABSPATH . WPINC . '/class-oembed.php' );
419
+
420
+ if ( function_exists( '_wp_oembed_get_object' ) ) {
421
+ $wp_oembed = _wp_oembed_get_object();
422
+ $providers = $wp_oembed->providers;
423
+ foreach ( $providers as $key => $provider ) {
424
+ $url = parse_url( $provider[0] );
425
+ $host = $url['host'];
426
+ $tmp = explode('.', $host);
427
+ if ( count( $tmp ) == 3 ) {
428
+ // Take domain names like .co.uk in consideration
429
+ if ( ! in_array( 'co', $tmp ) ) {
430
+ unset( $tmp[0] );
431
+ }
432
+ } elseif ( count( $tmp ) == 4 ) {
433
+ // Take domain names like .co.uk in consideration
434
+ unset( $tmp[0] );
435
+ }
436
+ $host = implode( '.', $tmp );
437
+ $providers[ $key ]['host'] = $host;
438
+ }
439
+ $this->providers = $providers;
440
+ return $providers;
441
+ }
442
+
443
+ // Return an empty array if no providers could be found
444
+ return array();
445
+
446
+ }
447
+
448
+ /**
449
+ * Takes a URL and returns the corresponding oEmbed provider's URL, if there is one.
450
+ * This function is ripped from WP since Pods has support from 3.8 and in the WP core this function is 4.0+
451
+ * We've stripped the autodiscover part from this function to keep it basic
452
+ *
453
+ * @since 2.7
454
+ * @access public
455
+ *
456
+ * @see WP_oEmbed::get_provider()
457
+ *
458
+ * @param string $url The URL to the content.
459
+ * @return false|string False on failure, otherwise the oEmbed provider URL.
460
+ */
461
+ public function get_provider( $url ) {
462
+
463
+ $provider = false;
464
+
465
+ foreach ( $this->providers as $matchmask => $data ) {
466
+ if ( isset( $data['host'] ) ) {
467
+ unset( $data['host'] );
468
+ }
469
+ reset( $data );
470
+
471
+ list( $providerurl, $regex ) = $data;
472
+
473
+ $match = $matchmask;
474
+
475
+ // Turn the asterisk-type provider URLs into regex
476
+ if ( !$regex ) {
477
+ $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i';
478
+ $matchmask = preg_replace( '|^#http\\\://|', '#https?\://', $matchmask );
479
+ }
480
+
481
+ if ( preg_match( $matchmask, $url ) ) {
482
+ //$provider = str_replace( '{format}', 'json', $providerurl ); // JSON is easier to deal with than XML
483
+ $provider = $match;
484
+ break;
485
+ }
486
+ }
487
+
488
+ return $provider;
489
+ }
490
+
491
+ /**
492
+ * Validate a value with the enabled oEmbed providers (if required)
493
+ *
494
+ * @since 2.7
495
+ * @param string $value
496
+ * @param array $options Field options
497
+ * @return bool
498
+ */
499
+ public function validate_provider( $value, $options ) {
500
+
501
+ // Do we even need to validate?
502
+ if ( false == (int) pods_v( self::$type . '_restrict_providers', $options ) ) {
503
+ return true;
504
+ }
505
+
506
+ $providers = $this->get_providers();
507
+
508
+ // Filter existing providers
509
+ foreach( $providers as $key => $provider ) {
510
+ $fieldname = self::$type . '_enabled_providers_' . tag_escape( $provider['host'] );
511
+
512
+ /**
513
+ * @todo Future compat to enable serialised strings as field options
514
+ */
515
+ /*if ( empty( $options[ self::$type . '_enabled_providers_' ][ $provider['host'] ] ) ) {
516
+ unset( $providers[ $key ] );
517
+ } else*/
518
+
519
+ /**
520
+ * Current solution: all separate field options
521
+ */
522
+ if ( empty( $options[ $fieldname ] ) ) {
523
+ unset( $providers[ $key ] );
524
+ }
525
+ }
526
+
527
+ // Value validation
528
+ $provider_match = $this->get_provider( $value );
529
+ foreach ( $providers as $match => $provider ) {
530
+ if ( $provider_match == $match ) {
531
+ return true;
532
+ }
533
+ }
534
+ return false;
535
+ }
536
+
537
+ /**
538
+ * Handle update preview AJAX
539
+ *
540
+ * @since 2.7
541
+ */
542
+ public function admin_ajax_oembed_update_preview() {
543
+
544
+ // Sanitize input
545
+ $params = pods_unslash( (array) $_POST );
546
+
547
+ if ( ! empty( $params['_nonce_pods_oembed'] )
548
+ && ! empty( $params['pods_field_oembed_value'] )
549
+ && wp_verify_nonce( $params['_nonce_pods_oembed'], 'pods_field_oembed_preview' )
550
+ ) {
551
+ $value = $this->strip_html( $params['pods_field_oembed_value'] );
552
+ $name = ( ! empty( $params['pods_field_oembed_name'] ) ) ? $this->strip_html( $params['pods_field_oembed_name'] ) : '';
553
+ $options = ( ! empty( $params['pods_field_oembed_options'] ) ) ? $params['pods_field_oembed_options'] : array();
554
+
555
+ // Load the field to get it's options
556
+ $options = pods_api()->load_field( (object) $options );
557
+
558
+ // Field options are stored here, if not, just stay with the full options array
559
+ if ( ! empty( $options['options'] ) ) {
560
+ $options = $options['options'];
561
+ }
562
+
563
+ // Run display function to run oEmbed
564
+ $value = $this->display( $value, $name, $options );
565
+
566
+ if ( empty( $value ) ) {
567
+ $value = __( 'Please choose a valid oEmbed URL.', 'pods' );
568
+ wp_send_json_error( $value );
569
+ } else {
570
+ wp_send_json_success( $value );
571
+ }
572
+ }
573
+ wp_send_json_error( __( 'Unauthorized request', 'pods' ) );
574
+
575
+ die(); // Kill it!
576
+ }
577
+
578
+ }
classes/fields/paragraph.php CHANGED
@@ -132,7 +132,16 @@ class PodsField_Paragraph extends PodsField {
132
  'default' => 0,
133
  'type' => 'number',
134
  'help' => __( 'Set to -1 for no limit', 'pods' )
135
- )/*,
 
 
 
 
 
 
 
 
 
136
  self::$type . '_size' => array(
137
  'label' => __( 'Field Size', 'pods' ),
138
  'default' => 'medium',
132
  'default' => 0,
133
  'type' => 'number',
134
  'help' => __( 'Set to -1 for no limit', 'pods' )
135
+ ),
136
+ self::$type . '_placeholder' => array(
137
+ 'label' => __( 'HTML Placeholder', 'pods' ),
138
+ 'default' => '',
139
+ 'type' => 'text',
140
+ 'help' => array(
141
+ __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
142
+ 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
143
+ ),
144
+ ),/*,
145
  self::$type . '_size' => array(
146
  'label' => __( 'Field Size', 'pods' ),
147
  'default' => 'medium',
classes/fields/password.php CHANGED
@@ -60,7 +60,16 @@ class PodsField_Password extends PodsField {
60
  'default' => 255,
61
  'type' => 'number',
62
  'help' => __( 'Set to -1 for no limit', 'pods' )
63
- )/*,
 
 
 
 
 
 
 
 
 
64
  self::$type . '_size' => array(
65
  'label' => __( 'Field Size', 'pods' ),
66
  'default' => 'medium',
60
  'default' => 255,
61
  'type' => 'number',
62
  'help' => __( 'Set to -1 for no limit', 'pods' )
63
+ ),
64
+ self::$type . '_placeholder' => array(
65
+ 'label' => __( 'HTML Placeholder', 'pods' ),
66
+ 'default' => '',
67
+ 'type' => 'text',
68
+ 'help' => array(
69
+ __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
70
+ 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
71
+ ),
72
+ ),/*,
73
  self::$type . '_size' => array(
74
  'label' => __( 'Field Size', 'pods' ),
75
  'default' => 'medium',
classes/fields/phone.php CHANGED
@@ -98,7 +98,16 @@ class PodsField_Phone extends PodsField {
98
  'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
99
  'default' => apply_filters( 'pods_form_ui_field_html5', 0, self::$type ),
100
  'type' => 'boolean'
101
- )/*,
 
 
 
 
 
 
 
 
 
102
  self::$type . '_size' => array(
103
  'label' => __( 'Field Size', 'pods' ),
104
  'default' => 'medium',
98
  'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
99
  'default' => apply_filters( 'pods_form_ui_field_html5', 0, self::$type ),
100
  'type' => 'boolean'
101
+ ),
102
+ self::$type . '_placeholder' => array(
103
+ 'label' => __( 'HTML Placeholder', 'pods' ),
104
+ 'default' => '',
105
+ 'type' => 'text',
106
+ 'help' => array(
107
+ __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
108
+ 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
109
+ ),
110
+ ),/*,
111
  self::$type . '_size' => array(
112
  'label' => __( 'Field Size', 'pods' ),
113
  'default' => 'medium',
classes/fields/pick.php CHANGED
@@ -1,75 +1,67 @@
1
  <?php
 
2
  /**
3
  * @package Pods\Fields
4
  */
5
  class PodsField_Pick extends PodsField {
6
 
7
- /**
8
- * Field Type Group
9
- *
10
- * @var string
11
- * @since 2.0
12
- */
13
- public static $group = 'Relationships / Media';
14
-
15
- /**
16
- * Field Type Identifier
17
- *
18
- * @var string
19
- * @since 2.0
20
- */
21
- public static $type = 'pick';
22
-
23
- /**
24
- * Field Type Label
25
- *
26
- * @var string
27
- * @since 2.0
28
- */
29
- public static $label = 'Relationship';
30
-
31
- /**
32
- * Available Related Objects
33
- *
34
- * @var array
35
- * @since 2.3
36
- */
37
- public static $related_objects = array();
38
-
39
- /**
40
- * Custom Related Objects
41
- *
42
- * @var array
43
- * @since 2.3
44
- */
45
- public static $custom_related_objects = array();
46
-
47
- /**
48
- * Data used during validate / save to avoid extra queries
49
- *
50
- * @var array
51
- * @since 2.3
52
- */
53
- public static $related_data = array();
54
-
55
- /**
56
- * Data used during input method (mainly for autocomplete)
57
- *
58
- * @var array
59
- * @since 2.3
60
- */
61
- public static $field_data = array();
62
-
63
- /**
64
- * API caching for fields that need it during validate/save
65
- *
66
- * @var \PodsAPI
67
- * @since 2.3
68
- */
69
- protected static $api = false;
70
 
71
  /**
72
- * Saved array of simple relationship names
73
  *
74
  * @var array
75
  * @since 2.5
@@ -92,151 +84,195 @@ class PodsField_Pick extends PodsField {
92
  */
93
  private static $names_bidirectional = null;
94
 
95
- /**
96
- * Setup related objects list
97
- *
98
- * @since 2.0
99
- */
100
- public function __construct () {
101
- self::$label = __( 'Relationship', 'pods' );
102
- }
103
-
104
- /**
105
- * Add admin_init actions
106
- *
107
- * @since 2.3
108
- */
109
- public function admin_init () {
110
- // AJAX for Relationship lookups
111
- add_action( 'wp_ajax_pods_relationship', array( $this, 'admin_ajax_relationship' ) );
112
- add_action( 'wp_ajax_nopriv_pods_relationship', array( $this, 'admin_ajax_relationship' ) );
113
- }
114
-
115
- /**
116
- * Add options and set defaults to
117
- *
118
- * @return array
119
- *
120
- * @since 2.0
121
- */
122
- public function options () {
123
- $options = array(
124
- self::$type . '_format_type' => array(
125
- 'label' => __( 'Selection Type', 'pods' ),
126
- 'help' => __( 'help', 'pods' ),
127
- 'default' => 'single',
128
- 'type' => 'pick',
129
- 'data' => array(
130
- 'single' => __( 'Single Select', 'pods' ),
131
- 'multi' => __( 'Multiple Select', 'pods' )
132
- ),
133
- 'dependency' => true
134
- ),
135
- self::$type . '_format_single' => array(
136
- 'label' => __( 'Format', 'pods' ),
137
- 'help' => __( 'help', 'pods' ),
138
- 'depends-on' => array( self::$type . '_format_type' => 'single' ),
139
- 'default' => 'dropdown',
140
- 'type' => 'pick',
141
- 'data' => apply_filters(
142
- 'pods_form_ui_field_pick_format_single_options',
143
- array(
144
- 'dropdown' => __( 'Drop Down', 'pods' ),
145
- 'radio' => __( 'Radio Buttons', 'pods' ),
146
- 'autocomplete' => __( 'Autocomplete', 'pods' )
147
- ) + ( ( pods_developer() && 1 == 0 ) ? array( 'flexible' => __( 'Flexible', 'pods' ) ) : array() ) // Disable for now
148
- ),
149
- 'dependency' => true
150
- ),
151
- self::$type . '_format_multi' => array(
152
- 'label' => __( 'Format', 'pods' ),
153
- 'help' => __( 'help', 'pods' ),
154
- 'depends-on' => array( self::$type . '_format_type' => 'multi' ),
155
- 'default' => 'checkbox',
156
- 'type' => 'pick',
157
- 'data' => apply_filters(
158
- 'pods_form_ui_field_pick_format_multi_options',
159
- array(
160
- 'checkbox' => __( 'Checkboxes', 'pods' ),
161
- 'multiselect' => __( 'Multi Select', 'pods' ),
162
- 'autocomplete' => __( 'Autocomplete', 'pods' )
163
- ) + ( ( pods_developer() && 1 == 0 ) ? array( 'flexible' => __( 'Flexible', 'pods' ) ) : array() ) // Disable for now
164
- ),
165
- 'dependency' => true
166
- ),
167
- self::$type . '_taggable' => array(
168
- 'label' => __( 'Taggable', 'pods' ),
169
- 'help' => __( 'Allow new values to be inserted when using an Autocomplete field', 'pods' ),
170
- 'excludes-on' => array(
171
- self::$type . '_format_single' => array( 'dropdown', 'radio' ),
172
- self::$type . '_format_multi' => array( 'checkbox', 'multiselect' ),
173
- self::$type . '_object' => array_merge(
174
- array( 'site', 'network' ),
175
- self::simple_objects()
176
- )
177
  ),
178
- 'type' => 'boolean',
179
- 'default' => 0
180
- ),
181
- self::$type . '_select_text' => array(
182
- 'label' => __( 'Default Select Text', 'pods' ),
183
- 'help' => __( 'This is the text use for the default "no selection" dropdown item, if empty, it will default to "-- Select One --"', 'pods' ),
184
- 'depends-on' => array(
185
- self::$type . '_format_type' => 'single',
186
- self::$type . '_format_single' => 'dropdown'
 
 
 
 
 
187
  ),
188
- 'default' => '',
189
- 'type' => 'text'
190
  ),
191
- self::$type . '_limit' => array(
192
- 'label' => __( 'Selection Limit', 'pods' ),
193
- 'help' => __( 'help', 'pods' ),
194
- 'depends-on' => array( self::$type . '_format_type' => 'multi' ),
195
- 'default' => 0,
196
- 'type' => 'number'
197
- ),
198
- self::$type . '_allow_html' => array(
199
- 'label' => __('Allow HTML','pods'),
200
- 'type' => 'boolean',
201
- 'default' => 0
 
 
 
202
  ),
203
- self::$type . '_table_id' => array(
204
- 'label' => __( 'Table ID Column', 'pods' ),
205
- 'help' => __( 'You must provide the ID column name for the table, this will be used to keep track of the relationship', 'pods' ),
206
- 'depends-on' => array( self::$type . '_object' => 'table' ),
207
- 'required' => 1,
208
- 'default' => '',
209
- 'type' => 'text'
210
- ),
211
- self::$type . '_table_index' => array(
212
- 'label' => __( 'Table Index Column', 'pods' ),
213
- 'help' => __( 'You must provide the index column name for the table, this may optionally also be the ID column name', 'pods' ),
214
- 'depends-on' => array( self::$type . '_object' => 'table' ),
215
- 'required' => 1,
216
- 'default' => '',
217
- 'type' => 'text'
218
- ),
219
- self::$type . '_display' => array(
220
- 'label' => __( 'Display Field in Selection List', 'pods' ),
221
- 'help' => __( 'Provide the name of a field on the related object to reference, example: {@post_title}', 'pods' ),
222
- 'excludes-on' => array(
223
- self::$type . '_object' => array_merge(
224
- array( 'site', 'network' ),
225
- self::simple_objects()
226
- )
227
- ),
228
- 'default' => '',
229
- 'type' => 'text'
230
- ),
231
- self::$type . '_user_role' => array(
232
- 'label' => __( 'Limit list to Role(s)', 'pods' ),
233
- 'help' => __( 'help', 'pods' ),
234
- 'depends-on' => array( self::$type . '_object' => 'user' ),
235
- 'default' => '',
236
- 'type' => 'pick',
237
- 'pick_object' => 'role',
238
- 'pick_format_type' => 'multi'
239
- ),/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  self::$type . '_user_site' => array(
241
  'label' => __( 'Limit list to Site(s)', 'pods' ),
242
  'help' => __( 'help', 'pods' ),
@@ -244,114 +280,117 @@ class PodsField_Pick extends PodsField {
244
  'default' => '',
245
  'type' => 'pick',
246
  'pick_object' => 'site',
247
- 'pick_format_type' => 'multi'
248
- ),*/
249
- self::$type . '_where' => array(
250
- 'label' => __( 'Customized <em>WHERE</em>', 'pods' ),
251
- 'help' => __( 'help', 'pods' ),
252
- 'excludes-on' => array(
253
- self::$type . '_object' => array_merge(
254
- array( 'site', 'network' ),
255
- self::simple_objects()
256
- )
257
- ),
258
- 'default' => '',
259
- 'type' => 'text'
260
- ),
261
- self::$type . '_orderby' => array(
262
- 'label' => __( 'Customized <em>ORDER BY</em>', 'pods' ),
263
- 'help' => __( 'help', 'pods' ),
264
- 'excludes-on' => array(
265
- self::$type . '_object' => array_merge(
266
- array( 'site', 'network' ),
267
- self::simple_objects()
268
- )
269
- ),
270
- 'default' => '',
271
- 'type' => 'text'
272
  ),
273
- self::$type . '_groupby' => array(
274
- 'label' => __( 'Customized <em>GROUP BY</em>', 'pods' ),
275
- 'help' => __( 'help', 'pods' ),
276
- 'excludes-on' => array(
277
- self::$type . '_object' => array_merge(
278
- array( 'site', 'network' ),
279
- self::simple_objects()
280
- )
281
- ),
282
- 'default' => '',
283
- 'type' => 'text'
284
- )
285
- /*,
286
- self::$type . '_size' => array(
287
- 'label' => __( 'Field Size', 'pods' ),
288
- 'default' => 'medium',
289
- 'type' => 'pick',
290
- 'data' => array(
291
- 'small' => __( 'Small', 'pods' ),
292
- 'medium' => __( 'Medium', 'pods' ),
293
- 'large' => __( 'Large', 'pods' )
294
- )
295
- )*/
296
- );
297
-
298
- $post_type_pick_objects = array();
299
- foreach ( get_post_types( '', 'names' ) as $post_type ) {
300
- $post_type_pick_objects[] = 'post-type_' .$post_type;
301
- }
302
- $options[ self::$type . '_post_status' ] = array(
303
- 'name' => 'post_status',
304
- 'label' => __( 'Post Status', 'pods' ),
305
- 'help' => __( 'help', 'pods' ),
306
- 'type' => 'pick',
307
- 'pick_object' => 'post-status',
308
- 'pick_format_type' => 'multi',
309
- 'default' => 'publish',
310
- 'depends-on' => array(
311
- self::$type . '_object' => $post_type_pick_objects
312
- )
313
- );
314
-
315
- /*if ( !is_multisite() )
316
- unset( $options[ self::$type . '_user_site' ] );*/
317
-
318
- return $options;
319
- }
320
-
321
- /**
322
- * Register a related object
323
- *
324
- * @param string $name Object name
325
- * @param string $label Object label
326
- * @param array $options Object options
327
- *
328
- * @return array|boolean Object array or false if unsuccessful
329
- * @since 2.3
330
- */
331
- public function register_related_object ( $name, $label, $options = null ) {
332
- if ( empty( $name ) || empty( $label ) )
333
- return false;
334
-
335
- $related_object = array(
336
- 'label' => $label,
337
- 'group' => 'Custom Relationships',
338
- 'simple' => true,
339
- 'bidirectional' => false,
340
- 'data' => array(),
341
- 'data_callback' => null
342
- );
343
-
344
- $related_object = array_merge( $related_object, $options );
345
-
346
- self::$custom_related_objects[ $name ] = $related_object;
347
-
348
- return true;
349
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
 
351
  /**
352
  * Setup related objects
353
  *
354
  * @param boolean $force Whether to force refresh of related objects
 
355
  * @return bool True when data has been loaded
356
  * @since 2.3
357
  */
@@ -360,42 +399,42 @@ class PodsField_Pick extends PodsField {
360
  $new_data_loaded = false;
361
 
362
  if ( ! $force && empty( self::$related_objects ) ) {
363
- // Only load transient if we aren't forcing a refresh
364
  self::$related_objects = pods_transient_get( 'pods_related_objects' );
365
 
366
  if ( false !== self::$related_objects ) {
367
  $new_data_loaded = true;
368
  }
369
  } elseif ( $force ) {
370
- // If we are rebuilding, make sure we start with a clean slate
371
  self::$related_objects = array();
372
  }
373
 
374
  if ( empty( self::$related_objects ) ) {
375
- // Do a complete build of related_objects
376
  $new_data_loaded = true;
377
 
378
- // Custom
379
  self::$related_objects['custom-simple'] = array(
380
  'label' => __( 'Simple (custom defined list)', 'pods' ),
381
  'group' => __( 'Custom', 'pods' ),
382
- 'simple' => true
383
  );
384
 
385
- // Pods
386
  $pod_options = array();
387
 
388
- // Include PodsMeta if not already included
389
  pods_meta();
390
 
391
- // Advanced Content Types
392
  $_pods = PodsMeta::$advanced_content_types;
393
 
394
  foreach ( $_pods as $pod ) {
395
  $pod_options[ $pod['name'] ] = $pod['label'] . ' (' . $pod['name'] . ')';
396
  }
397
 
398
- // Settings
399
  $_pods = PodsMeta::$settings;
400
 
401
  foreach ( $_pods as $pod ) {
@@ -408,18 +447,18 @@ class PodsField_Pick extends PodsField {
408
  self::$related_objects[ 'pod-' . $pod ] = array(
409
  'label' => $label,
410
  'group' => __( 'Pods', 'pods' ),
411
- 'bidirectional' => true
412
  );
413
  }
414
 
415
- // Post Types
416
  $post_types = get_post_types();
417
  asort( $post_types );
418
 
419
  $ignore = array( 'attachment', 'revision', 'nav_menu_item' );
420
 
421
  foreach ( $post_types as $post_type => $label ) {
422
- if ( in_array( $post_type, $ignore ) || empty( $post_type ) ) {
423
  unset( $post_types[ $post_type ] );
424
 
425
  continue;
@@ -434,11 +473,11 @@ class PodsField_Pick extends PodsField {
434
  self::$related_objects[ 'post_type-' . $post_type->name ] = array(
435
  'label' => $post_type->label . ' (' . $post_type->name . ')',
436
  'group' => __( 'Post Types', 'pods' ),
437
- 'bidirectional' => true
438
  );
439
  }
440
 
441
- // Taxonomies
442
  $taxonomies = get_taxonomies();
443
  asort( $taxonomies );
444
 
@@ -448,13 +487,13 @@ class PodsField_Pick extends PodsField {
448
  /**
449
  * Prevent ability to extend core Pods content types.
450
  *
451
- * @param bool Default is true, when set to false Pods internal content types can not be extended.
452
  *
453
  * @since 2.3.19
454
  */
455
  $ignore_internal = apply_filters( 'pods_pick_ignore_internal', true );
456
 
457
- if ( in_array( $taxonomy, $ignore ) || empty( $taxonomy ) ) {
458
  unset( $taxonomies[ $taxonomy ] );
459
 
460
  continue;
@@ -469,65 +508,65 @@ class PodsField_Pick extends PodsField {
469
  self::$related_objects[ 'taxonomy-' . $taxonomy->name ] = array(
470
  'label' => $taxonomy->label . ' (' . $taxonomy->name . ')',
471
  'group' => __( 'Taxonomies', 'pods' ),
472
- 'bidirectional' => true
473
  );
474
  }
475
 
476
- // Other WP Objects
477
  self::$related_objects['user'] = array(
478
  'label' => __( 'Users', 'pods' ),
479
  'group' => __( 'Other WP Objects', 'pods' ),
480
- 'bidirectional' => true
481
  );
482
 
483
  self::$related_objects['role'] = array(
484
  'label' => __( 'User Roles', 'pods' ),
485
  'group' => __( 'Other WP Objects', 'pods' ),
486
  'simple' => true,
487
- 'data_callback' => array( $this, 'data_roles' )
488
  );
489
 
490
  self::$related_objects['capability'] = array(
491
  'label' => __( 'User Capabilities', 'pods' ),
492
  'group' => __( 'Other WP Objects', 'pods' ),
493
  'simple' => true,
494
- 'data_callback' => array( $this, 'data_capabilities' )
495
  );
496
 
497
  self::$related_objects['media'] = array(
498
  'label' => __( 'Media', 'pods' ),
499
  'group' => __( 'Other WP Objects', 'pods' ),
500
- 'bidirectional' => true
501
  );
502
 
503
  self::$related_objects['comment'] = array(
504
  'label' => __( 'Comments', 'pods' ),
505
  'group' => __( 'Other WP Objects', 'pods' ),
506
- 'bidirectional' => true
507
  );
508
 
509
  self::$related_objects['image-size'] = array(
510
  'label' => __( 'Image Sizes', 'pods' ),
511
  'group' => __( 'Other WP Objects', 'pods' ),
512
  'simple' => true,
513
- 'data_callback' => array( $this, 'data_image_sizes' )
514
  );
515
 
516
  self::$related_objects['nav_menu'] = array(
517
  'label' => __( 'Navigation Menus', 'pods' ),
518
- 'group' => __( 'Other WP Objects', 'pods' )
519
  );
520
 
521
  self::$related_objects['post_format'] = array(
522
  'label' => __( 'Post Formats', 'pods' ),
523
- 'group' => __( 'Other WP Objects', 'pods' )
524
  );
525
 
526
  self::$related_objects['post-status'] = array(
527
  'label' => __( 'Post Status', 'pods' ),
528
  'group' => __( 'Other WP Objects', 'pods' ),
529
  'simple' => true,
530
- 'data_callback' => array( $this, 'data_post_stati' )
531
  );
532
 
533
  do_action( 'pods_form_ui_field_pick_related_objects_other' );
@@ -536,28 +575,35 @@ class PodsField_Pick extends PodsField {
536
  'label' => __( 'Countries', 'pods' ),
537
  'group' => __( 'Predefined Lists', 'pods' ),
538
  'simple' => true,
539
- 'data_callback' => array( $this, 'data_countries' )
540
  );
541
 
542
  self::$related_objects['us_state'] = array(
543
  'label' => __( 'US States', 'pods' ),
544
  'group' => __( 'Predefined Lists', 'pods' ),
545
  'simple' => true,
546
- 'data_callback' => array( $this, 'data_us_states' )
 
 
 
 
 
 
 
547
  );
548
 
549
  self::$related_objects['days_of_week'] = array(
550
  'label' => __( 'Calendar - Days of Week', 'pods' ),
551
  'group' => __( 'Predefined Lists', 'pods' ),
552
  'simple' => true,
553
- 'data_callback' => array( $this, 'data_days_of_week' )
554
  );
555
 
556
  self::$related_objects['months_of_year'] = array(
557
  'label' => __( 'Calendar - Months of Year', 'pods' ),
558
  'group' => __( 'Predefined Lists', 'pods' ),
559
  'simple' => true,
560
- 'data_callback' => array( $this, 'data_months_of_year' )
561
  );
562
 
563
  do_action( 'pods_form_ui_field_pick_related_objects_predefined' );
@@ -584,45 +630,49 @@ class PodsField_Pick extends PodsField {
584
 
585
  }
586
 
587
- /**
588
- * Return available related objects
589
- *
590
- * @param boolean $force Whether to force refresh of related objects
591
- *
592
- * @return array Field selection array
593
- * @since 2.3
594
- */
595
- public function related_objects ( $force = false ) {
596
- if ( $this->setup_related_objects( $force ) || null === self::$names_related ) {
597
- $related_objects = array();
598
-
599
- foreach ( self::$related_objects as $related_object_name => $related_object ) {
600
- if ( ! isset( $related_objects[ $related_object[ 'group' ] ] ) ) {
601
- $related_objects[ $related_object[ 'group' ] ] = array();
602
- }
603
-
604
- $related_objects[ $related_object[ 'group' ] ][ $related_object_name ] = $related_object[ 'label' ];
605
- }
606
-
607
- self::$names_related = (array) apply_filters( 'pods_form_ui_field_pick_related_objects', $related_objects );
608
- }
609
-
610
- return self::$names_related;
611
- }
612
-
613
- /**
614
- * Return available simple object names
615
- *
616
- * @return array Simple object names
617
- * @since 2.3
618
- */
619
- public function simple_objects () {
 
 
 
620
  if ( $this->setup_related_objects() || null === self::$names_simple ) {
621
  $simple_objects = array();
622
 
623
  foreach ( self::$related_objects as $object => $related_object ) {
624
- if ( !isset( $related_object[ 'simple' ] ) || !$related_object[ 'simple' ] )
625
  continue;
 
626
 
627
  $simple_objects[] = $object;
628
  }
@@ -630,1804 +680,2654 @@ class PodsField_Pick extends PodsField {
630
  self::$names_simple = (array) apply_filters( 'pods_form_ui_field_pick_simple_objects', $simple_objects );
631
  }
632
 
633
- return self::$names_simple;
634
- }
635
-
636
- /**
637
- * Return available bidirectional object names
638
- *
639
- * @return array Bidirectional object names
640
- * @since 2.3.4
641
- */
642
- public function bidirectional_objects () {
643
- if ( $this->setup_related_objects() || null === self::$names_bidirectional ) {
644
- $bidirectional_objects = array();
645
-
646
- foreach ( self::$related_objects as $object => $related_object ) {
647
- if ( !isset( $related_object[ 'bidirectional' ] ) || !$related_object[ 'bidirectional' ] )
648
- continue;
649
-
650
- $bidirectional_objects[] = $object;
651
- }
652
-
653
- self::$names_bidirectional = (array) apply_filters( 'pods_form_ui_field_pick_bidirectional_objects', $bidirectional_objects );
654
- }
655
-
656
- return self::$names_bidirectional;
657
- }
658
-
659
- /**
660
- * Define the current field's schema for DB table storage
661
- *
662
- * @param array $options
663
- *
664
- * @return array
665
- * @since 2.0
666
- */
667
- public function schema ( $options = null ) {
668
- $schema = false;
669
-
670
- $simple_tableless_objects = $this->simple_objects();
671
-
672
- if ( in_array( pods_var( self::$type . '_object', $options ), $simple_tableless_objects ) )
673
- $schema = 'LONGTEXT';
674
-
675
- return $schema;
676
- }
677
-
678
- /**
679
- * Change the way the value of the field is displayed with Pods::get
680
- *
681
- * @param mixed $value
682
- * @param string $name
683
- * @param array $options
684
- * @param array $fields
685
- * @param array $pod
686
- * @param int $id
687
- *
688
- * @since 2.0
689
- */
690
- public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
691
- $fields = null;
692
-
693
- if ( is_object( $pod ) && isset( $pod->fields ) ) {
694
- $fields = $pod->fields;
695
-
696
- if ( ! empty( $pod->pod_data[ 'object_fields' ] ) ) {
697
- $fields = array_merge( $fields, $pod->pod_data[ 'object_fields' ] );
698
- }
699
- } elseif ( is_array( $pod ) && isset( $pod[ 'fields' ] ) ) {
700
- $fields = $pod[ 'fields' ];
701
-
702
- if ( ! empty( $pod[ 'object_fields' ] ) ) {
703
- $fields = array_merge( $fields, $pod[ 'object_fields' ] );
704
- }
705
- }
706
-
707
- return pods_serial_comma( $value, array( 'field' => $name, 'fields' => $fields ) );
708
- }
709
-
710
- /**
711
- * Customize output of the form field
712
- *
713
- * @param string $name
714
- * @param mixed $value
715
- * @param array $options
716
- * @param array $pod
717
- * @param int $id
718
- *
719
- * @since 2.0
720
- */
721
- public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
722
- global $wpdb;
723
-
724
- $options = (array) $options;
725
- $form_field_type = PodsForm::$field_type;
726
-
727
- $options[ 'grouped' ] = 1;
728
-
729
- $options[ 'table_info' ] = array();
730
-
731
- $custom = pods_var_raw( self::$type . '_custom', $options, false );
732
-
733
- $custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $name, $value, $options, $pod, $id );
734
-
735
- $ajax = false;
736
-
737
- if ( ( 'custom-simple' != pods_var( self::$type . '_object', $options ) || empty( $custom ) ) && '' != pods_var( self::$type . '_object', $options, '', null, true ) )
738
- $ajax = true;
739
-
740
- if ( !empty( self::$field_data ) && self::$field_data[ 'id' ] == $options[ 'id' ] ) {
741
- $ajax = (boolean) self::$field_data[ 'autocomplete' ];
742
- }
743
-
744
- $ajax = apply_filters( 'pods_form_ui_field_pick_ajax', $ajax, $name, $value, $options, $pod, $id );
745
-
746
- if ( 0 == pods_var( self::$type . '_ajax', $options, 1 ) )
747
- $ajax = false;
748
-
749
- if ( 'single' == pods_var( self::$type . '_format_type', $options, 'single' ) ) {
750
- if ( 'dropdown' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) )
751
- $field_type = 'select';
752
- elseif ( 'radio' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) )
753
- $field_type = 'radio';
754
- elseif ( 'autocomplete' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) )
755
- $field_type = 'select2';
756
- else {
757
- // Support custom integration
758
- do_action( 'pods_form_ui_field_pick_input_' . pods_var( self::$type . '_format_type', $options, 'single' ) . '_' . pods_var( self::$type . '_format_single', $options, 'dropdown' ), $name, $value, $options, $pod, $id );
759
- do_action( 'pods_form_ui_field_pick_input', pods_var( self::$type . '_format_type', $options, 'single' ), $name, $value, $options, $pod, $id );
760
- return;
761
- }
762
- }
763
- elseif ( 'multi' == pods_var( self::$type . '_format_type', $options, 'single' ) ) {
764
- if ( !empty( $value ) && !is_array( $value ) )
765
- $value = explode( ',', $value );
766
-
767
- if ( 'checkbox' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) )
768
- $field_type = 'checkbox';
769
- elseif ( 'multiselect' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) )
770
- $field_type = 'select';
771
- elseif ( 'autocomplete' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) )
772
- $field_type = 'select2';
773
- else {
774
- // Support custom integration
775
- do_action( 'pods_form_ui_field_pick_input_' . pods_var( self::$type . '_format_type', $options, 'single' ) . '_' . pods_var( self::$type . '_format_multi', $options, 'checkbox' ), $name, $value, $options, $pod, $id );
776
- do_action( 'pods_form_ui_field_pick_input', pods_var( self::$type . '_format_type', $options, 'single' ), $name, $value, $options, $pod, $id );
777
- return;
778
- }
779
- }
780
- else {
781
- // Support custom integration
782
- do_action( 'pods_form_ui_field_pick_input', pods_var( self::$type . '_format_type', $options, 'single' ), $name, $value, $options, $pod, $id );
783
- return;
784
- }
785
-
786
- pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
787
- }
788
-
789
- /**
790
- * Validate a value before it's saved
791
- *
792
- * @param mixed $value
793
- * @param string $name
794
- * @param array $options
795
- * @param array $fields
796
- * @param array $pod
797
- * @param int $id
798
- *
799
- * @param null $params
800
- * @return array|bool
801
- * @since 2.0
802
- */
803
- public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
804
- if ( empty( self::$api ) )
805
- self::$api = pods_api();
806
-
807
- $simple_tableless_objects = $this->simple_objects();
808
-
809
- $related_pick_limit = 0;
810
- $related_field = $related_pod = $current_related_ids = false;
811
-
812
- // Bidirectional relationship requirement checks
813
- $related_object = pods_var( self::$type . '_object', $options, '' ); // pod, post_type, taxonomy, etc..
814
- $related_val = pods_var( self::$type . '_val', $options, $related_object, null, true ); // pod name, post type name, taxonomy name, etc..
815
- if ( empty( $related_val ) ) {
816
- $related_val = $related_object;
817
- }
818
-
819
- $related_sister_id = (int) pods_var( 'sister_id', $options, 0 );
820
-
821
- $options[ 'id' ] = (int) $options[ 'id' ];
822
-
823
- if ( !isset( self::$related_data[ $options[ 'id' ] ] ) || empty( self::$related_data[ $options[ 'id' ] ] ) )
824
- self::$related_data[ $options[ 'id' ] ] = array();
825
-
826
- if ( !empty( $related_sister_id ) && !in_array( $related_object, $simple_tableless_objects ) ) {
827
- $related_pod = self::$api->load_pod( array( 'name' => $related_val, 'table_info' => false ), false );
828
-
829
- if ( false !== $related_pod && ( 'pod' == $related_object || $related_object == $related_pod[ 'type' ] ) ) {
830
- $related_field = false;
831
-
832
- // Ensure sister_id exists on related Pod
833
- foreach ( $related_pod[ 'fields' ] as $related_pod_field ) {
834
- if ( 'pick' == $related_pod_field[ 'type' ] && $related_sister_id == $related_pod_field[ 'id' ] ) {
835
- $related_field = $related_pod_field;
836
-
837
- break;
838
- }
839
- }
840
-
841
- if ( !empty( $related_field ) ) {
842
- $current_ids = self::$api->lookup_related_items( $fields[ $name ][ 'id' ], $pod[ 'id' ], $id, $fields[ $name ], $pod );
843
-
844
- self::$related_data[ $options[ 'id' ] ][ 'current_ids' ] = $current_ids;
845
-
846
- $value_ids = $value;
847
-
848
- // Convert values from a comma-separated string into an array
849
- if ( !is_array( $value_ids ) )
850
- $value_ids = explode( ',', $value_ids );
851
-
852
- $value_ids = array_unique( array_filter( $value_ids ) );
853
-
854
- // Get ids to remove
855
- $remove_ids = array_diff( $current_ids, $value_ids );
856
-
857
- $related_required = (boolean) pods_var( 'required', $related_field[ 'options' ], 0 );
858
- $related_pick_limit = (int) pods_var( self::$type . '_limit', $related_field[ 'options' ], 0 );
859
-
860
- if ( 'single' == pods_var_raw( self::$type . '_format_type', $related_field[ 'options' ] ) )
861
- $related_pick_limit = 1;
862
-
863
- // Validate Required
864
- if ( $related_required && !empty( $remove_ids ) ) {
865
- foreach ( $remove_ids as $related_id ) {
866
- $bidirectional_ids = self::$api->lookup_related_items( $related_field[ 'id' ], $related_pod[ 'id' ], $related_id, $related_field, $related_pod );
867
-
868
- self::$related_data[ $options[ 'id' ] ][ 'related_ids_' . $related_id ] = $bidirectional_ids;
869
-
870
- if ( empty( $bidirectional_ids ) || ( in_array( $id, $bidirectional_ids ) && 1 == count( $bidirectional_ids ) ) )
871
- return sprintf( __( 'The %s field is required and cannot be removed by the %s field', 'pods' ), $related_field[ 'label' ], $options[ 'label' ] );
872
- }
873
- }
874
- }
875
- else
876
- $related_pod = false;
877
- }
878
- else
879
- $related_pod = false;
880
- }
881
-
882
- if ( empty( self::$related_data[ $options[ 'id' ] ] ) )
883
- unset( self::$related_data[ $options[ 'id' ] ] );
884
- else {
885
- self::$related_data[ $options[ 'id' ] ][ 'related_pod' ] = $related_pod;
886
- self::$related_data[ $options[ 'id' ] ][ 'related_field' ] = $related_field;
887
- self::$related_data[ $options[ 'id' ] ][ 'related_pick_limit' ] = $related_pick_limit;
888
-
889
- $pick_limit = (int) pods_var( self::$type . '_limit', $options[ 'options' ], 0 );
890
-
891
- if ( 'single' == pods_var_raw( self::$type . '_format_type', $options[ 'options' ] ) )
892
- $pick_limit = 1;
893
-
894
- $related_field[ 'id' ] = (int) $related_field[ 'id' ];
895
-
896
- if ( !isset( self::$related_data[ $related_field[ 'id' ] ] ) || empty( self::$related_data[ $related_field[ 'id' ] ] ) ) {
897
- self::$related_data[ $related_field[ 'id' ] ] = array(
898
- 'related_pod' => $pod,
899
- 'related_field' => $options,
900
- 'related_pick_limit' => $pick_limit
901
- );
902
- }
903
- }
904
-
905
- return true;
906
- }
907
-
908
- /**
909
- * Save the value to the DB
910
- *
911
- * @param mixed $value
912
- * @param int $id
913
- * @param string $name
914
- * @param array $options
915
- * @param array $fields
916
- * @param array $pod
917
- * @param object $params
918
- *
919
- * @since 2.3
920
- */
921
- public function save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
922
- if ( empty( self::$api ) )
923
- self::$api = pods_api();
924
-
925
- $options[ 'id' ] = (int) $options[ 'id' ];
926
-
927
- if ( !isset( self::$related_data[ $options[ 'id' ] ] ) )
928
- return;
929
-
930
- $related_pod = self::$related_data[ $options[ 'id' ] ][ 'related_pod' ];
931
- $related_field = self::$related_data[ $options[ 'id' ] ][ 'related_field' ];
932
- $related_pick_limit = self::$related_data[ $options[ 'id' ] ][ 'related_pick_limit' ];
933
-
934
- // Bidirectional relationship updates
935
- if ( !empty( $related_field ) ) {
936
- // Don't use no conflict mode unless this isn't the current pod type
937
- $no_conflict = true;
938
-
939
- if ( $related_pod[ 'type' ] != $pod[ 'type' ] )
940
- $no_conflict = pods_no_conflict_check( $related_pod[ 'type' ] );
941
-
942
- if ( !$no_conflict )
943
- pods_no_conflict_on( $related_pod[ 'type' ] );
944
-
945
- $value = array_filter( $value );
946
-
947
- foreach ( $value as $related_id ) {
948
- if ( isset( self::$related_data[ $options[ 'id' ] ][ 'related_ids_' . $related_id ] ) && !empty( self::$related_data[ $options[ 'id' ] ][ 'related_ids_' . $related_id ] ) )
949
- $bidirectional_ids = self::$related_data[ $options[ 'id' ] ][ 'related_ids_' . $related_id ];
950
- else
951
- $bidirectional_ids = self::$api->lookup_related_items( $related_field[ 'id' ], $related_pod[ 'id' ], $related_id, $related_field, $related_pod );
952
-
953
- $bidirectional_ids = array_filter( $bidirectional_ids );
954
-
955
- if ( empty( $bidirectional_ids ) )
956
- $bidirectional_ids = array();
957
-
958
- $remove_ids = array();
959
-
960
- if ( 0 < $related_pick_limit && !empty( $bidirectional_ids ) && !in_array( $id, $bidirectional_ids ) ) {
961
- while ( $related_pick_limit <= count( $bidirectional_ids ) ) {
962
- $remove_ids[] = (int) array_pop( $bidirectional_ids );
963
- }
964
- }
965
-
966
- // Remove this item from related items no longer related to
967
- $remove_ids = array_unique( array_filter( $remove_ids ) );
968
-
969
- // Add to related items
970
- if ( !in_array( $id, $bidirectional_ids ) )
971
- $bidirectional_ids[] = $id;
972
- // Nothing to change
973
- elseif ( empty( $remove_ids ) )
974
- continue;
975
-
976
- self::$api->save_relationships( $related_id, $bidirectional_ids, $related_pod, $related_field );
977
-
978
- if ( !empty( $remove_ids ) )
979
- self::$api->delete_relationships( $remove_ids, $related_id, $pod, $options );
980
- }
981
-
982
- if ( !$no_conflict )
983
- pods_no_conflict_off( $related_pod[ 'type' ] );
984
- }
985
- }
986
-
987
- /**
988
- * Delete the value from the DB
989
- *
990
- * @param int $id
991
- * @param string $name
992
- * @param array $options
993
- * @param array $pod
994
- *
995
- * @since 2.3
996
- */
997
- public function delete ( $id = null, $name = null, $options = null, $pod = null ) {
998
- if ( empty( self::$api ) )
999
- self::$api = pods_api();
1000
-
1001
- $simple_tableless_objects = $this->simple_objects();
1002
-
1003
- // Bidirectional relationship requirement checks
1004
- $related_object = pods_var( self::$type . '_object', $options, '' ); // pod, post_type, taxonomy, etc..
1005
- $related_val = pods_var( self::$type . '_val', $options, $related_object, null, true ); // pod name, post type name, taxonomy name, etc..
1006
- $related_sister_id = (int) pods_var( 'sister_id', $options, 0 );
1007
-
1008
- if ( !empty( $related_sister_id ) && !in_array( $related_object, $simple_tableless_objects ) ) {
1009
- $related_pod = self::$api->load_pod( array( 'name' => $related_val, 'table_info' => false ), false );
1010
-
1011
- if ( false !== $related_pod && ( 'pod' == $related_object || $related_object == $related_pod[ 'type' ] ) ) {
1012
- $related_field = false;
1013
-
1014
- // Ensure sister_id exists on related Pod
1015
- foreach ( $related_pod[ 'fields' ] as $related_pod_field ) {
1016
- if ( 'pick' == $related_pod_field[ 'type' ] && $related_sister_id == $related_pod_field[ 'id' ] ) {
1017
- $related_field = $related_pod_field;
1018
-
1019
- break;
1020
- }
1021
- }
1022
-
1023
- if ( !empty( $related_field ) ) {
1024
- $values = self::$api->lookup_related_items( $options[ 'id' ], $pod[ 'id' ], $id, $options, $pod );
1025
-
1026
- if ( !empty( $values ) ) {
1027
- $no_conflict = pods_no_conflict_check( $related_pod[ 'type' ] );
1028
-
1029
- if ( !$no_conflict )
1030
- pods_no_conflict_on( $related_pod[ 'type' ] );
1031
-
1032
- self::$api->delete_relationships( $values, $id, $related_pod, $related_field );
1033
-
1034
- if ( !$no_conflict )
1035
- pods_no_conflict_off( $related_pod[ 'type' ] );
1036
- }
1037
- }
1038
- }
1039
- }
1040
- }
1041
-
1042
- /**
1043
- * Customize the Pods UI manage table column output
1044
- *
1045
- * @param int $id
1046
- * @param mixed $value
1047
- * @param string $name
1048
- * @param array $options
1049
- * @param array $fields
1050
- * @param array $pod
1051
- *
1052
- * @since 2.0
1053
- */
1054
- public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
1055
- $value = $this->simple_value( $name, $value, $options, $pod, $id );
1056
-
1057
- return $this->display( $value, $name, $options, $pod, $id );
1058
- }
1059
-
1060
- /**
1061
- * Get the data from the field
1062
- *
1063
- * @param string $name The name of the field
1064
- * @param string|array $value The value of the field
1065
- * @param array $options Field options
1066
- * @param array $pod Pod data
1067
- * @param int $id Item ID
1068
- * @param boolean $in_form
1069
- *
1070
- * @return array Array of possible field data
1071
- *
1072
- * @since 2.0
1073
- */
1074
- public function data ( $name, $value = null, $options = null, $pod = null, $id = null, $in_form = true ) {
1075
- if ( isset( $options[ 'options' ] ) ) {
1076
- $options = array_merge( $options, $options[ 'options' ] );
1077
-
1078
- unset( $options[ 'options' ] );
1079
- }
1080
-
1081
- $data = pods_var_raw( 'data', $options, null, null, true );
1082
-
1083
- $object_params = array(
1084
- 'name' => $name, // The name of the field
1085
- 'value' => $value, // The value of the field
1086
- 'options' => $options, // Field options
1087
- 'pod' => $pod, // Pod data
1088
- 'id' => $id, // Item ID
1089
- 'context' => 'data', // Data context
1090
- );
1091
-
1092
- if ( null !== $data )
1093
- $data = (array) $data;
1094
- else
1095
- $data = $this->get_object_data( $object_params );
1096
-
1097
- if ( 'single' == pods_var( self::$type . '_format_type', $options, 'single' ) && 'dropdown' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) )
1098
- $data = array( '' => pods_var_raw( self::$type . '_select_text', $options, __( '-- Select One --', 'pods' ), null, true ) ) + $data;
1099
-
1100
- $data = apply_filters( 'pods_field_pick_data', $data, $name, $value, $options, $pod, $id );
1101
-
1102
- return $data;
1103
- }
1104
-
1105
- /**
1106
- * Convert a simple value to the correct value
1107
- *
1108
- * @param string $name The name of the field
1109
- * @param string|array $value The value of the field
1110
- * @param array $options Field options
1111
- * @param array $pod Pod data
1112
- * @param int $id Item ID
1113
- * @param boolean $raw Whether to return the raw list of keys (true) or convert to key=>value (false)
1114
- *
1115
- * @return mixed Corrected value
1116
- */
1117
- public function simple_value ( $name, $value = null, $options = null, $pod = null, $id = null, $raw = false ) {
1118
- if ( in_array( pods_var( self::$type . '_object', $options ), self::simple_objects() ) ) {
1119
- if ( isset( $options[ 'options' ] ) ) {
1120
- $options = array_merge( $options, $options[ 'options' ] );
1121
-
1122
- unset( $options[ 'options' ] );
1123
- }
1124
-
1125
- if ( !is_array( $value ) && 0 < strlen( $value ) ) {
1126
- $simple = @json_decode( $value, true );
1127
-
1128
- if ( is_array( $simple ) )
1129
- $value = $simple;
1130
- }
1131
-
1132
- $data = pods_var_raw( 'data', $options, null, null, true );
1133
-
1134
- $object_params = array(
1135
- 'name' => $name, // The name of the field
1136
- 'value' => $value, // The value of the field
1137
- 'options' => $options, // Field options
1138
- 'pod' => $pod, // Pod data
1139
- 'id' => $id, // Item ID
1140
- 'context' => 'simple_value', // Data context
1141
- );
1142
-
1143
- if ( null === $data )
1144
- $data = $this->get_object_data( $object_params );
1145
-
1146
- $data = (array) $data;
1147
-
1148
- $key = 0;
1149
-
1150
- if ( is_array( $value ) ) {
1151
- if ( !empty( $data ) ) {
1152
- $val = array();
1153
-
1154
- foreach ( $value as $k => $v ) {
1155
- if ( isset( $data[ $v ] ) ) {
1156
- if ( false === $raw ) {
1157
- $k = $v;
1158
- $v = $data[ $v ];
1159
- }
1160
-
1161
- $val[ $k ] = $v;
1162
- }
1163
- }
1164
-
1165
- $value = $val;
1166
- }
1167
- }
1168
- elseif ( isset( $data[ $value ] ) && false === $raw ) {
1169
- $key = $value;
1170
- $value = $data[ $value ];
1171
- }
1172
-
1173
- $single_multi = pods_var( self::$type . '_format_type', $options, 'single' );
1174
-
1175
- if ( 'multi' == $single_multi )
1176
- $limit = (int) pods_var( self::$type . '_limit', $options, 0 );
1177
- else
1178
- $limit = 1;
1179
-
1180
- if ( is_array( $value ) && 0 < $limit ) {
1181
- if ( 1 == $limit )
1182
- $value = current( $value );
1183
- else
1184
- $value = array_slice( $value, 0, $limit, true );
1185
- }
1186
- elseif ( !is_array( $value ) && null !== $value && 0 < strlen( $value ) ) {
1187
- if ( 1 != $limit || ( true === $raw && 'multi' == $single_multi ) ) {
1188
- $value = array(
1189
- $key => $value
1190
- );
1191
- }
1192
- }
1193
- }
1194
-
1195
- return $value;
1196
- }
1197
-
1198
- /**
1199
- * Get the label from a pick value
1200
- *
1201
- * @param string $name The name of the field
1202
- * @param string|array $value The value of the field
1203
- * @param array $options Field options
1204
- * @param array $pod Pod data
1205
- * @param int $id Item ID
1206
- *
1207
- * @return string
1208
- *
1209
- * @since 2.2
1210
- */
1211
- public function value_to_label ( $name, $value = null, $options = null, $pod = null, $id = null ) {
1212
- if ( isset( $options[ 'options' ] ) ) {
1213
- $options = array_merge( $options, $options[ 'options' ] );
1214
-
1215
- unset( $options[ 'options' ] );
1216
- }
1217
-
1218
- $data = pods_var_raw( 'data', $options, null, null, true );
1219
-
1220
- $object_params = array(
1221
- 'name' => $name, // The name of the field
1222
- 'value' => $value, // The value of the field
1223
- 'options' => $options, // Field options
1224
- 'pod' => $pod, // Pod data
1225
- 'id' => $id, // Item ID
1226
- 'context' => 'value_to_label', // Data context
1227
- );
1228
-
1229
- if ( null !== $data )
1230
- $data = (array) $data;
1231
- else
1232
- $data = $this->get_object_data( $object_params );
1233
-
1234
- $labels = array();
1235
-
1236
- foreach ( $data as $v => $l ) {
1237
- if ( !in_array( $l, $labels ) && ( $value == $v || ( is_array( $value ) && in_array( $v, $value ) ) ) )
1238
- $labels[] = $l;
1239
- }
1240
-
1241
- $labels = apply_filters( 'pods_field_pick_value_to_label', $labels, $name, $value, $options, $pod, $id );
1242
-
1243
- $labels = pods_serial_comma( $labels );
1244
-
1245
- return $labels;
1246
- }
1247
 
1248
  /**
1249
- * Get available items from a relationship field
1250
- *
1251
- * @param array|string $field Field array or field name
1252
- * @param array $options [optional] Field options array overrides
1253
- * @param array $object_params [optional] Additional get_object_data options
1254
  *
1255
- * @return array An array of available items from a relationship field
 
1256
  */
1257
- public function get_field_data( $field, $options = array(), $object_params = array() ) {
1258
 
1259
- // Handle field array overrides
1260
- if ( is_array( $field ) ) {
1261
- $options = array_merge( $field, $options );
1262
- }
1263
 
1264
- // Get field name from array
1265
- $field = pods_var_raw( 'name', $options, $field, null, true );
 
 
1266
 
1267
- // Field name or options not set
1268
- if ( empty( $field ) || empty( $options ) ) {
1269
- return array();
 
1270
  }
1271
 
1272
- // Options normalization
1273
- $options = array_merge( $options, pods_var_raw( 'options', $options, array(), null, true ) );
1274
 
1275
- // Setup object params
1276
- $object_params = array_merge(
1277
- array(
1278
- 'name' => $field, // The name of the field
1279
- 'options' => $options, // Field options
1280
- ),
1281
- $object_params
1282
- );
1283
 
1284
- // Get data override
1285
- $data = pods_var_raw( 'data', $options, null, null, true );
 
 
1286
 
1287
- // Return data override
1288
- if ( null !== $data ) {
1289
- $data = (array) $data;
1290
- }
1291
- // Get object data
1292
- else {
1293
- $data = $this->get_object_data( $object_params );
1294
  }
1295
 
1296
- return $data;
1297
 
1298
  }
1299
 
1300
- /**
1301
- * Get data from relationship objects
1302
- *
1303
- * @param array $object_params Object data parameters
1304
- *
1305
- * @return array|bool Object data
1306
- */
1307
- public function get_object_data ( $object_params = null ) {
1308
-
1309
- /**
1310
- * @var $wpdb wpdb
1311
- */
1312
- global $wpdb;
1313
-
1314
- $object_params = array_merge(
1315
- array(
1316
- 'name' => '', // The name of the field
1317
- 'value' => '', // The value of the field
1318
- 'options' => array(), // Field options
1319
- 'pod' => '', // Pod data
1320
- 'id' => '', // Item ID
1321
- 'context' => '', // Data context
1322
- 'data_params' => array(
1323
- 'query' => '' // Query being searched
1324
- ),
1325
- 'page' => 1, // Page number of results to get
1326
- 'limit' => 0 // How many data items to limit to (autocomplete defaults to 30, set to -1 or 1+ to override)
1327
- ),
1328
- $object_params
1329
- );
1330
 
1331
- $name = $object_params[ 'name' ];
1332
- $value = $object_params[ 'value' ];
1333
- $options = $object_params[ 'options' ] = (array) $object_params[ 'options' ];
1334
- $pod = $object_params[ 'pod' ];
1335
- $id = $object_params[ 'id' ];
1336
- $context = $object_params[ 'context' ];
1337
- $data_params = $object_params[ 'data_params' ] = (array) $object_params[ 'data_params' ];
1338
- $page = min( 1, (int) $object_params[ 'page' ] );
1339
- $limit = (int) $object_params[ 'limit' ];
1340
 
1341
- if ( isset( $options[ 'options' ] ) ) {
1342
- $options = array_merge( $options, $options[ 'options' ] );
 
 
 
1343
 
1344
- unset( $options[ 'options' ] );
1345
- }
 
 
1346
 
1347
- $data = apply_filters( 'pods_field_pick_object_data', null, $name, $value, $options, $pod, $id, $object_params );
1348
- $items = array();
1349
 
1350
- if ( !isset( $options[ self::$type . '_object' ] ) )
1351
- $data = pods_var_raw( 'data', $options, array(), null, true );
1352
 
1353
- $simple = false;
 
 
 
1354
 
1355
- if ( null === $data ) {
1356
- $data = array();
1357
 
1358
- if ( 'custom-simple' == $options[ self::$type . '_object' ] ) {
1359
- $custom = pods_var_raw( self::$type . '_custom', $options, '' );
1360
 
1361
- $custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $name, $value, $options, $pod, $id, $object_params );
 
1362
 
1363
- if ( !empty( $custom ) ) {
1364
- if ( !is_array( $custom ) ) {
1365
- $data = array();
1366
 
1367
- $custom = explode( "\n", trim( $custom ) );
 
1368
 
1369
- foreach ( $custom as $custom_value ) {
1370
- $custom_label = explode( '|', $custom_value );
1371
 
1372
- if ( empty( $custom_label ) )
1373
- continue;
1374
 
1375
- if ( 1 == count( $custom_label ) )
1376
- $custom_label = $custom_value;
1377
- else {
1378
- $custom_value = $custom_label[ 0 ];
1379
- $custom_label = $custom_label[ 1 ];
1380
- }
1381
 
1382
- $custom_value = trim( (string) $custom_value );
1383
- $custom_label = trim( (string) $custom_label );
1384
 
1385
- $data[ $custom_value ] = $custom_label;
1386
- }
1387
- }
1388
- else
1389
- $data = $custom;
1390
 
1391
- $simple = true;
1392
- }
1393
- }
1394
- elseif ( isset( self::$related_objects[ $options[ self::$type . '_object' ] ] ) && isset( self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data' ] ) && !empty( self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data' ] ) ) {
1395
- $data = self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data' ];
1396
 
1397
- $simple = true;
1398
- }
1399
- elseif ( isset( self::$related_objects[ $options[ self::$type . '_object' ] ] ) && isset( self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data_callback' ] ) && is_callable( self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data_callback' ] ) ) {
1400
- $data = call_user_func_array(
1401
- self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data_callback' ],
1402
- array( $name, $value, $options, $pod, $id )
1403
- );
1404
- if ( 'data' == $context ) {
1405
- self::$field_data = array(
1406
- 'field' => $name,
1407
- 'id' => $options[ 'id' ],
1408
- 'autocomplete' => false
1409
- );
1410
- }
1411
 
1412
- $simple = true;
 
 
1413
 
1414
- // Cache data from callback
1415
- if ( !empty( $data ) )
1416
- self::$related_objects[ $options[ self::$type . '_object' ] ][ 'data' ] = $data;
1417
- }
1418
- elseif ( 'simple_value' != $context ) {
1419
- $pick_val = pods_var( self::$type . '_val', $options );
1420
-
1421
- if ( 'table' == pods_var( self::$type . '_object', $options ) )
1422
- $pick_val = pods_var( self::$type . '_table', $options, $pick_val, null, true );
1423
-
1424
- if ( '__current__' == $pick_val ) {
1425
- if ( is_object( $pod ) )
1426
- $pick_val = $pod->pod;
1427
- elseif ( is_array( $pod ) )
1428
- $pick_val = $pod[ 'name' ];
1429
- elseif ( 0 < strlen( $pod ) )
1430
- $pick_val = $pod;
1431
- }
1432
-
1433
- $options[ 'table_info' ] = pods_api()->get_table_info( pods_var( self::$type . '_object', $options ), $pick_val, null, null, $options );
1434
-
1435
- $search_data = pods_data();
1436
- $search_data->table( $options[ 'table_info' ] );
1437
-
1438
- if ( isset( $options[ 'table_info' ][ 'pod' ] ) && !empty( $options[ 'table_info' ][ 'pod' ] ) && isset( $options[ 'table_info' ][ 'pod' ][ 'name' ] ) ) {
1439
- $search_data->pod = $options[ 'table_info' ][ 'pod' ][ 'name' ];
1440
- $search_data->fields = $options[ 'table_info' ][ 'pod' ][ 'fields' ];
1441
- }
1442
-
1443
- $params = array(
1444
- 'select' => "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`",
1445
- 'table' => $search_data->table,
1446
- 'where' => pods_var_raw( self::$type . '_where', $options, (array) $options[ 'table_info' ][ 'where_default' ], null, true ),
1447
- 'orderby' => pods_var_raw( self::$type . '_orderby', $options, null, null, true ),
1448
- 'groupby' => pods_var_raw( self::$type . '_groupby', $options, null, null, true ),
1449
- //'having' => pods_var_raw( self::$type . '_having', $options, null, null, true ),
1450
- 'pagination' => false,
1451
- 'search' => false
1452
- );
1453
-
1454
- if ( in_array( $options[ self::$type . '_object' ], array( 'site', 'network' ) ) )
1455
- $params[ 'select' ] .= ', `t`.`path`';
1456
-
1457
- if ( !empty( $params[ 'where' ] ) && (array) $options[ 'table_info' ][ 'where_default' ] != $params[ 'where' ] )
1458
- $params[ 'where' ] = pods_evaluate_tags( $params[ 'where' ], true );
1459
-
1460
- if ( empty( $params[ 'where' ] ) || ( !is_array( $params[ 'where' ] ) && strlen( trim( $params[ 'where' ] ) ) < 1 ) )
1461
- $params[ 'where' ] = array();
1462
- elseif ( !is_array( $params[ 'where' ] ) )
1463
- $params[ 'where' ] = (array) $params[ 'where' ];
1464
-
1465
- if ( 'value_to_label' == $context )
1466
- $params[ 'where' ][] = "`t`.`{$search_data->field_id}` = " . number_format( $value, 0, '', '' );
1467
-
1468
- /* not needed yet
1469
- if ( !empty( $params[ 'orderby' ] ) )
1470
- $params[ 'orderby' ] = pods_evaluate_tags( $params[ 'orderby' ], true );
1471
-
1472
- if ( !empty( $params[ 'groupby' ] ) )
1473
- $params[ 'groupby' ] = pods_evaluate_tags( $params[ 'groupby' ], true );*/
1474
-
1475
- $display = trim( pods_var( self::$type . '_display', $options ), ' {@}' );
1476
-
1477
- if ( 0 < strlen( $display ) ) {
1478
- if ( isset( $options[ 'table_info' ][ 'pod' ] ) && !empty( $options[ 'table_info' ][ 'pod' ] ) ) {
1479
- if ( isset( $options[ 'table_info' ][ 'pod' ][ 'object_fields' ] ) && isset( $options[ 'table_info' ][ 'pod' ][ 'object_fields' ][ $display ] ) ) {
1480
- $search_data->field_index = $display;
1481
-
1482
- $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
1483
- }
1484
- elseif ( isset( $options[ 'table_info' ][ 'pod' ][ 'fields' ][ $display ] ) ) {
1485
- $search_data->field_index = $display;
1486
-
1487
- if ( 'table' == $options[ 'table_info' ][ 'pod' ][ 'storage' ] && !in_array( $options[ 'table_info' ][ 'pod' ][ 'type' ], array( 'pod', 'table' ) ) )
1488
- $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `d`.`{$search_data->field_index}`";
1489
- elseif ( 'meta' == $options[ 'table_info' ][ 'pod' ][ 'storage' ] )
1490
- $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `{$search_data->field_index}`.`meta_value` AS {$search_data->field_index}";
1491
- else
1492
- $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
1493
- }
1494
- }
1495
- elseif ( isset( $options[ 'table_info' ][ 'object_fields' ] ) && isset( $options[ 'table_info' ][ 'object_fields' ][ $display ] ) ) {
1496
- $search_data->field_index = $display;
1497
-
1498
- $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
1499
- }
1500
- }
1501
-
1502
- $autocomplete = false;
1503
-
1504
- if ( 'single' == pods_var( self::$type . '_format_type', $options, 'single' ) && 'autocomplete' == pods_var( self::$type . '_format_single', $options, 'dropdown' ) )
1505
- $autocomplete = true;
1506
- elseif ( 'multi' == pods_var( self::$type . '_format_type', $options, 'single' ) && 'autocomplete' == pods_var( self::$type . '_format_multi', $options, 'checkbox' ) )
1507
- $autocomplete = true;
1508
-
1509
- $hierarchy = false;
1510
-
1511
- if ( 'data' == $context && !$autocomplete ) {
1512
- if ( 'single' == pods_var( self::$type . '_format_type', $options, 'single' ) && in_array( pods_var( self::$type . '_format_single', $options, 'dropdown' ), array( 'dropdown', 'radio' ) ) )
1513
- $hierarchy = true;
1514
- elseif ( 'multi' == pods_var( self::$type . '_format_type', $options, 'single' ) && in_array( pods_var( self::$type . '_format_multi', $options, 'checkbox' ), array( 'multiselect', 'checkbox' ) ) )
1515
- $hierarchy = true;
1516
- }
1517
-
1518
- if ( $hierarchy && $options[ 'table_info' ][ 'object_hierarchical' ] && !empty( $options[ 'table_info' ][ 'field_parent' ] ) )
1519
- $params[ 'select' ] .= ', ' . $options[ 'table_info' ][ 'field_parent_select' ];
1520
-
1521
- if ( $autocomplete ) {
1522
- if ( 0 == $limit ) {
1523
- $limit = 30;
1524
- }
1525
 
1526
- $params[ 'limit' ] = apply_filters( 'pods_form_ui_field_pick_autocomplete_limit', $limit, $name, $value, $options, $pod, $id, $object_params );
1527
 
1528
- if ( is_array( $value ) && $params[ 'limit' ] < count( $value ) ) {
1529
- $params[ 'limit' ] = count( $value );
1530
- }
1531
 
1532
- $params[ 'page' ] = $page;
1533
-
1534
- if ( 'admin_ajax_relationship' == $context ) {
1535
- $lookup_where = array(
1536
- $search_data->field_index => "`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'"
1537
- );
1538
-
1539
- // @todo Hook into WPML for each table
1540
- if ( $wpdb->users == $search_data->table ) {
1541
- $lookup_where[ 'display_name' ] = "`t`.`display_name` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'";
1542
- $lookup_where[ 'user_login' ] = "`t`.`user_login` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'";
1543
- $lookup_where[ 'user_email' ] = "`t`.`user_email` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'";
1544
- }
1545
- elseif ( $wpdb->posts == $search_data->table ) {
1546
- $lookup_where[ 'post_title' ] = "`t`.`post_title` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'";
1547
- $lookup_where[ 'post_name' ] = "`t`.`post_name` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'";
1548
- $lookup_where[ 'post_content' ] = "`t`.`post_content` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'";
1549
- $lookup_where[ 'post_excerpt' ] = "`t`.`post_excerpt` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'";
1550
- }
1551
- elseif ( $wpdb->terms == $search_data->table ) {
1552
- $lookup_where[ 'name' ] = "`t`.`name` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'";
1553
- $lookup_where[ 'slug' ] = "`t`.`slug` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'";
1554
- }
1555
- elseif ( $wpdb->comments == $search_data->table ) {
1556
- $lookup_where[ 'comment_content' ] = "`t`.`comment_content` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'";
1557
- $lookup_where[ 'comment_author' ] = "`t`.`comment_author` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'";
1558
- $lookup_where[ 'comment_author_email' ] = "`t`.`comment_author_email` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%'";
1559
- }
1560
-
1561
- $lookup_where = apply_filters( 'pods_form_ui_field_pick_autocomplete_lookup', $lookup_where, $data_params[ 'query' ], $name, $value, $options, $pod, $id, $object_params, $search_data );
1562
-
1563
- if ( !empty( $lookup_where ) )
1564
- $params[ 'where' ][] = implode( ' OR ', $lookup_where );
1565
-
1566
- $orderby = array();
1567
- $orderby[] = "(`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like( $data_params[ 'query' ] ) . "%' ) DESC";
1568
-
1569
- $pick_orderby = pods_var_raw( self::$type . '_orderby', $options, null, null, true );
1570
-
1571
- if ( 0 < strlen( $pick_orderby ) )
1572
- $orderby[] = $pick_orderby;
1573
-
1574
- $orderby[] = "`t`.`{$search_data->field_index}`";
1575
- $orderby[] = "`t`.`{$search_data->field_id}`";
1576
-
1577
- $params[ 'orderby' ] = $orderby;
1578
- }
1579
- }
1580
- elseif ( 0 < $limit ) {
1581
- $params[ 'limit' ] = $limit;
1582
- $params[ 'page' ] = $page;
1583
- }
1584
 
1585
- $extra = '';
1586
 
1587
- if ( $wpdb->posts == $search_data->table )
1588
- $extra = ', `t`.`post_type`';
1589
- elseif ( $wpdb->terms == $search_data->table )
1590
- $extra = ', `tt`.`taxonomy`';
1591
- elseif ( $wpdb->comments == $search_data->table )
1592
- $extra = ', `t`.`comment_type`';
1593
 
1594
- $params[ 'select' ] .= $extra;
 
 
1595
 
1596
- if ( 'user' == pods_var( self::$type . '_object', $options ) ) {
1597
- $roles = pods_var( self::$type . '_user_role', $options );
1598
 
1599
- if ( !empty( $roles ) ) {
1600
- $where = array();
 
1601
 
1602
- foreach ( (array) $roles as $role ) {
1603
- if ( empty( $role ) || ( pods_clean_name( $role ) != $role && sanitize_title( $role ) != $role ) )
1604
- continue;
1605
 
1606
- $where[] = $wpdb->base_prefix . ( ( is_multisite() && !is_main_site() ) ? get_current_blog_id() . '_' : '' ) . 'capabilities.meta_value LIKE "%\"' . pods_sanitize_like( $role ) . '\"%"';
1607
- }
1608
 
1609
- if ( !empty( $where ) ) {
1610
- $params[ 'where' ][] = implode( ' OR ', $where );
1611
- }
1612
- }
1613
- }
1614
 
1615
- $results = $search_data->select( $params );
 
1616
 
1617
- if ( $autocomplete && $params[ 'limit' ] < $search_data->total_found() ) {
1618
- if ( !empty( $value ) ) {
1619
- $ids = $value;
 
 
 
 
 
 
 
 
 
 
1620
 
1621
- if ( is_array( $ids ) && isset( $ids[ 0 ] ) && is_array( $ids[ 0 ] ) ) {
1622
- $ids = wp_list_pluck( $ids, $search_data->field_id );
1623
- }
1624
 
1625
- if ( is_array( $ids ) )
1626
- $ids = implode( ', ', $ids );
1627
-
1628
- if ( is_array( $params[ 'where' ] ) )
1629
- $params[ 'where' ] = implode( ' AND ', $params[ 'where' ] );
1630
- if ( !empty( $params[ 'where' ] ) )
1631
- $params[ 'where' ] .= ' AND ';
1632
-
1633
- $params[ 'where' ] .= "`t`.`{$search_data->field_id}` IN ( " . $ids . " )";
1634
-
1635
- $results = $search_data->select( $params );
1636
- }
1637
- }
1638
- else
1639
- $autocomplete = false;
1640
-
1641
- if ( 'data' == $context ) {
1642
- self::$field_data = array(
1643
- 'field' => $name,
1644
- 'id' => $options[ 'id' ],
1645
- 'autocomplete' => $autocomplete
1646
- );
1647
- }
1648
-
1649
- if ( $hierarchy && !$autocomplete && !empty( $results ) && $options[ 'table_info' ][ 'object_hierarchical' ] && !empty( $options[ 'table_info' ][ 'field_parent' ] ) ) {
1650
- $args = array(
1651
- 'id' => $options[ 'table_info' ][ 'field_id' ],
1652
- 'index' => $options[ 'table_info' ][ 'field_index' ],
1653
- 'parent' => $options[ 'table_info' ][ 'field_parent' ],
1654
- );
1655
-
1656
- $results = pods_hierarchical_select( $results, $args );
1657
- }
1658
-
1659
- $ids = array();
1660
-
1661
- if ( !empty( $results ) ) {
1662
- $display_filter = pods_var( 'display_filter', pods_var_raw( 'options', pods_var_raw( $search_data->field_index, $search_data->pod_data[ 'object_fields' ] ) ) );
1663
-
1664
- foreach ( $results as $result ) {
1665
- $result = get_object_vars( $result );
1666
-
1667
- if ( !isset( $result[ $search_data->field_id ] ) || !isset( $result[ $search_data->field_index ] ) )
1668
- continue;
1669
-
1670
- $result[ $search_data->field_index ] = trim( $result[ $search_data->field_index ] );
1671
-
1672
- $object = $object_type = '';
1673
-
1674
- if ( $wpdb->posts == $search_data->table && isset( $result[ 'post_type' ] ) ) {
1675
- $object = $result[ 'post_type' ];
1676
- $object_type = 'post_type';
1677
- }
1678
- elseif ( $wpdb->terms == $search_data->table && isset( $result[ 'taxonomy' ] ) ) {
1679
- $object = $result[ 'taxonomy' ];
1680
- $object_type = 'taxonomy';
1681
- }
1682
-
1683
- if ( 0 < strlen( $display_filter ) ) {
1684
- $display_filter_args = pods_var( 'display_filter_args', pods_var_raw( 'options', pods_var_raw( $search_data->field_index, $search_data->pod_data[ 'object_fields' ] ) ) );
1685
-
1686
- $args = array(
1687
- $display_filter,
1688
- $result[ $search_data->field_index ]
1689
- );
1690
-
1691
- if ( !empty( $display_filter_args ) ) {
1692
- foreach ( (array) $display_filter_args as $display_filter_arg ) {
1693
- if ( isset( $result[ $display_filter_arg ] ) )
1694
- $args[] = $result[ $display_filter_arg ];
1695
- }
1696
- }
1697
-
1698
- $result[ $search_data->field_index ] = call_user_func_array( 'apply_filters', $args );
1699
- }
1700
-
1701
- if ( in_array( $options[ self::$type . '_object' ], array( 'site', 'network' ) ) )
1702
- $result[ $search_data->field_index ] = $result[ $search_data->field_index ] . $result[ 'path' ];
1703
- elseif ( strlen( $result[ $search_data->field_index ] ) < 1 )
1704
- $result[ $search_data->field_index ] = '(No Title)';
1705
-
1706
- if ( 'admin_ajax_relationship' == $context ) {
1707
- $items[] = array(
1708
- 'id' => $result[ $search_data->field_id ],
1709
- 'text' => $result[ $search_data->field_index ],
1710
- 'image' => ''
1711
- );
1712
- }
1713
- else
1714
- $data[ $result[ $search_data->field_id ] ] = $result[ $search_data->field_index ];
1715
-
1716
- $ids[] = $result[ $search_data->field_id ];
1717
- }
1718
- }
1719
- }
1720
-
1721
- if ( $simple && 'admin_ajax_relationship' == $context ) {
1722
- $found_data = array();
1723
 
1724
- foreach ( $data as $k => $v ) {
1725
- if ( false !== stripos( $v, $data_params[ 'query' ] ) || false !== stripos( $k, $data_params[ 'query' ] ) ) {
1726
- $found_data[ $k ] = $v;
1727
- }
1728
- }
1729
 
1730
- $data = $found_data;
 
1731
  }
1732
- }
1733
-
1734
- if ( 'admin_ajax_relationship' == $context ) {
1735
- if ( empty( $items ) && !empty( $data ) ) {
1736
- foreach ( $data as $k => $v ) {
1737
- $items[] = array(
1738
- 'id' => $k,
1739
- 'text' => $v,
1740
- 'image' => ''
1741
- );
1742
- }
1743
- }
1744
-
1745
- return $items;
1746
- }
1747
-
1748
- return $data;
1749
- }
1750
-
1751
- /**
1752
- * Handle autocomplete AJAX
1753
- *
1754
- * @since 2.3
1755
- */
1756
- public function admin_ajax_relationship () {
1757
- pods_session_start();
1758
 
1759
- // Sanitize input
1760
- $params = pods_unslash( (array) $_POST );
1761
 
1762
- foreach ( $params as $key => $value ) {
1763
- if ( 'action' == $key )
1764
- continue;
1765
 
1766
- unset( $params[ $key ] );
 
 
 
 
 
 
 
1767
 
1768
- $params[ str_replace( '_podsfix_', '', $key ) ] = $value;
1769
- }
1770
 
1771
- $params = (object) $params;
1772
 
1773
- $uid = @session_id();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1774
 
1775
- if ( is_user_logged_in() )
1776
- $uid = 'user_' . get_current_user_id();
 
 
 
1777
 
1778
- $nonce_check = 'pods_relationship_' . (int) $params->pod . '_' . $uid . '_' . $params->uri . '_' . (int) $params->field;
1779
 
1780
- if ( !isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, $nonce_check ) )
1781
- pods_error( __( 'Unauthorized request', 'pods' ), PodsInit::$admin );
1782
 
1783
- $api = pods_api();
 
 
 
 
1784
 
1785
- $pod = $api->load_pod( array( 'id' => (int) $params->pod ) );
1786
- $field = $api->load_field( array( 'id' => (int) $params->field, 'table_info' => true ) );
1787
- $id = (int) $params->id;
1788
-
1789
- $limit = 15;
1790
-
1791
- if ( isset( $params->limit ) )
1792
- $limit = (int) $params->limit;
1793
-
1794
- $page = 1;
1795
-
1796
- if ( isset( $params->page ) )
1797
- $page = (int) $params->page;
1798
-
1799
- if ( !isset( $params->query ) || strlen( trim( $params->query ) ) < 1 )
1800
- pods_error( __( 'Invalid field request', 'pods' ), PodsInit::$admin );
1801
- elseif ( empty( $pod ) || empty( $field ) || $pod[ 'id' ] != $field[ 'pod_id' ] || !isset( $pod[ 'fields' ][ $field[ 'name' ] ] ) )
1802
- pods_error( __( 'Invalid field request', 'pods' ), PodsInit::$admin );
1803
- elseif ( 'pick' != $field[ 'type' ] || empty( $field[ 'table_info' ] ) )
1804
- pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin );
1805
- elseif ( 'single' == pods_var( self::$type . '_format_type', $field ) && 'autocomplete' == pods_var( self::$type . '_format_single', $field ) )
1806
- pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin );
1807
- elseif ( 'multi' == pods_var( self::$type . '_format_type', $field ) && 'autocomplete' == pods_var( self::$type . '_format_multi', $field ) )
1808
- pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin );
1809
-
1810
- $object_params = array(
1811
- 'name' => $field[ 'name' ], // The name of the field
1812
- 'value' => null, // The value of the field
1813
- 'options' => array_merge( $field, $field[ 'options' ] ), // Field options
1814
- 'pod' => $pod, // Pod data
1815
- 'id' => $id, // Item ID
1816
- 'context' => 'admin_ajax_relationship', // Data context
1817
- 'data_params' => $params,
1818
- 'page' => $page,
1819
- 'limit' => $limit
1820
- );
1821
-
1822
- $pick_data = apply_filters( 'pods_field_pick_data_ajax', null, $field[ 'name' ], null, $field, $pod, $id );
1823
-
1824
- if ( null !== $pick_data )
1825
- $items = $pick_data;
1826
- else
1827
- $items = $this->get_object_data( $object_params );
1828
-
1829
- if ( !empty( $items ) && isset( $items[ 0 ] ) && !is_array( $items[ 0 ] ) ) {
1830
- $new_items = array();
1831
-
1832
- foreach ( $items as $id => $text ) {
1833
- $new_items[] = array(
1834
- 'id' => $id,
1835
- 'text' => $text,
1836
- 'image' => ''
1837
- );
1838
- }
1839
-
1840
- $items = $new_items;
1841
- }
1842
-
1843
- $items = apply_filters( 'pods_field_pick_data_ajax_items', $items, $field[ 'name' ], null, $field, $pod, $id );
1844
-
1845
- $items = array(
1846
- 'results' => $items
1847
- );
1848
-
1849
- wp_send_json( $items );
1850
-
1851
- die(); // KBAI!
1852
- }
1853
-
1854
- /**
1855
- * Data callback for Post Stati
1856
- *
1857
- * @param string $name The name of the field
1858
- * @param string|array $value The value of the field
1859
- * @param array $options Field options
1860
- * @param array $pod Pod data
1861
- * @param int $id Item ID
1862
- *
1863
- * @return array
1864
- *
1865
- * @since 2.3
1866
- */
1867
- public function data_post_stati ( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
1868
- $data = array();
1869
-
1870
- $post_stati = get_post_stati( array(), 'objects' );
1871
-
1872
- foreach ( $post_stati as $post_status ) {
1873
- $data[ $post_status->name ] = $post_status->label;
1874
- }
1875
-
1876
- return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
1877
- }
1878
-
1879
- /**
1880
- * Data callback for User Roles
1881
- *
1882
- * @param string $name The name of the field
1883
- * @param string|array $value The value of the field
1884
- * @param array $options Field options
1885
- * @param array $pod Pod data
1886
- * @param int $id Item ID
1887
- *
1888
- * @return array
1889
- *
1890
- * @since 2.3
1891
- */
1892
- public function data_roles ( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
1893
- $data = array();
1894
-
1895
- global $wp_roles;
1896
-
1897
- foreach ( $wp_roles->role_objects as $key => $role ) {
1898
- $data[ $key ] = $wp_roles->role_names[ $key ];
1899
- }
1900
-
1901
- return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
1902
- }
1903
-
1904
- /**
1905
- * Data callback for User Capabilities
1906
- *
1907
- * @param string $name The name of the field
1908
- * @param string|array $value The value of the field
1909
- * @param array $options Field options
1910
- * @param array $pod Pod data
1911
- * @param int $id Item ID
1912
- *
1913
- * @return array
1914
- *
1915
- * @since 2.3
1916
- */
1917
- public function data_capabilities ( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
1918
- $data = array();
1919
-
1920
- global $wp_roles;
1921
-
1922
- $default_caps = array(
1923
- 'activate_plugins',
1924
- 'add_users',
1925
- 'create_users',
1926
- 'delete_others_pages',
1927
- 'delete_others_posts',
1928
- 'delete_pages',
1929
- 'delete_plugins',
1930
- 'delete_posts',
1931
- 'delete_private_pages',
1932
- 'delete_private_posts',
1933
- 'delete_published_pages',
1934
- 'delete_published_posts',
1935
- 'delete_users',
1936
- 'edit_dashboard',
1937
- 'edit_files',
1938
- 'edit_others_pages',
1939
- 'edit_others_posts',
1940
- 'edit_pages',
1941
- 'edit_plugins',
1942
- 'edit_posts',
1943
- 'edit_private_pages',
1944
- 'edit_private_posts',
1945
- 'edit_published_pages',
1946
- 'edit_published_posts',
1947
- 'edit_theme_options',
1948
- 'edit_themes',
1949
- 'edit_users',
1950
- 'import',
1951
- 'install_plugins',
1952
- 'install_themes',
1953
- 'list_users',
1954
- 'manage_categories',
1955
- 'manage_links',
1956
- 'manage_options',
1957
- 'moderate_comments',
1958
- 'promote_users',
1959
- 'publish_pages',
1960
- 'publish_posts',
1961
- 'read',
1962
- 'read_private_pages',
1963
- 'read_private_posts',
1964
- 'remove_users',
1965
- 'switch_themes',
1966
- 'unfiltered_html',
1967
- 'unfiltered_upload',
1968
- 'update_core',
1969
- 'update_plugins',
1970
- 'update_themes',
1971
- 'upload_files'
1972
- );
1973
-
1974
- $role_caps = array();
1975
-
1976
- foreach ( $wp_roles->role_objects as $key => $role ) {
1977
- if ( is_array( $role->capabilities ) ) {
1978
- foreach ( $role->capabilities as $cap => $grant ) {
1979
- $role_caps[ $cap ] = $cap;
1980
- }
1981
- }
1982
- }
1983
-
1984
- $role_caps = array_unique( $role_caps );
1985
-
1986
- $capabilities = array_merge( $default_caps, $role_caps );
1987
-
1988
- // To support Members filters
1989
- $capabilities = apply_filters( 'members_get_capabilities', $capabilities );
1990
-
1991
- $capabilities = apply_filters( 'pods_roles_get_capabilities', $capabilities );
1992
-
1993
- sort( $capabilities );
1994
-
1995
- $capabilities = array_unique( $capabilities );
1996
-
1997
- global $wp_roles;
1998
-
1999
- foreach ( $capabilities as $capability ) {
2000
- $data[ $capability ] = $capability;
2001
- }
2002
-
2003
- return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
2004
- }
2005
-
2006
- /**
2007
- * Data callback for Image Sizes
2008
- *
2009
- * @param string $name The name of the field
2010
- * @param string|array $value The value of the field
2011
- * @param array $options Field options
2012
- * @param array $pod Pod data
2013
- * @param int $id Item ID
2014
- *
2015
- * @return array
2016
- *
2017
- * @since 2.3
2018
- */
2019
- public function data_image_sizes ( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
2020
- $data = array();
2021
-
2022
- $image_sizes = get_intermediate_image_sizes();
2023
-
2024
- foreach ( $image_sizes as $image_size ) {
2025
- $data[ $image_size ] = ucwords( str_replace( '-', ' ', $image_size ) );
2026
- }
2027
-
2028
- return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
2029
- }
2030
-
2031
- /**
2032
- * Data callback for Countries
2033
- *
2034
- * @param string $name The name of the field
2035
- * @param string|array $value The value of the field
2036
- * @param array $options Field options
2037
- * @param array $pod Pod data
2038
- * @param int $id Item ID
2039
- *
2040
- * @return array
2041
- *
2042
- * @since 2.3
2043
- */
2044
- public function data_countries ( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
2045
- $data = array(
2046
- 'AF' => __( 'Afghanistan' ),
2047
- 'AL' => __( 'Albania' ),
2048
- 'DZ' => __( 'Algeria' ),
2049
- 'AS' => __( 'American Samoa' ),
2050
- 'AD' => __( 'Andorra' ),
2051
- 'AO' => __( 'Angola' ),
2052
- 'AI' => __( 'Anguilla' ),
2053
- 'AQ' => __( 'Antarctica' ),
2054
- 'AG' => __( 'Antigua and Barbuda' ),
2055
- 'AR' => __( 'Argentina' ),
2056
- 'AM' => __( 'Armenia' ),
2057
- 'AW' => __( 'Aruba' ),
2058
- 'AU' => __( 'Australia' ),
2059
- 'AT' => __( 'Austria' ),
2060
- 'AZ' => __( 'Azerbaijan' ),
2061
- 'BS' => __( 'Bahamas' ),
2062
- 'BH' => __( 'Bahrain' ),
2063
- 'BD' => __( 'Bangladesh' ),
2064
- 'BB' => __( 'Barbados' ),
2065
- 'BY' => __( 'Belarus' ),
2066
- 'BE' => __( 'Belgium' ),
2067
- 'BZ' => __( 'Belize' ),
2068
- 'BJ' => __( 'Benin' ),
2069
- 'BM' => __( 'Bermuda' ),
2070
- 'BT' => __( 'Bhutan' ),
2071
- 'BO' => __( 'Bolivia' ),
2072
- 'BA' => __( 'Bosnia and Herzegovina' ),
2073
- 'BW' => __( 'Botswana' ),
2074
- 'BV' => __( 'Bouvet Island' ),
2075
- 'BR' => __( 'Brazil' ),
2076
- 'BQ' => __( 'British Antarctic Territory' ),
2077
- 'IO' => __( 'British Indian Ocean Territory' ),
2078
- 'VG' => __( 'British Virgin Islands' ),
2079
- 'BN' => __( 'Brunei' ),
2080
- 'BG' => __( 'Bulgaria' ),
2081
- 'BF' => __( 'Burkina Faso' ),
2082
- 'BI' => __( 'Burundi' ),
2083
- 'KH' => __( 'Cambodia' ),
2084
- 'CM' => __( 'Cameroon' ),
2085
- 'CA' => __( 'Canada' ),
2086
- 'CT' => __( 'Canton and Enderbury Islands' ),
2087
- 'CV' => __( 'Cape Verde' ),
2088
- 'KY' => __( 'Cayman Islands' ),
2089
- 'CF' => __( 'Central African Republic' ),
2090
- 'TD' => __( 'Chad' ),
2091
- 'CL' => __( 'Chile' ),
2092
- 'CN' => __( 'China' ),
2093
- 'CX' => __( 'Christmas Island' ),
2094
- 'CC' => __( 'Cocos [Keeling] Islands' ),
2095
- 'CO' => __( 'Colombia' ),
2096
- 'KM' => __( 'Comoros' ),
2097
- 'CG' => __( 'Congo - Brazzaville' ),
2098
- 'CD' => __( 'Congo - Kinshasa' ),
2099
- 'CK' => __( 'Cook Islands' ),
2100
- 'CR' => __( 'Costa Rica' ),
2101
- 'HR' => __( 'Croatia' ),
2102
- 'CU' => __( 'Cuba' ),
2103
- 'CY' => __( 'Cyprus' ),
2104
- 'CZ' => __( 'Czech Republic' ),
2105
- 'CI' => __( 'Côte d’Ivoire' ),
2106
- 'DK' => __( 'Denmark' ),
2107
- 'DJ' => __( 'Djibouti' ),
2108
- 'DM' => __( 'Dominica' ),
2109
- 'DO' => __( 'Dominican Republic' ),
2110
- 'NQ' => __( 'Dronning Maud Land' ),
2111
- 'DD' => __( 'East Germany' ),
2112
- 'EC' => __( 'Ecuador' ),
2113
- 'EG' => __( 'Egypt' ),
2114
- 'SV' => __( 'El Salvador' ),
2115
- 'GQ' => __( 'Equatorial Guinea' ),
2116
- 'ER' => __( 'Eritrea' ),
2117
- 'EE' => __( 'Estonia' ),
2118
- 'ET' => __( 'Ethiopia' ),
2119
- 'FK' => __( 'Falkland Islands' ),
2120
- 'FO' => __( 'Faroe Islands' ),
2121
- 'FJ' => __( 'Fiji' ),
2122
- 'FI' => __( 'Finland' ),
2123
- 'FR' => __( 'France' ),
2124
- 'GF' => __( 'French Guiana' ),
2125
- 'PF' => __( 'French Polynesia' ),
2126
- 'TF' => __( 'French Southern Territories' ),
2127
- 'FQ' => __( 'French Southern and Antarctic Territories' ),
2128
- 'GA' => __( 'Gabon' ),
2129
- 'GM' => __( 'Gambia' ),
2130
- 'GE' => __( 'Georgia' ),
2131
- 'DE' => __( 'Germany' ),
2132
- 'GH' => __( 'Ghana' ),
2133
- 'GI' => __( 'Gibraltar' ),
2134
- 'GR' => __( 'Greece' ),
2135
- 'GL' => __( 'Greenland' ),
2136
- 'GD' => __( 'Grenada' ),
2137
- 'GP' => __( 'Guadeloupe' ),
2138
- 'GU' => __( 'Guam' ),
2139
- 'GT' => __( 'Guatemala' ),
2140
- 'GG' => __( 'Guernsey' ),
2141
- 'GN' => __( 'Guinea' ),
2142
- 'GW' => __( 'Guinea-Bissau' ),
2143
- 'GY' => __( 'Guyana' ),
2144
- 'HT' => __( 'Haiti' ),
2145
- 'HM' => __( 'Heard Island and McDonald Islands' ),
2146
- 'HN' => __( 'Honduras' ),
2147
- 'HK' => __( 'Hong Kong SAR China' ),
2148
- 'HU' => __( 'Hungary' ),
2149
- 'IS' => __( 'Iceland' ),
2150
- 'IN' => __( 'India' ),
2151
- 'ID' => __( 'Indonesia' ),
2152
- 'IR' => __( 'Iran' ),
2153
- 'IQ' => __( 'Iraq' ),
2154
- 'IE' => __( 'Ireland' ),
2155
- 'IM' => __( 'Isle of Man' ),
2156
- 'IL' => __( 'Israel' ),
2157
- 'IT' => __( 'Italy' ),
2158
- 'JM' => __( 'Jamaica' ),
2159
- 'JP' => __( 'Japan' ),
2160
- 'JE' => __( 'Jersey' ),
2161
- 'JT' => __( 'Johnston Island' ),
2162
- 'JO' => __( 'Jordan' ),
2163
- 'KZ' => __( 'Kazakhstan' ),
2164
- 'KE' => __( 'Kenya' ),
2165
- 'KI' => __( 'Kiribati' ),
2166
- 'KW' => __( 'Kuwait' ),
2167
- 'KG' => __( 'Kyrgyzstan' ),
2168
- 'LA' => __( 'Laos' ),
2169
- 'LV' => __( 'Latvia' ),
2170
- 'LB' => __( 'Lebanon' ),
2171
- 'LS' => __( 'Lesotho' ),
2172
- 'LR' => __( 'Liberia' ),
2173
- 'LY' => __( 'Libya' ),
2174
- 'LI' => __( 'Liechtenstein' ),
2175
- 'LT' => __( 'Lithuania' ),
2176
- 'LU' => __( 'Luxembourg' ),
2177
- 'MO' => __( 'Macau SAR China' ),
2178
- 'MK' => __( 'Macedonia' ),
2179
- 'MG' => __( 'Madagascar' ),
2180
- 'MW' => __( 'Malawi' ),
2181
- 'MY' => __( 'Malaysia' ),
2182
- 'MV' => __( 'Maldives' ),
2183
- 'ML' => __( 'Mali' ),
2184
- 'MT' => __( 'Malta' ),
2185
- 'MH' => __( 'Marshall Islands' ),
2186
- 'MQ' => __( 'Martinique' ),
2187
- 'MR' => __( 'Mauritania' ),
2188
- 'MU' => __( 'Mauritius' ),
2189
- 'YT' => __( 'Mayotte' ),
2190
- 'FX' => __( 'Metropolitan France' ),
2191
- 'MX' => __( 'Mexico' ),
2192
- 'FM' => __( 'Micronesia' ),
2193
- 'MI' => __( 'Midway Islands' ),
2194
- 'MD' => __( 'Moldova' ),
2195
- 'MC' => __( 'Monaco' ),
2196
- 'MN' => __( 'Mongolia' ),
2197
- 'ME' => __( 'Montenegro' ),
2198
- 'MS' => __( 'Montserrat' ),
2199
- 'MA' => __( 'Morocco' ),
2200
- 'MZ' => __( 'Mozambique' ),
2201
- 'MM' => __( 'Myanmar [Burma]' ),
2202
- 'NA' => __( 'Namibia' ),
2203
- 'NR' => __( 'Nauru' ),
2204
- 'NP' => __( 'Nepal' ),
2205
- 'NL' => __( 'Netherlands' ),
2206
- 'AN' => __( 'Netherlands Antilles' ),
2207
- 'NT' => __( 'Neutral Zone' ),
2208
- 'NC' => __( 'New Caledonia' ),
2209
- 'NZ' => __( 'New Zealand' ),
2210
- 'NI' => __( 'Nicaragua' ),
2211
- 'NE' => __( 'Niger' ),
2212
- 'NG' => __( 'Nigeria' ),
2213
- 'NU' => __( 'Niue' ),
2214
- 'NF' => __( 'Norfolk Island' ),
2215
- 'KP' => __( 'North Korea' ),
2216
- 'VD' => __( 'North Vietnam' ),
2217
- 'MP' => __( 'Northern Mariana Islands' ),
2218
- 'NO' => __( 'Norway' ),
2219
- 'OM' => __( 'Oman' ),
2220
- 'PC' => __( 'Pacific Islands Trust Territory' ),
2221
- 'PK' => __( 'Pakistan' ),
2222
- 'PW' => __( 'Palau' ),
2223
- 'PS' => __( 'Palestinian Territories' ),
2224
- 'PA' => __( 'Panama' ),
2225
- 'PZ' => __( 'Panama Canal Zone' ),
2226
- 'PG' => __( 'Papua New Guinea' ),
2227
- 'PY' => __( 'Paraguay' ),
2228
- 'YD' => __( "People's Democratic Republic of Yemen" ),
2229
- 'PE' => __( 'Peru' ),
2230
- 'PH' => __( 'Philippines' ),
2231
- 'PN' => __( 'Pitcairn Islands' ),
2232
- 'PL' => __( 'Poland' ),
2233
- 'PT' => __( 'Portugal' ),
2234
- 'PR' => __( 'Puerto Rico' ),
2235
- 'QA' => __( 'Qatar' ),
2236
- 'RO' => __( 'Romania' ),
2237
- 'RU' => __( 'Russia' ),
2238
- 'RW' => __( 'Rwanda' ),
2239
- 'RE' => __( 'Réunion' ),
2240
- 'BL' => __( 'Saint Barthélemy' ),
2241
- 'SH' => __( 'Saint Helena' ),
2242
- 'KN' => __( 'Saint Kitts and Nevis' ),
2243
- 'LC' => __( 'Saint Lucia' ),
2244
- 'MF' => __( 'Saint Martin' ),
2245
- 'PM' => __( 'Saint Pierre and Miquelon' ),
2246
- 'VC' => __( 'Saint Vincent and the Grenadines' ),
2247
- 'WS' => __( 'Samoa' ),
2248
- 'SM' => __( 'San Marino' ),
2249
- 'SA' => __( 'Saudi Arabia' ),
2250
- 'SN' => __( 'Senegal' ),
2251
- 'RS' => __( 'Serbia' ),
2252
- 'CS' => __( 'Serbia and Montenegro' ),
2253
- 'SC' => __( 'Seychelles' ),
2254
- 'SL' => __( 'Sierra Leone' ),
2255
- 'SG' => __( 'Singapore' ),
2256
- 'SK' => __( 'Slovakia' ),
2257
- 'SI' => __( 'Slovenia' ),
2258
- 'SB' => __( 'Solomon Islands' ),
2259
- 'SO' => __( 'Somalia' ),
2260
- 'ZA' => __( 'South Africa' ),
2261
- 'GS' => __( 'South Georgia and the South Sandwich Islands' ),
2262
- 'KR' => __( 'South Korea' ),
2263
- 'ES' => __( 'Spain' ),
2264
- 'LK' => __( 'Sri Lanka' ),
2265
- 'SD' => __( 'Sudan' ),
2266
- 'SR' => __( 'Suriname' ),
2267
- 'SJ' => __( 'Svalbard and Jan Mayen' ),
2268
- 'SZ' => __( 'Swaziland' ),
2269
- 'SE' => __( 'Sweden' ),
2270
- 'CH' => __( 'Switzerland' ),
2271
- 'SY' => __( 'Syria' ),
2272
- 'ST' => __( 'São Tomé and Príncipe' ),
2273
- 'TW' => __( 'Taiwan' ),
2274
- 'TJ' => __( 'Tajikistan' ),
2275
- 'TZ' => __( 'Tanzania' ),
2276
- 'TH' => __( 'Thailand' ),
2277
- 'TL' => __( 'Timor-Leste' ),
2278
- 'TG' => __( 'Togo' ),
2279
- 'TK' => __( 'Tokelau' ),
2280
- 'TO' => __( 'Tonga' ),
2281
- 'TT' => __( 'Trinidad and Tobago' ),
2282
- 'TN' => __( 'Tunisia' ),
2283
- 'TR' => __( 'Turkey' ),
2284
- 'TM' => __( 'Turkmenistan' ),
2285
- 'TC' => __( 'Turks and Caicos Islands' ),
2286
- 'TV' => __( 'Tuvalu' ),
2287
- 'UM' => __( 'U.S. Minor Outlying Islands' ),
2288
- 'PU' => __( 'U.S. Miscellaneous Pacific Islands' ),
2289
- 'VI' => __( 'U.S. Virgin Islands' ),
2290
- 'UG' => __( 'Uganda' ),
2291
- 'UA' => __( 'Ukraine' ),
2292
- 'SU' => __( 'Union of Soviet Socialist Republics' ),
2293
- 'AE' => __( 'United Arab Emirates' ),
2294
- 'GB' => __( 'United Kingdom' ),
2295
- 'US' => __( 'United States' ),
2296
- 'ZZ' => __( 'Unknown or Invalid Region' ),
2297
- 'UY' => __( 'Uruguay' ),
2298
- 'UZ' => __( 'Uzbekistan' ),
2299
- 'VU' => __( 'Vanuatu' ),
2300
- 'VA' => __( 'Vatican City' ),
2301
- 'VE' => __( 'Venezuela' ),
2302
- 'VN' => __( 'Vietnam' ),
2303
- 'WK' => __( 'Wake Island' ),
2304
- 'WF' => __( 'Wallis and Futuna' ),
2305
- 'EH' => __( 'Western Sahara' ),
2306
- 'YE' => __( 'Yemen' ),
2307
- 'ZM' => __( 'Zambia' ),
2308
- 'ZW' => __( 'Zimbabwe' ),
2309
- 'AX' => __( 'Åland Islands' )
2310
- );
2311
-
2312
- return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
2313
- }
2314
-
2315
- /**
2316
- * Data callback for US States
2317
- *
2318
- * @param string $name The name of the field
2319
- * @param string|array $value The value of the field
2320
- * @param array $options Field options
2321
- * @param array $pod Pod data
2322
- * @param int $id Item ID
2323
- *
2324
- * @return array
2325
- *
2326
- * @since 2.3
2327
- */
2328
- public function data_us_states ( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
2329
- $data = array(
2330
- 'AL' => __( 'Alabama' ),
2331
- 'AK' => __( 'Alaska' ),
2332
- 'AZ' => __( 'Arizona' ),
2333
- 'AR' => __( 'Arkansas' ),
2334
- 'CA' => __( 'California' ),
2335
- 'CO' => __( 'Colorado' ),
2336
- 'CT' => __( 'Connecticut' ),
2337
- 'DE' => __( 'Delaware' ),
2338
- 'DC' => __( 'District Of Columbia' ),
2339
- 'FL' => __( 'Florida' ),
2340
- 'GA' => __( 'Georgia' ),
2341
- 'HI' => __( 'Hawaii' ),
2342
- 'ID' => __( 'Idaho' ),
2343
- 'IL' => __( 'Illinois' ),
2344
- 'IN' => __( 'Indiana' ),
2345
- 'IA' => __( 'Iowa' ),
2346
- 'KS' => __( 'Kansas' ),
2347
- 'KY' => __( 'Kentucky' ),
2348
- 'LA' => __( 'Louisiana' ),
2349
- 'ME' => __( 'Maine' ),
2350
- 'MD' => __( 'Maryland' ),
2351
- 'MA' => __( 'Massachusetts' ),
2352
- 'MI' => __( 'Michigan' ),
2353
- 'MN' => __( 'Minnesota' ),
2354
- 'MS' => __( 'Mississippi' ),
2355
- 'MO' => __( 'Missouri' ),
2356
- 'MT' => __( 'Montana' ),
2357
- 'NE' => __( 'Nebraska' ),
2358
- 'NV' => __( 'Nevada' ),
2359
- 'NH' => __( 'New Hampshire' ),
2360
- 'NJ' => __( 'New Jersey' ),
2361
- 'NM' => __( 'New Mexico' ),
2362
- 'NY' => __( 'New York' ),
2363
- 'NC' => __( 'North Carolina' ),
2364
- 'ND' => __( 'North Dakota' ),
2365
- 'OH' => __( 'Ohio' ),
2366
- 'OK' => __( 'Oklahoma' ),
2367
- 'OR' => __( 'Oregon' ),
2368
- 'PA' => __( 'Pennsylvania' ),
2369
- 'RI' => __( 'Rhode Island' ),
2370
- 'SC' => __( 'South Carolina' ),
2371
- 'SD' => __( 'South Dakota' ),
2372
- 'TN' => __( 'Tennessee' ),
2373
- 'TX' => __( 'Texas' ),
2374
- 'UT' => __( 'Utah' ),
2375
- 'VT' => __( 'Vermont' ),
2376
- 'VA' => __( 'Virginia' ),
2377
- 'WA' => __( 'Washington' ),
2378
- 'WV' => __( 'West Virginia' ),
2379
- 'WI' => __( 'Wisconsin' ),
2380
- 'WY' => __( 'Wyoming' )
2381
- );
2382
-
2383
- return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
2384
- }
2385
-
2386
- /**
2387
- * Data callback for US States
2388
- *
2389
- * @param string $name The name of the field
2390
- * @param string|array $value The value of the field
2391
- * @param array $options Field options
2392
- * @param array $pod Pod data
2393
- * @param int $id Item ID
2394
- *
2395
- * @return array
2396
- *
2397
- * @since 2.3
2398
- */
2399
- public function data_days_of_week ( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
2400
 
2401
- /**
2402
- * @var WP_Locale
2403
- */
2404
- global $wp_locale;
2405
 
2406
- return $wp_locale->weekday;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2407
 
2408
- }
2409
-
2410
- /**
2411
- * Data callback for US States
2412
- *
2413
- * @param string $name The name of the field
2414
- * @param string|array $value The value of the field
2415
- * @param array $options Field options
2416
- * @param array $pod Pod data
2417
- * @param int $id Item ID
2418
- *
2419
- * @return array
2420
- *
2421
- * @since 2.3
2422
- */
2423
- public function data_months_of_year ( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
2424
 
2425
  /**
2426
- * @var WP_Locale
 
 
 
 
 
 
2427
  */
2428
- global $wp_locale;
2429
 
2430
- return $wp_locale->month;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2431
 
2432
- }
2433
  }
1
  <?php
2
+
3
  /**
4
  * @package Pods\Fields
5
  */
6
  class PodsField_Pick extends PodsField {
7
 
8
+ /**
9
+ * {@inheritdoc}
10
+ */
11
+ public static $group = 'Relationships / Media';
12
+
13
+ /**
14
+ * {@inheritdoc}
15
+ */
16
+ public static $type = 'pick';
17
+
18
+ /**
19
+ * {@inheritdoc}
20
+ */
21
+ public static $label = 'Relationship';
22
+
23
+ /**
24
+ * Available Related Objects.
25
+ *
26
+ * @var array
27
+ * @since 2.3
28
+ */
29
+ public static $related_objects = array();
30
+
31
+ /**
32
+ * Custom Related Objects
33
+ *
34
+ * @var array
35
+ * @since 2.3
36
+ */
37
+ public static $custom_related_objects = array();
38
+
39
+ /**
40
+ * Data used during validate / save to avoid extra queries.
41
+ *
42
+ * @var array
43
+ * @since 2.3
44
+ */
45
+ public static $related_data = array();
46
+
47
+ /**
48
+ * Data used during input method (mainly for autocomplete).
49
+ *
50
+ * @var array
51
+ * @since 2.3
52
+ */
53
+ public static $field_data = array();
54
+
55
+ /**
56
+ * API caching for fields that need it during validate/save.
57
+ *
58
+ * @var \PodsAPI
59
+ * @since 2.3
60
+ */
61
+ protected static $api = false;
 
 
 
 
 
 
 
 
 
62
 
63
  /**
64
+ * Saved array of simple relationship names.
65
  *
66
  * @var array
67
  * @since 2.5
84
  */
85
  private static $names_bidirectional = null;
86
 
87
+ /**
88
+ * {@inheritdoc}
89
+ */
90
+ public function __construct() {
91
+
92
+ self::$label = __( 'Relationship', 'pods' );
93
+ }
94
+
95
+ /**
96
+ * Add admin_init actions.
97
+ *
98
+ * @since 2.3
99
+ */
100
+ public function admin_init() {
101
+
102
+ // AJAX for Relationship lookups.
103
+ add_action( 'wp_ajax_pods_relationship', array( $this, 'admin_ajax_relationship' ) );
104
+ add_action( 'wp_ajax_nopriv_pods_relationship', array( $this, 'admin_ajax_relationship' ) );
105
+
106
+ // Handle modal input.
107
+ add_action( 'edit_form_top', array( $this, 'admin_modal_input' ) );
108
+ add_action( 'show_user_profile', array( $this, 'admin_modal_input' ) );
109
+ add_action( 'edit_user_profile', array( $this, 'admin_modal_input' ) );
110
+ add_action( 'edit_category_form', array( $this, 'admin_modal_input' ) );
111
+ add_action( 'edit_link_category_form', array( $this, 'admin_modal_input' ) );
112
+ add_action( 'edit_tag_form', array( $this, 'admin_modal_input' ) );
113
+ add_action( 'add_tag_form', array( $this, 'admin_modal_input' ) );
114
+ add_action( 'pods_meta_box_pre', array( $this, 'admin_modal_input' ) );
115
+
116
+ // Handle modal saving.
117
+ add_filter( 'redirect_post_location', array( $this, 'admin_modal_bail_post_redirect' ), 10, 2 );
118
+ add_action( 'load-edit-tags.php', array( $this, 'admin_modal_bail_term_action' ) );
119
+ add_action( 'load-categories.php', array( $this, 'admin_modal_bail_term_action' ) );
120
+ add_action( 'load-edit-link-categories.php', array( $this, 'admin_modal_bail_term_action' ) );
121
+ add_action( 'personal_options_update', array( $this, 'admin_modal_bail_user_action' ) );
122
+ add_action( 'user_register', array( $this, 'admin_modal_bail_user_action' ) );
123
+ add_action( 'pods_api_processed_form', array( $this, 'admin_modal_bail_pod' ), 10, 3 );
124
+
125
+ }
126
+
127
+ /**
128
+ * {@inheritdoc}
129
+ */
130
+ public function options() {
131
+
132
+ $options = array(
133
+ self::$type . '_format_type' => array(
134
+ 'label' => __( 'Selection Type', 'pods' ),
135
+ 'help' => __( 'help', 'pods' ),
136
+ 'default' => 'single',
137
+ 'type' => 'pick',
138
+ 'data' => array(
139
+ 'single' => __( 'Single Select', 'pods' ),
140
+ 'multi' => __( 'Multiple Select', 'pods' ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  ),
142
+ 'dependency' => true,
143
+ ),
144
+ self::$type . '_format_single' => array(
145
+ 'label' => __( 'Format', 'pods' ),
146
+ 'help' => __( 'help', 'pods' ),
147
+ 'depends-on' => array( self::$type . '_format_type' => 'single' ),
148
+ 'default' => 'dropdown',
149
+ 'type' => 'pick',
150
+ 'data' => apply_filters( 'pods_form_ui_field_pick_format_single_options', array(
151
+ 'dropdown' => __( 'Drop Down', 'pods' ),
152
+ 'radio' => __( 'Radio Buttons', 'pods' ),
153
+ 'autocomplete' => __( 'Autocomplete', 'pods' ),
154
+ 'list' => __( 'List view', 'pods' ),
155
+ )
156
  ),
157
+ 'dependency' => true,
 
158
  ),
159
+ self::$type . '_format_multi' => array(
160
+ 'label' => __( 'Format', 'pods' ),
161
+ 'help' => __( 'help', 'pods' ),
162
+ 'depends-on' => array( self::$type . '_format_type' => 'multi' ),
163
+ 'default' => 'checkbox',
164
+ 'type' => 'pick',
165
+ 'data' => apply_filters( 'pods_form_ui_field_pick_format_multi_options', array(
166
+ 'checkbox' => __( 'Checkboxes', 'pods' ),
167
+ 'multiselect' => __( 'Multi Select', 'pods' ),
168
+ 'autocomplete' => __( 'Autocomplete', 'pods' ),
169
+ 'list' => __( 'List view', 'pods' ),
170
+ )
171
+ ),
172
+ 'dependency' => true,
173
  ),
174
+ self::$type . '_allow_add_new' => array(
175
+ 'label' => __( 'Allow Add New', 'pods' ),
176
+ 'help' => __( 'Allow new related records to be created in a modal window', 'pods' ),
177
+ 'wildcard-on' => array(
178
+ self::$type . '_object' => array( '^post-type-(?!(custom-css|customize-changeset)).*$', '^taxonomy-.*$', '^user$', '^pod-.*$' )
179
+ ),
180
+ 'type' => 'boolean',
181
+ 'default' => 1
182
+ ),
183
+ self::$type . '_taggable' => array(
184
+ 'label' => __( 'Taggable', 'pods' ),
185
+ 'help' => __( 'Allow new values to be inserted when using an Autocomplete field', 'pods' ),
186
+ 'excludes-on' => array(
187
+ self::$type . '_format_single' => array( 'dropdown', 'radio', 'list' ),
188
+ self::$type . '_format_multi' => array( 'checkbox', 'multiselect', 'list' ),
189
+ self::$type . '_object' => array_merge( array( 'site', 'network' ), self::simple_objects() ),
190
+ ),
191
+ 'type' => 'boolean',
192
+ 'default' => 0,
193
+ ),
194
+ self::$type . '_show_icon' => array(
195
+ 'label' => __( 'Show Icons', 'pods' ),
196
+ 'excludes-on' => array(
197
+ self::$type . '_format_single' => array( 'dropdown', 'radio', 'autocomplete' ),
198
+ self::$type . '_format_multi' => array( 'checkbox', 'multiselect', 'autocomplete' ),
199
+ self::$type . '_object' => array_merge( array( 'site', 'network' ), self::simple_objects() ),
200
+ ),
201
+ 'type' => 'boolean',
202
+ 'default' => 1,
203
+ ),
204
+ self::$type . '_show_edit_link' => array(
205
+ 'label' => __( 'Show Edit Links', 'pods' ),
206
+ 'excludes-on' => array(
207
+ self::$type . '_format_single' => array( 'dropdown', 'radio', 'autocomplete' ),
208
+ self::$type . '_format_multi' => array( 'checkbox', 'multiselect', 'autocomplete' ),
209
+ self::$type . '_object' => array_merge( array( 'site', 'network' ), self::simple_objects() ),
210
+ ),
211
+ 'type' => 'boolean',
212
+ 'default' => 1,
213
+ ),
214
+ self::$type . '_show_view_link' => array(
215
+ 'label' => __( 'Show View Links', 'pods' ),
216
+ 'excludes-on' => array(
217
+ self::$type . '_format_single' => array( 'dropdown', 'radio', 'autocomplete' ),
218
+ self::$type . '_format_multi' => array( 'checkbox', 'multiselect', 'autocomplete' ),
219
+ self::$type . '_object' => array_merge( array( 'site', 'network' ), self::simple_objects() ),
220
+ ),
221
+ 'type' => 'boolean',
222
+ 'default' => 1,
223
+ ),
224
+ self::$type . '_select_text' => array(
225
+ 'label' => __( 'Default Select Text', 'pods' ),
226
+ 'help' => __( 'This is the text use for the default "no selection" dropdown item, if empty, it will default to "-- Select One --"', 'pods' ),
227
+ 'depends-on' => array(
228
+ self::$type . '_format_type' => 'single',
229
+ self::$type . '_format_single' => 'dropdown',
230
+ ),
231
+ 'default' => '',
232
+ 'type' => 'text',
233
+ ),
234
+ self::$type . '_limit' => array(
235
+ 'label' => __( 'Selection Limit', 'pods' ),
236
+ 'help' => __( 'help', 'pods' ),
237
+ 'depends-on' => array( self::$type . '_format_type' => 'multi' ),
238
+ 'default' => 0,
239
+ 'type' => 'number',
240
+ ),
241
+ self::$type . '_table_id' => array(
242
+ 'label' => __( 'Table ID Column', 'pods' ),
243
+ 'help' => __( 'You must provide the ID column name for the table, this will be used to keep track of the relationship', 'pods' ),
244
+ 'depends-on' => array( self::$type . '_object' => 'table' ),
245
+ 'required' => 1,
246
+ 'default' => '',
247
+ 'type' => 'text',
248
+ ),
249
+ self::$type . '_table_index' => array(
250
+ 'label' => __( 'Table Index Column', 'pods' ),
251
+ 'help' => __( 'You must provide the index column name for the table, this may optionally also be the ID column name', 'pods' ),
252
+ 'depends-on' => array( self::$type . '_object' => 'table' ),
253
+ 'required' => 1,
254
+ 'default' => '',
255
+ 'type' => 'text',
256
+ ),
257
+ self::$type . '_display' => array(
258
+ 'label' => __( 'Display Field in Selection List', 'pods' ),
259
+ 'help' => __( 'Provide the name of a field on the related object to reference, example: {@post_title}', 'pods' ),
260
+ 'excludes-on' => array(
261
+ self::$type . '_object' => array_merge( array( 'site', 'network' ), self::simple_objects() ),
262
+ ),
263
+ 'default' => '',
264
+ 'type' => 'text',
265
+ ),
266
+ self::$type . '_user_role' => array(
267
+ 'label' => __( 'Limit list to Role(s)', 'pods' ),
268
+ 'help' => __( 'help', 'pods' ),
269
+ 'depends-on' => array( self::$type . '_object' => 'user' ),
270
+ 'default' => '',
271
+ 'type' => 'pick',
272
+ 'pick_object' => 'role',
273
+ 'pick_format_type' => 'multi',
274
+ ),
275
+ /*
276
  self::$type . '_user_site' => array(
277
  'label' => __( 'Limit list to Site(s)', 'pods' ),
278
  'help' => __( 'help', 'pods' ),
280
  'default' => '',
281
  'type' => 'pick',
282
  'pick_object' => 'site',
283
+ 'pick_format_type' => 'multi',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  ),
285
+ */
286
+ self::$type . '_where' => array(
287
+ 'label' => __( 'Customized <em>WHERE</em>', 'pods' ),
288
+ 'help' => __( 'help', 'pods' ),
289
+ 'excludes-on' => array(
290
+ self::$type . '_object' => array_merge( array( 'site', 'network' ), self::simple_objects() ),
291
+ ),
292
+ 'default' => '',
293
+ 'type' => 'text',
294
+ ),
295
+ self::$type . '_orderby' => array(
296
+ 'label' => __( 'Customized <em>ORDER BY</em>', 'pods' ),
297
+ 'help' => __( 'help', 'pods' ),
298
+ 'excludes-on' => array(
299
+ self::$type . '_object' => array_merge( array( 'site', 'network' ), self::simple_objects() ),
300
+ ),
301
+ 'default' => '',
302
+ 'type' => 'text',
303
+ ),
304
+ self::$type . '_groupby' => array(
305
+ 'label' => __( 'Customized <em>GROUP BY</em>', 'pods' ),
306
+ 'help' => __( 'help', 'pods' ),
307
+ 'excludes-on' => array(
308
+ self::$type . '_object' => array_merge( array( 'site', 'network' ), self::simple_objects() ),
309
+ ),
310
+ 'default' => '',
311
+ 'type' => 'text',
312
+ ),
313
+ /*
314
+ self::$type . '_size' => array(
315
+ 'label' => __( 'Field Size', 'pods' ),
316
+ 'default' => 'medium',
317
+ 'type' => 'pick',
318
+ 'data' => array(
319
+ 'small' => __( 'Small', 'pods' ),
320
+ 'medium' => __( 'Medium', 'pods' ),
321
+ 'large' => __( 'Large', 'pods' )
322
+ )
323
+ ),
324
+ */
325
+ );
326
+
327
+ $post_type_pick_objects = array();
328
+
329
+ foreach ( get_post_types( '', 'names' ) as $post_type ) {
330
+ $post_type_pick_objects[] = 'post-type_' . $post_type;
331
+ }
332
+
333
+ $options[ self::$type . '_post_status' ] = array(
334
+ 'name' => 'post_status',
335
+ 'label' => __( 'Post Status', 'pods' ),
336
+ 'help' => __( 'help', 'pods' ),
337
+ 'type' => 'pick',
338
+ 'pick_object' => 'post-status',
339
+ 'pick_format_type' => 'multi',
340
+ 'default' => 'publish',
341
+ 'depends-on' => array(
342
+ self::$type . '_object' => $post_type_pick_objects,
343
+ ),
344
+ );
345
+
346
+ /*
347
+ if ( ! is_multisite() ) {
348
+ unset( $options[ self::$type . '_user_site' ] );
349
+ }
350
+ */
351
+
352
+ return $options;
353
+
354
+ }
355
+
356
+ /**
357
+ * Register a related object
358
+ *
359
+ * @param string $name Object name
360
+ * @param string $label Object label
361
+ * @param array $options Object options
362
+ *
363
+ * @return array|boolean Object array or false if unsuccessful
364
+ * @since 2.3
365
+ */
366
+ public function register_related_object( $name, $label, $options = null ) {
367
+
368
+ if ( empty( $name ) || empty( $label ) ) {
369
+ return false;
370
+ }
371
+
372
+ $related_object = array(
373
+ 'label' => $label,
374
+ 'group' => 'Custom Relationships',
375
+ 'simple' => true,
376
+ 'bidirectional' => false,
377
+ 'data' => array(),
378
+ 'data_callback' => null,
379
+ );
380
+
381
+ $related_object = array_merge( $related_object, $options );
382
+
383
+ self::$custom_related_objects[ $name ] = $related_object;
384
+
385
+ return true;
386
+
387
+ }
388
 
389
  /**
390
  * Setup related objects
391
  *
392
  * @param boolean $force Whether to force refresh of related objects
393
+ *
394
  * @return bool True when data has been loaded
395
  * @since 2.3
396
  */
399
  $new_data_loaded = false;
400
 
401
  if ( ! $force && empty( self::$related_objects ) ) {
402
+ // Only load transient if we aren't forcing a refresh.
403
  self::$related_objects = pods_transient_get( 'pods_related_objects' );
404
 
405
  if ( false !== self::$related_objects ) {
406
  $new_data_loaded = true;
407
  }
408
  } elseif ( $force ) {
409
+ // If we are rebuilding, make sure we start with a clean slate.
410
  self::$related_objects = array();
411
  }
412
 
413
  if ( empty( self::$related_objects ) ) {
414
+ // Do a complete build of related_objects.
415
  $new_data_loaded = true;
416
 
417
+ // Custom simple relationship lists.
418
  self::$related_objects['custom-simple'] = array(
419
  'label' => __( 'Simple (custom defined list)', 'pods' ),
420
  'group' => __( 'Custom', 'pods' ),
421
+ 'simple' => true,
422
  );
423
 
424
+ // Pods options.
425
  $pod_options = array();
426
 
427
+ // Include PodsMeta if not already included.
428
  pods_meta();
429
 
430
+ // Advanced Content Types for relationships.
431
  $_pods = PodsMeta::$advanced_content_types;
432
 
433
  foreach ( $_pods as $pod ) {
434
  $pod_options[ $pod['name'] ] = $pod['label'] . ' (' . $pod['name'] . ')';
435
  }
436
 
437
+ // Settings pods for relationships.
438
  $_pods = PodsMeta::$settings;
439
 
440
  foreach ( $_pods as $pod ) {
447
  self::$related_objects[ 'pod-' . $pod ] = array(
448
  'label' => $label,
449
  'group' => __( 'Pods', 'pods' ),
450
+ 'bidirectional' => true,
451
  );
452
  }
453
 
454
+ // Post Types for relationships.
455
  $post_types = get_post_types();
456
  asort( $post_types );
457
 
458
  $ignore = array( 'attachment', 'revision', 'nav_menu_item' );
459
 
460
  foreach ( $post_types as $post_type => $label ) {
461
+ if ( in_array( $post_type, $ignore, true ) || empty( $post_type ) ) {
462
  unset( $post_types[ $post_type ] );
463
 
464
  continue;
473
  self::$related_objects[ 'post_type-' . $post_type->name ] = array(
474
  'label' => $post_type->label . ' (' . $post_type->name . ')',
475
  'group' => __( 'Post Types', 'pods' ),
476
+ 'bidirectional' => true,
477
  );
478
  }
479
 
480
+ // Taxonomies for relationships.
481
  $taxonomies = get_taxonomies();
482
  asort( $taxonomies );
483
 
487
  /**
488
  * Prevent ability to extend core Pods content types.
489
  *
490
+ * @param bool $ignore_internal Default is true, when set to false Pods internal content types can not be extended.
491
  *
492
  * @since 2.3.19
493
  */
494
  $ignore_internal = apply_filters( 'pods_pick_ignore_internal', true );
495
 
496
+ if ( in_array( $taxonomy, $ignore, true ) || empty( $taxonomy ) ) {
497
  unset( $taxonomies[ $taxonomy ] );
498
 
499
  continue;
508
  self::$related_objects[ 'taxonomy-' . $taxonomy->name ] = array(
509
  'label' => $taxonomy->label . ' (' . $taxonomy->name . ')',
510
  'group' => __( 'Taxonomies', 'pods' ),
511
+ 'bidirectional' => true,
512
  );
513
  }
514
 
515
+ // Other WP Objects for relationships.
516
  self::$related_objects['user'] = array(
517
  'label' => __( 'Users', 'pods' ),
518
  'group' => __( 'Other WP Objects', 'pods' ),
519
+ 'bidirectional' => true,
520
  );
521
 
522
  self::$related_objects['role'] = array(
523
  'label' => __( 'User Roles', 'pods' ),
524
  'group' => __( 'Other WP Objects', 'pods' ),
525
  'simple' => true,
526
+ 'data_callback' => array( $this, 'data_roles' ),
527
  );
528
 
529
  self::$related_objects['capability'] = array(
530
  'label' => __( 'User Capabilities', 'pods' ),
531
  'group' => __( 'Other WP Objects', 'pods' ),
532
  'simple' => true,
533
+ 'data_callback' => array( $this, 'data_capabilities' ),
534
  );
535
 
536
  self::$related_objects['media'] = array(
537
  'label' => __( 'Media', 'pods' ),
538
  'group' => __( 'Other WP Objects', 'pods' ),
539
+ 'bidirectional' => true,
540
  );
541
 
542
  self::$related_objects['comment'] = array(
543
  'label' => __( 'Comments', 'pods' ),
544
  'group' => __( 'Other WP Objects', 'pods' ),
545
+ 'bidirectional' => true,
546
  );
547
 
548
  self::$related_objects['image-size'] = array(
549
  'label' => __( 'Image Sizes', 'pods' ),
550
  'group' => __( 'Other WP Objects', 'pods' ),
551
  'simple' => true,
552
+ 'data_callback' => array( $this, 'data_image_sizes' ),
553
  );
554
 
555
  self::$related_objects['nav_menu'] = array(
556
  'label' => __( 'Navigation Menus', 'pods' ),
557
+ 'group' => __( 'Other WP Objects', 'pods' ),
558
  );
559
 
560
  self::$related_objects['post_format'] = array(
561
  'label' => __( 'Post Formats', 'pods' ),
562
+ 'group' => __( 'Other WP Objects', 'pods' ),
563
  );
564
 
565
  self::$related_objects['post-status'] = array(
566
  'label' => __( 'Post Status', 'pods' ),
567
  'group' => __( 'Other WP Objects', 'pods' ),
568
  'simple' => true,
569
+ 'data_callback' => array( $this, 'data_post_stati' ),
570
  );
571
 
572
  do_action( 'pods_form_ui_field_pick_related_objects_other' );
575
  'label' => __( 'Countries', 'pods' ),
576
  'group' => __( 'Predefined Lists', 'pods' ),
577
  'simple' => true,
578
+ 'data_callback' => array( $this, 'data_countries' ),
579
  );
580
 
581
  self::$related_objects['us_state'] = array(
582
  'label' => __( 'US States', 'pods' ),
583
  'group' => __( 'Predefined Lists', 'pods' ),
584
  'simple' => true,
585
+ 'data_callback' => array( $this, 'data_us_states' ),
586
+ );
587
+
588
+ self::$related_objects['ca_province'] = array(
589
+ 'label' => __( 'CA Provinces', 'pods' ),
590
+ 'group' => __( 'Predefined Lists', 'pods' ),
591
+ 'simple' => true,
592
+ 'data_callback' => array( $this, 'data_ca_provinces' ),
593
  );
594
 
595
  self::$related_objects['days_of_week'] = array(
596
  'label' => __( 'Calendar - Days of Week', 'pods' ),
597
  'group' => __( 'Predefined Lists', 'pods' ),
598
  'simple' => true,
599
+ 'data_callback' => array( $this, 'data_days_of_week' ),
600
  );
601
 
602
  self::$related_objects['months_of_year'] = array(
603
  'label' => __( 'Calendar - Months of Year', 'pods' ),
604
  'group' => __( 'Predefined Lists', 'pods' ),
605
  'simple' => true,
606
+ 'data_callback' => array( $this, 'data_months_of_year' ),
607
  );
608
 
609
  do_action( 'pods_form_ui_field_pick_related_objects_predefined' );
630
 
631
  }
632
 
633
+ /**
634
+ * Return available related objects
635
+ *
636
+ * @param boolean $force Whether to force refresh of related objects
637
+ *
638
+ * @return array Field selection array
639
+ * @since 2.3
640
+ */
641
+ public function related_objects( $force = false ) {
642
+
643
+ if ( $this->setup_related_objects( $force ) || null === self::$names_related ) {
644
+ $related_objects = array();
645
+
646
+ foreach ( self::$related_objects as $related_object_name => $related_object ) {
647
+ if ( ! isset( $related_objects[ $related_object['group'] ] ) ) {
648
+ $related_objects[ $related_object['group'] ] = array();
649
+ }
650
+
651
+ $related_objects[ $related_object['group'] ][ $related_object_name ] = $related_object['label'];
652
+ }
653
+
654
+ self::$names_related = (array) apply_filters( 'pods_form_ui_field_pick_related_objects', $related_objects );
655
+ }
656
+
657
+ return self::$names_related;
658
+
659
+ }
660
+
661
+ /**
662
+ * Return available simple object names
663
+ *
664
+ * @return array Simple object names
665
+ * @since 2.3
666
+ */
667
+ public function simple_objects() {
668
+
669
  if ( $this->setup_related_objects() || null === self::$names_simple ) {
670
  $simple_objects = array();
671
 
672
  foreach ( self::$related_objects as $object => $related_object ) {
673
+ if ( ! isset( $related_object['simple'] ) || ! $related_object['simple'] ) {
674
  continue;
675
+ }
676
 
677
  $simple_objects[] = $object;
678
  }
680
  self::$names_simple = (array) apply_filters( 'pods_form_ui_field_pick_simple_objects', $simple_objects );
681
  }
682
 
683
+ return self::$names_simple;
684
+
685
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
686
 
687
  /**
688
+ * Return available bidirectional object names
 
 
 
 
689
  *
690
+ * @return array Bidirectional object names
691
+ * @since 2.3.4
692
  */
693
+ public function bidirectional_objects() {
694
 
695
+ if ( $this->setup_related_objects() || null === self::$names_bidirectional ) {
696
+ $bidirectional_objects = array();
 
 
697
 
698
+ foreach ( self::$related_objects as $object => $related_object ) {
699
+ if ( ! isset( $related_object['bidirectional'] ) || ! $related_object['bidirectional'] ) {
700
+ continue;
701
+ }
702
 
703
+ $bidirectional_objects[] = $object;
704
+ }
705
+
706
+ self::$names_bidirectional = (array) apply_filters( 'pods_form_ui_field_pick_bidirectional_objects', $bidirectional_objects );
707
  }
708
 
709
+ return self::$names_bidirectional;
 
710
 
711
+ }
 
 
 
 
 
 
 
712
 
713
+ /**
714
+ * {@inheritdoc}
715
+ */
716
+ public function schema( $options = null ) {
717
 
718
+ $schema = false;
719
+
720
+ $simple_tableless_objects = $this->simple_objects();
721
+
722
+ if ( in_array( pods_v( self::$type . '_object', $options ), $simple_tableless_objects, true ) ) {
723
+ $schema = 'LONGTEXT';
 
724
  }
725
 
726
+ return $schema;
727
 
728
  }
729
 
730
+ /**
731
+ * {@inheritdoc}
732
+ */
733
+ public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
734
+
735
+ $fields = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
736
 
737
+ if ( is_object( $pod ) && isset( $pod->fields ) ) {
738
+ /**
739
+ * @var $pod Pods
740
+ */
741
+ $fields = $pod->fields;
 
 
 
 
742
 
743
+ if ( ! empty( $pod->pod_data['object_fields'] ) ) {
744
+ $fields = array_merge( $fields, $pod->pod_data['object_fields'] );
745
+ }
746
+ } elseif ( is_array( $pod ) && isset( $pod['fields'] ) ) {
747
+ $fields = $pod['fields'];
748
 
749
+ if ( ! empty( $pod['object_fields'] ) ) {
750
+ $fields = array_merge( $fields, $pod['object_fields'] );
751
+ }
752
+ }
753
 
754
+ return pods_serial_comma( $value, array( 'field' => $name, 'fields' => $fields ) );
 
755
 
756
+ }
 
757
 
758
+ /**
759
+ * {@inheritdoc}
760
+ */
761
+ public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
762
 
763
+ $options = (array) $options;
 
764
 
765
+ $type = pods_v( 'type', $options, static::$type );
 
766
 
767
+ $args = compact( array_keys( get_defined_vars() ) );
768
+ $args = (object) $args;
769
 
770
+ wp_enqueue_script( 'pods-dfv' );
 
 
771
 
772
+ wp_enqueue_style( 'pods-select2' );
773
+ wp_enqueue_script( 'pods-select2' );
774
 
775
+ $this->render_input_script( $args );
 
776
 
777
+ return;
 
778
 
779
+ // @todo Support custom integrations.
780
+ do_action( 'pods_form_ui_field_pick_input_' . pods_v( self::$type . '_format_type', $options, 'single' ) . '_' . pods_v( self::$type . '_format_multi', $options, 'checkbox' ), $name, $value, $options, $pod, $id );
781
+ do_action( 'pods_form_ui_field_pick_input', pods_v( self::$type . '_format_type', $options, 'single' ), $name, $value, $options, $pod, $id );
 
 
 
782
 
783
+ // @todo Support custom integrations.
784
+ do_action( 'pods_form_ui_field_pick_input', pods_v( self::$type . '_format_type', $options, 'single' ), $name, $value, $options, $pod, $id );
785
 
786
+ }
 
 
 
 
787
 
788
+ /**
789
+ * {@inheritdoc}
790
+ */
791
+ public function build_dfv_field_options( $options, $args ) {
 
792
 
793
+ $options['grouped'] = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
794
 
795
+ if ( empty( $options[ $args->type . '_object' ] ) ) {
796
+ $options[ $args->type . '_object' ] = '';
797
+ }
798
 
799
+ if ( empty( $options[ $args->type . '_val' ] ) ) {
800
+ $options[ $args->type . '_val' ] = '';
801
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
802
 
803
+ $options['table_info'] = array();
804
 
805
+ $custom = pods_v( $args->type . '_custom', $options, false );
 
 
806
 
807
+ $custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $args->name, $args->value, $options, $args->pod, $args->id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
808
 
809
+ $ajax = false;
810
 
811
+ if ( ( 'custom-simple' !== pods_v( $args->type . '_object', $options ) || empty( $custom ) ) && '' !== pods_v( $args->type . '_object', $options, '', true ) ) {
812
+ $ajax = true;
813
+ }
 
 
 
814
 
815
+ if ( ! empty( self::$field_data ) && self::$field_data['id'] === $options['id'] ) {
816
+ $ajax = (boolean) self::$field_data['autocomplete'];
817
+ }
818
 
819
+ $ajax = apply_filters( 'pods_form_ui_field_pick_ajax', $ajax, $args->name, $args->value, $options, $args->pod, $args->id );
 
820
 
821
+ if ( 0 === (int) pods_v( $args->type . '_ajax', $options, 1 ) ) {
822
+ $ajax = false;
823
+ }
824
 
825
+ $options[ $args->type . '_ajax' ] = (int) $ajax;
 
 
826
 
827
+ $format_type = pods_v( $args->type . '_format_type', $options, 'single', true );
 
828
 
829
+ $limit = 1;
 
 
 
 
830
 
831
+ if ( 'single' === $format_type ) {
832
+ $format_single = pods_v( $args->type . '_format_single', $options, 'dropdown', true );
833
 
834
+ if ( 'dropdown' === $format_single ) {
835
+ $options['view_name'] = 'select';
836
+ } elseif ( 'radio' === $format_single ) {
837
+ $options['view_name'] = 'radio';
838
+ } elseif ( 'autocomplete' === $format_single ) {
839
+ $options['view_name'] = 'select2';
840
+ } elseif ( 'list' === $format_single ) {
841
+ $options['view_name'] = 'list';
842
+ } else {
843
+ $options['view_name'] = $format_single;
844
+ }
845
+ } elseif ( 'multi' === $format_type ) {
846
+ $format_multi = pods_v( $args->type . '_format_multi', $options, 'checkbox', true );
847
 
848
+ if ( ! empty( $args->value ) && ! is_array( $args->value ) ) {
849
+ $args->value = explode( ',', $args->value );
850
+ }
851
 
852
+ if ( 'checkbox' === $format_multi ) {
853
+ $options['view_name'] = 'checkbox';
854
+ } elseif ( 'multiselect' === $format_multi ) {
855
+ $options['view_name'] = 'select';
856
+ } elseif ( 'autocomplete' === $format_multi ) {
857
+ $options['view_name'] = 'select2';
858
+ } elseif ( 'list' === $format_multi ) {
859
+ $options['view_name'] = 'list';
860
+ } else {
861
+ $options['view_name'] = $format_multi;
862
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
863
 
864
+ $limit = 0;
 
 
 
 
865
 
866
+ if ( ! empty( $options[ $args->type . '_limit' ] ) ) {
867
+ $limit = absint( $options[ $args->type . '_limit' ] );
868
  }
869
+ } else {
870
+ $options['view_name'] = $format_type;
871
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
872
 
873
+ $options[ $args->type . '_limit' ] = $limit;
 
874
 
875
+ $options[ 'ajax_data' ] = $this->build_dfv_autocomplete_ajax_data( $options, $args, $ajax );
 
 
876
 
877
+ /**
878
+ * Allow overriding some of the Select2 options used in the JS init.
879
+ *
880
+ * @param array|null $select2_overrides Override options for Select2/SelectWoo
881
+ *
882
+ * @since 2.7
883
+ */
884
+ $options[ 'select2_overrides' ] = apply_filters( 'pods_pick_select2_overrides', null );
885
 
886
+ return $options;
 
887
 
888
+ }
889
 
890
+ /**
891
+ * @param array $options
892
+ * @param object $args {
893
+ * Field information arguments.
894
+ *
895
+ * @type string $name Field name
896
+ * @type string $type Field type
897
+ * @type array $options Field options
898
+ * @type mixed $value Current value
899
+ * @type array $pod Pod information
900
+ * @type int|string $id Current item ID
901
+ * }
902
+ *
903
+ * @param Boolean $ajax True if ajax mode should be used
904
+ *
905
+ * @return array
906
+ */
907
+ public function build_dfv_autocomplete_ajax_data( $options, $args, $ajax ) {
908
 
909
+ if ( is_object( $args->pod ) ) {
910
+ $pod_id = (int) $args->pod->pod_id;
911
+ } else {
912
+ $pod_id = 0;
913
+ }
914
 
915
+ $field_id = (int) $options[ 'id' ];
916
 
917
+ $id = (int) $args->id;
 
918
 
919
+ if ( is_user_logged_in() ) {
920
+ $uid = 'user_' . get_current_user_id();
921
+ } else {
922
+ $uid = @session_id();
923
+ }
924
 
925
+ $uri_hash = wp_create_nonce( 'pods_uri_' . $_SERVER[ 'REQUEST_URI' ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
926
 
927
+ $field_nonce = wp_create_nonce( 'pods_relationship_' . $pod_id . '_' . $uid . '_' . $uri_hash . '_' . $field_id );
 
 
 
928
 
929
+ // Values can be overridden via the `pods_field_dfv_data` filter in $data['fieldConfig']['ajax_data']
930
+ return array(
931
+ 'ajax' => $ajax,
932
+ 'delay' => 300,
933
+ 'minimum_input_length' => 1,
934
+ 'pod' => $pod_id,
935
+ 'field' => $field_id,
936
+ 'id' => $id,
937
+ 'uri' => $uri_hash,
938
+ '_wpnonce' => $field_nonce
939
+ );
940
+
941
+ }
942
+
943
+ /**
944
+ * {@inheritdoc}
945
+ */
946
+ public function build_dfv_field_config( $args ) {
947
+
948
+ $config = parent::build_dfv_field_config( $args );
949
 
950
+ if ( ! isset( $config['optgroup'] ) ) {
951
+ $config['optgroup'] = false;
952
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
953
 
954
  /**
955
+ * Filter on whether to allow modals to be used on the front of the site (in an non-admin area).
956
+ *
957
+ * @param boolean $show_on_front
958
+ * @param array $config
959
+ * @param array $args
960
+ *
961
+ * @since 2.7
962
  */
963
+ $show_on_front = apply_filters( 'pods_ui_dfv_pick_modals_show_on_front', false, $config, $args );
964
 
965
+ /**
966
+ * Filter on whether to allow nested modals to be used (modals within modals).
967
+ *
968
+ * @param boolean $allow_nested_modals
969
+ * @param array $config
970
+ * @param array $args
971
+ *
972
+ * @since 2.7
973
+ */
974
+ $allow_nested_modals = apply_filters( 'pods_ui_dfv_pick_modals_allow_nested', false, $config, $args );
975
+
976
+ // Disallow add/edit outside the admin and when we're already in a modal
977
+ if ( ( ! $show_on_front && ! is_admin() ) || ( ! $allow_nested_modals && pods_is_modal_window() ) ) {
978
+ $config[ $args->type . '_allow_add_new' ] = false;
979
+ $config[ $args->type . '_show_edit_link' ] = false;
980
+ }
981
+
982
+ $iframe = array(
983
+ 'src' => '',
984
+ 'url' => '',
985
+ 'query_args' => array(),
986
+ );
987
+
988
+ // Set the file name and args based on the content type of the relationship
989
+ switch ( $args->options['pick_object'] ) {
990
+ case 'post_type':
991
+ if ( ! empty( $args->options['pick_val'] ) ) {
992
+ $post_type_obj = get_post_type_object( $args->options['pick_val'] );
993
+
994
+ if ( $post_type_obj && current_user_can( $post_type_obj->cap->create_posts ) ) {
995
+ $iframe['url'] = admin_url( 'post-new.php' );
996
+ $iframe['query_args'] = array(
997
+ 'post_type' => $args->options['pick_val'],
998
+ );
999
+ }
1000
+ }
1001
+
1002
+ break;
1003
+
1004
+ case 'taxonomy':
1005
+ // @todo Fix add new modal issues
1006
+ /*if ( ! empty( $args->options['pick_val'] ) ) {
1007
+ $taxonomy_obj = get_taxonomy( $args->options['pick_val'] );
1008
+
1009
+ if ( $taxonomy_obj && current_user_can( $taxonomy_obj->cap->edit_terms ) ) {
1010
+ $iframe['url'] = admin_url( 'edit-tags.php' );
1011
+ $iframe['query_args'] = array(
1012
+ 'taxonomy' => $args->options['pick_val'],
1013
+ );
1014
+ }
1015
+ }*/
1016
+
1017
+ break;
1018
+
1019
+ case 'user':
1020
+ if ( current_user_can( 'create_users' ) ) {
1021
+ $iframe['url'] = admin_url( 'user-new.php' );
1022
+ }
1023
+
1024
+ break;
1025
+
1026
+ case 'pod':
1027
+ if ( ! empty( $args->options['pick_val'] ) ) {
1028
+ if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $args->options['pick_val'] ) ) ) {
1029
+ $iframe['url'] = admin_url( 'admin.php' );
1030
+ $iframe['query_args'] = array(
1031
+ 'page' => 'pods-manage-' . $args->options['pick_val'],
1032
+ 'action' => 'add',
1033
+ );
1034
+
1035
+ }
1036
+ }
1037
+
1038
+ break;
1039
+ }
1040
+
1041
+ // Potential valid modal target if we've set the file name
1042
+ if ( ! empty( $iframe['url'] ) ) {
1043
+ // @todo: Replace string literal with defined constant
1044
+ $iframe['query_args']['pods_modal'] = 1;
1045
+
1046
+ // Add args we always need
1047
+ $iframe['src'] = add_query_arg( $iframe['query_args'], $iframe['url'] );
1048
+ }
1049
+
1050
+ $iframe['title_add'] = sprintf( __( '%s: Add New', 'pods' ), $args->options['label'] );
1051
+ $iframe['title_edit'] = sprintf( __( '%s: Edit', 'pods' ), $args->options['label'] );
1052
+
1053
+ /**
1054
+ * Allow filtering iframe configuration
1055
+ *
1056
+ * @param array $iframe
1057
+ * @param array $config
1058
+ * @param array $args
1059
+ *
1060
+ * @since 2.7
1061
+ */
1062
+ $iframe = apply_filters( 'pods_ui_dfv_pick_modals_iframe', $iframe, $config, $args );
1063
+
1064
+ if ( ! empty( $iframe['src'] ) ) {
1065
+ // We extend wp.media.view.Modal for modal add/edit, we must ensure we load the template for it
1066
+ wp_enqueue_media();
1067
+
1068
+ }
1069
+
1070
+ $config['iframe_src'] = $iframe['src'];
1071
+ $config['iframe_title_add'] = $iframe['title_add'];
1072
+ $config['iframe_title_edit'] = $iframe['title_edit'];
1073
+
1074
+ return $config;
1075
+
1076
+ }
1077
+
1078
+ /**
1079
+ * {@inheritdoc}
1080
+ */
1081
+ public function build_dfv_field_item_data( $args ) {
1082
+
1083
+ $args->options['supports_thumbnails'] = null;
1084
+
1085
+ $item_data = array();
1086
+
1087
+ if ( ! empty( $args->options['data'] ) ) {
1088
+ $item_data = $this->build_dfv_field_item_data_recurse( $args->options['data'], $args );
1089
+ }
1090
+
1091
+ return $item_data;
1092
+
1093
+ }
1094
+
1095
+ /**
1096
+ * Loop through relationship data and expand item data with additional information for DFV.
1097
+ *
1098
+ * @param array $data Item data to expand.
1099
+ * @param object $args {
1100
+ * Field information arguments.
1101
+ *
1102
+ * @type string $name Field name
1103
+ * @type string $type Field type
1104
+ * @type array $options Field options
1105
+ * @type mixed $value Current value
1106
+ * @type array $pod Pod information
1107
+ * @type int|string $id Current item ID
1108
+ * }
1109
+ *
1110
+ * @return array
1111
+ */
1112
+ public function build_dfv_field_item_data_recurse( $data, $args ) {
1113
+
1114
+ $item_data = array();
1115
+
1116
+ foreach ( $data as $item_id => $item_title ) {
1117
+ if ( is_array( $item_title ) ) {
1118
+ $args->options['optgroup'] = true;
1119
+
1120
+ $item_data[] = array(
1121
+ 'label' => $item_id,
1122
+ 'collection' => $this->build_dfv_field_item_data_recurse( $item_title, $args ),
1123
+ );
1124
+ } else {
1125
+ // Key by item_id temporarily to be able to sort based on $args->value
1126
+ $item_data[ $item_id ] = $this->build_dfv_field_item_data_recurse_item( $item_id, $item_title, $args );
1127
+ }
1128
+ }
1129
+
1130
+ // Maintain any saved sort order from $args->value
1131
+ if ( is_array( $args->value ) && 1 < count( $args->value ) && $this->is_autocomplete( $args->options ) ) {
1132
+ $item_data = array_replace( $args->value, $item_data );
1133
+ }
1134
+
1135
+ // Convert from associative to numeric array
1136
+ $item_data = array_values( $item_data );
1137
+
1138
+ return $item_data;
1139
+
1140
+ }
1141
+
1142
+ /**
1143
+ * Loop through relationship data and expand item data with additional information for DFV.
1144
+ *
1145
+ * @param int|string $item_id
1146
+ * @param string $item_title
1147
+ * @param object $args {
1148
+ * Field information arguments.
1149
+ *
1150
+ * @type string $name Field name
1151
+ * @type string $type Field type
1152
+ * @type array $options Field options
1153
+ * @type mixed $value Current value
1154
+ * @type array $pod Pod information
1155
+ * @type int|string $id Current item ID
1156
+ * }
1157
+ *
1158
+ * @return array
1159
+ */
1160
+ public function build_dfv_field_item_data_recurse_item( $item_id, $item_title, $args ) {
1161
+
1162
+ $use_dashicon = false;
1163
+ $icon = '';
1164
+ $img_icon = '';
1165
+ $edit_link = '';
1166
+ $link = '';
1167
+
1168
+ if ( ! isset( $args->options['supports_thumbnails'] ) ) {
1169
+ $args->options['supports_thumbnails'] = null;
1170
+ }
1171
+
1172
+ switch ( $args->options['pick_object'] ) {
1173
+ case 'post_type':
1174
+ $item_id = (int) $item_id;
1175
+
1176
+ if ( null === $args->options['supports_thumbnails'] && ! empty( $args->options['pick_val'] ) ) {
1177
+ $args->options['supports_thumbnails'] = post_type_supports( $args->options['pick_val'], 'thumbnail' );
1178
+ }
1179
+
1180
+ if ( true === $args->options['supports_thumbnails'] ) {
1181
+ $post_thumbnail_id = get_post_thumbnail_id( $item_id );
1182
+
1183
+ if ( $post_thumbnail_id ) {
1184
+ $thumb = wp_get_attachment_image_src( $post_thumbnail_id, 'thumbnail', false );
1185
+ }
1186
+
1187
+ if ( ! empty( $thumb[0] ) ) {
1188
+ $img_icon = $thumb[0];
1189
+ }
1190
+ }
1191
+
1192
+ if ( empty( $img_icon ) ) {
1193
+
1194
+ // Default icon for posts.
1195
+ $icon = 'dashicons-admin-post';
1196
+
1197
+ // Post type icons.
1198
+ $post_type = (array) get_post_type_object( get_post_type( $item_id ) );
1199
+
1200
+ if ( ! empty( $post_type['menu_icon'] ) ) {
1201
+ // Post specific icon.
1202
+ $icon = $post_type['menu_icon'];
1203
+ } elseif ( isset( $post_type['name'] ) && 'page' ) {
1204
+ switch ( $post_type['name'] ) {
1205
+ case 'page':
1206
+ // Default for pages.
1207
+ $icon = 'dashicons-admin-page';
1208
+ break;
1209
+ case 'attachment':
1210
+ // Default for attachments.
1211
+ $icon = 'dashicons-admin-media';
1212
+ break;
1213
+ }
1214
+ }
1215
+ }
1216
+
1217
+ $edit_link = get_edit_post_link( $item_id, 'raw' );
1218
+
1219
+ $link = get_permalink( $item_id );
1220
+
1221
+ break;
1222
+
1223
+ case 'taxonomy':
1224
+ $item_id = (int) $item_id;
1225
+
1226
+ if ( ! empty( $args->options['pick_val'] ) ) {
1227
+
1228
+ // Default icon for taxonomy.
1229
+ $icon = 'dashicons-category';
1230
+
1231
+ // Change icon for non-hierarchical taxonomies.
1232
+ $taxonomy = get_term( $item_id );
1233
+ if ( isset( $taxonomy->taxonomy ) ) {
1234
+ $taxonomy = (array) get_taxonomy( $taxonomy->taxonomy );
1235
+ if ( isset( $taxonomy['hierarchical'] ) && ! $taxonomy['hierarchical'] ) {
1236
+ $icon = 'dashicons-tag';
1237
+ }
1238
+ }
1239
+
1240
+ $edit_link = get_edit_term_link( $item_id, $args->options['pick_val'] );
1241
+
1242
+ $link = get_term_link( $item_id, $args->options['pick_val'] );
1243
+ }
1244
+
1245
+ break;
1246
+
1247
+ case 'user':
1248
+ $item_id = (int) $item_id;
1249
+
1250
+ $args->options['supports_thumbnails'] = true;
1251
+
1252
+ $icon = 'dashicons-admin-users';
1253
+ $img_icon = get_avatar_url( $item_id, array( 'size' => 150 ) );
1254
+
1255
+ $edit_link = get_edit_user_link( $item_id );
1256
+
1257
+ $link = get_author_posts_url( $item_id );
1258
+
1259
+ break;
1260
+
1261
+ case 'comment':
1262
+ $item_id = (int) $item_id;
1263
+
1264
+ $args->options['supports_thumbnails'] = true;
1265
+
1266
+ $icon = 'dashicons-admin-comments';
1267
+ $img_icon = get_avatar_url( get_comment( $item_id ), array( 'size' => 150 ) );
1268
+
1269
+ $edit_link = get_edit_comment_link( $item_id );
1270
+
1271
+ $link = get_comment_link( $item_id );
1272
+
1273
+ break;
1274
+
1275
+ case 'pod':
1276
+ $item_id = (int) $item_id;
1277
+
1278
+ if ( ! empty( $args->options['pick_val'] ) ) {
1279
+
1280
+ $icon = 'dashicons-pods';
1281
+
1282
+ if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $args->options['pick_val'] ) ) ) {
1283
+ $file_name = 'admin.php';
1284
+ $query_args = array(
1285
+ 'page' => 'pods-manage-' . $args->options['pick_val'],
1286
+ 'action' => 'edit',
1287
+ 'id' => $item_id,
1288
+ );
1289
+
1290
+ $edit_link = add_query_arg( $query_args, admin_url( $file_name ) );
1291
+ }
1292
+
1293
+ // @todo Add $link support
1294
+ $link = '';
1295
+ }
1296
+
1297
+ break;
1298
+ }
1299
+
1300
+ // Image icons always overwrite default icons
1301
+ if ( ! empty( $img_icon ) ) {
1302
+ $icon = $img_icon;
1303
+ }
1304
+
1305
+ // Parse icon type
1306
+ if ( 'none' === $icon || 'div' === $icon ) {
1307
+ $icon = '';
1308
+ $use_dashicon = true;
1309
+ } elseif ( 0 === strpos( $icon, 'data:image/svg+xml;base64,' ) ) {
1310
+ $icon = esc_attr( $icon );
1311
+ $use_dashicon = false;
1312
+ } elseif ( 0 === strpos( $icon, 'dashicons-' ) ) {
1313
+ $icon = sanitize_html_class( $icon );
1314
+ $use_dashicon = true;
1315
+ }
1316
+
1317
+ // Support modal editing
1318
+ if ( ! empty( $edit_link ) ) {
1319
+ // @todo: Replace string literal with defined constant
1320
+ $edit_link = add_query_arg( array( 'pods_modal' => '1' ), $edit_link );
1321
+ }
1322
+
1323
+ // Determine if this is a selected item
1324
+ $selected = false;
1325
+
1326
+ if ( is_array( $args->value ) ) {
1327
+ if ( isset( $args->value[ $item_id ] ) ) {
1328
+ $selected = true;
1329
+ } elseif ( in_array( $item_id, $args->value, true ) ) {
1330
+ $selected = true;
1331
+ }
1332
+ } elseif ( (string) $item_id === (string) $args->value ) {
1333
+ $selected = true;
1334
+ }
1335
+
1336
+ $item = array(
1337
+ 'id' => $item_id,
1338
+ 'use_dashicon' => $use_dashicon,
1339
+ 'icon' => $icon,
1340
+ 'name' => $item_title,
1341
+ 'edit_link' => $edit_link,
1342
+ 'link' => $link,
1343
+ 'selected' => $selected,
1344
+ );
1345
+
1346
+ return $item;
1347
+
1348
+ }
1349
+
1350
+ /**
1351
+ * {@inheritdoc}
1352
+ */
1353
+ public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
1354
+
1355
+ if ( empty( self::$api ) ) {
1356
+ self::$api = pods_api();
1357
+ }
1358
+
1359
+ $simple_tableless_objects = $this->simple_objects();
1360
+
1361
+ $related_pick_limit = 0;
1362
+ $related_field = $related_pod = $current_related_ids = false;
1363
+
1364
+ // Bidirectional relationship requirement checks
1365
+ $related_object = pods_v( self::$type . '_object', $options, '' ); // pod, post_type, taxonomy, etc..
1366
+ $related_val = pods_v( self::$type . '_val', $options, $related_object, null, true ); // pod name, post type name, taxonomy name, etc..
1367
+ if ( empty( $related_val ) ) {
1368
+ $related_val = $related_object;
1369
+ }
1370
+
1371
+ $related_sister_id = (int) pods_v( 'sister_id', $options, 0 );
1372
+
1373
+ $options['id'] = (int) $options['id'];
1374
+
1375
+ if ( ! isset( self::$related_data[ $options['id'] ] ) || empty( self::$related_data[ $options['id'] ] ) ) {
1376
+ self::$related_data[ $options['id'] ] = array();
1377
+ }
1378
+
1379
+ if ( ! empty( $related_sister_id ) && ! in_array( $related_object, $simple_tableless_objects, true ) ) {
1380
+ $related_pod = self::$api->load_pod( array( 'name' => $related_val, 'table_info' => false ), false );
1381
+
1382
+ if ( false !== $related_pod && ( 'pod' === $related_object || $related_object === $related_pod['type'] ) ) {
1383
+ $related_field = false;
1384
+
1385
+ // Ensure sister_id exists on related Pod.
1386
+ foreach ( $related_pod['fields'] as $related_pod_field ) {
1387
+ if ( 'pick' === $related_pod_field['type'] && $related_sister_id === $related_pod_field['id'] ) {
1388
+ $related_field = $related_pod_field;
1389
+
1390
+ break;
1391
+ }
1392
+ }
1393
+
1394
+ if ( ! empty( $related_field ) ) {
1395
+ $current_ids = self::$api->lookup_related_items( $fields[ $name ]['id'], $pod['id'], $id, $fields[ $name ], $pod );
1396
+
1397
+ self::$related_data[ $options['id'] ]['current_ids'] = $current_ids;
1398
+
1399
+ $value_ids = $value;
1400
+
1401
+ // Convert values from a comma-separated string into an array.
1402
+ if ( ! is_array( $value_ids ) ) {
1403
+ $value_ids = explode( ',', $value_ids );
1404
+ }
1405
+
1406
+ $value_ids = array_unique( array_filter( $value_ids ) );
1407
+
1408
+ // Get ids to remove.
1409
+ $remove_ids = array_diff( $current_ids, $value_ids );
1410
+
1411
+ $related_required = (boolean) pods_v( 'required', $related_field['options'], 0 );
1412
+ $related_pick_limit = (int) pods_v( self::$type . '_limit', $related_field['options'], 0 );
1413
+
1414
+ if ( 'single' === pods_v( self::$type . '_format_type', $related_field['options'] ) ) {
1415
+ $related_pick_limit = 1;
1416
+ }
1417
+
1418
+ // Validate Required fields.
1419
+ if ( $related_required && ! empty( $remove_ids ) ) {
1420
+ foreach ( $remove_ids as $related_id ) {
1421
+ $bidirectional_ids = self::$api->lookup_related_items( $related_field['id'], $related_pod['id'], $related_id, $related_field, $related_pod );
1422
+
1423
+ self::$related_data[ $options['id'] ][ 'related_ids_' . $related_id ] = $bidirectional_ids;
1424
+
1425
+ if ( empty( $bidirectional_ids ) || ( in_array( (int) $id, $bidirectional_ids, true ) && 1 === count( $bidirectional_ids ) ) ) {
1426
+ return sprintf( __( 'The %1$s field is required and cannot be removed by the %2$s field', 'pods' ), $related_field['label'], $options['label'] );
1427
+ }
1428
+ }
1429
+ }
1430
+ } else {
1431
+ $related_pod = false;
1432
+ }
1433
+ } else {
1434
+ $related_pod = false;
1435
+ }
1436
+ }
1437
+
1438
+ if ( empty( self::$related_data[ $options['id'] ] ) ) {
1439
+ unset( self::$related_data[ $options['id'] ] );
1440
+ } else {
1441
+ self::$related_data[ $options['id'] ]['related_pod'] = $related_pod;
1442
+ self::$related_data[ $options['id'] ]['related_field'] = $related_field;
1443
+ self::$related_data[ $options['id'] ]['related_pick_limit'] = $related_pick_limit;
1444
+
1445
+ $pick_limit = (int) pods_v( self::$type . '_limit', $options['options'], 0 );
1446
+
1447
+ if ( 'single' === pods_v( self::$type . '_format_type', $options['options'] ) ) {
1448
+ $pick_limit = 1;
1449
+ }
1450
+
1451
+ $related_field['id'] = (int) $related_field['id'];
1452
+
1453
+ if ( ! isset( self::$related_data[ $related_field['id'] ] ) || empty( self::$related_data[ $related_field['id'] ] ) ) {
1454
+ self::$related_data[ $related_field['id'] ] = array(
1455
+ 'related_pod' => $pod,
1456
+ 'related_field' => $options,
1457
+ 'related_pick_limit' => $pick_limit,
1458
+ );
1459
+ }
1460
+ }
1461
+
1462
+ return true;
1463
+
1464
+ }
1465
+
1466
+ /**
1467
+ * {@inheritdoc}
1468
+ */
1469
+ public function save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
1470
+
1471
+ if ( empty( self::$api ) ) {
1472
+ self::$api = pods_api();
1473
+ }
1474
+
1475
+ $options['id'] = (int) $options['id'];
1476
+
1477
+ if ( ! isset( self::$related_data[ $options['id'] ] ) ) {
1478
+ return;
1479
+ }
1480
+
1481
+ $related_pod = self::$related_data[ $options['id'] ]['related_pod'];
1482
+ $related_field = self::$related_data[ $options['id'] ]['related_field'];
1483
+ $related_pick_limit = self::$related_data[ $options['id'] ]['related_pick_limit'];
1484
+
1485
+ // Bidirectional relationship updates.
1486
+ if ( ! empty( $related_field ) ) {
1487
+ // Don't use no conflict mode unless this isn't the current pod type.
1488
+ $no_conflict = true;
1489
+
1490
+ if ( $related_pod['type'] !== $pod['type'] ) {
1491
+ $no_conflict = pods_no_conflict_check( $related_pod['type'] );
1492
+ }
1493
+
1494
+ if ( ! $no_conflict ) {
1495
+ pods_no_conflict_on( $related_pod['type'] );
1496
+ }
1497
+
1498
+ $value = array_filter( $value );
1499
+
1500
+ foreach ( $value as $related_id ) {
1501
+ if ( isset( self::$related_data[ $options['id'] ][ 'related_ids_' . $related_id ] ) && ! empty( self::$related_data[ $options['id'] ][ 'related_ids_' . $related_id ] ) ) {
1502
+ $bidirectional_ids = self::$related_data[ $options['id'] ][ 'related_ids_' . $related_id ];
1503
+ } else {
1504
+ $bidirectional_ids = self::$api->lookup_related_items( $related_field['id'], $related_pod['id'], $related_id, $related_field, $related_pod );
1505
+ }
1506
+
1507
+ $bidirectional_ids = array_filter( $bidirectional_ids );
1508
+
1509
+ if ( empty( $bidirectional_ids ) ) {
1510
+ $bidirectional_ids = array();
1511
+ }
1512
+
1513
+ $remove_ids = array();
1514
+
1515
+ if ( 0 < $related_pick_limit && ! empty( $bidirectional_ids ) && ! in_array( $id, $bidirectional_ids, true ) ) {
1516
+ while ( $related_pick_limit <= count( $bidirectional_ids ) ) {
1517
+ $remove_ids[] = (int) array_pop( $bidirectional_ids );
1518
+ }
1519
+ }
1520
+
1521
+ // Remove this item from related items no longer related to.
1522
+ $remove_ids = array_unique( array_filter( $remove_ids ) );
1523
+
1524
+ if ( ! in_array( $id, $bidirectional_ids, true ) ) {
1525
+ // Add to related items.
1526
+ $bidirectional_ids[] = $id;
1527
+ } elseif ( empty( $remove_ids ) ) {
1528
+ // Nothing to change.
1529
+ continue;
1530
+ }
1531
+
1532
+ self::$api->save_relationships( $related_id, $bidirectional_ids, $related_pod, $related_field );
1533
+
1534
+ if ( ! empty( $remove_ids ) ) {
1535
+ self::$api->delete_relationships( $remove_ids, $related_id, $pod, $options );
1536
+ }
1537
+ }
1538
+
1539
+ if ( ! $no_conflict ) {
1540
+ pods_no_conflict_off( $related_pod['type'] );
1541
+ }
1542
+ }
1543
+
1544
+ }
1545
+
1546
+ /**
1547
+ * Delete the value from the DB
1548
+ *
1549
+ * @param int $id
1550
+ * @param string $name
1551
+ * @param array $options
1552
+ * @param array $pod
1553
+ *
1554
+ * @since 2.3
1555
+ */
1556
+ public function delete( $id = null, $name = null, $options = null, $pod = null ) {
1557
+
1558
+ if ( empty( self::$api ) ) {
1559
+ self::$api = pods_api();
1560
+ }
1561
+
1562
+ $simple_tableless_objects = $this->simple_objects();
1563
+
1564
+ // Bidirectional relationship requirement checks.
1565
+ $related_object = pods_v( self::$type . '_object', $options, '' ); // pod, post_type, taxonomy, etc..
1566
+ $related_val = pods_v( self::$type . '_val', $options, $related_object, true ); // pod name, post type name, taxonomy name, etc..
1567
+ $related_sister_id = (int) pods_v( 'sister_id', $options, 0 );
1568
+
1569
+ if ( ! empty( $related_sister_id ) && ! in_array( $related_object, $simple_tableless_objects, true ) ) {
1570
+ $related_pod = self::$api->load_pod( array( 'name' => $related_val, 'table_info' => false ), false );
1571
+
1572
+ if ( false !== $related_pod && ( 'pod' === $related_object || $related_object === $related_pod['type'] ) ) {
1573
+ $related_field = false;
1574
+
1575
+ // Ensure sister_id exists on related Pod.
1576
+ foreach ( $related_pod['fields'] as $related_pod_field ) {
1577
+ if ( 'pick' === $related_pod_field['type'] && (int) $related_sister_id === (int) $related_pod_field['id'] ) {
1578
+ $related_field = $related_pod_field;
1579
+
1580
+ break;
1581
+ }
1582
+ }
1583
+
1584
+ if ( ! empty( $related_field ) ) {
1585
+ $values = self::$api->lookup_related_items( $options['id'], $pod['id'], $id, $options, $pod );
1586
+
1587
+ if ( ! empty( $values ) ) {
1588
+ $no_conflict = pods_no_conflict_check( $related_pod['type'] );
1589
+
1590
+ if ( ! $no_conflict ) {
1591
+ pods_no_conflict_on( $related_pod['type'] );
1592
+ }
1593
+
1594
+ self::$api->delete_relationships( $values, $id, $related_pod, $related_field );
1595
+
1596
+ if ( ! $no_conflict ) {
1597
+ pods_no_conflict_off( $related_pod['type'] );
1598
+ }
1599
+ }
1600
+ }
1601
+ }
1602
+ }
1603
+
1604
+ }
1605
+
1606
+ /**
1607
+ * {@inheritdoc}
1608
+ */
1609
+ public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
1610
+
1611
+ $value = $this->simple_value( $name, $value, $options, $pod, $id );
1612
+
1613
+ return $this->display( $value, $name, $options, $pod, $id );
1614
+
1615
+ }
1616
+
1617
+ /**
1618
+ * Get the data from the field
1619
+ *
1620
+ * @param string $name The name of the field
1621
+ * @param string|array $value The value of the field
1622
+ * @param array $options Field options
1623
+ * @param array $pod Pod data
1624
+ * @param int $id Item ID
1625
+ * @param boolean $in_form
1626
+ *
1627
+ * @return array Array of possible field data
1628
+ *
1629
+ * @since 2.0
1630
+ */
1631
+ public function data( $name, $value = null, $options = null, $pod = null, $id = null, $in_form = true ) {
1632
+
1633
+ if ( isset( $options['options'] ) ) {
1634
+ $options = array_merge( $options, $options['options'] );
1635
+
1636
+ unset( $options['options'] );
1637
+ }
1638
+
1639
+ $data = pods_v( 'data', $options, null, true );
1640
+
1641
+ $object_params = array(
1642
+ 'name' => $name, // The name of the field.
1643
+ 'value' => $value, // The value of the field.
1644
+ 'options' => $options, // Field options.
1645
+ 'pod' => $pod, // Pod data.
1646
+ 'id' => $id, // Item ID.
1647
+ 'context' => 'data', // Data context.
1648
+ );
1649
+
1650
+ if ( null !== $data ) {
1651
+ $data = (array) $data;
1652
+ } else {
1653
+ $data = $this->get_object_data( $object_params );
1654
+ }
1655
+
1656
+ if ( 'single' === pods_v( self::$type . '_format_type', $options, 'single' ) && 'dropdown' === pods_v( self::$type . '_format_single', $options, 'dropdown' ) ) {
1657
+ $data = array( '' => pods_v( self::$type . '_select_text', $options, __( '-- Select One --', 'pods' ), true ) ) + $data;
1658
+ }
1659
+
1660
+ $data = apply_filters( 'pods_field_pick_data', $data, $name, $value, $options, $pod, $id );
1661
+
1662
+ return $data;
1663
+
1664
+ }
1665
+
1666
+ /**
1667
+ * Convert a simple value to the correct value
1668
+ *
1669
+ * @param string $name The name of the field
1670
+ * @param string|array $value The value of the field
1671
+ * @param array $options Field options
1672
+ * @param array $pod Pod data
1673
+ * @param int $id Item ID
1674
+ * @param boolean $raw Whether to return the raw list of keys (true) or convert to key=>value (false)
1675
+ *
1676
+ * @return mixed Corrected value
1677
+ */
1678
+ public function simple_value( $name, $value = null, $options = null, $pod = null, $id = null, $raw = false ) {
1679
+
1680
+ if ( in_array( pods_v( self::$type . '_object', $options ), self::simple_objects(), true ) ) {
1681
+ if ( isset( $options['options'] ) ) {
1682
+ $options = array_merge( $options, $options['options'] );
1683
+
1684
+ unset( $options['options'] );
1685
+ }
1686
+
1687
+ if ( ! is_array( $value ) && 0 < strlen( $value ) ) {
1688
+ $simple = @json_decode( $value, true );
1689
+
1690
+ if ( is_array( $simple ) ) {
1691
+ $value = $simple;
1692
+ }
1693
+ }
1694
+
1695
+ $data = pods_v( 'data', $options, null, true );
1696
+
1697
+ $object_params = array(
1698
+ 'name' => $name, // The name of the field.
1699
+ 'value' => $value, // The value of the field.
1700
+ 'options' => $options, // Field options.
1701
+ 'pod' => $pod, // Pod data.
1702
+ 'id' => $id, // Item ID.
1703
+ 'context' => 'simple_value', // Data context.
1704
+ );
1705
+
1706
+ if ( null === $data ) {
1707
+ $data = $this->get_object_data( $object_params );
1708
+ }
1709
+
1710
+ $data = (array) $data;
1711
+
1712
+ $key = 0;
1713
+
1714
+ if ( is_array( $value ) ) {
1715
+ if ( ! empty( $data ) ) {
1716
+ $val = array();
1717
+
1718
+ foreach ( $value as $k => $v ) {
1719
+ if ( isset( $data[ $v ] ) ) {
1720
+ if ( false === $raw ) {
1721
+ $k = $v;
1722
+ $v = $data[ $v ];
1723
+ }
1724
+
1725
+ $val[ $k ] = $v;
1726
+ }
1727
+ }
1728
+
1729
+ $value = $val;
1730
+ }
1731
+ } elseif ( isset( $data[ $value ] ) && false === $raw ) {
1732
+ $key = $value;
1733
+ $value = $data[ $value ];
1734
+ }
1735
+
1736
+ $single_multi = pods_v( self::$type . '_format_type', $options, 'single' );
1737
+
1738
+ if ( 'multi' === $single_multi ) {
1739
+ $limit = (int) pods_v( self::$type . '_limit', $options, 0 );
1740
+ } else {
1741
+ $limit = 1;
1742
+ }
1743
+
1744
+ if ( is_array( $value ) && 0 < $limit ) {
1745
+ if ( 1 === $limit ) {
1746
+ $value = current( $value );
1747
+ } else {
1748
+ $value = array_slice( $value, 0, $limit, true );
1749
+ }
1750
+ } elseif ( ! is_array( $value ) && null !== $value && 0 < strlen( $value ) ) {
1751
+ if ( 1 !== $limit || ( true === $raw && 'multi' === $single_multi ) ) {
1752
+ $value = array(
1753
+ $key => $value,
1754
+ );
1755
+ }
1756
+ }
1757
+ }
1758
+
1759
+ return $value;
1760
+
1761
+ }
1762
+
1763
+ /**
1764
+ * Get the label from a pick value
1765
+ *
1766
+ * @param string $name The name of the field
1767
+ * @param string|array $value The value of the field
1768
+ * @param array $options Field options
1769
+ * @param array $pod Pod data
1770
+ * @param int $id Item ID
1771
+ *
1772
+ * @return string
1773
+ *
1774
+ * @since 2.2
1775
+ */
1776
+ public function value_to_label( $name, $value = null, $options = null, $pod = null, $id = null ) {
1777
+
1778
+ if ( isset( $options['options'] ) ) {
1779
+ $options = array_merge( $options, $options['options'] );
1780
+
1781
+ unset( $options['options'] );
1782
+ }
1783
+
1784
+ $data = pods_v( 'data', $options, null, true );
1785
+
1786
+ $object_params = array(
1787
+ 'name' => $name, // The name of the field.
1788
+ 'value' => $value, // The value of the field.
1789
+ 'options' => $options, // Field options.
1790
+ 'pod' => $pod, // Pod data.
1791
+ 'id' => $id, // Item ID.
1792
+ 'context' => 'value_to_label', // Data context.
1793
+ );
1794
+
1795
+ if ( null !== $data ) {
1796
+ $data = (array) $data;
1797
+ } else {
1798
+ $data = $this->get_object_data( $object_params );
1799
+ }
1800
+
1801
+ $labels = array();
1802
+
1803
+ $check_value = $value;
1804
+
1805
+ foreach ( $check_value as &$check_v ) {
1806
+ $check_v = (string) $check_v;
1807
+ }
1808
+
1809
+ foreach ( $data as $v => $l ) {
1810
+ if ( ! in_array( (string) $l, $labels, true ) && ( (string) $value === (string) $v || ( is_array( $value ) && in_array( (string) $v, $value, true ) ) ) ) {
1811
+ $labels[] = (string) $l;
1812
+ }
1813
+ }
1814
+
1815
+ $labels = apply_filters( 'pods_field_pick_value_to_label', $labels, $name, $value, $options, $pod, $id );
1816
+
1817
+ $labels = pods_serial_comma( $labels );
1818
+
1819
+ return $labels;
1820
+
1821
+ }
1822
+
1823
+ /**
1824
+ * Get available items from a relationship field
1825
+ *
1826
+ * @param array|string $field Field array or field name
1827
+ * @param array $options [optional] Field options array overrides
1828
+ * @param array $object_params [optional] Additional get_object_data options
1829
+ *
1830
+ * @return array An array of available items from a relationship field
1831
+ */
1832
+ public function get_field_data( $field, $options = array(), $object_params = array() ) {
1833
+
1834
+ // Handle field array overrides.
1835
+ if ( is_array( $field ) ) {
1836
+ $options = array_merge( $field, $options );
1837
+ }
1838
+
1839
+ // Get field name from array.
1840
+ $field = pods_v( 'name', $options, $field, true );
1841
+
1842
+ // Field name or options not set.
1843
+ if ( empty( $field ) || empty( $options ) ) {
1844
+ return array();
1845
+ }
1846
+
1847
+ // Options normalization.
1848
+ $options = array_merge( $options, pods_v( 'options', $options, array(), true ) );
1849
+
1850
+ // Setup object params.
1851
+ $object_params = array_merge( array(
1852
+ 'name' => $field, // The name of the field.
1853
+ 'options' => $options, // Field options.
1854
+ ), $object_params );
1855
+
1856
+ // Get data override.
1857
+ $data = pods_v( 'data', $options, null, true );
1858
+
1859
+ if ( null !== $data ) {
1860
+ // Return data override.
1861
+ $data = (array) $data;
1862
+ } else {
1863
+ // Get object data.
1864
+ $data = $this->get_object_data( $object_params );
1865
+ }
1866
+
1867
+ return $data;
1868
+
1869
+ }
1870
+
1871
+ /**
1872
+ * Get data from relationship objects
1873
+ *
1874
+ * @param array $object_params Object data parameters
1875
+ *
1876
+ * @return array|bool Object data
1877
+ */
1878
+ public function get_object_data( $object_params = null ) {
1879
+
1880
+ /**
1881
+ * @var $wpdb wpdb
1882
+ */
1883
+ global $wpdb;
1884
+
1885
+ $object_params = array_merge( array(
1886
+ // The name of the field.
1887
+ 'name' => '',
1888
+ // The value of the field.
1889
+ 'value' => '',
1890
+ // Field options.
1891
+ 'options' => array(),
1892
+ // Pod data.
1893
+ 'pod' => '',
1894
+ // Item ID.
1895
+ 'id' => '',
1896
+ // Data context.
1897
+ 'context' => '',
1898
+ // Data parameters.
1899
+ 'data_params' => array(
1900
+ 'query' => '', // Query being searched.
1901
+ ),
1902
+ // Page number of results to get.
1903
+ 'page' => 1,
1904
+ // How many data items to limit to (autocomplete defaults to 30, set to -1 or 1+ to override).
1905
+ 'limit' => 0,
1906
+ ), $object_params );
1907
+
1908
+ $name = $object_params[ 'name' ];
1909
+ $value = $object_params[ 'value' ];
1910
+ $options = $object_params[ 'options' ] = (array) $object_params[ 'options' ];
1911
+ $pod = $object_params[ 'pod' ];
1912
+ $id = $object_params[ 'id' ];
1913
+ $context = $object_params[ 'context' ];
1914
+ $data_params = $object_params[ 'data_params' ] = (array) $object_params[ 'data_params' ];
1915
+ $page = min( 1, (int) $object_params[ 'page' ] );
1916
+ $limit = (int) $object_params[ 'limit' ];
1917
+ $autocomplete = false;
1918
+
1919
+ if ( isset( $options['options'] ) ) {
1920
+ $options = array_merge( $options, $options['options'] );
1921
+
1922
+ unset( $options['options'] );
1923
+ }
1924
+
1925
+ $data = apply_filters( 'pods_field_pick_object_data', null, $name, $value, $options, $pod, $id, $object_params );
1926
+ $items = array();
1927
+
1928
+ if ( ! isset( $options[ self::$type . '_object' ] ) ) {
1929
+ $data = pods_v( 'data', $options, array(), true );
1930
+ }
1931
+
1932
+ $simple = false;
1933
+
1934
+ if ( null === $data ) {
1935
+ $data = array();
1936
+
1937
+ if ( 'custom-simple' === $options[ self::$type . '_object' ] ) {
1938
+ $custom = pods_v( self::$type . '_custom', $options, '' );
1939
+
1940
+ $custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $name, $value, $options, $pod, $id, $object_params );
1941
+
1942
+ if ( ! empty( $custom ) ) {
1943
+ if ( ! is_array( $custom ) ) {
1944
+ $data = array();
1945
+
1946
+ $custom = explode( "\n", trim( $custom ) );
1947
+
1948
+ foreach ( $custom as $custom_value ) {
1949
+ $custom_label = explode( '|', $custom_value );
1950
+
1951
+ if ( empty( $custom_label ) ) {
1952
+ continue;
1953
+ }
1954
+
1955
+ if ( 1 === count( $custom_label ) ) {
1956
+ $custom_label = $custom_value;
1957
+ } else {
1958
+ $custom_value = $custom_label[0];
1959
+ $custom_label = $custom_label[1];
1960
+ }
1961
+
1962
+ $custom_value = trim( (string) $custom_value );
1963
+ $custom_label = trim( (string) $custom_label );
1964
+
1965
+ $data[ $custom_value ] = $custom_label;
1966
+ }
1967
+ } else {
1968
+ $data = $custom;
1969
+ }
1970
+
1971
+ $simple = true;
1972
+ }
1973
+ } elseif ( isset( self::$related_objects[ $options[ self::$type . '_object' ] ] ) && isset( self::$related_objects[ $options[ self::$type . '_object' ] ]['data'] ) && ! empty( self::$related_objects[ $options[ self::$type . '_object' ] ]['data'] ) ) {
1974
+ $data = self::$related_objects[ $options[ self::$type . '_object' ] ]['data'];
1975
+
1976
+ $simple = true;
1977
+ } elseif ( isset( self::$related_objects[ $options[ self::$type . '_object' ] ] ) && isset( self::$related_objects[ $options[ self::$type . '_object' ] ]['data_callback'] ) && is_callable( self::$related_objects[ $options[ self::$type . '_object' ] ]['data_callback'] ) ) {
1978
+ $data = call_user_func_array( self::$related_objects[ $options[ self::$type . '_object' ] ]['data_callback'], array(
1979
+ $name,
1980
+ $value,
1981
+ $options,
1982
+ $pod,
1983
+ $id,
1984
+ )
1985
+ );
1986
+
1987
+ if ( 'data' === $context ) {
1988
+ self::$field_data = array(
1989
+ 'field' => $name,
1990
+ 'id' => $options['id'],
1991
+ 'autocomplete' => false,
1992
+ );
1993
+ }
1994
+
1995
+ $simple = true;
1996
+
1997
+ // Cache data from callback.
1998
+ if ( ! empty( $data ) ) {
1999
+ self::$related_objects[ $options[ self::$type . '_object' ] ]['data'] = $data;
2000
+ }
2001
+ } elseif ( 'simple_value' !== $context ) {
2002
+ $pick_val = pods_v( self::$type . '_val', $options );
2003
+
2004
+ if ( 'table' === pods_v( self::$type . '_object', $options ) ) {
2005
+ $pick_val = pods_v( self::$type . '_table', $options, $pick_val, true );
2006
+ }
2007
+
2008
+ if ( '__current__' === $pick_val ) {
2009
+ if ( is_object( $pod ) ) {
2010
+ $pick_val = $pod->pod;
2011
+ } elseif ( is_array( $pod ) ) {
2012
+ $pick_val = $pod['name'];
2013
+ } elseif ( 0 < strlen( $pod ) ) {
2014
+ $pick_val = $pod;
2015
+ }
2016
+ }
2017
+
2018
+ $options['table_info'] = pods_api()->get_table_info( pods_v( self::$type . '_object', $options ), $pick_val, null, null, $object_params );
2019
+
2020
+ $search_data = pods_data();
2021
+ $search_data->table( $options['table_info'] );
2022
+
2023
+ if ( isset( $options['table_info']['pod'] ) && ! empty( $options['table_info']['pod'] ) && isset( $options['table_info']['pod']['name'] ) ) {
2024
+ $search_data->pod = $options['table_info']['pod']['name'];
2025
+ $search_data->fields = $options['table_info']['pod']['fields'];
2026
+ }
2027
+
2028
+ $params = array(
2029
+ 'select' => "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`",
2030
+ 'table' => $search_data->table,
2031
+ 'where' => pods_v( self::$type . '_where', $options, (array) $options['table_info']['where_default'], true ),
2032
+ 'orderby' => pods_v( self::$type . '_orderby', $options, null, true ),
2033
+ 'groupby' => pods_v( self::$type . '_groupby', $options, null, true ),
2034
+ // 'having' => pods_v( self::$type . '_having', $options, null, true ),
2035
+ 'pagination' => false,
2036
+ 'search' => false
2037
+ );
2038
+
2039
+ if ( in_array( $options[ self::$type . '_object' ], array( 'site', 'network' ), true ) ) {
2040
+ $params['select'] .= ', `t`.`path`';
2041
+ }
2042
+
2043
+ if ( ! empty( $params['where'] ) && (array) $options['table_info']['where_default'] !== $params['where'] ) {
2044
+ $params['where'] = pods_evaluate_tags( $params['where'], true );
2045
+ }
2046
+
2047
+ if ( empty( $params['where'] ) || ( ! is_array( $params['where'] ) && strlen( trim( $params['where'] ) ) < 1 ) ) {
2048
+ $params['where'] = array();
2049
+ } elseif ( ! is_array( $params['where'] ) ) {
2050
+ $params['where'] = (array) $params['where'];
2051
+ }
2052
+
2053
+ if ( 'value_to_label' === $context ) {
2054
+ $params['where'][] = "`t`.`{$search_data->field_id}` = " . number_format( $value, 0, '', '' );
2055
+ }
2056
+
2057
+ /*
2058
+ if ( ! empty( $params['orderby'] ) ) {
2059
+ $params['orderby'] = pods_evaluate_tags( $params['orderby'], true );
2060
+ }
2061
+
2062
+ if ( ! empty( $params['groupby'] ) ) {
2063
+ $params['groupby'] = pods_evaluate_tags( $params['groupby'], true );
2064
+ }
2065
+ */
2066
+
2067
+ $display = trim( pods_v( self::$type . '_display', $options ), ' {@}' );
2068
+
2069
+ if ( 0 < strlen( $display ) ) {
2070
+ if ( isset( $options['table_info']['pod'] ) && ! empty( $options['table_info']['pod'] ) ) {
2071
+ if ( isset( $options['table_info']['pod']['object_fields'] ) && isset( $options['table_info']['pod']['object_fields'][ $display ] ) ) {
2072
+ $search_data->field_index = $display;
2073
+
2074
+ $params['select'] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
2075
+ } elseif ( isset( $options['table_info']['pod']['fields'][ $display ] ) ) {
2076
+ $search_data->field_index = $display;
2077
+
2078
+ if ( 'table' === $options['table_info']['pod']['storage'] && ! in_array( $options['table_info']['pod']['type'], array(
2079
+ 'pod',
2080
+ 'table',
2081
+ ), true )
2082
+ ) {
2083
+ $params['select'] = "`t`.`{$search_data->field_id}`, `d`.`{$search_data->field_index}`";
2084
+ } elseif ( 'meta' === $options['table_info']['pod']['storage'] ) {
2085
+ $params['select'] = "`t`.`{$search_data->field_id}`, `{$search_data->field_index}`.`meta_value` AS {$search_data->field_index}";
2086
+ } else {
2087
+ $params['select'] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
2088
+ }
2089
+ }
2090
+ } elseif ( isset( $options['table_info']['object_fields'] ) && isset( $options['table_info']['object_fields'][ $display ] ) ) {
2091
+ $search_data->field_index = $display;
2092
+
2093
+ $params['select'] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
2094
+ }
2095
+ }
2096
+
2097
+ $autocomplete = $this->is_autocomplete( $options );
2098
+
2099
+ $hierarchy = false;
2100
+
2101
+ if ( 'data' === $context && ! $autocomplete ) {
2102
+ if ( 'single' === pods_v( self::$type . '_format_type', $options, 'single' ) && in_array( pods_v( self::$type . '_format_single', $options, 'dropdown' ), array(
2103
+ 'dropdown',
2104
+ 'radio',
2105
+ ), true )
2106
+ ) {
2107
+ $hierarchy = true;
2108
+ } elseif ( 'multi' === pods_v( self::$type . '_format_type', $options, 'single' ) && in_array( pods_v( self::$type . '_format_multi', $options, 'checkbox' ), array(
2109
+ 'multiselect',
2110
+ 'checkbox',
2111
+ ), true )
2112
+ ) {
2113
+ $hierarchy = true;
2114
+ }
2115
+ }
2116
+
2117
+ if ( $hierarchy && $options['table_info']['object_hierarchical'] && ! empty( $options['table_info']['field_parent'] ) ) {
2118
+ $params['select'] .= ', ' . $options['table_info']['field_parent_select'];
2119
+ }
2120
+
2121
+ if ( $autocomplete ) {
2122
+ if ( 0 === $limit ) {
2123
+ $limit = 30;
2124
+ }
2125
+
2126
+ $params['limit'] = apply_filters( 'pods_form_ui_field_pick_autocomplete_limit', $limit, $name, $value, $options, $pod, $id, $object_params );
2127
+
2128
+ if ( is_array( $value ) && $params['limit'] < count( $value ) ) {
2129
+ $params['limit'] = count( $value );
2130
+ }
2131
+
2132
+ $params['page'] = $page;
2133
+
2134
+ if ( 'admin_ajax_relationship' === $context ) {
2135
+ $lookup_where = array(
2136
+ $search_data->field_index => "`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'",
2137
+ );
2138
+
2139
+ // @todo Hook into WPML for each table
2140
+ if ( $wpdb->users === $search_data->table ) {
2141
+ $lookup_where['display_name'] = "`t`.`display_name` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'";
2142
+ $lookup_where['user_login'] = "`t`.`user_login` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'";
2143
+ $lookup_where['user_email'] = "`t`.`user_email` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'";
2144
+ } elseif ( $wpdb->posts === $search_data->table ) {
2145
+ $lookup_where['post_title'] = "`t`.`post_title` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'";
2146
+ $lookup_where['post_name'] = "`t`.`post_name` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'";
2147
+ $lookup_where['post_content'] = "`t`.`post_content` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'";
2148
+ $lookup_where['post_excerpt'] = "`t`.`post_excerpt` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'";
2149
+ } elseif ( $wpdb->terms === $search_data->table ) {
2150
+ $lookup_where['name'] = "`t`.`name` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'";
2151
+ $lookup_where['slug'] = "`t`.`slug` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'";
2152
+ } elseif ( $wpdb->comments === $search_data->table ) {
2153
+ $lookup_where['comment_content'] = "`t`.`comment_content` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'";
2154
+ $lookup_where['comment_author'] = "`t`.`comment_author` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'";
2155
+ $lookup_where['comment_author_email'] = "`t`.`comment_author_email` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%'";
2156
+ }
2157
+
2158
+ $lookup_where = apply_filters( 'pods_form_ui_field_pick_autocomplete_lookup', $lookup_where, $data_params['query'], $name, $value, $options, $pod, $id, $object_params, $search_data );
2159
+
2160
+ if ( ! empty( $lookup_where ) ) {
2161
+ $params['where'][] = implode( ' OR ', $lookup_where );
2162
+ }
2163
+
2164
+ $orderby = array();
2165
+ $orderby[] = "(`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like( $data_params['query'] ) . "%' ) DESC";
2166
+
2167
+ $pick_orderby = pods_v( self::$type . '_orderby', $options, null, true );
2168
+
2169
+ if ( 0 < strlen( $pick_orderby ) ) {
2170
+ $orderby[] = $pick_orderby;
2171
+ }
2172
+
2173
+ $orderby[] = "`t`.`{$search_data->field_index}`";
2174
+ $orderby[] = "`t`.`{$search_data->field_id}`";
2175
+
2176
+ $params['orderby'] = $orderby;
2177
+ }
2178
+ } elseif ( 0 < $limit ) {
2179
+ $params['limit'] = $limit;
2180
+ $params['page'] = $page;
2181
+ }
2182
+
2183
+ $extra = '';
2184
+
2185
+ if ( $wpdb->posts === $search_data->table ) {
2186
+ $extra = ', `t`.`post_type`';
2187
+ } elseif ( $wpdb->terms === $search_data->table ) {
2188
+ $extra = ', `tt`.`taxonomy`';
2189
+ } elseif ( $wpdb->comments === $search_data->table ) {
2190
+ $extra = ', `t`.`comment_type`';
2191
+ }
2192
+
2193
+ $params['select'] .= $extra;
2194
+
2195
+ if ( 'user' === pods_v( self::$type . '_object', $options ) ) {
2196
+ $roles = pods_v( self::$type . '_user_role', $options );
2197
+
2198
+ if ( ! empty( $roles ) ) {
2199
+ $where = array();
2200
+
2201
+ foreach ( (array) $roles as $role ) {
2202
+ if ( empty( $role ) || ( pods_clean_name( $role ) !== $role && sanitize_title( $role ) !== $role ) ) {
2203
+ continue;
2204
+ }
2205
+
2206
+ $where[] = $wpdb->base_prefix . ( ( is_multisite() && ! is_main_site() ) ? get_current_blog_id() . '_' : '' ) . 'capabilities.meta_value LIKE "%\"' . pods_sanitize_like( $role ) . '\"%"';
2207
+ }
2208
+
2209
+ if ( ! empty( $where ) ) {
2210
+ $params['where'][] = implode( ' OR ', $where );
2211
+ }
2212
+ }
2213
+ }
2214
+
2215
+ $results = $search_data->select( $params );
2216
+
2217
+ if ( $autocomplete && $params['limit'] < $search_data->total_found() ) {
2218
+ if ( ! empty( $value ) ) {
2219
+ $ids = $value;
2220
+
2221
+ if ( is_array( $ids ) && isset( $ids[0] ) && is_array( $ids[0] ) ) {
2222
+ $ids = wp_list_pluck( $ids, $search_data->field_id );
2223
+ }
2224
+
2225
+ if ( is_array( $ids ) ) {
2226
+ $ids = implode( ', ', $ids );
2227
+ }
2228
+
2229
+ if ( is_array( $params['where'] ) ) {
2230
+ $params['where'] = implode( ' AND ', $params['where'] );
2231
+ }
2232
+ if ( ! empty( $params['where'] ) ) {
2233
+ $params['where'] .= ' AND ';
2234
+ }
2235
+
2236
+ $params['where'] .= "`t`.`{$search_data->field_id}` IN ( {$ids} )";
2237
+
2238
+ $results = $search_data->select( $params );
2239
+ }
2240
+ } else {
2241
+ $autocomplete = false;
2242
+ }
2243
+
2244
+ if ( 'data' === $context ) {
2245
+ self::$field_data = array(
2246
+ 'field' => $name,
2247
+ 'id' => $options['id'],
2248
+ 'autocomplete' => $autocomplete,
2249
+ );
2250
+ }
2251
+
2252
+ if ( $hierarchy && ! $autocomplete && ! empty( $results ) && $options['table_info']['object_hierarchical'] && ! empty( $options['table_info']['field_parent'] ) ) {
2253
+ $select_args = array(
2254
+ 'id' => $options['table_info']['field_id'],
2255
+ 'index' => $options['table_info']['field_index'],
2256
+ 'parent' => $options['table_info']['field_parent'],
2257
+ );
2258
+
2259
+ $results = pods_hierarchical_select( $results, $select_args );
2260
+ }
2261
+
2262
+ $ids = array();
2263
+
2264
+ if ( ! empty( $results ) ) {
2265
+ $display_filter = pods_v( 'display_filter', pods_v( 'options', pods_v( $search_data->field_index, $search_data->pod_data['object_fields'] ) ) );
2266
+
2267
+ foreach ( $results as $result ) {
2268
+ $result = get_object_vars( $result );
2269
+
2270
+ if ( ! isset( $result[ $search_data->field_id ] ) || ! isset( $result[ $search_data->field_index ] ) ) {
2271
+ continue;
2272
+ }
2273
+
2274
+ $result[ $search_data->field_index ] = trim( $result[ $search_data->field_index ] );
2275
+
2276
+ $object = $object_type = '';
2277
+
2278
+ if ( $wpdb->posts === $search_data->table && isset( $result['post_type'] ) ) {
2279
+ $object = $result['post_type'];
2280
+ $object_type = 'post_type';
2281
+ } elseif ( $wpdb->terms === $search_data->table && isset( $result['taxonomy'] ) ) {
2282
+ $object = $result['taxonomy'];
2283
+ $object_type = 'taxonomy';
2284
+ }
2285
+
2286
+ if ( 0 < strlen( $display_filter ) ) {
2287
+ $display_filter_args = pods_v( 'display_filter_args', pods_v( 'options', pods_v( $search_data->field_index, $search_data->pod_data['object_fields'] ) ) );
2288
+
2289
+ $filter_args = array(
2290
+ $display_filter,
2291
+ $result[ $search_data->field_index ],
2292
+ );
2293
+
2294
+ if ( ! empty( $display_filter_args ) ) {
2295
+ foreach ( (array) $display_filter_args as $display_filter_arg ) {
2296
+ if ( isset( $result[ $display_filter_arg ] ) ) {
2297
+ $filter_args[] = $result[ $display_filter_arg ];
2298
+ }
2299
+ }
2300
+ }
2301
+
2302
+ $result[ $search_data->field_index ] = call_user_func_array( 'apply_filters', $filter_args );
2303
+ }
2304
+
2305
+ if ( in_array( $options[ self::$type . '_object' ], array( 'site', 'network' ), true ) ) {
2306
+ $result[ $search_data->field_index ] = $result[ $search_data->field_index ] . $result['path'];
2307
+ } elseif ( strlen( $result[ $search_data->field_index ] ) < 1 ) {
2308
+ $result[ $search_data->field_index ] = '(No Title)';
2309
+ }
2310
+
2311
+ if ( 'admin_ajax_relationship' === $context ) {
2312
+ $items[] = $this->build_dfv_field_item_data_recurse_item( $result[ $search_data->field_id ], $result[ $search_data->field_index ], (object) $object_params );
2313
+ } else {
2314
+ $data[ $result[ $search_data->field_id ] ] = $result[ $search_data->field_index ];
2315
+ }
2316
+
2317
+ $ids[] = $result[ $search_data->field_id ];
2318
+ }
2319
+ }
2320
+ }
2321
+
2322
+ if ( $simple && 'admin_ajax_relationship' === $context ) {
2323
+ $found_data = array();
2324
+
2325
+ foreach ( $data as $k => $v ) {
2326
+ if ( false !== stripos( $v, $data_params['query'] ) || false !== stripos( $k, $data_params['query'] ) ) {
2327
+ $found_data[ $k ] = $v;
2328
+ }
2329
+ }
2330
+
2331
+ $data = $found_data;
2332
+ }
2333
+ }
2334
+
2335
+ if ( 'admin_ajax_relationship' === $context ) {
2336
+ if ( empty( $items ) && ! empty( $data ) ) {
2337
+ foreach ( $data as $k => $v ) {
2338
+ $items[] = array(
2339
+ 'id' => $k,
2340
+ 'text' => $v
2341
+ );
2342
+ }
2343
+ }
2344
+
2345
+ $data = $items;
2346
+ }
2347
+
2348
+ return $data;
2349
+
2350
+ }
2351
+
2352
+ /**
2353
+ * @param array $options Field options
2354
+ *
2355
+ * @return bool
2356
+ */
2357
+ public function is_autocomplete( $options ) {
2358
+
2359
+ $autocomplete = false;
2360
+
2361
+ if ( 'single' === pods_v( self::$type . '_format_type', $options, 'single' ) ) {
2362
+ if ( in_array( pods_v( self::$type . '_format_single', $options, 'dropdown' ), array( 'autocomplete', 'list' ) ) ) {
2363
+ $autocomplete = true;
2364
+ }
2365
+ } elseif ( 'multi' === pods_v( self::$type . '_format_type', $options, 'single' ) ) {
2366
+ if ( in_array( pods_v( self::$type . '_format_multi', $options, 'checkbox' ), array( 'autocomplete', 'list' ) ) ) {
2367
+ $autocomplete = true;
2368
+ }
2369
+ }
2370
+
2371
+ return $autocomplete;
2372
+ }
2373
+
2374
+ /**
2375
+ * Handle autocomplete AJAX.
2376
+ *
2377
+ * @since 2.3
2378
+ */
2379
+ public function admin_ajax_relationship() {
2380
+
2381
+ pods_session_start();
2382
+
2383
+ // Sanitize input.
2384
+ $params = pods_unslash( (array) $_POST );
2385
+
2386
+ foreach ( $params as $key => $value ) {
2387
+ if ( 'action' === $key ) {
2388
+ continue;
2389
+ }
2390
+
2391
+ unset( $params[ $key ] );
2392
+
2393
+ $params[ str_replace( '_podsfix_', '', $key ) ] = $value;
2394
+ }
2395
+
2396
+ $params = (object) $params;
2397
+
2398
+ $uid = @session_id();
2399
+
2400
+ if ( is_user_logged_in() ) {
2401
+ $uid = 'user_' . get_current_user_id();
2402
+ }
2403
+
2404
+ $nonce_check = 'pods_relationship_' . (int) $params->pod . '_' . $uid . '_' . $params->uri . '_' . (int) $params->field;
2405
+
2406
+ if ( ! isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, $nonce_check ) ) {
2407
+ pods_error( __( 'Unauthorized request', 'pods' ), PodsInit::$admin );
2408
+ }
2409
+
2410
+ if ( empty( self::$api ) ) {
2411
+ self::$api = pods_api();
2412
+ }
2413
+
2414
+ $pod = self::$api->load_pod( array( 'id' => (int) $params->pod ) );
2415
+ $field = self::$api->load_field( array( 'id' => (int) $params->field, 'table_info' => true ) );
2416
+ $id = (int) $params->id;
2417
+
2418
+ $limit = 15;
2419
+
2420
+ if ( isset( $params->limit ) ) {
2421
+ $limit = (int) $params->limit;
2422
+ }
2423
+
2424
+ $page = 1;
2425
+
2426
+ if ( isset( $params->page ) ) {
2427
+ $page = (int) $params->page;
2428
+ }
2429
+
2430
+ if ( ! isset( $params->query ) || strlen( trim( $params->query ) ) < 1 ) {
2431
+ pods_error( __( 'Invalid field request', 'pods' ), PodsInit::$admin );
2432
+ } elseif ( empty( $pod ) || empty( $field ) || (int) $pod['id'] !== (int) $field['pod_id'] || ! isset( $pod['fields'][ $field['name'] ] ) ) {
2433
+ pods_error( __( 'Invalid field request', 'pods' ), PodsInit::$admin );
2434
+ } elseif ( 'pick' !== $field['type'] || empty( $field['table_info'] ) ) {
2435
+ pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin );
2436
+ } elseif ( 'single' === pods_v( self::$type . '_format_type', $field ) && 'autocomplete' === pods_v( self::$type . '_format_single', $field ) ) {
2437
+ pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin );
2438
+ } elseif ( 'multi' === pods_v( self::$type . '_format_type', $field ) && 'autocomplete' === pods_v( self::$type . '_format_multi', $field ) ) {
2439
+ pods_error( __( 'Invalid field', 'pods' ), PodsInit::$admin );
2440
+ }
2441
+
2442
+ $object_params = array(
2443
+ 'name' => $field['name'], // The name of the field.
2444
+ 'value' => null, // The value of the field.
2445
+ 'options' => array_merge( $field, $field['options'] ), // Field options.
2446
+ 'pod' => $pod, // Pod data.
2447
+ 'id' => $id, // Item ID.
2448
+ 'context' => 'admin_ajax_relationship', // Data context.
2449
+ 'data_params' => $params,
2450
+ 'page' => $page,
2451
+ 'limit' => $limit
2452
+ );
2453
+
2454
+ $pick_data = apply_filters( 'pods_field_pick_data_ajax', null, $field['name'], null, $field, $pod, $id );
2455
+
2456
+ if ( null !== $pick_data ) {
2457
+ $items = $pick_data;
2458
+ } else {
2459
+ $items = $this->get_object_data( $object_params );
2460
+ }
2461
+
2462
+ if ( ! empty( $items ) && isset( $items[0] ) && ! is_array( $items[0] ) ) {
2463
+ $new_items = array();
2464
+
2465
+ foreach ( $items as $id => $text ) {
2466
+ $new_items[] = array(
2467
+ 'id' => $id,
2468
+ 'text' => $text,
2469
+ 'image' => '',
2470
+ );
2471
+ }
2472
+
2473
+ $items = $new_items;
2474
+ }
2475
+
2476
+ $items = apply_filters( 'pods_field_pick_data_ajax_items', $items, $field['name'], null, $field, $pod, $id );
2477
+
2478
+ $items = array(
2479
+ 'results' => $items,
2480
+ );
2481
+
2482
+ wp_send_json( $items );
2483
+
2484
+ die(); // KBAI!
2485
+
2486
+ }
2487
+
2488
+ /**
2489
+ * Data callback for Post Stati
2490
+ *
2491
+ * @param string $name The name of the field
2492
+ * @param string|array $value The value of the field
2493
+ * @param array $options Field options
2494
+ * @param array $pod Pod data
2495
+ * @param int $id Item ID
2496
+ *
2497
+ * @return array
2498
+ *
2499
+ * @since 2.3
2500
+ */
2501
+ public function data_post_stati( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
2502
+
2503
+ $data = array();
2504
+
2505
+ $post_stati = get_post_stati( array(), 'objects' );
2506
+
2507
+ foreach ( $post_stati as $post_status ) {
2508
+ $data[ $post_status->name ] = $post_status->label;
2509
+ }
2510
+
2511
+ return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
2512
+
2513
+ }
2514
+
2515
+ /**
2516
+ * Data callback for User Roles
2517
+ *
2518
+ * @param string $name The name of the field
2519
+ * @param string|array $value The value of the field
2520
+ * @param array $options Field options
2521
+ * @param array $pod Pod data
2522
+ * @param int $id Item ID
2523
+ *
2524
+ * @return array
2525
+ *
2526
+ * @since 2.3
2527
+ */
2528
+ public function data_roles( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
2529
+
2530
+ $data = array();
2531
+
2532
+ global $wp_roles;
2533
+
2534
+ foreach ( $wp_roles->role_objects as $key => $role ) {
2535
+ $data[ $key ] = $wp_roles->role_names[ $key ];
2536
+ }
2537
+
2538
+ return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
2539
+
2540
+ }
2541
+
2542
+ /**
2543
+ * Data callback for User Capabilities
2544
+ *
2545
+ * @param string $name The name of the field
2546
+ * @param string|array $value The value of the field
2547
+ * @param array $options Field options
2548
+ * @param array $pod Pod data
2549
+ * @param int $id Item ID
2550
+ *
2551
+ * @return array
2552
+ *
2553
+ * @since 2.3
2554
+ */
2555
+ public function data_capabilities( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
2556
+
2557
+ $data = array();
2558
+
2559
+ global $wp_roles;
2560
+
2561
+ $default_caps = array(
2562
+ 'activate_plugins',
2563
+ 'add_users',
2564
+ 'create_users',
2565
+ 'delete_others_pages',
2566
+ 'delete_others_posts',
2567
+ 'delete_pages',
2568
+ 'delete_plugins',
2569
+ 'delete_posts',
2570
+ 'delete_private_pages',
2571
+ 'delete_private_posts',
2572
+ 'delete_published_pages',
2573
+ 'delete_published_posts',
2574
+ 'delete_users',
2575
+ 'edit_dashboard',
2576
+ 'edit_files',
2577
+ 'edit_others_pages',
2578
+ 'edit_others_posts',
2579
+ 'edit_pages',
2580
+ 'edit_plugins',
2581
+ 'edit_posts',
2582
+ 'edit_private_pages',
2583
+ 'edit_private_posts',
2584
+ 'edit_published_pages',
2585
+ 'edit_published_posts',
2586
+ 'edit_theme_options',
2587
+ 'edit_themes',
2588
+ 'edit_users',
2589
+ 'import',
2590
+ 'install_plugins',
2591
+ 'install_themes',
2592
+ 'list_users',
2593
+ 'manage_categories',
2594
+ 'manage_links',
2595
+ 'manage_options',
2596
+ 'moderate_comments',
2597
+ 'promote_users',
2598
+ 'publish_pages',
2599
+ 'publish_posts',
2600
+ 'read',
2601
+ 'read_private_pages',
2602
+ 'read_private_posts',
2603
+ 'remove_users',
2604
+ 'switch_themes',
2605
+ 'unfiltered_html',
2606
+ 'unfiltered_upload',
2607
+ 'update_core',
2608
+ 'update_plugins',
2609
+ 'update_themes',
2610
+ 'upload_files',
2611
+ );
2612
+
2613
+ $role_caps = array();
2614
+
2615
+ foreach ( $wp_roles->role_objects as $key => $role ) {
2616
+ if ( is_array( $role->capabilities ) ) {
2617
+ foreach ( $role->capabilities as $cap => $grant ) {
2618
+ $role_caps[ $cap ] = $cap;
2619
+ }
2620
+ }
2621
+ }
2622
+
2623
+ $role_caps = array_unique( $role_caps );
2624
+
2625
+ $capabilities = array_merge( $default_caps, $role_caps );
2626
+
2627
+ // To support Members filters
2628
+ $capabilities = apply_filters( 'members_get_capabilities', $capabilities );
2629
+
2630
+ $capabilities = apply_filters( 'pods_roles_get_capabilities', $capabilities );
2631
+
2632
+ sort( $capabilities );
2633
+
2634
+ $capabilities = array_unique( $capabilities );
2635
+
2636
+ global $wp_roles;
2637
+
2638
+ foreach ( $capabilities as $capability ) {
2639
+ $data[ $capability ] = $capability;
2640
+ }
2641
+
2642
+ return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
2643
+
2644
+ }
2645
+
2646
+ /**
2647
+ * Data callback for Image Sizes
2648
+ *
2649
+ * @param string $name The name of the field
2650
+ * @param string|array $value The value of the field
2651
+ * @param array $options Field options
2652
+ * @param array $pod Pod data
2653
+ * @param int $id Item ID
2654
+ *
2655
+ * @return array
2656
+ *
2657
+ * @since 2.3
2658
+ */
2659
+ public function data_image_sizes( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
2660
+
2661
+ $data = array();
2662
+
2663
+ $image_sizes = get_intermediate_image_sizes();
2664
+
2665
+ foreach ( $image_sizes as $image_size ) {
2666
+ $data[ $image_size ] = ucwords( str_replace( '-', ' ', $image_size ) );
2667
+ }
2668
+
2669
+ return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
2670
+
2671
+ }
2672
+
2673
+ /**
2674
+ * Data callback for Countries
2675
+ *
2676
+ * @param string $name The name of the field
2677
+ * @param string|array $value The value of the field
2678
+ * @param array $options Field options
2679
+ * @param array $pod Pod data
2680
+ * @param int $id Item ID
2681
+ *
2682
+ * @return array
2683
+ *
2684
+ * @since 2.3
2685
+ */
2686
+ public function data_countries( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
2687
+
2688
+ $data = array(
2689
+ 'AF' => __( 'Afghanistan' ),
2690
+ 'AL' => __( 'Albania' ),
2691
+ 'DZ' => __( 'Algeria' ),
2692
+ 'AS' => __( 'American Samoa' ),
2693
+ 'AD' => __( 'Andorra' ),
2694
+ 'AO' => __( 'Angola' ),
2695
+ 'AI' => __( 'Anguilla' ),
2696
+ 'AQ' => __( 'Antarctica' ),
2697
+ 'AG' => __( 'Antigua and Barbuda' ),
2698
+ 'AR' => __( 'Argentina' ),
2699
+ 'AM' => __( 'Armenia' ),
2700
+ 'AW' => __( 'Aruba' ),
2701
+ 'AU' => __( 'Australia' ),
2702
+ 'AT' => __( 'Austria' ),
2703
+ 'AZ' => __( 'Azerbaijan' ),
2704
+ 'BS' => __( 'Bahamas' ),
2705
+ 'BH' => __( 'Bahrain' ),
2706
+ 'BD' => __( 'Bangladesh' ),
2707
+ 'BB' => __( 'Barbados' ),
2708
+ 'BY' => __( 'Belarus' ),
2709
+ 'BE' => __( 'Belgium' ),
2710
+ 'BZ' => __( 'Belize' ),
2711
+ 'BJ' => __( 'Benin' ),
2712
+ 'BM' => __( 'Bermuda' ),
2713
+ 'BT' => __( 'Bhutan' ),
2714
+ 'BO' => __( 'Bolivia' ),
2715
+ 'BA' => __( 'Bosnia and Herzegovina' ),
2716
+ 'BW' => __( 'Botswana' ),
2717
+ 'BV' => __( 'Bouvet Island' ),
2718
+ 'BR' => __( 'Brazil' ),
2719
+ 'BQ' => __( 'British Antarctic Territory' ),
2720
+ 'IO' => __( 'British Indian Ocean Territory' ),
2721
+ 'VG' => __( 'British Virgin Islands' ),
2722
+ 'BN' => __( 'Brunei' ),
2723
+ 'BG' => __( 'Bulgaria' ),
2724
+ 'BF' => __( 'Burkina Faso' ),
2725
+ 'BI' => __( 'Burundi' ),
2726
+ 'KH' => __( 'Cambodia' ),
2727
+ 'CM' => __( 'Cameroon' ),
2728
+ 'CA' => __( 'Canada' ),
2729
+ 'CT' => __( 'Canton and Enderbury Islands' ),
2730
+ 'CV' => __( 'Cape Verde' ),
2731
+ 'KY' => __( 'Cayman Islands' ),
2732
+ 'CF' => __( 'Central African Republic' ),
2733
+ 'TD' => __( 'Chad' ),
2734
+ 'CL' => __( 'Chile' ),
2735
+ 'CN' => __( 'China' ),
2736
+ 'CX' => __( 'Christmas Island' ),
2737
+ 'CC' => __( 'Cocos [Keeling] Islands' ),
2738
+ 'CO' => __( 'Colombia' ),
2739
+ 'KM' => __( 'Comoros' ),
2740
+ 'CG' => __( 'Congo - Brazzaville' ),
2741
+ 'CD' => __( 'Congo - Kinshasa' ),
2742
+ 'CK' => __( 'Cook Islands' ),
2743
+ 'CR' => __( 'Costa Rica' ),
2744
+ 'HR' => __( 'Croatia' ),
2745
+ 'CU' => __( 'Cuba' ),
2746
+ 'CY' => __( 'Cyprus' ),
2747
+ 'CZ' => __( 'Czech Republic' ),
2748
+ 'CI' => __( 'Côte d’Ivoire' ),
2749
+ 'DK' => __( 'Denmark' ),
2750
+ 'DJ' => __( 'Djibouti' ),
2751
+ 'DM' => __( 'Dominica' ),
2752
+ 'DO' => __( 'Dominican Republic' ),
2753
+ 'NQ' => __( 'Dronning Maud Land' ),
2754
+ 'DD' => __( 'East Germany' ),
2755
+ 'EC' => __( 'Ecuador' ),
2756
+ 'EG' => __( 'Egypt' ),
2757
+ 'SV' => __( 'El Salvador' ),
2758
+ 'GQ' => __( 'Equatorial Guinea' ),
2759
+ 'ER' => __( 'Eritrea' ),
2760
+ 'EE' => __( 'Estonia' ),
2761
+ 'ET' => __( 'Ethiopia' ),
2762
+ 'FK' => __( 'Falkland Islands' ),
2763
+ 'FO' => __( 'Faroe Islands' ),
2764
+ 'FJ' => __( 'Fiji' ),
2765
+ 'FI' => __( 'Finland' ),
2766
+ 'FR' => __( 'France' ),
2767
+ 'GF' => __( 'French Guiana' ),
2768
+ 'PF' => __( 'French Polynesia' ),
2769
+ 'TF' => __( 'French Southern Territories' ),
2770
+ 'FQ' => __( 'French Southern and Antarctic Territories' ),
2771
+ 'GA' => __( 'Gabon' ),
2772
+ 'GM' => __( 'Gambia' ),
2773
+ 'GE' => __( 'Georgia' ),
2774
+ 'DE' => __( 'Germany' ),
2775
+ 'GH' => __( 'Ghana' ),
2776
+ 'GI' => __( 'Gibraltar' ),
2777
+ 'GR' => __( 'Greece' ),
2778
+ 'GL' => __( 'Greenland' ),
2779
+ 'GD' => __( 'Grenada' ),
2780
+ 'GP' => __( 'Guadeloupe' ),
2781
+ 'GU' => __( 'Guam' ),
2782
+ 'GT' => __( 'Guatemala' ),
2783
+ 'GG' => __( 'Guernsey' ),
2784
+ 'GN' => __( 'Guinea' ),
2785
+ 'GW' => __( 'Guinea-Bissau' ),
2786
+ 'GY' => __( 'Guyana' ),
2787
+ 'HT' => __( 'Haiti' ),
2788
+ 'HM' => __( 'Heard Island and McDonald Islands' ),
2789
+ 'HN' => __( 'Honduras' ),
2790
+ 'HK' => __( 'Hong Kong SAR China' ),
2791
+ 'HU' => __( 'Hungary' ),
2792
+ 'IS' => __( 'Iceland' ),
2793
+ 'IN' => __( 'India' ),
2794
+ 'ID' => __( 'Indonesia' ),
2795
+ 'IR' => __( 'Iran' ),
2796
+ 'IQ' => __( 'Iraq' ),
2797
+ 'IE' => __( 'Ireland' ),
2798
+ 'IM' => __( 'Isle of Man' ),
2799
+ 'IL' => __( 'Israel' ),
2800
+ 'IT' => __( 'Italy' ),
2801
+ 'JM' => __( 'Jamaica' ),
2802
+ 'JP' => __( 'Japan' ),
2803
+ 'JE' => __( 'Jersey' ),
2804
+ 'JT' => __( 'Johnston Island' ),
2805
+ 'JO' => __( 'Jordan' ),
2806
+ 'KZ' => __( 'Kazakhstan' ),
2807
+ 'KE' => __( 'Kenya' ),
2808
+ 'KI' => __( 'Kiribati' ),
2809
+ 'KW' => __( 'Kuwait' ),
2810
+ 'KG' => __( 'Kyrgyzstan' ),
2811
+ 'LA' => __( 'Laos' ),
2812
+ 'LV' => __( 'Latvia' ),
2813
+ 'LB' => __( 'Lebanon' ),
2814
+ 'LS' => __( 'Lesotho' ),
2815
+ 'LR' => __( 'Liberia' ),
2816
+ 'LY' => __( 'Libya' ),
2817
+ 'LI' => __( 'Liechtenstein' ),
2818
+ 'LT' => __( 'Lithuania' ),
2819
+ 'LU' => __( 'Luxembourg' ),
2820
+ 'MO' => __( 'Macau SAR China' ),
2821
+ 'MK' => __( 'Macedonia' ),
2822
+ 'MG' => __( 'Madagascar' ),
2823
+ 'MW' => __( 'Malawi' ),
2824
+ 'MY' => __( 'Malaysia' ),
2825
+ 'MV' => __( 'Maldives' ),
2826
+ 'ML' => __( 'Mali' ),
2827
+ 'MT' => __( 'Malta' ),
2828
+ 'MH' => __( 'Marshall Islands' ),
2829
+ 'MQ' => __( 'Martinique' ),
2830
+ 'MR' => __( 'Mauritania' ),
2831
+ 'MU' => __( 'Mauritius' ),
2832
+ 'YT' => __( 'Mayotte' ),
2833
+ 'FX' => __( 'Metropolitan France' ),
2834
+ 'MX' => __( 'Mexico' ),
2835
+ 'FM' => __( 'Micronesia' ),
2836
+ 'MI' => __( 'Midway Islands' ),
2837
+ 'MD' => __( 'Moldova' ),
2838
+ 'MC' => __( 'Monaco' ),
2839
+ 'MN' => __( 'Mongolia' ),
2840
+ 'ME' => __( 'Montenegro' ),
2841
+ 'MS' => __( 'Montserrat' ),
2842
+ 'MA' => __( 'Morocco' ),
2843
+ 'MZ' => __( 'Mozambique' ),
2844
+ 'MM' => __( 'Myanmar [Burma]' ),
2845
+ 'NA' => __( 'Namibia' ),
2846
+ 'NR' => __( 'Nauru' ),
2847
+ 'NP' => __( 'Nepal' ),
2848
+ 'NL' => __( 'Netherlands' ),
2849
+ 'AN' => __( 'Netherlands Antilles' ),
2850
+ 'NT' => __( 'Neutral Zone' ),
2851
+ 'NC' => __( 'New Caledonia' ),
2852
+ 'NZ' => __( 'New Zealand' ),
2853
+ 'NI' => __( 'Nicaragua' ),
2854
+ 'NE' => __( 'Niger' ),
2855
+ 'NG' => __( 'Nigeria' ),
2856
+ 'NU' => __( 'Niue' ),
2857
+ 'NF' => __( 'Norfolk Island' ),
2858
+ 'KP' => __( 'North Korea' ),
2859
+ 'VD' => __( 'North Vietnam' ),
2860
+ 'MP' => __( 'Northern Mariana Islands' ),
2861
+ 'NO' => __( 'Norway' ),
2862
+ 'OM' => __( 'Oman' ),
2863
+ 'PC' => __( 'Pacific Islands Trust Territory' ),
2864
+ 'PK' => __( 'Pakistan' ),
2865
+ 'PW' => __( 'Palau' ),
2866
+ 'PS' => __( 'Palestinian Territories' ),
2867
+ 'PA' => __( 'Panama' ),
2868
+ 'PZ' => __( 'Panama Canal Zone' ),
2869
+ 'PG' => __( 'Papua New Guinea' ),
2870
+ 'PY' => __( 'Paraguay' ),
2871
+ 'YD' => __( "People's Democratic Republic of Yemen" ),
2872
+ 'PE' => __( 'Peru' ),
2873
+ 'PH' => __( 'Philippines' ),
2874
+ 'PN' => __( 'Pitcairn Islands' ),
2875
+ 'PL' => __( 'Poland' ),
2876
+ 'PT' => __( 'Portugal' ),
2877
+ 'PR' => __( 'Puerto Rico' ),
2878
+ 'QA' => __( 'Qatar' ),
2879
+ 'RO' => __( 'Romania' ),
2880
+ 'RU' => __( 'Russia' ),
2881
+ 'RW' => __( 'Rwanda' ),
2882
+ 'RE' => __( 'Réunion' ),
2883
+ 'BL' => __( 'Saint Barthélemy' ),
2884
+ 'SH' => __( 'Saint Helena' ),
2885
+ 'KN' => __( 'Saint Kitts and Nevis' ),
2886
+ 'LC' => __( 'Saint Lucia' ),
2887
+ 'MF' => __( 'Saint Martin' ),
2888
+ 'PM' => __( 'Saint Pierre and Miquelon' ),
2889
+ 'VC' => __( 'Saint Vincent and the Grenadines' ),
2890
+ 'WS' => __( 'Samoa' ),
2891
+ 'SM' => __( 'San Marino' ),
2892
+ 'SA' => __( 'Saudi Arabia' ),
2893
+ 'SN' => __( 'Senegal' ),
2894
+ 'RS' => __( 'Serbia' ),
2895
+ 'CS' => __( 'Serbia and Montenegro' ),
2896
+ 'SC' => __( 'Seychelles' ),
2897
+ 'SL' => __( 'Sierra Leone' ),
2898
+ 'SG' => __( 'Singapore' ),
2899
+ 'SK' => __( 'Slovakia' ),
2900
+ 'SI' => __( 'Slovenia' ),
2901
+ 'SB' => __( 'Solomon Islands' ),
2902
+ 'SO' => __( 'Somalia' ),
2903
+ 'ZA' => __( 'South Africa' ),
2904
+ 'GS' => __( 'South Georgia and the South Sandwich Islands' ),
2905
+ 'KR' => __( 'South Korea' ),
2906
+ 'ES' => __( 'Spain' ),
2907
+ 'LK' => __( 'Sri Lanka' ),
2908
+ 'SD' => __( 'Sudan' ),
2909
+ 'SR' => __( 'Suriname' ),
2910
+ 'SJ' => __( 'Svalbard and Jan Mayen' ),
2911
+ 'SZ' => __( 'Swaziland' ),
2912
+ 'SE' => __( 'Sweden' ),
2913
+ 'CH' => __( 'Switzerland' ),
2914
+ 'SY' => __( 'Syria' ),
2915
+ 'ST' => __( 'São Tomé and Príncipe' ),
2916
+ 'TW' => __( 'Taiwan' ),
2917
+ 'TJ' => __( 'Tajikistan' ),
2918
+ 'TZ' => __( 'Tanzania' ),
2919
+ 'TH' => __( 'Thailand' ),
2920
+ 'TL' => __( 'Timor-Leste' ),
2921
+ 'TG' => __( 'Togo' ),
2922
+ 'TK' => __( 'Tokelau' ),
2923
+ 'TO' => __( 'Tonga' ),
2924
+ 'TT' => __( 'Trinidad and Tobago' ),
2925
+ 'TN' => __( 'Tunisia' ),
2926
+ 'TR' => __( 'Turkey' ),
2927
+ 'TM' => __( 'Turkmenistan' ),
2928
+ 'TC' => __( 'Turks and Caicos Islands' ),
2929
+ 'TV' => __( 'Tuvalu' ),
2930
+ 'UM' => __( 'U.S. Minor Outlying Islands' ),
2931
+ 'PU' => __( 'U.S. Miscellaneous Pacific Islands' ),
2932
+ 'VI' => __( 'U.S. Virgin Islands' ),
2933
+ 'UG' => __( 'Uganda' ),
2934
+ 'UA' => __( 'Ukraine' ),
2935
+ 'SU' => __( 'Union of Soviet Socialist Republics' ),
2936
+ 'AE' => __( 'United Arab Emirates' ),
2937
+ 'GB' => __( 'United Kingdom' ),
2938
+ 'US' => __( 'United States' ),
2939
+ 'ZZ' => __( 'Unknown or Invalid Region' ),
2940
+ 'UY' => __( 'Uruguay' ),
2941
+ 'UZ' => __( 'Uzbekistan' ),
2942
+ 'VU' => __( 'Vanuatu' ),
2943
+ 'VA' => __( 'Vatican City' ),
2944
+ 'VE' => __( 'Venezuela' ),
2945
+ 'VN' => __( 'Vietnam' ),
2946
+ 'WK' => __( 'Wake Island' ),
2947
+ 'WF' => __( 'Wallis and Futuna' ),
2948
+ 'EH' => __( 'Western Sahara' ),
2949
+ 'YE' => __( 'Yemen' ),
2950
+ 'ZM' => __( 'Zambia' ),
2951
+ 'ZW' => __( 'Zimbabwe' ),
2952
+ 'AX' => __( 'Åland Islands' ),
2953
+ );
2954
+
2955
+ return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
2956
+
2957
+ }
2958
+
2959
+ /**
2960
+ * Data callback for US States
2961
+ *
2962
+ * @param string $name The name of the field
2963
+ * @param string|array $value The value of the field
2964
+ * @param array $options Field options
2965
+ * @param array $pod Pod data
2966
+ * @param int $id Item ID
2967
+ *
2968
+ * @return array
2969
+ *
2970
+ * @since 2.3
2971
+ */
2972
+ public function data_us_states( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
2973
+
2974
+ $data = array(
2975
+ 'AL' => __( 'Alabama' ),
2976
+ 'AK' => __( 'Alaska' ),
2977
+ 'AZ' => __( 'Arizona' ),
2978
+ 'AR' => __( 'Arkansas' ),
2979
+ 'CA' => __( 'California' ),
2980
+ 'CO' => __( 'Colorado' ),
2981
+ 'CT' => __( 'Connecticut' ),
2982
+ 'DE' => __( 'Delaware' ),
2983
+ 'DC' => __( 'District Of Columbia' ),
2984
+ 'FL' => __( 'Florida' ),
2985
+ 'GA' => __( 'Georgia' ),
2986
+ 'HI' => __( 'Hawaii' ),
2987
+ 'ID' => __( 'Idaho' ),
2988
+ 'IL' => __( 'Illinois' ),
2989
+ 'IN' => __( 'Indiana' ),
2990
+ 'IA' => __( 'Iowa' ),
2991
+ 'KS' => __( 'Kansas' ),
2992
+ 'KY' => __( 'Kentucky' ),
2993
+ 'LA' => __( 'Louisiana' ),
2994
+ 'ME' => __( 'Maine' ),
2995
+ 'MD' => __( 'Maryland' ),
2996
+ 'MA' => __( 'Massachusetts' ),
2997
+ 'MI' => __( 'Michigan' ),
2998
+ 'MN' => __( 'Minnesota' ),
2999
+ 'MS' => __( 'Mississippi' ),
3000
+ 'MO' => __( 'Missouri' ),
3001
+ 'MT' => __( 'Montana' ),
3002
+ 'NE' => __( 'Nebraska' ),
3003
+ 'NV' => __( 'Nevada' ),
3004
+ 'NH' => __( 'New Hampshire' ),
3005
+ 'NJ' => __( 'New Jersey' ),
3006
+ 'NM' => __( 'New Mexico' ),
3007
+ 'NY' => __( 'New York' ),
3008
+ 'NC' => __( 'North Carolina' ),
3009
+ 'ND' => __( 'North Dakota' ),
3010
+ 'OH' => __( 'Ohio' ),
3011
+ 'OK' => __( 'Oklahoma' ),
3012
+ 'OR' => __( 'Oregon' ),
3013
+ 'PA' => __( 'Pennsylvania' ),
3014
+ 'RI' => __( 'Rhode Island' ),
3015
+ 'SC' => __( 'South Carolina' ),
3016
+ 'SD' => __( 'South Dakota' ),
3017
+ 'TN' => __( 'Tennessee' ),
3018
+ 'TX' => __( 'Texas' ),
3019
+ 'UT' => __( 'Utah' ),
3020
+ 'VT' => __( 'Vermont' ),
3021
+ 'VA' => __( 'Virginia' ),
3022
+ 'WA' => __( 'Washington' ),
3023
+ 'WV' => __( 'West Virginia' ),
3024
+ 'WI' => __( 'Wisconsin' ),
3025
+ 'WY' => __( 'Wyoming' ),
3026
+ );
3027
+
3028
+ return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
3029
+
3030
+ }
3031
+
3032
+ /**
3033
+ * Data callback for CA Provinces
3034
+ *
3035
+ * @param string $name The name of the field
3036
+ * @param string|array $value The value of the field
3037
+ * @param array $options Field options
3038
+ * @param array $pod Pod data
3039
+ * @param int $id Item ID
3040
+ *
3041
+ * @return array
3042
+ *
3043
+ * @since 2.3
3044
+ */
3045
+ public function data_ca_provinces( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
3046
+
3047
+ $data = array(
3048
+ 'AB' => __( 'Alberta' ),
3049
+ 'BC' => __( 'British Columbia' ),
3050
+ 'MB' => __( 'Manitoba' ),
3051
+ 'NB' => __( 'New Brunswick' ),
3052
+ 'NL' => __( 'Newfoundland and Labrador' ),
3053
+ 'NT' => __( 'Northwest Territories' ),
3054
+ 'NS' => __( 'Nova Scotia' ),
3055
+ 'NU' => __( 'Nunavut' ),
3056
+ 'ON' => __( 'Ontario' ),
3057
+ 'PE' => __( 'Prince Edward Island' ),
3058
+ 'QC' => __( 'Quebec' ),
3059
+ 'SK' => __( 'Saskatchewan' ),
3060
+ 'YT' => __( 'Yukon' ),
3061
+ );
3062
+
3063
+ return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
3064
+
3065
+ }
3066
+
3067
+ /**
3068
+ * Data callback for US States
3069
+ *
3070
+ * @param string $name The name of the field
3071
+ * @param string|array $value The value of the field
3072
+ * @param array $options Field options
3073
+ * @param array $pod Pod data
3074
+ * @param int $id Item ID
3075
+ *
3076
+ * @return array
3077
+ *
3078
+ * @since 2.3
3079
+ */
3080
+ public function data_days_of_week( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
3081
+
3082
+ /**
3083
+ * @var WP_Locale
3084
+ */
3085
+ global $wp_locale;
3086
+
3087
+ return $wp_locale->weekday;
3088
+
3089
+ }
3090
+
3091
+ /**
3092
+ * Data callback for US States
3093
+ *
3094
+ * @param string $name The name of the field
3095
+ * @param string|array $value The value of the field
3096
+ * @param array $options Field options
3097
+ * @param array $pod Pod data
3098
+ * @param int $id Item ID
3099
+ *
3100
+ * @return array
3101
+ *
3102
+ * @since 2.3
3103
+ */
3104
+ public function data_months_of_year( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
3105
+
3106
+ /**
3107
+ * @var WP_Locale
3108
+ */
3109
+ global $wp_locale;
3110
+
3111
+ return $wp_locale->month;
3112
+
3113
+ }
3114
+
3115
+ /**
3116
+ * Add our modal input to the form so we can track whether we're in our modal during saving or not.
3117
+ */
3118
+ public function admin_modal_input() {
3119
+
3120
+ if ( ! pods_is_modal_window() ) {
3121
+ return;
3122
+ }
3123
+
3124
+ echo '<input name="pods_modal" type="hidden" value="1" />';
3125
+
3126
+ }
3127
+
3128
+ /**
3129
+ * Bail to send new saved data back to our modal handler.
3130
+ *
3131
+ * @param int $item_id
3132
+ * @param string $item_title
3133
+ * @param object $field_args
3134
+ */
3135
+ public function admin_modal_bail( $item_id, $item_title, $field_args ) {
3136
+
3137
+ $model_data = $this->build_dfv_field_item_data_recurse_item( $item_id, $item_title, $field_args );
3138
+ ?>
3139
+ <script type="text/javascript">
3140
+ window.parent.jQuery( window.parent ).trigger(
3141
+ 'dfv:modal:update',
3142
+ <?php echo json_encode( $model_data, JSON_HEX_TAG ); ?>
3143
+ );
3144
+ </script>
3145
+ <?php
3146
+
3147
+ die();
3148
+
3149
+ }
3150
+
3151
+ /**
3152
+ * Bail to send new saved data back to our modal handler.
3153
+ *
3154
+ * @param int $item_id
3155
+ * @param string $item_title
3156
+ * @param object $field_args
3157
+ */
3158
+ public function admin_modal_bail_JSON( $item_id, $item_title, $field_args ) {
3159
+
3160
+ $model_data = $this->build_dfv_field_item_data_recurse_item( $item_id, $item_title, $field_args );
3161
+ echo json_encode( $model_data, JSON_HEX_TAG );
3162
+
3163
+ die();
3164
+ }
3165
+
3166
+ /**
3167
+ * Bail on Post save redirect for Admin modal.
3168
+ *
3169
+ * @param string $location The destination URL.
3170
+ * @param int $post_id The post ID.
3171
+ *
3172
+ * @return string
3173
+ */
3174
+ public function admin_modal_bail_post_redirect( $location, $post_id ) {
3175
+
3176
+ if ( ! pods_is_modal_window() ) {
3177
+ return $location;
3178
+ }
3179
+
3180
+ $post_title = get_the_title( $post_id );
3181
+
3182
+ $field_args = (object) array(
3183
+ 'options' => array(
3184
+ 'pick_object' => 'post_type',
3185
+ 'pick_val' => get_post_type( $post_id ),
3186
+ ),
3187
+ 'value' => array(
3188
+ $post_id => $post_title,
3189
+ ),
3190
+ );
3191
+
3192
+ $this->admin_modal_bail( $post_id, $post_title, $field_args );
3193
+
3194
+ return $location;
3195
+
3196
+ }
3197
+
3198
+ /**
3199
+ * Hook into term updating process to bail on redirect.
3200
+ */
3201
+ public function admin_modal_bail_term_action() {
3202
+
3203
+ if ( ! pods_is_modal_window() ) {
3204
+ return;
3205
+ }
3206
+
3207
+ add_action( 'created_term', array( $this, 'admin_modal_bail_term' ), 10, 3 );
3208
+ add_action( 'edited_term', array( $this, 'admin_modal_bail_term' ), 10, 3 );
3209
+
3210
+ }
3211
+
3212
+ /**
3213
+ * Bail on Term save redirect for Admin modal.
3214
+ *
3215
+ * @param int $term_id Term ID.
3216
+ * @param int $tt_id Term taxonomy ID.
3217
+ * @param string $taxonomy Taxonomy slug.
3218
+ */
3219
+ public function admin_modal_bail_term( $term_id, $tt_id, $taxonomy ) {
3220
+
3221
+ if ( ! pods_is_modal_window() ) {
3222
+ return;
3223
+ }
3224
+
3225
+ $term = get_term( $term_id );
3226
+
3227
+ if ( ! $term || is_wp_error( $term ) ) {
3228
+ return;
3229
+ }
3230
+
3231
+ $field_args = (object) array(
3232
+ 'options' => array(
3233
+ 'pick_object' => 'taxonomy',
3234
+ 'pick_val' => $term->taxonomy,
3235
+ ),
3236
+ 'value' => array(
3237
+ $term->term_id => $term->name,
3238
+ ),
3239
+ );
3240
+
3241
+ $this->admin_modal_bail( $term->term_id, $term->name, $field_args );
3242
+
3243
+ }
3244
+
3245
+ /**
3246
+ * Hook into user updating process to bail on redirect.
3247
+ */
3248
+ public function admin_modal_bail_user_action() {
3249
+
3250
+ if ( ! pods_is_modal_window() ) {
3251
+ return;
3252
+ }
3253
+
3254
+ add_filter( 'wp_redirect', array( $this, 'admin_modal_bail_user_redirect' ) );
3255
+
3256
+ }
3257
+
3258
+ /**
3259
+ * Bail on User save redirect for Admin modal.
3260
+ *
3261
+ * @param string $location The destination URL.
3262
+ *
3263
+ * @return string
3264
+ */
3265
+ public function admin_modal_bail_user_redirect( $location ) {
3266
+
3267
+ if ( ! pods_is_modal_window() ) {
3268
+ return $location;
3269
+ }
3270
+
3271
+ global $user_id;
3272
+
3273
+ $user = get_userdata( $user_id );
3274
+
3275
+ if ( ! $user || is_wp_error( $user ) ) {
3276
+ return $location;
3277
+ }
3278
+
3279
+ $field_args = (object) array(
3280
+ 'options' => array(
3281
+ 'pick_object' => 'user',
3282
+ 'pick_val' => '',
3283
+ ),
3284
+ 'value' => array(
3285
+ $user->ID => $user->display_name,
3286
+ ),
3287
+ );
3288
+
3289
+ $this->admin_modal_bail( $user->ID, $user->display_name, $field_args );
3290
+
3291
+ return $location;
3292
+
3293
+ }
3294
+
3295
+ /**
3296
+ * Bail on Pod item save for Admin modal.
3297
+ *
3298
+ * @param int $id Item ID.
3299
+ * @param array $params save_pod_item parameters.
3300
+ * @param null|Pods $obj Pod object (if set).
3301
+ */
3302
+ public function admin_modal_bail_pod( $id, $params, $obj ) {
3303
+
3304
+ if ( ! pods_is_modal_window() ) {
3305
+ return;
3306
+ }
3307
+
3308
+ if ( ! $obj ) {
3309
+ $obj = pods( $params['pod'] );
3310
+ }
3311
+
3312
+ if ( ! $obj || ! $obj->fetch( $id ) ) {
3313
+ return;
3314
+ }
3315
+
3316
+ $item_id = $obj->id();
3317
+ $item_title = $obj->index();
3318
+
3319
+ $field_args = (object) array(
3320
+ 'options' => array(
3321
+ 'pick_object' => $obj->pod_data['type'],
3322
+ 'pick_val' => $obj->pod,
3323
+ ),
3324
+ 'value' => array(
3325
+ $obj->id() => $item_title,
3326
+ ),
3327
+ );
3328
+
3329
+ $this->admin_modal_bail_JSON( $item_id, $item_title, $field_args );
3330
+
3331
+ }
3332
 
 
3333
  }
classes/fields/slug.php CHANGED
@@ -45,6 +45,27 @@ class PodsField_Slug extends PodsField {
45
  self::$label = __( 'Permalink (url-friendly)', 'pods' );
46
  }
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  /**
49
  * Define the current field's schema for DB table storage
50
  *
45
  self::$label = __( 'Permalink (url-friendly)', 'pods' );
46
  }
47
 
48
+ /**
49
+ * {@inheritdoc}
50
+ */
51
+ public function options () {
52
+
53
+ $options = array(
54
+ self::$type . '_placeholder' => array(
55
+ 'label' => __( 'HTML Placeholder', 'pods' ),
56
+ 'default' => '',
57
+ 'type' => 'text',
58
+ 'help' => array(
59
+ __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
60
+ 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
61
+ ),
62
+ ),
63
+ );
64
+
65
+ return $options;
66
+
67
+ }
68
+
69
  /**
70
  * Define the current field's schema for DB table storage
71
  *
classes/fields/text.php CHANGED
@@ -91,7 +91,16 @@ class PodsField_Text extends PodsField {
91
  'default' => 255,
92
  'type' => 'number',
93
  'help' => __( 'Set to -1 for no limit', 'pods' )
94
- )/*,
 
 
 
 
 
 
 
 
 
95
  self::$type . '_size' => array(
96
  'label' => __( 'Field Size', 'pods' ),
97
  'default' => 'medium',
91
  'default' => 255,
92
  'type' => 'number',
93
  'help' => __( 'Set to -1 for no limit', 'pods' )
94
+ ),
95
+ self::$type . '_placeholder' => array(
96
+ 'label' => __( 'HTML Placeholder', 'pods' ),
97
+ 'default' => '',
98
+ 'type' => 'text',
99
+ 'help' => array(
100
+ __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
101
+ 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
102
+ ),
103
+ ),/*,
104
  self::$type . '_size' => array(
105
  'label' => __( 'Field Size', 'pods' ),
106
  'default' => 'medium',
classes/fields/time.php CHANGED
@@ -1,349 +1,230 @@
1
  <?php
 
2
  /**
3
  * @package Pods\Fields
4
  */
5
- class PodsField_Time extends PodsField {
6
-
7
- /**
8
- * Field Type Group
9
- *
10
- * @var string
11
- * @since 2.0
12
- */
13
- public static $group = 'Date / Time';
14
-
15
- /**
16
- * Field Type Identifier
17
- *
18
- * @var string
19
- * @since 2.0
20
- */
21
- public static $type = 'time';
22
-
23
- /**
24
- * Field Type Label
25
- *
26
- * @var string
27
- * @since 2.0
28
- */
29
- public static $label = 'Time';
30
-
31
- /**
32
- * Field Type Preparation
33
- *
34
- * @var string
35
- * @since 2.0
36
- */
37
- public static $prepare = '%s';
38
-
39
- /**
40
- * Do things like register/enqueue scripts and stylesheets
41
- *
42
- * @since 2.0
43
- */
44
- public function __construct () {
45
- self::$label = __( 'Time', 'pods' );
46
- }
47
-
48
- /**
49
- * Add options and set defaults to
50
- *
51
- * @return array
52
- * @since 2.0
53
- */
54
- public function options () {
55
- $options = array(
56
- self::$type . '_repeatable' => array(
57
- 'label' => __( 'Repeatable Field', 'pods' ),
58
- 'default' => 0,
59
- 'type' => 'boolean',
60
- 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
61
- 'boolean_yes_label' => '',
62
- 'dependency' => true,
63
- 'developer_mode' => true
64
- ),
65
- self::$type . '_type' => array(
66
- 'label' => __( 'Time Format Type', 'pods' ),
67
- 'default' => '12',
68
- 'type' => 'pick',
69
- 'data' => array(
70
- '12' => __( '12 hour', 'pods' ),
71
- '24' => __( '24 hour', 'pods' )
72
- ),
73
- 'dependency' => true
74
- ),
75
- self::$type . '_format' => array(
76
- 'label' => __( 'Time Format', 'pods' ),
77
- 'depends-on' => array( self::$type . '_type' => '12' ),
78
- 'default' => 'h_mma',
79
- 'type' => 'pick',
80
- 'data' => array(
81
- 'h_mm_A' => date_i18n( 'g:i A' ),
82
- 'h_mm_ss_A' => date_i18n( 'g:i:s A' ),
83
- 'hh_mm_A' => date_i18n( 'h:i A' ),
84
- 'hh_mm_ss_A' => date_i18n( 'h:i:s A' ),
85
- 'h_mma' => date_i18n( 'g:ia' ),
86
- 'hh_mma' => date_i18n( 'h:ia' ),
87
- 'h_mm' => date_i18n( 'g:i' ),
88
- 'h_mm_ss' => date_i18n( 'g:i:s' ),
89
- 'hh_mm' => date_i18n( 'h:i' ),
90
- 'hh_mm_ss' => date_i18n( 'h:i:s' )
91
- )
92
- ),
93
- self::$type . '_format_24' => array(
94
- 'label' => __( 'Time Format', 'pods' ),
95
- 'depends-on' => array( self::$type . '_type' => '24' ),
96
- 'default' => 'hh_mm',
97
- 'type' => 'pick',
98
- 'data' => array(
99
- 'hh_mm' => date_i18n( 'H:i' ),
100
- 'hh_mm_ss' => date_i18n( 'H:i:s' )
101
- )
102
- ),
103
- self::$type . '_allow_empty' => array(
104
- 'label' => __( 'Allow empty value?', 'pods' ),
105
- 'default' => 1,
106
- 'type' => 'boolean'
107
- ),
108
- self::$type . '_html5' => array(
109
- 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
110
- 'default' => apply_filters( 'pods_form_ui_field_html5', 0, self::$type ),
111
- 'type' => 'boolean'
112
- )
113
- );
114
-
115
- $options[ self::$type . '_type' ][ 'default' ] = apply_filters( 'pods_form_ui_field_time_format_type_default', $options[ self::$type . '_type' ][ 'default' ] );
116
- $options[ self::$type . '_format' ][ 'data' ] = apply_filters( 'pods_form_ui_field_time_format_options', $options[ self::$type . '_format' ][ 'data' ] );
117
- $options[ self::$type . '_format' ][ 'default' ] = apply_filters( 'pods_form_ui_field_time_format_default', $options[ self::$type . '_format' ][ 'default' ] );
118
- $options[ self::$type . '_format_24' ][ 'data' ] = apply_filters( 'pods_form_ui_field_time_format_24_options', $options[ self::$type . '_format_24' ][ 'data' ] );
119
- $options[ self::$type . '_format_24' ][ 'default' ] = apply_filters( 'pods_form_ui_field_time_format_24_default', $options[ self::$type . '_format_24' ][ 'default' ] );
120
-
121
- return $options;
122
- }
123
-
124
- /**
125
- * Define the current field's schema for DB table storage
126
- *
127
- * @param array $options
128
- *
129
- * @return array
130
- * @since 2.0
131
- */
132
- public function schema ( $options = null ) {
133
- $schema = 'TIME NOT NULL default "00:00:00"';
134
-
135
- return $schema;
136
- }
137
-
138
- /**
139
- * Change the way the value of the field is displayed with Pods::get
140
- *
141
- * @param mixed $value
142
- * @param string $name
143
- * @param array $options
144
- * @param array $pod
145
- * @param int $id
146
- *
147
- * @return mixed|null|string
148
- * @since 2.0
149
- */
150
- public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
151
- $format = $this->format( $options );
152
-
153
- if ( !empty( $value ) && !in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00' ) ) ) {
154
- $date = $this->createFromFormat( 'H:i:s', (string) $value );
155
- $date_local = $this->createFromFormat( $format, (string) $value );
156
-
157
- if ( false !== $date )
158
- $value = $date->format( $format );
159
- elseif ( false !== $date_local )
160
- $value = $date_local->format( $format );
161
- else
162
- $value = date_i18n( $format, strtotime( (string) $value ) );
163
- }
164
- elseif ( 0 == pods_var( self::$type . '_allow_empty', $options, 1 ) )
165
- $value = date_i18n( $format );
166
- else
167
- $value = '';
168
-
169
- return $value;
170
- }
171
-
172
- /**
173
- * Customize output of the form field
174
- *
175
- * @param string $name
176
- * @param mixed $value
177
- * @param array $options
178
- * @param array $pod
179
- * @param int $id
180
- *
181
- * @since 2.0
182
- */
183
- public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
184
- $options = (array) $options;
185
- $form_field_type = PodsForm::$field_type;
186
-
187
- if ( is_array( $value ) )
188
- $value = implode( ' ', $value );
189
-
190
- // Format Value
191
- $value = $this->display( $value, $name, $options, null, $pod, $id );
192
-
193
- $field_type = 'time';
194
-
195
- if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) {
196
- if ( pods_var( 'read_only', $options, false ) ) {
197
- $options[ 'readonly' ] = true;
198
-
199
- $field_type = 'text';
200
- }
201
- else
202
- return;
203
- }
204
- elseif ( !pods_has_permissions( $options ) && pods_var( 'read_only', $options, false ) ) {
205
- $options[ 'readonly' ] = true;
206
-
207
- $field_type = 'text';
208
- }
209
-
210
- pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
211
- }
212
-
213
- /**
214
- * Change the value or perform actions after validation but before saving to the DB
215
- *
216
- * @param mixed $value
217
- * @param int $id
218
- * @param string $name
219
- * @param array $options
220
- * @param array $fields
221
- * @param array $pod
222
- * @param object $params
223
- *
224
- * @return mixed|string
225
- * @since 2.0
226
- */
227
- public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
228
- $format = $this->format( $options );
229
-
230
- if ( !empty( $value ) && ( 0 == pods_var( self::$type . '_allow_empty', $options, 1 ) || !in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00' ) ) ) )
231
- $value = $this->convert_date( $value, 'H:i:s', $format );
232
- elseif ( 1 == pods_var( self::$type . '_allow_empty', $options, 1 ) )
233
- $value = '00:00:00';
234
- else
235
- $value = date_i18n( 'H:i:s' );
236
-
237
- return $value;
238
- }
239
-
240
- /**
241
- * Customize the Pods UI manage table column output
242
- *
243
- * @param int $id
244
- * @param mixed $value
245
- * @param string $name
246
- * @param array $options
247
- * @param array $fields
248
- * @param array $pod
249
- *
250
- * @return mixed|null|string
251
- * @since 2.0
252
- */
253
- public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
254
- $value = $this->display( $value, $name, $options, $pod, $id );
255
-
256
- if ( 1 == pods_var( self::$type . '_allow_empty', $options, 1 ) && ( empty( $value ) || in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00' ) ) ) )
257
- $value = false;
258
-
259
- return $value;
260
- }
261
-
262
- /**
263
- * Build date/time format string based on options
264
- *
265
- * @param $options
266
- *
267
- * @return string
268
- * @since 2.0
269
- */
270
- public function format ( $options ) {
271
- $time_format = array(
272
- 'h_mm_A' => 'g:i A',
273
- 'h_mm_ss_A' => 'g:i:s A',
274
- 'hh_mm_A' => 'h:i A',
275
- 'hh_mm_ss_A' => 'h:i:s A',
276
- 'h_mma' => 'g:ia',
277
- 'hh_mma' => 'h:ia',
278
- 'h_mm' => 'g:i',
279
- 'h_mm_ss' => 'g:i:s',
280
- 'hh_mm' => 'h:i',
281
- 'hh_mm_ss' => 'h:i:s'
282
- );
283
-
284
- $time_format_24 = array(
285
- 'hh_mm' => 'H:i',
286
- 'hh_mm_ss' => 'H:i:s'
287
- );
288
-
289
- $time_format = apply_filters( 'pods_form_ui_field_time_formats', $time_format );
290
- $time_format_24 = apply_filters( 'pods_form_ui_field_time_formats_24', $time_format_24 );
291
-
292
- if ( 12 == pods_var( self::$type . '_type', $options ) )
293
- $format = $time_format[ pods_var( self::$type . '_format', $options, 'hh_mm', null, true ) ];
294
- else
295
- $format = $time_format_24[ pods_var( self::$type . '_format_24', $options, 'hh_mm', null, true ) ];
296
-
297
- return $format;
298
- }
299
-
300
- /**
301
- * @param $format
302
- * @param $date
303
- *
304
- * @return DateTime
305
- */
306
- public function createFromFormat ( $format, $date ) {
307
- $datetime = false;
308
-
309
- if ( method_exists( 'DateTime', 'createFromFormat' ) ) {
310
- $timezone = get_option( 'timezone_string' );
311
-
312
- if ( empty( $timezone ) )
313
- $timezone = timezone_name_from_abbr( '', get_option( 'gmt_offset' ) * HOUR_IN_SECONDS, 0 );
314
-
315
- if ( !empty( $timezone ) ) {
316
- $datetimezone = new DateTimeZone( $timezone );
317
-
318
- $datetime = DateTime::createFromFormat( $format, (string) $date, $datetimezone );
319
- }
320
- }
321
-
322
- if ( false === $datetime )
323
- $datetime = new DateTime( date_i18n( 'H:i:s', strtotime( (string) $date ) ) );
324
-
325
- return apply_filters( 'pods_form_ui_field_datetime_formatter', $datetime, $format, $date );
326
- }
327
-
328
- /**
329
- * Convert a date from one format to another
330
- *
331
- * @param $date
332
- * @param $new_format
333
- * @param $original_format
334
- */
335
- public function convert_date ( $value, $new_format, $original_format = 'H:i:s' ) {
336
- if ( !empty( $value ) && !in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00' ) ) ) {
337
- $date = $this->createFromFormat( $original_format, (string) $value );
338
-
339
- if ( false !== $date )
340
- $value = $date->format( $new_format );
341
- else
342
- $value = date_i18n( $new_format, strtotime( (string) $value ) );
343
- }
344
- else
345
- $value = date_i18n( $new_format );
346
-
347
- return $value;
348
- }
349
  }
1
  <?php
2
+ require_once( PODS_DIR . 'classes/fields/datetime.php' );
3
  /**
4
  * @package Pods\Fields
5
  */
6
+ class PodsField_Time extends PodsField_DateTime {
7
+
8
+ /**
9
+ * Field Type Group
10
+ *
11
+ * @var string
12
+ * @since 2.0
13
+ */
14
+ public static $group = 'Date / Time';
15
+
16
+ /**
17
+ * Field Type Identifier
18
+ *
19
+ * @var string
20
+ * @since 2.0
21
+ */
22
+ public static $type = 'time';
23
+
24
+ /**
25
+ * Field Type Label
26
+ *
27
+ * @var string
28
+ * @since 2.0
29
+ */
30
+ public static $label = 'Time';
31
+
32
+ /**
33
+ * Field Type Preparation
34
+ *
35
+ * @var string
36
+ * @since 2.0
37
+ */
38
+ public static $prepare = '%s';
39
+
40
+ /**
41
+ * Storage format.
42
+ *
43
+ * @var string
44
+ * @since 2.7
45
+ */
46
+ public static $storage_format = 'H:i:s';
47
+
48
+ /**
49
+ * The default empty value (database)
50
+ *
51
+ * @var string
52
+ * @since 2.7
53
+ */
54
+ public static $empty_value = '00:00:00';
55
+
56
+ /**
57
+ * Do things like register/enqueue scripts and stylesheets
58
+ *
59
+ * @since 2.0
60
+ */
61
+ public function __construct () {
62
+ static::$label = __( 'Time', 'pods' );
63
+ }
64
+
65
+ /**
66
+ * Add options and set defaults to
67
+ *
68
+ * @return array
69
+ * @since 2.0
70
+ */
71
+ public function options () {
72
+ $options = array(
73
+ static::$type . '_repeatable' => array(
74
+ 'label' => __( 'Repeatable Field', 'pods' ),
75
+ 'default' => 0,
76
+ 'type' => 'boolean',
77
+ 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
78
+ 'boolean_yes_label' => '',
79
+ 'dependency' => true,
80
+ 'developer_mode' => true
81
+ ),
82
+ static::$type . '_type' => array(
83
+ 'label' => __( 'Time Format Type', 'pods' ),
84
+ 'default' => '12', // Backwards compatibility
85
+ 'type' => 'pick',
86
+ 'help' => __( 'WordPress Default is the format used in Settings, General under "Time Format".', 'pods' ) . '<br>'
87
+ . __( '12/24 hour will allow you to select from a list of commonly used time formats.', 'pods' ) . '<br>'
88
+ . __( 'Custom will allow you to enter your own using PHP Date/Time Strings.', 'pods' ),
89
+ 'data' => array(
90
+ 'wp' => __( 'WordPress default', 'pods' ) . ': ' . date_i18n( get_option( 'time_format' ) ),
91
+ '12' => __( '12 hour', 'pods' ),
92
+ '24' => __( '24 hour', 'pods' ),
93
+ 'custom' => __( 'Custom format', 'pods' ),
94
+ ),
95
+ 'dependency' => true
96
+ ),
97
+ static::$type . '_format_custom' => array(
98
+ 'label' => __( 'Time format for display', 'pods' ),
99
+ 'depends-on' => array( static::$type . '_type' => 'custom' ),
100
+ 'default' => '',
101
+ 'type' => 'text',
102
+ 'help' => '<a href="http://php.net/manual/function.date.php" target="_blank">' . __( 'PHP date documentation', 'pods' ) . '</a>',
103
+ ),
104
+ static::$type . '_format_custom_js' => array(
105
+ 'label' => __( 'Time format for input', 'pods' ),
106
+ 'depends-on' => array( static::$type . '_type' => 'custom' ),
107
+ 'default' => '',
108
+ 'type' => 'text',
109
+ 'help' => '<a href="http://trentrichardson.com/examples/timepicker/#tp-formatting" target="_blank">' . __( 'jQuery UI timepicker documentation', 'pods' ) . '</a>'
110
+ . '<br>' . __( 'Leave empty to auto-generate from PHP format.', 'pods' ),
111
+ ),
112
+ static::$type . '_format' => array(
113
+ 'label' => __( 'Time Format', 'pods' ),
114
+ 'depends-on' => array( static::$type . '_type' => '12' ),
115
+ 'default' => 'h_mma',
116
+ 'type' => 'pick',
117
+ 'data' => array(
118
+ 'h_mm_A' => date_i18n( 'g:i A' ),
119
+ 'h_mm_ss_A' => date_i18n( 'g:i:s A' ),
120
+ 'hh_mm_A' => date_i18n( 'h:i A' ),
121
+ 'hh_mm_ss_A' => date_i18n( 'h:i:s A' ),
122
+ 'h_mma' => date_i18n( 'g:ia' ),
123
+ 'hh_mma' => date_i18n( 'h:ia' ),
124
+ 'h_mm' => date_i18n( 'g:i' ),
125
+ 'h_mm_ss' => date_i18n( 'g:i:s' ),
126
+ 'hh_mm' => date_i18n( 'h:i' ),
127
+ 'hh_mm_ss' => date_i18n( 'h:i:s' )
128
+ ),
129
+ 'dependency' => true
130
+ ),
131
+ static::$type . '_format_24' => array(
132
+ 'label' => __( 'Time Format', 'pods' ),
133
+ 'depends-on' => array( static::$type . '_type' => '24' ),
134
+ 'default' => 'hh_mm',
135
+ 'type' => 'pick',
136
+ 'data' => array(
137
+ 'hh_mm' => date_i18n( 'H:i' ),
138
+ 'hh_mm_ss' => date_i18n( 'H:i:s' )
139
+ )
140
+ ),
141
+ static::$type . '_allow_empty' => array(
142
+ 'label' => __( 'Allow empty value?', 'pods' ),
143
+ 'default' => 1,
144
+ 'type' => 'boolean'
145
+ ),
146
+ static::$type . '_html5' => array(
147
+ 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
148
+ 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
149
+ 'type' => 'boolean'
150
+ )
151
+ );
152
+
153
+ $options[ static::$type . '_type' ][ 'default' ] = apply_filters( 'pods_form_ui_field_time_format_type_default', $options[ static::$type . '_type' ][ 'default' ] );
154
+ $options[ static::$type . '_format' ][ 'data' ] = apply_filters( 'pods_form_ui_field_time_format_options', $options[ static::$type . '_format' ][ 'data' ] );
155
+ $options[ static::$type . '_format' ][ 'default' ] = apply_filters( 'pods_form_ui_field_time_format_default', $options[ static::$type . '_format' ][ 'default' ] );
156
+ $options[ static::$type . '_format_24' ][ 'data' ] = apply_filters( 'pods_form_ui_field_time_format_24_options', $options[ static::$type . '_format_24' ][ 'data' ] );
157
+ $options[ static::$type . '_format_24' ][ 'default' ] = apply_filters( 'pods_form_ui_field_time_format_24_default', $options[ static::$type . '_format_24' ][ 'default' ] );
158
+
159
+ return $options;
160
+ }
161
+
162
+ /**
163
+ * Define the current field's schema for DB table storage
164
+ *
165
+ * @param array $options
166
+ *
167
+ * @return string
168
+ * @since 2.0
169
+ */
170
+ public function schema ( $options = null ) {
171
+ $schema = 'TIME NOT NULL default "00:00:00"';
172
+
173
+ return $schema;
174
+ }
175
+
176
+ /**
177
+ * Build date/time format string based on options
178
+ *
179
+ * @param array $options
180
+ * @param bool $js Return format for jQuery UI?
181
+ *
182
+ * @return string
183
+ * @since 2.0
184
+ */
185
+ public function format ( $options, $js = false ) {
186
+ return $this->format_time( $options, $js );
187
+ }
188
+
189
+ /**
190
+ * Build time format string based on options
191
+ *
192
+ * @since 2.7
193
+ *
194
+ * @param array $options
195
+ * @param bool $js Return format for jQuery UI?
196
+ * @return string
197
+ */
198
+ public function format_time( $options, $js = false ) {
199
+
200
+ switch ( (string) pods_v( static::$type . '_type', $options, '12', true ) ) {
201
+ case '12':
202
+ $time_format = $this->get_time_formats( $js );
203
+ $format = $time_format[ pods_v( static::$type . '_format', $options, 'hh_mm', true ) ];
204
+ break;
205
+ case '24':
206
+ $time_format_24 = $this->get_time_formats_24( $js );
207
+ $format = $time_format_24[ pods_v( static::$type . '_format_24', $options, 'hh_mm', true ) ];
208
+ break;
209
+ case 'custom':
210
+ if ( ! $js ) {
211
+ $format = pods_v( static::$type . '_format_custom', $options, '' );
212
+ } else {
213
+ $format = pods_v( static::$type . '_format_custom_js', $options, '' );
214
+ if ( empty( $format ) ) {
215
+ $format = pods_v( static::$type . '_format_custom', $options, '' );
216
+ $format = $this->convert_format( $format, array( 'source' => 'php' ) );
217
+ }
218
+ }
219
+ break;
220
+ default:
221
+ $format = get_option( 'time_format' );
222
+ if ( $js ) {
223
+ $format = $this->convert_format( $format, array( 'source' => 'php' ) );
224
+ }
225
+ break;
226
+ }
227
+
228
+ return $format;
229
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  }
classes/fields/website.php CHANGED
@@ -4,322 +4,289 @@
4
  */
5
  class PodsField_Website extends PodsField {
6
 
7
- /**
8
- * Field Type Group
9
- *
10
- * @var string
11
- * @since 2.0
12
- */
13
- public static $group = 'Text';
14
-
15
- /**
16
- * Field Type Identifier
17
- *
18
- * @var string
19
- * @since 2.0
20
- */
21
- public static $type = 'website';
22
-
23
- /**
24
- * Field Type Label
25
- *
26
- * @var string
27
- * @since 2.0
28
- */
29
- public static $label = 'Website';
30
-
31
- /**
32
- * Field Type Preparation
33
- *
34
- * @var string
35
- * @since 2.0
36
- */
37
- public static $prepare = '%s';
38
-
39
- /**
40
- * Do things like register/enqueue scripts and stylesheets
41
- *
42
- * @since 2.0
43
- */
44
- public function __construct () {
45
- self::$label = __( 'Website', 'pods' );
46
- }
47
-
48
- /**
49
- * Add options and set defaults to
50
- *
51
- * @param array $options
52
- *
53
- * @since 2.0
54
- */
55
- public function options () {
56
- $options = array(
57
- self::$type . '_repeatable' => array(
58
- 'label' => __( 'Repeatable Field', 'pods' ),
59
- 'default' => 0,
60
- 'type' => 'boolean',
61
- 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
62
- 'boolean_yes_label' => '',
63
- 'dependency' => true,
64
- 'developer_mode' => true
65
- ),
66
- self::$type . '_format' => array(
67
- 'label' => __( 'Format', 'pods' ),
68
- 'default' => 'normal',
69
- 'type' => 'pick',
70
- 'data' => array(
71
- 'normal' => __( 'http://example.com/', 'pods' ),
72
- 'no-www' => __( 'http://example.com/ (remove www)', 'pods' ),
73
- 'force-www' => __( 'http://www.example.com/ (force www if no sub-domain provided)', 'pods' ),
74
- 'no-http' => __( 'example.com', 'pods' ),
75
- 'no-http-no-www' => __( 'example.com (force removal of www)', 'pods' ),
76
- 'no-http-force-www' => __( 'www.example.com (force www if no sub-domain provided)', 'pods' )
77
- )
78
- ),
79
- self::$type . '_clickable' => array(
80
- 'label' => __( 'Output as a link?', 'pods' ),
81
- 'default' => apply_filters( 'pods_form_ui_field_website_clickable', 0, self::$type ),
82
- 'type' => 'boolean',
83
- 'dependency' => true,
84
- ),
85
- self::$type . '_new_window' => array(
86
- 'label' => __( 'Open link in new window?', 'pods' ),
87
- 'default' => apply_filters( 'pods_form_ui_field_website_new_window', 0, self::$type ),
88
- 'type' => 'boolean',
89
- 'depends-on' => array( self::$type . '_clickable' => true ),
90
- ),
91
- self::$type . '_max_length' => array(
92
- 'label' => __( 'Maximum Length', 'pods' ),
93
- 'default' => 255,
94
- 'type' => 'number',
95
- 'help' => __( 'Set to -1 for no limit', 'pods' )
96
- ),
97
- self::$type . '_html5' => array(
98
- 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
99
- 'default' => apply_filters( 'pods_form_ui_field_html5', 0, self::$type ),
100
- 'type' => 'boolean'
101
- )/*,
102
- self::$type . '_size' => array(
103
- 'label' => __( 'Field Size', 'pods' ),
104
- 'default' => 'medium',
105
- 'type' => 'pick',
106
- 'data' => array(
107
- 'small' => __( 'Small', 'pods' ),
108
- 'medium' => __( 'Medium', 'pods' ),
109
- 'large' => __( 'Large', 'pods' )
110
- )
111
- )*/
112
- );
113
- return $options;
114
- }
115
-
116
- /**
117
- * Define the current field's schema for DB table storage
118
- *
119
- * @param array $options
120
- *
121
- * @return array
122
- * @since 2.0
123
- */
124
- public function schema ( $options = null ) {
125
- $length = (int) pods_var( self::$type . '_max_length', $options, 255 );
126
-
127
- $schema = 'VARCHAR(' . $length . ')';
128
-
129
- if ( 255 < $length || $length < 1 )
130
- $schema = 'LONGTEXT';
131
-
132
- return $schema;
133
- }
134
-
135
- /**
136
- * Change the way the value of the field is displayed with Pods::get
137
- *
138
- * @param mixed $value
139
- * @param string $name
140
- * @param array $options
141
- * @param array $pod
142
- * @param int $id
143
- *
144
- * @return mixed|null
145
- * @since 2.0
146
- */
147
- public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
148
- // Ensure proper format
149
- $value = $this->pre_save( $value, $id, $name, $options, null, $pod );
150
-
151
- if ( 1 == pods_v( self::$type . '_clickable', $options ) && 0 < strlen( $value ) ) {
152
- $link = '<a href="%s"%s>%s</a>';
153
-
154
- $atts = '';
155
-
156
- if ( 1 == pods_v( self::$type . '_new_window', $options ) ) {
157
- $atts .= ' target="_blank"';
158
- }
159
-
160
- $value = sprintf( $link, esc_url( $value ), $atts, esc_html( $value ) );
161
- }
162
-
163
- return $value;
164
- }
165
-
166
- /**
167
- * Customize output of the form field
168
- *
169
- * @param string $name
170
- * @param mixed $value
171
- * @param array $options
172
- * @param array $pod
173
- * @param int $id
174
- *
175
- * @since 2.0
176
- */
177
- public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
178
- $options = (array) $options;
179
- $form_field_type = PodsForm::$field_type;
180
-
181
- if ( is_array( $value ) )
182
- $value = implode( ' ', $value );
183
-
184
- $field_type = 'website';
185
-
186
- if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) {
187
- if ( pods_var( 'read_only', $options, false ) ) {
188
- $options[ 'readonly' ] = true;
189
-
190
- $field_type = 'text';
191
- }
192
- else
193
- return;
194
- }
195
- elseif ( !pods_has_permissions( $options ) && pods_var( 'read_only', $options, false ) ) {
196
- $options[ 'readonly' ] = true;
197
-
198
- $field_type = 'text';
199
- }
200
-
201
- pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
202
- }
203
-
204
- /**
205
- * Validate a value before it's saved
206
- *
207
- * @param mixed $value
208
- * @param string $name
209
- * @param array $options
210
- * @param array $fields
211
- * @param array $pod
212
- * @param int $id
213
- *
214
- * @since 2.0
215
- */
216
- public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
217
- $errors = array();
218
-
219
- $label = strip_tags( pods_var_raw( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) ) );
220
-
221
- $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
222
-
223
- if ( is_array( $check ) )
224
- $errors = $check;
225
- else {
226
- if ( 0 < strlen( $value ) && strlen( $check ) < 1 ) {
227
- if ( 1 == pods_var( 'required', $options ) )
228
- $errors[] = sprintf( __( 'The %s field is required.', 'pods' ), $label );
229
- else
230
- $errors[] = sprintf( __( 'Invalid website provided for the field %s.', 'pods' ), $label );
231
- }
232
- }
233
-
234
- if ( !empty( $errors ) )
235
- return $errors;
236
-
237
- return true;
238
- }
239
-
240
- /**
241
- * Change the value or perform actions after validation but before saving to the DB
242
- *
243
- * @param mixed $value
244
- * @param int $id
245
- * @param string $name
246
- * @param array $options
247
- * @param array $fields
248
- * @param array $pod
249
- * @param object $params
250
- *
251
- * @since 2.0
252
- */
253
- public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
254
- $options = (array) $options;
255
-
256
- if ( is_array( $value ) ) {
257
- if ( isset( $value[ 'scheme' ] ) )
258
- $value = $this->build_url( $value );
259
- else
260
- $value = implode( '', $value );
261
- }
262
-
263
- if ( false === strpos( $value, '://' ) && 0 !== strpos( $value, '//' ) )
264
- $value = 'http://' . $value;
265
-
266
- $url = @parse_url( $value );
267
-
268
- if ( empty( $url ) || count( $url ) < 2 )
269
- $value = '';
270
- else {
271
- $defaults = array(
272
- 'scheme' => 'http',
273
- 'host' => '',
274
- 'path' => '/',
275
- 'query' => '',
276
- 'fragment' => ''
277
- );
278
-
279
- $url = array_merge( $defaults, $url );
280
-
281
- if ( 'normal' == pods_var( self::$type . '_format', $options ) )
282
- $value = $this->build_url( $url );
283
- elseif ( 'no-www' == pods_var( self::$type . '_format', $options ) ) {
284
- if ( 0 === strpos( $url[ 'host' ], 'www.' ) )
285
- $url[ 'host' ] = substr( $url[ 'host' ], 4 );
286
-
287
- $value = $this->build_url( $url );
288
- }
289
- elseif ( 'force-www' == pods_var( self::$type . '_format', $options ) ) {
290
- if ( false !== strpos( $url[ 'host' ], '.' ) && false === strpos( $url[ 'host' ], '.', 1 ) )
291
- $url[ 'host' ] = 'www.' . $url[ 'host' ];
292
-
293
- $value = $this->build_url( $url );
294
- }
295
- elseif ( 'no-http' == pods_var( self::$type . '_format', $options ) ) {
296
- $value = $this->build_url( $url );
297
- $value = str_replace( trim( $url[ 'scheme' ] . '://', ':' ), '', $value );
298
-
299
- if ( '/' == $url[ 'path' ] )
300
- $value = trim( $value, '/' );
301
- }
302
- elseif ( 'no-http-no-www' == pods_var( self::$type . '_format', $options ) ) {
303
- if ( 0 === strpos( $url[ 'host' ], 'www.' ) )
304
- $url[ 'host' ] = substr( $url[ 'host' ], 4 );
305
-
306
- $value = $this->build_url( $url );
307
- $value = str_replace( trim( $url[ 'scheme' ] . '://', ':' ), '', $value );
308
-
309
- if ( '/' == $url[ 'path' ] )
310
- $value = trim( $value, '/' );
311
- }
312
- elseif ( 'no-http-force-www' == pods_var( self::$type . '_format', $options ) ) {
313
- if ( false !== strpos( $url[ 'host' ], '.' ) && false === strpos( $url[ 'host' ], '.', 1 ) )
314
- $url[ 'host' ] = 'www.' . $url[ 'host' ];
315
-
316
- $value = $this->build_url( $url );
317
- $value = str_replace( trim( $url[ 'scheme' ] . '://', ':' ), '', $value );
318
-
319
- if ( '/' == $url[ 'path' ] )
320
- $value = trim( $value, '/' );
321
- }
322
- }
323
 
324
  $length = (int) pods_var( self::$type . '_max_length', $options, 255 );
325
 
@@ -327,56 +294,234 @@ class PodsField_Website extends PodsField {
327
  $value = pods_mb_substr( $value, 0, $length );
328
  }
329
 
330
- return $value;
331
- }
332
-
333
- /**
334
- * Customize the Pods UI manage table column output
335
- *
336
- * @param int $id
337
- * @param mixed $value
338
- * @param string $name
339
- * @param array $options
340
- * @param array $fields
341
- * @param array $pod
342
- *
343
- * @since 2.0
344
- */
345
- public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
346
- $value = $this->display( $value, $name, $options, $pod, $id );
347
-
348
- return $value;
349
- }
350
-
351
- /**
352
- * Build an url
353
- *
354
- * @param array|string $url
355
- *
356
- * @return string
357
- */
358
- public function build_url ( $url ) {
359
- if ( function_exists( 'http_build_url' ) )
360
- return http_build_url( $url );
361
-
362
- $defaults = array(
363
- 'scheme' => 'http',
364
- 'host' => '',
365
- 'path' => '/',
366
- 'query' => '',
367
- 'fragment' => ''
368
- );
369
-
370
- $url = array_merge( $defaults, (array) $url );
371
-
372
- $new_url = trim( $url[ 'scheme' ] . '://', ':' ) . $url[ 'host' ] . '/' . ltrim( $url[ 'path' ], '/' );
373
-
374
- if ( !empty( $url[ 'query' ] ) )
375
- $new_url .= '?' . ltrim( $url[ 'query' ], '?' );
376
-
377
- if ( !empty( $url[ 'fragment' ] ) )
378
- $new_url .= '#' . ltrim( $url[ 'fragment' ], '#' );
379
-
380
- return $new_url;
381
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
382
  }
4
  */
5
  class PodsField_Website extends PodsField {
6
 
7
+ /**
8
+ * Field Type Group
9
+ *
10
+ * @var string
11
+ * @since 2.0
12
+ */
13
+ public static $group = 'Text';
14
+
15
+ /**
16
+ * Field Type Identifier
17
+ *
18
+ * @var string
19
+ * @since 2.0
20
+ */
21
+ public static $type = 'website';
22
+
23
+ /**
24
+ * Field Type Label
25
+ *
26
+ * @var string
27
+ * @since 2.0
28
+ */
29
+ public static $label = 'Website';
30
+
31
+ /**
32
+ * Field Type Preparation
33
+ *
34
+ * @var string
35
+ * @since 2.0
36
+ */
37
+ public static $prepare = '%s';
38
+
39
+ /**
40
+ * Do things like register/enqueue scripts and stylesheets
41
+ *
42
+ * @since 2.0
43
+ */
44
+ public function __construct () {
45
+
46
+ self::$label = __( 'Website', 'pods' );
47
+
48
+ }
49
+
50
+ /**
51
+ * Add options and set defaults to
52
+ *
53
+ * @param array $options
54
+ *
55
+ * @since 2.0
56
+ */
57
+ public function options () {
58
+ $options = array(
59
+ self::$type . '_repeatable' => array(
60
+ 'label' => __( 'Repeatable Field', 'pods' ),
61
+ 'default' => 0,
62
+ 'type' => 'boolean',
63
+ 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
64
+ 'boolean_yes_label' => '',
65
+ 'dependency' => true,
66
+ 'developer_mode' => true
67
+ ),
68
+ self::$type . '_format' => array(
69
+ 'label' => __( 'Format', 'pods' ),
70
+ 'default' => 'normal',
71
+ 'type' => 'pick',
72
+ 'data' => array(
73
+ 'normal' => __( 'http://example.com/', 'pods' ),
74
+ 'no-www' => __( 'http://example.com/ (remove www)', 'pods' ),
75
+ 'force-www' => __( 'http://www.example.com/ (force www if no sub-domain provided)', 'pods' ),
76
+ 'no-http' => __( 'example.com', 'pods' ),
77
+ 'no-http-no-www' => __( 'example.com (force removal of www)', 'pods' ),
78
+ 'no-http-force-www' => __( 'www.example.com (force www if no sub-domain provided)', 'pods' ),
79
+ 'none' => __( 'No format', 'pods' ),
80
+ ),
81
+ 'dependency' => true,
82
+ ),
83
+ self::$type . '_allow_port' => array(
84
+ 'label' => __( 'Allow port in URL?', 'pods' ),
85
+ 'default' => apply_filters( 'pods_form_ui_field_website_port', 0, self::$type ),
86
+ 'type' => 'boolean',
87
+ 'dependency' => true,
88
+ ),
89
+ self::$type . '_clickable' => array(
90
+ 'label' => __( 'Output as a link?', 'pods' ),
91
+ 'default' => apply_filters( 'pods_form_ui_field_website_clickable', 0, self::$type ),
92
+ 'type' => 'boolean',
93
+ 'dependency' => true,
94
+ ),
95
+ self::$type . '_new_window' => array(
96
+ 'label' => __( 'Open link in new window?', 'pods' ),
97
+ 'default' => apply_filters( 'pods_form_ui_field_website_new_window', 0, self::$type ),
98
+ 'type' => 'boolean',
99
+ 'depends-on' => array( self::$type . '_clickable' => true ),
100
+ ),
101
+ self::$type . '_max_length' => array(
102
+ 'label' => __( 'Maximum Length', 'pods' ),
103
+ 'default' => 255,
104
+ 'type' => 'number',
105
+ 'help' => __( 'Set to -1 for no limit', 'pods' ),
106
+ ),
107
+ self::$type . '_html5' => array(
108
+ 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
109
+ 'default' => apply_filters( 'pods_form_ui_field_html5', 0, self::$type ),
110
+ 'type' => 'boolean',
111
+ 'excludes-on' => array( self::$type . '_format' => array( 'no-http', 'no-http-no-www', 'no-http-force-www' ) ),
112
+ ),
113
+ self::$type . '_placeholder' => array(
114
+ 'label' => __( 'HTML Placeholder', 'pods' ),
115
+ 'default' => '',
116
+ 'type' => 'text',
117
+ 'help' => array(
118
+ __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
119
+ 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
120
+ ),
121
+ ),/*,
122
+ self::$type . '_size' => array(
123
+ 'label' => __( 'Field Size', 'pods' ),
124
+ 'default' => 'medium',
125
+ 'type' => 'pick',
126
+ 'data' => array(
127
+ 'small' => __( 'Small', 'pods' ),
128
+ 'medium' => __( 'Medium', 'pods' ),
129
+ 'large' => __( 'Large', 'pods' )
130
+ )
131
+ )*/
132
+ );
133
+ return $options;
134
+ }
135
+
136
+ /**
137
+ * Define the current field's schema for DB table storage
138
+ *
139
+ * @param array $options
140
+ *
141
+ * @return array
142
+ * @since 2.0
143
+ */
144
+ public function schema ( $options = null ) {
145
+ $length = (int) pods_var( self::$type . '_max_length', $options, 255 );
146
+
147
+ $schema = 'VARCHAR(' . $length . ')';
148
+
149
+ if ( 255 < $length || $length < 1 )
150
+ $schema = 'LONGTEXT';
151
+
152
+ return $schema;
153
+ }
154
+
155
+ /**
156
+ * Change the way the value of the field is displayed with Pods::get
157
+ *
158
+ * @param mixed $value
159
+ * @param string $name
160
+ * @param array $options
161
+ * @param array $pod
162
+ * @param int $id
163
+ *
164
+ * @return mixed|null
165
+ * @since 2.0
166
+ */
167
+ public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
168
+ // Ensure proper format
169
+ $value = $this->pre_save( $value, $id, $name, $options, null, $pod );
170
+
171
+ if ( 1 == pods_v( self::$type . '_clickable', $options ) && 0 < strlen( $value ) ) {
172
+ $link = '<a href="%s"%s>%s</a>';
173
+
174
+ $atts = '';
175
+
176
+ if ( 1 == pods_v( self::$type . '_new_window', $options ) ) {
177
+ $atts .= ' target="_blank"';
178
+ }
179
+
180
+ $value = sprintf( $link, esc_url( $value ), $atts, esc_html( $value ) );
181
+ }
182
+
183
+ return $value;
184
+ }
185
+
186
+ /**
187
+ * Customize output of the form field
188
+ *
189
+ * @param string $name
190
+ * @param mixed $value
191
+ * @param array $options
192
+ * @param array $pod
193
+ * @param int $id
194
+ *
195
+ * @since 2.0
196
+ */
197
+ public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
198
+ $options = (array) $options;
199
+ $form_field_type = PodsForm::$field_type;
200
+
201
+ // Ensure proper format
202
+ $value = $this->pre_save( $value, $id, $name, $options, null, $pod );
203
+
204
+ $field_type = 'website';
205
+
206
+ if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) {
207
+ if ( pods_var( 'read_only', $options, false ) ) {
208
+ $options[ 'readonly' ] = true;
209
+
210
+ $field_type = 'text';
211
+ }
212
+ else
213
+ return;
214
+ }
215
+ elseif ( !pods_has_permissions( $options ) && pods_var( 'read_only', $options, false ) ) {
216
+ $options[ 'readonly' ] = true;
217
+
218
+ $field_type = 'text';
219
+ }
220
+
221
+ pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
222
+ }
223
+
224
+ /**
225
+ * Validate a value before it's saved
226
+ *
227
+ * @param mixed $value
228
+ * @param string $name
229
+ * @param array $options
230
+ * @param array $fields
231
+ * @param array $pod
232
+ * @param int $id
233
+ *
234
+ * @return bool|array
235
+ *
236
+ * @since 2.0
237
+ */
238
+ public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
239
+ $errors = array();
240
+
241
+ $label = strip_tags( pods_var_raw( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) ) );
242
+
243
+ $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
244
+
245
+ if ( is_array( $check ) )
246
+ $errors = $check;
247
+ else {
248
+ if ( 0 < strlen( $value ) && strlen( $check ) < 1 ) {
249
+ if ( 1 == pods_var( 'required', $options ) )
250
+ $errors[] = sprintf( __( 'The %s field is required.', 'pods' ), $label );
251
+ else
252
+ $errors[] = sprintf( __( 'Invalid website provided for the field %s.', 'pods' ), $label );
253
+ }
254
+ }
255
+
256
+ if ( !empty( $errors ) )
257
+ return $errors;
258
+
259
+ return true;
260
+ }
261
+
262
+ /**
263
+ * Change the value or perform actions after validation but before saving to the DB
264
+ *
265
+ * @param mixed $value
266
+ * @param int $id
267
+ * @param string $name
268
+ * @param array $options
269
+ * @param array $fields
270
+ * @param array $pod
271
+ * @param object $params
272
+ *
273
+ * @return string
274
+ *
275
+ * @since 2.0
276
+ */
277
+ public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
278
+ $options = (array) $options;
279
+
280
+ // Update from a array input field (like link) if the field updates
281
+ if ( is_array( $value ) ) {
282
+ if ( isset( $value['url'] ) ) {
283
+ $value = $value['url'];
284
+ } else {
285
+ $value = implode( ' ', $value );
286
+ }
287
+ }
288
+
289
+ $value = $this->validate_url( $value, $options );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
 
291
  $length = (int) pods_var( self::$type . '_max_length', $options, 255 );
292
 
294
  $value = pods_mb_substr( $value, 0, $length );
295
  }
296
 
297
+ return $value;
298
+ }
299
+
300
+ /**
301
+ * Customize the Pods UI manage table column output
302
+ *
303
+ * @param int $id
304
+ * @param mixed $value
305
+ * @param string $name
306
+ * @param array $options
307
+ * @param array $fields
308
+ * @param array $pod
309
+ *
310
+ * @return string
311
+ *
312
+ * @since 2.0
313
+ */
314
+ public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
315
+ $value = $this->display( $value, $name, $options, $pod, $id );
316
+
317
+ return $value;
318
+ }
319
+
320
+ /**
321
+ * Validate an URL with the options
322
+ *
323
+ * @param string $value
324
+ * @param array $options
325
+ *
326
+ * @return string
327
+ *
328
+ * @since 2.7
329
+ */
330
+ public function validate_url( $value, $options = null ) {
331
+ if ( empty( $value ) ) {
332
+ return $value;
333
+ }
334
+
335
+ if ( 'none' === pods_var( self::$type . '_format', $options ) ) {
336
+ return $this->strip_html( $value, $options );
337
+ }
338
+
339
+ if ( is_array( $value ) ) {
340
+ if ( isset( $value[ 'scheme' ] ) )
341
+ $value = $this->build_url( $value, $options );
342
+ else
343
+ $value = implode( '', $value );
344
+ }
345
+
346
+ if ( false === strpos( $value, '://' ) && 0 !== strpos( $value, '//' ) )
347
+ $value = 'http://' . $value;
348
+
349
+ $url = @parse_url( $value );
350
+
351
+ if ( empty( $url ) || count( $url ) < 2 )
352
+ $value = '';
353
+ else {
354
+ $defaults = array(
355
+ 'scheme' => 'http',
356
+ 'host' => '',
357
+ 'port' => '',
358
+ 'path' => '/',
359
+ 'query' => '',
360
+ 'fragment' => ''
361
+ );
362
+
363
+ $url = array_merge( $defaults, $url );
364
+
365
+ if ( 'normal' == pods_var( self::$type . '_format', $options ) )
366
+ $value = $this->build_url( $url, $options );
367
+ elseif ( 'no-www' == pods_var( self::$type . '_format', $options ) ) {
368
+ if ( 0 === strpos( $url[ 'host' ], 'www.' ) )
369
+ $url[ 'host' ] = substr( $url[ 'host' ], 4 );
370
+
371
+ $value = $this->build_url( $url, $options );
372
+ }
373
+ elseif ( 'force-www' == pods_var( self::$type . '_format', $options ) ) {
374
+ if ( false !== strpos( $url[ 'host' ], '.' ) && false === strpos( $url[ 'host' ], '.', 1 ) )
375
+ $url[ 'host' ] = 'www.' . $url[ 'host' ];
376
+
377
+ $value = $this->build_url( $url, $options );
378
+ }
379
+ elseif ( 'no-http' == pods_var( self::$type . '_format', $options ) ) {
380
+ $value = $this->build_url( $url, $options );
381
+ $value = str_replace( trim( $url[ 'scheme' ] . '://', ':' ), '', $value );
382
+
383
+ if ( '/' == $url[ 'path' ] )
384
+ $value = trim( $value, '/' );
385
+ }
386
+ elseif ( 'no-http-no-www' == pods_var( self::$type . '_format', $options ) ) {
387
+ if ( 0 === strpos( $url[ 'host' ], 'www.' ) )
388
+ $url[ 'host' ] = substr( $url[ 'host' ], 4 );
389
+
390
+ $value = $this->build_url( $url, $options );
391
+ $value = str_replace( trim( $url[ 'scheme' ] . '://', ':' ), '', $value );
392
+
393
+ if ( '/' == $url[ 'path' ] )
394
+ $value = trim( $value, '/' );
395
+ }
396
+ elseif ( 'no-http-force-www' == pods_var( self::$type . '_format', $options ) ) {
397
+ if ( false !== strpos( $url[ 'host' ], '.' ) && false === strpos( $url[ 'host' ], '.', 1 ) )
398
+ $url[ 'host' ] = 'www.' . $url[ 'host' ];
399
+
400
+ $value = $this->build_url( $url, $options );
401
+ $value = str_replace( trim( $url[ 'scheme' ] . '://', ':' ), '', $value );
402
+
403
+ if ( '/' == $url[ 'path' ] )
404
+ $value = trim( $value, '/' );
405
+ }
406
+ }
407
+
408
+ return $value;
409
+ }
410
+
411
+ /**
412
+ * Strip HTML based on options
413
+ *
414
+ * @param string $value
415
+ * @param array $options
416
+ *
417
+ * @return string
418
+ *
419
+ * @since 2.7
420
+ */
421
+ public function strip_html ( $value, $options = null ) {
422
+ if ( is_array( $value ) )
423
+ $value = @implode( ' ', $value );
424
+
425
+ $value = trim( $value );
426
+
427
+ if ( empty( $value ) )
428
+ return $value;
429
+
430
+ $options = (array) $options;
431
+
432
+ if ( 1 == pods_var( self::$type . '_allow_html', $options, 0, null, true ) ) {
433
+ $allowed_html_tags = '';
434
+
435
+ if ( 0 < strlen( pods_var( self::$type . '_allowed_html_tags', $options ) ) ) {
436
+ $allowed_html_tags = explode( ' ', trim( pods_var( self::$type . '_allowed_html_tags', $options ) ) );
437
+ $allowed_html_tags = '<' . implode( '><', $allowed_html_tags ) . '>';
438
+ }
439
+
440
+ if ( !empty( $allowed_html_tags ) && '<>' != $allowed_html_tags )
441
+ $value = strip_tags( $value, $allowed_html_tags );
442
+ }
443
+ else
444
+ $value = strip_tags( $value );
445
+
446
+ return $value;
447
+ }
448
+
449
+ /**
450
+ * Validate an target attribute with the options
451
+ *
452
+ * @param string $value
453
+ *
454
+ * @return string
455
+ *
456
+ * @since 2.7
457
+ */
458
+ public function validate_target( $value ) {
459
+ if ( ! empty( $value ) && $value == '_blank' ) {
460
+ $value = '_blank';
461
+ } else {
462
+ $value = '';
463
+ }
464
+ return $value;
465
+ }
466
+
467
+ /**
468
+ * Build a url from url parts
469
+ *
470
+ * @param array|string $url
471
+ * @param array $options
472
+ *
473
+ * @return string
474
+ */
475
+ public function build_url( $url, $options = array() ) {
476
+
477
+ $url = (array) $url;
478
+
479
+ $allow_port = (int) pods_v( self::$type . '_allow_port', $options, 0 );
480
+
481
+ // If port is not allowed, always set to empty
482
+ if ( 0 === $allow_port ) {
483
+ $url['port'] = '';
484
+ }
485
+
486
+ if ( function_exists( 'http_build_url' ) ) {
487
+ return http_build_url( $url );
488
+ }
489
+
490
+ $defaults = array(
491
+ 'scheme' => 'http',
492
+ 'host' => '',
493
+ 'port' => '',
494
+ 'path' => '/',
495
+ 'query' => '',
496
+ 'fragment' => ''
497
+ );
498
+
499
+ $url = array_merge( $defaults, $url );
500
+
501
+ $new_url = array();
502
+
503
+ $new_url[] = trim( $url['scheme'] . '://', ':' );
504
+ $new_url[] = $url['host'];
505
+
506
+ if ( ! empty( $url['port'] ) ) {
507
+ $new_url[] = ':' . $url['port'];
508
+ }
509
+
510
+ $new_url[] = '/' . ltrim( $url['path'], '/' );
511
+
512
+ if ( ! empty( $url['query'] ) ) {
513
+ $new_url[] = '?' . ltrim( $url['query'], '?' );
514
+ }
515
+
516
+ if ( ! empty( $url['fragment'] ) ) {
517
+ $new_url[] = '#' . ltrim( $url['fragment'], '#' );
518
+ }
519
+
520
+ // Pull all of the parts back together
521
+ $new_url = implode( '', $new_url );
522
+
523
+ return $new_url;
524
+
525
+ }
526
+
527
  }
components/Helpers.php CHANGED
@@ -71,7 +71,7 @@ class Pods_Helpers extends PodsComponent {
71
  if ( is_admin() ) {
72
  add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 );
73
 
74
- add_action( 'dbx_post_advanced', array( $this, 'edit_page_form' ), 10 );
75
 
76
  add_action( 'pods_meta_groups', array( $this, 'add_meta_boxes' ) );
77
  add_filter( 'get_post_metadata', array( $this, 'get_meta' ), 10, 4 );
@@ -153,7 +153,7 @@ class Pods_Helpers extends PodsComponent {
153
  * @since 2.0
154
  */
155
  public function admin_assets () {
156
- wp_enqueue_style( 'pods-admin' );
157
  }
158
 
159
  /**
@@ -327,7 +327,7 @@ class Pods_Helpers extends PodsComponent {
327
  'post_content' => $meta_value
328
  );
329
 
330
- remove_filter( current_filter(), array( $this, __FUNCTION__ ), 10 );
331
 
332
  $revisions = false;
333
 
@@ -425,8 +425,61 @@ class Pods_Helpers extends PodsComponent {
425
 
426
  $params = $_safe_params;
427
  }
428
- elseif ( is_callable( (string) $params->helper ) )
429
- echo call_user_func( (string) $params->helper, $params->value, $params->name, $params, $obj );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
430
 
431
  $out = ob_get_clean();
432
 
71
  if ( is_admin() ) {
72
  add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 );
73
 
74
+ add_action( 'dbx_post_advanced', array( $this, 'edit_page_form' ) );
75
 
76
  add_action( 'pods_meta_groups', array( $this, 'add_meta_boxes' ) );
77
  add_filter( 'get_post_metadata', array( $this, 'get_meta' ), 10, 4 );
153
  * @since 2.0
154
  */
155
  public function admin_assets () {
156
+ wp_enqueue_style( 'pods-styles' );
157
  }
158
 
159
  /**
327
  'post_content' => $meta_value
328
  );
329
 
330
+ remove_filter( current_filter(), array( $this, __FUNCTION__ ) );
331
 
332
  $revisions = false;
333
 
425
 
426
  $params = $_safe_params;
427
  }
428
+ elseif ( is_callable( (string) $params->helper ) ) {
429
+ $params->helper = (string) $params->helper;
430
+
431
+ $disallowed = array(
432
+ 'system',
433
+ 'exec',
434
+ 'popen',
435
+ 'eval',
436
+ 'preg_replace',
437
+ 'create_function',
438
+ 'include',
439
+ 'include_once',
440
+ 'require',
441
+ 'require_once',
442
+ );
443
+
444
+ $allowed = array();
445
+
446
+ /**
447
+ * Allows adjusting the disallowed callbacks as needed.
448
+ *
449
+ * @param array $disallowed List of callbacks not allowed.
450
+ * @param array $params Parameters used by Pods::helper() method.
451
+ *
452
+ * @since 2.7
453
+ */
454
+ $disallowed = apply_filters( 'pods_helper_disallowed_callbacks', $disallowed, get_object_vars( $params ) );
455
+
456
+ /**
457
+ * Allows adjusting the allowed allowed callbacks as needed.
458
+ *
459
+ * @param array $allowed List of callbacks explicitly allowed.
460
+ * @param array $params Parameters used by Pods::helper() method.
461
+ *
462
+ * @since 2.7
463
+ */
464
+ $allowed = apply_filters( 'pods_helper_allowed_callbacks', $allowed, get_object_vars( $params ) );
465
+
466
+ // Clean up helper callback (if string)
467
+ $params->helper = strip_tags( str_replace( array( '`', chr( 96 ) ), "'", $params->helper ) );
468
+
469
+ $is_allowed = false;
470
+
471
+ if ( ! empty( $allowed ) ) {
472
+ if ( in_array( $params->helper, $allowed, true ) ) {
473
+ $is_allowed = true;
474
+ }
475
+ } elseif ( ! in_array( $params->helper, $disallowed, true ) ) {
476
+ $is_allowed = true;
477
+ }
478
+
479
+ if ( $is_allowed ) {
480
+ echo call_user_func( $params->helper, $params->value, $params->name, $params, $obj );
481
+ }
482
+ }
483
 
484
  $out = ob_get_clean();
485
 
components/I18n/I18n-polylang.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Pods_I18n_Polylang {
4
+
5
+ public $languages = array();
6
+ public $textdomain = 'polylang';
7
+
8
+ public function __construct() {
9
+
10
+ if ( function_exists( 'pll_languages_list' ) ) {
11
+ $this->languages = pll_languages_list( array( 'fields' => 'locale' ) );
12
+
13
+ add_filter( 'pods_component_i18n_admin_data', array( $this, 'pods_component_i18n_admin_data' ) );
14
+ add_filter( 'pods_component_i18n_admin_ui_fields', array( $this, 'pods_component_i18n_admin_ui_fields' ), 10, 2 );
15
+ }
16
+
17
+ }
18
+
19
+ public function pods_component_i18n_admin_data( $data ) {
20
+ foreach ( $data as $lang => $field_data ) {
21
+ if ( in_array( $lang, $this->languages ) ) {
22
+ $data[$lang]['polylang'] = true;
23
+ } else {
24
+ $data[$lang]['polylang'] = false;
25
+ }
26
+ }
27
+ return $data;
28
+ }
29
+
30
+ public function pods_component_i18n_admin_ui_fields( $fields, $data ) {
31
+ $fields['manage']['polylang'] = array(
32
+ 'label' => __( 'Polylang' , $this->textdomain ),
33
+ 'type' => 'boolean',
34
+ /*'options' => array(
35
+ 'text_allow_html' => 1,
36
+ 'text_allowed_html_tags' => 'br a',
37
+ )*/
38
+ );
39
+ return $fields;
40
+ }
41
+
42
+ }
43
+
44
+ new Pods_I18n_Polylang();
components/I18n/I18n-wpml.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Pods_I18n_WPML {
4
+
5
+ public $languages = array();
6
+ public $textdomain = 'sitepress-multilingual-cms';
7
+
8
+ public function __construct() {
9
+
10
+ $languages = apply_filters( 'wpml_active_languages', array() );
11
+ if ( ! empty( $languages ) ) {
12
+ foreach ($languages as $lang => $lang_data) {
13
+ if ( isset( $lang_data['default_locale'] ) ) {
14
+ $locale = $lang_data['default_locale'];
15
+ $this->languages[] = $locale;
16
+ }
17
+ }
18
+
19
+ add_filter( 'pods_component_i18n_admin_data', array( $this, 'pods_component_i18n_admin_data' ) );
20
+ add_filter( 'pods_component_i18n_admin_ui_fields', array( $this, 'pods_component_i18n_admin_ui_fields' ), 10, 2 );
21
+ }
22
+
23
+ }
24
+
25
+ public function pods_component_i18n_admin_data( $data ) {
26
+ foreach ( $data as $lang => $field_data ) {
27
+ if ( in_array( $lang, $this->languages ) ) {
28
+ $data[$lang]['wpml'] = true;
29
+ } else {
30
+ $data[$lang]['wpml'] = false;
31
+ }
32
+ }
33
+ return $data;
34
+ }
35
+
36
+ public function pods_component_i18n_admin_ui_fields( $fields, $data ) {
37
+ $fields['manage']['wpml'] = array(
38
+ 'label' => __( 'WPML' , $this->textdomain ),
39
+ 'type' => 'boolean',
40
+ /*'options' => array(
41
+ 'text_allow_html' => 1,
42
+ 'text_allowed_html_tags' => 'br a',
43
+ )*/
44
+ );
45
+ return $fields;
46
+ }
47
+
48
+ }
49
+
50
+ new Pods_I18n_WPML();
components/I18n/I18n.php ADDED
@@ -0,0 +1,897 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: Translate Pods Admin
4
+ *
5
+ * Menu Name: Translate Pods
6
+ *
7
+ * Description: Allow UI of Pods and fields to be translated
8
+ *
9
+ * Version: 0.1
10
+ *
11
+ * Category: I18n
12
+ *
13
+ * Class: Pods_Component_I18n
14
+ *
15
+ * @package Pods\Components
16
+ * @subpackage i18n
17
+ */
18
+
19
+ ! defined( 'ABSPATH' ) and die();
20
+
21
+ if ( class_exists( 'Pods_Component_I18n' ) )
22
+ return;
23
+
24
+ class Pods_Component_I18n extends PodsComponent {
25
+
26
+ public $settings = array();
27
+ public $locale = null;
28
+ public $languages = array();
29
+ public $languages_available = array();
30
+ public $languages_translated = array();
31
+ public $cur_pod = null;
32
+ public $option_key = 'pods_component_i18n_settings';
33
+ public $admin_page = 'pods-component-translate-pods-admin';
34
+ public $capability = 'pods_i18n_activate_lanuages';
35
+ public $nonce = 'pods_i18n_activate_lanuages';
36
+
37
+ public $translatable_fields = array(
38
+ 'label',
39
+ 'description',
40
+ 'placeholder',
41
+ 'menu_name',
42
+ 'name_admin_bar',
43
+ 'pick_select_text',
44
+ 'file_add_button',
45
+ 'file_modal_title',
46
+ 'file_modal_add_button',
47
+ );
48
+
49
+ /**
50
+ * Get mandatory data and add actions
51
+ *
52
+ * @since 0.1
53
+ */
54
+ public function __construct () {
55
+ $this->init();
56
+ }
57
+
58
+ /**
59
+ * Init function to register data, hooks and resources
60
+ * @since 0.1
61
+ */
62
+ public function init() {
63
+ $this->settings = get_option( $this->option_key, array() );
64
+
65
+ // Polylang
66
+ if ( function_exists( 'PLL' ) && file_exists( plugin_dir_path( __FILE__ ) . 'I18n-polylang.php' ) ) {
67
+ include_once( plugin_dir_path( __FILE__ ) . 'I18n-polylang.php' );
68
+ }
69
+ // WPML
70
+ if ( did_action( 'wpml_loaded' ) && file_exists( plugin_dir_path( __FILE__ ) . 'I18n-wpml.php' ) ) {
71
+ include_once( plugin_dir_path( __FILE__ ) . 'I18n-wpml.php' );
72
+ }
73
+
74
+ $active = false;
75
+ // Are there active languages?
76
+ if ( ! empty( $this->settings['enabled_languages'] ) ) {
77
+ $this->languages = $this->settings['enabled_languages'];
78
+ $this->locale = get_locale();
79
+ $active = true;
80
+ }
81
+
82
+ $is_component_page = false;
83
+ $is_pods_edit_page = false;
84
+ if ( is_admin() && isset( $_GET['page'] ) ) {
85
+
86
+ // Is the current page the admin page of this component or a Pods edit page?
87
+ if ( $_GET['page'] === $this->admin_page ) {
88
+ $is_component_page = true;
89
+ } elseif ( $_GET['page'] === 'pods' ) {
90
+ $is_pods_edit_page = true;
91
+ }
92
+
93
+ if ( $is_component_page || ( $is_pods_edit_page && $active ) ) {
94
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) );
95
+ }
96
+ }
97
+
98
+ if ( $is_component_page ) {
99
+ // Do save action here because otherwise the loading of post_types get done first and labels aren't translated
100
+ if ( pods_is_admin( $this->capability )
101
+ && isset( $_POST['_nonce_i18n'] )
102
+ && wp_verify_nonce( $_POST['_nonce_i18n'], $this->nonce )
103
+ ) {
104
+ $this->admin_save();
105
+ }
106
+ }
107
+
108
+ if ( $active ) {
109
+ // WP Object filters (post_type and taxonomy)
110
+ add_filter( 'pods_register_post_type', array( $this, 'pods_register_wp_object_i18n' ), 10, 2 );
111
+ add_filter( 'pods_register_taxonomy', array( $this, 'pods_register_wp_object_i18n' ), 10, 2 );
112
+
113
+ // ACT's
114
+ add_filter( 'pods_advanced_content_type_pod_data', array( $this, 'pods_filter_object_strings_i18n' ), 10, 2 );
115
+
116
+ // Setting pages
117
+ add_filter( 'pods_admin_menu_page_title', array( $this, 'admin_menu_page_title_i18n' ), 10, 2 );
118
+ add_filter( 'pods_admin_menu_label', array( $this, 'admin_menu_label_i18n' ), 10, 2 );
119
+
120
+ // Default filters for all fields
121
+ add_filter( 'pods_form_ui_label_text', array( $this, 'fields_ui_label_text_i18n' ), 10, 4 );
122
+ add_filter( 'pods_form_ui_comment_text', array( $this, 'fields_ui_comment_text_i18n' ), 10, 3 );
123
+
124
+ foreach ( pods_form()->field_types() as $type => $data ) {
125
+ add_filter( 'pods_form_ui_field_' . $type . '_options', array( $this, 'form_ui_field_options_i18n' ), 10, 5 );
126
+ }
127
+
128
+ // Field specific
129
+ //add_filter( 'pods_field_pick_data', array( $this, 'field_pick_data_i18n' ), 10, 6 );
130
+
131
+ if ( $is_pods_edit_page ) {
132
+
133
+ $pod = null;
134
+ // Get the pod if available
135
+ if ( isset( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
136
+ $pod = pods_api()->load_pod( array( 'id' => $_GET['id'] ) );
137
+ // Append options to root array for pods_v function to work
138
+ foreach ( $pod[ 'options' ] as $_option => $_value ) {
139
+ $pod[ $_option ] = $_value;
140
+ }
141
+ }
142
+ $this->cur_pod = $pod;
143
+
144
+ //Add option tab for post types
145
+ //add_filter( 'pods_admin_setup_edit_tabs_post_type', array( $this, 'pod_tab' ), 11, 3 );
146
+
147
+ //Add the same tab for taxonomies
148
+ //add_filter( 'pods_admin_setup_edit_tabs_taxonomy', array( $this, 'pod_tab' ), 11, 3 );
149
+
150
+ //Add options to the new tab
151
+ //add_filter( 'pods_admin_setup_edit_options', array( $this, 'pod_options' ), 12, 2 );
152
+
153
+ //Add options metabox to the pod edit screens
154
+ add_action( 'pods_add_meta_boxes', array( $this, 'admin_meta_box' ) );
155
+
156
+ //Add the i18n input fields based on existing fields
157
+ add_filter( 'pods_form_ui_field_text', array( $this, 'add_i18n_inputs' ), 10, 6 );
158
+ }
159
+
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Load assets for this component
165
+ * @since 0.1
166
+ */
167
+ public function admin_assets() {
168
+ wp_enqueue_script( 'pods-admin-i18n', PODS_URL . 'components/I18n/pods-admin-i18n.js', array( 'jquery', 'pods-i18n' ), '1.0', true );
169
+ $localize_script = array();
170
+ if ( ! empty( $this->languages ) ) {
171
+ foreach ( $this->languages as $lang => $lang_data ) {
172
+ $lang_label = $this->create_lang_label( $lang_data );
173
+ if ( ! empty( $lang_label ) ) {
174
+ $lang_label = $lang . ' ('. $lang_label .')';
175
+ } else {
176
+ $lang_label = $lang;
177
+ }
178
+ $localize_script[ $lang ] = $lang_label;
179
+ }
180
+ }
181
+ wp_localize_script( 'pods-admin-i18n', 'pods_admin_i18n_strings', $localize_script );
182
+
183
+ // Add strings to the i18n js object
184
+ add_filter( 'pods_localized_strings', array( $this, 'localize_assets' ) );
185
+ }
186
+
187
+ /**
188
+ * Localize the assets
189
+ * @param array $str Existing strings
190
+ * @return array
191
+ */
192
+ public function localize_assets( $str ) {
193
+ $str['Add translation'] = __( 'Add translation', 'pods' );
194
+ $str['Toggle translations'] = __( 'Toggle translations', 'pods' );
195
+ $str['Show translations'] = __( 'Show translations', 'pods' );
196
+ $str['Hide translations'] = __( 'Hide translations', 'pods' );
197
+ $str['Select'] = __( 'Select', 'pods' );
198
+ return $str;
199
+ }
200
+
201
+ /**
202
+ * Check is a field name is set for translation
203
+ *
204
+ * @since 0.1
205
+ * @param string $name
206
+ * @return bool
207
+ */
208
+ public function is_translatable_field( $name ) {
209
+
210
+ $translatable_fields = $this->get_translatable_fields();
211
+
212
+ // All fields that start with "label"
213
+ if ( strpos( $name, 'label' ) === 0 ) {
214
+ return true;
215
+ }
216
+ // All translatable fields
217
+ if ( in_array( $name, $translatable_fields ) ) {
218
+ return true;
219
+ }
220
+ // Custom fields data, the name must begin with field_data[
221
+ if ( strpos( $name, 'field_data[' ) === 0 ) {
222
+ $name = str_replace( 'field_data[', '', $name );
223
+ $name = rtrim( $name, ']' );
224
+ $name = explode( '][', $name );
225
+ $name = end( $name );
226
+ // All translatable fields from field_data[ (int) ][ $name ]
227
+ if ( in_array( $name, $translatable_fields ) ) {
228
+ return true;
229
+ }
230
+ }
231
+ return false;
232
+ }
233
+
234
+ /**
235
+ * Get a translated option for a field key (if available)
236
+ *
237
+ * @since 0.1
238
+ * @param string $current Current value
239
+ * @param string $key The key / opion name to search for
240
+ * @param array $data Pod data (can also be an options array of a pod or field)
241
+ * @return string
242
+ */
243
+ public function get_value_translation( $current, $key, $data ) {
244
+ $locale = $this->locale;
245
+ // Validate locale and pod
246
+ if ( is_array( $data ) && array_key_exists( $locale, $this->languages ) && $this->obj_is_language_enabled( $locale, $data ) ) {
247
+ // Add option keys to $data array
248
+ if ( ! empty( $data['options'] ) ) {
249
+ $data = array_merge( $data, $data['options'] );
250
+ }
251
+ // Check if the i18n option exists and isn't empty
252
+ if ( ! empty( $data[ $key . '_' . $locale ] ) ) {
253
+ return (string) $data[ $key . '_' . $locale ];
254
+ }
255
+ }
256
+ return $current;
257
+ }
258
+
259
+ /**
260
+ * Page title for setting pages
261
+ *
262
+ * @since 0.1
263
+ * @see PodsAdmin.php >> admin_menu()
264
+ * @see PodsAdmin.php >> admin_content_settings()
265
+ * @param string $page_title Current page title
266
+ * @param array $pod Pod data
267
+ * @return string
268
+ */
269
+ public function admin_menu_page_title_i18n( $page_title, $pod ) {
270
+ return (string) $this->get_value_translation( $page_title, 'label', $pod );
271
+ }
272
+
273
+ /**
274
+ * Menu title for setting pages
275
+ *
276
+ * @since 0.1
277
+ * @see PodsAdmin.php >> admin_menu()
278
+ * @param string $menu_label Current menu label
279
+ * @param array $pod Pod data
280
+ * @return string
281
+ */
282
+ public function admin_menu_label_i18n( $menu_label, $pod ) {
283
+ return (string) $this->get_value_translation( $menu_label, 'menu_name', $pod );
284
+ }
285
+
286
+ /**
287
+ * Returns the translated label if available
288
+ *
289
+ * @since 0.1
290
+ * @see PodsForm.php >> 'pods_form_ui_label_text' (filter)
291
+ * @param string $label The default label
292
+ * @param string $name The field name
293
+ * @param string $help The help text
294
+ * @param array $options The field options
295
+ * @return string
296
+ */
297
+ public function fields_ui_label_text_i18n( $label, $name, $help, $options ) {
298
+ return (string) $this->get_value_translation( $label, 'label', $options );
299
+ }
300
+
301
+ /**
302
+ * Returns the translated description if available
303
+ *
304
+ * @since 0.1
305
+ * @see PodsForm.php >> 'pods_form_ui_comment_text' (filter)
306
+ * @param string $message The default description
307
+ * @param string $name The field name
308
+ * @param array $options The field options
309
+ * @return string
310
+ */
311
+ public function fields_ui_comment_text_i18n( $message, $name, $options ) {
312
+ return (string) $this->get_value_translation( $message, 'description', $options );
313
+ }
314
+
315
+ /**
316
+ * Replaces the default selected text with a translation if available
317
+ *
318
+ * @since 0.1
319
+ * @see pick.php >> 'pods_field_pick_data' (filter)
320
+ * @param array $data The default data of the field
321
+ * @param string $name The field name
322
+ * @param string $value The field value
323
+ * @param array $options The field options
324
+ * @param array $pod The Pod
325
+ * @param int $id The field ID
326
+ * @return array
327
+ */
328
+ public function field_pick_data_i18n( $data, $name, $value, $options, $pod, $id ) {
329
+ if ( isset( $data[''] ) && isset( $options['pick_select_text'] ) ) {
330
+ $locale = $this->locale;
331
+ if ( isset( $options['pick_select_text_' . $locale ] )
332
+ && array_key_exists( $locale, $this->languages )
333
+ && $this->obj_is_language_enabled( $locale, $pod )
334
+ ) {
335
+ $data[''] = $options['pick_select_text_' . $locale ];
336
+ }
337
+ }
338
+ return $data;
339
+ }
340
+
341
+ /**
342
+ * Replaces the default values with a translation if available
343
+ *
344
+ * @since 0.1
345
+ * @see PodsForm.php >> 'pods_form_ui_field_' . $type . '_options' (filter)
346
+ * @param array $options The field options
347
+ * @param string $name The field name
348
+ * @param string $value The field value
349
+ * @param array $pod The Pod
350
+ * @param int $id The field ID
351
+ * @return array
352
+ */
353
+ public function form_ui_field_options_i18n( $options, $name, $value, $pod, $id ) {
354
+ foreach ( $this->get_translatable_fields() as $field ) {
355
+ $locale = $this->locale;
356
+ if ( isset( $options[ $field . '_' . $locale ] )
357
+ && array_key_exists( $locale, $this->languages )
358
+ && $this->obj_is_language_enabled( $locale, $pod )
359
+ ) {
360
+ $options[ $field ] = $options[ $field . '_' . $locale ];
361
+ }
362
+ }
363
+ return $options;
364
+ }
365
+
366
+ /**
367
+ * Filter hook function to overwrite the labels and description with translations (if available)
368
+ *
369
+ * @since 0.1
370
+ * @see PodsInit.php >> setup_content_types()
371
+ * @param array $options The array of object options
372
+ * @param string $object The object type name/slug
373
+ * @return array
374
+ */
375
+ public function pods_register_wp_object_i18n( $options, $object ) {
376
+
377
+ $locale = $this->locale;
378
+
379
+ $pod = pods_api()->load_pod( $object );
380
+
381
+ if ( ! $this->obj_is_language_enabled( $locale, $pod ) ) {
382
+ return $options;
383
+ }
384
+
385
+ // Load the pod
386
+ foreach ( $pod[ 'options' ] as $_option => $_value ) {
387
+ $pod[ $_option ] = $_value;
388
+ }
389
+
390
+ // Default
391
+ $locale_labels = array();
392
+ $locale_labels['name'] = esc_html( pods_v( 'label_'.$locale, $pod, '', true ) );
393
+ $locale_labels['singular_name'] = esc_html( pods_v( 'label_singular_'.$locale, $pod, '', true ) );
394
+ $locale_labels['menu_name'] = pods_v( 'menu_name_' . $locale, $pod, '', true );
395
+ $locale_labels['add_new_item'] = pods_v( 'label_add_new_item_' . $locale, $pod, '', true );
396
+ $locale_labels['edit_item'] = pods_v( 'label_edit_item_' . $locale, $pod, '', true );
397
+ $locale_labels['view_item'] = pods_v( 'label_view_item_' . $locale, $pod, '', true );
398
+ $locale_labels['all_items'] = pods_v( 'label_all_items_' . $locale, $pod, '', true );
399
+ $locale_labels['search_items'] = pods_v( 'label_search_items_' . $locale, $pod, '', true );
400
+ $locale_labels['parent_item_colon'] = pods_v( 'label_parent_item_colon_' . $locale, $pod, '', true );
401
+ $locale_labels['not_found'] = pods_v( 'label_not_found_' . $locale, $pod, '', true );
402
+ $locale_labels['items_list_navigation'] = pods_v( 'label_items_list_navigation_' . $locale, $pod, '', true );
403
+ $locale_labels['items_list'] = pods_v( 'label_items_list_' . $locale, $pod, '', true );
404
+
405
+ // Post Types
406
+ $locale_labels['name_admin_bar'] = pods_v( 'name_admin_bar_' . $locale, $pod, '', true );
407
+ $locale_labels['add_new'] = pods_v( 'label_add_new_' . $locale, $pod, '', true );
408
+ $locale_labels['new_item'] = pods_v( 'label_new_item_' . $locale, $pod, '', true );
409
+ $locale_labels['edit'] = pods_v( 'label_edit_' . $locale, $pod, '', true );
410
+ $locale_labels['view'] = pods_v( 'label_view_' . $locale, $pod, '', true );
411
+ $locale_labels['view_items'] = pods_v( 'label_view_items_' . $locale, $pod, '', true );
412
+ $locale_labels['parent'] = pods_v( 'label_parent_' . $locale, $pod, '', true );
413
+ $locale_labels['not_found_in_trash'] = pods_v( 'label_not_found_in_trash_' . $locale, $pod, '', true );
414
+ $locale_labels['archives'] = pods_v( 'label_archives_' . $locale, $pod, '', true );
415
+ $locale_labels['attributes'] = pods_v( 'label_attributes_' . $locale, $pod, '', true );
416
+ $locale_labels['insert_into_item'] = pods_v( 'label_insert_into_item_' . $locale, $pod, '', true );
417
+ $locale_labels['uploaded_to_this_item'] = pods_v( 'label_uploaded_to_this_item_' . $locale, $pod, '', true );
418
+ $locale_labels['featured_image'] = pods_v( 'label_featured_image_' . $locale, $pod, '', true );
419
+ $locale_labels['set_featured_image'] = pods_v( 'label_set_featured_image_' . $locale, $pod, '', true );
420
+ $locale_labels['remove_featured_image'] = pods_v( 'label_remove_featured_image_' . $locale, $pod, '', true );
421
+ $locale_labels['use_featured_image'] = pods_v( 'label_use_featured_image_' . $locale, $pod, '', true );
422
+ $locale_labels['filter_items_list'] = pods_v( 'label_filter_items_list_' . $locale, $pod, '', true );
423
+
424
+ // Taxonomies
425
+ $locale_labels['update_item'] = pods_v( 'label_update_item_' . $locale, $pod, '', true );
426
+ $locale_labels['popular_items'] = pods_v( 'label_popular_items_' . $locale, $pod, '', true );
427
+ $locale_labels['parent_item'] = pods_v( 'label_parent_item_' . $locale, $pod, '', true );
428
+ $locale_labels['new_item_name'] = pods_v( 'label_new_item_name_' . $locale, $pod, '', true );
429
+ $locale_labels['separate_items_with_commas'] = pods_v( 'label_separate_items_with_commas_' . $locale, $pod, '', true );
430
+ $locale_labels['add_or_remove_items'] = pods_v( 'label_add_or_remove_items_' . $locale, $pod, '', true );
431
+ $locale_labels['choose_from_most_used'] = pods_v( 'label_choose_from_the_most_used_' . $locale, $pod, '', true );
432
+ $locale_labels['no_terms'] = pods_v( 'label_no_terms_' . $locale, $pod, '', true );
433
+
434
+ // Assign to label array
435
+ if ( isset( $options['labels'] ) && is_array( $options['labels'] ) ) {
436
+ foreach( $options['labels'] as $key => $value ) {
437
+ // @todo Currently I only overwrite, maybe also append even if the default locale isn't set?
438
+ if ( isset( $locale_labels[ $key ] ) && ! empty( $locale_labels[ $key ] ) ) {
439
+ $options['labels'][ $key ] = $locale_labels[ $key ];
440
+ }
441
+ }
442
+ }
443
+
444
+ return $options;
445
+ }
446
+
447
+ /**
448
+ * Filter hook function to overwrite the labels and description with translations (if available)
449
+ *
450
+ * @since 0.1
451
+ * @see PodsInit.php >> admin_menu()
452
+ * @param array $options The array of object options
453
+ * @param string $object The object type name/slug
454
+ * @return array
455
+ */
456
+ function pods_filter_object_strings_i18n( $options, $object ) {
457
+
458
+ /**
459
+ * @todo allow labels to be set even if the default language isn't
460
+ *
461
+ * - Find all keys that end with the current locale
462
+ * - Assign them to the keys without that locale
463
+ */
464
+
465
+ foreach( $options as $key => $option ) {
466
+ if ( is_string( $option ) && $this->is_translatable_field( $key ) ) {
467
+ $options[ $key ] = $this->get_value_translation( $option, $key, $options );
468
+ }
469
+ }
470
+
471
+ if ( ! empty( $options['options'] ) ) {
472
+ foreach( $options['options'] as $key => $option ) {
473
+ if ( is_string( $option ) && $this->is_translatable_field( $key ) ) {
474
+ $options['options'][ $key ] = $this->get_value_translation( $option, $key, $options['options'] );
475
+ }
476
+ }
477
+ }
478
+
479
+ return $options;
480
+ }
481
+
482
+ /**
483
+ * Save component settings
484
+ *
485
+ * @since 0.1
486
+ */
487
+ public function admin_save() {
488
+
489
+ $this->languages_available = get_available_languages();
490
+
491
+ /**
492
+ * format: array( language, version, updated, english_name, native_name, package, iso, strings )
493
+ */
494
+ require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
495
+ $this->languages_translated = wp_get_available_translations();
496
+
497
+ $new_languages = array();
498
+
499
+ if ( isset( $_POST['pods_i18n_enabled_languages'] ) && is_array( $_POST['pods_i18n_enabled_languages'] ) ) {
500
+ foreach ( $_POST['pods_i18n_enabled_languages'] as $locale ) {
501
+ $locale = sanitize_text_field( $locale );
502
+
503
+ if ( in_array( $locale, $this->languages_available ) ) {
504
+ $new_languages[ $locale ] = array();
505
+
506
+ if ( isset( $this->languages_translated[ $locale ]['language'] ) ) {
507
+ $new_languages[ $locale ]['language'] = $this->languages_translated[ $locale ]['language'];
508
+ }
509
+
510
+ if ( isset( $this->languages_translated[ $locale ]['english_name'] ) ) {
511
+ $new_languages[ $locale ]['english_name'] = $this->languages_translated[ $locale ]['english_name'];
512
+ }
513
+
514
+ if ( isset( $this->languages_translated[ $locale ]['native_name'] ) ) {
515
+ $new_languages[ $locale ]['native_name'] = $this->languages_translated[ $locale ]['native_name'];
516
+ }
517
+ }
518
+ }
519
+ }
520
+
521
+ $this->languages = $new_languages;
522
+ $this->settings['enabled_languages'] = $new_languages;
523
+
524
+ update_option( $this->option_key, $this->settings );
525
+
526
+ }
527
+
528
+ /**
529
+ * Build admin area
530
+ *
531
+ * @since 0.1
532
+ * @param $options
533
+ * @param $component
534
+ * @return void
535
+ */
536
+ public function admin ( $options, $component ) {
537
+
538
+ $this->languages_available = get_available_languages();
539
+
540
+ /**
541
+ * format: array( language, version, updated, english_name, native_name, package, iso, strings )
542
+ */
543
+ require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
544
+
545
+ $this->languages_translated = wp_get_available_translations();
546
+
547
+ // en_US is always installed (default locale of WP)
548
+ $data = array(
549
+ 'en_US' => array(
550
+ 'id' => 'en_US',
551
+ 'locale' => 'en_US',
552
+ 'lang' => 'English',
553
+ 'lang_native' => 'English',
554
+ 'enabled' => 'Default',
555
+ )
556
+ );
557
+
558
+ foreach ( $this->languages_available as $locale ) {
559
+ $checked = checked( isset( $this->languages[ $locale ] ), true, false );
560
+
561
+ $enabled = sprintf(
562
+ '<input type="checkbox" name="pods_i18n_enabled_languages[%s]" value="%s"%s />',
563
+ esc_attr( $locale ),
564
+ esc_attr( $locale ),
565
+ $checked
566
+ );
567
+
568
+ $data[ $locale ] = array(
569
+ 'id' => $locale,
570
+ 'locale' => $locale,
571
+ 'lang' => $this->languages_translated[ $locale ]['english_name'],
572
+ 'lang_native' => $this->languages_translated[ $locale ]['native_name'],
573
+ 'enabled' => $enabled,
574
+ );
575
+ }
576
+
577
+ $ui = array(
578
+ 'component' => $component,
579
+ //'data' => $data,
580
+ //'total' => count( $data ),
581
+ //'total_found' => count( $data ),
582
+ 'items' => __('Languages', 'pods'),
583
+ 'item' => __('Language', 'pods'),
584
+ 'fields' => array(
585
+ 'manage' => array(
586
+ 'enabled' => array(
587
+ 'label' => __( 'Active', 'pods' ),
588
+ 'type' => 'raw',
589
+ ),
590
+ 'locale' => array( 'label' => __( 'Locale', 'pods' ), 'classes' => array( 'column-secondary' ) ),
591
+ 'lang' => array( 'label' => __( 'Language', 'pods' ) ),
592
+ 'lang_native' => array( 'label' => __( 'Native name', 'pods' ) ),
593
+ /*'fields' => array(
594
+ 'label' => __( 'Fields', 'pods' ),
595
+ 'type' => 'text',
596
+ 'options' => array(
597
+ 'text_allow_html' => 1,
598
+ 'text_allowed_html_tags' => 'br code'
599
+ )
600
+ ),*/
601
+ )
602
+ ),
603
+ 'actions_disabled' => array( 'edit', 'add', 'delete', 'duplicate', 'view', 'export' ),
604
+ 'actions_custom' => array(
605
+ //'add' => array( $this, 'admin_add' ),
606
+ //'edit' => array( $this, 'admin_edit' ),
607
+ //'delete' => array( $this, 'admin_delete' )
608
+ ),
609
+ 'search' => false,
610
+ 'searchable' => false,
611
+ 'sortable' => false,
612
+ 'pagination' => false
613
+ );
614
+
615
+ /**
616
+ * Filter the language data
617
+ * @since 0.1
618
+ * @param array
619
+ */
620
+ $data = apply_filters( 'pods_component_i18n_admin_data', $data );
621
+
622
+ /**
623
+ * Filter the UI fields
624
+ * @since 0.1
625
+ * @param array
626
+ */
627
+ $ui['fields'] = apply_filters( 'pods_component_i18n_admin_ui_fields', $ui['fields'], $data );
628
+
629
+ $ui['data'] = $data;
630
+ $ui['total'] = count( $data );
631
+ $ui['total_found'] = count( $data );
632
+
633
+ /*if ( !pods_is_admin( array( 'pods_i18n_activate_lanuages' ) ) )
634
+ $ui[ 'actions_disabled' ][] = 'edit';*/
635
+
636
+ echo '<div id="pods_admin_i18n" class="pods-submittable-fields">';
637
+
638
+ // Do save action here because otherwise the loading of post_types get done first and labels aren't translated
639
+ if ( pods_is_admin( $this->capability )
640
+ && isset( $_POST['_nonce_i18n'] )
641
+ && wp_verify_nonce( $_POST['_nonce_i18n'], $this->nonce )
642
+ ) {
643
+ pods_message( __( 'Updated active languages.', 'pods' ) );
644
+ }
645
+
646
+ pods_ui( $ui );
647
+
648
+ // @todo Do this in pods_ui so we don't rely on javascript
649
+ echo '<div id="pods_i18n_settings_save">';
650
+ wp_nonce_field( $this->nonce, '_nonce_i18n', false );
651
+ submit_button();
652
+ echo '</div>';
653
+
654
+ echo '</div>';
655
+ }
656
+
657
+ /**
658
+ * The i18n option tab.
659
+ *
660
+ * @todo Remove if not used in final version
661
+ *
662
+ * @since 0.1
663
+ * @param array $tabs
664
+ * @param array $pod
665
+ * @param array $args
666
+ * @return array
667
+ */
668
+ public function pod_tab( $tabs, $pod, $args ) {
669
+ $tabs[ 'pods-i18n' ] = __( 'Translation Options', 'pods' );
670
+ return $tabs;
671
+ }
672
+
673
+ /**
674
+ * The i18n options
675
+ *
676
+ * @todo Remove if not used in final version
677
+ *
678
+ * @since 0.1
679
+ * @param array $options
680
+ * @param array $pod
681
+ * @return array
682
+ */
683
+ public function pod_options( $options, $pod ) {
684
+
685
+ //if ( $pod['type'] === '' )
686
+ /*$options[ 'pods-i18n' ] = array(
687
+ 'enabled_languages' => array(
688
+ 'label' => __( 'Enable/Disable languages for this Pod', 'pods' ),
689
+ 'help' => __( 'This overwrites the defaults set in the component admin.', 'pods' ),
690
+ 'group' => array(),
691
+ ),
692
+ );
693
+
694
+ foreach ( $this->languages as $locale => $lang_data ) {
695
+ $options['pods-i18n']['enabled_languages']['group']['enable_i18n'][ $locale ] = array(
696
+ 'label' => $locale . ' (' . $this->create_lang_label( $lang_data ) . ')',
697
+ 'default' => 1,
698
+ 'type' => 'boolean',
699
+ );
700
+ }*/
701
+
702
+ return $options;
703
+
704
+ }
705
+
706
+ /**
707
+ * Add the i18n metabox.
708
+ *
709
+ * @since 0.1
710
+ */
711
+ public function admin_meta_box() {
712
+ add_meta_box(
713
+ 'pods_i18n', // ID
714
+ __( 'Translation options', 'pods' ), // Label
715
+ array( $this, 'meta_box' ), // Callback
716
+ '_pods_pod', // Screen
717
+ 'side', // Context (side)
718
+ 'default' // Priority
719
+ );
720
+ }
721
+
722
+ /**
723
+ * The i18n metabox.
724
+ *
725
+ * @todo Store enabled languages serialized instead of separate inputs
726
+ *
727
+ * @since 0.1
728
+ */
729
+ public function meta_box() {
730
+
731
+ $pod = $this->cur_pod;
732
+
733
+ if ( ! empty( $this->languages ) ) {
734
+ ?>
735
+ <p><?php _e( 'Enable/Disable languages for this Pod', 'pods' ); ?></p>
736
+ <p><small class="description"><?php _e( 'This overwrites the defaults set in the component admin.', 'pods' ); ?></small></p>
737
+ <div class="pods-field-enable-disable-language">
738
+ <?php
739
+ foreach ( $this->languages as $locale => $lang_data ) {
740
+
741
+ if ( ! isset( $pod['options']['enable_i18n'][ $locale ] ) ) {
742
+ // Enabled by default
743
+ $pod['options']['enable_i18n'][ $locale ] = 1;
744
+ }
745
+ ?>
746
+ <div class="pods-field-option pods-enable-disable-language" data-locale="<?php echo esc_attr( $locale ) ?>">
747
+ <?php
748
+ echo PodsForm::field( 'enable_i18n[' . $locale . ']', $pod['options']['enable_i18n'][ $locale ], 'boolean', array(
749
+ 'boolean_yes_label' => '<code>' . $locale . '</code> ' . $this->create_lang_label( $lang_data ),
750
+ 'boolean_no_label' => '',
751
+ ) );
752
+ ?>
753
+ </div>
754
+ <?php
755
+ }
756
+ ?>
757
+ </div>
758
+ <hr>
759
+ <p><button id="toggle_i18n" class="button-secondary"><?php _e( 'Toggle translation visibility', 'pods' ); ?></button></p>
760
+ <?php
761
+ }
762
+ }
763
+
764
+ /**
765
+ * Adds translation inputs to fields
766
+ *
767
+ * @since 0.1
768
+ * @see PodsForm.php >> 'pods_form_ui_field_' . $type (filter)
769
+ * @param string $output The default output of the field
770
+ * @param string $name The field name
771
+ * @param string $value The field value
772
+ * @param array $options The field options
773
+ * @param array $pod The Pod
774
+ * @param int $id The field ID
775
+ * @return string
776
+ */
777
+ public function add_i18n_inputs( $output, $name, $value, $options, $pod, $id ) {
778
+
779
+ if ( ! empty( $pod ) || empty( $name ) || ! $this->is_translatable_field( $name ) ) {
780
+ return $output;
781
+ }
782
+
783
+
784
+ $pod = $this->cur_pod;
785
+ //print_r( $pod );
786
+ if ( empty( $pod ) ) {
787
+ // Setting the $pod var to a non-empty value is mandatory to prevent a loop
788
+ $pod = true;
789
+ }
790
+
791
+ $output .= '<br clear="both" />';
792
+ $output .= '<div class="pods-i18n-field">';
793
+ foreach ( $this->languages as $locale => $lang_data ) {
794
+
795
+ if ( ! $this->obj_is_language_enabled( $locale, (array) $pod ) ) {
796
+ continue;
797
+ }
798
+ // Our own shiny label with language information
799
+ $lang_code = '<code style="font-size: 1em;">' . $locale . '</code>';
800
+ /*$lang_label = $this->create_lang_label( $lang_data );
801
+ if ( ! empty( $lang_label ) ) {
802
+ $lang_label = $lang_code . ' ('. $lang_label .')';
803
+ } else {*/
804
+ $lang_label = $lang_code;
805
+ //}
806
+ $lang_label = '<small>' . $lang_label . '</small>';
807
+
808
+ $style = '';
809
+
810
+ // Add language data to name for normal strings and array formatted strings
811
+ if ( strpos( $name, ']' ) !== false ) {
812
+ // Hide the i18n options for fields by default if they are empty
813
+ $field_value = pods_v( $name, $pod );
814
+
815
+ if ( strpos( $name, 'field_data' ) !== false && empty( $field_value ) ) {
816
+ $style = ' style="display: none;"';
817
+ }
818
+
819
+ $field_name = rtrim( $name, ']' );
820
+ $field_name .= '_'.$locale.']';
821
+ } else {
822
+ $field_name = $name.'_'.$locale;
823
+ }
824
+
825
+ // Add the translation fields
826
+ $output .= '<div class="pods-i18n-input pods-i18n-input-' . $locale . '" data-locale="' . $locale . '" ' . $style . '>';
827
+ $output .= PodsForm::label( $field_name, $lang_label );
828
+ $output .= PodsForm::field( $field_name, pods_v( $field_name, $pod ), 'text', null, $pod );
829
+ $output .= '</div>';
830
+ }
831
+ $output .= '</div>';
832
+ return $output;
833
+ }
834
+
835
+ /**
836
+ * Check if a language is get to enabled for an object
837
+ *
838
+ * @since 0.1
839
+ * @param string $locale The locale to validate
840
+ * @param array $data Object data
841
+ * @return bool
842
+ */
843
+ public function obj_is_language_enabled( $locale, $data ) {
844
+ // If the locale isn't enabled in the global scope from the component it's always disabled
845
+ if ( ! array_key_exists( $locale, $this->languages ) ) {
846
+ return false;
847
+ }
848
+ $data = (array) $data;
849
+ $options = ( isset( $data['options'] ) ) ? $data['options'] : $data;
850
+ // If it doesn't exist in the object data then use the default (enabled)
851
+ if ( isset( $options['enable_i18n'][ $locale ] ) && false === (bool) $options['enable_i18n'][ $locale ] ) {
852
+ return false;
853
+ }
854
+ return true;
855
+ }
856
+
857
+ /**
858
+ * Create a label with the english and native name combined
859
+ *
860
+ * @since 0.1
861
+ * @param array $lang_data
862
+ * @return string
863
+ */
864
+ public function create_lang_label( $lang_data ) {
865
+
866
+ $english_name = '';
867
+ $native_name = '';
868
+
869
+ if ( isset( $lang_data['english_name'] ) ) {
870
+ $english_name = $lang_data['english_name'];
871
+ }
872
+ if ( isset( $lang_data['native_name'] ) ) {
873
+ $native_name = $lang_data['native_name'];
874
+ }
875
+
876
+ if ( ! empty( $native_name ) && ! empty( $english_name ) ) {
877
+ if ( $native_name == $english_name ) {
878
+ return $english_name;
879
+ } else {
880
+ return $english_name . ' / ' . $native_name;
881
+ }
882
+ } else {
883
+ if ( ! empty( $english_name ) ) {
884
+ return $english_name;
885
+ }
886
+ if ( ! empty( $native_name ) ) {
887
+ return $native_name;
888
+ }
889
+ }
890
+ return '';
891
+ }
892
+
893
+ public function get_translatable_fields() {
894
+ return apply_filters( 'pods_translatable_fields', $this->translatable_fields );
895
+ }
896
+
897
+ }
components/I18n/pods-admin-i18n.js ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ;( function ( $ ) {
2
+
3
+ /**
4
+ * Component admin page
5
+ */
6
+ PodsAdminI18n = {
7
+ init: function() {
8
+ if ( $('#pods_i18n_settings_save').length ) {
9
+ this.initSave();
10
+ }
11
+ },
12
+
13
+ initSave: function () {
14
+ $( document ).on( 'click', '#pods_i18n_settings_save #submit', function() {
15
+ $( '#_nonce_i18n' ).appendTo( '.pods-admin form#posts-filter' );
16
+
17
+ $( '.pods-admin form#posts-filter' ).prop( 'method', 'post' ).submit();
18
+ } );
19
+ }
20
+ };
21
+
22
+ if ( $('#pods_admin_i18n').length ) {
23
+ PodsAdminI18n.init();
24
+ }
25
+
26
+
27
+ /**
28
+ * Pod edit page
29
+ */
30
+ PodsEditI18n = {
31
+ i18nVisible: true,
32
+ selector: '.pods-i18n-input',
33
+ toggleSpeed: 100,
34
+
35
+ init: function() {
36
+ this.toggleI18nInputs();
37
+ this.dynamicAddRemoveInputs();
38
+ },
39
+
40
+ validateI18nVisibility: function() {
41
+ /**
42
+ * Check if we're on the fields tab
43
+ * If we're on a fields tab, check if the first i18n input is visible and change this object's visibility property
44
+ */
45
+ if ( $('#pods-manage-fields').is(':visible') && $('#pods-manage-fields .pods-manage-list .pods-manage-row-expanded').length ) {
46
+ var first = $('#pods-manage-fields .pods-manage-list .pods-manage-row-expanded' ).first().find( PodsEditI18n.selector ).first();
47
+ if ( first.is(':visible') ) {
48
+ PodsEditI18n.i18nVisible = true;
49
+ } else {
50
+ PodsEditI18n.i18nVisible = false;
51
+ }
52
+ }
53
+
54
+ },
55
+
56
+ toggleI18nInputs: function() {
57
+
58
+ // Toggle i18n inputs for pod options
59
+ // @todo Enable auto-toggle when opening a field
60
+ $(document).on( 'click', 'button#toggle_i18n', function(e) {
61
+ e.preventDefault();
62
+
63
+ PodsEditI18n.validateI18nVisibility();
64
+
65
+ if ( PodsEditI18n.i18nVisible ) {
66
+
67
+ PodsEditI18n.i18nVisible = false;
68
+ $( PodsEditI18n.selector ).each( function() {
69
+ $( this ).slideUp( PodsEditI18n.toggleSpeed, function() {
70
+ // Fallback for hidden fields
71
+ $( this ).css('display', 'none');
72
+ } );
73
+ } );
74
+
75
+ } else {
76
+
77
+ PodsEditI18n.i18nVisible = true;
78
+ $( PodsEditI18n.selector ).each( function() {
79
+ $( this ).slideDown( PodsEditI18n.toggleSpeed, function() {
80
+ // Fallback for hidden fields
81
+ $( this ).css('display', 'block');
82
+ } );
83
+ } );
84
+
85
+ }
86
+ return false;
87
+ });
88
+ },
89
+
90
+ dynamicAddRemoveInputs: function() {
91
+
92
+ $(document).on( 'change', '#pods_i18n .pods-enable-disable-language input', function(e) {
93
+
94
+ PodsEditI18n.validateI18nVisibility();
95
+
96
+ var locale = $(this).parents('.pods-enable-disable-language').attr('data-locale');
97
+
98
+ if ( $(this).is(':checked') ) {
99
+
100
+ // Get the index for this locale
101
+ var index = 0;
102
+ $('#pods_i18n .pods-enable-disable-language input:checked').each( function() {
103
+ if ( $( this ).parents('.pods-enable-disable-language').attr( 'data-locale' ) == locale ) {
104
+ return false;
105
+ }
106
+ index++;
107
+ });
108
+
109
+ $('.pods-i18n-field').each( function() {
110
+ if ( $('.pods-i18n-input-' + locale, this).length ) {
111
+ $('.pods-i18n-input-' + locale, this).slideDown( PodsEditI18n.toggleSpeed, function() {
112
+ $('input', this).removeAttr('disabled');
113
+ });
114
+ } else {
115
+ var name = $(this).parent().children('input').first().attr('name');
116
+ // Place the new input on the right index
117
+ if ( $( '.pods-i18n-input:visible', this ).eq(index).length ) {
118
+ $( '.pods-i18n-input:visible', this ).eq(index).before( PodsEditI18n.i18nInputTemplate( name, locale ) );
119
+ } else {
120
+ $( this ).append( PodsEditI18n.i18nInputTemplate( name, locale ) );
121
+ }
122
+ if ( PodsEditI18n.i18nVisible ) {
123
+ $('.pods-i18n-input-' + locale, this).slideDown( PodsEditI18n.toggleSpeed );
124
+ }
125
+ }
126
+ });
127
+
128
+ } else {
129
+ $('.pods-i18n-input-' + locale + ' input').each( function() {
130
+ $(this).parent().slideUp( PodsEditI18n.toggleSpeed, function() {
131
+ $('input', this).attr('disabled', 'disabled');
132
+ });
133
+ });
134
+ }
135
+
136
+ });
137
+
138
+ },
139
+
140
+ i18nInputTemplate: function( name, locale ) {
141
+
142
+ var locale_clean = locale.toLowerCase().replace('_', '-');
143
+ var name_clean = name.toLowerCase().replace('_', '-');
144
+
145
+ html = '<div class="pods-i18n-input pods-i18n-input-'+locale+'" data-locale="'+locale+'" style="display: none;">';
146
+ html += '<label class="pods-form-ui-label" for="pods-form-ui-label-'+locale_clean+'"><small><code style="font-size: 1em;">'+locale+'</code></small></label>';
147
+ html += '<input name="'+name+'_'+locale+'" data-name-clean="'+name_clean+'-'+locale_clean+'" id="pods-form-ui-label-'+locale_clean+'" class="pods-form-ui-field pods-form-ui-field-type-text pods-form-ui-field-name-'+name_clean+'-'+locale_clean+'" type="text" value="" tabindex="2" maxlength="255">';
148
+ html += '</div>';
149
+ return html;
150
+ }
151
+
152
+ };
153
+
154
+ if ( $('#post-body').length ) {
155
+ PodsEditI18n.init();
156
+ }
157
+
158
+ } )( jQuery );
components/Migrate-Packages/ui/wizard.php CHANGED
@@ -91,7 +91,7 @@
91
  <div class="inside pods-manage-field pods-dependency">
92
  <div class="pods-field-option">
93
  <?php
94
- echo PodsForm::field( 'import_package', pods_var_raw( 'import_package', 'post' ), 'paragraph', array( 'attributes' => array( 'style' => 'width: 94%; max-width: 94%; height: 300px;' ) ) );
95
  ?>
96
  </div>
97
  </div>
91
  <div class="inside pods-manage-field pods-dependency">
92
  <div class="pods-field-option">
93
  <?php
94
+ echo PodsForm::field( 'import_package', pods_var_raw( 'import_package', 'post' ), 'paragraph', array( 'attributes' => array( 'style' => 'width: 100%; max-width: 100%; height: 300px;' ) ) );
95
  ?>
96
  </div>
97
  </div>
components/Pages.php CHANGED
@@ -100,7 +100,7 @@ class Pods_Pages extends PodsComponent {
100
  else {
101
  add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 );
102
 
103
- add_action( 'dbx_post_advanced', array( $this, 'edit_page_form' ), 10 );
104
 
105
  add_action( 'pods_meta_groups', array( $this, 'add_meta_boxes' ) );
106
  add_filter( 'get_post_metadata', array( $this, 'get_meta' ), 10, 4 );
@@ -225,7 +225,7 @@ class Pods_Pages extends PodsComponent {
225
  * @since 2.0
226
  */
227
  public function admin_assets () {
228
- wp_enqueue_style( 'pods-admin' );
229
  }
230
 
231
  /**
@@ -581,7 +581,7 @@ class Pods_Pages extends PodsComponent {
581
  'post_content' => $meta_value
582
  );
583
 
584
- remove_filter( current_filter(), array( $this, __FUNCTION__ ), 10 );
585
 
586
  $revisions = false;
587
 
100
  else {
101
  add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 );
102
 
103
+ add_action( 'dbx_post_advanced', array( $this, 'edit_page_form' ) );
104
 
105
  add_action( 'pods_meta_groups', array( $this, 'add_meta_boxes' ) );
106
  add_filter( 'get_post_metadata', array( $this, 'get_meta' ), 10, 4 );
225
  * @since 2.0
226
  */
227
  public function admin_assets () {
228
+ wp_enqueue_style( 'pods-styles' );
229
  }
230
 
231
  /**
581
  'post_content' => $meta_value
582
  );
583
 
584
+ remove_filter( current_filter(), array( $this, __FUNCTION__ ) );
585
 
586
  $revisions = false;
587
 
components/Roles/Roles.php CHANGED
@@ -183,9 +183,9 @@ class Pods_Roles extends PodsComponent {
183
  return $obj->error( sprintf( __( 'You cannot remove the <strong>%s</strong> role, you must set a new default role for the site first.', 'pods' ), $obj->data[ $id ][ 'name' ] ) );
184
  }
185
 
186
- $wp_user_search = new WP_User_Search( '', '', $id );
187
 
188
- $users = $wp_user_search->get_results();
189
 
190
  if ( !empty( $users ) && is_array( $users ) ) {
191
  foreach ( $users as $user ) {
183
  return $obj->error( sprintf( __( 'You cannot remove the <strong>%s</strong> role, you must set a new default role for the site first.', 'pods' ), $obj->data[ $id ][ 'name' ] ) );
184
  }
185
 
186
+ $wp_user_query = new WP_User_Query( array( 'role' => $id ) );
187
 
188
+ $users = $wp_user_query->get_results();
189
 
190
  if ( !empty( $users ) && is_array( $users ) ) {
191
  foreach ( $users as $user ) {
components/Roles/ui/edit.php CHANGED
@@ -1,191 +1,194 @@
1
  <div class="wrap pods-admin">
2
- <script>
3
- var PODS_URL = '<?php echo esc_js( PODS_URL ); ?>';
4
- </script>
5
- <div id="icon-pods" class="icon32"><br /></div>
6
-
7
- <form action="" method="post" class="pods-submittable pods-form">
8
- <div class="pods-submittable-fields">
9
- <?php echo PodsForm::field( 'action', 'pods_admin_components', 'hidden' ); ?>
10
- <?php echo PodsForm::field( 'component', $component, 'hidden' ); ?>
11
- <?php echo PodsForm::field( 'method', $method, 'hidden' ); ?>
12
- <?php echo PodsForm::field( 'id', $id, 'hidden' ); ?>
13
- <?php echo PodsForm::field( '_wpnonce', wp_create_nonce( 'pods-component-' . $component . '-' . $method ), 'hidden' ); ?>
14
-
15
- <h2 class="italicized"><?php _e( 'Roles &amp; Capabilities: Edit Role', 'pods' ); ?></h2>
16
-
17
- <?php
18
- if ( isset( $_GET[ 'do' ] ) ) {
19
- $action = __( 'saved', 'pods' );
20
-
21
- if ( 'create' == pods_var( 'do', 'get', 'save' ) )
22
- $action = __( 'created', 'pods' );
23
-
24
- $message = sprintf( __( '<strong>Success!</strong> %s %s successfully.', 'pods' ), $obj->item, $action );
25
-
26
- echo $obj->message( $message );
27
- }
28
- ?>
29
-
30
- <p><?php _e( 'Choose below which Capabilities you would like this existing user role to have.', 'pods' ); ?></p>
31
-
32
- <div id="poststuff" class="metabox-holder has-right-sidebar"> <!-- class "has-right-sidebar" preps for a sidebar... always present? -->
33
-
34
- <div id="side-info-column" class="inner-sidebar">
35
- <div id="side-sortables" class="meta-box-sortables ui-sortable">
36
- <!-- BEGIN PUBLISH DIV -->
37
- <div id="submitdiv" class="postbox">
38
- <div class="handlediv" title="Click to toggle"><br /></div>
39
- <h3 class="hndle"><span><?php _e( 'Manage', 'pods' ); ?></span></h3>
40
-
41
- <div class="inside">
42
- <div class="submitbox" id="submitpost">
43
- <div id="minor-publishing">
44
- <div id="major-publishing-actions">
45
- <div id="publishing-action">
46
- <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
47
- <input type="submit" name="publish" id="publish" class="button-primary" value="<?php _e( 'Save', 'pods' ); ?>" accesskey="p" />
48
- </div>
49
- <!-- /#publishing-action -->
50
-
51
- <div class="clear"></div>
52
- </div>
53
- <!-- /#major-publishing-actions -->
54
- </div>
55
- <!-- /#minor-publishing -->
56
- </div>
57
- <!-- /#submitpost -->
58
- </div>
59
- <!-- /.inside -->
60
- </div>
61
- <!-- /#submitdiv --><!-- END PUBLISH DIV --><!-- TODO: minor column fields -->
62
- </div>
63
- <!-- /#side-sortables -->
64
- </div>
65
- <!-- /#side-info-column -->
66
-
67
- <div id="post-body">
68
- <div id="post-body-content">
69
- <div id="normal-sortables" class="meta-box-sortables ui-sortable">
70
- <div id="pods-meta-box" class="postbox" style="">
71
- <div class="handlediv" title="Click to toggle"><br /></div>
72
- <h3 class="hndle">
73
- <span>
74
- <?php _e( 'Assign the Capabilities for', 'pods' ); ?>
75
- <strong><?php echo $role_label; ?></strong>
76
- </span>
77
- </h3>
78
-
79
- <div class="inside pods-manage-field pods-dependency">
80
- <div class="pods-field-option-group">
81
- <p>
82
- <a href="#toggle" class="button" id="toggle-all"><?php _e( 'Toggle All Capabilities on / off', 'pods' ); ?></a>
83
- </p>
84
-
85
- <div class="pods-pick-values pods-pick-checkbox pods-zebra">
86
- <ul>
87
- <?php
88
- $zebra = false;
89
-
90
- foreach ( $capabilities as $capability ) {
91
- $checked = false;
92
-
93
- if ( true === (boolean) pods_var( $capability, $role_capabilities, false ) )
94
- $checked = true;
95
-
96
- $class = ( $zebra ? 'even' : 'odd' );
97
-
98
- $zebra = ( !$zebra );
99
- ?>
100
- <li class="pods-zebra-<?php echo esc_attr( $class ); ?>" data-capability="<?php echo esc_attr( $capability ); ?>">
101
- <?php echo PodsForm::field( 'capabilities[' . $capability . ']', pods_var_raw( 'capabilities[' . $capability . ']', 'post', $checked ), 'boolean', array( 'boolean_yes_label' => $capability ) ); ?>
102
- </li>
103
- <?php
104
- }
105
- ?>
106
- </ul>
107
- </div>
108
- </div>
109
-
110
- <div class="pods-field-option-group">
111
- <p class="pods-field-option-group-label">
112
- <?php
113
- echo PodsForm::label( 'custom_capabilities[0]', __( 'Custom Capabilities', 'pods' ), __( 'These capabilities will automatically be created and assigned to this role', 'pods' ) );
114
- ?>
115
- </p>
116
-
117
- <div class="pods-pick-values pods-pick-checkbox">
118
- <ul id="custom-capabilities">
119
- <li class="pods-repeater hidden">
120
- <?php echo PodsForm::field( 'custom_capabilities[--1]', '', 'text' ); ?>
121
- </li>
122
- <li>
123
- <?php echo PodsForm::field( 'custom_capabilities[0]', '', 'text' ); ?>
124
- </li>
125
- </ul>
126
-
127
- <p><a href="#add-capability" id="add-capability" class="button">Add Another Custom Capability</a></p>
128
- </div>
129
- </div>
130
- </div>
131
- <!-- /.inside -->
132
- </div>
133
- <!-- /#pods-meta-box -->
134
- </div>
135
- <!-- /#normal-sortables -->
136
-
137
- <!--<div id="advanced-sortables" class="meta-box-sortables ui-sortable">
138
- </div>
139
- /#advanced-sortables -->
140
-
141
- </div>
142
- <!-- /#post-body-content -->
143
-
144
- <br class="clear" />
145
- </div>
146
- <!-- /#post-body -->
147
-
148
- <br class="clear" />
149
- </div>
150
- <!-- /#poststuff -->
151
- </div>
152
- </form>
153
- <!-- /#pods-record -->
 
 
 
154
  </div>
155
 
156
  <script type="text/javascript">
157
- var pods_admin_submit_callback = function ( id ) {
158
- id = parseInt( id );
159
- document.location = 'admin.php?page=pods-component-<?php echo esc_js( $component ); ?>&action=edit&id=<?php echo esc_js( $id ); ?>&do=save';
160
- }
161
 
162
- jQuery( function ( $ ) {
163
- $( document ).Pods( 'validate' );
164
- $( document ).Pods( 'submit' );
165
- $( document ).Pods( 'wizard' );
166
- $( document ).Pods( 'dependency' );
167
- $( document ).Pods( 'advanced' );
168
- $( document ).Pods( 'confirm' );
169
- $( document ).Pods( 'sluggable' );
170
 
171
- var toggle_all = true;
172
 
173
- $( '#toggle-all' ).on( 'click', function ( e ) {
174
- e.preventDefault();
175
 
176
- $( '.pods-field.pods-boolean input[type="checkbox"]' ).prop( 'checked', toggle_all );
177
 
178
- toggle_all = ( !toggle_all );
179
- } );
180
 
181
- $( '#add-capability' ).on( 'click', function ( e ) {
182
- e.preventDefault();
183
 
184
- var new_id = $( 'ul#custom-capabilities li' ).length;
185
- var html = $( 'ul#custom-capabilities li.pods-repeater' ).html().replace( /\-\-1/g, new_id );
186
 
187
- $( 'ul#custom-capabilities' ).append( '<li id="capability-' + new_id + '">' + html + '</li>' );
188
- $( 'li#capability-' + new_id + ' input' ).focus();
189
- } );
190
- } );
191
  </script>
1
  <div class="wrap pods-admin">
2
+ <script>
3
+ var PODS_URL = '<?php echo esc_js( PODS_URL ); ?>';
4
+ </script>
5
+ <div id="icon-pods" class="icon32"><br /></div>
6
+
7
+ <form action="" method="post" class="pods-submittable pods-form">
8
+ <div class="pods-submittable-fields">
9
+ <?php echo PodsForm::field( 'action', 'pods_admin_components', 'hidden' ); ?>
10
+ <?php echo PodsForm::field( 'component', $component, 'hidden' ); ?>
11
+ <?php echo PodsForm::field( 'method', $method, 'hidden' ); ?>
12
+ <?php echo PodsForm::field( 'id', $id, 'hidden' ); ?>
13
+ <?php echo PodsForm::field( '_wpnonce', wp_create_nonce( 'pods-component-' . $component . '-' . $method ), 'hidden' ); ?>
14
+
15
+ <h2 class="italicized"><?php _e( 'Roles &amp; Capabilities: Edit Role', 'pods' ); ?></h2>
16
+
17
+ <?php
18
+ if ( isset( $_GET[ 'do' ] ) ) {
19
+ $action = __( 'saved', 'pods' );
20
+
21
+ if ( 'create' == pods_var( 'do', 'get', 'save' ) )
22
+ $action = __( 'created', 'pods' );
23
+
24
+ $message = sprintf( __( '<strong>Success!</strong> %s %s successfully.', 'pods' ), $obj->item, $action );
25
+
26
+ echo $obj->message( $message );
27
+ }
28
+ ?>
29
+
30
+ <p><?php _e( 'Choose below which Capabilities you would like this existing user role to have.', 'pods' ); ?></p>
31
+
32
+ <div id="poststuff">
33
+ <div id="post-body" class="metabox-holder columns-2">
34
+
35
+ <div id="postbox-container-1" class="postbox-container">
36
+ <div id="side-sortables" class="meta-box-sortables ui-sortable">
37
+ <!-- BEGIN PUBLISH DIV -->
38
+ <div id="submitdiv" class="postbox">
39
+ <div class="handlediv" title="Click to toggle"><br /></div>
40
+ <h3 class="hndle"><span><?php _e( 'Manage', 'pods' ); ?></span></h3>
41
+
42
+ <div class="inside">
43
+ <div class="submitbox" id="submitpost">
44
+ <div id="minor-publishing">
45
+ <div id="major-publishing-actions">
46
+ <div id="publishing-action">
47
+ <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
48
+ <input type="submit" name="publish" id="publish" class="button-primary" value="<?php _e( 'Save', 'pods' ); ?>" accesskey="p" />
49
+ </div>
50
+ <!-- /#publishing-action -->
51
+
52
+ <div class="clear"></div>
53
+ </div>
54
+ <!-- /#major-publishing-actions -->
55
+ </div>
56
+ <!-- /#minor-publishing -->
57
+ </div>
58
+ <!-- /#submitpost -->
59
+ </div>
60
+ <!-- /.inside -->
61
+ </div>
62
+ <!-- /#submitdiv --><!-- END PUBLISH DIV --><!-- TODO: minor column fields -->
63
+ </div>
64
+ <!-- /#side-sortables -->
65
+ </div>
66
+ <!-- /#side-info-column -->
67
+
68
+ <div id="postbox-container-2" class="postbox-container">
69
+ <div id="post-body-content">
70
+ <div id="normal-sortables" class="meta-box-sortables ui-sortable">
71
+ <div id="pods-meta-box" class="postbox" style="">
72
+ <div class="handlediv" title="Click to toggle"><br /></div>
73
+ <h3 class="hndle">
74
+ <span>
75
+ <?php _e( 'Assign the Capabilities for', 'pods' ); ?>
76
+ <strong><?php echo $role_label; ?></strong>
77
+ </span>
78
+ </h3>
79
+
80
+ <div class="inside pods-manage-field pods-dependency">
81
+ <div class="pods-field-option-group">
82
+ <p>
83
+ <a href="#toggle" class="button" id="toggle-all"><?php _e( 'Toggle All Capabilities on / off', 'pods' ); ?></a>
84
+ </p>
85
+
86
+ <div class="pods-pick-values pods-pick-checkbox pods-zebra">
87
+ <ul>
88
+ <?php
89
+ $zebra = false;
90
+
91
+ foreach ( $capabilities as $capability ) {
92
+ $checked = false;
93
+
94
+ if ( true === (boolean) pods_var( $capability, $role_capabilities, false ) )
95
+ $checked = true;
96
+
97
+ $class = ( $zebra ? 'even' : 'odd' );
98
+
99
+ $zebra = ( !$zebra );
100
+ ?>
101
+ <li class="pods-zebra-<?php echo esc_attr( $class ); ?>" data-capability="<?php echo esc_attr( $capability ); ?>">
102
+ <?php echo PodsForm::field( 'capabilities[' . $capability . ']', pods_var_raw( 'capabilities[' . $capability . ']', 'post', $checked ), 'boolean', array( 'boolean_yes_label' => $capability ) ); ?>
103
+ </li>
104
+ <?php
105
+ }
106
+ ?>
107
+ </ul>
108
+ </div>
109
+ </div>
110
+
111
+ <div class="pods-field-option-group">
112
+ <p class="pods-field-option-group-label">
113
+ <?php
114
+ echo PodsForm::label( 'custom_capabilities[0]', __( 'Custom Capabilities', 'pods' ), __( 'These capabilities will automatically be created and assigned to this role', 'pods' ) );
115
+ ?>
116
+ </p>
117
+
118
+ <div class="pods-pick-values pods-pick-checkbox">
119
+ <ul id="custom-capabilities">
120
+ <li class="pods-repeater hidden">
121
+ <?php echo PodsForm::field( 'custom_capabilities[--1]', '', 'text' ); ?>
122
+ </li>
123
+ <li>
124
+ <?php echo PodsForm::field( 'custom_capabilities[0]', '', 'text' ); ?>
125
+ </li>
126
+ </ul>
127
+
128
+ <p><a href="#add-capability" id="add-capability" class="button">Add Another Custom Capability</a></p>
129
+ </div>
130
+ </div>
131
+ </div>
132
+ <!-- /.inside -->
133
+ </div>
134
+ <!-- /#pods-meta-box -->
135
+ </div>
136
+ <!-- /#normal-sortables -->
137
+
138
+ <!--<div id="advanced-sortables" class="meta-box-sortables ui-sortable">
139
+ </div>
140
+ /#advanced-sortables -->
141
+
142
+ </div>
143
+ <!-- /#post-body-content -->
144
+
145
+ <br class="clear" />
146
+ </div>
147
+ <!-- /#post-body -->
148
+
149
+ <br class="clear" />
150
+
151
+ </div>
152
+ </div>
153
+ <!-- /#poststuff -->
154
+ </div>
155
+ </form>
156
+ <!-- /#pods-record -->
157
  </div>
158
 
159
  <script type="text/javascript">
160
+ var pods_admin_submit_callback = function ( id ) {
161
+ id = parseInt( id );
162
+ document.location = 'admin.php?page=pods-component-<?php echo esc_js( $component ); ?>&action=edit&id=<?php echo esc_js( $id ); ?>&do=save';
163
+ };
164
 
165
+ jQuery( function ( $ ) {
166
+ $( document ).Pods( 'validate' );
167
+ $( document ).Pods( 'submit' );
168
+ $( document ).Pods( 'wizard' );
169
+ $( document ).Pods( 'dependency' );
170
+ $( document ).Pods( 'advanced' );
171
+ $( document ).Pods( 'confirm' );
172
+ $( document ).Pods( 'sluggable' );
173
 
174
+ var toggle_all = true;
175
 
176
+ $( '#toggle-all' ).on( 'click', function ( e ) {
177
+ e.preventDefault();
178
 
179
+ $( '.pods-field.pods-boolean input[type="checkbox"]' ).prop( 'checked', toggle_all );
180
 
181
+ toggle_all = ( !toggle_all );
182
+ } );
183
 
184
+ $( '#add-capability' ).on( 'click', function ( e ) {
185
+ e.preventDefault();
186
 
187
+ var new_id = $( 'ul#custom-capabilities li' ).length;
188
+ var html = $( 'ul#custom-capabilities li.pods-repeater' ).html().replace( /\-\-1/g, new_id );
189
 
190
+ $( 'ul#custom-capabilities' ).append( '<li id="capability-' + new_id + '">' + html + '</li>' );
191
+ $( 'li#capability-' + new_id + ' input' ).focus();
192
+ } );
193
+ } );
194
  </script>
components/Templates/Templates.php CHANGED
@@ -96,7 +96,7 @@ class Pods_Templates extends PodsComponent {
96
  if ( is_admin() ) {
97
  add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 );
98
 
99
- add_action( 'dbx_post_advanced', array( $this, 'edit_page_form' ), 10 );
100
 
101
  add_action( 'pods_meta_groups', array( $this, 'add_meta_boxes' ) );
102
 
@@ -196,7 +196,7 @@ class Pods_Templates extends PodsComponent {
196
  * @since 2.0
197
  */
198
  public function admin_assets () {
199
- wp_enqueue_style( 'pods-admin' );
200
  }
201
 
202
  /**
@@ -382,7 +382,7 @@ class Pods_Templates extends PodsComponent {
382
  'post_content' => $meta_value
383
  );
384
 
385
- remove_filter( current_filter(), array( $this, __FUNCTION__ ), 10 );
386
 
387
  $revisions = false;
388
 
96
  if ( is_admin() ) {
97
  add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 );
98
 
99
+ add_action( 'dbx_post_advanced', array( $this, 'edit_page_form' ) );
100
 
101
  add_action( 'pods_meta_groups', array( $this, 'add_meta_boxes' ) );
102
 
196
  * @since 2.0
197
  */
198
  public function admin_assets () {
199
+ wp_enqueue_style( 'pods-styles' );
200
  }
201
 
202
  /**
382
  'post_content' => $meta_value
383
  );
384
 
385
+ remove_filter( current_filter(), array( $this, __FUNCTION__ ) );
386
 
387
  $revisions = false;
388
 
components/Templates/includes/functions-view_template.php CHANGED
@@ -15,6 +15,17 @@ add_shortcode( "pod_after_template", "frontier_template_blocks" );
15
  add_shortcode( "pod_before_template", "frontier_template_blocks" );
16
  add_shortcode( "pod_if_field", "frontier_if_block" );
17
 
 
 
 
 
 
 
 
 
 
 
 
18
  /**
19
  * @param $content
20
  *
@@ -23,7 +34,7 @@ add_shortcode( "pod_if_field", "frontier_if_block" );
23
  */
24
  function frontier_do_shortcode( $content ) {
25
 
26
- $content = pods_do_shortcode( $content, array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) );
27
 
28
  return $content;
29
 
@@ -61,18 +72,21 @@ function frontier_decode_template( $code, $atts ) {
61
  * processes if condition within a template
62
  *
63
  *
64
- * @param array attributes from template
65
- * @param string encoded template to be decoded
66
  *
67
  * @return string
68
  * @since 2.4
69
  */
70
  function frontier_if_block( $atts, $code ) {
71
 
72
- $pod = pods( $atts[ 'pod' ], $atts[ 'id' ] );
73
- $code = explode( '[else]', frontier_decode_template( $code, $atts ) );
74
 
75
- $template = pods_do_shortcode( $pod->do_magic_tags( $code[ 0 ] ), array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) );
 
 
 
 
76
 
77
  // sysvals
78
  $system_values = array(
@@ -81,67 +95,81 @@ function frontier_if_block( $atts, $code ) {
81
 
82
  // field data
83
  $field_data = null;
 
84
 
85
- if ( in_array( $atts[ 'field' ], $system_values) ) {
86
- switch ( $atts[ 'field' ] ){
87
  case '_index':
88
  $field_data = $atts['index'];
 
89
  break;
90
  }
 
 
 
 
91
  }
92
- else{
93
 
94
- $field_data = $pod->field( $atts[ 'field' ] );
 
 
 
 
 
95
 
 
96
  }
97
 
98
- if ( ! empty( $field_data ) || isset( $atts[ 'value' ] ) ) {
 
 
99
  // theres a field - let go deeper
100
- if ( isset( $atts[ 'value' ] ) ) {
101
 
102
  // check if + or - are present
103
- if( substr( $atts[ 'value' ], 0, 1) === '+' ){
104
  // is greater
105
- $atts[ 'value' ] = (float) substr( $atts[ 'value' ], 1) + 1;
106
- if( (float) $field_data > $atts[ 'value' ] ){
 
107
  // is greater - set it the same to allow
108
- $atts[ 'value' ] = $field_data;
109
  }
110
-
111
- }elseif( substr( $atts[ 'value' ], 0, 1) === '-' ){
112
  // is smaller
113
- $atts[ 'value' ] = (float) substr( $atts[ 'value' ], 1) - 1;
114
- if( (float) $field_data < $atts[ 'value' ] ){
 
115
  // is greater - set it the same to allow
116
- $atts[ 'value' ] = $field_data;
117
  }
118
-
119
  }
120
 
121
- if ( $field_data == $atts[ 'value' ] ) {
122
- return pods_do_shortcode( $template, array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) );
 
123
  } else {
124
- if ( isset( $code[ 1 ] ) ) {
125
- $template = pods_do_shortcode( $pod->do_magic_tags( $code[ 1 ] ), array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) );
126
-
127
- return pods_do_shortcode( $template, array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) );
128
  } else {
129
- // Value did not match, nothing should be displayed
130
- return '';
131
  }
132
  }
 
 
 
133
  }
134
-
135
- return pods_do_shortcode( $template, array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) );
136
- }
137
- else {
138
- if ( isset( $code[ 1 ] ) ) {
139
- $template = pods_do_shortcode( $pod->do_magic_tags( $code[ 1 ] ), array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) );
140
-
141
- return $template;
142
- }
143
  }
144
 
 
145
  }
146
 
147
  /**
@@ -209,7 +237,7 @@ function frontier_template_once_blocks( $atts, $code ) {
209
  }
210
  $frontier_once_hashes[ ] = $blockhash;
211
 
212
- return pods_do_shortcode( frontier_decode_template( $code, $atts ), array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) );
213
  }
214
 
215
  /**
@@ -226,13 +254,15 @@ function frontier_do_subtemplate( $atts, $content ) {
226
 
227
  $out = null;
228
  $pod = pods( $atts[ 'pod' ], $atts[ 'id' ] );
 
229
 
230
- $params = array(
231
- 'name' => $atts[ 'field' ],
232
- );
233
-
234
- $entries = $pod->field( $atts[ 'field' ] );
235
  if ( ! empty( $entries ) ) {
 
 
 
 
 
236
 
237
  /**
238
  * Note on the change below for issue #3018:
@@ -245,71 +275,146 @@ function frontier_do_subtemplate( $atts, $content ) {
245
  * the $pod->fields array and is something to not expect to be there in
246
  * 3.0 as this was unintentional.
247
  */
248
- if ( ! empty( $pod->fields[ $atts[ 'field' ] ][ 'table_info' ] ) || 'taxonomy' == $pod->fields[ $atts[ 'field' ] ][ 'type' ] ) {
 
249
  foreach ( $entries as $key => $entry ) {
250
- $subpod = pods( $pod->fields[ $atts[ 'field' ] ][ 'pick_val' ] );
251
 
252
  $subatts = array(
253
  'id' => $entry[ $subpod->api->pod_data[ 'field_id' ] ],
254
- 'pod' => $pod->fields[ $atts[ 'field' ] ][ 'pick_val' ]
255
  );
256
 
257
  $template = frontier_decode_template( $content, array_merge( $atts, $subatts ) );
258
  $template = str_replace( '{_index}', $key, $template );
259
- $template = str_replace( '{@' . $atts[ 'field' ] . '.', '{@', $template );
260
 
261
  // Kludge to work with taxonomies, pending a better solution: see issue #3018
262
  $target_id = null;
263
  if ( isset( $entry[ 'ID' ] ) ) {
264
  $target_id = $entry[ 'ID' ];
 
 
 
265
  } elseif ( isset( $entry[ 'term_id' ] ) ) {
266
  $target_id = $entry[ 'term_id' ];
267
  }
268
 
269
  $out .= pods_shortcode( array(
270
- 'name' => $pod->fields[ $atts[ 'field' ] ][ 'pick_val' ],
271
  'slug' => $target_id,
272
  'index' => $key
273
  ), $template );
274
 
275
  }
276
- } elseif ( 'file' == $pod->fields[ $atts[ 'field' ] ][ 'type' ] && 'attachment' == $pod->fields[ $atts[ 'field' ] ][ 'options' ][ 'file_uploader' ] && 'multi' == $pod->fields[ $atts[ 'field' ] ][ 'options' ][ 'file_format_type' ] ) {
277
  $template = frontier_decode_template( $content, $atts );
278
  foreach ( $entries as $key => $entry ) {
279
  $content = str_replace( '{_index}', $key, $template );
280
  $content = str_replace( '{@_img', '{@image_attachment.' . $entry[ 'ID' ], $content );
281
  $content = str_replace( '{@_src', '{@image_attachment_url.' . $entry[ 'ID' ], $content );
282
- $content = str_replace( '{@' . $atts[ 'field' ] . '}', '{@image_attachment.' . $entry[ 'ID' ] . '}', $content );
283
-
284
- $out .= pods_do_shortcode( $pod->do_magic_tags( $content ), array(
285
- 'each',
286
- 'pod_sub_template',
287
- 'once',
288
- 'pod_once_template',
289
- 'before',
290
- 'pod_before_template',
291
- 'after',
292
- 'pod_after_template',
293
- 'if',
294
- 'pod_if_field'
295
- ) );
296
  }
297
 
 
 
 
 
 
 
 
 
 
 
298
  }
299
  }
300
 
301
- return pods_do_shortcode( $out, array(
302
- 'each',
303
- 'pod_sub_template',
304
- 'once',
305
- 'pod_once_template',
306
- 'before',
307
- 'pod_before_template',
308
- 'after',
309
- 'pod_after_template',
310
- 'if',
311
- 'pod_if_field'
312
- ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  }
314
 
315
  /**
@@ -428,7 +533,7 @@ function frontier_backtrack_template( $code, $aliases ) {
428
  $content = $used[ 5 ][ $key ];
429
  $atts = shortcode_parse_atts( $used[ 3 ][ $key ] );
430
  if ( !empty( $atts ) ) {
431
- if ( !empty( $atts[ 'field' ] ) ) {
432
  $content = str_replace( $atts[ 'field' ] . '.', '', $content );
433
  }
434
  preg_match_all( '/' . $regex . '/s', $content, $subused );
@@ -489,5 +594,5 @@ function frontier_end_template( $code, $base, $template, $pod ) {
489
  unset( $template_post_blocks[ 'after' ][ $pod->pod ] );
490
  }
491
 
492
- return pods_do_shortcode( $code, array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) );
493
  }
15
  add_shortcode( "pod_before_template", "frontier_template_blocks" );
16
  add_shortcode( "pod_if_field", "frontier_if_block" );
17
 
18
+ /**
19
+ * Return array of valid frontier type shortcode tags
20
+ *
21
+ * @return array
22
+ */
23
+ function frontier_get_shortcodes() {
24
+ $shortcodes = array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' );
25
+
26
+ return $shortcodes;
27
+ }
28
+
29
  /**
30
  * @param $content
31
  *
34
  */
35
  function frontier_do_shortcode( $content ) {
36
 
37
+ $content = pods_do_shortcode( $content, frontier_get_shortcodes() );
38
 
39
  return $content;
40
 
72
  * processes if condition within a template
73
  *
74
  *
75
+ * @param array $atts attributes from template
76
+ * @param string $code encoded template to be decoded
77
  *
78
  * @return string
79
  * @since 2.4
80
  */
81
  function frontier_if_block( $atts, $code ) {
82
 
83
+ $pod = pods( $atts['pod'], $atts['id'] );
 
84
 
85
+ if ( ! $pod || ! $pod->valid() || ! $pod->exists() ) {
86
+ return '';
87
+ }
88
+
89
+ $code = explode( '[else]', frontier_decode_template( $code, $atts ) );
90
 
91
  // sysvals
92
  $system_values = array(
95
 
96
  // field data
97
  $field_data = null;
98
+ $field_type = null;
99
 
100
+ if ( in_array( $atts['field'], $system_values, true ) ) {
101
+ switch ( $atts['field'] ) {
102
  case '_index':
103
  $field_data = $atts['index'];
104
+
105
  break;
106
  }
107
+ } else {
108
+ $field_data = $pod->field( $atts['field'] );
109
+
110
+ $field_type = $pod->fields( $atts['field'], 'type' );
111
  }
 
112
 
113
+ $is_empty = true;
114
+
115
+ if ( null !== $field_data ) {
116
+ if ( empty( $field_type ) ) {
117
+ $field_type = 'text';
118
+ }
119
 
120
+ $is_empty = PodsForm::field_method( $field_type, 'is_empty', $field_data );
121
  }
122
 
123
+ $output = '';
124
+
125
+ if ( ! $is_empty || isset( $atts['value'] ) ) {
126
  // theres a field - let go deeper
127
+ if ( isset( $atts['value'] ) ) {
128
 
129
  // check if + or - are present
130
+ if ( '+' === substr( $atts['value'], 0, 1 ) ) {
131
  // is greater
132
+ $atts['value'] = (float) substr( $atts['value'], 1 ) + 1;
133
+
134
+ if ( (float) $field_data > $atts['value'] ) {
135
  // is greater - set it the same to allow
136
+ $atts['value'] = $field_data;
137
  }
138
+ } elseif ( substr( $atts['value'], 0, 1 ) === '-' ) {
 
139
  // is smaller
140
+ $atts['value'] = (float) substr( $atts['value'], 1 ) - 1;
141
+
142
+ if ( (float) $field_data < $atts['value'] ) {
143
  // is greater - set it the same to allow
144
+ $atts['value'] = $field_data;
145
  }
 
146
  }
147
 
148
+ if ( (string) $field_data === (string) $atts['value'] ) {
149
+ // IF statement true, use [IF] content as template
150
+ $template = $pod->do_magic_tags( $code[0] );
151
  } else {
152
+ // No 'field' value (or value false), switch to [else] content
153
+ if ( isset( $code[1] ) ) {
154
+ // There is an [ELSE] tag
155
+ $template = $pod->do_magic_tags( $code[1] );
156
  } else {
157
+ // Value did not match (and no [ELSE]), nothing should be displayed
158
+ $template = '';
159
  }
160
  }
161
+ } else {
162
+ // Field exists and is not empty, use [IF] content
163
+ $template = $pod->do_magic_tags( $code[0] );
164
  }
165
+ } elseif ( isset( $code[1] ) ) {
166
+ // No value or field is empty and there is an [ELSE] tag. Use [ELSE]
167
+ $template = $pod->do_magic_tags( $code[1] );
168
+ } else {
169
+ $template = '';
 
 
 
 
170
  }
171
 
172
+ return do_shortcode( $template );
173
  }
174
 
175
  /**
237
  }
238
  $frontier_once_hashes[ ] = $blockhash;
239
 
240
+ return pods_do_shortcode( frontier_decode_template( $code, $atts ), frontier_get_shortcodes() );
241
  }
242
 
243
  /**
254
 
255
  $out = null;
256
  $pod = pods( $atts[ 'pod' ], $atts[ 'id' ] );
257
+ $field_name = $atts[ 'field' ];
258
 
259
+ $entries = $pod->field( $field_name );
 
 
 
 
260
  if ( ! empty( $entries ) ) {
261
+ $entries = (array) $entries;
262
+
263
+ $field = $pod->fields[ $field_name ];
264
+ // Object types that could be Pods
265
+ $object_types = array( 'post_type', 'pod' );
266
 
267
  /**
268
  * Note on the change below for issue #3018:
275
  * the $pod->fields array and is something to not expect to be there in
276
  * 3.0 as this was unintentional.
277
  */
278
+ if ( in_array( $field[ 'pick_object' ], $object_types ) || 'taxonomy' == $field[ 'type' ] ) {
279
+ // Match any Pod object or taxonomy
280
  foreach ( $entries as $key => $entry ) {
281
+ $subpod = pods( $field[ 'pick_val' ] );
282
 
283
  $subatts = array(
284
  'id' => $entry[ $subpod->api->pod_data[ 'field_id' ] ],
285
+ 'pod' => $field[ 'pick_val' ]
286
  );
287
 
288
  $template = frontier_decode_template( $content, array_merge( $atts, $subatts ) );
289
  $template = str_replace( '{_index}', $key, $template );
290
+ $template = str_replace( '{@' . $field_name . '.', '{@', $template );
291
 
292
  // Kludge to work with taxonomies, pending a better solution: see issue #3018
293
  $target_id = null;
294
  if ( isset( $entry[ 'ID' ] ) ) {
295
  $target_id = $entry[ 'ID' ];
296
+ } elseif ( isset( $entry[ 'id' ] ) ) {
297
+ // Advanced Content Types have lowercase 'id'
298
+ $target_id = $entry[ 'id' ];
299
  } elseif ( isset( $entry[ 'term_id' ] ) ) {
300
  $target_id = $entry[ 'term_id' ];
301
  }
302
 
303
  $out .= pods_shortcode( array(
304
+ 'name' => $field[ 'pick_val' ],
305
  'slug' => $target_id,
306
  'index' => $key
307
  ), $template );
308
 
309
  }
310
+ } elseif ( 'file' == $field[ 'type' ] && 'attachment' == $field[ 'options' ][ 'file_uploader' ] && 'multi' == $field[ 'options' ][ 'file_format_type' ] ) {
311
  $template = frontier_decode_template( $content, $atts );
312
  foreach ( $entries as $key => $entry ) {
313
  $content = str_replace( '{_index}', $key, $template );
314
  $content = str_replace( '{@_img', '{@image_attachment.' . $entry[ 'ID' ], $content );
315
  $content = str_replace( '{@_src', '{@image_attachment_url.' . $entry[ 'ID' ], $content );
316
+ $content = str_replace( '{@' . $field_name . '}', '{@image_attachment.' . $entry[ 'ID' ] . '}', $content );
317
+ $content = frontier_pseudo_magic_tags( $content, $entry, $pod, true );
318
+
319
+ $out .= pods_do_shortcode( $pod->do_magic_tags( $content ), frontier_get_shortcodes() );
 
 
 
 
 
 
 
 
 
 
320
  }
321
 
322
+ } else {
323
+ // Relationship to something other than a Pod (ie: user)
324
+ foreach ( $entries as $key => $entry ) {
325
+ $template = frontier_decode_template( $content, $atts );
326
+ $template = str_replace( '{_index}', $key, $template );
327
+ if ( !is_array( $entry ) ) {
328
+ $entry = array( '_key' => $key, '_value' => $entry );
329
+ }
330
+ $out .= pods_do_shortcode( frontier_pseudo_magic_tags( $template, $entry, $pod ), frontier_get_shortcodes() );
331
+ }
332
  }
333
  }
334
 
335
+ return pods_do_shortcode( $out, frontier_get_shortcodes() );
336
+ }
337
+
338
+ /**
339
+ *
340
+ * Search and replace like Pods magic tags but with an array of data instead of a Pod
341
+ *
342
+ * @param Pod $pod
343
+ * @param string $template
344
+ * @param array $data
345
+ * @param boolean $skip_unknown If true then values not in $data will not be touched
346
+ *
347
+ * @return string
348
+ * @since 2.7
349
+ */
350
+ function frontier_pseudo_magic_tags( $template, $data, $pod = null, $skip_unknown = false ) {
351
+
352
+ return preg_replace_callback( '/({@(.*?)})/m',
353
+ function( $tag ) use ( $pod, $data, $skip_unknown ) {
354
+
355
+ // This is essentially Pods->process_magic_tags() but with the Pods specific code ripped out
356
+ if ( is_array( $tag ) ) {
357
+ if ( !isset( $tag[ 2 ] ) && strlen( trim( $tag[ 2 ] ) ) < 1 ) {
358
+ return '';
359
+ }
360
+
361
+ $original_tag = $tag[0];
362
+ $tag = $tag[ 2 ];
363
+ }
364
+
365
+ $tag = trim( $tag, ' {@}' );
366
+ $tag = explode( ',', $tag );
367
+
368
+ if ( empty( $tag ) || !isset( $tag[ 0 ] ) || strlen( trim( $tag[ 0 ] ) ) < 1 ) {
369
+ return '';
370
+ }
371
+
372
+ foreach ( $tag as $k => $v ) {
373
+ $tag[ $k ] = trim( $v );
374
+ }
375
+
376
+ $field_name = $tag[ 0 ];
377
+
378
+ $helper_name = $before = $after = '';
379
+
380
+ if ( isset( $data[ $field_name ] ) ) {
381
+ $value = $data[ $field_name ];
382
+ if ( isset( $tag[ 1 ] ) && !empty( $tag[ 1 ] ) ) {
383
+ $helper_name = $tag[ 1 ];
384
+
385
+ if ( isset( $pod ) ) {
386
+ $value = $pod->helper( $helper_name, $value, $field_name );
387
+ }
388
+ }
389
+ } else {
390
+ if ( $skip_unknown ) {
391
+ return $original_tag;
392
+ }
393
+ $value = '';
394
+ }
395
+
396
+ if ( isset( $tag[ 2 ] ) && !empty( $tag[ 2 ] ) ) {
397
+ $before = $tag[ 2 ];
398
+ }
399
+
400
+ if ( isset( $tag[ 3 ] ) && !empty( $tag[ 3 ] ) ) {
401
+ $after = $tag[ 3 ];
402
+ }
403
+
404
+ $value = apply_filters( 'pods_do_magic_tags', $value, $field_name, $helper_name, $before, $after );
405
+
406
+ if ( is_array( $value ) ) {
407
+ $value = pods_serial_comma( $value, array( 'field' => $field_name, 'fields' => $this->fields ) );
408
+ }
409
+
410
+ if ( null !== $value && false !== $value ) {
411
+ return $before . $value . $after;
412
+ }
413
+
414
+ return '';
415
+ }
416
+ , $template
417
+ );
418
  }
419
 
420
  /**
533
  $content = $used[ 5 ][ $key ];
534
  $atts = shortcode_parse_atts( $used[ 3 ][ $key ] );
535
  if ( !empty( $atts ) ) {
536
+ if ( !empty( $atts[ 'field' ] ) && false !== strpos( $atts[ 'field' ], '.' ) ) {
537
  $content = str_replace( $atts[ 'field' ] . '.', '', $content );
538
  }
539
  preg_match_all( '/' . $regex . '/s', $content, $subused );
594
  unset( $template_post_blocks[ 'after' ][ $pod->pod ] );
595
  }
596
 
597
+ return pods_do_shortcode( $code, frontier_get_shortcodes() );
598
  }
includes/classes.php CHANGED
@@ -13,7 +13,7 @@
13
  *
14
  * @return bool|\Pods returns false if $strict, WP_DEBUG, PODS_STRICT or (PODS_DEPRECATED && PODS_STRICT_MODE) are true
15
  * @since 2.0
16
- * @link http://pods.io/docs/pods/
17
  */
18
  function pods ( $type = null, $id = null, $strict = null ) {
19
  require_once( PODS_DIR . 'classes/Pods.php' );
@@ -41,7 +41,7 @@ function pods ( $type = null, $id = null, $strict = null ) {
41
  * @return PodsUI
42
  *
43
  * @since 2.0
44
- * @link http://pods.io/docs/pods-ui/
45
  */
46
  function pods_ui ( $obj, $deprecated = false ) {
47
  require_once( PODS_DIR . 'classes/PodsUI.php' );
@@ -60,7 +60,7 @@ function pods_ui ( $obj, $deprecated = false ) {
60
  * @return PodsAPI
61
  *
62
  * @since 2.0
63
- * @link http://pods.io/docs/pods-api/
64
  */
65
  function pods_api ( $pod = null, $format = null ) {
66
  require_once( PODS_DIR . 'classes/PodsAPI.php' );
@@ -184,6 +184,15 @@ function pods_array ( $container ) {
184
  return new PodsArray( $container );
185
  }
186
 
 
 
 
 
 
 
 
 
 
187
  /**
188
  * Include a file that's child/parent theme-aware, and can be cached into object cache or transients
189
  *
@@ -198,7 +207,7 @@ function pods_array ( $container ) {
198
  * @return string|bool The view output
199
  *
200
  * @since 2.0
201
- * @link http://pods.io/docs/pods-view/
202
  */
203
  function pods_view ( $view, $data = null, $expires = false, $cache_mode = 'cache', $return = false ) {
204
  require_once( PODS_DIR . 'classes/PodsView.php' );
13
  *
14
  * @return bool|\Pods returns false if $strict, WP_DEBUG, PODS_STRICT or (PODS_DEPRECATED && PODS_STRICT_MODE) are true
15
  * @since 2.0
16
+ * @link https://pods.io/docs/pods/
17
  */
18
  function pods ( $type = null, $id = null, $strict = null ) {
19
  require_once( PODS_DIR . 'classes/Pods.php' );
41
  * @return PodsUI
42
  *
43
  * @since 2.0
44
+ * @link https://pods.io/docs/pods-ui/
45
  */
46
  function pods_ui ( $obj, $deprecated = false ) {
47
  require_once( PODS_DIR . 'classes/PodsUI.php' );
60
  * @return PodsAPI
61
  *
62
  * @since 2.0
63
+ * @link https://pods.io/docs/pods-api/
64
  */
65
  function pods_api ( $pod = null, $format = null ) {
66
  require_once( PODS_DIR . 'classes/PodsAPI.php' );
184
  return new PodsArray( $container );
185
  }
186
 
187
+ /**
188
+ * @since 2.7
189
+ */
190
+ function pods_i18n() {
191
+ require_once( PODS_DIR . 'classes/PodsI18n.php' );
192
+
193
+ return PodsI18n::get_instance();
194
+ }
195
+
196
  /**
197
  * Include a file that's child/parent theme-aware, and can be cached into object cache or transients
198
  *
207
  * @return string|bool The view output
208
  *
209
  * @since 2.0
210
+ * @link https://pods.io/docs/pods-view/
211
  */
212
  function pods_view ( $view, $data = null, $expires = false, $cache_mode = 'cache', $return = false ) {
213
  require_once( PODS_DIR . 'classes/PodsView.php' );
includes/data.php CHANGED
@@ -113,13 +113,7 @@ function pods_sanitize_like( $input ) {
113
  global $wpdb;
114
  $input = pods_unslash( $input );
115
 
116
- if ( pods_version_check( 'wp', '4.0' ) ) {
117
- $output = pods_sanitize( $wpdb->esc_like( $input ) );
118
- }
119
- else {
120
- // like_escape is deprecated in WordPress 4.0
121
- $output = pods_sanitize( like_escape( $input ) );
122
- }
123
  }
124
 
125
  return $output;
@@ -237,13 +231,7 @@ function pods_unsanitize( $input, $params = array() ) {
237
  }
238
  }
239
  else {
240
- // @todo Figure out what to do to unescape mysql_real_escape_string
241
- if ( pods_version_check( 'wp', '3.6' ) ) {
242
- $output = stripslashes( $input );
243
- }
244
- else {
245
- $output = stripslashes( $input );
246
- }
247
  }
248
 
249
  return $output;
@@ -287,13 +275,7 @@ function pods_unslash( $input ) {
287
  }
288
  }
289
  else {
290
- // @todo Figure out what to do to unescape mysql_real_escape_string
291
- if ( pods_version_check( 'wp', '3.6' ) ) {
292
- $output = wp_unslash( $input );
293
- }
294
- else {
295
- $output = stripslashes( $input );
296
- }
297
  }
298
 
299
  return $output;
@@ -990,12 +972,7 @@ function pods_v_set( $value, $var, $type = 'get' ) {
990
  elseif ( 'user' == $type && is_user_logged_in() ) {
991
  $user = get_userdata( get_current_user_id() );
992
 
993
- if ( !pods_version_check( 'wp', '3.5' ) ) {
994
- $user_data = get_object_vars( $user->data );
995
- }
996
- else {
997
- $user_data = $user->to_array();
998
- }
999
 
1000
  // Role
1001
  if ( 'role' == $var ) {
@@ -1734,7 +1711,7 @@ function pods_serial_comma ( $value, $field = null, $fields = null, $and = null,
1734
  return $original_value[ $params->field_index ];
1735
  elseif ( null !== $params->field_index && isset( $value[ $params->field_index ] ) )
1736
  return $value[ $params->field_index ];
1737
- elseif ( !isset( $value[ 0 ] ) )
1738
  $value = array( $value );
1739
 
1740
  foreach ( $value as $k => $v ) {
113
  global $wpdb;
114
  $input = pods_unslash( $input );
115
 
116
+ $output = pods_sanitize( $wpdb->esc_like( $input ) );
 
 
 
 
 
 
117
  }
118
 
119
  return $output;
231
  }
232
  }
233
  else {
234
+ $output = wp_unslash( $input );
 
 
 
 
 
 
235
  }
236
 
237
  return $output;
275
  }
276
  }
277
  else {
278
+ $output = wp_unslash( $input );
 
 
 
 
 
 
279
  }
280
 
281
  return $output;
972
  elseif ( 'user' == $type && is_user_logged_in() ) {
973
  $user = get_userdata( get_current_user_id() );
974
 
975
+ $user_data = $user->to_array();
 
 
 
 
 
976
 
977
  // Role
978
  if ( 'role' == $var ) {
1711
  return $original_value[ $params->field_index ];
1712
  elseif ( null !== $params->field_index && isset( $value[ $params->field_index ] ) )
1713
  return $value[ $params->field_index ];
1714
+ elseif ( !is_array( $value ) )
1715
  $value = array( $value );
1716
 
1717
  foreach ( $value as $k => $v ) {
includes/general.php CHANGED
@@ -462,13 +462,6 @@ function pods_help ( $text, $url = null ) {
462
  wp_enqueue_script( 'jquery-qtip2' );
463
  }
464
 
465
- if ( ! wp_style_is( 'jquery-qtip2', 'registered' ) ) {
466
- wp_register_style( 'jquery-qtip2', PODS_URL . 'ui/css/jquery.qtip.min.css', array(), '2.2' );
467
- }
468
- elseif ( ! wp_style_is( 'jquery-qtip2', 'queue' ) && ! wp_style_is( 'jquery-qtip2', 'to_do' ) && ! wp_style_is( 'jquery-qtip2', 'done' ) ) {
469
- wp_enqueue_style( 'jquery-qtip2' );
470
- }
471
-
472
  if ( ! wp_script_is( 'pods-qtip-init', 'registered' ) ) {
473
  wp_register_script( 'pods-qtip-init', PODS_URL . 'ui/js/qtip.js', array(
474
  'jquery',
@@ -817,7 +810,7 @@ function pods_shortcode ( $tags, $content = null ) {
817
  $params[ 'where' ] = $tags[ 'where' ];
818
 
819
  if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) {
820
- $params[ 'where' ] = pods_evaluate_tags( $params[ 'where' ] );
821
  }
822
  }
823
 
@@ -825,7 +818,7 @@ function pods_shortcode ( $tags, $content = null ) {
825
  $params[ 'having' ] = $tags[ 'having' ];
826
 
827
  if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) {
828
- $params[ 'having' ] = pods_evaluate_tags( $id );
829
  }
830
  }
831
 
@@ -1171,20 +1164,26 @@ function pods_function_or_file ( $function_or_file, $function_name = null, $file
1171
  *
1172
  * @param string $location The path to redirect to
1173
  * @param int $status Status code to use
 
1174
  *
1175
  * @return void
1176
  *
1177
  * @since 2.0
1178
  */
1179
- function pods_redirect ( $location, $status = 302 ) {
1180
  if ( !headers_sent() ) {
1181
  wp_redirect( $location, $status );
1182
- die();
 
 
1183
  }
1184
  else {
1185
- die( '<script type="text/javascript">'
1186
  . 'document.location = "' . str_replace( '&amp;', '&', esc_js( $location ) ) . '";'
1187
- . '</script>' );
 
 
 
1188
  }
1189
  }
1190
 
@@ -1310,7 +1309,7 @@ function pods_by_title ( $title, $output = OBJECT, $type = 'page', $status = nul
1310
  'publish'
1311
  );
1312
 
1313
- if ( current_user_can( 'read_private_' . $type . 's') )
1314
  $status[] = 'private';
1315
 
1316
  if ( current_user_can( 'edit_' . $type . 's' ) )
@@ -1804,7 +1803,7 @@ function pods_require_component ( $component ) {
1804
  * @return void
1805
  *
1806
  * @since 2.0
1807
- * @link http://pods.io/docs/pods-group-add/
1808
  */
1809
  function pods_group_add ( $pod, $label, $fields, $context = 'normal', $priority = 'default', $type = null ) {
1810
  if ( !is_array( $pod ) && null !== $type ) {
@@ -1883,186 +1882,192 @@ function pods_no_conflict_check ( $object_type = 'post' ) {
1883
  *
1884
  * @since 2.0
1885
  */
1886
- function pods_no_conflict_on ( $object_type = 'post', $object = null ) {
1887
 
1888
- if ( 'post_type' == $object_type )
1889
- $object_type = 'post';
1890
- elseif ( 'term' == $object_type )
1891
- $object_type = 'taxonomy';
 
1892
 
1893
- if ( ! class_exists( 'PodsInit' ) )
1894
- pods_init();
 
1895
 
1896
- if ( !empty( PodsInit::$no_conflict ) && isset( PodsInit::$no_conflict[ $object_type ] ) && !empty( PodsInit::$no_conflict[ $object_type ] ) )
1897
- return true;
 
1898
 
1899
- if ( !is_object( PodsInit::$meta ) )
1900
- return false;
 
1901
 
1902
- $no_conflict = array(
1903
- 'filter' => array()
1904
  );
1905
 
1906
- // Filters = Usually get/update/delete meta functions
1907
- // Actions = Usually insert/update/save/delete object functions
1908
- if ( 'post' == $object_type ) {
1909
  if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
1910
- // Handle *_post_meta
1911
  if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
1912
- $no_conflict[ 'filter' ] = array(
1913
  array( 'get_post_metadata', array( PodsInit::$meta, 'get_post_meta' ), 10, 4 ),
1914
  );
1915
  }
1916
 
1917
- if ( !pods_tableless() ) {
1918
- $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1919
  array( 'add_post_metadata', array( PodsInit::$meta, 'add_post_meta' ), 10, 5 ),
1920
  array( 'update_post_metadata', array( PodsInit::$meta, 'update_post_meta' ), 10, 5 ),
1921
- array( 'delete_post_metadata', array( PodsInit::$meta, 'delete_post_meta' ), 10, 5 )
1922
  ) );
1923
  }
1924
  }
1925
 
1926
- $no_conflict[ 'action' ] = array(
1927
- array( 'transition_post_status', array( PodsInit::$meta, 'save_post_detect_new' ), 10, 3 ),
1928
- array( 'save_post', array( PodsInit::$meta, 'save_post' ), 10, 2 )
1929
- );
1930
- }
1931
- elseif ( 'taxonomy' == $object_type ) {
1932
  if ( apply_filters( 'pods_meta_handler', true, 'term' ) ) {
1933
- // Handle *_term_meta
1934
  if ( apply_filters( 'pods_meta_handler_get', true, 'term' ) ) {
1935
- $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1936
- array( 'get_term_metadata', array( PodsInit::$meta, 'get_term_meta' ), 10, 4 )
1937
  ) );
1938
  }
1939
 
1940
- if ( !pods_tableless() ) {
1941
- $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1942
  array( 'add_term_metadata', array( PodsInit::$meta, 'add_term_meta' ), 10, 5 ),
1943
  array( 'update_term_metadata', array( PodsInit::$meta, 'update_term_meta' ), 10, 5 ),
1944
- array( 'delete_term_metadata', array( PodsInit::$meta, 'delete_term_meta' ), 10, 5 )
1945
  ) );
1946
  }
1947
 
1948
- $no_conflict[ 'action' ] = array(
1949
  array( 'edited_term', array( PodsInit::$meta, 'save_taxonomy' ), 10, 3 ),
1950
- array( 'create_term', array( PodsInit::$meta, 'save_taxonomy' ), 10, 3 )
 
1951
  );
1952
  }
1953
- }
1954
- elseif ( 'media' == $object_type ) {
1955
- $no_conflict[ 'filter' ] = array(
1956
- array( 'wp_update_attachment_metadata', array( PodsInit::$meta, 'save_media' ), 10, 2 )
 
1957
  );
1958
 
1959
  if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
1960
- // Handle *_post_meta
1961
  if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
1962
- $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1963
- array( 'get_post_metadata', array( PodsInit::$meta, 'get_post_meta' ), 10, 4 )
1964
  ) );
1965
  }
1966
 
1967
- if ( !pods_tableless() ) {
1968
- $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1969
  array( 'add_post_metadata', array( PodsInit::$meta, 'add_post_meta' ), 10, 5 ),
1970
  array( 'update_post_metadata', array( PodsInit::$meta, 'update_post_meta' ), 10, 5 ),
1971
- array( 'delete_post_metadata', array( PodsInit::$meta, 'delete_post_meta' ), 10, 5 )
1972
  ) );
1973
  }
1974
 
1975
- $no_conflict[ 'action' ] = array();
1976
  }
1977
- }
1978
- elseif ( 'user' == $object_type ) {
1979
  if ( apply_filters( 'pods_meta_handler', true, 'user' ) ) {
1980
- // Handle *_term_meta
1981
  if ( apply_filters( 'pods_meta_handler_get', true, 'user' ) ) {
1982
- $no_conflict[ 'filter' ] = array(
1983
  array( 'get_user_metadata', array( PodsInit::$meta, 'get_user_meta' ), 10, 4 ),
1984
  );
1985
  }
1986
 
1987
- if ( !pods_tableless() ) {
1988
- $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
1989
  array( 'add_user_metadata', array( PodsInit::$meta, 'add_user_meta' ), 10, 5 ),
1990
  array( 'update_user_metadata', array( PodsInit::$meta, 'update_user_meta' ), 10, 5 ),
1991
- array( 'delete_user_metadata', array( PodsInit::$meta, 'delete_user_meta' ), 10, 5 )
1992
  ) );
1993
  }
1994
  }
1995
 
1996
- $no_conflict[ 'action' ] = array(
1997
- array( 'user_register', array( PodsInit::$meta, 'save_user' ) ),
1998
- array( 'profile_update', array( PodsInit::$meta, 'save_user' ), 10, 2 )
1999
- );
2000
- }
2001
- elseif ( 'comment' == $object_type ) {
2002
  if ( apply_filters( 'pods_meta_handler', true, 'comment' ) ) {
2003
- // Handle *_term_meta
2004
  if ( apply_filters( 'pods_meta_handler_get', true, 'comment' ) ) {
2005
- $no_conflict[ 'filter' ] = array(
2006
  array( 'get_comment_metadata', array( PodsInit::$meta, 'get_comment_meta' ), 10, 4 ),
2007
  );
2008
  }
2009
 
2010
- if ( !pods_tableless() ) {
2011
- $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array(
2012
  array( 'add_comment_metadata', array( PodsInit::$meta, 'add_comment_meta' ), 10, 5 ),
2013
  array( 'update_comment_metadata', array( PodsInit::$meta, 'update_comment_meta' ), 10, 5 ),
2014
- array( 'delete_comment_metadata', array( PodsInit::$meta, 'delete_comment_meta' ), 10, 5 )
2015
  ) );
2016
  }
2017
  }
2018
 
2019
- $no_conflict[ 'action' ] = array(
2020
- array( 'pre_comment_approved', array( PodsInit::$meta, 'validate_comment' ), 10, 2 ),
2021
- array( 'comment_post', array( PodsInit::$meta, 'save_comment' ) ),
2022
- array( 'edit_comment', array( PodsInit::$meta, 'save_comment' ) )
2023
- );
2024
- }
2025
- elseif ( 'settings' == $object_type ) {
2026
- $no_conflict[ 'filter' ] = array();
2027
-
2028
- // @todo Better handle settings conflicts apart from each other
2029
- /*if ( empty( $object ) ) {
2030
- foreach ( PodsMeta::$settings as $setting_pod ) {
2031
- foreach ( $setting_pod[ 'fields' ] as $option ) {
2032
- $no_conflict[ 'filter' ][] = array( 'pre_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( PodsInit::$meta, 'get_option' ), 10, 1 );
2033
- $no_conflict[ 'filter' ][] = array( 'pre_update_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( PodsInit::$meta, 'update_option' ), 10, 2 );
2034
- }
2035
- }
2036
- }
2037
- elseif ( isset( PodsMeta::$settings[ $object ] ) ) {
2038
- foreach ( PodsMeta::$settings[ $object ][ 'fields' ] as $option ) {
2039
- $no_conflict[ 'filter' ][] = array( 'pre_option_' . $object . '_' . $option[ 'name' ], array( PodsInit::$meta, 'get_option' ), 10, 1 );
2040
- $no_conflict[ 'filter' ][] = array( 'pre_update_option_' . $object . '_' . $option[ 'name' ], array( PodsInit::$meta, 'update_option' ), 10, 2 );
2041
- }
2042
- }*/
2043
- }
2044
 
2045
- $conflicted = false;
2046
 
2047
- foreach ( $no_conflict as $action_filter => $conflicts ) {
2048
- foreach ( $conflicts as $k => $args ) {
2049
- if ( call_user_func_array( 'has_' . $action_filter, array_slice( $args, 0, 2 ) ) ) {
2050
- call_user_func_array( 'remove_' . $action_filter, array_slice( $args, 0, 3 ) );
2051
 
2052
- $conflicted = true;
2053
- }
2054
- else
2055
- unset( $no_conflict[ $action_filter ][ $k ] );
2056
- }
2057
- }
2058
 
2059
- if ( $conflicted ) {
2060
- PodsInit::$no_conflict[ $object_type ] = $no_conflict;
2061
 
2062
- return true;
2063
- }
 
 
2064
 
2065
- return false;
2066
  }
2067
 
2068
  /**
@@ -2149,3 +2154,58 @@ function pods_session_start() {
2149
  return true;
2150
 
2151
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462
  wp_enqueue_script( 'jquery-qtip2' );
463
  }
464
 
 
 
 
 
 
 
 
465
  if ( ! wp_script_is( 'pods-qtip-init', 'registered' ) ) {
466
  wp_register_script( 'pods-qtip-init', PODS_URL . 'ui/js/qtip.js', array(
467
  'jquery',
810
  $params[ 'where' ] = $tags[ 'where' ];
811
 
812
  if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) {
813
+ $params[ 'where' ] = pods_evaluate_tags( html_entity_decode( $params[ 'where' ] ) );
814
  }
815
  }
816
 
818
  $params[ 'having' ] = $tags[ 'having' ];
819
 
820
  if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) {
821
+ $params[ 'having' ] = pods_evaluate_tags( html_entity_decode( $params[ 'having' ] ) );
822
  }
823
  }
824
 
1164
  *
1165
  * @param string $location The path to redirect to
1166
  * @param int $status Status code to use
1167
+ * @param boolean $die If true, PHP code exection will stop
1168
  *
1169
  * @return void
1170
  *
1171
  * @since 2.0
1172
  */
1173
+ function pods_redirect ( $location, $status = 302, $die = true ) {
1174
  if ( !headers_sent() ) {
1175
  wp_redirect( $location, $status );
1176
+ if ( $die ) {
1177
+ die();
1178
+ }
1179
  }
1180
  else {
1181
+ echo '<script type="text/javascript">'
1182
  . 'document.location = "' . str_replace( '&amp;', '&', esc_js( $location ) ) . '";'
1183
+ . '</script>';
1184
+ if ( $die ) {
1185
+ die();
1186
+ }
1187
  }
1188
  }
1189
 
1309
  'publish'
1310
  );
1311
 
1312
+ if ( current_user_can( 'read_private_' . $type . 's' ) )
1313
  $status[] = 'private';
1314
 
1315
  if ( current_user_can( 'edit_' . $type . 's' ) )
1803
  * @return void
1804
  *
1805
  * @since 2.0
1806
+ * @link https://pods.io/docs/pods-group-add/
1807
  */
1808
  function pods_group_add ( $pod, $label, $fields, $context = 'normal', $priority = 'default', $type = null ) {
1809
  if ( !is_array( $pod ) && null !== $type ) {
1882
  *
1883
  * @since 2.0
1884
  */
1885
+ function pods_no_conflict_on( $object_type = 'post', $object = null ) {
1886
 
1887
+ if ( 'post_type' == $object_type ) {
1888
+ $object_type = 'post';
1889
+ } elseif ( 'term' == $object_type ) {
1890
+ $object_type = 'taxonomy';
1891
+ }
1892
 
1893
+ if ( ! class_exists( 'PodsInit' ) ) {
1894
+ pods_init();
1895
+ }
1896
 
1897
+ if ( ! empty( PodsInit::$no_conflict ) && isset( PodsInit::$no_conflict[ $object_type ] ) && ! empty( PodsInit::$no_conflict[ $object_type ] ) ) {
1898
+ return true;
1899
+ }
1900
 
1901
+ if ( ! is_object( PodsInit::$meta ) ) {
1902
+ return false;
1903
+ }
1904
 
1905
+ $no_conflict = array(
1906
+ 'filter' => array(),
1907
  );
1908
 
1909
+ // Filters = Usually get/update/delete meta functions
1910
+ // Actions = Usually insert/update/save/delete object functions
1911
+ if ( 'post' == $object_type ) {
1912
  if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
1913
+ // Handle *_post_meta
1914
  if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
1915
+ $no_conflict['filter'] = array(
1916
  array( 'get_post_metadata', array( PodsInit::$meta, 'get_post_meta' ), 10, 4 ),
1917
  );
1918
  }
1919
 
1920
+ if ( ! pods_tableless() ) {
1921
+ $no_conflict['filter'] = array_merge( $no_conflict['filter'], array(
1922
  array( 'add_post_metadata', array( PodsInit::$meta, 'add_post_meta' ), 10, 5 ),
1923
  array( 'update_post_metadata', array( PodsInit::$meta, 'update_post_meta' ), 10, 5 ),
1924
+ array( 'delete_post_metadata', array( PodsInit::$meta, 'delete_post_meta' ), 10, 5 ),
1925
  ) );
1926
  }
1927
  }
1928
 
1929
+ $no_conflict['action'] = array(
1930
+ array( 'transition_post_status', array( PodsInit::$meta, 'save_post_detect_new' ), 10, 3 ),
1931
+ array( 'save_post', array( PodsInit::$meta, 'save_post' ), 10, 2 ),
1932
+ array( 'wp_insert_post_data', array( PodsInit::$meta, 'save_post_track_changed_fields' ), 10, 2 ),
1933
+ );
1934
+ } elseif ( 'taxonomy' == $object_type ) {
1935
  if ( apply_filters( 'pods_meta_handler', true, 'term' ) ) {
1936
+ // Handle *_term_meta
1937
  if ( apply_filters( 'pods_meta_handler_get', true, 'term' ) ) {
1938
+ $no_conflict['filter'] = array_merge( $no_conflict['filter'], array(
1939
+ array( 'get_term_metadata', array( PodsInit::$meta, 'get_term_meta' ), 10, 4 ),
1940
  ) );
1941
  }
1942
 
1943
+ if ( ! pods_tableless() ) {
1944
+ $no_conflict['filter'] = array_merge( $no_conflict['filter'], array(
1945
  array( 'add_term_metadata', array( PodsInit::$meta, 'add_term_meta' ), 10, 5 ),
1946
  array( 'update_term_metadata', array( PodsInit::$meta, 'update_term_meta' ), 10, 5 ),
1947
+ array( 'delete_term_metadata', array( PodsInit::$meta, 'delete_term_meta' ), 10, 5 ),
1948
  ) );
1949
  }
1950
 
1951
+ $no_conflict['action'] = array(
1952
  array( 'edited_term', array( PodsInit::$meta, 'save_taxonomy' ), 10, 3 ),
1953
+ array( 'create_term', array( PodsInit::$meta, 'save_taxonomy' ), 10, 3 ),
1954
+ array( 'edit_terms', array( PodsInit::$meta, 'save_taxonomy_track_changed_fields' ), 10, 2 ),
1955
  );
1956
  }
1957
+ } elseif ( 'media' == $object_type ) {
1958
+ $no_conflict['filter'] = array(
1959
+ array( 'attachment_fields_to_save', array( PodsInit::$meta, 'save_media' ), 10, 2 ),
1960
+ array( 'wp_update_attachment_metadata', array( PodsInit::$meta, 'save_media' ), 10, 2 ),
1961
+ array( 'wp_insert_attachment_data', array( PodsInit::$meta, 'save_post_track_changed_fields' ), 10, 2 ),
1962
  );
1963
 
1964
  if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) {
1965
+ // Handle *_post_meta
1966
  if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) {
1967
+ $no_conflict['filter'] = array_merge( $no_conflict['filter'], array(
1968
+ array( 'get_post_metadata', array( PodsInit::$meta, 'get_post_meta' ), 10, 4 ),
1969
  ) );
1970
  }
1971
 
1972
+ if ( ! pods_tableless() ) {
1973
+ $no_conflict['filter'] = array_merge( $no_conflict['filter'], array(
1974
  array( 'add_post_metadata', array( PodsInit::$meta, 'add_post_meta' ), 10, 5 ),
1975
  array( 'update_post_metadata', array( PodsInit::$meta, 'update_post_meta' ), 10, 5 ),
1976
+ array( 'delete_post_metadata', array( PodsInit::$meta, 'delete_post_meta' ), 10, 5 ),
1977
  ) );
1978
  }
1979
 
1980
+ $no_conflict['action'] = array();
1981
  }
1982
+ } elseif ( 'user' == $object_type ) {
 
1983
  if ( apply_filters( 'pods_meta_handler', true, 'user' ) ) {
1984
+ // Handle *_term_meta
1985
  if ( apply_filters( 'pods_meta_handler_get', true, 'user' ) ) {
1986
+ $no_conflict['filter'] = array(
1987
  array( 'get_user_metadata', array( PodsInit::$meta, 'get_user_meta' ), 10, 4 ),
1988
  );
1989
  }
1990
 
1991
+ if ( ! pods_tableless() ) {
1992
+ $no_conflict['filter'] = array_merge( $no_conflict['filter'], array(
1993
  array( 'add_user_metadata', array( PodsInit::$meta, 'add_user_meta' ), 10, 5 ),
1994
  array( 'update_user_metadata', array( PodsInit::$meta, 'update_user_meta' ), 10, 5 ),
1995
+ array( 'delete_user_metadata', array( PodsInit::$meta, 'delete_user_meta' ), 10, 5 ),
1996
  ) );
1997
  }
1998
  }
1999
 
2000
+ $no_conflict['action'] = array(
2001
+ array( 'user_register', array( PodsInit::$meta, 'save_user' ) ),
2002
+ array( 'profile_update', array( PodsInit::$meta, 'save_user' ), 10, 2 ),
2003
+ array( 'pre_user_login', array( PodsInit::$meta, 'save_user_track_changed_fields' ) ),
2004
+ );
2005
+ } elseif ( 'comment' == $object_type ) {
2006
  if ( apply_filters( 'pods_meta_handler', true, 'comment' ) ) {
2007
+ // Handle *_term_meta
2008
  if ( apply_filters( 'pods_meta_handler_get', true, 'comment' ) ) {
2009
+ $no_conflict['filter'] = array(
2010
  array( 'get_comment_metadata', array( PodsInit::$meta, 'get_comment_meta' ), 10, 4 ),
2011
  );
2012
  }
2013
 
2014
+ if ( ! pods_tableless() ) {
2015
+ $no_conflict['filter'] = array_merge( $no_conflict['filter'], array(
2016
  array( 'add_comment_metadata', array( PodsInit::$meta, 'add_comment_meta' ), 10, 5 ),
2017
  array( 'update_comment_metadata', array( PodsInit::$meta, 'update_comment_meta' ), 10, 5 ),
2018
+ array( 'delete_comment_metadata', array( PodsInit::$meta, 'delete_comment_meta' ), 10, 5 ),
2019
  ) );
2020
  }
2021
  }
2022
 
2023
+ $no_conflict['action'] = array(
2024
+ array( 'pre_comment_approved', array( PodsInit::$meta, 'validate_comment' ), 10, 2 ),
2025
+ array( 'comment_post', array( PodsInit::$meta, 'save_comment' ) ),
2026
+ array( 'edit_comment', array( PodsInit::$meta, 'save_comment' ) ),
2027
+ array( 'wp_update_comment_data', array( PodsInit::$meta, 'save_comment_track_changed_fields' ), 10, 3 ),
2028
+ );
2029
+ } elseif ( 'settings' == $object_type ) {
2030
+ $no_conflict['filter'] = array();
2031
+
2032
+ // @todo Better handle settings conflicts apart from each other
2033
+ /*if ( empty( $object ) ) {
2034
+ foreach ( PodsMeta::$settings as $setting_pod ) {
2035
+ foreach ( $setting_pod[ 'fields' ] as $option ) {
2036
+ $no_conflict[ 'filter' ][] = array( 'pre_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( PodsInit::$meta, 'get_option' ), 10, 1 );
2037
+ $no_conflict[ 'filter' ][] = array( 'pre_update_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( PodsInit::$meta, 'update_option' ), 10, 2 );
2038
+ }
2039
+ }
2040
+ }
2041
+ elseif ( isset( PodsMeta::$settings[ $object ] ) ) {
2042
+ foreach ( PodsMeta::$settings[ $object ][ 'fields' ] as $option ) {
2043
+ $no_conflict[ 'filter' ][] = array( 'pre_option_' . $object . '_' . $option[ 'name' ], array( PodsInit::$meta, 'get_option' ), 10, 1 );
2044
+ $no_conflict[ 'filter' ][] = array( 'pre_update_option_' . $object . '_' . $option[ 'name' ], array( PodsInit::$meta, 'update_option' ), 10, 2 );
2045
+ }
2046
+ }*/
2047
+ }
2048
 
2049
+ $conflicted = false;
2050
 
2051
+ foreach ( $no_conflict as $action_filter => $conflicts ) {
2052
+ foreach ( $conflicts as $k => $args ) {
2053
+ if ( call_user_func_array( 'has_' . $action_filter, array_slice( $args, 0, 2 ) ) ) {
2054
+ call_user_func_array( 'remove_' . $action_filter, array_slice( $args, 0, 3 ) );
2055
 
2056
+ $conflicted = true;
2057
+ } else {
2058
+ unset( $no_conflict[ $action_filter ][ $k ] );
2059
+ }
2060
+ }
2061
+ }
2062
 
2063
+ if ( $conflicted ) {
2064
+ PodsInit::$no_conflict[ $object_type ] = $no_conflict;
2065
 
2066
+ return true;
2067
+ }
2068
+
2069
+ return false;
2070
 
 
2071
  }
2072
 
2073
  /**
2154
  return true;
2155
 
2156
  }
2157
+
2158
+ /**
2159
+ * @todo: replace string literal with a defined constant
2160
+ *
2161
+ * @return bool
2162
+ *
2163
+ * @since 2.7
2164
+ */
2165
+ function pods_is_modal_window() {
2166
+ $is_modal_window = false;
2167
+
2168
+ if ( ! empty( $_GET['pods_modal'] ) || ! empty( $_POST['pods_modal'] ) ) {
2169
+ $is_modal_window = true;
2170
+ }
2171
+
2172
+ return $is_modal_window;
2173
+ }
2174
+
2175
+ /**
2176
+ * Check if the pod object is valid and the pod exists.
2177
+ *
2178
+ * @param Pods|mixed $pod The pod object or something that isn't a pod object
2179
+ *
2180
+ * @return bool Whether the pod object is valid and exists
2181
+ *
2182
+ * @since 2.7
2183
+ */
2184
+ function pod_is_valid( $pod ) {
2185
+ $is_valid = false;
2186
+
2187
+ if ( $pod && is_a( $pod, 'Pods' ) && $pod->valid() ) {
2188
+ $is_valid = true;
2189
+ }
2190
+
2191
+ return $is_valid;
2192
+ }
2193
+
2194
+ /**
2195
+ * Check if the pod object has item(s).
2196
+ *
2197
+ * @param Pods|mixed $pod The pod object or something that isn't a pod object
2198
+ *
2199
+ * @return bool Whether the pod object has items
2200
+ *
2201
+ * @since 2.7
2202
+ */
2203
+ function pod_has_items( $pod ) {
2204
+ $has_items = false;
2205
+
2206
+ if ( pod_is_valid( $pod ) && ( $pod->id && $pod->exists() ) || ( ! empty( $pod->params ) && 0 < $pod->total() ) ) {
2207
+ $has_items = true;
2208
+ }
2209
+
2210
+ return $has_items;
2211
+ }
init.php CHANGED
@@ -1,16 +1,15 @@
1
  <?php
2
  /*
3
  Plugin Name: Pods - Custom Content Types and Fields
4
- Plugin URI: http://pods.io/
5
  Description: Pods is a framework for creating, managing, and deploying customized content types and fields
6
- Version: 2.6.11
7
  Author: Pods Framework Team
8
- Author URI: http://pods.io/about/
9
  Text Domain: pods
10
  GitHub Plugin URI: https://github.com/pods-framework/pods
11
- GitHub Branch: master
12
 
13
- Copyright 2009-2017 Pods Foundation, Inc (email : contact@podsfoundation.org)
14
 
15
  This program is free software; you can redistribute it and/or modify
16
  it under the terms of the GNU General Public License as published by
@@ -33,96 +32,104 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33
 
34
  // Prevent conflicts with Pods 1.x
35
  if ( defined( 'PODS_VERSION' ) || defined( 'PODS_DIR' ) ) {
36
- add_action( 'init', 'pods_deactivate_pods_1_x' );
37
- add_action( 'init', 'pods_deactivate_pods_ui' );
38
- }
39
- else {
40
- // Current version
41
- define( 'PODS_VERSION', '2.6.11' );
42
-
43
- // Version tracking between DB updates themselves
44
- define( 'PODS_DB_VERSION', '2.3.5' );
45
-
46
- if ( !defined( 'PODS_WP_VERSION_MINIMUM' ) ) {
47
- define( 'PODS_WP_VERSION_MINIMUM', '3.8' );
 
48
  }
49
 
50
- if ( !defined( 'PODS_PHP_VERSION_MINIMUM' ) ) {
51
- define( 'PODS_PHP_VERSION_MINIMUM', '5.2.4' );
 
 
52
  }
53
 
54
- if ( !defined( 'PODS_MYSQL_VERSION_MINIMUM' ) ) {
55
- define( 'PODS_MYSQL_VERSION_MINIMUM', '5.0' );
 
 
 
56
  }
57
 
58
- define( 'PODS_SLUG', plugin_basename( __FILE__ ) );
59
- define( 'PODS_URL', plugin_dir_url( __FILE__ ) );
60
- define( 'PODS_DIR', plugin_dir_path( __FILE__ ) );
61
-
62
- // Prevent conflicts with old Pods UI plugin
63
- if ( function_exists( 'pods_ui_manage' ) )
64
- add_action( 'init', 'pods_deactivate_pods_ui' );
65
- else {
66
- global $pods, $pods_init, $pods_form;
67
-
68
- require_once( PODS_DIR . 'includes/classes.php' );
69
- require_once( PODS_DIR . 'includes/data.php' );
70
- require_once( PODS_DIR . 'includes/general.php' );
71
-
72
- if ( !defined( 'PODS_MEDIA' ) || PODS_MEDIA )
73
- require_once( PODS_DIR . 'includes/media.php' );
74
-
75
- if ( !defined( 'SHORTINIT' ) || !SHORTINIT ) {
76
- if ( pods_allow_deprecated() ) {
77
- require_once( PODS_DIR . 'deprecated/deprecated.php' );
78
- }
79
-
80
- if ( false !== pods_compatibility_check() ) {
81
- $pods_form = pods_form();
82
-
83
- if ( ! is_network_admin() ) {
84
- $pods_init = pods_init();
85
- }
86
-
87
- }
88
-
89
- }
90
-
91
- }
92
  }
93
 
94
  /**
95
  * Deactivate Pods 1.x or other Pods plugins
96
  */
97
- function pods_deactivate_pods_1_x () {
98
- if ( defined( 'PODS_VERSION' ) && defined( 'PODS_DIR' ) && file_exists( untrailingslashit( PODS_DIR ) . '/init.php' ) ) {
99
- if ( !function_exists( 'deactivate_plugins' ) )
100
- include_once ABSPATH . 'wp-admin/includes/plugin.php';
101
-
102
- deactivate_plugins( realpath( untrailingslashit( PODS_DIR ) . '/init.php' ) );
103
-
104
- if ( !headers_sent() && ( !function_exists( 'pods_ui_manage' ) && !file_exists( WP_CONTENT_DIR . 'plugins/pods-ui/pods-ui.php' ) ) ) {
105
- wp_redirect( $_SERVER[ 'REQUEST_URI' ] );
106
- die();
107
- }
108
- }
 
 
 
109
  }
110
 
111
  /**
112
  * Deactivate Pods UI plugin
113
  */
114
- function pods_deactivate_pods_ui () {
115
- if ( function_exists( 'pods_ui_manage' ) && file_exists( WP_CONTENT_DIR . 'plugins/pods-ui/pods-ui.php' ) ) {
116
- if ( !function_exists( 'deactivate_plugins' ) )
117
- include_once ABSPATH . 'wp-admin/includes/plugin.php';
118
 
119
- deactivate_plugins( realpath( WP_CONTENT_DIR . 'plugins/pods-ui/pods-ui.php' ) );
 
 
 
120
 
121
- if ( !headers_sent() ) {
122
- wp_redirect( $_SERVER[ 'REQUEST_URI' ] );
123
- die();
124
- }
125
 
126
- }
 
 
 
 
127
 
128
  }
1
  <?php
2
  /*
3
  Plugin Name: Pods - Custom Content Types and Fields
4
+ Plugin URI: https://pods.io/
5
  Description: Pods is a framework for creating, managing, and deploying customized content types and fields
6
+ Version: 2.7.1
7
  Author: Pods Framework Team
8
+ Author URI: https://pods.io/about/
9
  Text Domain: pods
10
  GitHub Plugin URI: https://github.com/pods-framework/pods
 
11
 
12
+ Copyright 2009-2018 Pods Foundation, Inc (email : contact@podsfoundation.org)
13
 
14
  This program is free software; you can redistribute it and/or modify
15
  it under the terms of the GNU General Public License as published by
32
 
33
  // Prevent conflicts with Pods 1.x
34
  if ( defined( 'PODS_VERSION' ) || defined( 'PODS_DIR' ) ) {
35
+ add_action( 'init', 'pods_deactivate_pods_1_x' );
36
+ add_action( 'init', 'pods_deactivate_pods_ui' );
37
+ } else {
38
+ // Current version
39
+ define( 'PODS_VERSION', '2.7.1' );
40
+
41
+ // Version tracking between DB updates themselves
42
+ define( 'PODS_DB_VERSION', '2.3.5' );
43
+
44
+ // This should always be -2 versions behind the latest WP release
45
+ // To be updated each Major x.x Pods release
46
+ if ( ! defined( 'PODS_WP_VERSION_MINIMUM' ) ) {
47
+ define( 'PODS_WP_VERSION_MINIMUM', '4.5' );
48
  }
49
 
50
+ // This should match minimum WP requirements or usage (90%+)
51
+ // Found at: https://wordpress.org/about/stats/
52
+ if ( ! defined( 'PODS_PHP_VERSION_MINIMUM' ) ) {
53
+ define( 'PODS_PHP_VERSION_MINIMUM', '5.3' );
54
  }
55
 
56
+ // This should match minimum WP requirements or usage (90%+)
57
+ // Found at: https://wordpress.org/about/stats/
58
+ // Using 5.1 for now, many RedHat servers aren't EOL yet and they backport security releases
59
+ if ( ! defined( 'PODS_MYSQL_VERSION_MINIMUM' ) ) {
60
+ define( 'PODS_MYSQL_VERSION_MINIMUM', '5.1' );
61
  }
62
 
63
+ define( 'PODS_SLUG', plugin_basename( __FILE__ ) );
64
+ define( 'PODS_URL', plugin_dir_url( __FILE__ ) );
65
+ define( 'PODS_DIR', plugin_dir_path( __FILE__ ) );
66
+
67
+ // Prevent conflicts with old Pods UI plugin
68
+ if ( function_exists( 'pods_ui_manage' ) ) {
69
+ add_action( 'init', 'pods_deactivate_pods_ui' );
70
+ } else {
71
+ global $pods, $pods_init, $pods_form;
72
+
73
+ require_once( PODS_DIR . 'includes/classes.php' );
74
+ require_once( PODS_DIR . 'includes/data.php' );
75
+ require_once( PODS_DIR . 'includes/general.php' );
76
+
77
+ if ( ! defined( 'PODS_MEDIA' ) || PODS_MEDIA ) {
78
+ require_once( PODS_DIR . 'includes/media.php' );
79
+ }
80
+
81
+ if ( ! defined( 'SHORTINIT' ) || ! SHORTINIT ) {
82
+ if ( pods_allow_deprecated() ) {
83
+ require_once( PODS_DIR . 'deprecated/deprecated.php' );
84
+ }
85
+
86
+ if ( false !== pods_compatibility_check() ) {
87
+ $pods_form = pods_form();
88
+
89
+ if ( ! is_network_admin() ) {
90
+ $pods_init = pods_init();
91
+ }
92
+ }
93
+ }
94
+ }
 
 
95
  }
96
 
97
  /**
98
  * Deactivate Pods 1.x or other Pods plugins
99
  */
100
+ function pods_deactivate_pods_1_x() {
101
+
102
+ if ( defined( 'PODS_VERSION' ) && defined( 'PODS_DIR' ) && file_exists( untrailingslashit( PODS_DIR ) . '/init.php' ) ) {
103
+ if ( ! function_exists( 'deactivate_plugins' ) ) {
104
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
105
+ }
106
+
107
+ deactivate_plugins( realpath( untrailingslashit( PODS_DIR ) . '/init.php' ) );
108
+
109
+ if ( ! headers_sent() && ( ! function_exists( 'pods_ui_manage' ) && ! file_exists( WP_CONTENT_DIR . 'plugins/pods-ui/pods-ui.php' ) ) ) {
110
+ wp_redirect( $_SERVER['REQUEST_URI'] );
111
+ die();
112
+ }
113
+ }
114
+
115
  }
116
 
117
  /**
118
  * Deactivate Pods UI plugin
119
  */
120
+ function pods_deactivate_pods_ui() {
 
 
 
121
 
122
+ if ( function_exists( 'pods_ui_manage' ) && file_exists( WP_CONTENT_DIR . 'plugins/pods-ui/pods-ui.php' ) ) {
123
+ if ( ! function_exists( 'deactivate_plugins' ) ) {
124
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
125
+ }
126
 
127
+ deactivate_plugins( realpath( WP_CONTENT_DIR . 'plugins/pods-ui/pods-ui.php' ) );
 
 
 
128
 
129
+ if ( ! headers_sent() ) {
130
+ wp_redirect( $_SERVER['REQUEST_URI'] );
131
+ die();
132
+ }
133
+ }
134
 
135
  }
readme.txt CHANGED
@@ -1,10 +1,11 @@
1
  === Pods - Custom Content Types and Fields ===
2
- Contributors: sc0ttkclark, pglewis, jimtrue, Shelob9, jamesgol, clubduece, dan.stefan, Desertsnowman, curtismchale, logikal16, mikedamage, jchristopher, keraweb, ramoonus, pcfreak30
3
  Donate link: https://pods.io/friends-of-pods/
4
  Tags: pods, custom post types, custom taxonomies, content types, custom fields, cck, database, user fields, comment fields, media fields, relationships, drupal
5
- Requires at least: 3.8
6
- Tested up to: 4.8.2
7
- Stable tag: 2.6.11
 
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -17,7 +18,7 @@ Manage all your custom content needs in ONE location with the Pods Framework. Yo
17
  * Easily display your custom content, whether you want to use shortcodes, widgets, the code-free Pods Template approach, or use standard PHP in WordPress Theme templates and functions.
18
  * Create connections between any of your content to help organize it in logical and useful ways with relationship fields.
19
 
20
- Let Pods help you grow your development skills and manage content beyond the standard WordPress Posts & Pages. Check out [pods.io](http://pods.io/) for our User Guide, [Support Forum](https://pods.io/forums/), and our [Slack Chat](https://pods.io/chat/) to help you develop with Pods.
21
 
22
  = Introduction =
23
  [youtube http://www.youtube.com/watch?v=bYEE2i3nPOM]
@@ -122,8 +123,8 @@ We also do our best to integrate and play nicely with other projects:
122
  * [Timber](http://upstatement.com/timber/)
123
  * [Gravity Forms](http://www.gravityforms.com/) Using the [Pods Gravity Forms Add-on](https://wordpress.org/plugins/pods-gravity-forms/)
124
  * [Caldera Forms](http://calderaforms.com) Using the [Pods Caldera Forms Add-on](https://github.com/pods-framework/pods-caldera-forms)
 
125
  * Themes we've integrated with
126
- * [Beaver Builder](https://beaverbuilder.com) (BeaverBuilder)
127
  * [Builder](http://www.ithemes.com/) (iThemes)
128
  * [Genesis](http://www.studiopress.com/) (StudioPress)
129
 
@@ -179,6 +180,51 @@ We also have a dedicated [Slack Chat](https://pods.io/chat/) channel to help our
179
 
180
  == Changelog ==
181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  = 2.6.11 - September 20th 2017 =
183
  * Fixed: WordPress 4.8.2 introduced a breaking change that no longer correctly prepared number/currency queries. It did not introduce a vulnerability but only produced Database errors.
184
  * Stay tuned for Pods 2.7 which will be out soon -- [Download Pods 2.7 RC1](https://github.com/pods-framework/pods/archive/release/2.7.zip) and join our [Pods Slack channel #pods-beta](https://pods.io/chat/) to help us finish the final testing
@@ -520,7 +566,7 @@ We also have a dedicated [Slack Chat](https://pods.io/chat/) channel to help our
520
  * Fixed issue where user_url was created as a required field when extending users.
521
  * Add ability to use pods_group_add() in the ACT editor.
522
  * Security Update Reminder: As of Pods 2.4.2, we recommend all Pods 2.x installations be updated to the latest version, or replace your plugin files with the download of your version from http://wordpress.org/plugins/pods/developers/
523
- * If you need assistance in upgrading your Pods 2.x site to the latest version of Pods, please don't hesitate to contact us at http://pods.io/help/
524
 
525
  = 2.4.3 - June 23rd, 2014 =
526
  * Fixed: Pods Templates component now has better handling of the new shortcodes
@@ -609,3 +655,9 @@ We also have a dedicated [Slack Chat](https://pods.io/chat/) channel to help our
609
  Found a bug? Have a great feature idea? Get on GitHub and tell us about it and we'll get right on it: https://pods.io/submit/
610
 
611
  Our GitHub has the full list of all prior releases of Pods: https://github.com/pods-framework/pods/releases
 
 
 
 
 
 
1
  === Pods - Custom Content Types and Fields ===
2
+ Contributors: sc0ttkclark, pglewis, jimtrue, jamesgol, keraweb, ramoonus, nicdford, Shelob9, clubduece, dan.stefan, Desertsnowman, curtismchale, mgibbs189, mikedamage, jchristopher, pcfreak30
3
  Donate link: https://pods.io/friends-of-pods/
4
  Tags: pods, custom post types, custom taxonomies, content types, custom fields, cck, database, user fields, comment fields, media fields, relationships, drupal
5
+ Requires at least: 4.5
6
+ Requires PHP: 5.3
7
+ Tested up to: 4.9
8
+ Stable tag: 2.7.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
18
  * Easily display your custom content, whether you want to use shortcodes, widgets, the code-free Pods Template approach, or use standard PHP in WordPress Theme templates and functions.
19
  * Create connections between any of your content to help organize it in logical and useful ways with relationship fields.
20
 
21
+ Let Pods help you grow your development skills and manage content beyond the standard WordPress Posts & Pages. Check out [pods.io](https://pods.io/) for our User Guide, [Support Forum](https://pods.io/forums/), and our [Slack Chat](https://pods.io/chat/) to help you develop with Pods.
22
 
23
  = Introduction =
24
  [youtube http://www.youtube.com/watch?v=bYEE2i3nPOM]
123
  * [Timber](http://upstatement.com/timber/)
124
  * [Gravity Forms](http://www.gravityforms.com/) Using the [Pods Gravity Forms Add-on](https://wordpress.org/plugins/pods-gravity-forms/)
125
  * [Caldera Forms](http://calderaforms.com) Using the [Pods Caldera Forms Add-on](https://github.com/pods-framework/pods-caldera-forms)
126
+ * [Beaver Builder](https://www.wpbeaverbuilder.com/) and [Beaver Themer](https://www.wpbeaverbuilder.com/beaver-themer/) Using the [Pods Beaver Themer Add-On](https://wordpress.org/plugins/pods-beaver-builder-themer-add-on/)
127
  * Themes we've integrated with
 
128
  * [Builder](http://www.ithemes.com/) (iThemes)
129
  * [Genesis](http://www.studiopress.com/) (StudioPress)
130
 
180
 
181
  == Changelog ==
182
 
183
+ = 2.7.1 - December 8th 2017 =
184
+
185
+ * Fix table join logic for taxonomies when renaming meta fields #4613 @sc0ttkclark
186
+ * Fix Pods Form submit errors and 404s #4618 @pglewis
187
+ * Fix dashicons style conflicts with Pods Form #4626 @nicdford
188
+ * Roll-back minimum version requirement for MySQL from 5.5 to 5.1 #4634 @sc0ttkclark
189
+
190
+ = 2.7 - December 4th 2017 =
191
+
192
+ **New PHP & WP Minimum Version Requirements:**
193
+
194
+ * PHP Version Change Requirement 5.3+
195
+ * WP Version Change Required 4.5+
196
+
197
+ **Major Changes in 2.7 Release: Flexible Relationships:**
198
+
199
+ * New Relationship Field Format "List View": The power of the new flexible relationships is our new modal window that opens within the existing record for relationship fields. This is modeled after the Media Modal from WordPress and provides full functionality to Add New related records or edit existing records all from within the parent record of the relationship. This is provided through our new List View field format for relationship fields. To see a demo of this field in action [head on over to our YouTube](https://youtu.be/V8c067GAEcA)
200
+ * Add New with Flexible Relationships: The new flexible relationships will automatically enable Add New on all your existing relationships, but you can disable this from the Additional Options tab for each relationship field. You can switch field formats to the new List View from additional options tab as well.
201
+ * Dynamic Field Views: The relationship fields and file upload fields have been rewritten to take advantage of "Dynamic Field Views", driven by JavaScript. More technical details about the directions we went towards these field changes can be read about in our ["Pods 2.7: What We Did and Why We Did It"](https://pods.io/2017/12/05/pods-2-7-developer-notes/)
202
+
203
+ **Significant Improvements and Fixes:**
204
+
205
+ * Enhancements for Date, Time & Date/Time Fields to improve class inheritance, use WP Defaults and allow for custom options for saving and display @JoryHOgeveen
206
+ * Gallery & Tile View for Upload/Media Fields #3589 @JoryHogeveen
207
+ * IsEmpty for all Date/Time Fields, Number, Currency, etc. improvements for `[if field][/if]` for Templates @JoryHogeveen
208
+ * Major fixes for Pods Templates: Proper handling of shortcodes within Pods Templates and in if/each blocks. Proper handling of all image tags and user traversal @jamesgol
209
+ * Comment Traversal #4118 @sc0ttkclark
210
+ * Update Compatibility with Admin Columns 3.0+ #4570 @JoryHogeveen
211
+ * Filter Added for Select2 Overrides #4571 @sc0ttkclark
212
+ * Fix for Advanced Content Types and Relationships in `[each][/each]` tags correcting for lowercase id. #4585 @0xLBF
213
+
214
+ **Behind the Scenes Fixes and Improvements:**
215
+
216
+ * js unit tests #3640, #4049 @pglewis
217
+ * pods_ui_get_params hook #3785 @telwing
218
+ * table storage list fields #4420 @jamesgol
219
+ * Refactor CSS @nicdford
220
+ * Built with Node @pglewis
221
+ * Pods Templates added for Polylang Translation Compatibility @JoryHogeveen
222
+ * SelectWoo migration from Select2 to address version incompatibilities #4546 @pglewis
223
+
224
+ **Known Issues with this Release:**
225
+
226
+ * Relationships to Taxonomy have Flexible Relationships disabled as the input screen for Taxonomy was not able to be accessed in an iFrame. We’re working on this for a future release.
227
+
228
  = 2.6.11 - September 20th 2017 =
229
  * Fixed: WordPress 4.8.2 introduced a breaking change that no longer correctly prepared number/currency queries. It did not introduce a vulnerability but only produced Database errors.
230
  * Stay tuned for Pods 2.7 which will be out soon -- [Download Pods 2.7 RC1](https://github.com/pods-framework/pods/archive/release/2.7.zip) and join our [Pods Slack channel #pods-beta](https://pods.io/chat/) to help us finish the final testing
566
  * Fixed issue where user_url was created as a required field when extending users.
567
  * Add ability to use pods_group_add() in the ACT editor.
568
  * Security Update Reminder: As of Pods 2.4.2, we recommend all Pods 2.x installations be updated to the latest version, or replace your plugin files with the download of your version from http://wordpress.org/plugins/pods/developers/
569
+ * If you need assistance in upgrading your Pods 2.x site to the latest version of Pods, please don't hesitate to contact us at https://pods.io/help/
570
 
571
  = 2.4.3 - June 23rd, 2014 =
572
  * Fixed: Pods Templates component now has better handling of the new shortcodes
655
  Found a bug? Have a great feature idea? Get on GitHub and tell us about it and we'll get right on it: https://pods.io/submit/
656
 
657
  Our GitHub has the full list of all prior releases of Pods: https://github.com/pods-framework/pods/releases
658
+
659
+
660
+ == Upgrade Notice ==
661
+
662
+ = 2.7 =
663
+ This upgrade requires a minimum PHP version of 5.3+ and WordPress 4.5+.
ui/admin/components-admin.php CHANGED
@@ -21,24 +21,26 @@
21
  foreach ( $options as $field_name => $field_option ) {
22
  $field_option = PodsForm::field_setup( $field_option, null, $field_option[ 'type' ] );
23
 
24
- $depends = PodsForm::dependencies( $field_option );
 
 
25
 
26
- if ( ( !empty( $depends_on ) || !empty( $depends ) ) && $depends_on != $depends ) {
27
  if ( !empty( $depends_on ) ) {
28
  ?>
29
  </tbody>
30
  <?php
31
  }
32
 
33
- if ( !empty( $depends ) ) {
34
  ?>
35
- <tbody class="pods-field-option-container <?php echo esc_attr( $depends ); ?>">
36
  <?php
37
  }
38
  }
39
 
40
  if ( !is_array( $field_option[ 'group' ] ) ) {
41
- $value = pods_var_raw( $field_name, $settings, $field_option[ 'default' ] );
42
  ?>
43
  <tr valign="top" class="pods-field-option" id="pods-setting-<?php echo esc_attr( $field_name ); ?>">
44
  <th>
@@ -67,11 +69,13 @@
67
 
68
  $field_group_option[ 'boolean_yes_label' ] = $field_group_option[ 'label' ];
69
 
70
- $depends_option = PodsForm::dependencies( $field_group_option );
 
 
71
 
72
- $value = pods_var_raw( $field_group_name, $settings, $field_group_option[ 'default' ] );
73
  ?>
74
- <li class="<?php echo esc_attr( $depends_option ); ?>">
75
  <?php echo PodsForm::field( 'pods_setting_' . $field_group_name, $value, $field_group_option[ 'type' ], $field_group_option ); ?>
76
  </li>
77
  <?php
@@ -83,8 +87,8 @@
83
  <?php
84
  }
85
 
86
- if ( false !== $depends_on || !empty( $depends ) )
87
- $depends_on = $depends;
88
  }
89
 
90
  if ( !empty( $depends_on ) ) {
21
  foreach ( $options as $field_name => $field_option ) {
22
  $field_option = PodsForm::field_setup( $field_option, null, $field_option[ 'type' ] );
23
 
24
+ $dep_options = PodsForm::dependencies( $field_option );
25
+ $dep_classes = $dep_options[ 'classes' ];
26
+ $dep_data = $dep_options[ 'data' ];
27
 
28
+ if ( ( !empty( $depends_on ) || !empty( $dep_classes ) ) && $depends_on != $dep_classes ) {
29
  if ( !empty( $depends_on ) ) {
30
  ?>
31
  </tbody>
32
  <?php
33
  }
34
 
35
+ if ( !empty( $dep_classes ) ) {
36
  ?>
37
+ <tbody class="pods-field-option-container <?php echo esc_attr( $dep_classes ); ?>" <?php PodsForm::data( $dep_data ); ?>>
38
  <?php
39
  }
40
  }
41
 
42
  if ( !is_array( $field_option[ 'group' ] ) ) {
43
+ $value = pods_v( $field_name, $settings, $field_option[ 'default' ] );
44
  ?>
45
  <tr valign="top" class="pods-field-option" id="pods-setting-<?php echo esc_attr( $field_name ); ?>">
46
  <th>
69
 
70
  $field_group_option[ 'boolean_yes_label' ] = $field_group_option[ 'label' ];
71
 
72
+ $group_dep_options = PodsForm::dependencies( $field_group_option );
73
+ $group_dep_classes = $group_dep_options[ 'classes' ];
74
+ $group_dep_data = $group_dep_options[ 'data' ];
75
 
76
+ $value = pods_v( $field_group_name, $settings, $field_group_option[ 'default' ] );
77
  ?>
78
+ <li class="<?php echo esc_attr( $group_dep_classes ); ?>" <?php PodsForm::data( $group_dep_data ); ?>>
79
  <?php echo PodsForm::field( 'pods_setting_' . $field_group_name, $value, $field_group_option[ 'type' ], $field_group_option ); ?>
80
  </li>
81
  <?php
87
  <?php
88
  }
89
 
90
+ if ( false !== $depends_on || !empty( $dep_classes ) )
91
+ $depends_on = $dep_options;
92
  }
93
 
94
  if ( !empty( $depends_on ) ) {
ui/admin/field-option.php CHANGED
@@ -9,18 +9,20 @@ foreach ( $field_options as $field_name => $field_option ) {
9
 
10
  $field_option = (array) $field_option;
11
 
12
- $depends = PodsForm::dependencies( $field_option, ( !isset( $pods_tab_form ) ? 'field-data-' : '' ) );
 
 
13
 
14
- if ( ( !empty( $depends_on ) || !empty( $depends ) ) && $depends_on != $depends ) {
15
- if ( !empty( $depends_on ) ) {
16
  ?>
17
- </div>
18
- <?php
19
  }
20
- if ( !empty( $depends ) ) {
21
  ?>
22
- <div class="pods-field-option-container <?php echo esc_attr( $depends ); ?>">
23
- <?php
24
  }
25
  }
26
 
@@ -35,7 +37,7 @@ foreach ( $field_options as $field_name => $field_option ) {
35
  if ( isset( $field_option[ 'value' ] ) && 0 < strlen( $field_option[ 'value' ] ) )
36
  $value = $field_option[ 'value' ];
37
  else
38
- $value = pods_var_raw( $field_name, $field, $value );
39
 
40
  if ( in_array( $field_option[ 'type' ], PodsForm::file_field_types() ) ) {
41
  if ( is_array( $value ) && !isset( $value[ 'id' ] ) ) {
@@ -69,7 +71,9 @@ foreach ( $field_options as $field_name => $field_option ) {
69
 
70
  $field_group_option[ 'boolean_yes_label' ] = $field_group_option[ 'label' ];
71
 
72
- $depends_option = PodsForm::dependencies( $field_group_option, ( !isset( $pods_tab_form ) ? 'field-data-' : '' ) );
 
 
73
 
74
  $row_name = $field_group_name;
75
 
@@ -81,10 +85,10 @@ foreach ( $field_options as $field_name => $field_option ) {
81
  if ( isset( $field_group_option[ 'value' ] ) && 0 < strlen( $field_group_option[ 'value' ] ) )
82
  $value = $field_group_option[ 'value' ];
83
  else
84
- $value = pods_var_raw( $field_group_name, $field, $value );
85
 
86
  ?>
87
- <li class="<?php echo esc_attr( $depends_option ); ?>">
88
  <?php echo PodsForm::field( $row_name, $value, $field_group_option[ 'type' ], $field_group_option ); ?>
89
  </li>
90
  <?php
@@ -96,8 +100,8 @@ foreach ( $field_options as $field_name => $field_option ) {
96
  <?php
97
  }
98
 
99
- if ( false !== $depends_on || !empty( $depends ) )
100
- $depends_on = $depends;
101
  }
102
 
103
  if ( !empty( $depends_on ) ) {
9
 
10
  $field_option = (array) $field_option;
11
 
12
+ $dep_options = PodsForm::dependencies( $field_option, ( !isset( $pods_tab_form ) ? 'field-data-' : '' ) );
13
+ $dep_classes = $dep_options[ 'classes' ];
14
+ $dep_data = $dep_options[ 'data' ];
15
 
16
+ if ( ( ! empty( $depends_on ) || ! empty( $dep_classes ) ) && $depends_on != $dep_classes ) {
17
+ if ( ! empty( $depends_on ) ) {
18
  ?>
19
+ </div>
20
+ <?php
21
  }
22
+ if ( ! empty( $dep_classes ) ) {
23
  ?>
24
+ <div class="pods-field-option-container <?php echo esc_attr( $dep_classes ); ?>" <?php PodsForm::data( $dep_data ); ?>>
25
+ <?php
26
  }
27
  }
28
 
37
  if ( isset( $field_option[ 'value' ] ) && 0 < strlen( $field_option[ 'value' ] ) )
38
  $value = $field_option[ 'value' ];
39
  else
40
+ $value = pods_v( $field_name, $field, $value );
41
 
42
  if ( in_array( $field_option[ 'type' ], PodsForm::file_field_types() ) ) {
43
  if ( is_array( $value ) && !isset( $value[ 'id' ] ) ) {
71
 
72
  $field_group_option[ 'boolean_yes_label' ] = $field_group_option[ 'label' ];
73
 
74
+ $group_dep_options = PodsForm::dependencies( $field_group_option, ( !isset( $pods_tab_form ) ? 'field-data-' : '' ) );
75
+ $group_dep_classes = $group_dep_options[ 'classes' ];
76
+ $group_dep_data = $group_dep_options[ 'data' ];
77
 
78
  $row_name = $field_group_name;
79
 
85
  if ( isset( $field_group_option[ 'value' ] ) && 0 < strlen( $field_group_option[ 'value' ] ) )
86
  $value = $field_group_option[ 'value' ];
87
  else
88
+ $value = pods_v( $field_group_name, $field, $value );
89
 
90
  ?>
91
+ <li class="<?php echo esc_attr( $group_dep_classes ); ?>" <?php PodsForm::data( $group_dep_data ); ?>>
92
  <?php echo PodsForm::field( $row_name, $value, $field_group_option[ 'type' ], $field_group_option ); ?>
93
  </li>
94
  <?php
100
  <?php
101
  }
102
 
103
+ if ( false !== $depends_on || !empty( $dep_classes ) )
104
+ $depends_on = $dep_classes;
105
  }
106
 
107
  if ( !empty( $depends_on ) ) {
ui/admin/form-settings.php CHANGED
@@ -15,19 +15,19 @@ foreach ( $fields as $k => $field ) {
15
  if ( in_array( $field[ 'name' ], array( 'created', 'modified' ) ) )
16
  unset( $fields[ $k ] );
17
  elseif ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $fields, $pod, $pod->id() ) ) {
18
- if ( pods_var( 'hidden', $field[ 'options' ], false ) )
19
  $fields[ $k ][ 'type' ] = 'hidden';
20
  else
21
  unset( $fields[ $k ] );
22
  }
23
- elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_var( 'hidden', $field[ 'options' ], false ) )
24
  $fields[ $k ][ 'type' ] = 'hidden';
25
  }
26
 
27
  $submittable_fields = $fields;
28
 
29
  foreach ( $submittable_fields as $k => $field ) {
30
- if ( pods_var( 'readonly', $field, false ) )
31
  unset( $submittable_fields[ $k ] );
32
  }
33
 
@@ -109,18 +109,20 @@ $do = 'save';
109
  if ( 'hidden' == $field[ 'type' ] )
110
  continue;
111
 
112
- $depends = PodsForm::dependencies( $field );
 
 
113
 
114
- if ( ( !empty( $depends_on ) || !empty( $depends ) ) && $depends_on != $depends ) {
115
  if ( !empty( $depends_on ) ) {
116
  ?>
117
  </tbody>
118
  <?php
119
  }
120
 
121
- if ( !empty( $depends ) ) {
122
  ?>
123
- <tbody class="pods-field-option-container <?php echo esc_attr( $depends ); ?>">
124
  <?php
125
  }
126
  }
@@ -135,8 +137,8 @@ $do = 'save';
135
  </td>
136
  </tr>
137
  <?php
138
- if ( false !== $depends_on || !empty( $depends ) )
139
- $depends_on = $depends;
140
  }
141
 
142
  if ( !empty( $depends_on ) ) {
15
  if ( in_array( $field[ 'name' ], array( 'created', 'modified' ) ) )
16
  unset( $fields[ $k ] );
17
  elseif ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $fields, $pod, $pod->id() ) ) {
18
+ if ( pods_v_sanitized( 'hidden', $field[ 'options' ], false ) )
19
  $fields[ $k ][ 'type' ] = 'hidden';
20
  else
21
  unset( $fields[ $k ] );
22
  }
23
+ elseif ( !pods_has_permissions( $field[ 'options' ] ) && pods_v_sanitized( 'hidden', $field[ 'options' ], false ) )
24
  $fields[ $k ][ 'type' ] = 'hidden';
25
  }
26
 
27
  $submittable_fields = $fields;
28
 
29
  foreach ( $submittable_fields as $k => $field ) {
30
+ if ( pods_v_sanitized( 'readonly', $field, false ) )
31
  unset( $submittable_fields[ $k ] );
32
  }
33
 
109
  if ( 'hidden' == $field[ 'type' ] )
110
  continue;
111
 
112
+ $dep_options = PodsForm::dependencies( $field );
113
+ $dep_classes = $dep_options[ 'classes' ];
114
+ $dep_data = $dep_options[ 'data' ];
115
 
116
+ if ( ( !empty( $depends_on ) || !empty( $dep_classes ) ) && $depends_on != $dep_classes ) {
117
  if ( !empty( $depends_on ) ) {
118
  ?>
119
  </tbody>
120
  <?php
121
  }
122
 
123
+ if ( !empty( $dep_classes ) ) {
124
  ?>
125
+ <tbody class="pods-field-option-container <?php echo esc_attr( $dep_classes ); ?>" <?php PodsForm::data( $dep_data ); ?>>
126
  <?php
127
  }
128
  }
137
  </td>
138
  </tr>
139
  <?php
140
+ if ( false !== $depends_on || !empty( $dep_classes ) )
141
+ $depends_on = $dep_classes;
142
  }
143
 
144
  if ( !empty( $depends_on ) ) {
ui/admin/form.php CHANGED
@@ -12,6 +12,10 @@ else
12
 
13
  $groups = PodsInit::$meta->groups_get( $pod->pod_data[ 'type' ], $pod->pod_data[ 'name' ], $fields );
14
 
 
 
 
 
15
  $group_fields = array();
16
  $submittable_fields = array();
17
 
@@ -24,10 +28,10 @@ foreach ( $groups as $g => $group ) {
24
  continue;
25
  }
26
  elseif ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $group[ 'fields' ], $pod, $pod->id() ) ) {
27
- if ( pods_var( 'hidden', $field[ 'options' ], false ) ) {
28
  $group[ 'fields' ][ $k ][ 'type' ] = 'hidden';
29
  }
30
- elseif ( pods_var( 'read_only', $field[ 'options' ], false ) ) {
31
  $group[ 'fields' ][ $k ][ 'readonly' ] = true;
32
  }
33
  else {
@@ -37,15 +41,15 @@ foreach ( $groups as $g => $group ) {
37
  }
38
  }
39
  elseif ( !pods_has_permissions( $field[ 'options' ] ) ) {
40
- if ( pods_var( 'hidden', $field[ 'options' ], false ) ) {
41
  $group[ 'fields' ][ $k ][ 'type' ] = 'hidden';
42
  }
43
- elseif ( pods_var( 'read_only', $field[ 'options' ], false ) ) {
44
  $group[ 'fields' ][ $k ][ 'readonly' ] = true;
45
  }
46
  }
47
 
48
- if ( !pods_var( 'readonly', $field, false ) ) {
49
  $submittable_fields[ $field[ 'name' ]] = $group[ 'fields' ][ $k ];
50
  }
51
 
@@ -70,9 +74,9 @@ $nonce = wp_create_nonce( 'pods_form_' . $pod->pod . '_' . $uid . '_' . ( $dupli
70
  if ( isset( $_POST[ '_pods_nonce' ] ) ) {
71
  $action = __( 'saved', 'pods' );
72
 
73
- if ( 'create' == pods_var_raw( 'do', 'post', 'save' ) )
74
  $action = __( 'created', 'pods' );
75
- elseif ( 'duplicate' == pods_var_raw( 'do', 'get', 'save' ) )
76
  $action = __( 'duplicated', 'pods' );
77
 
78
  try {
@@ -81,7 +85,7 @@ if ( isset( $_POST[ '_pods_nonce' ] ) ) {
81
 
82
  $message = sprintf( __( '<strong>Success!</strong> %s %s successfully.', 'pods' ), $obj->item, $action );
83
 
84
- if ( 0 < strlen( pods_var( 'detail_url', $pod->pod_data[ 'options' ] ) ) )
85
  $message .= ' <a target="_blank" href="' . $pod->field( 'detail_url' ) . '">' . sprintf( __( 'View %s', 'pods' ), $obj->item ) . '</a>';
86
 
87
  $error = sprintf( __( '<strong>Error:</strong> %s %s successfully.', 'pods' ), $obj->item, $action );
@@ -98,14 +102,14 @@ if ( isset( $_POST[ '_pods_nonce' ] ) ) {
98
  elseif ( isset( $_GET[ 'do' ] ) ) {
99
  $action = __( 'saved', 'pods' );
100
 
101
- if ( 'create' == pods_var_raw( 'do', 'get', 'save' ) )
102
  $action = __( 'created', 'pods' );
103
- elseif ( 'duplicate' == pods_var_raw( 'do', 'get', 'save' ) )
104
  $action = __( 'duplicated', 'pods' );
105
 
106
  $message = sprintf( __( '<strong>Success!</strong> %s %s successfully.', 'pods' ), $obj->item, $action );
107
 
108
- if ( 0 < strlen( pods_var( 'detail_url', $pod->pod_data[ 'options' ] ) ) )
109
  $message .= ' <a target="_blank" href="' . $pod->field( 'detail_url' ) . '">' . sprintf( __( 'View %s', 'pods' ), $obj->item ) . '</a>';
110
 
111
  $error = sprintf( __( '<strong>Error:</strong> %s not %s.', 'pods' ), $obj->item, $action );
@@ -180,16 +184,16 @@ if ( 0 < $pod->id() ) {
180
  <!-- BEGIN PUBLISH DIV -->
181
  <div id="submitdiv" class="postbox">
182
  <div class="handlediv" title="Click to toggle"><br /></div>
183
- <h3 class="hndle"><span><?php _e( 'Manage', 'pods' ); ?></span></h3>
184
 
185
  <div class="inside">
186
  <div class="submitbox" id="submitpost">
187
  <?php
188
- if ( 0 < $pod->id() && ( isset( $pod->pod_data[ 'fields' ][ 'created' ] ) || isset( $pod->pod_data[ 'fields' ][ 'modified' ] ) || 0 < strlen( pods_var( 'detail_url', $pod->pod_data[ 'options' ] ) ) ) ) {
189
  ?>
190
  <div id="minor-publishing">
191
  <?php
192
- if ( 0 < strlen( pods_var( 'detail_url', $pod->pod_data[ 'options' ] ) ) ) {
193
  ?>
194
  <div id="minor-publishing-actions">
195
  <div id="preview-action">
@@ -257,7 +261,7 @@ if ( 0 < $pod->id() ) {
257
  ) );
258
  ?>
259
  <div id="delete-action">
260
- <a class="submitdelete deletion" href="<?php echo esc_url( $link ); ?>" onclick="return confirm('You are about to permanently delete this item\n Choose \'Cancel\' to stop, \'OK\' to delete.');"><?php _e( 'Delete', 'pods' ); ?></a>
261
  </div>
262
  <!-- /#delete-action -->
263
  <?php } ?>
@@ -305,12 +309,12 @@ if ( 0 < $pod->id() ) {
305
  </div>
306
  <!-- /#submitdiv --><!-- END PUBLISH DIV --><!-- TODO: minor column fields -->
307
  <?php
308
- if ( pods_var_raw( 'action' ) == 'edit' && !$duplicate && !in_array( 'navigate', (array) $obj->actions_disabled ) && !in_array( 'navigate', (array) $obj->actions_hidden ) ) {
309
  if ( !isset( $singular_label ) )
310
  $singular_label = ucwords( str_replace( '_', ' ', $pod->pod_data[ 'name' ] ) );
311
 
312
- $singular_label = pods_var_raw( 'label', $pod->pod_data[ 'options' ], $singular_label, null, true );
313
- $singular_label = pods_var_raw( 'label_singular', $pod->pod_data[ 'options' ], $singular_label, null, true );
314
 
315
  $pod->params = $obj->get_params( null, 'manage' );
316
 
@@ -424,7 +428,7 @@ if ( 0 < $pod->id() ) {
424
  $more = true;
425
  $extra = '';
426
 
427
- $max_length = (int) pods_var( 'maxlength', $field[ 'options' ], pods_var( $field[ 'type' ] . '_max_length', $field[ 'options' ], 0 ), null, true );
428
 
429
  if ( 0 < $max_length )
430
  $extra .= ' maxlength="' . esc_attr( $max_length ) . '"';
12
 
13
  $groups = PodsInit::$meta->groups_get( $pod->pod_data[ 'type' ], $pod->pod_data[ 'name' ], $fields );
14
 
15
+ $pod_options = $pod->pod_data[ 'options' ];
16
+ $pod_options = apply_filters( 'pods_advanced_content_type_pod_data_' . $pod->pod_data[ 'name' ], $pod_options, $pod->pod_data[ 'name' ] );
17
+ $pod_options = apply_filters( 'pods_advanced_content_type_pod_data', $pod_options, $pod->pod_data[ 'name' ] );
18
+
19
  $group_fields = array();
20
  $submittable_fields = array();
21
 
28
  continue;
29
  }
30
  elseif ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $group[ 'fields' ], $pod, $pod->id() ) ) {
31
+ if ( pods_v_sanitized( 'hidden', $field[ 'options' ], false ) ) {
32
  $group[ 'fields' ][ $k ][ 'type' ] = 'hidden';
33
  }
34
+ elseif ( pods_v_sanitized( 'read_only', $field[ 'options' ], false ) ) {
35
  $group[ 'fields' ][ $k ][ 'readonly' ] = true;
36
  }
37
  else {
41
  }
42
  }
43
  elseif ( !pods_has_permissions( $field[ 'options' ] ) ) {
44
+ if ( pods_v_sanitized( 'hidden', $field[ 'options' ], false ) ) {
45
  $group[ 'fields' ][ $k ][ 'type' ] = 'hidden';
46
  }
47
+ elseif ( pods_v_sanitized( 'read_only', $field[ 'options' ], false ) ) {
48
  $group[ 'fields' ][ $k ][ 'readonly' ] = true;
49
  }
50
  }
51
 
52
+ if ( !pods_v_sanitized( 'readonly', $field, false ) ) {
53
  $submittable_fields[ $field[ 'name' ]] = $group[ 'fields' ][ $k ];
54
  }
55
 
74
  if ( isset( $_POST[ '_pods_nonce' ] ) ) {
75
  $action = __( 'saved', 'pods' );
76
 
77
+ if ( 'create' == pods_v( 'do', 'post', 'save' ) )
78
  $action = __( 'created', 'pods' );
79
+ elseif ( 'duplicate' == pods_v( 'do', 'get', 'save' ) )
80
  $action = __( 'duplicated', 'pods' );
81
 
82
  try {
85
 
86
  $message = sprintf( __( '<strong>Success!</strong> %s %s successfully.', 'pods' ), $obj->item, $action );
87
 
88
+ if ( 0 < strlen( pods_v_sanitized( 'detail_url', $pod_options ) ) )
89
  $message .= ' <a target="_blank" href="' . $pod->field( 'detail_url' ) . '">' . sprintf( __( 'View %s', 'pods' ), $obj->item ) . '</a>';
90
 
91
  $error = sprintf( __( '<strong>Error:</strong> %s %s successfully.', 'pods' ), $obj->item, $action );
102
  elseif ( isset( $_GET[ 'do' ] ) ) {
103
  $action = __( 'saved', 'pods' );
104
 
105
+ if ( 'create' == pods_v( 'do', 'get', 'save' ) )
106
  $action = __( 'created', 'pods' );
107
+ elseif ( 'duplicate' == pods_v( 'do', 'get', 'save' ) )
108
  $action = __( 'duplicated', 'pods' );
109
 
110
  $message = sprintf( __( '<strong>Success!</strong> %s %s successfully.', 'pods' ), $obj->item, $action );
111
 
112
+ if ( 0 < strlen( pods_v_sanitized( 'detail_url', $pod_options ) ) )
113
  $message .= ' <a target="_blank" href="' . $pod->field( 'detail_url' ) . '">' . sprintf( __( 'View %s', 'pods' ), $obj->item ) . '</a>';
114
 
115
  $error = sprintf( __( '<strong>Error:</strong> %s not %s.', 'pods' ), $obj->item, $action );
184
  <!-- BEGIN PUBLISH DIV -->
185
  <div id="submitdiv" class="postbox">
186
  <div class="handlediv" title="Click to toggle"><br /></div>
187
+ <h3 class="hndle"><span><?php echo pods_v( 'label_manage', $pod_options, __( 'Manage', 'pods' ) ); ?></span></h3>
188
 
189
  <div class="inside">
190
  <div class="submitbox" id="submitpost">
191
  <?php
192
+ if ( 0 < $pod->id() && ( isset( $pod->pod_data[ 'fields' ][ 'created' ] ) || isset( $pod->pod_data[ 'fields' ][ 'modified' ] ) || 0 < strlen( pods_v_sanitized( 'detail_url', $pod_options ) ) ) ) {
193
  ?>
194
  <div id="minor-publishing">
195
  <?php
196
+ if ( 0 < strlen( pods_v_sanitized( 'detail_url', $pod_options ) ) ) {
197
  ?>
198
  <div id="minor-publishing-actions">
199
  <div id="preview-action">
261
  ) );
262
  ?>
263
  <div id="delete-action">
264
+ <a class="submitdelete deletion" href="<?php echo esc_url( $link ); ?>" onclick="return confirm('<?php _e( "You are about to permanently delete this item. Choose CANCEL to stop, OK to delete.", 'pods' ); ?>');"><?php _e( 'Delete', 'pods' ); ?></a>
265
  </div>
266
  <!-- /#delete-action -->
267
  <?php } ?>
309
  </div>
310
  <!-- /#submitdiv --><!-- END PUBLISH DIV --><!-- TODO: minor column fields -->
311
  <?php
312
+ if ( pods_v( 'action' ) == 'edit' && !$duplicate && !in_array( 'navigate', (array) $obj->actions_disabled ) && !in_array( 'navigate', (array) $obj->actions_hidden ) ) {
313
  if ( !isset( $singular_label ) )
314
  $singular_label = ucwords( str_replace( '_', ' ', $pod->pod_data[ 'name' ] ) );
315
 
316
+ $singular_label = pods_v( 'label', $pod_options, $singular_label, null, true );
317
+ $singular_label = pods_v( 'label_singular', $pod_options, $singular_label, null, true );
318
 
319
  $pod->params = $obj->get_params( null, 'manage' );
320
 
428
  $more = true;
429
  $extra = '';
430
 
431
+ $max_length = (int) pods_v_sanitized( 'maxlength', $field[ 'options' ], pods_v_sanitized( $field[ 'type' ] . '_max_length', $field[ 'options' ], 0 ), null, true );
432
 
433
  if ( 0 < $max_length )
434
  $extra .= ' maxlength="' . esc_attr( $max_length ) . '"';
ui/admin/help.php CHANGED
@@ -5,11 +5,11 @@
5
 
6
  <h3><?php _e( 'Pods Support' , 'pods'); ?></h3>
7
 
8
- <p><?php _e( 'There are many resources available to help you learn to use Pods on our site, <a href="http://pods.io/" target="_blank">Pods.io</a>:', 'pods'); ?></p>
9
  <ul class="ul-disc">
10
- <li><?php _e('To learn more about using Pods, see the <a href="http://pods.io/docs/" target="_blank">documentation</a>, or our <a href="http://pods.io/tutorials/" target="_blank">tutorials section</a>', 'pods'); ?>.
11
 
12
- <li><?php _e( 'To get help with a specific issue, you can ask in our <a href="http://pods.io/forums/" target="_blank">support forums</a>, or in <a href="http://pods.io/forums/chat/" target="_blank">our chat</a>', 'pods'); ?>.
13
 
14
  <li><?php _e('To report <strong>bugs or request features</strong>, go to our <a href="https://github.com/pods-framework/pods/issues?sort=updated&direction=desc&state=open" target="_blank">GitHub</a>.', 'pods' ); ?></li>
15
 
@@ -21,7 +21,7 @@
21
  <?php
22
  include_once( ABSPATH . WPINC . '/feed.php' );
23
 
24
- $feed = fetch_feed( 'http://pods.io/forums/forum/pods-2-x/feed/' );
25
 
26
  if ( !is_wp_error( $feed ) ) {
27
  $max_items = $feed->get_item_quantity( 10 );
@@ -29,7 +29,7 @@
29
 
30
  if ( 0 < $max_items ) {
31
  ?>
32
- <h3><?php _e( 'Latest Forum Posts at <a href="http://pods.io/forums/forum/general-discussion/pods-2-x/" target="_blank">pods.io</a>', 'pods'); ?></h3>
33
 
34
  <ul class="ul-disc">
35
  <?php
5
 
6
  <h3><?php _e( 'Pods Support' , 'pods'); ?></h3>
7
 
8
+ <p><?php _e( 'There are many resources available to help you learn to use Pods on our site, <a href="https://pods.io/" target="_blank">Pods.io</a>:', 'pods'); ?></p>
9
  <ul class="ul-disc">
10
+ <li><?php _e('To learn more about using Pods, see the <a href="https://pods.io/docs/" target="_blank">documentation</a>, or our <a href="https://pods.io/tutorials/" target="_blank">tutorials section</a>', 'pods'); ?>.
11
 
12
+ <li><?php _e( 'To get help with a specific issue, you can ask in our <a href="https://pods.io/forums/" target="_blank">support forums</a>, or in <a href="https://pods.io/forums/chat/" target="_blank">our chat</a>', 'pods'); ?>.
13
 
14
  <li><?php _e('To report <strong>bugs or request features</strong>, go to our <a href="https://github.com/pods-framework/pods/issues?sort=updated&direction=desc&state=open" target="_blank">GitHub</a>.', 'pods' ); ?></li>
15
 
21
  <?php
22
  include_once( ABSPATH . WPINC . '/feed.php' );
23
 
24
+ $feed = fetch_feed( 'https://pods.io/forums/forum/pods-2-x/feed/' );
25
 
26
  if ( !is_wp_error( $feed ) ) {
27
  $max_items = $feed->get_item_quantity( 10 );
29
 
30
  if ( 0 < $max_items ) {
31
  ?>
32
+ <h3><?php _e( 'Latest Forum Posts at <a href="https://pods.io/forums/forum/general-discussion/pods-2-x/" target="_blank">pods.io</a>', 'pods'); ?></h3>
33
 
34
  <ul class="ul-disc">
35
  <?php
ui/admin/settings-reset.php CHANGED
@@ -27,7 +27,7 @@
27
  // Monday Mode
28
  $monday_mode = pods_v( 'pods_monday_mode', 'get', 0, true );
29
 
30
- if ( pods_var( 'pods_reset_weekend', 'post', pods_var( 'pods_reset_weekend', 'get', 0, null, true ), null, true ) ) {
31
  if ( $monday_mode ) {
32
  $html = '<br /><br /><iframe width="480" height="360" src="http://www.youtube-nocookie.com/embed/QH2-TGUlwu4?autoplay=1" frameborder="0" allowfullscreen></iframe>';
33
  pods_message( 'The weekend has been reset and you have been sent back to Friday night. Unfortunately due to a tear in the fabric of time, you slipped back to Monday. We took video of the whole process and you can see it below..' . $html );
27
  // Monday Mode
28
  $monday_mode = pods_v( 'pods_monday_mode', 'get', 0, true );
29
 
30
+ if ( pods_v_sanitized( 'pods_reset_weekend', 'post', pods_v_sanitized( 'pods_reset_weekend', 'get', 0, null, true ), null, true ) ) {
31
  if ( $monday_mode ) {
32
  $html = '<br /><br /><iframe width="480" height="360" src="http://www.youtube-nocookie.com/embed/QH2-TGUlwu4?autoplay=1" frameborder="0" allowfullscreen></iframe>';
33
  pods_message( 'The weekend has been reset and you have been sent back to Friday night. Unfortunately due to a tear in the fabric of time, you slipped back to Monday. We took video of the whole process and you can see it below..' . $html );
ui/admin/settings-tools.php CHANGED
@@ -12,13 +12,13 @@
12
  pods_redirect( pods_query_arg( array( 'pods_clearcache' => 1 ), array( 'page', 'tab' ) ) );
13
  }
14
  }
15
- elseif ( 1 == pods_var( 'pods_clearcache' ) )
16
  pods_message( 'Pods transients and cache have been cleared.' );
17
  ?>
18
 
19
  <h3><?php _e( 'Clear Pods Cache', 'pods' ); ?></h3>
20
 
21
- <p><?php _e( 'This tool will clear all of the transients/cache that are used by Pods. ', 'pods' ); ?></p>
22
 
23
  <p class="submit">
24
  <input type="submit" class="button button-primary" name="clearcache" value="<?php esc_attr_e( 'Clear Pods Cache', 'pods' ); ?>" />
12
  pods_redirect( pods_query_arg( array( 'pods_clearcache' => 1 ), array( 'page', 'tab' ) ) );
13
  }
14
  }
15
+ elseif ( 1 == pods_v_sanitized( 'pods_clearcache' ) )
16
  pods_message( 'Pods transients and cache have been cleared.' );
17
  ?>
18
 
19
  <h3><?php _e( 'Clear Pods Cache', 'pods' ); ?></h3>
20
 
21
+ <p><?php esc_html_e( 'This tool will clear all of the transients/cache that are used by Pods.', 'pods' ); ?></p>
22
 
23
  <p class="submit">
24
  <input type="submit" class="button button-primary" name="clearcache" value="<?php esc_attr_e( 'Clear Pods Cache', 'pods' ); ?>" />
ui/admin/settings.php CHANGED
@@ -18,7 +18,7 @@
18
  foreach ( $tabs as $tab => $label ) {
19
  $class = '';
20
 
21
- if ( $tab == pods_var( 'tab', 'get', $default ) ) {
22
  $class = ' nav-tab-active';
23
 
24
  $label = 'Pods ' . $label;
@@ -38,7 +38,7 @@
38
  <?php
39
  wp_nonce_field( 'pods-settings' );
40
 
41
- $tab = pods_var( 'tab', 'get', $default );
42
  $tab = sanitize_title( $tab );
43
 
44
  echo pods_view( PODS_DIR . 'ui/admin/settings-' . $tab . '.php' );
18
  foreach ( $tabs as $tab => $label ) {
19
  $class = '';
20
 
21
+ if ( $tab == pods_v_sanitized( 'tab', 'get', $default ) ) {
22
  $class = ' nav-tab-active';
23
 
24
  $label = 'Pods ' . $label;
38
  <?php
39
  wp_nonce_field( 'pods-settings' );
40
 
41
+ $tab = pods_v_sanitized( 'tab', 'get', $default );
42
  $tab = sanitize_title( $tab );
43
 
44
  echo pods_view( PODS_DIR . 'ui/admin/settings-' . $tab . '.php' );
ui/admin/setup-add.php CHANGED
@@ -1,3 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <div class="wrap pods-admin">
2
  <script>
3
  var PODS_URL = '<?php echo esc_js( PODS_URL ); ?>';
@@ -47,7 +65,7 @@
47
  <p>
48
  <?php _e( 'Pods are content types that you can customize and define fields for based on your needs. You can choose to create a Custom Post Type, Custom Taxonomy, or Custom Settings Pages for site-specific data. You can also extend existing content types like WP Objects such as Post Types, Taxonomies, Users, or Comments.', 'pods' ); ?>
49
  <br /><br />
50
- <?php _e( 'Not sure what content type you should use? Check out our <a href="http://pods.io/docs/comparisons/compare-content-types/" target="_blank">Content Type Comparison</a> to help you decide.', 'pods' ); ?>
51
  </p>
52
 
53
  </div>
@@ -81,7 +99,7 @@
81
  <div class="inside pods-manage-field pods-dependency">
82
  <div class="pods-field-option">
83
  <?php
84
- echo PodsForm::label( 'create_pod_type', __( 'Content Type', 'pods' ), array( __( '<h6>Content Types</h6> There are many content types to choose from, we have put together a comparison between them all to help you decide what fits your needs best.', 'pods' ), 'http://pods.io/docs/comparisons/compare-content-types/' ) );
85
 
86
  $data = array(
87
  'post_type' => __( 'Custom Post Type (like Posts or Pages)', 'pods' ),
@@ -95,7 +113,7 @@
95
  if ( empty( $data[ 'pod' ] ) )
96
  unset( $data[ 'pod' ] );
97
 
98
- echo PodsForm::field( 'create_pod_type', pods_var_raw( 'create_pod_type', 'post' ), 'pick', array( 'data' => $data, 'class' => 'pods-dependent-toggle' ) );
99
  ?>
100
  </div>
101
 
@@ -104,7 +122,7 @@
104
  ?>
105
  <div class="pods-field-option pods-depends-on pods-depends-on-create-pod-type pods-depends-on-create-pod-type-taxonomy">
106
  <?php
107
- echo PodsForm::label( 'create_storage_taxonomy', __( 'Enable Extra Fields?', 'pods' ), array( __( '<h6>Storage Types</h6> Taxonomies do not support extra fields natively, but Pods can add this feature for you easily. Table based storage will operate in a way where each field you create for your content type becomes a field in a table.', 'pods' ), 'http://pods.io/docs/comparisons/compare-storage-types/' ) );
108
 
109
  $data = array(
110
  'none' => __( 'Do not enable extra fields to be added', 'pods' ),
@@ -122,7 +140,7 @@
122
  $default = 'meta';
123
  }
124
 
125
- echo PodsForm::field( 'create_storage_taxonomy', pods_var_raw( 'create_storage_taxonomy', 'post', $default, null, true ), 'pick', array( 'data' => $data ) );
126
  ?>
127
  </div>
128
  <?php
@@ -133,13 +151,13 @@
133
  <div class="pods-field-option">
134
  <?php
135
  echo PodsForm::label( 'create_label_singular', __( 'Singular Label', 'pods' ), __( '<h6>Singular Label</h6> This is the label for 1 item (Singular) that will appear throughout the WordPress admin area for managing the content.', 'pods' ) );
136
- echo PodsForm::field( 'create_label_singular', pods_var_raw( 'create_label_singular', 'post' ), 'text', array( 'class' => 'pods-validate pods-validate-required', 'text_max_length' => 30 ) );
137
  ?>
138
  </div>
139
  <div class="pods-field-option">
140
  <?php
141
  echo PodsForm::label( 'create_label_plural', __( 'Plural Label', 'pods' ), __( '<h6>Plural Label</h6> This is the label for more than 1 item (Plural) that will appear throughout the WordPress admin area for managing the content.', 'pods' ) );
142
- echo PodsForm::field( 'create_label_plural', pods_var_raw( 'create_label_plural', 'post' ), 'text', array( 'text_max_length' => 30 ) );
143
  ?>
144
  </div>
145
  </div>
@@ -147,13 +165,13 @@
147
  <div class="pods-field-option">
148
  <?php
149
  echo PodsForm::label( 'create_label_title', __( 'Page Title', 'pods' ), __( '<h6>Page Title</h6> This is the text that will appear at the top of your settings page.', 'pods' ) );
150
- echo PodsForm::field( 'create_label_title', pods_var_raw( 'create_label_title', 'post' ), 'text', array( 'class' => 'pods-validate pods-validate-required', 'text_max_length' => 30 ) );
151
  ?>
152
  </div>
153
  <div class="pods-field-option">
154
  <?php
155
  echo PodsForm::label( 'create_label_menu', __( 'Menu Label', 'pods' ), __( '<h6>Menu Label</h6> This is the label that will appear throughout the WordPress admin area for your settings.', 'pods' ) );
156
- echo PodsForm::field( 'create_label_menu', pods_var_raw( 'create_label_menu', 'post' ), 'text', array( 'text_max_length' => 30 ) );
157
  ?>
158
  </div>
159
  <div class="pods-field-option">
@@ -161,12 +179,12 @@
161
  echo PodsForm::label( 'create_menu_location', __( 'Menu Location', 'pods' ), __( '<h6>Menu Location</h6> This is the location where the new settings page will be added in the WordPress Dashboard menu.', 'pods' ) );
162
 
163
  $data = array(
164
- 'settings' => 'Add to Settings menu',
165
- 'appearances' => 'Add to Appearances menu',
166
- 'top' => 'Make a new menu item below Settings'
167
  );
168
 
169
- echo PodsForm::field( 'create_menu_location', pods_var_raw( 'create_menu_location', 'post' ), 'pick', array( 'data' => $data ) );
170
  ?>
171
  </div>
172
  </div>
@@ -184,7 +202,7 @@
184
  $max_length_name -= strlen( $wpdb->prefix . 'pods_' );
185
 
186
  echo PodsForm::label( 'create_name', __( 'Pod Name', 'pods' ), __( '<h6>Pod Identifier</h6> This is different than the labels users will see in the WordPress admin areas, it is the name you will use to programatically reference this object throughout your theme, WordPress, and other PHP.', 'pods' ) );
187
- echo PodsForm::field( 'create_name', pods_var_raw( 'create_name', 'post' ), 'db', array( 'attributes' => array( 'maxlength' => $max_length_name, 'size' => 25 ) ) );
188
  ?>
189
  </div>
190
  <div class="pods-field-option pods-depends-on pods-depends-on-create-pod-type pods-depends-on-create-pod-type-settings">
@@ -195,7 +213,7 @@
195
  $max_length_name -= strlen( $wpdb->prefix . 'pods_' );
196
 
197
  echo PodsForm::label( 'create_setting_name', __( 'Pod Name', 'pods' ), __( '<h6>Pod Identifier</h6> This is different than the labels users will see in the WordPress admin areas, it is the name you will use to programatically reference this object throughout your theme, WordPress, and other PHP.', 'pods' ) );
198
- echo PodsForm::field( 'create_setting_name', pods_var_raw( 'create_setting_name', 'post' ), 'db', array( 'attributes' => array( 'maxlength' => $max_length_name, 'size' => 25 ) ) );
199
  ?>
200
  </div>
201
 
@@ -204,14 +222,14 @@
204
  ?>
205
  <div class="pods-field-option pods-depends-on pods-depends-on-create-pod-type pods-depends-on-create-pod-type-post-type">
206
  <?php
207
- echo PodsForm::label( 'create_storage', __( 'Storage Type', 'pods' ), array( __( '<h6>Storage Types</h6> Table based storage will operate in a way where each field you create for your content type becomes a field in a table. Meta based storage relies upon the WordPress meta storage table for all field data.', 'pods' ), 'http://pods.io/docs/comparisons/compare-storage-types/' ) );
208
 
209
  $data = array(
210
  'meta' => __( 'Meta Based (WP Default)', 'pods' ),
211
  'table' => __( 'Table Based', 'pods' )
212
  );
213
 
214
- echo PodsForm::field( 'create_storage', pods_var_raw( 'create_storage', 'post' ), 'pick', array( 'data' => $data ) );
215
  ?>
216
  </div>
217
  <?php
@@ -232,7 +250,7 @@
232
 
233
  <div class="pods-field-option">
234
  <?php
235
- echo PodsForm::label( 'extend_pod_type', __( 'Content Type', 'pods' ), array( __( '<h6>Content Types</h6> There are many content types to choose from, we have put together a comparison between them all to help you decide what fits your needs best.', 'pods' ), 'http://pods.io/docs/comparisons/compare-content-types/' ) );
236
 
237
  $data = array(
238
  'post_type' => __( 'Post Types (Posts, Pages, etc..)', 'pods' ),
@@ -260,17 +278,18 @@
260
  if ( empty( $data[ 'taxonomy' ] ) )
261
  unset( $data[ 'taxonomy' ] );
262
 
263
- echo PodsForm::field( 'extend_pod_type', pods_var_raw( 'extend_pod_type', 'post' ), 'pick', array( 'data' => $data, 'class' => 'pods-dependent-toggle' ) );
264
  ?>
265
  </div>
266
  <div class="pods-field-option pods-depends-on pods-depends-on-extend-pod-type pods-depends-on-extend-pod-type-post-type">
267
  <?php
268
  $post_types = get_post_types();
269
- $ignore = array( 'attachment', 'revision', 'nav_menu_item' );
270
 
271
  foreach ( $post_types as $post_type => $label ) {
272
  if ( in_array( $post_type, $ignore ) || empty( $post_type ) || 0 === strpos( $post_type, '_pods_' ) ) {
 
273
  unset( $post_types[ $post_type ] );
 
274
  continue;
275
  }
276
  elseif ( isset( $all_pods[ $post_type ] ) && 'post_type' == $all_pods[ $post_type ][ 'type' ] ) {
@@ -283,23 +302,18 @@
283
  }
284
 
285
  echo PodsForm::label( 'extend_post_type', __( 'Post Type', 'pods' ), array( __( '<h6>Post Types</h6> WordPress can hold and display many different types of content. Internally, these are all stored in the same place, in the wp_posts table. These are differentiated by a column called post_type.', 'pods' ), 'http://codex.wordpress.org/Post_Types' ) );
286
- echo PodsForm::field( 'extend_post_type', pods_var_raw( 'extend_post_type', 'post', 'table', null, true ), 'pick', array( 'data' => $post_types ) );
287
  ?>
288
  </div>
289
  <div class="pods-field-option pods-depends-on pods-depends-on-extend-pod-type pods-depends-on-extend-pod-type-taxonomy">
290
  <?php
291
  $taxonomies = get_taxonomies();
292
 
293
- //Add Support for built-in taxonomy "link_category"
294
- //if links are in use.
295
- $bookmarkcount = count(get_bookmarks());
296
- if ($bookmarkcount < 1){
297
- $ignore = array( 'link_category' );
298
- }
299
-
300
  foreach ( $taxonomies as $taxonomy => $label ) {
301
  if ( in_array( $taxonomy, $ignore ) ) {
 
302
  unset( $taxonomies[ $taxonomy ] );
 
303
  continue;
304
  }
305
  elseif ( isset( $all_pods[ $taxonomy ] ) && 'taxonomy' == $all_pods[ $taxonomy ][ 'type' ] ) {
@@ -312,7 +326,7 @@
312
  }
313
 
314
  echo PodsForm::label( 'extend_taxonomy', __( 'Taxonomy', 'pods' ), array( __( '<h6>Taxonomies</h6> A taxonomy is a way to group Post Types.', 'pods' ), 'http://codex.wordpress.org/Taxonomies' ) );
315
- echo PodsForm::field( 'extend_taxonomy', pods_var_raw( 'extend_taxonomy', 'post' ), 'pick', array( 'data' => $taxonomies ) );
316
  ?>
317
  </div>
318
 
@@ -321,7 +335,7 @@
321
  ?>
322
  <div class="pods-field-option pods-depends-on pods-depends-on-extend-pod-type pods-depends-on-extend-pod-type-taxonomy">
323
  <?php
324
- echo PodsForm::label( 'extend_storage_taxonomy', __( 'Enable Extra Fields?', 'pods' ), array( __( '<h6>Storage Types</h6> Taxonomies do not support extra fields natively, but Pods can add this feature for you easily. Table based storage will operate in a way where each field you create for your content type becomes a field in a table.', 'pods' ), 'http://pods.io/docs/comparisons/compare-storage-types/' ) );
325
 
326
  $data = array(
327
  'none' => __( 'Do not enable extra fields to be added', 'pods' ),
@@ -339,7 +353,7 @@
339
  $default = 'meta';
340
  }
341
 
342
- echo PodsForm::field( 'extend_storage_taxonomy', pods_var_raw( 'extend_storage_taxonomy', 'post', $default, null, true ), 'pick', array( 'data' => $data ) );
343
  ?>
344
  </div>
345
  <?php
@@ -355,14 +369,14 @@
355
  <div class="pods-advanced">
356
  <div class="pods-field-option">
357
  <?php
358
- echo PodsForm::label( 'extend_storage', __( 'Storage Type', 'pods' ), array( __( '<h6>Storage Types</h6> Table based storage will operate in a way where each field you create for your content type becomes a field in a table. Meta based storage relies upon the WordPress meta storage table for all field data.', 'pods' ), 'http://pods.io/docs/comparisons/compare-storage-types/' ) );
359
 
360
  $data = array(
361
  'meta' => __( 'Meta Based (WP Default)', 'pods' ),
362
  'table' => __( 'Table Based', 'pods' )
363
  );
364
 
365
- echo PodsForm::field( 'extend_storage', pods_var_raw( 'extend_storage', 'post' ), 'pick', array( 'data' => $data ) );
366
  ?>
367
  </div>
368
  </div>
@@ -398,11 +412,11 @@
398
  else {
399
  document.location = 'admin.php?page=pods&do=create';
400
  }
401
- }
402
 
403
  var pods_admin_option_select_callback = function ( $opt ) {
404
  jQuery( '#pods_create_extend' ).val( $opt.data( 'opt' ) );
405
- }
406
 
407
  jQuery( function ( $ ) {
408
  $( document ).Pods( 'validate' );
@@ -413,8 +427,8 @@
413
  $( document ).Pods( 'confirm' );
414
  $( document ).Pods( 'sluggable' );
415
 
416
- $( document ).find( '.pods-dependency .pods-dependent-toggle' ).each( function () {
417
- $( this ).trigger( 'change' );
418
  } );
419
  } );
420
  </script>
1
+ <?php
2
+ $ignore = array(
3
+ 'attachment',
4
+ 'revision',
5
+ 'nav_menu_item',
6
+ 'custom_css',
7
+ 'customize_changeset',
8
+ 'post_format',
9
+ );
10
+
11
+ // Only add support for built-in taxonomy "link_category" if link manager is enabled.
12
+ $link_manager_enabled = (int) get_option( 'link_manager_enabled', 0 );
13
+
14
+ if ( 0 === $link_manager_enabled ) {
15
+ $ignore[] = 'link_category';
16
+ }
17
+ ?>
18
+
19
  <div class="wrap pods-admin">
20
  <script>
21
  var PODS_URL = '<?php echo esc_js( PODS_URL ); ?>';
65
  <p>
66
  <?php _e( 'Pods are content types that you can customize and define fields for based on your needs. You can choose to create a Custom Post Type, Custom Taxonomy, or Custom Settings Pages for site-specific data. You can also extend existing content types like WP Objects such as Post Types, Taxonomies, Users, or Comments.', 'pods' ); ?>
67
  <br /><br />
68
+ <?php _e( 'Not sure what content type you should use? Check out our <a href="https://pods.io/docs/comparisons/compare-content-types/" target="_blank">Content Type Comparison</a> to help you decide.', 'pods' ); ?>
69
  </p>
70
 
71
  </div>
99
  <div class="inside pods-manage-field pods-dependency">
100
  <div class="pods-field-option">
101
  <?php
102
+ echo PodsForm::label( 'create_pod_type', __( 'Content Type', 'pods' ), array( __( '<h6>Content Types</h6> There are many content types to choose from, we have put together a comparison between them all to help you decide what fits your needs best.', 'pods' ), 'https://pods.io/docs/comparisons/compare-content-types/' ) );
103
 
104
  $data = array(
105
  'post_type' => __( 'Custom Post Type (like Posts or Pages)', 'pods' ),
113
  if ( empty( $data[ 'pod' ] ) )
114
  unset( $data[ 'pod' ] );
115
 
116
+ echo PodsForm::field( 'create_pod_type', pods_v( 'create_pod_type', 'post' ), 'pick', array( 'data' => $data, 'class' => 'pods-dependent-toggle' ) );
117
  ?>
118
  </div>
119
 
122
  ?>
123
  <div class="pods-field-option pods-depends-on pods-depends-on-create-pod-type pods-depends-on-create-pod-type-taxonomy">
124
  <?php
125
+ echo PodsForm::label( 'create_storage_taxonomy', __( 'Enable Extra Fields?', 'pods' ), array( __( '<h6>Storage Types</h6> Taxonomies do not support extra fields natively, but Pods can add this feature for you easily. Table based storage will operate in a way where each field you create for your content type becomes a field in a table.', 'pods' ), 'https://pods.io/docs/comparisons/compare-storage-types/' ) );
126
 
127
  $data = array(
128
  'none' => __( 'Do not enable extra fields to be added', 'pods' ),
140
  $default = 'meta';
141
  }
142
 
143
+ echo PodsForm::field( 'create_storage_taxonomy', pods_v( 'create_storage_taxonomy', 'post', $default, null, true ), 'pick', array( 'data' => $data ) );
144
  ?>
145
  </div>
146
  <?php
151
  <div class="pods-field-option">
152
  <?php
153
  echo PodsForm::label( 'create_label_singular', __( 'Singular Label', 'pods' ), __( '<h6>Singular Label</h6> This is the label for 1 item (Singular) that will appear throughout the WordPress admin area for managing the content.', 'pods' ) );
154
+ echo PodsForm::field( 'create_label_singular', pods_v( 'create_label_singular', 'post' ), 'text', array( 'class' => 'pods-validate pods-validate-required', 'text_max_length' => 30 ) );
155
  ?>
156
  </div>
157
  <div class="pods-field-option">
158
  <?php
159
  echo PodsForm::label( 'create_label_plural', __( 'Plural Label', 'pods' ), __( '<h6>Plural Label</h6> This is the label for more than 1 item (Plural) that will appear throughout the WordPress admin area for managing the content.', 'pods' ) );
160
+ echo PodsForm::field( 'create_label_plural', pods_v( 'create_label_plural', 'post' ), 'text', array( 'text_max_length' => 30 ) );
161
  ?>
162
  </div>
163
  </div>
165
  <div class="pods-field-option">
166
  <?php
167
  echo PodsForm::label( 'create_label_title', __( 'Page Title', 'pods' ), __( '<h6>Page Title</h6> This is the text that will appear at the top of your settings page.', 'pods' ) );
168
+ echo PodsForm::field( 'create_label_title', pods_v( 'create_label_title', 'post' ), 'text', array( 'class' => 'pods-validate pods-validate-required', 'text_max_length' => 30 ) );
169
  ?>
170
  </div>
171
  <div class="pods-field-option">
172
  <?php
173
  echo PodsForm::label( 'create_label_menu', __( 'Menu Label', 'pods' ), __( '<h6>Menu Label</h6> This is the label that will appear throughout the WordPress admin area for your settings.', 'pods' ) );
174
+ echo PodsForm::field( 'create_label_menu', pods_v( 'create_label_menu', 'post' ), 'text', array( 'text_max_length' => 30 ) );
175
  ?>
176
  </div>
177
  <div class="pods-field-option">
179
  echo PodsForm::label( 'create_menu_location', __( 'Menu Location', 'pods' ), __( '<h6>Menu Location</h6> This is the location where the new settings page will be added in the WordPress Dashboard menu.', 'pods' ) );
180
 
181
  $data = array(
182
+ 'settings' => __( 'Add to Settings menu', 'pods' ),
183
+ 'appearances' => __( 'Add to Appearances menu', 'pods' ),
184
+ 'top' => __( 'Make a new menu item below Settings', 'pods' )
185
  );
186
 
187
+ echo PodsForm::field( 'create_menu_location', pods_v( 'create_menu_location', 'post' ), 'pick', array( 'data' => $data ) );
188
  ?>
189
  </div>
190
  </div>
202
  $max_length_name -= strlen( $wpdb->prefix . 'pods_' );
203
 
204
  echo PodsForm::label( 'create_name', __( 'Pod Name', 'pods' ), __( '<h6>Pod Identifier</h6> This is different than the labels users will see in the WordPress admin areas, it is the name you will use to programatically reference this object throughout your theme, WordPress, and other PHP.', 'pods' ) );
205
+ echo PodsForm::field( 'create_name', pods_v( 'create_name', 'post' ), 'db', array( 'attributes' => array( 'maxlength' => $max_length_name, 'size' => 25 ) ) );
206
  ?>
207
  </div>
208
  <div class="pods-field-option pods-depends-on pods-depends-on-create-pod-type pods-depends-on-create-pod-type-settings">
213
  $max_length_name -= strlen( $wpdb->prefix . 'pods_' );
214
 
215
  echo PodsForm::label( 'create_setting_name', __( 'Pod Name', 'pods' ), __( '<h6>Pod Identifier</h6> This is different than the labels users will see in the WordPress admin areas, it is the name you will use to programatically reference this object throughout your theme, WordPress, and other PHP.', 'pods' ) );
216
+ echo PodsForm::field( 'create_setting_name', pods_v( 'create_setting_name', 'post' ), 'db', array( 'attributes' => array( 'maxlength' => $max_length_name, 'size' => 25 ) ) );
217
  ?>
218
  </div>
219
 
222
  ?>
223
  <div class="pods-field-option pods-depends-on pods-depends-on-create-pod-type pods-depends-on-create-pod-type-post-type">
224
  <?php
225
+ echo PodsForm::label( 'create_storage', __( 'Storage Type', 'pods' ), array( __( '<h6>Storage Types</h6> Table based storage will operate in a way where each field you create for your content type becomes a field in a table. Meta based storage relies upon the WordPress meta storage table for all field data.', 'pods' ), 'https://pods.io/docs/comparisons/compare-storage-types/' ) );
226
 
227
  $data = array(
228
  'meta' => __( 'Meta Based (WP Default)', 'pods' ),
229
  'table' => __( 'Table Based', 'pods' )
230
  );
231
 
232
+ echo PodsForm::field( 'create_storage', pods_v( 'create_storage', 'post' ), 'pick', array( 'data' => $data ) );
233
  ?>
234
  </div>
235
  <?php
250
 
251
  <div class="pods-field-option">
252
  <?php
253
+ echo PodsForm::label( 'extend_pod_type', __( 'Content Type', 'pods' ), array( __( '<h6>Content Types</h6> There are many content types to choose from, we have put together a comparison between them all to help you decide what fits your needs best.', 'pods' ), 'https://pods.io/docs/comparisons/compare-content-types/' ) );
254
 
255
  $data = array(
256
  'post_type' => __( 'Post Types (Posts, Pages, etc..)', 'pods' ),
278
  if ( empty( $data[ 'taxonomy' ] ) )
279
  unset( $data[ 'taxonomy' ] );
280
 
281
+ echo PodsForm::field( 'extend_pod_type', pods_v( 'extend_pod_type', 'post' ), 'pick', array( 'data' => $data, 'class' => 'pods-dependent-toggle' ) );
282
  ?>
283
  </div>
284
  <div class="pods-field-option pods-depends-on pods-depends-on-extend-pod-type pods-depends-on-extend-pod-type-post-type">
285
  <?php
286
  $post_types = get_post_types();
 
287
 
288
  foreach ( $post_types as $post_type => $label ) {
289
  if ( in_array( $post_type, $ignore ) || empty( $post_type ) || 0 === strpos( $post_type, '_pods_' ) ) {
290
+ // Post type is ignored
291
  unset( $post_types[ $post_type ] );
292
+
293
  continue;
294
  }
295
  elseif ( isset( $all_pods[ $post_type ] ) && 'post_type' == $all_pods[ $post_type ][ 'type' ] ) {
302
  }
303
 
304
  echo PodsForm::label( 'extend_post_type', __( 'Post Type', 'pods' ), array( __( '<h6>Post Types</h6> WordPress can hold and display many different types of content. Internally, these are all stored in the same place, in the wp_posts table. These are differentiated by a column called post_type.', 'pods' ), 'http://codex.wordpress.org/Post_Types' ) );
305
+ echo PodsForm::field( 'extend_post_type', pods_v( 'extend_post_type', 'post', 'table', null, true ), 'pick', array( 'data' => $post_types ) );
306
  ?>
307
  </div>
308
  <div class="pods-field-option pods-depends-on pods-depends-on-extend-pod-type pods-depends-on-extend-pod-type-taxonomy">
309
  <?php
310
  $taxonomies = get_taxonomies();
311
 
 
 
 
 
 
 
 
312
  foreach ( $taxonomies as $taxonomy => $label ) {
313
  if ( in_array( $taxonomy, $ignore ) ) {
314
+ // Taxonomy is ignored
315
  unset( $taxonomies[ $taxonomy ] );
316
+
317
  continue;
318
  }
319
  elseif ( isset( $all_pods[ $taxonomy ] ) && 'taxonomy' == $all_pods[ $taxonomy ][ 'type' ] ) {
326
  }
327
 
328
  echo PodsForm::label( 'extend_taxonomy', __( 'Taxonomy', 'pods' ), array( __( '<h6>Taxonomies</h6> A taxonomy is a way to group Post Types.', 'pods' ), 'http://codex.wordpress.org/Taxonomies' ) );
329
+ echo PodsForm::field( 'extend_taxonomy', pods_v( 'extend_taxonomy', 'post' ), 'pick', array( 'data' => $taxonomies ) );
330
  ?>
331
  </div>
332
 
335
  ?>
336
  <div class="pods-field-option pods-depends-on pods-depends-on-extend-pod-type pods-depends-on-extend-pod-type-taxonomy">
337
  <?php
338
+ echo PodsForm::label( 'extend_storage_taxonomy', __( 'Enable Extra Fields?', 'pods' ), array( __( '<h6>Storage Types</h6> Taxonomies do not support extra fields natively, but Pods can add this feature for you easily. Table based storage will operate in a way where each field you create for your content type becomes a field in a table.', 'pods' ), 'https://pods.io/docs/comparisons/compare-storage-types/' ) );
339
 
340
  $data = array(
341
  'none' => __( 'Do not enable extra fields to be added', 'pods' ),
353
  $default = 'meta';
354
  }
355
 
356
+ echo PodsForm::field( 'extend_storage_taxonomy', pods_v( 'extend_storage_taxonomy', 'post', $default, null, true ), 'pick', array( 'data' => $data ) );
357
  ?>
358
  </div>
359
  <?php
369
  <div class="pods-advanced">
370
  <div class="pods-field-option">
371
  <?php
372
+ echo PodsForm::label( 'extend_storage', __( 'Storage Type', 'pods' ), array( __( '<h6>Storage Types</h6> Table based storage will operate in a way where each field you create for your content type becomes a field in a table. Meta based storage relies upon the WordPress meta storage table for all field data.', 'pods' ), 'https://pods.io/docs/comparisons/compare-storage-types/' ) );
373
 
374
  $data = array(
375
  'meta' => __( 'Meta Based (WP Default)', 'pods' ),
376
  'table' => __( 'Table Based', 'pods' )
377
  );
378
 
379
+ echo PodsForm::field( 'extend_storage', pods_v( 'extend_storage', 'post' ), 'pick', array( 'data' => $data ) );
380
  ?>
381
  </div>
382
  </div>
412
  else {
413
  document.location = 'admin.php?page=pods&do=create';
414
  }
415
+ };
416
 
417
  var pods_admin_option_select_callback = function ( $opt ) {
418
  jQuery( '#pods_create_extend' ).val( $opt.data( 'opt' ) );
419
+ };
420
 
421
  jQuery( function ( $ ) {
422
  $( document ).Pods( 'validate' );
427
  $( document ).Pods( 'confirm' );
428
  $( document ).Pods( 'sluggable' );
429
 
430
+ $( '.pods-admin' ).on( 'render', '.pods-form-ui-field', function ( e ) {
431
+ $( this ).find( '.pods-dependent-toggle[data-name-clean]' ).trigger( 'change' );
432
  } );
433
  } );
434
  </script>
ui/admin/setup-edit-field-fluid.php CHANGED
@@ -1,9 +1,9 @@
1
  <?php
2
  $field = array_merge( $field_settings[ 'field_defaults' ], $field );
3
 
4
- $pick_object = trim( pods_var( 'pick_object', $field ) . '-' . pods_var( 'pick_val', $field ), '-' );
5
  ?>
6
- <tr id="row-<?php echo esc_attr( $pods_i ); ?>" class="pods-manage-row pods-field-new pods-field-<?php echo esc_attr( pods_var( 'name', $field ) ) . ( '--1' === $pods_i ? ' flexible-row' : ' pods-submittable-fields' ); ?>" valign="top" data-row="<?php echo esc_attr( $pods_i ); ?>">
7
  <th scope="row" class="check-field pods-manage-sort">
8
  <img src="<?php echo esc_url( PODS_URL ); ?>ui/images/handle.gif" alt="<?php esc_attr_e( 'Move', 'pods' ); ?>" />
9
  </th>
@@ -60,38 +60,38 @@ $pick_object = trim( pods_var( 'pick_object', $field ) . '-' . pods_var( 'pick_v
60
  <div id="pods-basic-options-<?php echo esc_attr( $pods_i ); ?>" class="pods-tab pods-basic-options">
61
  <div class="pods-field-option">
62
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][label]', __( 'Label', 'pods' ), __( 'help', 'pods' ) ); ?>
63
- <?php echo PodsForm::field( 'field_data[' . $pods_i . '][label]', pods_var_raw( 'label', $field, '' ), 'text', array( 'class' => 'pods-validate pods-validate-required' ) ); ?>
64
  </div>
65
  <div class="pods-field-option">
66
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][name]', __( 'Name', 'pods' ), __( 'You will use this name to programatically reference this field throughout WordPress', 'pods' ) ); ?>
67
- <?php echo PodsForm::field( 'field_data[' . $pods_i . '][name]', pods_var_raw( 'name', $field, '' ), 'db', array( 'attributes' => array( 'maxlength' => 50, 'data-sluggable' => 'field_data[' . $pods_i . '][label]' ), 'class' => 'pods-validate pods-validate-required pods-slugged-lower' ) ); ?>
68
  </div>
69
  <div class="pods-field-option">
70
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][description]', __( 'Description', 'pods' ), __( 'help', 'pods' ) ); ?>
71
- <?php echo PodsForm::field( 'field_data[' . $pods_i . '][description]', pods_var_raw( 'description', $field, '' ), 'text' ); ?>
72
  </div>
73
  <div class="pods-field-option">
74
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][type]', __( 'Field Type', 'pods' ), __( 'help', 'pods' ) ); ?>
75
- <?php echo PodsForm::field( 'field_data[' . $pods_i . '][type]', pods_var_raw( 'type', $field, '' ), 'pick', array( 'data' => pods_var_raw( 'field_types_select', $field_settings ), 'class' => 'pods-dependent-toggle' ) ); ?>
76
  </div>
77
  <div class="pods-field-option-container pods-depends-on pods-depends-on-field-data-type pods-depends-on-field-data-type-pick">
78
  <div class="pods-field-option">
79
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][pick_object]', __( 'Related To', 'pods' ), __( 'help', 'pods' ) ); ?>
80
- <?php echo PodsForm::field( 'field_data[' . $pods_i . '][pick_object]', $pick_object, 'pick', array( 'required' => true, 'data' => pods_var_raw( 'pick_object', $field_settings ), 'class' => 'pods-dependent-toggle' ) ); ?>
81
  </div>
82
  <div class="pods-field-option pods-depends-on pods-depends-on-field-data-pick-object pods-depends-on-field-data-pick-object-custom-simple">
83
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][pick_custom]', __( 'Custom Defined Options', 'pods' ), __( 'One option per line, use <em>value|Label</em> for separate values and labels', 'pods' ) ); ?>
84
- <?php echo PodsForm::field( 'field_data[' . $pods_i . '][pick_custom]', pods_var_raw( 'pick_custom', $field, '' ), 'paragraph' ); ?>
85
  </div>
86
  <div class="pods-field-option pods-depends-on pods-depends-on-field-data-pick-object pods-depends-on-field-data-pick-object-table">
87
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][pick_table]', __( 'Related Table', 'pods' ), __( 'help', 'pods' ) ); ?>
88
- <?php echo PodsForm::field( 'field_data[' . $pods_i . '][pick_table]', pods_var_raw( 'pick_table', $field, '' ), 'pick', array( 'required' => true, 'data' => pods_var_raw( 'pick_table', $field_settings ) ) ); ?>
89
  </div>
90
  <div class="pods-field-option pods-depends-on pods-depends-on-field-data-pick-object pods-depends-on-field-data-pick-object-<?php echo esc_attr( str_replace( '_', '-', implode( ' pods-depends-on-field-data-pick-object-', $bidirectional_objects ) ) ); ?>" data-dependency-trigger="pods_sister_field">
91
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][sister_id]', __( 'Bi-directional Field', 'pods' ), __( 'Bi-directional fields will update their related field for any item you select. This feature is only available for two relationships between two Pods.<br /><br />For example, when you update a Parent pod item to relate to a Child item, when you go to edit that Child item you will see the Parent pod item selected.', 'pods' ) ); ?>
92
 
93
  <div class="pods-sister-field">
94
- <?php echo PodsForm::field( 'field_data[' . $pods_i . '][sister_id]', pods_var_raw( 'sister_id', $field, '' ), 'text' ); ?>
95
  </div>
96
  </div>
97
  </div>
@@ -103,13 +103,13 @@ $pick_object = trim( pods_var( 'pick_object', $field ) . '-' . pods_var( 'pick_v
103
  <div class="pods-pick-values pods-pick-checkbox">
104
  <ul>
105
  <li>
106
- <?php echo PodsForm::field( 'field_data[' . $pods_i . '][required]', pods_var_raw( 'required', $field, 0 ), 'boolean', array( 'class' => 'pods-dependent-toggle', 'boolean_yes_label' => __( 'Required', 'pods' ), 'help' => __( 'help', 'pods' ) ) ); ?>
107
  </li>
108
  <?php
109
  if ( 'table' == $pod[ 'storage' ] ) {
110
  ?>
111
  <li class="pods-excludes-on pods-excludes-on-field-data-type pods-excludes-on-field-data-type-pick pods-excludes-on-field-data-type-file pods-excludes-on-field-data-type-boolean pods-excludes-on-field-data-type-date pods-excludes-on-field-data-type-datetime pods-excludes-on-field-data-type-time">
112
- <?php echo PodsForm::field( 'field_data[' . $pods_i . '][unique]', pods_var_raw( 'unique', $field, 0 ), 'boolean', array( 'class' => 'pods-dependent-toggle', 'boolean_yes_label' => __( 'Unique', 'pods' ), 'help' => __( 'help', 'pods' ) ) ); ?>
113
  </li>
114
  <?php
115
  }
@@ -187,7 +187,7 @@ $pick_object = trim( pods_var( 'pick_object', $field ) . '-' . pods_var( 'pick_v
187
  <a class="submitdelete deletion" href="#delete-field"><?php _e( 'Delete Field', 'pods' ); ?></a>
188
  </div>
189
  <p class="pods-manage-row-save">
190
- <a class="pods-manage-row-cancel" href="#cancel-edit-field"><?php _e( 'Cancel', 'pods' ); ?></a> &nbsp;&nbsp; <a href="#save-field" class="button-primary pods-button-update"><?php _e( 'Update Field', 'pods' ); ?></a><a href="#save-field" class="button-primary pods-button-add"><?php _e( 'Add Field', 'pods' ); ?></a>
191
  </p>
192
  </div>
193
  </div>
@@ -195,18 +195,18 @@ $pick_object = trim( pods_var( 'pick_object', $field ) . '-' . pods_var( 'pick_v
195
  </div>
196
  </td>
197
  <td class="pods-manage-row-name">
198
- <a title="Edit this field" class="pods-manage-row-edit row-name" href="#edit-field"><?php echo esc_html( pods_var_raw( 'name', $field ) ); ?></a>
199
  </td>
200
  <td class="pods-manage-row-type">
201
  <?php
202
  $type = 'Unknown';
203
 
204
- if ( isset( $field_types[ pods_var( 'type', $field ) ] ) )
205
- $type = $field_types[ pods_var( 'type', $field ) ][ 'label' ];
206
 
207
- echo esc_html( $type ) . ' <span class="pods-manage-row-more">[type: ' . pods_var( 'type', $field ) . ']</span>';
208
 
209
- if ( 'pick' == pods_var( 'type', $field ) && '' != pods_var( 'pick_object', $field, '' ) ) {
210
  $pick_object_name = null;
211
 
212
  foreach ( $field_settings[ 'pick_object' ] as $object => $object_label ) {
@@ -230,7 +230,7 @@ $pick_object = trim( pods_var( 'pick_object', $field ) . '-' . pods_var( 'pick_v
230
  }
231
  }
232
  }
233
- elseif ( pods_var( 'pick_object', $field ) == $object ) {
234
  $pick_object_name = $object_label;
235
 
236
  break;
@@ -238,10 +238,10 @@ $pick_object = trim( pods_var( 'pick_object', $field ) . '-' . pods_var( 'pick_v
238
  }
239
 
240
  if ( null === $pick_object_name ) {
241
- $pick_object_name = ucwords( str_replace( array( '-', '_' ), ' ', pods_var_raw( 'pick_object', $field ) ) );
242
 
243
- if ( 0 < strlen( pods_var_raw( 'pick_val', $field ) ) )
244
- $pick_object_name = pods_var_raw( 'pick_val', $field ) . ' (' . $pick_object_name . ')';
245
  }
246
  ?>
247
  <br /><span class="pods-manage-field-type-desc">&rsaquo; <?php echo $pick_object_name; ?></span>
1
  <?php
2
  $field = array_merge( $field_settings[ 'field_defaults' ], $field );
3
 
4
+ $pick_object = trim( pods_v_sanitized( 'pick_object', $field ) . '-' . pods_v_sanitized( 'pick_val', $field ), '-' );
5
  ?>
6
+ <tr id="row-<?php echo esc_attr( $pods_i ); ?>" class="pods-manage-row pods-field-new pods-field-<?php echo esc_attr( pods_v_sanitized( 'name', $field ) ) . ( '--1' === $pods_i ? ' flexible-row' : ' pods-submittable-fields' ); ?>" valign="top" data-row="<?php echo esc_attr( $pods_i ); ?>">
7
  <th scope="row" class="check-field pods-manage-sort">
8
  <img src="<?php echo esc_url( PODS_URL ); ?>ui/images/handle.gif" alt="<?php esc_attr_e( 'Move', 'pods' ); ?>" />
9
  </th>
60
  <div id="pods-basic-options-<?php echo esc_attr( $pods_i ); ?>" class="pods-tab pods-basic-options">
61
  <div class="pods-field-option">
62
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][label]', __( 'Label', 'pods' ), __( 'help', 'pods' ) ); ?>
63
+ <?php echo PodsForm::field( 'field_data[' . $pods_i . '][label]', pods_v( 'label', $field, '' ), 'text', array( 'class' => 'pods-validate pods-validate-required' ) ); ?>
64
  </div>
65
  <div class="pods-field-option">
66
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][name]', __( 'Name', 'pods' ), __( 'You will use this name to programatically reference this field throughout WordPress', 'pods' ) ); ?>
67
+ <?php echo PodsForm::field( 'field_data[' . $pods_i . '][name]', pods_v( 'name', $field, '' ), 'db', array( 'attributes' => array( 'maxlength' => 50, 'data-sluggable' => 'field_data[' . $pods_i . '][label]' ), 'class' => 'pods-validate pods-validate-required pods-slugged-lower' ) ); ?>
68
  </div>
69
  <div class="pods-field-option">
70
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][description]', __( 'Description', 'pods' ), __( 'help', 'pods' ) ); ?>
71
+ <?php echo PodsForm::field( 'field_data[' . $pods_i . '][description]', pods_v( 'description', $field, '' ), 'text' ); ?>
72
  </div>
73
  <div class="pods-field-option">
74
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][type]', __( 'Field Type', 'pods' ), __( 'help', 'pods' ) ); ?>
75
+ <?php echo PodsForm::field( 'field_data[' . $pods_i . '][type]', pods_v( 'type', $field, '' ), 'pick', array( 'data' => pods_v( 'field_types_select', $field_settings ), 'class' => 'pods-dependent-toggle' ) ); ?>
76
  </div>
77
  <div class="pods-field-option-container pods-depends-on pods-depends-on-field-data-type pods-depends-on-field-data-type-pick">
78
  <div class="pods-field-option">
79
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][pick_object]', __( 'Related To', 'pods' ), __( 'help', 'pods' ) ); ?>
80
+ <?php echo PodsForm::field( 'field_data[' . $pods_i . '][pick_object]', $pick_object, 'pick', array( 'required' => true, 'data' => pods_v( 'pick_object', $field_settings ), 'class' => 'pods-dependent-toggle' ) ); ?>
81
  </div>
82
  <div class="pods-field-option pods-depends-on pods-depends-on-field-data-pick-object pods-depends-on-field-data-pick-object-custom-simple">
83
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][pick_custom]', __( 'Custom Defined Options', 'pods' ), __( 'One option per line, use <em>value|Label</em> for separate values and labels', 'pods' ) ); ?>
84
+ <?php echo PodsForm::field( 'field_data[' . $pods_i . '][pick_custom]', pods_v( 'pick_custom', $field, '' ), 'paragraph' ); ?>
85
  </div>
86
  <div class="pods-field-option pods-depends-on pods-depends-on-field-data-pick-object pods-depends-on-field-data-pick-object-table">
87
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][pick_table]', __( 'Related Table', 'pods' ), __( 'help', 'pods' ) ); ?>
88
+ <?php echo PodsForm::field( 'field_data[' . $pods_i . '][pick_table]', pods_v( 'pick_table', $field, '' ), 'pick', array( 'required' => true, 'data' => pods_v( 'pick_table', $field_settings ) ) ); ?>
89
  </div>
90
  <div class="pods-field-option pods-depends-on pods-depends-on-field-data-pick-object pods-depends-on-field-data-pick-object-<?php echo esc_attr( str_replace( '_', '-', implode( ' pods-depends-on-field-data-pick-object-', $bidirectional_objects ) ) ); ?>" data-dependency-trigger="pods_sister_field">
91
  <?php echo PodsForm::label( 'field_data[' . $pods_i . '][sister_id]', __( 'Bi-directional Field', 'pods' ), __( 'Bi-directional fields will update their related field for any item you select. This feature is only available for two relationships between two Pods.<br /><br />For example, when you update a Parent pod item to relate to a Child item, when you go to edit that Child item you will see the Parent pod item selected.', 'pods' ) ); ?>
92
 
93
  <div class="pods-sister-field">
94
+ <?php echo PodsForm::field( 'field_data[' . $pods_i . '][sister_id]', pods_v( 'sister_id', $field, '' ), 'text' ); ?>
95
  </div>
96
  </div>
97
  </div>
103
  <div class="pods-pick-values pods-pick-checkbox">
104
  <ul>
105
  <li>
106
+ <?php echo PodsForm::field( 'field_data[' . $pods_i . '][required]', pods_v( 'required', $field, 0 ), 'boolean', array( 'class' => 'pods-dependent-toggle', 'boolean_yes_label' => __( 'Required', 'pods' ), 'help' => __( 'help', 'pods' ) ) ); ?>
107
  </li>
108
  <?php
109
  if ( 'table' == $pod[ 'storage' ] ) {
110
  ?>
111
  <li class="pods-excludes-on pods-excludes-on-field-data-type pods-excludes-on-field-data-type-pick pods-excludes-on-field-data-type-file pods-excludes-on-field-data-type-boolean pods-excludes-on-field-data-type-date pods-excludes-on-field-data-type-datetime pods-excludes-on-field-data-type-time">
112
+ <?php echo PodsForm::field( 'field_data[' . $pods_i . '][unique]', pods_v( 'unique', $field, 0 ), 'boolean', array( 'class' => 'pods-dependent-toggle', 'boolean_yes_label' => __( 'Unique', 'pods' ), 'help' => __( 'help', 'pods' ) ) ); ?>
113
  </li>
114
  <?php
115
  }
187
  <a class="submitdelete deletion" href="#delete-field"><?php _e( 'Delete Field', 'pods' ); ?></a>
188
  </div>
189
  <p class="pods-manage-row-save">
190
+ <a class="pods-manage-row-cancel" href="#cancel-edit-field"><?php _e( 'Cancel', 'pods' ); ?></a> &nbsp;&nbsp; <a href="#save-field" class="button-primary pods-button-update"><?php _e( 'Update Field', 'pods' ); ?></a><a href="#save-field" class="button-primary pods-button-add"><?php _e( 'Save Field', 'pods' ); ?></a>
191
  </p>
192
  </div>
193
  </div>
195
  </div>
196
  </td>
197
  <td class="pods-manage-row-name">
198
+ <a title="Edit this field" class="pods-manage-row-edit row-name" href="#edit-field"><?php echo esc_html( pods_v( 'name', $field ) ); ?></a>
199
  </td>
200
  <td class="pods-manage-row-type">
201
  <?php
202
  $type = 'Unknown';
203
 
204
+ if ( isset( $field_types[ pods_v_sanitized( 'type', $field ) ] ) )
205
+ $type = $field_types[ pods_v_sanitized( 'type', $field ) ][ 'label' ];
206
 
207
+ echo esc_html( $type ) . ' <span class="pods-manage-row-more">[type: ' . pods_v_sanitized( 'type', $field ) . ']</span>';
208
 
209
+ if ( 'pick' == pods_v_sanitized( 'type', $field ) && '' != pods_v_sanitized( 'pick_object', $field, '' ) ) {
210
  $pick_object_name = null;
211
 
212
  foreach ( $field_settings[ 'pick_object' ] as $object => $object_label ) {
230
  }
231
  }
232
  }
233
+ elseif ( pods_v_sanitized( 'pick_object', $field ) == $object ) {
234
  $pick_object_name = $object_label;
235
 
236
  break;
238
  }
239
 
240
  if ( null === $pick_object_name ) {
241
+ $pick_object_name = ucwords( str_replace( array( '-', '_' ), ' ', pods_v( 'pick_object', $field ) ) );
242
 
243
+ if ( 0 < strlen( pods_v( 'pick_val', $field ) ) )
244
+ $pick_object_name = pods_v( 'pick_val', $field ) . ' (' . $pick_object_name . ')';
245
  }
246
  ?>
247
  <br /><span class="pods-manage-field-type-desc">&rsaquo; <?php echo $pick_object_name; ?></span>
ui/admin/setup-edit-field.php CHANGED
@@ -2,7 +2,7 @@
2
  $field = array_merge( $field_settings[ 'field_defaults' ], $field );
3
 
4
  // Migrate pick object when saving
5
- if ( 'pod' == pods_var( 'pick_object', $field ) ) {
6
  if ( isset( PodsMeta::$post_types[ $field[ 'pick_val' ] ] ) )
7
  $field[ 'pick_object' ] = 'post_type';
8
  elseif ( isset( PodsMeta::$taxonomies[ $field[ 'pick_val' ] ] ) )
@@ -23,9 +23,9 @@
23
 
24
  $ignored_pick_objects = apply_filters( '', array( 'table' ) );
25
 
26
- if ( !in_array( pods_var( 'pick_object', $field ), $ignored_pick_objects ) ) {
27
  // Set pick object
28
- $field[ 'pick_object' ] = trim( pods_var( 'pick_object', $field ) . '-' . pods_var( 'pick_val', $field ), '-' );
29
  }
30
 
31
  // Unset pick_val for the field to be used above
@@ -43,20 +43,20 @@
43
  'row' => $pods_i
44
  );
45
  ?>
46
- <tr id="row-<?php echo esc_attr( $pods_i ); ?>" class="pods-manage-row pods-field-init pods-field-<?php echo esc_attr( pods_var( 'name', $field ) ) . ( '--1' === $pods_i ? ' flexible-row' : ' pods-submittable-fields' ); ?>" valign="top"<?php PodsForm::data( $data ); ?>>
47
  <th scope="row" class="check-field pods-manage-sort">
48
  <img src="<?php echo esc_url( PODS_URL ); ?>ui/images/handle.gif" alt="<?php esc_attr_e( 'Move', 'pods' ); ?>" />
49
  </th>
50
  <td class="pods-manage-row-label">
51
  <strong> <a class="pods-manage-row-edit row-label" title="<?php esc_attr_e( 'Edit this field', 'pods' ); ?>" href="#edit-field">
52
- <?php echo esc_html( pods_var_raw( 'label', $field ) ); ?>
53
- </a> <abbr title="required" class="required<?php echo esc_attr( 1 == pods_var_raw( 'required', $field ) ? '' : ' hidden' ); ?>">*</abbr> </strong>
54
 
55
  <?php
56
- if ( '__1' != pods_var( 'id', $field ) ) {
57
  ?>
58
  <span class="pods-manage-row-more">
59
- [id: <?php echo esc_html( pods_var( 'id', $field ) ); ?>]
60
  </span>
61
  <?php
62
  }
@@ -77,25 +77,25 @@
77
  <input type="hidden" name="field_data_json[<?php echo esc_attr( $pods_i ); ?>]" value="<?php echo esc_attr( ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $field, JSON_UNESCAPED_UNICODE ) : json_encode( $field ) ) ); ?>" class="field_data" />
78
 
79
  <div class="pods-manage-field pods-dependency">
80
- <input type="hidden" name="field_data[<?php echo esc_attr( $pods_i ); ?>][id]" value="<?php echo esc_attr( pods_var_raw( 'id', $field ) ); ?>" />
81
  <div>
82
  </div>
83
  </td>
84
  <td class="pods-manage-row-name">
85
- <a title="Edit this field" class="pods-manage-row-edit row-name" href="#edit-field"><?php echo esc_html( pods_var_raw( 'name', $field ) ); ?></a>
86
  </td>
87
  <td class="pods-manage-row-type">
88
  <?php
89
  $type = 'Unknown';
90
 
91
- if ( isset( $field_types[ pods_var( 'type', $field ) ] ) )
92
- $type = $field_types[ pods_var( 'type', $field ) ][ 'label' ];
93
 
94
- echo esc_html( $type ) . ' <span class="pods-manage-row-more">[type: ' . pods_var( 'type', $field ) . ']</span>';
95
 
96
- $pick_object = trim( pods_var( 'pick_object', $field ) . '-' . pods_var( 'pick_val', $field ), '-' );
97
 
98
- if ( 'pick' == pods_var( 'type', $field ) && '' != pods_var( 'pick_object', $field, '' ) ) {
99
  $pick_object_name = null;
100
 
101
  foreach ( $field_settings[ 'pick_object' ] as $object => $object_label ) {
@@ -121,7 +121,7 @@
121
  }
122
  }
123
  }
124
- elseif ( pods_var( 'pick_object', $field ) == $object ) {
125
  $pick_object_name = $object_label;
126
 
127
  break;
@@ -129,10 +129,10 @@
129
  }
130
 
131
  if ( null === $pick_object_name ) {
132
- $pick_object_name = ucwords( str_replace( array( '-', '_' ), ' ', pods_var_raw( 'pick_object', $field ) ) );
133
 
134
- if ( 0 < strlen( pods_var_raw( 'pick_val', $field ) ) )
135
- $pick_object_name = pods_var_raw( 'pick_val', $field ) . ' (' . $pick_object_name . ')';
136
  }
137
  ?>
138
  <br /><span class="pods-manage-field-type-desc">&rsaquo; <?php echo $pick_object_name; ?></span>
2
  $field = array_merge( $field_settings[ 'field_defaults' ], $field );
3
 
4
  // Migrate pick object when saving
5
+ if ( 'pod' == pods_v_sanitized( 'pick_object', $field ) ) {
6
  if ( isset( PodsMeta::$post_types[ $field[ 'pick_val' ] ] ) )
7
  $field[ 'pick_object' ] = 'post_type';
8
  elseif ( isset( PodsMeta::$taxonomies[ $field[ 'pick_val' ] ] ) )
23
 
24
  $ignored_pick_objects = apply_filters( '', array( 'table' ) );
25
 
26
+ if ( !in_array( pods_v_sanitized( 'pick_object', $field ), $ignored_pick_objects ) ) {
27
  // Set pick object
28
+ $field[ 'pick_object' ] = trim( pods_v_sanitized( 'pick_object', $field ) . '-' . pods_v_sanitized( 'pick_val', $field ), '-' );
29
  }
30
 
31
  // Unset pick_val for the field to be used above
43
  'row' => $pods_i
44
  );
45
  ?>
46
+ <tr id="row-<?php echo esc_attr( $pods_i ); ?>" class="pods-manage-row pods-field-init pods-field-<?php echo esc_attr( pods_v_sanitized( 'name', $field ) ) . ( '--1' === $pods_i ? ' flexible-row' : ' pods-submittable-fields' ); ?>" valign="top"<?php PodsForm::data( $data ); ?>>
47
  <th scope="row" class="check-field pods-manage-sort">
48
  <img src="<?php echo esc_url( PODS_URL ); ?>ui/images/handle.gif" alt="<?php esc_attr_e( 'Move', 'pods' ); ?>" />
49
  </th>
50
  <td class="pods-manage-row-label">
51
  <strong> <a class="pods-manage-row-edit row-label" title="<?php esc_attr_e( 'Edit this field', 'pods' ); ?>" href="#edit-field">
52
+ <?php echo esc_html( pods_v( 'label', $field ) ); ?>
53
+ </a> <abbr title="required" class="required<?php echo esc_attr( 1 == pods_v( 'required', $field ) ? '' : ' hidden' ); ?>">*</abbr> </strong>
54
 
55
  <?php
56
+ if ( '__1' != pods_v_sanitized( 'id', $field ) ) {
57
  ?>
58
  <span class="pods-manage-row-more">
59
+ [id: <?php echo esc_html( pods_v_sanitized( 'id', $field ) ); ?>]
60
  </span>
61
  <?php
62
  }
77
  <input type="hidden" name="field_data_json[<?php echo esc_attr( $pods_i ); ?>]" value="<?php echo esc_attr( ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $field, JSON_UNESCAPED_UNICODE ) : json_encode( $field ) ) ); ?>" class="field_data" />
78
 
79
  <div class="pods-manage-field pods-dependency">
80
+ <input type="hidden" name="field_data[<?php echo esc_attr( $pods_i ); ?>][id]" value="<?php echo esc_attr( pods_v( 'id', $field ) ); ?>" />
81
  <div>
82
  </div>
83
  </td>
84
  <td class="pods-manage-row-name">
85
+ <a title="Edit this field" class="pods-manage-row-edit row-name" href="#edit-field"><?php echo esc_html( pods_v( 'name', $field ) ); ?></a>
86
  </td>
87
  <td class="pods-manage-row-type">
88
  <?php
89
  $type = 'Unknown';
90
 
91
+ if ( isset( $field_types[ pods_v_sanitized( 'type', $field ) ] ) )
92
+ $type = $field_types[ pods_v_sanitized( 'type', $field ) ][ 'label' ];
93
 
94
+ echo esc_html( $type ) . ' <span class="pods-manage-row-more">[type: ' . pods_v_sanitized( 'type', $field ) . ']</span>';
95
 
96
+ $pick_object = trim( pods_v_sanitized( 'pick_object', $field ) . '-' . pods_v_sanitized( 'pick_val', $field ), '-' );
97
 
98
+ if ( 'pick' == pods_v_sanitized( 'type', $field ) && '' != pods_v_sanitized( 'pick_object', $field, '' ) ) {
99
  $pick_object_name = null;
100
 
101
  foreach ( $field_settings[ 'pick_object' ] as $object => $object_label ) {
121
  }
122
  }
123
  }
124
+ elseif ( pods_v_sanitized( 'pick_object', $field ) == $object ) {
125
  $pick_object_name = $object_label;
126
 
127
  break;
129
  }
130
 
131
  if ( null === $pick_object_name ) {
132
+ $pick_object_name = ucwords( str_replace( array( '-', '_' ), ' ', pods_v( 'pick_object', $field ) ) );
133
 
134
+ if ( 0 < strlen( pods_v( 'pick_val', $field ) ) )
135
+ $pick_object_name = pods_v( 'pick_val', $field ) . ' (' . $pick_object_name . ')';
136
  }
137
  ?>
138
  <br /><span class="pods-manage-field-type-desc">&rsaquo; <?php echo $pick_object_name; ?></span>
ui/admin/setup-edit.php CHANGED
@@ -5,7 +5,9 @@ $api = pods_api();
5
 
6
  $pod = $api->load_pod( array( 'id' => $obj->id ) );
7
 
8
- if ( 'taxonomy' == $pod[ 'type' ] && 'none' == $pod[ 'storage' ] && 1 == pods_var( 'enable_extra_fields', 'get' ) ) {
 
 
9
  $api->save_pod( array( 'id' => $obj->id, 'storage' => 'table' ) );
10
 
11
  $pod = $api->load_pod( array( 'id' => $obj->id ) );
@@ -34,9 +36,9 @@ foreach ( $field_types as $type => $field_type_data ) {
34
  if ( true !== $field_type_vars[ 'pod_types' ] ) {
35
  if ( empty( $field_type_vars[ 'pod_types' ] ) )
36
  continue;
37
- elseif ( is_array( $field_type_vars[ 'pod_types' ] ) && !in_array( pods_var( 'type', $pod ), $field_type_vars[ 'pod_types' ] ) )
38
  continue;
39
- elseif ( !is_array( $field_type_vars[ 'pod_types' ] ) && pods_var( 'type', $pod ) != $field_type_vars[ 'pod_types' ] )
40
  continue;
41
  }
42
 
@@ -134,6 +136,22 @@ foreach ( $field_tab_options[ 'additional-field' ] as $field_type => $field_type
134
  if ( empty( $field_type_fields ) )
135
  $no_additional[] = $field_type;
136
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  ?>
138
  <div class="wrap pods-admin">
139
  <div id="icon-pods" class="icon32"><br /></div>
@@ -146,7 +164,7 @@ foreach ( $field_tab_options[ 'additional-field' ] as $field_type => $field_type
146
  <input type="hidden" name="old_name" value="<?php echo esc_attr( $pod[ 'name' ] ); ?>" />
147
 
148
  <h2>
149
- Edit Pod:
150
  <?php
151
  if ( ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && !empty( $pod[ 'object' ] ) ) || in_array( $pod[ 'type' ], array( 'media', 'user', 'comment' ) ) ) {
152
  ?>
@@ -158,17 +176,17 @@ foreach ( $field_tab_options[ 'additional-field' ] as $field_type => $field_type
158
  <span class="pods-sluggable">
159
  <span class="pods-slug">
160
  <em><?php echo esc_html( $pod[ 'name' ] ); ?></em>
161
- <input type="button" class="edit-slug-button button" value="Edit" />
162
  </span>
163
  <span class="pods-slug-edit">
164
- <?php echo PodsForm::field( 'name', pods_var_raw( 'name', $pod ), 'db', array(
165
  'attributes' => array(
166
  'maxlength' => $max_length_name,
167
  'size' => 25
168
  ),
169
  'class' => 'pods-validate pods-validate-required'
170
  ) ); ?>
171
- <input type="button" class="save-button button" value="OK" /> <a class="cancel" href="#cancel-edit">Cancel</a>
172
  </span>
173
  </span>
174
  <?php
@@ -182,7 +200,7 @@ foreach ( $field_tab_options[ 'additional-field' ] as $field_type => $field_type
182
 
183
  <h2 class="nav-tab-wrapper pods-nav-tabs">
184
  <?php
185
- $default = sanitize_title( pods_var( 'tab', 'get', 'manage-fields', null, true ) );
186
 
187
  if ( !isset( $tabs[ $default ] ) ) {
188
  $tab_keys = array_keys( $tabs );
@@ -217,9 +235,11 @@ foreach ( $field_tab_options[ 'additional-field' ] as $field_type => $field_type
217
  if ( isset( $_GET[ 'do' ] ) ) {
218
  $action = __( 'saved', 'pods' );
219
 
220
- if ( 'create' == pods_var( 'do', 'get', 'save' ) )
 
 
221
  $action = __( 'created', 'pods' );
222
- elseif ( 'duplicate' == pods_var( 'do', 'get', 'save' ) )
223
  $action = __( 'duplicated', 'pods' );
224
 
225
  $message = sprintf( __( '<strong>Success!</strong> %s %s successfully.', 'pods' ), $obj->item, $action );
@@ -257,13 +277,13 @@ if ( isset( $_GET[ 'do' ] ) ) {
257
  <span>&nbsp;</span>
258
  </th>
259
  <th scope="col" id="label" class="manage-column field-label">
260
- <span>Label<?php pods_help( __( "<h6>Label</h6>The label is the descriptive name to identify the Pod field.", 'pods' ) ); ?></span>
261
  </th>
262
  <th scope="col" id="machine-name" class="manage-column field-machine-name">
263
- <span>Name<?php pods_help( __( "<h6>Name</h6>The name attribute is what is used to identify and access the Pod field programatically.", 'pods' ) ); ?></span>
264
  </th>
265
  <th scope="col" id="field-type" class="manage-column field-field-type">
266
- <span>Field Type<?php pods_help( __( "<h6>Field Types</h6>Field types are used to determine what kind of data will be stored in the Pod. They can range from, dates, text, files, etc.", 'pods' ) ); ?></span>
267
  </th>
268
  </tr>
269
  </thead>
@@ -273,13 +293,13 @@ if ( isset( $_GET[ 'do' ] ) ) {
273
  <span>&nbsp;</span>
274
  </th>
275
  <th scope="col" class="manage-column field-label">
276
- <span>Label<?php pods_help( __( "<h6>Label</h6>The label is the descriptive name to identify the Pod field.", 'pods' ) ); ?></span>
277
  </th>
278
  <th scope="col" class="manage-column field-machine-name">
279
- <span>Name<?php pods_help( __( "<h6>Name</h6>The name attribute is what is used to identify and access the Pod field programatically.", 'pods' ) ); ?></span>
280
  </th>
281
  <th scope="col" class="manage-column field-field-type">
282
- <span>Field Type<?php pods_help( __( "<h6>Field Types</h6>Field types are used to determine what kind of data will be stored in the Pod. They can range from, dates, text, files, etc.", 'pods' ) ); ?></span>
283
  </th>
284
  </tr>
285
  </tfoot>
@@ -306,7 +326,7 @@ if ( isset( $_GET[ 'do' ] ) ) {
306
  }
307
  ?>
308
  <tr class="no-items<?php echo esc_attr( 1 < $pods_i ? ' hidden' : '' ); ?>">
309
- <td class="colspanchange" colspan="4">No fields have been added yet</td>
310
  </tr>
311
  </tbody>
312
  </table>
@@ -324,141 +344,13 @@ if ( isset( $_GET[ 'do' ] ) ) {
324
  ?>
325
  <div id="pods-labels" class="pods-nav-tab pods-manage-field pods-dependency pods-submittable-fields">
326
  <?php
327
- if ( strlen( pods_var( 'object', $pod ) ) < 1 && 'settings' != pods_var( 'type', $pod ) ) {
328
- ?>
329
- <div class="pods-field-option">
330
- <?php echo PodsForm::label( 'label', __( 'Label', 'pods' ), __( 'help', 'pods' ) ); ?>
331
- <?php echo PodsForm::field( 'label', pods_var_raw( 'label', $pod ), 'text', array( 'text_max_length' => 30 ) ); ?>
332
- </div>
333
- <div class="pods-field-option">
334
- <?php echo PodsForm::label( 'label_singular', __( 'Singular Label', 'pods' ), __( 'help', 'pods' ) ); ?>
335
- <?php echo PodsForm::field( 'label_singular', pods_var_raw( 'label_singular', $pod, pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', pods_var_raw( 'name', $pod ) ) ) ) ), 'text', array( 'text_max_length' => 30 ) ); ?>
336
- </div>
337
- <div class="pods-field-option">
338
- <?php echo PodsForm::label( 'label_add_new', __( 'Add New', 'pods' ), __( 'help', 'pods' ) ); ?>
339
- <?php echo PodsForm::field( 'label_add_new', pods_var_raw( 'label_add_new', $pod ), 'text' ); ?>
340
- </div>
341
- <div class="pods-field-option">
342
- <?php echo PodsForm::label( 'label_add_new_item', __( 'Add New <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), __( 'help', 'pods' ) ); ?>
343
- <?php echo PodsForm::field( 'label_add_new_item', pods_var_raw( 'label_add_new_item', $pod ), 'text' ); ?>
344
- </div>
345
- <div class="pods-field-option">
346
- <?php echo PodsForm::label( 'label_new_item', __( 'New <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), __( 'help', 'pods' ) ); ?>
347
- <?php echo PodsForm::field( 'label_new_item', pods_var_raw( 'label_new_item', $pod ), 'text' ); ?>
348
- </div>
349
- <div class="pods-field-option">
350
- <?php echo PodsForm::label( 'label_edit', __( 'Edit', 'pods' ), __( 'help', 'pods' ) ); ?>
351
- <?php echo PodsForm::field( 'label_edit', pods_var_raw( 'label_edit', $pod ), 'text' ); ?>
352
- </div>
353
- <div class="pods-field-option">
354
- <?php echo PodsForm::label( 'label_edit_item', __( 'Edit <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), __( 'help', 'pods' ) ); ?>
355
- <?php echo PodsForm::field( 'label_edit_item', pods_var_raw( 'label_edit_item', $pod ), 'text' ); ?>
356
- </div>
357
- <div class="pods-field-option">
358
- <?php echo PodsForm::label( 'label_update_item', __( 'Update <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), __( 'help', 'pods' ) ); ?>
359
- <?php echo PodsForm::field( 'label_update_item', pods_var_raw( 'label_update_item', $pod ), 'text' ); ?>
360
- </div>
361
- <div class="pods-field-option">
362
- <?php echo PodsForm::label( 'label_view', __( 'View', 'pods' ), __( 'help', 'pods' ) ); ?>
363
- <?php echo PodsForm::field( 'label_view', pods_var_raw( 'label_view', $pod ), 'text' ); ?>
364
- </div>
365
- <div class="pods-field-option">
366
- <?php echo PodsForm::label( 'label_view_item', __( 'View <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), __( 'help', 'pods' ) ); ?>
367
- <?php echo PodsForm::field( 'label_view_item', pods_var_raw( 'label_view_item', $pod ), 'text' ); ?>
368
- </div>
369
- <div class="pods-field-option">
370
- <?php echo PodsForm::label( 'label_all_items', __( 'All <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ), __( 'help', 'pods' ) ); ?>
371
- <?php echo PodsForm::field( 'label_all_items', pods_var_raw( 'label_all_items', $pod ), 'text' ); ?>
372
- </div>
373
- <div class="pods-field-option">
374
- <?php echo PodsForm::label( 'label_search_items', __( 'Search <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ), __( 'help', 'pods' ) ); ?>
375
- <?php echo PodsForm::field( 'label_search_items', pods_var_raw( 'label_search_items', $pod ), 'text' ); ?>
376
- </div>
377
- <div class="pods-field-option">
378
- <?php echo PodsForm::label( 'label_not_found', __( 'Not Found', 'pods' ), __( 'help', 'pods' ) ); ?>
379
- <?php echo PodsForm::field( 'label_not_found', pods_var_raw( 'label_not_found', $pod ), 'text' ); ?>
380
- </div>
381
- <div class="pods-field-option">
382
- <?php echo PodsForm::label( 'label_feature_image', __( 'Featured Image', 'pods' ), __( 'help', 'pods' ) ); ?>
383
- <?php echo PodsForm::field( 'label_feature_image', pods_var_raw( 'label_feature_image', $pod ), 'text' ); ?>
384
- </div>
385
- <div class="pods-field-option">
386
- <?php echo PodsForm::label( 'label_set_featured_image', __( 'Set featured image', 'pods' ), __( 'help', 'pods' ) ); ?>
387
- <?php echo PodsForm::field( 'label_set_featured_image', pods_var_raw( 'label_set_featured_image', $pod ), 'text' ); ?>
388
- </div>
389
- <div class="pods-field-option">
390
- <?php echo PodsForm::label( 'label_remove_featured_image', __( 'Remove featured image', 'pods' ), __( 'help', 'pods' ) ); ?>
391
- <?php echo PodsForm::field( 'label_remove_featured_image', pods_var_raw( 'label_remove_featured_image', $pod ), 'text' ); ?>
392
- </div>
393
- <div class="pods-field-option">
394
- <?php echo PodsForm::label( 'label_use_featured_image', __( 'Use as featured image', 'pods' ), __( 'help', 'pods' ) ); ?>
395
- <?php echo PodsForm::field( 'label_use_featured_image', pods_var_raw( 'label_use_featured_image', $pod ), 'text' ); ?>
396
- </div>
397
- <div class="pods-field-option">
398
- <?php echo PodsForm::label( 'label_archives', __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Archives', 'pods' ), __( 'help', 'pods' ) ); ?>
399
- <?php echo PodsForm::field( 'label_archives', pods_var_raw( 'label_archives', $pod ), 'text' ); ?>
400
- </div>
401
- <div class="pods-field-option">
402
- <?php echo PodsForm::label( 'label_insert_into_item', __( 'Insert into <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), __( 'help', 'pods' ) ); ?>
403
- <?php echo PodsForm::field( 'label_insert_into_item', pods_var_raw( 'label_insert_into_item', $pod ), 'text' ); ?>
404
- </div>
405
- <div class="pods-field-option">
406
- <?php echo PodsForm::label( 'label_uploaded_to_this_item', __( 'Uploaded to this <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), __( 'help', 'pods' ) ); ?>
407
- <?php echo PodsForm::field( 'label_uploaded_to_this_item', pods_var_raw( 'label_uploaded_to_this_item', $pod ), 'text' ); ?>
408
- </div>
409
- <div class="pods-field-option">
410
- <?php echo PodsForm::label( 'label_filter_items_list', __( 'Filter <span class="pods-slugged" data-sluggable="label">Items</span> lists', 'pods' ), __( 'help', 'pods' ) ); ?>
411
- <?php echo PodsForm::field( 'label_filter_items_list', pods_var_raw( 'label_filter_items_list', $pod ), 'text' ); ?>
412
- </div>
413
- <div class="pods-field-option">
414
- <?php echo PodsForm::label( 'label_items_list_navigation', __( '<span class="pods-slugged" data-sluggable="label">Items</span> list navigation', 'pods' ), __( 'help', 'pods' ) ); ?>
415
- <?php echo PodsForm::field( 'label_items_list_navigation', pods_var_raw( 'label_items_list_navigation', $pod ), 'text' ); ?>
416
- </div>
417
- <div class="pods-field-option">
418
- <?php echo PodsForm::label( 'label_items_list', __( '<span class="pods-slugged" data-sluggable="label">Items</span> list', 'pods' ), __( 'help', 'pods' ) ); ?>
419
- <?php echo PodsForm::field( 'label_items_list', pods_var_raw( 'label_items_list', $pod ), 'text' ); ?>
420
- </div>
421
- <?php
422
- if ( in_array( pods_var( 'type', $pod ), array( 'post_type', 'pod' ) ) ) {
423
- ?>
424
- <div class="pods-field-option">
425
- <?php echo PodsForm::label( 'label_not_found_in_trash', __( 'Not Found in Trash', 'pods' ), __( 'help', 'pods' ) ); ?>
426
- <?php echo PodsForm::field( 'label_not_found_in_trash', pods_var_raw( 'label_not_found_in_trash', $pod ), 'text' ); ?>
427
- </div>
428
- <?php
429
- }
430
- ?>
431
 
432
- <div class="pods-field-option">
433
- <?php echo PodsForm::label( 'label_popular_items', __( 'Popular <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ), __( 'help', 'pods' ) ); ?>
434
- <?php echo PodsForm::field( 'label_popular_items', pods_var_raw( 'label_popular_items', $pod ), 'text' ); ?>
435
- </div>
436
- <div class="pods-field-option">
437
- <?php echo PodsForm::label( 'label_separate_items_with_commas', __( 'Separate <span class="pods-slugged-lower" data-sluggable="label">items</span> with commas', 'pods' ), __( 'help', 'pods' ) ); ?>
438
- <?php echo PodsForm::field( 'label_separate_items_with_commas', pods_var_raw( 'label_separate_items_with_commas', $pod ), 'text' ); ?>
439
- </div>
440
- <div class="pods-field-option">
441
- <?php echo PodsForm::label( 'label_add_or_remove_items', __( 'Add or remove <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ), __( 'help', 'pods' ) ); ?>
442
- <?php echo PodsForm::field( 'label_add_or_remove_items', pods_var_raw( 'label_add_or_remove_items', $pod ), 'text' ); ?>
443
- </div>
444
- <div class="pods-field-option">
445
- <?php echo PodsForm::label( 'label_choose_from_the_most_used', __( 'Choose from the most used', 'pods' ), __( 'help', 'pods' ) ); ?>
446
- <?php echo PodsForm::field( 'label_choose_from_the_most_used', pods_var_raw( 'label_choose_from_the_most_used', $pod ), 'text' ); ?>
447
- </div>
448
- <?php
449
- }
450
- elseif ( 'settings' == pods_var( 'type', $pod ) ) {
451
- ?>
452
- <div class="pods-field-option">
453
- <?php echo PodsForm::label( 'label', __( 'Page Title', 'pods' ), __( 'help', 'pods' ) ); ?>
454
- <?php echo PodsForm::field( 'label', pods_var_raw( 'label', $pod ), 'text', array( 'text_max_length' => 30 ) ); ?>
455
- </div>
456
- <div class="pods-field-option">
457
- <?php echo PodsForm::label( 'menu_name', __( 'Menu Name', 'pods' ), __( 'help', 'pods' ) ); ?>
458
- <?php echo PodsForm::field( 'menu_name', pods_var_raw( 'menu_name', $pod, pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', pods_var_raw( 'name', $pod ) ) ) ) ), 'text', array( 'text_max_length' => 30 ) ); ?>
459
- </div>
460
- <?php
461
- }
462
  ?>
463
  </div>
464
  <?php
@@ -468,7 +360,7 @@ if ( isset( $tabs[ 'advanced' ] ) ) {
468
  ?>
469
  <div id="pods-advanced" class="pods-nav-tab pods-manage-field pods-dependency pods-submittable-fields">
470
  <?php
471
- if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) {
472
  $fields = $tab_options[ 'advanced' ];
473
  $field_options = PodsForm::fields_setup( $fields );
474
  $field = $pod;
@@ -484,74 +376,74 @@ if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod
484
  <ul>
485
  <li>
486
  <div class="pods-field pods-boolean">
487
- <?php echo PodsForm::field( 'supports_title', pods_var_raw( 'supports_title', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Title', 'pods' ) ) ); ?>
488
  </div>
489
  </li>
490
  <li>
491
  <div class="pods-field pods-boolean">
492
- <?php echo PodsForm::field( 'supports_editor', pods_var_raw( 'supports_editor', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Editor', 'pods' ) ) ); ?>
493
  </div>
494
  </li>
495
  <li>
496
  <div class="pods-field pods-boolean">
497
- <?php echo PodsForm::field( 'supports_author', pods_var_raw( 'supports_author', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Author', 'pods' ) ) ); ?>
498
  </div>
499
  </li>
500
  <li>
501
  <div class="pods-field pods-boolean">
502
- <?php echo PodsForm::field( 'supports_thumbnail', pods_var_raw( 'supports_thumbnail', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Featured Image', 'pods' ) ) ); ?>
503
  </div>
504
  </li>
505
  <li>
506
  <div class="pods-field pods-boolean">
507
- <?php echo PodsForm::field( 'supports_excerpt', pods_var_raw( 'supports_excerpt', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Excerpt', 'pods' ) ) ); ?>
508
  </div>
509
  </li>
510
  <li>
511
  <div class="pods-field pods-boolean">
512
- <?php echo PodsForm::field( 'supports_trackbacks', pods_var_raw( 'supports_trackbacks', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Trackbacks', 'pods' ) ) ); ?>
513
  </div>
514
  </li>
515
  <li>
516
  <div class="pods-field pods-boolean">
517
- <?php echo PodsForm::field( 'supports_custom_fields', pods_var_raw( 'supports_custom_fields', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Custom Fields', 'pods' ) ) ); ?>
518
  </div>
519
  </li>
520
  <li>
521
  <div class="pods-field pods-boolean">
522
- <?php echo PodsForm::field( 'supports_comments', pods_var_raw( 'supports_comments', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Comments', 'pods' ) ) ); ?>
523
  </div>
524
  </li>
525
  <li>
526
  <div class="pods-field pods-boolean">
527
- <?php echo PodsForm::field( 'supports_revisions', pods_var_raw( 'supports_revisions', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Revisions', 'pods' ) ) ); ?>
528
  </div>
529
  </li>
530
  <li>
531
  <div class="pods-field pods-boolean">
532
- <?php echo PodsForm::field( 'supports_page_attributes', pods_var_raw( 'supports_page_attributes', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Page Attributes', 'pods' ) ) ); ?>
533
  </div>
534
  </li>
535
  <li>
536
  <div class="pods-field pods-boolean">
537
- <?php echo PodsForm::field( 'supports_post_formats', pods_var_raw( 'supports_post_formats', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Post Formats', 'pods' ) ) ); ?>
538
  </div>
539
  </li>
540
 
541
  <?php if ( function_exists( 'genesis' ) ) { ?>
542
  <li>
543
  <div class="pods-field pods-boolean">
544
- <?php echo PodsForm::field( 'supports_genesis_seo', pods_var_raw( 'supports_genesis_seo', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Genesis: SEO', 'pods' ) ) ); ?>
545
  </div>
546
  </li>
547
  <li>
548
  <div class="pods-field pods-boolean">
549
- <?php echo PodsForm::field( 'supports_genesis_layouts', pods_var_raw( 'supports_genesis_layouts', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Genesis: Layouts', 'pods' ) ) ); ?>
550
  </div>
551
  </li>
552
  <li>
553
  <div class="pods-field pods-boolean">
554
- <?php echo PodsForm::field( 'supports_genesis_simple_sidebars', pods_var_raw( 'supports_genesis_simple_sidebars', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Genesis: Simple Sidebars', 'pods' ) ) ); ?>
555
  </div>
556
  </li>
557
  <?php } ?>
@@ -559,7 +451,7 @@ if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod
559
  <?php if ( defined( 'YARPP_VERSION' ) ) { ?>
560
  <li>
561
  <div class="pods-field pods-boolean">
562
- <?php echo PodsForm::field( 'supports_yarpp_support', pods_var_raw( 'supports_yarpp_support', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'YARPP Support', 'pods' ) ) ); ?>
563
  </div>
564
  </li>
565
  <?php } ?>
@@ -567,12 +459,12 @@ if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod
567
  <?php if ( class_exists( 'Jetpack' ) ) { ?>
568
  <li>
569
  <div class="pods-field pods-boolean">
570
- <?php echo PodsForm::field( 'supports_jetpack_publicize', pods_var_raw( 'supports_jetpack_publicize', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Jetpack Publicize Support', 'pods' ) ) ); ?>
571
  </div>
572
  </li>
573
  <li>
574
  <div class="pods-field pods-boolean">
575
- <?php echo PodsForm::field( 'supports_jetpack_markdown', pods_var_raw( 'supports_jetpack_markdown', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Jetpack Markdown Support', 'pods' ) ) ); ?>
576
  </div>
577
  </li>
578
  <?php } ?>
@@ -581,7 +473,7 @@ if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod
581
  </div>
582
  <div class="pods-field-option">
583
  <?php echo PodsForm::label( 'supports_custom', __( 'Advanced Supports', 'pods' ), __( 'Comma-separated list of custom "supports" values to pass to register_post_type.', 'pods' ) ); ?>
584
- <?php echo PodsForm::field( 'supports_custom', pods_var_raw( 'supports_custom', $pod, '' ), 'text' ); ?>
585
  </div>
586
  <div class="pods-field-option-group">
587
  <p class="pods-field-option-group-label">
@@ -596,7 +488,7 @@ if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod
596
  ?>
597
  <li>
598
  <div class="pods-field pods-boolean">
599
- <?php echo PodsForm::field( 'built_in_taxonomies_' . $taxonomy, pods_var_raw( 'built_in_taxonomies_' . $taxonomy, $pod, false ), 'boolean', array( 'boolean_yes_label' => $label . ' <small>(' . $taxonomy . ')</small>' ) ); ?>
600
  </div>
601
  </li>
602
  <?php
@@ -607,7 +499,7 @@ if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod
607
  </div>
608
  <?php
609
  }
610
- elseif ( 'taxonomy' == pods_v_sanitized( 'type', $pod ) && strlen( pods_v_sanitized( 'object', $pod ) ) < 1 ) {
611
  $fields = $tab_options[ 'advanced' ];
612
  $field_options = PodsForm::fields_setup( $fields );
613
  $field = $pod;
@@ -628,34 +520,27 @@ elseif ( 'taxonomy' == pods_v_sanitized( 'type', $pod ) && strlen( pods_v_saniti
628
  ?>
629
  <li>
630
  <div class="pods-field pods-boolean">
631
- <?php echo PodsForm::field( 'built_in_post_types_' . $post_type, pods_var_raw( 'built_in_post_types_' . $post_type, $pod, false ), 'boolean', array( 'boolean_yes_label' => $label ) ); ?>
632
- </div>
633
- </li>
634
- <?php
635
- }
636
- ?>
637
-
638
- <?php
639
- if ( pods_version_check( 'wp', '3.5' ) ) {
640
- ?>
641
- <li>
642
- <div class="pods-field pods-boolean">
643
- <?php echo PodsForm::field( 'built_in_post_types_attachment', pods_var_raw( 'built_in_post_types_attachment', $pod, false ), 'boolean', array( 'boolean_yes_label' => 'Media <small>(attachment)</small>' ) ); ?>
644
  </div>
645
  </li>
646
  <?php
647
  }
648
  ?>
 
 
 
 
 
649
  </ul>
650
  </div>
651
  </div>
652
  <?php
653
  }
654
- elseif ( 'pod' == pods_var( 'type', $pod ) ) {
655
  ?>
656
  <div class="pods-field-option">
657
  <?php echo PodsForm::label( 'detail_url', __( 'Detail Page URL', 'pods' ), __( 'help', 'pods' ) ); ?>
658
- <?php echo PodsForm::field( 'detail_url', pods_var_raw( 'detail_url', $pod ), 'text' ); ?>
659
  </div>
660
 
661
  <?php
@@ -669,19 +554,19 @@ elseif ( 'pod' == pods_var( 'type', $pod ) ) {
669
 
670
  <div class="pods-field-option">
671
  <?php echo PodsForm::label( 'pod_index', __( 'Title Field', 'pods' ), __( 'If you delete the "name" field, we need to specify the field to use as your primary title field. This field will serve as an index of your content. Most commonly this field represents the name of a person, place, thing, or a summary field.', 'pods' ) ); ?>
672
- <?php echo PodsForm::field( 'pod_index', pods_var_raw( 'pod_index', $pod, 'name' ), 'pick', array( 'data' => $index_fields ) ); ?>
673
  </div>
674
 
675
  <div class="pods-field-option">
676
  <?php echo PodsForm::label( 'hierarchical', __( 'Hierarchical', 'pods' ), __( 'help', 'pods' ) ); ?>
677
- <?php echo PodsForm::field( 'hierarchical', (int) pods_var_raw( 'hierarchical', $pod, 0 ), 'boolean', array( 'dependency' => true, 'boolean_yes_label' => '' ) ); ?>
678
  </div>
679
 
680
  <?php
681
  $hierarchical_fields = array();
682
 
683
  foreach ( $pod[ 'fields' ] as $field ) {
684
- if ( 'pick' == $field[ 'type' ] && 'pod' == pods_var( 'pick_object', $field ) && $pod[ 'name' ] == pods_var( 'pick_val', $field ) && 'single' == pods_var( 'pick_format_type', $field[ 'options' ] ) )
685
  $hierarchical_fields[ $field[ 'name' ] ] = $field[ 'label' ];
686
  }
687
 
@@ -691,7 +576,7 @@ elseif ( 'pod' == pods_var( 'type', $pod ) ) {
691
 
692
  <div class="pods-field-option pods-depends-on pods-depends-on-hierarchical">
693
  <?php echo PodsForm::label( 'pod_parent', __( 'Hierarchical Field', 'pods' ), __( 'help', 'pods' ) ); ?>
694
- <?php echo PodsForm::field( 'pod_parent', pods_var_raw( 'pod_parent', $pod, 'name' ), 'pick', array( 'data' => $hierarchical_fields ) ); ?>
695
  </div>
696
 
697
  <?php
@@ -709,7 +594,7 @@ elseif ( 'pod' == pods_var( 'type', $pod ) ) {
709
  }
710
 
711
  echo PodsForm::label( 'pre_save_helpers', __( 'Pre-Save Helper(s)', 'pods' ), __( 'help', 'pods' ) );
712
- echo PodsForm::field( 'pre_save_helpers', pods_var_raw( 'pre_save_helpers', $pod ), 'pick', array( 'data' => $pre_save_helpers ) );
713
  ?>
714
  </div>
715
  <div class="pods-field-option">
@@ -723,7 +608,7 @@ elseif ( 'pod' == pods_var( 'type', $pod ) ) {
723
  }
724
 
725
  echo PodsForm::label( 'post_save_helpers', __( 'Post-Save Helper(s)', 'pods' ), __( 'help', 'pods' ) );
726
- echo PodsForm::field( 'post_save_helpers', pods_var_raw( 'post_save_helpers', $pod ), 'pick', array( 'data' => $post_save_helpers ) );
727
  ?>
728
  </div>
729
  <div class="pods-field-option">
@@ -737,7 +622,7 @@ elseif ( 'pod' == pods_var( 'type', $pod ) ) {
737
  }
738
 
739
  echo PodsForm::label( 'pre_delete_helpers', __( 'Pre-Delete Helper(s)', 'pods' ), __( 'help', 'pods' ) );
740
- echo PodsForm::field( 'pre_delete_helpers', pods_var_raw( 'pre_delete_helpers', $pod ), 'pick', array( 'data' => $pre_delete_helpers ) );
741
  ?>
742
  </div>
743
  <div class="pods-field-option">
@@ -751,7 +636,7 @@ elseif ( 'pod' == pods_var( 'type', $pod ) ) {
751
  }
752
 
753
  echo PodsForm::label( 'post_delete_helpers', __( 'Post-Delete Helper(s)', 'pods' ), __( 'help', 'pods' ) );
754
- echo PodsForm::field( 'post_delete_helpers', pods_var_raw( 'post_delete_helpers', $pod ), 'pick', array( 'data' => $post_delete_helpers ) );
755
  ?>
756
  </div>
757
  <?php
@@ -785,9 +670,9 @@ if ( isset( $tabs[ 'extra-fields' ] ) ) {
785
  <div id="pods-extra-fields" class="pods-nav-tab">
786
  <p><?php _e( 'Taxonomies do not support extra fields natively, but Pods can add this feature for you easily. Table based storage will operate in a way where each field you create for your content type becomes a field in a table.', 'pods' ); ?></p>
787
 
788
- <p><?php echo sprintf( __( 'Enabling extra fields for this taxonomy will add a custom table into your database as <em>%s</em>.', 'pods' ), $wpdb->prefix . 'pods_' . pods_var( 'name', $pod ) ); ?></p>
789
 
790
- <p><a href="http://pods.io/docs/comparisons/compare-storage-types/" target="_blank"><?php _e( 'Find out more', 'pods' ); ?> &raquo;</a></p>
791
 
792
  <p class="submit">
793
  <a href="<?php echo esc_url( pods_query_arg( array( 'enable_extra_fields' => 1 ) ) ); ?>" class="button-primary"><?php _e( 'Enable Extra Fields', 'pods' ); ?></a>
@@ -803,7 +688,7 @@ if ( isset( $tabs[ 'extra-fields' ] ) ) {
803
  <div id="side-info-field" class="inner-sidebar">
804
  <div id="side-sortables">
805
  <div id="submitdiv" class="postbox pods-no-toggle">
806
- <h3><span>Manage <small>(<a href="<?php echo esc_url( pods_query_arg( array( 'action' . $obj->num => 'manage', 'id' . $obj->num => '' ) ) ); ?>">&laquo; <?php _e( 'Back to Manage', 'pods' ); ?></a>)
807
  </small></span></h3>
808
  <div class="inside">
809
  <div class="submitbox" id="submitpost">
@@ -813,7 +698,7 @@ if ( isset( $tabs[ 'extra-fields' ] ) ) {
813
  </div>
814
  <div id="publishing-action">
815
  <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
816
- <button class="button-primary" type="submit">Save Pod</button>
817
  </div>
818
  <div class="clear"></div>
819
  </div>
@@ -821,6 +706,9 @@ if ( isset( $tabs[ 'extra-fields' ] ) ) {
821
  </div>
822
  </div>
823
  <!-- /#submitdiv -->
 
 
 
824
  </div>
825
  </div>
826
  </div>
@@ -888,101 +776,148 @@ if ( isset( $tabs[ 'extra-fields' ] ) ) {
888
  var thank_you = '<?php echo pods_slash( pods_query_arg( array( 'do' => 'save' ) ) ); ?>';
889
 
890
  document.location = thank_you.replace( 'X_ID_X', id );
891
- }
892
-
893
- var pods_sister_field_going = {
894
-
895
  };
896
 
 
 
 
897
  var pods_sister_field = function ( $el ) {
 
 
 
898
  var id = $el.closest( 'tr.pods-manage-row' ).data( 'row' );
 
899
 
900
- if ( 'undefined' != typeof pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] && true == pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] )
901
  return;
 
902
 
903
- pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] = true;
904
-
905
- var default_select = '<?php echo str_replace( array( "\n", "\r" ), ' ', PodsForm::field( 'field_data[--1][sister_id]', '', 'pick', array( 'data' => pods_var_raw( 'sister_id', $field_settings ) ) ) ); ?>';
906
- default_select = default_select.replace( /\-\-1/g, id );
907
-
908
- var related_pod_name = jQuery( '#pods-form-ui-field-data-' + id + '-pick-object' ).val();
909
 
910
- if ( 0 != related_pod_name.indexOf( 'pod-' ) && 0 != related_pod_name.indexOf( 'post_type-' ) && 0 != related_pod_name.indexOf( 'taxonomy-' ) && 0 != related_pod_name.indexOf( 'user' ) && 0 != related_pod_name.indexOf( 'media' ) && 0 != related_pod_name.indexOf( 'comment' ) ) {
911
- pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] = false;
 
 
 
 
912
 
 
913
  return;
914
  }
915
 
916
- var selected_value = jQuery( '#pods-form-ui-field-data-' + id + '-sister-id' ).val();
 
 
 
 
 
 
 
 
 
917
 
918
- var select_container = default_select.match( /<select[^<]*>/g );
 
 
 
 
 
 
 
 
 
919
 
920
- $el.find( '.pods-sister-field' ).html( select_container + '<option value=""><?php esc_attr_e( 'Loading available fields..', 'pods' ); ?></option></select>' );
921
 
922
- postdata = {
923
- action : 'pods_admin',
924
- method : 'load_sister_fields',
925
- _wpnonce : '<?php echo esc_js( wp_create_nonce( 'pods-load_sister_fields' ) ); ?>',
926
- pod : '<?php echo esc_js( pods_v( 'name', $pod ) ); ?>',
927
- related_pod : related_pod_name
928
  };
929
 
930
  jQuery.ajax( {
931
- type : 'POST',
932
- dataType : 'html',
933
- url : ajaxurl + '?pods_ajax=1',
934
- cache : false,
935
- data : postdata,
936
  success : function ( d ) {
 
 
 
 
937
  if ( -1 == d.indexOf( '<e>' ) && -1 == d.indexOf('</e>') && -1 != d && '[]' != d ) {
938
- var json = d.match( /{.*}$/ );
939
 
940
- if ( null !== json && 0 < json.length )
 
 
941
  json = jQuery.parseJSON( json[ 0 ] );
942
- else
943
  json = {};
944
-
945
- var select_container = default_select.match( /<select[^<]*>/g );
946
 
947
  if ( 'object' != typeof json || ! jQuery.isEmptyObject( json ) ) {
 
948
  if ( 'object' != typeof json ) {
949
  if ( window.console ) console.log( d );
950
  if ( window.console ) console.log( json );
951
 
952
- select_container += '<option value=""><?php esc_attr_e( 'There was a server error with your AJAX request.', 'pods' ); ?></option>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
953
  }
 
 
954
 
955
- select_container += '<option value=""><?php esc_attr_e( '-- Select Related Field --', 'pods' ); ?></option>';
956
-
957
- for ( var field_id in json ) {
958
- var field_name = json[field_id];
959
-
960
- select_container += '<option value="' + field_id + '">' + field_name + '</option>';
961
- }
962
-
963
- select_container += '</select>';
964
-
965
- $el.find( '.pods-sister-field' ).html( select_container );
966
-
967
- jQuery( '#pods-form-ui-field-data-' + id + '-sister-id' ).val( selected_value );
968
- }
969
- else {
970
  // None found
971
- $el.find( '.pods-sister-field' ).html( default_select );
 
 
 
972
  }
973
- }
974
- else {
975
  // None found
976
- $el.find( '.pods-sister-field' ).html( default_select );
 
 
 
977
  }
978
 
979
- pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] = false;
980
  },
981
  error : function () {
982
  // None found
983
- $el.find( '.pods-sister-field' ).html( default_select );
 
 
 
984
 
985
- pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] = false;
986
  }
987
  } );
988
  }
5
 
6
  $pod = $api->load_pod( array( 'id' => $obj->id ) );
7
 
8
+ $pod_type = pods_v( 'type', $pod );
9
+
10
+ if ( 'taxonomy' == $pod[ 'type' ] && 'none' == $pod[ 'storage' ] && 1 == pods_v( 'enable_extra_fields', 'get' ) ) {
11
  $api->save_pod( array( 'id' => $obj->id, 'storage' => 'table' ) );
12
 
13
  $pod = $api->load_pod( array( 'id' => $obj->id ) );
36
  if ( true !== $field_type_vars[ 'pod_types' ] ) {
37
  if ( empty( $field_type_vars[ 'pod_types' ] ) )
38
  continue;
39
+ elseif ( is_array( $field_type_vars[ 'pod_types' ] ) && !in_array( $pod_type, $field_type_vars[ 'pod_types' ] ) )
40
  continue;
41
+ elseif ( !is_array( $field_type_vars[ 'pod_types' ] ) && $pod_type != $field_type_vars[ 'pod_types' ] )
42
  continue;
43
  }
44
 
136
  if ( empty( $field_type_fields ) )
137
  $no_additional[] = $field_type;
138
  }
139
+
140
+ /**
141
+ * Make use of the WP core meta box functionality
142
+ *
143
+ * Currently only context 'side' is available
144
+ *
145
+ * @since 2.7
146
+ * @see https://codex.wordpress.org/Plugin_API/Action_Reference/add_meta_boxes
147
+ * @param array $pod The Pod object as an array
148
+ */
149
+ do_action( 'pods_add_meta_boxes', '_pods_pod', $pod );
150
+
151
+ $pod_post = get_post( $pod['id'] );
152
+
153
+ /** This action is documented in wp-admin/edit-form-advanced.php */
154
+ do_action( 'add_meta_boxes', $pod_post->post_type, $pod_post );
155
  ?>
156
  <div class="wrap pods-admin">
157
  <div id="icon-pods" class="icon32"><br /></div>
164
  <input type="hidden" name="old_name" value="<?php echo esc_attr( $pod[ 'name' ] ); ?>" />
165
 
166
  <h2>
167
+ <?php esc_html_e( 'Edit Pod', 'pods' ); ?>:
168
  <?php
169
  if ( ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && !empty( $pod[ 'object' ] ) ) || in_array( $pod[ 'type' ], array( 'media', 'user', 'comment' ) ) ) {
170
  ?>
176
  <span class="pods-sluggable">
177
  <span class="pods-slug">
178
  <em><?php echo esc_html( $pod[ 'name' ] ); ?></em>
179
+ <input type="button" class="edit-slug-button button" value="<?php esc_attr_e( 'Edit', 'pods' ); ?>" />
180
  </span>
181
  <span class="pods-slug-edit">
182
+ <?php echo PodsForm::field( 'name', pods_v( 'name', $pod ), 'db', array(
183
  'attributes' => array(
184
  'maxlength' => $max_length_name,
185
  'size' => 25
186
  ),
187
  'class' => 'pods-validate pods-validate-required'
188
  ) ); ?>
189
+ <input type="button" class="save-button button" value="<?php esc_attr_e( 'OK', 'pods' ); ?>" /> <a class="cancel" href="#cancel-edit"><?php esc_html_e( 'Cancel', 'pods' ); ?></a>
190
  </span>
191
  </span>
192
  <?php
200
 
201
  <h2 class="nav-tab-wrapper pods-nav-tabs">
202
  <?php
203
+ $default = sanitize_title( pods_v( 'tab', 'get', 'manage-fields', null, true ) );
204
 
205
  if ( !isset( $tabs[ $default ] ) ) {
206
  $tab_keys = array_keys( $tabs );
235
  if ( isset( $_GET[ 'do' ] ) ) {
236
  $action = __( 'saved', 'pods' );
237
 
238
+ $do = pods_v( 'do', 'get', 'save' );
239
+
240
+ if ( 'create' == $do )
241
  $action = __( 'created', 'pods' );
242
+ elseif ( 'duplicate' ==$do )
243
  $action = __( 'duplicated', 'pods' );
244
 
245
  $message = sprintf( __( '<strong>Success!</strong> %s %s successfully.', 'pods' ), $obj->item, $action );
277
  <span>&nbsp;</span>
278
  </th>
279
  <th scope="col" id="label" class="manage-column field-label">
280
+ <span><?php esc_html_e( 'Label', 'pods' ); pods_help( "<h6>" . __( 'Label', 'pods' ) . "</h6>" . __( 'The label is the descriptive name to identify the Pod field.', 'pods' ) ); ?></span>
281
  </th>
282
  <th scope="col" id="machine-name" class="manage-column field-machine-name">
283
+ <span><?php esc_html_e( 'Name', 'pods' ); pods_help( "<h6>" . __( 'Name', 'pods' ) . "</h6>" . __( 'The name attribute is what is used to identify and access the Pod field programatically.', 'pods' ) ); ?></span>
284
  </th>
285
  <th scope="col" id="field-type" class="manage-column field-field-type">
286
+ <span><?php esc_html_e( 'Field Type', 'pods' ); pods_help( "<h6>" . __( 'Field Type', 'pods' ) . "</h6>" . __( 'Field types are used to determine what kind of data will be stored in the Pod. They can range from, dates, text, files, etc.', 'pods' ) ); ?></span>
287
  </th>
288
  </tr>
289
  </thead>
293
  <span>&nbsp;</span>
294
  </th>
295
  <th scope="col" class="manage-column field-label">
296
+ <span><?php esc_html_e( 'Label', 'pods' ); pods_help( "<h6>" . __( 'Label', 'pods' ) . "</h6>" . __( 'The label is the descriptive name to identify the Pod field.', 'pods' ) ); ?></span>
297
  </th>
298
  <th scope="col" class="manage-column field-machine-name">
299
+ <span><?php esc_html_e( 'Name', 'pods' ); pods_help( "<h6>" . __( 'Name', 'pods' ) . "</h6>" . __( 'The name attribute is what is used to identify and access the Pod field programatically.', 'pods' ) ); ?></span>
300
  </th>
301
  <th scope="col" class="manage-column field-field-type">
302
+ <span><?php esc_html_e( 'Field Type', 'pods' ); pods_help( "<h6>" . __( 'Field Type', 'pods' ) . "</h6>" . __( 'Field types are used to determine what kind of data will be stored in the Pod. They can range from, dates, text, files, etc.', 'pods' ) ); ?></span>
303
  </th>
304
  </tr>
305
  </tfoot>
326
  }
327
  ?>
328
  <tr class="no-items<?php echo esc_attr( 1 < $pods_i ? ' hidden' : '' ); ?>">
329
+ <td class="colspanchange" colspan="4"><?php esc_html_e( 'No fields have been added yet', 'pods' ); ?></td>
330
  </tr>
331
  </tbody>
332
  </table>
344
  ?>
345
  <div id="pods-labels" class="pods-nav-tab pods-manage-field pods-dependency pods-submittable-fields">
346
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
 
348
+ $fields = $tab_options[ 'labels' ];
349
+ $field_options = PodsForm::fields_setup( $fields );
350
+ $field = $pod;
351
+
352
+ include PODS_DIR . 'ui/admin/field-option.php';
353
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  ?>
355
  </div>
356
  <?php
360
  ?>
361
  <div id="pods-advanced" class="pods-nav-tab pods-manage-field pods-dependency pods-submittable-fields">
362
  <?php
363
+ if ( 'post_type' == $pod_type && strlen( pods_v( 'object', $pod ) ) < 1 ) {
364
  $fields = $tab_options[ 'advanced' ];
365
  $field_options = PodsForm::fields_setup( $fields );
366
  $field = $pod;
376
  <ul>
377
  <li>
378
  <div class="pods-field pods-boolean">
379
+ <?php echo PodsForm::field( 'supports_title', pods_v( 'supports_title', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Title', 'pods' ) ) ); ?>
380
  </div>
381
  </li>
382
  <li>
383
  <div class="pods-field pods-boolean">
384
+ <?php echo PodsForm::field( 'supports_editor', pods_v( 'supports_editor', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Editor', 'pods' ) ) ); ?>
385
  </div>
386
  </li>
387
  <li>
388
  <div class="pods-field pods-boolean">
389
+ <?php echo PodsForm::field( 'supports_author', pods_v( 'supports_author', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Author', 'pods' ) ) ); ?>
390
  </div>
391
  </li>
392
  <li>
393
  <div class="pods-field pods-boolean">
394
+ <?php echo PodsForm::field( 'supports_thumbnail', pods_v( 'supports_thumbnail', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Featured Image', 'pods' ), 'dependency' => true ) ); ?>
395
  </div>
396
  </li>
397
  <li>
398
  <div class="pods-field pods-boolean">
399
+ <?php echo PodsForm::field( 'supports_excerpt', pods_v( 'supports_excerpt', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Excerpt', 'pods' ) ) ); ?>
400
  </div>
401
  </li>
402
  <li>
403
  <div class="pods-field pods-boolean">
404
+ <?php echo PodsForm::field( 'supports_trackbacks', pods_v( 'supports_trackbacks', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Trackbacks', 'pods' ) ) ); ?>
405
  </div>
406
  </li>
407
  <li>
408
  <div class="pods-field pods-boolean">
409
+ <?php echo PodsForm::field( 'supports_custom_fields', pods_v( 'supports_custom_fields', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Custom Fields', 'pods' ) ) ); ?>
410
  </div>
411
  </li>
412
  <li>
413
  <div class="pods-field pods-boolean">
414
+ <?php echo PodsForm::field( 'supports_comments', pods_v( 'supports_comments', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Comments', 'pods' ) ) ); ?>
415
  </div>
416
  </li>
417
  <li>
418
  <div class="pods-field pods-boolean">
419
+ <?php echo PodsForm::field( 'supports_revisions', pods_v( 'supports_revisions', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Revisions', 'pods' ) ) ); ?>
420
  </div>
421
  </li>
422
  <li>
423
  <div class="pods-field pods-boolean">
424
+ <?php echo PodsForm::field( 'supports_page_attributes', pods_v( 'supports_page_attributes', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Page Attributes', 'pods' ) ) ); ?>
425
  </div>
426
  </li>
427
  <li>
428
  <div class="pods-field pods-boolean">
429
+ <?php echo PodsForm::field( 'supports_post_formats', pods_v( 'supports_post_formats', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Post Formats', 'pods' ) ) ); ?>
430
  </div>
431
  </li>
432
 
433
  <?php if ( function_exists( 'genesis' ) ) { ?>
434
  <li>
435
  <div class="pods-field pods-boolean">
436
+ <?php echo PodsForm::field( 'supports_genesis_seo', pods_v( 'supports_genesis_seo', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Genesis: SEO', 'pods' ) ) ); ?>
437
  </div>
438
  </li>
439
  <li>
440
  <div class="pods-field pods-boolean">
441
+ <?php echo PodsForm::field( 'supports_genesis_layouts', pods_v( 'supports_genesis_layouts', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Genesis: Layouts', 'pods' ) ) ); ?>
442
  </div>
443
  </li>
444
  <li>
445
  <div class="pods-field pods-boolean">
446
+ <?php echo PodsForm::field( 'supports_genesis_simple_sidebars', pods_v( 'supports_genesis_simple_sidebars', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Genesis: Simple Sidebars', 'pods' ) ) ); ?>
447
  </div>
448
  </li>
449
  <?php } ?>
451
  <?php if ( defined( 'YARPP_VERSION' ) ) { ?>
452
  <li>
453
  <div class="pods-field pods-boolean">
454
+ <?php echo PodsForm::field( 'supports_yarpp_support', pods_v( 'supports_yarpp_support', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'YARPP Support', 'pods' ) ) ); ?>
455
  </div>
456
  </li>
457
  <?php } ?>
459
  <?php if ( class_exists( 'Jetpack' ) ) { ?>
460
  <li>
461
  <div class="pods-field pods-boolean">
462
+ <?php echo PodsForm::field( 'supports_jetpack_publicize', pods_v( 'supports_jetpack_publicize', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Jetpack Publicize Support', 'pods' ) ) ); ?>
463
  </div>
464
  </li>
465
  <li>
466
  <div class="pods-field pods-boolean">
467
+ <?php echo PodsForm::field( 'supports_jetpack_markdown', pods_v( 'supports_jetpack_markdown', $pod, false ), 'boolean', array( 'boolean_yes_label' => __( 'Jetpack Markdown Support', 'pods' ) ) ); ?>
468
  </div>
469
  </li>
470
  <?php } ?>
473
  </div>
474
  <div class="pods-field-option">
475
  <?php echo PodsForm::label( 'supports_custom', __( 'Advanced Supports', 'pods' ), __( 'Comma-separated list of custom "supports" values to pass to register_post_type.', 'pods' ) ); ?>
476
+ <?php echo PodsForm::field( 'supports_custom', pods_v( 'supports_custom', $pod, '' ), 'text' ); ?>
477
  </div>
478
  <div class="pods-field-option-group">
479
  <p class="pods-field-option-group-label">
488
  ?>
489
  <li>
490
  <div class="pods-field pods-boolean">
491
+ <?php echo PodsForm::field( 'built_in_taxonomies_' . $taxonomy, pods_v( 'built_in_taxonomies_' . $taxonomy, $pod, false ), 'boolean', array( 'boolean_yes_label' => $label . ' <small>(' . $taxonomy . ')</small>' ) ); ?>
492
  </div>
493
  </li>
494
  <?php
499
  </div>
500
  <?php
501
  }
502
+ elseif ( 'taxonomy' == $pod_type && strlen( pods_v( 'object', $pod ) ) < 1 ) {
503
  $fields = $tab_options[ 'advanced' ];
504
  $field_options = PodsForm::fields_setup( $fields );
505
  $field = $pod;
520
  ?>
521
  <li>
522
  <div class="pods-field pods-boolean">
523
+ <?php echo PodsForm::field( 'built_in_post_types_' . $post_type, pods_v( 'built_in_post_types_' . $post_type, $pod, false ), 'boolean', array( 'boolean_yes_label' => $label ) ); ?>
 
 
 
 
 
 
 
 
 
 
 
 
524
  </div>
525
  </li>
526
  <?php
527
  }
528
  ?>
529
+ <li>
530
+ <div class="pods-field pods-boolean">
531
+ <?php echo PodsForm::field( 'built_in_post_types_attachment', pods_v( 'built_in_post_types_attachment', $pod, false ), 'boolean', array( 'boolean_yes_label' => 'Media <small>(attachment)</small>' ) ); ?>
532
+ </div>
533
+ </li>
534
  </ul>
535
  </div>
536
  </div>
537
  <?php
538
  }
539
+ elseif ( 'pod' == $pod_type ) {
540
  ?>
541
  <div class="pods-field-option">
542
  <?php echo PodsForm::label( 'detail_url', __( 'Detail Page URL', 'pods' ), __( 'help', 'pods' ) ); ?>
543
+ <?php echo PodsForm::field( 'detail_url', pods_v( 'detail_url', $pod ), 'text' ); ?>
544
  </div>
545
 
546
  <?php
554
 
555
  <div class="pods-field-option">
556
  <?php echo PodsForm::label( 'pod_index', __( 'Title Field', 'pods' ), __( 'If you delete the "name" field, we need to specify the field to use as your primary title field. This field will serve as an index of your content. Most commonly this field represents the name of a person, place, thing, or a summary field.', 'pods' ) ); ?>
557
+ <?php echo PodsForm::field( 'pod_index', pods_v( 'pod_index', $pod, 'name' ), 'pick', array( 'data' => $index_fields ) ); ?>
558
  </div>
559
 
560
  <div class="pods-field-option">
561
  <?php echo PodsForm::label( 'hierarchical', __( 'Hierarchical', 'pods' ), __( 'help', 'pods' ) ); ?>
562
+ <?php echo PodsForm::field( 'hierarchical', (int) pods_v( 'hierarchical', $pod, 0 ), 'boolean', array( 'dependency' => true, 'boolean_yes_label' => '' ) ); ?>
563
  </div>
564
 
565
  <?php
566
  $hierarchical_fields = array();
567
 
568
  foreach ( $pod[ 'fields' ] as $field ) {
569
+ if ( 'pick' == $field[ 'type' ] && 'pod' == pods_v( 'pick_object', $field ) && $pod[ 'name' ] == pods_v( 'pick_val', $field ) && 'single' == pods_v( 'pick_format_type', $field[ 'options' ] ) )
570
  $hierarchical_fields[ $field[ 'name' ] ] = $field[ 'label' ];
571
  }
572
 
576
 
577
  <div class="pods-field-option pods-depends-on pods-depends-on-hierarchical">
578
  <?php echo PodsForm::label( 'pod_parent', __( 'Hierarchical Field', 'pods' ), __( 'help', 'pods' ) ); ?>
579
+ <?php echo PodsForm::field( 'pod_parent', pods_v( 'pod_parent', $pod, 'name' ), 'pick', array( 'data' => $hierarchical_fields ) ); ?>
580
  </div>
581
 
582
  <?php
594
  }
595
 
596
  echo PodsForm::label( 'pre_save_helpers', __( 'Pre-Save Helper(s)', 'pods' ), __( 'help', 'pods' ) );
597
+ echo PodsForm::field( 'pre_save_helpers', pods_v( 'pre_save_helpers', $pod ), 'pick', array( 'data' => $pre_save_helpers ) );
598
  ?>
599
  </div>
600
  <div class="pods-field-option">
608
  }
609
 
610
  echo PodsForm::label( 'post_save_helpers', __( 'Post-Save Helper(s)', 'pods' ), __( 'help', 'pods' ) );
611
+ echo PodsForm::field( 'post_save_helpers', pods_v( 'post_save_helpers', $pod ), 'pick', array( 'data' => $post_save_helpers ) );
612
  ?>
613
  </div>
614
  <div class="pods-field-option">
622
  }
623
 
624
  echo PodsForm::label( 'pre_delete_helpers', __( 'Pre-Delete Helper(s)', 'pods' ), __( 'help', 'pods' ) );
625
+ echo PodsForm::field( 'pre_delete_helpers', pods_v( 'pre_delete_helpers', $pod ), 'pick', array( 'data' => $pre_delete_helpers ) );
626
  ?>
627
  </div>
628
  <div class="pods-field-option">
636
  }
637
 
638
  echo PodsForm::label( 'post_delete_helpers', __( 'Post-Delete Helper(s)', 'pods' ), __( 'help', 'pods' ) );
639
+ echo PodsForm::field( 'post_delete_helpers', pods_v( 'post_delete_helpers', $pod ), 'pick', array( 'data' => $post_delete_helpers ) );
640
  ?>
641
  </div>
642
  <?php
670
  <div id="pods-extra-fields" class="pods-nav-tab">
671
  <p><?php _e( 'Taxonomies do not support extra fields natively, but Pods can add this feature for you easily. Table based storage will operate in a way where each field you create for your content type becomes a field in a table.', 'pods' ); ?></p>
672
 
673
+ <p><?php echo sprintf( __( 'Enabling extra fields for this taxonomy will add a custom table into your database as <em>%s</em>.', 'pods' ), $wpdb->prefix . 'pods_' . pods_v( 'name', $pod ) ); ?></p>
674
 
675
+ <p><a href="https://pods.io/docs/comparisons/compare-storage-types/" target="_blank"><?php _e( 'Find out more', 'pods' ); ?> &raquo;</a></p>
676
 
677
  <p class="submit">
678
  <a href="<?php echo esc_url( pods_query_arg( array( 'enable_extra_fields' => 1 ) ) ); ?>" class="button-primary"><?php _e( 'Enable Extra Fields', 'pods' ); ?></a>
688
  <div id="side-info-field" class="inner-sidebar">
689
  <div id="side-sortables">
690
  <div id="submitdiv" class="postbox pods-no-toggle">
691
+ <h3><span><?php esc_html_e( 'Manage', 'pods' ); ?> <small>(<a href="<?php echo esc_url( pods_query_arg( array( 'action' . $obj->num => 'manage', 'id' . $obj->num => '' ) ) ); ?>">&laquo; <?php _e( 'Back to Manage', 'pods' ); ?></a>)
692
  </small></span></h3>
693
  <div class="inside">
694
  <div class="submitbox" id="submitpost">
698
  </div>
699
  <div id="publishing-action">
700
  <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
701
+ <button class="button-primary" type="submit"><?php esc_html_e( 'Save Pod', 'pods' ); ?></button>
702
  </div>
703
  <div class="clear"></div>
704
  </div>
706
  </div>
707
  </div>
708
  <!-- /#submitdiv -->
709
+ <div class="pods-submittable-fields">
710
+ <?php do_meta_boxes( '_pods_pod', 'side', $pod_post ); ?>
711
+ </div>
712
  </div>
713
  </div>
714
  </div>
776
  var thank_you = '<?php echo pods_slash( pods_query_arg( array( 'do' => 'save' ) ) ); ?>';
777
 
778
  document.location = thank_you.replace( 'X_ID_X', id );
 
 
 
 
779
  };
780
 
781
+ var sisterFieldsProcessing = {};
782
+
783
+ /*global PodsDFV */
784
  var pods_sister_field = function ( $el ) {
785
+ var postData, relatedPodName, selectedValue, $container;
786
+ var fieldModel, collection, selectField;
787
+
788
  var id = $el.closest( 'tr.pods-manage-row' ).data( 'row' );
789
+ var fieldKey = id + '_' + $el.prop( 'id' );
790
 
791
+ if ( 'undefined' != typeof sisterFieldsProcessing[ fieldKey ] && true == sisterFieldsProcessing[ fieldKey ] ) {
792
  return;
793
+ }
794
 
795
+ relatedPodName = jQuery( '#pods-form-ui-field-data-' + id + '-pick-object' ).val() + '';
796
+ selectedValue = jQuery( '#pods-form-ui-field-data-' + id + '-sister-id' ).val() + '';
797
+ $container = $el.find( '.pods-sister-field' );
 
 
 
798
 
799
+ if ( 0 != relatedPodName.indexOf( 'pod-' )
800
+ && 0 != relatedPodName.indexOf( 'post_type-' )
801
+ && 0 != relatedPodName.indexOf( 'taxonomy-' )
802
+ && 0 != relatedPodName.indexOf( 'user' )
803
+ && 0 != relatedPodName.indexOf( 'media' )
804
+ && 0 != relatedPodName.indexOf( 'comment' ) ) {
805
 
806
+ sisterFieldsProcessing[ fieldKey ] = false;
807
  return;
808
  }
809
 
810
+ sisterFieldsProcessing[ fieldKey ] = true;
811
+
812
+ fieldModel = new PodsDFV.models.PodsDFVFieldModel( {
813
+ htmlAttr: {
814
+ id : "pods-form-ui-field-data-" + id + "-sister-id",
815
+ "class" : "pods-form-ui-field pods-form-ui-field-type-pick pods-form-ui-field-name-field-data-sister-id",
816
+ name : "field_data[" + id + "][sister_id]",
817
+ name_clean: "field-data-sister-id"
818
+ }
819
+ } );
820
 
821
+ collection = new PodsDFV.models.RelationshipCollection( {
822
+ id : "",
823
+ name: <?php echo json_encode( __( 'Loading available fields..', 'pods' ) ); ?>
824
+ } );
825
+
826
+ selectField = new PodsDFV.fields.Pick( {
827
+ el : $container,
828
+ model : fieldModel,
829
+ collection: collection
830
+ } );
831
 
832
+ selectField.render();
833
 
834
+ postData = {
835
+ action : 'pods_admin',
836
+ method : 'load_sister_fields',
837
+ _wpnonce : '<?php echo esc_js( wp_create_nonce( 'pods-load_sister_fields' ) ); ?>',
838
+ pod : '<?php echo esc_js( pods_v( 'name', $pod ) ); ?>',
839
+ related_pod: relatedPodName
840
  };
841
 
842
  jQuery.ajax( {
843
+ type : 'POST',
844
+ dataType: 'html',
845
+ url : ajaxurl + '?pods_ajax=1',
846
+ cache : false,
847
+ data : postData,
848
  success : function ( d ) {
849
+ var json, newItems, fieldID, fieldName;
850
+
851
+ newItems = [];
852
+
853
  if ( -1 == d.indexOf( '<e>' ) && -1 == d.indexOf('</e>') && -1 != d && '[]' != d ) {
 
854
 
855
+ json = d.match( /{.*}$/ );
856
+
857
+ if ( null !== json && 0 < json.length ) {
858
  json = jQuery.parseJSON( json[ 0 ] );
859
+ } else {
860
  json = {};
861
+ }
 
862
 
863
  if ( 'object' != typeof json || ! jQuery.isEmptyObject( json ) ) {
864
+
865
  if ( 'object' != typeof json ) {
866
  if ( window.console ) console.log( d );
867
  if ( window.console ) console.log( json );
868
 
869
+ newItems.push( {
870
+ id: "",
871
+ name: <?php echo json_encode( __( 'There was a server error with your AJAX request.', 'pods' ) ); ?>
872
+ } );
873
+
874
+ } else {
875
+ newItems.push( {
876
+ id : "",
877
+ name: <?php echo json_encode( __( '-- Select Related Field --', 'pods' ) ); ?>
878
+ } );
879
+
880
+ for ( fieldID in json ) {
881
+ if ( json.hasOwnProperty( fieldID ) ) {
882
+ fieldName = json[ fieldID ];
883
+
884
+ newItems.push( {
885
+ id : fieldID,
886
+ name : fieldName,
887
+ selected: (selectedValue == fieldID)
888
+ } );
889
+ }
890
+ }
891
  }
892
+ collection.reset( newItems );
893
+ jQuery( '#pods-form-ui-field-data-' + id + '-sister-id' ).val( selectedValue );
894
 
895
+ } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
896
  // None found
897
+ collection.reset( {
898
+ id : "",
899
+ name: <?php echo json_encode( __( 'No Related Fields Found', 'pods' ) ); ?>
900
+ } );
901
  }
902
+
903
+ } else {
904
  // None found
905
+ collection.reset( {
906
+ id : "",
907
+ name: <?php echo json_encode( __( 'No Related Fields Found', 'pods' ) ); ?>
908
+ } );
909
  }
910
 
911
+ sisterFieldsProcessing[ fieldKey ] = false;
912
  },
913
  error : function () {
914
  // None found
915
+ collection.reset( {
916
+ id : "",
917
+ name: <?php echo json_encode( __( 'No Related Fields Found', 'pods' ) ); ?>
918
+ } );
919
 
920
+ sisterFieldsProcessing[ fieldKey ] = false;
921
  }
922
  } );
923
  }
ui/admin/widgets/list.php CHANGED
@@ -10,7 +10,7 @@
10
  }
11
  </style>
12
 
13
- <p><em><?php _e('You must specify a Pods Template or create a custom template, using <a href="http://pods.io/docs/build/using-magic-tags/" title="Using Magic Tags" target="_blank">magic tags</a>.', 'pods'); ?></p></em>
14
 
15
  <ol class="pods_list_widget_form">
16
  <li>
10
  }
11
  </style>
12
 
13
+ <p><em><?php _e('You must specify a Pods Template or create a custom template, using <a href="https://pods.io/docs/build/using-magic-tags/" title="Using Magic Tags" target="_blank">magic tags</a>.', 'pods'); ?></p></em>
14
 
15
  <ol class="pods_list_widget_form">
16
  <li>
ui/admin/widgets/single.php CHANGED
@@ -10,7 +10,7 @@
10
  }
11
  </style>
12
 
13
- <p><em><?php _e('You must specify a Pods Template or create a custom template, using <a href="http://pods.io/docs/build/using-magic-tags/" title="Using Magic Tags" target="_blank">magic tags</a>.', 'pods'); ?></p></em>
14
 
15
  <ol class="pods_single_widget_form">
16
  <li>
10
  }
11
  </style>
12
 
13
+ <p><em><?php _e('You must specify a Pods Template or create a custom template, using <a href="https://pods.io/docs/build/using-magic-tags/" title="Using Magic Tags" target="_blank">magic tags</a>.', 'pods'); ?></p></em>
14
 
15
  <ol class="pods_single_widget_form">
16
  <li>
ui/fields/cleditor.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  wp_enqueue_script( 'pods-cleditor' );
3
- wp_enqueue_style( 'pods-cleditor' );
4
 
5
  $type = 'textarea';
6
  $attributes = array();
1
  <?php
2
  wp_enqueue_script( 'pods-cleditor' );
3
+ wp_enqueue_style( 'pods-styles' );
4
 
5
  $type = 'textarea';
6
  $attributes = array();
ui/fields/codemirror.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  wp_enqueue_script( 'pods-codemirror' );
3
- wp_enqueue_style( 'pods-codemirror' );
4
  wp_enqueue_script( 'pods-codemirror-loadmode' );
5
 
6
  $type = 'textarea';
@@ -8,6 +8,7 @@ $attributes = array();
8
  $attributes[ 'tabindex' ] = 2;
9
  $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options, 'pods-ui-field-codemirror' );
10
  ?>
 
11
  <div class="code-toolbar"><!-- Placeholder --></div>
12
  <textarea<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?>><?php echo esc_textarea( $value ); ?></textarea>
13
  <div class="code-footer"><!-- Placeholder --></div>
@@ -40,3 +41,4 @@ $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type,
40
  }
41
  } );
42
  </script>
 
1
  <?php
2
  wp_enqueue_script( 'pods-codemirror' );
3
+ wp_enqueue_style( 'pods-styles' );
4
  wp_enqueue_script( 'pods-codemirror-loadmode' );
5
 
6
  $type = 'textarea';
8
  $attributes[ 'tabindex' ] = 2;
9
  $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options, 'pods-ui-field-codemirror' );
10
  ?>
11
+ <div class="pods-codemirror pods-form-ui-field">
12
  <div class="code-toolbar"><!-- Placeholder --></div>
13
  <textarea<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?>><?php echo esc_textarea( $value ); ?></textarea>
14
  <div class="code-footer"><!-- Placeholder --></div>
41
  }
42
  } );
43
  </script>
44
+ </div>
ui/fields/date.php CHANGED
@@ -1,119 +1,109 @@
1
  <?php
2
- $date_format = array(
3
- 'mdy' => 'mm/dd/yy',
4
- 'mdy_dash' => 'mm-dd-yy',
5
- 'mdy_dot' => 'mm.dd.yy',
6
- 'dmy' => 'dd/mm/yy',
7
- 'dmy_dash' => 'dd-mm-yy',
8
- 'dmy_dot' => 'dd.mm.yy',
9
- 'ymd_slash' => 'yy/mm/dd',
10
- 'ymd_dash' => 'yy-mm-dd',
11
- 'ymd_dot' => 'yy.mm.dd',
12
- 'dMy' => 'dd/M/yy',
13
- 'dMy_dash' => 'dd-M-yy',
14
- 'fjy' => 'MM d, yy',
15
- 'fjsy' => 'MM d, yy',
16
- 'y' => 'yy'
17
- );
18
 
19
- $date_format = apply_filters( 'pods_form_ui_field_date_js_formats', $date_format );
 
20
 
21
- wp_enqueue_script( 'jquery-ui-datepicker' );
22
- wp_enqueue_style( 'jquery-ui' );
23
 
24
- $attributes = array();
25
 
26
- $type = 'text';
27
 
28
- if ( 1 == pods_var( $form_field_type . '_html5', $options ) )
29
- $type = $form_field_type;
30
 
31
- $attributes[ 'type' ] = $type;
32
- $attributes[ 'tabindex' ] = 2;
33
 
34
- $format = PodsForm::field_method( 'date', 'format', $options );
35
 
36
- $method = 'datepicker';
37
 
38
- $args = array(
39
- 'dateFormat' => $date_format[ pods_var( $form_field_type . '_format', $options, 'mdy', null, true ) ],
40
- 'changeMonth' => true,
41
- 'changeYear' => true,
42
- 'firstDay' => (int) get_option( 'start_of_week', 0 )
43
- );
 
44
 
45
- $html5_format = 'Y-m-d';
46
 
47
- $date = PodsForm::field_method( 'date', 'createFromFormat', $format, (string) $value );
48
- $date_default = PodsForm::field_method( 'date', 'createFromFormat', 'Y-m-d', (string) $value );
49
 
50
- $formatted_date = $value;
51
 
52
- if ( 1 == pods_var( $form_field_type . '_allow_empty', $options, 1 ) && in_array( $value, array( '', '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
53
- $formatted_date = $value = '';
54
- elseif ( 'text' != $type ) {
55
- $formatted_date = $value;
56
 
57
- if ( false !== $date )
58
- $value = $date->format( $html5_format );
59
- elseif ( false !== $date_default )
60
- $value = $date_default->format( $html5_format );
61
- elseif ( !empty( $value ) )
62
- $value = date_i18n( $html5_format, strtotime( (string) $value ) );
63
- else
64
- $value = date_i18n( $html5_format );
65
- }
66
 
67
- $args = apply_filters( 'pods_form_ui_field_date_args', $args, $type, $options, $attributes, $name, $form_field_type );
68
 
69
- $attributes[ 'value' ] = $value;
70
 
71
- $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options );
72
  ?>
73
  <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?> />
74
 
75
  <script>
76
- jQuery( function () {
77
- var <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args = <?php echo json_encode( $args ); ?>;
78
-
79
- <?php
80
- if ( 'text' != $type ) {
81
- ?>
82
- if ( 'undefined' == typeof pods_test_date_field_<?php echo esc_js( $type ); ?> ) {
83
- // Test whether or not the browser supports date inputs
84
- function pods_test_date_field_<?php echo esc_js( $type ); ?> () {
85
- var input = jQuery( '<input/>', {
86
- 'type' : '<?php echo esc_js( $type ); ?>',
87
- css : {
88
- position : 'absolute',
89
- display : 'none'
90
- }
91
- } );
92
-
93
- jQuery( 'body' ).append( input );
94
-
95
- var bool = input.prop( 'type' ) !== 'text';
96
-
97
- if ( bool ) {
98
- var smile = ":)";
99
- input.val( smile );
100
-
101
- return (input.val() != smile);
102
- }
103
- }
104
- }
105
-
106
- if ( !pods_test_date_field_<?php echo esc_js( $type ); ?>() ) {
107
- jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).val( '<?php echo esc_js( $formatted_date ); ?>' );
108
- jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).<?php echo esc_js( $method ); ?>( <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args );
109
- }
110
- <?php
111
- }
112
- else {
113
- ?>
114
- jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).<?php echo esc_js( $method ); ?>( <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args );
115
- <?php
116
- }
117
- ?>
118
- } );
119
  </script>
1
  <?php
2
+ /**
3
+ * @var string $form_field_type
4
+ * @var array $options
5
+ * @var $value
6
+ */
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ wp_enqueue_script( 'jquery-ui-datepicker' );
9
+ wp_enqueue_style( 'pods-styles' );
10
 
11
+ PodsForm::field_method( 'date', 'enqueue_jquery_ui_i18n' );
 
12
 
13
+ $attributes = array();
14
 
15
+ $type = 'text';
16
 
17
+ if ( 1 == pods_var( $form_field_type . '_html5', $options ) )
18
+ $type = $form_field_type;
19
 
20
+ $attributes[ 'type' ] = $type;
21
+ $attributes[ 'tabindex' ] = 2;
22
 
23
+ $format = PodsForm::field_method( 'date', 'format', $options );
24
 
25
+ $method = 'datepicker';
26
 
27
+ $args = array(
28
+ // Get selected JS date format.
29
+ 'dateFormat' => PodsForm::field_method( 'date', 'format', $options, true ),
30
+ 'changeMonth' => true,
31
+ 'changeYear' => true,
32
+ 'firstDay' => (int) get_option( 'start_of_week', 0 ),
33
+ );
34
 
35
+ $html5_format = 'Y-m-d';
36
 
37
+ $date = PodsForm::field_method( 'date', 'createFromFormat', $format, (string) $value );
38
+ $date_default = PodsForm::field_method( 'date', 'createFromFormat', 'Y-m-d', (string) $value );
39
 
40
+ $formatted_date = $value;
41
 
42
+ if ( 1 == pods_var( $form_field_type . '_allow_empty', $options, 1 ) && in_array( $value, array( '', '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
43
+ $formatted_date = $value = '';
44
+ elseif ( 'text' != $type ) {
45
+ $formatted_date = $value;
46
 
47
+ if ( false !== $date )
48
+ $value = $date->format( $html5_format );
49
+ elseif ( false !== $date_default )
50
+ $value = $date_default->format( $html5_format );
51
+ elseif ( !empty( $value ) )
52
+ $value = date_i18n( $html5_format, strtotime( (string) $value ) );
53
+ else
54
+ $value = date_i18n( $html5_format );
55
+ }
56
 
57
+ $args = apply_filters( 'pods_form_ui_field_date_args', $args, $type, $options, $attributes, $name, $form_field_type );
58
 
59
+ $attributes[ 'value' ] = $value;
60
 
61
+ $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options );
62
  ?>
63
  <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?> />
64
 
65
  <script>
66
+ jQuery( function () {
67
+ var <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args = <?php echo json_encode( $args ); ?>;
68
+
69
+ <?php
70
+ if ( 'text' != $type ) {
71
+ ?>
72
+ if ( 'undefined' == typeof pods_test_date_field_<?php echo esc_js( $type ); ?> ) {
73
+ // Test whether or not the browser supports date inputs
74
+ function pods_test_date_field_<?php echo esc_js( $type ); ?> () {
75
+ var input = jQuery( '<input/>', {
76
+ 'type' : '<?php echo esc_js( $type ); ?>',
77
+ css : {
78
+ position : 'absolute',
79
+ display : 'none'
80
+ }
81
+ } );
82
+
83
+ jQuery( 'body' ).append( input );
84
+
85
+ var bool = input.prop( 'type' ) !== 'text';
86
+
87
+ if ( bool ) {
88
+ var smile = ":)";
89
+ input.val( smile );
90
+
91
+ return (input.val() != smile);
92
+ }
93
+ }
94
+ }
95
+
96
+ if ( !pods_test_date_field_<?php echo esc_js( $type ); ?>() ) {
97
+ jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).val( '<?php echo esc_js( $formatted_date ); ?>' );
98
+ jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).<?php echo esc_js( $method ); ?>( <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args );
99
+ }
100
+ <?php
101
+ }
102
+ else {
103
+ ?>
104
+ jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).<?php echo esc_js( $method ); ?>( <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args );
105
+ <?php
106
+ }
107
+ ?>
108
+ } );
109
  </script>
ui/fields/datetime.php CHANGED
@@ -1,167 +1,132 @@
1
  <?php
2
- $date_format = array(
3
- 'mdy' => 'mm/dd/yy',
4
- 'mdy_dash' => 'mm-dd-yy',
5
- 'mdy_dot' => 'mm.dd.yy',
6
- 'dmy' => 'dd/mm/yy',
7
- 'dmy_dash' => 'dd-mm-yy',
8
- 'dmy_dot' => 'dd.mm.yy',
9
- 'ymd_slash' => 'yy/mm/dd',
10
- 'ymd_dash' => 'yy-mm-dd',
11
- 'ymd_dot' => 'yy.mm.dd',
12
- 'dMy' => 'dd/mmm/yy',
13
- 'dMy_dash' => 'dd-mmm-yy',
14
- 'fjy' => 'MM d, yy',
15
- 'fjsy' => 'MM d, yy',
16
- 'c' => 'yy-mm-dd'
17
- );
18
-
19
- $time_format = array(
20
- 'h_mm_A' => 'h:mm:ss TT',
21
- 'h_mm_ss_A' => 'h:mm TT',
22
- 'hh_mm_A' => 'hh:mm TT',
23
- 'hh_mm_ss_A' => 'hh:mm:ss TT',
24
- 'h_mma' => 'h:mmtt',
25
- 'hh_mma' => 'hh:mmtt',
26
- 'h_mm' => 'h:mm',
27
- 'h_mm_ss' => 'h:mm:ss',
28
- 'hh_mm' => 'hh:mm',
29
- 'hh_mm_ss' => 'hh:mm:ss'
30
- );
31
-
32
- $time_format_24 = array(
33
- 'hh_mm' => 'HH:mm',
34
- 'hh_mm_ss' => 'HH:mm:ss'
35
- );
36
-
37
- $date_format = apply_filters( 'pods_form_ui_field_date_js_formats', $date_format );
38
-
39
- $time_format = apply_filters( 'pods_form_ui_field_time_js_formats', $time_format );
40
- $time_format_24 = apply_filters( 'pods_form_ui_field_time_js_formats_24', $time_format_24 );
41
-
42
- wp_enqueue_script( 'jquery-ui-datepicker' );
43
- wp_enqueue_script( 'jquery-ui-timepicker' );
44
- wp_enqueue_style( 'jquery-ui' );
45
- wp_enqueue_style( 'jquery-ui-timepicker' );
46
-
47
- $attributes = array();
48
-
49
- $type = 'text';
50
-
51
- if ( 1 == pods_var( $form_field_type . '_html5', $options ) )
52
- $type = $form_field_type;
53
-
54
- $attributes[ 'type' ] = $type;
55
- $attributes[ 'tabindex' ] = 2;
56
-
57
- $format = PodsForm::field_method( 'datetime', 'format', $options );
58
-
59
- $method = 'datetimepicker';
60
-
61
- $format_value = pods_var( $form_field_type . '_format', $options, 'mdy', null, true );
62
-
63
- $args = array(
64
- 'timeFormat' => $time_format[ pods_var( $form_field_type . '_time_format', $options, 'h_mma', null, true ) ],
65
- 'dateFormat' => $date_format[ $format_value ],
66
- 'changeMonth' => true,
67
- 'changeYear' => true,
68
- 'firstDay' => (int) get_option( 'start_of_week', 0 )
69
- );
70
-
71
- if ( false !== stripos( $args[ 'timeFormat' ], 'tt' ) )
72
- $args[ 'ampm' ] = true;
73
-
74
- $html5_format = 'Y-m-d H:i:s';
75
-
76
- if ( 'c' == $format_value ) {
77
- $args[ 'ampm' ] = false;
78
- $args[ 'separator' ] = 'T';
79
- $args[ 'timeFormat' ] = 'HH:mm:ssz';
80
- //$args[ 'showTimezone' ] = true;
81
-
82
- $timezone = (int) get_option( 'gmt_offset' );
83
- $timezone = $timezone * 60;
84
-
85
- if ( 0 <= $timezone )
86
- $timezone = '+' . (string) $timezone;
87
-
88
- $args[ 'timezone' ] = (string) $timezone;
89
- }
90
- elseif ( 24 == pods_var( $form_field_type . '_time_type', $options, 12 ) ) {
91
- $args[ 'ampm' ] = false;
92
- $args[ 'timeFormat' ] = $time_format_24[ pods_var( $form_field_type . '_time_format_24', $options, 'hh_mm', null, true ) ];
93
- }
94
-
95
- $date = PodsForm::field_method( 'datetime', 'createFromFormat', $format, (string) $value );
96
- $date_default = PodsForm::field_method( 'datetime', 'createFromFormat', 'Y-m-d H:i:s', (string) $value );
97
-
98
- $formatted_date = $value;
99
-
100
- if ( 1 == pods_var( $form_field_type . '_allow_empty', $options, 1 ) && in_array( $value, array( '', '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
101
- $formatted_date = $value = '';
102
- elseif ( 'text' != $type ) {
103
- $formatted_date = $value;
104
-
105
- if ( false !== $date )
106
- $value = $date->format( $html5_format );
107
- elseif ( false !== $date_default )
108
- $value = $date_default->format( $html5_format );
109
- elseif ( !empty( $value ) )
110
- $value = date_i18n( $html5_format, strtotime( (string) $value ) );
111
- else
112
- $value = date_i18n( $html5_format );
113
- }
114
 
115
- $args = apply_filters( 'pods_form_ui_field_datetime_args', $args, $type, $options, $attributes, $name, $form_field_type );
 
 
 
116
 
117
- $attributes[ 'value' ] = $value;
118
 
119
- $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  ?>
121
  <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?> />
122
 
123
  <script>
124
- jQuery( function () {
125
- var <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args = <?php echo json_encode( $args ); ?>;
126
-
127
- <?php
128
- if ( 'text' != $type ) {
129
- ?>
130
- if ( 'undefined' == typeof pods_test_date_field_<?php echo esc_js( $type ); ?> ) {
131
- // Test whether or not the browser supports date inputs
132
- function pods_test_date_field_<?php echo esc_js( $type ); ?> () {
133
- var input = jQuery( '<input/>', {
134
- 'type' : '<?php echo esc_js( $type ); ?>',
135
- css : {
136
- position : 'absolute',
137
- display : 'none'
138
- }
139
- } );
140
-
141
- jQuery( 'body' ).append( input );
142
-
143
- var bool = input.prop( 'type' ) !== 'text';
144
-
145
- if ( bool ) {
146
- var smile = ":)";
147
- input.val( smile );
148
-
149
- return (input.val() != smile);
150
- }
151
- }
152
- }
153
-
154
- if ( !pods_test_date_field_<?php echo esc_js( $type ); ?>() ) {
155
- jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).val( '<?php echo esc_js( $formatted_date ); ?>' );
156
- jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).<?php echo esc_js( $method ); ?>( <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args );
157
- }
158
- <?php
159
- }
160
- else {
161
- ?>
162
- jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).<?php echo esc_js( $method ); ?>( <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args );
163
- <?php
164
- }
165
- ?>
166
- } );
167
  </script>
1
  <?php
2
+ /**
3
+ * @var string $form_field_type
4
+ * @var array $options
5
+ * @var $value
6
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ wp_enqueue_script( 'jquery-ui-datepicker' );
9
+ wp_enqueue_script( 'jquery-ui-timepicker' );
10
+ wp_enqueue_style( 'pods-styles' );
11
+ wp_enqueue_style( 'jquery-ui-timepicker' );
12
 
13
+ PodsForm::field_method( 'datetime', 'enqueue_jquery_ui_i18n' );
14
 
15
+ $attributes = array();
16
+
17
+ $type = 'text';
18
+
19
+ if ( 1 == pods_var( $form_field_type . '_html5', $options ) )
20
+ $type = $form_field_type;
21
+
22
+ $attributes[ 'type' ] = $type;
23
+ $attributes[ 'tabindex' ] = 2;
24
+
25
+ $format = PodsForm::field_method( 'datetime', 'format', $options );
26
+
27
+ $method = 'datetimepicker';
28
+
29
+ $format_value = pods_v( $form_field_type . '_format', $options, 'mdy', true );
30
+
31
+ $args = array(
32
+ 'timeFormat' => PodsForm::field_method( 'datetime', 'format_time', $options, true ),
33
+ 'dateFormat' => PodsForm::field_method( 'datetime', 'format_date', $options, true ),
34
+ 'ampm' => false,
35
+ 'changeMonth' => true,
36
+ 'changeYear' => true,
37
+ 'firstDay' => (int) get_option( 'start_of_week', 0 ),
38
+ );
39
+
40
+ if ( false !== stripos( $args[ 'timeFormat' ], 'tt' ) )
41
+ $args[ 'ampm' ] = true;
42
+
43
+ $html5_format = 'Y-m-d H:i:s';
44
+
45
+ if ( 'format' === pods_v( $form_field_type . '_type', $options, 'format', true ) && 'c' === $format_value ) {
46
+ $args[ 'ampm' ] = false;
47
+ $args[ 'separator' ] = 'T';
48
+ $args[ 'timeFormat' ] = 'HH:mm:ssz';
49
+ //$args[ 'showTimezone' ] = true;
50
+
51
+ $timezone = (int) get_option( 'gmt_offset' );
52
+ $timezone = $timezone * 60;
53
+
54
+ if ( 0 <= $timezone )
55
+ $timezone = '+' . (string) $timezone;
56
+
57
+ $args[ 'timezone' ] = (string) $timezone;
58
+ }
59
+
60
+ $date = PodsForm::field_method( 'datetime', 'createFromFormat', $format, (string) $value );
61
+ $date_default = PodsForm::field_method( 'datetime', 'createFromFormat', 'Y-m-d H:i:s', (string) $value );
62
+
63
+ $formatted_date = $value;
64
+
65
+ if ( 1 == pods_var( $form_field_type . '_allow_empty', $options, 1 ) && in_array( $value, array( '', '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
66
+ $formatted_date = $value = '';
67
+ elseif ( 'text' != $type ) {
68
+ $formatted_date = $value;
69
+
70
+ if ( false !== $date )
71
+ $value = $date->format( $html5_format );
72
+ elseif ( false !== $date_default )
73
+ $value = $date_default->format( $html5_format );
74
+ elseif ( !empty( $value ) )
75
+ $value = date_i18n( $html5_format, strtotime( (string) $value ) );
76
+ else
77
+ $value = date_i18n( $html5_format );
78
+ }
79
+
80
+ $args = apply_filters( 'pods_form_ui_field_datetime_args', $args, $type, $options, $attributes, $name, $form_field_type );
81
+
82
+ $attributes[ 'value' ] = $value;
83
+
84
+ $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options );
85
  ?>
86
  <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?> />
87
 
88
  <script>
89
+ jQuery( function () {
90
+ var <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args = <?php echo json_encode( $args ); ?>;
91
+
92
+ <?php
93
+ if ( 'text' != $type ) {
94
+ ?>
95
+ if ( 'undefined' == typeof pods_test_date_field_<?php echo esc_js( $type ); ?> ) {
96
+ // Test whether or not the browser supports date inputs
97
+ function pods_test_date_field_<?php echo esc_js( $type ); ?> () {
98
+ var input = jQuery( '<input/>', {
99
+ 'type' : '<?php echo esc_js( $type ); ?>',
100
+ css : {
101
+ position : 'absolute',
102
+ display : 'none'
103
+ }
104
+ } );
105
+
106
+ jQuery( 'body' ).append( input );
107
+
108
+ var bool = input.prop( 'type' ) !== 'text';
109
+
110
+ if ( bool ) {
111
+ var smile = ":)";
112
+ input.val( smile );
113
+
114
+ return (input.val() != smile);
115
+ }
116
+ }
117
+ }
118
+
119
+ if ( !pods_test_date_field_<?php echo esc_js( $type ); ?>() ) {
120
+ jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).val( '<?php echo esc_js( $formatted_date ); ?>' );
121
+ jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).<?php echo esc_js( $method ); ?>( <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args );
122
+ }
123
+ <?php
124
+ }
125
+ else {
126
+ ?>
127
+ jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).<?php echo esc_js( $method ); ?>( <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args );
128
+ <?php
129
+ }
130
+ ?>
131
+ } );
132
  </script>
ui/fields/link.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ wp_enqueue_script( 'wplink' );
4
+ wp_enqueue_style( 'editor-buttons' );
5
+
6
+ wp_enqueue_script( 'pods-link-picker', PODS_URL . 'ui/js/pods-link-picker.js', array( 'jquery' ), '1.0.0' );
7
+
8
+ PodsForm::field_method( 'link', 'validate_link_modal' );
9
+
10
+ $url_attributes = array();
11
+ $url_type = 'text';
12
+ if ( 1 == pods_var( 'link_html5', $options ) ) {
13
+ $url_type = 'url';
14
+ }
15
+ $url_attributes[ 'type' ] = $url_type;
16
+ $url_attributes[ 'class' ] = 'linkPickerUrl';
17
+ $url_attributes[ 'value' ] = (isset($value['url'])?$value['url']:'');
18
+ $url_attributes[ 'tabindex' ] = 2;
19
+ $url_name = $name.'[url]';
20
+ $url_attributes = PodsForm::merge_attributes( $url_attributes, $url_name, $form_field_type, $options );
21
+
22
+ $text_attributes = array();
23
+ $text_type = 'text';
24
+ $text_attributes[ 'type' ] = $text_type;
25
+ $text_attributes[ 'class' ] = 'linkPickerText';
26
+ $text_attributes[ 'value' ] = (isset($value['text'])?$value['text']:'');
27
+ $text_attributes[ 'tabindex' ] = 2;
28
+ $text_name = $name.'[text]';
29
+ $text_attributes = PodsForm::merge_attributes( $text_attributes, $text_name, $form_field_type, $options );
30
+
31
+ $target_attributes = array();
32
+ $target_type = 'checkbox';
33
+ $target_attributes[ 'type' ] = $target_type;
34
+ $target_attributes[ 'class' ] = 'linkPickerTarget';
35
+ $target_attributes[ 'value' ] = '_blank';
36
+ $target_attributes[ 'tabindex' ] = 2;
37
+ $target_attributes[ 'style' ] = 'display: inline-block;';
38
+ if ( isset( $value['target'] ) && $value['target'] == '_blank' || ( ! isset( $value['target'] ) && ! empty( $options['link_new_window'] ) ) ) {
39
+ $target_attributes[ 'checked' ] = 'checked';
40
+ }
41
+ $target_name = $name.'[target]';
42
+ $target_attributes = PodsForm::merge_attributes( $target_attributes, $target_name, $form_field_type, $options );
43
+
44
+ $attributes = array();
45
+ $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options, 'pods-ui-field-link' );
46
+ $class_attributes = array( 'class' => $attributes[ 'class' ] );
47
+ ?>
48
+
49
+ <div<?php PodsForm::attributes( $class_attributes, $name, $form_field_type, $options ); ?>>
50
+ <div class="pods-link-options">
51
+ <p class="howto"><?php _e('Enter the destination URL') ?></p>
52
+ <p>
53
+ <div class="alignleft">
54
+ <label><span><?php _e('URL') ?></span><input<?php PodsForm::attributes( $url_attributes, $url_name, $form_field_type, $options ); ?> /></label>
55
+ </div>
56
+ <div class="alignleft">
57
+ <label><span><?php _e('Link Text') ?></span><input<?php PodsForm::attributes( $text_attributes, $text_name, $form_field_type, $options ); ?> /></label>
58
+ </div>
59
+ <div class="link-target">
60
+ <label><div>&nbsp;</div><input<?php PodsForm::attributes( $target_attributes, $target_name, $form_field_type, $options ); ?> /> <?php _e('Open link in a new tab') ?></label>
61
+ </div>
62
+ </p>
63
+ <br clear="both">
64
+
65
+ <?php if ( 1 == pods_v( 'link_select_existing', $options, 1 ) ) { ?>
66
+ <div class="howto link-existing-content" style="display: none;">
67
+ <a href="#" class="podsLinkPopup"><?php _e('Or link to existing content') ?></a>
68
+ <textarea id="pods-link-editor-hidden" disabled="disabled" style="display: none;"></textarea>
69
+ </div>
70
+ <?php } ?>
71
+ </div>
72
+ </div>
73
+
74
+ <?php
75
+ PodsForm::regex( $form_field_type, $options );
ui/fields/oembed.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $attributes = array();
3
+ $attributes[ 'type' ] = 'text';
4
+ $attributes[ 'value' ] = $value;
5
+ $attributes[ 'tabindex' ] = 2;
6
+ $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options );
7
+
8
+ if ( pods_var( 'readonly', $options, false ) ) {
9
+ $attributes[ 'readonly' ] = 'READONLY';
10
+
11
+ $attributes[ 'class' ] .= ' pods-form-ui-read-only';
12
+ }
13
+
14
+ $show_preview = (int) pods_v( $form_field_type . '_show_preview', $options, 0 );
15
+ ?>
16
+ <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?> />
17
+
18
+ <?php
19
+ if ( 1 == $show_preview ) {
20
+ $oembed_width = ( isset( $options['oembed_width'] ) ) ? (int) $options['oembed_width'] : 0;
21
+ $oembed_height = ( isset( $options['oembed_height'] ) ) ? (int) $options['oembed_height'] : 0;
22
+ ?>
23
+ <p class="howto">
24
+ <?php _e( 'Preview', 'pods' );?>
25
+ </p>
26
+ <input type="hidden" id="<?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_preview_nonce" name="_nonce_pods_oembed" value="<?php echo wp_create_nonce( 'pods_field_oembed_preview' ); ?>" />
27
+ <div id="<?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_preview" class="pods-oembed-preview">
28
+ <?php echo PodsForm::field_method( $form_field_type, 'display', $value, $name, $options ); ?>
29
+ </div>
30
+ <script type="text/javascript">
31
+ jQuery( function( $ ){
32
+ var pods_ajaxurl = ajaxurl + '?pods_ajax=1';
33
+
34
+ $(document).on('keyup', '#<?php echo esc_js( $attributes[ 'id' ] ); ?>', function(){
35
+ var value = $(this).val();
36
+ var name = '<?php echo $name; ?>';
37
+ var options = {
38
+ id: <?php echo $options[ 'id' ]; ?>,
39
+ oembed_width: '<?php echo $oembed_width; ?>',
40
+ oembed_height: '<?php echo $oembed_height; ?>'
41
+ };
42
+ var nonce = $(this).parent().find('#<?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_preview_nonce').val();
43
+ delay(function(){
44
+ var postdata = {
45
+ 'action': 'oembed_update_preview',
46
+ '_nonce_pods_oembed': nonce,
47
+ 'pods_field_oembed_value': value,
48
+ 'pods_field_oembed_name': name,
49
+ 'pods_field_oembed_options': options
50
+ };
51
+ $.ajax({
52
+ type : 'POST',
53
+ url : pods_ajaxurl,
54
+ cache : false,
55
+ data : postdata,
56
+ success : function ( response ) {
57
+ if ( typeof response.data == 'string' ) {
58
+ $('#<?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_preview').html( response.data );
59
+ }
60
+ }
61
+ });
62
+ }, 500);
63
+ });
64
+
65
+ var delay = (function(){
66
+ var timer = 0;
67
+ return function(callback, ms){
68
+ clearTimeout (timer);
69
+ timer = setTimeout(callback, ms);
70
+ };
71
+ })();
72
+
73
+ });
74
+ </script>
75
+ <?php
76
+ }
77
+ PodsForm::regex( $form_field_type, $options );
ui/fields/slider.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  wp_enqueue_script( 'jquery-ui-slider' );
3
- wp_enqueue_style( 'jquery-ui' );
4
 
5
  if ( is_array( $value ) )
6
  $value = implode( ',', $value );
1
  <?php
2
  wp_enqueue_script( 'jquery-ui-slider' );
3
+ wp_enqueue_style( 'pods-styles' );
4
 
5
  if ( is_array( $value ) )
6
  $value = implode( ',', $value );
ui/fields/text.php CHANGED
@@ -3,6 +3,7 @@
3
  $attributes[ 'type' ] = 'text';
4
  $attributes[ 'value' ] = $value;
5
  $attributes[ 'tabindex' ] = 2;
 
6
  $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options );
7
 
8
  if ( pods_var( 'readonly', $options, false ) ) {
3
  $attributes[ 'type' ] = 'text';
4
  $attributes[ 'value' ] = $value;
5
  $attributes[ 'tabindex' ] = 2;
6
+ $attributes[ 'class' ] = 'regular-text'; // For setting pages
7
  $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options );
8
 
9
  if ( pods_var( 'readonly', $options, false ) ) {
ui/fields/time.php CHANGED
@@ -1,128 +1,113 @@
1
  <?php
2
- $time_format = array(
3
- 'h_mm_A' => 'h:mm:ss TT',
4
- 'h_mm_ss_A' => 'h:mm TT',
5
- 'hh_mm_A' => 'hh:mm TT',
6
- 'hh_mm_ss_A' => 'hh:mm:ss TT',
7
- 'h_mma' => 'h:mmtt',
8
- 'hh_mma' => 'hh:mmtt',
9
- 'h_mm' => 'h:mm',
10
- 'h_mm_ss' => 'h:mm:ss',
11
- 'hh_mm' => 'hh:mm',
12
- 'hh_mm_ss' => 'hh:mm:ss'
13
- );
14
 
15
- $time_format_24 = array(
16
- 'hh_mm' => 'HH:mm',
17
- 'hh_mm_ss' => 'HH:mm:ss'
18
- );
19
 
20
- $time_format = apply_filters( 'pods_form_ui_field_time_js_formats', $time_format );
21
- $time_format_24 = apply_filters( 'pods_form_ui_field_time_js_formats_24', $time_format_24 );
22
 
23
- wp_enqueue_script( 'jquery-ui-datepicker' );
24
- wp_enqueue_script( 'jquery-ui-timepicker' );
25
- wp_enqueue_style( 'jquery-ui' );
26
- wp_enqueue_style( 'jquery-ui-timepicker' );
27
 
28
- $attributes = array();
29
 
30
- $type = 'text';
 
31
 
32
- if ( 1 == pods_var( $form_field_type . '_html5', $options ) )
33
- $type = $form_field_type;
34
 
35
- $attributes[ 'type' ] = $type;
36
- $attributes[ 'tabindex' ] = 2;
37
 
38
- $format = PodsForm::field_method( 'time', 'format', $options );
39
 
40
- $method = 'timepicker';
 
 
 
 
41
 
42
- $args = array(
43
- 'timeFormat' => $time_format[ pods_var( $form_field_type . '_format', $options, 'h_mma', null, true ) ]
44
- );
45
 
46
- if ( false !== stripos( $args[ 'timeFormat' ], 'tt' ) )
47
- $args[ 'ampm' ] = true;
48
 
49
- $html5_format = 'H:i:s';
 
50
 
51
- if ( 24 == pods_var( $form_field_type . '_type', $options, 12 ) ) {
52
- $args[ 'ampm' ] = false;
53
- $args[ 'timeFormat' ] = $time_format_24[ pods_var( $form_field_type . '_format_24', $options, 'hh_mm', null, true ) ];
54
- }
55
 
56
- $date = PodsForm::field_method( 'time', 'createFromFormat', $format, (string) $value );
57
- $date_default = PodsForm::field_method( 'time', 'createFromFormat', 'H:i:s', (string) $value );
 
 
58
 
59
- $formatted_date = $value;
 
 
 
 
 
 
 
 
60
 
61
- if ( 1 == pods_var( $form_field_type . '_allow_empty', $options, 1 ) && in_array( $value, array( '', '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
62
- $formatted_date = $value = '';
63
- elseif ( 'text' != $type ) {
64
- $formatted_date = $value;
65
 
66
- if ( false !== $date )
67
- $value = $date->format( $html5_format );
68
- elseif ( false !== $date_default )
69
- $value = $date_default->format( $html5_format );
70
- elseif ( !empty( $value ) )
71
- $value = date_i18n( $html5_format, strtotime( (string) $value ) );
72
- else
73
- $value = date_i18n( $html5_format );
74
- }
75
 
76
- $args = apply_filters( 'pods_form_ui_field_time_args', $args, $type, $options, $attributes, $name, $form_field_type );
77
 
78
- $attributes[ 'value' ] = $value;
79
-
80
- $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options );
81
  ?>
82
  <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?> />
83
 
84
  <script>
85
- jQuery( function () {
86
- var <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args = <?php echo json_encode( $args ); ?>;
87
-
88
- <?php
89
- if ( 'text' != $type ) {
90
- ?>
91
- if ( 'undefined' == typeof pods_test_time_field_<?php echo esc_js( $type ); ?> ) {
92
- // Test whether or not the browser supports date inputs
93
- function pods_test_time_field_<?php echo esc_js( $type ); ?> () {
94
- var input = jQuery( '<input/>', {
95
- 'type' : '<?php echo esc_js( $type ); ?>',
96
- css : {
97
- position : 'absolute',
98
- display : 'none'
99
- }
100
- } );
101
-
102
- jQuery( 'body' ).append( input );
103
-
104
- var bool = input.prop( 'type' ) !== 'text';
105
-
106
- if ( bool ) {
107
- var smile = ":)";
108
- input.val( smile );
109
-
110
- return (input.val() != smile);
111
- }
112
- }
113
- }
114
-
115
- if ( !pods_test_time_field_<?php echo esc_js( $type ); ?>() ) {
116
- jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).val( '<?php echo esc_js( $formatted_date ); ?>' );
117
- jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).<?php echo esc_js( $method ); ?>( <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args );
118
- }
119
- <?php
120
- }
121
- else {
122
- ?>
123
- jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).<?php echo esc_js( $method ); ?>( <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args );
124
- <?php
125
- }
126
- ?>
127
- } );
128
  </script>
1
  <?php
2
+ /**
3
+ * @var string $form_field_type
4
+ * @var array $options
5
+ * @var $value
6
+ */
 
 
 
 
 
 
 
7
 
8
+ wp_enqueue_script( 'jquery-ui-datepicker' );
9
+ wp_enqueue_script( 'jquery-ui-timepicker' );
10
+ wp_enqueue_style( 'pods-styles' );
11
+ wp_enqueue_style( 'jquery-ui-timepicker' );
12
 
13
+ PodsForm::field_method( 'time', 'enqueue_jquery_ui_i18n' );
 
14
 
15
+ $attributes = array();
 
 
 
16
 
17
+ $type = 'text';
18
 
19
+ if ( 1 == pods_var( $form_field_type . '_html5', $options ) )
20
+ $type = $form_field_type;
21
 
22
+ $attributes[ 'type' ] = $type;
23
+ $attributes[ 'tabindex' ] = 2;
24
 
25
+ $format = PodsForm::field_method( 'time', 'format', $options );
 
26
 
27
+ $method = 'timepicker';
28
 
29
+ $args = array(
30
+ 'ampm' => false,
31
+ // Get selected JS time format.
32
+ 'timeFormat' => PodsForm::field_method( 'time', 'format', $options, true ),
33
+ );
34
 
35
+ if ( false !== stripos( $args[ 'timeFormat' ], 'tt' ) )
36
+ $args[ 'ampm' ] = true;
 
37
 
38
+ $html5_format = 'H:i:s';
 
39
 
40
+ $date = PodsForm::field_method( 'time', 'createFromFormat', $format, (string) $value );
41
+ $date_default = PodsForm::field_method( 'time', 'createFromFormat', 'H:i:s', (string) $value );
42
 
43
+ $formatted_date = $value;
 
 
 
44
 
45
+ if ( 1 == pods_var( $form_field_type . '_allow_empty', $options, 1 ) && in_array( $value, array( '', '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
46
+ $formatted_date = $value = '';
47
+ elseif ( 'text' != $type ) {
48
+ $formatted_date = $value;
49
 
50
+ if ( false !== $date )
51
+ $value = $date->format( $html5_format );
52
+ elseif ( false !== $date_default )
53
+ $value = $date_default->format( $html5_format );
54
+ elseif ( !empty( $value ) )
55
+ $value = date_i18n( $html5_format, strtotime( (string) $value ) );
56
+ else
57
+ $value = date_i18n( $html5_format );
58
+ }
59
 
60
+ $args = apply_filters( 'pods_form_ui_field_time_args', $args, $type, $options, $attributes, $name, $form_field_type );
 
 
 
61
 
62
+ $attributes[ 'value' ] = $value;
 
 
 
 
 
 
 
 
63
 
64
+ $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options );
65
 
 
 
 
66
  ?>
67
  <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?> />
68
 
69
  <script>
70
+ jQuery( function () {
71
+ var <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args = <?php echo json_encode( $args ); ?>;
72
+
73
+ <?php
74
+ if ( 'text' != $type ) {
75
+ ?>
76
+ if ( 'undefined' == typeof pods_test_time_field_<?php echo esc_js( $type ); ?> ) {
77
+ // Test whether or not the browser supports date inputs
78
+ function pods_test_time_field_<?php echo esc_js( $type ); ?> () {
79
+ var input = jQuery( '<input/>', {
80
+ 'type' : '<?php echo esc_js( $type ); ?>',
81
+ css : {
82
+ position : 'absolute',
83
+ display : 'none'
84
+ }
85
+ } );
86
+
87
+ jQuery( 'body' ).append( input );
88
+
89
+ var bool = input.prop( 'type' ) !== 'text';
90
+
91
+ if ( bool ) {
92
+ var smile = ":)";
93
+ input.val( smile );
94
+
95
+ return (input.val() != smile);
96
+ }
97
+ }
98
+ }
99
+
100
+ if ( !pods_test_time_field_<?php echo esc_js( $type ); ?>() ) {
101
+ jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).val( '<?php echo esc_js( $formatted_date ); ?>' );
102
+ jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).<?php echo esc_js( $method ); ?>( <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args );
103
+ }
104
+ <?php
105
+ }
106
+ else {
107
+ ?>
108
+ jQuery( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ).<?php echo esc_js( $method ); ?>( <?php echo esc_js( pods_js_name( $attributes[ 'id' ] ) ); ?>_args );
109
+ <?php
110
+ }
111
+ ?>
112
+ } );
113
  </script>
ui/fields/website.php CHANGED
@@ -3,8 +3,9 @@ $attributes = array();
3
 
4
  $type = 'text';
5
 
6
- if ( 1 == pods_var( 'website_html5', $options ) )
7
- $type = 'url';
 
8
 
9
  $attributes[ 'type' ] = $type;
10
  $attributes[ 'value' ] = $value;
@@ -13,4 +14,4 @@ $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type,
13
  ?>
14
  <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?> />
15
  <?php
16
- PodsForm::regex( $form_field_type, $options );
3
 
4
  $type = 'text';
5
 
6
+ if ( pods_v( 'website_html5', $options, false ) && ! in_array( pods_v( 'website_format', $options ), array( 'no-http', 'no-http-no-www', 'no-http-force-www' ) ) ) {
7
+ $type = 'url';
8
+ }
9
 
10
  $attributes[ 'type' ] = $type;
11
  $attributes[ 'value' ] = $value;
14
  ?>
15
  <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?> />
16
  <?php
17
+ PodsForm::regex( $form_field_type, $options );
ui/front/form.php CHANGED
@@ -1,12 +1,20 @@
1
  <?php
2
- wp_enqueue_style( 'pods-form', false, array(), false, true );
3
-
4
- if ( wp_script_is( 'pods', 'registered' ) && !wp_script_is( 'pods', 'done' ) ) {
5
- wp_print_scripts( 'pods' );
6
- }
7
 
8
  // unset fields
9
  foreach ( $fields as $k => $field ) {
 
 
 
 
 
 
 
 
 
 
 
10
  if ( in_array( $field[ 'name' ], array( 'created', 'modified' ) ) ) {
11
  unset( $fields[ $k ] );
12
  }
@@ -170,18 +178,21 @@ if ( !$fields_only ) {
170
  </form>
171
 
172
  <script type="text/javascript">
173
- if ( 'undefined' == typeof pods_form_init && 'undefined' != typeof jQuery( document ).Pods ) {
174
- var pods_form_init = true;
175
 
176
- if ( 'undefined' == typeof ajaxurl ) {
177
- var ajaxurl = '<?php echo pods_slash( admin_url( 'admin-ajax.php' ) ); ?>';
178
- }
179
 
180
- jQuery( function ( $ ) {
181
- $( document ).Pods( 'validate' );
182
- $( document ).Pods( 'submit' );
183
- } );
184
- }
 
 
 
 
185
  </script>
186
  <?php
187
  }
1
  <?php
2
+ wp_enqueue_style( 'pods-form' );
3
+ wp_enqueue_script( 'pods' );
 
 
 
4
 
5
  // unset fields
6
  foreach ( $fields as $k => $field ) {
7
+
8
+ // Make sure all required array keys exist.
9
+ $field = wp_parse_args( $field, array(
10
+ 'name' => '',
11
+ 'type' => '',
12
+ 'label' => '',
13
+ 'help' => '',
14
+ 'options' => array(),
15
+ ) );
16
+ $fields[ $k ] = $field;
17
+
18
  if ( in_array( $field[ 'name' ], array( 'created', 'modified' ) ) ) {
19
  unset( $fields[ $k ] );
20
  }
178
  </form>
179
 
180
  <script type="text/javascript">
181
+ if ( 'undefined' === typeof pods_form_init ) {
182
+ var pods_form_init = true;
183
 
184
+ jQuery(document).ready( function( $ ) {
185
+ if ( 'undefined' !== typeof jQuery( document ).Pods ) {
 
186
 
187
+ if ( 'undefined' === typeof ajaxurl ) {
188
+ window.ajaxurl = '<?php echo pods_slash( admin_url( 'admin-ajax.php' ) ); ?>';
189
+ }
190
+
191
+ $( document ).Pods( 'validate' );
192
+ $( document ).Pods( 'submit' );
193
+ }
194
+ } );
195
+ }
196
  </script>
197
  <?php
198
  }
ui/front/view.php CHANGED
@@ -1,5 +1,5 @@
1
  <?php
2
- wp_enqueue_style( 'pods-form', false, array(), false, true );
3
 
4
  /**
5
  * @var array $fields
1
  <?php
2
+ wp_enqueue_style( 'pods-form' );
3
 
4
  /**
5
  * @var array $fields
ui/images/smoothness/ui-bg_flat_0_aaaaaa_40x100.png ADDED
Binary file
ui/images/smoothness/ui-bg_flat_75_ffffff_40x100.png ADDED
Binary file
ui/images/smoothness/ui-bg_glass_55_fbf9ee_1x400.png ADDED
Binary file
ui/images/smoothness/ui-bg_glass_65_ffffff_1x400.png ADDED
Binary file
ui/images/smoothness/ui-bg_glass_75_dadada_1x400.png ADDED
Binary file
ui/images/smoothness/ui-bg_glass_75_e6e6e6_1x400.png ADDED
Binary file
ui/images/smoothness/ui-bg_glass_95_fef1ec_1x400.png ADDED
Binary file
ui/images/smoothness/ui-bg_highlight-soft_75_cccccc_1x100.png ADDED
Binary file
ui/images/smoothness/ui-icons_222222_256x240.png ADDED
Binary file
ui/images/smoothness/ui-icons_2e83ff_256x240.png ADDED
Binary file
ui/images/smoothness/ui-icons_454545_256x240.png ADDED
Binary file
ui/images/smoothness/ui-icons_888888_256x240.png ADDED
Binary file
ui/images/smoothness/ui-icons_cd0a0a_256x240.png ADDED
Binary file
ui/js/floatmenu.js CHANGED
@@ -1,17 +1,39 @@
1
  // change the menu position based on the scroll positon
2
- window.onscroll = function () {
3
- if ( window.XMLHttpRequest ) {
4
- if ( document.documentElement.scrollTop > 33 || self.pageYOffset > 33 ) {
5
- jQuery( '.pods_floatmenu' ).css( 'position', 'fixed' );
6
- jQuery( '.pods_floatmenu' ).css( 'top', '52px' );
7
- jQuery( '.pods_floatmenu' ).css( 'right', '315px' );
 
 
 
 
8
  }
9
- else if ( document.documentElement.scrollTop < 33 || self.pageYOffset < 33 ) {
10
- jQuery( '.pods_floatmenu' ).css( 'position', 'relative' );
11
- jQuery( '.pods_floatmenu' ).css( 'top', 'auto' );
12
- jQuery( '.pods_floatmenu' ).css( 'right', 'auto' );
13
- //jQuery('.pods_floatmenu').css('top','112px');
14
- //jQuery('.pods_floatmenu').css('right','15px');
15
- }
16
- }
17
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  // change the menu position based on the scroll positon
2
+
3
+ jQuery(document).ready(function($) {
4
+ $( '.pods_floatmenu' ).each(function() {
5
+ var floatmenu = $( this );
6
+ var margin = 20;
7
+ var offset = floatmenu.offset();
8
+ var top = margin;
9
+ if ( $('html').hasClass( 'wp-toolbar' ) ) {
10
+ offset.top -= parseInt( $('html').css('padding-top') );
11
+ top += parseInt( $('html').css('padding-top') );
12
  }
13
+ offset.left -= margin;
14
+ offset.top -= margin;
15
+ var right = $(window).width() - offset.left;
16
+ window.onscroll = function () {
17
+ if ( window.XMLHttpRequest ) {
18
+ // Make sure the window height is larger than the floatmenu height
19
+ if ( $(window).height() < ( floatmenu.height() + ( 2 * margin ) ) ) {
20
+ return;
21
+ }
22
+ if ( document.documentElement.scrollTop > offset.top || self.pageYOffset > offset.top ) {
23
+ floatmenu.css( {
24
+ 'position': 'fixed',
25
+ 'top': top + 'px',
26
+ 'right': right + 'px'
27
+ } );
28
+ }
29
+ else if ( document.documentElement.scrollTop < offset.top || self.pageYOffset < offset.top ) {
30
+ floatmenu.css( {
31
+ 'position': 'relative',
32
+ 'top': 'auto',
33
+ 'right': 'auto'
34
+ } );
35
+ }
36
+ }
37
+ };
38
+ });
39
+ });
ui/js/jquery.pods.attach.js CHANGED
@@ -1,3 +1,4 @@
 
1
  var pods_file_context = false; // tracks whether or not we've got a thickbox displayed in our context
2
  var pods_file_thickbox_modder; // stores our interval for making necessary changes to thickbox content
3
 
@@ -14,7 +15,7 @@ function pods_attachments ( src, file_limit ) {
14
 
15
  if ( wp_media_show.data( 'pods-injected-quick-add') !== true ) {
16
  // Create 'Add' link
17
- var pods_file_quick_add = jQuery( '<a href="#">Add</a>' ).addClass( 'pods-quick-add' );
18
 
19
  pods_file_quick_add.bind( 'click', function( e ) {
20
  var item = jQuery( this );
@@ -23,7 +24,7 @@ function pods_attachments ( src, file_limit ) {
23
  item.fadeOut( 'fast', function() {
24
 
25
  // Not sure if the close link should be there for each link?
26
- item.before( '<span class="pods-attached pods-quick-add">Added!</span>' );
27
  //item.before( '<span class="pods-attached pods-quick-add">Added! <a href="#">close this box</a>.</span>' );
28
 
29
  item.remove(); }
@@ -92,7 +93,7 @@ function pods_attachments ( src, file_limit ) {
92
  }
93
 
94
  if ( 1 < file_limit || file_limit == 0 ) {
95
- jQuery( this ).after( ' <span class="pods-attached">Added! Choose another or <a href="#">close this box</a>.</span>' );
96
  jQuery( this ).parent().find( 'span.pods-attached a' ).on( 'click', function ( e ) {
97
  parent.eval( 'tb_remove()' );
98
 
1
+ /*@global PodsI18n */
2
  var pods_file_context = false; // tracks whether or not we've got a thickbox displayed in our context
3
  var pods_file_thickbox_modder; // stores our interval for making necessary changes to thickbox content
4
 
15
 
16
  if ( wp_media_show.data( 'pods-injected-quick-add') !== true ) {
17
  // Create 'Add' link
18
+ var pods_file_quick_add = jQuery( '<a href="#">' + PodsI18n.__( 'Add' ) + '</a>' ).addClass( 'pods-quick-add' );
19
 
20
  pods_file_quick_add.bind( 'click', function( e ) {
21
  var item = jQuery( this );
24
  item.fadeOut( 'fast', function() {
25
 
26
  // Not sure if the close link should be there for each link?
27
+ item.before( '<span class="pods-attached pods-quick-add">' + PodsI18n.__( 'Added!' ) + '</span>' );
28
  //item.before( '<span class="pods-attached pods-quick-add">Added! <a href="#">close this box</a>.</span>' );
29
 
30
  item.remove(); }
93
  }
94
 
95
  if ( 1 < file_limit || file_limit == 0 ) {
96
+ jQuery( this ).after( ' <span class="pods-attached">' + PodsI18n.__( 'Added! Choose another or <a href="#">close this box</a>' ) + '</span>' );
97
  jQuery( this ).parent().find( 'span.pods-attached a' ).on( 'click', function ( e ) {
98
  parent.eval( 'tb_remove()' );
99
 
ui/js/jquery.pods.js CHANGED
@@ -1,3 +1,4 @@
 
1
  ( function ( $ ) {
2
  var pods_changed = false,
3
  pods_form_field_names = [],
@@ -48,7 +49,12 @@
48
  if ( !valid_field ) {
49
  if ( -1 == jQuery.inArray( $el.prop( 'name' ), pods_form_field_names ) ) {
50
  $el.closest( '.pods-field-input' ).find( '.pods-validate-error-message' ).remove();
51
- $el.closest( '.pods-field-input' ).append( '<div class="pods-validate-error-message">' + label.replace( /( <([^>]+ )> )/ig, '' ) + ' is required.</div>' );
 
 
 
 
 
52
  $el.addClass( 'pods-validate-error' );
53
 
54
  pods_form_field_names.push( $el.prop( 'name' ) );
@@ -142,7 +148,7 @@
142
  } );
143
  },
144
  submit : function () {
145
- var $submitbutton;
146
 
147
  // Handle submit of form and translate to AJAX
148
  $( 'form.pods-submittable' ).on( 'submit', function ( e ) {
@@ -204,6 +210,16 @@
204
  }
205
  } );
206
 
 
 
 
 
 
 
 
 
 
 
207
  if ( 'undefined' != typeof pods_admin_submit_validation )
208
  valid_form = pods_admin_submit_validation( valid_form, $submittable );
209
 
@@ -237,32 +253,57 @@
237
  cache : false,
238
  data : postdata,
239
  success : function ( d ) {
240
- if ( -1 == d.indexOf( '<e>' ) && -1 == d.indexOf( '</e>' ) && -1 != d ) {
241
- var id = d.match( /\d*$/, '' );
242
 
243
- if ( 0 < id.length ) {
244
- id = parseInt( id[ 0 ] );
 
 
 
 
 
245
 
246
- if ( isNa
1
+ /*@global PodsI18n */
2
  ( function ( $ ) {
3
  var pods_changed = false,
4
  pods_form_field_names = [],
49
  if ( !valid_field ) {
50
  if ( -1 == jQuery.inArray( $el.prop( 'name' ), pods_form_field_names ) ) {
51
  $el.closest( '.pods-field-input' ).find( '.pods-validate-error-message' ).remove();
52
+
53
+ if ( $el.closest( '.pods-field-input > td' ).length > 0 ) {
54
+ $el.closest( '.pods-field-input > td' ).last().prepend( '<div class="pods-validate-error-message">' + PodsI18n.__( '%s is required.' ).replace( '%s', label.replace( /( <([^>]+ )> )/ig, '' ) ) + '</div>' );
55
+ } else {
56
+ $el.closest( '.pods-field-input' ).append( '<div class="pods-validate-error-message">' + PodsI18n.__( '%s is required.' ).replace( '%s', label.replace( /( <([^>]+ )> )/ig, '' ) ) + '</div>' );
57
+ }
58
  $el.addClass( 'pods-validate-error' );
59
 
60
  pods_form_field_names.push( $el.prop( 'name' ) );
148
  } );
149
  },
150
  submit : function () {
151
+ var $submitbutton, id, data;
152
 
153
  // Handle submit of form and translate to AJAX
154
  $( 'form.pods-submittable' ).on( 'submit', function ( e ) {
210
  }
211
  } );
212
 
213
+ // Check for unsaved open fields. (separate if's to prevent possible unneeded jQuery selector)
214
+ if ( 'undefined' !== typeof postdata.method ) {
215
+ if ( 'save_pod' === postdata.method ) {
216
+ if ( $( 'tbody.pods-manage-list tr.pods-manage-row-expanded', $submittable ).length ) {
217
+ alert( PodsI18n.__( 'Some fields have changes that were not saved yet, please save them or cancel the changes before saving the Pod.' ) );
218
+ valid_form = false;
219
+ }
220
+ }
221
+ }
222
+
223
  if ( 'undefined' != typeof pods_admin_submit_validation )
224
  valid_form = pods_admin_submit_validation( valid_form, $submittable );
225
 
253
  cache : false,
254
  data : postdata,
255
  success : function ( d ) {
 
 
256
 
257
+ // Attempt to parse what was returned as data
258
+ try {
259
+ data = $.parseJSON( d );
260
+ }
261
+ catch ( e ) {
262
+ data = undefined;
263
+ }
264