Advanced Custom Fields - Version 3.3.4

Version Description

  • [Added] Added new API function: has_sub_field - replacement for the_repeater_field and the_flexible_field. Allows for nested while loops!
  • [Improved] Improve save_post functions- http://support.advancedcustomfields.com/discussion/2540/bug-fix-for-taxonomies-and-revisions-solved
  • [Fixed] Fix relationship AJAX abort for multiple fields - http://support.advancedcustomfields.com/discussion/2555/problem-width-relationship-after-update-the-latest-version
Download this release

Release Info

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

Code changes from version 3.3.3 to 3.3.4

acf.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Advanced Custom Fields
4
  Plugin URI: http://www.advancedcustomfields.com/
5
  Description: Fully customise WordPress edit screens with powerful fields. Boasting a professional interface and a powerfull API, it’s a must have for any web developer working with WordPress. Field types include: Wysiwyg, text, textarea, image, file, select, checkbox, page link, post object, date picker, color picker, repeater, flexible content, gallery and more!
6
- Version: 3.3.3
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
@@ -47,7 +47,7 @@ class Acf
47
  // vars
48
  $this->path = plugin_dir_path(__FILE__);
49
  $this->dir = plugins_url('',__FILE__);
50
- $this->version = '3.3.3';
51
  $this->upgrade_version = '3.3.3'; // this is the latest version which requires an upgrade
52
  $this->cache = array(); // basic array cache to hold data throughout the page load
53
 
3
  Plugin Name: Advanced Custom Fields
4
  Plugin URI: http://www.advancedcustomfields.com/
5
  Description: Fully customise WordPress edit screens with powerful fields. Boasting a professional interface and a powerfull API, it’s a must have for any web developer working with WordPress. Field types include: Wysiwyg, text, textarea, image, file, select, checkbox, page link, post object, date picker, color picker, repeater, flexible content, gallery and more!
6
+ Version: 3.3.4
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
47
  // vars
48
  $this->path = plugin_dir_path(__FILE__);
49
  $this->dir = plugins_url('',__FILE__);
50
+ $this->version = '3.3.4';
51
  $this->upgrade_version = '3.3.3'; // this is the latest version which requires an upgrade
52
  $this->cache = array(); // basic array cache to hold data throughout the page load
53
 
core/api.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
- // set some globals
4
- reset_the_repeater_field();
5
 
6
 
7
  /*--------------------------------------------------------------------------------------
@@ -155,60 +155,83 @@ function the_field($field_name, $post_id = false)
155
 
156
  /*--------------------------------------------------------------------------------------
157
  *
158
- * the_repeater_field
159
  *
160
  * @author Elliot Condon
161
- * @since 1.0.3
162
  *
163
  *-------------------------------------------------------------------------------------*/
164
 
165
- function the_repeater_field($field_name, $post_id = false)
166
  {
167
 
168
- // if no field, create field + reset count
169
- if(!$GLOBALS['acf_field'])
170
  {
171
- reset_the_repeater_field();
172
- $GLOBALS['acf_field'] = get_field($field_name, $post_id);
 
 
 
173
  }
174
 
175
- // increase order_no
176
- $GLOBALS['acf_count']++;
177
 
178
  // vars
179
- $field = $GLOBALS['acf_field'];
180
- $i = $GLOBALS['acf_count'];
 
 
181
 
182
- if(isset($field[$i]))
 
 
 
183
  {
184
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  }
186
 
187
- // no row, reset the global values
188
- reset_the_repeater_field();
189
- return false;
190
 
191
- }
192
-
193
- function the_flexible_field($field_name, $post_id = false)
194
- {
195
- return the_repeater_field($field_name, $post_id);
196
- }
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
- /*--------------------------------------------------------------------------------------
200
- *
201
- * reset_the_repeater_field
202
- *
203
- * @author Elliot Condon
204
- * @since 1.0.3
205
- *
206
- *-------------------------------------------------------------------------------------*/
207
-
208
- function reset_the_repeater_field()
209
- {
210
- $GLOBALS['acf_field'] = false;
211
- $GLOBALS['acf_count'] = -1;
212
  }
213
 
214
 
@@ -224,16 +247,27 @@ function reset_the_repeater_field()
224
  function get_sub_field($field_name)
