Advanced Custom Fields - Version 1.1.0

Version Description

  • Lots of Field Type Bug Fixes
  • Now uses custom database tables to save and store data!
  • Lots of tidying up
  • New help button for location meta box
  • Added $post_id parameter to API functions (so you can get fields from any post / page)
  • Added support for key and value for select and checkbox field types
  • Re wrote most of the core files due to new database tables
  • Update script should copy across your old data to the new data system
  • Added True / False Field Type
Download this release

Release Info

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

Code changes from version 1.0.5 to 1.1.0

acf.php CHANGED
@@ -3,7 +3,7 @@
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, text, image, select, checkbox and more! Hide unwanted metaboxes and assign to any edit page!
6
- Version: 1.0.5
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
@@ -33,7 +33,7 @@ class Acf
33
  $this->dir = plugins_url('',__FILE__);
34
  $this->siteurl = get_bloginfo('url');
35
  $this->wpadminurl = admin_url();
36
- $this->version = '1.0.5';
37
 
38
  // set text domain
39
  load_plugin_textdomain('acf', false, $this->path.'/lang' );
@@ -48,13 +48,28 @@ class Acf
48
  add_action('admin_menu', array($this,'_admin_menu'));
49
  add_action('save_post', array($this, '_save_post'));
50
  add_action('admin_footer-edit.php', array($this, '_admin_footer'));
 
 
 
 
51
 
52
  //register_activation_hook(__FILE__, array($this,'activate'));
53
 
54
  return true;
55
  }
56
 
57
-
 
 
 
 
 
 
 
 
 
 
 
58
  /*---------------------------------------------------------------------------------------------
59
  * Init
60
  *
@@ -68,6 +83,29 @@ class Acf
68
  $this->_acf_post_type();
69
  }
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  /*---------------------------------------------------------------------------------------------
73
  * Save Post
@@ -84,6 +122,11 @@ class Acf
84
  // verify this with nonce because save_post can be triggered at other times
85
  if (!wp_verify_nonce($_POST['ei_noncename'], 'ei-n')) return $post_id;
86
 
 
 
 
 
 
87
  // set post ID if is a revision
88
  if(wp_is_post_revision($post_id))
89
  {
@@ -184,6 +227,7 @@ class Acf
184
  include('core/fields/file.php');
185
  include('core/fields/select.php');
186
  include('core/fields/checkbox.php');
 
187
  include('core/fields/page_link.php');
188
  include('core/fields/post_object.php');
189
  include('core/fields/date_picker/date_picker.php');
@@ -195,6 +239,7 @@ class Acf
195
  $array['file'] = new File($this->dir);
196
  $array['select'] = new Select($this);
197
  $array['checkbox'] = new Checkbox();
 
198
  $array['page_link'] = new Page_link($this);
199
  $array['post_object'] = new Post_object($this);
200
  $array['date_picker'] = new Date_picker($this->dir);
@@ -210,15 +255,15 @@ class Acf
210
  * @since 1.0.0
211
  *
212
  ---------------------------------------------------------------------------------------------*/
213
- function create_field($options)
214
  {
215
- if(!$this->fields[$options['type']])
216
  {
217
  echo 'error: Field Type does not exist!';
218
  return false;
219
  }
220
 
221
- $this->fields[$options['type']]->html($options);
222
  }
223
 
224
  /*---------------------------------------------------------------------------------------------
@@ -321,57 +366,42 @@ class Acf
321
  ---------------------------------------------------------------------------------------------*/
322
  function get_fields($acf_id)
323
  {
324
- $keys = get_post_custom_keys($acf_id);
325
-
326
- if(empty($keys))
327
- {
328
- return null;
329
- }
330
-
331
- $fields = array();
332
- for($i = 0; $i < 99; $i++)
333
- {
334
- if(in_array('_acf_field_'.$i.'_label',$keys))
335
- {
336
- $field = array(
337
- 'label' => get_post_meta($acf_id, '_acf_field_'.$i.'_label', true),
338
- 'name' => get_post_meta($acf_id, '_acf_field_'.$i.'_name', true),
339
- 'type' => get_post_meta($acf_id, '_acf_field_'.$i.'_type', true),
340
- 'options' => $this->string_to_clean_array(
341
- get_post_meta($acf_id, '_acf_field_'.$i.'_options', true)
342
- ),
343
- );
344
-
345
- // if matrix, it will have sub fields
346
- for($j = 0; $j < 99; $j++)
347
- {
348
- if(in_array('_acf_field_'.$i.'_field_'.$j.'_label',$keys))
349
- {
350
- $field['options']['repeaters'][] = array(
351
- 'label' => get_post_meta($acf_id, '_acf_field_'.$i.'_field_'.$j.'_label', true),
352
- 'name' => get_post_meta($acf_id, '_acf_field_'.$i.'_field_'.$j.'_name', true),
353
- 'type' => get_post_meta($acf_id, '_acf_field_'.$i.'_field_'.$j.'_type', true),
354
- );
355
- }
356
- else
357
- {
358
- // data doesnt exist, break loop
359
- //echo 'not in array, field = '.$field['label'].'<br>';
360
- break;
361
- }
362
- }
363
 
364
- $fields[] = $field;
365
-
366
- }
367
- else
368
- {
369
- // data doesnt exist, break loop
370
- break;
371
- }
372
- }
 
 
373
 
374
- return $fields;
375
  }
376
 
377
  /*---------------------------------------------------------------------------------------------
@@ -410,20 +440,46 @@ class Acf
410
  ---------------------------------------------------------------------------------------------*/
411
  function get_acf_location($acf_id)
412
  {
413
- $location = array(
414
- 'post_type' => get_post_meta($acf_id, '_acf_location_post_type', true),
415
- 'page_slug' => get_post_meta($acf_id, '_acf_location_page_slug', true),
416
- 'post_id' => get_post_meta($acf_id, '_acf_location_post_id', true),
417
- 'page_template' => get_post_meta($acf_id, '_acf_location_page_template', true),
418
- 'parent_id' => get_post_meta($acf_id, '_acf_location_parent_id', true),
419
- 'ignore_other_acf' => get_post_meta($acf_id, '_acf_location_ignore_other_acf', true),
420
- );
421
-
422
- // post type needs to be in array format
423
- //$location['post_type'] = str_replace(', ',',',$location['post_type']);
424
- //$location['post_type'] = explode(',',$location['post_type']);
425
-
426
- return $location;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427
  }
428
 
429
 
@@ -436,116 +492,142 @@ class Acf
436
  ---------------------------------------------------------------------------------------------*/
437
  function get_acf_options($acf_id)
438
  {
439
- $options = array();
440
 
441
- $keys = get_post_custom_keys($acf_id);
 
 
 
 
 
 
 
 
442
 
443
- if(empty($keys))
444
- {
445
- $options['show_on_page'] = 'the_content, discussion, custom_fields, comments, slug, author';
446
- }
447
- else
 
 
 
 
 
448
  {
449
- $options['show_on_page'] = get_post_meta($acf_id, '_acf_option_show_on_page', true);
 
 
450
  }
451
 
452
- return $options;
 
 
 
 
 
 
 
 
 
 
 
 
 
453
  }
454
-
455
-
456
- /*---------------------------------------------------------------------------------------------
457
- * add_to_Edit_screen
458
  *
459
  * @author Elliot Condon
460
  * @since 1.0.0
461
  *
462
  ---------------------------------------------------------------------------------------------*/
463
- function add_to_edit_screen()
464
  {
465
-
 
 
 
 
 
466
  }
467
 
468
-
469
  /*---------------------------------------------------------------------------------------------
470
- * string_to_clean_array
471
  *
472
  * @author Elliot Condon
473
- * @since 1.0.0
474
  *
475
  ---------------------------------------------------------------------------------------------*/
476
- function string_to_clean_array($string)
477
- {
478
- if(!is_array(unserialize($string)))
479
- {
480
- return array();
481
- }
482
-
483
- $array = unserialize($string);
484
- /*print_r($string);
485
-
486
- foreach($array as $key => $value)
487
- {
488
- if(is_array($value)) // options is an array, so unserialize it and strip slashes
489
- {
490
- $child_array = array();
491
- foreach($value as $child_key => $child_value)
492
- {
493
- $child_array[$child_key] = stripslashes($child_value);
494
- }
495
- $value[$key] = $child_array;
496
- }
497
- else // everythis else is a simple string.
498
- {
499
- $array[$key] = stripslashes($value);
500
- }
501
- }*/
502
- return $array;
503
- }
504
-
505
-
506
- /*---------------------------------------------------------------------------------------------
507
- * get_adv_options
508
- *
509
- * @author Elliot Condon
510
- * @since 1.0.0
511
- *
512
- ---------------------------------------------------------------------------------------------*/
513
- function get_adv_options($acf_id)
514
- {
515
- $adv = array();
516
-
517
- $adv['show_on_page'] = get_post_meta($acf_id, '_acf_option_show_on_page', true);
518
-
519
- if(empty($adv['show_on_page']))
520
  {
521
- $adv['show_on_page'] = array();
522
  }
523
  else
524
  {
525
- $adv['show_on_page'] = str_replace(', ',',',$adv['show_on_page']);
526
- $adv['show_on_page'] = explode(',',$adv['show_on_page']);
 
 
 
 
 
527
  }
528
-
529
- return $adv;
530
- }
531
-
532
- /*---------------------------------------------------------------------------------------------
533
- * admin_footer
 
 
 
 
 
 
 
 
 
534
  *
535
  * @author Elliot Condon
536
- * @since 1.0.0
537
  *
538
  ---------------------------------------------------------------------------------------------*/
539
- function _admin_footer()
540
  {
541
- if($_GET['post_type'] != 'acf'){return false;}
 
 
 
 
 
 
 
 
 
 
 
 
 
542
 
543
- echo "<style type='text/css'>.row-actions span.inline, .row-actions span.view { display: none; }</style>";
544
- echo '<link rel="stylesheet" href="'.$this->dir.'/css/style.info.css" type="text/css" media="all" />';
545
- echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.info.js"></script>';
546
- include('core/info_meta_box.php');
 
 
 
 
 
 
547
  }
548
 
549
-
550
 
551
- }
 
 
 
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, text, image, select, checkbox and more! Hide unwanted metaboxes and assign to any edit page!
6
+ Version: 1.1.0
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
33
  $this->dir = plugins_url('',__FILE__);
34
  $this->siteurl = get_bloginfo('url');
35
  $this->wpadminurl = admin_url();
36
+ $this->version = '1.1.0';
37
 
38
  // set text domain
39
  load_plugin_textdomain('acf', false, $this->path.'/lang' );
48
  add_action('admin_menu', array($this,'_admin_menu'));
49
  add_action('save_post', array($this, '_save_post'));
50
  add_action('admin_footer-edit.php', array($this, '_admin_footer'));
51
+
52
+ // add thickbox
53
+ add_action("admin_print_scripts", array($this, '_admin_print_scripts'));
54
+ add_action("admin_print_styles", array($this, '_admin_print_styles'));
55
 
56
  //register_activation_hook(__FILE__, array($this,'activate'));
57
 
58
  return true;
59
  }
60
 
61
+ /*---------------------------------------------------------------------------------------------
62
+ * Update
63
+ *
64
+ * @author Elliot Condon
65
+ * @since 1.0.6
66
+ *
67
+ ---------------------------------------------------------------------------------------------*/
68
+ function update()
69
+ {
70
+ include('core/update.php');
71
+ }
72
+
73
  /*---------------------------------------------------------------------------------------------
74
  * Init
75
  *
83
  $this->_acf_post_type();
84
  }
85
 
86
+ function _admin_print_scripts()
87
+ {
88
+ $currentFile = $_SERVER["SCRIPT_NAME"];
89
+ $parts = Explode('/', $currentFile);
90
+ $currentFile = $parts[count($parts) - 1];
91
+
92
+ if($currentFile == 'edit.php')
93
+ {
94
+ wp_enqueue_script('thickbox');
95
+ }
96
+ }
97
+
98
+ function _admin_print_styles()
99
+ {
100
+ $currentFile = $_SERVER["SCRIPT_NAME"];
101
+ $parts = Explode('/', $currentFile);
102
+ $currentFile = $parts[count($parts) - 1];
103
+
104
+ if($currentFile == 'edit.php')
105
+ {
106
+ wp_enqueue_style('thickbox');
107
+ }
108
+ }
109
 
110
  /*---------------------------------------------------------------------------------------------
111
  * Save Post
122
  // verify this with nonce because save_post can be triggered at other times
123
  if (!wp_verify_nonce($_POST['ei_noncename'], 'ei-n')) return $post_id;
124
 
125
+ // only save once! WordPress save's twice for some strange reason.
126
+ global $flag;
127
+ if ($flag != 0) return $post_id;
128
+ $flag = 1;
129
+
130
  // set post ID if is a revision
131
  if(wp_is_post_revision($post_id))
132
  {
227
  include('core/fields/file.php');
228
  include('core/fields/select.php');
229
  include('core/fields/checkbox.php');
230
+ include('core/fields/true_false.php');
231
  include('core/fields/page_link.php');
232
  include('core/fields/post_object.php');
233
  include('core/fields/date_picker/date_picker.php');
239
  $array['file'] = new File($this->dir);
240
  $array['select'] = new Select($this);
241
  $array['checkbox'] = new Checkbox();
242
+ $array['true_false'] = new True_false();
243
  $array['page_link'] = new Page_link($this);
244
  $array['post_object'] = new Post_object($this);
245
  $array['date_picker'] = new Date_picker($this->dir);
255
  * @since 1.0.0
256
  *
257
  ---------------------------------------------------------------------------------------------*/
258
+ function create_field($field)
259
  {
260
+ if(!$this->fields[$field->type])
261
  {
262
  echo 'error: Field Type does not exist!';
263
  return false;
264
  }
265
 
266
+ $this->fields[$field->type]->html($field);
267
  }
268
 
269
  /*---------------------------------------------------------------------------------------------
366
  ---------------------------------------------------------------------------------------------*/
367
  function get_fields($acf_id)
368
  {
369
+
370
+ // If this is a new acf, there will be no custom keys!
371
+ if(!get_post_custom_keys($acf_id))
372
+ {
373
+ $fields = array();
374
+ $field = new stdClass();
375
+ $field->label = '';
376
+ $field->name = '';
377
+ $field->type = '';
378
+ $field->options = array();
379
+
380
+ $fields[] = $field;
381
+ return $fields;
382
+ }
383
+
384
+ // set table name
385
+ global $wpdb;
386
+ $table_name = $wpdb->prefix.'acf_fields';
387
+
388
+
389
+ // get fields
390
+ $fields = $wpdb->get_results("SELECT * FROM $table_name WHERE post_id = '$acf_id' ORDER BY order_no,name");
391
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392
 
393
+ // loop through fields
394
+ foreach($fields as $field)
395
+ {
396
+ // unserialize options
397
+ $field->options = unserialize($field->options);
398
+ }
399
+
400
+
401
+ // return fields
402
+ return $fields;
403
+
404
 
 
405
  }
406
 
407
  /*---------------------------------------------------------------------------------------------
440
  ---------------------------------------------------------------------------------------------*/
441
  function get_acf_location($acf_id)
442
  {
443
+
444
+ // set table name
445
+ global $wpdb;
446
+ $table_name = $wpdb->prefix.'acf_options';
447
+
448
+
449
+ // get fields and add them to $options
450
+ $location = new stdClass();
451
+ $db_locations = $wpdb->get_results("SELECT name, value FROM $table_name WHERE acf_id = '$acf_id' AND type = 'location'");
452
+
453
+ foreach($db_locations as $db_location)
454
+ {
455
+ $key = $db_location->name;
456
+ $value = $db_location->value;
457
+ $location->$key = $value;
458
+ }
459
+
460
+
461
+ // unserialize values
462
+ $location->post_types = unserialize($location->post_types);
463
+ $location->page_titles = unserialize($location->page_titles);
464
+ $location->page_slugs = unserialize($location->page_slugs);
465
+ $location->post_ids = unserialize($location->post_ids);
466
+ $location->page_templates = unserialize($location->page_templates);
467
+ $location->page_parents = unserialize($location->page_parents);
468
+
469
+
470
+ // if empty
471
+ if(empty($location->post_types)){$location->post_types = array();}
472
+ if(empty($location->page_titles)){$location->page_titles = array();}
473
+ if(empty($location->page_slugs)){$location->page_slugs = array();}
474
+ if(empty($location->post_ids)){$location->post_ids = array();}
475
+ if(empty($location->page_templates)){$location->page_templates = array();}
476
+ if(empty($location->page_parents)){$location->page_parents = array();}
477
+ if(empty($location->page_parents)){$location->page_parents = array();}
478
+
479
+
480
+ // return location
481
+ return $location;
482
+
483
  }
