Advanced Custom Fields - Version 2.1.4

Version Description

  • Fixed add image tinymce error for options Page WYSIWYG
  • API: added new function: update_the_field($field_name, $value, $post_id)
  • New field: Relationship field
  • New Option for Relationship + Post Object: filter posts via meta_key and meta_value
  • Added new option: Image preview size (thumb, medium, large, full)
  • Fixed duplicate posts double value problem
  • API update: get_field($repeater) will return an array of values in order, or false (like it used to!)
  • Radio Button: added labels around values
  • Post object + Page Link: select drop down is now hierarchal
  • Input save errors fixed
  • Add 'return_id' option to get_field / get_sub_field
  • Many bug fixes
Download this release

Release Info

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

Code changes from version 2.1.3 to 2.1.4

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: Customise your edit pages with an assortment of field types: Wysiwyg, Repeater, text, textarea, image, file, select, checkbox post type, page link and more! Hide unwanted metaboxes and assign to any edit page!
6
- Version: 2.1.3
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
@@ -51,8 +51,8 @@ class Acf
51
  $this->dir = plugins_url('',__FILE__);
52
  $this->siteurl = get_bloginfo('url');
53
  $this->wpadminurl = admin_url();
54
- $this->version = '2.1.3';
55
- $this->upgrade_version = '2.1.0'; // this is the latest version which requires an upgrade
56
  $this->activated_fields = $this->get_activated_fields();
57
  $this->options_page = new Acf_options_page($this);
58
 
@@ -73,7 +73,8 @@ class Acf
73
  add_action('admin_head', array($this,'admin_head'));
74
  add_action('admin_menu', array($this,'admin_menu'));
75
  add_action('save_post', array($this, 'save_post'));
76
- add_action('admin_footer', array($this, '_admin_footer'));
 
77
  add_action('wp_ajax_input_meta_box_html', array($this, 'input_meta_box_html'));
78
 
79
 
@@ -184,7 +185,8 @@ class Acf
184
 
185
 
186
  // verify this with nonce because save_post can be triggered at other times
187
- if (!wp_verify_nonce($_POST['ei_noncename'], 'ei-n')) return $post_id;
 
188
 
189
 
190
  // only save once! WordPress save's twice for some strange reason.
@@ -208,6 +210,46 @@ class Acf
208
  }
209
 
210
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
212
  /*--------------------------------------------------------------------------------------
213
  *
@@ -265,6 +307,7 @@ class Acf
265
  include_once('core/fields/true_false.php');
266
  include_once('core/fields/page_link.php');
267
  include_once('core/fields/post_object.php');
 
268
  include_once('core/fields/date_picker/date_picker.php');
269
  include_once('core/fields/repeater.php');
270
 
@@ -279,6 +322,7 @@ class Acf
279
  $array['true_false'] = new acf_True_false();
280
  $array['page_link'] = new acf_Page_link($this);
281
  $array['post_object'] = new acf_Post_object($this);
 
282
  $array['date_picker'] = new acf_Date_picker($this->dir);
283
 
284
  if(array_key_exists('repeater', $this->activated_fields))
@@ -592,14 +636,14 @@ class Acf
592
 
593
  /*--------------------------------------------------------------------------------------
594
  *
595
- * _admin_footer
596
  *
597
  * @author Elliot Condon
598
  * @since 1.0.0
599
  *
600
  *-------------------------------------------------------------------------------------*/
601
 
