Advanced Custom Fields - Version 2.1.1

Version Description

  • Fixed Javascript bugs on edit pages
Download this release

Release Info

Developer elliotcondon
Plugin Icon 128x128 Advanced Custom Fields
Version 2.1.1
Comparing to
See all releases

Code changes from version 2.0.5 to 2.1.1

Files changed (50) hide show
  1. acf.php +771 -393
  2. core/acf_post_type.php +0 -36
  3. core/actions/admin_head.php +60 -0
  4. core/{fields_save.php → actions/fields_save.php} +5 -11
  5. core/actions/init.php +195 -0
  6. core/actions/input_save.php +95 -0
  7. core/{location_save.php → actions/location_save.php} +0 -0
  8. core/{options_save.php → actions/options_save.php} +0 -0
  9. core/{fields_meta_box.php → admin/fields_meta_box.php} +47 -26
  10. core/admin/input_meta_box.php +172 -0
  11. core/{location_meta_box.php → admin/location_meta_box.php} +30 -2
  12. core/{options_meta_box.php → admin/options_meta_box.php} +0 -0
  13. core/{options_page.php → admin/options_page.php} +99 -41
  14. core/admin_head.php +0 -238
  15. core/api.php +175 -252
  16. core/fields/checkbox.php +12 -3
  17. core/fields/date_picker/date_picker.php +4 -3
  18. core/fields/date_picker/jquery.ui.datepicker.js +0 -0
  19. core/fields/date_picker/style.date_picker.css +0 -0
  20. core/fields/file.php +53 -34
  21. core/fields/image.php +41 -53
  22. core/fields/page_link.php +35 -14
  23. core/fields/post_object.php +41 -15
  24. core/fields/radio.php +237 -0
  25. core/fields/repeater.php +110 -56
  26. core/fields/select.php +43 -10
  27. core/fields/text.php +35 -1
  28. core/fields/textarea.php +36 -2
  29. core/fields/true_false.php +5 -3
  30. core/fields/wysiwyg.php +1 -1
  31. core/import.php +9 -8
  32. core/input_meta_box.php +0 -145
  33. core/input_save.php +0 -78
  34. core/screen_extra.php +2 -2
  35. core/third_party.php +61 -0
  36. core/update.php +0 -593
  37. core/upgrade.php +207 -0
  38. css/style.fields.css +148 -86
  39. css/style.global.css +29 -15
  40. css/style.input.css +53 -15
  41. css/style.screen_extra.css +11 -1
  42. images/backgrounds +0 -0
  43. images/backgrounds.png +0 -0
  44. images/backgrounds.psd +0 -0
  45. images/loading.gif +0 -0
  46. images/loading_old.gif +0 -0
  47. js/functions.fields.js +73 -48
  48. js/functions.input.js +264 -226
  49. js/functions.screen_extra.js +3 -0
  50. readme.txt +20 -0
acf.php CHANGED
@@ -2,8 +2,8 @@
2
  /*
3
  Plugin Name: Advanced Custom Fields
4
  Plugin URI: http://plugins.elliotcondon.com/advanced-custom-fields/
5
- Description: Completely Customise your edit pages with an assortment of field types: Wysiwyg, Repeater, text, textarea, image, file, select, checkbox post type, page link and more! Hide unwanted metaboxes and assign to any edit page!
6
- Version: 2.0.5
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
@@ -14,7 +14,7 @@ Copyright: Elliot Condon
14
  //error_reporting(E_ALL|E_STRICT);
15
 
16
 
17
- include('core/options_page.php');
18
 
19
  $acf = new Acf();
20
 
@@ -23,7 +23,7 @@ include('core/api.php');
23
 
24
  class Acf
25
  {
26
- var $name;
27
  var $dir;
28
  var $path;
29
  var $siteurl;
@@ -33,16 +33,25 @@ class Acf
33
  var $activated_fields;
34
  var $options_page;
35
 
 
 
 
 
 
 
 
 
 
 
36
  function Acf()
37
  {
38
 
39
  // set class variables
40
- $this->name = 'Advanced Custom Fields';
41
  $this->path = dirname(__FILE__).'';
42
  $this->dir = plugins_url('',__FILE__);
43
  $this->siteurl = get_bloginfo('url');
44
  $this->wpadminurl = admin_url();
45
- $this->version = '2.0.5';
46
  $this->activated_fields = $this->get_activated_fields();
47
  $this->options_page = new Acf_options_page($this);
48
 
@@ -50,73 +59,77 @@ class Acf
50
  // set text domain
51
  load_plugin_textdomain('acf', false, $this->path.'/lang' );
52
 
53
-
54
  // populate post types
55
- $this->fields = $this->_get_field_types();
56
 
57
 
58
  // add actions
59
- add_action('init', array($this, '_init'));
60
  add_action('init', array($this, 'import'));
61
  add_action('init', array($this, 'export'));
62
- add_action('admin_head', array($this,'_admin_head'));
63
- add_action('admin_menu', array($this,'_admin_menu'));
64
- add_action('save_post', array($this, '_save_post'));
 
65
  add_action('admin_footer', array($this, '_admin_footer'));
 
66
 
67
 
68
-
69
- // add thickbox
70
- add_action("admin_print_scripts", array($this, '_admin_print_scripts'));
71
- add_action("admin_print_styles", array($this, '_admin_print_styles'));
72
-
73
-
74
- // update if versions don't match
75
- if(get_option('acf_version') != $this->version)
76
- {
77
- $this->update();
78
- }
79
-
80
 
81
  return true;
82
  }
83
-
84
- /*---------------------------------------------------------------------------------------------
85
- * Update
86
- *
87
- * @author Elliot Condon
88
- * @since 1.0.6
89
- *
90
- ---------------------------------------------------------------------------------------------*/
91
- function update()
 
 
 
92
  {
93
- include('core/update.php');
94
  }
95
 
96
-
97
- /*---------------------------------------------------------------------------------------------
98
- * Init
99
- *
100
- * @author Elliot Condon
101
- * @since 1.0.0
102
- *
103
- ---------------------------------------------------------------------------------------------*/
104
- function _init()
 
 
 
105
  {
106
- // create acf post type
107
- $this->_acf_post_type();
108
-
109
  }
110
 
111
- function _admin_print_scripts()
 
 
 
 
 
 
 
 
 
 
112
  {
113
- $currentFile = $_SERVER["SCRIPT_NAME"];
114
- $parts = Explode('/', $currentFile);
115
- $currentFile = $parts[count($parts) - 1];
116
-
117
-
118
- if($currentFile == 'post.php' || $currentFile == 'post-new.php' || $currentFile == 'edit.php')
119
  {
 
120
  wp_enqueue_script('jquery');
121
  wp_enqueue_script('jquery-ui-core');
122
 
@@ -127,40 +140,52 @@ class Acf
127
  wp_enqueue_script('word-count');
128
  wp_enqueue_script('post');
129
  wp_enqueue_script('editor');
130
-
131
 
132
  // repeater
133
  wp_enqueue_script('jquery-ui-sortable');
134
  }
135
  }
136
 
137
- function _admin_print_styles()
 
 
 
 
 
 
 
 
 
 
138
  {
139
- $currentFile = $_SERVER["SCRIPT_NAME"];
140
- $parts = Explode('/', $currentFile);
141
- $currentFile = $parts[count($parts) - 1];
142
-
143
- if($currentFile == 'post.php' || $currentFile == 'post-new.php' || $currentFile == 'edit.php')
144
  {
145
  wp_enqueue_style('thickbox');
146
  }
147
  }
148
 
149
- /*---------------------------------------------------------------------------------------------
150
- * Save Post
151
- *
152
- * @author Elliot Condon
153
- * @since 1.0.0
154
- *
155
- ---------------------------------------------------------------------------------------------*/
156
- function _save_post($post_id)
157
- {
 
 
 
 
158
  // do not save if this is an auto save routine
159
  if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
160
 
 
161
  // verify this with nonce because save_post can be triggered at other times
162
  if (!wp_verify_nonce($_POST['ei_noncename'], 'ei-n')) return $post_id;
163
 
 
164
  // only save once! WordPress save's twice for some strange reason.
165
  global $flag;
166
  if ($flag != 0) return $post_id;
@@ -174,91 +199,57 @@ class Acf
174
  }
175
 
176
 
177
- // delete _acf custom fields if needed
178
- if(isset($_POST['fields_meta_box']) || isset($_POST['location_meta_box']) || isset($_POST['input_meta_box']))
179
- {
180
- $this->delete_acf_custom_fields($post_id);
181
- }
182
-
183
-
184
- // include meta box save files
185
- include('core/fields_save.php');
186
- include('core/location_save.php');
187
- include('core/options_save.php');
188
- include('core/input_save.php');
189
  }
 
190
 
191
 
192
- /*---------------------------------------------------------------------------------------------
193
- * Create ACF Post Type
194
- *
195
- * @author Elliot Condon
196
- * @since 1.0.0
197
- *
198
- ---------------------------------------------------------------------------------------------*/
199
- function _acf_post_type()
200
- {
201
- include('core/acf_post_type.php');
202
- }
203
-
204
 
205
- /*---------------------------------------------------------------------------------------------
206
- * Admin Menu
207
- *
208
- * @author Elliot Condon
209
- * @since 1.0.0
210
- *
211
- ---------------------------------------------------------------------------------------------*/
212
- function _admin_menu() {
213
 
214
  // add sub menu
215
- add_submenu_page('options-general.php', 'CFA', __('Adv Custom Fields','acf'), 'manage_options','edit.php?post_type=acf');
216
-
217
- // remove acf menu item
218
- global $menu;
219
- $restricted = array(__('Advanced Custom Fields','acf'));
220
- end ($menu);
221
- while (prev($menu)){
222
- $value = explode(' ',$menu[key($menu)][0]);
223
- if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
224
- }
225
 
226
  }
227
 
228
- /*---------------------------------------------------------------------------------------------
229
- * Admin Head
230
- *
231
- * @author Elliot Condon
232
- * @since 1.0.0
233
- *
234
- ---------------------------------------------------------------------------------------------*/
235
- function _admin_head()
236
- {
237
- include('core/admin_head.php');
238
- }
239
 
 
 
 
 
 
 
 
 
240
 
241
- /*---------------------------------------------------------------------------------------------
242
- * activate
243
- *
244
- * @author Elliot Condon
245
- * @since 1.0.0
246
- *
247
- ---------------------------------------------------------------------------------------------*/
248
- function activate()
249
  {
250
- //include('core/update.php');
251
  }
 
252
 
 
 
 
 
 
 
 
 
253
 
254
- /*---------------------------------------------------------------------------------------------
255
- * _get_field_types
256
- *
257
- * @author Elliot Condon
258
- * @since 1.0.0
259
- *
260
- ---------------------------------------------------------------------------------------------*/
261
- function _get_field_types()
262
  {
263
  $array = array();
264
 
@@ -269,19 +260,21 @@ class Acf
269
  include_once('core/fields/file.php');
270
  include_once('core/fields/select.php');
271
  include_once('core/fields/checkbox.php');
 
272
  include_once('core/fields/true_false.php');
273
  include_once('core/fields/page_link.php');
274
  include_once('core/fields/post_object.php');
275
  include_once('core/fields/date_picker/date_picker.php');
276
  include_once('core/fields/repeater.php');
277
 
278
- $array['text'] = new acf_Text();
279
- $array['textarea'] = new acf_Textarea();
280
  $array['wysiwyg'] = new acf_Wysiwyg();
281
  $array['image'] = new acf_Image($this);
282
  $array['file'] = new acf_File($this);
283
  $array['select'] = new acf_Select($this);
284
  $array['checkbox'] = new acf_Checkbox();
 
285
  $array['true_false'] = new acf_True_false();
286
  $array['page_link'] = new acf_Page_link($this);
287
  $array['post_object'] = new acf_Post_object($this);
@@ -296,13 +289,15 @@ class Acf
296
  }
297
 
298
 
299
- /*---------------------------------------------------------------------------------------------
300
- * create_field
301
- *
302
- * @author Elliot Condon
303
- * @since 1.0.0
304
- *
305
- ---------------------------------------------------------------------------------------------*/
 
 
306
  function create_field($field)
307
  {
308
  if(!is_object($this->fields[$field->type]))
@@ -314,13 +309,16 @@ class Acf
314
  $this->fields[$field->type]->html($field);
315
  }
316
 
317
- /*---------------------------------------------------------------------------------------------
318
- * save_field
319
- *
320
- * @author Elliot Condon
321
- * @since 1.0.0
322
- *
323
- ---------------------------------------------------------------------------------------------*/
 
 
 
324
  function save_field($options)
325
  {
326
  if(!$this->fields[$options['field_type']])
@@ -333,87 +331,80 @@ class Acf
333
  }
334
 
335
 
336
- /*---------------------------------------------------------------------------------------------
337
- * Add Meta Box to the ACF post type edit page
338
- *
339
- * @author Elliot Condon
340
- * @since 1.0.0
341
- *
342
- ---------------------------------------------------------------------------------------------*/
 
 
343
  function _fields_meta_box()
344
  {
345
- include('core/fields_meta_box.php');
346
  }
347
 
348
 
349
- /*---------------------------------------------------------------------------------------------
350
- * Add Meta Box to the ACF post type edit page
351
- *
352
- * @author Elliot Condon
353
- * @since 1.0.0
354
- *
355
- ---------------------------------------------------------------------------------------------*/
 
 
356
  function _location_meta_box()
357
  {
358
- include('core/location_meta_box.php');
359
  }
360
 
361
 
362
- /*---------------------------------------------------------------------------------------------
363
- * Add Meta Box to the selected post type edit page
364
- *
365
- * @author Elliot Condon
366
- * @since 1.0.0
367
- *
368
- ---------------------------------------------------------------------------------------------*/
369
- function _input_meta_box($post, $args)
 
 
370
  {
371
- include('core/input_meta_box.php');
372
  }
373
 
374
 
375
- /*---------------------------------------------------------------------------------------------
376
- * Add Meta Box to the ACF post type edit page
377
- *
378
- * @author Elliot Condon
379
- * @since 1.0.0
380
- *
381
- ---------------------------------------------------------------------------------------------*/
382
- function _options_meta_box()
 
 
383
  {
384
- include('core/options_meta_box.php');
385
  }
386
 
 
 
387
 
388
- /*---------------------------------------------------------------------------------------------
389
- * delete_acf_custom_fields
390
- *
391
- * @author Elliot Condon
392
- * @since 1.0.0
393
- *
394
- ---------------------------------------------------------------------------------------------*/
395
- function delete_acf_custom_fields($post_id)
396
- {
397
-
398
- foreach(get_post_custom($post_id) as $key => $values)
399
- {
400
- if(strpos($key, '_acf') !== false)
401
- {
402
- // this custom field needs to be deleted!
403
- delete_post_meta($post_id, $key);
404
- }
405
- }
406
- }
407
-
408
- /*---------------------------------------------------------------------------------------------
409
- * get_fields
410
- *
411
- * @author Elliot Condon
412
- * @since 1.0.0
413
- *
414
- ---------------------------------------------------------------------------------------------*/
415
- function get_fields($acf_id)
416
- {
417
 
418
  // set table name
419
  global $wpdb;
@@ -426,7 +417,7 @@ class Acf
426
 
427
 
428
  // if fields are empty, this must be a new or broken acf. add blank field
429
- if(empty($fields))
430
  {
431
  return array();
432
  }
@@ -437,9 +428,11 @@ class Acf
437
  {
438
 
439
  // unserialize options
440
- $field->options = @unserialize($field->options);
441
-
442
- if(!is_array($field->options))
 
 
443
  {
444
  $field->options = array();
445
  }
@@ -462,35 +455,45 @@ class Acf
462
  foreach($sub_fields as $sub_field)
463
  {
464
  // unserialize options
465
- $sub_field->options = unserialize($sub_field->options);
 
 
 
 
 
 
 
 
466
  }
467
 
468
 
469
  // assign array to the field options array
470
  $field->options['sub_fields'] = $sub_fields;
471
  }
472
-
473
-
474
-
475
  }
476
  // end if sub field
477
  }
478
  // end foreach $fields
479
 
 
480
  // return fields
481
- return $fields;
482
 
483
- }
484
 
485
- /*---------------------------------------------------------------------------------------------
486
- * get_field_options
487
- *
488
- * @author Elliot Condon
489
- * @since 1.0.0
490
- *
491
- ---------------------------------------------------------------------------------------------*/
492
- function get_field_options($type, $options)
493
- {
 
 
 
494
  $field_options = $this->fields[$type]->options();
495
 
496
  ?>
@@ -507,17 +510,20 @@ class Acf
507
  <?php endforeach; ?>
508
  </table>
509
  <?php
510
- }
511
-
512
- /*---------------------------------------------------------------------------------------------
513
- * get_acf_location
514
- *
515
- * @author Elliot Condon
516
- * @since 1.0.0
517
- *
518
- ---------------------------------------------------------------------------------------------*/
519
- function get_acf_location($acf_id)
520
- {
 
 
 
521
 
522
  // set table name
523
  global $wpdb;
@@ -533,18 +539,21 @@ class Acf
533
  // return location
534
  return $location;
535
 
536
- }
537
 
538
 
539
- /*---------------------------------------------------------------------------------------------
540
- * get_acf_options
541
- *
542
- * @author Elliot Condon
543
- * @since 1.0.0
544
- *
545
- ---------------------------------------------------------------------------------------------*/
546
- function get_acf_options($acf_id)
547
- {
 
 
 
548
  $options = new stdClass();
549
 
550
 
@@ -577,21 +586,22 @@ class Acf
577
 
578
  return $options;
579
 
580
- }
581
 
582
 
583
- /*---------------------------------------------------------------------------------------------
584
- * admin_footer
585
- *
586
- * @author Elliot Condon
587
- * @since 1.0.0
588
- *
589
- ---------------------------------------------------------------------------------------------*/
 
 
590
  function _admin_footer()
591
  {
592
- global $post;
593
-
594
- if(isset($_GET['post_type']) && $_GET['post_type'] == 'acf')
595
  {
596
  echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.screen_extra.css" />';
597
  echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.screen_extra.js" ></script>';
@@ -600,96 +610,127 @@ class Acf
600
 
601
  }
602
 
603
- /*---------------------------------------------------------------------------------------------
604
- * load_value_for_input
605
- *
606
- * @author Elliot Condon
607
- * @since 1.0.6
608
- *
609
- ---------------------------------------------------------------------------------------------*/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
610
  function load_value_for_input($post_id, $field)
611
  {
612
- if(method_exists($this->fields[$field->type], 'load_value_for_input'))
 
 
 
 
613
  {
614
  $value = $this->fields[$field->type]->load_value_for_input($post_id, $field);
615
  }
616
  else
617
  {
618
- // set table name
619
  global $wpdb;
620
- $table_name = $wpdb->prefix.'acf_values';
 
621
 
622
 
623
  // get row
624
- $value = $wpdb->get_var("SELECT value FROM $table_name WHERE field_id = '$field->id' AND post_id = '$post_id'");
625
-
626
- }
627
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
628
 
629
- // format if needed
630
- if(method_exists($this->fields[$field->type], 'format_value_for_input'))
631
- {
632
- $value = $this->fields[$field->type]->format_value_for_input($value);
633
  }
634
 
635
-
636
  // return value
637
  return $value;
638
  }
639
 
640
-
641
- /*---------------------------------------------------------------------------------------------
642
- * load_value_id_input
643
- *
644
- * @author Elliot Condon
645
- * @since 2.0.4
646
- *
647
- ---------------------------------------------------------------------------------------------*/
648
-
649
- function load_value_id_input($post_id, $field)
650
- {
651
- // set table name
652
- global $wpdb;
653
- $table_name = $wpdb->prefix.'acf_values';
654
-
655
-
656
- // get row
657
- $value = $wpdb->get_var("SELECT id FROM $table_name WHERE field_id = '$field->id' AND post_id = '$post_id'");
658
-
659
- return $value;
660
- }
661
 
662
 
663
-
664
- /*---------------------------------------------------------------------------------------------
665
- * load_value_for_api
666
- *
667
- * @author Elliot Condon
668
- * @since 1.0.6
669
- *
670
- ---------------------------------------------------------------------------------------------*/
 
671
  function load_value_for_api($post_id, $field)
672
  {
673
- if(method_exists($this->fields[$field->type], 'load_value_for_api'))
 
674
  {
675
  $value = $this->fields[$field->type]->load_value_for_api($post_id, $field);
676
  }
677
  else
678
  {
679
- // set table name
680
  global $wpdb;
681
- $table_name = $wpdb->prefix.'acf_values';
 
682
 
683
 
684
  // get var
685
- $value = $wpdb->get_var("SELECT value FROM $table_name WHERE field_id = '$field->id' AND post_id = '$post_id'");
686
- //$value = stripslashes($value);
687
-
688
 
 
689
  // format if needed
690
- if(method_exists($this->fields[$field->type], 'format_value_for_api'))
691
  {
692
- $value = $this->fields[$field->type]->format_value_for_api($value);
693
  }
694
  }
695
 
@@ -705,13 +746,15 @@ class Acf
705
  }
706
 
707
 
708
- /*---------------------------------------------------------------------------------------------
709
- * get_activated_fields
710
- *
711
- * @author Elliot Condon
712
- * @since 2.0.0
713
- *
714
- ---------------------------------------------------------------------------------------------*/
 
 
715
  function get_activated_fields()
716
  {
717
  $activated = array();
@@ -724,10 +767,6 @@ class Acf
724
  {
725
  $activated['repeater'] = get_option("acf_repeater_ac");
726
  }
727
- if($md5 == "44146dd6d0f8873f34e4a0b75e5639f7")
728
- {
729
- $activated['repeater'] = get_option("acf_repeater_ac")." (Testing License)";
730
- }
731
  }
732
 
733
 
@@ -745,24 +784,28 @@ class Acf
745
  }
746
 
747
 
748
-
749
- /*---------------------------------------------------------------------------------------------
750
- * match_location_rule
751
- *
752
- * @author Elliot Condon
753
- * @since 2.0.s
754
- *
755
- ---------------------------------------------------------------------------------------------*/
756
- function match_location_rule($post, $rule)
 