484
 
485
 
492
  ---------------------------------------------------------------------------------------------*/
493
  function get_acf_options($acf_id)
494
  {
495
+ $options = new stdClass();
496
 
497
+
498
+ // If this is a new acf, there will be no custom keys!
499
+ if(!get_post_custom_keys($acf_id))
500
+ {
501
+ $options->show_on_page = array('the_content', 'discussion', 'custom_fields', 'comments', 'slug', 'author');
502
+ $options->user_roles = array('10', '7', '4', '1');
503
+
504
+ return $options;
505
+ }
506
 
507
+
508
+ // set table name
509
+ global $wpdb;
510
+ $table_name = $wpdb->prefix.'acf_options';
511
+
512
+
513
+ // get fields and add them to $options
514
+ $db_options = $wpdb->get_results("SELECT name, value FROM $table_name WHERE acf_id = '$acf_id' AND type = 'option'");
515
+
516
+ foreach($db_options as $db_option)
517
  {
518
+ $key = $db_option->name;
519
+ $value = $db_option->value;
520
+ $options->$key = $value;
521
  }
522
 
523
+
524
+ // unserialize options
525
+ $options->show_on_page = unserialize($options->show_on_page);
526
+ $options->user_roles = unserialize($options->user_roles);
527
+
528
+
529
+ // if empty
530
+ if(empty($options->show_on_page)){$options->show_on_page = array();}
531
+ if(empty($options->user_roles)){$options->user_roles = array('10', '7', '4', '1');}
532
+
533
+
534
+ // return fields
535
+ return $options;
536
+
537
  }
538
+
539
+
540
+ /*---------------------------------------------------------------------------------------------
541
+ * admin_footer
542
  *
543
  * @author Elliot Condon
544
  * @since 1.0.0
545
  *
546
  ---------------------------------------------------------------------------------------------*/
547
+ function _admin_footer()
548
  {
549
+ if($_GET['post_type'] != 'acf'){return false;}
550
+
551
+ echo "<style type='text/css'>.row-actions span.inline, .row-actions span.view { display: none; }</style>";
552
+ echo '<link rel="stylesheet" href="'.$this->dir.'/css/style.info.css" type="text/css" media="all" />';
553
+ echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.info.js"></script>';
554
+ include('core/info_meta_box.php');
555
  }
556
 
 
557
  /*---------------------------------------------------------------------------------------------
558
+ * load_value_for_input
559
  *
560
  * @author Elliot Condon
561
+ * @since 1.0.6
562
  *
563
  ---------------------------------------------------------------------------------------------*/
564
+ function load_value_for_input($post_id, $field)
565
+ {
566
+ if(method_exists($this->fields[$field->type], 'load_value_for_input'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
567
  {
568
+ $value = $this->fields[$field->type]->load_value_for_input($post_id, $field);
569
  }
570
  else
571
  {
572
+ // set table name
573
+ global $wpdb;
574
+ $table_name = $wpdb->prefix.'acf_values';
575
+
576
+
577
+ // get var
578
+ $value = $wpdb->get_var("SELECT value FROM $table_name WHERE field_id = '$field->id' AND post_id = '$post_id'");
579
  }
580
+
581
+
582
+ // format if needed
583
+ if(method_exists($this->fields[$field->type], 'format_value_for_input'))
584
+ {
585
+ $value = $this->fields[$field->type]->format_value_for_input($value);
586
+ }
587
+
588
+
589
+ // return value
590
+ return $value;
591
+ }
592
+
593
+ /*---------------------------------------------------------------------------------------------
594
+ * load_value_for_input
595
  *
596
  * @author Elliot Condon
597
+ * @since 1.0.6
598
  *
599
  ---------------------------------------------------------------------------------------------*/
600
+ function load_value_for_api($post_id, $field)
601
  {
602
+ if(method_exists($this->fields[$field->type], 'load_value_for_api'))
603
+ {
604
+ $value = $this->fields[$field->type]->load_value_for_api($post_id, $field);
605
+ }
606
+ else
607
+ {
608
+ // set table name
609
+ global $wpdb;
610
+ $table_name = $wpdb->prefix.'acf_values';
611
+
612
+
613
+ // get var
614
+ $value = $wpdb->get_var("SELECT value FROM $table_name WHERE field_id = '$field->id' AND post_id = '$post_id'");
615
+ }
616
 
617
+
618
+ // format if needed
619
+ if(method_exists($this->fields[$field->type], 'format_value_for_api'))
620
+ {
621
+ $value = $this->fields[$field->type]->format_value_for_api($value);
622
+ }
623
+
624
+
625
+ // return value
626
+ return $value;
627
  }
628
 
 
629
 
630
+ }
631
+
632
+ // update on activate
633
+ register_activation_hook( __FILE__, array('Acf', 'update') );
core/acf_post_type.php CHANGED
@@ -32,5 +32,4 @@ register_post_type('acf', array(
32
  'supports' => $supports,
33
  ));
34
 
35
-
36
  ?>
32
  'supports' => $supports,
33
  ));
34
 
 
35
  ?>
core/admin_head.php CHANGED
@@ -3,21 +3,17 @@
3
  global $post;
4
 
5
  // shows hidden custom fields
6
- echo "<style type='text/css'>#postcustom .hidden { display: table-row; }</style>";
7
-
8
- // add metabox, style and javascript to acf page
9
- //if($_GET['post_type'] == 'acf')
10
- //{
11
- // not edit screen
12
- //}
13
 
 
14
  $currentFile = $_SERVER["SCRIPT_NAME"];
15
  $parts = Explode('/', $currentFile);
16
  $currentFile = $parts[count($parts) - 1];
17
 
 
18
  if($currentFile == 'edit.php')
19
  {
20
-
21
  }
22
  elseif(get_post_type($post) == 'acf')
23
  {
@@ -54,48 +50,43 @@ else
54
 
55
  // get options of matrix
56
  $location = $this->get_acf_location($acf->ID);
57
- //print_r($location);
 
58
 
59
  // post type
60
- if($location['post_type'] != '')
61
- {
62
- $post_types = explode(',',str_replace(' ','',$location['post_type']));
63
- if(in_array(get_post_type($post), $post_types)) {$add_box = true; }
64
- }
 
65
 
66
  // page slug
67
- if($location['page_slug'] != '')
68
- {
69
- $page_slugs = explode(',',str_replace(' ','',$location['page_slug']));
70
- if(in_array($post->post_name, $page_slugs)) {$add_box = true; }
71
- }
72
 
73
- // post ID
74
- if($location['post_id'] != '')
75
- {
76
- $post_ids = explode(',',str_replace(' ','',$location['post_id']));
77
- if(in_array($post->ID, $post_ids)) {$add_box = true; }
78
- }
79
 
80
  // page template
81
- if($location['page_template'] != '')
82
- {
83
- $page_template = explode(',',str_replace(' ','',$location['page_template']));
84
- if(in_array(get_post_meta($post->ID,'_wp_page_template',true), $page_template)) {$add_box = true;}
85
- }
86
 
87
- // parent id
88
- if($location['parent_id'] != '')
89
- {
90
- $parent_ids = explode(',',str_replace(' ','',$location['parent_id']));
91
- if(in_array($post->post_parent, $parent_ids)) {$add_box = true;}
92
-
93
- }
94
 
 
 
 
 
 
 
 
 
 
 
95
  if($add_box == true)
96
  {
97
  // Override
98
- if($location['ignore_other_acf'] == 'true')
99
  {
100
  // if ignore other acf's was ticked, override the $add_acf array and break the loop
101
  $add_acf = array($acf);
@@ -115,7 +106,6 @@ else
115
  // add these acf's to the page
116
  echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.global.css" />';
117
  echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.input.css" />';
118
- echo '<script type="text/javascript" src="'.$this->dir.'/js/swap.jquery.js" ></script>';
119
  echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.input.js" ></script>';
120
 
121
  add_meta_box('acf_input', 'ACF Fields', array($this, '_input_meta_box'), get_post_type($post), 'normal', 'high', array('acfs' => $add_acf));
3
  global $post;
4
 
5
  // shows hidden custom fields
6
+ //echo "<style type='text/css'>#postcustom .hidden { display: table-row; }</style>";
 
 
 
 
 
 
7
 
8
+ // get current page
9
  $currentFile = $_SERVER["SCRIPT_NAME"];
10
  $parts = Explode('/', $currentFile);
11
  $currentFile = $parts[count($parts) - 1];
12
 
13
+ // do stuff
14
  if($currentFile == 'edit.php')
15
  {
16
+
17
  }
18
  elseif(get_post_type($post) == 'acf')
19
  {
50
 
51
  // get options of matrix
52
  $location = $this->get_acf_location($acf->ID);
53
+ $options = $this->get_acf_options($acf->ID);
54
+
55
 
56
  // post type
57
+ if(in_array(get_post_type($post), $location->post_types)) {$add_box = true; }
58
+
59
+
60
+ // page title
61
+ if(in_array($post->post_title, $location->page_titles)) {$add_box = true; }
62
+
63
 
64
  // page slug
65
+ if(in_array($post->post_name, $location->page_slugs)) {$add_box = true; }
66
+
67
+
68
+ // post id
69
+ if(in_array($post->ID, $location->post_ids)) {$add_box = true; }
70
 
 
 
 
 
 
 
71
 
72
  // page template
73
+ if(in_array(get_post_meta($post->ID,'_wp_page_template',true), $location->page_templates)) {$add_box = true; }
 
 
 
 
74
 
 
 
 
 
 
 
 
75
 
76
+ // page parents
77
+ if(in_array($post->post_parent, $location->page_parents)) {$add_box = true; }
78
+
79
+
80
+ // current user role
81
+ global $current_user;
82
+ get_currentuserinfo();
83
+ if(!in_array($current_user->user_level, $options->user_roles)) {$add_box = false; }
84
+
85
+
86
  if($add_box == true)
87
  {
88
  // Override
89
+ if($location->ignore_other_acfs == '1')
90
  {
91
  // if ignore other acf's was ticked, override the $add_acf array and break the loop
92
  $add_acf = array($acf);
106
  // add these acf's to the page
107
  echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.global.css" />';
108
  echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.input.css" />';
 
109
  echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.input.js" ></script>';
110
 
111
  add_meta_box('acf_input', 'ACF Fields', array($this, '_input_meta_box'), get_post_type($post), 'normal', 'high', array('acfs' => $add_acf));
core/api.php CHANGED
@@ -1,10 +1,4 @@
1
  <?php
2
- /*---------------------------------------------------------------------------------------------
3
- * api.php
4
- *
5
- * @version 1.0.6
6
- ---------------------------------------------------------------------------------------------*/
7
-
8
  /*---------------------------------------------------------------------------------------------
9
  * acf_object
10
  *
@@ -18,8 +12,12 @@ class acf_object
18
  {
19
  foreach($variables as $key => $value)
20
  {
21
- $this->$key = $value;
22
- }
 
 
 
 
23
  }
24
 
25
  }
@@ -33,24 +31,32 @@ class acf_object
33
  ---------------------------------------------------------------------------------------------*/
34
  function get_acf($post_id = false)
35
  {
 
36
  global $acf;
37
- global $wpdb;
38
  global $post;
39
 
 
 
 
 
 
 
 
40
  if(!$post_id)
41
  {
42
  $post_id = $post->ID;
43
  }
44
 
45
- $results = array();
 
46
  $acf_id = explode(',',get_post_meta($post_id, '_acf_id', true));
47
 
48
- $fields = array();
49
-
50
- // checkpoint
51
 
 
52
  if(empty($acf_id)){return null;}
53
-
 
 
54
  foreach($acf_id as $id)
55
  {
56
  $this_fields = $acf->get_fields($id);
@@ -61,61 +67,78 @@ function get_acf($post_id = false)
61
  $fields[] = $this_field;
62
  }
63
  }
 
64
 
65
- // checkpoint
66
  if(empty($fields)){return null;}
67
 
68
- $variables = array();
69
 
70
  foreach($fields as $field)
71
  {
72
  // get value
73
- $field['value'] = get_post_meta($post_id, '_acf_'.$field['name'], true);
74
 
75
- // if field has a format function, format the value
76
- if($acf->fields[$field['type']]->has_format_value())
77
- {
78
- $field['value'] = $acf->fields[$field['type']]->format_value($field['value']);
79
- }
80
 
81
- // add name + value to variables array
82
- $variables[$field['name']] = $field['value'];
83
 
84
  }
85
 
86
- return new acf_object($variables);
 
 
 
 
 
 
 
 
 
 
 
87
 
88
 
89
  }
90
 
 
91
  // get fields
92
- function get_fields()
93
  {
94
- return get_acf();
95
  }
96
 
 
97
  // get field
98
- function get_field($field_name)
99
  {
100
  global $acf_fields;
101
  global $post;
102
 
 
 
 
 
 
 
 
103
  if(empty($acf_fields))
104
  {
105
  $acf_fields = array();
106
  }
107
- if(empty($acf_fields[$post->ID]))
108
  {
109
- $acf_fields[$post->ID] = get_acf();
110
  }
111
 
112
- return $acf_fields[$post->ID]->$field_name;
113
  }
114
 
 
115
  // the field
116
- function the_field($field_name)
117
  {
118
- echo get_field($field_name);
 
119
  }
120
 
121
  ?>
1
  <?php
 
 
 
 
 
 
2
  /*---------------------------------------------------------------------------------------------
3
  * acf_object
4
  *
12
  {
13
  foreach($variables as $key => $value)
14
  {
15
+ // field may exist but field name may be blank!!!
16
+ if($key)
17
+ {
18
+ $this->$key = $value;
19
+ }
20
+ }
21
  }
22
 
23
  }
31
  ---------------------------------------------------------------------------------------------*/
32
  function get_acf($post_id = false)
33
  {
34
+ // get global vars
35
  global $acf;
 
36
  global $post;
37
 
38
+
39
+ // create blank arrays
40
+ $fields = array();
41
+ $variables = array();
42
+
43
+
44
+ // if no ID was passed through, just use the $post->ID
45
  if(!$post_id)
46
  {
47
  $post_id = $post->ID;
48
  }
49
 
50
+
51
+ // get ID's for this post
52
  $acf_id = explode(',',get_post_meta($post_id, '_acf_id', true));
53
 
 
 
 
54
 
55
+ // checkpoint: If no id's exist for this page, get out of here!
56
  if(empty($acf_id)){return null;}
57
+
58
+
59
+ // loop through ID's
60
  foreach($acf_id as $id)
61
  {
62
  $this_fields = $acf->get_fields($id);
67
  $fields[] = $this_field;
68
  }
69
  }
70
+
71
 
72
+ // checkpoint: If no fields, get out of here!
73
  if(empty($fields)){return null;}
74
 
 
75
 
76
  foreach($fields as $field)
77
  {
78
  // get value
79
+ $field->value = $acf->load_value_for_api($post_id, $field);
80
 
 
 
 
 
 
81
 
82
+ // add this field: name => value
83
+ $variables[$field->name] = $field->value;
84
 
85
  }
86
 
87
+
88
+ // create a new obejct and give in variables
89
+ $object = new stdClass();
90
+
91
+ foreach($variables as $key => $value)
92
+ {
93
+ $object->$key = $value;
94
+ }
95
+
96
+
97
+ // return the object
98
+ return $object;
99
 
100
 
101
  }
102
 
103
+
104
  // get fields
105
+ function get_fields($post_id = false)
106
  {
107
+ return get_acf($post_id);
108
  }
109
 
110
+
111
  // get field
112
+ function get_field($field_name, $post_id = false)
113
  {
114
  global $acf_fields;
115
  global $post;
116
 
117
+ if(!$post_id)
118
+ {
119
+ $post_id = $post->ID;
120
+ }
121
+
122
+ //echo 'field name: '.$field_name.', post id: '.$post_id;
123
+
124
  if(empty($acf_fields))
125
  {
126
  $acf_fields = array();
127
  }
128
+ if(empty($acf_fields[$post_id]))
129
  {
130
+ $acf_fields[$post_id] = get_acf($post_id);
131
  }
132
 
133
+ return $acf_fields[$post_id]->$field_name;
134
  }
135
 
136
+
137
  // the field
138
+ function the_field($field_name, $post_id = false)
139
  {
140
+ //echo 'field name: '.$field_name.', post id: '.$post_id;
141
+ echo get_field($field_name, $post_id);
142
  }
143
 
144
  ?>
core/fields/checkbox.php CHANGED
@@ -11,95 +11,192 @@ class Checkbox
11
  $this->title = 'Checkbox';
12
  }
13
 
14
- function html($options)
15
  {
16
- if(empty($options['value']))
17
  {
18
- $options['value'] = array();
19
- }
20
- else
21
- {
22
- $options['value'] = str_replace(', ',',',$options['value']);
23
- $options['value'] = explode(',',$options['value']);
24
  }
25
 
26
- echo '<ul class="checkbox_list '.$options['class'].'">';
27
  // loop through values and add them as options
28
 
29
  $name_extra = '[]';
30
- if(count($options['options']['choices']) <= 1)
31
  {
32
  $name_extra = '';
33
  }
34
 
35
- foreach($options['options']['choices'] as $key => $value)
36
  {
37
  $selected = '';
38
- if(in_array($key, $options['value']))
39
  {
40
  $selected = 'checked="yes"';
41
  }
42
- echo '<li><input type="checkbox" class="'.$options['class'].'" name="'.$options['name'].$name_extra.'" value="'.$key.'" '.$selected.' />'.$value.'</li>';
43
  }
44
  echo '</ul>';
45
 
46
  }
47
-
48
- function has_options()
49
- {
50
- return true;
51
- }
52
-
53
- function options($key, $options)
 
 
 
 
 
54
  {
55
- //if($options['choices'] == ''){$options['choices'] = "option 1\noption 2\noption 3";}
 
 
 
 
 
 
 
 
 
56
  ?>
57
 
58
  <table class="acf_input">
59
  <tr>
60
  <td class="label">
61
  <label for="">Choices</label>
62
- <p>Enter your choices one per line. eg:<br />
63
- Option 1<br />
64
- Option 2 <br />
65
- Option 3</p>
66
  </td>
67
  <td>
68
  <textarea rows="5" name="acf[fields][<?php echo $key; ?>][options][choices]" id=""><?php echo $options['choices']; ?></textarea>
 
 
 
 
69
  </td>
70
  </tr>
71
  </table>
72
 
73
  <?php
74
  }
75
-
76
- function has_format_value()
 
 
 
 
 
 
 
 
 
 
77
  {
78
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  }
80
 
81
- function format_value($value)
82
- {
83
- $value = str_replace(', ',',',$value);
84
- $value = explode(',',$value);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
- if(!is_array($value))
 
 
87
  {
88
- $value = array($value);
 
 
 
 
 
 
 
 
 
89
  }
90
 
91
- return $value;
 
 
 
 
92
  }
93
 
94
- function save_field($post_id, $field_name, $field_value)
 
 
 
 
 
 
 
 
 
95
  {
96
- if(is_array($field_value))
97
  {
98
- $field_value = implode(',',$field_value);
99
  }
100
- add_post_meta($post_id, '_acf_'.$field_name, $field_value);
101
  }
102
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  }
104
 
105
  ?>
11
  $this->title = 'Checkbox';
12
  }
13
 
14
+ function html($field)
15
  {
16
+ if(empty($field->value))
17
  {
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
 
24
  $name_extra = '[]';
25
+ if(count($field->options['choices']) <= 1)
26
  {
27
  $name_extra = '';
28
  }
29
 
30
+ foreach($field->options['choices'] as $key => $value)
31
  {
32
  $selected = '';
33
+ if(in_array($key, $field->value))
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
 
41
  }
42
+
43
+
44
+ /*---------------------------------------------------------------------------------------------
45
+ * Options HTML
46
+ * - called from fields_meta_box.php
47
+ * - displays options in html format
48
+ *
49
+ * @author Elliot Condon
50
+ * @since 1.1
51
+ *
52
+ ---------------------------------------------------------------------------------------------*/
53
+ function options_html($key, $options)
54
  {
55
+ // implode checkboxes so they work in a textarea
56
+ if(!empty($options['choices']) && is_array($options['choices']))
57
+ {
58
+ foreach($options['choices'] as $choice_key => $choice_val)
59
+ {
60
+ $options['choices'][$choice_key] = $choice_key.' : '.$choice_val;
61
+ }
62
+ $options['choices'] = implode("\n", $options['choices']);
63
+ }
64
+
65
  ?>
66
 
67
  <table class="acf_input">
68
  <tr>
69
  <td class="label">
70
  <label for="">Choices</label>
 
 
 
 
71
  </td>
72
  <td>
73
  <textarea rows="5" name="acf[fields][<?php echo $key; ?>][options][choices]" id=""><?php echo $options['choices']; ?></textarea>
74
+ <p class="description">Enter your choices one per line. eg:<br />
75
+ option_1 : Option 1<br />
76
+ option_3 : Option 2<br />
77
+ option_3 : Option 3</p>
78
  </td>
79
  </tr>
80
  </table>
81
 
82
  <?php
83
  }
84
+
85
+
86
+ /*---------------------------------------------------------------------------------------------
87
+ * save input
88
+ * - called from fields_save.php
89
+ * - saves input data
90
+ *
91
+ * @author Elliot Condon
92
+ * @since 1.1
93
+ *
94
+ ---------------------------------------------------------------------------------------------*/
95
+ function save_input($post_id, $field)
96
  {
97
+ // set table name
98
+ global $wpdb;
99
+ $table_name = $wpdb->prefix.'acf_values';
100
+
101
+
102
+ // if select is a multiple, you need to save it as an array!
103
+ if(is_array($field['value']))
104
+ {
105
+ $field['value'] = serialize($field['value']);
106
+ }
107
+
108
+
109
+ // insert new data
110
+ $new_id = $wpdb->insert($table_name, array(
111
+ 'post_id' => $post_id,
112
+ 'field_id' => $field['field_id'],
113
+ 'value' => $field['value']
114
+ ));
115
  }
116
 
117
+
118
+ /*---------------------------------------------------------------------------------------------
119
+ * Format Options
120
+ * - this is called from save_field.php, this function formats the options into a savable format
121
+ *
122
+ * @author Elliot Condon
123
+ * @since 1.1
124
+ *
125
+ ---------------------------------------------------------------------------------------------*/
126
+ function format_options($options)
127
+ {
128
+ // if no choices, dont do anything
129
+ if($options['choices'] == '')
130
+ {
131
+ return $options;
132
+ }
133
+
134
+
135
+ // explode choices from each line
136
+ if(strpos($options['choices'], "\n") !== false)
137
+ {
138
+ // found multiple lines, explode it
139
+ $choices = explode("\n", $options['choices']);
140
+ }
141
+ else
142
+ {
143
+ // no multiple lines!
144
+ $choices = array($options['choices']);
145
+ }
146
+
147
 
148
+
149
+ $new_choices = array();
150
+ foreach($choices as $choice)
151
  {
152
+ if(strpos($choice, ':') !== false)
153
+ {
154
+
155
+ $choice = explode(':', $choice);
156
+ $new_choices[trim($choice[0])] = trim($choice[1]);
157
+ }
158
+ else
159
+ {
160
+ $new_choices[trim($choice)] = trim($choice);
161
+ }
162
  }
163
 
164
+
165
+ // return array containing all choices
166
+ $options['choices'] = $new_choices;
167
+
168
+ return $options;
169
  }
170
 
171
+
172
+ /*---------------------------------------------------------------------------------------------
173
+ * Format Value
174
+ * - this is called from api.php
175
+ *
176
+ * @author Elliot Condon
177
+ * @since 1.1
178
+ *
179
+ ---------------------------------------------------------------------------------------------*/
180
+ function format_value_for_api($value)
181
  {
182
+ if(is_array(unserialize($value)))
183
  {
184
+ return(unserialize($value));
185
  }
 
186
  }
187
 
188
+ /*---------------------------------------------------------------------------------------------
189
+ * Format Value for input
190
+ * - this is called from acf.php
191
+ *
192
+ * @author Elliot Condon
193
+ * @since 1.1
194
+ *
195
+ ---------------------------------------------------------------------------------------------*/
196
+ function format_value_for_input($value)
197
+ {
198
+ return $this->format_value_for_api($value);
199
+ }
200
  }
201
 
202
  ?>
core/fields/date_picker/date_picker.php CHANGED
@@ -13,21 +13,16 @@ class Date_picker
13
  $this->plugin_dir = $plugin_dir;
14
  }
15
 
16
- function html($options)
17
  {
18
  echo '<link rel="stylesheet" type="text/css" href="'.$this->plugin_dir.'/core/fields/date_picker/style.date_picker.css" />';
19
  echo '<script type="text/javascript" src="'.$this->plugin_dir.'/core/fields/date_picker/jquery.ui.datepicker.js" ></script>';
20
- echo '<input type="hidden" value="'.$options['options']['date_format'].'" name="date_format" />';
21
- echo '<input type="text" value="'.$options['value'].'" id="'.$options['id'].'" class="acf_datepicker" name="'.$options['name'].'" />';
22
 
23
  }
24
 
25
- function has_options()
26
- {
27
- return true;
28
- }
29
-
30
- function options($key, $options)
31
  {
32
  ?>
33
  <table class="acf_input">
@@ -44,17 +39,7 @@ class Date_picker
44
  <?php
45
  }
46
 
47
- function has_format_value()
48
- {
49
- return false;
50
- }
51
-
52
 
53
- function save_field($post_id, $field_name, $field_value)
54
- {
55
- // this is a normal text save
56
- add_post_meta($post_id, '_acf_'.$field_name, $field_value);
57
- }
58
 
59
  }
