Advanced Custom Fields - Version 1.1.2

Version Description

  • Fixed WYSIWYG API format issue
  • Fixed Page Link API format issue
  • Select / Checkbox can now contain a url in the value or label
  • Can now unselect all user types form field options
  • Updated value save / read functions
  • Lots of small bug fixes
Download this release

Release Info

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

Code changes from version 1.1.1 to 1.1.2

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.1.1
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.1.1';
37
 
38
  // set text domain
39
  load_plugin_textdomain('acf', false, $this->path.'/lang' );
@@ -257,7 +257,7 @@ class Acf
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;
@@ -367,28 +367,28 @@ class Acf
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)
@@ -401,7 +401,6 @@ class Acf
401
  // return fields
402
  return $fields;
403
 
404
-
405
  }
406
 
407
  /*---------------------------------------------------------------------------------------------
@@ -499,7 +498,7 @@ class Acf
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
  }
@@ -528,7 +527,7 @@ class Acf
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
@@ -576,7 +575,6 @@ class Acf
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
  $value = stripslashes($value);
581
 
582
  }
@@ -593,6 +591,30 @@ class Acf
593
  return $value;
594
  }
595
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
596
  /*---------------------------------------------------------------------------------------------
597
  * load_value_for_input
598
  *
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.2
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.2';
37
 
38
  // set text domain
39
  load_plugin_textdomain('acf', false, $this->path.'/lang' );
257
  ---------------------------------------------------------------------------------------------*/
258
  function create_field($field)