602
- function _admin_footer()
603
  {
604
 
605
  if($GLOBALS['pagenow'] == 'edit.php' && $GLOBALS['post_type'] == 'acf')
@@ -682,7 +726,7 @@ class Acf
682
  if($post_id != 0)
683
  {
684
  $post_meta = get_post_custom($post_id);
685
- if(empty($post_meta) && isset($field->default_value) && !empty($field->default_value))
686
  {
687
  $value->value = $field->default_value;
688
  }
@@ -1178,7 +1222,7 @@ class Acf
1178
  // display document in browser as plain text
1179
  //header("Content-Type: text/plain");
1180
  echo '<?xml version="1.0"?> ';
1181
- ?>
1182
 
1183
  <?php if($acfs): ?>
1184
  <posts>
@@ -1188,7 +1232,6 @@ class Acf
1188
  $fields = $this->get_fields($post->ID);
1189
  $location = $this->get_acf_location($post->ID);
1190
  $options = $this->get_acf_options($post->ID);
1191
-
1192
  ?>
1193
  <post>
1194
  <title><?php echo apply_filters( 'the_title_rss', $post->post_title ); ?></title>
@@ -1536,10 +1579,12 @@ class Acf
1536
 
1537
  if($field->type != 'repeater')
1538
  {
1539
- echo '<input type="hidden" name="acf['.$field->id.'][value_id]" value="'.$field->value->value_id.'" />';
1540
- echo '<input type="hidden" name="acf['.$field->id.'][meta_id]" value="'.$field->value->meta_id.'" />';
1541
-
1542
  $temp_field->value = $field->value->value;
 
 
 
1543
  }
1544
  else
1545
  {
3
  Plugin Name: Advanced Custom Fields
4
  Plugin URI: http://plugins.elliotcondon.com/advanced-custom-fields/
5
  Description: Customise your edit pages with an assortment of field types: Wysiwyg, Repeater, text, textarea, image, file, select, checkbox post type, page link and more! Hide unwanted metaboxes and assign to any edit page!
6
+ Version: 2.1.4
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
51
  $this->dir = plugins_url('',__FILE__);
52
  $this->siteurl = get_bloginfo('url');
53
  $this->wpadminurl = admin_url();
54
+ $this->version = '2.1.4';
55
+ $this->upgrade_version = '2.1.4'; // this is the latest version which requires an upgrade
56
  $this->activated_fields = $this->get_activated_fields();
57
  $this->options_page = new Acf_options_page($this);
58
 
73
  add_action('admin_head', array($this,'admin_head'));
74
  add_action('admin_menu', array($this,'admin_menu'));
75
  add_action('save_post', array($this, 'save_post'));
76
+ add_action('delete_post', array($this, 'delete_post'), 10);
77
+ add_action('admin_footer', array($this, 'admin_footer'));
78
  add_action('wp_ajax_input_meta_box_html', array($this, 'input_meta_box_html'));
79
 
80
 
185
 
186
 
187
  // verify this with nonce because save_post can be triggered at other times
188
+ if(!isset($_POST['ei_noncename'])) return $post_id;
189
+ if(!wp_verify_nonce($_POST['ei_noncename'], 'ei-n')) return $post_id;
190
 
191
 
192
  // only save once! WordPress save's twice for some strange reason.
210
  }
211
 
212
 
213
+ /*--------------------------------------------------------------------------------------
214
+ *
215
+ * delete_post
216
+ *
217
+ * @author Elliot Condon
218
+ * @since 2.1.4
219
+ *
220
+ *-------------------------------------------------------------------------------------*/
221
+
222
+ function delete_post($post_id)
223
+ {
224
+ //echo 'delete_posts';
225
+
226
+ // global
227
+ global $wpdb;
228
+
229
+ // tables
230
+ $acf_fields = $wpdb->prefix.'acf_fields';
231
+ $acf_values = $wpdb->prefix.'acf_values';
232
+ $acf_rules = $wpdb->prefix.'acf_rules';
233
+ $wp_postmeta = $wpdb->prefix.'postmeta';
234
+
235
+ if(get_post_type($post_id) == 'acf')
236
+ {
237
+ // delete fields
238
+ $wpdb->query("DELETE FROM $acf_fields WHERE post_id = '$post_id'");
239
+
240
+ // delete rules
241
+ $wpdb->query("DELETE FROM $acf_rules WHERE acf_id = '$post_id'");
242
+ }
243
+ else
244
+ {
245
+ // delete values
246
+ $wpdb->query("DELETE FROM $acf_values WHERE post_id = '$post_id'");
247
+ }
248
+
249
+ return true;
250
+
251
+ }
252
+
253
 
254
  /*--------------------------------------------------------------------------------------
255
  *
307
  include_once('core/fields/true_false.php');
308
  include_once('core/fields/page_link.php');
309
  include_once('core/fields/post_object.php');
310
+ include_once('core/fields/relationship.php');
311
  include_once('core/fields/date_picker/date_picker.php');
312
  include_once('core/fields/repeater.php');
313
 
322
  $array['true_false'] = new acf_True_false();
323
  $array['page_link'] = new acf_Page_link($this);
324
  $array['post_object'] = new acf_Post_object($this);
325
+ $array['relationship'] = new acf_Relationship($this);
326
  $array['date_picker'] = new acf_Date_picker($this->dir);
327
 
328
  if(array_key_exists('repeater', $this->activated_fields))
636
 
637
  /*--------------------------------------------------------------------------------------
638
  *
639
+ * admin_footer
640
  *
641
  * @author Elliot Condon
642
  * @since 1.0.0
643
  *
644
  *-------------------------------------------------------------------------------------*/
645
 
646
+ function admin_footer()
647
  {
648
 
649
  if($GLOBALS['pagenow'] == 'edit.php' && $GLOBALS['post_type'] == 'acf')
726
  if($post_id != 0)
727
  {
728
  $post_meta = get_post_custom($post_id);
729
+ if(empty($post_meta) && isset($field->default_value))
730
  {
731
  $value->value = $field->default_value;
732
  }
1222
  // display document in browser as plain text
1223
  //header("Content-Type: text/plain");
1224
  echo '<?xml version="1.0"?> ';
1225
+ ?>
1226
 
1227
  <?php if($acfs): ?>
1228
  <posts>
1232
  $fields = $this->get_fields($post->ID);
1233
  $location = $this->get_acf_location($post->ID);
1234
  $options = $this->get_acf_options($post->ID);
 
1235
  ?>
1236
  <post>
1237
  <title><?php echo apply_filters( 'the_title_rss', $post->post_title ); ?></title>
1579
 
1580
  if($field->type != 'repeater')
1581
  {
1582
+ $value_id = isset($field->value->value_id) ? $field->value->value_id : '';
1583
+ $meta_id = isset($field->value->meta_id) ? $field->value->meta_id : '';
 
1584
  $temp_field->value = $field->value->value;
1585
+
1586
+ echo '<input type="hidden" name="acf['.$field->id.'][value_id]" value="' . $value_id . '" />';
1587
+ echo '<input type="hidden" name="acf['.$field->id.'][meta_id]" value="' . $meta_id . '" />';
1588
  }
1589
  else
1590
  {
core/actions/admin_head.php CHANGED
@@ -52,9 +52,4 @@ if(in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php')))
52
  }
53
 
54
 
55
- ?>
56
- <style type="text/css">
57
- #menu-posts-acf {
58
- display: none;
59
- }
60
- </style>
52
  }
53
 
54
 
55
+ ?>
 
 
 
 
 
core/actions/init.php CHANGED
@@ -169,6 +169,7 @@ register_post_type('acf', array(
169
  'rewrite' => array("slug" => "acf"),
170
  'query_var' => "acf",
171
  'supports' => $supports,
 
172
  ));
173
 
174
 
169
  'rewrite' => array("slug" => "acf"),
170
  'query_var' => "acf",
171
  'supports' => $supports,
172
+ 'show_in_menu' =>false,
173
  ));
174
 
175
 
core/actions/input_save.php CHANGED
@@ -18,25 +18,23 @@ if(isset($_POST['input_meta_box']) && $_POST['input_meta_box'] == 'true')
18
  $wp_postmeta = $wpdb->prefix.'postmeta';
19
 
20
 
21
-
 
 
 
 
 
 
 
 
 
 
22
  // add the new values to the database
23
  foreach($_POST['acf'] as $field)
24
  {
25
 
26
  // remove all old values from the database
27
  $field_id = $field['field_id'];
28
- $values = $wpdb->get_results("SELECT v.id, m.meta_id FROM $acf_values v LEFT JOIN $wp_postmeta m ON v.value = m.meta_id WHERE v.field_id = '$field_id' AND m.post_id = '$post_id'");
29
-
30
-
31
- if($values)
32
- {
33
- foreach($values as $value)
34
- {
35
- $wpdb->query("DELETE FROM $acf_values WHERE id = '$value->id'");
36
- $wpdb->query("DELETE FROM $wp_postmeta WHERE meta_id = '$value->meta_id'");
37
- }
38
- }
39
-
40
 
41
 
42
  if(method_exists($this->fields[$field['field_type']], 'save_input'))
@@ -58,11 +56,15 @@ if(isset($_POST['input_meta_box']) && $_POST['input_meta_box'] == 'true')
58
 
59
  // create data: wp_postmeta
60
  $data1 = array(
61
- 'meta_id' => isset($field['meta_id']) ? $field['meta_id'] : null,
62
  'post_id' => $post_id,
63
  'meta_key' => $field['field_name'],
64
  'meta_value' => $field['value']
65
  );
 
 
 
 
66
 
67
  $wpdb->insert($wp_postmeta, $data1);
68
 
@@ -73,11 +75,15 @@ if(isset($_POST['input_meta_box']) && $_POST['input_meta_box'] == 'true')
73
  {
74
 
75
  $data2 = array(
76
- 'id' => isset($field['value_id']) ? $field['value_id'] : null,
 
77
  'field_id' => $field['field_id'],
78
  'value' => $new_id,
79
- 'post_id' => $post_id,
80
  );
 
 
 
 
81
 
82
  $wpdb->insert($acf_values, $data2);
83
 
18
  $wp_postmeta = $wpdb->prefix.'postmeta';
19
 
20
 
21
+ // delete old data
22
+ $values = $wpdb->get_results("SELECT v.id, m.meta_id FROM $acf_values v LEFT JOIN $wp_postmeta m ON v.value = m.meta_id WHERE v.post_id = '$post_id'");
23
+ if($values)
24
+ {
25
+ foreach($values as $value)
26
+ {
27
+ $wpdb->query("DELETE FROM $acf_values WHERE id = '$value->id'");
28
+ $wpdb->query("DELETE FROM $wp_postmeta WHERE meta_id = '$value->meta_id'");
29
+ }
30
+ }
31
+
32
  // add the new values to the database
33
  foreach($_POST['acf'] as $field)
34
  {
35
 
36
  // remove all old values from the database
37
  $field_id = $field['field_id'];
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
 
40
  if(method_exists($this->fields[$field['field_type']], 'save_input'))
56
 
57
  // create data: wp_postmeta
58
  $data1 = array(
59
+ 'meta_id' => null,
60
  'post_id' => $post_id,
61
  'meta_key' => $field['field_name'],
62
  'meta_value' => $field['value']
63
  );
64
+ if(isset($field['meta_id']) && !empty($field['meta_id']))
65
+ {
66
+ $data1['meta_id'] = $field['meta_id'];
67
+ }
68
 
69
  $wpdb->insert($wp_postmeta, $data1);
70
 
75
  {
76
 
77
  $data2 = array(
78
+ 'id' => null,
79
+ 'post_id' => $post_id,
80
  'field_id' => $field['field_id'],
81
  'value' => $new_id,
 
82
  );
83
+ if(isset($field['value_id']) && !empty($field['value_id']))
84
+ {
85
+ $data2['id'] = $field['value_id'];
86
+ }
87
 
88
  $wpdb->insert($acf_values, $data2);
89
 
core/api.php CHANGED
@@ -3,8 +3,7 @@
3
  global $acf_global;
4
 
5
  $acf_global = array(
6
- 'field_id' => 0,
7
- 'post_id' => 0,
8
  'order_no' => -1,
9
  );
10
 
@@ -81,13 +80,14 @@ function get_fields($post_id = false)
81
  *
82
  *-------------------------------------------------------------------------------------*/
83
 
84
- function get_field($field_name, $post_id = false)
85
  {
86
 
87
  global $post;
88
  global $wpdb;
89
  global $acf;
90
 
 
91
 
92
  // tables
93
  $acf_values = $wpdb->prefix.'acf_values';
@@ -105,11 +105,11 @@ function get_field($field_name, $post_id = false)
105
  }
106
 
107
 
108
- $sql = "SELECT m.meta_value as value, f.type, f.options
109
  FROM $wp_postmeta m
110
  LEFT JOIN $acf_values v ON m.meta_id = v.value
111
  LEFT JOIN $acf_fields f ON v.field_id = f.id
112
- WHERE f.name = '$field_name' AND m.post_id = '$post_id'";
113
 
114
  $results = $wpdb->get_results($sql);
115
 
@@ -129,15 +129,59 @@ function get_field($field_name, $post_id = false)
129
  // repeater field
130
  if($field->type == 'repeater')
131
  {
132
- $has_values = false;
 
133
  foreach($results as $result)
134
  {
135
- if($result->value)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  {
137
- $has_values = true;
 
 
 
 
 
 
 
 
 
138
  }
 
 
 
 
 
 
 
 
139
  }
140
- return $has_values;
 
 
141
  }
142
 
143
 
@@ -160,6 +204,17 @@ function get_field($field_name, $post_id = false)
160
  $value = $acf->fields[$field->type]->format_value_for_api($value, $field->options);
161
  }
162
 
 
 
 
 
 
 
 
 
 
 
 
163
  return $value;
164
 
165
  }
@@ -200,61 +255,35 @@ function the_field($field_name, $post_id = false)
200
 
201
  function the_repeater_field($field_name, $post_id = false)
202
  {
203
-
204
  global $acf_global;
205
- global $post;
206
- global $wpdb;
207
- global $acf;
208
-
209
-
210
- // tables
211
- $acf_values = $wpdb->prefix.'acf_values';
212
- $acf_fields = $wpdb->prefix.'acf_fields';
213
- $wp_postmeta = $wpdb->prefix.'postmeta';
214
 
215
 
216
- if(!$post_id)
 
217
  {
218
- $post_id = $post->ID;
219
- }
220
- elseif($post_id == "options")
221
- {
222
- $post_id = 0;
223
  }
224
 
225
 
226
- // vars
227
  $acf_global['order_no']++;
228
- $order_no = $acf_global['order_no'];
229
 
230
 
231
- $sql = "SELECT v.field_id
232
- FROM $wp_postmeta m
233
- LEFT JOIN $acf_values v ON m.meta_id = v.value
234
- LEFT JOIN $acf_fields f ON v.field_id = f.id
235
- WHERE f.name = '$field_name' AND v.order_no = '$order_no' AND m.post_id = '$post_id'";
236
-
237
- $results = $wpdb->get_results($sql);
238
-
239
 
240
- // no value
241
- if($results)
242
  {
243
-
244
- $acf_global['field_id'] = $results[0]->field_id;
245
- $acf_global['post_id'] = $post_id;
246
  return true;
247
  }
248
- else
249
- {
250
- $acf_global['field_id'] = 0;
251
- $acf_global['post_id'] = 0;
252
- $acf_global['order_no'] = -1;
253
- return false;
254
- }
255
 
 
 
 
 
256
 
257
-
258
  }
259
 
260
 
@@ -269,60 +298,19 @@ function the_repeater_field($field_name, $post_id = false)
269
 
270
  function get_sub_field($field_name)
271
  {
 
272
  global $acf_global;
273
- global $wpdb;
274
- global $acf;
275
-
276
-
277
- // tables
278
- $acf_values = $wpdb->prefix.'acf_values';
279
- $acf_fields = $wpdb->prefix.'acf_fields';
280
- $wp_postmeta = $wpdb->prefix.'postmeta';
281
-
282
 
283
  // vars
284
- $field_id = $acf_global['field_id'];
285
- $post_id = $acf_global['post_id'];
286
- $order_no = $acf_global['order_no'];
287
-
288
-
289
- $sql = "SELECT m.meta_value as value, f.type, f.options
290
- FROM $wp_postmeta m
291
- LEFT JOIN $acf_values v ON m.meta_id = v.value
292
- LEFT JOIN $acf_fields f ON v.sub_field_id = f.id
293
- WHERE f.name = '$field_name' AND v.field_id = '$field_id' AND v.order_no = '$order_no' AND m.post_id = '$post_id'";
294
-
295
- $field = $wpdb->get_row($sql);
296
-
297
 
298
  // no value
299
- if(!$field)
300
- {
301
- return false;
302
- }
303
-
304
 
305
- // normal field
306
- $value = $field->value;
307
 
308
-
309
- // format if needed
310
- if($acf->field_method_exists($field->type, 'format_value_for_api'))
311
- {
312
-
313
- if(@unserialize($field->options))
314
- {
315
- $field->options = unserialize($field->options);
316
- }
317
- else
318
- {
319
- $field->options = array();
320
- }
321
-
322
- $value = $acf->fields[$field->type]->format_value_for_api($value, $field->options);
323
- }
324
-
325
- return $value;
326
  }
327
 
328
 
@@ -347,4 +335,52 @@ function the_sub_field($field_name, $field = false)
347
  echo $value;
348
  }
349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  ?>
3
  global $acf_global;
4
 
5
  $acf_global = array(
6
+ 'field' => 0,
 
7
  'order_no' => -1,
8
  );
9
 
80
  *
81
  *-------------------------------------------------------------------------------------*/
82
 
83
+ function get_field($field_name, $post_id = false, $options = array())
84
  {
85
 
86
  global $post;
87
  global $wpdb;
88
  global $acf;
89
 
90
+ $return_id = isset($options['return_id']) ? $options['return_id'] : false;
91
 
92
  // tables
93
  $acf_values = $wpdb->prefix.'acf_values';
105
  }
106
 
107
 
108
+ $sql = "SELECT m.meta_value as value, v.id, f.type, f.options, v.sub_field_id, v.order_no
109
  FROM $wp_postmeta m
110
  LEFT JOIN $acf_values v ON m.meta_id = v.value
111
  LEFT JOIN $acf_fields f ON v.field_id = f.id
112
+ WHERE f.name = '$field_name' AND m.post_id = '$post_id' ORDER BY v.order_no ASC";
113
 
114
  $results = $wpdb->get_results($sql);
115
 
129
  // repeater field
130
  if($field->type == 'repeater')
131
  {
132
+ $return_array = array();
133
+
134
  foreach($results as $result)
135
  {
136
+ $sql2 = "SELECT type, name, options
137
+ FROM $acf_fields
138
+ WHERE id = '$result->sub_field_id'";
139
+
140
+ $sub_field = $wpdb->get_row($sql2);
141
+
142
+
143
+ // format the sub field value
144
+ if($acf->field_method_exists($sub_field->type, 'format_value_for_api'))
145
+ {
146
+ if(@unserialize($sub_field->options))
147
+ {
148
+ $sub_field->options = unserialize($sub_field->options);
149
+ }
150
+ else
151
+ {
152
+ $sub_field->options = array();
153
+ }
154
+
155
+ $result->value = $acf->fields[$sub_field->type]->format_value_for_api($result->value, $sub_field->options);
156
+ }
157
+
158
+
159
+ // only add the value if it is not null or false
160
+ if($result->value != '' || $result->value != false)
161
  {
162
+ if($return_id)
163
+ {
164
+ $return_array[$result->order_no][$sub_field->name]['id'] = (int) $result->id;
165
+ $return_array[$result->order_no][$sub_field->name]['value'] = $result->value;
166
+ }
167
+ else
168
+ {
169
+ $return_array[$result->order_no][$sub_field->name] = $result->value;
170
+ }
171
+
172
  }
173
+
174
+ }
175
+
176
+
177
+ // if empty, just return false
178
+ if(empty($return_array))
179
+ {
180
+ $return_array = false;
181
  }
182
+
183
+ return $return_array;
184
+
185
  }
186
 
187
 
204
  $value = $acf->fields[$field->type]->format_value_for_api($value, $field->options);
205
  }
206
 
207
+
208
+ if($return_id)
209
+ {
210
+ $return_array = array(
211
+ 'id' => (int) $field->id,
212
+ 'value' => $value,
213
+ );
214
+ return $return_array;
215
+ }
216
+
217
+
218
  return $value;
219
 
220
  }