60
 
13
  $this->plugin_dir = $plugin_dir;
14
  }
15
 
16
+ function html($field)
17
  {
18
  echo '<link rel="stylesheet" type="text/css" href="'.$this->plugin_dir.'/core/fields/date_picker/style.date_picker.css" />';
19
  echo '<script type="text/javascript" src="'.$this->plugin_dir.'/core/fields/date_picker/jquery.ui.datepicker.js" ></script>';
20
+ echo '<input type="hidden" value="'.$field->options['date_format'].'" name="date_format" />';
21
+ echo '<input type="text" value="'.$field->value.'" id="'.$field->input_id.'" class="acf_datepicker" name="'.$field->input_name.'" />';
22
 
23
  }
24
 
25
+ function options_html($key, $options)
 
 
 
 
 
26
  {
27
  ?>
28
  <table class="acf_input">
39
  <?php
40
  }
41
 
 
 
 
 
 
42
 
 
 
 
 
 
43
 
44
  }
45
 
core/fields/file.php CHANGED
@@ -13,43 +13,28 @@ class File
13
  $this->plugin_dir = $plugin_dir;
14
  }
15
 
16
- function html($options)
17
  {
18
  echo '<div class="acf_file_uploader">';
19
 
20
- if($options['value'] != '')
21
  {
22
  echo '<a href="#" class="remove_file"></a>';
23
- echo '<span>'.$options['value'].'</span>';
24
- echo '<input type="hidden" name="'.$options['name'].'" value="'.$options['value'].'" />';
25
  echo '<iframe class="hide" src="'.$this->plugin_dir.'/core/upload.php"></iframe>';
26
  }
27
  else
28
  {
29
  echo '<a href="#" class="remove_file hide"></a>';
30
- echo '<input type="hidden" name="'.$options['name'].'" value="'.$options['value'].'" />';
31
  echo '<iframe src="'.$this->plugin_dir.'/core/upload.php"></iframe>';
32
  }
33
 
34
  echo '</div>';
35
 
36
  }
37
-
38
- function has_options()
39
- {
40
- return false;
41
- }
42
-
43
- function has_format_value()
44
- {
45
- return false;
46
- }
47
-
48
- function save_field($post_id, $field_name, $field_value)
49
- {
50
- // this is a normal text save
51
- add_post_meta($post_id, '_acf_'.$field_name, $field_value);
52
- }
53
 
54
  }
55
 
13
  $this->plugin_dir = $plugin_dir;
14
  }
15
 
16
+ function html($field)
17
  {
18
  echo '<div class="acf_file_uploader">';
19
 
20
+ if($field->value != '')
21
  {
22
  echo '<a href="#" class="remove_file"></a>';
23
+ echo '<span>'.$field->value.'</span>';
24
+ echo '<input type="hidden" name="'.$field->input_name.'" value="'.$field->value.'" />';
25
  echo '<iframe class="hide" src="'.$this->plugin_dir.'/core/upload.php"></iframe>';
26
  }
27
  else
28
  {
29
  echo '<a href="#" class="remove_file hide"></a>';
30
+ echo '<input type="hidden" name="'.$field->input_name.'" value="'.$field->value.'" />';
31
  echo '<iframe src="'.$this->plugin_dir.'/core/upload.php"></iframe>';
32
  }
33
 
34
  echo '</div>';
35
 
36
  }
37
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  }
40
 
core/fields/image.php CHANGED
@@ -13,43 +13,28 @@ class Image
13
  $this->plugin_dir = $plugin_dir;
14
  }
15
 
16
- function html($options)
17
  {
18
  echo '<div class="acf_image_uploader">';
19
 
20
- if($options['value'] != '')
21
  {
22
  echo '<a href="#" class="remove_image"></a>';
23
- echo '<img src="'.$options['value'].'"/>';
24
- echo '<input type="hidden" name="'.$options['name'].'" value="'.$options['value'].'" />';
25
  echo '<iframe class="hide" src="'.$this->plugin_dir.'/core/upload.php"></iframe>';
26
  }
27
  else
28
  {
29
  echo '<a href="#" class="remove_image hide"></a>';
30
- echo '<input type="hidden" name="'.$options['name'].'" value="'.$options['value'].'" />';
31
  echo '<iframe src="'.$this->plugin_dir.'/core/upload.php"></iframe>';
32
  }
33
 
34
  echo '</div>';
35
 
36
  }
37
-
38
- function has_options()
39
- {
40
- return false;
41
- }
42
-
43
- function has_format_value()
44
- {
45
- return false;
46
- }
47
-
48
- function save_field($post_id, $field_name, $field_value)
49
- {
50
- // this is a normal text save
51
- add_post_meta($post_id, '_acf_'.$field_name, $field_value);
52
- }
53
 
54
  }
55
 
13
  $this->plugin_dir = $plugin_dir;
14
  }
15
 
16
+ function html($field)
17
  {
18
  echo '<div class="acf_image_uploader">';
19
 
20
+ if($field->value != '')
21
  {
22
  echo '<a href="#" class="remove_image"></a>';
23
+ echo '<img src="'.$field->value.'"/>';
24
+ echo '<input type="hidden" name="'.$field->input_name.'" value="'.$field->value.'" />';
25
  echo '<iframe class="hide" src="'.$this->plugin_dir.'/core/upload.php"></iframe>';
26
  }
27
  else
28
  {
29
  echo '<a href="#" class="remove_image hide"></a>';
30
+ echo '<input type="hidden" name="'.$field->input_name.'" value="'.$field->value.'" />';
31
  echo '<iframe src="'.$this->plugin_dir.'/core/upload.php"></iframe>';
32
  }
33
 
34
  echo '</div>';
35
 
36
  }
37
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  }
40
 
core/fields/page_link.php CHANGED
@@ -6,6 +6,7 @@ class Page_link
6
  var $title;
7
  var $parent;
8
 
 
9
  function Page_link($parent)
10
  {
11
  $this->name = 'page_link';
@@ -13,13 +14,22 @@ class Page_link
13
  $this->parent = $parent;
14
  }
15
 
16
- function html($options)
 
 
 
 
 
 
 
 
 