259
  {
260
+ if(!is_object($this->fields[$field->type]))
261
  {
262
  echo 'error: Field Type does not exist!';
263
  return false;
367
  function get_fields($acf_id)
368
  {
369
 
370
+ // set table name
371
+ global $wpdb;
372
+ $table_name = $wpdb->prefix.'acf_fields';
373
+
374
+
375
+ // get fields
376
+ $fields = $wpdb->get_results("SELECT * FROM $table_name WHERE post_id = '$acf_id' ORDER BY order_no,name");
377
+
378
+
379
+ // if fields are empty, this must be a new or broken acf. add blank field
380
+ if(empty($fields))
381
  {
382
  $fields = array();
383
  $field = new stdClass();
384
  $field->label = '';
385
  $field->name = '';
386
  $field->type = '';
387
+ $field->options = '';
388
 
389
  $fields[] = $field;
 
390
  }
391
 
 
 
 
 
 
 
 
 
392
 
393
  // loop through fields
394
  foreach($fields as $field)
401
  // return fields
402
  return $fields;
403
 
 
404
  }
405
 
406
  /*---------------------------------------------------------------------------------------------
498
  if(!get_post_custom_keys($acf_id))
499
  {
500
  $options->show_on_page = array('the_content', 'discussion', 'custom_fields', 'comments', 'slug', 'author');
501
+ $options->user_roles = array();
502
 
503
  return $options;
504
  }
527
 
528
  // if empty
529
  if(empty($options->show_on_page)){$options->show_on_page = array();}
530
+ if(empty($options->user_roles)){$options->user_roles = array();}
531
 
532
 
533
  // return fields
575
 
576
  // get var
577
  $value = $wpdb->get_var("SELECT value FROM $table_name WHERE field_id = '$field->id' AND post_id = '$post_id'");
 
578
  $value = stripslashes($value);
579
 
580
  }
591
  return $value;
592
  }
593
 
594
+
595
+ /*---------------------------------------------------------------------------------------------
596
+ * load_row_id_for_input
597
+ *
598
+ * @author Elliot Condon
599
+ * @since 1.1.2
600
+ *
601
+ ---------------------------------------------------------------------------------------------*/
602
+ function load_row_id_for_input($post_id, $field_id)
603
+ {
604
+ // set table name
605
+ global $wpdb;
606
+ $table_name = $wpdb->prefix.'acf_values';
607
+
608
+
609
+ // get var
610
+ $value = $wpdb->get_var("SELECT id FROM $table_name WHERE field_id = '$field_id' AND post_id = '$post_id'");
611
+
612
+
613
+ // return id
614
+ return $value;
615
+ }
616
+
617
+
618
  /*---------------------------------------------------------------------------------------------
619
  * load_value_for_input
620
  *
core/admin_head.php CHANGED
@@ -80,7 +80,11 @@ else
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)
80
  // current user role
81
  global $current_user;
82
  get_currentuserinfo();
83
+ if(!empty($options->user_roles))
84
+ {
85
+ if(!in_array($current_user->user_level, $options->user_roles)) {$add_box = false; }
86
+ }
87
+
88
 
89
 
90
  if($add_box == true)
core/fields/checkbox.php CHANGED
@@ -149,10 +149,10 @@ class Checkbox
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
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
core/fields/page_link.php CHANGED
@@ -169,7 +169,7 @@ class Page_link
169
  * @since 1.1
170
  *
171
  ---------------------------------------------------------------------------------------------*/
172
- function format_value($value)
173
  {
174
  $value = get_permalink($value);
175
  return $value;
169
  * @since 1.1
170
  *
171
  ---------------------------------------------------------------------------------------------*/
172
+ function format_value_for_api($value)
173
  {
174
  $value = get_permalink($value);
175
  return $value;
core/fields/select.php CHANGED
@@ -181,10 +181,10 @@ class Select
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
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
core/fields/wysiwyg.php CHANGED
@@ -18,7 +18,7 @@ class Wysiwyg
18
  echo '</textarea></div>';
19
  }
20
 
21
- function format_value($value)
22
  {
23
  $value = apply_filters('the_content',$value);
24
  return $value;
18
  echo '</textarea></div>';
19
  }
20
 
21
+ function format_value_for_api($value)
22
  {
23
  $value = apply_filters('the_content',$value);
24
  return $value;
core/input_meta_box.php CHANGED
@@ -60,14 +60,17 @@ if(!in_array('the_content',$adv_options->show_on_page)): ?>
60
 
61
  // set value, id and name for field
62
  $field->value = $this->load_value_for_input($post->ID, $field);
 
63
  $field->input_id = 'acf['.$i.'][value]';
64
  $field->input_name = 'acf['.$i.'][value]';
65
 
66
  ?>
67
  <tr>
68
  <td>
69
- <input type="hidden" name="acf[<?php echo $i; ?>][field_type]" value="<?php echo $field->type; ?>" />
70
  <input type="hidden" name="acf[<?php echo $i; ?>][field_id]" value="<?php echo $field->id; ?>" />
 
 
71
  <label for="<?php echo $field->input_id ?>"><?php echo $field->label ?></label>
72
  <?php $this->create_field($field); ?>
73
  </td>
60
 
61
  // set value, id and name for field
62
  $field->value = $this->load_value_for_input($post->ID, $field);
63
+ $field->row_id = $this->load_row_id_for_input($post->ID, $field->id);
64
  $field->input_id = 'acf['.$i.'][value]';
65
  $field->input_name = 'acf['.$i.'][value]';
66
 
67
  ?>
68
  <tr>
69
  <td>
70
+ <input type="hidden" name="acf[<?php echo $i; ?>][row_id]" value="<?php echo $field->row_id; ?>" />
71
  <input type="hidden" name="acf[<?php echo $i; ?>][field_id]" value="<?php echo $field->id; ?>" />
72
+ <input type="hidden" name="acf[<?php echo $i; ?>][field_type]" value="<?php echo $field->type; ?>" />
73
+
74
  <label for="<?php echo $field->input_id ?>"><?php echo $field->label ?></label>
75
  <?php $this->create_field($field); ?>
76
  </td>
core/input_save.php CHANGED
@@ -31,12 +31,24 @@ if($_POST['input_meta_box'] == 'true')
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
 
31
  }
32
  else
33
  {
34
+ //$field = apply_filters('wp_insert_post_data', $field);
35
+ $field = stripslashes_deep( $field );
36
+
37
+ $data = array(
38
  'post_id' => $post_id,
39
  'field_id' => $field['field_id'],
40
  'value' => $field['value']
41
+ );
42
+
43
+ // if there is an id, this value already exists, so save it in the same ID spot
44
+ if($field['row_id'])
45
+ {
46
+ $data['id'] = $field['row_id'];
47
+ }
48
+
49
+
50
+ // insert new data
51
+ $new_id = $wpdb->insert($table_name, $data);
52
  }
53
 
54
 
core/options_meta_box.php CHANGED
@@ -40,7 +40,8 @@
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>
@@ -68,8 +69,8 @@
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
 
40
 
41
  ?>
42
 
43
+ <p class="description">Select the metaboxes you wish to keep on your edit screen.<br />
44
+ Tip: This is useful to customise the edit screen</p>
45
  </td>
46
  </tr>
47
  <tr>
69
  $this->create_field($temp_field);
70
 
71
  ?>
72
+ <p class="description">Select user types to give them access to this ACF<br />
73
+ Tip: If no user types are selected, all user's will have access to this ACF</p>
74
  </td>
75
  </tr>
76
 
core/update.php CHANGED
@@ -270,5 +270,5 @@ if(version_compare($version,'1.1.0') < 0)
270
 
271
 
272
  // update to latest acf version
273
- update_option('acf_version','1.1.1');
274
  ?>
270
 
271
 
272
  // update to latest acf version
273
+ update_option('acf_version','1.1.2');
274
  ?>
readme.txt CHANGED
@@ -43,6 +43,9 @@ Advanced Custom Fields is the perfect solution for any wordpress website which n
43
  = Video Tutorials =
44
  http://plugins.elliotcondon.com/advanced-custom-fields/user-guide/
45
 
 
 
 
46
  = Website =
47
  http://plugins.elliotcondon.com/advanced-custom-fields/
48
 
@@ -77,6 +80,14 @@ http://support.plugins.elliotcondon.com/categories/advanced-custom-fields/
77
 
78
  == Changelog ==
79
 
 
 
 
 
 
 
 
 
80
  = 1.1.1 =
81
  * Fixed Slashes issue on edit screens for text based fields
82
 
43
  = Video Tutorials =
44
  http://plugins.elliotcondon.com/advanced-custom-fields/user-guide/
45
 
46
+ = Field Type Info =
47
+ http://plugins.elliotcondon.com/advanced-custom-fields/field-types/
48
+
49
  = Website =
50
  http://plugins.elliotcondon.com/advanced-custom-fields/
51
 
80
 
81
  == Changelog ==
82
 
83
+ = 1.1.2 =
84
+ * Fixed WYSIWYG API format issue
85
+ * Fixed Page Link API format issue
86
+ * Select / Checkbox can now contain a url in the value or label
87
+ * Can now unselect all user types form field options
88
+ * Updated value save / read functions
89
+ * Lots of small bug fixes
90
+
91
  = 1.1.1 =
92
  * Fixed Slashes issue on edit screens for text based fields
93