255
 
256
  function the_repeater_field($field_name, $post_id = false)
257
  {
 
258
  global $acf_global;
 
 
 
 
 
 
 
 
 
259
 
260
 
261
+ // if no field, create field + reset count
262
+ if(!$acf_global['field'])
263
  {
264
+ $acf_global['order_no'] = -1;
265
+ $acf_global['field'] = get_field($field_name, $post_id);
 
 
 
266
  }
267
 
268
 
269
+ // increase order_no
270
  $acf_global['order_no']++;
 
271
 
272
 
273
+ // vars
274
+ $field = $acf_global['field'];
275
+ $i = $acf_global['order_no'];
 
 
 
 
 
276
 
277
+ if(isset($field[$i]))
 
278
  {
 
 
 
279
  return true;
280
  }
 
 
 
 
 
 
 
281
 
282
+ // no row, reset the global values
283
+ $acf_global['order_no'] = -1;
284
+ $acf_global['field'] = false;
285
+ return false;
286
 
 
287
  }
288
 
289
 
298
 
299
  function get_sub_field($field_name)
300
  {
301
+ // global
302
  global $acf_global;
 
 
 
 
 
 
 
 
 
303
 
304
  // vars
305
+ $field = $acf_global['field'];
306
+ $i = $acf_global['order_no'];
 
 
 
 
 
 
 
 
 
 
 
307
 
308
  // no value
309
+ if(!$field) return false;
 
 
 
 
310
 
311
+ if(!isset($field[$i][$field_name])) return false;
 
312
 
313
+ return $field[$i][$field_name];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
  }
315
 
316
 
335
  echo $value;
336
  }
337
 
338
+
339
+ /*--------------------------------------------------------------------------------------
340
+ *
341
+ * update_the_field
342
+ *
343
+ * @author Elliot Condon
344
+ * @since 2.1.4
345
+ *
346
+ *-------------------------------------------------------------------------------------*/
347
+
348
+ function update_the_field($field_name = false, $value = false, $post_id = false)
349
+ {
350
+ // checkpoint
351
+ if(!$field_name || !$value || !$post_id) return false;
352
+
353
+ // global
354
+ global $wpdb;
355
+
356
+ // tables
357
+ $acf_values = $wpdb->prefix.'acf_values';
358
+ $acf_fields = $wpdb->prefix.'acf_fields';
359
+ $wp_postmeta = $wpdb->prefix.'postmeta';
360
+
361
+ // sql
362
+ $sql = "SELECT m.meta_id
363
+ FROM $wp_postmeta m
364
+ LEFT JOIN $acf_values v ON m.meta_id = v.value
365
+ LEFT JOIN $acf_fields f ON v.field_id = f.id
366
+ WHERE f.name = '$field_name' AND m.post_id = '$post_id'";
367
+
368
+ $meta_id = $wpdb->get_var($sql);
369
+
370
+ // no meta_value
371
+ if(!$meta_id)
372
+ {
373
+ return false;
374
+ }
375
+
376
+ // update
377
+ $save = $wpdb->update($wp_postmeta, array('meta_value' => $value), array('meta_id' => $meta_id));
378
+
379
+ // return
380
+ if($save) return true;
381
+
382
+ return false;
383
+
384
+ }
385
+
386
  ?>
core/fields/date_picker/jquery.ui.datepicker.js CHANGED
File without changes
core/fields/date_picker/style.date_picker.css CHANGED
File without changes
core/fields/file.php CHANGED
@@ -30,7 +30,10 @@ class acf_File
30
  ---------------------------------------------------------------------------------------------*/
31
  function options_html($key, $field)