17
  {
18
  // get post types
19
- if(is_array($options['options']['post_type']))
20
  {
21
  // 1. If select has selected post types, just use them
22
- $post_types = $options['options']['post_type'];
23
  }
24
  else
25
  {
@@ -62,35 +72,25 @@ class Page_link
62
  $choices[] = null;
63
  }
64
 
65
- $options['options']['choices'] = $choices;
66
-
67
-
68
 
69
- echo '<select id="'.$options['id'].'" class="'.$options['class'].'" name="'.$options['name'].'" >';
70
 
71
- // add top option
72
- echo '<option value="">- Select Option -</option>';
73
-
74
- // loop through values and add them as options
75
- foreach($options['options']['choices'] as $key => $value)
76
- {
77
- $selected = '';
78
- if($options['value'] == $key)
79
- {
80
- $selected = 'selected="selected"';
81
- }
82
- echo '<option value="'.$key.'" '.$selected.'>'.$value.'</option>';
83
- }
84
-
85
- echo '</select>';
86
- }
87
-
88
- function has_options()
89
- {
90
- return true;
91
  }
92
 
93
- function options($key, $options)
 
 
 
 
 
 
 
 
 
 
94
  {
95
  ?>
96
  <table class="acf_input">
@@ -109,32 +109,72 @@ class Page_link
109
  unset($post_types['revision']);
110
  unset($post_types['acf']);
111
 
112
- $this->parent->create_field(array('type'=>'select','name'=>'acf[fields]['.$key.'][options][post_type]','value'=>$options['post_type'],'id'=>'acf[fields]['.$key.'][options][post_type]', 'options' => array('choices' => $post_types, 'multiple' => 'true')));
113
  ?>
114
- <p class="description">Filter posts by selecting a post type</p>
 
 
 
 
 
 
 
 
 
 
 
 
115
  </td>
116
  </tr>
117
  </table>
118
  <?php
119
  }
120
 
121
- function has_format_value()
 
 
 
 
 
 
 
 
 
122
  {
123
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  }
125
 
 
 
 
 
 
 
 
 
 
126
  function format_value($value)
127
  {
128
  $value = get_permalink($value);
129
-
130
  return $value;
131
  }
132
-
133
- function save_field($post_id, $field_name, $field_value)
134
- {
135
- // this is a normal text save
136
- add_post_meta($post_id, '_acf_'.$field_name, $field_value);
137
- }
138
 
139
  }
140
 
6
  var $title;
7
  var $parent;
8
 
9
+
10
  function Page_link($parent)
11
  {
12
  $this->name = 'page_link';
14
  $this->parent = $parent;
15
  }
16
 
17
+
18
+ /*---------------------------------------------------------------------------------------------
19
+ * HTML
20
+ * - this is called all over the shop, it creates the input html
21
+ *
22
+ * @author Elliot Condon
23
+ * @since 1.1
24
+ *
25
+ ---------------------------------------------------------------------------------------------*/
26
+ function html($field)
27
  {
28
  // get post types
29
+ if(is_array($field->options['post_type']))
30
  {
31
  // 1. If select has selected post types, just use them
32
+ $post_types = $field->options['post_type'];
33
  }
34
  else
35
  {
72
  $choices[] = null;
73
  }
74
 
75
+ $field->options['choices'] = $choices;
 
 
76
 
 
77
 
78
+ // change type to select and make it!
79
+ $field->type = 'select';
80
+ $this->parent->create_field($field);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
82
 
83
+
84
+ /*---------------------------------------------------------------------------------------------
85
+ * Options HTML
86
+ * - called from fields_meta_box.php
87
+ * - displays options in html format
88
+ *
89
+ * @author Elliot Condon
90
+ * @since 1.1
91
+ *
92
+ ---------------------------------------------------------------------------------------------*/
93
+ function options_html($key, $options)
94
  {
95
  ?>
96
  <table class="acf_input">
109
  unset($post_types['revision']);
110
  unset($post_types['acf']);
111
 
 
112
  ?>
113
+ <?php
114
+ $temp_field = new stdClass();
115
+ $temp_field->type = 'select';
116
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][post_type]';
117
+ $temp_field->input_class = '';
118
+ $temp_field->input_id = 'acf[fields]['.$key.'][options][post_type]';
119
+ $temp_field->value = $options['post_type'];
120
+ $temp_field->options = array('choices' => $post_types, 'multiple' => '1');
121
+ $this->parent->create_field($temp_field);
122
+
123
+ ?>
124
+ <p class="description">Filter posts by selecting a post type<br />
125
+ * unselecting all is the same as selecting all</p>
126
  </td>
127
  </tr>
128
  </table>
129
  <?php
130
  }
131
 
132
+
133
+ /*---------------------------------------------------------------------------------------------
134
+ * Save Input
135
+ * - this is called from save_input.php, this function saves the field's value(s)
136
+ *
137
+ * @author Elliot Condon
138
+ * @since 1.1
139
+ *
140
+ ---------------------------------------------------------------------------------------------*/
141
+ function save_input($post_id, $field)
142
  {
143
+ // set table name
144
+ global $wpdb;
145
+ $table_name = $wpdb->prefix.'acf_values';
146
+
147
+
148
+ // if select is a multiple, you need to save it as an array!
149
+ if(is_array($field['value']))
150
+ {
151
+ $field['value'] = serialize($field['value']);
152
+ }
153
+
154
+
155
+ // insert new data
156
+ $new_id = $wpdb->insert($table_name, array(
157
+ 'post_id' => $post_id,
158
+ 'field_id' => $field['field_id'],
159
+ 'value' => $field['value']
160
+ ));
161
  }
162
 
163
+
164
+ /*---------------------------------------------------------------------------------------------
165
+ * Format Value
166
+ * - this is called from api.php
167
+ *
168
+ * @author Elliot Condon
169
+ * @since 1.1
170
+ *
171
+ ---------------------------------------------------------------------------------------------*/
172
  function format_value($value)
173
  {
174
  $value = get_permalink($value);
 
175
  return $value;
176
  }
177
+
 
 
 
 
 
178
 
179
  }
180
 
core/fields/post_object.php CHANGED
@@ -13,13 +13,13 @@ class Post_object
13
  $this->parent = $parent;
14
  }
15
 
16
- function html($options)
17
  {
18
  // get post types
19
- if(is_array($options['options']['post_type']))
20
  {
21
  // 1. If select has selected post types, just use them
22
- $post_types = $options['options']['post_type'];
23
  }
24
  else
25
  {
@@ -62,25 +62,26 @@ class Post_object
62
  $choices[] = null;
63
  }
64
 
65
- $options['options']['choices'] = $choices;
66
 
67
- $this->parent->create_field(array(
68
- 'type'=>'select',
69
- 'name'=>$options['name'],
70
- 'value'=>$options['value'],
71
- 'id'=>$options['name'],
72
- 'options' => $options['options']
73
- ));
74
 
75
 
 
 
 
76
  }
77
 
78
- function has_options()
79
- {
80
- return true;
81
- }
82
 
83
- function options($key, $options)
 
 
 
 
 
 
 
 
 
84
  {
85
  ?>
86
  <table class="acf_input">
@@ -90,6 +91,7 @@ class Post_object
90
  </td>
91
  <td>
92
  <?php
 
93
  foreach (get_post_types() as $post_type ) {
94
  $post_types[$post_type] = $post_type;
95
  }
@@ -99,9 +101,19 @@ class Post_object
99
  unset($post_types['revision']);
100
  unset($post_types['acf']);
101
 
102
- $this->parent->create_field(array('type'=>'select','name'=>'acf[fields]['.$key.'][options][post_type]','value'=>$options['post_type'],'id'=>'acf[fields]['.$key.'][options][post_type]', 'options' => array('choices' => $post_types, 'multiple' => 'true')));
 
 
 
 
 
 
 
 
 
103
  ?>
104
- <p class="description">Filter posts by selecting a post type</p>
 
105
  </td>
106
  </tr>
107
  <tr>
@@ -109,26 +121,66 @@ class Post_object
109
  <label>Multiple?</label>
110
  </td>
111
  <td>
112
- <?php $this->parent->create_field(array(
113
- 'type'=>'checkbox',
114
- 'name'=>'acf[fields]['.$key.'][options][multiple]',
115
- 'value'=>$options['multiple'],
116
- 'id'=>'acf[fields]['.$key.'][options][multiple]',
117
- 'options' => array('choices' => array('true' => 'Select multiple posts'))
118
- )); ?>
 
 
 
119
  </td>
120
  </tr>
121
  </table>
122
  <?php
123
  }
124
 
125
- function has_format_value()
 
 
 
 
 
 
 
 
 
 
126
  {
127
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  }
129
 
130
- function format_value($value)
 
 
 
 
 
 
 
 
131
  {
 
 
132
  if(is_array($value))
133
  {
134
  foreach($value as $k => $v)
@@ -144,10 +196,26 @@ class Post_object
144
  return $value;
145
  }
146
 
147
- function save_field($post_id, $field_name, $field_value)
 
 
 
 
 
 
 
 
 
148
  {
149
- // this is a normal text save
150
- add_post_meta($post_id, '_acf_'.$field_name, $field_value);
 
 
 
 
 
 
 
151
  }
152
 
153
  }
13
  $this->parent = $parent;
14
  }
15
 
16
+ function html($field)
17
  {
18
  // get post types
19
+ if(is_array($field->options['post_type']))
20
  {
21
  // 1. If select has selected post types, just use them
22
+ $post_types = $field->options['post_type'];
23
  }
24
  else
25
  {
62
  $choices[] = null;
63
  }
64
 
 
65
 
66
+ $field->options['choices'] = $choices;
 
 
 
 
 
 
67
 
68
 
69
+ // change type to select and make it!
70
+ $field->type = 'select';
71
+ $this->parent->create_field($field);
72
  }
73
 
 
 
 
 
74
 
75
+ /*---------------------------------------------------------------------------------------------
76
+ * Options HTML
77
+ * - called from fields_meta_box.php
78
+ * - displays options in html format
79
+ *
80
+ * @author Elliot Condon
81
+ * @since 1.1
82
+ *
83
+ ---------------------------------------------------------------------------------------------*/
84
+ function options_html($key, $options)
85
  {
86
  ?>
87
  <table class="acf_input">
91
  </td>
92
  <td>
93
  <?php
94
+
95
  foreach (get_post_types() as $post_type ) {
96
  $post_types[$post_type] = $post_type;
97
  }
101
  unset($post_types['revision']);
102
  unset($post_types['acf']);
103
 
104
+
105
+ $temp_field = new stdClass();
106
+ $temp_field->type = 'select';
107
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][post_type]';
108
+ $temp_field->input_class = '';
109
+ $temp_field->input_id = 'acf[fields]['.$key.'][options][post_type]';
110
+ $temp_field->value = $options['post_type'];
111
+ $temp_field->options = array('choices' => $post_types, 'multiple' => '1');
112
+ $this->parent->create_field($temp_field);
113
+
114
  ?>
115
+ <p class="description">Filter posts by selecting a post type<br />
116
+ * unselecting all is the same as selecting all</p>
117
  </td>
118
  </tr>
119
  <tr>
121
  <label>Multiple?</label>
122
  </td>
123
  <td>
124
+ <?php
125
+ $temp_field = new stdClass();
126
+ $temp_field->type = 'true_false';
127
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][multiple]';
128
+ $temp_field->input_class = '';
129
+ $temp_field->input_id = 'acf[fields]['.$key.'][options][multiple]';
130
+ $temp_field->value = $options['multiple'];
131
+ $temp_field->options = array('message' => 'Select multiple posts');
132
+ $this->parent->create_field($temp_field);
133
+ ?>
134
  </td>
135
  </tr>
136
  </table>
137
  <?php
138
  }
139
 
140
+
141
+
142
+ /*---------------------------------------------------------------------------------------------
143
+ * Save Input
144
+ * - this is called from save_input.php, this function saves the field's value(s)
145
+ *
146
+ * @author Elliot Condon
147
+ * @since 1.1
148
+ *
149
+ ---------------------------------------------------------------------------------------------*/
150
+ function save_input($post_id, $field)
151
  {
152
+ // set table name
153
+ global $wpdb;
154
+ $table_name = $wpdb->prefix.'acf_values';
155
+
156
+
157
+ // if select is a multiple, you need to save it as an array!
158
+ if(is_array($field['value']))
159
+ {
160
+ $field['value'] = serialize($field['value']);
161
+ }
162
+
163
+
164
+ // insert new data
165
+ $new_id = $wpdb->insert($table_name, array(
166
+ 'post_id' => $post_id,
167
+ 'field_id' => $field['field_id'],
168
+ 'value' => $field['value']
169
+ ));
170
  }
171
 
172
+ /*---------------------------------------------------------------------------------------------
173
+ * Format Value
174
+ * - this is called from api.php
175
+ *
176
+ * @author Elliot Condon
177
+ * @since 1.1
178
+ *
179
+ ---------------------------------------------------------------------------------------------*/
180
+ function format_value_for_api($value)
181
  {
182
+ $value = $this->format_value_for_input($value);
183
+
184
  if(is_array($value))
185
  {
186
  foreach($value as $k => $v)
196
  return $value;
197
  }
198
 
199
+
200
+ /*---------------------------------------------------------------------------------------------
201
+ * Format Value for input
202
+ * - this is called from api.php
203
+ *
204
+ * @author Elliot Condon
205
+ * @since 1.1
206
+ *
207
+ ---------------------------------------------------------------------------------------------*/
208
+ function format_value_for_input($value)
209
  {
210
+ if(is_array(unserialize($value)))
211
+ {
212
+ return(unserialize($value));
213
+ }
214
+ else
215
+ {
216
+ return $value;
217
+ }
218
+
219
  }
220
 
221
  }
core/fields/select.php CHANGED
@@ -13,21 +13,20 @@ class Select
13
  $this->parent = $parent;
14
  }
15
 