757
  {
 
758
  switch ($rule->param) {
759
 
760
  // POST TYPE
761
  case "post_type":
 
 
762
 
763
  if($rule->operator == "==")
764
  {
765
- if(get_post_type($post) == $rule->value)
766
  {
767
  return true;
768
  }
@@ -771,7 +814,7 @@ class Acf
771
  }
772
  elseif($rule->operator == "!=")
773
  {
774
- if(get_post_type($post) != $rule->value)
775
  {
776
  return true;
777
  }
@@ -784,9 +827,11 @@ class Acf
784
  // PAGE
785
  case "page":
786
 
 
 
787
  if($rule->operator == "==")
788
  {
789
- if($post->ID == $rule->value)
790
  {
791
  return true;
792
  }
@@ -795,7 +840,7 @@ class Acf
795
  }
796
  elseif($rule->operator == "!=")
797
  {
798
- if($post->ID != $rule->value)
799
  {
800
  return true;
801
  }
@@ -808,14 +853,16 @@ class Acf
808
  // PAGE
809
  case "page_type":
810
 
 
 
811
  if($rule->operator == "==")
812
  {
813
- if($rule->value == "parent" && $post->post_parent == "0")
814
  {
815
  return true;
816
  }
817
 
818
- if($rule->value == "child" && $post->post_parent != "0")
819
  {
820
  return true;
821
  }
@@ -824,12 +871,12 @@ class Acf
824
  }
825
  elseif($rule->operator == "!=")
826
  {
827
- if($rule->value == "parent" && $post->post_parent != "0")
828
  {
829
  return true;
830
  }
831
 
832
- if($rule->value == "child" && $post->post_parent == "0")
833
  {
834
  return true;
835
  }
@@ -842,9 +889,11 @@ class Acf
842
  // PAGE PARENT
843
  case "page_parent":
844
 
 
 
845
  if($rule->operator == "==")
846
  {
847
- if($post->post_parent == $rule->value)
848
  {
849
  return true;
850
  }
@@ -854,7 +903,7 @@ class Acf
854
  }
855
  elseif($rule->operator == "!=")
856
  {
857
- if($post->post_parent != $rule->value)
858
  {
859
  return true;
860
  }
@@ -867,24 +916,25 @@ class Acf
867
  // PAGE
868
  case "page_template":
869
 
 
 
870
  if($rule->operator == "==")
871
  {
872
- if(get_post_meta($post->ID,'_wp_page_template',true) == $rule->value)
873
  {
874
  return true;
875
  }
876
 
877
- if($rule->value == "default" && !get_post_meta($post->ID,'_wp_page_template',true))
878
  {
879
  return true;
880
  }
881
 
882
-
883
  return false;
884
  }
885
  elseif($rule->operator == "!=")
886
  {
887
- if(get_post_meta($post->ID,'_wp_page_template',true) != $rule->value)
888
  {
889
  return true;
890
  }
@@ -897,9 +947,11 @@ class Acf
897
  // POST
898
  case "post":
899
 
 
 
900
  if($rule->operator == "==")
901
  {
902
- if($post->ID == $rule->value)
903
  {
904
  return true;
905
  }
@@ -908,7 +960,7 @@ class Acf
908
  }
909
  elseif($rule->operator == "!=")
910
  {
911
- if($post->ID != $rule->value)
912
  {
913
  return true;
914
  }
@@ -921,19 +973,28 @@ class Acf
921
  // POST CATEGORY
922
  case "post_category":
923
 
924
- // category names
925
- $cats = get_the_category();
926
-
 
 
 
 
 
 
 
 
 
 
 
 
927
  if($rule->operator == "==")
928
  {
929
  if($cats)
930
  {
931
- foreach($cats as $cat)
932
  {
933
- if($cat->term_id == $rule->value)
934
- {
935
- return true;
936
- }
937
  }
938
  }
939
 
@@ -943,12 +1004,9 @@ class Acf
943
  {
944
  if($cats)
945
  {
946
- foreach($cats as $cat)
947
  {
948
- if($cat->term_id != $rule->value)
949
- {
950
- return true;
951
- }
952
  }
953
  }
954
 
@@ -958,11 +1016,14 @@ class Acf
958
  break;
959
 
960
  // PAGE PARENT
 
961
  case "post_format":
962
 
 
 
963
  if($rule->operator == "==")
964
  {
965
- if(get_post_format() == $rule->value)
966
  {
967
  return true;
968
  }
@@ -970,7 +1031,7 @@ class Acf
970
  return false;
971
 
972
  }
973
- elseif(get_post_format() == "!=")
974
  {
975
  if($post->post_parent != $rule->value)
976
  {
@@ -981,7 +1042,7 @@ class Acf
981
  }
982
 
983
  break;
984
-
985
 
986
  // USER TYPE
987
  case "user_type":
@@ -1010,7 +1071,7 @@ class Acf
1010
  // Options Page
1011
  case "options_page":
1012
 
1013
-
1014
  if($rule->operator == "==")
1015
  {
1016
  if(get_admin_page_title() == $rule->value)
@@ -1032,17 +1093,49 @@ class Acf
1032
 
1033
  break;
1034
 
1035
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1036
  }
 
1037
  }
1038
 
1039
 
1040
 
1041
- /*----------------------------------------------------------------------
1042
  *
1043
  * export
1044
  *
1045
- *---------------------------------------------------------------------*/
 
 
 
1046
 
1047
  function export()
1048
  {
@@ -1108,6 +1201,7 @@ class Acf
1108
  <label><?php echo $field->label; ?></label>
1109
  <name><?php echo $field->name; ?></name>
1110
  <type><?php echo $field->type; ?></type>
 
1111
  <options>
1112
  <?php if($field->options):
1113
  foreach($field->options as $k => $option):
@@ -1118,6 +1212,7 @@ class Acf
1118
  <label><?php echo $sub_field->label; ?></label>
1119
  <name><?php echo $sub_field->name; ?></name>
1120
  <type><?php echo $sub_field->type; ?></type>
 
1121
  <options>
1122
  <?php if($sub_field->options):
1123
  foreach($sub_field->options as $k2 => $option2): ?>
@@ -1135,7 +1230,6 @@ class Acf
1135
  endif; ?>
1136
  </options>
1137
  <instructions><?php echo $field->instructions ?></instructions>
1138
- <save_as_cf><?php echo $field->save_as_cf; ?></save_as_cf>
1139
  </field>
1140
  <?php endforeach;
1141
  endif; ?>
@@ -1167,11 +1261,14 @@ class Acf
1167
 
1168
 
1169
 
1170
- /*----------------------------------------------------------------------
1171
  *
1172
  * import
1173
  *
1174
- *---------------------------------------------------------------------*/
 
 
 
1175
 
1176
  function import()
1177
  {
@@ -1183,11 +1280,14 @@ class Acf
1183
  }
1184
 
1185
 
1186
- /*----------------------------------------------------------------------
1187
  *
1188
- * Admin Error
1189
  *
1190
- *---------------------------------------------------------------------*/
 
 
 
1191
 
1192
  function admin_error($message = "")
1193
  {
@@ -1197,17 +1297,20 @@ class Acf
1197
  function my_admin_notice()
1198
  {
1199
  global $acf_mesage;
1200
- echo '<div class="error fade" id="message"><p>'.$acf_mesage.'</p></div>';
1201
  }
1202
  add_action('admin_notices', 'my_admin_notice');
1203
  }
1204
 
1205
 
1206
- /*----------------------------------------------------------------------
1207
  *
1208
- * Admin Message
1209
  *
1210
- *---------------------------------------------------------------------*/
 
 
 
1211
 
1212
  function admin_message($message = "")
1213
  {
@@ -1217,9 +1320,284 @@ class Acf
1217
  function my_admin_notice()
1218
  {
1219
  global $acf_mesage;
1220
- echo '<div class="updated fade" id="message"><p>'.$acf_mesage.'</p></div>';
1221
  }
1222
  add_action('admin_notices', 'my_admin_notice');
1223
  }
1224
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  /*
3
  Plugin Name: Advanced Custom Fields
4
  Plugin URI: http://plugins.elliotcondon.com/advanced-custom-fields/
5
+ Description: Customise your edit pages with an assortment of field types: Wysiwyg, Repeater, text, textarea, image, file, select, checkbox post type, page link and more! Hide unwanted metaboxes and assign to any edit page!
6
+ Version: 2.1.1
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
14
  //error_reporting(E_ALL|E_STRICT);
15
 
16
 
17
+ include('core/admin/options_page.php');
18
 
19
  $acf = new Acf();
20
 
23
 
24
  class Acf
25
  {
26
+
27
  var $dir;
28
  var $path;
29
  var $siteurl;
33
  var $activated_fields;
34
  var $options_page;
35
 
36
+
37
+ /*--------------------------------------------------------------------------------------
38
+ *
39
+ * Constructor
40
+ *
41
+ * @author Elliot Condon
42
+ * @since 1.0.0
43
+ *
44
+ *-------------------------------------------------------------------------------------*/
45
+
46
  function Acf()
47
  {
48
 
49
  // set class variables
 
50
  $this->path = dirname(__FILE__).'';
51
  $this->dir = plugins_url('',__FILE__);
52
  $this->siteurl = get_bloginfo('url');
53
  $this->wpadminurl = admin_url();
54
+ $this->version = '2.1.1';
55
  $this->activated_fields = $this->get_activated_fields();
56
  $this->options_page = new Acf_options_page($this);
57
 
59
  // set text domain
60
  load_plugin_textdomain('acf', false, $this->path.'/lang' );
61
 
62
+
63
  // populate post types
64
+ $this->fields = $this->get_field_types();
65
 
66
 
67
  // add actions
68
+ add_action('init', array($this, 'init'));
69
  add_action('init', array($this, 'import'));
70
  add_action('init', array($this, 'export'));
71
+ add_action('init', array($this, 'third_party'));
72
+ add_action('admin_head', array($this,'admin_head'));
73
+ add_action('admin_menu', array($this,'admin_menu'));
74
+ add_action('save_post', array($this, 'save_post'));
75
  add_action('admin_footer', array($this, '_admin_footer'));
76
+ add_action('wp_ajax_input_meta_box_html', array($this, 'input_meta_box_html'));
77
 
78
 
79
+ // admin styles + scripts
80
+ add_action("admin_print_scripts", array($this, 'admin_print_scripts'));
81
+ add_action("admin_print_styles", array($this, 'admin_print_styles'));
82
+
 
 
 
 
 
 
 
 
83
 
84
  return true;
85
  }
86
+
87
+
88
+ /*--------------------------------------------------------------------------------------
89
+ *
90
+ * Upgrade
91
+ *
92
+ * @author Elliot Condon
93
+ * @since 2.0.6
94
+ *
95
+ *-------------------------------------------------------------------------------------*/
96
+
97
+ function upgrade()
98
  {
99
+ include('core/upgrade.php');
100
  }
101
 
102
+
103
+
104
+ /*--------------------------------------------------------------------------------------
105
+ *
106
+ * Init
107
+ *
108
+ * @author Elliot Condon
109
+ * @since 1.0.0
110
+ *
111
+ *-------------------------------------------------------------------------------------*/
112
+
113
+ function init()
114
  {
115
+ include('core/actions/init.php');
 
 
116
  }
117
 
118
+
119
+ /*--------------------------------------------------------------------------------------
120
+ *
121
+ * admin_print_scripts
122
+ *
123
+ * @author Elliot Condon
124
+ * @since 1.0.0
125
+ *
126
+ *-------------------------------------------------------------------------------------*/
127
+
128
+ function admin_print_scripts()
129
  {
130
+ if(in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php', 'edit.php')))
 
 
 
 
 
131
  {
132
+ // jquery
133
  wp_enqueue_script('jquery');
134
  wp_enqueue_script('jquery-ui-core');
135
 
140
  wp_enqueue_script('word-count');
141
  wp_enqueue_script('post');
142
  wp_enqueue_script('editor');
143
+
144
 
145
  // repeater
146
  wp_enqueue_script('jquery-ui-sortable');
147
  }
148
  }
149
 
150
+
151
+ /*--------------------------------------------------------------------------------------
152
+ *
153
+ * admin_print_styles
154
+ *
155
+ * @author Elliot Condon
156
+ * @since 1.0.0
157
+ *
158
+ *-------------------------------------------------------------------------------------*/
159
+
160
+ function admin_print_styles()
161
  {
162
+ if(in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php', 'edit.php')))
 
 
 
 
163
  {
164
  wp_enqueue_style('thickbox');
165
  }
166
  }
167
 
168
+
169
+ /*--------------------------------------------------------------------------------------
170
+ *
171
+ * save_post
172
+ *
173
+ * @author Elliot Condon
174
+ * @since 1.0.0
175
+ *
176
+ *-------------------------------------------------------------------------------------*/
177
+
178
+ function save_post($post_id)
179
+ {
180
+
181
  // do not save if this is an auto save routine
182
  if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
183
 
184
+
185
  // verify this with nonce because save_post can be triggered at other times
186
  if (!wp_verify_nonce($_POST['ei_noncename'], 'ei-n')) return $post_id;
187
 
188
+
189
  // only save once! WordPress save's twice for some strange reason.
190
  global $flag;
191
  if ($flag != 0) return $post_id;
199
  }
200
 
201
 
202
+ // include save files
203
+ include('core/actions/fields_save.php');
204
+ include('core/actions/location_save.php');
205
+ include('core/actions/options_save.php');
206
+ include('core/actions/input_save.php');
 
 
 
 
 
 
 
207
  }
208
+
209
 
210
 
211
+ /*--------------------------------------------------------------------------------------
212
+ *
213
+ * admin_menu
214
+ *
215
+ * @author Elliot Condon
216
+ * @since 1.0.0
217
+ *
218
+ *-------------------------------------------------------------------------------------*/
 
 
 
 
219
 
220
+ function admin_menu() {
 
 
 
 
 
 
 
221
 
222
  // add sub menu
223
+ add_options_page(__("Adv Custom Fields",'acf'), __("Adv Custom Fields",'acf'), 'manage_options', 'edit.php?post_type=acf');
 
 
 
 
 
 
 
 
 
224
 
225
  }
226
 
 
 
 
 
 
 
 
 
 
 
 
227
 
228
+ /*--------------------------------------------------------------------------------------
229
+ *
230
+ * admin_head
231
+ *
232
+ * @author Elliot Condon
233
+ * @since 1.0.0
234
+ *
235
+ *-------------------------------------------------------------------------------------*/
236
 
237
+ function admin_head()
 
 
 
 
 
 
 
238
  {
239
+ include('core/actions/admin_head.php');
240
  }
241
+
242
 
243
+ /*--------------------------------------------------------------------------------------
244
+ *
245
+ * get_field_types
246
+ *
247
+ * @author Elliot Condon
248
+ * @since 1.0.0
249
+ *
250
+ *-------------------------------------------------------------------------------------*/
251
 
252
+ function get_field_types()
 
 
 
 
 
 
 
253
  {
254
  $array = array();
255
 
260
  include_once('core/fields/file.php');
261
  include_once('core/fields/select.php');
262
  include_once('core/fields/checkbox.php');
263
+ include_once('core/fields/radio.php');
264
  include_once('core/fields/true_false.php');
265
  include_once('core/fields/page_link.php');
266
  include_once('core/fields/post_object.php');
267
  include_once('core/fields/date_picker/date_picker.php');
268
  include_once('core/fields/repeater.php');
269
 
270
+ $array['text'] = new acf_Text($this);
271
+ $array['textarea'] = new acf_Textarea($this);
272
  $array['wysiwyg'] = new acf_Wysiwyg();
273
  $array['image'] = new acf_Image($this);
274
  $array['file'] = new acf_File($this);
275
  $array['select'] = new acf_Select($this);
276
  $array['checkbox'] = new acf_Checkbox();
277
+ $array['radio'] = new acf_Radio();
278
  $array['true_false'] = new acf_True_false();
279
  $array['page_link'] = new acf_Page_link($this);
280
  $array['post_object'] = new acf_Post_object($this);
289
  }
290
 
291
 
292
+ /*--------------------------------------------------------------------------------------
293
+ *
294
+ * create_field
295
+ *
296
+ * @author Elliot Condon
297
+ * @since 1.0.0
298
+ *
299
+ *-------------------------------------------------------------------------------------*/
300
+
301
  function create_field($field)
302
  {
303
  if(!is_object($this->fields[$field->type]))
309
  $this->fields[$field->type]->html($field);
310
  }
311
 
312
+
313
+ /*--------------------------------------------------------------------------------------
314
+ *
315
+ * save_field
316
+ *
317
+ * @author Elliot Condon
318
+ * @since 1.0.0
319
+ *
320
+ *-------------------------------------------------------------------------------------*/
321
+
322
  function save_field($options)
323
  {
324
  if(!$this->fields[$options['field_type']])
331
  }
332
 
333
 
334
+ /*--------------------------------------------------------------------------------------
335
+ *
336
+ * _fields_meta_box
337
+ *
338
+ * @author Elliot Condon
339
+ * @since 1.0.0
340
+ *
341
+ *-------------------------------------------------------------------------------------*/
342
+
343
  function _fields_meta_box()
344
  {
345
+ include('core/admin/fields_meta_box.php');
346
  }
347
 
348
 
349
+ /*--------------------------------------------------------------------------------------
350
+ *
351
+ * _location_meta_box
352
+ *
353
+ * @author Elliot Condon
354
+ * @since 1.0.0
355
+ *
356
+ *-------------------------------------------------------------------------------------*/
357
+
358
  function _location_meta_box()
359
  {
360
+ include('core/admin/location_meta_box.php');
361
  }
362
 
363
 
364
+ /*--------------------------------------------------------------------------------------
365
+ *
366
+ * _options_meta_box
367
+ *
368
+ * @author Elliot Condon
369
+ * @since 1.0.0
370
+ *
371
+ *-------------------------------------------------------------------------------------*/
372
+
373
+ function _options_meta_box()
374
  {
375
+ include('core/admin/options_meta_box.php');
376
  }
377
 
378
 
379
+ /*--------------------------------------------------------------------------------------
380
+ *
381
+ * _input_meta_box
382
+ *
383
+ * @author Elliot Condon
384
+ * @since 1.0.0
385
+ *
386
+ *-------------------------------------------------------------------------------------*/
387
+
388
+ function input_meta_box($post, $args)
389
  {
390
+ include('core/admin/input_meta_box.php');
391
  }
392
 
393
+
394
+
395
 
396
+
397
+ /*--------------------------------------------------------------------------------------
398
+ *
399
+ * get_fields
400
+ *
401
+ * @author Elliot Condon
402
+ * @since 1.0.0
403
+ *
404
+ *-------------------------------------------------------------------------------------*/
405
+
406
+ function get_fields($acf_id)
407
+ {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
 
409
  // set table name
410
  global $wpdb;
417
 
418
 
419
  // if fields are empty, this must be a new or broken acf. add blank field
420
+ if(!$fields)
421
  {
422
  return array();
423
  }
428
  {
429
 
430
  // unserialize options
431
+ if(@unserialize($field->options))
432
+ {
433
+ $field->options = unserialize($field->options);
434
+ }
435
+ else
436
  {
437
  $field->options = array();
438
  }
455
  foreach($sub_fields as $sub_field)
456
  {
457
  // unserialize options
458
+ if(@unserialize($sub_field->options))
459
+ {
460
+ $sub_field->options = @unserialize($sub_field->options);
461
+ }
462
+ else
463
+ {
464
+ $sub_field->options = array();
465
+ }
466
+
467
  }
468
 
469
 
470
  // assign array to the field options array
471
  $field->options['sub_fields'] = $sub_fields;
472
  }
473
+
 
 
474
  }
475
  // end if sub field
476
  }
477
  // end foreach $fields
478
 
479
+
480
  // return fields
481
+ return $fields;
482
 
483
+ }
484
 
485
+
486
+ /*--------------------------------------------------------------------------------------
487
+ *
488
+ * get_field_options
489
+ *
490
+ * @author Elliot Condon
491
+ * @since 1.0.0
492
+ *
493
+ *-------------------------------------------------------------------------------------*/
494
+
495
+ function get_field_options($type, $options)
496
+ {
497
  $field_options = $this->fields[$type]->options();
498
 
499
  ?>
510
  <?php endforeach; ?>
511
  </table>
512
  <?php
513
+ }
514
+
515
+
516
+ /*--------------------------------------------------------------------------------------
517
+ *
518
+ * get_acf_location
519
+ *
520
+ * @author Elliot Condon
521
+ * @since 1.0.0
522
+ *
523
+ *-------------------------------------------------------------------------------------*/
524
+
525
+ function get_acf_location($acf_id)
526
+ {
527
 
528
  // set table name
529
  global $wpdb;
539
  // return location
540
  return $location;
541
 
542
+ }
543
 
544
 
545
+ /*--------------------------------------------------------------------------------------
546
+ *
547
+ * get_acf_options
548
+ *
549
+ * @author Elliot Condon
550
+ * @since 1.0.0
551
+ *
552
+ *-------------------------------------------------------------------------------------*/
553
+
554
+ function get_acf_options($acf_id)
555
+ {
556
+
557
  $options = new stdClass();
558
 
559
 
586
 
587
  return $options;
588
 
589
+ }
590
 
591
 
592
+ /*--------------------------------------------------------------------------------------
593
+ *
594
+ * _admin_footer
595
+ *
596
+ * @author Elliot Condon
597
+ * @since 1.0.0
598
+ *
599
+ *-------------------------------------------------------------------------------------*/
600
+
601
  function _admin_footer()
602
  {
603
+
604
+ if($GLOBALS['pagenow'] == 'edit.php' && $GLOBALS['post_type'] == 'acf')
 
605
  {
606
  echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.screen_extra.css" />';
607
  echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.screen_extra.js" ></script>';
610
 
611
  }
612
 
613
+
614
+ /*--------------------------------------------------------------------------------------
615
+ *
616
+ * field_method_exists
617
+ *
618
+ * @author Elliot Condon
619
+ * @since 2.0.6
620
+ *
621
+ *-------------------------------------------------------------------------------------*/
622
+
623
+ function field_method_exists($field_type, $method)
624
+ {
625
+ if(method_exists($this->fields[$field_type], $method))
626
+ {
627
+ return true;
628
+ }
629
+ else
630
+ {
631
+ return false;
632
+ }
633
+ }
634
+
635
+ /*--------------------------------------------------------------------------------------
636
+ *
637
+ * load_value_for_input
638
+ *
639
+ * @author Elliot Condon
640
+ * @since 1.0.6
641
+ *
642
+ *-------------------------------------------------------------------------------------*/
643
+
644
  function load_value_for_input($post_id, $field)
645
  {
646
+
647
+ $value;
648
+
649
+
650
+ if($this->field_method_exists($field->type, 'load_value_for_input'))
651
  {
652
  $value = $this->fields[$field->type]->load_value_for_input($post_id, $field);
653
  }
654
  else
655
  {
656
+ // tables
657
  global $wpdb;
658
+ $acf_values = $wpdb->prefix.'acf_values';
659
+ $wp_postmeta = $wpdb->prefix.'postmeta';
660
 
661
 
662
  // get row
663
+ $value = $wpdb->get_row("SELECT m.meta_value as value, m.meta_id, v.id as value_id FROM $wp_postmeta m LEFT JOIN $acf_values v ON m.meta_id = v.value WHERE v.field_id = '$field->id' AND m.post_id = '$post_id'");
664
+ //$value = $wpdb->get_var("SELECT value FROM $table_name WHERE field_id = '$field->id' AND post_id = '$post_id'");
665
+
666
+ if($value)
667
+ {
668
+ // format if needed
669
+ if($this->field_method_exists($field->type, 'format_value_for_input'))
670
+ {
671
+ $value->value = $this->fields[$field->type]->format_value_for_input($value->value);
672
+ }
673
+ }
674
+ else
675
+ {
676
+ $value = new stdClass();
677
+ $value->value = false;
678
+
679
+
680
+ // override with default value
681
+ if($post_id != 0)
682
+ {
683
+ $post_meta = get_post_custom($post_id);
684
+ if(empty($post_meta) && isset($field->default_value) && !empty($field->default_value))
685
+ {
686
+ $value->value = $field->default_value;
687
+ }
688
 
689
+ }
690
+
691
+
692
+ }
693
  }
694
 
695
+
696
  // return value
697
  return $value;
698
  }
699
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
700
 
701
 
702
+ /*--------------------------------------------------------------------------------------
703
+ *
704
+ * load_value_for_api
705
+ *
706
+ * @author Elliot Condon
707
+ * @since 1.0.6
708
+ *
709
+ *-------------------------------------------------------------------------------------*/
710
+
711
  function load_value_for_api($post_id, $field)
712
  {
713
+
714
+ if($this->field_method_exists($field->type, 'load_value_for_api'))
715
  {
716
  $value = $this->fields[$field->type]->load_value_for_api($post_id, $field);
717
  }
718
  else
719
  {
720
+ // tables
721
  global $wpdb;
722
+ $acf_values = $wpdb->prefix.'acf_values';
723
+ $wp_postmeta = $wpdb->prefix.'postmeta';
724
 
725
 
726
  // get var
727
+ $value = $wpdb->get_var("SELECT m.meta_value FROM $wp_postmeta m LEFT JOIN $acf_values v ON m.meta_id = v.value WHERE v.field_id = '$field->id' AND m.post_id = '$post_id'");
 
 
728
 
729
+
730
  // format if needed
731
+ if($this->field_method_exists($field->type, 'format_value_for_api'))
732
  {
733
+ $value = $this->fields[$field->type]->format_value_for_api($value, $field->options);
734
  }
735
  }
736
 
746
  }
747
 
748
 
749
+ /*--------------------------------------------------------------------------------------
750
+ *
751
+ * get_activated_fields
752
+ *
753
+ * @author Elliot Condon
754
+ * @since 2.0.0
755
+ *
756
+ *-------------------------------------------------------------------------------------*/
757
+
758
  function get_activated_fields()
759
  {
760
  $activated = array();
767
  {
768
  $activated['repeater'] = get_option("acf_repeater_ac");
769
  }
 
 
 
 
770
  }
771
 
772
 
784
  }
785
 
786
 
787
+ /*--------------------------------------------------------------------------------------
788
+ *
789
+ * match_location_rule
790
+ *
791
+ * @author Elliot Condon
792
+ * @since 2.0.0
793
+ *
794
+ *-------------------------------------------------------------------------------------*/
795
+
796
+ function match_location_rule($post, $rule, $overrides = array())
797
  {
798
+
799
  switch ($rule->param) {
800
 
801
  // POST TYPE
802
  case "post_type":
803
+
804
+ $post_type = isset($overrides['post_type']) ? $overrides['post_type'] : get_post_type($post);
805
 
806
  if($rule->operator == "==")
807
  {
808
+ if($post_type == $rule->value)
809
  {
810
  return true;
811
  }
814
  }
815
  elseif($rule->operator == "!=")
816
  {
817
+ if($post_type != $rule->value)
818
  {
819
  return true;
820
  }
827
  // PAGE
828
  case "page":
829
 
830
+ $page = isset($overrides['page']) ? $overrides['page'] : $post->ID;
831
+
832
  if($rule->operator == "==")
833
  {
834
+ if($page == $rule->value)
835
  {
836
  return true;
837
  }
840
  }
841
  elseif($rule->operator == "!=")
842
  {
843
+ if($page != $rule->value)
844
  {
845
  return true;
846
  }
853
  // PAGE
854
  case "page_type":
855
 
856
+ $page_type = isset($overrides['page_type']) ? $overrides['page_type'] : $post->post_parent;
857
+
858
  if($rule->operator == "==")
859
  {
860
+ if($rule->value == "parent" && $page_type == "0")
861
  {
862
  return true;
863
  }
864
 
865
+ if($rule->value == "child" && $page_type != "0")
866
  {
867
  return true;
868
  }
871
  }
872
  elseif($rule->operator == "!=")
873
  {
874
+ if($rule->value == "parent" && $page_type != "0")
875
  {
876
  return true;
877
  }
878
 
879
+ if($rule->value == "child" && $page_type == "0")
880
  {
881
  return true;
882
  }
889
  // PAGE PARENT
890
  case "page_parent":
891
 
892
+ $page_parent = isset($overrides['page_parent']) ? $overrides['page_parent'] : $post->post_parent;
893
+
894
  if($rule->operator == "==")
895
  {
896
+ if($page_parent == $rule->value)
897
  {
898
  return true;
899
  }
903
  }
904
  elseif($rule->operator == "!=")
905
  {
906
+ if($page_parent != $rule->value)
907
  {
908
  return true;
909
  }
916
  // PAGE
917
  case "page_template":
918
 
919
+ $page_template = isset($overrides['page_template']) ? $overrides['page_template'] : get_post_meta($post->ID,'_wp_page_template',true);
920
+
921
  if($rule->operator == "==")
922
  {
923
+ if($page_template == $rule->value)
924
  {
925
  return true;
926
  }
927
 
928
+ if($rule->value == "default" && !$page_template)
929
  {
930
  return true;
931
  }
932
 
 
933
  return false;
934
  }
935
  elseif($rule->operator == "!=")
936
  {
937
+ if($page_template != $rule->value)
938
  {
939
  return true;
940
  }
947
  // POST
948
  case "post":
949
 
950
+ $post_id = isset($overrides['post']) ? $overrides['post'] : $post->ID;
951
+
952
  if($rule->operator == "==")
953
  {
954
+ if($post_id == $rule->value)
955
  {
956
  return true;
957
  }
960
  }
961
  elseif($rule->operator == "!=")
962
  {
963
+ if($post_id != $rule->value)
964
  {
965
  return true;
966
  }
973
  // POST CATEGORY
974
  case "post_category":
975
 
976
+ $cats = array();
977
+
978
+ if(isset($overrides['post_category']))
979
+ {
980
+ $cats = $overrides['post_category'];
981
+ }
982
+ else
983
+ {
984
+ $all_cats = get_the_category($post->ID);
985
+ foreach($all_cats as $cat)
986
+ {
987
+ $cats[] = $cat->term_id;
988
+ }
989
+ }
990
+
991
  if($rule->operator == "==")
992
  {
993
  if($cats)
994
  {
995
+ if(in_array($rule->value, $cats))
996
  {
997
+ return true;
 
 
 
998
  }
999
  }
1000
 
1004
  {
1005
  if($cats)
1006
  {
1007
+ if(!in_array($rule->value, $cats))
1008
  {
1009
+ return true;
 
 
 
1010
  }
1011
  }
1012
 
1016
  break;
1017
 
1018
  // PAGE PARENT
1019
+ /*
1020
  case "post_format":
1021
 
1022
+ $post_format = isset($overrides['post_format']) ? $overrides['post_format'] : get_post_format();
1023
+
1024
  if($rule->operator == "==")
1025
  {
1026
+ if($post_format == $rule->value)
1027
  {
1028
  return true;
1029
  }
1031
  return false;
1032
 
1033
  }
1034
+ elseif($post_format == "!=")
1035
  {
1036
  if($post->post_parent != $rule->value)
1037
  {
1042
  }
1043
 
1044
  break;
1045
+ */
1046
 
1047
  // USER TYPE
1048
  case "user_type":
1071
  // Options Page
1072
  case "options_page":
1073
 
1074
+
1075
  if($rule->operator == "==")
1076
  {
1077
  if(get_admin_page_title() == $rule->value)
1093
 
1094
  break;
1095
 
1096
+
1097
+ // Post Format
1098
+ case "post_format":
1099
+
1100
+
1101
+ $post_format = isset($overrides['post_format']) ? has_post_format($overrides['post_format'],$post->ID) : has_post_format($rule->value,$post->ID);
1102
+
1103
+ if($rule->operator == "==")
1104
+ {
1105
+ if($post_format)
1106
+ {
1107
+ return true;
1108
+ }
1109
+
1110
+ return false;
1111
+ }
1112
+ elseif($rule->operator == "!=")
1113
+ {
1114
+ if(!$post_format)
1115
+ {
1116
+ return true;
1117
+ }
1118
+
1119
+ return false;
1120
+ }
1121
+
1122
+ break;
1123
+
1124
+
1125
  }
1126
+
1127
  }
1128
 
1129
 
1130
 
1131
+ /*--------------------------------------------------------------------------------------
1132
  *
1133
  * export
1134
  *
1135
+ * @author Elliot Condon
1136
+ * @since 2.0.5
1137
+ *
1138
+ *-------------------------------------------------------------------------------------*/
1139
 
1140
  function export()
1141
  {
1201
  <label><?php echo $field->label; ?></label>
1202
  <name><?php echo $field->name; ?></name>
1203
  <type><?php echo $field->type; ?></type>
1204
+ <default_value><?php echo $field->default_value; ?></default_value>
1205
  <options>
1206
  <?php if($field->options):
1207
  foreach($field->options as $k => $option):
1212
  <label><?php echo $sub_field->label; ?></label>
1213
  <name><?php echo $sub_field->name; ?></name>
1214
  <type><?php echo $sub_field->type; ?></type>
1215
+ <default_value><?php echo $sub_field->default_value; ?></default_value>
1216
  <options>
1217
  <?php if($sub_field->options):
1218
  foreach($sub_field->options as $k2 => $option2): ?>
1230
  endif; ?>
1231
  </options>
1232
  <instructions><?php echo $field->instructions ?></instructions>
 
1233
  </field>
1234
  <?php endforeach;
1235
  endif; ?>
1261
 
1262
 
1263
 
1264
+ /*--------------------------------------------------------------------------------------
1265
  *
1266
  * import
1267
  *
1268
+ * @author Elliot Condon
1269
+ * @since 2.0.5
1270
+ *
1271
+ *-------------------------------------------------------------------------------------*/
1272
 
1273
  function import()
1274
  {
1280
  }
1281
 
1282
 
1283
+ /*--------------------------------------------------------------------------------------
1284
  *
1285
+ * admin_error
1286
  *
1287
+ * @author Elliot Condon
1288
+ * @since 2.0.5
1289
+ *
1290
+ *-------------------------------------------------------------------------------------*/
1291
 
1292
  function admin_error($message = "")
1293
  {
1297
  function my_admin_notice()
1298
  {
1299
  global $acf_mesage;
1300
+ echo '<div class="error" id="message"><p>'.$acf_mesage.'</p></div>';
1301
  }
1302
  add_action('admin_notices', 'my_admin_notice');
1303
  }
1304
 
1305
 
1306
+ /*--------------------------------------------------------------------------------------
1307
  *
1308
+ * admin_message
1309
  *
1310
+ * @author Elliot Condon
1311
+ * @since 2.0.5
1312
+ *
1313
+ *-------------------------------------------------------------------------------------*/
1314
 
1315
  function admin_message($message = "")
1316
  {
1320
  function my_admin_notice()
1321
  {
1322
  global $acf_mesage;
1323
+ echo '<div class="updated" id="message"><p>'.$acf_mesage.'</p></div>';
1324
  }
1325
  add_action('admin_notices', 'my_admin_notice');
1326
  }
1327
+
1328
+
1329
+ /*--------------------------------------------------------------------------------------
1330
+ *
1331
+ * input_meta_box_html
1332
+ *
1333
+ * @author Elliot Condon
1334
+ * @since 2.0.6
1335
+ *
1336
+ *-------------------------------------------------------------------------------------*/
1337
+ function input_meta_box_html($ajax = true)
1338
+ {
1339
+
1340
+ $overrides = array();
1341
+ if(isset($_POST['page_template']) && $_POST['page_template'] != 'false') $overrides['page_template'] = $_POST['page_template'];
1342
+ if(isset($_POST['page_parent']) && $_POST['page_parent'] != 'false') $overrides['page_parent'] = $_POST['page_parent'];
1343
+ if(isset($_POST['page_type']) && $_POST['page_type'] != 'false') $overrides['page_type'] = $_POST['page_type'];
1344
+ if(isset($_POST['page']) && $_POST['page'] != 'false') $overrides['page'] = $_POST['page'];
1345
+ if(isset($_POST['post']) && $_POST['post'] != 'false') $overrides['post'] = $_POST['post'];
1346
+ if(isset($_POST['post_category']) && $_POST['post_category'] != 'false') $overrides['post_category'] = $_POST['post_category'];
1347
+ if(isset($_POST['post_format']) && $_POST['post_format'] != 'false') $overrides['post_format'] = $_POST['post_format'];
1348
+
1349
+ $this->input_meta_box_html_no_ajax($_POST['post_id'], $overrides);
1350
+
1351
+ die;
1352
+
1353
+ }
1354
+
1355
+
1356
+ /*--------------------------------------------------------------------------------------
1357
+ *
1358
+ * input_meta_box_html_no_ajax
1359
+ *
1360
+ * @author Elliot Condon
1361
+ * @since 2.0.6
1362
+ *
1363
+ *-------------------------------------------------------------------------------------*/
1364
+
1365
+ function input_meta_box_html_no_ajax($post_id, $overrides = array())
1366
+ {
1367
+ // create post object to match against
1368
+ $post = get_post($post_id);
1369
+
1370
+
1371
+ //var_dump($overrides);
1372
+ $acfs = get_pages(array(
1373
+ 'numberposts' => -1,
1374
+ 'post_type' => 'acf',
1375
+ 'sort_column' => 'menu_order',
1376
+ ));
1377
+
1378
+
1379
+ // blank array to hold acfs
1380
+ $add_acf = array();
1381
+
1382
+ if($acfs)
1383
+ {
1384
+ foreach($acfs as $acf)
1385
+ {
1386
+ $add_box = false;
1387
+ $location = $this->get_acf_location($acf->ID);
1388
 
1389
+
1390
+ if($location->allorany == 'all')
1391
+ {
1392
+ // ALL
1393
+
1394
+ $add_box = true;
1395
+
1396
+ if($location->rules)
1397
+ {
1398
+ foreach($location->rules as $rule)
1399
+ {
1400
+ // if any rules dont return true, dont add this acf
1401
+ if(!$this->match_location_rule($post, $rule, $overrides))
1402
+ {
1403
+ $add_box = false;
1404
+ }
1405
+ }
1406
+ }
1407
+
1408
+ }
1409
+ elseif($location->allorany == 'any')
1410
+ {
1411
+ // ANY
1412
+
1413
+ $add_box = false;
1414
+
1415
+ if($location->rules)
1416
+ {
1417
+ foreach($location->rules as $rule)
1418
+ {
1419
+ // if any rules return true, add this acf
1420
+ if($this->match_location_rule($post, $rule, $overrides))
1421
+ {
1422
+ $add_box = true;
1423
+ }
1424
+ }
1425
+ }
1426
+ }
1427
+
1428
+ if($add_box == true)
1429
+ {
1430
+ $add_acf[] = $acf;
1431
+ }
1432
+
1433
+ }// end foreach
1434
+
1435
+ if(!empty($add_acf))
1436
+ {
1437
+
1438
+ $adv_options = $this->get_acf_options($add_acf[0]->ID);
1439
+
1440
+
1441
+ $fields = array();
1442
+ foreach($add_acf as $acf)
1443
+ {
1444
+ // get this acf's fields and add them to the global $fields
1445
+ $this_fields = $this->get_fields($acf->ID);
1446
+ foreach($this_fields as $this_field)
1447
+ {
1448
+ $fields[] = $this_field;
1449
+ }
1450
+
1451
+ }
1452
+
1453
+ ?>
1454
+
1455
+
1456
+ <style type="text/css" id="acf_dynamic_style">
1457
+ <?php if(!in_array('the_content',$adv_options->show_on_page)): ?>
1458
+ #postdivrich {display: none;}
1459
+ <?php endif; ?>
1460
+
1461
+ <?php if(!in_array('custom_fields',$adv_options->show_on_page)): ?>
1462
+ #postcustom,
1463
+ #screen-meta label[for=postcustom-hide] {display: none;}
1464
+ <?php endif; ?>
1465
+
1466
+ <?php if(!in_array('discussion',$adv_options->show_on_page)): ?>
1467
+ #commentstatusdiv,
1468
+ #screen-meta label[for=commentstatusdiv-hide] {display: none;}
1469
+ <?php endif; ?>
1470
+
1471
+ <?php if(!in_array('comments',$adv_options->show_on_page)): ?>
1472
+ #commentsdiv,
1473
+ #screen-meta label[for=commentsdiv-hide] {display: none;}
1474
+ <?php endif; ?>
1475
+
1476
+ <?php if(!in_array('slug',$adv_options->show_on_page)): ?>
1477
+ #slugdiv,
1478
+ #screen-meta label[for=slugdiv-hide] {display: none;}
1479
+ <?php endif; ?>
1480
+
1481
+ <?php if(!in_array('author',$adv_options->show_on_page)): ?>
1482
+ #authordiv,
1483
+ #screen-meta label[for=authordiv-hide] {display: none;}
1484
+ <?php endif; ?>
1485
+
1486
+ #screen-meta label[for=acf_input-hide] {display: none;}
1487
+ </style>
1488
+
1489
+
1490
+
1491
+
1492
+ <?php
1493
+
1494
+ foreach($add_acf as $acf)
1495
+ {
1496
+
1497
+ // load acf data
1498
+ $options = $this->get_acf_options($acf->ID);
1499
+ $fields = $this->get_fields($acf->ID);
1500
+ $html = '';
1501
+
1502
+
1503
+ if($options->field_group_layout == "in_box")
1504
+ {
1505
+ echo '<div class="acf_ajax_fields postbox" data-acf_id="'.$acf->ID.'"><h3><span>'.$acf->post_title.'</span></h3><div class="inside">';
1506
+ }
1507
+ else
1508
+ {
1509
+ echo '<div class="acf_ajax_fields" data-acf_id="'.$acf->ID.'">';
1510
+ }
1511
+
1512
+
1513
+ foreach($fields as $field)
1514
+ {
1515
+
1516
+ // if they didn't select a type, skip this field
1517
+ if($field->type == 'null')
1518
+ {
1519
+ continue;
1520
+ }
1521
+
1522
+
1523
+ // set value, id and name for field
1524
+ $field->value = $this->load_value_for_input($post->ID, $field);
1525
+ $field->input_name = isset($field->input_name) ? $field->input_name : '';
1526
+
1527
+ $temp_field = new stdClass();
1528
+
1529
+
1530
+ echo '<div class="field">';
1531
+
1532
+ echo '<input type="hidden" name="acf['.$field->id.'][field_id]" value="'.$field->id.'" />';
1533
+ echo '<input type="hidden" name="acf['.$field->id.'][field_type]" value="'.$field->type.'" />';
1534
+ echo '<input type="hidden" name="acf['.$field->id.'][field_name]" value="'.$field->name.'" />';
1535
+
1536
+ if($field->type != 'repeater')
1537
+ {
1538
+ echo '<input type="hidden" name="acf['.$field->id.'][value_id]" value="'.$field->value->value_id.'" />';
1539
+ echo '<input type="hidden" name="acf['.$field->id.'][meta_id]" value="'.$field->value->meta_id.'" />';
1540
+
1541
+ $temp_field->value = $field->value->value;
1542
+ }
1543
+ else
1544
+ {
1545
+ $temp_field->value = $field->value;
1546
+ }
1547
+
1548
+
1549
+ echo '<label for="'.$field->input_name.'">'.$field->label.'</label>';
1550
+
1551
+
1552
+ if($field->instructions)
1553
+ {
1554
+ echo '<p class="instructions">'.$field->instructions.'</p>';
1555
+ }
1556
+
1557
+ $temp_field->type = $field->type;
1558
+ $temp_field->input_name = 'acf['.$field->id.'][value]';
1559
+ $temp_field->input_class = $field->type;
1560
+ $temp_field->options = $field->options;
1561
+
1562
+ $this->create_field($temp_field);
1563
+
1564
+
1565
+ echo '</div>';
1566
+
1567
+
1568
+ }
1569
+
1570
+
1571
+ if($options->field_group_layout == "in_box")
1572
+ {
1573
+ echo '</div></div>';
1574
+ }
1575
+ else
1576
+ {
1577
+ echo '</div>';
1578
+ }
1579
+ }
1580
+
1581
+ }
1582
+
1583
+ }// end if
1584
+
1585
+
1586
+ }
1587
+
1588
+
1589
+ /*--------------------------------------------------------------------------------------
1590
+ *
1591
+ * third_party
1592
+ *
1593
+ * @author Elliot Condon
1594
+ * @since 2.0.6
1595
+ *
1596
+ *-------------------------------------------------------------------------------------*/
1597
+ function third_party()
1598
+ {
1599
+ include('core/third_party.php');
1600
+ }
1601
+
1602
+
1603
+ }
core/acf_post_type.php DELETED
@@ -1,36 +0,0 @@
1
- <?php
2
-
3
- $labels = array(
4
- 'name' => __( 'Advanced&nbsp;Custom&nbsp;Fields', 'acf' ),
5
- 'singular_name' => __( 'Advanced Custom Fields', 'acf' ),
6
- 'add_new' => __( 'Add New' , 'acf' ),
7
- 'add_new_item' => __( 'Add New Advanced Custom Field Group' , 'acf' ),
8
- 'edit_item' => __( 'Edit Advanced Custom Field Group' , 'acf' ),
9
- 'new_item' => __( 'New Advanced Custom Field Group' , 'acf' ),
10
- 'view_item' => __('View Advanced Custom Field Group'),
11
- 'search_items' => __('Search Advanced Custom Field Groups'),
12
- 'not_found' => __('No Advanced Custom Field Groups found'),
13
- 'not_found_in_trash' => __('No Advanced Custom Field Groups found in Trash'),
14
- );
15
-
16
-
17
- $supports = array(
18
- 'title',
19
- //'revisions',
20
- //'custom-fields',
21
- 'page-attributes'
22
- );
23
-
24
- register_post_type('acf', array(
25
- 'labels' => $labels,
26
- 'public' => false,
27
- 'show_ui' => true,
28
- '_builtin' => false,
29
- 'capability_type' => 'page',
30
- 'hierarchical' => true,
31
- 'rewrite' => array("slug" => "acf"),
32
- 'query_var' => "acf",
33
- 'supports' => $supports,
34
- ));
35
-
36
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/actions/admin_head.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ global $post;
4
+
5
+
6
+ /*----------------------------------------------------------------------
7
+ *
8
+ * Add Post Boxes
9
+ *
10
+ *---------------------------------------------------------------------*/
11
+
12
+ if(in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php')))
13
+ {
14
+
15
+ if($GLOBALS['post_type'] == 'acf')
16
+ {
17
+ echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.fields.js" ></script>';
18
+ echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.location.js" ></script>';
19
+
20
+ echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.global.css" />';
21
+ echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.fields.css" />';
22
+ echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.location.css" />';
23
+ echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.options.css" />';
24
+
25
+ add_meta_box('acf_fields', 'Fields', array($this, '_fields_meta_box'), 'acf', 'normal', 'high');
26
+ add_meta_box('acf_location', 'Location </span><span class="description">- Add Fields to Edit Screens', array($this, '_location_meta_box'), 'acf', 'normal', 'high');
27
+ add_meta_box('acf_options', 'Advanced Options</span><span class="description">- Customise the edit page', array($this, '_options_meta_box'), 'acf', 'normal', 'high');
28
+
29
+ }
30
+ else
31
+ {
32
+ // find post type and add wysiwyg support
33
+ $post_type = get_post_type($post);
34
+ if(!post_type_supports($post_type, 'editor'))
35
+ {
36
+ wp_tiny_mce();
37
+ }
38
+
39
+ // add css + javascript
40
+ echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.global.css" />';
41
+ echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.input.css" />';
42
+ echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.input.js" ></script>';
43
+
44
+ // add datepicker
45
+ echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/core/fields/date_picker/style.date_picker.css" />';
46
+ echo '<script type="text/javascript" src="'.$this->dir.'/core/fields/date_picker/jquery.ui.datepicker.js" ></script>';
47
+
48
+ // add meta box
49
+ add_meta_box('acf_input', 'ACF Fields', array($this, 'input_meta_box'), $post_type, 'normal', 'high');
50
+
51
+ }
52
+ }
53
+
54
+
55
+ ?>
56
+ <style type="text/css">
57
+ #menu-posts-acf {
58
+ display: none;
59
+ }
60
+ </style>
core/{fields_save.php → actions/fields_save.php} RENAMED
@@ -4,12 +4,6 @@
4
  ---------------------------------------------------------------------------------------------*/
5
  if(isset($_POST['fields_meta_box']) && $_POST['fields_meta_box'] == 'true')
6
  {
7
-
8
- //echo '<pre>';
9
- //print_r($_POST['acf']);
10
- //echo '</pre>';
11
- //die;
12
-
13
 
14
  // set table name
15
  global $wpdb;
@@ -37,7 +31,7 @@ if(isset($_POST['fields_meta_box']) && $_POST['fields_meta_box'] == 'true')
37
  if(!isset($field['type'])) { $field['label'] = "text"; }
38
  if(!isset($field['options'])) { $field['options'] = array(); }
39
  if(!isset($field['instructions'])) { $field['instructions'] = ""; }
40
- if(!isset($field['save_as_cf'])) { $field['save_as_cf'] = ""; }
41
 
42
 
43
  // clean field
@@ -45,7 +39,7 @@ if(isset($_POST['fields_meta_box']) && $_POST['fields_meta_box'] == 'true')
45
 
46
 
47
  // format options if needed
48
- if(method_exists($this->fields[$field['type']], 'format_options'))
49
  {
50
  $field['options'] = $this->fields[$field['type']]->format_options($field['options']);
51
  }
@@ -60,14 +54,14 @@ if(isset($_POST['fields_meta_box']) && $_POST['fields_meta_box'] == 'true')
60
  'type' => $field['type'],
61
  'options' => serialize($field['options']),
62
  'instructions' => $field['instructions'],
63
- 'save_as_cf' => $field['save_as_cf'],
64
  );
65
 
66
 
67
  // if there is an id, this field already exists, so save it in the same ID spot
68
  if($field['id'])
69
  {
70
- $data['id'] = $field['id'];
71
  }
72
 
73
 
@@ -76,7 +70,7 @@ if(isset($_POST['fields_meta_box']) && $_POST['fields_meta_box'] == 'true')
76
 
77
 
78
  // save field if needed (used to save sub fields)
79
- if(method_exists($this->fields[$field['type']], 'save_field'))
80
  {
81
  if($field['id'])
82
  {
4
  ---------------------------------------------------------------------------------------------*/
5
  if(isset($_POST['fields_meta_box']) && $_POST['fields_meta_box'] == 'true')
6
  {
 
 
 
 
 
 
7
 
8
  // set table name
9
  global $wpdb;
31
  if(!isset($field['type'])) { $field['label'] = "text"; }
32
  if(!isset($field['options'])) { $field['options'] = array(); }
33
  if(!isset($field['instructions'])) { $field['instructions'] = ""; }
34
+ if(!isset($field['default_value'])) { $field['default_value'] = ""; }
35
 
36
 
37
  // clean field
39
 
40
 
41
  // format options if needed
42
+ if($this->field_method_exists($field['type'], 'format_options'))
43
  {
44
  $field['options'] = $this->fields[$field['type']]->format_options($field['options']);
45
  }
54
  'type' => $field['type'],
55
  'options' => serialize($field['options']),
56
  'instructions' => $field['instructions'],
57
+ 'default_value' => $field['default_value'],
58
  );
59
 
60
 
61
  // if there is an id, this field already exists, so save it in the same ID spot
62
  if($field['id'])
63
  {
64
+ $data['id'] = (int) $field['id'];
65
  }
66
 
67
 
70
 
71
 
72
  // save field if needed (used to save sub fields)
73
+ if($this->field_method_exists($field['type'], 'save_field'))
74
  {
75
  if($field['id'])
76
  {
core/actions/init.php ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*----------------------------------------------------------------------
4
+ *
5
+ * upgrade
6
+ *
7
+ *---------------------------------------------------------------------*/
8
+
9
+ $version = get_option('acf_version','1.0.5');
10
+
11
+ if(isset($_POST['acf_upgrade']))
12
+ {
13
+ $this->upgrade();
14
+ }
15
+ else
16
+ {
17
+ // if current version is less than the latest upgrade version, show the upgrade message
18
+ if(version_compare($version,'2.1.0') < 0)
19
+ {
20
+ global $acf_temp_mesage;
21
+ $acf_temp_mesage = '<form method="post"><p>Advanced Custom Fields v' . $this->version . ' requires a database upgrade. Please <a href="http://codex.wordpress.org/Backing_Up_Your_Database">backup your database</a> then click <input type="submit" class="button" name="acf_upgrade" value="Upgrade Database" /></p></form>';
22
+
23
+ function my_temp_notice()
24
+ {
25
+ global $acf_temp_mesage;
26
+ echo '<div class="updated" id="message">'.$acf_temp_mesage.'</div>';
27
+ }
28
+ add_action('admin_notices', 'my_temp_notice');
29
+ }
30
+ elseif($version != $this->version)
31
+ {
32
+ update_option('acf_version',$this->version);
33
+ }
34
+ }
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+ /*----------------------------------------------------------------------
43
+ *
44
+ * deactivate_field
45
+ *
46
+ *---------------------------------------------------------------------*/
47
+
48
+ if(isset($_POST['acf_field_deactivate']))
49
+ {
50
+ // delete field
51
+ $field = $_POST['acf_field_deactivate'];
52
+ $option = 'acf_'.$field.'_ac';
53
+ delete_option($option);
54
+
55
+
56
+ // update activated fields
57
+ $this->activated_fields = $this->get_activated_fields();
58
+ $this->fields = $this->get_field_types();
59
+
60
+
61
+ //set message
62
+ $acf_message_field = "";
63
+ if($field == "repeater")
64
+ {
65
+ $acf_message_field = "Repeater Field";
66
+ }
67
+ elseif($field == "options_page")
68
+ {
69
+ $acf_message_field = "Options Page";
70
+ }
71
+
72
+
73
+ // show message on page
74
+ $this->admin_message($acf_message_field.' deactivated');
75
+
76
+ }
77
+
78
+
79
+
80
+ /*----------------------------------------------------------------------
81
+ *
82
+ * activate_field
83
+ *
84
+ *---------------------------------------------------------------------*/
85
+
86
+ if(isset($_POST['acf_field_activate']) && isset($_POST['acf_ac']))
87
+ {
88
+
89
+ $field = $_POST['acf_field_activate'];
90
+ $ac = $_POST['acf_ac'];
91
+
92
+
93
+ // update option
94
+ $option = 'acf_'.$field.'_ac';
95
+ update_option($option, $ac);
96
+
97
+
98
+ // update activated fields
99
+ $old_count = count($this->activated_fields);
100
+ $this->activated_fields = $this->get_activated_fields();
101
+ $this->fields = $this->get_field_types();
102
+ $new_count = count($this->activated_fields);
103
+
104
+
105
+ // set message
106
+ global $acf_message_field;
107
+ $acf_message_field = "";
108
+ if($field == "repeater")
109
+ {
110
+ $acf_message_field = "Repeater Field activated";
111
+ }
112
+ elseif($field == "options_page")
113
+ {
114
+ $acf_message_field = "Options Page activated";
115
+ }
116
+
117
+
118
+ // show message
119
+ if($new_count == $old_count)
120
+ {
121
+ $this->admin_message('Activation code unrecognized');
122
+ }
123
+ else
124
+ {
125
+ $this->admin_message($acf_message_field);
126
+ }
127
+
128
+ }
129
+
130
+
131
+
132
+ /*--------------------------------------------------------------------------------------
133
+ *
134
+ * Create Post Type
135
+ *
136
+ * @author Elliot Condon
137
+ * @since 1.0.6
138
+ *
139
+ *-------------------------------------------------------------------------------------*/
140
+
141
+ $labels = array(
142
+ 'name' => __( 'Advanced&nbsp;Custom&nbsp;Fields', 'acf' ),
143
+ 'singular_name' => __( 'Advanced Custom Fields', 'acf' ),
144
+ 'add_new' => __( 'Add New' , 'acf' ),
145
+ 'add_new_item' => __( 'Add New Advanced Custom Field Group' , 'acf' ),
146
+ 'edit_item' => __( 'Edit Advanced Custom Field Group' , 'acf' ),
147
+ 'new_item' => __( 'New Advanced Custom Field Group' , 'acf' ),
148
+ 'view_item' => __('View Advanced Custom Field Group'),
149
+ 'search_items' => __('Search Advanced Custom Field Groups'),
150
+ 'not_found' => __('No Advanced Custom Field Groups found'),
151
+ 'not_found_in_trash' => __('No Advanced Custom Field Groups found in Trash'),
152
+ );
153
+
154
+
155
+ $supports = array(
156
+ 'title',
157
+ //'revisions',
158
+ //'custom-fields',
159
+ 'page-attributes'
160
+ );
161
+
162
+ register_post_type('acf', array(
163
+ 'labels' => $labels,
164
+ 'public' => false,
165
+ 'show_ui' => true,
166
+ '_builtin' => false,
167
+ 'capability_type' => 'page',
168
+ 'hierarchical' => true,
169
+ 'rewrite' => array("slug" => "acf"),
170
+ 'query_var' => "acf",
171
+ 'supports' => $supports,
172
+ ));
173
+
174
+
175
+ /*--------------------------------------------------------------------------------------
176
+ *
177
+ * Custom Columns
178
+ *
179
+ * @author Elliot Condon
180
+ * @since 2.1.0
181
+ *
182
+ *-------------------------------------------------------------------------------------*/
183
+
184
+ function acf_columns_filter($columns)
185
+ {
186
+ $columns = array(
187
+ 'cb' => '<input type="checkbox" />',
188
+ 'title' => 'Title',
189
+ );
190
+ return $columns;
191
+ }
192
+
193
+ add_filter("manage_edit-acf_columns", "acf_columns_filter");
194
+
195
+ ?>
core/actions/input_save.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*---------------------------------------------------------------------------------------------
3
+ Fields Meta Box
4
+ ---------------------------------------------------------------------------------------------*/
5
+ if(isset($_POST['input_meta_box']) && $_POST['input_meta_box'] == 'true')
6
+ {
7
+
8
+ // If acf was not posted, don't go any further
9
+ if(!isset($_POST['acf']))
10
+ {
11
+ return true;
12
+ }
13
+
14
+
15
+ // tables
16
+ global $wpdb;
17
+ $acf_values = $wpdb->prefix.'acf_values';
18
+ $wp_postmeta = $wpdb->prefix.'postmeta';
19
+
20
+
21
+
22
+ // add the new values to the database
23
+ foreach($_POST['acf'] as $field)
24
+ {
25
+
26
+ // remove all old values from the database
27
+ $field_id = $field['field_id'];
28
+ $values = $wpdb->get_results("SELECT v.id, m.meta_id FROM $acf_values v LEFT JOIN $wp_postmeta m ON v.value = m.meta_id WHERE v.field_id = '$field_id' AND m.post_id = '$post_id'");
29
+
30
+
31
+ if($values)
32
+ {
33
+ foreach($values as $value)
34
+ {
35
+ $wpdb->query("DELETE FROM $acf_values WHERE id = '$value->id'");
36
+ $wpdb->query("DELETE FROM $wp_postmeta WHERE meta_id = '$value->meta_id'");
37
+ }
38
+ }
39
+
40
+
41
+
42
+ if(method_exists($this->fields[$field['field_type']], 'save_input'))
43
+ {
44
+ $this->fields[$field['field_type']]->save_input($post_id, $field);
45
+ }
46
+ else
47
+ {
48
+ //$field = apply_filters('wp_insert_post_data', $field);
49
+ $field = stripslashes_deep( $field );
50
+
51
+
52
+ // if select is a multiple (multiple select value), you need to save it as an array!
53
+ if(is_array($field['value']))
54
+ {
55
+ $field['value'] = serialize($field['value']);
56
+ }
57
+
58
+
59
+ // create data: wp_postmeta
60
+ $data1 = array(
61
+ 'meta_id' => isset($field['meta_id']) ? $field['meta_id'] : null,
62
+ 'post_id' => $post_id,
63
+ 'meta_key' => $field['field_name'],
64
+ 'meta_value' => $field['value']
65
+ );
66
+
67
+ $wpdb->insert($wp_postmeta, $data1);
68
+
69
+ $new_id = $wpdb->insert_id;
70
+
71
+ // create data: acf_values
72
+ if($new_id && $new_id != 0)
73
+ {
74
+
75
+ $data2 = array(
76
+ 'id' => isset($field['value_id']) ? $field['value_id'] : null,
77
+ 'field_id' => $field['field_id'],
78
+ 'value' => $new_id,
79
+ 'post_id' => $post_id,
80
+ );
81
+
82
+ $wpdb->insert($acf_values, $data2);
83
+
84
+ }
85
+
86
+ }
87
+
88
+
89
+ }
90
+ //foreach($_POST['acf'] as $field)
91
+
92
+
93
+ }
94
+
95
+ ?>
core/{location_save.php → actions/location_save.php} RENAMED
File without changes
core/{options_save.php → actions/options_save.php} RENAMED
File without changes
core/{fields_meta_box.php → admin/fields_meta_box.php} RENAMED
@@ -11,6 +11,8 @@
11
  $field->name = 'new_field';
12
  $field->type = 'text';
13
  $field->options = array();
 
 
14
  $fields[999] = $field;
15
 
16
 
@@ -26,20 +28,27 @@
26
  <input type="hidden" name="fields_meta_box" value="true" />
27
  <input type="hidden" name="total_fields" value="<?php echo count($fields); ?>" />
28
  <input type="hidden" name="fields_limit" value="99" />
29
-
30
  <input type="hidden" name="ei_noncename" id="ei_noncename" value="<?php echo wp_create_nonce('ei-n'); ?>" />
31
 
32
-
33
- <table class="acf widefat">
34
- <thead>
35
- <tr>
36
- <th class="field_order"><?php _e('Field Order','acf'); ?></th>
37
- <th class="field_label"><?php _e('Field Label','acf'); ?></th>
38
- <th class="field_name"><?php _e('Field Name','acf'); ?></th>
39
- <th class="field_type"><?php _e('Field Type','acf'); ?></th>
40
- </tr>
41
- </thead>
42
- </table>
 
 
 
 
 
 
 
 
43
  <div class="fields">
44
 
45
  <div class="no_fields_message" <?php if(sizeof($fields) > 1){ echo 'style="display:none;"'; } ?>>
@@ -47,12 +56,21 @@
47
  </div>
48
 
49
  <?php foreach($fields as $key => $field): ?>
50
- <div class="<?php if($key == 999){echo "field_clone";}else{echo "field";} ?>">
51
- <input type="hidden" name="acf[fields][<?php echo $key; ?>][id]'" value="<?php echo $field->id; ?>" />
52
-
 
 
 
 
 
 
 
 
 
53
  <table class="acf widefat">
54
  <tr>
55
- <td class="field_order"><?php echo ($key+1); ?></td>
56
  <td class="field_label">
57
 
58
  <strong>
@@ -76,8 +94,8 @@
76
  </td>
77
  </tr>
78
  </table>
79
-
80
- <div class="field_form_mask">
81
  <div class="field_form">
82
 
83
  <table class="acf_input widefat">
@@ -152,7 +170,8 @@
152
  ?>
153
  </td>
154
  </tr>
155
- <tr class="field_save_as_cf">
 
156
  <td class="label">
157
  <label><?php _e("Is field searchable?",'acf'); ?></label>
158
  </td>
@@ -166,17 +185,19 @@
166
  $this->create_field($temp_field);
167
  ?>
168
  </td>
169
- </tr>
 
 
170
  <?php foreach($fields_names as $field_name => $field_title): ?>
171
  <?php if(method_exists($this->fields[$field_name], 'options_html')): ?>
172
 
173
- <?php $this->fields[$field_name]->options_html($key, $field->options); ?>
174
 
175
  <?php endif; ?>
176
  <?php endforeach; ?>
177
  <tr class="field_save">
178
- <td class="label"><label>Save Field</label>
179
- <p class="description">This will save your data and reload the page</p>
180
  </td>
181
  <td><input type="submit" value="Save Field" class="button-primary" name="save" />
182
  or <a class="acf_edit_field" title="Hide this edit screen" href="javascript:;">continue editing ACF</a>
@@ -187,10 +208,10 @@
187
  </table>
188
 
189
  </div>
190
- </div>
191
-
192
  </div>
193
- <?php endforeach; ?>
 
 
194
 
195
 
196
  </div>
11
  $field->name = 'new_field';
12
  $field->type = 'text';
13
  $field->options = array();
14
+ $field->instructions = '';
15
+ $field->default_value = '';
16
  $fields[999] = $field;
17
 
18
 
28
  <input type="hidden" name="fields_meta_box" value="true" />
29
  <input type="hidden" name="total_fields" value="<?php echo count($fields); ?>" />
30
  <input type="hidden" name="fields_limit" value="99" />
 
31
  <input type="hidden" name="ei_noncename" id="ei_noncename" value="<?php echo wp_create_nonce('ei-n'); ?>" />
32
 
33
+ <?php
34
+ /*--------------------------------------------------------------------------------------
35
+ *
36
+ * Fields Header
37
+ *
38
+ *-------------------------------------------------------------------------------------*/
39
+ ?>
40
+ <div class="fields_header">
41
+ <table class="acf widefat">
42
+ <thead>
43
+ <tr>
44
+ <th class="field_order"><?php _e('Field Order','acf'); ?></th>
45
+ <th class="field_label"><?php _e('Field Label','acf'); ?></th>
46
+ <th class="field_name"><?php _e('Field Name','acf'); ?></th>
47
+ <th class="field_type"><?php _e('Field Type','acf'); ?></th>
48
+ </tr>
49
+ </thead>
50
+ </table>
51
+ </div>
52
  <div class="fields">
53
 
54
  <div class="no_fields_message" <?php if(sizeof($fields) > 1){ echo 'style="display:none;"'; } ?>>
56
  </div>
57
 
58
  <?php foreach($fields as $key => $field): ?>
59
+
60
+
61
+ <div class="<?php if($key == 999){echo "field_clone";}else{echo "field";} ?>">
62
+ <input type="hidden" name="acf[fields][<?php echo $key; ?>][id]'" value="<?php echo $field->id; ?>" />
63
+ <?php
64
+ /*--------------------------------------------------------------------------------------
65
+ *
66
+ * Field Meta
67
+ *
68
+ *-------------------------------------------------------------------------------------*/
69
+ ?>
70
+ <div class="field_meta">
71
  <table class="acf widefat">
72
  <tr>
73
+ <td class="field_order"><span class="circle"><?php echo ($key+1); ?></span></td>
74
  <td class="field_label">
75
 
76
  <strong>
94
  </td>
95
  </tr>
96
  </table>
97
+ </div>
98
+ <div class="field_form_mask">
99
  <div class="field_form">
100
 
101
  <table class="acf_input widefat">
170
  ?>
171
  </td>
172
  </tr>
173
+ <?php
174
+ /*<tr class="field_save_as_cf">
175
  <td class="label">
176
  <label><?php _e("Is field searchable?",'acf'); ?></label>
177
  </td>
185
  $this->create_field($temp_field);
186
  ?>
187
  </td>
188
+ </tr>*/
189
+ ?>
190
+
191
  <?php foreach($fields_names as $field_name => $field_title): ?>
192
  <?php if(method_exists($this->fields[$field_name], 'options_html')): ?>
193
 
194
+ <?php $this->fields[$field_name]->options_html($key, $field); ?>
195
 
196
  <?php endif; ?>
197
  <?php endforeach; ?>
198
  <tr class="field_save">
199
+ <td class="label">
200
+ <label>Save Field</label>
201
  </td>
202
  <td><input type="submit" value="Save Field" class="button-primary" name="save" />
203
  or <a class="acf_edit_field" title="Hide this edit screen" href="javascript:;">continue editing ACF</a>
208
  </table>
209
 
210
  </div>
 
 
211
  </div>
212
+
213
+ </div>
214
+ <?php endforeach; ?>
215
 
216
 
217
  </div>
core/admin/input_meta_box.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <input type="hidden" name="ei_noncename" id="ei_noncename" value="<?php echo wp_create_nonce('ei-n'); ?>" />
2
+ <input type="hidden" name="input_meta_box" value="true" />
3
+
4
+ <div id="acf_loading"></div>
5
+ <div id="acf_fields_ajax">
6
+ <?php
7
+ global $acf;
8
+ global $post;
9
+
10
+ // false parameter stops the function from calling die (ajax on/off)
11
+ $acf->input_meta_box_html_no_ajax($post->ID);
12
+ ?>
13
+ </div>
14
+
15
+ <script type="text/javascript">
16
+
17
+ (function($){
18
+
19
+ /*--------------------------------------------------------------------------------------
20
+ *
21
+ * overrides
22
+ *
23
+ *-------------------------------------------------------------------------------------*/
24
+ var page_template = false;
25
+ var page_parent = false;
26
+ var page_type = false;
27
+ var page = $('input#post_ID').val();
28
+ var post = $('input#post_ID').val();
29
+ var post_category = false;
30
+ var post_format = false;
31
+
32
+
33
+
34
+ /*--------------------------------------------------------------------------------------
35
+ *
36
+ * Change
37
+ *
38
+ *-------------------------------------------------------------------------------------*/
39
+
40
+ $('#page_template').change(function(){
41
+
42
+ page_template = $(this).val();
43
+ update_fields();
44
+
45
+ });
46
+
47
+ $('#parent_id').change(function(){
48
+
49
+ page_parent = $(this).val();
50
+
51
+ if($(this).val() != "")
52
+ {
53
+ page_type = 'child';
54
+ }
55
+ else
56
+ {
57
+ page_type = 'parent';
58
+ }
59
+
60
+ update_fields();
61
+
62
+ });
63
+
64
+ $('#categorychecklist input[type="checkbox"]').change(function(){
65
+
66
+ post_category = [];
67
+
68
+ $('#categorychecklist :checked').each(function(){
69
+ post_category.push($(this).val())
70
+ });
71
+
72
+ console.log(post_category);
73
+
74
+ update_fields();
75
+
76
+ });
77
+
78
+
79
+ $('#post-formats-select input[type="radio"]').change(function(){
80
+
81
+ post_format = $(this).val();
82
+ update_fields();
83
+
84
+ });
85
+
86
+ function update_fields()
87
+ {
88
+
89
+
90
+ // fade out fields and show loading
91
+ /*$('#acf_input').addClass('loading');
92
+ $('#acf_fields_ajax').animate({
93
+ opacity : 0.5
94
+ }, 500);*/
95
+
96
+
97
+ // get post id
98
+ var post_id = $('input#post_ID').val();
99
+
100
+ // create data
101
+ var data = {
102
+ action : 'input_meta_box_html',
103
+ post_id : post_id,
104
+ page_template : page_template,
105
+ page_parent : page_parent,
106
+ page_type : page_type,
107
+ page : page,
108
+ post : post,
109
+ post_category : post_category,
110
+ post_format : post_format,
111
+
112
+ };
113
+ //console.log(data);
114
+
115
+ // post off and find new fields
116
+ $.post(ajaxurl, data, function(data) {
117
+
118
+ //setTimeout(function(){
119
+
120
+ var new_divs = [];
121
+ var old_divs = [];
122
+
123
+ /*$('#acf_input').removeClass('loading');
124
+ $('#acf_fields_ajax').animate({
125
+ opacity : 1
126
+ }, 500);*/
127
+
128
+ $('#acf_fields_ajax .acf_ajax_fields').each(function(){
129
+
130
+ old_divs[$(this).attr('data-acf_id')] = $(this);
131
+
132
+ $(this).remove();
133
+ });
134
+
135
+ var divs = $(data).filter(function(){ return $(this).is('.acf_ajax_fields') });
136
+ divs.each(function(){
137
+
138
+ if(old_divs[$(this).attr('data-acf_id')])
139
+ {
140
+ $('#acf_fields_ajax').append(old_divs[$(this).attr('data-acf_id')]);
141
+ }
142
+ else
143
+ {
144
+ $('#acf_fields_ajax').append($(this));
145
+ }
146
+
147
+ });
148
+
149
+
150
+ // new dynamic style
151
+ $('#acf_fields_ajax #acf_dynamic_style').remove();
152
+ var style = $(data).filter(function(){ return $(this).is('style')});
153
+ style.each(function(){
154
+ $('#acf_fields_ajax').append($(this));
155
+ });
156
+
157
+
158
+ $('body').setup_acf();
159
+
160
+
161
+ //}, 500);
162
+
163
+
164
+ });
165
+ }
166
+
167
+ update_fields();
168
+
169
+
170
+ })(jQuery);
171
+
172
+ </script>
core/{location_meta_box.php → admin/location_meta_box.php} RENAMED
@@ -51,6 +51,7 @@
51
  'page_template' => 'Page Template',
52
  'post' => 'Post',
53
  'post_category' => 'Post Category',
 
54
  'user_type' => 'User Type',
55
  ));
56
 
@@ -144,9 +145,17 @@
144
  <div rel="page_parent">
145
  <?php
146
  $choices = array();
147
- foreach(get_pages('parent=0&sort_column=menu_order&sort_order=desc') as $page)
148
  {
149
- $choices[$page->ID] = $page->post_title;
 
 
 
 
 
 
 
 
150
  }
151
  $temp_field->options = array(
152
  'choices' => $choices,
@@ -211,6 +220,25 @@
211
 
212
  ?>
213
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  <div rel="user_type">
215
 
216
  <?php
51
  'page_template' => 'Page Template',
52
  'post' => 'Post',
53
  'post_category' => 'Post Category',
54
+ 'post_format' => 'Post Format',
55
  'user_type' => 'User Type',
56
  ));
57
 
145
  <div rel="page_parent">
146
  <?php
147
  $choices = array();
148
+ foreach(get_pages('sort_column=menu_order&sort_order=desc') as $page)
149
  {
150
+ if($page->post_parent != 0)
151
+ {
152
+ $choices[$page->ID] = '- '.$page->post_title;
153
+ }
154
+ else
155
+ {
156
+ $choices[$page->ID] = $page->post_title;
157
+ }
158
+
159
  }
160
  $temp_field->options = array(
161
  'choices' => $choices,
220
 
221
  ?>
222
  </div>
223
+ <div rel="post_format">
224
+ <?php
225
+ $choices = array(
226
+ '0' => 'Standard',
227
+ 'aside' => 'Aside',
228
+ 'link' => 'Link',
229
+ 'gallery' => 'Gallery',
230
+ 'status' => 'Status',
231
+ 'quote' => 'Quote',
232
+ 'image' => 'Image',
233
+ );
234
+
235
+ $temp_field->options = array(
236
+ 'choices' => $choices,
237
+ );
238
+
239
+ $this->create_field($temp_field);
240
+ ?>
241
+ </div>
242
  <div rel="user_type">
243
 
244
  <?php
core/{options_meta_box.php → admin/options_meta_box.php} RENAMED
File without changes
core/{options_page.php → admin/options_page.php} RENAMED
@@ -34,7 +34,7 @@ class Acf_options_page
34
  $this->parent = $parent;
35
  $this->dir = $parent->dir;
36
 
37
-
38
  // Customize the Labels here
39
  $this->menu_name = __('Options','acf');
40
  $this->menu_heading = __('Options','acf');
@@ -56,7 +56,12 @@ class Acf_options_page
56
  *-------------------------------------------------------------------------------------*/
57
  function admin_menu()
58
  {
59
-
 
 
 
 
 
60
  // add page
61
  $options_page = add_menu_page('acf_options', $this->menu_name, 'edit_posts', 'acf-options',array($this, 'options_page'));
62
 
@@ -151,7 +156,6 @@ class Acf_options_page
151
  {
152
  if(!array_key_exists('options_page', $this->parent->activated_fields)){exit;}
153
 
154
-
155
  // load acf's
156
  $acfs = get_pages(array(
157
  'numberposts' => -1,
@@ -181,7 +185,7 @@ class Acf_options_page
181
  foreach($location->rules as $rule)
182
  {
183
  // if any rules dont return true, dont add this acf
184
- if(!$this->parent->match_location_rule($post, $rule))
185
  {
186
  $add_box = false;
187
  }
@@ -200,7 +204,7 @@ class Acf_options_page
200
  foreach($location->rules as $rule)
201
  {
202
  // if any rules return true, add this acf
203
- if($this->parent->match_location_rule($post, $rule))
204
  {
205
  $add_box = true;
206
  }
@@ -217,7 +221,7 @@ class Acf_options_page
217
 
218
  ?>
219
 
220
- <div class="wrap">
221
 
222
  <div class="icon32" id="icon-options-general"><br></div>
223
  <h2><?php echo $this->menu_heading; ?></h2>
@@ -250,10 +254,9 @@ class Acf_options_page
250
  <div id="post-body">
251
  <div id="post-body-content">
252
  <div id="acf_input" class="postbox">
253
- <div class="acf_fields_input">
254
  <?php
255
 
256
- $i = 0;
257
  if($add_acf)
258
  {
259
  foreach($add_acf as $acf)
@@ -267,7 +270,11 @@ class Acf_options_page
267
 
268
  if($options->field_group_layout == "in_box")
269
  {
270
- echo '<div class="postbox"><div title="Click to toggle" class="handlediv"><br></div><h3 class="hndle"><span>'.$acf->post_title.'</span></h3><div class="inside">';
 
 
 
 
271
  }
272
 
273
 
@@ -282,19 +289,31 @@ class Acf_options_page
282
 
283
 
284
  // set value, id and name for field
285
- $field->value_id = $this->parent->load_value_id_input($post->ID, $field);
286
- $field->value = $this->parent->load_value_for_input($post->ID, $field);
287
- $field->input_name = 'acf['.$i.'][value]';
288
- $field->input_class = '';
289
 
290
 
291
  echo '<div class="field">';
292
 
293
- echo '<input type="hidden" name="acf['.$i.'][field_id]" value="'.$field->id.'" />';
294
- echo '<input type="hidden" name="acf['.$i.'][field_type]" value="'.$field->type.'" />';
295
- echo '<input type="hidden" name="acf['.$i.'][value_id]" value="'.$field->value_id.'" />';
296
-
297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  echo '<label for="'.$field->input_name.'">'.$field->label.'</label>';
299
 
300
 
@@ -302,13 +321,18 @@ class Acf_options_page
302
  {
303
  echo '<p class="instructions">'.$field->instructions.'</p>';
304
  }
 
 
 
 
 
305
 
306
-
307
- $this->parent->create_field($field);
308
 
309
  echo '</div>';
310
 
311
- $i++;
312
  }
313
 
314
 
@@ -316,6 +340,10 @@ class Acf_options_page
316
  {
317
  echo '</div></div>';
318
  }
 
 
 
 
319
  }
320
  }
321
  else
@@ -337,6 +365,7 @@ class Acf_options_page
337
  }
338
 
339
 
 
340
  ?>
341
  </div>
342
  </div>
@@ -359,18 +388,33 @@ class Acf_options_page
359
  *-------------------------------------------------------------------------------------*/
360
  function update_options()
361
  {
362
- // vars
363
  global $wpdb;
364
- $table_name = $wpdb->prefix.'acf_values';
 
365
  $post_id = 0;
366
 
367
 
368
- // remove all old values from the database
369
- $wpdb->query("DELETE FROM $table_name WHERE post_id = '$post_id'");
370
-
371
-
372
  foreach($_POST['acf'] as $field)
373
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  if(method_exists($this->parent->fields[$field['field_type']], 'save_input'))
375
  {
376
  $this->parent->fields[$field['field_type']]->save_input($post_id, $field);
@@ -387,30 +431,44 @@ class Acf_options_page
387
  $field['value'] = serialize($field['value']);
388
  }
389
 
390
-
391
- // create data object to save
392
- $data = array(
393
- 'post_id' => $post_id,
394
- 'field_id' => $field['field_id'],
395
- 'value' => $field['value']
 
396
  );
397
 
398
- // if there is an id, this value already exists, so save it in the same ID spot
399
- if($field['value_id'])
400
- {
401
- $data['id'] = $field['value_id'];
402
- }
403
 
 
404
 
405
- // insert new data
406
- $new_id = $wpdb->insert($table_name, $data);
 
 
 
 
 
 
 
 
 
 
 
 
 
407
  }
 
408
 
409
-
410
  }
411
-
 
412
  }
413
 
 
 
414
  }
415
 
416
  ?>
34
  $this->parent = $parent;
35
  $this->dir = $parent->dir;
36
 
37
+
38
  // Customize the Labels here
39
  $this->menu_name = __('Options','acf');
40
  $this->menu_heading = __('Options','acf');
56
  *-------------------------------------------------------------------------------------*/
57
  function admin_menu()
58
  {
59
+
60
+ if(!array_key_exists('options_page', $this->parent->activated_fields)){
61
+ return true;
62
+ }
63
+
64
+
65
  // add page
66
  $options_page = add_menu_page('acf_options', $this->menu_name, 'edit_posts', 'acf-options',array($this, 'options_page'));
67
 
156
  {
157
  if(!array_key_exists('options_page', $this->parent->activated_fields)){exit;}
158
 
 
159
  // load acf's
160
  $acfs = get_pages(array(
161
  'numberposts' => -1,
185
  foreach($location->rules as $rule)
186
  {
187
  // if any rules dont return true, dont add this acf
188
+ if(!$this->parent->match_location_rule(false, $rule))
189
  {
190
  $add_box = false;
191
  }
204
  foreach($location->rules as $rule)
205
  {
206
  // if any rules return true, add this acf
207
+ if($this->parent->match_location_rule(false, $rule))
208
  {
209
  $add_box = true;
210
  }
221
 
222
  ?>
223
 
224
+ <div class="wrap no_move">
225
 
226
  <div class="icon32" id="icon-options-general"><br></div>
227
  <h2><?php echo $this->menu_heading; ?></h2>
254
  <div id="post-body">
255
  <div id="post-body-content">
256
  <div id="acf_input" class="postbox">
257
+ <div class="acf_fields_input" id="acf_fields_ajax">
258
  <?php
259
 
 
260
  if($add_acf)
261
  {
262
  foreach($add_acf as $acf)
270
 
271
  if($options->field_group_layout == "in_box")
272
  {
273
+ echo '<div class="acf_ajax_fields postbox" data-acf_id="'.$acf->ID.'"><h3><span>'.$acf->post_title.'</span></h3><div class="inside">';
274
+ }
275
+ else
276
+ {
277
+ echo '<div class="acf_ajax_fields" data-acf_id="'.$acf->ID.'">';
278
  }
279
 
280
 
289
 
290
 
291
  // set value, id and name for field
292
+ $field->value = $this->parent->load_value_for_input(0, $field);
293
+ $field->input_name = isset($field->input_name) ? $field->input_name : '';
294
+
295
+ $temp_field = new stdClass();
296
 
297
 
298
  echo '<div class="field">';
299
 
300
+ echo '<input type="hidden" name="acf['.$field->id.'][field_id]" value="'.$field->id.'" />';
301
+ echo '<input type="hidden" name="acf['.$field->id.'][field_type]" value="'.$field->type.'" />';
302
+ echo '<input type="hidden" name="acf['.$field->id.'][field_name]" value="'.$field->name.'" />';
 
303
 
304
+ if($field->type != 'repeater')
305
+ {
306
+ echo '<input type="hidden" name="acf['.$field->id.'][value_id]" value="'.$field->value->value_id.'" />';
307
+ echo '<input type="hidden" name="acf['.$field->id.'][meta_id]" value="'.$field->value->meta_id.'" />';
308
+
309
+ $temp_field->value = $field->value->value;
310
+ }
311
+ else
312
+ {
313
+ $temp_field->value = $field->value;
314
+ }
315
+
316
+
317
  echo '<label for="'.$field->input_name.'">'.$field->label.'</label>';
318
 
319
 
321
  {
322
  echo '<p class="instructions">'.$field->instructions.'</p>';
323
  }
324
+
325
+ $temp_field->type = $field->type;
326
+ $temp_field->input_name = 'acf['.$field->id.'][value]';
327
+ $temp_field->input_class = $field->type;
328
+ $temp_field->options = $field->options;
329
 
330
+ $this->parent->create_field($temp_field);
331
+
332
 
333
  echo '</div>';
334
 
335
+
336
  }
337
 
338
 
340
  {
341
  echo '</div></div>';
342
  }
343
+ else
344
+ {
345
+ echo '</div>';
346
+ }
347
  }
348
  }
349
  else
365
  }
366
 
367
 
368
+
369
  ?>
370
  </div>
371
  </div>
388
  *-------------------------------------------------------------------------------------*/
389
  function update_options()
390
  {
391
+ // tables
392
  global $wpdb;
393
+ $acf_values = $wpdb->prefix.'acf_values';
394
+ $wp_postmeta = $wpdb->prefix.'postmeta';
395
  $post_id = 0;
396
 
397
 
398
+ // add the new values to the database
 
 
 
399
  foreach($_POST['acf'] as $field)
400
  {
401
+
402
+ // remove all old values from the database
403
+ $field_id = $field['field_id'];
404
+ $values = $wpdb->get_results("SELECT v.id, m.meta_id FROM $acf_values v LEFT JOIN $wp_postmeta m ON v.value = m.meta_id WHERE v.field_id = '$field_id' AND m.post_id = '$post_id'");
405
+
406
+
407
+ if($values)
408
+ {
409
+ foreach($values as $value)
410
+ {
411
+ $wpdb->query("DELETE FROM $acf_values WHERE id = '$value->id'");
412
+ $wpdb->query("DELETE FROM $wp_postmeta WHERE meta_id = '$value->meta_id'");
413
+ }
414
+ }
415
+
416
+ //var_dump($field);
417
+
418
  if(method_exists($this->parent->fields[$field['field_type']], 'save_input'))
419
  {
420
  $this->parent->fields[$field['field_type']]->save_input($post_id, $field);
431
  $field['value'] = serialize($field['value']);
432
  }
433
 
434
+
435
+ // create data: wp_postmeta
436
+ $data1 = array(
437
+ 'meta_id' => isset($field['meta_id']) ? $field['meta_id'] : null,
438
+ 'post_id' => $post_id,
439
+ 'meta_key' => $field['field_name'],
440
+ 'meta_value' => $field['value']
441
  );
442
 
443
+ $wpdb->insert($wp_postmeta, $data1);
 
 
 
 
444
 
445
+ $new_id = $wpdb->insert_id;
446
 
447
+ // create data: acf_values
448
+ if($new_id && $new_id != 0)
449
+ {
450
+
451
+ $data2 = array(
452
+ 'id' => isset($field['value_id']) ? $field['value_id'] : null,
453
+ 'field_id' => $field['field_id'],
454
+ 'value' => $new_id,
455
+ 'post_id' => $post_id,
456
+ );
457
+
458
+ $wpdb->insert($acf_values, $data2);
459
+
460
+ }
461
+
462
  }
463
+
464
 
 
465
  }
466
+ //foreach($_POST['acf'] as $field)
467
+ //die;
468
  }
469
 
470
+
471
+
472
  }
473
 
474
  ?>
core/admin_head.php DELETED
@@ -1,238 +0,0 @@
1
- <?php
2
-
3
- global $post;
4
-
5
-
6
-
7
- /*----------------------------------------------------------------------
8
- *
9
- * deactivate_field
10
- *
11
- *---------------------------------------------------------------------*/
12
-
13
- if(isset($_POST['acf_field_deactivate']))
14
- {
15
- // delete field
16
- $field = $_POST['acf_field_deactivate'];
17
- $option = 'acf_'.$field.'_ac';
18
- delete_option($option);
19
-
20
-
21
- // update activated fields
22
- $this->activated_fields = $this->get_activated_fields();
23
- $this->fields = $this->_get_field_types();
24
-
25
-
26
- //set message
27
- $acf_message_field = "";
28
- if($field == "repeater")
29
- {
30
- $acf_message_field = "Repeater Field";
31
- }
32
- elseif($field == "options_page")
33
- {
34
- $acf_message_field = "Options Page";
35
- }
36
-
37
-
38
- // show message on page
39
- $this->admin_message($acf_message_field.' deactivated');
40
-
41
- }
42
-
43
-
44
-
45
- /*----------------------------------------------------------------------
46
- *
47
- * activate_field
48
- *
49
- *---------------------------------------------------------------------*/
50
-
51
- if(isset($_POST['acf_field_activate']) && isset($_POST['acf_ac']))
52
- {
53
-
54
- $field = $_POST['acf_field_activate'];
55
- $ac = $_POST['acf_ac'];
56
-
57
-
58
- // update option
59
- $option = 'acf_'.$field.'_ac';
60
- update_option($option, $ac);
61
-
62
-
63
- // update activated fields
64
- $old_count = count($this->activated_fields);
65
- $this->activated_fields = $this->get_activated_fields();
66
- $this->fields = $this->_get_field_types();
67
- $new_count = count($this->activated_fields);
68
-
69
-
70
- // set message
71
- global $acf_message_field;
72
- $acf_message_field = "";
73
- if($field == "repeater")
74
- {
75
- $acf_message_field = "Repeater Field";
76
- }
77
- elseif($field == "options_page")
78
- {
79
- $acf_message_field = "Options Page";
80
- }
81
-
82
-
83
- // show message
84
- if($new_count == $old_count)
85
- {
86
- $this->admin_message('Activation code unrecognized');
87
- }
88
- else
89
- {
90
- $this->admin_message($acf_message_field.' activated');
91
- }
92
-
93
-
94
-
95
- }
96
-
97
-
98
-
99
- /*----------------------------------------------------------------------
100
- *
101
- * Options
102
- *
103
- *---------------------------------------------------------------------*/
104
-
105
- if(!array_key_exists('options_page', $this->activated_fields))
106
- {
107
- ?>
108
- <style type="text/css">
109
- #adminmenu li.menu-top#toplevel_page_acf-options {
110
- display: none;
111
- }
112
- </style>
113
- <?php
114
- }
115
-
116
-
117
- // get current page
118
- $currentFile = $_SERVER["SCRIPT_NAME"];
119
- $parts = Explode('/', $currentFile);
120
- $currentFile = $parts[count($parts) - 1];
121
-
122
-
123
- // only add html to post.php and post-new.php pages
124
- if($currentFile == 'post.php' || $currentFile == 'post-new.php')
125
- {
126
-
127
- if(get_post_type($post) == 'acf')
128
- {
129
-
130
- // ACF
131
- echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.fields.js" ></script>';
132
- echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.location.js" ></script>';
133
-
134
- echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.global.css" />';
135
- echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.fields.css" />';
136
- echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.location.css" />';
137
- echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.options.css" />';
138
-
139
- add_meta_box('acf_fields', 'Fields', array($this, '_fields_meta_box'), 'acf', 'normal', 'high');
140
- add_meta_box('acf_location', 'Location </span><span class="description">- Add Fields to Edit Screens', array($this, '_location_meta_box'), 'acf', 'normal', 'high');
141
- add_meta_box('acf_options', 'Advanced Options</span><span class="description">- Customise the edit page', array($this, '_options_meta_box'), 'acf', 'normal', 'high');
142
-
143
- }
144
- else
145
- {
146
- // any other edit page
147
- $acfs = get_pages(array(
148
- 'numberposts' => -1,
149
- 'post_type' => 'acf',
150
- 'sort_column' => 'menu_order',
151
- ));
152
-
153
- // blank array to hold acfs
154
- $add_acf = array();
155
-
156
- if($acfs)
157
- {
158
- foreach($acfs as $acf)
159
- {
160
- $add_box = false;
161
- $location = $this->get_acf_location($acf->ID);
162
-
163
-
164
- if($location->allorany == 'all')
165
- {
166
- // ALL
167
-
168
- $add_box = true;
169
-
170
- if($location->rules)
171
- {
172
- foreach($location->rules as $rule)
173
- {
174
- // if any rules dont return true, dont add this acf
175
- if(!$this->match_location_rule($post, $rule))
176
- {
177
- $add_box = false;
178
- }
179
- }
180
- }
181
-
182
- }
183
- elseif($location->allorany == 'any')
184
- {
185
- // ANY
186
-
187
- $add_box = false;
188
-
189
- if($location->rules)
190
- {
191
- foreach($location->rules as $rule)
192
- {
193
- // if any rules return true, add this acf
194
- if($this->match_location_rule($post, $rule))
195
- {
196
- $add_box = true;
197
- }
198
- }
199
- }
200
- }
201
-
202
- if($add_box == true)
203
- {
204
- $add_acf[] = $acf;
205
- }
206
-
207
- }// end foreach
208
-
209
- if(!empty($add_acf))
210
- {
211
-
212
- // create tyn mce instance for wysiwyg
213
- $post_type = get_post_type($post);
214
- if(!post_type_supports($post_type, 'editor'))
215
- {
216
- wp_tiny_mce();
217
- }
218
-
219
-
220
- // add these acf's to the page
221
- echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.global.css" />';
222
- echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.input.css" />';
223
- echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.input.js" ></script>';
224
-
225
-
226
- // date picker!
227
- echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/core/fields/date_picker/style.date_picker.css" />';
228
- echo '<script type="text/javascript" src="'.$this->dir.'/core/fields/date_picker/jquery.ui.datepicker.js" ></script>';
229
-
230
- add_meta_box('acf_input', 'ACF Fields', array($this, '_input_meta_box'), $post_type, 'normal', 'high', array('acfs' => $add_acf));
231
- }
232
-
233
- }// end if
234
- }
235
- }
236
-
237
-
238
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/api.php CHANGED
@@ -1,62 +1,36 @@
1
- <?php
2
-
3
- /*---------------------------------------------------------------------------------------------
4
- * Global Vars for Groovy Repeater while loop
5
- *
6
- * @author Elliot Condon
7
- * @since 2.0.3
8
- *
9
- ---------------------------------------------------------------------------------------------*/
10
- global $repeater_row_count, $repeater_row;
11
-
12
- $repeater_row_count = 0;
13
- $repeater_row = null;
14
 
 
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- /*---------------------------------------------------------------------------------------------
18
- * acf_object
19
- *
20
- * @author Elliot Condon
21
- * @since 1.0.0
22
- *
23
- ---------------------------------------------------------------------------------------------*/
24
- class acf_object
25
  {
26
- function acf_object($variables)
27
- {
28
- foreach($variables as $key => $value)
29
- {
30
- // field may exist but field name may be blank!!!
31
- if($key)
32
- {
33
- $this->$key = $value;
34
- }
35
- }
36
- }
37
-
38
- }
39
 
40
- /*---------------------------------------------------------------------------------------------
41
- * get_acf
42
- *
43
- * @author Elliot Condon
44
- * @since 1.0.0
45
- *
46
- ---------------------------------------------------------------------------------------------*/
47
- function get_acf($post_id = false)
48
- {
49
- // get global vars
50
- global $acf;
51
  global $post;
 
 
52
 
53
 
54
- // create blank arrays
55
- $fields = array();
56
- $variables = array();
 
57
 
58
 
59
- // if no ID was passed through, just use the $post->ID
60
  if(!$post_id)
61
  {
62
  $post_id = $post->ID;
@@ -66,125 +40,68 @@ function get_acf($post_id = false)
66
  $post_id = 0;
67
  }
68
 
69
-
70
- global $wpdb;
71
- $acf_fields = $wpdb->prefix.'acf_fields';
72
- $acf_values = $wpdb->prefix.'acf_values';
73
-
74
-
75
- // get fields
76
- $fields = array();
77
- $temp_fields = $wpdb->get_results("SELECT DISTINCT f.* FROM $acf_fields f
78
- LEFT JOIN $acf_values v ON v.field_id=f.id
79
- WHERE v.post_id = '$post_id'");
80
-
81
-
82
- if(empty($temp_fields)){return null;}
83
-
84
 
85
- // add fields to field array with key = field->id
86
- foreach($temp_fields as $field)
87
- {
88
- $fields[$field->id] = $field;
89
- }
 
 
90
 
91
 
92
- // now look for child fields
93
- foreach($fields as $i => $field)
94
  {
95
- if($field->parent_id != 0)
96
- {
97
- // this is a sub field.
98
- $parent_field = $wpdb->get_row("SELECT * FROM $acf_fields WHERE id = $field->parent_id");
99
-
100
- if(isset($fields[$parent_field->id]))
101
- {
102
- // parent field has already been created!
103
- $fields[$parent_field->id]->options['sub_fields'][] = $field;
104
- }
105
- else
106
- {
107
- // add sub field to parent field
108
- $parent_field->options = array();
109
- $parent_field->options['sub_fields'][] = $field;
110
-
111
-
112
- // add parent field
113
- $fields[$parent_field->id] = $parent_field;
114
- }
115
-
116
-
117
- unset($fields[$i]);
118
- }
119
  }
120
 
121
- foreach($fields as $field)
122
- {
123
 
124
- // add this field: name => value
125
- $variables[$field->name] = $acf->load_value_for_api($post_id, $field);
126
-
 
127
  }
128
 
129
 
130
- // create a new obejct and give in variables
131
- $object = new stdClass();
 
 
132
 
133
- foreach($variables as $key => $value)
 
134
  {
135
- if (empty($key))
 
 
 
 
 
136
  {
137
- continue;
138
  }
139
 
140
- $object->$key = $value;
141
  }
142
 
 
143
 
144
- // return the object
145
- return $object;
146
-
147
-
148
  }
149
 
150
 
151
- // get fields
152
- function get_fields($post_id = false)
153
- {
154
- return get_acf($post_id);
155
- }
156
-
 
 
157
 
158
- // get field
159
- function get_field($field_name, $post_id = false)
160
- {
161
- global $acf_fields;
162
- global $post;
163
-
164
- if(!$post_id)
165
- {
166
- $post_id = $post->ID;
167
- }
168
-
169
- //echo 'field name: '.$field_name.', post id: '.$post_id;
170
-
171
- if(!isset($acf_fields))
172
- {
173
- $acf_fields = array();
174
- }
175
- if(!isset($acf_fields[$post_id]))
176
- {
177
- $acf_fields[$post_id] = get_acf($post_id);
178
- }
179
-
180
- return $acf_fields[$post_id]->$field_name;
181
- }
182
-
183
-
184
- // the field
185
  function the_field($field_name, $post_id = false)
186
  {
187
- //echo 'field name: '.$field_name.', post id: '.$post_id;
188
  $value = get_field($field_name, $post_id);
189
 
190
  if(is_array($value))
@@ -193,160 +110,166 @@ function the_field($field_name, $post_id = false)
193
  }
194
 
195
  echo $value;
196
-
197
-
198
  }
199
 
200
 
201
- /*---------------------------------------------------------------------------------------------
202
- * Repeater Field functions
203
- *
204
- * @author Elliot Condon
205
- * @since 2.0.3
206
- *
207
- ---------------------------------------------------------------------------------------------*/
 
208
 
209
  function the_repeater_field($field_name, $post_id = false)
210
  {
211
- global $repeater_row_count, $repeater_row;
212
-
213
- $rows = get_field($field_name, $post_id);
214
 
215
- if(isset($rows[$repeater_row_count]))
216
- {
217
- $repeater_row = $rows[$repeater_row_count];
218
- $repeater_row_count ++;
219
- return true;
220
- }
 
 
 
 
221
 
222
 
223
- // reset the vars and return false to end the loop
 
 
 
 
 
 
 
224
 
225
- $repeater_row_count = 0;
226
- $repeater_row = null;
227
 
228
- return false;
 
 
229
 
230
- }
231
-
232
-
233
- // get sub field
234
- function get_sub_field($field_name, $field = false)
235
- {
236
 
 
 
 
 
 
 
 
237
 
238
- if($field == false)
239
- {
240
- global $repeater_row;
241
- $field = $repeater_row;
242
- }
243
 
244
- if(isset($field[$field_name]))
 
245
  {
246
- return $field[$field_name];
 
 
 
247
  }
248
  else
249
  {
 
 
 
250
  return false;
251
  }
252
- }
253
-
254
-
255
- // get sub field
256
- function the_sub_field($field_name, $field = false)
257
- {
258
- $value = get_sub_field($field_name, $field);
259
 
260
- if(is_array($value))
261
- {
262
- $value = implode(', ',$value);
263
- }
264
 
265
- echo $value;
266
  }
267
 
268
 
 
 
 
 
 
 
 
 
269
 
270
- /*---------------------------------------------------------------------------------------------
271
- * ACF_WP_Query
272
- *
273
- * @author Elliot Condon
274
- * @since 1.1.3
275
- *
276
- ---------------------------------------------------------------------------------------------*/
277
- class ACF_WP_Query extends WP_Query
278
  {
279
- var $orderby_field;
280
- var $order;
281
- var $orderby_type;
282
 
283
- function __construct($args=array())
284
- {
285
- // set default variabls
286
- $this->orderby_field = '';
287
- $this->order = 'ASC';
288
- $this->orderby_type = 'string';
289
-
290
-
291
- // set order
292
- if(!empty($args['order']))
293
- {
294
- $this->order = $args['order'];
295
- }
296
-
297
-
298
- // set value type
299
- if(!empty($args['orderby_type']))
300
- {
301
- $this->orderby_type = $args['orderby_type'];
302
- }
303
 
304
 
305
- if(!empty($args['orderby_field']))
306
- {
307
- $this->orderby_field = $args['orderby_field'];
308
-
309
- add_filter('posts_join', array($this, 'posts_join'));
310
- add_filter('posts_where', array($this, 'posts_where'));
311
- add_filter('posts_orderby', array($this, 'posts_orderby'));
312
- }
313
 
314
- parent::query($args);
315
- }
316
 
317
- function posts_join($join)
318
- {
319
- global $wpdb;
320
- $acf_fields = $wpdb->prefix.'acf_fields';
321
- $acf_values = $wpdb->prefix.'acf_values';
322
-
323
- $join .= "LEFT JOIN $acf_values v ON v.post_id=".$wpdb->prefix."posts.ID
324
- LEFT JOIN $acf_fields f ON f.id=v.field_id";
325
-
326
- return $join;
327
- }
328
 
329
- function posts_where($where)
 
330
  {
331
- $where .= "AND f.name = '".$this->orderby_field."'";
332
- return $where;
333
  }
 
 
 
 
334
 
335
- function posts_orderby($orderby)
336
- {
337
 
338
- if($this->orderby_type == 'int')
 
 
 
 
339
  {
340
- $orderby = "ABS(v.value) ".$this->order;
341
  }
342
  else
343
  {
344
- $orderby = "v.value ".$this->order;
345
  }
346
 
 
 
 
 
 
 
347
 
348
- return $orderby;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
  }
 
 
350
  }
351
 
352
  ?>
1
+ <?php
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ global $acf_global;
4
 
5
+ $acf_global = array(
6
+ 'field_id' => 0,
7
+ 'post_id' => 0,
8
+ 'order_no' => -1,
9
+ );
10
+
11
+ /*--------------------------------------------------------------------------------------
12
+ *
13
+ * get_field
14
+ *
15
+ * @author Elliot Condon
16
+ * @since 1.0.3
17
+ *
18
+ *-------------------------------------------------------------------------------------*/
19
 
20
+ function get_field($field_name, $post_id = false)
 
 
 
 
 
 
 
21
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
 
 
 
 
 
 
 
 
 
 
 
23
  global $post;
24
+ global $wpdb;
25
+ global $acf;
26
 
27
 
28
+ // tables
29
+ $acf_values = $wpdb->prefix.'acf_values';
30
+ $acf_fields = $wpdb->prefix.'acf_fields';
31
+ $wp_postmeta = $wpdb->prefix.'postmeta';
32
 
33
 
 
34
  if(!$post_id)
35
  {
36
  $post_id = $post->ID;
40
  $post_id = 0;
41
  }
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ $sql = "SELECT m.meta_value as value, f.type, f.options
45
+ FROM $wp_postmeta m
46
+ LEFT JOIN $acf_values v ON m.meta_id = v.value
47
+ LEFT JOIN $acf_fields f ON v.field_id = f.id
48
+ WHERE f.name = '$field_name' AND m.post_id = '$post_id'";
49
+
50
+ $results = $wpdb->get_results($sql);
51
 
52
 
53
+ // no value
54
+ if(!$results)
55
  {
56
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  }
58
 
 
 
59
 
60
+ // repeater field
61
+ if(count($results) > 1)
62
+ {
63
+ return true;
64
  }
65
 
66
 
67
+ // normal field
68
+ $field = $results[0];
69
+ $value = $field->value;
70
+
71
 
72
+ // format if needed
73
+ if($acf->field_method_exists($field->type, 'format_value_for_api'))
74
  {
75
+
76
+ if(@unserialize($field->options))
77
+ {
78
+ $field->options = unserialize($field->options);
79
+ }
80
+ else
81
  {
82
+ $field->options = array();
83
  }
84
 
85
+ $value = $acf->fields[$field->type]->format_value_for_api($value, $field->options);
86
  }
87
 
88
+ return $value;
89
 
 
 
 
 
90
  }
91
 
92
 
93
+ /*--------------------------------------------------------------------------------------
94
+ *
95
+ * the_field
96
+ *
97
+ * @author Elliot Condon
98
+ * @since 1.0.3
99
+ *
100
+ *-------------------------------------------------------------------------------------*/
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  function the_field($field_name, $post_id = false)
103
  {
104
+
105
  $value = get_field($field_name, $post_id);
106
 
107
  if(is_array($value))
110
  }
111
 
112
  echo $value;
113
+
 
114
  }
115
 
116
 
117
+ /*--------------------------------------------------------------------------------------
118
+ *
119
+ * the_repeater_field
120
+ *
121
+ * @author Elliot Condon
122
+ * @since 1.0.3
123
+ *
124
+ *-------------------------------------------------------------------------------------*/
125
 
126
  function the_repeater_field($field_name, $post_id = false)
127
  {
 
 
 
128
 
129
+ global $acf_global;
130
+ global $post;
131
+ global $wpdb;
132
+ global $acf;
133
+
134
+
135
+ // tables
136
+ $acf_values = $wpdb->prefix.'acf_values';
137
+ $acf_fields = $wpdb->prefix.'acf_fields';
138
+ $wp_postmeta = $wpdb->prefix.'postmeta';
139
 
140
 
141
+ if(!$post_id)
142
+ {
143
+ $post_id = $post->ID;
144
+ }
145
+ elseif($post_id == "options")
146
+ {
147
+ $post_id = 0;
148
+ }
149
 
 
 
150
 
151
+ // vars
152
+ $acf_global['order_no']++;
153
+ $order_no = $acf_global['order_no'];
154
 
 
 
 
 
 
 
155
 
156
+ $sql = "SELECT v.field_id
157
+ FROM $wp_postmeta m
158
+ LEFT JOIN $acf_values v ON m.meta_id = v.value
159
+ LEFT JOIN $acf_fields f ON v.field_id = f.id
160
+ WHERE f.name = '$field_name' AND v.order_no = '$order_no' AND m.post_id = '$post_id'";
161
+
162
+ $results = $wpdb->get_results($sql);
163
 
 
 
 
 
 
164
 
165
+ // no value
166
+ if($results)
167
  {
168
+
169
+ $acf_global['field_id'] = $results[0]->field_id;
170
+ $acf_global['post_id'] = $post_id;
171
+ return true;
172
  }
173
  else
174
  {
175
+ $acf_global['field_id'] = 0;
176
+ $acf_global['post_id'] = 0;
177
+ $acf_global['order_no'] = -1;
178
  return false;
179
  }
 
 
 
 
 
 
 
180
 
 
 
 
 
181
 
182
+
183
  }
184
 
185
 
186
+ /*--------------------------------------------------------------------------------------
187
+ *
188
+ * get_sub_field
189
+ *
190
+ * @author Elliot Condon
191
+ * @since 1.0.3
192
+ *
193
+ *-------------------------------------------------------------------------------------*/
194
 
195
+ function get_sub_field($field_name)
 
 
 
 
 
 
 
196
  {
197
+ global $acf_global;
198
+ global $wpdb;
199
+ global $acf;
200
 
201
+
202
+ // tables
203
+ $acf_values = $wpdb->prefix.'acf_values';
204
+ $acf_fields = $wpdb->prefix.'acf_fields';
205
+ $wp_postmeta = $wpdb->prefix.'postmeta';
206
+
207
+
208
+ // vars
209
+ $field_id = $acf_global['field_id'];
210
+ $post_id = $acf_global['post_id'];
211
+ $order_no = $acf_global['order_no'];
 
 
 
 
 
 
 
 
 
212
 
213
 
214
+ $sql = "SELECT m.meta_value as value, f.type, f.options
215
+ FROM $wp_postmeta m
216
+ LEFT JOIN $acf_values v ON m.meta_id = v.value
217
+ LEFT JOIN $acf_fields f ON v.sub_field_id = f.id
218
+ WHERE f.name = '$field_name' AND v.field_id = '$field_id' AND v.order_no = '$order_no' AND m.post_id = '$post_id'";
 
 
 
219
 
220
+ $field = $wpdb->get_row($sql);
 
221
 
 
 
 
 
 
 
 
 
 
 
 
222
 
223
+ // no value
224
+ if(!$field)
225
  {
226
+ return false;
 
227
  }
228
+
229
+
230
+ // normal field
231
+ $value = $field->value;
232
 
 
 
233
 
234
+ // format if needed
235
+ if($acf->field_method_exists($field->type, 'format_value_for_api'))
236
+ {
237
+
238
+ if(@unserialize($field->options))
239
  {
240
+ $field->options = unserialize($field->options);
241
  }
242
  else
243
  {
244
+ $field->options = array();
245
  }
246
 
247
+ $value = $acf->fields[$field->type]->format_value_for_api($value, $field->options);
248
+ }
249
+
250
+ return $value;
251
+ }
252
+
253
 
254
+ /*--------------------------------------------------------------------------------------
255
+ *
256
+ * the_sub_field
257
+ *
258
+ * @author Elliot Condon
259
+ * @since 1.0.3
260
+ *
261
+ *-------------------------------------------------------------------------------------*/
262
+
263
+ function the_sub_field($field_name, $field = false)
264
+ {
265
+ $value = get_sub_field($field_name, $field);
266
+
267
+ if(is_array($value))
268
+ {
269
+ $value = implode(', ',$value);
270
  }
271
+
272
+ echo $value;
273
  }
274
 
275
  ?>
core/fields/checkbox.php CHANGED
@@ -18,6 +18,13 @@ class acf_Checkbox
18
  $field->value = array();
19
  }
20
 
 
 
 
 
 
 
 
21
  echo '<ul class="checkbox_list '.$field->input_class.'">';
22
  // loop through values and add them as options
23
 
@@ -34,7 +41,7 @@ class acf_Checkbox
34
  {
35
  $selected = 'checked="yes"';
36
  }
37
- echo '<li><input type="checkbox" class="'.$field->input_class.'" name="'.$field->input_name.$name_extra.'" value="'.$key.'" '.$selected.' />'.$value.'</li>';
38
  }
39
  echo '</ul>';
40
 
@@ -50,8 +57,10 @@ class acf_Checkbox
50
  * @since 1.1
51
  *
52
  ---------------------------------------------------------------------------------------------*/
53
- function options_html($key, $options)
54
  {
 
 
55
  // implode checkboxes so they work in a textarea
56
  if(isset($options['choices']) && is_array($options['choices']))
57
  {
@@ -155,7 +164,7 @@ class acf_Checkbox
155
  * @since 1.1
156
  *
157
  ---------------------------------------------------------------------------------------------*/
158
- function format_value_for_api($value)
159
  {
160
  if(is_array(unserialize($value)))
161
  {
18
  $field->value = array();
19
  }
20
 
21
+ if(empty($field->options['choices']))
22
+ {
23
+
24
+ echo '<p>' . __("No choices to choose from",'acf') . '</p>';
25
+ return false;
26
+ }
27
+
28
  echo '<ul class="checkbox_list '.$field->input_class.'">';
29
  // loop through values and add them as options
30
 
41
  {
42
  $selected = 'checked="yes"';
43
  }
44
+ echo '<li><label><input type="checkbox" class="'.$field->input_class.'" name="'.$field->input_name.$name_extra.'" value="'.$key.'" '.$selected.' />'.$value.'</label></li>';
45
  }
46
  echo '</ul>';
47
 
57
  * @since 1.1
58
  *
59
  ---------------------------------------------------------------------------------------------*/
60
+ function options_html($key, $field)
61
  {
62
+ $options = $field->options;
63
+
64
  // implode checkboxes so they work in a textarea
65
  if(isset($options['choices']) && is_array($options['choices']))
66
  {
164
  * @since 1.1
165
  *
166
  ---------------------------------------------------------------------------------------------*/
167
+ function format_value_for_api($value, $options)
168
  {
169
  if(is_array(unserialize($value)))
170
  {
core/fields/date_picker/date_picker.php CHANGED
@@ -15,13 +15,14 @@ class acf_Date_picker
15
 
16
  function html($field)
17
  {
18
- echo '<input type="hidden" value="'.$field->options['date_format'].'" name="date_format" />';
19
- echo '<input type="text" value="'.$field->value.'" id="'.$field->input_id.'" class="acf_datepicker" name="'.$field->input_name.'" />';
20
 
21
  }
22
 
23
- function options_html($key, $options)
24
  {
 
 
25
  if(!isset($options['date_format']))
26
  {
27
  $options['date_format'] = "";
15
 
16
  function html($field)
17
  {
18
+ echo '<input type="text" value="'.$field->value.'" class="acf_datepicker" name="'.$field->input_name.'" data-date_format="'.$field->options['date_format'].'" />';
 
19
 
20
  }
21
 
22
+ function options_html($key, $field)
23
  {
24
+ $options = $field->options;
25
+
26
  if(!isset($options['date_format']))
27
  {
28
  $options['date_format'] = "";
core/fields/date_picker/jquery.ui.datepicker.js CHANGED
File without changes
core/fields/date_picker/style.date_picker.css CHANGED
File without changes
core/fields/file.php CHANGED
@@ -28,12 +28,13 @@ class acf_File
28
  * @since 2.0.3
29
  *
30
  ---------------------------------------------------------------------------------------------*/
31
- function options_html($key, $options)
32
  {
 
33
  ?>
34
  <tr class="field_option field_option_file">
35
  <td class="label">
36
- <label><?php _e("Save Format",'acf'); ?></label>
37
  </td>
38
  <td>
39
  <?php
@@ -138,67 +139,85 @@ class acf_File
138
  ?>
139
  <script type="text/javascript">
140
 
141
- if(self.parent.acf_div.find('input.value').hasClass('id'))
142
- {
143
- self.parent.acf_div.find('input.value').val('<?php echo $id; ?>');
144
- }
145
- else
146
- {
147
- self.parent.acf_div.find('input.value').val('<?php echo $file_src; ?>');
148
- }
149
-
150
- self.parent.acf_div.find('p.file span').html('<?php echo $file_src; ?>');
151
  self.parent.acf_div.addClass('active');
152
 
153
  // reset acf_div and return false
154
  self.parent.acf_div = null;
155
-
156
  self.parent.tb_remove();
157
 
158
  </script>
159
  <?php
160
  exit;
161
- }
162
  else
163
  {
164
  return $html;
165
  }
166
-
167
  }
168
 
169
 
 
 
 
 
 
 
 
 
 
170
  function html($field)
171
  {
172
 
173
  $class = "";
174
- $file = "";
175
 
176
- if($field->value != '')
177
  {
178
- $file = $field->value;
179
- $class = " active";
180
- }
181
-
182
- if(!isset($field->options['save_format'])){$field->options['save_format'] = 'url';}
183
-
184
- echo '<div class="acf_file_uploader'.$class.'">';
185
- echo '<a href="#" class="remove_file"></a>';
186
- if($field->options['save_format'] == 'id')
187
- {
188
- $file_src = wp_get_attachment_url($field->value);
189
- echo '<p class="file"><span>'.$file_src.'</span> <input type="button" class="button" value="'.__('Remove File','acf').'" /></p>';
190
- }
191
- else
192
  {
193
- echo '<p class="file"><span>'.$field->value.'</span> <input type="button" class="button" value="'.__('Remove File','acf').'" /></p>';
194
  }
195
-
196
- echo '<input class="value '.$field->options['save_format'].'" type="hidden" name="'.$field->input_name.'" value="'.$field->value.'" />';
 
 
 
 
197
  echo '<p class="no_file">'.__('No File selected','acf').'. <input type="button" class="button" value="'.__('Add File','acf').'" /></p>';
198
  echo '</div>';
199
 
200
  }
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  }
203
 
204
  ?>
28
  * @since 2.0.3
29
  *
30
  ---------------------------------------------------------------------------------------------*/
31
+ function options_html($key, $field)
32
  {
33
+ $options = $field->options;
34
  ?>
35
  <tr class="field_option field_option_file">
36
  <td class="label">
37
+ <label><?php _e("Return Value",'acf'); ?></label>
38
  </td>
39
  <td>
40
  <?php
139
  ?>
140
  <script type="text/javascript">
141
 
142
+ self.parent.acf_div.find('input.value').val('<?php echo $id; ?>');
143
+ self.parent.acf_div.find('span.file_url').text('<?php echo $file_src; ?>');
 
 
 
 
 
 
 
 
144
  self.parent.acf_div.addClass('active');
145
 
146
  // reset acf_div and return false
147
  self.parent.acf_div = null;
 
148
  self.parent.tb_remove();
149
 
150
  </script>
151
  <?php
152
  exit;
153
+ }
154
  else
155
  {
156
  return $html;
157
  }
 
158
  }
159
 
160
 
161
+ /*--------------------------------------------------------------------------------------
162
+ *
163
+ * html
164
+ *
165
+ * @author Elliot Condon
166
+ * @since 2.0.6
167
+ *
168
+ *-------------------------------------------------------------------------------------*/
169
+
170
  function html($field)
171
  {
172
 
173
  $class = "";
174
+ $file_src = "";
175
 
176
+ if($field->value != '' && is_numeric($field->value))
177
  {
178
+ $file_src = wp_get_attachment_url($field->value);
179
+
180
+ if($file_src)
 
 
 
 
 
 
 
 
 
 
 
181
  {
182
+ $class = " active";
183
  }
184
+ }
185
+
186
+
187
+ echo '<div class="acf_file_uploader'.$class.'">';
188
+ echo '<p class="file"><span class="file_url">'.$file_src.'</span> <input type="button" class="button" value="'.__('Remove File','acf').'" /></p>';
189
+ echo '<input class="value" type="hidden" name="'.$field->input_name.'" value="'.$field->value.'" />';
190
  echo '<p class="no_file">'.__('No File selected','acf').'. <input type="button" class="button" value="'.__('Add File','acf').'" /></p>';
191
  echo '</div>';
192
 
193
  }
194
 
195
+
196
+ /*--------------------------------------------------------------------------------------
197
+ *
198
+ * Format Value
199
+ * - this is called from api.php
200
+ *
201
+ * @author Elliot Condon
202
+ * @since 2.0.6
203
+ *
204
+ *-------------------------------------------------------------------------------------*/
205
+
206
+ function format_value_for_api($value, $options = null)
207
+ {
208
+
209
+ $format = isset($options['save_format']) ? $options['save_format'] : 'url';
210
+
211
+ if($format == 'url')
212
+ {
213
+ $value = wp_get_attachment_url($value);
214
+ }
215
+
216
+ return $value;
217
+
218
+ }
219
+
220
+
221
  }
222
 
223
  ?>
core/fields/image.php CHANGED
@@ -28,12 +28,13 @@ class acf_Image
28
  * @since 2.0.3
29
  *
30
  ---------------------------------------------------------------------------------------------*/
31
- function options_html($key, $options)
32
  {
 
33
  ?>
34
  <tr class="field_option field_option_image">
35
  <td class="label">
36
- <label><?php _e("Save Format",'acf'); ?></label>
37
  </td>
38
  <td>
39
  <?php
@@ -118,30 +119,6 @@ class acf_Image
118
  }
119
 
120
 
121
- /*---------------------------------------------------------------------------------------------
122
- * rename_buttons - RENAMES MEDIA THICKBOX BUTTONS
123
- *
124
- * @author Elliot Condon
125
- * @since 1.1.4
126
- *
127
- ---------------------------------------------------------------------------------------------
128
- function admin_init()
129
- {
130
- //if(isset($_GET["acf_type"]) && $_GET["acf_type"] == "image")
131
- //{
132
- // add_filter('gettext', array($this, 'rename_buttons'), 1, 3);
133
- //}
134
- }
135
-
136
- function rename_buttons($translated_text, $source_text, $domain) {
137
- if ($source_text == 'Insert into Post') {
138
- return __('Select Image', 'acf' );
139
- }
140
-
141
- return $translated_text;
142
- }*/
143
-
144
-
145
  /*---------------------------------------------------------------------------------------------
146
  * media_send_to_editor - SEND IMAGE TO ACF DIV
147
  *
@@ -161,22 +138,12 @@ class acf_Image
161
  ?>
162
  <script type="text/javascript">
163
 
164
- if(self.parent.acf_div.find('input.value').hasClass('id'))
165
- {
166
- self.parent.acf_div.find('input.value').val('<?php echo $id; ?>');
167
- }
168
- else
169
- {
170
- self.parent.acf_div.find('input.value').val('<?php echo $file_src; ?>');
171
- }
172
-
173
-
174
  self.parent.acf_div.find('img').attr('src','<?php echo $file_src; ?>');
175
  self.parent.acf_div.addClass('active');
176
 
177
  // reset acf_div and return false
178
  self.parent.acf_div = null;
179
-
180
  self.parent.tb_remove();
181
 
182
  </script>
@@ -187,7 +154,7 @@ class acf_Image
187
  {
188
  return $html;
189
  }
190
-
191
  }
192
 
193
 
@@ -195,32 +162,53 @@ class acf_Image
195
  {
196
 
197
  $class = "";
 
198
 
199
- if($field->value != '')
200
  {
201
- $class = " active";
 
 
 
 
 
202
  }
203
-
204
- if(!isset($field->options['save_format'])){$field->options['save_format'] = 'url';}
205
 
206
  echo '<div class="acf_image_uploader'.$class.'">';
207
  echo '<a href="#" class="remove_image"></a>';
208
- if($field->options['save_format'] == 'id')
209
- {
210
- $file_src = wp_get_attachment_url($field->value);
211
- echo '<img src="'.$file_src.'" alt=""/>';
212
- }
213
- else
214
- {
215
- echo '<img src="'.$field->value.'" alt=""/>';
216
- }
217
-
218
- echo '<input class="value '.$field->options['save_format'].'" type="hidden" name="'.$field->input_name.'" value="'.$field->value.'" />';
219
  echo '<p>'.__('No image selected','acf').'. <input type="button" class="button" value="'.__('Add Image','acf').'" /></p>';
220
  echo '</div>';
221
 
222
  }
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  }
225
 
226
  ?>
28
  * @since 2.0.3
29
  *
30
  ---------------------------------------------------------------------------------------------*/
31
+ function options_html($key, $field)
32
  {
33
+ $options = $field->options;
34
  ?>
35
  <tr class="field_option field_option_image">
36
  <td class="label">
37
+ <label><?php _e("Return Value",'acf'); ?></label>
38
  </td>
39
  <td>
40
  <?php
119
  }
120
 
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  /*---------------------------------------------------------------------------------------------
123
  * media_send_to_editor - SEND IMAGE TO ACF DIV
124
  *
138
  ?>
139
  <script type="text/javascript">
140
 
141
+ self.parent.acf_div.find('input.value').val('<?php echo $id; ?>');
 
 
 
 
 
 
 
 
 
142
  self.parent.acf_div.find('img').attr('src','<?php echo $file_src; ?>');
143
  self.parent.acf_div.addClass('active');
144
 
145
  // reset acf_div and return false
146
  self.parent.acf_div = null;
 
147
  self.parent.tb_remove();
148
 
149
  </script>
154
  {
155
  return $html;
156
  }
157
+
158
  }
159
 
160
 
162
  {
163
 
164
  $class = "";
165
+ $file_src = "";
166
 
167
+ if($field->value != '' && is_numeric($field->value))
168
  {
169
+ $file_src = wp_get_attachment_url($field->value);
170
+
171
+ if($file_src)
172
+ {
173
+ $class = " active";
174
+ }
175
  }
176
+
 
177
 
178
  echo '<div class="acf_image_uploader'.$class.'">';
179
  echo '<a href="#" class="remove_image"></a>';
180
+ echo '<img src="'.$file_src.'" alt=""/>';
181
+ echo '<input class="value" type="hidden" name="'.$field->input_name.'" value="'.$field->value.'" />';
 
 
 
 
 
 
 
 
 
182
  echo '<p>'.__('No image selected','acf').'. <input type="button" class="button" value="'.__('Add Image','acf').'" /></p>';
183
  echo '</div>';
184
 
185
  }
186
 
187
+
188
+ /*--------------------------------------------------------------------------------------
189
+ *
190
+ * Format Value
191
+ * - this is called from api.php
192
+ *
193
+ * @author Elliot Condon
194
+ * @since 2.0.6
195
+ *
196
+ *-------------------------------------------------------------------------------------*/
197
+
198
+ function format_value_for_api($value, $options)
199
+ {
200
+
201
+ $format = isset($options['save_format']) ? $options['save_format'] : 'url';
202
+
203
+ if($format == 'url')
204
+ {
205
+ $value = wp_get_attachment_url($value);
206
+ }
207
+
208
+ return $value;
209
+
210
+ }
211
+
212
  }
213
 
214
  ?>
core/fields/page_link.php CHANGED
@@ -53,8 +53,12 @@ class acf_Page_link
53
  else
54
  {
55
  echo '<select id="'.$field->input_name.'" class="'.$field->input_class.'" name="'.$field->input_name.'" >';
56
- // add top option
57
- //echo '<option value="null">- '.__("Select Option",'acf').' -</option>';
 
 
 
 
58
  }
59
 
60
 
@@ -126,17 +130,14 @@ class acf_Page_link
126
  * @since 1.1
127
  *
128
  ---------------------------------------------------------------------------------------------*/
129
- function options_html($key, $options)
130
  {
131
- if(!isset($options['post_type']))
132
- {
133
- $options['post_type'] = "";
134
- }
 
135
 
136
- if(!isset($options['multiple']))
137
- {
138
- $options['multiple'] = '0';
139
- }
140
  ?>
141
 
142
  <tr class="field_option field_option_page_link">
@@ -174,16 +175,31 @@ class acf_Page_link
174
  </tr>
175
  <tr class="field_option field_option_page_link">
176
  <td class="label">
177
- <label><?php _e("Select multiple values?",'acf'); ?></label>
178
  </td>
179
  <td>
180
  <?php
181
  $temp_field = new stdClass();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  $temp_field->type = 'true_false';
183
  $temp_field->input_name = 'acf[fields]['.$key.'][options][multiple]';
184
  $temp_field->input_class = '';
185
  $temp_field->value = $options['multiple'];
186
- $temp_field->options = array('message' => '');
187
  $this->parent->create_field($temp_field);
188
  ?>
189
  </td>
@@ -201,10 +217,15 @@ class acf_Page_link
201
  * @since 1.1.3
202
  *
203
  ---------------------------------------------------------------------------------------------*/
204
- function format_value_for_api($value)
205
  {
206
  $value = $this->format_value_for_input($value);
207
 
 
 
 
 
 
208
  if(is_array($value))
209
  {
210
  foreach($value as $k => $v)
53
  else
54
  {
55
  echo '<select id="'.$field->input_name.'" class="'.$field->input_class.'" name="'.$field->input_name.'" >';
56
+
57
+ // add null
58
+ if(isset($field->options['allow_null']) && $field->options['allow_null'] == '1')
59
+ {
60
+ echo '<option value="null"> - Select - </option>';
61
+ }
62
  }
63
 
64
 
130
  * @since 1.1
131
  *
132
  ---------------------------------------------------------------------------------------------*/
133
+ function options_html($key, $field)
134
  {
135
+ $options = $field->options;
136
+
137
+ $options['post_type'] = isset($options['post_type']) ? $options['post_type'] : '';
138
+ $options['multiple'] = isset($options['multiple']) ? $options['multiple'] : '0';
139
+ $options['allow_null'] = isset($options['allow_null']) ? $options['allow_null'] : '0';
140
 
 
 
 
 
141
  ?>
142
 
143
  <tr class="field_option field_option_page_link">
175
  </tr>
176
  <tr class="field_option field_option_page_link">
177
  <td class="label">
178
+ <label><?php _e("Allow Null?",'acf'); ?></label>
179
  </td>
180
  <td>
181
  <?php
182
  $temp_field = new stdClass();
183
+ $temp_field->type = 'true_false';
184
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][allow_null]';
185
+ $temp_field->input_class = '';
186
+ $temp_field->value = $options['allow_null'];
187
+ $temp_field->options = array('message' => 'Add null value above choices');
188
+ $this->parent->create_field($temp_field);
189
+ ?>
190
+ </td>
191
+ </tr>
192
+ <tr class="field_option field_option_page_link">
193
+ <td class="label">
194
+ <label><?php _e("Select multiple values?",'acf'); ?></label>
195
+ </td>
196
+ <td>
197
+ <?php
198
  $temp_field->type = 'true_false';
199
  $temp_field->input_name = 'acf[fields]['.$key.'][options][multiple]';
200
  $temp_field->input_class = '';
201
  $temp_field->value = $options['multiple'];
202
+ $temp_field->options = array('message' => 'Turn this drop-down into a multi-select');
203
  $this->parent->create_field($temp_field);
204
  ?>
205
  </td>
217
  * @since 1.1.3
218
  *
219
  ---------------------------------------------------------------------------------------------*/
220
+ function format_value_for_api($value, $options = null)
221
  {
222
  $value = $this->format_value_for_input($value);
223
 
224
+ if($value == 'null')
225
+ {
226
+ return false;
227
+ }
228
+
229
  if(is_array($value))
230
  {
231
  foreach($value as $k => $v)
core/fields/post_object.php CHANGED
@@ -44,8 +44,12 @@ class acf_Post_object
44
  else
45
  {
46
  echo '<select id="'.$field->input_name.'" class="'.$field->input_class.'" name="'.$field->input_name.'" >';
47
- // add top option
48
- echo '<option value="null">- '.__("Select Option",'acf').' -</option>';
 
 
 
 
49
  }
50
 
51
 
@@ -114,17 +118,14 @@ class acf_Post_object
114
  * @since 1.1
115
  *
116
  ---------------------------------------------------------------------------------------------*/
117
- function options_html($key, $options)
118
  {
119
- if(!isset($options['post_type']))
120
- {
121
- $options['post_type'] = "";
122
- }
 
123
 
124
- if(!isset($options['multiple']))
125
- {
126
- $options['multiple'] = '0';
127
- }
128
  ?>
129
 
130
  <tr class="field_option field_option_post_object">
@@ -161,16 +162,31 @@ class acf_Post_object
161
  </tr>
162
  <tr class="field_option field_option_post_object">
163
  <td class="label">
164
- <label><?php _e("Select multiple posts?",'acf'); ?></label>
165
  </td>
166
  <td>
167
  <?php
168
  $temp_field = new stdClass();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  $temp_field->type = 'true_false';
170
  $temp_field->input_name = 'acf[fields]['.$key.'][options][multiple]';
171
  $temp_field->input_class = '';
172
  $temp_field->value = $options['multiple'];
173
- $temp_field->options = array('message' => '');
174
  $this->parent->create_field($temp_field);
175
  ?>
176
  </td>
@@ -190,10 +206,20 @@ class acf_Post_object
190
  * @since 1.1
191
  *
192
  ---------------------------------------------------------------------------------------------*/
193
- function format_value_for_api($value)
194
  {
195
  $value = $this->format_value_for_input($value);
196
-
 
 
 
 
 
 
 
 
 
 
197
  if(is_array($value))
198
  {
199
  foreach($value as $k => $v)
44
  else
45
  {
46
  echo '<select id="'.$field->input_name.'" class="'.$field->input_class.'" name="'.$field->input_name.'" >';
47
+
48
+ // add null
49
+ if(isset($field->options['allow_null']) && $field->options['allow_null'] == '1')
50
+ {
51
+ echo '<option value="null"> - Select - </option>';
52
+ }
53
  }
54
 
55
 
118
  * @since 1.1
119
  *
120
  ---------------------------------------------------------------------------------------------*/
121
+ function options_html($key, $field)
122
  {
123
+ $options = $field->options;
124
+
125
+ $options['post_type'] = isset($options['post_type']) ? $options['post_type'] : '';
126
+ $options['multiple'] = isset($options['multiple']) ? $options['multiple'] : '0';
127
+ $options['allow_null'] = isset($options['allow_null']) ? $options['allow_null'] : '0';
128
 
 
 
 
 
129
  ?>
130
 
131
  <tr class="field_option field_option_post_object">
162
  </tr>
163
  <tr class="field_option field_option_post_object">
164
  <td class="label">
165
+ <label><?php _e("Allow Null?",'acf'); ?></label>
166
  </td>
167
  <td>
168
  <?php
169
  $temp_field = new stdClass();
170
+ $temp_field->type = 'true_false';
171
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][allow_null]';
172
+ $temp_field->input_class = '';
173
+ $temp_field->value = $options['allow_null'];
174
+ $temp_field->options = array('message' => 'Add null value above choices');
175
+ $this->parent->create_field($temp_field);
176
+ ?>
177
+ </td>
178
+ </tr>
179
+ <tr class="field_option field_option_post_object">
180
+ <td class="label">
181
+ <label><?php _e("Select multiple values?",'acf'); ?></label>
182
+ </td>
183
+ <td>
184
+ <?php
185
  $temp_field->type = 'true_false';
186
  $temp_field->input_name = 'acf[fields]['.$key.'][options][multiple]';
187
  $temp_field->input_class = '';
188
  $temp_field->value = $options['multiple'];
189
+ $temp_field->options = array('message' => 'Turn this drop-down into a multi-select');
190
  $this->parent->create_field($temp_field);
191
  ?>
192
  </td>
206
  * @since 1.1
207
  *
208
  ---------------------------------------------------------------------------------------------*/
209
+ function format_value_for_api($value, $options = null)
210
  {
211
  $value = $this->format_value_for_input($value);
212
+
213
+ if($value == 'null')
214
+ {
215
+ return false;
216
+ }
217
+
218
+ if(!$value)
219
+ {
220
+ return false;
221
+ }
222
+
223
  if(is_array($value))
224
  {
225
  foreach($value as $k => $v)
core/fields/radio.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class acf_Radio
4
+ {
5
+ var $name;
6
+ var $title;
7
+
8
+ function acf_Radio()
9
+ {
10
+ $this->name = 'radio';
11
+ $this->title = __('Radio Button','acf');
12
+ }
13
+
14
+
15
+ /*--------------------------------------------------------------------------------------
16
+ *
17
+ * HTML
18
+ *
19
+ * @author Elliot Condon
20
+ * @since 2.0.6
21
+ *
22
+ *-------------------------------------------------------------------------------------*/
23
+
24
+ function html($field)
25
+ {
26
+ if(empty($field->value))
27
+ {
28
+ $field->value = array();
29
+ }
30
+
31
+ if(empty($field->options['choices']))
32
+ {
33
+
34
+ echo '<p>' . __("No choices to choose from",'acf') . '</p>';
35
+
36
+ return false;
37
+ }
38
+
39
+ $layout = isset($field->options['layout']) ? $field->options['layout'] : 'vertical';
40
+
41
+
42
+ echo '<ul class="radio_list ' .$field->input_class . ' ' . $layout . '">';
43
+
44
+ foreach($field->options['choices'] as $key => $value)
45
+ {
46
+ $selected = '';
47
+
48
+ if($key == $field->value)
49
+ {
50
+ $selected = 'checked="checked"';
51
+ }
52
+
53
+ echo '<li><input type="radio" class="'.$field->input_class.'" name="'.$field->input_name.'" value="'.$key.'" '.$selected.' />'.$value.'</li>';
54
+ }
55
+
56
+ echo '</ul>';
57
+
58
+ }
59
+
60
+
61
+ /*--------------------------------------------------------------------------------------
62
+ *
63
+ * Options HTML
64
+ *
65
+ * @author Elliot Condon
66
+ * @since 2.0.6
67
+ *
68
+ *-------------------------------------------------------------------------------------*/
69
+
70
+ function options_html($key, $field)
71
+ {
72
+ $options = $field->options;
73
+
74
+ // layout
75
+ $options['layout'] = isset($options['layout']) ? $options['layout'] : 'vertical';
76
+
77
+ // implode checkboxes so they work in a textarea
78
+ if(isset($options['choices']) && is_array($options['choices']))
79
+ {
80
+ foreach($options['choices'] as $choice_key => $choice_val)
81
+ {
82
+ $options['choices'][$choice_key] = $choice_key.' : '.$choice_val;
83
+ }
84
+ $options['choices'] = implode("\n", $options['choices']);
85
+ }
86
+ else
87
+ {
88
+ $options['choices'] = "";
89
+ }
90
+
91
+ ?>
92
+
93
+
94
+ <tr class="field_option field_option_radio">
95
+ <td class="label">
96
+ <label for=""><?php _e("Choices",'acf'); ?></label>
97
+ <p class="description"><?php _e("Enter your choices one per line<br />
98
+ <br />
99
+ Red<br />
100
+ Blue<br />
101
+ <br />
102
+ or<br />
103
+ <br />
104
+ red : Red<br />
105
+ blue : Blue",'acf'); ?></p>
106
+ </td>
107
+ <td>
108
+ <textarea rows="5" name="acf[fields][<?php echo $key; ?>][options][choices]" id=""><?php echo $options['choices']; ?></textarea>
109
+ </td>
110
+ </tr>
111
+ <tr class="field_option field_option_radio">
112
+ <td class="label">
113
+ <label for=""><?php _e("Layout",'acf'); ?></label>
114
+ </td>
115
+ <td>
116
+ <?php
117
+ $temp_field = new stdClass();
118
+ $temp_field->type = 'radio';
119
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][layout]';
120
+ $temp_field->input_class = '';
121
+ $temp_field->value = $options['layout'];
122
+ $temp_field->options = array('layout' => 'horizontal', 'choices' => array('vertical' => 'Vertical', 'horizontal' => 'Horizontal'));
123
+ $this->html($temp_field);
124
+ ?>
125
+ </td>
126
+ </tr>
127
+
128
+
129
+ <?php
130
+ }
131
+
132
+
133
+ /*--------------------------------------------------------------------------------------
134
+ *
135
+ * Format Options
136
+ * - this is called from save_field.php, this function formats the options into a savable format
137
+ *
138
+ * @author Elliot Condon
139
+ * @since 2.0.6
140
+ *
141
+ *-------------------------------------------------------------------------------------*/
142
+
143
+ function format_options($options)
144
+ {
145
+ // if no choices, dont do anything
146
+ if(!$options['choices'] || is_array($options['choices']))
147
+ {
148
+ return $options;
149
+ }
150
+
151
+
152
+ // explode choices from each line
153
+ if(strpos($options['choices'], "\n") !== false)
154
+ {
155
+ // found multiple lines, explode it
156
+ $choices = explode("\n", $options['choices']);
157
+ }
158
+ else
159
+ {
160
+ // no multiple lines!
161
+ $choices = array($options['choices']);
162
+ }
163
+
164
+
165
+
166
+ $new_choices = array();
167
+ foreach($choices as $choice)
168
+ {
169
+ if(strpos($choice, ' : ') !== false)
170
+ {
171
+
172
+ $choice = explode(' : ', $choice);
173
+ $new_choices[trim($choice[0])] = trim($choice[1]);
174
+ }
175
+ else
176
+ {
177
+ $new_choices[trim($choice)] = trim($choice);
178
+ }
179
+ }
180
+
181
+
182
+ // return array containing all choices
183
+ $options['choices'] = $new_choices;
184
+
185
+ return $options;
186
+ }
187
+
188
+
189
+ /*--------------------------------------------------------------------------------------
190
+ *
191
+ * Format Value
192
+ * - this is called from api.php
193
+ *
194
+ * @author Elliot Condon
195
+ * @since 2.0.6
196
+ *
197
+ *-------------------------------------------------------------------------------------*/
198
+
199
+ function format_value_for_api($value, $options = null)
200
+ {
201
+ if(!$value)
202
+ {
203
+ return false;
204
+ }
205
+
206
+ $is_array = @unserialize($value);
207
+
208
+ if($is_array)
209
+ {
210
+ return unserialize($value);
211
+ }
212
+ else
213
+ {
214
+ return $value;
215
+ }
216
+
217
+
218
+ }
219
+
220
+
221
+ /*--------------------------------------------------------------------------------------
222
+ *
223
+ * Format Value for input
224
+ * - this is called from acf.php
225
+ *
226
+ * @author Elliot Condon
227
+ * @since 2.0.6
228
+ *
229
+ *-------------------------------------------------------------------------------------*/
230
+
231
+ function format_value_for_input($value)
232
+ {
233
+ return $this->format_value_for_api($value);
234
+ }
235
+ }
236
+
237
+ ?>
core/fields/repeater.php CHANGED
@@ -31,12 +31,8 @@ class acf_Repeater
31
  $layout = $field->options['layout'];
32
  }
33
 
34
-
35
-
36
-
37
  ?>
38
- <div class="repeater">
39
- <input type="hidden" name="row_limit" value="<?php echo $row_limit; ?>" />
40
  <table class="widefat <?php if($layout == 'row'): ?>row_layout<?php endif; ?>">
41
  <?php if($layout == 'table'): ?>
42
  <thead>
@@ -77,7 +73,9 @@ class acf_Repeater
77
  <label><?php echo $sub_fields[$j]->label; ?></label>
78
  <?php endif; ?>
79
 
80
- <input type="hidden" name="<?php echo $field->input_name.'['.$i.']['.$j.'][row_id]'; ?>" value="<?php echo $field->value[$i][$j]->id; ?>" />
 
 
81
  <input type="hidden" name="<?php echo $field->input_name.'['.$i.']['.$j.'][field_id]'; ?>" value="<?php echo $sub_field->id; ?>" />
82
  <input type="hidden" name="<?php echo $field->input_name.'['.$i.']['.$j.'][field_type]' ?>" value="<?php echo $sub_field->type; ?>" />
83
 
@@ -128,8 +126,10 @@ class acf_Repeater
128
  * @since 1.1
129
  *
130
  ---------------------------------------------------------------------------------------------*/
131
- function options_html($key, $options)
132
  {
 
 
133
  if(isset($options['sub_fields']))
134
  {
135
  $fields = $options['sub_fields'];
@@ -138,9 +138,7 @@ class acf_Repeater
138
  {
139
  $fields = array();
140
  }
141
-
142
 
143
-
144
 
145
  // add clone
146
  $field = new stdClass();
@@ -166,20 +164,22 @@ class acf_Repeater
166
  </td>
167
  <td>
168
  <div class="repeater">
169
- <table class="acf widefat">
170
- <thead>
171
- <tr>
172
- <th class="field_order"><?php _e('Field Order','acf'); ?></th>
173
- <th class="field_label"><?php _e('Field Label','acf'); ?></th>
174
- <th class="field_name"><?php _e('Field Name','acf'); ?></th>
175
- <th class="field_type"><?php _e('Field Type','acf'); ?></th>
176
- </tr>
177
- </thead>
178
- </table>
 
 
179
  <div class="fields">
180
 
181
  <div class="no_fields_message" <?php if(sizeof($fields) > 1){ echo 'style="display:none;"'; } ?>>
182
- No fields. Click the "Add Field" button to create your first field.
183
  </div>
184
 
185
 
@@ -187,9 +187,11 @@ class acf_Repeater
187
  <div class="<?php if($key2 == 999){echo "field_clone";}else{echo "field";} ?> sub_field">
188
 
189
  <input type="hidden" name="acf[fields][<?php echo $key; ?>][sub_fields][<?php echo $key2; ?>][id]'" value="<?php echo $field->id; ?>" />
 
 
190
  <table class="acf widefat">
191
  <tr>
192
- <td class="field_order"><?php echo ($key2+1); ?></td>
193
  <td class="field_label">
194
  <strong>
195
  <a class="acf_edit_field" title="Edit this Field" href="javascript:;"><?php echo $field->label; ?></a>
@@ -203,6 +205,7 @@ class acf_Repeater
203
  <td class="field_type"><?php echo $field->type; ?></td>
204
  </tr>
205
  </table>
 
206
 
207
  <div class="field_form_mask">
208
  <div class="field_form">
@@ -267,7 +270,7 @@ class acf_Repeater
267
  <?php foreach($fields_names as $field_name => $field_title): ?>
268
  <?php if(method_exists($this->parent->fields[$field_name], 'options_html')): ?>
269
 
270
- <?php $this->parent->fields[$field_name]->options_html($key.'][sub_fields]['.$key2, $field->options); ?>
271
 
272
  <?php endif; ?>
273
  <?php endforeach; ?>
@@ -349,10 +352,7 @@ class acf_Repeater
349
  global $wpdb;
350
  $table_name = $wpdb->prefix.'acf_fields';
351
 
352
- //echo '<pre>';
353
- //print_r($field);
354
- //echo '</pre>';
355
- //die;
356
  if($field['sub_fields'])
357
  {
358
  foreach($field['sub_fields'] as $key => $field)
@@ -362,11 +362,18 @@ class acf_Repeater
362
  continue;
363
  }
364
 
 
365
  // defaults
366
  if(!isset($field['label'])) { $field['label'] = ""; }
367
  if(!isset($field['name'])) { $field['label'] = ""; }
368
  if(!isset($field['type'])) { $field['label'] = "text"; }
369
  if(!isset($field['options'])) { $field['options'] = array(); }
 
 
 
 
 
 
370
 
371
 
372
  // format options if needed
@@ -384,6 +391,7 @@ class acf_Repeater
384
  'label' => $field['label'],
385
  'name' => $field['name'],
386
  'type' => $field['type'],
 
387
  'options' => serialize($field['options']),
388
 
389
  );
@@ -396,7 +404,7 @@ class acf_Repeater
396
  // if there is an id, this field already exists, so save it in the same ID spot
397
  if($field['id'])
398
  {
399
- $data['id'] = $field['id'];
400
  }
401
 
402
 
@@ -422,12 +430,11 @@ class acf_Repeater
422
  ---------------------------------------------------------------------------------------------*/
423
  function save_input($post_id, $field)
424
  {
425
- //print_r($field);
426
- //die;
427
 
428
  // set table name
429
  global $wpdb;
430
- $table_name = $wpdb->prefix.'acf_values';
 
431
 
432
 
433
  $field = stripslashes_deep( $field );
@@ -442,6 +449,7 @@ class acf_Repeater
442
  foreach($row as $j => $cell)
443
  {
444
 
 
445
  // if select is a multiple (multiple select value), you need to save it as an array!
446
  if(isset($cell['value']) && $cell['value'] != "")
447
  {
@@ -452,29 +460,58 @@ class acf_Repeater
452
  }
453
  else
454
  {
455
- //$cell['value'] = "";
456
- continue;
457
  }
458
-
459
 
460
- // $j = cell number
461
- $data = array(
462
- 'post_id' => $post_id,
463
- 'field_id' => $cell['field_id'],
464
- 'value' => $cell['value'],
465
- 'order_no' => $i
 
466
  );
 
 
 
 
 
467
 
468
 
469
- // if there is an id, this value already exists, so save it in the same ID spot
470
- if($cell['row_id'])
 
471
  {
472
- $data['id'] = $cell['row_id'];
473
  }
 
 
 
 
 
474
 
475
 
476
- // insert new data
477
- $new_id = $wpdb->insert($table_name, $data);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
 
479
  }
480
  //foreach($row as $j => $cell)
@@ -484,6 +521,7 @@ class acf_Repeater
484
  //foreach($field['value'] as $i => $row)
485
  }
486
  //if($field['value'])
 
487
  }
488
 
489
  /*---------------------------------------------------------------------------------------------
@@ -496,19 +534,23 @@ class acf_Repeater
496
  ---------------------------------------------------------------------------------------------*/
497
  function load_value_for_input($post_id, $field)
498
  {
 
499
  $sub_fields = $field->options['sub_fields'];
500
  $values = array();
501
 
502
 
503
  // set table name
504
  global $wpdb;
505
- $table_name = $wpdb->prefix.'acf_values';
 
506
 
507
-
508
  foreach($sub_fields as $sub_field)
509
  {
510
  // get var
511
- $db_values = $wpdb->get_results("SELECT * FROM $table_name WHERE field_id = '$sub_field->id' AND post_id = '$post_id' ORDER BY order_no ASC");
 
 
512
 
513
  if($db_values)
514
  {
@@ -527,16 +569,31 @@ class acf_Repeater
527
  }
528
  else
529
  {
530
- // $values[0][$sub_field->name] = "";
531
  $value = new stdClass();
532
- $value->value = "";
533
- $values[0][$sub_field->order_no] = $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
534
  }
535
 
536
  }
 
537
 
538
  //print_r($values);
539
  return $values;
 
540
 
541
  }
542
 
@@ -551,10 +608,7 @@ class acf_Repeater
551
  ---------------------------------------------------------------------------------------------*/
552
  function load_value_for_api($post_id, $field)
553
  {
554
- //echo '<pre>';
555
- //print_r($field);
556
- //echo '</pre>';
557
- //die;
558
 
559
 
560
  $sub_fields = $field->options['sub_fields'];
@@ -565,7 +619,7 @@ class acf_Repeater
565
  global $wpdb;
566
  $table_name = $wpdb->prefix.'acf_values';
567
 
568
- if($sub_fields)
569
  {
570
  foreach($sub_fields as $sub_field)
571
  {
@@ -581,7 +635,7 @@ class acf_Repeater
581
  // format if needed
582
  if(method_exists($this->parent->fields[$sub_field->type], 'format_value_for_api'))
583
  {
584
- $value = $this->parent->fields[$sub_field->type]->format_value_for_api($value);
585
  }
586
 
587
  //echo 'db order no = '.$db_value->order_no;
31
  $layout = $field->options['layout'];
32
  }
33
 
 
 
 
34
  ?>
35
+ <div class="repeater" data-row_limit="<?php echo $row_limit; ?>">
 
36
  <table class="widefat <?php if($layout == 'row'): ?>row_layout<?php endif; ?>">
37
  <?php if($layout == 'table'): ?>
38
  <thead>
73
  <label><?php echo $sub_fields[$j]->label; ?></label>
74
  <?php endif; ?>
75
 
76
+ <input type="hidden" name="<?php echo $field->input_name.'['.$i.']['.$j.'][meta_id]'; ?>" value="<?php echo $field->value[$i][$j]->meta_id; ?>" />
77
+ <input type="hidden" name="<?php echo $field->input_name.'['.$i.']['.$j.'][value_id]'; ?>" value="<?php echo $field->value[$i][$j]->value_id; ?>" />
78
+
79
  <input type="hidden" name="<?php echo $field->input_name.'['.$i.']['.$j.'][field_id]'; ?>" value="<?php echo $sub_field->id; ?>" />
80
  <input type="hidden" name="<?php echo $field->input_name.'['.$i.']['.$j.'][field_type]' ?>" value="<?php echo $sub_field->type; ?>" />
81
 
126
  * @since 1.1
127
  *
128
  ---------------------------------------------------------------------------------------------*/
129
+ function options_html($key, $field)
130
  {
131
+ $options = $field->options;
132
+
133
  if(isset($options['sub_fields']))
134
  {
135
  $fields = $options['sub_fields'];
138
  {
139
  $fields = array();
140
  }
 
141
 
 
142
 
143
  // add clone
144
  $field = new stdClass();
164
  </td>
165
  <td>
166
  <div class="repeater">
167
+ <div class="fields_header">
168
+ <table class="acf widefat">
169
+ <thead>
170
+ <tr>
171
+ <th class="field_order"><?php _e('Field Order','acf'); ?></th>
172
+ <th class="field_label"><?php _e('Field Label','acf'); ?></th>
173
+ <th class="field_name"><?php _e('Field Name','acf'); ?></th>
174
+ <th class="field_type"><?php _e('Field Type','acf'); ?></th>
175
+ </tr>
176
+ </thead>
177
+ </table>
178
+ </div>
179
  <div class="fields">
180
 
181
  <div class="no_fields_message" <?php if(sizeof($fields) > 1){ echo 'style="display:none;"'; } ?>>
182
+ <?php _e("No fields. Click the \"+ Add Field button\" to create your first field.",'acf'); ?>
183
  </div>
184
 
185
 
187
  <div class="<?php if($key2 == 999){echo "field_clone";}else{echo "field";} ?> sub_field">
188
 
189
  <input type="hidden" name="acf[fields][<?php echo $key; ?>][sub_fields][<?php echo $key2; ?>][id]'" value="<?php echo $field->id; ?>" />
190
+
191
+ <div class="field_meta">
192
  <table class="acf widefat">
193
  <tr>
194
+ <td class="field_order"><span class="circle"><?php echo ($key2+1); ?></span></td>
195
  <td class="field_label">
196
  <strong>
197
  <a class="acf_edit_field" title="Edit this Field" href="javascript:;"><?php echo $field->label; ?></a>
205
  <td class="field_type"><?php echo $field->type; ?></td>
206
  </tr>
207
  </table>
208
+ </div>
209
 
210
  <div class="field_form_mask">
211
  <div class="field_form">
270
  <?php foreach($fields_names as $field_name => $field_title): ?>
271
  <?php if(method_exists($this->parent->fields[$field_name], 'options_html')): ?>
272
 
273
+ <?php $this->parent->fields[$field_name]->options_html($key.'][sub_fields]['.$key2, $field); ?>
274
 
275
  <?php endif; ?>
276
  <?php endforeach; ?>
352
  global $wpdb;
353
  $table_name = $wpdb->prefix.'acf_fields';
354
 
355
+
 
 
 
356
  if($field['sub_fields'])
357
  {
358
  foreach($field['sub_fields'] as $key => $field)
362
  continue;
363
  }
364
 
365
+
366
  // defaults
367
  if(!isset($field['label'])) { $field['label'] = ""; }
368
  if(!isset($field['name'])) { $field['label'] = ""; }
369
  if(!isset($field['type'])) { $field['label'] = "text"; }
370
  if(!isset($field['options'])) { $field['options'] = array(); }
371
+ if(!isset($field['instructions'])) { $field['instructions'] = ""; }
372
+ if(!isset($field['default_value'])) { $field['default_value'] = ""; }
373
+
374
+
375
+ // clean field
376
+ $field = stripslashes_deep($field);
377
 
378
 
379
  // format options if needed
391
  'label' => $field['label'],
392
  'name' => $field['name'],
393
  'type' => $field['type'],
394
+ 'default_value' => $field['default_value'],
395
  'options' => serialize($field['options']),
396
 
397
  );
404
  // if there is an id, this field already exists, so save it in the same ID spot
405
  if($field['id'])
406
  {
407
+ $data['id'] = (int) $field['id'];
408
  }
409
 
410
 
430
  ---------------------------------------------------------------------------------------------*/
431
  function save_input($post_id, $field)
432
  {
 
 
433
 
434
  // set table name
435
  global $wpdb;
436
+ $acf_values = $wpdb->prefix.'acf_values';
437
+ $wp_postmeta = $wpdb->prefix.'postmeta';
438
 
439
 
440
  $field = stripslashes_deep( $field );
449
  foreach($row as $j => $cell)
450
  {
451
 
452
+
453
  // if select is a multiple (multiple select value), you need to save it as an array!
454
  if(isset($cell['value']) && $cell['value'] != "")
455
  {
460
  }
461
  else
462
  {
463
+ $cell['value'] = "";
464
+ //continue;
465
  }
 
466
 
467
+
468
+ // create data: wp_postmeta
469
+ $data1 = array(
470
+ 'post_id' => (int) $post_id,
471
+ //'meta_key' => $field['field_name'] . '_' . $i . '_' . $j,
472
+ 'meta_key' => $field['field_name'],
473
+ 'meta_value' => $cell['value']
474
  );
475
+ if(isset($cell['meta_id']) && $cell['meta_id'] != "")
476
+ {
477
+ $data1['meta_id'] = (int) $cell['meta_id'];
478
+ }
479
+
480
 
481
 
482
+ // get the new id
483
+ $wpdb->insert($wp_postmeta, $data1);
484
+ if(isset($cell['meta_id']) && $cell['meta_id'] != "")
485
  {
486
+ $new_id = $cell['meta_id'];
487
  }
488
+ else
489
+ {
490
+ $new_id = $wpdb->insert_id;
491
+ }
492
+
493
 
494
 
495
+ // create data: acf_values
496
+ if($new_id && $new_id != 0)
497
+ {
498
+
499
+ $data2 = array(
500
+ 'field_id' => $field['field_id'],
501
+ 'sub_field_id' => (int) $cell['field_id'],
502
+ 'value' => $new_id,
503
+ 'order_no' => $i,
504
+ );
505
+ if(isset($cell['value_id']) && $cell['value_id'] != "")
506
+ {
507
+ $data2['id'] = (int) $cell['value_id'];
508
+ }
509
+
510
+
511
+ $wpdb->insert($acf_values, $data2);
512
+
513
+ }
514
+
515
 
516
  }
517
  //foreach($row as $j => $cell)
521
  //foreach($field['value'] as $i => $row)
522
  }
523
  //if($field['value'])
524
+
525
  }
526
 
527
  /*---------------------------------------------------------------------------------------------
534
  ---------------------------------------------------------------------------------------------*/
535
  function load_value_for_input($post_id, $field)
536
  {
537
+
538
  $sub_fields = $field->options['sub_fields'];
539
  $values = array();
540
 
541
 
542
  // set table name
543
  global $wpdb;
544
+ $acf_values = $wpdb->prefix.'acf_values';
545
+ $wp_postmeta = $wpdb->prefix.'postmeta';
546
 
547
+
548
  foreach($sub_fields as $sub_field)
549
  {
550
  // get var
551
+ $db_values = $wpdb->get_results("SELECT m.meta_id, m.meta_value as value, v.order_no, v.id as value_id FROM $wp_postmeta m LEFT JOIN $acf_values v ON m.meta_id = v.value WHERE v.sub_field_id = '$sub_field->id' AND m.post_id = '$post_id' ORDER BY v.order_no ASC");
552
+
553
+ //$db_values = $wpdb->get_results("SELECT * FROM $table_name WHERE field_id = '$sub_field->id' AND post_id = '$post_id' ORDER BY order_no ASC");
554
 
555
  if($db_values)
556
  {
569
  }
570
  else
571
  {
 
572
  $value = new stdClass();
573
+ $value->value = false;
574
+
575
+
576
+ // override with default value
577
+ if($post_id != 0)
578
+ {
579
+ $post_meta = get_post_custom($post_id);
580
+ if(empty($post_meta) && isset($sub_field->default_value) && !empty($sub_field->default_value))
581
+ {
582
+ $value->value = $sub_field->default_value;
583
+ }
584
+
585
+ }
586
+
587
+ $values[0][$sub_field->order_no] = $value;
588
+
589
  }
590
 
591
  }
592
+
593
 
594
  //print_r($values);
595
  return $values;
596
+
597
 
598
  }
599
 
608
  ---------------------------------------------------------------------------------------------*/
609
  function load_value_for_api($post_id, $field)
610
  {
611
+ // get sub fields
 
 
 
612
 
613
 
614
  $sub_fields = $field->options['sub_fields'];
619
  global $wpdb;
620
  $table_name = $wpdb->prefix.'acf_values';
621
 
622
+ if(is_array($sub_fields) && count($sub_fields) > 0)
623
  {
624
  foreach($sub_fields as $sub_field)
625
  {
635
  // format if needed
636
  if(method_exists($this->parent->fields[$sub_field->type], 'format_value_for_api'))
637
  {
638
+ $value = $this->parent->fields[$sub_field->type]->format_value_for_api($value, $sub_field->options);
639
  }
640
 
641
  //echo 'db order no = '.$db_value->order_no;
core/fields/select.php CHANGED
@@ -28,9 +28,20 @@ class acf_Select
28
  {
29
  echo '<select id="'.$field->input_name.'" class="'.$field->input_class.'" name="'.$field->input_name.'" >';
30
  // add top option
31
- //echo '<option value="null">- Select Option -</option>';
 
 
 
 
 
32
  }
33
 
 
 
 
 
 
 
34
 
35
  // loop through values and add them as options
36
  foreach($field->options['choices'] as $key => $value)
@@ -61,8 +72,10 @@ class acf_Select
61
  }
62
 
63
 
64
- function options_html($key, $options)
65
  {
 
 
66
  // implode selects so they work in a textarea
67
  if(isset($options['choices']) && is_array($options['choices']))
68
  {
@@ -77,10 +90,8 @@ class acf_Select
77
  $options['choices'] = "";
78
  }
79
 
80
- if(!isset($options['multiple']))
81
- {
82
- $options['multiple'] = '0';
83
- }
84
 
85
  ?>
86
 
@@ -104,16 +115,31 @@ class acf_Select
104
  </tr>
105
  <tr class="field_option field_option_select">
106
  <td class="label">
107
- <label><?php _e("Select multiple values?",'acf'); ?></label>
108
  </td>
109
  <td>
110
  <?php
111
  $temp_field = new stdClass();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  $temp_field->type = 'true_false';
113
  $temp_field->input_name = 'acf[fields]['.$key.'][options][multiple]';
114
  $temp_field->input_class = '';
115
  $temp_field->value = $options['multiple'];
116
- $temp_field->options = array('message' => '');
117
  $this->parent->create_field($temp_field);
118
  ?>
119
  </td>
@@ -185,9 +211,16 @@ class acf_Select
185
  * @since 1.1
186
  *
187
  ---------------------------------------------------------------------------------------------*/
188
- function format_value_for_api($value)
189
  {
190
- return $this->format_value_for_input($value);
 
 
 
 
 
 
 
191
  }
192
 
193
 
28
  {
29
  echo '<select id="'.$field->input_name.'" class="'.$field->input_class.'" name="'.$field->input_name.'" >';
30
  // add top option
31
+
32
+ if(isset($field->options['allow_null']) && $field->options['allow_null'] == '1')
33
+ {
34
+ echo '<option value="null"> - Select - </option>';
35
+ }
36
+
37
  }
38
 
39
+ if(empty($field->options['choices']))
40
+ {
41
+
42
+ echo '<p>' . __("No choices to choose from",'acf') . '</p>';
43
+ return false;
44
+ }
45
 
46
  // loop through values and add them as options
47
  foreach($field->options['choices'] as $key => $value)
72
  }
73
 
74
 
75
+ function options_html($key, $field)
76
  {
77
+ $options = $field->options;
78
+
79
  // implode selects so they work in a textarea
80
  if(isset($options['choices']) && is_array($options['choices']))
81
  {
90
  $options['choices'] = "";
91
  }
92
 
93
+ $options['multiple'] = isset($options['multiple']) ? $options['multiple'] : '0';
94
+ $options['allow_null'] = isset($options['allow_null']) ? $options['allow_null'] : '0';
 
 
95
 
96
  ?>
97
 
115
  </tr>
116
  <tr class="field_option field_option_select">
117
  <td class="label">
118
+ <label><?php _e("Allow Null?",'acf'); ?></label>
119
  </td>
120
  <td>
121
  <?php
122
  $temp_field = new stdClass();
123
+ $temp_field->type = 'true_false';
124
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][allow_null]';
125
+ $temp_field->input_class = '';
126
+ $temp_field->value = $options['allow_null'];
127
+ $temp_field->options = array('message' => 'Add null value above choices');
128
+ $this->parent->create_field($temp_field);
129
+ ?>
130
+ </td>
131
+ </tr>
132
+ <tr class="field_option field_option_select">
133
+ <td class="label">
134
+ <label><?php _e("Select multiple values?",'acf'); ?></label>
135
+ </td>
136
+ <td>
137
+ <?php
138
  $temp_field->type = 'true_false';
139
  $temp_field->input_name = 'acf[fields]['.$key.'][options][multiple]';
140
  $temp_field->input_class = '';
141
  $temp_field->value = $options['multiple'];
142
+ $temp_field->options = array('message' => 'Turn this drop-down into a multi-select');
143
  $this->parent->create_field($temp_field);
144
  ?>
145
  </td>
211
  * @since 1.1
212
  *
213
  ---------------------------------------------------------------------------------------------*/
214
+ function format_value_for_api($value, $options = null)
215
  {
216
+ $value = $this->format_value_for_input($value);
217
+
218
+ if($value == 'null')
219
+ {
220
+ return false;
221
+ }
222
+
223
+ return $value;
224
  }
225
 
226
 
core/fields/text.php CHANGED
@@ -4,11 +4,13 @@ class acf_Text
4
  {
5
  var $name;
6
  var $title;
 
7
 
8
- function acf_Text()
9
  {
10
  $this->name = 'text';
11
  $this->title = __("Text",'acf');
 
12
  }
13
 
14
  function html($field)
@@ -16,6 +18,38 @@ class acf_Text
16
  echo '<input type="text" value="'.$field->value.'" id="'.$field->input_name.'" class="'.$field->input_class.'" name="'.$field->input_name.'" />';
17
  }
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  function format_value_for_input($value)
20
  {
21
  return htmlspecialchars($value, ENT_QUOTES);
4
  {
5
  var $name;
6
  var $title;
7
+ var $parent;
8
 
9
+ function acf_Text($parent)
10
  {
11
  $this->name = 'text';
12
  $this->title = __("Text",'acf');
13
+ $this->parent = $parent;
14
  }
15
 
16
  function html($field)
18
  echo '<input type="text" value="'.$field->value.'" id="'.$field->input_name.'" class="'.$field->input_class.'" name="'.$field->input_name.'" />';
19
  }
20
 
21
+
22
+ /*--------------------------------------------------------------------------------------
23
+ *
24
+ * Options HTML
25
+ *
26
+ * @author Elliot Condon
27
+ * @since 2.0.6
28
+ *
29
+ *-------------------------------------------------------------------------------------*/
30
+
31
+ function options_html($key, $field)
32
+ {
33
+ ?>
34
+ <tr class="field_option field_option_text">
35
+ <td class="label">
36
+ <label><?php _e("Default Value",'acf'); ?></label>
37
+ </td>
38
+ <td>
39
+ <?php
40
+ $temp_field = new stdClass();
41
+ $temp_field->type = 'text';
42
+ $temp_field->input_name = 'acf[fields]['.$key.'][default_value]';
43
+ $temp_field->input_class = 'default_value';
44
+ $temp_field->value = $field->default_value;
45
+ $this->parent->create_field($temp_field);
46
+ ?>
47
+ </td>
48
+ </tr>
49
+ <?php
50
+ }
51
+
52
+
53
  function format_value_for_input($value)
54
  {
55
  return htmlspecialchars($value, ENT_QUOTES);
core/fields/textarea.php CHANGED
@@ -4,11 +4,13 @@ class acf_Textarea
4
  {
5
  var $name;
6
  var $title;
 
7
 
8
- function acf_Textarea()
9
  {
10
  $this->name = 'textarea';
11
  $this->title = __("Text Area",'acf');
 
12
  }
13
 
14
  function html($field)
@@ -18,13 +20,45 @@ class acf_Textarea
18
  echo '<textarea id="'.$field->input_name.'" rows="4" class="'.$field->input_class.'" name="'.$field->input_name.'" >'.$field->value.'</textarea>';
19
  }
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  function format_value_for_input($value)
22
  {
23
  $value = htmlspecialchars($value, ENT_QUOTES);
24
  return $value;
25
  }
26
 
27
- function format_value_for_api($value)
28
  {
29
  $value = nl2br($value);
30
  return $value;
4
  {
5
  var $name;
6
  var $title;
7
+ var $parent;
8
 
9
+ function acf_Textarea($parent)
10
  {
11
  $this->name = 'textarea';
12
  $this->title = __("Text Area",'acf');
13
+ $this->parent = $parent;
14
  }
15
 
16
  function html($field)
20
  echo '<textarea id="'.$field->input_name.'" rows="4" class="'.$field->input_class.'" name="'.$field->input_name.'" >'.$field->value.'</textarea>';
21
  }
22
 
23
+
24
+ /*--------------------------------------------------------------------------------------
25
+ *
26
+ * Options HTML
27
+ *
28
+ * @author Elliot Condon
29
+ * @since 2.0.6
30
+ *
31
+ *-------------------------------------------------------------------------------------*/
32
+
33
+ function options_html($key, $field)
34
+ {
35
+
36
+ ?>
37
+ <tr class="field_option field_option_textarea">
38
+ <td class="label">
39
+ <label><?php _e("Default Value",'acf'); ?></label>
40
+ </td>
41
+ <td>
42
+ <?php
43
+ $temp_field = new stdClass();
44
+ $temp_field->type = 'textarea';
45
+ $temp_field->input_name = 'acf[fields]['.$key.'][default_value]';
46
+ $temp_field->input_class = 'default_value';
47
+ $temp_field->value = $field->default_value;
48
+ $this->parent->create_field($temp_field);
49
+ ?>
50
+ </td>
51
+ </tr>
52
+ <?php
53
+ }
54
+
55
  function format_value_for_input($value)
56
  {
57
  $value = htmlspecialchars($value, ENT_QUOTES);
58
  return $value;
59
  }
60
 
61
+ function format_value_for_api($value, $options = null)
62
  {
63
  $value = nl2br($value);
64
  return $value;
core/fields/true_false.php CHANGED
@@ -34,7 +34,7 @@ class acf_True_false
34
  {
35
  $selected = 'checked="yes"';
36
  }
37
- echo '<li><input type="checkbox" class="'.$field->input_class.'" name="'.$field->input_name.'" value="'.$key.'" '.$selected.' />'.$value.'</li>';
38
  }
39
 
40
  echo '</ul>';
@@ -51,8 +51,10 @@ class acf_True_false
51
  * @since 1.1
52
  *
53
  ---------------------------------------------------------------------------------------------*/
54
- function options_html($key, $options)
55
  {
 
 
56
  if(!isset($options['message']))
57
  {
58
  $options['message'] = "";
@@ -82,7 +84,7 @@ class acf_True_false
82
  * @since 1.1
83
  *
84
  ---------------------------------------------------------------------------------------------*/
85
- function format_value_for_api($value)
86
  {
87
  return $this->format_value_for_input($value);
88
  }
34
  {
35
  $selected = 'checked="yes"';
36
  }
37
+ echo '<li><label><input type="checkbox" class="'.$field->input_class.'" name="'.$field->input_name.'" value="'.$key.'" '.$selected.' />'.$value.'</label></li>';
38
  }
39
 
40
  echo '</ul>';
51
  * @since 1.1
52
  *
53
  ---------------------------------------------------------------------------------------------*/
54
+ function options_html($key, $field)
55
  {
56
+ $options = $field->options;
57
+
58
  if(!isset($options['message']))
59
  {
60
  $options['message'] = "";
84
  * @since 1.1
85
  *
86
  ---------------------------------------------------------------------------------------------*/
87
+ function format_value_for_api($value, $options = null)
88
  {
89
  return $this->format_value_for_input($value);
90
  }
core/fields/wysiwyg.php CHANGED
@@ -18,7 +18,7 @@ class acf_Wysiwyg
18
  echo '</textarea></div>';
19
  }
20
 
21
- function format_value_for_api($value)
22
  {
23
  $value = apply_filters('the_content',$value);
24
  return $value;
18
  echo '</textarea></div>';
19
  }
20
 
21
+ function format_value_for_api($value, $options = null)
22
  {
23
  $value = apply_filters('the_content',$value);
24
  return $value;
core/import.php CHANGED
@@ -85,12 +85,12 @@ foreach($posts as $post)
85
  $i++;
86
 
87
  $post_field = array(
88
- 'label' => the_xml_value($field->label),
89
- 'name' => the_xml_value($field->name),
90
- 'type' => the_xml_value($field->type),
 
91
  'options' => array(),
92
- 'instructions' => the_xml_value($field->instructions),
93
- 'save_as_cf' => the_xml_value($field->save_as_cf),
94
  );
95
 
96
  if($field->options[0]->children())
@@ -107,9 +107,10 @@ foreach($posts as $post)
107
  $j++;
108
 
109
  $post_sub_field = array(
110
- 'label' => the_xml_value($sub_field->label),
111
- 'name' => the_xml_value($sub_field->name),
112
- 'type' => the_xml_value($sub_field->type),
 
113
  'options' => array(),
114
  );
115
 
85
  $i++;
86
 
87
  $post_field = array(
88
+ 'label' => isset($field->label) ? the_xml_value($field->label) : '',
89
+ 'name' => isset($field->name) ? the_xml_value($field->name) : '',
90
+ 'type' => isset($field->type) ? the_xml_value($field->type) : '',
91
+ 'default_value' => isset($field->default_value) ? the_xml_value($field->default_value) : '',
92
  'options' => array(),
93
+ 'instructions' => isset($field->instructions) ? the_xml_value($field->instructions) : '',
 
94
  );
95
 
96
  if($field->options[0]->children())
107
  $j++;
108
 
109
  $post_sub_field = array(
110
+ 'label' => isset($sub_field->label) ? the_xml_value($sub_field->label) : '',
111
+ 'name' => isset($sub_field->name) ? the_xml_value($sub_field->name) : '',
112
+ 'type' => isset($sub_field->type) ? the_xml_value($sub_field->type) : '',
113
+ 'default_value' => isset($sub_field->default_value) ? the_xml_value($sub_field->default_value) : '',
114
  'options' => array(),
115
  );
116
 
core/input_meta_box.php DELETED
@@ -1,145 +0,0 @@
1
- <?php
2
-
3
- /*---------------------------------------------------------------------------------------------
4
- Input Meta Box
5
- ---------------------------------------------------------------------------------------------*/
6
-
7
-
8
- // vars
9
- global $post;
10
- $acfs = $args['args']['acfs'];
11
- $adv_options = $this->get_acf_options($acfs[0]->ID);
12
-
13
-
14
-
15
-
16
-
17
- $fields = array();
18
-
19
- foreach($acfs as $acf)
20
- {
21
- // get this acf's fields and add them to the global $fields
22
- $this_fields = $this->get_fields($acf->ID);
23
- foreach($this_fields as $this_field)
24
- {
25
- $fields[] = $this_field;
26
- }
27
-
28
- }
29
-
30
- ?>
31
-
32
-
33
- <input type="hidden" name="ei_noncename" id="ei_noncename" value="<?php echo wp_create_nonce('ei-n'); ?>" />
34
- <input type="hidden" name="input_meta_box" value="true" />
35
-
36
-
37
- <style type="text/css">
38
- <?php if(!in_array('the_content',$adv_options->show_on_page)): ?>
39
- #postdivrich {display: none;}
40
- <?php endif; ?>
41
-
42
- <?php if(!in_array('custom_fields',$adv_options->show_on_page)): ?>
43
- #postcustom,
44
- #screen-meta label[for=postcustom-hide] {display: none;}
45
- <?php endif; ?>
46
-
47
- <?php if(!in_array('discussion',$adv_options->show_on_page)): ?>
48
- #commentstatusdiv,
49
- #screen-meta label[for=commentstatusdiv-hide] {display: none;}
50
- <?php endif; ?>
51
-
52
- <?php if(!in_array('comments',$adv_options->show_on_page)): ?>
53
- #commentsdiv,
54
- #screen-meta label[for=commentsdiv-hide] {display: none;}
55
- <?php endif; ?>
56
-
57
- <?php if(!in_array('slug',$adv_options->show_on_page)): ?>
58
- #slugdiv,
59
- #screen-meta label[for=slugdiv-hide] {display: none;}
60
- <?php endif; ?>
61
-
62
- <?php if(!in_array('author',$adv_options->show_on_page)): ?>
63
- #authordiv,
64
- #screen-meta label[for=authordiv-hide] {display: none;}
65
- <?php endif; ?>
66
-
67
- #screen-meta label[for=acf_input-hide] {display: none;}
68
- </style>
69
-
70
-
71
- <div class="acf_fields_input">
72
-
73
- <?php
74
-
75
- $i = 0;
76
- foreach($acfs as $acf)
77
- {
78
-
79
- // load acf data
80
- $options = $this->get_acf_options($acf->ID);
81
- $fields = $this->get_fields($acf->ID);
82
- $html = '';
83
-
84
-
85
- if($options->field_group_layout == "in_box")
86
- {
87
- echo '<div class="postbox"><div title="Click to toggle" class="handlediv"><br></div><h3 class="hndle"><span>'.$acf->post_title.'</span></h3><div class="inside">';
88
- }
89
-
90
-
91
- foreach($fields as $field)
92
- {
93
-
94
- // if they didn't select a type, skip this field
95
- if($field->type == 'null')
96
- {
97
- continue;
98
- }
99
-
100
-
101
- // set value, id and name for field
102
- $field->value_id = $this->load_value_id_input($post->ID, $field);
103
- $field->value = $this->load_value_for_input($post->ID, $field);
104
- $field->input_name = 'acf['.$i.'][value]';
105
- $field->input_class = '';
106
-
107
-
108
- echo '<div class="field">';
109
-
110
- echo '<input type="hidden" name="acf['.$i.'][field_id]" value="'.$field->id.'" />';
111
- echo '<input type="hidden" name="acf['.$i.'][field_type]" value="'.$field->type.'" />';
112
- echo '<input type="hidden" name="acf['.$i.'][value_id]" value="'.$field->value_id.'" />';
113
-
114
- if($field->save_as_cf == 1)
115
- {
116
- echo '<input type="hidden" name="acf['.$i.'][save_as_cf]" value="'.$field->name.'" />';
117
- }
118
-
119
-
120
- echo '<label for="'.$field->input_name.'">'.$field->label.'</label>';
121
-
122
-
123
- if($field->instructions)
124
- {
125
- echo '<p class="instructions">'.$field->instructions.'</p>';
126
- }
127
-
128
-
129
- $this->create_field($field);
130
-
131
- echo '</div>';
132
-
133
- $i++;
134
- }
135
-
136
-
137
- if($options->field_group_layout == "in_box")
138
- {
139
- echo '</div></div>';
140
- }
141
- }
142
-
143
- ?>
144
-
145
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/input_save.php DELETED
@@ -1,78 +0,0 @@
1
- <?php
2
- /*---------------------------------------------------------------------------------------------
3
- Fields Meta Box
4
- ---------------------------------------------------------------------------------------------*/
5
- if(isset($_POST['input_meta_box']) && $_POST['input_meta_box'] == 'true')
6
- {
7
-
8
- // If acf was not posted, don't go any further
9
- if(!isset($_POST['acf']))
10
- {
11
- return true;
12
- }
13
-
14
-
15
- // set table name
16
- global $wpdb;
17
- $table_name = $wpdb->prefix.'acf_values';
18
-
19
- // remove all old values from the database
20
- $wpdb->query("DELETE FROM $table_name WHERE post_id = '$post_id'");
21
-
22
- foreach($_POST['acf'] as $field)
23
- {
24
- if(method_exists($this->fields[$field['field_type']], 'save_input'))
25
- {
26
- $this->fields[$field['field_type']]->save_input($post_id, $field);
27
- }
28
- else
29
- {
30
- //$field = apply_filters('wp_insert_post_data', $field);
31
- $field = stripslashes_deep( $field );
32
-
33
-
34
- // if select is a multiple (multiple select value), you need to save it as an array!
35
- if(is_array($field['value']))
36
- {
37
- $field['value'] = serialize($field['value']);
38
- }
39
-
40
-
41
- // create data object to save
42
- $data = array(
43
- 'post_id' => $post_id,
44
- 'field_id' => $field['field_id'],
45
- 'value' => $field['value']
46
- );
47
-
48
- // if there is an id, this value already exists, so save it in the same ID spot
49
- if($field['value_id'])
50
- {
51
- $data['id'] = $field['value_id'];
52
- }
53
-
54
-
55
- // insert new data
56
- $new_id = $wpdb->insert($table_name, $data);
57
- }
58
-
59
-
60
-
61
- // save as standard cf
62
- if(isset($field['save_as_cf']))
63
- {
64
- if(is_array($field['value']))
65
- {
66
- $field['value'] = serialize($field['value']);
67
- }
68
-
69
- update_post_meta($post_id, $field['save_as_cf'], $field['value']);
70
- }
71
-
72
-
73
- }
74
-
75
-
76
- }
77
-
78
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/screen_extra.php CHANGED
@@ -26,11 +26,11 @@ if($currentFile == 'edit.php'):
26
  <p><?php _e("Watch tutorials, read documentation, learn the API code and find some tips &amp; tricks for your next web project.",'acf'); ?><br />
27
  <a href="http://plugins.elliotcondon.com/advanced-custom-fields/"><?php _e("View the plugins website",'acf'); ?></a></p>
28
  </div>
29
- <div class="field">
30
  <h4><?php _e("Support",'acf'); ?></h4>
31
  <p><?php _e("Join the growing community over at the support forum to share ideas, report bugs and keep up to date with ACF",'acf'); ?><br />
32
  <a href="http://support.plugins.elliotcondon.com/categories/advanced-custom-fields/"><?php _e("View the Support Forum",'acf'); ?></a></p>
33
- </div>
34
  <div class="field">
35
  <h4><?php _e("Developed by",'acf'); ?> Elliot Condon</h4>
36
  <p><a href="http://wordpress.org/extend/plugins/advanced-custom-fields/"><?php _e("Vote for ACF",'acf'); ?></a> | <a href="http://twitter.com/elliotcondon"><?php _e("Twitter",'acf'); ?></a> | <a href="http://blog.elliotcondon.com"><?php _e("Blog",'acf'); ?></a></p>
26
  <p><?php _e("Watch tutorials, read documentation, learn the API code and find some tips &amp; tricks for your next web project.",'acf'); ?><br />
27
  <a href="http://plugins.elliotcondon.com/advanced-custom-fields/"><?php _e("View the plugins website",'acf'); ?></a></p>
28
  </div>
29
+ <!-- <div class="field">
30
  <h4><?php _e("Support",'acf'); ?></h4>
31
  <p><?php _e("Join the growing community over at the support forum to share ideas, report bugs and keep up to date with ACF",'acf'); ?><br />
32
  <a href="http://support.plugins.elliotcondon.com/categories/advanced-custom-fields/"><?php _e("View the Support Forum",'acf'); ?></a></p>
33
+ </div> -->
34
  <div class="field">
35
  <h4><?php _e("Developed by",'acf'); ?> Elliot Condon</h4>
36
  <p><a href="http://wordpress.org/extend/plugins/advanced-custom-fields/"><?php _e("Vote for ACF",'acf'); ?></a> | <a href="http://twitter.com/elliotcondon"><?php _e("Twitter",'acf'); ?></a> | <a href="http://blog.elliotcondon.com"><?php _e("Blog",'acf'); ?></a></p>
core/third_party.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*--------------------------------------------------------------------------------------
4
+ *
5
+ * Integrate with Duplicate Posts plugin
6
+ *
7
+ * @author unknownnf - thanks mate
8
+ * @since 2.0.6
9
+ *
10
+ *-------------------------------------------------------------------------------------*/
11
+ function acf_duplicate($newId, $post)
12
+ {
13
+
14
+ // tables
15
+ global $wpdb;
16
+ $acf_values = $wpdb->prefix.'acf_values';
17
+ $wp_postmeta = $wpdb->prefix.'postmeta';
18
+
19
+
20
+ // get rows
21
+ $sql = "SELECT m.meta_key, m.meta_value, v.value, v.field_id, v.sub_field_id, v.order_no
22
+ FROM $wp_postmeta m LEFT JOIN $acf_values v ON m.meta_id = v.value
23
+ WHERE m.post_id = '$post->ID'";
24
+
25
+ $rows = $wpdb->get_results($sql);
26
+
27
+ foreach ($rows as $row) {
28
+
29
+ // save postmeta
30
+ $data = array(
31
+ 'post_id' => $newId,
32
+ 'meta_key' => $row->meta_key,
33
+ 'meta_value' => $row->meta_value,
34
+ );
35
+
36
+ $wpdb->insert($wp_postmeta, $data);
37
+
38
+ $new_value_id = $wpdb->insert_id;
39
+
40
+ if($new_value_id && $new_value_id != 0)
41
+ {
42
+ // create data object to save
43
+ $data2 = array(
44
+ 'post_id' => $newId,
45
+ 'order_no' => $row->order_no,
46
+ 'field_id' => $row->field_id,
47
+ 'sub_field_id' => $row->sub_field_id,
48
+ 'value' => $new_value_id,
49
+ );
50
+
51
+ $wpdb->insert($acf_values, $data2);
52
+ }
53
+
54
+ }
55
+
56
+ }
57
+
58
+ add_action('dp_duplicate_page', 'acf_duplicate', 10, 2);
59
+ add_action('dp_duplicate_post', 'acf_duplicate', 10, 2);
60
+
61
+ ?>
core/update.php DELETED
@@ -1,593 +0,0 @@
1
- <?php
2
-
3
- $version = get_option('acf_version','1.0.5');
4
-
5
-
6
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
7
-
8
-
9
- /*---------------------------------------------------------------------------------------------
10
- * Update to 1.1.0 - this version needs tables!
11
- *
12
- * @author Elliot Condon
13
- * @since 1.0.6
14
- *
15
- ---------------------------------------------------------------------------------------------*/
16
- if(version_compare($version,'1.1.0') < 0)
17
- {
18
- // Version is less than 1.1.0
19
-
20
- global $wpdb;
21
-
22
-
23
- // set charset
24
- if ($wpdb->has_cap('collation'))
25
- {
26
- if(!empty($wpdb->charset))
27
- {
28
- $charset_collate = " DEFAULT CHARACTER SET $wpdb->charset";
29
- }
30
- if(!empty($wpdb->collate))
31
- {
32
- $charset_collate .= " COLLATE $wpdb->collate";
33
-
34
- }
35
- }
36
-
37
-
38
- // create acf_fields table
39
- $table_name = $wpdb->prefix.'acf_fields';
40
- if(!$wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
41
- {
42
- $sql = "CREATE TABLE " . $table_name . " (
43
- id bigint(20) NOT NULL AUTO_INCREMENT,
44
- order_no int(9) NOT NULL DEFAULT '0',
45
- post_id bigint(20) NOT NULL DEFAULT '0',
46
- parent_id bigint(20) NOT NULL DEFAULT '0',
47
- label text NOT NULL,
48
- name text NOT NULL,
49
- type text NOT NULL,
50
- options text NOT NULL,
51
- UNIQUE KEY id (id)
52
- ) ".$charset_collate.";";
53
- dbDelta($sql);
54
- }
55
-
56
-
57
- // create acf_options table
58
- $table_name = $wpdb->prefix.'acf_options';
59
- if(!$wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
60
- {
61
- $sql = "CREATE TABLE " . $table_name . " (
62
- id bigint(20) NOT NULL AUTO_INCREMENT,
63
- acf_id bigint(20) NOT NULL DEFAULT '0',
64
- name text NOT NULL,
65
- value text NOT NULL,
66
- type text NOT NULL,
67
- UNIQUE KEY id (id)
68
- ) ".$charset_collate.";";
69
- dbDelta($sql);
70
- }
71
-
72
-
73
- // create acf_options table
74
- $table_name = $wpdb->prefix.'acf_values';
75
- if(!$wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
76
- {
77
- $sql = "CREATE TABLE " . $table_name . " (
78
- id bigint(20) NOT NULL AUTO_INCREMENT,
79
- order_no int(9) NOT NULL DEFAULT '0',
80
- field_id bigint(20) NOT NULL DEFAULT '0',
81
- value text NOT NULL,
82
- post_id bigint(20) NOT NULL DEFAULT '0',
83
- UNIQUE KEY id (id)
84
- ) ".$charset_collate.";";
85
- dbDelta($sql);
86
- }
87
-
88
-
89
-
90
- $acfs = get_posts(array(
91
- 'numberposts' => -1,
92
- 'post_type' => 'acf',
93
- ));
94
-
95
-
96
- if($acfs)
97
- {
98
- foreach($acfs as $acf)
99
- {
100
- $keys = get_post_custom_keys($acf->ID);
101
-
102
- if(empty($keys)){continue;}
103
-
104
-
105
- // FIELDS
106
- $table_name = $wpdb->prefix.'acf_fields';
107
-
108
-
109
- for($i = 0; $i < 99; $i++)
110
- {
111
- if(in_array('_acf_field_'.$i.'_label',$keys))
112
- {
113
- $field = array(
114
- 'label' => get_post_meta($acf->ID, '_acf_field_'.$i.'_label', true),
115
- 'name' => get_post_meta($acf->ID, '_acf_field_'.$i.'_name', true),
116
- 'type' => get_post_meta($acf->ID, '_acf_field_'.$i.'_type', true),
117
- 'options' => unserialize(get_post_meta($acf->ID, '_acf_field_'.$i.'_options', true)) // explode choices!
118
- );
119
-
120
- // if choices, exlode them
121
- if($field['options']['choices'])
122
- {
123
- // explode choices from each line
124
- if(strpos($field['options']['choices'], "\n") !== false)
125
- {
126
- // found multiple lines, explode it
127
- $field['options']['choices'] = explode("\n", $field['options']['choices']);
128
- }
129
- else
130
- {
131
- // no multiple lines!
132
- $field['options']['choices'] = array($field['options']['choices']);
133
- }
134
-
135
- $new_choices = array();
136
- foreach($field['options']['choices'] as $choice)
137
- {
138
- $new_choices[trim($choice)] = trim($choice);
139
- }
140
-
141
-
142
- // return array containing all choices
143
- $field['options']['choices'] = $new_choices;
144
-
145
- }
146
-
147
- // now save field to database
148
- $data = array(
149
- 'order_no' => $i,
150
- 'post_id' => $acf->ID,
151
- 'label' => $field['label'],
152
- 'name' => $field['name'],
153
- 'type' => $field['type'],
154
- 'options' => serialize($field['options']),
155
-
156
- );
157
-
158
-
159
- // save field as row in database
160
-
161
- $new_id = $wpdb->insert($table_name, $data);
162
- }
163
- else
164
- {
165
- // data doesnt exist, break loop
166
- break;
167
- }
168
- }
169
-
170
-
171
- // START LOCATION
172
- $table_name = $wpdb->prefix.'acf_options';
173
- //$wpdb->query("DELETE FROM $table_name WHERE acf_id = '$acf->ID' AND type = 'location'");
174
-
175
- $location = array(
176
- 'post_types' => get_post_meta($acf->ID, '_acf_location_post_type', true),
177
- 'page_slugs' => get_post_meta($acf->ID, '_acf_location_page_slug', true),
178
- 'post_ids' => get_post_meta($acf->ID, '_acf_location_post_id', true),
179
- 'page_templates' => get_post_meta($acf->ID, '_acf_location_page_template', true),
180
- 'parent_ids' => get_post_meta($acf->ID, '_acf_location_parent_id', true),
181
- 'ignore_other_acfs' => get_post_meta($acf->ID, '_acf_location_ignore_other_acf', true),
182
- );
183
-
184
- foreach($location as $key => $value)
185
- {
186
- if(empty($value))
187
- {
188
- continue;
189
- }
190
-
191
- if(strpos($value, ',') !== false)
192
- {
193
- // found ',', explode it
194
- $value = str_replace(', ',',',$value);
195
- $value = explode(',', $value);
196
- }
197
- else
198
- {
199
- // no ','!
200
- $value = array($value);
201
- }
202
-
203
-
204
- $new_id = $wpdb->insert($table_name, array(
205
- 'acf_id' => $acf->ID,
206
- 'name' => $key,
207
- 'value' => serialize($value),
208
- 'type' => 'location'
209
- ));
210
- }
211
- // END LOCATION
212
-
213
-
214
- // START OPTIONS
215
- $table_name = $wpdb->prefix.'acf_options';
216
- //$wpdb->query("DELETE FROM $table_name WHERE acf_id = '$acf->ID' AND type = 'option'");
217
-
218
-
219
- $show_on_page = get_post_meta($acf->ID, '_acf_option_show_on_page', true);
220
-
221
-
222
- if(!empty($show_on_page))
223
- {
224
- $show_on_page = str_replace(', ',',',$show_on_page);
225
- $show_on_page = explode(',',$show_on_page);
226
-
227
-
228
- $new_id = $wpdb->insert($table_name, array(
229
- 'acf_id' => $acf->ID,
230
- 'name' => 'show_on_page',
231
- 'value' => serialize($show_on_page),
232
- 'type' => 'option'
233
- ));
234
- }
235
- // END OPTIONS
236
-
237
-
238
- // delete data
239
- foreach(get_post_custom($acf->ID) as $key => $values)
240
- {
241
- if(strpos($key, '_acf') !== false)
242
- {
243
- // this custom field needs to be deleted!
244
- delete_post_meta($acf->ID, $key);
245
- }
246
- }
247
- }
248
- }
249
- // START VALUES
250
-
251
- $table_name = $wpdb->prefix.'acf_values';
252
- //$wpdb->query("DELETE FROM $table_name WHERE acf_id = '$acf->ID' AND type = 'option'");
253
-
254
- $posts = get_posts(array(
255
- 'numberposts' => -1,
256
- 'post_type' => 'any'
257
- ));
258
-
259
- if($posts)
260
- {
261
- foreach($posts as $post)
262
- {
263
- foreach(get_post_custom($post->ID) as $key => $value)
264
- {
265
- if(strpos($key, '_acf') !== false)
266
- {
267
- // found an acf cusomt field!
268
- $name = str_replace('_acf_','',$key);
269
-
270
- if($name == 'id'){continue;}
271
-
272
- // get field id
273
- $table_name = $wpdb->prefix.'acf_fields';
274
- $field_id = $wpdb->get_var("SELECT id FROM $table_name WHERE name = '$name'");
275
-
276
- $table_name = $wpdb->prefix.'acf_values';
277
- $new_id = $wpdb->insert($table_name, array(
278
- 'field_id' => $field_id,
279
- 'value' => $value[0],
280
- 'post_id' => $post->ID,
281
- ));
282
-
283
- }
284
- }
285
-
286
- // delete data
287
- foreach(get_post_custom($post->ID) as $key => $values)
288
- {
289
- if(strpos($key, '_acf') !== false)
290
- {
291
- // this custom field needs to be deleted!
292
- delete_post_meta($post->ID, $key);
293
- }
294
- }
295
-
296
-
297
- }
298
- }
299
-
300
- // END VALUES
301
-
302
-
303
- update_option('acf_version','1.1.0');
304
- $version = '1.1.0';
305
- }
306
-
307
-
308
-
309
- /*---------------------------------------------------------------------------------------------
310
- * Update to 1.1.0 - this version adds updates tables to be utf-8
311
- *
312
- * @author Elliot Condon
313
- * @since 1.0.6
314
- *
315
- ---------------------------------------------------------------------------------------------*/
316
-
317
- if(version_compare($version,'1.1.4') < 0)
318
- {
319
- // Version is less than 1.1.4
320
-
321
- global $wpdb;
322
-
323
-
324
- // set charset
325
- if(!empty($wpdb->charset))
326
- {
327
- $char = $wpdb->charset;
328
- }
329
- else
330
- {
331
- $char = "utf8";
332
- }
333
-
334
-
335
-
336
- // alter acf_fields table
337
- $table_name = $wpdb->prefix.'acf_fields';
338
- if($wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
339
- {
340
- $sql = "ALTER TABLE $table_name charset=$char;";
341
- $wpdb->query($sql);
342
- }
343
-
344
-
345
- // alter acf_options table
346
- $table_name = $wpdb->prefix.'acf_options';
347
- if($wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
348
- {
349
- $sql = "ALTER TABLE $table_name charset=$char;";
350
- $wpdb->query($sql);
351
- }
352
-
353
-
354
- // alter acf_values table
355
- $table_name = $wpdb->prefix.'acf_values';
356
- if($wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
357
- {
358
- $sql = "ALTER TABLE $table_name charset=$char;";
359
- $wpdb->query($sql);
360
- }
361
-
362
- update_option('acf_version','1.1.4');
363
- $version = '1.1.4';
364
- }
365
-
366
-
367
- /*---------------------------------------------------------------------------------------------
368
- * Update to 2.0.1 - this version adds field description and save as custom field columns to acf_fields
369
- *
370
- * @author Elliot Condon
371
- * @since 2.0.6
372
- *
373
- ---------------------------------------------------------------------------------------------*/
374
-
375
- if(version_compare($version,'2.0.1') < 0)
376
- {
377
-
378
- global $wpdb;
379
-
380
-
381
- // set charset
382
- if(!empty($wpdb->charset))
383
- {
384
- $char = $wpdb->charset;
385
- }
386
- else
387
- {
388
- $char = "utf8";
389
- }
390
-
391
-
392
- // create acf_fields table
393
- $table_name = $wpdb->prefix.'acf_fields';
394
- if($wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
395
- {
396
- $sql = "CREATE TABLE " . $table_name . " (
397
- id bigint(20) NOT NULL AUTO_INCREMENT,
398
- order_no int(9) NOT NULL DEFAULT '0',
399
- post_id bigint(20) NOT NULL DEFAULT '0',
400
- parent_id bigint(20) NOT NULL DEFAULT '0',
401
- label text NOT NULL,
402
- name text NOT NULL,
403
- instructions text NOT NULL DEFAULT '',
404
- save_as_cf int(1) NOT NULL DEFAULT 0,
405
- type text NOT NULL,
406
- options text NOT NULL,
407
- UNIQUE KEY id (id)
408
- ) ".$char.";";
409
- dbDelta($sql);
410
- }
411
-
412
- update_option('acf_version','2.0.1');
413
- $version = '2.0.1';
414
- }
415
-
416
-
417
- /*---------------------------------------------------------------------------------------------
418
- * Update to 2.0.1 - this version adds field description and save as custom field columns to acf_fields
419
- *
420
- * @author Elliot Condon
421
- * @since 2.0.6
422
- *
423
- ---------------------------------------------------------------------------------------------*/
424
-
425
- if(version_compare($version,'2.0.2') < 0)
426
- {
427
- global $wpdb;
428
-
429
-
430
- // 1. CREATE NEW RULES TABLE
431
-
432
- $table_name = $wpdb->prefix.'acf_rules';
433
-
434
- if ($wpdb->has_cap('collation'))
435
- {
436
- if(!empty($wpdb->charset))
437
- {
438
- $charset_collate = " DEFAULT CHARACTER SET $wpdb->charset";
439
- }
440
- if(!empty($wpdb->collate))
441
- {
442
- $charset_collate .= " COLLATE $wpdb->collate";
443
-
444
- }
445
- }
446
-
447
- if(!$wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
448
- {
449
- // rules table does not exist
450
-
451
- $sql = "CREATE TABLE " . $table_name . " (
452
- id bigint(20) NOT NULL AUTO_INCREMENT,
453
- acf_id bigint(20) NOT NULL DEFAULT '0',
454
- order_no int(9) NOT NULL DEFAULT '0',
455
- param text NOT NULL,
456
- operator text NOT NULL,
457
- value text NOT NULL,
458
- UNIQUE KEY id (id)
459
- ) ".$charset_collate.";";
460
- dbDelta($sql);
461
-
462
- }
463
-
464
-
465
- // 2. SAVE LOCATION DATA AS RULES
466
-
467
- $table_name = $wpdb->prefix.'acf_options';
468
- $rules = array();
469
-
470
-
471
- // get fields and add them to $options
472
- $locations = $wpdb->get_results("SELECT * FROM $table_name WHERE type = 'location'");
473
-
474
-
475
- // rewrite into new format
476
- if($locations)
477
- {
478
- foreach($locations as $location)
479
- {
480
-
481
- $values = unserialize($location->value);
482
-
483
- foreach($values as $value)
484
- {
485
-
486
- $rules[] = array(
487
- 'acf_id' => $location->acf_id,
488
- 'order_no' => 0,
489
- 'param' => substr($location->name, 0, -1),
490
- 'operator' => '==',
491
- 'value' => $value,
492
- );
493
-
494
- }
495
- }
496
- }
497
-
498
-
499
- // 3. SAVE USER TYPE OPTION DATA AS RULES
500
-
501
-
502
- // get fields and add them to $options
503
- $locations = $wpdb->get_results("SELECT * FROM $table_name WHERE type = 'option' AND name = 'user_roles'");
504
-
505
-
506
- // rewrite into new format
507
- if($locations)
508
- {
509
-
510
- $user_roles = array(
511
- '10' => 'administrator',
512
- '7' => 'editor',
513
- '4' => 'author',
514
- '1' => 'contributor',
515
- );
516
-
517
-
518
- foreach($locations as $location)
519
- {
520
-
521
- $values = unserialize($location->value);
522
-
523
- foreach($values as $value)
524
- {
525
-
526
- $rules[] = array(
527
- 'acf_id' => $location->acf_id,
528
- 'order_no' => 0,
529
- 'param' => 'user_type',
530
- 'operator' => '==',
531
- 'value' => $user_roles[$value],
532
- );
533
-
534
- }
535
- }
536
- }
537
-
538
-
539
- // 4. SAVE RULES INTO DATABASE
540
-
541
- $table_name = $wpdb->prefix.'acf_rules';
542
-
543
- foreach($rules as $rule)
544
- {
545
- $wpdb->insert($table_name, $rule);
546
- }
547
-
548
-
549
- // 5. SAVE OPTIONS
550
-
551
- $table_name = $wpdb->prefix.'acf_options';
552
- $options = array();
553
-
554
- $options = $wpdb->get_results("SELECT * FROM $table_name WHERE type = 'option' AND name = 'show_on_page'");
555
-
556
- if($options)
557
- {
558
- foreach($options as $option)
559
- {
560
- update_post_meta($option->acf_id, 'show_on_page', $option->value);
561
-
562
- }
563
- }
564
-
565
-
566
- // 6. SAVE NEW POST META
567
-
568
- $options = $wpdb->get_results("SELECT DISTINCT acf_id FROM $table_name WHERE type = 'option'");
569
-
570
-
571
- if($options)
572
- {
573
- foreach($options as $option)
574
- {
575
- update_post_meta($option->acf_id, 'allorany', 'any');
576
- update_post_meta($option->acf_id, 'field_group_layout', 'default');
577
- }
578
- }
579
-
580
-
581
- // drop options table
582
- $wpdb->query("DROP TABLE $table_name");
583
-
584
-
585
- update_option('acf_version','2.0.2');
586
- $version = '2.0.2';
587
-
588
-
589
- }
590
-
591
- update_option('acf_version',$this->version);
592
-
593
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/upgrade.php ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*--------------------------------------------------------------------------------------
4
+ *
5
+ * Update - run on update
6
+ *
7
+ * @author Elliot Condon
8
+ * @since 1.0.6
9
+ *
10
+ *-------------------------------------------------------------------------------------*/
11
+
12
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
13
+ global $wpdb;
14
+
15
+
16
+ // tables
17
+ $acf_fields = $wpdb->prefix.'acf_fields';
18
+ $acf_values = $wpdb->prefix.'acf_values';
19
+ $acf_rules = $wpdb->prefix.'acf_rules';
20
+ $wp_postmeta = $wpdb->prefix.'postmeta';
21
+
22
+ // get current version
23
+ $version = get_option('acf_version','1.0.5');
24
+ $acf_update_msg = false;
25
+
26
+
27
+ /*--------------------------------------------------------------------------------------
28
+ *
29
+ * 1.1.0
30
+ *
31
+ *-------------------------------------------------------------------------------------*/
32
+
33
+ if(version_compare($version,'1.1.0') < 0)
34
+ {
35
+
36
+
37
+ // create acf_fields table
38
+ $sql = "CREATE TABLE " . $acf_fields . " (
39
+ id bigint(20) NOT NULL AUTO_INCREMENT,
40
+ order_no int(9) NOT NULL DEFAULT '0',
41
+ post_id bigint(20) NOT NULL DEFAULT '0',
42
+ parent_id bigint(20) NOT NULL DEFAULT '0',
43
+ label text NOT NULL,
44
+ name text NOT NULL,
45
+ instructions text NOT NULL,
46
+ default_value text NOT NULL,
47
+ type text NOT NULL,
48
+ options text NOT NULL,
49
+ UNIQUE KEY id (id)
50
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
51
+ dbDelta($sql);
52
+
53
+
54
+ // create acf_values table
55
+ $sql = "CREATE TABLE " . $acf_values . " (
56
+ id bigint(20) NOT NULL AUTO_INCREMENT,
57
+ order_no int(9) NOT NULL DEFAULT '0',
58
+ field_id bigint(20) NOT NULL DEFAULT '0',
59
+ value text NOT NULL,
60
+ post_id bigint(20) NOT NULL DEFAULT '0',
61
+ UNIQUE KEY id (id)
62
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
63
+ dbDelta($sql);
64
+
65
+
66
+ // create acf_rules table
67
+ $sql = "CREATE TABLE " . $acf_rules . " (
68
+ id bigint(20) NOT NULL AUTO_INCREMENT,
69
+ acf_id bigint(20) NOT NULL DEFAULT '0',
70
+ order_no int(9) NOT NULL DEFAULT '0',
71
+ param text NOT NULL,
72
+ operator text NOT NULL,
73
+ value text NOT NULL,
74
+ UNIQUE KEY id (id)
75
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
76
+ dbDelta($sql);
77
+
78
+
79
+
80
+ update_option('acf_version','1.1.0');
81
+ $version = '1.1.0';
82
+ }
83
+
84
+
85
+ /*--------------------------------------------------------------------------------------
86
+ *
87
+ * 2.1.0
88
+ *
89
+ *-------------------------------------------------------------------------------------*/
90
+
91
+ if(version_compare($version,'2.1.0') < 0)
92
+ {
93
+
94
+ // add default_value to fields table
95
+ $sql = "CREATE TABLE " . $acf_fields . " (
96
+ id bigint(20) NOT NULL AUTO_INCREMENT,
97
+ order_no int(9) NOT NULL DEFAULT '0',
98
+ post_id bigint(20) NOT NULL DEFAULT '0',
99
+ parent_id bigint(20) NOT NULL DEFAULT '0',
100
+ label text NOT NULL,
101
+ name text NOT NULL,
102
+ instructions text NOT NULL,
103
+ default_value text NOT NULL,
104
+ type text NOT NULL,
105
+ options text NOT NULL,
106
+ UNIQUE KEY id (id)
107
+ ) DEFAULT CHARSET=utf8;";
108
+ dbDelta($sql);
109
+
110
+
111
+ // images and files are all now saved as id's
112
+ $fields = $wpdb->get_results("SELECT id FROM $acf_fields WHERE type = 'image' OR type = 'file'");
113
+ $postmeta = $wpdb->prefix.'postmeta';
114
+
115
+ if($fields)
116
+ {
117
+ foreach($fields as $field)
118
+ {
119
+ $values = $wpdb->get_results("SELECT id,value FROM $acf_values WHERE field_id = '$field->id'");
120
+ if($values)
121
+ {
122
+ foreach($values as $value)
123
+ {
124
+ if(!empty($value->value) && !is_numeric($value->value))
125
+ {
126
+ $find_value = str_replace(get_bloginfo('url') . '/wp-content/uploads/', '', $value->value);
127
+ $attachment_id = $wpdb->get_var("SELECT post_id FROM $postmeta WHERE meta_value = '$find_value'");
128
+
129
+ // update value
130
+ $wpdb->query("UPDATE $acf_values SET value = '$attachment_id' WHERE id = '$value->id'");
131
+ }
132
+ }
133
+ }
134
+ }
135
+ }
136
+
137
+
138
+ // values are now stored as custom fields
139
+ $values = $wpdb->get_results("SELECT v.id, v.value, v.post_id, f.name FROM $acf_values v LEFT JOIN $acf_fields f ON v.field_id = f.id ORDER BY v.id ASC");
140
+ if($values)
141
+ {
142
+ foreach($values as $value)
143
+ {
144
+ if($value->value == ""){continue;}
145
+
146
+ $data = array(
147
+ 'post_id' => $value->post_id,
148
+ 'meta_key' => $value->name,
149
+ 'meta_value' => $value->value,
150
+ );
151
+
152
+ $wpdb->insert($wp_postmeta, $data);
153
+
154
+ $new_id = $wpdb->insert_id;
155
+
156
+ if($new_id && $new_id != 0)
157
+ {
158
+ $wpdb->query("UPDATE $acf_values SET value = '$new_id' WHERE id = '$value->id'");
159
+ }
160
+
161
+
162
+ }
163
+ }
164
+
165
+
166
+ // value is now an int
167
+ $sql = "CREATE TABLE " . $acf_values . " (
168
+ id bigint(20) NOT NULL AUTO_INCREMENT,
169
+ order_no int(9) NOT NULL DEFAULT '0',
170
+ field_id bigint(20) NOT NULL DEFAULT '0',
171
+ sub_field_id bigint(20) NOT NULL DEFAULT '0',
172
+ value bigint(20) NOT NULL DEFAULT '0',
173
+ UNIQUE KEY id (id)
174
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
175
+ dbDelta($sql);
176
+
177
+
178
+ // now set sub_field_if values
179
+ $values = $wpdb->get_results("SELECT v.id, f.id as sub_field_id, f.parent_id as field_id FROM $acf_values v LEFT JOIN $acf_fields f ON v.field_id = f.id WHERE f.parent_id != '0' ORDER BY v.id ASC");
180
+ if($values)
181
+ {
182
+ foreach($values as $value)
183
+ {
184
+ $wpdb->query("UPDATE $acf_values SET field_id = '$value->field_id', sub_field_id = '$value->sub_field_id' WHERE id = '$value->id'");
185
+ }
186
+ }
187
+
188
+
189
+ // set version
190
+ update_option('acf_version','2.0.6');
191
+ $version = '2.0.6';
192
+
193
+ }
194
+
195
+
196
+
197
+ /*--------------------------------------------------------------------------------------
198
+ *
199
+ * Finish
200
+ *
201
+ *-------------------------------------------------------------------------------------*/
202
+
203
+ $this->admin_message('Advanced Custom Fields successfully upgraded to ' . $this->version . '! <a href="' . get_bloginfo('url') . '/wp-admin/plugin-install.php?tab=plugin-information&plugin=advanced-custom-fields&section=changelog&TB_iframe=true&width=640&height=559" class="thickbox">See what\'s new</a>');
204
+
205
+ update_option('acf_version',$this->version);
206
+
207
+ ?>
css/style.fields.css CHANGED
@@ -3,7 +3,7 @@
3
  ---------------------------------------------------------------------------------------------*/
4
 
5
  .postbox#acf_fields {
6
-
7
  }
8
 
9
  .postbox#acf_fields .handlediv {
@@ -19,50 +19,18 @@
19
  padding: 0;
20
  }
21
 
22
- /*---------------------------------------------------------------------------------------------
23
- Fields
24
- ---------------------------------------------------------------------------------------------*/
25
- .fields {
26
- position: relative;
27
- overflow: hidden;
28
- background: #F5F5F5;
29
- }
30
-
31
- .fields .field {
32
- position: relative;
33
- overflow: hidden;
34
- border-top: #fff solid 1px;;
35
- border-bottom: #DFDFDF solid 1px;
36
- }
37
-
38
- .fields .field:nth-child(even) {
39
- background: #FCFCFC;
40
- }
41
-
42
- .fields .field:nth-child(odd) {
43
-
44
- }
45
-
46
- .fields .field:hover {
47
- background: #FFFFE0;
48
- }
49
-
50
- .fields .field.form_open {
51
- background: #FFFFE0;
52
  }
53
 
54
- .fields .field_clone {
 
55
  display: none;
56
  }
57
 
58
- .fields .field:first-child {
59
- border-top: 0 none;
60
- }
61
-
62
- .fields .field:last-child {
63
- border-bottom: 0 none;
64
- }
65
-
66
  table.widefat.acf {
67
  border: 0 none;
68
  background: transparent none;
@@ -78,21 +46,6 @@ table.widefat.acf td {
78
  vertical-align: top;
79
  }
80
 
81
-
82
- /*---------------------------------------------------------------------------------------------
83
- Table Heading
84
- ---------------------------------------------------------------------------------------------*/
85
- /*.acf tr th {
86
- background: url("../../../../wp-admin/images/gray-grad.png") repeat-x scroll left top #DFDFDF;
87
- text-shadow: 0 1px 0 #FFFFFF;
88
- color: #333;
89
- font-weight: bold;
90
- font-size: 11px;
91
- line-height: 1.3;
92
- padding: 8px;
93
- text-align: left;
94
- }*/
95
-
96
  .acf tr th span {
97
  color: #666;
98
  font-size: 10px;
@@ -110,10 +63,6 @@ table.widefat.acf td {
110
  cursor: move;
111
  }
112
 
113
-
114
- /*---------------------------------------------------------------------------------------------
115
- Table Cell Alignment
116
- ---------------------------------------------------------------------------------------------*/
117
  .acf tr td.field_order,
118
  .acf tr th.field_order {
119
  width: 25%;
@@ -134,15 +83,6 @@ table.widefat.acf td {
134
  width: 25%;
135
  }
136
 
137
- /*---------------------------------------------------------------------------------------------
138
- Table Body - Fields
139
- ---------------------------------------------------------------------------------------------*/
140
- .no_fields_message {
141
- padding: 15px 10px;
142
- text-shadow: #fff 0 1px 0;
143
- border-bottom: #DFDFDF solid 1px;
144
- }
145
-
146
  .acf tr td {
147
  background: transparent;
148
  padding: 8px;
@@ -150,32 +90,131 @@ table.widefat.acf td {
150
  font-size: 12px;
151
  }
152
 
153
- .acf td.field_label strong a {
154
- text-decoration: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  }
156
 
157
- .acf td.field_label strong {
 
 
 
 
 
158
  display: block;
159
  padding-bottom: 6px;
160
  }
161
 
162
- .acf .row_options {
163
  font-size: 11px;
164
  visibility: hidden;
165
  }
166
- .acf:hover .row_options {
 
167
  visibility: visible;
168
  }
169
 
170
- .acf:hover .acf .row_options {
171
- visibility: hidden;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  }
173
 
174
 
175
 
176
  /*---------------------------------------------------------------------------------------------
177
- Table Body - Field Options
178
  ---------------------------------------------------------------------------------------------*/
 
 
 
 
 
 
179
 
180
 
181
  /*---------------------------------------------------------------------------------------------
@@ -186,6 +225,8 @@ table.widefat.acf td {
186
  overflow: hidden;
187
  padding: 8px;
188
  background: #EAF2FA;
 
 
189
  }
190
 
191
  #acf_fields .table_footer .order_message {
@@ -239,19 +280,17 @@ table.widefat.acf td {
239
  }
240
 
241
 
 
 
 
242
  /*---------------------------------------------------------------------------------------------
243
  Repeater
244
  ---------------------------------------------------------------------------------------------*/
245
- .repeater {
246
- border: #CCCCCC solid 1px;
247
- -moz-border-radius: 5px; -webkit-border-radius: 5px; -khtml-border-radius: 5px; border-radius: 5px;
248
  position: relative;
249
- overflow: hidden;
250
  }
251
 
252
  .field_options .field_option .repeater table {
253
- border: 0 none;
254
- -moz-border-radius: 0; -webkit-border-radius: 0; -khtml-border-radius: 0; border-radius: 0;
255
  }
256
 
257
  table.acf_input tr td .acf tr td {
@@ -266,15 +305,38 @@ table.acf_input tr td .acf tr td {
266
  /*---------------------------------------------------------------------------------------------
267
  Field Form
268
  ---------------------------------------------------------------------------------------------*/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  .field_form_mask {
270
  display: none;
271
  width: 100%;
272
  position: relative;
273
  overflow: hidden;
274
- }
275
-
276
- .field_form {
277
- padding: 0 10px 10px;
278
  }
279
 
280
  .field_form .field_option {
3
  ---------------------------------------------------------------------------------------------*/
4
 
5
  .postbox#acf_fields {
6
+ border: 0 none;
7
  }
8
 
9
  .postbox#acf_fields .handlediv {
19
  padding: 0;
20
  }
21
 
22
+ .postbox#acf_fields a {
23
+ text-decoration: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  }
25
 
26
+ #minor-publishing,
27
+ #misc-publishing-actions {
28
  display: none;
29
  }
30
 
31
+ /*---------------------------------------------------------------------------------------------
32
+ Table
33
+ ---------------------------------------------------------------------------------------------*/
 
 
 
 
 
34
  table.widefat.acf {
35
  border: 0 none;
36
  background: transparent none;
46
  vertical-align: top;
47
  }
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  .acf tr th span {
50
  color: #666;
51
  font-size: 10px;
63
  cursor: move;
64
  }
65
 
 
 
 
 
66
  .acf tr td.field_order,
67
  .acf tr th.field_order {
68
  width: 25%;
83
  width: 25%;
84
  }
85
 
 
 
 
 
 
 
 
 
 
86
  .acf tr td {
87
  background: transparent;
88
  padding: 8px;
90
  font-size: 12px;
91
  }
92
 
93
+
94
+
95
+
96
+ /*---------------------------------------------------------------------------------------------
97
+ Fields Header
98
+ ---------------------------------------------------------------------------------------------*/
99
+ .fields_header {
100
+ -moz-border-radius: 3px 3px 0 0;
101
+ -webkit-border-radius: 3px 3px 0 0;
102
+ -khtml-border-radius: 3px 3px 0 0;
103
+ border-radius: 3px 3px 0 0;
104
+ border: #DFDFDF solid 1px;
105
+ border-bottom: 0 none;
106
+ }
107
+
108
+
109
+ /*---------------------------------------------------------------------------------------------
110
+ Field Meta
111
+ ---------------------------------------------------------------------------------------------*/
112
+
113
+ #acf_fields .field_meta {
114
+ position: relative;
115
+ overflow: hidden;
116
  }
117
 
118
+ #acf_fields .field .field_meta {
119
+ border: #DFDFDF solid 1px;
120
+ border-top: 0 none;
121
+ }
122
+
123
+ #acf_fields .field .field_meta strong {
124
  display: block;
125
  padding-bottom: 6px;
126
  }
127
 
128
+ #acf_fields .field .field_meta .row_options {
129
  font-size: 11px;
130
  visibility: hidden;
131
  }
132
+
133
+ #acf_fields .field .field_meta:hover .row_options {
134
  visibility: visible;
135
  }
136
 
137
+ #acf_fields .field.form_open > .field_meta {
138
+ background: #6e6e6e url(../images/backgrounds.png) 0 0 repeat-x;
139
+ color: #fff;
140
+ text-shadow: #000 0 1px 0;
141
+ border-bottom: #565656 solid 1px;
142
+ border-top: #565656 solid 1px;
143
+ border-left:0 none;
144
+ border-right:0 none;
145
+
146
+ }
147
+
148
+ #acf_fields .field.form_open > .field_meta td,
149
+ #acf_fields .field.form_open > .field_meta a {
150
+ color: #fff;
151
+ }
152
+
153
+ #acf_fields .field.form_open > .field_meta a:hover {
154
+ color: #ff8a4f;
155
+ }
156
+
157
+ #acf_fields .fields .field .field_meta .circle {
158
+ width: 20px;
159
+ height: 20px;
160
+ text-align: center;
161
+ font-size: 11px;
162
+ line-height: 20px;
163
+ display: block;
164
+ float: left;
165
+ margin: 7px 0 0 7px;
166
+ text-indent: 0;
167
+ background: url(../images/backgrounds.png) 0 -100px no-repeat;
168
+ }
169
+
170
+ #acf_fields .fields .field:nth-child(2n) .field_meta .circle {
171
+ background-position: 0 -150px;
172
+
173
+ }
174
+
175
+ #acf_fields .field.form_open > .field_meta .circle {
176
+ background-position: 0 -50px !important;
177
+ }
178
+
179
+
180
+ .fields {
181
+ position: relative;
182
+ overflow: hidden;
183
+ background: #F5F5F5;
184
+ }
185
+
186
+ .fields .field {
187
+ position: relative;
188
+ overflow: hidden;
189
+ }
190
+
191
+ .fields .field:nth-child(even) {
192
+ background: #FCFCFC;
193
+ }
194
+
195
+ .fields .field_clone {
196
+ display: none;
197
+ }
198
+
199
+ .fields .field:first-child {
200
+ border-top: 0 none;
201
+ }
202
+
203
+ .fields .field:last-child {
204
+ border-bottom: 0 none;
205
  }
206
 
207
 
208
 
209
  /*---------------------------------------------------------------------------------------------
210
+ Table Body - Fields
211
  ---------------------------------------------------------------------------------------------*/
212
+ .no_fields_message {
213
+ padding: 15px 10px;
214
+ text-shadow: #fff 0 1px 0;
215
+ border: #DFDFDF solid 1px;
216
+ border-top: #fff solid 1px;
217
+ }
218
 
219
 
220
  /*---------------------------------------------------------------------------------------------
225
  overflow: hidden;
226
  padding: 8px;
227
  background: #EAF2FA;
228
+ border: #c7d7e2 solid 1px;
229
+ border-top:0 none;
230
  }
231
 
232
  #acf_fields .table_footer .order_message {
280
  }
281
 
282
 
283
+ .field_save td {
284
+ line-height: 25px;
285
+ }
286
  /*---------------------------------------------------------------------------------------------
287
  Repeater
288
  ---------------------------------------------------------------------------------------------*/
289
+ .repeater {
 
 
290
  position: relative;
 
291
  }
292
 
293
  .field_options .field_option .repeater table {
 
 
294
  }
295
 
296
  table.acf_input tr td .acf tr td {
305
  /*---------------------------------------------------------------------------------------------
306
  Field Form
307
  ---------------------------------------------------------------------------------------------*/
308
+ .field_form {
309
+ border: #98b6cb solid 1px;
310
+ border-top: 0 none;
311
+ background: #accde4;
312
+ padding: 10px;
313
+ clear: both;
314
+ vertical-align: top;
315
+ }
316
+
317
+ .field_form table.acf_input {
318
+ border: #98b6cb solid 1px;
319
+ -moz-border-radius: 5px; -webkit-border-radius: 5px; -khtml-border-radius: 5px; border-radius: 5px;
320
+ position: relative;
321
+ overflow: hidden;
322
+ }
323
+
324
+ .field_form table.acf_input tr.field_label td {
325
+ border-top: 0 none;
326
+ }
327
+
328
+ .field_form table.acf_input td {
329
+ background: transparent;
330
+ border-bottom-color: #DFDFDF;
331
+ border-top-color: #FFFFFF;
332
+ }
333
+
334
  .field_form_mask {
335
  display: none;
336
  width: 100%;
337
  position: relative;
338
  overflow: hidden;
339
+ clear: both;
 
 
 
340
  }
341
 
342
  .field_form .field_option {
css/style.global.css CHANGED
@@ -5,24 +5,12 @@ table.acf_input {
5
  border: 0 none;
6
  }
7
 
8
- .field_form table.acf_input {
9
- border: #DFDFDF solid 1px;
10
- }
11
-
12
  table.acf_input tbody tr td {
13
  padding: 10px;
14
  }
15
 
16
- table.acf_input tr:nth-child(even) {
17
- background: #FCFCFC;
18
- }
19
-
20
- table.acf_input tr:nth-child(odd) {
21
- background: transparent;
22
- }
23
-
24
  table.acf_input tr.field_save {
25
- background: #EAF2FA;
26
  }
27
 
28
  table.acf_input tbody tr:last-child td {
@@ -32,7 +20,7 @@ table.acf_input tbody tr:last-child td {
32
  table.acf_input tbody tr td.label {
33
  width: 24%;
34
  vertical-align: top;
35
- border-right: #DFDFDF solid 1px;
36
  }
37
 
38
  table.acf_input tbody tr td.label label{
@@ -66,4 +54,30 @@ table.acf_input input[type=text],
66
  table.acf_input textarea,
67
  table.acf_input select{
68
  width: 99.95%;
69
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  border: 0 none;
6
  }
7
 
 
 
 
 
8
  table.acf_input tbody tr td {
9
  padding: 10px;
10
  }
11
 
 
 
 
 
 
 
 
 
12
  table.acf_input tr.field_save {
13
+
14
  }
15
 
16
  table.acf_input tbody tr:last-child td {
20
  table.acf_input tbody tr td.label {
21
  width: 24%;
22
  vertical-align: top;
23
+ border-right: #ebebeb solid 1px;
24
  }
25
 
26
  table.acf_input tbody tr td.label label{
54
  table.acf_input textarea,
55
  table.acf_input select{
56
  width: 99.95%;
57
+ padding: 5px;
58
+ outline: none;
59
+ }
60
+
61
+ table.acf_input input[type=text]:focus,
62
+ table.acf_input textarea:focus,
63
+ table.acf_input select:focus {
64
+ border-color:#98B6CB;
65
+ }
66
+
67
+
68
+ ul.radio_list {
69
+ position: relative;
70
+ overflow: hidden;
71
+ display: block;
72
+ padding: 3px 0;
73
+ }
74
+
75
+ ul.radio_list input[type="radio"] {
76
+ margin-right: 5px;
77
+
78
+ }
79
+
80
+ ul.radio_list.horizontal li {
81
+ float: left;
82
+ margin-right: 20px;
83
+ }
css/style.input.css CHANGED
@@ -2,20 +2,44 @@
2
  border: #EAEAEA solid 0px;
3
  background: transparent;
4
  position: relative;
5
- overflow: visible;border: 0 none !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  }
7
 
8
- .acf_fields_input {
9
  position: relative;
10
  }
11
 
12
- .acf_fields_input .field {
13
  position: relative;
14
  padding: 10px 2px;
15
  border-top: 1px solid #eaeaea;
16
  }
17
 
18
- .acf_fields_input .field label {
19
  display: block;
20
  color: #21759B;
21
  font-size: 12px;
@@ -24,7 +48,6 @@
24
  text-shadow: 0 1px 0 #FFFFFF;
25
  }
26
 
27
-
28
  .postbox#acf_input > h3.hndle{
29
  display: none;
30
  }
@@ -40,6 +63,10 @@
40
  width: 0;
41
  }
42
 
 
 
 
 
43
  .acf_wysiwyg {
44
  border: #DFDFDF solid 1px;
45
  overflow: hidden;
@@ -50,9 +77,9 @@
50
  top: -2px !important;
51
  }
52
 
53
- .acf_fields_input .field input[type="text"],
54
- .acf_fields_input .field textarea,
55
- .acf_fields_input .field select{
56
  width: 99.8%;
57
  }
58
 
@@ -169,7 +196,7 @@
169
  }
170
 
171
  .repeater > table > tbody > tr:nth-child(even) {
172
- background: transparent;
173
  }
174
 
175
  .repeater > table > tbody > tr:nth-child(odd) {
@@ -193,8 +220,14 @@
193
  visibility: hidden;
194
  }
195
 
 
196
  .repeater > table.row_layout > tbody > tr > td > label {
197
- padding-top: 20px;
 
 
 
 
 
198
  }
199
 
200
  .repeater > table.row_layout > tbody > tr > td > label:first-child {
@@ -293,29 +326,34 @@ ul.checkbox_list {
293
  }
294
 
295
 
 
296
  /*---------------------------------------------------------------------------------------------
297
  In Box
298
  ---------------------------------------------------------------------------------------------*/
299
 
300
- #acf_input .acf_fields_input {
301
 
302
  }
303
 
304
- #acf_input .acf_fields_input .postbox {
305
 
306
  }
307
 
308
- #acf_input .acf_fields_input .postbox .inside {
309
  margin: 0;
310
  padding: 0;
311
  }
312
 
313
- #acf_input .acf_fields_input .postbox .inside .field {
314
  padding: 10px 10px;
315
  border-top: 1px solid #fff;
316
  border-bottom: #DFDFDF solid 1px;
317
  }
318
 
319
- #acf_input .acf_fields_input .postbox .inside .field:last-child {
320
  border-bottom: none;
 
 
 
 
321
  }
2
  border: #EAEAEA solid 0px;
3
  background: transparent;
4
  position: relative;
5
+ overflow: visible;
6
+ border: 0 none !important;
7
+
8
+ }
9
+
10
+ .postbox#acf_input.loading {
11
+ min-height: 50px;
12
+ }
13
+
14
+ .postbox#acf_input #acf_loading {
15
+ position: absolute;
16
+ top: 50%;
17
+ left: 50%;
18
+ height: 50px;
19
+ width: 50px;
20
+ margin-left: -25px;
21
+ margin-top: -25px;
22
+ background: #5a5a5a url(../images/loading.gif) 50% 50% no-repeat;
23
+ -moz-border-radius: 5px; -webkit-border-radius: 5px; -khtml-border-radius: 5px; border-radius: 5px;
24
+ display: none;
25
+ z-index: 3;
26
+ }
27
+
28
+ .postbox#acf_input.loading #acf_loading {
29
+ display: block;
30
  }
31
 
32
+ #acf_fields_ajax {
33
  position: relative;
34
  }
35
 
36
+ #acf_fields_ajax .field {
37
  position: relative;
38
  padding: 10px 2px;
39
  border-top: 1px solid #eaeaea;
40
  }
41
 
42
+ #acf_fields_ajax .field > label {
43
  display: block;
44
  color: #21759B;
45
  font-size: 12px;
48
  text-shadow: 0 1px 0 #FFFFFF;
49
  }
50
 
 
51
  .postbox#acf_input > h3.hndle{
52
  display: none;
53
  }
63
  width: 0;
64
  }
65
 
66
+ #acf_fields_ajax .postbox h3 {
67
+ cursor: default;
68
+ }
69
+
70
  .acf_wysiwyg {
71
  border: #DFDFDF solid 1px;
72
  overflow: hidden;
77
  top: -2px !important;
78
  }
79
 
80
+ #acf_fields_ajax .field input[type="text"],
81
+ #acf_fields_ajax .field textarea,
82
+ #acf_fields_ajax .field select{
83
  width: 99.8%;
84
  }
85
 
196
  }
197
 
198
  .repeater > table > tbody > tr:nth-child(even) {
199
+ background: #F9F9F9;
200
  }
201
 
202
  .repeater > table > tbody > tr:nth-child(odd) {
220
  visibility: hidden;
221
  }
222
 
223
+
224
  .repeater > table.row_layout > tbody > tr > td > label {
225
+ display: block;
226
+ color: #21759B;
227
+ font-size: 12px;
228
+ font-weight: bold;
229
+ padding: 20px 0 8px;
230
+ text-shadow: 0 1px 0 #FFFFFF;
231
  }
232
 
233
  .repeater > table.row_layout > tbody > tr > td > label:first-child {
326
  }
327
 
328
 
329
+
330
  /*---------------------------------------------------------------------------------------------
331
  In Box
332
  ---------------------------------------------------------------------------------------------*/
333
 
334
+ #acf_input #acf_fields_ajax {
335
 
336
  }
337
 
338
+ #acf_input #acf_fields_ajax .postbox {
339
 
340
  }
341
 
342
+ #acf_input #acf_fields_ajax .postbox .inside {
343
  margin: 0;
344
  padding: 0;
345
  }
346
 
347
+ #acf_input #acf_fields_ajax .postbox .inside .field {
348
  padding: 10px 10px;
349
  border-top: 1px solid #fff;
350
  border-bottom: #DFDFDF solid 1px;
351
  }
352
 
353
+ #acf_input #acf_fields_ajax .postbox .inside .field:last-child {
354
  border-bottom: none;
355
+ }
356
+
357
+ .no_move .postbox .hndle {
358
+ cursor: default !important;
359
  }
css/style.screen_extra.css CHANGED
@@ -138,4 +138,14 @@ table.acf_activate input[type="submit"] {
138
  --------------------------------------------------------------------------------------------*/
139
  #wpcontent select[multiple="multiple"] {
140
  height: auto;
141
- }
 
 
 
 
 
 
 
 
 
 
138
  --------------------------------------------------------------------------------------------*/
139
  #wpcontent select[multiple="multiple"] {
140
  height: auto;
141
+ min-width: 150px;
142
+ }
143
+
144
+
145
+ /*--------------------------------------------------------------------------------------------
146
+ Columns
147
+ --------------------------------------------------------------------------------------------*/
148
+ .row-actions .inline {
149
+ display: none;
150
+ }
151
+
images/backgrounds ADDED
Binary file
images/backgrounds.png ADDED
Binary file
images/backgrounds.psd ADDED
Binary file
images/loading.gif CHANGED
Binary file
images/loading_old.gif ADDED
Binary file
js/functions.fields.js CHANGED
@@ -1,18 +1,26 @@
1
  (function($){
2
 
3
- // exists
 
 
 
 
 
4
  $.fn.exists = function()
5
  {
6
- return jQuery(this).length>0;
7
  };
8
 
 
 
 
 
 
 
 
9
 
10
- /*--------------------------------------------------------------------------
11
- Update Names
12
- --------------------------------------------------------------------------*/
13
  $.fn.update_names = function(new_no, new_sub_no)
14
  {
15
- //console.log('update names: new_no = '+new_no+', new_sub_no = '+new_sub_no);
16
 
17
  //alert('passed through '+total_fields);
18
  $(this).find('[name]').each(function()
@@ -52,40 +60,38 @@
52
  }
53
 
54
 
55
- /*--------------------------------------------------------------------------
56
- Update Order Numbers
57
- --------------------------------------------------------------------------*/
 
 
 
58
  function update_order_numbers(){
59
 
60
- $('.fields').each(function(){
61
  $(this).children('.field').each(function(i){
62
- $(this).find('td.field_order').first().html(i+1);
63
  });
64
  });
65
-
66
-
67
  }
68
 
69
 
70
- /*--------------------------------------------------------------------------
71
- setup_fields
72
- --------------------------------------------------------------------------*/
 
 
 
73
  function setup_fields()
74
  {
75
-
76
- if(!$('.postbox#acf_fields').exists())
77
- {
78
- alert('ERROR. Could not find .postbox#acf_fields');
79
- return false;
80
- }
81
-
82
-
83
  // add edit button functionality
84
- $('a.acf_edit_field').live('click', function(){
85
- //console.log('me');
86
  var field = $(this).closest('.field');
87
 
88
- if(field.is('.form_open'))
89
  {
90
  field.removeClass('form_open');
91
  }
@@ -94,14 +100,14 @@
94
  field.addClass('form_open');
95
  }
96
 
97
-
98
  field.children('.field_form_mask').animate({'height':'toggle'}, 500);
 
99
  });
100
 
101
 
102
  // add delete button functionality
103
- $('a.acf_delete_field').live('click', function(){
104
- //console.log('me');
105
  var field = $(this).closest('.field');
106
  var fields = field.closest('.fields');
107
 
@@ -113,16 +119,12 @@
113
  // no more fields, show the message
114
  fields.children('.no_fields_message').show();
115
  }
116
- //field.animate({'opacity':'0'}, 500, function(){
117
- // $(this).animate({'height':'0'}, 500, function(){
118
- //
119
- // });
120
- //});
121
  });
122
 
123
 
124
  // show field type options
125
- $('.field_form tr.field_type select').live('change', function(){
126
 
127
  var tbody = $(this).closest('tbody');
128
  var type = $(this).val();
@@ -130,7 +132,6 @@
130
  // does it have repeater?
131
  if(!$(this).find('option[value="repeater"]').exists())
132
  {
133
- //console.log('select: '+type+'. parent length: '+$(this).closest('.repeater').length);
134
  if($(this).closest('.repeater').length == 0)
135
  {
136
  $(this).append('<option value="null" disabled="true">Repeater (Unlock field with activation code)</option>');
@@ -153,11 +154,11 @@
153
 
154
 
155
  // Add Field Button
156
- $('#add_field').live('click',function(){
157
 
158
  var table_footer = $(this).closest('.table_footer');
159
  var fields = table_footer.siblings('.fields');
160
- //console.log(fields);
161
 
162
  // clone last tr
163
  var new_field = fields.children('.field_clone').clone();
@@ -197,15 +198,14 @@
197
  fields.children('.no_fields_message').hide();
198
  }
199
 
200
-
201
- // open up the edit form
202
- new_field.find('a.acf_edit_field').first().trigger('click');
203
-
204
-
205
- // clear text inputs
206
  new_field.find('.field_form input[type="text"]').val('');
207
  new_field.find('.field_form input[type="text"]').first().focus();
 
208
 
 
 
 
209
 
210
  // update order numbers
211
  update_order_numbers();
@@ -258,13 +258,38 @@
258
 
259
  }
260
 
261
- /*--------------------------------------------------------------------------
262
- Document Ready
263
- --------------------------------------------------------------------------*/
 
 
 
264
  $(document).ready(function(){
 
 
 
265
 
 
 
 
 
 
266
  setup_fields();
 
 
 
 
 
 
 
 
 
 
267
 
 
 
 
 
268
  });
269
 
270
  })(jQuery);
1
  (function($){
2
 
3
+ /*----------------------------------------------------------------------
4
+ *
5
+ * Exists
6
+ *
7
+ *---------------------------------------------------------------------*/
8
+
9
  $.fn.exists = function()
10
  {
11
+ return $(this).length>0;
12
  };
13
 
14
+
15
+
16
+ /*----------------------------------------------------------------------
17
+ *
18
+ * Update Names
19
+ *
20
+ *---------------------------------------------------------------------*/
21
 
 
 
 
22
  $.fn.update_names = function(new_no, new_sub_no)
23
  {
 
24
 
25
  //alert('passed through '+total_fields);
26
  $(this).find('[name]').each(function()
60
  }
61
 
62
 
63
+ /*----------------------------------------------------------------------
64
+ *
65
+ * Update Order Numbers
66
+ *
67
+ *---------------------------------------------------------------------*/
68
+
69
  function update_order_numbers(){
70
 
71
+ $('#acf_fields .fields').each(function(){
72
  $(this).children('.field').each(function(i){
73
+ $(this).find('td.field_order .circle').first().html(i+1);
74
  });
75
  });
76
+
 
77
  }
78
 
79
 
80
+ /*----------------------------------------------------------------------
81
+ *
82
+ * setup_fields
83
+ *
84
+ *---------------------------------------------------------------------*/
85
+
86
  function setup_fields()
87
  {
88
+
 
 
 
 
 
 
 
89
  // add edit button functionality
90
+ $('#acf_fields a.acf_edit_field').live('click', function(){
91
+
92
  var field = $(this).closest('.field');
93
 
94
+ if(field.hasClass('form_open'))
95
  {
96
  field.removeClass('form_open');
97
  }
100
  field.addClass('form_open');
101
  }
102
 
 
103
  field.children('.field_form_mask').animate({'height':'toggle'}, 500);
104
+
105
  });
106
 
107
 
108
  // add delete button functionality
109
+ $('#acf_fields a.acf_delete_field').live('click', function(){
110
+
111
  var field = $(this).closest('.field');
112
  var fields = field.closest('.fields');
113
 
119
  // no more fields, show the message
120
  fields.children('.no_fields_message').show();
121
  }
122
+
 
 
 
 
123
  });
124
 
125
 
126
  // show field type options
127
+ $('#acf_fields tr.field_type select').live('change', function(){
128
 
129
  var tbody = $(this).closest('tbody');
130
  var type = $(this).val();
132
  // does it have repeater?
133
  if(!$(this).find('option[value="repeater"]').exists())
134
  {
 
135
  if($(this).closest('.repeater').length == 0)
136
  {
137
  $(this).append('<option value="null" disabled="true">Repeater (Unlock field with activation code)</option>');
154
 
155
 
156
  // Add Field Button
157
+ $('#acf_fields #add_field').live('click',function(){
158
 
159
  var table_footer = $(this).closest('.table_footer');
160
  var fields = table_footer.siblings('.fields');
161
+
162
 
163
  // clone last tr
164
  var new_field = fields.children('.field_clone').clone();
198
  fields.children('.no_fields_message').hide();
199
  }
200
 
201
+ // clear name
 
 
 
 
 
202
  new_field.find('.field_form input[type="text"]').val('');
203
  new_field.find('.field_form input[type="text"]').first().focus();
204
+ new_field.find('tr.field_type select').trigger('change');
205
 
206
+ // open up form
207
+ new_field.find('a.acf_edit_field').first().trigger('click');
208
+
209
 
210
  // update order numbers
211
  update_order_numbers();
258
 
259
  }
260
 
261
+ /*----------------------------------------------------------------------
262
+ *
263
+ * Document Ready
264
+ *
265
+ *---------------------------------------------------------------------*/
266
+
267
  $(document).ready(function(){
268
+
269
+ // firefox radio button bug
270
+ if($.browser.mozilla) $("form").attr("autocomplete", "off");
271
 
272
+
273
+ // add active to Settings Menu
274
+ $('#adminmenu #menu-settings').addClass('current');
275
+
276
+ // setup fields
277
  setup_fields();
278
+
279
+
280
+ $('#acf_fields input[type="radio"]').each(function(){
281
+
282
+ if($(this).is(':checked'))
283
+ {
284
+ $(this).removeAttr('checked').attr('checked', 'checked');
285
+ }
286
+ else
287
+ {
288
 
289
+ }
290
+
291
+ });
292
+
293
  });
294
 
295
  })(jQuery);
js/functions.input.js CHANGED
@@ -1,210 +1,298 @@
 
 
1
  (function($){
2
 
3
- // exists
 
 
 
 
 
4
  $.fn.exists = function()
5
  {
6
  return $(this).length>0;
7
  };
8
 
9
- // vars
 
 
 
 
 
 
10
  var wysiwyg_count = 0;
11
- var post_id = 0;
12
-
13
- // global vars
14
- window.acf_div = null;
15
-
16
-
17
- /*-------------------------------------------
18
- Wysiwyg
19
- -------------------------------------------*/
20
- $.fn.make_acf_wysiwyg = function()
21
- {
22
- wysiwyg_count++;
23
- var id = 'acf_wysiwyg_'+wysiwyg_count;
24
- //alert(id);
25
- $(this).find('textarea').attr('id',id);
26
- tinyMCE.execCommand('mceAddControl', false, id);
27
- };
28
 
29
- /*-------------------------------------------
30
- Datepicker
31
- -------------------------------------------*/
32
- $.fn.make_acf_datepicker = function()
33
  {
34
- var format = 'dd/mm/yy';
35
- if($(this).siblings('input[name="date_format"]').val() != '')
36
- {
37
- format = $(this).siblings('input[name="date_format"]').val();
38
- }
39
 
40
- $(this).datepicker({
41
- dateFormat: format
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  });
43
-
44
- $('#ui-datepicker-div').wrap('<div class="acf_datepicker" />');
45
- };
46
 
 
47
 
48
- /*-------------------------------------------
49
- Image Upload
50
- -------------------------------------------*/
51
- $.fn.make_acf_image = function(){
52
 
53
- var div = $(this);
 
 
 
 
 
 
 
 
54
 
55
- div.find('input.button').click(function(){
56
-
57
- // set global var
58
- window.acf_div = div;
59
 
 
 
 
60
 
61
- // show the thickbox
62
- tb_show('Add Image to field', 'media-upload.php?type=image&acf_type=image&TB_iframe=1');
63
-
64
-
65
- return false;
66
- });
67
-
68
-
69
- div.find('a.remove_image').unbind('click').click(function()
70
- {
71
- div.find('input.value').val('');
72
- div.removeClass('active');
73
 
74
- return false;
75
  });
76
  };
77
 
78
 
79
- /*-------------------------------------------
80
- File Upload
81
- -------------------------------------------*/
82
- $.fn.make_acf_file = function(){
 
83
 
84
- var div = $(this);
85
-
86
 
87
- div.find('p.no_file input.button').click(function(){
 
 
88
 
89
- // set global var
90
- window.acf_div = div;
91
 
 
92
 
93
- // show the thickbox
94
- tb_show('Add File to field', 'media-upload.php?type=file&acf_type=file&TB_iframe=1');
 
 
 
 
 
 
95
 
96
 
97
- return false;
 
 
 
 
 
 
 
98
  });
99
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
- div.find('p.file input.button').unbind('click').click(function()
103
- {
104
- div.find('input.value').val('');
105
- div.removeClass('active');
106
-
107
- return false;
108
  });
 
109
  };
110
 
111
 
 
 
 
 
 
112
 
113
- /*-------------------------------------------
114
- Repeaters
115
- -------------------------------------------*/
116
- $.fn.make_acf_repeater = function(){
117
 
118
- // vars
119
- var div = $(this);
120
- var add_field = div.find('a#add_field');
121
- var row_limit = parseInt(div.children('input[name="row_limit"]').val());
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
- /*-------------------------------------------
125
- Add Field Button
126
- -------------------------------------------*/
127
- add_field.unbind("click").click(function(){
 
 
 
 
128
 
129
- var field_count = div.children('table').children('tbody').children('tr').length;
130
- if(field_count >= row_limit)
131
  {
132
  // reached row limit!
133
-
134
- add_field.attr('disabled','true');
135
  return false;
136
  }
137
 
138
- // clone last tr
139
- var new_field = div.children('table').children('tbody').children('tr').last().clone(false);
 
 
 
140
 
141
- // append to table
142
- div.children('table').children('tbody').append(new_field);
 
 
 
143
 
144
- // set new field
145
- new_field.reset_values();
146
 
147
- // re make special fields
148
- new_field.make_all_fields();
149
-
150
- // update order numbers
151
- update_order_numbers();
152
 
153
- if(div.children('table').children('tbody').children('tr').length > 1)
 
154
  {
155
- div.removeClass('hide_remove_buttons');
156
  }
157
 
158
- if((field_count+1) >= row_limit)
 
159
  {
160
- // reached row limit!
161
- add_field.attr('disabled','true');
162
  }
163
 
164
  return false;
165
 
166
  });
167
 
168
- div.add_remove_buttons();
169
 
170
- if(row_limit > 1){
171
- div.make_sortable();
172
- }
173
-
174
-
175
- if(div.children('table').children('tbody').children('tr').length == 1)
176
- {
177
- div.addClass('hide_remove_buttons');
178
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
- var field_count = div.children('table').children('tbody').children('tr').length;
181
- if(field_count >= row_limit)
182
- {
183
- add_field.attr('disabled','true');
184
- }
185
 
186
  };
187
 
188
 
189
- /*-------------------------------------------
190
- Update Order Numbers
191
- -------------------------------------------*/
192
- function update_order_numbers(){
193
- $('.postbox#acf_input .repeater').each(function(){
194
- $(this).children('table').children('tbody').children('tr').each(function(i){
195
- $(this).children('td.order').html(i+1);
196
- });
197
-
 
198
  });
 
199
  }
200
 
201
- /*-------------------------------------------
202
- Sortable
203
- -------------------------------------------*/
 
 
 
204
  $.fn.make_sortable = function(){
205
 
206
  //alert('make sortable');
207
- var div = $(this);
208
 
209
  var fixHelper = function(e, ui) {
210
  ui.children().each(function() {
@@ -213,45 +301,45 @@
213
  return ui;
214
  };
215
 
216
- div.children('table').children('tbody').unbind('sortable').sortable({
217
  update: function(event, ui){
218
- update_order_numbers();
219
- $(this).make_all_fields();
220
- //alert('update');
221
- },
 
 
222
  handle: 'td.order',
223
  helper: fixHelper,
224
- //pre process stuff as soon as the element has been lifted
225
  start: function(event, ui)
226
  {
227
  //console.log(ui.item);
228
- if(ui.item.find('.acf_wysiwyg').exists())
229
  {
230
- //console.log('aaaah, i found a wysiwyg')
231
  var id = ui.item.find('.acf_wysiwyg textarea').attr('id');
232
- //alert(tinyMCE.get(id).getContent());
233
  tinyMCE.execCommand("mceRemoveControl", false, id);
234
- }
235
  },
236
-
237
- //post process stuff as soon as the element has been dropped
238
  stop: function(event, ui)
239
  {
240
- if(ui.item.find('.acf_wysiwyg').exists())
 
241
  {
242
  var id = ui.item.find('.acf_wysiwyg textarea').attr('id');
243
  tinyMCE.execCommand("mceAddControl", false, id);
244
- //div.make_sortable();
245
- }
246
  }
247
  });
248
  }
249
 
250
 
251
 
252
- /*-------------------------------------------
253
- Reset Values
254
- -------------------------------------------*/
 
 
 
255
  $.fn.reset_values = function(){
256
 
257
  var div = $(this);
@@ -331,78 +419,17 @@
331
 
332
  };
333
 
334
- $.fn.make_all_fields = function()
335
- {
336
- var div = $(this);
337
-
338
- // wysiwyg
339
- div.find('.acf_wysiwyg').each(function(){
340
- $(this).make_acf_wysiwyg();
341
- });
342
-
343
- // datepicker
344
- div.find('.acf_datepicker').each(function(){
345
- $(this).make_acf_datepicker();
346
- });
347
-
348
- // image
349
- div.find('.acf_image_uploader').each(function(){
350
- $(this).make_acf_image();
351
- });
352
-
353
- // file
354
- div.find('.acf_file_uploader').each(function(){
355
- $(this).make_acf_file();
356
- });
357
- };
358
-
359
-
360
- /*-------------------------------------------
361
- Remove Field Button
362
- -------------------------------------------*/
363
- $.fn.add_remove_buttons = function(){
364
- $(this).find('a.remove_field').unbind('click').live('click', function(){
365
-
366
- var total_fields = $(this).closest('.repeater').children('table').children('tbody').children('tr').length;
367
-
368
- // needs at least one
369
- if(total_fields <= 1)
370
- {
371
- return false;
372
- }
373
- else if(total_fields == 2)
374
- {
375
- // total fields will be 1 after the tr is removed
376
- $(this).parents('.repeater').addClass('hide_remove_buttons');
377
- }
378
-
379
- var tr = $(this).closest('tr');
380
-
381
- tr.animate({'opacity':'0'}, 300,function(){
382
- tr.remove();
383
- update_order_numbers();
384
- });
385
-
386
-
387
- $(this).closest('.repeater').find('a#add_field').removeAttr('disabled');
388
-
389
-
390
- return false;
391
-
392
- });
393
- };
394
-
395
 
 
 
 
 
 
396
 
397
-
398
- /*-------------------------------------------
399
- Document Ready
400
- -------------------------------------------*/
401
- $(document).ready(function(){
402
-
403
 
404
- post_id = $('form#post input#post_ID').val();
405
- var div = $('#acf_input');
406
 
407
 
408
  if(typeof(tinyMCE) != "undefined")
@@ -419,13 +446,24 @@
419
  }
420
 
421
 
422
- div.make_all_fields();
423
-
424
- // repeater
425
- div.find('.repeater').each(function(){
426
- $(this).make_acf_repeater();
427
- });
 
 
 
 
 
 
 
 
 
 
428
 
 
429
 
430
  });
431
 
1
+ window.acf_div = null;
2
+
3
  (function($){
4
 
5
+ /*----------------------------------------------------------------------
6
+ *
7
+ * Exists
8
+ *
9
+ *---------------------------------------------------------------------*/
10
+
11
  $.fn.exists = function()
12
  {
13
  return $(this).length>0;
14
  };
15
 
16
+
17
+
18
+ /*----------------------------------------------------------------------
19
+ *
20
+ * WYSIWYG
21
+ *
22
+ *---------------------------------------------------------------------*/
23
  var wysiwyg_count = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ $.fn.setup_wysiwyg = function()
 
 
 
26
  {
 
 
 
 
 
27
 
28
+ $(this).find('.acf_wysiwyg').each(function(){
29
+
30
+
31
+ if($(this).find('table').exists())
32
+ {
33
+ //alert('had wysiwyg')
34
+ $(this).children('span').remove();
35
+ $(this).children('textarea').removeAttr('aria-hidden').removeAttr('style');
36
+ }
37
+
38
+ // get a unique id
39
+ wysiwyg_count = wysiwyg_count + 1;
40
+
41
+ // add id
42
+ var id = 'acf_wysiwyg_'+wysiwyg_count;
43
+ $(this).find('textarea').attr('id',id);
44
+
45
+ // create wysiwyg
46
+ tinyMCE.execCommand('mceAddControl', false, id);
47
+
48
+
49
+
50
  });
 
 
 
51
 
52
+ }
53
 
 
 
 
 
54
 
55
+ /*----------------------------------------------------------------------
56
+ *
57
+ * Datepicker
58
+ *
59
+ *---------------------------------------------------------------------*/
60
+
61
+ $.fn.setup_datepicker = function()
62
+ {
63
+ $(this).find('.acf_datepicker').each(function(){
64
 
65
+ var format = $(this).attr('data-date_format') ? $(this).attr('data-date_format') : 'dd/mm/yy';
 
 
 
66
 
67
+ $(this).datepicker({
68
+ dateFormat: format
69
+ });
70
 
71
+ $('#ui-datepicker-div').wrap('<div class="acf_datepicker" />');
 
 
 
 
 
 
 
 
 
 
 
72
 
 
73
  });
74
  };
75
 
76
 
77
+ /*----------------------------------------------------------------------
78
+ *
79
+ * Image
80
+ *
81
+ *---------------------------------------------------------------------*/
82
 
83
+ $.fn.setup_image = function(){
 
84
 
85
+ var post_id = $('input#post_ID').val();
86
+
87
+ $(this).find('.acf_image_uploader').each(function(){
88
 
89
+ var div = $(this);
 
90
 
91
+ div.find('input.button').unbind('click').click(function(){
92
 
93
+ // set global var
94
+ window.acf_div = div;
95
+
96
+ // show the thickbox
97
+ tb_show('Add Image to field', 'media-upload.php?post_id='+post_id+'&type=image&acf_type=image&TB_iframe=1');
98
+
99
+ return false;
100
+ });
101
 
102
 
103
+ div.find('a.remove_image').unbind('click').click(function()
104
+ {
105
+ div.find('input.value').val('');
106
+ div.removeClass('active');
107
+
108
+ return false;
109
+ });
110
+
111
  });
112
 
113
+ };
114
+
115
+
116
+ /*----------------------------------------------------------------------
117
+ *
118
+ * File
119
+ *
120
+ *---------------------------------------------------------------------*/
121
+
122
+ $.fn.setup_file = function(){
123
+
124
+ $(this).find('.acf_file_uploader').each(function(){
125
 
126
+ var div = $(this);
127
+
128
+ div.find('p.no_file input.button').click(function(){
129
+
130
+ // set global var
131
+ window.acf_div = div;
132
+
133
+ // show the thickbox
134
+ tb_show('Add File to field', 'media-upload.php?type=file&acf_type=file&TB_iframe=1');
135
+
136
+ return false;
137
+ });
138
+
139
+
140
+ div.find('p.file input.button').unbind('click').click(function()
141
+ {
142
+ div.find('input.value').val('');
143
+ div.removeClass('active');
144
+
145
+ return false;
146
+ });
147
 
 
 
 
 
 
 
148
  });
149
+
150
  };
151
 
152
 
153
+ /*----------------------------------------------------------------------
154
+ *
155
+ * Repeater
156
+ *
157
+ *---------------------------------------------------------------------*/
158
 
159
+ $.fn.setup_repeater = function(){
 
 
 
160
 
161
+ $(this).find('.repeater').each(function(){
 
 
 
162
 
163
+ var r = $(this);
164
+ var row_limit = parseInt(r.attr('data-row_limit'));
165
+ var row_count = r.children('table').children('tbody').children('tr').length;
166
+
167
+ // has limit been reached?
168
+ if(row_count >= row_limit)
169
+ {
170
+ r.find('#add_field').attr('disabled','true');
171
+ //return false;
172
+ }
173
+
174
+ // sortable
175
+ if(row_limit > 1){
176
+ r.make_sortable();
177
+ }
178
+
179
+ if(row_count == 1)
180
+ {
181
+ r.addClass('hide_remove_buttons');
182
+ }
183
+ });
184
 
185
+
186
+ // add field
187
+ $('.repeater #add_field').die('click');
188
+ $('.repeater #add_field').live('click', function(){
189
+
190
+ var r = $(this).closest('.repeater');
191
+ var row_limit = parseInt(r.attr('data-row_limit'));
192
+ var row_count = r.children('table').children('tbody').children('tr').length;
193
 
194
+ // row limit
195
+ if(row_count >= row_limit)
196
  {
197
  // reached row limit!
198
+ r.find('#add_field').attr('disabled','true');
 
199
  return false;
200
  }
201
 
202
+ // create and add the new field
203
+ var new_field = r.children('table').children('tbody').children('tr:last-child').clone(false);
204
+ r.children('table').children('tbody').append(new_field);
205
+
206
+ new_field.reset_values();
207
 
208
+ // setup sub fields
209
+ new_field.setup_wysiwyg();
210
+ new_field.setup_datepicker();
211
+ new_field.setup_image();
212
+ new_field.setup_file();
213
 
214
+ r.update_order_numbers();
 
215
 
216
+ // there is now 1 more row
217
+ row_count ++;
 
 
 
218
 
219
+ // hide remove buttons if only 1 field
220
+ if(row_count > 1)
221
  {
222
+ r.removeClass('hide_remove_buttons');
223
  }
224
 
225
+ // disable the add field button if row limit is reached
226
+ if((row_count+1) >= row_limit)
227
  {
228
+ r.find('#add_field').attr('disabled','true');
 
229
  }
230
 
231
  return false;
232
 
233
  });
234
 
 
235
 
236
+ // remove field
237
+ $('.repeater a.remove_field').die('click');
238
+ $('.repeater a.remove_field').live('click', function(){
239
+
240
+ var r = $(this).closest('.repeater');
241
+ var row_count = r.children('table').children('tbody').children('tr').length;
242
+
243
+ // needs at least one
244
+ if(row_count <= 1)
245
+ {
246
+ return false;
247
+ }
248
+ else if(row_count == 2)
249
+ {
250
+ // total fields will be 1 after the tr is removed
251
+ r.addClass('hide_remove_buttons');
252
+ }
253
+
254
+ var tr = $(this).closest('tr');
255
+
256
+ tr.find('td').animate({'opacity':'0', 'height' : '0px'}, 300,function(){
257
+ tr.remove();
258
+ r.update_order_numbers();
259
+ });
260
+
261
+
262
+ r.find('#add_field').removeAttr('disabled');
263
+
264
+ return false;
265
+
266
+ });
267
 
 
 
 
 
 
268
 
269
  };
270
 
271
 
272
+ /*----------------------------------------------------------------------
273
+ *
274
+ * Update Order Numbers
275
+ *
276
+ *---------------------------------------------------------------------*/
277
+
278
+ $.fn.update_order_numbers = function(){
279
+
280
+ $(this).children('table').children('tbody').children('tr').each(function(i){
281
+ $(this).children('td.order').html(i+1);
282
  });
283
+
284
  }
285
 
286
+
287
+ /*----------------------------------------------------------------------
288
+ *
289
+ * Sortable
290
+ *
291
+ *---------------------------------------------------------------------*/
292
  $.fn.make_sortable = function(){
293
 
294
  //alert('make sortable');
295
+ var r = $(this);
296
 
297
  var fixHelper = function(e, ui) {
298
  ui.children().each(function() {
301
  return ui;
302
  };
303
 
304
+ r.children('table').children('tbody').unbind('sortable').sortable({
305
  update: function(event, ui){
306
+ r.update_order_numbers();
307
+ r.setup_wysiwyg();
308
+ r.setup_datepicker();
309
+ r.setup_image();
310
+ r.setup_file();
311
+ },
312
  handle: 'td.order',
313
  helper: fixHelper,
 
314
  start: function(event, ui)
315
  {
316
  //console.log(ui.item);
317
+ /*if(ui.item.find('.acf_wysiwyg').exists())
318
  {
 
319
  var id = ui.item.find('.acf_wysiwyg textarea').attr('id');
 
320
  tinyMCE.execCommand("mceRemoveControl", false, id);
321
+ }*/
322
  },
 
 
323
  stop: function(event, ui)
324
  {
325
+ ui.item.setup_wysiwyg();
326
+ /*if(ui.item.find('.acf_wysiwyg').exists())
327
  {
328
  var id = ui.item.find('.acf_wysiwyg textarea').attr('id');
329
  tinyMCE.execCommand("mceAddControl", false, id);
330
+ }*/
 
331
  }
332
  });
333
  }
334
 
335
 
336
 
337
+ /*----------------------------------------------------------------------
338
+ *
339
+ * reset_values
340
+ *
341
+ *---------------------------------------------------------------------*/
342
+
343
  $.fn.reset_values = function(){
344
 
345
  var div = $(this);
419
 
420
  };
421
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
 
423
+ /*----------------------------------------------------------------------
424
+ *
425
+ * Setup ACF
426
+ *
427
+ *---------------------------------------------------------------------*/
428
 
429
+ $.fn.setup_acf = function()
430
+ {
 
 
 
 
431
 
432
+ var div = $('#acf_fields_ajax');
 
433
 
434
 
435
  if(typeof(tinyMCE) != "undefined")
446
  }
447
 
448
 
449
+ div.setup_wysiwyg();
450
+ div.setup_datepicker();
451
+ div.setup_image();
452
+ div.setup_file();
453
+ div.setup_repeater();
454
+ }
455
+
456
+
457
+
458
+ /*----------------------------------------------------------------------
459
+ *
460
+ * Document Ready
461
+ *
462
+ *---------------------------------------------------------------------*/
463
+
464
+ $(document).ready(function(){
465
 
466
+ $('body').setup_acf();
467
 
468
  });
469
 
js/functions.screen_extra.js CHANGED
@@ -48,6 +48,9 @@
48
 
49
  });
50
 
 
 
 
51
 
52
  });
53
 
48
 
49
  });
50
 
51
+ // add active to Settings Menu
52
+ $('#adminmenu #menu-settings').addClass('current');
53
+
54
 
55
  });
56
 
readme.txt CHANGED
@@ -81,6 +81,26 @@ http://support.plugins.elliotcondon.com/categories/advanced-custom-fields/
81
 
82
  == Changelog ==
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  = 2.0.5 =
85
  * New Feature: Import / Export
86
  * Bug Fixed: Wysiwyg javascript conflicts
81
 
82
  == Changelog ==
83
 
84
+ = 2.1.1 =
85
+ * Fixed Javascript bugs on edit pages
86
+
87
+ = 2.1.0 =
88
+ * Integrate acf_values and wp_postmeta! Values are now saved as custom fields!
89
+ * Ajax load in fields + update fields when the page / post is modified
90
+ * API has been completely re written for better performance
91
+ * Default Value - text / textarea
92
+ * New upgrade database message / system
93
+ * Separate upgrade / activate scripts
94
+ * Select / page link / post object add Null option
95
+ * Integrate with Duplicate Posts plugin
96
+ * New location rule: post format
97
+ * Repeater field attach image to post
98
+ * Location: add children to drop down menu for page parent
99
+ * Update script replaces image urls with their id's
100
+ * All images / Files save as id's now, api formats the value back into a url
101
+ * Simple CSS + JS improvements
102
+ * New Field: Radio Buttons (please note Firefox has a current bug with jquery and radio buttons with the checked attribute)
103
+
104
  = 2.0.5 =
105
  * New Feature: Import / Export
106
  * Bug Fixed: Wysiwyg javascript conflicts