32
  {
 
33
  $options = $field->options;
 
 
34
  ?>
35
  <tr class="field_option field_option_file">
36
  <td class="label">
30
  ---------------------------------------------------------------------------------------------*/
31
  function options_html($key, $field)
32
  {
33
+ // vars
34
  $options = $field->options;
35
+ $options['save_format'] = isset($options['save_format']) ? $options['save_format'] : 'url';
36
+
37
  ?>
38
  <tr class="field_option field_option_file">
39
  <td class="label">
core/fields/image.php CHANGED
@@ -30,7 +30,11 @@ class acf_Image
30
  ---------------------------------------------------------------------------------------------*/
31
  function options_html($key, $field)
32
  {
 
33
  $options = $field->options;
 
 
 
34
  ?>
35
  <tr class="field_option field_option_image">
36
  <td class="label">
@@ -51,6 +55,26 @@ class acf_Image
51
  ?>
52
  </td>
53
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  <?php
56
  }
@@ -68,6 +92,8 @@ class acf_Image
68
  {
69
  if(isset($_GET["acf_type"]) && $_GET['acf_type'] == 'image')
70
  {
 
 
71
  ?>
72
  <style type="text/css">
73
  #media-upload-header #sidemenu li#tab-type_url,
@@ -107,6 +133,7 @@ class acf_Image
107
 
108
  $('form#filter').each(function(){
109
 
 
110
  $(this).append('<input type="hidden" name="acf_type" value="image" />');
111
 
112
  });
@@ -132,8 +159,11 @@ class acf_Image
132
 
133
  if(isset($arr_postinfo["acf_type"]) && $arr_postinfo["acf_type"] == "image")
134
  {
135
-
136
- $file_src = wp_get_attachment_url($id);
 
 
 
137
 
138
  ?>
139
  <script type="text/javascript">
@@ -163,10 +193,12 @@ class acf_Image
163
 
164
  $class = "";
165
  $file_src = "";
 
166
 
167
  if($field->value != '' && is_numeric($field->value))
168
  {
169
- $file_src = wp_get_attachment_url($field->value);
 
170
 
171
  if($file_src)
172
  {
@@ -175,7 +207,7 @@ class acf_Image
175
  }
176
 
177
 
178
- echo '<div class="acf_image_uploader'.$class.'">';
179
  echo '<a href="#" class="remove_image"></a>';
180
  echo '<img src="'.$file_src.'" alt=""/>';
181
  echo '<input class="value" type="hidden" name="'.$field->input_name.'" value="'.$field->value.'" />';
@@ -195,7 +227,7 @@ class acf_Image
195
  *
196
  *-------------------------------------------------------------------------------------*/
197
 
198
- function format_value_for_api($value, $options)
199
  {
200
 
201
  $format = isset($options['save_format']) ? $options['save_format'] : 'url';
30
  ---------------------------------------------------------------------------------------------*/
31
  function options_html($key, $field)
32
  {
33
+ // vars
34
  $options = $field->options;
35
+ $options['save_format'] = isset($options['save_format']) ? $options['save_format'] : 'url';
36
+ $options['preview_size'] = isset($options['preview_size']) ? $options['preview_size'] : 'thumbnail';
37
+
38
  ?>
39
  <tr class="field_option field_option_image">
40
  <td class="label">
55
  ?>
56
  </td>
57
  </tr>
58
+ <tr class="field_option field_option_image">
59
+ <td class="label">
60
+ <label><?php _e("Preview Size",'acf'); ?></label>
61
+ </td>
62
+ <td>
63
+ <?php
64
+ $temp_field->type = 'select';
65
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][preview_size]';
66
+ $temp_field->input_class = '';
67
+ $temp_field->value = $options['preview_size'];
68
+ $temp_field->options = array('choices' => array(
69
+ 'thumbnail' => 'Thumbnail',
70
+ 'medium' => 'Medium',
71
+ 'large' => 'Large',
72
+ 'full' => 'Full'
73
+ ));
74
+ $this->parent->create_field($temp_field);
75
+ ?>
76
+ </td>
77
+ </tr>
78
 
79
  <?php
80
  }
92
  {
93
  if(isset($_GET["acf_type"]) && $_GET['acf_type'] == 'image')
94
  {
95
+ $preview_size = isset($arr_postinfo['preview_size']) ? $arr_postinfo['preview_size'] : 'medium';
96
+
97
  ?>
98
  <style type="text/css">
99
  #media-upload-header #sidemenu li#tab-type_url,
133
 
134
  $('form#filter').each(function(){
135
 
136
+ $(this).append('<input type="hidden" name="acf_preview_size" value="<?php echo $preview_size; ?>" />');
137
  $(this).append('<input type="hidden" name="acf_type" value="image" />');
138
 
139
  });
159
 
160
  if(isset($arr_postinfo["acf_type"]) && $arr_postinfo["acf_type"] == "image")
161
  {
162
+
163
+ $preview_size = isset($arr_postinfo['acf_preview_size']) ? $arr_postinfo['acf_preview_size'] : 'medium';
164
+
165
+ $file_src = wp_get_attachment_image_src($id, $preview_size);
166
+ $file_src = $file_src[0];
167
 
168
  ?>
169
  <script type="text/javascript">
193
 
194
  $class = "";
195
  $file_src = "";
196
+ $preview_size = isset($field->options['preview_size']) ? $field->options['preview_size'] : 'medium';
197
 
198
  if($field->value != '' && is_numeric($field->value))
199
  {
200
+ $file_src = wp_get_attachment_image_src($field->value, $preview_size);
201
+ $file_src = $file_src[0];
202
 
203
  if($file_src)
204
  {
207
  }
208
 
209
 
210
+ echo '<div class="acf_image_uploader'.$class.'" data-preview_size="' . $preview_size . '">';
211
  echo '<a href="#" class="remove_image"></a>';
212
  echo '<img src="'.$file_src.'" alt=""/>';
213
  echo '<input class="value" type="hidden" name="'.$field->input_name.'" value="'.$field->value.'" />';
227
  *
228
  *-------------------------------------------------------------------------------------*/
229
 
230
+ function format_value_for_api($value, $options = null)
231
  {
232
 
233
  $format = isset($options['save_format']) ? $options['save_format'] : 'url';
core/fields/page_link.php CHANGED
@@ -66,12 +66,32 @@ class acf_Page_link
66
  foreach($post_types as $post_type)
67
  {
68
  // get posts
69
- $posts = get_posts(array(
70
- 'numberposts' => -1,
71
- 'post_type' => $post_type,
72
- 'orderby' => 'title',
73
- 'order' => 'ASC'
74
- ));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
 
77
  // if posts, make a group for them
@@ -82,7 +102,17 @@ class acf_Page_link
82
  foreach($posts as $post)
83
  {
84
  $key = $post->ID;
85
- $value = get_the_title($post->ID);
 
 
 
 
 
 
 
 
 
 
86
  $selected = '';
87
 
88
 
66
  foreach($post_types as $post_type)
67
  {
68
  // get posts
69
+ $posts = false;
70
+
71
+ if(is_post_type_hierarchical($post_type))
72
+ {
73
+ // get pages
74
+ $posts = get_pages(array(
75
+ 'numberposts' => -1,
76
+ 'post_type' => $post_type,
77
+ 'sort_column' => 'menu_order',
78
+ 'order' => 'ASC',
79
+ 'meta_key' => $options['meta_key'],
80
+ 'meta_value' => $options['meta_value'],
81
+ ));
82
+ }
83
+ else
84
+ {
85
+ // get posts
86
+ $posts = get_posts(array(
87
+ 'numberposts' => -1,
88
+ 'post_type' => $post_type,
89
+ 'orderby' => 'title',
90
+ 'order' => 'ASC',
91
+ 'meta_key' => $options['meta_key'],
92
+ 'meta_value' => $options['meta_value'],
93
+ ));
94
+ }
95
 
96
 
97
  // if posts, make a group for them
102
  foreach($posts as $post)
103
  {
104
  $key = $post->ID;
105
+
106
+ $value = '';
107
+ $ancestors = get_ancestors($post->ID, $post_type);
108
+ if($ancestors)
109
+ {
110
+ foreach($ancestors as $a)
111
+ {
112
+ $value .= '– ';
113
+ }
114
+ }
115
+ $value .= get_the_title($post->ID);
116
  $selected = '';
117
 
118
 
core/fields/post_object.php CHANGED
@@ -15,15 +15,15 @@ class acf_Post_object
15
 
16
  function html($field)
17
  {
 
 
 
 
 
18
  // get post types
19
- if(is_array($field->options['post_type']) && $field->options['post_type'][0] != "")
20
- {
21
- // 1. If select has selected post types, just use them
22
- $post_types = $field->options['post_type'];
23
- }
24
- else
25
  {
26
- //2. If not post types have been selected, load all the public ones
27
  $post_types = get_post_types(array('public' => true));
28
  foreach($post_types as $key => $value)
29
  {
@@ -34,7 +34,6 @@ class acf_Post_object
34
  }
35
  }
36
 
37
-
38
  // start select
39
  if(isset($field->options['multiple']) && $field->options['multiple'] == '1')
40
  {
@@ -52,16 +51,36 @@ class acf_Post_object
52
  }
53
  }
54
 
55
-
56
  foreach($post_types as $post_type)
57
  {
58
  // get posts
59
- $posts = get_posts(array(
60
- 'numberposts' => -1,
61
- 'post_type' => $post_type,
62
- 'orderby' => 'title',
63
- 'order' => 'ASC'
64
- ));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
 
67
  // if posts, make a group for them
@@ -72,7 +91,18 @@ class acf_Post_object
72
  foreach($posts as $post)
73
  {
74
  $key = $post->ID;
75
- $value = get_the_title($post->ID);
 
 
 
 
 
 
 
 
 
 
 
76
  $selected = '';
77
 
78
 
@@ -125,6 +155,8 @@ class acf_Post_object
125
  $options['post_type'] = isset($options['post_type']) ? $options['post_type'] : '';
126
  $options['multiple'] = isset($options['multiple']) ? $options['multiple'] : '0';
127
  $options['allow_null'] = isset($options['allow_null']) ? $options['allow_null'] : '0';
 
 
128
 
129
  ?>
130
 
@@ -160,6 +192,33 @@ class acf_Post_object
160
 
161
  </td>
162
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  <tr class="field_option field_option_post_object">
164
  <td class="label">
165
  <label><?php _e("Allow Null?",'acf'); ?></label>
15
 
16
  function html($field)
17
  {
18
+ // options
19
+ $options = $field->options;
20
+ $options['meta_key'] = isset($options['meta_key']) ? $options['meta_key'] : '';
21
+ $options['meta_value'] = isset($options['meta_value']) ? $options['meta_value'] : '';
22
+
23
  // get post types
24
+ $post_types = isset($options['post_type']) ? $options['post_type'] : false;
25
+ if(!$post_types || $post_types[0] == "")
 
 
 
 
26
  {
 
27
  $post_types = get_post_types(array('public' => true));
28
  foreach($post_types as $key => $value)
29
  {
34
  }
35
  }
36
 
 
37
  // start select
38
  if(isset($field->options['multiple']) && $field->options['multiple'] == '1')
39
  {
51
  }
52
  }
53
 
54
+ // loop through post types
55
  foreach($post_types as $post_type)
56
  {
57
  // get posts
58
+ $posts = false;
59
+
60
+ if(is_post_type_hierarchical($post_type))
61
+ {
62
+ // get pages
63
+ $posts = get_pages(array(
64
+ 'numberposts' => -1,
65
+ 'post_type' => $post_type,
66
+ 'sort_column' => 'menu_order',
67
+ 'order' => 'ASC',
68
+ 'meta_key' => $options['meta_key'],
69
+ 'meta_value' => $options['meta_value'],
70
+ ));
71
+ }
72
+ else
73
+ {
74
+ // get posts
75
+ $posts = get_posts(array(
76
+ 'numberposts' => -1,
77
+ 'post_type' => $post_type,
78
+ 'orderby' => 'title',
79
+ 'order' => 'ASC',
80
+ 'meta_key' => $options['meta_key'],
81
+ 'meta_value' => $options['meta_value'],
82
+ ));
83
+ }
84
 
85
 
86
  // if posts, make a group for them
91
  foreach($posts as $post)
92
  {
93
  $key = $post->ID;
94
+
95
+ $value = '';
96
+ $ancestors = get_ancestors($post->ID, $post_type);
97
+ if($ancestors)
98
+ {
99
+ foreach($ancestors as $a)
100
+ {
101
+ $value .= '– ';
102
+ }
103
+ }
104
+ $value .= get_the_title($post->ID);
105
+
106
  $selected = '';
107
 
108
 
155
  $options['post_type'] = isset($options['post_type']) ? $options['post_type'] : '';
156
  $options['multiple'] = isset($options['multiple']) ? $options['multiple'] : '0';
157
  $options['allow_null'] = isset($options['allow_null']) ? $options['allow_null'] : '0';
158
+ $options['meta_key'] = isset($options['meta_key']) ? $options['meta_key'] : '';
159
+ $options['meta_value'] = isset($options['meta_value']) ? $options['meta_value'] : '';
160
 
161
  ?>
162
 
192
 
193
  </td>
194
  </tr>
195
+ <tr class="field_option field_option_post_object">
196
+ <td class="label">
197
+ <label><?php _e("Filter Posts",'acf'); ?></label>
198
+ <p class="description"><?php _e("Where meta_key == meta_value",'acf'); ?></p>
199
+ </td>
200
+ <td>
201
+ <div style="width:45%; float:left">
202
+ <?php
203
+ $temp_field->type = 'text';
204
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][meta_key]';
205
+ $temp_field->input_class = '';
206
+ $temp_field->value = $options['meta_key'];
207
+ $this->parent->create_field($temp_field);
208
+ ?>
209
+ </div>
210
+ <div style="width:10%; float:left; text-align:center; padding:5px 0 0;">is equal to</div>
211
+ <div style="width:45%; float:left">
212
+ <?php
213
+ $temp_field->type = 'text';
214
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][meta_value]';
215
+ $temp_field->input_class = '';
216
+ $temp_field->value = $options['meta_value'];
217
+ $this->parent->create_field($temp_field);
218
+ ?>
219
+ </div>
220
+ </td>
221
+ </tr>
222
  <tr class="field_option field_option_post_object">
223
  <td class="label">
224
  <label><?php _e("Allow Null?",'acf'); ?></label>
core/fields/radio.php CHANGED
@@ -50,7 +50,7 @@ class acf_Radio
50
  $selected = 'checked="checked"';
51
  }
52
 
53
- echo '<li><input type="radio" class="'.$field->input_class.'" name="'.$field->input_name.'" value="'.$key.'" '.$selected.' />'.$value.'</li>';
54
  }
55
 
56
  echo '</ul>';
50
  $selected = 'checked="checked"';
51
  }
52
 
53
+ echo '<li><label><input type="radio" class="'.$field->input_class.'" name="'.$field->input_name.'" value="'.$key.'" '.$selected.' />'.$value.'</label></li>';
54
  }
55
 
56
  echo '</ul>';
core/fields/relationship.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class acf_Relationship
4
+ {
5
+ var $name;
6
+ var $title;
7
+ var $parent;
8
+
9
+ function acf_Relationship($parent)
10
+ {
11
+ $this->name = 'relationship';
12
+ $this->title = __("Relationship",'acf');
13
+ $this->parent = $parent;
14
+ }
15
+
16
+ function html($field)
17
+ {
18
+ $options = $field->options;
19
+ //$options['min'] = isset($options['min']) ? $options['min'] : '0';
20
+ $options['max'] = isset($options['max']) ? $options['max'] : '-1';
21
+ $options['meta_key'] = isset($options['meta_key']) ? $options['meta_key'] : '';
22
+ $options['meta_value'] = isset($options['meta_value']) ? $options['meta_value'] : '';
23
+
24
+ // get post types
25
+ $post_types = isset($options['post_type']) ? $options['post_type'] : false;
26
+ if(!$post_types || $post_types[0] == "")
27
+ {
28
+
29
+ $post_types = get_post_types(array('public' => true));
30
+ foreach($post_types as $key => $value)
31
+ {
32
+ if($value == 'attachment')
33
+ {
34
+ unset($post_types[$key]);
35
+ }
36
+ }
37
+ }
38
+
39
+
40
+ // get posts for list
41
+ $posts = get_posts(array(
42
+ 'numberposts' => -1,
43
+ 'post_type' => $post_types,
44
+ 'orderby' => 'title',
45
+ 'order' => 'ASC',
46
+ 'meta_key' => $options['meta_key'],
47
+ 'meta_value' => $options['meta_value'],
48
+ ));
49
+
50
+
51
+ $values_array = array();
52
+ if($field->value != "")
53
+ {
54
+ $values_array = explode(',', $field->value);
55
+ }
56
+
57
+ ?>
58
+ <div class="acf_relationship" data-max="<?php echo $options['max']; ?>">
59
+
60
+ <input type="hidden" name="<?php echo $field->input_name; ?>" value="<?php echo $field->value; ?>" />
61
+
62
+ <div class="relationship_left">
63
+ <table class="widefat">
64
+ <thead>
65
+ <tr>
66
+ <th>
67
+ <label class="relationship_label" for="relationship_<?php echo $field->input_name; ?>">Search...</label>
68
+ <input class="relationship_search" type="text" id="relationship_<?php echo $field->input_name; ?>" />
69
+ <div class="clear_relationship_search"></div>
70
+ </th>
71
+ </tr>
72
+ </thead>
73
+ </table>
74
+ <div class="relationship_list">
75
+ <?php
76
+ if($posts)
77
+ {
78
+ foreach($posts as $post)
79
+ {
80
+ if(!get_the_title($post->ID)) continue;
81
+
82
+ $class = in_array($post->ID, $values_array) ? 'hide' : '';
83
+ echo '<a href="javascript:;" class="' . $class . '" data-post_id="' . $post->ID . '">' . get_the_title($post->ID) . '<span class="add"></span></a>';
84
+ }
85
+ }
86
+ ?>
87
+ </div>
88
+ </div>
89
+
90
+ <div class="relationship_right">
91
+ <div class="relationship_list">
92
+ <?php
93
+ $temp_posts = array();
94
+
95
+ if($posts)
96
+ {
97
+ foreach($posts as $post)
98
+ {
99
+ $temp_posts[$post->ID] = $post;
100
+ }
101
+ }
102
+
103
+ if($temp_posts)
104
+ {
105
+ foreach($values_array as $value)
106
+ {
107
+ echo '<a href="javascript:;" class="" data-post_id="' . $temp_posts[$value]->ID . '">' . get_the_title($temp_posts[$value]->ID) . '<span class="remove"></span></a>';
108
+ unset($temp_posts[$value]);
109
+ }
110
+
111
+ foreach($temp_posts as $id => $post)
112
+ {
113
+ echo '<a href="javascript:;" class="hide" data-post_id="' . $post->ID . '">' . get_the_title($post->ID) . '<span class="remove"></span></a>';
114
+ }
115
+ }
116
+
117
+ ?>
118
+ </div>
119
+ </div>
120
+
121
+
122
+ </div>
123
+ <?php
124
+
125
+
126
+ }
127
+
128
+
129
+ /*---------------------------------------------------------------------------------------------
130
+ * Options HTML
131
+ * - called from fields_meta_box.php
132
+ * - displays options in html format
133
+ *
134
+ * @author Elliot Condon
135
+ * @since 1.1
136
+ *
137
+ ---------------------------------------------------------------------------------------------*/
138
+ function options_html($key, $field)
139
+ {
140
+ $options = $field->options;
141
+
142
+ $options['post_type'] = isset($options['post_type']) ? $options['post_type'] : '';
143
+ $options['max'] = isset($options['max']) ? $options['max'] : '-1';
144
+ $options['meta_key'] = isset($options['meta_key']) ? $options['meta_key'] : '';
145
+ $options['meta_value'] = isset($options['meta_value']) ? $options['meta_value'] : '';
146
+
147
+ ?>
148
+
149
+ <tr class="field_option field_option_relationship">
150
+ <td class="label">
151
+ <label for=""><?php _e("Post Type",'acf'); ?></label>
152
+ <p class="description"><?php _e("Filter posts by selecting a post type",'acf'); ?></p>
153
+ </td>
154
+ <td>
155
+ <?php
156
+ $post_types = array('' => '- All -');
157
+
158
+ foreach (get_post_types() as $post_type ) {
159
+ $post_types[$post_type] = $post_type;
160
+ }
161
+
162
+ unset($post_types['attachment']);
163
+ unset($post_types['nav_menu_item']);
164
+ unset($post_types['revision']);
165
+ unset($post_types['acf']);
166
+
167
+
168
+ $temp_field = new stdClass();
169
+ $temp_field->type = 'select';
170
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][post_type]';
171
+ $temp_field->input_class = '';
172
+ $temp_field->value = $options['post_type'];
173
+ $temp_field->options = array('choices' => $post_types, 'multiple' => '1');
174
+ $this->parent->create_field($temp_field);
175
+
176
+ ?>
177
+
178
+ </td>
179
+ </tr>
180
+ <tr class="field_option field_option_relationship">
181
+ <td class="label">
182
+ <label><?php _e("Filter Posts",'acf'); ?></label>
183
+ <p class="description"><?php _e("Where meta_key == meta_value",'acf'); ?></p>
184
+ </td>
185
+ <td>
186
+ <div style="width:45%; float:left">
187
+ <?php
188
+ $temp_field->type = 'text';
189
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][meta_key]';
190
+ $temp_field->input_class = '';
191
+ $temp_field->value = $options['meta_key'];
192
+ $this->parent->create_field($temp_field);
193
+ ?>
194
+ </div>
195
+ <div style="width:10%; float:left; text-align:center; padding:5px 0 0;">is equal to</div>
196
+ <div style="width:45%; float:left">
197
+ <?php
198
+ $temp_field->type = 'text';
199
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][meta_value]';
200
+ $temp_field->input_class = '';
201
+ $temp_field->value = $options['meta_value'];
202
+ $this->parent->create_field($temp_field);
203
+ ?>
204
+ </div>
205
+ </td>
206
+ </tr>
207
+ <tr class="field_option field_option_relationship">
208
+ <td class="label">
209
+ <label><?php _e("Maximum posts",'acf'); ?></label>
210
+ <p class="description"><?php _e("Set to -1 for inifinit",'acf'); ?></p>
211
+ </td>
212
+ <td>
213
+ <?php
214
+ $temp_field->type = 'text';
215
+ $temp_field->input_name = 'acf[fields]['.$key.'][options][max]';
216
+ $temp_field->input_class = '';
217
+ $temp_field->value = $options['max'];
218
+ $this->parent->create_field($temp_field);
219
+ ?>
220
+ </td>
221
+ </tr>
222
+
223
+
224
+ <?php
225
+ }
226
+
227
+
228
+
229
+
230
+ /*---------------------------------------------------------------------------------------------
231
+ * Format Value
232
+ * - this is called from api.php
233
+ *
234
+ * @author Elliot Condon
235
+ * @since 1.1
236
+ *
237
+ ---------------------------------------------------------------------------------------------*/
238
+ function format_value_for_api($value, $options = null)
239
+ {
240
+ $return = false;
241
+
242
+ if(!$value || $value == "")
243
+ {
244
+ return $return;
245
+ }
246
+
247
+ $value = explode(',', $value);
248
+
249
+ if(is_array($value))
250
+ {
251
+ $return = array();
252
+ foreach($value as $v)
253
+ {
254
+ $return[$v] = get_post($v);
255
+ }
256
+ }
257
+ else
258
+ {
259
+ $return = array(get_post($value));
260
+ }
261
+
262
+ return $return;
263
+ }
264
+
265
+
266
+
267
+ }
268
+
269
+ ?>
core/fields/repeater.php CHANGED
@@ -430,6 +430,7 @@ class acf_Repeater
430
  ---------------------------------------------------------------------------------------------*/
431
  function save_input($post_id, $field)
432
  {
 
433
 
434
  // set table name
435
  global $wpdb;
@@ -442,6 +443,7 @@ class acf_Repeater
442
 
443
  if($field['value'])
444
  {
 
445
  $i = 0;
446
  foreach($field['value'] as $row)
447
  {
@@ -468,7 +470,6 @@ class acf_Repeater
468
  // create data: wp_postmeta
469
  $data1 = array(
470
  'post_id' => (int) $post_id,
471
- //'meta_key' => $field['field_name'] . '_' . $i . '_' . $j,
472
  'meta_key' => $field['field_name'],
473
  'meta_value' => $cell['value']
474
  );
@@ -498,6 +499,7 @@ class acf_Repeater
498
 
499
  $data2 = array(
500
  'field_id' => $field['field_id'],
 
501
  'sub_field_id' => (int) $cell['field_id'],
502
  'value' => $new_id,
503
  'order_no' => $i,
430
  ---------------------------------------------------------------------------------------------*/
431
  function save_input($post_id, $field)
432
  {
433
+ //echo 'saving repeater';
434
 
435
  // set table name
436
  global $wpdb;
443
 
444
  if($field['value'])
445
  {
446
+
447
  $i = 0;
448
  foreach($field['value'] as $row)
449
  {
470
  // create data: wp_postmeta
471
  $data1 = array(
472
  'post_id' => (int) $post_id,
 
473
  'meta_key' => $field['field_name'],
474
  'meta_value' => $cell['value']
475
  );
499
 
500
  $data2 = array(
501
  'field_id' => $field['field_id'],
502
+ 'post_id' => (int) $post_id,
503
  'sub_field_id' => (int) $cell['field_id'],
504
  'value' => $new_id,
505
  'order_no' => $i,
core/import.php CHANGED
@@ -182,7 +182,7 @@ foreach($posts as $post)
182
 
183
  }
184
 
185
- $this->_save_post($post_id);
186
  }
187
  // if($post_id != 0)
188
 
182
 
183
  }
184
 
185
+ $this->save_post($post_id);
186
  }
187
  // if($post_id != 0)
188
 
core/third_party.php CHANGED
@@ -10,47 +10,152 @@
10
  *-------------------------------------------------------------------------------------*/
11
  function acf_duplicate($newId, $post)
12
  {
13
-
14
- // tables
15
  global $wpdb;
 
 
 
16
  $acf_values = $wpdb->prefix.'acf_values';
 
17
  $wp_postmeta = $wpdb->prefix.'postmeta';
18
 
19
-
20
- // get rows
21
- $sql = "SELECT m.meta_key, m.meta_value, v.value, v.field_id, v.sub_field_id, v.order_no
22
- FROM $wp_postmeta m LEFT JOIN $acf_values v ON m.meta_id = v.value
23
- WHERE m.post_id = '$post->ID'";
24
-
25
- $rows = $wpdb->get_results($sql);
26
-
27
- foreach ($rows as $row) {
28
 
29
- // save postmeta
30
- $data = array(
31
- 'post_id' => $newId,
32
- 'meta_key' => $row->meta_key,
33
- 'meta_value' => $row->meta_value,
34
- );
 
35
 
36
- $wpdb->insert($wp_postmeta, $data);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
- $new_value_id = $wpdb->insert_id;
 
 
 
 
 
39
 
40
- if($new_value_id && $new_value_id != 0)
41
  {
42
- // create data object to save
43
- $data2 = array(
44
- 'post_id' => $newId,
45
- 'order_no' => $row->order_no,
46
- 'field_id' => $row->field_id,
47
- 'sub_field_id' => $row->sub_field_id,
48
- 'value' => $new_value_id,
49
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- $wpdb->insert($acf_values, $data2);
 
 
 
 
 
 
 
52
  }
 
 
 
 
 
 
 
 
 
 
 
 
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  }
55
 
56
  }
10
  *-------------------------------------------------------------------------------------*/
11
  function acf_duplicate($newId, $post)
12
  {
13
+ // global
 
14
  global $wpdb;
15
+
16
+ // tables
17
+ $acf_fields = $wpdb->prefix.'acf_fields';
18
  $acf_values = $wpdb->prefix.'acf_values';
19
+ $acf_rules = $wpdb->prefix.'acf_rules';
20
  $wp_postmeta = $wpdb->prefix.'postmeta';
21
 
22
+ if($post->post_type == 'acf')
23
+ {
 
 
 
 
 
 
 
24
 
25
+ // save fields
26
+ $sql = "SELECT *
27
+ FROM $acf_fields
28
+ WHERE post_id = '$post->ID'
29
+ ORDER BY parent_id ASC";
30
+
31
+ $rows = $wpdb->get_results($sql);
32
 
33
+ if($rows)
34
+ {
35
+ $repeater_fields = array();
36
+
37
+ foreach ($rows as $row) {
38
+
39
+ // save postmeta
40
+ $data = array(
41
+ 'post_id' => $newId,
42
+ 'label' => $row->label,
43
+ 'name' => $row->name,
44
+ 'type' => $row->type,
45
+ 'parent_id' => $row->parent_id,
46
+ 'options' => $row->options,
47
+ 'order_no' => $row->order_no,
48
+ 'instructions' => $row->instructions,
49
+ 'default_value' => $row->default_value,
50
+ );
51
+
52
+ // override parent_id
53
+ if( (int) $row->parent_id != 0 )
54
+ {
55
+ $data['parent_id'] = (int) $repeater_fields[$row->parent_id];
56
+ }
57
+
58
+ // insert
59
+ $wpdb->insert($acf_fields, $data);
60
+
61
+ // update repeater id
62
+ if($row->type == 'repeater')
63
+ {
64
+ $repeater_fields[$row->id] = $wpdb->insert_id;
65
+ }
66
+
67
+ }
68
+
69
+ }
70
 
71
+ // save rules
72
+ $sql = "SELECT *
73
+ FROM $acf_rules
74
+ WHERE acf_id = '$post->ID'";
75
+
76
+ $rows = $wpdb->get_results($sql);
77
 
78
+ if($rows)
79
  {
80
+ foreach ($rows as $row) {
81
+
82
+ // save postmeta
83
+ $data = array(
84
+ 'acf_id' => $newId,
85
+ 'param' => $row->param,
86
+ 'operator' => $row->operator,
87
+ 'value' => $row->value,
88
+ 'order_no' => $row->order_no,
89
+ );
90
+
91
+ $wpdb->insert($acf_rules, $data);
92
+
93
+ }
94
+ }
95
+
96
+ }
97
+ else
98
+ {
99
+
100
+ // deletes duplicated acf postmeta
101
+ $sql = "SELECT f.name
102
+ FROM $wp_postmeta m
103
+ LEFT JOIN $acf_values v ON m.meta_id = v.value
104
+ LEFT JOIN $acf_fields f ON v.field_id = f.id
105
+ WHERE m.post_id = '$post->ID' AND f.name != 'NULL'";
106
 
107
+ $results = $wpdb->get_results($sql);
108
+
109
+ if($results)
110
+ {
111
+ foreach($results as $result)
112
+ {
113
+ $wpdb->query("DELETE FROM $wp_postmeta WHERE meta_key = '$result->name' AND post_id = '$newId'");
114
+ }
115
  }
116
+
117
+
118
+ // duplicate postmen + values
119
+ $sql = "SELECT m.meta_key, m.meta_value, v.value, v.field_id, v.sub_field_id, v.order_no
120
+ FROM $wp_postmeta m
121
+ LEFT JOIN $acf_values v ON m.meta_id = v.value
122
+ LEFT JOIN $acf_fields f ON v.field_id = f.id
123
+ WHERE m.post_id = '$post->ID' AND f.name != 'NULL'";
124
+
125
+ $rows = $wpdb->get_results($sql);
126
+ if($rows)
127
+ {
128
 
129
+ foreach ($rows as $row) {
130
+
131
+ // save postmeta
132
+ $data = array(
133
+ 'post_id' => $newId,
134
+ 'meta_key' => $row->meta_key,
135
+ 'meta_value' => $row->meta_value,
136
+ );
137
+
138
+ $wpdb->insert($wp_postmeta, $data);
139
+
140
+ $new_value_id = $wpdb->insert_id;
141
+
142
+ if($new_value_id && $new_value_id != 0)
143
+ {
144
+ // create data object to save
145
+ $data2 = array(
146
+ 'post_id' => $newId,
147
+ 'order_no' => $row->order_no,
148
+ 'field_id' => $row->field_id,
149
+ 'sub_field_id' => $row->sub_field_id,
150
+ 'value' => $new_value_id,
151
+ );
152
+
153
+ $wpdb->insert($acf_values, $data2);
154
+ }
155
+
156
+ }
157
+ }
158
+
159
  }
160
 
161
  }
core/upgrade.php CHANGED
@@ -54,10 +54,11 @@ if(version_compare($version,'1.1.0') < 0)
54
  // create acf_values table
55
  $sql = "CREATE TABLE " . $acf_values . " (
56
  id bigint(20) NOT NULL AUTO_INCREMENT,
 
57
  order_no int(9) NOT NULL DEFAULT '0',
58
  field_id bigint(20) NOT NULL DEFAULT '0',
59
- value text NOT NULL,
60
- post_id bigint(20) NOT NULL DEFAULT '0',
61
  UNIQUE KEY id (id)
62
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
63
  dbDelta($sql);
@@ -166,6 +167,7 @@ if(version_compare($version,'2.1.0') < 0)
166
  // value is now an int
167
  $sql = "CREATE TABLE " . $acf_values . " (
168
  id bigint(20) NOT NULL AUTO_INCREMENT,
 
169
  order_no int(9) NOT NULL DEFAULT '0',
170
  field_id bigint(20) NOT NULL DEFAULT '0',
171
  sub_field_id bigint(20) NOT NULL DEFAULT '0',
@@ -193,7 +195,46 @@ if(version_compare($version,'2.1.0') < 0)
193
  }
194
 
195
 
 
 
 
 
 
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  /*--------------------------------------------------------------------------------------
198
  *
199
  * Finish
54
  // create acf_values table
55
  $sql = "CREATE TABLE " . $acf_values . " (
56
  id bigint(20) NOT NULL AUTO_INCREMENT,
57
+ post_id bigint(20) NOT NULL DEFAULT '0',
58
  order_no int(9) NOT NULL DEFAULT '0',
59
  field_id bigint(20) NOT NULL DEFAULT '0',
60
+ sub_field_id bigint(20) NOT NULL DEFAULT '0',
61
+ value bigint(20) NOT NULL DEFAULT '0',
62
  UNIQUE KEY id (id)
63
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
64
  dbDelta($sql);
167
  // value is now an int
168
  $sql = "CREATE TABLE " . $acf_values . " (
169
  id bigint(20) NOT NULL AUTO_INCREMENT,
170
+ post_id bigint(20) NOT NULL DEFAULT '0',
171
  order_no int(9) NOT NULL DEFAULT '0',
172
  field_id bigint(20) NOT NULL DEFAULT '0',
173
  sub_field_id bigint(20) NOT NULL DEFAULT '0',
195
  }
196
 
197
 
198
+ /*--------------------------------------------------------------------------------------
199
+ *
200
+ * 2.1.4
201
+ *
202
+ *-------------------------------------------------------------------------------------*/
203
 
204
+ if(version_compare($version,'2.1.4') < 0)
205
+ {
206
+
207
+ // add back in post_id to values table (useful for duplicate posts / third party stuff)
208
+ $sql = "CREATE TABLE " . $acf_values . " (
209
+ id bigint(20) NOT NULL AUTO_INCREMENT,
210
+ post_id bigint(20) NOT NULL DEFAULT '0',
211
+ order_no int(9) NOT NULL DEFAULT '0',
212
+ field_id bigint(20) NOT NULL DEFAULT '0',
213
+ sub_field_id bigint(20) NOT NULL DEFAULT '0',
214
+ value bigint(20) NOT NULL DEFAULT '0',
215
+ UNIQUE KEY id (id)
216
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
217
+ dbDelta($sql);
218
+
219
+
220
+ // copy across post_id
221
+ $sql2 = "SELECT m.post_id, v.id
222
+ FROM $wp_postmeta m
223
+ LEFT JOIN $acf_values v ON m.meta_id = v.value";
224
+
225
+ $values = $wpdb->get_results($sql2);
226
+ if($values)
227
+ {
228
+ foreach($values as $value)
229
+ {
230
+ $wpdb->query("UPDATE $acf_values SET post_id = '$value->post_id' WHERE id = '$value->id'");
231
+ }
232
+ }
233
+
234
+ // set version
235
+ update_option('acf_version','2.1.4');
236
+ $version = '2.1.4';
237
+ }
238
  /*--------------------------------------------------------------------------------------
239
  *
240
  * Finish
css/style.fields.css CHANGED
@@ -1,6 +1,9 @@
1
  /*---------------------------------------------------------------------------------------------
2
  Postbox
3
  ---------------------------------------------------------------------------------------------*/
 
 
 
4
 
5
  .postbox#acf_fields {
6
  border: 0 none;
@@ -342,5 +345,3 @@ table.acf_input tr td .acf tr td {
342
  .field_form .field_option {
343
  display: none;
344
  }
345
-
346
-
1
  /*---------------------------------------------------------------------------------------------
2
  Postbox
3
  ---------------------------------------------------------------------------------------------*/
4
+ #icon-edit {
5
+ background: url(../images/acf-icon-32.png) 0 0 no-repeat !important;
6
+ }
7
 
8
  .postbox#acf_fields {
9
  border: 0 none;
345
  .field_form .field_option {
346
  display: none;
347
  }
 
 
css/style.input.css CHANGED
@@ -72,6 +72,10 @@
72
  background: #fff;
73
  }
74
 
 
 
 
 
75
  #post-body .acf_wysiwyg .wp_themeSkin .mceStatusbar a.mceResize {
76
  top: -2px !important;
77
  }
@@ -118,9 +122,6 @@
118
  }
119
 
120
  .acf_image_uploader img {
121
- max-height: 100px;
122
- width: auto;
123
- height: auto;
124
  display: none;
125
  -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
126
  }
@@ -355,4 +356,136 @@ ul.checkbox_list {
355
 
356
  .no_move .postbox .hndle {
357
  cursor: default !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  }
72
  background: #fff;
73
  }
74
 
75
+ .acf_wysiwyg textarea{
76
+ height: 320px;
77
+ }
78
+
79
  #post-body .acf_wysiwyg .wp_themeSkin .mceStatusbar a.mceResize {
80
  top: -2px !important;
81
  }
122
  }
123
 
124
  .acf_image_uploader img {
 
 
 
125
  display: none;
126
  -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
127
  }
356
 
357
  .no_move .postbox .hndle {
358
  cursor: default !important;
359
+ }
360
+
361
+ /*---------------------------------------------------------------------------------------------
362
+ relationship
363
+ ---------------------------------------------------------------------------------------------*/
364
+
365
+ .acf_relationship {
366
+ position: relative;
367
+ overflow: hidden;
368
+ }
369
+
370
+ .acf_relationship .relationship_left {
371
+ width: 50%;
372
+ float: left;
373
+ }
374
+
375
+ .acf_relationship .relationship_right {
376
+ width: 50%;
377
+ float: left;
378
+ }
379
+
380
+ .acf_relationship .relationship_label {
381
+ font-size: 12px;
382
+ font-family: sans-serif;
383
+ color: #999;
384
+ position: absolute;
385
+ margin-top: 4px;
386
+ margin-left: 7px;
387
+ }
388
+
389
+ .acf_relationship .widefat {
390
+ border-bottom-left-radius: 0;
391
+ border-bottom-right-radius: 0;
392
+ }
393
+
394
+ .acf_relationship .widefat th {
395
+ border-bottom: 0 none;
396
+ }
397
+
398
+
399
+ .acf_relationship .relationship_search {
400
+ margin: 0;
401
+ font-size: 12px;
402
+ line-height: 13px;
403
+ padding: 5px;
404
+ border-radius: 13px
405
+ }
406
+
407
+ .acf_relationship .relationship_list {
408
+ background: #fff;
409
+ position: relative;
410
+ overflow: auto;
411
+ height: 150px;
412
+ border: #DFDFDF solid 1px;
413
+ border-top-width: 0;
414
+ }
415
+
416
+ .acf_relationship .relationship_list a.hide {
417
+ display: none;
418
+ }
419
+
420
+ .acf_relationship .relationship_list a.filter_hide {
421
+ display: none;
422
+ }
423
+
424
+ .acf_relationship .relationship_list a {
425
+ display: block;
426
+ position: relative;
427
+ padding: 7px 9px;
428
+ text-decoration: none;
429
+ border-bottom: #f8f8f8 solid 1px;
430
+ }
431
+
432
+
433
+ .acf_relationship .relationship_list a:hover {
434
+ background: #eaf2fa;
435
+ border-bottom-color: #eaf2fa;
436
+ color: #000;
437
+ }
438
+
439
+ .acf_relationship .relationship_right .relationship_list {
440
+ margin-left: 10px;
441
+ height: 193px;
442
+ border-top-width:1px;
443
+ }
444
+
445
+ .acf_relationship .relationship_list a .add {
446
+ width: 16px;
447
+ height: 16px;
448
+ background: url(../images/button_add.png) 0 0 no-repeat;
449
+ position: absolute;
450
+ top:0;
451
+ right: 0;
452
+ cursor: pointer;
453
+ margin: 5px 9px 0 0;
454
+ display: none;
455
+ }
456
+
457
+ .acf_relationship .relationship_list a.sortable_active {
458
+ background: #eaf2fa;
459
+ }
460
+
461
+ .acf_relationship .relationship_list a:hover .add {
462
+ display: block;
463
+ }
464
+
465
+ .acf_relationship .relationship_list a .add:hover {
466
+ background-position: 0 100%;
467
+ }
468
+
469
+ .acf_relationship .relationship_list a .remove {
470
+ width: 16px;
471
+ height: 16px;
472
+ background: url(../images/button_remove.png) 0 0 no-repeat;
473
+ position: absolute;
474
+ top:0;
475
+ right: 0;
476
+ cursor: pointer;
477
+ margin: 5px 9px 0 0;
478
+ display: none;
479
+ }
480
+
481
+ .acf_relationship .relationship_list a:hover .remove {
482
+ display: block;
483
+ }
484
+
485
+ .acf_relationship .relationship_list a .remove:hover {
486
+ background-position: 0 100%;
487
+ }
488
+
489
+ .acf_relationship .relationship_right .relationship_list a {
490
+ cursor: move;
491
  }
css/style.screen_extra.css CHANGED
@@ -1,6 +1,10 @@
1
  /*--------------------------------------------------------------------------------------------
2
  Screen Extra
3
  --------------------------------------------------------------------------------------------*/
 
 
 
 
4
  .acf_cols {position: relative; overflow: hidden; clear: both;}
5
  .acf_col_left {margin-right: 300px;}
6
  .acf_col_left .tablenav {display: none;}
1
  /*--------------------------------------------------------------------------------------------
2
  Screen Extra
3
  --------------------------------------------------------------------------------------------*/
4
+ #icon-options-general {
5
+ background: url(../images/acf-icon-32.png) 0 0 no-repeat !important;
6
+ }
7
+
8
  .acf_cols {position: relative; overflow: hidden; clear: both;}
9
  .acf_col_left {margin-right: 300px;}
10
  .acf_col_left .tablenav {display: none;}
images/acf-icon-32.png ADDED
Binary file
images/backgrounds DELETED
Binary file
js/functions.input.js CHANGED
@@ -1,7 +1,14 @@
1
  window.acf_div = null;
2
 
3
  (function($){
4
-
 
 
 
 
 
 
 
5
  /*----------------------------------------------------------------------
6
  *
7
  * Exists
@@ -79,6 +86,124 @@ window.acf_div = null;
79
  };
80
 
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  /*----------------------------------------------------------------------
83
  *
84
  * Datepicker
@@ -114,6 +239,7 @@ window.acf_div = null;
114
  $(this).find('.acf_image_uploader').each(function(){
115
 
116
  var div = $(this);
 
117
 
118
  div.find('input.button').unbind('click').click(function(){
119
 
@@ -121,7 +247,7 @@ window.acf_div = null;
121
  window.acf_div = div;
122
 
123
  // show the thickbox
124
- tb_show('Add Image to field', 'media-upload.php?post_id='+post_id+'&type=image&acf_type=image&TB_iframe=1');
125
 
126
  return false;
127
  });
@@ -152,7 +278,7 @@ window.acf_div = null;
152
 
153
  $(this).find('.acf_file_uploader').each(function(){
154
 
155
- console.log('file setup');
156
  var div = $(this);
157
 
158
  div.find('p.no_file input.button').click(function(){
@@ -232,11 +358,30 @@ window.acf_div = null;
232
  // create and add the new field
233
  var new_field = r.children('table').children('tbody').children('tr:last-child').clone(false);
234
  r.children('table').children('tbody').append(new_field);
235
-
236
- new_field.reset_values();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
 
238
  // setup sub fields
239
  new_field.setup_wysiwyg();
 
240
  new_field.setup_datepicker();
241
  new_field.setup_image();
242
  new_field.setup_file();
@@ -334,6 +479,7 @@ window.acf_div = null;
334
  update: function(event, ui){
335
  r.update_order_numbers();
336
  r.setup_wysiwyg();
 
337
  r.setup_datepicker();
338
  r.setup_image();
339
  r.setup_file();
@@ -365,13 +511,33 @@ window.acf_div = null;
365
  var div = $(this);
366
 
367
 
 
368
  if(div.find('.acf_wysiwyg').exists())
369
  {
370
- var wysiwyg = $(this).find('.acf_wysiwyg');
371
 
372
- var name = wysiwyg.find('textarea').first().attr('name');
 
 
 
373
 
374
- wysiwyg.html('<div id="editorcontainer"><textarea name="'+name+'"></textarea></div>');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
  }
376
 
377
 
@@ -393,19 +559,12 @@ window.acf_div = null;
393
  });
394
 
395
 
396
-
397
-
398
- // total fields
399
- var total_fields = $(this).siblings('tr').length;
400
 
401
-
402
  // reset all values
403
  $(this).find('[name]').each(function()
404
  {
405
- var name = $(this).attr('name').replace('[value]['+(total_fields-1)+']','[value]['+(total_fields)+']');
406
- $(this).attr('name', name);
407
- $(this).attr('id', name);
408
-
409
  if(name.indexOf("[field_id]") != -1)
410
  {
411
  // do nothing, we want to keep this hidden field with it's current values
@@ -422,7 +581,7 @@ window.acf_div = null;
422
  {
423
  $(this).val('');
424
  }
425
-
426
  // selected / ticked
427
  if($(this).is(':selected'))
428
  {
@@ -440,6 +599,42 @@ window.acf_div = null;
440
  };
441
 
442
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
  /*----------------------------------------------------------------------
444
  *
445
  * Setup ACF
@@ -453,10 +648,13 @@ window.acf_div = null;
453
 
454
 
455
  div.setup_wysiwyg();
 
456
  div.setup_datepicker();
457
  div.setup_image();
458
  div.setup_file();
459
  div.setup_repeater();
 
 
460
  };
461
 
462
 
@@ -469,8 +667,23 @@ window.acf_div = null;
469
 
470
  $(document).ready(function(){
471
 
472
-
473
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  });
475
 
 
 
476
  })(jQuery);
1
  window.acf_div = null;
2
 
3
  (function($){
4
+
5
+ /*----------------------------------------------------------------------
6
+ *
7
+ * vars
8
+ *
9
+ *---------------------------------------------------------------------*/
10
+ var shift_is_down = false;
11
+
12
  /*----------------------------------------------------------------------
13
  *
14
  * Exists
86
  };
87
 
88
 
89
+ /*----------------------------------------------------------------------
90
+ *
91
+ * Relationship
92
+ *
93
+ *---------------------------------------------------------------------*/
94
+
95
+ $.fn.setup_relationship = function()
96
+ {
97
+ $(this).find('.acf_relationship').each(function(){
98
+
99
+ //console.log('setup');
100
+
101
+ var div = $(this);
102
+ //var min = parseInt(div.attr('data-min'));
103
+ var max = parseInt(div.attr('data-max')); if(max == -1){max = 9999;}
104
+ var input = div.children('input');
105
+ var left = div.find('.relationship_left .relationship_list');
106
+ var right = div.find('.relationship_right .relationship_list');
107
+ var search = div.find('input.relationship_search');
108
+
109
+
110
+ left.find('a').unbind('click').click(function(){
111
+
112
+ if(right.find('a:not(.hide)').length >= max)
113
+ {
114
+ alert('Maximum values reached ( ' + max + ' values )');
115
+ return false;
116
+ }
117
+
118
+ var id = $(this).attr('data-post_id');
119
+
120
+ $(this).addClass('hide');
121
+ right.find('a[data-post_id="' + id + '"]').removeClass('hide').appendTo(right);
122
+
123
+ update_input_val();
124
+
125
+ return false;
126
+
127
+ });
128
+
129
+
130
+ right.find('a').unbind('click').click(function(){
131
+
132
+ var id = $(this).attr('data-post_id');
133
+
134
+ $(this).addClass('hide');
135
+ left.find('a[data-post_id="' + id + '"]').removeClass('hide');
136
+
137
+ update_input_val();
138
+
139
+ return false;
140
+
141
+ });
142
+
143
+
144
+ right.unbind('sortable').sortable({
145
+ axis: "y", // limit the dragging to up/down only
146
+ start: function(event, ui)
147
+ {
148
+ ui.item.addClass('sortable_active');
149
+ },
150
+ stop: function(event, ui)
151
+ {
152
+ ui.item.removeClass('sortable_active');
153
+ update_input_val();
154
+ }
155
+ });
156
+
157
+
158
+ $.expr[':'].Contains = function(a,i,m){
159
+ return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
160
+ };
161
+
162
+ search.val('');
163
+ search.change(function ()
164
+ {
165
+ var filter = $(this).val();
166
+ if(filter)
167
+ {
168
+ left.find("a:not(:Contains(" + filter + "))").addClass('filter_hide');
169
+ left.find("a:Contains(" + filter + "):not(.hide)").removeClass('filter_hide');
170
+ }
171
+ else
172
+ {
173
+ left.find("a:not(.hide)").removeClass('filter_hide');
174
+ }
175
+
176
+ return false;
177
+
178
+ })
179
+ .keyup( function () {
180
+ $(this).change();
181
+ });
182
+
183
+ search.focus(function(){
184
+ $(this).siblings('label').hide();
185
+ })
186
+ .blur(function(){
187
+ if($(this).val() == "")
188
+ {
189
+ $(this).siblings('label').show();
190
+ }
191
+ });
192
+
193
+
194
+ function update_input_val()
195
+ {
196
+ var value = new Array();
197
+ right.find('a:not(.hide)').each(function(){
198
+ value.push($(this).attr('data-post_id'));
199
+ });
200
+ input.val(value.join(','));
201
+ }
202
+
203
+ });
204
+ };
205
+
206
+
207
  /*----------------------------------------------------------------------
208
  *
209
  * Datepicker
239
  $(this).find('.acf_image_uploader').each(function(){
240
 
241
  var div = $(this);
242
+ var preview_size = div.attr('data-preview_size');
243
 
244
  div.find('input.button').unbind('click').click(function(){
245
 
247
  window.acf_div = div;
248
 
249
  // show the thickbox
250
+ tb_show('Add Image to field', 'media-upload.php?post_id=' + post_id + '&type=image&acf_type=image&acf_preview_size=' + preview_size + 'TB_iframe=1');
251
 
252
  return false;
253
  });
278
 
279
  $(this).find('.acf_file_uploader').each(function(){
280
 
281
+ //console.log('file setup');
282
  var div = $(this);
283
 
284
  div.find('p.no_file input.button').click(function(){
358
  // create and add the new field
359
  var new_field = r.children('table').children('tbody').children('tr:last-child').clone(false);
360
  r.children('table').children('tbody').append(new_field);
361
+
362
+ // update names
363
+ new_field.find('[name]').each(function(){
364
+
365
+ var name = $(this).attr('name').replace('[value]['+(row_count-1)+']','[value]['+(row_count)+']');
366
+ $(this).attr('name', name);
367
+ $(this).attr('id', name);
368
+
369
+ if(name.indexOf("[value_id]") != -1 || name.indexOf("[meta_id]") != -1)
370
+ {
371
+ $(this).val('');
372
+ }
373
+
374
+ });
375
+
376
+ // reset values
377
+ if(!shift_is_down)
378
+ {
379
+ new_field.reset_values();
380
+ }
381
 
382
  // setup sub fields
383
  new_field.setup_wysiwyg();
384
+ new_field.setup_relationship();
385
  new_field.setup_datepicker();
386
  new_field.setup_image();
387
  new_field.setup_file();
479
  update: function(event, ui){
480
  r.update_order_numbers();
481
  r.setup_wysiwyg();
482
+ r.setup_relationship();
483
  r.setup_datepicker();
484
  r.setup_image();
485
  r.setup_file();
511
  var div = $(this);
512
 
513
 
514
+ // wysiwyg
515
  if(div.find('.acf_wysiwyg').exists())
516
  {
517
+ div.find('.acf_wysiwyg').each(function(){
518
 
519
+ var name = $(this).find('textarea').first().attr('name');
520
+ $(this).html('<div id="editorcontainer"><textarea name="'+name+'"></textarea></div>');
521
+
522
+ });
523
 
524
+ }
525
+
526
+
527
+ // relationship
528
+ if(div.find('.acf_relationship').exists())
529
+ {
530
+ div.find('.acf_relationship').each(function(){
531
+
532
+ $(this).find('.relationship_left .relationship_list a').each(function(){
533
+ $(this).removeClass('hide');
534
+ });
535
+
536
+ $(this).find('.relationship_right .relationship_list a').each(function(){
537
+ $(this).addClass('hide');
538
+ });
539
+
540
+ });
541
  }
542
 
543
 
559
  });
560
 
561
 
 
 
 
 
562
 
 
563
  // reset all values
564
  $(this).find('[name]').each(function()
565
  {
566
+ var name = $(this).attr('name');
567
+
 
 
568
  if(name.indexOf("[field_id]") != -1)
569
  {
570
  // do nothing, we want to keep this hidden field with it's current values
581
  {
582
  $(this).val('');
583
  }
584
+
585
  // selected / ticked
586
  if($(this).is(':selected'))
587
  {
599
  };
600
 
601
 
602
+ /*----------------------------------------------------------------------
603
+ *
604
+ * Setup Validation
605
+ *
606
+ *---------------------------------------------------------------------*/
607
+
608
+ $.fn.setup_validation = function()
609
+ {
610
+ /*var div = $(this);
611
+
612
+ $('#publish').click(function(){
613
+
614
+
615
+ // relationship
616
+ div.find('.acf_relationship').each(function(){
617
+
618
+ var r = $(this);
619
+ var min = parseInt(r.attr('data-min'));
620
+
621
+ if(r.find('.relationship_right .relationship_list a:not(.hide)').length < min)
622
+ {
623
+ alert('Minimum values not reached ( ' + max + ' values )');
624
+ return false;
625
+ }
626
+
627
+ });
628
+
629
+ console.log('setup');
630
+
631
+ var div = $(this);
632
+
633
+
634
+
635
+ });*/
636
+ }
637
+
638
  /*----------------------------------------------------------------------
639
  *
640
  * Setup ACF
648
 
649
 
650
  div.setup_wysiwyg();
651
+ div.setup_relationship();
652
  div.setup_datepicker();
653
  div.setup_image();
654
  div.setup_file();
655
  div.setup_repeater();
656
+ div.setup_validation();
657
+
658
  };
659
 
660
 
667
 
668
  $(document).ready(function(){
669
 
670
+ // add shift key trigger for duplicating repeater field
671
 
672
+ $(window).keydown(function(evt){
673
+ if(evt.which == 16)
674
+ {
675
+ shift_is_down = true;
676
+ }
677
+ }).keyup(function(evt) {
678
+ if(evt.which == 16)
679
+ {
680
+ shift_is_down = false;
681
+ }
682
+ });
683
+
684
+
685
  });
686
 
687
+
688
+
689
  })(jQuery);
lang/advanced-custom-fields-nl_NL.mo ADDED
Binary file
lang/advanced-custom-fields-ru-RU.mo ADDED
Binary file
readme.txt CHANGED
@@ -13,7 +13,7 @@ Completely Customise your edit pages with an assortment of field types: Wysiwyg,
13
  Advanced Custom Fields is the perfect solution for any wordpress website which needs more flexible data like other Content Management Systems.
14
 
15
  * Visually create your Fields
16
- * Select from multiple input types (text, textarea, wysiwyg, image upload, page link, select, checkbox, more to come)
17
  * Assign your fields to multiple edit pages (specific ID's, post types, post slugs, parent ID's, template names)
18
  * Add, Edit and reorder infinite rows to your fields
19
  * Easily load data through a simple and friendly API
@@ -41,8 +41,11 @@ Advanced Custom Fields is the perfect solution for any wordpress website which n
41
  * PC Firefox :)
42
  * PC ie7 :S
43
 
44
- = Video Tutorials =
45
- http://plugins.elliotcondon.com/advanced-custom-fields/user-guide/
 
 
 
46
 
47
  = Field Type Info =
48
  http://plugins.elliotcondon.com/advanced-custom-fields/field-types/
@@ -61,11 +64,22 @@ Your votes really make a difference! Thanks.
61
 
62
  1. Upload 'advanced-custom-fields' to the '/wp-content/plugins/' directory
63
  2. Activate the plugin through the 'Plugins' menu in WordPress
64
- 3. Click on Settings -> Adv Custom Fields and create your first matrix!
 
 
 
65
 
66
 
67
  == Frequently Asked Questions ==
68
- Please View the forum
 
 
 
 
 
 
 
 
69
  http://support.plugins.elliotcondon.com/categories/advanced-custom-fields/
70
 
71
 
@@ -76,17 +90,30 @@ http://support.plugins.elliotcondon.com/categories/advanced-custom-fields/
76
 
77
  3. The Page edit screen after creating the Advanced Custom Fields
78
 
79
- 4. Simple and intuitive API. Read the documentation at: http://plugins.elliotcondon.com/advanced-custom-fields/code-examples/
80
 
81
 
82
  == Changelog ==
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  = 2.1.3 =
85
  * Fixed API returning true for repeater fields with no data
86
  * Added get_fields back into the api!
87
  * Fixed field type select from showing multiple repeater activation messages
88
 
89
-
90
  = 2.1.2 =
91
  * Fixed repeater sortable bug on options page
92
  * Fixed wysiwyg image insert on options page
@@ -233,3 +260,9 @@ http://support.plugins.elliotcondon.com/categories/advanced-custom-fields/
233
 
234
  = 1.0.0 =
235
  * Advanced Custom Fields.
 
 
 
 
 
 
13
  Advanced Custom Fields is the perfect solution for any wordpress website which needs more flexible data like other Content Management Systems.
14
 
15
  * Visually create your Fields
16
+ * Select from multiple input types (text, textarea, wysiwyg, image, file, page link, post object, relationship, select, checkbox, radio buttons, repeater, more to come)
17
  * Assign your fields to multiple edit pages (specific ID's, post types, post slugs, parent ID's, template names)
18
  * Add, Edit and reorder infinite rows to your fields
19
  * Easily load data through a simple and friendly API
41
  * PC Firefox :)
42
  * PC ie7 :S
43
 
44
+ = Demonstration =
45
+ http://plugins.elliotcondon.com/advanced-custom-fields/demonstration/
46
+
47
+ = Documentation =
48
+ http://plugins.elliotcondon.com/advanced-custom-fields/documentation/
49
 
50
  = Field Type Info =
51
  http://plugins.elliotcondon.com/advanced-custom-fields/field-types/
64
 
65
  1. Upload 'advanced-custom-fields' to the '/wp-content/plugins/' directory
66
  2. Activate the plugin through the 'Plugins' menu in WordPress
67
+ 3. You may be prompted for a Database Upgrade. This is necessary for ACF to function. Please backup your database and click the Upgrade button
68
+ 3. Click on Settings -> Adv Custom Fields and create your first Custom Field Group!
69
+ 4. Your ACF field group will now appear on the page / post / template you specified in the field group's location rules!
70
+ 5. Read the documentation to display your data:
71
 
72
 
73
  == Frequently Asked Questions ==
74
+
75
+ = Q. I can't see the "Select Image" button for my image field! =
76
+ A. For Image uploads to work, your post type must support "editor"
77
+
78
+ = Q. ACF uses custom database tables, can I still query posts based on meta_key / value? =
79
+ A. Yes, meta_key and meta_value act as usual. All field data is stored as a normal custom field, but is attached to a row in the acf_values table for extra functionality!
80
+
81
+ = Q. I have a question =
82
+ A. Chances are, someone else has asked it. Check out the support forum at:
83
  http://support.plugins.elliotcondon.com/categories/advanced-custom-fields/
84
 
85
 
90
 
91
  3. The Page edit screen after creating the Advanced Custom Fields
92
 
93
+ 4. Simple and intuitive API. Read the documentation at: http://plugins.elliotcondon.com/advanced-custom-fields/documentation/
94
 
95
 
96
  == Changelog ==
97
 
98
+ = 2.1.4 =
99
+ * Fixed add image tinymce error for options Page WYSIWYG
100
+ * API: added new function: update_the_field($field_name, $value, $post_id)
101
+ * New field: Relationship field
102
+ * New Option for Relationship + Post Object: filter posts via meta_key and meta_value
103
+ * Added new option: Image preview size (thumb, medium, large, full)
104
+ * Fixed duplicate posts double value problem
105
+ * API update: get_field($repeater) will return an array of values in order, or false (like it used to!)
106
+ * Radio Button: added labels around values
107
+ * Post object + Page Link: select drop down is now hierarchal
108
+ * Input save errors fixed
109
+ * Add 'return_id' option to get_field / get_sub_field
110
+ * Many bug fixes
111
+
112
  = 2.1.3 =
113
  * Fixed API returning true for repeater fields with no data
114
  * Added get_fields back into the api!
115
  * Fixed field type select from showing multiple repeater activation messages
116
 
 
117
  = 2.1.2 =
118
  * Fixed repeater sortable bug on options page
119
  * Fixed wysiwyg image insert on options page
260
 
261
  = 1.0.0 =
262
  * Advanced Custom Fields.
263
+
264
+
265
+ == Upgrade Notice ==
266
+
267
+ = 2.1.4 =
268
+ * Adds post_id column back into acf_values
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file