16
- function html($options)
17
  {
18
- //$options['choices'] = explode("\n",$options['choices']);
19
- if($options['options']['multiple'] == 'true')
20
  {
21
  $name_extra = '[]';
22
- if(count($options['options']['choices']) <= 1)
23
  {
24
  $name_extra = '';
25
  }
26
- echo '<select id="'.$options['id'].'" class="'.$options['class'].'" name="'.$options['name'].$name_extra.'" multiple="multiple" size="5" >';
27
  }
28
  else
29
  {
30
- echo '<select id="'.$options['id'].'" class="'.$options['class'].'" name="'.$options['name'].'" >';
31
  // add top option
32
  echo '<option value="null">- Select Option -</option>';
33
  }
@@ -37,18 +36,13 @@ class Select
37
 
38
 
39
  // loop through values and add them as options
40
- foreach($options['options']['choices'] as $key => $value)
41
  {
42
  $selected = '';
43
- if($options['options']['multiple'] == 'true' && empty($options['value']))
44
- {
45
- // 1. If it is multiple select & there are no values selected, make all options selected
46
- $selected = 'selected="selected"';
47
- }
48
- elseif(is_array($options['value']))
49
  {
50
  // 2. If the value is an array (multiple select), loop through values and check if it is selected
51
- if(in_array($key, $options['value']))
52
  {
53
  $selected = 'selected="selected"';
54
  }
@@ -56,7 +50,7 @@ class Select
56
  else
57
  {
58
  // 3. this is not a multiple select, just check normaly
59
- if($key == $options['value'])
60
  {
61
  $selected = 'selected="selected"';
62
  }
@@ -74,9 +68,18 @@ class Select
74
  return true;
75
  }
76
 
77
- function options($key, $options)
78
  {
79
- //if($options['choices'] == ''){$options['choices'] = "option 1\noption 2\noption 3";}
 
 
 
 
 
 
 
 
 
80
  ?>
81
  <table class="acf_input">
82
  <tr>
@@ -86,9 +89,9 @@ class Select
86
  <td>
87
  <textarea rows="5" name="acf[fields][<?php echo $key; ?>][options][choices]" id=""><?php echo $options['choices']; ?></textarea>
88
  <p class="description">Enter your choices one per line. eg:<br />
89
- Option 1<br />
90
- Option 2 <br />
91
- Option 3</p>
92
  </td>
93
  </tr>
94
  <tr>
@@ -96,30 +99,144 @@ class Select
96
  <label>Multiple?</label>
97
  </td>
98
  <td>
99
- <?php $this->parent->create_field(array(
100
- 'type'=>'checkbox',
101
- 'name'=>'acf[fields]['.$key.'][options][multiple]',
102
- 'value'=>$options['multiple'],
103
- 'id'=>'acf[fields]['.$key.'][options][multiple]',
104
- 'options' => array('choices' => array('true' => 'Select multiple values'))
105
- )); ?>
 
 
 
106
  </td>
107
  </tr>
108
  </table>
109
  <?php
110
  }
111
 
112
- function has_format_value()
 
 
 
 
 
 
 
 
 
113
  {
114
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  }
116
 
117
- function save_field($post_id, $field_name, $field_value)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  {
119
- // this is a normal text save
120
- add_post_meta($post_id, '_acf_'.$field_name, $field_value);
 
 
 
 
 
 
121
  }
122
 
 
 
123
  }
124
 
125
  ?>
13
  $this->parent = $parent;
14
  }
15
 
16
+ function html($field)
17
  {
18
+ if($field->options['multiple'] == '1')
 
19
  {
20
  $name_extra = '[]';
21
+ if(count($field->options['choices']) <= 1)
22
  {
23
  $name_extra = '';
24
  }
25
+ echo '<select id="'.$field->input_id.'" class="'.$field->input_class.'" name="'.$field->input_name.$name_extra.'" multiple="multiple" size="5" >';
26
  }
27
  else
28
  {
29
+ echo '<select id="'.$field->input_id.'" class="'.$field->input_class.'" name="'.$field->input_name.'" >';
30
  // add top option
31
  echo '<option value="null">- Select Option -</option>';
32
  }
36
 
37
 
38
  // loop through values and add them as options
39
+ foreach($field->options['choices'] as $key => $value)
40
  {
41
  $selected = '';
42
+ if(is_array($field->value))
 
 
 
 
 
43
  {
44
  // 2. If the value is an array (multiple select), loop through values and check if it is selected
45
+ if(in_array($key, $field->value))
46
  {
47
  $selected = 'selected="selected"';
48
  }
50
  else
51
  {
52
  // 3. this is not a multiple select, just check normaly
53
+ if($key == $field->value)
54
  {
55
  $selected = 'selected="selected"';
56
  }
68
  return true;
69
  }
70
 
71
+ function options_html($key, $options)
72
  {
73
+ // implode selects so they work in a textarea
74
+ if(!empty($options['choices']) && is_array($options['choices']))
75
+ {
76
+ foreach($options['choices'] as $choice_key => $choice_val)
77
+ {
78
+ $options['choices'][$choice_key] = $choice_key.' : '.$choice_val;
79
+ }
80
+ $options['choices'] = implode("\n", $options['choices']);
81
+ }
82
+
83
  ?>
84
  <table class="acf_input">
85
  <tr>
89
  <td>
90
  <textarea rows="5" name="acf[fields][<?php echo $key; ?>][options][choices]" id=""><?php echo $options['choices']; ?></textarea>
91
  <p class="description">Enter your choices one per line. eg:<br />
92
+ option_1 : Option 1<br />
93
+ option_3 : Option 2<br />
94
+ option_3 : Option 3</p>
95
  </td>
96
  </tr>
97
  <tr>
99
  <label>Multiple?</label>
100
  </td>
101
  <td>
102
+ <?php
103
+ $temp_field = new stdClass();
104
+ $temp_field->type = 'true_false';
105
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][multiple]';
106
+ $temp_field->input_class = '';
107
+ $temp_field->input_id = 'acf[fields]['.$key.'][options][multiple]';
108
+ $temp_field->value = $options['multiple'];
109
+ $temp_field->options = array('message' => 'Select multiple values');
110
+ $this->parent->create_field($temp_field);
111
+ ?>
112
  </td>
113
  </tr>
114
  </table>
115
  <?php
116
  }
117
 
118
+
119
+ /*---------------------------------------------------------------------------------------------
120
+ * Save Input
121
+ * - this is called from save_input.php, this function saves the field's value(s)
122
+ *
123
+ * @author Elliot Condon
124
+ * @since 1.1
125
+ *
126
+ ---------------------------------------------------------------------------------------------*/
127
+ function save_input($post_id, $field)
128
  {
129
+ // set table name
130
+ global $wpdb;
131
+ $table_name = $wpdb->prefix.'acf_values';
132
+
133
+
134
+ // if select is a multiple, you need to save it as an array!
135
+ if(is_array($field['value']))
136
+ {
137
+ $field['value'] = serialize($field['value']);
138
+ }
139
+
140
+
141
+ // insert new data
142
+ $new_id = $wpdb->insert($table_name, array(
143
+ 'post_id' => $post_id,
144
+ 'field_id' => $field['field_id'],
145
+ 'value' => $field['value']
146
+ ));
147
  }
148
 
149
+
150
+ /*---------------------------------------------------------------------------------------------
151
+ * Format Options
152
+ * - this is called from save_field.php, this function formats the options into a savable format
153
+ *
154
+ * @author Elliot Condon
155
+ * @since 1.1
156
+ *
157
+ ---------------------------------------------------------------------------------------------*/
158
+ function format_options($options)
159
+ {
160
+ // if no choices, dont do anything
161
+ if($options['choices'] == '')
162
+ {
163
+ return $options;
164
+ }
165
+
166
+
167
+ // explode choices from each line
168
+ if(strpos($options['choices'], "\n") !== false)
169
+ {
170
+ // found multiple lines, explode it
171
+ $choices = explode("\n", $options['choices']);
172
+ }
173
+ else
174
+ {
175
+ // no multiple lines!
176
+ $choices = array($options['choices']);
177
+ }
178
+
179
+
180
+
181
+ $new_choices = array();
182
+ foreach($choices as $choice)
183
+ {
184
+ if(strpos($choice, ':') !== false)
185
+ {
186
+
187
+ $choice = explode(':', $choice);
188
+ $new_choices[trim($choice[0])] = trim($choice[1]);
189
+ }
190
+ else
191
+ {
192
+ $new_choices[trim($choice)] = trim($choice);
193
+ }
194
+ }
195
+
196
+
197
+ // return array containing all choices
198
+ $options['choices'] = $new_choices;
199
+
200
+ return $options;
201
+ }
202
+
203
+
204
+ /*---------------------------------------------------------------------------------------------
205
+ * Format Value
206
+ * - this is called from api.php
207
+ *
208
+ * @author Elliot Condon
209
+ * @since 1.1
210
+ *
211
+ ---------------------------------------------------------------------------------------------*/
212
+ function format_value_for_api($value)
213
+ {
214
+ return $this->format_value_for_input($value);
215
+ }
216
+
217
+
218
+ /*---------------------------------------------------------------------------------------------
219
+ * Format Value for input
220
+ * - this is called from api.php
221
+ *
222
+ * @author Elliot Condon
223
+ * @since 1.1
224
+ *
225
+ ---------------------------------------------------------------------------------------------*/
226
+ function format_value_for_input($value)
227
  {
228
+ if(is_array(unserialize($value)))
229
+ {
230
+ return(unserialize($value));
231
+ }
232
+ else
233
+ {
234
+ return $value;
235
+ }
236
  }
237
 
238
+
239
+
240
  }
241
 
242
  ?>
core/fields/text.php CHANGED
@@ -11,26 +11,11 @@ class Text
11
  $this->title = 'Text';
12
  }
13
 
14
- function html($options)
15
  {
16
- echo '<input type="text" value="'.$options['value'].'" id="'.$options['id'].'" class="'.$options['class'].'" name="'.$options['name'].'" />';
17
- }
18
-
19
- function has_options()
20
- {
21
- return false;
22
- }
23
-
24
- function has_format_value()
25
- {
26
- return false;
27
- }
28
-
29
- function save_field($post_id, $field_name, $field_value)
30
- {
31
- // this is a normal text save
32
- add_post_meta($post_id, '_acf_'.$field_name, $field_value);
33
  }
 
34
 
35
  }
36
 
11
  $this->title = 'Text';
12
  }
13
 
14
+ function html($field)
15
  {
16
+ echo '<input type="text" value="'.$field->value.'" id="'.$field->input_id.'" class="'.$field->input_class.'" name="'.$field->input_name.'" />';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  }
18
+
19
 
20
  }
21
 
core/fields/textarea.php CHANGED
@@ -11,20 +11,13 @@ class Textarea
11
  $this->title = 'Text Area';
12
  }
13
 
14
- function html($options)
15
  {
16
- echo '<textarea id="'.$options['id'].'" rows="4" class="'.$options['class'].'" name="'.$options['name'].'" >'.$options['value'].'</textarea>';
 
 
17
  }
18
 
19
- function has_options()
20
- {
21
- return false;
22
- }
23
-
24
- function has_format_value()
25
- {
26
- return true;
27
- }
28
 
29
  function format_value($value)
30
  {
@@ -32,12 +25,6 @@ class Textarea
32
 
33
  return $value;
34
  }
35
-
36
- function save_field($post_id, $field_name, $field_value)
37
- {
38
- // this is a normal text save
39
- add_post_meta($post_id, '_acf_'.$field_name, $field_value);
40
- }
41
  }
42
 
43
  ?>
11
  $this->title = 'Text Area';
12
  }
13
 
14
+ function html($field)
15
  {
16
+ // remove unwanted <br /> tags
17
+ $field->value = str_replace('<br />','',$field->value);
18
+ echo '<textarea id="'.$field->input_id.'" rows="4" class="'.$field->input_class.'" name="'.$field->input_name.'" >'.$field->value.'</textarea>';
19
  }
20
 
 
 
 
 
 
 
 
 
 
21
 
22
  function format_value($value)
23
  {
25
 
26
  return $value;
27
  }
 
 
 
 
 
 
28
  }
29
 
30
  ?>
core/fields/true_false.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class True_false
4
+ {
5
+ var $name;
6
+ var $title;
7
+
8
+ function True_false()
9
+ {
10
+ $this->name = 'true_false';
11
+ $this->title = 'True / False';
12
+ }
13
+
14
+ function html($field)
15
+ {
16
+ // set default message
17
+ if(empty($field->options['message']))
18
+ {
19
+ $field->options['message'] = 'True';
20
+ }
21
+
22
+ // set choices
23
+ $field->options['choices'] = array(
24
+ '1' => $field->options['message']
25
+ );
26
+
27
+ // echo html
28
+ echo '<ul class="checkbox_list '.$field->input_class.'">';
29
+
30
+ foreach($field->options['choices'] as $key => $value)
31
+ {
32
+ $selected = '';
33
+ if($key == $field->value)
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>';
41
+
42
+ }
43
+
44
+
45
+ /*---------------------------------------------------------------------------------------------
46
+ * Options HTML
47
+ * - called from fields_meta_box.php
48
+ * - displays options in html format
49
+ *
50
+ * @author Elliot Condon
51
+ * @since 1.1
52
+ *
53
+ ---------------------------------------------------------------------------------------------*/
54
+ function options_html($key, $options)
55
+ {
56
+ ?>
57
+ <table class="acf_input">
58
+ <tr>
59
+ <td class="label">
60
+ <label for="acf[fields][<?php echo $key; ?>][options][message]">Message</label>
61
+ </td>
62
+ <td>
63
+ <input type="text" name="acf[fields][<?php echo $key; ?>][options][message]" id="acf[fields][<?php echo $key; ?>][options][message]" value="<?php echo $options['message']; ?>" />
64
+ <p class="description">eg. Show extra content</a></p>
65
+ </td>
66
+ </tr>
67
+ </table>
68
+ <?php
69
+ }
70
+
71
+
72
+ /*---------------------------------------------------------------------------------------------
73
+ * Format Value
74
+ * - this is called from api.php
75
+ *
76
+ * @author Elliot Condon
77
+ * @since 1.1
78
+ *
79
+ ---------------------------------------------------------------------------------------------*/
80
+ function format_value_for_api($value)
81
+ {
82
+ return $this->format_value_for_input($value);
83
+ }
84
+
85
+
86
+ /*---------------------------------------------------------------------------------------------
87
+ * Format Value for input
88
+ * - this is called from api.php
89
+ *
90
+ * @author Elliot Condon
91
+ * @since 1.1
92
+ *
93
+ ---------------------------------------------------------------------------------------------*/
94
+ function format_value_for_input($value)
95
+ {
96
+ if($value == '1')
97
+ {
98
+ return true;
99
+ }
100
+ else
101
+ {
102
+ return false;
103
+ }
104
+ }
105
+
106
+
107
+ }
108
+
109
+ ?>
core/fields/wysiwyg.php CHANGED
@@ -11,35 +11,18 @@ class Wysiwyg
11
  $this->title = 'Wysiwyg Editor';
12
  }
13
 
14
- function html($options)
15
  {
16
- echo '<div class="acf_wysiwyg"><textarea name="'.$options['name'].'" >';
17
- echo wp_richedit_pre($options['value']);
18
  echo '</textarea></div>';
19
  }
20
 
21
- function has_options()
22
- {
23
- return false;
24
- }
25
-
26
- function has_format_value()
27
- {
28
- return true;
29
- }
30
-
31
  function format_value($value)
32
  {
33
  $value = apply_filters('the_content',$value);
34
-
35
  return $value;
36
  }
37
-
38
- function save_field($post_id, $field_name, $field_value)
39
- {
40
- // this is a normal text save
41
- add_post_meta($post_id, '_acf_'.$field_name, $field_value);
42
- }
43
  }
44
 
45
  ?>
11
  $this->title = 'Wysiwyg Editor';
12
  }
13
 
14
+ function html($field)
15
  {
16
+ echo '<div class="acf_wysiwyg"><textarea name="'.$field->input_name.'" >';
17
+ echo wp_richedit_pre($field->value);
18
  echo '</textarea></div>';
19
  }
20
 
 
 
 
 
 
 
 
 
 
 
21
  function format_value($value)
22
  {
23
  $value = apply_filters('the_content',$value);
 
24
  return $value;
25
  }
 
 
 
 
 
 
26
  }
27
 
28
  ?>
core/fields_meta_box.php CHANGED
@@ -4,18 +4,8 @@
4
  global $post;
5
  $fields = $this->get_fields($post->ID);
6
 
7
- // if no fields (new acf), add blank field
8
- if(empty($fields))
9
- {
10
- $fields[] = array(
11
- 'title' => '',
12
- 'label' => '',
13
- 'type' => 'text',
14
- 'options' => array()
15
- );
16
- }
17
 
18
- // get name of all fields for use in field type
19
  $fields_names = array();
20
  foreach($this->fields as $field)