225
  {
226
 
 
 
 
 
 
 
 
227
  // vars
228
- $field = $GLOBALS['acf_field'];
229
- $i = $GLOBALS['acf_count'];
 
 
 
 
 
 
 
 
230
 
231
- // no value
232
- if(!$field) return false;
233
-
234
- if(!isset($field[$i][$field_name])) return false;
235
 
236
- return $field[$i][$field_name];
237
  }
238
 
239
 
@@ -246,9 +280,9 @@ function get_sub_field($field_name)
246
  *
247
  *-------------------------------------------------------------------------------------*/
248
 
249
- function the_sub_field($field_name, $field = false)
250
  {
251
- $value = get_sub_field($field_name, $field);
252
 
253
  if(is_array($value))
254
  {
@@ -382,17 +416,11 @@ add_filter('acf_register_options_page', 'acf_register_options_page');
382
 
383
  function get_row_layout()
384
  {
385
-
386
  // vars
387
- $field = $GLOBALS['acf_field'];
388
- $i = $GLOBALS['acf_count'];
389
 
390
- // no value
391
- if(!$field) return false;
392
-
393
- if(!isset($field[$i]['acf_fc_layout'])) return false;
394
 
395
- return $field[$i]['acf_fc_layout'];
396
  }
397
 
398
 
@@ -729,4 +757,61 @@ function update_field($field_name, $value, $post_id = false)
729
  $acf->update_value($post_id, $field, $value);
730
  }
731
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
732
  ?>
1
  <?php
2
 
3
+ // vars
4
+ $GLOBALS['acf_field'] = array();
5
 
6
 
7
  /*--------------------------------------------------------------------------------------
155
 
156
  /*--------------------------------------------------------------------------------------
157
  *
158
+ * has_sub_field
159
  *
160
  * @author Elliot Condon
161
+ * @since 3.3.4
162
  *
163
  *-------------------------------------------------------------------------------------*/
164
 
165
+ function has_sub_field($field_name, $post_id = false)
166
  {
167
 
168
+ // empty?
169
+ if( empty($GLOBALS['acf_field']) )
170
  {
171
+ $GLOBALS['acf_field'][] = array(
172
+ 'name' => $field_name,
173
+ 'value' => get_field($field_name, $post_id),
174
+ 'row' => -1
175
+ );
176
  }
177
 
 
 
178
 
179
  // vars
180
+ $depth = count( $GLOBALS['acf_field'] ) - 1;
181
+ $name = $GLOBALS['acf_field'][$depth]['name'];
182
+ $value = $GLOBALS['acf_field'][$depth]['value'];
183
+ $row = $GLOBALS['acf_field'][$depth]['row'];
184
 
185
+
186
+
187
+ // does the given $field_name match the current field?
188
+ if( $field_name != $name )
189
  {
190
+ // is this a "new" while loop refering to a sub field?
191
+ if( isset($value[$row][$field_name]) )
192
+ {
193
+ $GLOBALS['acf_field'][] = array(
194
+ 'name' => $field_name,
195
+ 'value' => $value[$row][$field_name],
196
+ 'row' => -1
197
+ );
198
+ }
199
+
200
+
201
+ // if someone used break; We should see if the parent value has this field_name as a value.
202
+ if( isset($GLOBALS['acf_field'][$depth-1]) && $GLOBALS['acf_field'][$depth-1]['name'] == $field_name )
203
+ {
204
+ unset( $GLOBALS['acf_field'][$depth] );
205
+ $GLOBALS['acf_field'] = array_values($GLOBALS['acf_field']);
206
+ }
207
+
208
  }
209
 
 
 
 
210
 
211
+ // update vars
212
+ $depth = count( $GLOBALS['acf_field'] ) - 1;
213
+ $value = $GLOBALS['acf_field'][$depth]['value'];
214
+ $row = $GLOBALS['acf_field'][$depth]['row'];
 
 
215
 
216
+
217
+ // increase row number
218
+ $GLOBALS['acf_field'][$depth]['row']++;
219
+ $row++;
220
+
221
+
222
+ if( isset($value[$row]) )
223
+ {
224
+ // next row exists
225
+ return true;
226
+ }
227
+
228
+
229
+ // no next row! Unset this array and return false to stop while loop
230
+ unset( $GLOBALS['acf_field'][$depth] );
231
+ $GLOBALS['acf_field'] = array_values($GLOBALS['acf_field']);
232
 
233
+ return false;
234
+
 
 
 
 
 
 
 
 
 
 
 
235
  }
236
 
237
 
247
  function get_sub_field($field_name)
248
  {
249
 
250
+ // no field?
251
+ if( empty($GLOBALS['acf_field']) )
252
+ {
253
+ return false;
254
+ }
255
+
256
+
257
  // vars
258
+ $depth = count( $GLOBALS['acf_field'] ) - 1;
259
+ $value = $GLOBALS['acf_field'][$depth]['value'];
260
+ $row = $GLOBALS['acf_field'][$depth]['row'];
261
+
262
+
263
+ // no value at i
264
+ if( !isset($GLOBALS['acf_field'][$depth]['value'][$row][$field_name]) )
265
+ {
266
+ return false;
267
+ }
268
 
 
 
 
 
269
 
270
+ return $GLOBALS['acf_field'][$depth]['value'][$row][$field_name];
271
  }
272
 
273
 
280
  *
281
  *-------------------------------------------------------------------------------------*/
282
 
283
+ function the_sub_field($field_name)
284
  {
285
+ $value = get_sub_field($field_name);
286
 
287
  if(is_array($value))
288
  {
416
 
417
  function get_row_layout()
418
  {
 
419
  // vars
420
+ $value = get_sub_field('acf_fc_layout');
 
421
 
 
 
 
 
422
 
423
+ return $value;
424
  }
425
 
426
 
757
  $acf->update_value($post_id, $field, $value);
758
  }
759
 
760
+
761
+ /*
762
+ * Depreceated Functions
763
+ *
764
+ * @description:
765
+ * @created: 23/07/12
766
+ */
767
+
768
+
769
+ /*--------------------------------------------------------------------------------------
770
+ *
771
+ * reset_the_repeater_field
772
+ *
773
+ * @author Elliot Condon
774
+ * @depreciated: 3.3.4 - now use has_sub_field
775
+ * @since 1.0.3
776
+ *
777
+ *-------------------------------------------------------------------------------------*/
778
+
779
+ function reset_the_repeater_field()
780
+ {
781
+ // do nothing
782
+ }
783
+
784
+
785
+ /*--------------------------------------------------------------------------------------
786
+ *
787
+ * the_repeater_field
788
+ *
789
+ * @author Elliot Condon
790
+ * @depreciated: 3.3.4 - now use has_sub_field
791
+ * @since 1.0.3
792
+ *
793
+ *-------------------------------------------------------------------------------------*/
794
+
795
+ function the_repeater_field($field_name, $post_id = false)
796
+ {
797
+ return has_sub_field($field_name, $post_id);
798
+ }
799
+
800
+
801
+ /*--------------------------------------------------------------------------------------
802
+ *
803
+ * the_flexible_field
804
+ *
805
+ * @author Elliot Condon
806
+ * @depreciated: 3.3.4 - now use has_sub_field
807
+ * @since 3.?.?
808
+ *
809
+ *-------------------------------------------------------------------------------------*/
810
+
811
+ function the_flexible_field($field_name, $post_id = false)
812
+ {
813
+ return has_sub_field($field_name, $post_id);
814
+ }
815
+
816
+
817
  ?>
core/controllers/field_group.php CHANGED
@@ -500,20 +500,11 @@ class acf_field_group
500
  }
501
 
502
 
503
- // only save once! WordPress save's twice for some strange reason.
504
- global $acf_flag;
505
- if ($acf_flag != 0)
506
  {
507
- return $post_id;
508
- }
509
- $acf_flag = 1;
510
-
511
-
512
- // set post ID if is a revision
513
- if(wp_is_post_revision($post_id))
514
- {
515
- $post_id = wp_is_post_revision($post_id);
516
- }
517
 
518
 
519
  /*
500
  }
501
 
502
 
503
+ // only save once! WordPress save's a revision as well.
504
+ if( wp_is_post_revision($post_id) )
 
505
  {
506
+ return $post_id;
507
+ }
 
 
 
 
 
 
 
 
508
 
509
 
510
  /*
core/controllers/input.php CHANGED
@@ -400,20 +400,12 @@ class acf_input
400
  }
401
 
402
 
403
- // only save once! WordPress save's twice for some strange reason.
404
- global $acf_flag;
405
- if ($acf_flag != 0)
406
  {
407
- return $post_id;
408
- }
409
- $acf_flag = 1;
410
-
411
-
412
- // set post ID if is a revision
413
- if(wp_is_post_revision($post_id))
414
- {
415
- $post_id = wp_is_post_revision($post_id);
416
- }
417
 
418
  // save fields
419
  $fields = $_POST['fields'];
400
  }
401
 
402
 
403
+ // only save once! WordPress save's a revision as well.
404
+ if( wp_is_post_revision($post_id) )
 
405
  {
406
+ return $post_id;
407
+ }
408
+
 
 
 
 
 
 
 
409
 
410
  // save fields
411
  $fields = $_POST['fields'];
js/input-actions.js CHANGED
@@ -571,8 +571,10 @@ var acf = {
571
 
572
 
573
  // ajax
574
- acf.relationship_update_results( div );
575
-
 
 
576
 
577
  return false;
578
 
@@ -619,13 +621,6 @@ var acf = {
619
  div.addClass('loading');
620
 
621
 
622
- // abort previous request
623
- if( acf.relationship_xhr )
624
- {
625
- acf.relationship_xhr.abort();
626
- }
627
-
628
-
629
  // vars
630
  var s = div.attr('data-s'),
631
  paged = parseInt( div.attr('data-paged') ),
@@ -636,7 +631,7 @@ var acf = {
636
 
637
 
638
  // get results
639
- acf.relationship_xhr = $.ajax({
640
  url: ajaxurl,
641
  type: 'post',
642
  dataType: 'html',
@@ -655,6 +650,7 @@ var acf = {
655
  if( !html )
656
  {
657
  div.addClass('no-results');
 
658
  return;
659
  }
660
 
@@ -1175,7 +1171,7 @@ var acf = {
1175
  new_field_html = div.find('> .clones > .layout[data-layout="' + layout + '"]').html().replace(/(="[\w-\[\]]*?)(\[999\])/g, '$1[' + new_id + ']'),
1176
  new_field = $('<div class="layout" data-layout="' + layout + '"></div>').append( new_field_html );
1177
 
1178
-
1179
  // hide no values message
1180
  div.children('.no_value_message').hide();
1181
 
571
 
572
 
573
  // ajax
574
+ clearTimeout( acf.relationship_timeout );
575
+ acf.relationship_timeout = setTimeout(function(){
576
+ acf.relationship_update_results( div );
577
+ }, 250);
578
 
579
  return false;
580
 
621
  div.addClass('loading');
622
 
623
 
 
 
 
 
 
 
 
624
  // vars
625
  var s = div.attr('data-s'),
626
  paged = parseInt( div.attr('data-paged') ),
631
 
632
 
633
  // get results
634
+ $.ajax({
635
  url: ajaxurl,
636
  type: 'post',
637
  dataType: 'html',
650
  if( !html )
651
  {
652
  div.addClass('no-results');
653
+ left.find('li:not(.load-more)').remove();
654
  return;
655
  }
656
 
1171
  new_field_html = div.find('> .clones > .layout[data-layout="' + layout + '"]').html().replace(/(="[\w-\[\]]*?)(\[999\])/g, '$1[' + new_id + ']'),
1172
  new_field = $('<div class="layout" data-layout="' + layout + '"></div>').append( new_field_html );
1173
 
1174
+
1175
  // hide no values message
1176
  div.children('.no_value_message').hide();
1177
 
readme.txt CHANGED
@@ -85,6 +85,11 @@ http://www.advancedcustomfields.com/support/
85
 
86
  == Changelog ==
87
 
 
 
 
 
 
88
  = 3.3.3 =
89
  * [Upgrade] Database Upgrade is required to modify the taxonomy filtering data for fields. This allows for performance boosts throughout ACF.
90
  * [Improved] relationship field: Improve querying posts / results and use AJAX powered search to increase performance on large-scale websites
85
 
86
  == Changelog ==
87
 
88
+ = 3.3.4 =
89
+ * [Added] Added new API function: has_sub_field - replacement for the_repeater_field and the_flexible_field. Allows for nested while loops!
90
+ * [Improved] Improve save_post functions- http://support.advancedcustomfields.com/discussion/2540/bug-fix-for-taxonomies-and-revisions-solved
91
+ * [Fixed] Fix relationship AJAX abort for multiple fields - http://support.advancedcustomfields.com/discussion/2555/problem-width-relationship-after-update-the-latest-version
92
+
93
  = 3.3.3 =
94
  * [Upgrade] Database Upgrade is required to modify the taxonomy filtering data for fields. This allows for performance boosts throughout ACF.
95
  * [Improved] relationship field: Improve querying posts / results and use AJAX powered search to increase performance on large-scale websites