21
  {
@@ -44,34 +34,49 @@
44
  <div class="fields">
45
  <?php foreach($fields as $key => $field): ?>
46
  <div class="field">
47
-
 
 
 
48
  <table class="acf">
49
  <tr>
50
  <td class="order"><?php echo ($key+1); ?></td>
51
  <td class="label">
52
- <?php $this->create_field(array(
53
- 'type' => 'text',
54
- 'name' => 'acf[fields]['.$key.'][label]',
55
- 'value' => $field['label'],
56
- 'class' => 'label'
57
- )); ?>
 
 
 
 
58
  </td>
59
  <td class="name">
60
- <?php $this->create_field(array(
61
- 'type' => 'text',
62
- 'name' => 'acf[fields]['.$key.'][name]',
63
- 'value' => $field['name'],
64
- 'class' => 'name'
65
- )); ?>
 
 
 
 
66
  </td>
67
  <td class="type">
68
- <?php $this->create_field(array(
69
- 'type' => 'select',
70
- 'name' => 'acf[fields]['.$key.'][type]',
71
- 'value' => $field['type'],
72
- 'class' => 'type',
73
- 'options' => array('choices' => $fields_names)
74
- )); ?>
 
 
 
 
75
  </td>
76
  <td class="blank"></td>
77
  <td class="remove"><a href="javascript:;" class="remove_field"></a></td>
@@ -80,9 +85,9 @@
80
 
81
  <div class="field_options">
82
  <?php foreach($fields_names as $field_name => $field_title): ?>
83
- <?php if($this->fields[$field_name]->has_options()): ?>
84
  <div class="field_option" id="<?php echo $field_name; ?>">
85
- <?php $this->fields[$field_name]->options($key, $field['options']); ?>
86
  </div>
87
  <?php endif; ?>
88
  <?php endforeach; ?>
4
  global $post;
5
  $fields = $this->get_fields($post->ID);
6
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ // get name of all fields for use in field type drop down
9
  $fields_names = array();
10
  foreach($this->fields as $field)
11
  {
34
  <div class="fields">
35
  <?php foreach($fields as $key => $field): ?>
36
  <div class="field">
37
+
38
+ <input type="hidden" name="acf[fields][<?php echo $key; ?>][id]'" value="<?php echo $field->id; ?>" />
39
+ <?php $temp_field = new stdClass(); ?>
40
+
41
  <table class="acf">
42
  <tr>
43
  <td class="order"><?php echo ($key+1); ?></td>
44
  <td class="label">
45
+ <?php
46
+
47
+ $temp_field->type = 'text';
48
+ $temp_field->input_name = 'acf[fields]['.$key.'][label]';
49
+ $temp_field->input_class = 'label';
50
+ $temp_field->value = $field->label;
51
+
52
+ $this->create_field($temp_field);
53
+
54
+ ?>
55
  </td>
56
  <td class="name">
57
+ <?php
58
+
59
+ $temp_field->type = 'text';
60
+ $temp_field->input_name = 'acf[fields]['.$key.'][name]';
61
+ $temp_field->input_class = 'name';
62
+ $temp_field->value = $field->name;
63
+
64
+ $this->create_field($temp_field);
65
+
66
+ ?>
67
  </td>
68
  <td class="type">
69
+ <?php
70
+
71
+ $temp_field->type = 'select';
72
+ $temp_field->input_name = 'acf[fields]['.$key.'][type]';
73
+ $temp_field->input_class = 'type';
74
+ $temp_field->value = $field->type;
75
+ $temp_field->options = array('choices' => $fields_names);
76
+
77
+ $this->create_field($temp_field);
78
+
79
+ ?>
80
  </td>
81
  <td class="blank"></td>
82
  <td class="remove"><a href="javascript:;" class="remove_field"></a></td>
85
 
86
  <div class="field_options">
87
  <?php foreach($fields_names as $field_name => $field_title): ?>
88
+ <?php if(method_exists($this->fields[$field_name], 'options_html')): ?>
89
  <div class="field_option" id="<?php echo $field_name; ?>">
90
+ <?php $this->fields[$field_name]->options_html($key, $field->options); ?>
91
  </div>
92
  <?php endif; ?>
93
  <?php endforeach; ?>
core/fields_save.php CHANGED
@@ -1,36 +1,55 @@
1
  <?php
2
  /*---------------------------------------------------------------------------------------------
3
- Fields Meta Box
4
  ---------------------------------------------------------------------------------------------*/
5
  if($_POST['fields_meta_box'] == 'true')
6
  {
 
 
 
 
 
 
 
 
 
 
7
  $i = 0;
8
-
9
  foreach($_POST['acf']['fields'] as $field)
10
  {
11
- // add post meta
12
- add_post_meta($post_id, '_acf_field_'.$i.'_label', $field['label']);
13
- add_post_meta($post_id, '_acf_field_'.$i.'_name', $field['name']);
14
- add_post_meta($post_id, '_acf_field_'.$i.'_type', $field['type']);
15
 
16
- if(!empty($field['fields']))
 
17
  {
18
- $j = 0;
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- foreach($field['fields'] as $repeater)
21
- {
22
- // add post meta
23
- add_post_meta($post_id, '_acf_field_'.$i.'_field_'.$j.'_label', $repeater['label']);
24
- add_post_meta($post_id, '_acf_field_'.$i.'_field_'.$j.'_name', $repeater['name']);
25
- add_post_meta($post_id, '_acf_field_'.$i.'_field_'.$j.'_type', $repeater['type']);
26
-
27
- $j++;
28
- }
29
  }
30
 
31
- add_post_meta($post_id, '_acf_field_'.$i.'_options', serialize($field['options']));
32
-
33
- // increase counter
 
 
 
34
  $i++;
35
  }
36
  }
1
  <?php
2
  /*---------------------------------------------------------------------------------------------
3
+ Save Fields Meta Box
4
  ---------------------------------------------------------------------------------------------*/
5
  if($_POST['fields_meta_box'] == 'true')
6
  {
7
+ // set table name
8
+ global $wpdb;
9
+ $table_name = $wpdb->prefix.'acf_fields';
10
+
11
+
12
+ // remove all old fields from the database
13
+ $wpdb->query("DELETE FROM $table_name WHERE post_id = '$post_id'");
14
+
15
+
16
+ // loop through fields and save them
17
  $i = 0;
 
18
  foreach($_POST['acf']['fields'] as $field)
19
  {
20
+
 
 
 
21
 
22
+ // format options if needed
23
+ if(method_exists($this->fields[$field['type']], 'format_options'))
24
  {
25
+ $field['options'] = $this->fields[$field['type']]->format_options($field['options']);
26
+ }
27
+
28
+
29
+ // create data
30
+ $data = array(
31
+ 'order_no' => $i,
32
+ 'post_id' => $post_id,
33
+ 'label' => $field['label'],
34
+ 'name' => $field['name'],
35
+ 'type' => $field['type'],
36
+ 'options' => serialize($field['options']),
37
 
38
+ );
39
+
40
+
41
+ // if there is an id, this field already exists, so save it in the same ID spot
42
+ if($field['id'])
43
+ {
44
+ $data['id'] = $field['id'];
 
 
45
  }
46
 
47
+
48
+ // save field as row in database
49
+ $new_id = $wpdb->insert($table_name, $data);
50
+
51
+
52
+ // increase order_no
53
  $i++;
54
  }
55
  }
core/info_meta_box.php CHANGED
@@ -2,7 +2,9 @@
2
 
3
  <div class="postbox">
4
  <div title="Click to toggle" class="handlediv"><br></div>
5
- <h3 class="hndle"><span>Advanced Custom Fields v<?php echo $this->version; ?></span></h3>
 
 
6
  <div class="inside">
7
  <table cellpadding="0" cellspacing="0" class="author">
8
  <tr>
2
 
3
  <div class="postbox">
4
  <div title="Click to toggle" class="handlediv"><br></div>
5
+ <h3 class="hndle"><span>Advanced Custom Fields v<?php echo $this->version; ?></span>
6
+ <a class="thickbox button" href="http://localhost:8888/acf/wp-admin/plugin-install.php?tab=plugin-information&amp;plugin=advanced-custom-fields&amp;section=changelog&amp;TB_iframe=true&amp;width=640&amp;height=570">see what's new</a>
7
+ </h3>
8
  <div class="inside">
9
  <table cellpadding="0" cellspacing="0" class="author">
10
  <tr>
core/input_meta_box.php CHANGED
@@ -21,101 +21,53 @@
21
  }
22
 
23
  // get options from first (top level) acf
24
- $adv_options = $this->get_adv_options($acfs[0]->ID);
25
-
26
- // loop through multiple acfs
27
- /*$adv_options = array();
28
- foreach($acfs as $acf)
29
- {
30
- // get this acf's fields and add them to the global $fields
31
- $this_fields = $this->get_fields($acf->ID);
32
- foreach($this_fields as $this_field)
33
- {
34
- $fields[] = $this_field;
35
- }
36
-
37
- $this_options = $this->get_adv_options($acf->ID);
38
- foreach($this_options as $key => $this_option)
39
- {
40
- // if global options doesn't even have this key, just add the array
41
- if(empty($adv_options[$key]))
42
- {
43
- $adv_options[$key] = $this_option;
44
- }
45
- else
46
- {
47
- // the global array has the so it has an array here
48
- foreach($this_option as $key2 => $this_option_value)
49
- {
50
- // if the global options is blank at this key, add in the new key.
51
- if(empty($adv_options[$key][$key2]))
52
- {
53
- $adv_options[$key][$key2] = $this_option_value;
54
- }
55
- }
56
- }
57
-
58
-
59
- }
60
- }*/
61
 
62
 
63
  ?>
64
 
65
- <input type="hidden" name="ei_noncename" id="ei_noncename" value="<?php echo wp_create_nonce('ei-n'); ?>" />
66
 
 
67
  <input type="hidden" name="input_meta_box" value="true" />
68
- <input type="hidden" name="acf[id]" value="<?php echo implode(',',$acf_ids); ?>" />
 
69
 
70
- <?php if(!in_array('the_content',$adv_options['show_on_page'])): // hide the content quicker than jquery ?>
 
 
71
  <style type="text/css">
72
  #postdivrich {display: none;}
73
  </style>
74
  <?php endif; ?>
75
 
76
- <?php foreach($adv_options['show_on_page'] as $option): ?>
77
-
78
  <input type="hidden" name="show_<?php echo $option; ?>" value="true" />
79
  <?php endforeach; ?>
80
 
81
  <table class="acf_input" id="acf_input">
82
- <?php foreach($fields as $field): ?>
 
83
  <?php
 
84
  // if they didn't select a type, skip this field
85
- if($field['type'] == 'null')
86
  {
87
  continue;
88
  }
89
- elseif($field['type'] == 'repeater')
90
- {
91
- // if repeater, get the repeater class to find and add the values to field
92
- $field = $this->fields['repeater']->add_values_to_field($field);
93
-
94
- }
95
- else
96
- {
97
- $field['value'] = get_post_meta($post->ID, '_acf_'.$field['name'], true);
98
- $field['id'] = 'acf['.$field['name'].']';
99
- $field['name'] = 'acf['.$field['name'].']';
100
- }
101
 
102
-
103
- if($field['type'] == 'select' || $field['type'] == 'checkbox')
104
- {
105
- $array = array();
106
- foreach(explode("\n",$field['options']['choices']) as $choice)
107
- {
108
- $array[trim($choice)] = trim($choice);
109
- }
110
- $field['options']['choices'] = $array;
111
- }
112
 
113
- //print_r($field['options']['choices']);
 
 
 
 
114
  ?>
115
  <tr>
116
-
117
  <td>
118
- <label for="<?php echo $field['id']; ?>"><?php echo $field['label']; ?></label>
 
 
119
  <?php $this->create_field($field); ?>
120
  </td>
121
  </tr>
21
  }
22
 
23
  // get options from first (top level) acf
24
+ $adv_options = $this->get_acf_options($acfs[0]->ID);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
 
27
  ?>
28
 
 
29
 
30
+ <input type="hidden" name="ei_noncename" id="ei_noncename" value="<?php echo wp_create_nonce('ei-n'); ?>" />
31
  <input type="hidden" name="input_meta_box" value="true" />
32
+ <input type="hidden" name="acf_id" value="<?php echo implode(',',$acf_ids); ?>" />
33
+ <?php
34
 
35
+
36
+ // hide the_content with style (faster than waiting for jquery to load)
37
+ if(!in_array('the_content',$adv_options->show_on_page)): ?>
38
  <style type="text/css">
39
  #postdivrich {display: none;}
40
  </style>
41
  <?php endif; ?>
42
 
43
+
44
+ <?php foreach($adv_options->show_on_page as $option): ?>
45
  <input type="hidden" name="show_<?php echo $option; ?>" value="true" />
46
  <?php endforeach; ?>
47
 
48
  <table class="acf_input" id="acf_input">
49
+ <?php $i = -1; ?>
50
+ <?php foreach($fields as $field): $i++ ?>
51
  <?php
52
+
53
  // if they didn't select a type, skip this field
54
+ if($field->type == 'null')
55
  {
56
  continue;
57
  }
 
 
 
 
 
 
 
 
 
 
 
 
58
 
 
 
 
 
 
 
 
 
 
 
59
 
60
+ // set value, id and name for field
61
+ $field->value = $this->load_value_for_input($post->ID, $field);
62
+ $field->input_id = 'acf['.$i.'][value]';
63
+ $field->input_name = 'acf['.$i.'][value]';
64
+
65
  ?>
66
  <tr>
 
67
  <td>
68
+ <input type="hidden" name="acf[<?php echo $i; ?>][field_type]" value="<?php echo $field->type; ?>" />
69
+ <input type="hidden" name="acf[<?php echo $i; ?>][field_id]" value="<?php echo $field->id; ?>" />
70
+ <label for="<?php echo $field->input_id ?>"><?php echo $field->label ?></label>
71
  <?php $this->create_field($field); ?>
72
  </td>
73
  </tr>
core/input_save.php CHANGED
@@ -4,43 +4,44 @@
4
  ---------------------------------------------------------------------------------------------*/
5
  if($_POST['input_meta_box'] == 'true')
6
  {
7
- // save acf id's
8
- add_post_meta($post_id, '_acf_id', $_POST['acf']['id']);
9
-
10
- // get field id's
11
- $acf_id = explode(',',$_POST['acf']['id']);
12
- $fields = array();
 
 
 
 
 
13
 
14
- if(empty($acf_id)){return null;}
15
- foreach($acf_id as $id)
16
- {
17
- $this_fields = $this->get_fields($id);
18
- if(empty($this_fields)){return null;}
19
- foreach($this_fields as $this_field)
 
 
 
 
20
  {
21
- $fields[] = $this_field;
22
  }
23
- }
24
-
25
- // now we have this page's fields, loop through them and save
26
- foreach($fields as $field)
27
- {
28
- // if this field has not been submitted, don't save, just continue to next loop
29
- /*if(!isset($_POST['acf'][$field['name']]))
30
  {
31
- echo $field['name'] . ' was not set';
32
- continue;
33
- }*/
34
-
35
- $options = array(
36
- 'post_id' => $post_id,
37
- 'field_name' => $field['name'],
38
- 'field_value' => $_POST['acf'][$field['name']],
39
- 'field_type' => $field['type'],
40
- );
41
 
42
- $this->save_field($options);
43
- }
44
 
45
  }
46
 
4
  ---------------------------------------------------------------------------------------------*/
5
  if($_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
+ // save which ACF's were here: for use in the api
16
+ add_post_meta($post_id, '_acf_id', $_POST['acf_id']);
17
+
18
 
19
+ // set table name
20
+ global $wpdb;
21
+ $table_name = $wpdb->prefix.'acf_values';
22
+
23
+ // remove all old values from the database
24
+ $wpdb->query("DELETE FROM $table_name WHERE post_id = '$post_id'");
25
+
26
+ foreach($_POST['acf'] as $field)
27
+ {
28
+ if(method_exists($this->fields[$field['field_type']], 'save_input'))
29
  {
30
+ $this->fields[$field['field_type']]->save_input($post_id, $field);
31
  }
32
+ else
 
 
 
 
 
 
33
  {
34
+ // insert new data
35
+ $new_id = $wpdb->insert($table_name, array(
36
+ 'post_id' => $post_id,
37
+ 'field_id' => $field['field_id'],
38
+ 'value' => $field['value']
39
+ ));
40
+ }
41
+
 
 
42
 
43
+ }
44
+
45
 
46
  }
47
 
core/location_meta_box.php CHANGED
@@ -5,20 +5,24 @@
5
  // get options
6
  $location = $this->get_acf_location($post->ID);
7
 
8
- // if post_type exists, it will be an array and neds to be exploded
9
- if(is_array($location['post_type']))
10
- {
11
- $location['post_type'] = explode(',',str_replace(' ','',$location['post_type']));
12
- }
13
- elseif(empty($location['post_type']))
14
- {
15
- $location['post_type'] = array('false' => 'false');
16
- }
17
-
18
- //print_r($location);
19
-
20
  ?>
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  <input type="hidden" name="location_meta_box" value="true" />
23
  <input type="hidden" name="ei_noncename" id="ei_noncename" value="<?php echo wp_create_nonce('ei-n'); ?>" />
24
 
@@ -42,19 +46,61 @@
42
  unset($post_types['acf']);
43
 
44
 
45
- $this->create_field(array('type'=>'select','name'=>'acf[location][post_type]','value'=>$location['post_type'],'id'=>'post_type', 'options' => array('choices' => $post_types, 'multiple' => 'true')));
 
 
 
 
 
 
 
 
 
 
 
46
  ?>
47
  <p class="description">Selecting a post type here will add this ACF to all edit screens of that post type.<br />(if your custom post type does not appear, make sure it is publicly query-able)<br /><br />
48
  Tip: Unselect post types and use the options below to customise your ACF location!<br />
49
  (command+click)</p>
50
  </td>
51
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  <tr>
53
  <td class="label">
54
  <label for="page_slug">Page Slug's</label>
55
  </td>
56
  <td>
57
- <?php $this->create_field(array('type'=>'text','name'=>'acf[location][page_slug]','value'=>$location['page_slug'],'id'=>'page_slug')); ?>
 
 
 
 
 
 
 
 
 
 
 
58
  <p class="description">eg. home, about-us</p>
59
  </td>
60
  </tr>
@@ -63,7 +109,18 @@
63
  <label for="post_id">Post ID's</label>
64
  </td>
65
  <td>
66
- <?php $this->create_field(array('type'=>'text','name'=>'acf[location][post_id]','value'=>$location['post_id'],'id'=>'post_id')); ?>
 
 
 
 
 
 
 
 
 
 
 
67
  <p class="description">eg. 1, 2, 3</p>
68
  </td>
69
  </tr>
@@ -72,7 +129,18 @@
72
  <label for="template_name">Page Template's</label>
73
  </td>
74
  <td>
75
- <?php $this->create_field(array('type'=>'text','name'=>'acf[location][page_template]','value'=>$location['page_template'],'id'=>'page_template')); ?>
 
 
 
 
 
 
 
 
 
 
 
76
  <p class="description">eg. home_page.php</p>
77
  </td>
78
  </tr>
@@ -81,7 +149,18 @@
81
  <label for="page_parent">Page Parent ID's</label>
82
  </td>
83
  <td>
84
- <?php $this->create_field(array('type'=>'text','name'=>'acf[location][parent_id]','value'=>$location['parent_id'],'id'=>'parent_id')); ?>
 
 
 
 
 
 
 
 
 
 
 
85
  <p class="description">eg. 1, 2, 3</p>
86
  </td>
87
  </tr>
@@ -90,7 +169,20 @@
90
  <label for="page_parent">Overrides</label>
91
  </td>
92
  <td>
93
- <?php $this->create_field(array('type'=>'checkbox','name'=>'acf[location][ignore_other_acf]','value'=>$location['ignore_other_acf'],'id'=>'ignore_other_acf', 'options' => array('choices' => array('true' => 'Ignore all other Advanced Custom Field\'s')))); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  <p class="description">Tick this box to remove all other ACF's <br />(from the edit screen where this ACF appears)</p>
95
  </td>
96
  </tr>
5
  // get options
6
  $location = $this->get_acf_location($post->ID);
7
 
8
+ // create temp field from creating inputs
9
+ $temp_field = new stdClass();
 
 
 
 
 
 
 
 
 
 
10
  ?>
11
 
12
+ <a class="help" href="javascript:;"></a>
13
+
14
+ <div class="help_box_mask">
15
+ <div class="help_box">
16
+ <h4>Enter values in the fields below to add this ACF to an edit screen</h4>
17
+ <ul>
18
+ <li>The values you enter bellow will be used to match against edit screens.</li>
19
+ <li>If any of the values match the edit screen, this ACF will be used </li>
20
+ <li>Blank fields will be ignored</li>
21
+ <li>Use the override to remove all previous ACF's form an edit screen. This is useful for creating an ACF for all normal pages, and then creating a custom ACF for a home page (page title = 'Home'). Please note that the home page ACF needs a higher page order to remove ACF's before it.</li>
22
+ </ul>
23
+ </div>
24
+ </div>
25
+
26
  <input type="hidden" name="location_meta_box" value="true" />
27
  <input type="hidden" name="ei_noncename" id="ei_noncename" value="<?php echo wp_create_nonce('ei-n'); ?>" />
28
 
46
  unset($post_types['acf']);
47
 
48
 
49
+ $temp_field->type = 'select';
50
+ $temp_field->input_name = 'acf[location][post_types]';
51
+ $temp_field->input_class = '';
52
+ $temp_field->input_id = 'post_types';
53
+ $temp_field->value = $location->post_types;
54
+ $temp_field->options = array(
55
+ 'choices' => $post_types,
56
+ 'multiple' => '1'
57
+ );
58
+
59
+ $this->create_field($temp_field);
60
+
61
  ?>
62
  <p class="description">Selecting a post type here will add this ACF to all edit screens of that post type.<br />(if your custom post type does not appear, make sure it is publicly query-able)<br /><br />
63
  Tip: Unselect post types and use the options below to customise your ACF location!<br />
64
  (command+click)</p>
65
  </td>
66
  </tr>
67
+ <tr>
68
+ <td class="label">
69
+ <label for="page_title">Page Title's</label>
70
+ </td>
71
+ <td>
72
+ <?php
73
+
74
+ $temp_field->type = 'text';
75
+ $temp_field->input_name = 'acf[location][page_titles]';
76
+ $temp_field->input_class = '';
77
+ $temp_field->input_id = 'page_titles';
78
+ $temp_field->value = implode(', ',$location->page_titles);
79
+ $temp_field->options = array();
80
+
81
+ $this->create_field($temp_field);
82
+
83
+ ?>
84
+ <p class="description">eg. Home, About Us</p>
85
+ </td>
86
+ </tr>
87
  <tr>
88
  <td class="label">
89
  <label for="page_slug">Page Slug's</label>
90
  </td>
91
  <td>
92
+ <?php
93
+
94
+ $temp_field->type = 'text';
95
+ $temp_field->input_name = 'acf[location][page_slugs]';
96
+ $temp_field->input_class = '';
97
+ $temp_field->input_id = 'page_slugs';
98
+ $temp_field->value = implode(', ',$location->page_slugs);
99
+ $temp_field->options = array();
100
+
101
+ $this->create_field($temp_field);
102
+
103
+ ?>
104
  <p class="description">eg. home, about-us</p>
105
  </td>
106
  </tr>
109
  <label for="post_id">Post ID's</label>
110
  </td>
111
  <td>
112
+ <?php
113
+
114
+ $temp_field->type = 'text';
115
+ $temp_field->input_name = 'acf[location][post_ids]';
116
+ $temp_field->input_class = '';
117
+ $temp_field->input_id = 'post_ids';
118
+ $temp_field->value = implode(', ',$location->post_ids);
119
+ $temp_field->options = array();
120
+
121
+ $this->create_field($temp_field);
122
+
123
+ ?>
124
  <p class="description">eg. 1, 2, 3</p>
125
  </td>
126
  </tr>
129
  <label for="template_name">Page Template's</label>
130
  </td>
131
  <td>
132
+ <?php
133
+
134
+ $temp_field->type = 'text';
135
+ $temp_field->input_name = 'acf[location][page_templates]';
136
+ $temp_field->input_class = '';
137
+ $temp_field->input_id = 'page_templates';
138
+ $temp_field->value = implode(', ',$location->page_templates);
139
+ $temp_field->options = array();
140
+
141
+ $this->create_field($temp_field);
142
+
143
+ ?>
144
  <p class="description">eg. home_page.php</p>
145
  </td>
146
  </tr>
149
  <label for="page_parent">Page Parent ID's</label>
150
  </td>
151
  <td>
152
+ <?php
153
+
154
+ $temp_field->type = 'text';
155
+ $temp_field->input_name = 'acf[location][page_parents]';
156
+ $temp_field->input_class = '';
157
+ $temp_field->input_id = 'page_parents';
158
+ $temp_field->value = implode(', ',$location->page_parents);
159
+ $temp_field->options = array();
160
+
161
+ $this->create_field($temp_field);
162
+
163
+ ?>
164
  <p class="description">eg. 1, 2, 3</p>
165
  </td>
166
  </tr>
169
  <label for="page_parent">Overrides</label>
170
  </td>
171
  <td>
172
+ <?php
173
+
174
+ $temp_field->type = 'true_false';
175
+ $temp_field->input_name = 'acf[location][ignore_other_acfs]';
176
+ $temp_field->input_class = '';
177
+ $temp_field->input_id = 'ignore_other_acfs';
178
+ $temp_field->value = $location->ignore_other_acfs;
179
+ $temp_field->options = array(
180
+ 'message' => 'Ignore all other Advanced Custom Field\'s'
181
+ );
182
+
183
+ $this->create_field($temp_field);
184
+
185
+ ?>
186
  <p class="description">Tick this box to remove all other ACF's <br />(from the edit screen where this ACF appears)</p>
187
  </td>
188
  </tr>
core/location_save.php CHANGED
@@ -4,24 +4,59 @@
4
  ---------------------------------------------------------------------------------------------*/
5
  if($_POST['location_meta_box'] == 'true')
6
  {
7
- $location = $_POST['acf']['location'];
 
 
8
 
9
- // add post meta
10
- if(is_array($location['post_type']))
11
- {
12
- $location['post_type'] = implode(',',$location['post_type']);
13
- }
14
- if(is_array($location['ignore_other_acf']))
 
 
15
  {
16
- $location['ignore_other_acf'] = implode(', ',$location['ignore_other_acf']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  }
18
-
19
- add_post_meta($post_id, '_acf_location_post_type', $location['post_type']);
20
- add_post_meta($post_id, '_acf_location_page_slug', $location['page_slug']);
21
- add_post_meta($post_id, '_acf_location_post_id', $location['post_id']);
22
- add_post_meta($post_id, '_acf_location_page_template', $location['page_template']);
23
- add_post_meta($post_id, '_acf_location_parent_id', $location['parent_id']);
24
- add_post_meta($post_id, '_acf_location_ignore_other_acf', $location['ignore_other_acf']);
25
  }
26
 
27
  ?>
4
  ---------------------------------------------------------------------------------------------*/
5
  if($_POST['location_meta_box'] == 'true')
6
  {
7
+ // set table name
8
+ global $wpdb;
9
+ $table_name = $wpdb->prefix.'acf_options';
10
 
11
+
12
+ // remove all old fields from the database
13
+ $wpdb->query("DELETE FROM $table_name WHERE acf_id = '$post_id' AND type = 'location'");
14
+
15
+
16
+ // turn inputs into database friendly data
17
+ $locations = $_POST['acf']['location'];
18
+ if($locations)
19
  {
20
+ foreach($locations as $key => $value)
21
+ {
22
+ if(empty($value))
23
+ {
24
+ continue;
25
+ }
26
+
27
+
28
+ // if not an array (most inputs are strings), convert into an array
29
+ if($key == 'post_types')
30
+ {
31
+ // already array, serialize the array for database save
32
+ $value = serialize($value);
33
+ }
34
+ elseif($key == 'ignore_other_acfs')
35
+ {
36
+ // do nothing
37
+ }
38
+ else
39
+ {
40
+ // must be a string, lets explode it!
41
+ $value = str_replace(', ',',',$value);
42
+ $value = explode(',',$value);
43
+
44
+ // serialize the array for database save
45
+ $value = serialize($value);
46
+ }
47
+
48
+ // location can now be saved
49
+ $new_id = $wpdb->insert($table_name, array(
50
+ 'acf_id' => $post_id,
51
+ 'name' => $key,
52
+ 'value' => $value,
53
+ 'type' => 'location'
54
+ ));
55
+
56
+ //echo $post_id.' : '.$key.': '.' : '.$value;
57
+
58
+ }
59
  }
 
 
 
 
 
 
 
60
  }
61
 
62
  ?>
core/options_meta_box.php CHANGED
@@ -4,7 +4,9 @@
4
 
5
  // get options
6
  $options = $this->get_acf_options($post->ID);
7
- //print_r($options);
 
 
8
  ?>
9
 
10
  <input type="hidden" name="options_meta_box" value="true" />
@@ -16,30 +18,59 @@
16
  <label for="post_type">Show on page</label>
17
  </td>
18
  <td>
19
- <?php
20
- $show = array(
 
 
 
 
 
 
 
21
  'the_content' => 'Content Editor',
22
  'custom_fields' => 'Custom Fields',
23
  'discussion' => 'Discussion',
24
  'comments' => 'Comments',
25
  'slug' => 'Slug',
26
  'author' => 'Author'
27
- );
28
-
29
- if(empty($options['show_on_page']))
30
- {
31
- $options['show_on_page'] = 'bilbo bagains';
32
- }
33
  ?>
34
- <?php $this->create_field(array(
35
- 'type' => 'checkbox',
36
- 'name' => 'acf[options][show_on_page]',
37
- 'value' => $options['show_on_page'],
38
- 'id' => 'show_on_page',
39
- 'options' => array('choices' => $show)
40
- )); ?>
41
  <p class="description">Unselected items will not be shown on the edit screen.<br>This is useful to clean up the edit page</p>
42
  </td>
43
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  </table>
4
 
5
  // get options
6
  $options = $this->get_acf_options($post->ID);
7
+
8
+ // create temp field from creating inputs
9
+ $temp_field = new stdClass();
10
  ?>
11
 
12
  <input type="hidden" name="options_meta_box" value="true" />
18
  <label for="post_type">Show on page</label>
19
  </td>
20
  <td>
21
+ <?php
22
+
23
+ $temp_field->type = 'checkbox';
24
+ $temp_field->input_name = 'acf[options][show_on_page]';
25
+ $temp_field->input_class = '';
26
+ $temp_field->input_id = 'show_on_page';
27
+ $temp_field->value = $options->show_on_page;
28
+ $temp_field->options = array(
29
+ 'choices' => array(
30
  'the_content' => 'Content Editor',
31
  'custom_fields' => 'Custom Fields',
32
  'discussion' => 'Discussion',
33
  'comments' => 'Comments',
34
  'slug' => 'Slug',
35
  'author' => 'Author'
36
+ )
37
+ );
38
+
39
+ $this->create_field($temp_field);
40
+
 
41
  ?>
42
+
 
 
 
 
 
 
43
  <p class="description">Unselected items will not be shown on the edit screen.<br>This is useful to clean up the edit page</p>
44
  </td>
45
  </tr>
46
+ <tr>
47
+ <td class="label">
48
+ <label for="post_type">Filter Users</label>
49
+ </td>
50
+ <td>
51
+ <?php
52
+
53
+ $temp_field->type = 'select';
54
+ $temp_field->input_name = 'acf[options][user_roles]';
55
+ $temp_field->input_class = '';
56
+ $temp_field->input_id = 'user_roles';
57
+ $temp_field->value = $options->user_roles;
58
+ $temp_field->options = array(
59
+ 'multiple' => '1',
60
+ 'choices' => array(
61
+ '10' => 'Administrator',
62
+ '7' => 'Editor',
63
+ '4' => 'Author',
64
+ '1' => 'contributor'
65
+ )
66
+ );
67
+
68
+ $this->create_field($temp_field);
69
+
70
+ ?>
71
+ <p class="description">Select a user type to allow them to view / use this ACF<br />
72
+ * unselecting all is the same as selecting all</p>
73
+ </td>
74
+ </tr>
75
 
76
  </table>
core/options_save.php CHANGED
@@ -4,17 +4,39 @@
4
  ---------------------------------------------------------------------------------------------*/
5
  if($_POST['options_meta_box'] == 'true')
6
  {
 
 
 
 
 
 
7
  $options = $_POST['acf']['options'];
8
 
9
- if(is_array($options['show_on_page']))
 
 
 
 
 
 
10
  {
11
- $options['show_on_page'] = implode(', ',$options['show_on_page']);
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  }
13
 
14
 
15
- // add post meta
16
- add_post_meta($post_id, '_acf_option_show_on_page', $options['show_on_page']);
17
-
18
  }
19
 
20
  ?>
4
  ---------------------------------------------------------------------------------------------*/
5
  if($_POST['options_meta_box'] == 'true')
6
  {
7
+ // set table name
8
+ global $wpdb;
9
+ $table_name = $wpdb->prefix.'acf_options';
10
+
11
+
12
+ // turn inputs into database friendly data
13
  $options = $_POST['acf']['options'];
14
 
15
+
16
+ // remove all old fields from the database
17
+ $wpdb->query("DELETE FROM $table_name WHERE acf_id = '$post_id' AND type = 'option'");
18
+
19
+
20
+ // loop through and save
21
+ if($options)
22
  {
23
+ foreach($options as $key => $value)
24
+ {
25
+ // already array, serialize the array for database save
26
+ $value = serialize($value);
27
+
28
+
29
+ //save todatabase
30
+ $new_id = $wpdb->insert($table_name, array(
31
+ 'acf_id' => $post_id,
32
+ 'name' => $key,
33
+ 'value' => $value,
34
+ 'type' => 'option'
35
+ ));
36
+ }
37
  }
38
 
39
 
 
 
 
40
  }
41
 
42
  ?>
core/update.php ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $version = get_option('acf_version','1.0.5');
4
+
5
+ if(version_compare($version,'1.1.0') < 0)
6
+ {
7
+ // Version is less than 1.1.0
8
+
9
+ global $wpdb;
10
+
11
+ // create acf_fields table
12
+ $table_name = $wpdb->prefix.'acf_fields';
13
+ $sql = "CREATE TABLE " . $table_name . " (
14
+ id bigint(20) NOT NULL AUTO_INCREMENT,
15
+ order_no int(9) NOT NULL DEFAULT '0',
16
+ post_id bigint(20) NOT NULL DEFAULT '0',
17
+ parent_id bigint(20) NOT NULL DEFAULT '0',
18
+ label text NOT NULL,
19
+ name text NOT NULL,
20
+ type text NOT NULL,
21
+ options text NOT NULL,
22
+ UNIQUE KEY id (id)
23
+ );";
24
+
25
+
26
+ // create acf_options table
27
+ $table_name = $wpdb->prefix.'acf_options';
28
+ $sql .= "CREATE TABLE " . $table_name . " (
29
+ id bigint(20) NOT NULL AUTO_INCREMENT,
30
+ acf_id bigint(20) NOT NULL DEFAULT '0',
31
+ name text NOT NULL,
32
+ value text NOT NULL,
33
+ type text NOT NULL,
34
+ UNIQUE KEY id (id)
35
+ );";
36
+
37
+
38
+ // create acf_options table
39
+ $table_name = $wpdb->prefix.'acf_values';
40
+ $sql .= "CREATE TABLE " . $table_name . " (
41
+ id bigint(20) NOT NULL AUTO_INCREMENT,
42
+ order_no int(9) NOT NULL DEFAULT '0',
43
+ field_id bigint(20) NOT NULL DEFAULT '0',
44
+ value text NOT NULL,
45
+ post_id bigint(20) NOT NULL DEFAULT '0',
46
+ UNIQUE KEY id (id)
47
+ );";
48
+
49
+
50
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
51
+ dbDelta($sql);
52
+
53
+
54
+ $acfs = get_posts(array(
55
+ 'numberposts' => -1,
56
+ 'post_type' => 'acf',
57
+ ));
58
+
59
+
60
+ if($acfs)
61
+ {
62
+ foreach($acfs as $acf)
63
+ {
64
+ $keys = get_post_custom_keys($acf->ID);
65
+
66
+ if(empty($keys)){continue;}
67
+
68
+
69
+ // FIELDS
70
+ $table_name = $wpdb->prefix.'acf_fields';
71
+
72
+
73
+ for($i = 0; $i < 99; $i++)
74
+ {
75
+ if(in_array('_acf_field_'.$i.'_label',$keys))
76
+ {
77
+ $field = array(
78
+ 'label' => get_post_meta($acf->ID, '_acf_field_'.$i.'_label', true),
79
+ 'name' => get_post_meta($acf->ID, '_acf_field_'.$i.'_name', true),
80
+ 'type' => get_post_meta($acf->ID, '_acf_field_'.$i.'_type', true),
81
+ 'options' => unserialize(get_post_meta($acf->ID, '_acf_field_'.$i.'_options', true)) // explode choices!
82
+ );
83
+
84
+ // if choices, exlode them
85
+ if($field['options']['choices'])
86
+ {
87
+ // explode choices from each line
88
+ if(strpos($field['options']['choices'], "\n") !== false)
89
+ {
90
+ // found multiple lines, explode it
91
+ $field['options']['choices'] = explode("\n", $field['options']['choices']);
92
+ }
93
+ else
94
+ {
95
+ // no multiple lines!
96
+ $field['options']['choices'] = array($field['options']['choices']);
97
+ }
98
+
99
+ $new_choices = array();
100
+ foreach($field['options']['choices'] as $choice)
101
+ {
102
+ $new_choices[trim($choice)] = trim($choice);
103
+ }
104
+
105
+
106
+ // return array containing all choices
107
+ $field['options']['choices'] = $new_choices;
108
+
109
+ }
110
+
111
+ // now save field to database
112
+ $data = array(
113
+ 'order_no' => $i,
114
+ 'post_id' => $acf->ID,
115
+ 'label' => $field['label'],
116
+ 'name' => $field['name'],
117
+ 'type' => $field['type'],
118
+ 'options' => serialize($field['options']),
119
+
120
+ );
121
+
122
+
123
+ // save field as row in database
124
+
125
+ $new_id = $wpdb->insert($table_name, $data);
126
+ }
127
+ else
128
+ {
129
+ // data doesnt exist, break loop
130
+ break;
131
+ }
132
+ }
133
+
134
+
135
+ // START LOCATION
136
+ $table_name = $wpdb->prefix.'acf_options';
137
+ //$wpdb->query("DELETE FROM $table_name WHERE acf_id = '$acf->ID' AND type = 'location'");
138
+
139
+ $location = array(
140
+ 'post_types' => get_post_meta($acf->ID, '_acf_location_post_type', true),
141
+ 'page_slugs' => get_post_meta($acf->ID, '_acf_location_page_slug', true),
142
+ 'post_ids' => get_post_meta($acf->ID, '_acf_location_post_id', true),
143
+ 'page_templates' => get_post_meta($acf->ID, '_acf_location_page_template', true),
144
+ 'parent_ids' => get_post_meta($acf->ID, '_acf_location_parent_id', true),
145
+ 'ignore_other_acfs' => get_post_meta($acf->ID, '_acf_location_ignore_other_acf', true),
146
+ );
147
+
148
+ foreach($location as $key => $value)
149
+ {
150
+ if(empty($value))
151
+ {
152
+ continue;
153
+ }
154
+
155
+ if(strpos($value, ',') !== false)
156
+ {
157
+ // found ',', explode it
158
+ $value = str_replace(', ',',',$value);
159
+ $value = explode(',', $value);
160
+ }
161
+ else
162
+ {
163
+ // no ','!
164
+ $value = array($value);
165
+ }
166
+
167
+
168
+ $new_id = $wpdb->insert($table_name, array(
169
+ 'acf_id' => $acf->ID,
170
+ 'name' => $key,
171
+ 'value' => serialize($value),
172
+ 'type' => 'location'
173
+ ));
174
+ }
175
+ // END LOCATION
176
+
177
+
178
+ // START OPTIONS
179
+ $table_name = $wpdb->prefix.'acf_options';
180
+ //$wpdb->query("DELETE FROM $table_name WHERE acf_id = '$acf->ID' AND type = 'option'");
181
+
182
+
183
+ $show_on_page = get_post_meta($acf->ID, '_acf_option_show_on_page', true);
184
+
185
+
186
+ if(!empty($show_on_page))
187
+ {
188
+ $show_on_page = str_replace(', ',',',$show_on_page);
189
+ $show_on_page = explode(',',$show_on_page);
190
+
191
+
192
+ $new_id = $wpdb->insert($table_name, array(
193
+ 'acf_id' => $acf->ID,
194
+ 'name' => 'show_on_page',
195
+ 'value' => serialize($show_on_page),
196
+ 'type' => 'option'
197
+ ));
198
+ }
199
+ // END OPTIONS
200
+
201
+
202
+ // delete data
203
+ foreach(get_post_custom($acf->ID) as $key => $values)
204
+ {
205
+ if(strpos($key, '_acf') !== false)
206
+ {
207
+ // this custom field needs to be deleted!
208
+ delete_post_meta($acf->ID, $key);
209
+ }
210
+ }
211
+ }
212
+ }
213
+ // START VALUES
214
+
215
+ $table_name = $wpdb->prefix.'acf_values';
216
+ //$wpdb->query("DELETE FROM $table_name WHERE acf_id = '$acf->ID' AND type = 'option'");
217
+
218
+ $posts = get_posts(array(
219
+ 'numberposts' => -1,
220
+ 'post_type' => 'any'
221
+ ));
222
+
223
+ if($posts)
224
+ {
225
+ foreach($posts as $post)
226
+ {
227
+ foreach(get_post_custom($post->ID) as $key => $value)
228
+ {
229
+ if(strpos($key, '_acf') !== false)
230
+ {
231
+ // found an acf cusomt field!
232
+ $name = str_replace('_acf_','',$key);
233
+
234
+ if($name == 'id'){continue;}
235
+
236
+ // get field id
237
+ $table_name = $wpdb->prefix.'acf_fields';
238
+ $field_id = $wpdb->get_var("SELECT id FROM $table_name WHERE name = '$name'");
239
+
240
+ $table_name = $wpdb->prefix.'acf_values';
241
+ $new_id = $wpdb->insert($table_name, array(
242
+ 'field_id' => $field_id,
243
+ 'value' => $value[0],
244
+ 'post_id' => $post->ID,
245
+ ));
246
+
247
+ }
248
+ }
249
+
250
+ // delete data
251
+ foreach(get_post_custom($post->ID) as $key => $values)
252
+ {
253
+ if(strpos($key, '_acf') !== false)
254
+ {
255
+ // this custom field needs to be deleted!
256
+ delete_post_meta($post->ID, $key);
257
+ }
258
+ }
259
+
260
+
261
+ }
262
+ }
263
+
264
+ // END VALUES
265
+
266
+
267
+ update_option('acf_version','1.1.0');
268
+ $version = '1.1.0';
269
+ }
270
+
271
+ ?>
css/style.global.css CHANGED
@@ -36,7 +36,8 @@ table.acf_input > tbody > tr > td > label{
36
  }
37
 
38
  table.acf_input > tbody > tr > td > input[type=text],
39
- table.acf_input > tbody > tr > td > textarea{
 
40
  width: 300px;
41
  float: left;
42
  }
36
  }
37
 
38
  table.acf_input > tbody > tr > td > input[type=text],
39
+ table.acf_input > tbody > tr > td > textarea,
40
+ table.acf_input > tbody > tr > td > select{
41
  width: 300px;
42
  float: left;
43
  }
css/style.info.css CHANGED
@@ -33,4 +33,17 @@
33
  float: left;
34
  margin: 0 0 0 8px;
35
  padding: 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  }
33
  float: left;
34
  margin: 0 0 0 8px;
35
  padding: 0;
36
+ }
37
+
38
+ .postbox h3.hndle {
39
+ cursor: default;
40
+ position: relative;
41
+ }
42
+
43
+ .postbox h3.hndle a.button {
44
+ height: 13px;
45
+ line-height: 12px;
46
+ position: absolute;
47
+ right: 6px;
48
+ top: 2px;
49
  }
css/style.location.css CHANGED
@@ -6,9 +6,7 @@
6
  background: transparent none;
7
  }
8
 
9
- .postbox#acf_location .hndlediv {
10
- display: none;
11
- }
12
 
13
 
14
  .postbox#acf_location .inside {
@@ -28,4 +26,52 @@ table.acf_input > tbody > tr > td > select[multiple="multiple"] {
28
  float: left;
29
  width: 300px;
30
  height: auto !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
6
  background: transparent none;
7
  }
8
 
9
+
 
 
10
 
11
 
12
  .postbox#acf_location .inside {
26
  float: left;
27
  width: 300px;
28
  height: auto !important;
29
+ }
30
+
31
+ .postbox#acf_location a.help {
32
+ width: 16px;
33
+ height: 17px;
34
+ background: url(../images/help.png) 0 0 no-repeat;
35
+ position: absolute;
36
+ top: 5px;
37
+ right: 5px;
38
+ }
39
+
40
+ .postbox#acf_location .handlediv {
41
+ display: none;
42
+ }
43
+
44
+ .help_box_mask {
45
+ display: none;
46
+ position: relative;
47
+ }
48
+
49
+ .help_box {
50
+ background: #EAF2FA;
51
+ border: #DFDFDF solid 1px;
52
+ padding: 8px 16px;
53
+ margin-bottom: 10px;
54
+ }
55
+
56
+ .help_box h4 {
57
+ margin: 8px 0 0;
58
+ padding: 0;
59
+ }
60
+
61
+ .help_box p {
62
+
63
+ }
64
+
65
+ .help_box ul {
66
+ margin: 12px 0;
67
+ padding: 6px 0 0 14px;
68
+ list-style: square;
69
+ }
70
+
71
+ .help_box ul li {
72
+ display: list-item;
73
+ font-size: 11px;
74
+ line-height: 12px;
75
+ color: #6b8298;
76
+ margin-bottom: 6px;
77
  }
images/help.png ADDED
Binary file
js/functions.fields.js CHANGED
@@ -151,6 +151,7 @@
151
  $.fn.reset_values = function(){
152
 
153
  $(this).find('input[type="text"]').val('');
 
154
  $(this).find('textarea').val('');
155
  $(this).find('select option').removeAttr('selected');
156
  $(this).find('select[multiple="multiple"] option').attr('selected','selected');
@@ -195,6 +196,10 @@
195
  });
196
 
197
  });
 
 
 
 
198
  });
199
 
200
  })(jQuery);
151
  $.fn.reset_values = function(){
152
 
153
  $(this).find('input[type="text"]').val('');
154
+ $(this).find('input[type="hidden"]').val('');
155
  $(this).find('textarea').val('');
156
  $(this).find('select option').removeAttr('selected');
157
  $(this).find('select[multiple="multiple"] option').attr('selected','selected');
196
  });
197
 
198
  });
199
+
200
+ $('div.postbox a.help').click(function(){
201
+ $('div.postbox .help_box_mask').animate({'height':'toggle'}, 500);
202
+ });
203
  });
204
 
205
  })(jQuery);
readme.txt CHANGED
@@ -18,6 +18,7 @@ Advanced Custom Fields is the perfect solution for any wordpress website which n
18
  * Add, Edit and reorder infinite rows to your fields
19
  * Easily load data through a simple and friendly API
20
  * Uses the native WordPress custom post type for ease of use and fast processing
 
21
 
22
  = Field Types =
23
  * Text (type text, api returns text)
@@ -30,6 +31,7 @@ Advanced Custom Fields is the perfect solution for any wordpress website which n
30
  * Page Link (select 1 or more page, post or custom post types, api returns the url)
31
  * Post Object (select 1 or more page, post or custom post types, api returns post objects)
32
  * Date Picker (jquery date picker, options for format, api returns string)
 
33
 
34
  = Tested on =
35
  * Mac Firefox :)
@@ -48,6 +50,8 @@ http://plugins.elliotcondon.com/advanced-custom-fields/
48
  http://support.plugins.elliotcondon.com/categories/advanced-custom-fields/
49
 
50
  = Please Vote and Enjoy =
 
 
51
 
52
  == Installation ==
53
 
@@ -73,6 +77,17 @@ http://support.plugins.elliotcondon.com/categories/advanced-custom-fields/
73
 
74
  == Changelog ==
75
 
 
 
 
 
 
 
 
 
 
 
 
76
  = 1.0.5 =
77
  * New Field Type: Post Object
78
  * Added multiple select option to Select field type
18
  * Add, Edit and reorder infinite rows to your fields
19
  * Easily load data through a simple and friendly API
20
  * Uses the native WordPress custom post type for ease of use and fast processing
21
+ * Now uses custom Database tables to improve speed, reliability and future development
22
 
23
  = Field Types =
24
  * Text (type text, api returns text)
31
  * Page Link (select 1 or more page, post or custom post types, api returns the url)
32
  * Post Object (select 1 or more page, post or custom post types, api returns post objects)
33
  * Date Picker (jquery date picker, options for format, api returns string)
34
+ * True / False (tick box with message, api returns true or false)
35
 
36
  = Tested on =
37
  * Mac Firefox :)
50
  http://support.plugins.elliotcondon.com/categories/advanced-custom-fields/
51
 
52
  = Please Vote and Enjoy =
53
+ Your votes really make a difference! Thanks.
54
+
55
 
56
  == Installation ==
57
 
77
 
78
  == Changelog ==
79
 
80
+ = 1.1.0 =
81
+ * Lots of Field Type Bug Fixes
82
+ * Now uses custom database tables to save and store data!
83
+ * Lots of tidying up
84
+ * New help button for location meta box
85
+ * Added $post_id parameter to API functions (so you can get fields from any post / page)
86
+ * Added support for key and value for select and checkbox field types
87
+ * Re wrote most of the core files due to new database tables
88
+ * Update script should copy across your old data to the new data system
89
+ * Added True / False Field Type
90
+
91
  = 1.0.5 =
92
  * New Field Type: Post Object
93
  * Added multiple select option to Select field type