Advanced Custom Fields - Version 4.0.0

Version Description

  • [Optimized] Optimize performance by removing heavy class structure and implementing light weight hooks & filters!
  • [Changed] Remove all Add-on code from the core plugin and separate into individual plugins with self hosted updates
  • [Added] Add field 'Taxonomy'
  • [Added] Add field 'User'
  • [Added] Add field 'Email'
  • [Added] Add field 'Password'
  • [Added] Add field group title validation
  • [Fixed] Fix issue where get_field_object returns the wrong field when using WPML
  • [Fixed] Fix duplicate functionality - http://support.advancedcustomfields.com/discussion/4471/duplicate-fields-in-admin-doesn039t-replicate-repeater-fields
  • [Added] Add conditional statements to tab field - http://support.advancedcustomfields.com/discussion/4674/conditional-tabs
  • [Fixed] Fix issue with Preview / Draft where preview would not save custom field data - http://support.advancedcustomfields.com/discussion/4401/cannot-preview-or-schedule-content-to-be-published
  • [Added] Add function get_field_groups()
  • [Added] Add function delete_field() - http://support.advancedcustomfields.com/discussion/4788/deleting-a-field-through-php
  • [Added] Add get_sub_field_object function - http://support.advancedcustomfields.com/discussion/4991/select-inside-repeaterfield
  • [Added] Add 'Top Level' option to page type location rule
  • [Fixed] Fix taxonomy location rule - http://support.advancedcustomfields.com/discussion/5004/field-group-rules-issue
  • [Fixed] Fix tab field with conditional logic - https://github.com/elliotcondon/acf4/issues/14
  • [Fixed] Revert back to original field_key idea. attractive field key's cause too many issues with import / export
  • [Added] Add message field - http://support.advancedcustomfields.com/discussion/5263/additional-description-field
  • [Removed] Removed the_content filter from WYSIWYG field
Download this release

Release Info

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

Code changes from version 3.5.8 to 4.0.0

Files changed (69) hide show
  1. README.md +57 -0
  2. acf.php +386 -1343
  3. core/actions/export.php +8 -7
  4. core/api.php +709 -420
  5. core/controllers/addons.php +227 -0
  6. core/controllers/everything_fields.php +234 -146
  7. core/controllers/export.php +544 -0
  8. core/controllers/field_group.php +343 -180
  9. core/controllers/field_groups.php +185 -53
  10. core/controllers/input.php +184 -288
  11. core/controllers/location.php +50 -29
  12. core/controllers/options_page.php +0 -318
  13. core/controllers/settings.php +0 -684
  14. core/controllers/third_party.php +36 -81
  15. core/controllers/upgrade.php +26 -35
  16. core/fields/_base.php +135 -0
  17. core/fields/_functions.php +574 -0
  18. core/fields/acf_field.php +0 -313
  19. core/fields/checkbox.php +62 -53
  20. core/fields/color_picker.php +61 -53
  21. core/fields/date_picker/date_picker.php +77 -57
  22. core/fields/dummy.php +279 -0
  23. core/fields/email.php +92 -0
  24. core/fields/file.php +223 -209
  25. core/fields/flexible_content.php +0 -952
  26. core/fields/gallery.php +0 -796
  27. core/fields/image.php +236 -216
  28. core/fields/message.php +94 -0
  29. core/fields/number.php +59 -44
  30. core/fields/page_link.php +131 -118
  31. core/fields/password.php +48 -0
  32. core/fields/post_object.php +157 -143
  33. core/fields/radio.php +65 -62
  34. core/fields/relationship.php +171 -151
  35. core/fields/repeater.php +0 -820
  36. core/fields/select.php +205 -199
  37. core/fields/tab.php +42 -32
  38. core/fields/taxonomy.php +480 -0
  39. core/fields/text.php +107 -86
  40. core/fields/textarea.php +104 -87
  41. core/fields/true_false.php +70 -55
  42. core/fields/user.php +312 -0
  43. core/fields/wysiwyg.php +168 -183
  44. core/views/meta_box_fields.php +42 -38
  45. core/views/meta_box_location.php +7 -5
  46. core/views/meta_box_options.php +1 -1
  47. css/acf.css +175 -48
  48. css/field-group.css +23 -53
  49. css/global.css +57 -3
  50. css/input.css +51 -616
  51. images/add-ons/flexible-content-field-thumb.jpg +0 -0
  52. images/add-ons/gallery-field-thumb.jpg +0 -0
  53. images/add-ons/options-page-thumb.jpg +0 -0
  54. images/add-ons/repeater-field-thumb.jpg +0 -0
  55. images/sprite.png +0 -0
  56. images/sprite@2x.png +0 -0
  57. js/field-group.js +166 -332
  58. js/input.php +0 -3
  59. js/input/actions.js +38 -27
  60. js/input/ajax.js +6 -4
  61. js/input/flexible-content.js +0 -261
  62. js/input/gallery.js +0 -530
  63. js/input/image.js +3 -3
  64. js/input/relationship.js +34 -19
  65. js/input/repeater.js +0 -388
  66. js/input/tab.js +10 -9
  67. js/input/validation.js +2 -1
  68. js/input/wysiwyg.js +5 -6
  69. readme.txt +45 -30
README.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Advanced Custom Fields v4.0 Beta
2
+
3
+ Welcome to the beta repository for Advanced Custom Fields v4.0.
4
+ This repository will be temporarily available for beta testing, issue reporting and bug fixing. Once the v4.0 plugin is ready, this repository will be removed and all code will be available on the WordPress.org website as per usual.
5
+
6
+
7
+ -----------------------
8
+
9
+ ### Overview
10
+
11
+ Since the recent change of WP's terms and conditions regarding hosting of plugins, the ACF plugin has undergone some BIG changes to adhere to the new rules.
12
+ The problem is that ACF includes the 'Premium' code inside the free hosted plugin. All 'Add-on' code has been taken out of the core plugin, and replaced with seperate plugins for each of the 4 add-ons.
13
+
14
+ During this proccess, the entire plugin has been re written to use actions and filters instead of nested class structures. Hopefuly, as a result, we will see some Performance increases from both PHP and SQL!
15
+
16
+
17
+ ### Where are the Add-ons?
18
+
19
+ The add-ons are currently not available for download, however, over the next few days a new page will appear on the ACF website where you can enter your activation code / login to your account and download the add-on files.
20
+
21
+ Each add-on is now a plugin which will pull updates from the ACF website. Each plugin has also been writen to allow for theme inclusion! Meaning, you don't need to install the plugin, you can simply include it in your functions.php file. Doing this, however, will prevent any plugin updates.
22
+
23
+
24
+ ### Participate in Testing
25
+
26
+ If you have the time, please participate in this beta testing. The more developers we can get, the quicker this new version can be released!
27
+ Please report all issues related to this beta version here on github, not on the ACF support forum.
28
+
29
+
30
+ ### New Featues
31
+ * [Optimized] Optimize performance by removing heavy class structure and implementing light weight hooks & filters!
32
+ * [Fixed] Fix issue with Preview / Draft where preview would not save custom field data - http://support.advancedcustomfields.com/discussion/4401/cannot-preview-or-schedule-content-to-be-published
33
+ * [Changed] Remove all Add-on code from the core plugin and separate into individual plugins with self hosted updates
34
+ * [Added] Add field group title validation
35
+ * [Fixed] Fix WPML issue where get_field_object / get_field find the wrong field
36
+ * [Fixed] Fix duplicate functionality - http://support.advancedcustomfields.com/discussion/4471/duplicate-fields-in-admin-doesn039t-replicate-repeater-fields
37
+ * [Added] Add conditional statements to tab field - http://support.advancedcustomfields.com/discussion/4674/conditional-tabs
38
+ * [Improved] Improved creating / registering a custom field - Need to ad documnetation - For now, please look at the core/fields/dummy.php file and see how a field is made!
39
+ * [Added] Add new Hooks / Filter - Need to add documnetation
40
+
41
+
42
+ ### Download Add-Ons
43
+ You can now download your purchased Add-ons here: http://www.advancedcustomfields.com/add-ons-download/
44
+
45
+
46
+ ### Known Issues
47
+ * The register_field() function has been removed as there is a new way to create / regsiter your own field type. This means that all previously submitted add-ons will not work. I will help all developers re-make their add-ons for v4.
48
+ * No add-ons are included in the plugin - these will be released seperatly soon
49
+ * Export page is not yet available
50
+
51
+
52
+ ### Things to be improved
53
+ * Caching - Please feel free to offer any advice for caching in the plugin
54
+
55
+
56
+ ### Thank You
57
+ A BIG THANK YOU to everyone who can help assist in this new version!
acf.php CHANGED
@@ -2,41 +2,47 @@
2
  /*
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 powerful 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.5.8.2
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
10
  Copyright: Elliot Condon
11
  */
12
 
13
- include('core/api.php');
14
 
15
- $acf = new Acf();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  class Acf
18
  {
19
- var $dir,
20
- $path,
21
- $version,
22
- $upgrade_version,
23
- $fields,
24
- $cache,
25
- $defaults,
26
-
27
-
28
- // controllers
29
- $upgrade,
30
- $settings,
31
- $field_groups,
32
- $field_group,
33
- $input,
34
- $options_page,
35
- $everything_fields,
36
- $third_party,
37
- $location;
38
-
39
-
40
  /*
41
  * Constructor
42
  *
@@ -47,24 +53,17 @@ class Acf
47
 
48
  function __construct()
49
  {
 
 
 
 
 
50
  // vars
51
- $this->path = plugin_dir_path( __FILE__ );
52
- $this->dir = plugin_dir_url( __FILE__ );
53
- $this->version = '3.5.8.2';
54
- $this->upgrade_version = '3.4.1'; // this is the latest version which requires an upgrade
55
- $this->cache = array(); // basic array cache to hold data throughout the page load
56
- $this->defaults = array(
57
- 'options_page' => array(
58
- 'capability' => 'edit_posts', // capability to view options page
59
- 'title' => __('Options','acf'), // title / menu name ('Site Options')
60
- 'pages' => array(), // an array of sub pages ('Header, Footer, Home, etc')
61
- ),
62
- 'activation_codes' => array(
63
- 'repeater' => '', // activation code for the repeater add-on (XXXX-XXXX-XXXX-XXXX)
64
- 'options_page' => '', // activation code for the options page add-on (XXXX-XXXX-XXXX-XXXX)
65
- 'flexible_content' => '', // activation code for the flexible content add-on (XXXX-XXXX-XXXX-XXXX)
66
- 'gallery' => '', // activation code for the gallery add-on (XXXX-XXXX-XXXX-XXXX)
67
- ),
68
  );
69
 
70
 
@@ -72,33 +71,173 @@ class Acf
72
  load_plugin_textdomain('acf', false, basename(dirname(__FILE__)).'/lang' );
73
 
74
 
75
- // controllers
76
- $this->setup_controllers();
77
-
78
-
79
  // actions
80
- add_action('init', array($this, 'init'));
81
- add_action('admin_menu', array($this,'admin_menu'));
82
- add_action('admin_head', array($this,'admin_head'));
83
- add_action('acf_save_post', array($this, 'acf_save_post'), 10); // save post, called from many places (api, input, everything, options)
84
 
85
 
86
- // action functions
87
- add_action('acf/create_field', array($this, 'create_field'), 1, 1);
88
- add_filter('acf/get_field_groups', array($this, 'get_field_groups'), 1, 1);
89
- //add_filter('acf/get_field', array($this, 'get_field'), 10, 1);
 
 
 
90
 
91
 
92
- // filters
93
- add_filter('acf_load_field', array($this, 'acf_load_field'), 1, 1);
94
- add_filter('post_updated_messages', array($this, 'post_updated_messages'));
95
- add_filter('acf_parse_value', array($this, 'acf_parse_value'));
 
 
 
96
 
97
 
98
  return true;
99
  }
100
 
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  /*
103
  * Init
104
  *
@@ -109,18 +248,7 @@ class Acf
109
 
110
  function init()
111
  {
112
- // setup defaults
113
- $this->defaults = apply_filters('acf_settings', $this->defaults);
114
-
115
-
116
- // allow for older filters
117
- $this->defaults['options_page']['title'] = apply_filters('acf_options_page_title', $this->defaults['options_page']['title']);
118
 
119
-
120
- // setup fields
121
- $this->setup_fields();
122
-
123
-
124
  // Create ACF post type
125
  $labels = array(
126
  'name' => __( 'Field Groups', 'acf' ),
@@ -135,7 +263,6 @@ class Acf
135
  'not_found_in_trash' => __('No Field Groups found in Trash', 'acf'),
136
  );
137
 
138
-
139
  register_post_type('acf', array(
140
  'labels' => $labels,
141
  'public' => false,
@@ -153,234 +280,86 @@ class Acf
153
 
154
 
155
  // register acf scripts
156
- $scripts = array(
157
- 'acf-field-group' => $this->dir . 'js/field-group.js',
158
- 'acf-input' => $this->dir . 'js/input.php',
159
- 'acf-input-ajax' => $this->dir . 'js/input/ajax.js',
160
- 'acf-datepicker' => $this->dir . 'core/fields/date_picker/jquery.ui.datepicker.js',
161
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
 
163
- foreach( $scripts as $k => $v )
164
  {
165
- wp_register_script( $k, $v, array('jquery'), $this->version );
166
  }
167
 
168
 
169
  // register acf styles
170
  $styles = array(
171
- 'acf' => $this->dir . 'css/acf.css',
172
- 'acf-field-group' => $this->dir . 'css/field-group.css',
173
- 'acf-global' => $this->dir . 'css/global.css',
174
- 'acf-input' => $this->dir . 'css/input.css',
175
- 'acf-datepicker' => $this->dir . 'core/fields/date_picker/style.date_picker.css',
176
  );
177
 
178
  foreach( $styles as $k => $v )
179
  {
180
- wp_register_style( $k, $v, false, $this->version );
181
  }
182
 
183
 
184
- }
185
-
186
-
187
- /*
188
- * get_cache
189
- *
190
- * @description: Simple ACF (once per page) cache
191
- * @since 3.1.9
192
- * @created: 23/06/12
193
- */
194
-
195
- function get_cache($key = false)
196
- {
197
- // key is required
198
- if( !$key )
199
- return false;
200
-
201
-
202
- // does cache at key exist?
203
- if( !isset($this->cache[$key]) )
204
- return false;
205
-
206
-
207
- // return cahced item
208
- return $this->cache[$key];
209
- }
210
-
211
-
212
- /*
213
- * set_cache
214
- *
215
- * @description: Simple ACF (once per page) cache
216
- * @since 3.1.9
217
- * @created: 23/06/12
218
- */
219
-
220
- function set_cache($key = false, $value = null)
221
- {
222
- // key is required
223
- if( !$key )
224
- return false;
225
-
226
-
227
- // update the cache array
228
- $this->cache[$key] = $value;
229
-
230
 
231
- // return true. Probably not needed
232
- return true;
233
- }
234
-
235
-
236
- /*
237
- * setup_fields
238
- *
239
- * @description: Create an array of field objects, including custom registered field types
240
- * @since 1.0.0
241
- * @created: 23/06/12
242
- */
243
-
244
- function setup_fields()
245
- {
246
- // include parent field
247
- include_once('core/fields/acf_field.php');
248
-
249
-
250
- // include child fields
251
- include_once('core/fields/acf_field.php');
252
- include_once('core/fields/tab.php');
253
  include_once('core/fields/text.php');
254
  include_once('core/fields/textarea.php');
 
 
 
 
255
  include_once('core/fields/wysiwyg.php');
256
  include_once('core/fields/image.php');
257
  include_once('core/fields/file.php');
258
- include_once('core/fields/number.php');
259
  include_once('core/fields/select.php');
260
  include_once('core/fields/checkbox.php');
261
  include_once('core/fields/radio.php');
262
  include_once('core/fields/true_false.php');
 
263
  include_once('core/fields/page_link.php');
264
  include_once('core/fields/post_object.php');
265
  include_once('core/fields/relationship.php');
 
 
 
266
  include_once('core/fields/date_picker/date_picker.php');
267
  include_once('core/fields/color_picker.php');
268
 
269
-
270
- // add child fields
271
- $this->fields['none'] = new acf_Field($this);
272
- $this->fields['tab'] = new acf_Tab($this);
273
- $this->fields['text'] = new acf_Text($this);
274
- $this->fields['textarea'] = new acf_Textarea($this);
275
- $this->fields['wysiwyg'] = new acf_Wysiwyg($this);
276
- $this->fields['image'] = new acf_Image($this);
277
- $this->fields['file'] = new acf_File($this);
278
- $this->fields['number'] = new acf_Number($this);
279
- $this->fields['select'] = new acf_Select($this);
280
- $this->fields['checkbox'] = new acf_Checkbox($this);
281
- $this->fields['radio'] = new acf_Radio($this);
282
- $this->fields['true_false'] = new acf_True_false($this);
283
- $this->fields['page_link'] = new acf_Page_link($this);
284
- $this->fields['post_object'] = new acf_Post_object($this);
285
- $this->fields['relationship'] = new acf_Relationship($this);
286
- $this->fields['date_picker'] = new acf_Date_picker($this);
287
- $this->fields['color_picker'] = new acf_Color_picker($this);
288
-
289
-
290
- // add repeater
291
- if($this->is_field_unlocked('repeater'))
292
- {
293
- include_once('core/fields/repeater.php');
294
- $this->fields['repeater'] = new acf_Repeater($this);
295
- }
296
-
297
-
298
- // add flexible content
299
- if($this->is_field_unlocked('flexible_content'))
300
- {
301
- include_once('core/fields/flexible_content.php');
302
- $this->fields['flexible_content'] = new acf_Flexible_content($this);
303
- }
304
-
305
-
306
- // add gallery
307
- if($this->is_field_unlocked('gallery'))
308
- {
309
- include_once('core/fields/gallery.php');
310
- $this->fields['gallery'] = new acf_Gallery($this);
311
- }
312
-
313
-
314
- // hook to load in third party fields
315
- $custom = apply_filters('acf_register_field',array());
316
- if(!empty($custom))
317
- {
318
- foreach($custom as $v)
319
- {
320
- //var_dump($v['url']);
321
- include($v['url']);
322
- $name = $v['class'];
323
- $custom_field = new $name($this);
324
- $this->fields[$custom_field->name] = $custom_field;
325
- }
326
- }
327
-
328
- }
329
-
330
-
331
- /*
332
- * setup_fields
333
- *
334
- * @description:
335
- * @since 3.2.6
336
- * @created: 23/06/12
337
- */
338
-
339
- function setup_controllers()
340
- {
341
- // Settings
342
- include_once('core/controllers/settings.php');
343
- $this->settings = new acf_settings($this);
344
-
345
-
346
- // upgrade
347
- include_once('core/controllers/upgrade.php');
348
- $this->upgrade = new acf_upgrade($this);
349
-
350
-
351
- // field_groups
352
- include_once('core/controllers/field_groups.php');
353
- $this->field_groups = new acf_field_groups($this);
354
-
355
-
356
- // field_group
357
- include_once('core/controllers/field_group.php');
358
- $this->field_group = new acf_field_group($this);
359
-
360
-
361
- // input
362
- include_once('core/controllers/input.php');
363
- $this->input = new acf_input($this);
364
-
365
-
366
- // options page
367
- include_once('core/controllers/options_page.php');
368
- $this->options_page = new acf_options_page($this);
369
-
370
-
371
- // everthing fields
372
- include_once('core/controllers/everything_fields.php');
373
- $this->everything_fields = new acf_everything_fields($this);
374
 
375
 
376
- // Third Party Compatibility
377
- include_once('core/controllers/third_party.php');
378
- $this->third_party = new acf_third_party($this);
379
 
380
 
381
- // Location
382
- include_once('core/controllers/location.php');
383
- $this->location = new acf_location($this);
384
  }
385
 
386
 
@@ -392,11 +371,9 @@ class Acf
392
  * @created: 23/06/12
393
  */
394
 
395
- function admin_menu() {
396
-
397
- // add acf page to options menu
398
  add_utility_page(__("Custom Fields",'acf'), __("Custom Fields",'acf'), 'manage_options', 'edit.php?post_type=acf');
399
-
400
  }
401
 
402
 
@@ -442,1030 +419,207 @@ class Acf
442
 
443
  function admin_head()
444
  {
445
- // hide upgrade page from nav
446
- echo '<style type="text/css">
447
- #adminmenu #toplevel_page_edit-post_type-acf a[href="edit.php?post_type=acf&page=acf-upgrade"]{ display:none; }
448
- #adminmenu #toplevel_page_edit-post_type-acf .wp-menu-image { background-position: 1px -33px; }
449
- #adminmenu #toplevel_page_edit-post_type-acf:hover .wp-menu-image,
450
- #adminmenu #toplevel_page_edit-post_type-acf.wp-menu-open .wp-menu-image { background-position: 1px -1px; }
451
- </style>';
 
452
  }
453
 
454
 
455
  /*
456
- * get_field_groups
457
  *
458
  * @description:
459
- * @since: 3.5.7
460
- * @created: 12/01/13
461
  */
462
 
463
- function get_field_groups( $return )
464
- {
465
- // return must be an array
466
- if( !is_array($return) )
467
- {
468
- $return = array();
469
- }
470
-
471
 
472
- // get acf's
473
- $result = get_posts(array(
474
- 'numberposts' => -1,
475
- 'post_type' => 'acf',
476
- 'orderby' => 'menu_order title',
477
- 'order' => 'asc',
478
- 'suppress_filters' => false,
479
- ));
480
-
481
 
482
- // populate acfs
483
- if($result)
484
  {
485
- foreach($result as $acf)
486
  {
487
- $return[] = array(
488
- 'id' => $acf->ID,
489
- 'title' => get_the_title($acf->ID),
490
- 'fields' => $this->get_acf_fields($acf->ID),
491
- 'location' => $this->get_acf_location($acf->ID),
492
- 'options' => $this->get_acf_options($acf->ID),
493
- 'menu_order' => $acf->menu_order,
494
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
495
  }
496
  }
497
 
498
- // hook to load in registered field groups
499
- //$return = apply_filters('acf_register_field_group', $return);
500
-
501
- return $return;
502
  }
503
 
504
 
505
- /*--------------------------------------------------------------------------------------
506
- *
507
- * get_acf_fields
508
- * - returns an array of fields for a acf object
509
  *
510
- * @author Elliot Condon
511
- * @since 1.0.0
512
- *
513
- *-------------------------------------------------------------------------------------*/
514
-
515
- function get_acf_fields($post_id)
516
  {
517
- // vars
518
- global $wpdb;
519
-
520
- $return = array();
521
-
522
 
523
- // get field from postmeta
524
- $rows = $wpdb->get_results( $wpdb->prepare("SELECT meta_key FROM $wpdb->postmeta WHERE post_id = %d AND meta_key LIKE %s", $post_id, 'field\_%'), ARRAY_A);
525
 
526
- if( $rows )
527
- {
528
- foreach( $rows as $row )
529
- {
530
- $field = $this->get_acf_field( $row['meta_key'], $post_id );
531
-
532
- $return[ $field['order_no'] ] = $field;
533
- }
534
-
535
- ksort($return);
536
- }
537
-
538
-
539
- // return
540
- return $return;
541
 
542
- }
543
-
544
-
545
- /*--------------------------------------------------------------------------------------
546
- *
547
- * get_acf_field
548
- * - returns a field
549
- * - $post_id can be passed to make sure the correct field is loaded. Eg: a duplicated
550
- * field group may have the same field_key, but a different post_id
551
- *
552
- * @author Elliot Condon
553
- * @since 1.0.0
554
- *
555
- *-------------------------------------------------------------------------------------*/
556
-
557
- function get_acf_field( $field_key, $post_id = false )
558
- {
559
-
560
-
561
- // return cache
562
- $cache = $this->get_cache('acf_field_' . $field_key);
563
- if($cache != false)
564
- {
565
- return $cache;
566
- }
567
-
568
-
569
- // vars
570
- global $wpdb;
571
-
572
-
573
- // get field from postmeta
574
- $sql = $wpdb->prepare("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s", $field_key);
575
-
576
- if( $post_id )
577
- {
578
- $sql .= $wpdb->prepare("AND post_id = %d", $post_id);
579
- }
580
-
581
- $row = $wpdb->get_results( $sql, ARRAY_A );
582
-
583
-
584
-
585
- if( $row )
586
- {
587
- $row = $row[0];
588
-
589
-
590
- // return field if it is not in a trashed field group
591
- if( get_post_status( $row['post_id'] ) != "trash" )
592
- {
593
- $row['meta_value'] = maybe_unserialize( $row['meta_value'] );
594
- $row['meta_value'] = maybe_unserialize( $row['meta_value'] ); // run again for WPML
595
-
596
-
597
- // store field
598
- $field = $row['meta_value'];
599
-
600
-
601
- // apply filters
602
- $field = apply_filters('acf_load_field', $field);
603
-
604
- $keys = array('type', 'name', 'key');
605
- foreach( $keys as $key )
606
- {
607
- if( isset($field[ $key ]) )
608
- {
609
- $field = apply_filters('acf_load_field-' . $field[ $key ], $field);
610
- }
611
- }
612
-
613
-
614
- // set cache
615
- $this->set_cache('acf_field_' . $field_key, $field);
616
-
617
- return $field;
618
- }
619
- }
620
-
621
-
622
-
623
- // hook to load in registered field groups
624
- $acfs = apply_filters('acf/get_field_groups', false);
625
-
626
- if($acfs)
627
- {
628
- // loop through acfs
629
- foreach($acfs as $acf)
630
- {
631
- // loop through fields
632
- if($acf['fields'])
633
- {
634
- foreach($acf['fields'] as $field)
635
- {
636
- if($field['key'] == $field_key)
637
- {
638
- // apply filters
639
- $field = apply_filters('acf_load_field', $field);
640
-
641
- $keys = array('type', 'name', 'key');
642
- foreach( $keys as $key )
643
- {
644
- if( isset($field[ $key ]) )
645
- {
646
- $field = apply_filters('acf_load_field-' . $field[ $key ], $field);
647
- }
648
- }
649
-
650
-
651
- // set cache
652
- $this->set_cache('acf_field_' . $field_key, $field);
653
-
654
- return $field;
655
- }
656
- }
657
- }
658
- // if($acf['fields'])
659
- }
660
- // foreach($acfs as $acf)
661
- }
662
- // if($acfs)
663
-
664
-
665
- return null;
666
- }
667
-
668
-
669
- /*
670
- * acf_load_field
671
- *
672
- * @description:
673
- * @since 3.5.1
674
- * @created: 14/10/12
675
- */
676
-
677
- function acf_load_field( $field )
678
- {
679
- if( !is_array($field) )
680
- {
681
- return $field;
682
- }
683
-
684
- $defaults = array(
685
- 'key' => '',
686
- 'label' => '',
687
- 'name' => '',
688
- 'type' => 'text',
689
- 'order_no' => 1,
690
- 'instructions' => '',
691
- 'required' => 0,
692
- 'conditional_logic' => array(
693
- 'status' => 0,
694
- 'allorany' => 'all',
695
- 'rules' => 0
696
- ),
697
- );
698
-
699
- $field = array_merge($defaults, $field);
700
-
701
-
702
- // Parse Values
703
- $field = apply_filters( 'acf_parse_value', $field );
704
-
705
-
706
- // trim name
707
- $field['name'] = trim( $field['name'] );
708
-
709
-
710
- return $field;
711
- }
712
-
713
-
714
- /*
715
- * acf_parse_value
716
- *
717
- * @description:
718
- * @since: 2.0.4
719
- * @created: 9/12/12
720
- */
721
-
722
- function acf_parse_value( $value )
723
- {
724
-
725
- // is value another array?
726
- if( is_array($value) )
727
- {
728
- foreach( $value as $k => $v )
729
- {
730
- $value[ $k ] = apply_filters( 'acf_parse_value', $v );
731
- }
732
- }
733
- else
734
- {
735
- // numbers
736
- if( is_numeric($value) )
737
- {
738
- // float / int
739
- if( strpos($value,'.') !== false )
740
- {
741
- $value = floatval( $value );
742
- }
743
- else
744
- {
745
- $value = intval( $value );
746
- }
747
- }
748
- }
749
-
750
-
751
- // return
752
- return $value;
753
- }
754
-
755
-
756
- /*--------------------------------------------------------------------------------------
757
- *
758
- * create_field
759
- *
760
- * @author Elliot Condon
761
- * @since 1.0.0
762
- *
763
- *-------------------------------------------------------------------------------------*/
764
-
765
- function create_field($field)
766
- {
767
-
768
- if(!isset($this->fields[$field['type']]) || !is_object($this->fields[$field['type']]))
769
- {
770
- _e('Error: Field Type does not exist!','acf');
771
- return false;
772
- }
773
-
774
-
775
- // defaults - class
776
- if( ! isset($field['class']) )
777
- {
778
- $field['class'] = $field['type'];
779
- }
780
-
781
-
782
- // defaults - id
783
- if( ! isset($field['id']) )
784
- {
785
- $id = $field['name'];
786
- $id = str_replace('][', '_', $id);
787
- $id = str_replace('fields[', '', $id);
788
- $id = str_replace('[', '-', $id); // location rules (select) does'nt have "fields[" in it
789
- $id = str_replace(']', '', $id);
790
-
791
-
792
- $field['id'] = 'acf-' . $id;
793
- }
794
-
795
-
796
- $this->fields[ $field['type'] ]->create_field($field);
797
-
798
-
799
- // conditional logic
800
- // - isset is needed for the edit field group page where fields are created without many parameters
801
- if( isset($field['conditional_logic']['status']) && $field['conditional_logic']['status'] ):
802
-
803
- $join = ' && ';
804
- if( $field['conditional_logic']['allorany'] == "any" )
805
- {
806
- $join = ' || ';
807
- }
808
-
809
- ?>
810
- <script type="text/javascript">
811
- (function($){
812
-
813
- // create the conditional function
814
- $(document).live('acf/conditional_logic/<?php echo $field['key']; ?>', function(){
815
-
816
- var field = $('.field-<?php echo $field['key']; ?>');
817
- <?php
818
-
819
- $if = array();
820
- foreach( $field['conditional_logic']['rules'] as $rule )
821
- {
822
- $if[] = 'acf.conditional_logic.calculate({ field : "'. $field['key'] .'", toggle : "' . $rule['field'] . '", operator : "' . $rule['operator'] .'", value : "' . $rule['value'] . '"})' ;
823
- }
824
-
825
- ?>
826
- if(<?php echo implode( $join, $if ); ?>)
827
- {
828
- field.removeClass('acf-conditional_logic-hide').addClass('acf-conditional_logic-show');
829
- }
830
- else
831
- {
832
- field.removeClass('acf-conditional_logic-show').addClass('acf-conditional_logic-hide');
833
- }
834
-
835
- });
836
-
837
-
838
- // add change events to all fields
839
- <?php
840
-
841
- $already_added = array();
842
-
843
- foreach( $field['conditional_logic']['rules'] as $rule ):
844
-
845
- if( in_array( $rule['field'], $already_added) )
846
- {
847
- continue;
848
- }
849
- else
850
- {
851
- $already_added[] = $rule['field'];
852
- }
853
-
854
- ?>
855
- $('.field-<?php echo $rule['field']; ?> *[name]').live('change', function(){
856
- $(document).trigger('acf/conditional_logic/<?php echo $field['key']; ?>');
857
- });
858
- <?php endforeach; ?>
859
-
860
- $(document).live('acf/setup_fields', function(e, postbox){
861
- $(document).trigger('acf/conditional_logic/<?php echo $field['key']; ?>');
862
- });
863
-
864
- })(jQuery);
865
- </script>
866
- <?php
867
- endif;
868
- }
869
-
870
-
871
- /*--------------------------------------------------------------------------------------
872
- *
873
- * get_acf_location
874
- *
875
- * @author Elliot Condon
876
- * @since 1.0.0
877
- *
878
- *-------------------------------------------------------------------------------------*/
879
-
880
- function get_acf_location($post_id)
881
- {
882
- // defaults
883
- $return = array(
884
- 'rules' => array(),
885
- 'allorany' => 'all',
886
- );
887
-
888
-
889
- // vars
890
- $allorany = get_post_meta($post_id, 'allorany', true);
891
- if( $allorany )
892
- {
893
- $return['allorany'] = $allorany;
894
- }
895
-
896
-
897
- // get all fields
898
- $rules = get_post_meta($post_id, 'rule', false);
899
-
900
-
901
- if($rules)
902
- {
903
-
904
- foreach($rules as $rule)
905
- {
906
- // if field group was duplicated, it may now be a serialized string!
907
- $rule = maybe_unserialize($rule);
908
-
909
-
910
- $return['rules'][$rule['order_no']] = $rule;
911
- }
912
- }
913
-
914
-
915
- // sort
916
- ksort($return['rules']);
917
-
918
-
919
- // return fields
920
- return $return;
921
-
922
- }
923
-
924
-
925
- /*--------------------------------------------------------------------------------------
926
- *
927
- * get_acf_options
928
- *
929
- * @author Elliot Condon
930
- * @since 1.0.0
931
- *
932
- *-------------------------------------------------------------------------------------*/
933
-
934
- function get_acf_options($post_id)
935
- {
936
-
937
- // defaults
938
- $options = array(
939
- 'position' => 'normal',
940
- 'layout' => 'no_box',
941
- 'hide_on_screen' => array(),
942
- );
943
-
944
-
945
- // vars
946
- $position = get_post_meta($post_id, 'position', true);
947
- if( $position )
948
- {
949
- $options['position'] = $position;
950
- }
951
-
952
- $layout = get_post_meta($post_id, 'layout', true);
953
- if( $layout )
954
- {
955
- $options['layout'] = $layout;
956
- }
957
-
958
- $hide_on_screen = get_post_meta($post_id, 'hide_on_screen', true);
959
- if( $hide_on_screen )
960
- {
961
- $hide_on_screen = maybe_unserialize($hide_on_screen);
962
- $options['hide_on_screen'] = $hide_on_screen;
963
- }
964
-
965
-
966
- // return
967
- return $options;
968
- }
969
-
970
-
971
-
972
- /*--------------------------------------------------------------------------------------
973
- *
974
- * get_value
975
- *
976
- * @author Elliot Condon
977
- * @since 3.0.0
978
- *
979
- *-------------------------------------------------------------------------------------*/
980
-
981
- function get_value($post_id, $field)
982
- {
983
- if( empty($this->fields) )
984
- {
985
- $this->setup_fields();
986
- }
987
-
988
- if( !isset($field['type'], $this->fields[ $field['type'] ]) )
989
- {
990
- return false;
991
- }
992
-
993
- return $this->fields[$field['type']]->get_value($post_id, $field);
994
- }
995
-
996
-
997
- /*--------------------------------------------------------------------------------------
998
- *
999
- * get_value_for_api
1000
- *
1001
- * @author Elliot Condon
1002
- * @since 3.0.0
1003
- *
1004
- *-------------------------------------------------------------------------------------*/
1005
-
1006
- function get_value_for_api($post_id, $field)
1007
- {
1008
- if( empty($this->fields) )
1009
- {
1010
- $this->setup_fields();
1011
- }
1012
-
1013
- if( !isset($field['type'], $this->fields[ $field['type'] ]) )
1014
- {
1015
- return false;
1016
- }
1017
-
1018
- return $this->fields[$field['type']]->get_value_for_api($post_id, $field);
1019
- }
1020
-
1021
-
1022
- /*--------------------------------------------------------------------------------------
1023
- *
1024
- * update_value
1025
- *
1026
- * @author Elliot Condon
1027
- * @since 3.0.0
1028
- *
1029
- *-------------------------------------------------------------------------------------*/
1030
-
1031
- function update_value($post_id, $field, $value)
1032
- {
1033
- if( isset($field['type'], $this->fields[ $field['type'] ]) )
1034
- {
1035
- $this->fields[$field['type']]->update_value($post_id, $field, $value);
1036
- }
1037
- }
1038
-
1039
-
1040
- /*--------------------------------------------------------------------------------------
1041
- *
1042
- * update_field
1043
- *
1044
- * @author Elliot Condon
1045
- * @since 3.0.0
1046
- *
1047
- *-------------------------------------------------------------------------------------*/
1048
-
1049
- function update_field($post_id, $field)
1050
- {
1051
- // apply filters
1052
- $field = apply_filters('acf_save_field', $field );
1053
- $field = apply_filters('acf_save_field-' . $field['type'], $field );
1054
-
1055
-
1056
- // save
1057
- update_post_meta($post_id, $field['key'], $field);
1058
- }
1059
-
1060
-
1061
- /*--------------------------------------------------------------------------------------
1062
- *
1063
- * format_value_for_api
1064
- *
1065
- * @author Elliot Condon
1066
- * @since 3.0.0
1067
- *
1068
- *-------------------------------------------------------------------------------------*/
1069
-
1070
- function format_value_for_api($value, $field)
1071
- {
1072
- return $this->fields[$field['type']]->format_value_for_api($value, $field);
1073
- }
1074
-
1075
-
1076
- /*--------------------------------------------------------------------------------------
1077
- *
1078
- * create_format_data
1079
- *
1080
- * @author Elliot Condon
1081
- * @since 3.0.0
1082
- *
1083
- *-------------------------------------------------------------------------------------*/
1084
-
1085
- function create_format_data($field)
1086
- {
1087
- return $this->fields[$field['type']]->create_format_data($field);
1088
- }
1089
-
1090
-
1091
- /*
1092
- * render_fields_for_input
1093
- *
1094
- * @description:
1095
- * @since 3.1.6
1096
- * @created: 23/06/12
1097
- */
1098
-
1099
- function render_fields_for_input($fields, $post_id)
1100
- {
1101
-
1102
- // create fields
1103
- if($fields)
1104
- {
1105
- foreach($fields as $field)
1106
- {
1107
- // if they didn't select a type, skip this field
1108
- if(!$field['type'] || $field['type'] == 'null') continue;
1109
-
1110
-
1111
- // set value
1112
- if( ! isset($field['value']) )
1113
- {
1114
- $field['value'] = $this->get_value($post_id, $field);
1115
- }
1116
-
1117
-
1118
- $required_class = "";
1119
- $required_label = "";
1120
-
1121
- if( $field['required'] )
1122
- {
1123
- $required_class = ' required';
1124
- $required_label = ' <span class="required">*</span>';
1125
- }
1126
-
1127
- echo '<div id="acf-' . $field['name'] . '" class="field field-' . $field['type'] . ' field-' . $field['key'] . $required_class . '" data-field_name="' . $field['name'] . '" data-field_key="' . $field['key'] . '">';
1128
-
1129
- echo '<p class="label">';
1130
- echo '<label for="fields[' . $field['key'] . ']">' . $field['label'] . $required_label . '</label>';
1131
- echo $field['instructions'];
1132
- echo '</p>';
1133
-
1134
- $field['name'] = 'fields[' . $field['key'] . ']';
1135
- $this->create_field($field);
1136
-
1137
- echo '</div>';
1138
-
1139
- }
1140
- // foreach($fields as $field)
1141
- }
1142
- // if($fields)
1143
-
1144
- }
1145
-
1146
-
1147
- /*--------------------------------------------------------------------------------------
1148
- *
1149
- * get_input_metabox_ids
1150
- * - called by function.fields to hide / show metaboxes
1151
- *
1152
- * @author Elliot Condon
1153
- * @since 2.0.5
1154
- *
1155
- *-------------------------------------------------------------------------------------*/
1156
-
1157
- function get_input_metabox_ids( $options = array() )
1158
- {
1159
- // vars
1160
- $defaults = array(
1161
- 'post_id' => 0,
1162
- 'post_type' => 0,
1163
- 'page_template' => 0,
1164
- 'page_parent' => 0,
1165
- 'page_type' => 0,
1166
- 'page' => 0,
1167
- 'post' => 0,
1168
- 'post_category' => 0,
1169
- 'post_format' => 0,
1170
- 'taxonomy' => 0,
1171
- 'lang' => 0,
1172
- 'return' => 'php'
1173
- );
1174
-
1175
-
1176
- // merge in $options
1177
- $options = array_merge($defaults, $options);
1178
-
1179
-
1180
- // merge in $_POST
1181
- if( isset($_POST) )
1182
- {
1183
- $options = array_merge($options, $_POST);
1184
- }
1185
-
1186
-
1187
- // Parse values
1188
- $options = apply_filters( 'acf_parse_value', $options );
1189
-
1190
-
1191
- // WPML
1192
- if( $options['lang'] )
1193
- {
1194
- global $sitepress;
1195
- $sitepress->switch_lang( $options['lang'] );
1196
- }
1197
-
1198
-
1199
- // find all acf objects
1200
- $acfs = apply_filters('acf/get_field_groups', false);
1201
-
1202
-
1203
- // blank array to hold acfs
1204
- $return = array();
1205
-
1206
-
1207
- if( $acfs )
1208
- {
1209
- foreach( $acfs as $acf )
1210
- {
1211
- // vars
1212
- $add_box = false;
1213
-
1214
-
1215
- // if all of the rules are required to match, start at true and let any !$match set $add_box to false
1216
- if( $acf['location']['allorany'] == 'all' )
1217
- {
1218
- $add_box = true;
1219
- }
1220
-
1221
-
1222
- if( $acf['location']['rules'] )
1223
- {
1224
- // defaults
1225
- $rule_defaults = array(
1226
- 'param' => '',
1227
- 'operator' => '==',
1228
- 'value' => ''
1229
- );
1230
-
1231
- foreach($acf['location']['rules'] as $rule)
1232
- {
1233
- // make sure rule has all 3 keys
1234
- $rule = array_merge( $rule_defaults, $rule );
1235
-
1236
-
1237
- // $match = true / false
1238
- $match = false;
1239
- $match = apply_filters( 'acf/location_rules/match/' . $rule['param'] , $match, $rule, $options );
1240
-
1241
-
1242
- if( $acf['location']['allorany'] == 'all' && !$match )
1243
- {
1244
- // if all of the rules are required to match and this rule did not, don't add this box!
1245
- $add_box = false;
1246
- }
1247
- elseif($acf['location']['allorany'] == 'any' && $match )
1248
- {
1249
- // if any of the rules are required to match and this rule did, add this box!
1250
- $add_box = true;
1251
- }
1252
-
1253
-
1254
- }
1255
- }
1256
-
1257
-
1258
- // add ID to array
1259
- if( $add_box )
1260
- {
1261
- $return[] = $acf['id'];
1262
- }
1263
-
1264
  }
1265
  }
1266
 
1267
 
1268
- // if json
1269
- if( $options['return'] == 'json' )
1270
- {
1271
- echo json_encode($return);
1272
- die;
1273
- }
1274
-
1275
-
1276
- // not json, normal return
1277
- return $return;
1278
-
1279
- }
1280
-
1281
-
1282
- /*--------------------------------------------------------------------------------------
1283
- *
1284
- * is_field_unlocked
1285
- *
1286
- * @author Elliot Condon
1287
- * @since 3.0.0
1288
- *
1289
- *-------------------------------------------------------------------------------------*/
1290
-
1291
- function is_field_unlocked($field_name)
1292
- {
1293
- $hashes = array(
1294
- 'repeater' => 'bbefed143f1ec106ff3a11437bd73432',
1295
- 'options_page' => '1fc8b993548891dc2b9a63ac057935d8',
1296
- 'flexible_content' => 'd067e06c2b4b32b1c1f5b6f00e0d61d6',
1297
- 'gallery' => '69f4adc9883195bd206a868ffa954b49',
1298
- );
1299
-
1300
- $hash = md5( $this->get_license_key($field_name) );
1301
-
1302
- if( $hashes[$field_name] == $hash )
1303
- {
1304
- return true;
1305
- }
1306
-
1307
- return false;
1308
-
1309
- }
1310
-
1311
- /*--------------------------------------------------------------------------------------
1312
- *
1313
- * is_field_unlocked
1314
- *
1315
- * @author Elliot Condon
1316
- * @since 3.0.0
1317
- *
1318
- *-------------------------------------------------------------------------------------*/
1319
-
1320
- function get_license_key($field_name)
1321
- {
1322
- $value = '';
1323
-
1324
- if( isset( $this->defaults['activation_codes'][ $field_name ] ) )
1325
- {
1326
- $value = $this->defaults['activation_codes'][ $field_name ];
1327
- }
1328
-
1329
- if( !$value )
1330
  {
1331
- $value = get_option('acf_' . $field_name . '_ac');
1332
  }
1333
-
1334
- return $value;
1335
- }
1336
-
1337
-
1338
- /*--------------------------------------------------------------------------------------
1339
- *
1340
- * admin_message
1341
- *
1342
- * @author Elliot Condon
1343
- * @since 2.0.5
1344
- *
1345
- *-------------------------------------------------------------------------------------*/
1346
-
1347
- function admin_message($message = "", $type = 'updated')
1348
- {
1349
- $GLOBALS['acf_mesage'] = $message;
1350
- $GLOBALS['acf_mesage_type'] = $type;
1351
-
1352
- add_action('admin_notices', array($this, 'acf_admin_notice'));
1353
- }
1354
-
1355
- function acf_admin_notice()
1356
- {
1357
- echo '<div class="' . $GLOBALS['acf_mesage_type'] . '" id="message">'.$GLOBALS['acf_mesage'].'</div>';
1358
- }
1359
-
1360
-
1361
-
1362
- /*--------------------------------------------------------------------------------------
1363
- *
1364
- * get_taxonomies_for_select
1365
- *
1366
- *---------------------------------------------------------------------------------------
1367
- *
1368
- * returns a multidimentional array of taxonomies grouped by the post type / taxonomy
1369
- *
1370
- * @author Elliot Condon
1371
- * @since 3.0.2
1372
- *
1373
- *-------------------------------------------------------------------------------------*/
1374
-
1375
- function get_taxonomies_for_select( $args = array() )
1376
- {
1377
- // vars
1378
- $post_types = get_post_types();
1379
- $choices = array();
1380
- $defaults = array(
1381
- 'simple_value' => false,
1382
- );
1383
-
1384
- $options = array_merge($defaults, $args);
1385
 
1386
 
1387
- if($post_types)
1388
- {
1389
- foreach($post_types as $post_type)
1390
- {
1391
- $post_type_object = get_post_type_object($post_type);
1392
- $taxonomies = get_object_taxonomies($post_type);
1393
- if($taxonomies)
1394
- {
1395
- foreach($taxonomies as $taxonomy)
1396
- {
1397
- if(!is_taxonomy_hierarchical($taxonomy)) continue;
1398
- $terms = get_terms($taxonomy, array('hide_empty' => false));
1399
- if($terms)
1400
- {
1401
- foreach($terms as $term)
1402
- {
1403
- $value = $taxonomy . ':' . $term->term_id;
1404
-
1405
- if( $options['simple_value'] )
1406
- {
1407
- $value = $term->term_id;
1408
- }
1409
-
1410
- $choices[$post_type_object->label . ': ' . $taxonomy][$value] = $term->name;
1411
- }
1412
- }
1413
- }
1414
- }
1415
- }
1416
- }
1417
 
1418
- return $choices;
1419
  }
1420
 
1421
 
1422
-
1423
  /*
1424
- * get_all_image_sizes
1425
  *
1426
  * @description: returns an array holding all the image sizes
1427
  * @since 3.2.8
1428
  * @created: 6/07/12
1429
  */
1430
 
1431
- function get_all_image_sizes()
1432
  {
1433
  // find all sizes
1434
  $all_sizes = get_intermediate_image_sizes();
1435
 
1436
 
1437
  // define default sizes
1438
- $image_sizes = array(
1439
  'thumbnail' => __("Thumbnail",'acf'),
1440
  'medium' => __("Medium",'acf'),
1441
  'large' => __("Large",'acf'),
1442
  'full' => __("Full",'acf')
1443
- );
1444
 
1445
 
1446
  // add extra registered sizes
1447
- foreach($all_sizes as $size)
1448
  {
1449
- if (!isset($image_sizes[$size]))
1450
  {
1451
- $image_sizes[$size] = ucwords( str_replace('-', ' ', $size) );
1452
  }
1453
  }
1454
 
1455
 
1456
  // return array
1457
- return $image_sizes;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1458
  }
1459
 
1460
 
1461
  /*
1462
- * acf_save_post
1463
  *
1464
  * @description:
1465
- * @created: 4/09/12
 
1466
  */
1467
 
1468
- function acf_save_post( $post_id )
1469
  {
1470
 
1471
  // load from post
@@ -1474,16 +628,21 @@ foreach( $field['conditional_logic']['rules'] as $rule ):
1474
  return false;
1475
  }
1476
 
1477
-
1478
  // loop through and save
1479
  if( $_POST['fields'] )
1480
  {
1481
  foreach( $_POST['fields'] as $key => $value )
1482
  {
 
 
 
1483
  // get field
1484
- $field = $this->get_acf_field($key);
 
 
 
1485
 
1486
- $this->update_value($post_id, $field, $value);
1487
  }
1488
  // foreach($fields as $key => $value)
1489
  }
@@ -1492,126 +651,10 @@ foreach( $field['conditional_logic']['rules'] as $rule ):
1492
 
1493
  return true;
1494
  }
1495
-
1496
-
1497
-
1498
- /*
1499
- * get_post_language
1500
- *
1501
- * @description: finds the translation code for a post
1502
- * @since 3.3.9
1503
- * @created: 17/08/12
1504
- */
1505
-
1506
- /*function get_post_language( $post )
1507
- {
1508
- // global
1509
- global $wpdb;
1510
 
1511
-
1512
- // vars
1513
- $table = $wpdb->prefix.'icl_translations';
1514
- $element_type = 'post_' . $post->post_type;
1515
- $element_id = $post->ID;
1516
-
1517
- $lang = $wpdb->get_var("SELECT language_code FROM $table WHERE element_type = '$element_type' AND element_id = '$element_id'");
1518
-
1519
- return ' (' . $lang . ')';
1520
- }*/
1521
-
1522
-
1523
- /*
1524
- * get_post_types
1525
- *
1526
- * @description:
1527
- * @since: 3.5.5
1528
- * @created: 16/12/12
1529
- */
1530
-
1531
- function get_post_types( $exclude = array(), $include = array() )
1532
- {
1533
- // get all custom post types
1534
- $post_types = get_post_types();
1535
-
1536
-
1537
- // core include / exclude
1538
- $acf_includes = array_merge( array(), $include );
1539
- $acf_excludes = array_merge( array( 'acf', 'revision', 'nav_menu_item' ), $exclude );
1540
-
1541
-
1542
- // include
1543
- foreach( $acf_includes as $p )
1544
- {
1545
- if( post_type_exists($p) )
1546
- {
1547
- $post_types[ $p ] = $p;
1548
- }
1549
- }
1550
-
1551
-
1552
- // exclude
1553
- foreach( $acf_excludes as $p )
1554
- {
1555
- unset( $post_types[ $p ] );
1556
- }
1557
-
1558
- return $post_types;
1559
-
1560
- }
1561
-
1562
-
1563
- /*
1564
- * get_next_field_id
1565
- *
1566
- * @description:
1567
- * @since: 3.5.5
1568
- * @created: 31/12/12
1569
- */
1570
-
1571
- function get_next_field_id()
1572
- {
1573
- // vars
1574
- global $wpdb;
1575
- $exists = true;
1576
-
1577
-
1578
- // get next id
1579
- $next_id = intval( get_option('acf_next_field_id', 1) );
1580
-
1581
-
1582
- // while doesnt exist
1583
- while( $exists == true )
1584
- {
1585
- // get field from postmeta
1586
- $row = $wpdb->get_row($wpdb->prepare(
1587
- "
1588
- SELECT meta_id
1589
- FROM $wpdb->postmeta
1590
- WHERE meta_key = %s
1591
- ",
1592
- 'field_' . $next_id
1593
- ), ARRAY_A );
1594
-
1595
-
1596
- // loop again or break through?
1597
- if( ! $row )
1598
- {
1599
- $exists = false;
1600
- }
1601
- else
1602
- {
1603
- $next_id++;
1604
- }
1605
- }
1606
-
1607
-
1608
- // update the acf_next_field_id
1609
- update_option('acf_next_field_id', ($next_id + 1) );
1610
-
1611
-
1612
- // return
1613
- return $next_id;
1614
- }
1615
 
1616
  }
 
 
 
1617
  ?>
2
  /*
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: 4.0.0
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
10
  Copyright: Elliot Condon
11
  */
12
 
 
13
 
14
+ // lite mode
15
+ if( !defined('ACF_LITE') )
16
+ {
17
+ define( 'ACF_LITE', false );
18
+ }
19
+
20
+
21
+ // API
22
+ include_once('core/api.php');
23
+
24
+
25
+ // controllers
26
+ include_once('core/controllers/field_groups.php');
27
+ include_once('core/controllers/field_group.php');
28
+ include_once('core/controllers/input.php');
29
+ include_once('core/controllers/location.php');
30
+
31
+ if( is_admin() && !ACF_LITE )
32
+ {
33
+ include_once('core/controllers/export.php');
34
+ include_once('core/controllers/addons.php');
35
+ include_once('core/controllers/third_party.php');
36
+ include_once('core/controllers/everything_fields.php');
37
+ include_once('core/controllers/upgrade.php');
38
+ }
39
+
40
 
41
  class Acf
42
  {
43
+ var $settings;
44
+
45
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  /*
47
  * Constructor
48
  *
53
 
54
  function __construct()
55
  {
56
+ // helpers
57
+ add_filter('acf/helpers/get_path', array($this, 'helpers_get_path'), 1, 1);
58
+ add_filter('acf/helpers/get_dir', array($this, 'helpers_get_dir'), 1, 1);
59
+
60
+
61
  // vars
62
+ $this->settings = array(
63
+ 'path' => apply_filters('acf/helpers/get_path', __FILE__),
64
+ 'dir' => apply_filters('acf/helpers/get_dir', __FILE__),
65
+ 'version' => '4.0.0',
66
+ 'upgrade_version' => '3.4.1',
 
 
 
 
 
 
 
 
 
 
 
 
67
  );
68
 
69
 
71
  load_plugin_textdomain('acf', false, basename(dirname(__FILE__)).'/lang' );
72
 
73
 
 
 
 
 
74
  // actions
75
+ add_action('init', array($this, 'init'), 1);
76
+ add_action('acf/save_post', array($this, 'save_post'), 10);
 
 
77
 
78
 
79
+ // filters
80
+ add_filter('acf/get_info', array($this, 'get_info'), 1, 1);
81
+ add_filter('acf/parse_types', array($this, 'parse_types'), 1, 1);
82
+ add_filter('acf/get_post_types', array($this, 'get_post_types'), 1, 3);
83
+ add_filter('acf/get_taxonomies_for_select', array($this, 'get_taxonomies_for_select'), 1, 2);
84
+ add_filter('acf/get_image_sizes', array($this, 'get_image_sizes'), 1, 1);
85
+ add_action('acf/create_fields', array($this, 'create_fields'), 1, 2);
86
 
87
 
88
+ // admin only
89
+ if( is_admin() && !ACF_LITE )
90
+ {
91
+ add_action('admin_menu', array($this,'admin_menu'));
92
+ add_action('admin_head', array($this,'admin_head'));
93
+ add_filter('post_updated_messages', array($this, 'post_updated_messages'));
94
+ }
95
 
96
 
97
  return true;
98
  }
99
 
100
 
101
+ /*
102
+ * helpers_get_path
103
+ *
104
+ * @description: calculates the path (works for plugin / theme folders)
105
+ * @since: 3.6
106
+ * @created: 30/01/13
107
+ */
108
+
109
+ function helpers_get_path( $file )
110
+ {
111
+ return trailingslashit(dirname($file));
112
+ }
113
+
114
+
115
+
116
+ /*
117
+ * helpers_get_dir
118
+ *
119
+ * @description: calculates the directory (works for plugin / theme folders)
120
+ * @since: 3.6
121
+ * @created: 30/01/13
122
+ */
123
+
124
+ function helpers_get_dir( $file )
125
+ {
126
+ $dir = trailingslashit(dirname($file));
127
+ $count = 0;
128
+
129
+
130
+ // sanitize for Win32 installs
131
+ $dir = str_replace('\\' ,'/', $dir);
132
+
133
+
134
+ // if file is in plugins folder
135
+ $wp_plugin_dir = str_replace('\\' ,'/', WP_PLUGIN_DIR);
136
+ $dir = str_replace($wp_plugin_dir, WP_PLUGIN_URL, $dir, $count);
137
+
138
+
139
+ if( $count < 1 )
140
+ {
141
+ // if file is in wp-content folder
142
+ $wp_content_dir = str_replace('\\' ,'/', WP_CONTENT_DIR);
143
+ $dir = str_replace($wp_content_dir, WP_CONTENT_URL, $dir, $count);
144
+ }
145
+
146
+
147
+ if( $count < 1 )
148
+ {
149
+ // if file is in ??? folder
150
+ $wp_dir = str_replace('\\' ,'/', ABSPATH);
151
+ $dir = str_replace($wp_dir, site_url('/'), $dir);
152
+ }
153
+
154
+
155
+ return $dir;
156
+ }
157
+
158
+
159
+ /*
160
+ * get_info
161
+ *
162
+ * @description: helper to get variable from settings array
163
+ * @since: 3.6
164
+ * @created: 24/01/13
165
+ */
166
+
167
+ function get_info( $info )
168
+ {
169
+ // vars
170
+ $return = false;
171
+
172
+
173
+ // specific
174
+ if( isset($this->settings[ $info ]) )
175
+ {
176
+ $return = $this->settings[ $info ];
177
+ }
178
+
179
+
180
+ // all
181
+ if( $info == 'all' )
182
+ {
183
+ $return = $this->settings;
184
+ }
185
+
186
+
187
+ // return
188
+ return $return;
189
+ }
190
+
191
+
192
+ /*
193
+ * parse_types
194
+ *
195
+ * @description: helper function to set the 'types' of variables
196
+ * @since: 2.0.4
197
+ * @created: 9/12/12
198
+ */
199
+
200
+ function parse_types( $value )
201
+ {
202
+
203
+ // is value another array?
204
+ if( is_array($value) )
205
+ {
206
+ foreach( $value as $k => $v )
207
+ {
208
+ $value[ $k ] = apply_filters( 'acf/parse_types', $v );
209
+ }
210
+ }
211
+ else
212
+ {
213
+ // string
214
+ if( is_string($value) )
215
+ {
216
+ $value = trim( $value );
217
+ }
218
+
219
+
220
+ // numbers
221
+ if( is_numeric($value) )
222
+ {
223
+ // float / int
224
+ if( strpos($value,'.') !== false )
225
+ {
226
+ $value = floatval( $value );
227
+ }
228
+ else
229
+ {
230
+ $value = intval( $value );
231
+ }
232
+ }
233
+ }
234
+
235
+
236
+ // return
237
+ return $value;
238
+ }
239
+
240
+
241
  /*
242
  * Init
243
  *
248
 
249
  function init()
250
  {
 
 
 
 
 
 
251
 
 
 
 
 
 
252
  // Create ACF post type
253
  $labels = array(
254
  'name' => __( 'Field&nbsp;Groups', 'acf' ),
263
  'not_found_in_trash' => __('No Field Groups found in Trash', 'acf'),
264
  );
265
 
 
266
  register_post_type('acf', array(
267
  'labels' => $labels,
268
  'public' => false,
280
 
281
 
282
  // register acf scripts
283
+ $scripts = array();
284
+ $scripts[] = array(
285
+ 'handle' => 'acf-field-group',
286
+ 'src' => $this->settings['dir'] . 'js/field-group.js',
287
+ 'deps' => array('jquery')
288
  );
289
+ $scripts[] = array(
290
+ 'handle' => 'acf-input',
291
+ 'src' => $this->settings['dir'] . 'js/input.php',
292
+ 'deps' => array('jquery')
293
+ );
294
+ $scripts[] = array(
295
+ 'handle' => 'acf-input-ajax',
296
+ 'src' => $this->settings['dir'] . 'js/input/ajax.js',
297
+ 'deps' => array('jquery', 'acf-input')
298
+ );
299
+ $scripts[] = array(
300
+ 'handle' => 'acf-datepicker',
301
+ 'src' => $this->settings['dir'] . 'core/fields/date_picker/jquery.ui.datepicker.js',
302
+ 'deps' => array('jquery', 'acf-input')
303
+ );
304
+
305
 
306
+ foreach( $scripts as $script )
307
  {
308
+ wp_register_script( $script['handle'], $script['src'], $script['deps'], $this->settings['version'] );
309
  }
310
 
311
 
312
  // register acf styles
313
  $styles = array(
314
+ 'acf' => $this->settings['dir'] . 'css/acf.css',
315
+ 'acf-field-group' => $this->settings['dir'] . 'css/field-group.css',
316
+ 'acf-global' => $this->settings['dir'] . 'css/global.css',
317
+ 'acf-input' => $this->settings['dir'] . 'css/input.css',
318
+ 'acf-datepicker' => $this->settings['dir'] . 'core/fields/date_picker/style.date_picker.css',
319
  );
320
 
321
  foreach( $styles as $k => $v )
322
  {
323
+ wp_register_style( $k, $v, false, $this->settings['version'] );
324
  }
325
 
326
 
327
+ // register fields
328
+ include_once('core/fields/_functions.php');
329
+ include_once('core/fields/_base.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
  include_once('core/fields/text.php');
332
  include_once('core/fields/textarea.php');
333
+ include_once('core/fields/number.php');
334
+ include_once('core/fields/email.php');
335
+ include_once('core/fields/password.php');
336
+
337
  include_once('core/fields/wysiwyg.php');
338
  include_once('core/fields/image.php');
339
  include_once('core/fields/file.php');
340
+
341
  include_once('core/fields/select.php');
342
  include_once('core/fields/checkbox.php');
343
  include_once('core/fields/radio.php');
344
  include_once('core/fields/true_false.php');
345
+
346
  include_once('core/fields/page_link.php');
347
  include_once('core/fields/post_object.php');
348
  include_once('core/fields/relationship.php');
349
+ include_once('core/fields/taxonomy.php');
350
+ include_once('core/fields/user.php');
351
+
352
  include_once('core/fields/date_picker/date_picker.php');
353
  include_once('core/fields/color_picker.php');
354
 
355
+ include_once('core/fields/message.php');
356
+ include_once('core/fields/tab.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
 
358
 
359
+ // register 3rd party fields
360
+ do_action('acf/register_fields');
 
361
 
362
 
 
 
 
363
  }
364
 
365
 
371
  * @created: 23/06/12
372
  */
373
 
374
+ function admin_menu()
375
+ {
 
376
  add_utility_page(__("Custom Fields",'acf'), __("Custom Fields",'acf'), 'manage_options', 'edit.php?post_type=acf');
 
377
  }
378
 
379
 
419
 
420
  function admin_head()
421
  {
422
+ ?>
423
+ <style type="text/css">
424
+ #adminmenu #toplevel_page_edit-post_type-acf a[href="edit.php?post_type=acf&page=acf-upgrade"]{ display:none; }
425
+ #adminmenu #toplevel_page_edit-post_type-acf .wp-menu-image { background-position: 1px -33px; }
426
+ #adminmenu #toplevel_page_edit-post_type-acf:hover .wp-menu-image,
427
+ #adminmenu #toplevel_page_edit-post_type-acf.wp-menu-open .wp-menu-image { background-position: 1px -1px; }
428
+ </style>
429
+ <?php
430
  }
431
 
432
 
433
  /*
434
+ * get_taxonomies_for_select
435
  *
436
  * @description:
437
+ * @since: 3.6
438
+ * @created: 27/01/13
439
  */
440
 
441
+ function get_taxonomies_for_select( $choices, $simple_value = false )
442
+ {
443
+ // vars
444
+ $post_types = get_post_types();
 
 
 
 
445
 
 
 
 
 
 
 
 
 
 
446
 
447
+ if($post_types)
 
448
  {
449
+ foreach($post_types as $post_type)
450
  {
451
+ $post_type_object = get_post_type_object($post_type);
452
+ $taxonomies = get_object_taxonomies($post_type);
453
+ if($taxonomies)
454
+ {
455
+ foreach($taxonomies as $taxonomy)
456
+ {
457
+ if(!is_taxonomy_hierarchical($taxonomy)) continue;
458
+ $terms = get_terms($taxonomy, array('hide_empty' => false));
459
+ if($terms)
460
+ {
461
+ foreach($terms as $term)
462
+ {
463
+ $value = $taxonomy . ':' . $term->term_id;
464
+
465
+ if( $simple_value )
466
+ {
467
+ $value = $term->term_id;
468
+ }
469
+
470
+ $choices[$post_type_object->label . ': ' . $taxonomy][$value] = $term->name;
471
+ }
472
+ }
473
+ }
474
+ }
475
  }
476
  }
477
 
478
+ return $choices;
 
 
 
479
  }
480
 
481
 
482
+ /*
483
+ * get_post_types
 
 
484
  *
485
+ * @description:
486
+ * @since: 3.5.5
487
+ * @created: 16/12/12
488
+ */
489
+
490
+ function get_post_types( $post_types, $exclude = array(), $include = array() )
491
  {
492
+ // get all custom post types
493
+ $post_types = array_merge($post_types, get_post_types());
 
 
 
494
 
 
 
495
 
496
+ // core include / exclude
497
+ $acf_includes = array_merge( array(), $include );
498
+ $acf_excludes = array_merge( array( 'acf', 'revision', 'nav_menu_item' ), $exclude );
499
+
 
 
 
 
 
 
 
 
 
 
 
500
 
501
+ // include
502
+ foreach( $acf_includes as $p )
503
+ {
504
+ if( post_type_exists($p) )
505
+ {
506
+ $post_types[ $p ] = $p;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
507
  }
508
  }
509
 
510
 
511
+ // exclude
512
+ foreach( $acf_excludes as $p )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
513
  {
514
+ unset( $post_types[ $p ] );
515
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
516
 
517
 
518
+ return $post_types;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
519
 
 
520
  }
521
 
522
 
 
523
  /*
524
+ * get_image_sizes
525
  *
526
  * @description: returns an array holding all the image sizes
527
  * @since 3.2.8
528
  * @created: 6/07/12
529
  */
530
 
531
+ function get_image_sizes( $sizes )
532
  {
533
  // find all sizes
534
  $all_sizes = get_intermediate_image_sizes();
535
 
536
 
537
  // define default sizes
538
+ $sizes = array_merge($sizes, array(
539
  'thumbnail' => __("Thumbnail",'acf'),
540
  'medium' => __("Medium",'acf'),
541
  'large' => __("Large",'acf'),
542
  'full' => __("Full",'acf')
543
+ ));
544
 
545
 
546
  // add extra registered sizes
547
+ foreach( $all_sizes as $size )
548
  {
549
+ if( !isset($sizes[ $size ]) )
550
  {
551
+ $sizes[ $size ] = ucwords( str_replace('-', ' ', $size) );
552
  }
553
  }
554
 
555
 
556
  // return array
557
+ return $sizes;
558
+ }
559
+
560
+
561
+ /*
562
+ * render_fields_for_input
563
+ *
564
+ * @description:
565
+ * @since 3.1.6
566
+ * @created: 23/06/12
567
+ */
568
+
569
+ function create_fields( $fields, $post_id )
570
+ {
571
+ if( is_array($fields) ){ foreach( $fields as $field ){
572
+
573
+ // if they didn't select a type, skip this field
574
+ if( !$field['type'] || $field['type'] == 'null' ) continue;
575
+
576
+
577
+ // set value
578
+ if( !isset($field['value']) )
579
+ {
580
+
581
+ $field['value'] = apply_filters('acf/load_value', false, $post_id, $field);
582
+ $field['value'] = apply_filters('acf/format_value', $field['value'], $post_id, $field);
583
+ }
584
+
585
+
586
+ // required
587
+ $required_class = "";
588
+ $required_label = "";
589
+
590
+ if( $field['required'] )
591
+ {
592
+ $required_class = ' required';
593
+ $required_label = ' <span class="required">*</span>';
594
+ }
595
+
596
+
597
+ echo '<div id="acf-' . $field['name'] . '" class="field field_type-' . $field['type'] . ' field_key-' . $field['key'] . $required_class . '" data-field_name="' . $field['name'] . '" data-field_key="' . $field['key'] . '" data-field_type="' . $field['type'] . '">';
598
+
599
+ echo '<p class="label">';
600
+ echo '<label for="' . $field['id'] . '">' . $field['label'] . $required_label . '</label>';
601
+ echo $field['instructions'];
602
+ echo '</p>';
603
+
604
+ $field['name'] = 'fields[' . $field['key'] . ']';
605
+ do_action('acf/create_field', $field);
606
+
607
+ echo '</div>';
608
+
609
+ }}
610
+
611
  }
612
 
613
 
614
  /*
615
+ * save_post
616
  *
617
  * @description:
618
+ * @since: 3.6
619
+ * @created: 28/01/13
620
  */
621
 
622
+ function save_post( $post_id )
623
  {
624
 
625
  // load from post
628
  return false;
629
  }
630
 
631
+
632
  // loop through and save
633
  if( $_POST['fields'] )
634
  {
635
  foreach( $_POST['fields'] as $key => $value )
636
  {
637
+ // parse types
638
+ $value = apply_filters('acf/parse_types', $value);
639
+
640
  // get field
641
+ $field = apply_filters('acf/load_field', false, $key );
642
+
643
+ // update field
644
+ do_action('acf/update_value', $value, $post_id, $field );
645
 
 
646
  }
647
  // foreach($fields as $key => $value)
648
  }
651
 
652
  return true;
653
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
655
 
656
  }
657
+
658
+ $acf = new Acf();
659
+
660
  ?>
core/actions/export.php CHANGED
@@ -1,12 +1,13 @@
1
  <?php
2
- /*--------------------------------------------------------------------------------------
3
- *
4
- * ACF Export
5
  *
6
- * @author Elliot Condon
7
- * @since 3.0.2
8
- *
9
- *-------------------------------------------------------------------------------------*/
 
10
 
11
  // vars
12
  $defaults = array(
1
  <?php
2
+
3
+ /*
4
+ * Export
5
  *
6
+ * @description:
7
+ * @since: 3.6
8
+ * @created: 25/01/13
9
+ */
10
+
11
 
12
  // vars
13
  $defaults = array(
core/api.php CHANGED
@@ -13,9 +13,9 @@ $GLOBALS['acf_field'] = array();
13
  * @since 3.6
14
  * @date 29/01/13
15
  *
16
- * @param $post_id
17
  *
18
- * @return $post_id
19
  */
20
 
21
  function acf_filter_post_id( $post_id )
@@ -64,27 +64,89 @@ function acf_filter_post_id( $post_id )
64
  return $post_id;
65
  }
66
 
67
- /*--------------------------------------------------------------------------------------
 
 
68
  *
69
- * get_fields
 
70
  *
71
- * @author Elliot Condon
72
- * @since 1.0.3
73
- *
74
- *-------------------------------------------------------------------------------------*/
 
 
 
 
 
75
 
76
- function get_fields($post_id = false)
77
  {
 
 
 
 
 
 
 
 
78
  // vars
79
- global $post, $wpdb;
 
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
- // filter post_id
83
- $post_id = acf_filter_post_id( $post_id );
84
 
 
 
 
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  // vars
87
- $field_key = "";
88
  $value = array();
89
 
90
 
@@ -92,9 +154,10 @@ function get_fields($post_id = false)
92
  if( is_numeric($post_id) )
93
  {
94
  $keys = $wpdb->get_col($wpdb->prepare(
95
- "SELECT meta_key FROM $wpdb->postmeta WHERE post_id = %d and meta_key NOT LIKE %s",
96
  $post_id,
97
- '\_%'
 
98
  ));
99
  }
100
  elseif( strpos($post_id, 'user_') !== false )
@@ -102,146 +165,223 @@ function get_fields($post_id = false)
102
  $user_id = str_replace('user_', '', $post_id);
103
 
104
  $keys = $wpdb->get_col($wpdb->prepare(
105
- "SELECT meta_key FROM $wpdb->usermeta WHERE user_id = %d and meta_key NOT LIKE %s",
106
  $user_id,
107
- '\_%'
 
108
  ));
109
  }
110
  else
111
  {
112
  $keys = $wpdb->get_col($wpdb->prepare(
113
  "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s",
114
- $post_id . '\_%'
115
  ));
116
  }
117
 
118
 
119
- if($keys)
120
  {
121
- foreach($keys as $key)
122
  {
123
- $value[$key] = get_field($key, $post_id);
 
 
 
 
 
 
 
124
  }
125
  }
126
 
127
 
128
  // no value
129
- if(empty($value))
130
  {
131
  return false;
132
  }
133
 
 
 
134
  return $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
 
 
 
 
 
 
 
 
 
136
  }
137
 
138
 
139
- /*--------------------------------------------------------------------------------------
 
140
  *
141
- * get_field
 
 
142
  *
143
- * @author Elliot Condon
144
- * @since 1.0.3
145
- *
146
- *-------------------------------------------------------------------------------------*/
 
 
 
 
 
 
147
 
148
- function get_field($field_key, $post_id = false, $format_value = true)
149
- {
150
- global $post, $acf;
151
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  // filter post_id
154
  $post_id = acf_filter_post_id( $post_id );
155
-
 
156
 
157
- // return cache
158
- $cache = wp_cache_get('acf_get_field_' . $post_id . '_' . $field_key);
159
- if($cache)
160
- {
161
- return $cache;
162
- }
163
-
164
- // default
165
- $value = "";
166
- $field = array(
167
- 'type' => 'text',
168
- 'name' => $field_key,
169
- 'key' => 'temp_key_for_' . $field_key
170
  );
171
-
172
 
173
- if( $format_value )
 
 
 
 
174
  {
175
- // is $field_name a name? pre 3.4.0
176
- if( strpos($field_key, "field_") === false )
177
- {
178
- // get field key
179
- if( is_numeric($post_id) )
180
- {
181
- $field_key = get_post_meta($post_id, '_' . $field_key, true);
182
- }
183
- elseif( strpos($post_id, 'user_') !== false )
184
- {
185
- $temp_post_id = str_replace('user_', '', $post_id);
186
- $field_key = get_user_meta($temp_post_id, '_' . $field_key, true);
187
- }
188
- else
189
- {
190
- $field_key = get_option('_' . $post_id . '_' . $field_key);
191
- }
192
- }
193
-
194
-
195
- // get field
196
- if( strpos($field_key, "field_") !== false )
197
- {
198
- $field = $acf->get_acf_field($field_key);
199
- }
200
  }
201
- else
 
 
 
202
  {
203
- $field = array(
204
- 'type' => 'none',
205
- 'name' => $field_key,
206
- 'key' => 'temp_key_for_' . $field_key
207
- );
208
  }
209
 
210
-
211
- // load value
212
- $value = $acf->get_value_for_api($post_id, $field);
213
 
214
-
215
- // no value?
216
- if( $value == "" )
217
  {
218
- $value = false;
 
 
 
 
 
219
  }
220
 
221
-
222
- // update cache
223
- wp_cache_set('acf_get_field_' . $post_id . '_' . $field_key, $value);
224
-
225
 
226
- return $value;
227
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  }
229
 
230
 
231
- /*--------------------------------------------------------------------------------------
 
232
  *
233
- * the_field
234
  *
235
- * @author Elliot Condon
236
- * @since 1.0.3
237
- *
238
- *-------------------------------------------------------------------------------------*/
 
 
 
 
 
239
 
240
- function the_field($field_name, $post_id = false)
241
  {
242
  $value = get_field($field_name, $post_id);
243
 
244
- if(is_array($value))
245
  {
246
  $value = @implode(', ',$value);
247
  }
@@ -250,42 +390,54 @@ function the_field($field_name, $post_id = false)
250
  }
251
 
252
 
253
- /*--------------------------------------------------------------------------------------
 
254
  *
255
- * has_sub_field
 
 
256
  *
257
- * @author Elliot Condon
258
- * @since 3.3.4
259
- *
260
- *-------------------------------------------------------------------------------------*/
 
 
 
 
 
261
 
262
- function has_sub_field($field_name, $post_id = false)
263
  {
264
- // needs a post_id
265
- global $post;
266
-
267
-
268
  // filter post_id
269
  $post_id = acf_filter_post_id( $post_id );
270
-
271
-
272
 
273
  // empty?
274
  if( empty($GLOBALS['acf_field']) )
275
  {
 
 
 
 
 
 
276
  $GLOBALS['acf_field'][] = array(
277
  'name' => $field_name,
278
- 'value' => get_field($field_name, $post_id),
 
279
  'row' => -1,
280
  'post_id' => $post_id,
281
  );
282
  }
283
 
284
-
285
  // vars
286
  $depth = count( $GLOBALS['acf_field'] ) - 1;
287
  $name = $GLOBALS['acf_field'][$depth]['name'];
288
  $value = $GLOBALS['acf_field'][$depth]['value'];
 
289
  $row = $GLOBALS['acf_field'][$depth]['row'];
290
  $id = $GLOBALS['acf_field'][$depth]['post_id'];
291
 
@@ -293,10 +445,16 @@ function has_sub_field($field_name, $post_id = false)
293
  // if ID has changed, this is a new repeater / flexible field!
294
  if( $post_id != $id )
295
  {
296
- // reset
 
 
 
 
 
297
  $GLOBALS['acf_field'][] = array(
298
  'name' => $field_name,
299
- 'value' => get_field($field_name, $post_id),
 
300
  'row' => -1,
301
  'post_id' => $post_id,
302
  );
@@ -309,11 +467,12 @@ function has_sub_field($field_name, $post_id = false)
309
  if( $field_name != $name )
310
  {
311
  // is this a "new" while loop refering to a sub field?
312
- if( isset($value[$row][$field_name]) )
313
  {
314
  $GLOBALS['acf_field'][] = array(
315
  'name' => $field_name,
316
- 'value' => $value[$row][$field_name],
 
317
  'row' => -1,
318
  'post_id' => $post_id,
319
  );
@@ -337,6 +496,7 @@ function has_sub_field($field_name, $post_id = false)
337
  // update vars
338
  $depth = count( $GLOBALS['acf_field'] ) - 1;
339
  $value = $GLOBALS['acf_field'][$depth]['value'];
 
340
  $row = $GLOBALS['acf_field'][$depth]['row'];
341
 
342
 
@@ -361,16 +521,42 @@ function has_sub_field($field_name, $post_id = false)
361
  }
362
 
363
 
364
- /*--------------------------------------------------------------------------------------
 
365
  *
366
- * get_sub_field
367
  *
368
- * @author Elliot Condon
369
- * @since 1.0.3
370
- *
371
- *-------------------------------------------------------------------------------------*/
 
 
 
 
 
372
 
373
- function get_sub_field($field_name)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  {
375
 
376
  // no field?
@@ -383,28 +569,34 @@ function get_sub_field($field_name)
383
  // vars
384
  $depth = count( $GLOBALS['acf_field'] ) - 1;
385
  $value = $GLOBALS['acf_field'][$depth]['value'];
 
386
  $row = $GLOBALS['acf_field'][$depth]['row'];
387
-
388
-
389
  // no value at i
390
- if( !isset($GLOBALS['acf_field'][$depth]['value'][$row][$field_name]) )
391
  {
392
  return false;
393
  }
 
394
 
395
-
396
- return $GLOBALS['acf_field'][$depth]['value'][$row][$field_name];
397
  }
398
 
399
 
400
- /*--------------------------------------------------------------------------------------
 
401
  *
402
- * the_sub_field
403
  *
404
- * @author Elliot Condon
405
- * @since 1.0.3
406
- *
407
- *-------------------------------------------------------------------------------------*/
 
 
 
 
408
 
409
  function the_sub_field($field_name)
410
  {
@@ -419,49 +611,119 @@ function the_sub_field($field_name)
419
  }
420
 
421
 
422
- /*--------------------------------------------------------------------------------------
 
423
  *
424
- * register_field
425
  *
426
- * @author Elliot Condon
427
- * @since 3.0.0
428
- *
429
- *-------------------------------------------------------------------------------------*/
430
-
431
- $GLOBALS['acf_register_field'] = array();
 
 
432
 
433
- function register_field($class = "", $url = "")
434
  {
435
- $GLOBALS['acf_register_field'][] = array(
436
- 'url' => $url,
437
- 'class' => $class,
438
- );
 
 
 
 
 
 
 
 
 
 
 
439
  }
440
 
441
- function acf_register_field($array)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
442
  {
443
- $array = array_merge($array, $GLOBALS['acf_register_field']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
 
445
- return $array;
446
  }
447
- add_filter('acf_register_field', 'acf_register_field');
448
 
449
 
450
- /*--------------------------------------------------------------------------------------
 
451
  *
452
- * register_field_group
 
453
  *
454
- * @author Elliot Condon
455
- * @since 3.0.6
456
- *
457
- *-------------------------------------------------------------------------------------*/
 
 
 
 
458
 
459
  $GLOBALS['acf_register_field_group'] = array();
460
 
461
- function register_field_group($array)
462
  {
463
  // add id
464
- if(!isset($array['id']))
465
  {
466
  $array['id'] = uniqid();
467
  }
@@ -480,30 +742,29 @@ function register_field_group($array)
480
  }
481
 
482
 
483
- add_filter('acf/get_field_groups', 'acf_register_field_group', 10, 1);
484
- function acf_register_field_group( $return )
485
  {
486
-
487
  // validate
488
  if( empty($GLOBALS['acf_register_field_group']) )
489
  {
490
  return $return;
491
  }
492
 
493
- // ensure $return is an array
494
- if( ! is_array( $return ) )
495
- {
496
- $return = array();
497
- }
498
-
499
- // merge in custom
500
- $return = array_merge($return, $GLOBALS['acf_register_field_group']);
501
-
502
 
 
 
 
 
 
 
 
 
 
503
 
504
  // order field groups based on menu_order, title
505
  // Obtain a list of columns
506
- foreach ($return as $key => $row)
507
  {
508
  $menu_order[ $key ] = $row['menu_order'];
509
  $title[ $key ] = $row['title'];
@@ -520,43 +781,109 @@ function acf_register_field_group( $return )
520
  }
521
 
522
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
523
 
524
- /*--------------------------------------------------------------------------------------
525
- *
526
- * register_options_page
527
- *
528
- * @author Elliot Condon
529
- * @since 3.0.0
530
- *
531
- *-------------------------------------------------------------------------------------*/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
532
 
533
- $GLOBALS['acf_options_pages'] = array();
534
 
535
- function register_options_page( $title = "" )
 
536
  {
537
- $GLOBALS['acf_options_pages'][] = $title;
 
 
 
 
 
 
 
 
 
 
 
 
 
538
  }
539
 
540
 
541
- function acf_settings_options_pages( $options )
 
 
542
  {
543
- // merge in options pages
544
- $options['options_page']['pages'] = array_merge( $options['options_page']['pages'], $GLOBALS['acf_options_pages'] );
545
-
 
 
 
 
 
 
 
 
 
546
 
547
  return $options;
548
  }
549
- add_filter('acf_settings', 'acf_settings_options_pages');
550
 
551
 
552
- /*--------------------------------------------------------------------------------------
 
553
  *
554
- * get_row_layout
555
  *
556
- * @author Elliot Condon
557
- * @since 1.0.3
558
- *
559
- *-------------------------------------------------------------------------------------*/
 
 
560
 
561
  function get_row_layout()
562
  {
@@ -568,14 +895,21 @@ function get_row_layout()
568
  }
569
 
570
 
571
- /*--------------------------------------------------------------------------------------
 
572
  *
573
- * shorcode support
574
  *
575
- * @author Elliot Condon
576
- * @since 1.1.1
577
- *
578
- *-------------------------------------------------------------------------------------*/
 
 
 
 
 
 
579
 
580
  function acf_shortcode( $atts )
581
  {
@@ -597,7 +931,7 @@ function acf_shortcode( $atts )
597
  $value = get_field( $field, $post_id );
598
 
599
 
600
- if(is_array($value))
601
  {
602
  $value = @implode( ', ',$value );
603
  }
@@ -607,35 +941,39 @@ function acf_shortcode( $atts )
607
  add_shortcode( 'acf', 'acf_shortcode' );
608
 
609
 
610
- /*--------------------------------------------------------------------------------------
 
611
  *
612
- * Front end form Head
613
  *
614
- * @author Elliot Condon
615
- * @since 1.1.4
616
- *
617
- *-------------------------------------------------------------------------------------*/
 
 
 
 
618
 
619
  function acf_form_head()
620
  {
621
  // global vars
622
- global $acf, $post_id;
623
-
624
 
625
 
626
- // run database save first
627
- if( isset($_POST['acf_save']) )
628
  {
629
  // $post_id to save against
630
  $post_id = $_POST['post_id'];
631
 
632
-
633
  // allow for custom save
634
- $post_id = apply_filters('acf_form_pre_save_post', $post_id);
635
 
636
 
637
  // save the data
638
- do_action('acf_save_post', $post_id);
639
 
640
 
641
  // redirect
@@ -644,14 +982,8 @@ function acf_form_head()
644
  wp_redirect($_POST['return']);
645
  exit;
646
  }
647
-
648
  }
649
 
650
-
651
- // register css / javascript
652
- do_action('acf_print_scripts-input');
653
- do_action('acf_print_styles-input');
654
-
655
 
656
  // need wp styling
657
  wp_enqueue_style(array(
@@ -659,50 +991,66 @@ function acf_form_head()
659
  ));
660
 
661
 
662
- // form was not posted, load js head stuff
 
 
663
  add_action('wp_head', 'acf_form_wp_head');
664
 
665
  }
666
 
667
  function acf_form_wp_head()
668
  {
669
- // add user js + css
670
- do_action('acf_head-input');
671
  }
672
 
673
 
674
- /*--------------------------------------------------------------------------------------
 
675
  *
676
- * Front end form
677
  *
678
- * @author Elliot Condon
679
- * @since 1.1.4
680
- *
681
- *-------------------------------------------------------------------------------------*/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
682
 
683
- function acf_form($options = null)
684
  {
685
- global $post, $acf;
686
 
687
 
688
  // defaults
689
  $defaults = array(
690
- 'post_id' => false, // post id to get field groups from and save data to
691
- 'field_groups' => array(), // this will find the field groups for this post
692
  'form' => true,
693
- 'form_attributes' => array( // attributes will be added to the form element
694
  'class' => ''
695
  ),
696
- 'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
697
- 'html_before_fields' => '', // html inside form before fields
698
- 'html_after_fields' => '', // html inside form after fields
699
- 'submit_value' => 'Update', // vale for submit field
700
- 'updated_message' => 'Post updated.', // default updated message. Can be false
701
  );
702
 
703
 
704
  // merge defaults with options
705
- if($options && is_array($options))
706
  {
707
  $options = array_merge($defaults, $options);
708
  }
@@ -724,23 +1072,28 @@ function acf_form($options = null)
724
  'post_id' => $options['post_id']
725
  );
726
 
 
727
  if( strpos($options['post_id'], 'user_') !== false )
728
  {
729
  $user_id = str_replace('user_', '', $options['post_id']);
730
- $filter['ef_user'] = $user_id;
 
 
731
  }
732
  elseif( strpos($options['post_id'], 'taxonomy_') !== false )
733
  {
734
  $taxonomy_id = str_replace('taxonomy_', '', $options['post_id']);
735
- $filter['ef_taxonomy'] = $taxonomy_id;
 
 
736
  }
737
 
738
 
739
  $options['field_groups'] = array();
740
  $options['field_groups'] = apply_filters( 'acf/location/match_field_groups', $options['field_groups'], $filter );
741
  }
742
-
743
-
744
  // updated message
745
  if(isset($_GET['updated']) && $_GET['updated'] == 'true' && $options['updated_message'])
746
  {
@@ -757,8 +1110,9 @@ function acf_form($options = null)
757
  if( $options['form'] ): ?>
758
  <form action="" id="post" method="post" <?php if($options['form_attributes']){foreach($options['form_attributes'] as $k => $v){echo $k . '="' . $v .'" '; }} ?>>
759
  <?php endif; ?>
 
760
  <div style="display:none">
761
- <input type="hidden" name="acf_save" value="true" />
762
  <input type="hidden" name="post_id" value="<?php echo $options['post_id']; ?>" />
763
  <input type="hidden" name="return" value="<?php echo $options['return']; ?>" />
764
  <?php wp_editor('', 'acf_settings'); ?>
@@ -770,35 +1124,37 @@ function acf_form($options = null)
770
  // html before fields
771
  echo $options['html_before_fields'];
772
 
773
- $field_groups = apply_filters('acf/get_field_groups', false);
774
-
775
- if($field_groups):
776
- foreach($field_groups as $field_group):
777
-
778
- if(!in_array($field_group['id'], $options['field_groups'])) continue;
779
-
780
-
781
- // defaults
782
- if(!$field_group['options'])
783
- {
784
- $field_group['options'] = array(
785
- 'layout' => 'default'
786
- );
787
- }
788
-
789
-
790
- if($field_group['fields'])
791
- {
792
- echo '<div id="acf_' . $field_group['id'] . '" class="postbox acf_postbox">';
793
- echo '<h3 class="hndle"><span>' . $field_group['title'] . '</span></h3>';
794
- echo '<div class="inside">';
795
- echo '<div class="options" data-layout="' . $field_group['options']['layout'] . '" data-show="1"></div>';
796
- $acf->render_fields_for_input($field_group['fields'], $options['post_id']);
797
- echo '</div></div>';
798
- }
799
-
800
- endforeach;
801
- endif;
 
 
802
 
803
  // html after fields
804
  echo $options['html_after_fields'];
@@ -812,60 +1168,47 @@ function acf_form($options = null)
812
  </div>
813
  <!-- / Submit -->
814
  <?php endif; ?>
815
-
816
  </div><!-- <div id="poststuff"> -->
817
 
818
  <?php if( $options['form'] ): ?>
819
  </form>
820
  <?php endif;
821
-
822
  }
823
 
824
 
825
- /*--------------------------------------------------------------------------------------
 
826
  *
827
- * update_field
828
  *
829
- * @author Elliot Condon
830
- * @since 3.1.9
831
- *
832
- *-------------------------------------------------------------------------------------*/
 
 
 
 
 
 
833
 
834
- function update_field($field_key, $value, $post_id = false)
835
  {
836
- global $post, $acf;
837
-
838
-
839
  // filter post_id
840
  $post_id = acf_filter_post_id( $post_id );
841
 
842
 
843
- // is $field_name a name? pre 3.4.0
844
- if( strpos($field_key, "field_") === false )
845
- {
846
- // get field key
847
- if( is_numeric($post_id) )
848
- {
849
- $field_key = get_post_meta($post_id, '_' . $field_key, true);
850
- }
851
- elseif( strpos($post_id, 'user_') !== false )
852
- {
853
- $temp_post_id = str_replace('user_', '', $post_id);
854
- $field_key = get_user_meta($temp_post_id, '_' . $field_key, true);
855
- }
856
- else
857
- {
858
- $field_key = get_option('_' . $post_id . '_' . $field_key);
859
- }
860
- }
861
-
862
 
863
- // get field
864
- $field = $acf->get_acf_field($field_key);
865
 
866
 
867
- // backup if no field was found, save as a text field
868
- if( !$field )
869
  {
870
  $field = array(
871
  'type' => 'none',
@@ -892,7 +1235,7 @@ function update_field($field_key, $value, $post_id = false)
892
 
893
 
894
  // save
895
- $acf->update_value($post_id, $field, $value);
896
 
897
 
898
  return true;
@@ -900,16 +1243,61 @@ function update_field($field_key, $value, $post_id = false)
900
  }
901
 
902
 
903
- /*--------------------------------------------------------------------------------------
 
904
  *
905
- * acf_convert_field_names_to_keys
906
  *
907
- * @description: Helper for the update_field function
908
- * @created: 30/09/12
909
- * @author Elliot Condon
910
- * @since 3.5.0
911
  *
912
- *-------------------------------------------------------------------------------------*/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
913
 
914
  function acf_convert_field_names_to_keys( $value, $field )
915
  {
@@ -932,7 +1320,7 @@ function acf_convert_field_names_to_keys( $value, $field )
932
 
933
 
934
  // loop through the values and format the array to use sub field keys
935
- if( $value )
936
  {
937
  foreach( $value as $row_i => $row)
938
  {
@@ -976,105 +1364,6 @@ function acf_convert_field_names_to_keys( $value, $field )
976
 
977
 
978
 
979
- /*--------------------------------------------------------------------------------------
980
- *
981
- * get_field_object
982
- *
983
- * @description: returns an array containing all the field data for a given field_name.
984
- * @created: 3/09/12
985
- * @author Elliot Condon
986
- * @since 3.4.0
987
- *
988
- * @return: Array in this format
989
-
990
- Array
991
- (
992
- [key] => field_5043fe0e3c58f
993
- [label] => Select
994
- [name] => select
995
- [type] => select
996
- [instructions] =>
997
- [required] => 1
998
- [choices] => Array
999
- (
1000
- [yes] => Yes
1001
- [no] => No
1002
- [maybe] => Maybe
1003
- )
1004
-
1005
- [default_value] =>
1006
- [allow_null] => 1
1007
- [multiple] => 1
1008
- [order_no] => 4
1009
- [value] => Array
1010
- (
1011
- [0] => Yes
1012
- [1] => Maybe
1013
- )
1014
-
1015
- )
1016
-
1017
- *-------------------------------------------------------------------------------------*/
1018
-
1019
- function get_field_object($field_key, $post_id = false, $options = array())
1020
- {
1021
- // defaults for options
1022
- $defaults = array(
1023
- 'load_value' => true,
1024
- );
1025
-
1026
- $options = array_merge($defaults, $options);
1027
-
1028
-
1029
- // vars
1030
- global $post, $acf;
1031
-
1032
-
1033
- // filter post_id
1034
- $post_id = acf_filter_post_id( $post_id );
1035
-
1036
-
1037
- // is $field_name a name? pre 3.4.0
1038
- if( strpos($field_key, "field_") === false )
1039
- {
1040
- // get field key
1041
- if( is_numeric($post_id) )
1042
- {
1043
- $field_key = get_post_meta($post_id, '_' . $field_key, true);
1044
- }
1045
- elseif( strpos($post_id, 'user_') !== false )
1046
- {
1047
- $temp_post_id = str_replace('user_', '', $post_id);
1048
- $field_key = get_user_meta($temp_post_id, '_' . $field_key, true);
1049
- }
1050
- else
1051
- {
1052
- $field_key = get_option('_' . $post_id . '_' . $field_key);
1053
- }
1054
- }
1055
-
1056
-
1057
- // get field
1058
- $field = $acf->get_acf_field($field_key);
1059
-
1060
-
1061
- // backup if no field was found, save as a text field
1062
- if( !$field )
1063
- {
1064
- return false;
1065
- }
1066
-
1067
-
1068
- if( $options['load_value'] )
1069
- {
1070
- $field['value'] = $acf->get_value_for_api($post_id, $field);
1071
- }
1072
-
1073
- return $field;
1074
-
1075
- }
1076
-
1077
-
1078
  /*
1079
  * Depreceated Functions
1080
  *
13
  * @since 3.6
14
  * @date 29/01/13
15
  *
16
+ * @param mixed $post_id
17
  *
18
+ * @return mixed $post_id
19
  */
20
 
21
  function acf_filter_post_id( $post_id )
64
  return $post_id;
65
  }
66
 
67
+
68
+ /*
69
+ * get_field_reference()
70
  *
71
+ * This function will find the $field_key that is related to the $field_name.
72
+ * This is know as the field value reference
73
  *
74
+ * @type function
75
+ * @since 3.6
76
+ * @date 29/01/13
77
+ *
78
+ * @param mixed $field_name: the name of the field - 'sub_heading'
79
+ * @param int $post_id: the post_id of which the value is saved against
80
+ *
81
+ * @return string $return: a string containing the field_key
82
+ */
83
 
84
+ function get_field_reference( $field_name, $post_id )
85
  {
86
+ // cache
87
+ $cache = wp_cache_get( 'field_reference-' . $post_id . '-' . $field_name, 'acf' );
88
+ if( $cache )
89
+ {
90
+ return $cache;
91
+ }
92
+
93
+
94
  // vars
95
+ $return = '';
96
+
97
 
98
+ // get field key
99
+ if( is_numeric($post_id) )
100
+ {
101
+ $return = get_post_meta($post_id, '_' . $field_name, true);
102
+ }
103
+ elseif( strpos($post_id, 'user_') !== false )
104
+ {
105
+ $temp_post_id = str_replace('user_', '', $post_id);
106
+ $return = get_user_meta($temp_post_id, '_' . $field_name, true);
107
+ }
108
+ else
109
+ {
110
+ $return = get_option('_' . $post_id . '_' . $field_name);
111
+ }
112
 
 
 
113
 
114
+ // set cache
115
+ wp_cache_set( 'field_reference-' . $post_id . '-' . $field_name, $return, 'acf' );
116
+
117
 
118
+ // return
119
+ return $return;
120
+ }
121
+
122
+
123
+ /*
124
+ * get_field_objects()
125
+ *
126
+ * This function will return an array containing all the custom field objects for a specific post_id.
127
+ * The function is not very elegant and wastes a lot of PHP memory / SQL queries if you are not using all the fields / values.
128
+ *
129
+ * @type function
130
+ * @since 3.6
131
+ * @date 29/01/13
132
+ *
133
+ * @param mixed $post_id: the post_id of which the value is saved against
134
+ *
135
+ * @return array $return: an array containin the field groups
136
+ */
137
+
138
+ function get_field_objects( $post_id = false, $options = array() )
139
+ {
140
+ // global
141
+ global $wpdb;
142
+
143
+
144
+ // filter post_id
145
+ $post_id = acf_filter_post_id( $post_id );
146
+
147
+
148
  // vars
149
+ $field_key = '';
150
  $value = array();
151
 
152
 
154
  if( is_numeric($post_id) )
155
  {
156
  $keys = $wpdb->get_col($wpdb->prepare(
157
+ "SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d and meta_key LIKE %s AND meta_value LIKE %s",
158
  $post_id,
159
+ '\_%',
160
+ 'field\_%'
161
  ));
162
  }
163
  elseif( strpos($post_id, 'user_') !== false )
165
  $user_id = str_replace('user_', '', $post_id);
166
 
167
  $keys = $wpdb->get_col($wpdb->prepare(
168
+ "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = %d and meta_key LIKE %s AND meta_value LIKE %s",
169
  $user_id,
170
+ '\_%',
171
+ 'field\_%'
172
  ));
173
  }
174
  else
175
  {
176
  $keys = $wpdb->get_col($wpdb->prepare(
177
  "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s",
178
+ '\_' . $post_id . '\_%'
179
  ));
180
  }
181
 
182
 
183
+ if( is_array($keys) )
184
  {
185
+ foreach( $keys as $key )
186
  {
187
+ $field = get_field_object( $key, $post_id, $options );
188
+
189
+ if( !is_array($field) )
190
+ {
191
+ continue;
192
+ }
193
+
194
+ $value[ $field['name'] ] = $field;
195
  }
196
  }
197
 
198
 
199
  // no value
200
+ if( empty($value) )
201
  {
202
  return false;
203
  }
204
 
205
+
206
+ // return
207
  return $value;
208
+ }
209
+
210
+
211
+ /*
212
+ * get_fields()
213
+ *
214
+ * This function will return an array containing all the custom field values for a specific post_id.
215
+ * The function is not very elegant and wastes a lot of PHP memory / SQL queries if you are not using all the values.
216
+ *
217
+ * @type function
218
+ * @since 3.6
219
+ * @date 29/01/13
220
+ *
221
+ * @param mixed $post_id: the post_id of which the value is saved against
222
+ *
223
+ * @return array $return: an array containin the field values
224
+ */
225
+
226
+ function get_fields( $post_id = false )
227
+ {
228
+ $fields = get_field_objects( $post_id );
229
 
230
+ if( is_array($fields) )
231
+ {
232
+ foreach( $fields as $k => $field )
233
+ {
234
+ $fields[ $k ] = $field['value'];
235
+ }
236
+ }
237
+
238
+ return $fields;
239
  }
240
 
241
 
242
+ /*
243
+ * get_field()
244
  *
245
+ * This function will return a custom field value for a specific field name/key + post_id.
246
+ * There is a 3rd parameter to turn on/off formating. This means that an Image field will not use
247
+ * its 'return option' to format the value but return only what was saved in the database
248
  *
249
+ * @type function
250
+ * @since 3.6
251
+ * @date 29/01/13
252
+ *
253
+ * @param string $field_key: string containing the name of teh field name / key ('sub_field' / 'field_1')
254
+ * @param mixed $post_id: the post_id of which the value is saved against
255
+ * @param boolean $format_value: whether or not to format the value as described above
256
+ *
257
+ * @return mixed $value: the value found
258
+ */
259
 
260
+ function get_field( $field_key, $post_id = false, $format_value = true )
261
+ {
262
+ // vars
263
+ $return = false;
264
+ $options = array(
265
+ 'load_value' => true,
266
+ 'format_value' => $format_value
267
+ );
268
+
269
+
270
+ $field = get_field_object( $field_key, $post_id, $options);
271
+
272
+
273
+ if( is_array($field) )
274
+ {
275
+ $return = $field['value'];
276
+ }
277
+
278
+
279
+ return $return;
280
 
281
+ }
282
+
283
+
284
+ /*
285
+ * get_field_object()
286
+ *
287
+ * This function will return an array containing all the field data for a given field_name
288
+ *
289
+ * @type function
290
+ * @since 3.6
291
+ * @date 3/02/13
292
+ *
293
+ * @param string $field_key: string containing the name of teh field name / key ('sub_field' / 'field_1')
294
+ * @param mixed $post_id: the post_id of which the value is saved against
295
+ * @param array $options: an array containing options
296
+ * boolean + load_value: load the field value or not. Defaults to true
297
+ * boolean + format_value: format the field value or not. Defaults to true
298
+ *
299
+ * @return array $return: an array containin the field groups
300
+ */
301
+
302
+ function get_field_object( $field_key, $post_id = false, $options = array() )
303
+ {
304
  // filter post_id
305
  $post_id = acf_filter_post_id( $post_id );
306
+ $field = false;
307
+ $orig_field_key = $field_key;
308
 
309
+
310
+ // defaults for options
311
+ $defaults = array(
312
+ 'load_value' => true,
313
+ 'format_value' => true,
 
 
 
 
 
 
 
 
314
  );
 
315
 
316
+ $options = array_merge($defaults, $options);
317
+
318
+
319
+ // is $field_name a name? pre 3.4.0
320
+ if( strpos($field_key, "field_") === false )
321
  {
322
+ // get field key
323
+ $field_key = get_field_reference( $field_key, $post_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  }
325
+
326
+
327
+ // get field
328
+ if( strpos($field_key, "field_") !== false )
329
  {
330
+ $field = apply_filters('acf/load_field', false, $field_key );
 
 
 
 
331
  }
332
 
 
 
 
333
 
334
+ // validate field
335
+ if( !$field )
 
336
  {
337
+ // treat as text field
338
+ $field = array(
339
+ 'type' => 'text',
340
+ 'name' => $orig_field_key,
341
+ 'key' => 'temp_key_for_' . $orig_field_key,
342
+ );
343
  }
344
 
 
 
 
 
345
 
346
+ // load value
347
+ if( $options['load_value'] )
348
+ {
349
+ $field['value'] = apply_filters('acf/load_value', false, $post_id, $field);
350
+
351
+
352
+ // format value
353
+ if( $options['format_value'] )
354
+ {
355
+ $field['value'] = apply_filters('acf/format_value_for_api', $field['value'], $post_id, $field);
356
+ }
357
+ }
358
+
359
+
360
+ return $field;
361
+
362
  }
363
 
364
 
365
+ /*
366
+ * the_field()
367
  *
368
+ * This function is the same as echo get_field().
369
  *
370
+ * @type function
371
+ * @since 1.0.3
372
+ * @date 29/01/13
373
+ *
374
+ * @param string $field_name: the name of the field - 'sub_heading'
375
+ * @param mixed $post_id: the post_id of which the value is saved against
376
+ *
377
+ * @return string $value
378
+ */
379
 
380
+ function the_field( $field_name, $post_id = false )
381
  {
382
  $value = get_field($field_name, $post_id);
383
 
384
+ if( is_array($value) )
385
  {
386
  $value = @implode(', ',$value);
387
  }
390
  }
391
 
392
 
393
+ /*
394
+ * has_sub_field()
395
  *
396
+ * This function is used inside a while loop to return either true or false (loop again or stop).
397
+ * When using a repeater or flexible content field, it will loop through the rows until
398
+ * there are none left or a break is detected
399
  *
400
+ * @type function
401
+ * @since 1.0.3
402
+ * @date 29/01/13
403
+ *
404
+ * @param string $field_name: the name of the field - 'sub_heading'
405
+ * @param mixed $post_id: the post_id of which the value is saved against
406
+ *
407
+ * @return bool
408
+ */
409
 
410
+ function has_sub_field( $field_name, $post_id = false )
411
  {
412
+
 
 
 
413
  // filter post_id
414
  $post_id = acf_filter_post_id( $post_id );
415
+
 
416
 
417
  // empty?
418
  if( empty($GLOBALS['acf_field']) )
419
  {
420
+ // vars
421
+ $f = get_field_object( $field_name, $post_id );
422
+ $v = $f['value'];
423
+ unset( $f['value'] );
424
+
425
+
426
  $GLOBALS['acf_field'][] = array(
427
  'name' => $field_name,
428
+ 'value' => $v,
429
+ 'field' => $f,
430
  'row' => -1,
431
  'post_id' => $post_id,
432
  );
433
  }
434
 
435
+
436
  // vars
437
  $depth = count( $GLOBALS['acf_field'] ) - 1;
438
  $name = $GLOBALS['acf_field'][$depth]['name'];
439
  $value = $GLOBALS['acf_field'][$depth]['value'];
440
+ $field = $GLOBALS['acf_field'][$depth]['field'];
441
  $row = $GLOBALS['acf_field'][$depth]['row'];
442
  $id = $GLOBALS['acf_field'][$depth]['post_id'];
443
 
445
  // if ID has changed, this is a new repeater / flexible field!
446
  if( $post_id != $id )
447
  {
448
+ // vars
449
+ $f = get_field_object( $field_name, $post_id );
450
+ $v = $f['value'];
451
+ unset( $f['value'] );
452
+
453
+
454
  $GLOBALS['acf_field'][] = array(
455
  'name' => $field_name,
456
+ 'value' => $v,
457
+ 'field' => $f,
458
  'row' => -1,
459
  'post_id' => $post_id,
460
  );
467
  if( $field_name != $name )
468
  {
469
  // is this a "new" while loop refering to a sub field?
470
+ if( isset($value[ $row ][ $field_name ]) )
471
  {
472
  $GLOBALS['acf_field'][] = array(
473
  'name' => $field_name,
474
+ 'value' => $value[ $row ][ $field_name ],
475
+ 'field' => acf_get_child_field_from_parent_field( $field_name, $field ),
476
  'row' => -1,
477
  'post_id' => $post_id,
478
  );
496
  // update vars
497
  $depth = count( $GLOBALS['acf_field'] ) - 1;
498
  $value = $GLOBALS['acf_field'][$depth]['value'];
499
+ $field = $GLOBALS['acf_field'][$depth]['field'];
500
  $row = $GLOBALS['acf_field'][$depth]['row'];
501
 
502
 
521
  }
522
 
523
 
524
+ /*
525
+ * has_sub_fields()
526
  *
527
+ * This function is a replica of 'has_sub_field'
528
  *
529
+ * @type function
530
+ * @since 4.0.0
531
+ * @date 29/01/13
532
+ *
533
+ * @param string $field_name: the name of the field - 'sub_heading'
534
+ * @param mixed $post_id: the post_id of which the value is saved against
535
+ *
536
+ * @return bool
537
+ */
538
 
539
+ function has_sub_fields( $field_name, $post_id = false )
540
+ {
541
+ return has_sub_field( $field_name, $post_id );
542
+ }
543
+
544
+
545
+ /*
546
+ * get_sub_field()
547
+ *
548
+ * This function is used inside a 'has_sub_field' while loop to return a sub field value
549
+ *
550
+ * @type function
551
+ * @since 1.0.3
552
+ * @date 29/01/13
553
+ *
554
+ * @param string $field_name: the name of the field - 'sub_heading'
555
+ *
556
+ * @return mixed $value
557
+ */
558
+
559
+ function get_sub_field( $field_name )
560
  {
561
 
562
  // no field?
569
  // vars
570
  $depth = count( $GLOBALS['acf_field'] ) - 1;
571
  $value = $GLOBALS['acf_field'][$depth]['value'];
572
+ $field = $GLOBALS['acf_field'][$depth]['field'];
573
  $row = $GLOBALS['acf_field'][$depth]['row'];
574
+
575
+
576
  // no value at i
577
+ if( !isset($value[ $row ][ $field_name ]) )
578
  {
579
  return false;
580
  }
581
+
582
 
583
+ return $value[ $row ][ $field_name ];
 
584
  }
585
 
586
 
587
+ /*
588
+ * get_sub_field()
589
  *
590
+ * This function is the same as echo get_sub_field
591
  *
592
+ * @type function
593
+ * @since 1.0.3
594
+ * @date 29/01/13
595
+ *
596
+ * @param string $field_name: the name of the field - 'sub_heading'
597
+ *
598
+ * @return string $value
599
+ */
600
 
601
  function the_sub_field($field_name)
602
  {
611
  }
612
 
613
 
614
+ /*
615
+ * get_sub_field_object()
616
  *
617
+ * This function is used inside a 'has_sub_field' while loop to return a sub field object
618
  *
619
+ * @type function
620
+ * @since 3.5.8.1
621
+ * @date 29/01/13
622
+ *
623
+ * @param string $field_name: the name of the field - 'sub_heading'
624
+ *
625
+ * @return array $sub_field
626
+ */
627
 
628
+ function get_sub_field_object( $child_name )
629
  {
630
+ // no field?
631
+ if( empty($GLOBALS['acf_field']) )
632
+ {
633
+ return false;
634
+ }
635
+
636
+
637
+ // vars
638
+ $depth = count( $GLOBALS['acf_field'] ) - 1;
639
+ $parent = $GLOBALS['acf_field'][$depth]['field'];
640
+
641
+
642
+ // return
643
+ return acf_get_child_field_from_parent_field( $child_name, $parent );
644
+
645
  }
646
 
647
+
648
+ /*
649
+ * acf_get_sub_field_from_parent_field()
650
+ *
651
+ * This function is used by the get_sub_field_object to find a sub field within a parent field
652
+ *
653
+ * @type function
654
+ * @since 3.5.8.1
655
+ * @date 29/01/13
656
+ *
657
+ * @param string $child_name: the name of the field - 'sub_heading'
658
+ * @param array $parent: the parent field object
659
+ *
660
+ * @return array $sub_field
661
+ */
662
+
663
+ function acf_get_child_field_from_parent_field( $child_name, $parent )
664
  {
665
+ // vars
666
+ $return = false;
667
+
668
+
669
+ // find child
670
+ if( isset($parent['sub_fields']) && is_array($parent['sub_fields']) )
671
+ {
672
+ foreach( $parent['sub_fields'] as $child )
673
+ {
674
+ if( $child['name'] == $child_name || $child['key'] == $child_name )
675
+ {
676
+ $return = $child;
677
+ break;
678
+ }
679
+ }
680
+ }
681
+ elseif( isset($parent['layouts']) && is_array($parent['layouts']) )
682
+ {
683
+ foreach( $parent['layouts'] as $layout )
684
+ {
685
+ if( isset($layout['sub_fields']) && is_array($layout['sub_fields']) )
686
+ {
687
+ foreach( $layout['sub_fields'] as $child )
688
+ {
689
+ if( $child['name'] == $child_name || $child['key'] == $child_name )
690
+ {
691
+ $return = $child;
692
+ break;
693
+ }
694
+ }
695
+ }
696
+ }
697
+ }
698
+
699
+
700
+ // return
701
+ return $return;
702
 
 
703
  }
 
704
 
705
 
706
+ /*
707
+ * register_field_group()
708
  *
709
+ * This function is used to register a field group via code. It acceps 1 array containing
710
+ * all the field group data. This data can be obtained by using teh export tool within ACF
711
  *
712
+ * @type function
713
+ * @since 3.0.6
714
+ * @date 29/01/13
715
+ *
716
+ * @param array $array: an array holding all the field group data
717
+ *
718
+ * @return
719
+ */
720
 
721
  $GLOBALS['acf_register_field_group'] = array();
722
 
723
+ function register_field_group( $array )
724
  {
725
  // add id
726
+ if( !isset($array['id']) )
727
  {
728
  $array['id'] = uniqid();
729
  }
742
  }
743
 
744
 
745
+ add_filter('acf/get_field_groups', 'api_acf_get_field_groups', 2, 1);
746
+ function api_acf_get_field_groups( $return )
747
  {
 
748
  // validate
749
  if( empty($GLOBALS['acf_register_field_group']) )
750
  {
751
  return $return;
752
  }
753
 
 
 
 
 
 
 
 
 
 
754
 
755
+ foreach( $GLOBALS['acf_register_field_group'] as $acf )
756
+ {
757
+ $return[] = array(
758
+ 'id' => $acf['id'],
759
+ 'title' => $acf['title'],
760
+ 'menu_order' => $acf['menu_order'],
761
+ );
762
+ }
763
+
764
 
765
  // order field groups based on menu_order, title
766
  // Obtain a list of columns
767
+ foreach( $return as $key => $row )
768
  {
769
  $menu_order[ $key ] = $row['menu_order'];
770
  $title[ $key ] = $row['title'];
781
  }
782
 
783
 
784
+ add_filter('acf/field_group/get_fields', 'api_acf_field_group_get_fields', 1, 2);
785
+ function api_acf_field_group_get_fields( $fields, $post_id )
786
+ {
787
+ // validate
788
+ if( !empty($GLOBALS['acf_register_field_group']) )
789
+ {
790
+ foreach( $GLOBALS['acf_register_field_group'] as $acf )
791
+ {
792
+ if( $acf['id'] == $post_id )
793
+ {
794
+ foreach( $acf['fields'] as $f )
795
+ {
796
+ $fields[] = apply_filters('acf/load_field', $f, $f['key']);
797
+ }
798
+
799
+ break;
800
+ }
801
+ }
802
+ }
803
 
804
+ return $fields;
805
+
806
+ }
807
+
808
+
809
+ add_filter('acf/load_field', 'api_acf_load_field', 1, 2);
810
+ function api_acf_load_field( $field, $field_key )
811
+ {
812
+ // validate
813
+ if( !empty($GLOBALS['acf_register_field_group']) )
814
+ {
815
+ foreach( $GLOBALS['acf_register_field_group'] as $acf )
816
+ {
817
+ if( !empty($acf['fields']) )
818
+ {
819
+ foreach( $acf['fields'] as $f )
820
+ {
821
+ if( $f['key'] == $field_key )
822
+ {
823
+ $field = $f;
824
+ break;
825
+ }
826
+ }
827
+ }
828
+ }
829
+ }
830
+
831
+ return $field;
832
+ }
833
 
 
834
 
835
+ add_filter('acf/field_group/get_location', 'api_acf_field_group_get_location', 1, 2);
836
+ function api_acf_field_group_get_location( $location, $post_id )
837
  {
838
+ // validate
839
+ if( !empty($GLOBALS['acf_register_field_group']) )
840
+ {
841
+ foreach( $GLOBALS['acf_register_field_group'] as $acf )
842
+ {
843
+ if( $acf['id'] == $post_id )
844
+ {
845
+ $location = $acf['location'];
846
+ break;
847
+ }
848
+ }
849
+ }
850
+
851
+ return $location;
852
  }
853
 
854
 
855
+
856
+ add_filter('acf/field_group/get_options', 'api_acf_field_group_get_options', 1, 2);
857
+ function api_acf_field_group_get_options( $options, $post_id )
858
  {
859
+ // validate
860
+ if( !empty($GLOBALS['acf_register_field_group']) )
861
+ {
862
+ foreach( $GLOBALS['acf_register_field_group'] as $acf )
863
+ {
864
+ if( $acf['id'] == $post_id )
865
+ {
866
+ $options = $acf['options'];
867
+ break;
868
+ }
869
+ }
870
+ }
871
 
872
  return $options;
873
  }
 
874
 
875
 
876
+ /*
877
+ * get_row_layout()
878
  *
879
+ * This function will return a string representation of the current row layout within a 'has_sub_field' loop
880
  *
881
+ * @type function
882
+ * @since 3.0.6
883
+ * @date 29/01/13
884
+ *
885
+ * @return $value - string containing the layout
886
+ */
887
 
888
  function get_row_layout()
889
  {
895
  }
896
 
897
 
898
+ /*
899
+ * acf_shortcode()
900
  *
901
+ * This function is used to add basic shortcode support for the ACF plugin
902
  *
903
+ * @type function
904
+ * @since 1.1.1
905
+ * @date 29/01/13
906
+ *
907
+ * @param array $atts: an array holding the shortcode options
908
+ * string + field: the field name
909
+ * mixed + post_id: the post_id to load from
910
+ *
911
+ * @return string $value: the value found by get_field
912
+ */
913
 
914
  function acf_shortcode( $atts )
915
  {
931
  $value = get_field( $field, $post_id );
932
 
933
 
934
+ if( is_array($value) )
935
  {
936
  $value = @implode( ', ',$value );
937
  }
941
  add_shortcode( 'acf', 'acf_shortcode' );
942
 
943
 
944
+ /*
945
+ * acf_form_head()
946
  *
947
+ * This function is placed at the very top of a template (before any HTML is rendered) and saves the $_POST data sent by acf_form.
948
  *
949
+ * @type function
950
+ * @since 1.1.4
951
+ * @date 29/01/13
952
+ *
953
+ * @param N/A
954
+ *
955
+ * @return N/A
956
+ */
957
 
958
  function acf_form_head()
959
  {
960
  // global vars
961
+ global $post_id;
 
962
 
963
 
964
+ // verify nonce
965
+ if( isset($_POST['acf_nonce']) && wp_verify_nonce($_POST['acf_nonce'], 'input') )
966
  {
967
  // $post_id to save against
968
  $post_id = $_POST['post_id'];
969
 
970
+
971
  // allow for custom save
972
+ $post_id = apply_filters('acf/pre_save_post', $post_id);
973
 
974
 
975
  // save the data
976
+ do_action('acf/save_post', $post_id);
977
 
978
 
979
  // redirect
982
  wp_redirect($_POST['return']);
983
  exit;
984
  }
 
985
  }
986
 
 
 
 
 
 
987
 
988
  // need wp styling
989
  wp_enqueue_style(array(
991
  ));
992
 
993
 
994
+ // actions
995
+ do_action('acf/input/admin_enqueue_scripts');
996
+
997
  add_action('wp_head', 'acf_form_wp_head');
998
 
999
  }
1000
 
1001
  function acf_form_wp_head()
1002
  {
1003
+ do_action('acf/input/admin_head');
 
1004
  }
1005
 
1006
 
1007
+ /*
1008
+ * acf_form()
1009
  *
1010
+ * This function is used to create an ACF form.
1011
  *
1012
+ * @type function
1013
+ * @since 1.1.4
1014
+ * @date 29/01/13
1015
+ *
1016
+ * @param array $options: an array containing many options to customize the form
1017
+ * string + post_id: post id to get field groups from and save data to. Default is false
1018
+ * array + field_groups: an array containing field group ID's. If this option is set,
1019
+ * the post_id will not be used to dynamically find the field groups
1020
+ * boolean + form: display the form tag or not. Defaults to true
1021
+ * array + form_attributes: an array containg attributes which will be added into the form tag
1022
+ * string + return: the return URL
1023
+ * string + html_before_fields: html inside form before fields
1024
+ * string + html_after_fields: html inside form after fields
1025
+ * string + submit_value: value of submit button
1026
+ * string + updated_message: default updated message. Can be false
1027
+ *
1028
+ * @return N/A
1029
+ */
1030
 
1031
+ function acf_form( $options = false )
1032
  {
1033
+ global $post;
1034
 
1035
 
1036
  // defaults
1037
  $defaults = array(
1038
+ 'post_id' => false,
1039
+ 'field_groups' => array(),
1040
  'form' => true,
1041
+ 'form_attributes' => array(
1042
  'class' => ''
1043
  ),
1044
+ 'return' => add_query_arg( 'updated', 'true', get_permalink() ),
1045
+ 'html_before_fields' => '',
1046
+ 'html_after_fields' => '',
1047
+ 'submit_value' => 'Update',
1048
+ 'updated_message' => 'Post updated.',
1049
  );
1050
 
1051
 
1052
  // merge defaults with options
1053
+ if( $options && is_array($options) )
1054
  {
1055
  $options = array_merge($defaults, $options);
1056
  }
1072
  'post_id' => $options['post_id']
1073
  );
1074
 
1075
+
1076
  if( strpos($options['post_id'], 'user_') !== false )
1077
  {
1078
  $user_id = str_replace('user_', '', $options['post_id']);
1079
+ $filter = array(
1080
+ 'ef_user' => $user_id
1081
+ );
1082
  }
1083
  elseif( strpos($options['post_id'], 'taxonomy_') !== false )
1084
  {
1085
  $taxonomy_id = str_replace('taxonomy_', '', $options['post_id']);
1086
+ $filter = array(
1087
+ 'ef_taxonomy' => $taxonomy_id
1088
+ );
1089
  }
1090
 
1091
 
1092
  $options['field_groups'] = array();
1093
  $options['field_groups'] = apply_filters( 'acf/location/match_field_groups', $options['field_groups'], $filter );
1094
  }
1095
+
1096
+
1097
  // updated message
1098
  if(isset($_GET['updated']) && $_GET['updated'] == 'true' && $options['updated_message'])
1099
  {
1110
  if( $options['form'] ): ?>
1111
  <form action="" id="post" method="post" <?php if($options['form_attributes']){foreach($options['form_attributes'] as $k => $v){echo $k . '="' . $v .'" '; }} ?>>
1112
  <?php endif; ?>
1113
+
1114
  <div style="display:none">
1115
+ <input type="hidden" name="acf_nonce" value="<?php echo wp_create_nonce( 'input' ); ?>" />
1116
  <input type="hidden" name="post_id" value="<?php echo $options['post_id']; ?>" />
1117
  <input type="hidden" name="return" value="<?php echo $options['return']; ?>" />
1118
  <?php wp_editor('', 'acf_settings'); ?>
1124
  // html before fields
1125
  echo $options['html_before_fields'];
1126
 
1127
+
1128
+ $acfs = apply_filters('acf/get_field_groups', array());
1129
+
1130
+ if( is_array($acfs) ){ foreach( $acfs as $acf ){
1131
+
1132
+ // only add the chosen field groups
1133
+ if( !in_array( $acf['id'], $options['field_groups'] ) )
1134
+ {
1135
+ continue;
1136
+ }
1137
+
1138
+
1139
+ // load options
1140
+ $acf['options'] = apply_filters('acf/field_group/get_options', array(), $acf['id']);
1141
+
1142
+
1143
+ // load fields
1144
+ $fields = apply_filters('acf/field_group/get_fields', array(), $acf['id']);
1145
+
1146
+
1147
+ echo '<div id="acf_' . $acf['id'] . '" class="postbox acf_postbox">';
1148
+ echo '<h3 class="hndle"><span>' . $acf['title'] . '</span></h3>';
1149
+ echo '<div class="inside">';
1150
+ echo '<div class="options" data-layout="' . $acf['options']['layout'] . '" data-show="1"></div>';
1151
+
1152
+ do_action('acf/create_fields', $fields, $options['post_id']);
1153
+
1154
+ echo '</div></div>';
1155
+
1156
+ }}
1157
+
1158
 
1159
  // html after fields
1160
  echo $options['html_after_fields'];
1168
  </div>
1169
  <!-- / Submit -->
1170
  <?php endif; ?>
1171
+
1172
  </div><!-- <div id="poststuff"> -->
1173
 
1174
  <?php if( $options['form'] ): ?>
1175
  </form>
1176
  <?php endif;
 
1177
  }
1178
 
1179
 
1180
+ /*
1181
+ * update_field()
1182
  *
1183
+ * This function will update a value in the database
1184
  *
1185
+ * @type function
1186
+ * @since 3.1.9
1187
+ * @date 29/01/13
1188
+ *
1189
+ * @param mixed $field_name: the name of the field - 'sub_heading'
1190
+ * @param mixed $value: the value to save in the database. The variable type is dependant on the field type
1191
+ * @param mixed $post_id: the post_id of which the value is saved against
1192
+ *
1193
+ * @return N/A
1194
+ */
1195
 
1196
+ function update_field( $field_key, $value, $post_id = false )
1197
  {
 
 
 
1198
  // filter post_id
1199
  $post_id = acf_filter_post_id( $post_id );
1200
 
1201
 
1202
+ // vars
1203
+ $options = array(
1204
+ 'load_value' => false,
1205
+ 'format_value' => false
1206
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1207
 
1208
+ $field = get_field_object( $field_key, $post_id, $options);
 
1209
 
1210
 
1211
+ if( !is_array($field) )
 
1212
  {
1213
  $field = array(
1214
  'type' => 'none',
1235
 
1236
 
1237
  // save
1238
+ do_action('acf/update_value', $value, $post_id, $field );
1239
 
1240
 
1241
  return true;
1243
  }
1244
 
1245
 
1246
+ /*
1247
+ * delete_field()
1248
  *
1249
+ * This function will remove a value from the database
1250
  *
1251
+ * @type function
1252
+ * @since 3.1.9
1253
+ * @date 29/01/13
 
1254
  *
1255
+ * @param mixed $field_name: the name of the field - 'sub_heading'
1256
+ * @param mixed $post_id: the post_id of which the value is saved against
1257
+ *
1258
+ * @return N/A
1259
+ */
1260
+
1261
+ function delete_field( $field_name, $post_id )
1262
+ {
1263
+ do_action('acf/delete_value', $post_id, $field_name );
1264
+ }
1265
+
1266
+
1267
+ /*
1268
+ * create_field()
1269
+ *
1270
+ * This function will creat the HTML for a field
1271
+ *
1272
+ * @type function
1273
+ * @since 4.0.0
1274
+ * @date 17/03/13
1275
+ *
1276
+ * @param array $field - an array containing all the field attributes
1277
+ *
1278
+ * @return N/A
1279
+ */
1280
+
1281
+ function create_field( $field )
1282
+ {
1283
+ do_action('acf/create_field', $field );
1284
+ }
1285
+
1286
+
1287
+ /*
1288
+ * acf_convert_field_names_to_keys()
1289
+ *
1290
+ * Helper for the update_field function
1291
+ *
1292
+ * @type function
1293
+ * @since 4.0.0
1294
+ * @date 17/03/13
1295
+ *
1296
+ * @param array $value: the value returned via get_field
1297
+ * @param array $field: the field or layout to find sub fields from
1298
+ *
1299
+ * @return N/A
1300
+ */
1301
 
1302
  function acf_convert_field_names_to_keys( $value, $field )
1303
  {
1320
 
1321
 
1322
  // loop through the values and format the array to use sub field keys
1323
+ if( is_array($value) )
1324
  {
1325
  foreach( $value as $row_i => $row)
1326
  {
1364
 
1365
 
1366
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1367
  /*
1368
  * Depreceated Functions
1369
  *
core/controllers/addons.php ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * acf_addons
5
+ *
6
+ * @description: controller for add-ons sub menu page
7
+ * @since: 3.6
8
+ * @created: 25/01/13
9
+ */
10
+
11
+ class acf_addons
12
+ {
13
+
14
+ var $action;
15
+
16
+
17
+ /*
18
+ * __construct
19
+ *
20
+ * @description:
21
+ * @since 3.1.8
22
+ * @created: 23/06/12
23
+ */
24
+
25
+ function __construct()
26
+ {
27
+ // actions
28
+ add_action('admin_menu', array($this,'admin_menu'), 11, 0);
29
+ }
30
+
31
+
32
+ /*
33
+ * admin_menu
34
+ *
35
+ * @description:
36
+ * @created: 2/08/12
37
+ */
38
+
39
+ function admin_menu()
40
+ {
41
+ // add page
42
+ $page = add_submenu_page('edit.php?post_type=acf', __('Add-Ons','acf'), __('Add-Ons','acf'), 'manage_options', 'acf-addons', array($this,'html'));
43
+
44
+
45
+ // actions
46
+ add_action('load-' . $page, array($this,'load'));
47
+ add_action('admin_print_scripts-' . $page, array($this, 'admin_print_scripts'));
48
+ add_action('admin_print_styles-' . $page, array($this, 'admin_print_styles'));
49
+ add_action('admin_head-' . $page, array($this,'admin_head'));
50
+ }
51
+
52
+
53
+ /*
54
+ * load
55
+ *
56
+ * @description:
57
+ * @since 3.5.2
58
+ * @created: 16/11/12
59
+ * @thanks: Kevin Biloski and Charlie Eriksen via Secunia SVCRP
60
+ */
61
+
62
+ function load()
63
+ {
64
+
65
+ }
66
+
67
+
68
+ /*
69
+ * admin_print_scripts
70
+ *
71
+ * @description:
72
+ * @since 3.1.8
73
+ * @created: 23/06/12
74
+ */
75
+
76
+ function admin_print_scripts()
77
+ {
78
+
79
+ }
80
+
81
+
82
+ /*
83
+ * admin_print_styles
84
+ *
85
+ * @description:
86
+ * @since 3.1.8
87
+ * @created: 23/06/12
88
+ */
89
+
90
+ function admin_print_styles()
91
+ {
92
+ wp_enqueue_style(array(
93
+ 'wp-pointer',
94
+ 'acf-global',
95
+ 'acf',
96
+ ));
97
+ }
98
+
99
+
100
+ /*
101
+ * admin_head
102
+ *
103
+ * @description:
104
+ * @since 3.1.8
105
+ * @created: 23/06/12
106
+ */
107
+
108
+ function admin_head()
109
+ {
110
+
111
+ }
112
+
113
+
114
+ /*
115
+ * html
116
+ *
117
+ * @description:
118
+ * @since 3.1.8
119
+ * @created: 23/06/12
120
+ */
121
+
122
+ function html()
123
+ {
124
+ // vars
125
+ $dir = apply_filters('acf/get_info', 'dir');
126
+
127
+
128
+ $active = array(
129
+ 'repeater' => class_exists('acf_field_repeater'),
130
+ 'gallery' => class_exists('acf_field_gallery'),
131
+ 'options_page' => class_exists('acf_options_page_plugin'),
132
+ 'flexible_content' => class_exists('acf_field_flexible_content')
133
+ );
134
+
135
+ ?>
136
+ <div class="wrap">
137
+
138
+ <div class="icon32" id="icon-acf"><br></div>
139
+ <h2 style="margin: 4px 0 15px;"><?php _e("Advanced Custom Fields Add-Ons",'acf'); ?></h2>
140
+
141
+ <p style="margin: 0 0 20px;"><?php _e("The following Add-ons are available to increase the functionality of the Advanced Custom Fields plugin.",'acf'); ?><br />
142
+ <?php _e("Each Add-on can be installed as a separate plugin (receives updates) or included in your theme (does not receive updates).",'acf'); ?></p>
143
+
144
+ <div class="acf-alert">
145
+ <p><strong><?php _e("Just updated to version 4?",'acf'); ?></strong> <?php _e("Activation codes have changed to plugins! Download your purchased add-ons",'acf'); ?> <a href="http://www.advancedcustomfields.com/add-ons-download/" target="_blank"><?php _e("here",'acf'); ?></a></p>
146
+ </div>
147
+
148
+ <div id="add-ons" class="clearfix">
149
+
150
+ <div class="add-on wp-box <?php if( $active['repeater'] ): ?>add-on-active<?php endif; ?>">
151
+ <img src="<?php echo $dir; ?>images/add-ons/repeater-field-thumb.jpg" />
152
+ <div class="inner">
153
+ <h3><?php _e("Repeater Field",'acf'); ?></h3>
154
+ <p><?php _e("Create infinite rows of repeatable data with this versatile interface!",'acf'); ?></p>
155
+ </div>
156
+ <div class="footer">
157
+ <?php if( $active['repeater'] ): ?>
158
+ <a class="button button-disabled"><span class="tick"></span><?php _e("Installed",'acf'); ?></a>
159
+ <?php else: ?>
160
+ <a target="_blank" href="http://www.advancedcustomfields.com/add-ons/repeater-field/" class="button"><?php _e("Purchase & Install",'acf'); ?></a>
161
+ <?php endif; ?>
162
+ </div>
163
+ </div>
164
+
165
+
166
+ <div class="add-on wp-box <?php if( $active['gallery'] ): ?>add-on-active<?php endif; ?>">
167
+ <img src="<?php echo $dir; ?>images/add-ons/gallery-field-thumb.jpg" />
168
+ <div class="inner">
169
+ <h3><?php _e("Gallery Field",'acf'); ?></h3>
170
+ <p><?php _e("Create image galleries in a simple and intuitive interface!",'acf'); ?></p>
171
+ </div>
172
+ <div class="footer">
173
+ <?php if( $active['gallery'] ): ?>
174
+ <a class="button button-disabled"><span class="tick"></span><?php _e("Installed",'acf'); ?></a>
175
+ <?php else: ?>
176
+ <a target="_blank" href="http://www.advancedcustomfields.com/add-ons/gallery-field/" class="button"><?php _e("Purchase & Install",'acf'); ?></a>
177
+ <?php endif; ?>
178
+ </div>
179
+ </div>
180
+
181
+
182
+ <div class="add-on wp-box <?php if( $active['options_page'] ): ?>add-on-active<?php endif; ?>">
183
+ <img src="<?php echo $dir; ?>images/add-ons/options-page-thumb.jpg" />
184
+ <div class="inner">
185
+ <h3><?php _e("Options Page",'acf'); ?></h3>
186
+ <p><?php _e("Create global data to use throughout your website!",'acf'); ?></p>
187
+ </div>
188
+ <div class="footer">
189
+ <?php if( $active['options_page'] ): ?>
190
+ <a class="button button-disabled"><span class="tick"></span><?php _e("Installed",'acf'); ?></a>
191
+ <?php else: ?>
192
+ <a target="_blank" href="http://www.advancedcustomfields.com/add-ons/options-page/" class="button"><?php _e("Purchase & Install",'acf'); ?></a>
193
+ <?php endif; ?>
194
+ </div>
195
+ </div>
196
+
197
+
198
+ <div class="add-on wp-box <?php if( $active['flexible_content'] ): ?>add-on-active<?php endif; ?>">
199
+ <img src="<?php echo $dir; ?>images/add-ons/flexible-content-field-thumb.jpg" />
200
+ <div class="inner">
201
+ <h3><?php _e("Flexible Content Field",'acf'); ?></h3>
202
+ <p><?php _e("Create unique designs with a flexible content layout manager!",'acf'); ?></p>
203
+ </div>
204
+ <div class="footer">
205
+ <?php if( $active['flexible_content'] ): ?>
206
+ <a class="button button-disabled"><span class="tick"></span><?php _e("Installed",'acf'); ?></a>
207
+ <?php else: ?>
208
+ <a target="_blank" href="http://www.advancedcustomfields.com/add-ons/flexible-content-field/" class="button"><?php _e("Purchase & Install",'acf'); ?></a>
209
+ <?php endif; ?>
210
+ </div>
211
+ </div>
212
+
213
+
214
+ </div>
215
+
216
+
217
+ </div>
218
+ <?php
219
+
220
+ return;
221
+
222
+ }
223
+ }
224
+
225
+ new acf_addons();
226
+
227
+ ?>
core/controllers/everything_fields.php CHANGED
@@ -2,27 +2,21 @@
2
 
3
  class acf_everything_fields
4
  {
5
-
6
- var $parent;
7
- var $dir;
8
- var $data;
9
 
10
- /*--------------------------------------------------------------------------------------
11
- *
12
- * Everything_fields
13
- *
14
- * @author Elliot Condon
15
- * @since 3.1.8
16
- *
17
- *-------------------------------------------------------------------------------------*/
18
 
19
- function __construct($parent)
20
- {
21
- // vars
22
- $this->parent = $parent;
23
- $this->dir = $parent->dir;
24
-
 
 
25
 
 
 
26
  // data for passing variables
27
  $this->data = array(
28
  'page_id' => '', // a string used to load values
@@ -35,7 +29,7 @@ class acf_everything_fields
35
 
36
  // actions
37
  add_action('admin_menu', array($this,'admin_menu'));
38
- add_action('wp_ajax_acf_everything_fields', array($this, 'acf_everything_fields'));
39
 
40
 
41
  // save
@@ -113,13 +107,13 @@ class acf_everything_fields
113
 
114
 
115
  // set page type
116
- $options = array();
117
 
118
  if( $pagenow == "admin.php" && isset( $_GET['page'], $_GET['id'] ) && $_GET['page'] == "shopp-categories" )
119
  {
120
 
121
  $this->data['page_type'] = "shopp_category";
122
- $options['ef_taxonomy'] = "shopp_category";
123
 
124
  $this->data['page_action'] = "add";
125
  $this->data['option_name'] = "";
@@ -135,7 +129,7 @@ class acf_everything_fields
135
  {
136
 
137
  $this->data['page_type'] = "taxonomy";
138
- $options['ef_taxonomy'] = $_GET['taxonomy'];
139
 
140
  $this->data['page_action'] = "add";
141
  $this->data['option_name'] = "";
@@ -151,7 +145,7 @@ class acf_everything_fields
151
  {
152
 
153
  $this->data['page_type'] = "user";
154
- $options['ef_user'] = get_current_user_id();
155
 
156
  $this->data['page_action'] = "edit";
157
  $this->data['option_name'] = "user_" . get_current_user_id();
@@ -161,7 +155,7 @@ class acf_everything_fields
161
  {
162
 
163
  $this->data['page_type'] = "user";
164
- $options['ef_user'] = $_GET['user_id'];
165
 
166
  $this->data['page_action'] = "edit";
167
  $this->data['option_name'] = "user_" . $_GET['user_id'];
@@ -170,7 +164,7 @@ class acf_everything_fields
170
  elseif( $pagenow == "user-new.php" )
171
  {
172
  $this->data['page_type'] = "user";
173
- $options['ef_user'] ='all';
174
 
175
  $this->data['page_action'] = "add";
176
  $this->data['option_name'] = "";
@@ -180,7 +174,7 @@ class acf_everything_fields
180
  {
181
 
182
  $this->data['page_type'] = "media";
183
- $options['ef_media'] = 'all';
184
 
185
  $this->data['page_action'] = "add";
186
  $this->data['option_name'] = "";
@@ -196,28 +190,38 @@ class acf_everything_fields
196
 
197
  // get field groups
198
  $metabox_ids = array();
199
- $this->data['metabox_ids'] = apply_filters( 'acf/location/match_field_groups', $metabox_ids, $options );
200
 
201
 
202
  // dont continue if no ids were found
203
- if(empty( $this->data['metabox_ids'] ))
204
  {
205
  return false;
206
  }
207
 
208
 
209
- // some fields require js + css
210
- do_action('acf_print_scripts-input');
211
- do_action('acf_print_styles-input');
212
-
213
-
214
- // Add admin head
215
  add_action('admin_head', array($this,'admin_head'));
216
 
217
 
218
  }
219
 
220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  /*--------------------------------------------------------------------------------------
222
  *
223
  * admin_head
@@ -233,80 +237,121 @@ class acf_everything_fields
233
 
234
 
235
  // add user js + css
236
- do_action('acf_head-input');
237
 
238
 
239
  ?>
240
- <script type="text/javascript">
241
- (function($){
242
 
243
- acf.data = {
244
- action : 'acf_everything_fields',
245
- metabox_ids : '<?php echo implode( ',', $this->data['metabox_ids'] ); ?>',
246
- page_type : '<?php echo $this->data['page_type']; ?>',
247
- page_action : '<?php echo $this->data['page_action']; ?>',
248
- option_name : '<?php echo $this->data['option_name']; ?>'
249
- };
250
-
251
- $(document).ready(function(){
252
 
253
- $.ajax({
254
- url: ajaxurl,
255
- data: acf.data,
256
- type: 'post',
257
- dataType: 'html',
258
- success: function(html){
259
-
 
 
260
  <?php
261
- if($this->data['page_type'] == "user")
262
- {
263
- if($this->data['page_action'] == "add")
264
- {
265
- echo "$('#createuser > table.form-table > tbody').append( html );";
266
- }
267
- else
268
- {
269
- echo "$('#your-profile > p.submit').before( html );";
270
- }
271
- }
272
- elseif($this->data['page_type'] == "shopp_category")
273
- {
274
- echo "$('#post-body-content').append( html );";
275
- }
276
- elseif($this->data['page_type'] == "taxonomy")
277
- {
278
- if($this->data['page_action'] == "add")
279
- {
280
- echo "$('#addtag > p.submit').before( html );";
281
- }
282
- else
283
- {
284
- echo "$('#edittag > p.submit').before( html );";
285
- }
286
- }
287
- elseif($this->data['page_type'] == "media")
288
- {
289
- if($this->data['page_action'] == "add")
290
- {
291
- echo "$('#addtag > p.submit').before( html );";
292
- }
293
- else
294
- {
295
- echo "$('#media-single-form table tbody tr.submit').before( html );";
296
- }
297
- }
298
  ?>
299
 
300
- setTimeout( function(){
301
- $(document).trigger('acf/setup_fields', $('#wpbody') );
302
- }, 200);
303
-
304
- }
305
- });
 
 
 
 
 
 
 
 
 
 
 
306
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  });
308
- })(jQuery);
309
- </script>
 
 
 
 
 
 
310
  <?php
311
  }
312
 
@@ -323,6 +368,13 @@ class acf_everything_fields
323
 
324
  function save_taxonomy( $term_id )
325
  {
 
 
 
 
 
 
 
326
  // for some weird reason, this is triggered by saving a menu...
327
  if( !isset($_POST['taxonomy']) )
328
  {
@@ -332,7 +384,7 @@ class acf_everything_fields
332
  // $post_id to save against
333
  $post_id = $_POST['taxonomy'] . '_' . $term_id;
334
 
335
- do_action('acf_save_post', $post_id);
336
  }
337
 
338
 
@@ -347,10 +399,18 @@ class acf_everything_fields
347
 
348
  function save_user( $user_id )
349
  {
 
 
 
 
 
 
 
350
  // $post_id to save against
351
  $post_id = 'user_' . $user_id;
352
 
353
- do_action('acf_save_post', $post_id);
 
354
  }
355
 
356
 
@@ -365,10 +425,19 @@ class acf_everything_fields
365
 
366
  function save_attachment( $post, $attachment )
367
  {
 
 
 
 
 
 
 
368
  // $post_id to save against
369
  $post_id = $post['ID'];
370
 
371
- do_action('acf_save_post', $post_id);
 
 
372
 
373
  return $post;
374
  }
@@ -384,10 +453,18 @@ class acf_everything_fields
384
 
385
  function shopp_category_saved( $category )
386
  {
 
 
 
 
 
 
 
387
  // $post_id to save against
388
  $post_id = 'shopp_category_' . $category->id;
389
 
390
- do_action('acf_save_post', $post_id);
 
391
  }
392
 
393
 
@@ -436,64 +513,67 @@ class acf_everything_fields
436
  }
437
 
438
 
439
- if($acfs)
440
  {
441
- foreach($acfs as $acf)
442
  {
 
 
 
 
443
  // only add the chosen field groups
444
  if( !in_array( $acf['id'], $options['metabox_ids'] ) )
445
  {
446
  continue;
447
  }
448
-
449
-
450
- // needs fields
451
- if(!$acf['fields'])
452
  {
453
- continue;
454
  }
455
 
456
- $title = "";
457
- if ( is_numeric( $acf['id'] ) )
458
- {
459
- $title = get_the_title( $acf['id'] );
460
- }
461
- else
462
- {
463
- $title = apply_filters( 'the_title', $acf['title'] );
464
- }
465
-
466
 
467
- // title
468
- if( $options['page_action'] == "edit" && !in_array($options['page_type'], array('media', 'shopp_category')) )
469
  {
470
- echo '<h3>' .$title . '</h3>';
471
- echo '<table class="form-table">';
472
  }
473
- elseif( $layout == 'metabox' )
 
 
 
 
 
 
474
  {
475
  echo '<div class="postbox acf_postbox" id="acf_'. $acf['id'] .'">';
476
- echo '<div title="Click to toggle" class="handlediv"><br></div><h3 class="hndle"><span>' . $title . '</span></h3>';
477
  echo '<div class="inside">';
478
  }
479
-
480
 
481
- // render
482
- foreach($acf['fields'] as $field)
483
- {
484
 
 
 
 
 
 
 
485
  // if they didn't select a type, skip this field
486
- if($field['type'] == 'null') continue;
487
 
488
- // set value
489
- $field['value'] = $this->parent->get_value( $options['option_name'], $field);
490
 
491
- // required
492
- if(!isset($field['required']))
493
  {
494
- $field['required'] = 0;
 
495
  }
496
 
 
 
497
  $required_class = "";
498
  $required_label = "";
499
 
@@ -506,7 +586,7 @@ class acf_everything_fields
506
 
507
  if( $layout == 'metabox' )
508
  {
509
- echo '<div id="acf-' . $field['name'] . '" class="field field-' . $field['type'] . ' field-'.$field['key'] . $required_class . '">';
510
 
511
  echo '<p class="label">';
512
  echo '<label for="fields[' . $field['key'] . ']">' . $field['label'] . $required_label . '</label>';
@@ -520,16 +600,18 @@ class acf_everything_fields
520
  }
521
  elseif( $layout == 'div' )
522
  {
523
- echo '<div id="acf-' . $field['name'] . '" class="form-field field field-' . $field['type'] . ' field-'.$field['key'] . $required_class . '">';
 
524
  echo '<label for="fields[' . $field['key'] . ']">' . $field['label'] . $required_label . '</label>';
525
  $field['name'] = 'fields[' . $field['key'] . ']';
526
  do_action('acf/create_field', $field );
527
  if($field['instructions']) echo '<p class="description">' . $field['instructions'] . '</p>';
 
528
  echo '</div>';
529
  }
530
  else
531
  {
532
- echo '<tr id="acf-' . $field['name'] . '" class="form-field field field-' . $field['type'] . ' field-'.$field['key'] . $required_class . '">';
533
  echo '<th valign="top" scope="row"><label for="fields[' . $field['key'] . ']">' . $field['label'] . $required_label . '</label></th>';
534
  echo '<td>';
535
  $field['name'] = 'fields[' . $field['key'] . ']';
@@ -541,20 +623,24 @@ class acf_everything_fields
541
 
542
  }
543
 
544
-
545
- }
546
- // foreach($fields as $field)
547
 
 
548
 
549
- // footer
550
- if( $options['page_action'] == "edit" && $options['page_type'] != "media")
551
  {
552
- echo '</table>';
553
  }
554
- elseif( $options['page_type'] == 'shopp_category' )
 
 
 
555
  {
556
- echo '</div></div>';
557
  }
 
 
558
  }
559
  // foreach($acfs as $acf)
560
  }
@@ -587,4 +673,6 @@ class acf_everything_fields
587
 
588
  }
589
 
 
 
590
  ?>
2
 
3
  class acf_everything_fields
4
  {
 
 
 
 
5
 
6
+ var $settings,
7
+ $data;
 
 
 
 
 
 
8
 
9
+
10
+ /*
11
+ * __construct
12
+ *
13
+ * @description:
14
+ * @since 3.1.8
15
+ * @created: 23/06/12
16
+ */
17
 
18
+ function __construct()
19
+ {
20
  // data for passing variables
21
  $this->data = array(
22
  'page_id' => '', // a string used to load values
29
 
30
  // actions
31
  add_action('admin_menu', array($this,'admin_menu'));
32
+ add_action('wp_ajax_acf/everything_fields', array($this, 'acf_everything_fields'));
33
 
34
 
35
  // save
107
 
108
 
109
  // set page type
110
+ $filter = array();
111
 
112
  if( $pagenow == "admin.php" && isset( $_GET['page'], $_GET['id'] ) && $_GET['page'] == "shopp-categories" )
113
  {
114
 
115
  $this->data['page_type'] = "shopp_category";
116
+ $filter['ef_taxonomy'] = "shopp_category";
117
 
118
  $this->data['page_action'] = "add";
119
  $this->data['option_name'] = "";
129
  {
130
 
131
  $this->data['page_type'] = "taxonomy";
132
+ $filter['ef_taxonomy'] = $_GET['taxonomy'];
133
 
134
  $this->data['page_action'] = "add";
135
  $this->data['option_name'] = "";
145
  {
146
 
147
  $this->data['page_type'] = "user";
148
+ $filter['ef_user'] = get_current_user_id();
149
 
150
  $this->data['page_action'] = "edit";
151
  $this->data['option_name'] = "user_" . get_current_user_id();
155
  {
156
 
157
  $this->data['page_type'] = "user";
158
+ $filter['ef_user'] = $_GET['user_id'];
159
 
160
  $this->data['page_action'] = "edit";
161
  $this->data['option_name'] = "user_" . $_GET['user_id'];
164
  elseif( $pagenow == "user-new.php" )
165
  {
166
  $this->data['page_type'] = "user";
167
+ $filter['ef_user'] ='all';
168
 
169
  $this->data['page_action'] = "add";
170
  $this->data['option_name'] = "";
174
  {
175
 
176
  $this->data['page_type'] = "media";
177
+ $filter['ef_media'] = 'all';
178
 
179
  $this->data['page_action'] = "add";
180
  $this->data['option_name'] = "";
190
 
191
  // get field groups
192
  $metabox_ids = array();
193
+ $this->data['metabox_ids'] = apply_filters( 'acf/location/match_field_groups', $metabox_ids, $filter );
194
 
195
 
196
  // dont continue if no ids were found
197
+ if( empty( $this->data['metabox_ids'] ) )
198
  {
199
  return false;
200
  }
201
 
202
 
203
+ // actions
204
+ add_action('admin_enqueue_scripts', array($this,'admin_enqueue_scripts'));
 
 
 
 
205
  add_action('admin_head', array($this,'admin_head'));
206
 
207
 
208
  }
209
 
210
 
211
+ /*
212
+ * admin_enqueue_scripts
213
+ *
214
+ * @description:
215
+ * @since: 3.6
216
+ * @created: 30/01/13
217
+ */
218
+
219
+ function admin_enqueue_scripts()
220
+ {
221
+ do_action('acf/input/admin_enqueue_scripts');
222
+ }
223
+
224
+
225
  /*--------------------------------------------------------------------------------------
226
  *
227
  * admin_head
237
 
238
 
239
  // add user js + css
240
+ do_action('acf/input/admin_head');
241
 
242
 
243
  ?>
244
+ <script type="text/javascript">
245
+ (function($){
246
 
247
+ acf.data = {
248
+ action : 'acf/everything_fields',
249
+ metabox_ids : '<?php echo implode( ',', $this->data['metabox_ids'] ); ?>',
250
+ page_type : '<?php echo $this->data['page_type']; ?>',
251
+ page_action : '<?php echo $this->data['page_action']; ?>',
252
+ option_name : '<?php echo $this->data['option_name']; ?>'
253
+ };
 
 
254
 
255
+ $(document).ready(function(){
256
+
257
+ $.ajax({
258
+ url: ajaxurl,
259
+ data: acf.data,
260
+ type: 'post',
261
+ dataType: 'html',
262
+ success: function(html){
263
+
264
  <?php
265
+ if($this->data['page_type'] == "user")
266
+ {
267
+ if($this->data['page_action'] == "add")
268
+ {
269
+ echo "$('#createuser > table.form-table > tbody').append( html );";
270
+ }
271
+ else
272
+ {
273
+ echo "$('#your-profile > p.submit').before( html );";
274
+ }
275
+ }
276
+ elseif($this->data['page_type'] == "shopp_category")
277
+ {
278
+ echo "$('#post-body-content').append( html );";
279
+ }
280
+ elseif($this->data['page_type'] == "taxonomy")
281
+ {
282
+ if($this->data['page_action'] == "add")
283
+ {
284
+ echo "$('#addtag > p.submit').before( html );";
285
+ }
286
+ else
287
+ {
288
+ echo "$('#edittag > table.form-table > tbody').append( html );";
289
+ }
290
+ }
291
+ elseif($this->data['page_type'] == "media")
292
+ {
293
+ if($this->data['page_action'] == "add")
294
+ {
295
+ echo "$('#addtag > p.submit').before( html );";
296
+ }
297
+ else
298
+ {
299
+ echo "$('#media-single-form table tbody tr.submit').before( html );";
300
+ }
301
+ }
302
  ?>
303
 
304
+ setTimeout( function(){
305
+ $(document).trigger('acf/setup_fields', $('#wpbody') );
306
+ }, 200);
307
+
308
+ }
309
+ });
310
+
311
+
312
+ /*
313
+ * Taxonomy Add
314
+ *
315
+ * @description:
316
+ * @since: 3.6
317
+ * @created: 24/02/13
318
+ */
319
+
320
+ $(document).ajaxComplete(function(event, xhr, settings) {
321
 
322
+ // vars
323
+ data = acf.helpers.url_to_object(settings.data);
324
+
325
+
326
+ // validate
327
+ if( data.action != 'add-tag' )
328
+ {
329
+ return;
330
+ }
331
+
332
+
333
+ // clear WYSIWYG field
334
+ $('#addtag').find('.acf_wysiwyg textarea').each(function(){
335
+
336
+
337
+ // vars
338
+ var textarea = $(this),
339
+ id = textarea.attr('id'),
340
+ editor = tinyMCE.get( id );
341
+
342
+ editor.setContent('');
343
+ editor.save();
344
+
345
+
346
  });
347
+
348
+ });
349
+
350
+ });
351
+
352
+
353
+ })(jQuery);
354
+ </script>
355
  <?php
356
  }
357
 
368
 
369
  function save_taxonomy( $term_id )
370
  {
371
+ // verify nonce
372
+ if( !isset($_POST['acf_nonce']) || !wp_verify_nonce($_POST['acf_nonce'], 'input') )
373
+ {
374
+ return $term_id;
375
+ }
376
+
377
+
378
  // for some weird reason, this is triggered by saving a menu...
379
  if( !isset($_POST['taxonomy']) )
380
  {
384
  // $post_id to save against
385
  $post_id = $_POST['taxonomy'] . '_' . $term_id;
386
 
387
+ do_action('acf/save_post', $post_id);
388
  }
389
 
390
 
399
 
400
  function save_user( $user_id )
401
  {
402
+ // verify nonce
403
+ if( !isset($_POST['acf_nonce']) || !wp_verify_nonce($_POST['acf_nonce'], 'input') )
404
+ {
405
+ return $user_id;
406
+ }
407
+
408
+
409
  // $post_id to save against
410
  $post_id = 'user_' . $user_id;
411
 
412
+
413
+ do_action('acf/save_post', $post_id);
414
  }
415
 
416
 
425
 
426
  function save_attachment( $post, $attachment )
427
  {
428
+ // verify nonce
429
+ if( !isset($_POST['acf_nonce']) || !wp_verify_nonce($_POST['acf_nonce'], 'input') )
430
+ {
431
+ return $post;
432
+ }
433
+
434
+
435
  // $post_id to save against
436
  $post_id = $post['ID'];
437
 
438
+
439
+ do_action('acf/save_post', $post_id);
440
+
441
 
442
  return $post;
443
  }
453
 
454
  function shopp_category_saved( $category )
455
  {
456
+ // verify nonce
457
+ if( !isset($_POST['acf_nonce']) || !wp_verify_nonce($_POST['acf_nonce'], 'input') )
458
+ {
459
+ return $category;
460
+ }
461
+
462
+
463
  // $post_id to save against
464
  $post_id = 'shopp_category_' . $category->id;
465
 
466
+
467
+ do_action('acf/save_post', $post_id);
468
  }
469
 
470
 
513
  }
514
 
515
 
516
+ if( $acfs )
517
  {
518
+ foreach( $acfs as $acf )
519
  {
520
+ // load options
521
+ $acf['options'] = apply_filters('acf/field_group/get_options', array(), $acf['id']);
522
+
523
+
524
  // only add the chosen field groups
525
  if( !in_array( $acf['id'], $options['metabox_ids'] ) )
526
  {
527
  continue;
528
  }
529
+
530
+
531
+ // title
532
+ if( $options['page_action'] == "edit" && $options['page_type'] == 'user' )
533
  {
534
+ echo '<h3>' .$acf['title'] . '</h3><table class="form-table"><tbody>';
535
  }
536
 
 
 
 
 
 
 
 
 
 
 
537
 
538
+ // wrapper
539
+ if( $layout == 'tr' )
540
  {
541
+ //nonce
542
+ echo '<tr><td colspan="2"><input type="hidden" name="acf_nonce" value="' . wp_create_nonce( 'input' ) . '" /></td></tr>';
543
  }
544
+ else
545
+ {
546
+ //nonce
547
+ echo '<input type="hidden" name="acf_nonce" value="' . wp_create_nonce( 'input' ) . '" />';
548
+ }
549
+
550
+ if( $layout == 'metabox' )
551
  {
552
  echo '<div class="postbox acf_postbox" id="acf_'. $acf['id'] .'">';
553
+ echo '<div title="Click to toggle" class="handlediv"><br></div><h3 class="hndle"><span>' . $acf['title'] . '</span></h3>';
554
  echo '<div class="inside">';
555
  }
 
556
 
 
 
 
557
 
558
+ // load fields
559
+ $fields = apply_filters('acf/field_group/get_fields', array(), $acf['id']);
560
+
561
+
562
+ if( is_array($fields) ){ foreach( $fields as $field ){
563
+
564
  // if they didn't select a type, skip this field
565
+ if( !$field['type'] || $field['type'] == 'null' ) continue;
566
 
 
 
567
 
568
+ // set value
569
+ if( !isset($field['value']) )
570
  {
571
+ $field['value'] = apply_filters('acf/load_value', false, $options['option_name'], $field);
572
+ $field['value'] = apply_filters('acf/format_value', $field['value'], $options['option_name'], $field);
573
  }
574
 
575
+
576
+ // required
577
  $required_class = "";
578
  $required_label = "";
579
 
586
 
587
  if( $layout == 'metabox' )
588
  {
589
+ echo '<div id="acf-' . $field['name'] . '" class="field field_type-' . $field['type'] . ' field_key-' . $field['key'] . $required_class . '" data-field_name="' . $field['name'] . '" data-field_key="' . $field['key'] . '" data-field_type="' . $field['type'] . '">';
590
 
591
  echo '<p class="label">';
592
  echo '<label for="fields[' . $field['key'] . ']">' . $field['label'] . $required_label . '</label>';
600
  }
601
  elseif( $layout == 'div' )
602
  {
603
+ echo '<div id="acf-' . $field['name'] . '" class="form-field field field_type-' . $field['type'] . ' field_key-' . $field['key'] . $required_class . '" data-field_name="' . $field['name'] . '" data-field_key="' . $field['key'] . '" data-field_type="' . $field['type'] . '">';
604
+
605
  echo '<label for="fields[' . $field['key'] . ']">' . $field['label'] . $required_label . '</label>';
606
  $field['name'] = 'fields[' . $field['key'] . ']';
607
  do_action('acf/create_field', $field );
608
  if($field['instructions']) echo '<p class="description">' . $field['instructions'] . '</p>';
609
+
610
  echo '</div>';
611
  }
612
  else
613
  {
614
+ echo '<tr id="acf-' . $field['name'] . '" class="form-field field field_type-' . $field['type'] . ' field_key-'.$field['key'] . $required_class . '" data-field_name="' . $field['name'] . '" data-field_key="' . $field['key'] . '" data-field_type="' . $field['type'] . '">';
615
  echo '<th valign="top" scope="row"><label for="fields[' . $field['key'] . ']">' . $field['label'] . $required_label . '</label></th>';
616
  echo '<td>';
617
  $field['name'] = 'fields[' . $field['key'] . ']';
623
 
624
  }
625
 
626
+ }}
 
 
627
 
628
+
629
 
630
+ // wrapper
631
+ if( $layout == 'metabox' )
632
  {
633
+ echo '</div></div>';
634
  }
635
+
636
+
637
+ // title
638
+ if( $options['page_action'] == "edit" && $options['page_type'] == 'user' )
639
  {
640
+ echo '</tbody></table>';
641
  }
642
+
643
+
644
  }
645
  // foreach($acfs as $acf)
646
  }
673
 
674
  }
675
 
676
+ new acf_everything_fields();
677
+
678
  ?>
core/controllers/export.php ADDED
@@ -0,0 +1,544 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * acf_export
5
+ *
6
+ * @description: controller for export sub menu page
7
+ * @since: 3.6
8
+ * @created: 25/01/13
9
+ */
10
+
11
+ class acf_export
12
+ {
13
+
14
+ var $action;
15
+
16
+
17
+ /*
18
+ * __construct
19
+ *
20
+ * @description:
21
+ * @since 3.1.8
22
+ * @created: 23/06/12
23
+ */
24
+
25
+ function __construct()
26
+ {
27
+ // vars
28
+ $this->action = '';
29
+
30
+
31
+ // actions
32
+ add_action('admin_menu', array($this,'admin_menu'), 11, 0);
33
+
34
+
35
+ // filters
36
+ add_filter('acf/export/clean_fields', array($this,'clean_fields'), 10, 1);
37
+ }
38
+
39
+
40
+ /*
41
+ * admin_menu
42
+ *
43
+ * @description:
44
+ * @created: 2/08/12
45
+ */
46
+
47
+ function admin_menu()
48
+ {
49
+ // add page
50
+ $page = add_submenu_page('edit.php?post_type=acf', __('Export','acf'), __('Export','acf'), 'manage_options', 'acf-export', array($this,'html'));
51
+
52
+
53
+ // actions
54
+ add_action('load-' . $page, array($this,'load'));
55
+ add_action('admin_print_scripts-' . $page, array($this, 'admin_print_scripts'));
56
+ add_action('admin_print_styles-' . $page, array($this, 'admin_print_styles'));
57
+ add_action('admin_head-' . $page, array($this,'admin_head'));
58
+ }
59
+
60
+
61
+ /*
62
+ * load
63
+ *
64
+ * @description:
65
+ * @since 3.5.2
66
+ * @created: 16/11/12
67
+ * @thanks: Kevin Biloski and Charlie Eriksen via Secunia SVCRP
68
+ */
69
+
70
+ function load()
71
+ {
72
+ // vars
73
+ $path = apply_filters('acf/get_info', 'path');
74
+
75
+
76
+ // verify nonce
77
+ if( isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'acf_nonce') )
78
+ {
79
+ if( isset($_POST['export_to_xml']) )
80
+ {
81
+ $this->action = 'export_to_xml';
82
+ }
83
+ elseif( isset($_POST['export_to_php']) )
84
+ {
85
+ $this->action = 'export_to_php';
86
+ }
87
+ }
88
+
89
+
90
+ // include export action
91
+ if( $this->action == 'export_to_xml' )
92
+ {
93
+ include_once($path . 'core/actions/export.php');
94
+ die;
95
+ }
96
+ }
97
+
98
+
99
+ /*
100
+ * admin_print_scripts
101
+ *
102
+ * @description:
103
+ * @since 3.1.8
104
+ * @created: 23/06/12
105
+ */
106
+
107
+ function admin_print_scripts()
108
+ {
109
+
110
+ }
111
+
112
+
113
+ /*
114
+ * admin_print_styles
115
+ *
116
+ * @description:
117
+ * @since 3.1.8
118
+ * @created: 23/06/12
119
+ */
120
+
121
+ function admin_print_styles()
122
+ {
123
+ wp_enqueue_style(array(
124
+ 'wp-pointer',
125
+ 'acf-global',
126
+ 'acf',
127
+ ));
128
+ }
129
+
130
+
131
+ /*
132
+ * admin_head
133
+ *
134
+ * @description:
135
+ * @since 3.1.8
136
+ * @created: 23/06/12
137
+ */
138
+
139
+ function admin_head()
140
+ {
141
+
142
+ }
143
+
144
+
145
+ /*
146
+ * html
147
+ *
148
+ * @description:
149
+ * @since 3.1.8
150
+ * @created: 23/06/12
151
+ */
152
+
153
+ function html()
154
+ {
155
+ ?>
156
+ <div class="wrap">
157
+
158
+ <div class="icon32" id="icon-acf"><br></div>
159
+ <h2 style="margin: 4px 0 25px;"><?php _e("Export",'acf'); ?></h2>
160
+ <?php
161
+
162
+ if( $this->action == "export_to_php" )
163
+ {
164
+ $this->html_php();
165
+ }
166
+ else
167
+ {
168
+ $this->html_index();
169
+ }
170
+
171
+ ?>
172
+ </div>
173
+ <?php
174
+
175
+ return;
176
+
177
+ }
178
+
179
+
180
+ /*
181
+ * html_index
182
+ *
183
+ * @description:
184
+ * @created: 9/08/12
185
+ */
186
+
187
+ function html_index()
188
+ {
189
+ // vars
190
+ $acfs = get_posts(array(
191
+ 'numberposts' => -1,
192
+ 'post_type' => 'acf',
193
+ 'orderby' => 'menu_order title',
194
+ 'order' => 'asc',
195
+ ));
196
+
197
+ // blank array to hold acfs
198
+ $choices = array();
199
+
200
+ if($acfs)
201
+ {
202
+ foreach($acfs as $acf)
203
+ {
204
+ // find title. Could use get_the_title, but that uses get_post(), so I think this uses less Memory
205
+ $title = apply_filters( 'the_title', $acf->post_title, $acf->ID );
206
+
207
+ $choices[$acf->ID] = $title;
208
+ }
209
+ }
210
+
211
+ ?>
212
+ <form method="post">
213
+ <input type="hidden" name="nonce" value="<?php echo wp_create_nonce( 'acf_nonce' ); ?>" />
214
+ <div class="wp-box">
215
+ <div class="title">
216
+ <h3><?php _e("Export Field Groups",'acf'); ?></h3>
217
+ </div>
218
+ <table class="acf_input widefat">
219
+ <tr>
220
+ <td class="label">
221
+ <label><?php _e("Field Groups",'acf'); ?></label>
222
+ <p class="description"><?php _e("Select the field groups to be exported",'acf'); ?></p>
223
+ </td>
224
+ <td>
225
+ <?php do_action('acf/create_field', array(
226
+ 'type' => 'select',
227
+ 'name' => 'acf_posts',
228
+ 'value' => '',
229
+ 'choices' => $choices,
230
+ 'multiple' => 1,
231
+ )); ?>
232
+ </td>
233
+ </tr>
234
+ <tr>
235
+ <td class="label"></td>
236
+ <td>
237
+ <ul class="hl clearfix">
238
+ <li>
239
+ <input type="submit" class="acf-button" name="export_to_xml" value="<?php _e("Export to XML",'acf'); ?>" />
240
+ </li>
241
+ <li>
242
+ <input type="submit" class="acf-button" name="export_to_php" value="<?php _e("Export to PHP",'acf'); ?>" />
243
+ </li>
244
+ </ul>
245
+ </td>
246
+ </tr>
247
+ </table>
248
+ </div>
249
+ </form>
250
+
251
+ <p><br /></p>
252
+ <h3><?php _e("Export to XML",'acf'); ?></h3>
253
+ <p><?php _e("ACF will create a .xml export file which is compatible with the native WP import plugin.",'acf'); ?></p>
254
+ <p><?php _e("Imported field groups <b>will</b> appear in the list of editable field groups. This is useful for migrating fields groups between Wp websites.",'acf'); ?></p>
255
+ <ol>
256
+ <li><?php _e("Select field group(s) from the list and click \"Export XML\"",'acf'); ?></li>
257
+ <li><?php _e("Save the .xml file when prompted",'acf'); ?></li>
258
+ <li><?php _e("Navigate to Tools &raquo; Import and select WordPress",'acf'); ?></li>
259
+ <li><?php _e("Install WP import plugin if prompted",'acf'); ?></li>
260
+ <li><?php _e("Upload and import your exported .xml file",'acf'); ?></li>
261
+ <li><?php _e("Select your user and ignore Import Attachments",'acf'); ?></li>
262
+ <li><?php _e("That's it! Happy WordPressing",'acf'); ?></li>
263
+ </ol>
264
+
265
+ <p><br /></p>
266
+
267
+ <h3><?php _e("Export to PHP",'acf'); ?></h3>
268
+ <p><?php _e("ACF will create the PHP code to include in your theme.",'acf'); ?></p>
269
+ <p><?php _e("Registered field groups <b>will not</b> appear in the list of editable field groups. This is useful for including fields in themes.",'acf'); ?></p>
270
+ <p><?php _e("Please note that if you export and register field groups within the same WP, you will see duplicate fields on your edit screens. To fix this, please move the origional field group to the trash or remove the code from your functions.php file.",'acf'); ?></p>
271
+ <ol>
272
+ <li><?php _e("Select field group(s) from the list and click \"Create PHP\"",'acf'); ?></li>
273
+ <li><?php _e("Copy the PHP code generated",'acf'); ?></li>
274
+ <li><?php _e("Paste into your functions.php file",'acf'); ?></li>
275
+ <li><?php _e("To activate any Add-ons, edit and use the code in the first few lines.",'acf'); ?></li>
276
+ </ol>
277
+ <?php
278
+
279
+ }
280
+
281
+
282
+ /*
283
+ * html_php
284
+ *
285
+ * @description:
286
+ * @created: 9/08/12
287
+ */
288
+
289
+ function html_php()
290
+ {
291
+
292
+ ?>
293
+ <div class="wp-box">
294
+ <div class="title">
295
+ <h3><?php _e("Export Field Groups to PHP",'acf'); ?></h3>
296
+ </div>
297
+ <table class="acf_input widefat">
298
+ <tr>
299
+ <td class="label">
300
+ <h3><?php _e("Instructions",'acf'); ?></h3>
301
+ <ol>
302
+ <li><?php _e("Copy the PHP code generated",'acf'); ?></li>
303
+ <li><?php _e("Paste into your functions.php file",'acf'); ?></li>
304
+ <li><?php _e("To activate any Add-ons, edit and use the code in the first few lines.",'acf'); ?></li>
305
+ </ol>
306
+
307
+ <p><br /></p>
308
+
309
+ <h3><?php _e("Notes",'acf'); ?></h3>
310
+ <p><?php _e("Registered field groups <b>will not</b> appear in the list of editable field groups. This is useful for including fields in themes.",'acf'); ?></p>
311
+ <p><?php _e("Please note that if you export and register field groups within the same WP, you will see duplicate fields on your edit screens. To fix this, please move the origional field group to the trash or remove the code from your functions.php file.",'acf'); ?></p>
312
+
313
+
314
+ <p><br /></p>
315
+
316
+ <h3><?php _e("Include in theme",'acf'); ?></h3>
317
+ <p><?php _e("The Advanced Custom Fields plugin can be included within a theme. To do so, move the ACF plugin inside your theme and add the following code to your functions.php file:",'acf'); ?></p>
318
+
319
+ <pre>
320
+ include_once('advanced-custom-fields/acf.php');
321
+ </pre>
322
+
323
+ <p><?php _e("To remove all visual interfaces from the ACF plugin, you can use a constant to enable lite mode. Add the following code to you functions.php file <b>before</b> the include_once code:",'acf'); ?></p>
324
+
325
+ <pre>
326
+ define( 'ACF_LITE', true );
327
+ </pre>
328
+
329
+ <p><br /></p>
330
+
331
+ <p><a href="">&laquo; <?php _e("Back to export",'acf'); ?></a></p>
332
+ </td>
333
+ <td>
334
+ <textarea class="pre" readonly="true"><?php
335
+
336
+ $acfs = array();
337
+
338
+ if( isset($_POST['acf_posts']) )
339
+ {
340
+ $acfs = get_posts(array(
341
+ 'numberposts' => -1,
342
+ 'post_type' => 'acf',
343
+ 'orderby' => 'menu_order title',
344
+ 'order' => 'asc',
345
+ 'include' => $_POST['acf_posts'],
346
+ 'suppress_filters' => false,
347
+ ));
348
+ }
349
+ if( $acfs )
350
+ {
351
+ ?>
352
+ <?php _e("/**
353
+ * Install Add-ons
354
+ *
355
+ * The following code will include all 4 premium Add-Ons in your theme.
356
+ * Please do not attempt to include a file which does not exist. This will produce an error.
357
+ *
358
+ * All fields must be included during the 'acf/register_fields' action.
359
+ * Other types of Add-ons (like the options page) can be included outside of this action.
360
+ *
361
+ * The following code assumes you have a folder 'add-ons' inside your theme.
362
+ *
363
+ * IMPORTANT
364
+ * Add-ons may be included in a premium theme as outlined in the terms and conditions.
365
+ * However, they are NOT to be included in a premium / free plugin.
366
+ * For more information, please read http://www.advancedcustomfields.com/terms-conditions/
367
+ */",'acf'); ?>
368
+
369
+
370
+ // <?php _e("Fields",'acf'); ?>
371
+ add_action('acf/register_fields', 'my_register_fields');
372
+
373
+ function my_register_fields()
374
+ {
375
+ //include_once('add-ons/acf-repeater/repeater.php');
376
+ //include_once('add-ons/acf-gallery/gallery.php');
377
+ //include_once('add-ons/acf-flexible-content/flexible-content.php');
378
+ }
379
+
380
+ // <?php _e("Options Page",'acf'); ?>
381
+ //include_once( 'add-ons/acf-options-page/acf-options-page.php' );
382
+
383
+
384
+ <?php _e("/**
385
+ * Register Field Groups
386
+ *
387
+ * The register_field_group function accepts 1 array which holds the relevant data to register a field group
388
+ * You may edit the array as you see fit. However, this may result in errors if the array is not compatible with ACF
389
+ */",'acf'); ?>
390
+
391
+
392
+ if(function_exists("register_field_group"))
393
+ {
394
+ <?php
395
+ foreach( $acfs as $i => $acf )
396
+ {
397
+ // populate acfs
398
+ $var = array(
399
+ 'id' => $acf->post_name,
400
+ 'title' => $acf->post_title,
401
+ 'fields' => apply_filters('acf/field_group/get_fields', array(), $acf->ID),
402
+ 'location' => apply_filters('acf/field_group/get_location', array(), $acf->ID),
403
+ 'options' => apply_filters('acf/field_group/get_options', array(), $acf->ID),
404
+ 'menu_order' => $acf->menu_order,
405
+ );
406
+
407
+
408
+ $var['fields'] = apply_filters('acf/export/clean_fields', $var['fields']);
409
+
410
+
411
+ // create html
412
+ $html = var_export($var, true);
413
+
414
+ // change double spaces to tabs
415
+ $html = str_replace(" ", "\t", $html);
416
+
417
+ // correctly formats "=> array("
418
+ $html = preg_replace('/([\t\r\n]+?)array/', 'array', $html);
419
+
420
+ // Remove number keys from array
421
+ $html = preg_replace('/[0-9] => array/', 'array', $html);
422
+
423
+ // add extra tab at start of each line
424
+ $html = str_replace("\n", "\n\t", $html);
425
+
426
+ ?> register_field_group(<?php echo $html ?>);
427
+ <?php
428
+ }
429
+ ?>
430
+ }
431
+ <?php
432
+ }
433
+ else
434
+ {
435
+ _e("No field groups were selected",'acf');
436
+ }
437
+ ?></textarea>
438
+ </td>
439
+ </tr>
440
+ </table>
441
+ </div>
442
+ <script type="text/javascript">
443
+ (function($){
444
+
445
+ var i = 0;
446
+
447
+ $('textarea.pre').live( 'mousedown', function (){
448
+
449
+ if( i == 0 )
450
+ {
451
+ i++;
452
+
453
+ $(this).focus().select();
454
+
455
+ return false;
456
+ }
457
+
458
+ });
459
+
460
+
461
+ $('textarea.pre').live( 'keyup', function (){
462
+ $(this).height( 0 );
463
+ $(this).height( this.scrollHeight );
464
+ });
465
+
466
+
467
+ $(document).ready(function(){
468
+
469
+ $('textarea.pre').trigger('keyup');
470
+
471
+ });
472
+
473
+ })(jQuery);
474
+ </script>
475
+ <?php
476
+ }
477
+
478
+
479
+ /*
480
+ * clean_fields
481
+ *
482
+ * @description:
483
+ * @since: 3.5.7
484
+ * @created: 7/03/13
485
+ */
486
+
487
+ function clean_fields( $fields )
488
+ {
489
+ // trim down the fields
490
+ if( $fields )
491
+ {
492
+ foreach( $fields as $i => $field )
493
+ {
494
+ // unset unneccessary bits
495
+ unset( $field['id'], $field['class'], $field['order_no'] );
496
+
497
+
498
+ // instructions
499
+ if( !$field['instructions'] )
500
+ {
501
+ unset( $field['instructions'] );
502
+ }
503
+
504
+
505
+ // Required
506
+ if( !$field['required'] )
507
+ {
508
+ unset( $field['required'] );
509
+ }
510
+
511
+
512
+ // conditional logic
513
+ if( !$field['conditional_logic']['status'] )
514
+ {
515
+ unset( $field['conditional_logic'] );
516
+ }
517
+
518
+
519
+ // children
520
+ if( isset($field['sub_fields']) )
521
+ {
522
+ $field['sub_fields'] = apply_filters('acf/export/clean_fields', $field['sub_fields']);
523
+ }
524
+ elseif( isset($field['layouts']) )
525
+ {
526
+ foreach( $field['layouts'] as $l => $layout )
527
+ {
528
+ $field['layouts'][ $l ]['sub_fields'] = apply_filters('acf/export/clean_fields', $layout['sub_fields']);
529
+ }
530
+ }
531
+
532
+
533
+ // override field
534
+ $fields[ $i ] = $field;
535
+ }
536
+ }
537
+
538
+ return $fields;
539
+ }
540
+ }
541
+
542
+ new acf_export();
543
+
544
+ ?>
core/controllers/field_group.php CHANGED
@@ -1,20 +1,18 @@
1
  <?php
2
 
3
  /*
4
- * Field Group
5
  *
6
- * @description: All the functionality for creating / editing a field group
7
- * @since 3.2.6
8
- * @created: 23/06/12
9
  */
10
 
11
-
12
  class acf_field_group
13
  {
14
-
15
- var $parent,
16
- $data;
17
-
18
 
19
  /*
20
  * __construct
@@ -24,35 +22,240 @@ class acf_field_group
24
  * @created: 23/06/12
25
  */
26
 
27
- function __construct($parent)
28
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  // vars
31
- $this->parent = $parent;
 
 
 
 
32
 
33
 
34
- // actions
35
- add_action('admin_print_scripts', array($this,'admin_print_scripts'));
36
- add_action('admin_print_styles', array($this,'admin_print_styles'));
37
- add_action('admin_head', array($this,'admin_head'));
38
- add_action('save_post', array($this, 'save_post'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
 
41
- // filters
42
- add_filter('name_save_pre', array($this, 'save_name'));
 
 
 
 
 
 
 
 
 
 
 
 
43
 
 
 
 
 
 
44
 
45
- // ajax
46
- add_action('wp_ajax_acf_field_options', array($this, 'ajax_acf_field_options'));
47
- add_action('wp_ajax_acf_location', array($this, 'ajax_acf_location'));
48
- add_action('wp_ajax_acf_next_field_id', array($this, 'ajax_acf_next_field_id'));
 
 
 
 
 
 
49
  }
50
 
51
 
52
  /*
53
  * validate_page
54
  *
55
- * @description: returns true | false. Used to stop a function from continuing
56
  * @since 3.2.6
57
  * @created: 23/06/12
58
  */
@@ -62,7 +265,7 @@ class acf_field_group
62
  // global
63
  global $pagenow, $typenow;
64
 
65
-
66
  // vars
67
  $return = false;
68
 
@@ -83,20 +286,24 @@ class acf_field_group
83
  // return
84
  return $return;
85
  }
86
-
87
 
88
  /*
89
- * admin_print_scripts
90
  *
91
- * @description:
92
- * @since 3.1.8
93
- * @created: 23/06/12
94
  */
95
 
96
- function admin_print_scripts()
97
  {
98
  // validate page
99
- if( ! $this->validate_page() ) return;
 
 
 
 
100
 
101
 
102
  // no autosave
@@ -109,24 +316,6 @@ class acf_field_group
109
  ));
110
 
111
 
112
- do_action('acf_print_scripts-fields');
113
- }
114
-
115
-
116
- /*
117
- * admin_print_styles
118
- *
119
- * @description:
120
- * @since 3.1.8
121
- * @created: 23/06/12
122
- */
123
-
124
- function admin_print_styles()
125
- {
126
- // validate page
127
- if( ! $this->validate_page() ) return;
128
-
129
-
130
  // custom styles
131
  wp_enqueue_style(array(
132
  'acf-global',
@@ -134,7 +323,9 @@ class acf_field_group
134
  ));
135
 
136
 
137
- do_action('acf_print_styles-fields');
 
 
138
 
139
  }
140
 
@@ -149,10 +340,6 @@ class acf_field_group
149
 
150
  function admin_head()
151
  {
152
- // validate page
153
- if( ! $this->validate_page() ) return;
154
-
155
-
156
  global $post;
157
 
158
 
@@ -163,13 +350,13 @@ class acf_field_group
163
  </script>';
164
 
165
 
166
- do_action('acf_head-fields');
167
 
168
 
169
  // add metaboxes
170
- add_meta_box('acf_fields', __("Fields",'acf'), array($this, 'meta_box_fields'), 'acf', 'normal', 'high');
171
- add_meta_box('acf_location', __("Location",'acf'), array($this, 'meta_box_location'), 'acf', 'normal', 'high');
172
- add_meta_box('acf_options', __("Options",'acf'), array($this, 'meta_box_options'), 'acf', 'normal', 'high');
173
 
174
 
175
  // add screen settings
@@ -178,76 +365,77 @@ class acf_field_group
178
 
179
 
180
  /*
181
- * screen_settings
182
  *
183
  * @description:
184
- * @created: 4/09/12
 
185
  */
186
 
187
- function screen_settings( $current )
188
  {
189
- $current .= '<h5>' . __("Fields",'acf') . '</h5>';
190
-
191
- $current .= '<div class="show-field_key">Show Field Key:';
192
- $current .= '<label class="show-field_key-no"><input checked="checked" type="radio" value="0" name="show-field_key" /> No</label>';
193
- $current .= '<label class="show-field_key-yes"><input type="radio" value="1" name="show-field_key" /> Yes</label>';
194
- $current .= '</div>';
195
-
196
- return $current;
197
  }
198
 
199
 
200
  /*
201
- * meta_box_fields
202
  *
203
  * @description:
204
  * @since 1.0.0
205
  * @created: 23/06/12
206
  */
207
-
208
- function meta_box_fields()
209
  {
210
- include( $this->parent->path . 'core/views/meta_box_fields.php' );
211
  }
212
 
213
 
214
  /*
215
- * meta_box_location
216
  *
217
  * @description:
218
  * @since 1.0.0
219
  * @created: 23/06/12
220
  */
221
-
222
- function meta_box_location()
223
  {
224
- include( $this->parent->path . 'core/views/meta_box_location.php' );
225
  }
226
 
227
 
228
  /*
229
- * meta_box_options
230
  *
231
  * @description:
232
- * @since 1.0.0
233
- * @created: 23/06/12
234
  */
235
 
236
- function meta_box_options()
237
  {
238
- include( $this->parent->path . 'core/views/meta_box_options.php' );
 
 
 
 
 
 
 
239
  }
240
 
241
 
242
  /*
243
- * ajax_acf_field_options
244
  *
245
  * @description: creates the HTML for a field's options (field group edit page)
246
  * @since 3.1.6
247
  * @created: 23/06/12
248
  */
249
 
250
- function ajax_acf_field_options()
251
  {
252
  // vars
253
  $options = array(
@@ -268,7 +456,6 @@ class acf_field_group
268
  }
269
 
270
 
271
-
272
  // required
273
  if( ! $options['field_type'] )
274
  {
@@ -281,11 +468,13 @@ class acf_field_group
281
  $options['field_key'] = str_replace("][type]", "", $options['field_key']) ;
282
 
283
 
284
-
285
- $field = array();
286
-
287
  // render options
288
- $this->parent->fields[ $options['field_type'] ]->create_options($options['field_key'], $field);
 
 
 
 
 
289
 
290
  die();
291
 
@@ -293,14 +482,14 @@ class acf_field_group
293
 
294
 
295
  /*
296
- * ajax_acf_location
297
  *
298
  * @description: creates the HTML for the field group location metabox. Called from both Ajax and PHP
299
  * @since 3.1.6
300
  * @created: 23/06/12
301
  */
302
 
303
- function ajax_acf_location($options = array())
304
  {
305
  // defaults
306
  $defaults = array(
@@ -309,8 +498,15 @@ class acf_field_group
309
  'param' => null,
310
  );
311
 
 
 
 
 
 
 
 
312
  // Is AJAX call?
313
- if(isset($_POST['action']) && $_POST['action'] == "acf_location")
314
  {
315
  $options = array_merge($defaults, $_POST);
316
  }
@@ -319,6 +515,10 @@ class acf_field_group
319
  $options = array_merge($defaults, $options);
320
  }
321
 
 
 
 
 
322
 
323
  // some case's have the same outcome
324
  if($options['param'] == "page_parent")
@@ -327,15 +527,12 @@ class acf_field_group
327
  }
328
 
329
 
330
- $choices = array();
331
- $optgroup = false;
332
-
333
  switch($options['param'])
334
  {
335
  case "post_type":
336
 
337
  // all post types except attachment
338
- $choices = $this->parent->get_post_types( array('attachment') );
339
 
340
  break;
341
 
@@ -403,8 +600,9 @@ class acf_field_group
403
  $choices = array(
404
  'front_page' => __("Front Page",'acf'),
405
  'posts_page' => __("Posts Page",'acf'),
406
- 'parent' => __("Parent Page",'acf'),
407
- 'child' => __("Child Page",'acf'),
 
408
  );
409
 
410
  break;
@@ -495,30 +693,11 @@ class acf_field_group
495
 
496
  break;
497
 
498
- case "options_page" :
499
-
500
- $defaults = $this->parent->defaults['options_page'];
501
-
502
- $choices = array(
503
- 'acf-options' => $defaults['title']
504
- );
505
-
506
- $titles = $defaults['pages'];
507
- if( !empty($titles) )
508
- {
509
- $choices = array();
510
- foreach( $titles as $title )
511
- {
512
- $slug = 'acf-options-' . sanitize_title( $title );
513
- $choices[ $slug ] = $title;
514
- }
515
- }
516
-
517
- break;
518
-
519
  case "taxonomy" :
520
 
521
- $choices = $this->parent->get_taxonomies_for_select( array('simple_value' => true) );
 
 
522
  $optgroup = true;
523
 
524
  break;
@@ -573,8 +752,9 @@ class acf_field_group
573
  'optgroup' => $optgroup,
574
  ));
575
 
 
576
  // ajax?
577
- if(isset($_POST['action']) && $_POST['action'] == "acf_location")
578
  {
579
  die();
580
  }
@@ -583,7 +763,7 @@ class acf_field_group
583
 
584
 
585
  /*
586
- * save_name
587
  *
588
  * @description: intercepts the acf post obejct and adds an "acf_" to the start of
589
  * it's name to stop conflicts between acf's and page's urls
@@ -591,12 +771,24 @@ class acf_field_group
591
  * @created: 23/06/12
592
  */
593
 
594
- function save_name($name)
595
  {
596
- if (isset($_POST['post_type']) && $_POST['post_type'] == 'acf')
597
- {
598
- $name = 'acf_' . sanitize_title_with_dashes($_POST['post_title']);
599
- }
 
 
 
 
 
 
 
 
 
 
 
 
600
 
601
  return $name;
602
  }
@@ -611,17 +803,19 @@ class acf_field_group
611
  */
612
 
613
  function save_post($post_id)
614
- {
615
-
616
- // only for save acf
617
- if( ! isset($_POST['acf_field_group']) || ! wp_verify_nonce($_POST['acf_field_group'], 'acf_field_group') )
618
  {
619
  return $post_id;
620
  }
621
 
622
 
623
- // do not save if this is an auto save routine
624
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
 
 
 
625
 
626
 
627
  // only save once! WordPress save's a revision as well.
@@ -635,20 +829,19 @@ class acf_field_group
635
  * save fields
636
  */
637
 
638
-
639
  // vars
640
  $dont_delete = array();
641
 
642
 
643
-
644
  if( $_POST['fields'] )
645
  {
646
  $i = -1;
647
-
648
 
649
  // remove clone field
650
  unset( $_POST['fields']['field_clone'] );
651
 
 
652
 
653
  // loop through and save fields
654
  foreach( $_POST['fields'] as $key => $field )
@@ -661,18 +854,15 @@ class acf_field_group
661
  $field['key'] = $key;
662
 
663
 
664
- // trim key
665
- $field['key'] = preg_replace('/\s+/' , '' , $field['key']);
666
-
667
-
668
  // save
669
- $this->parent->update_field( $post_id, $field);
670
 
671
 
672
  // add to dont delete array
673
  $dont_delete[] = $field['key'];
674
  }
675
  }
 
676
 
677
 
678
  // delete all other field
@@ -682,7 +872,7 @@ class acf_field_group
682
  if( strpos($key, 'field_') !== false && !in_array($key, $dont_delete) )
683
  {
684
  // this is a field, and it wasn't found in the dont_delete array
685
- delete_post_meta($post_id, $key);
686
  }
687
  }
688
 
@@ -703,59 +893,32 @@ class acf_field_group
703
  add_post_meta($post_id, 'rule', $rule);
704
  }
705
  }
 
706
 
707
 
708
  /*
709
  * save options
710
  */
711
 
712
- $options = $_POST['options'];
713
-
714
- if(!isset($options['position'])) { $options['position'] = 'normal'; }
715
- if(!isset($options['layout'])) { $options['layout'] = 'default'; }
716
- if(!isset($options['hide_on_screen'])) { $options['hide_on_screen'] = array(); }
 
717
 
718
  update_post_meta($post_id, 'position', $options['position']);
719
  update_post_meta($post_id, 'layout', $options['layout']);
720
  update_post_meta($post_id, 'hide_on_screen', $options['hide_on_screen']);
721
 
 
722
 
723
 
724
  }
725
-
726
 
727
- /*
728
- * ajax_next_field_id
729
- *
730
- * @description:
731
- * @since: 2.0.4
732
- * @created: 5/12/12
733
- */
734
-
735
- function ajax_acf_next_field_id()
736
- {
737
- // vars
738
- $options = array(
739
- 'nonce' => '',
740
- );
741
- $options = array_merge($options, $_POST);
742
-
743
-
744
- // verify nonce
745
- if( ! wp_verify_nonce($options['nonce'], 'acf_nonce') )
746
- {
747
- die(0);
748
- }
749
-
750
-
751
- // return id
752
- $id = $this->parent->get_next_field_id();
753
-
754
-
755
- // die
756
- die( 'field_' . $id );
757
- }
758
-
759
  }
760
 
 
 
761
  ?>
1
  <?php
2
 
3
  /*
4
+ * acf_field_group
5
  *
6
+ * @description: controller for editing a field group
7
+ * @since: 3.6
8
+ * @created: 25/01/13
9
  */
10
 
 
11
  class acf_field_group
12
  {
13
+
14
+ var $settings;
15
+
 
16
 
17
  /*
18
  * __construct
22
  * @created: 23/06/12
23
  */
24
 
25
+ function __construct()
26
  {
27
+ // actions
28
+ add_action('admin_enqueue_scripts', array($this,'admin_enqueue_scripts'));
29
+
30
+
31
+ // filters
32
+ add_filter('acf/get_field_groups', array($this, 'get_field_groups'), 1, 1);
33
+ add_filter('acf/field_group/get_fields', array($this, 'get_fields'), 5, 2);
34
+ add_filter('acf/field_group/get_location', array($this, 'get_location'), 5, 2);
35
+ add_filter('acf/field_group/get_options', array($this, 'get_options'), 5, 2);
36
+ add_filter('acf/field_group/get_next_field_id', array($this, 'get_next_field_id'), 5, 1);
37
+
38
+
39
+ // save
40
+ add_filter('name_save_pre', array($this, 'name_save_pre'));
41
+ add_action('save_post', array($this, 'save_post'));
42
+
43
+
44
+ // ajax
45
+ add_action('wp_ajax_acf/field_group/render_options', array($this, 'ajax_render_options'));
46
+ add_action('wp_ajax_acf/field_group/render_location', array($this, 'ajax_render_location'));
47
+
48
+ }
49
+
50
+
51
+ /*
52
+ * get_field_groups
53
+ *
54
+ * @description:
55
+ * @since: 3.6
56
+ * @created: 27/01/13
57
+ */
58
+
59
+ function get_field_groups( $array )
60
+ {
61
+ // cache
62
+ $cache = wp_cache_get( 'field_groups', 'acf' );
63
+ if( $cache )
64
+ {
65
+ return $cache;
66
+ }
67
+
68
+
69
+ // get acf's
70
+ $posts = get_posts(array(
71
+ 'numberposts' => -1,
72
+ 'post_type' => 'acf',
73
+ 'orderby' => 'menu_order title',
74
+ 'order' => 'asc',
75
+ 'suppress_filters' => false,
76
+ ));
77
+
78
+
79
+ // populate acfs
80
+ if( $posts ){ foreach( $posts as $post ){
81
+
82
+ $array[] = array(
83
+ 'id' => $post->ID,
84
+ 'title' => $post->post_title,
85
+ 'menu_order' => $post->menu_order,
86
+ );
87
+
88
+ }}
89
+
90
+
91
+ // set cache
92
+ wp_cache_set( 'field_groups', $array, 'acf' );
93
+
94
+
95
+ return $array;
96
+ }
97
+
98
+
99
+ /*
100
+ * get_fields
101
+ *
102
+ * @description: returns all fields for a field group
103
+ * @since: 3.6
104
+ * @created: 26/01/13
105
+ */
106
+
107
+ function get_fields( $fields, $post_id )
108
+ {
109
+ // global
110
+ global $wpdb;
111
+
112
+
113
+ // loaded by PHP already?
114
+ if( !empty($fields) )
115
+ {
116
+ return $fields;
117
+ }
118
+
119
+
120
+ // get field from postmeta
121
+ $rows = $wpdb->get_results( $wpdb->prepare("SELECT meta_key FROM $wpdb->postmeta WHERE post_id = %d AND meta_key LIKE %s", $post_id, 'field\_%'), ARRAY_A);
122
+
123
+
124
+ if( $rows )
125
+ {
126
+ foreach( $rows as $row )
127
+ {
128
+ $field = apply_filters('acf/load_field', false, $row['meta_key'], $post_id );
129
+
130
+ $fields[ $field['order_no'] ] = $field;
131
+ }
132
+
133
+ // sort
134
+ ksort( $fields );
135
+ }
136
+
137
+
138
+
139
+ // return
140
+ return $fields;
141
+
142
+ }
143
+
144
 
145
+ /*
146
+ * get_location
147
+ *
148
+ * @description:
149
+ * @since: 3.6
150
+ * @created: 26/01/13
151
+ */
152
+
153
+ function get_location( $location, $post_id )
154
+ {
155
+ // loaded by PHP already?
156
+ if( !empty($location) )
157
+ {
158
+ return $location;
159
+ }
160
+
161
+
162
+ // defaults
163
+ $location = array(
164
+ 'rules' => array(),
165
+ 'allorany' => 'all',
166
+ );
167
+
168
+
169
  // vars
170
+ $allorany = get_post_meta($post_id, 'allorany', true);
171
+ if( $allorany )
172
+ {
173
+ $location['allorany'] = $allorany;
174
+ }
175
 
176
 
177
+ // get all fields
178
+ $rules = get_post_meta($post_id, 'rule', false);
179
+
180
+
181
+ if($rules)
182
+ {
183
+
184
+ foreach($rules as $rule)
185
+ {
186
+ // if field group was duplicated, it may now be a serialized string!
187
+ $rule = maybe_unserialize($rule);
188
+
189
+
190
+ $location['rules'][ $rule['order_no'] ] = $rule;
191
+ }
192
+ }
193
+
194
+
195
+ // sort
196
+ ksort($location['rules']);
197
+
198
+
199
+ // return fields
200
+ return $location;
201
+ }
202
+
203
+
204
+ /*
205
+ * get_options
206
+ *
207
+ * @description:
208
+ * @since: 3.6
209
+ * @created: 26/01/13
210
+ */
211
+
212
+ function get_options( $options, $post_id )
213
+ {
214
+ // loaded by PHP already?
215
+ if( !empty($options) )
216
+ {
217
+ return $options;
218
+ }
219
 
220
 
221
+ // defaults
222
+ $options = array(
223
+ 'position' => 'normal',
224
+ 'layout' => 'no_box',
225
+ 'hide_on_screen' => array(),
226
+ );
227
+
228
+
229
+ // vars
230
+ $position = get_post_meta($post_id, 'position', true);
231
+ if( $position )
232
+ {
233
+ $options['position'] = $position;
234
+ }
235
 
236
+ $layout = get_post_meta($post_id, 'layout', true);
237
+ if( $layout )
238
+ {
239
+ $options['layout'] = $layout;
240
+ }
241
 
242
+ $hide_on_screen = get_post_meta($post_id, 'hide_on_screen', true);
243
+ if( $hide_on_screen )
244
+ {
245
+ $hide_on_screen = maybe_unserialize($hide_on_screen);
246
+ $options['hide_on_screen'] = $hide_on_screen;
247
+ }
248
+
249
+
250
+ // return
251
+ return $options;
252
  }
253
 
254
 
255
  /*
256
  * validate_page
257
  *
258
+ * @description:
259
  * @since 3.2.6
260
  * @created: 23/06/12
261
  */
265
  // global
266
  global $pagenow, $typenow;
267
 
268
+
269
  // vars
270
  $return = false;
271
 
286
  // return
287
  return $return;
288
  }
289
+
290
 
291
  /*
292
+ * admin_enqueue_scripts
293
  *
294
+ * @description: run after post query but before any admin script / head actions. A good place to register all actions.
295
+ * @since: 3.6
296
+ * @created: 26/01/13
297
  */
298
 
299
+ function admin_enqueue_scripts()
300
  {
301
  // validate page
302
+ if( ! $this->validate_page() ){ return; }
303
+
304
+
305
+ // settings
306
+ $this->settings = apply_filters('acf/get_info', 'all');
307
 
308
 
309
  // no autosave
316
  ));
317
 
318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  // custom styles
320
  wp_enqueue_style(array(
321
  'acf-global',
323
  ));
324
 
325
 
326
+ // actions
327
+ do_action('acf/field_group/admin_enqueue_scripts');
328
+ add_action('admin_head', array($this,'admin_head'));
329
 
330
  }
331
 
340
 
341
  function admin_head()
342
  {
 
 
 
 
343
  global $post;
344
 
345
 
350
  </script>';
351
 
352
 
353
+ do_action('acf/field_group/admin_head'); // new action
354
 
355
 
356
  // add metaboxes
357
+ add_meta_box('acf_fields', __("Fields",'acf'), array($this, 'html_fields'), 'acf', 'normal', 'high');
358
+ add_meta_box('acf_location', __("Location",'acf'), array($this, 'html_location'), 'acf', 'normal', 'high');
359
+ add_meta_box('acf_options', __("Options",'acf'), array($this, 'html_options'), 'acf', 'normal', 'high');
360
 
361
 
362
  // add screen settings
365
 
366
 
367
  /*
368
+ * html_fields
369
  *
370
  * @description:
371
+ * @since 1.0.0
372
+ * @created: 23/06/12
373
  */
374
 
375
+ function html_fields()
376
  {
377
+ include( $this->settings['path'] . 'core/views/meta_box_fields.php' );
 
 
 
 
 
 
 
378
  }
379
 
380
 
381
  /*
382
+ * html_location
383
  *
384
  * @description:
385
  * @since 1.0.0
386
  * @created: 23/06/12
387
  */
388
+
389
+ function html_location()
390
  {
391
+ include( $this->settings['path'] . 'core/views/meta_box_location.php' );
392
  }
393
 
394
 
395
  /*
396
+ * html_options
397
  *
398
  * @description:
399
  * @since 1.0.0
400
  * @created: 23/06/12
401
  */
402
+
403
+ function html_options()
404
  {
405
+ include( $this->settings['path'] . 'core/views/meta_box_options.php' );
406
  }
407
 
408
 
409
  /*
410
+ * screen_settings
411
  *
412
  * @description:
413
+ * @since: 3.6
414
+ * @created: 26/01/13
415
  */
416
 
417
+ function screen_settings( $current )
418
  {
419
+ $current .= '<h5>' . __("Fields",'acf') . '</h5>';
420
+
421
+ $current .= '<div class="show-field_key">Show Field Key:';
422
+ $current .= '<label class="show-field_key-no"><input checked="checked" type="radio" value="0" name="show-field_key" /> No</label>';
423
+ $current .= '<label class="show-field_key-yes"><input type="radio" value="1" name="show-field_key" /> Yes</label>';
424
+ $current .= '</div>';
425
+
426
+ return $current;
427
  }
428
 
429
 
430
  /*
431
+ * ajax_render_options
432
  *
433
  * @description: creates the HTML for a field's options (field group edit page)
434
  * @since 3.1.6
435
  * @created: 23/06/12
436
  */
437
 
438
+ function ajax_render_options()
439
  {
440
  // vars
441
  $options = array(
456
  }
457
 
458
 
 
459
  // required
460
  if( ! $options['field_type'] )
461
  {
468
  $options['field_key'] = str_replace("][type]", "", $options['field_key']) ;
469
 
470
 
 
 
 
471
  // render options
472
+ $field = array(
473
+ 'type' => $options['field_type'],
474
+ 'name' => $options['field_key']
475
+ );
476
+ do_action('acf/create_field_options', $field );
477
+
478
 
479
  die();
480
 
482
 
483
 
484
  /*
485
+ * ajax_render_location
486
  *
487
  * @description: creates the HTML for the field group location metabox. Called from both Ajax and PHP
488
  * @since 3.1.6
489
  * @created: 23/06/12
490
  */
491
 
492
+ function ajax_render_location($options = array())
493
  {
494
  // defaults
495
  $defaults = array(
498
  'param' => null,
499
  );
500
 
501
+ $is_ajax = false;
502
+ if( isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'acf_nonce') )
503
+ {
504
+ $is_ajax = true;
505
+ }
506
+
507
+
508
  // Is AJAX call?
509
+ if( $is_ajax )
510
  {
511
  $options = array_merge($defaults, $_POST);
512
  }
515
  $options = array_merge($defaults, $options);
516
  }
517
 
518
+ // vars
519
+ $choices = array();
520
+ $optgroup = false;
521
+
522
 
523
  // some case's have the same outcome
524
  if($options['param'] == "page_parent")
527
  }
528
 
529
 
 
 
 
530
  switch($options['param'])
531
  {
532
  case "post_type":
533
 
534
  // all post types except attachment
535
+ $choices = apply_filters('acf/get_post_types', array(), array('attachment'));
536
 
537
  break;
538
 
600
  $choices = array(
601
  'front_page' => __("Front Page",'acf'),
602
  'posts_page' => __("Posts Page",'acf'),
603
+ 'top_level' => __("Top Level Page (parent of 0)",'acf'),
604
+ 'parent' => __("Parent Page (has children)",'acf'),
605
+ 'child' => __("Child Page (has parent)",'acf'),
606
  );
607
 
608
  break;
693
 
694
  break;
695
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
696
  case "taxonomy" :
697
 
698
+ $choices = array();
699
+ $simple_value = true;
700
+ $choices = apply_filters('acf/get_taxonomies_for_select', $choices, $simple_value);
701
  $optgroup = true;
702
 
703
  break;
752
  'optgroup' => $optgroup,
753
  ));
754
 
755
+
756
  // ajax?
757
+ if( $is_ajax )
758
  {
759
  die();
760
  }
763
 
764
 
765
  /*
766
+ * name_save_pre
767
  *
768
  * @description: intercepts the acf post obejct and adds an "acf_" to the start of
769
  * it's name to stop conflicts between acf's and page's urls
771
  * @created: 23/06/12
772
  */
773
 
774
+ function name_save_pre($name)
775
  {
776
+ // validate
777
+ if( !isset($_POST['post_type']) || $_POST['post_type'] != 'acf' )
778
+ {
779
+ return $name;
780
+ }
781
+
782
+
783
+ // need a title
784
+ if( !$_POST['post_title'] )
785
+ {
786
+ $_POST['post_title'] = 'Unnamed Field Group';
787
+ }
788
+
789
+
790
+ $name = 'acf_' . sanitize_title_with_dashes($_POST['post_title']);
791
+
792
 
793
  return $name;
794
  }
803
  */
804
 
805
  function save_post($post_id)
806
+ {
807
+ // do not save if this is an auto save routine
808
+ if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
 
809
  {
810
  return $post_id;
811
  }
812
 
813
 
814
+ // verify nonce
815
+ if( !isset($_POST['acf_nonce']) || !wp_verify_nonce($_POST['acf_nonce'], 'field_group') )
816
+ {
817
+ return $post_id;
818
+ }
819
 
820
 
821
  // only save once! WordPress save's a revision as well.
829
  * save fields
830
  */
831
 
 
832
  // vars
833
  $dont_delete = array();
834
 
835
 
 
836
  if( $_POST['fields'] )
837
  {
838
  $i = -1;
839
+
840
 
841
  // remove clone field
842
  unset( $_POST['fields']['field_clone'] );
843
 
844
+
845
 
846
  // loop through and save fields
847
  foreach( $_POST['fields'] as $key => $field )
854
  $field['key'] = $key;
855
 
856
 
 
 
 
 
857
  // save
858
+ do_action('acf/update_field', $field, $post_id );
859
 
860
 
861
  // add to dont delete array
862
  $dont_delete[] = $field['key'];
863
  }
864
  }
865
+ unset( $_POST['fields'] );
866
 
867
 
868
  // delete all other field
872
  if( strpos($key, 'field_') !== false && !in_array($key, $dont_delete) )
873
  {
874
  // this is a field, and it wasn't found in the dont_delete array
875
+ do_action('acf/delete_field', $post_id, $key);
876
  }
877
  }
878
 
893
  add_post_meta($post_id, 'rule', $rule);
894
  }
895
  }
896
+ unset( $_POST['location'] );
897
 
898
 
899
  /*
900
  * save options
901
  */
902
 
903
+ $options = array(
904
+ 'position' => 'normal',
905
+ 'layout' => 'default',
906
+ 'hide_on_screen' => array()
907
+ );
908
+ $options = array_merge($options, $_POST['options']);
909
 
910
  update_post_meta($post_id, 'position', $options['position']);
911
  update_post_meta($post_id, 'layout', $options['layout']);
912
  update_post_meta($post_id, 'hide_on_screen', $options['hide_on_screen']);
913
 
914
+ unset( $_POST['options'] );
915
 
916
 
917
  }
 
918
 
919
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
920
  }
921
 
922
+ new acf_field_group();
923
+
924
  ?>
core/controllers/field_groups.php CHANGED
@@ -1,12 +1,16 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
3
  class acf_field_groups
4
  {
5
 
6
- var $parent,
7
- $data;
8
-
9
-
10
  /*
11
  * __construct
12
  *
@@ -15,16 +19,10 @@ class acf_field_groups
15
  * @created: 23/06/12
16
  */
17
 
18
- function __construct($parent)
19
  {
20
-
21
- // vars
22
- $this->parent = $parent;
23
-
24
-
25
  // actions
26
  add_action('admin_menu', array($this,'admin_menu'));
27
-
28
  }
29
 
30
 
@@ -39,13 +37,20 @@ class acf_field_groups
39
  {
40
 
41
  // validate page
42
- if( ! $this->validate_page() ) return;
 
 
 
43
 
 
 
44
  add_action('admin_print_scripts', array($this,'admin_print_scripts'));
45
  add_action('admin_print_styles', array($this,'admin_print_styles'));
46
  add_action('admin_footer', array($this,'admin_footer'));
47
 
48
- add_filter( 'manage_edit-acf_columns', array($this,'acf_edit_columns') );
 
 
49
  add_action( 'manage_acf_posts_custom_column' , array($this,'acf_columns_display'), 10, 2 );
50
 
51
  }
@@ -157,9 +162,6 @@ class acf_field_groups
157
  function acf_columns_display( $column, $post_id )
158
  {
159
  // vars
160
- $options = $this->parent->get_acf_options( $post_id );
161
-
162
-
163
  switch ($column)
164
  {
165
  case "fields":
@@ -182,34 +184,6 @@ class acf_field_groups
182
  echo $count;
183
 
184
  break;
185
-
186
- case "order":
187
-
188
- global $post;
189
-
190
- echo $order = $post->menu_order;
191
-
192
- break;
193
-
194
- case "position":
195
-
196
- $choices = array(
197
- 'normal' => __("Normal",'acf'),
198
- 'side' => __("Side",'acf'),
199
- );
200
-
201
- echo $choices[$options['position']];
202
-
203
- break;
204
-
205
- case "style":
206
-
207
- $choices = array(
208
- 'default' => __("Standard Metabox",'acf'),
209
- 'no_box' => __("No Metabox",'acf'),
210
- );
211
-
212
- echo $choices[$options['layout']];
213
  }
214
  }
215
 
@@ -224,20 +198,34 @@ class acf_field_groups
224
 
225
  function admin_footer()
226
  {
 
 
 
 
 
 
 
227
  ?>
228
- <div id="acf-col-right" class="hidden">
 
229
 
230
  <div class="wp-box">
231
  <div class="inner">
232
- <h3 class="h2"><?php _e("Advanced Custom Fields",'acf'); ?> <span>v<?php echo $this->parent->version; ?></span></h3>
233
 
234
  <h3><?php _e("Changelog",'acf'); ?></h3>
235
- <p><?php _e("See what's new in",'acf'); ?> <a class="thickbox" href="<?php echo admin_url('plugin-install.php'); ?>?tab=plugin-information&plugin=advanced-custom-fields&section=changelog&TB_iframe=true&width=640&height=559">v<?php echo $this->parent->version; ?></a>
236
 
237
  <h3><?php _e("Resources",'acf'); ?></h3>
238
- <p><?php _e("Read documentation, learn the functions and find some tips &amp; tricks for your next web project.",'acf'); ?><br />
239
- <a href="http://www.advancedcustomfields.com/" target="_blank"><?php _e("Visit the ACF website",'acf'); ?></a></p>
240
-
 
 
 
 
 
 
241
  </div>
242
  <div class="footer footer-blue">
243
  <ul class="left hl">
@@ -250,14 +238,156 @@ class acf_field_groups
250
  </div>
251
  </div>
252
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  <script type="text/javascript">
254
  (function($){
255
- $('#wpbody .wrap').wrapInner('<div id="acf-col-left" />');
256
- $('#wpbody .wrap').wrapInner('<div id="acf-cols" />');
257
- $('#acf-col-right').removeClass('hidden').prependTo('#acf-cols');
258
 
 
 
 
 
 
 
 
 
 
 
 
259
  $('#acf-col-left > .icon32').insertBefore('#acf-cols');
260
  $('#acf-col-left > h2').insertBefore('#acf-cols');
 
 
 
 
 
 
 
 
 
261
  })(jQuery);
262
  </script>
263
  <?php
@@ -265,4 +395,6 @@ class acf_field_groups
265
 
266
  }
267
 
 
 
268
  ?>
1
  <?php
2
 
3
+ /*
4
+ * acf_field_groups
5
+ *
6
+ * @description:
7
+ * @since: 3.6
8
+ * @created: 25/01/13
9
+ */
10
+
11
  class acf_field_groups
12
  {
13
 
 
 
 
 
14
  /*
15
  * __construct
16
  *
19
  * @created: 23/06/12
20
  */
21
 
22
+ function __construct()
23
  {
 
 
 
 
 
24
  // actions
25
  add_action('admin_menu', array($this,'admin_menu'));
 
26
  }
27
 
28
 
37
  {
38
 
39
  // validate page
40
+ if( ! $this->validate_page() )
41
+ {
42
+ return;
43
+ }
44
 
45
+
46
+ // actions
47
  add_action('admin_print_scripts', array($this,'admin_print_scripts'));
48
  add_action('admin_print_styles', array($this,'admin_print_styles'));
49
  add_action('admin_footer', array($this,'admin_footer'));
50
 
51
+
52
+ // columns
53
+ add_filter( 'manage_edit-acf_columns', array($this,'acf_edit_columns'), 10, 1 );
54
  add_action( 'manage_acf_posts_custom_column' , array($this,'acf_columns_display'), 10, 2 );
55
 
56
  }
162
  function acf_columns_display( $column, $post_id )
163
  {
164
  // vars
 
 
 
165
  switch ($column)
166
  {
167
  case "fields":
184
  echo $count;
185
 
186
  break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  }
188
  }
189
 
198
 
199
  function admin_footer()
200
  {
201
+ // vars
202
+ $version = apply_filters('acf/get_info', 'version');
203
+ $dir = apply_filters('acf/get_info', 'dir');
204
+ $path = apply_filters('acf/get_info', 'path');
205
+ $show_tab = isset($_GET['info']);
206
+ $tab = isset($_GET['info']) ? $_GET['info'] : 'changelog';
207
+
208
  ?>
209
+ <script type="text/html" id="tmpl-acf-col-right">
210
+ <div id="acf-col-right">
211
 
212
  <div class="wp-box">
213
  <div class="inner">
214
+ <h3 class="h2"><?php _e("Advanced Custom Fields",'acf'); ?> <?php echo $version; ?></h3>
215
 
216
  <h3><?php _e("Changelog",'acf'); ?></h3>
217
+ <p><?php _e("See what's new in",'acf'); ?> <a href="<?php echo admin_url('edit.php?post_type=acf&info=changelog'); ?>">version <?php echo $version; ?></a>
218
 
219
  <h3><?php _e("Resources",'acf'); ?></h3>
220
+ <ul>
221
+ <li><a href="http://www.advancedcustomfields.com/resources/#getting-started" target="_blank"><?php _e("Getting Started",'acf'); ?></a></li>
222
+ <li><a href="http://www.advancedcustomfields.com/resources/#field-types" target="_blank"><?php _e("Field Types",'acf'); ?></a></li>
223
+ <li><a href="http://www.advancedcustomfields.com/resources/#functions" target="_blank"><?php _e("Functions",'acf'); ?></a></li>
224
+ <li><a href="http://www.advancedcustomfields.com/resources/#actions" target="_blank"><?php _e("Actions",'acf'); ?></a></li>
225
+ <li><a href="http://www.advancedcustomfields.com/resources/#filters" target="_blank"><?php _e("Filters",'acf'); ?></a></li>
226
+ <li><a href="http://www.advancedcustomfields.com/resources/#how-to" target="_blank"><?php _e("\"How to\" guides",'acf'); ?></a></li>
227
+ <li><a href="http://www.advancedcustomfields.com/resources/#tutorials" target="_blank"><?php _e("Tutorials",'acf'); ?></a></li>
228
+ </ul>
229
  </div>
230
  <div class="footer footer-blue">
231
  <ul class="left hl">
238
  </div>
239
  </div>
240
  </div>
241
+ </script>
242
+ <script type="text/html" id="tmpl-acf-about">
243
+ <!-- acf-about -->
244
+ <div id="acf-about" class="acf-content">
245
+
246
+ <!-- acf-content-title -->
247
+ <div class="acf-content-title">
248
+ <h1><?php _e("Welcome to Advanced Custom Fields",'acf'); ?> <?php echo $version; ?></h1>
249
+ <h2><?php _e("Thank you for updating to the latest version!",'acf'); ?> <br />ACF <?php echo $version; ?> <?php _e("is more polished and enjoyable than ever before. We hope you like it.",'acf'); ?></h2>
250
+ </div>
251
+ <!-- / acf-content-title -->
252
+
253
+ <!-- acf-content-body -->
254
+ <div class="acf-content-body">
255
+ <h2 class="nav-tab-wrapper">
256
+ <a class="acf-tab-toggle nav-tab <?php if( $tab == 'whats-new' ){ echo 'nav-tab-active'; } ?>" href="<?php echo admin_url('edit.php?post_type=acf&info=whats-new'); ?>"><?php _e("What’s New",'acf'); ?></a>
257
+ <a class="acf-tab-toggle nav-tab <?php if( $tab == 'changelog' ){ echo 'nav-tab-active'; } ?>" href="<?php echo admin_url('edit.php?post_type=acf&info=changelog'); ?>"><?php _e("Changelog",'acf'); ?></a>
258
+ </h2>
259
+
260
+ <?php if( $tab == 'whats-new' ): ?>
261
+
262
+ <table id="acf-add-ons-table" class="alignright">
263
+ <tr>
264
+ <td><img src="<?php echo $dir; ?>images/add-ons/repeater-field-thumb.jpg" /></td>
265
+ <td><img src="<?php echo $dir; ?>images/add-ons/gallery-field-thumb.jpg" /></td>
266
+ </tr>
267
+ <tr>
268
+ <td><img src="<?php echo $dir; ?>images/add-ons/options-page-thumb.jpg" /></td>
269
+ <td><img src="<?php echo $dir; ?>images/add-ons/flexible-content-field-thumb.jpg" /></td>
270
+ </tr>
271
+ </table>
272
+
273
+ <h3><?php _e("Add-ons",'acf'); ?></h3>
274
+
275
+ <h4><?php _e("Activation codes have grown into plugins!",'acf'); ?></h4>
276
+ <p><?php _e("Add-ons are now activated by downloading and installing individual plugins. Although these plugins will not be hosted on the wordpress.org repository, each Add-on will continue to receive updates in the usual way.",'acf'); ?></p>
277
+
278
+ <h4><?php _e("Where can I find my Add-on plugins?",'acf'); ?></h4>
279
+ <p><?php _e("Download links can be found alongside the activation code in your ACF receipt.",'acf'); ?> <a href="http://www.advancedcustomfields.com/store/account/" target="_blank"><?php _e("Visit your account",'acf'); ?></a>.<br />
280
+ <?php _e("For faster access, this",'acf'); ?> <a href="http://www.advancedcustomfields.com/add-ons-download/" target="_blank"><?php _e("download page",'acf'); ?></a> <?php _e("has also been created.",'acf'); ?></p>
281
+
282
+ <hr />
283
+
284
+ <h3><?php _e("Easier Development",'acf'); ?></h3>
285
+
286
+ <h4><?php _e("New Field Types",'acf'); ?></h4>
287
+ <ul>
288
+ <li><?php _e("Taxonomy Field",'acf'); ?></li>
289
+ <li><?php _e("User Field",'acf'); ?></li>
290
+ <li><?php _e("Email Field",'acf'); ?></li>
291
+ <li><?php _e("Password Field",'acf'); ?></li>
292
+ </ul>
293
+ <h4><?php _e("Custom Field Types",'acf'); ?></h4>
294
+ <p><?php _e("Creating your own field type has never been easier! Unfortunately, version 3 field types are not compatible with version 4.",'acf'); ?><br />
295
+ <?php _e("Migrating your field types is easy, please",'acf'); ?> <a href="http://www.advancedcustomfields.com/docs/tutorials/creating-a-new-field-type/" target="_blank"><?php _e("follow this tutorial",'acf'); ?></a> <?php _e("to learn more.",'acf'); ?></p>
296
+
297
+ <h4><?php _e("Actions &amp; Filters",'acf'); ?></h4>
298
+ <p><?php _e("All actions & filters have recieved a major facelift to make customizing ACF even easier! Please",'acf'); ?> <a href="http://www.advancedcustomfields.com/resources/getting-started/migrating-from-v3-to-v4/" target="_blank"><?php _e("read this guide",'acf'); ?></a> <?php _e("to find the updated naming convention.",'acf'); ?></p>
299
+
300
+ <h4><?php _e("Preview draft is now working!",'acf'); ?></h4>
301
+ <p><?php _e("This bug has been squashed along with many other little critters!",'acf'); ?> <a class="acf-tab-toggle" href="#" data-tab="2"><?php _e("See the full changelog",'acf'); ?></a></p>
302
+
303
+ <hr />
304
+
305
+ <h3><?php _e("Important",'acf'); ?></h3>
306
+
307
+ <h4><?php _e("Database Changes",'acf'); ?></h4>
308
+ <p><?php _e("Absolutely <strong>no</strong> changes have been made to the database between versions 3 and 4. This means you can roll back to version 3 without any issues.",'acf'); ?></p>
309
+
310
+ <h4><?php _e("Potential Issues",'acf'); ?></h4>
311
+ <p><?php _e("Do to the sizable changes surounding Add-ons, field types and action/filters, your website may not operate correctly. It is important that you read the full",'acf'); ?> <a href="http://www.advancedcustomfields.com/resources/getting-started/migrating-from-v3-to-v4/" target="_blank"><?php _e("Migrating from v3 to v4",'acf'); ?></a> <?php _e("guide to view the full list of changes.",'acf'); ?></p>
312
+
313
+ <div class="acf-alert acf-alert-error">
314
+ <p><strong><?php _e("Really Important!",'acf'); ?></strong> <?php _e("If you updated the ACF plugin without prior knowledge of such changes, Please roll back to the latest",'acf'); ?> <a href="http://wordpress.org/extend/plugins/advanced-custom-fields/developers/"><?php _e("version 3",'acf'); ?></a> <?php _e("of this plugin.",'acf'); ?></p>
315
+ </div>
316
+
317
+ <hr />
318
+
319
+ <h3><?php _e("Thank You",'acf'); ?></h3>
320
+ <p><?php _e("A <strong>BIG</strong> thank you to everyone who has helped test the version 4 beta and for all the support I have received.",'acf'); ?></p>
321
+ <p><?php _e("Without you all, this release would not have been possible!",'acf'); ?></p>
322
+
323
+ <?php elseif( $tab == 'changelog' ): ?>
324
+
325
+ <h3><?php _e("Changelog for",'acf'); ?> <?php echo $version; ?></h3>
326
+ <?php
327
+
328
+ $items = file_get_contents( $path . 'readme.txt' );
329
+
330
+ $items = end( explode('= ' . $version . ' =', $items) );
331
+ $items = current( explode("\n\n", $items) );
332
+ $items = array_filter( array_map('trim', explode("*", $items)) );
333
+
334
+ ?>
335
+ <ul class="acf-changelog">
336
+ <?php foreach( $items as $item ):
337
+
338
+ $item = explode('http', $item);
339
+
340
+
341
+ ?>
342
+ <li><?php echo $item[0]; ?><?php if( isset($item[1]) ): ?><a href="http<?php echo $item[1]; ?>" target="_blank"><?php _e("Learn more",'acf'); ?></a><?php endif; ?></li>
343
+ <?php endforeach; ?>
344
+ </ul>
345
+
346
+ <?php endif; ?>
347
+
348
+
349
+ </div>
350
+ <!-- / acf-content-body -->
351
+
352
+
353
+ <!-- acf-content-footer -->
354
+ <div class="acf-content-footer">
355
+ <ul class="hl clearfix">
356
+ <li><a class="acf-button acf-button-big" href="<?php echo admin_url('edit.php?post_type=acf'); ?>"><?php _e("Awesome. Let's get to work",'acf'); ?></a></li>
357
+ </ul>
358
+ </div>
359
+ <!-- / acf-content-footer -->
360
+
361
+
362
+
363
+ </div>
364
+ <!-- / acf-about -->
365
+ </script>
366
  <script type="text/javascript">
367
  (function($){
 
 
 
368
 
369
+ // wrap
370
+ $('#wpbody .wrap').attr('id', 'acf-field_groups');
371
+ $('#acf-field_groups').wrapInner('<div id="acf-col-left" />');
372
+ $('#acf-field_groups').wrapInner('<div id="acf-cols" />');
373
+
374
+
375
+ // add sidebar
376
+ $('#acf-cols').prepend( $('#tmpl-acf-col-right').html() );
377
+
378
+
379
+ // take out h2 + icon
380
  $('#acf-col-left > .icon32').insertBefore('#acf-cols');
381
  $('#acf-col-left > h2').insertBefore('#acf-cols');
382
+
383
+
384
+ <?php if( $show_tab ): ?>
385
+ // add about copy
386
+ $('#wpbody-content').prepend( $('#tmpl-acf-about').html() );
387
+ $('#acf-field_groups').hide();
388
+ $('#screen-meta-links').hide();
389
+ <?php endif; ?>
390
+
391
  })(jQuery);
392
  </script>
393
  <?php
395
 
396
  }
397
 
398
+ new acf_field_groups();
399
+
400
  ?>
core/controllers/input.php CHANGED
@@ -3,17 +3,16 @@
3
  /*
4
  * Input
5
  *
6
- * @description: All the functionality for adding fields to a page / post
7
- * @since 3.2.6
8
- * @created: 23/06/12
9
  */
10
-
11
  class acf_input
12
  {
13
-
14
- var $parent,
15
- $data;
16
-
17
 
18
  /*
19
  * __construct
@@ -23,39 +22,36 @@ class acf_input
23
  * @created: 23/06/12
24
  */
25
 
26
- function __construct($parent)
27
  {
28
-
29
- // vars
30
- $this->parent = $parent;
31
-
32
-
33
  // actions
34
- add_action('admin_print_scripts', array($this,'admin_print_scripts'));
35
- add_action('admin_print_styles', array($this,'admin_print_styles'));
36
- add_action('admin_head', array($this,'admin_head'));
37
 
38
 
39
  // save
40
- add_action('save_post', array($this, 'save_post'), 10, 1);
 
 
 
 
 
41
 
42
 
43
- // custom actions (added in 3.1.8)
44
- add_action('acf_head-input', array($this, 'acf_head_input'));
45
- add_action('acf_print_scripts-input', array($this, 'acf_print_scripts_input'));
46
- add_action('acf_print_styles-input', array($this, 'acf_print_styles_input'));
47
  add_action('wp_restore_post_revision', array($this, 'wp_restore_post_revision'), 10, 2 );
 
 
 
48
  add_filter('_wp_post_revision_fields', array($this, 'wp_post_revision_fields') );
49
 
50
- // ajax
51
- add_action('wp_ajax_acf_input', array($this, 'ajax_acf_input'));
52
- add_action('wp_ajax_get_input_style', array($this, 'ajax_get_input_style'));
 
53
 
54
 
55
  // edit attachment hooks (used by image / file / gallery)
56
  add_action('admin_head-media.php', array($this, 'admin_head_media'));
57
  add_action('admin_head-upload.php', array($this, 'admin_head_upload'));
58
-
59
  }
60
 
61
 
@@ -105,43 +101,28 @@ class acf_input
105
 
106
 
107
  /*
108
- * admin_print_scripts
109
  *
110
- * @description:
111
- * @since 3.1.8
112
- * @created: 23/06/12
113
  */
114
 
115
- function admin_print_scripts()
116
  {
117
  // validate page
118
- if( ! $this->validate_page() ) return;
119
-
120
-
121
- do_action('acf_print_scripts-input');
122
-
123
 
124
  // only "edit post" input pages need the ajax
125
  wp_enqueue_script(array(
126
  'acf-input-ajax',
127
  ));
128
- }
129
-
130
-
131
- /*
132
- * admin_print_styles
133
- *
134
- * @description:
135
- * @since 3.1.8
136
- * @created: 23/06/12
137
- */
138
-
139
- function admin_print_styles()
140
- {
141
- // validate page
142
- if( ! $this->validate_page() ) return;
143
 
144
- do_action('acf_print_styles-input');
 
 
 
145
  }
146
 
147
 
@@ -155,10 +136,6 @@ class acf_input
155
 
156
  function admin_head()
157
  {
158
- // validate page
159
- if( ! $this->validate_page() ) return;
160
-
161
-
162
  // globals
163
  global $post, $pagenow, $typenow;
164
 
@@ -187,7 +164,7 @@ class acf_input
187
  $style = '';
188
  if( isset($metabox_ids[0]) )
189
  {
190
- $style = $this->get_input_style( $metabox_ids[0] );
191
  }
192
 
193
 
@@ -197,19 +174,23 @@ class acf_input
197
 
198
 
199
  // add user js + css
200
- do_action('acf_head-input');
201
 
202
 
203
- // get acf's
204
- $acfs = apply_filters('acf/get_field_groups', false);
205
 
206
 
207
- if($acfs)
208
  {
209
- foreach($acfs as $acf)
210
  {
211
- // hide / show
212
- $show = in_array($acf['id'], $metabox_ids) ? 1 : 0;
 
 
 
 
213
  $priority = 'high';
214
  if( $acf['options']['position'] == 'side' )
215
  {
@@ -225,7 +206,7 @@ class acf_input
225
  $typenow,
226
  $acf['options']['position'],
227
  $priority,
228
- array( 'fields' => $acf['fields'], 'options' => $acf['options'], 'show' => $show, 'post_id' => $post->ID )
229
  );
230
 
231
  }
@@ -236,95 +217,85 @@ class acf_input
236
 
237
 
238
  /*
239
- * get_input_style
240
  *
241
  * @description: called by admin_head to generate acf css style (hide other metaboxes)
242
  * @since 2.0.5
243
  * @created: 23/06/12
244
  */
245
 
246
- function get_input_style($acf_id = false)
247
  {
 
 
 
 
248
  // vars
249
- $acfs = apply_filters('acf/get_field_groups', false);
250
- $html = "";
 
251
 
252
- // find acf
253
- if($acfs)
254
  {
255
- foreach($acfs as $acf)
256
- {
257
- if($acf['id'] != $acf_id) continue;
258
-
259
-
260
- // add style to html
261
- if( in_array('the_content',$acf['options']['hide_on_screen']) )
262
- {
263
- $html .= '#postdivrich {display: none;} ';
264
- }
265
- if( in_array('excerpt',$acf['options']['hide_on_screen']) )
266
- {
267
- $html .= '#postexcerpt, #screen-meta label[for=postexcerpt-hide] {display: none;} ';
268
- }
269
- if( in_array('custom_fields',$acf['options']['hide_on_screen']) )
270
- {
271
- $html .= '#postcustom, #screen-meta label[for=postcustom-hide] { display: none; } ';
272
- }
273
- if( in_array('discussion',$acf['options']['hide_on_screen']) )
274
- {
275
- $html .= '#commentstatusdiv, #screen-meta label[for=commentstatusdiv-hide] {display: none;} ';
276
- }
277
- if( in_array('comments',$acf['options']['hide_on_screen']) )
278
- {
279
- $html .= '#commentsdiv, #screen-meta label[for=commentsdiv-hide] {display: none;} ';
280
- }
281
- if( in_array('slug',$acf['options']['hide_on_screen']) )
282
- {
283
- $html .= '#slugdiv, #screen-meta label[for=slugdiv-hide] {display: none;} ';
284
- }
285
- if( in_array('author',$acf['options']['hide_on_screen']) )
286
- {
287
- $html .= '#authordiv, #screen-meta label[for=authordiv-hide] {display: none;} ';
288
- }
289
- if( in_array('format',$acf['options']['hide_on_screen']) )
290
- {
291
- $html .= '#formatdiv, #screen-meta label[for=formatdiv-hide] {display: none;} ';
292
- }
293
- if( in_array('featured_image',$acf['options']['hide_on_screen']) )
294
- {
295
- $html .= '#postimagediv, #screen-meta label[for=postimagediv-hide] {display: none;} ';
296
- }
297
- if( in_array('revisions',$acf['options']['hide_on_screen']) )
298
- {
299
- $html .= '#revisionsdiv, #screen-meta label[for=revisionsdiv-hide] {display: none;} ';
300
- }
301
- if( in_array('categories',$acf['options']['hide_on_screen']) )
302
- {
303
- $html .= '#categorydiv, #screen-meta label[for=categorydiv-hide] {display: none;} ';
304
- }
305
- if( in_array('tags',$acf['options']['hide_on_screen']) )
306
- {
307
- $html .= '#tagsdiv-post_tag, #screen-meta label[for=tagsdiv-post_tag-hide] {display: none;} ';
308
- }
309
- if( in_array('send-trackbacks',$acf['options']['hide_on_screen']) )
310
- {
311
- $html .= '#trackbacksdiv, #screen-meta label[for=trackbacksdiv-hide] {display: none;} ';
312
- }
313
-
314
-
315
- break;
316
-
317
- }
318
- // foreach($acfs as $acf)
319
  }
320
- //if($acfs)
321
 
 
322
  return $html;
323
  }
324
 
325
 
326
  /*
327
- * the_input_style
328
  *
329
  * @description: called by input-actions.js to hide / show other metaboxes
330
  * @since 2.0.5
@@ -333,12 +304,28 @@ class acf_input
333
 
334
  function ajax_get_input_style()
335
  {
336
- // overrides
337
- if(isset($_POST['acf_id']))
 
 
 
 
 
 
 
 
 
 
338
  {
339
- echo $this->get_input_style($_POST['acf_id']);
340
  }
341
 
 
 
 
 
 
 
342
  die;
343
  }
344
 
@@ -351,75 +338,68 @@ class acf_input
351
  * @created: 23/06/12
352
  */
353
 
354
- function meta_box_input($post, $args)
355
  {
356
  // vars
357
- $options = array(
358
- 'fields' => array(),
359
- 'options' => array(
360
- 'layout' => 'default'
361
- ),
362
- 'show' => 0,
363
- 'post_id' => 0,
364
- );
365
- $options = array_merge( $options, $args['args'] );
366
 
 
 
367
 
368
- // needs fields
369
- if( $options['fields'] )
370
  {
371
- echo '<input type="hidden" name="save_input" value="true" />';
372
- echo '<div class="options" data-layout="' . $options['options']['layout'] . '" data-show="' . $options['show'] . '" style="display:none"></div>';
373
-
374
- if( $options['show'] )
375
- {
376
- $this->parent->render_fields_for_input( $options['fields'], $options['post_id'] );
377
- }
378
- else
379
- {
380
- echo '<div class="acf-replace-with-fields"><div class="acf-loading"></div></div>';
381
- }
382
-
383
  }
384
  }
385
 
386
 
387
  /*
388
- * ajax_acf_input
389
  *
390
  * @description:
391
  * @since 3.1.6
392
  * @created: 23/06/12
393
  */
394
 
395
- function ajax_acf_input()
396
  {
397
 
398
  // defaults
399
- $defaults = array(
400
- 'acf_id' => null,
401
- 'post_id' => null,
 
402
  );
403
 
 
404
  // load post options
405
- $options = array_merge($defaults, $_POST);
406
 
407
- // required
408
- if(!$options['acf_id'] || !$options['post_id'])
 
409
  {
410
- echo "";
411
- die();
412
  }
413
 
 
414
  // get acfs
415
- $acfs = apply_filters('acf/get_field_groups', false);
416
  if( $acfs )
417
  {
418
  foreach( $acfs as $acf )
419
  {
420
  if( $acf['id'] == $options['acf_id'] )
421
  {
422
- $this->parent->render_fields_for_input( $acf['fields'], $options['post_id']);
 
 
423
 
424
  break;
425
  }
@@ -439,97 +419,43 @@ class acf_input
439
  * @created: 23/06/12
440
  */
441
 
442
- function save_post($post_id)
443
  {
444
 
445
  // do not save if this is an auto save routine
446
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
447
-
448
-
449
- // only for save acf
450
- if( ! isset($_POST['save_input']) || $_POST['save_input'] != 'true')
451
  {
452
  return $post_id;
453
  }
454
 
455
 
456
- // Save revision (copy and paste of current metadata. ie: what it was)
457
- $parent_id = wp_is_post_revision( $post_id );
458
- if( $parent_id )
459
  {
460
- $this->save_post_revision( $parent_id, $post_id );
461
- }
462
- else
463
- {
464
- do_action('acf_save_post', $post_id);
465
- }
466
-
467
- }
468
-
469
-
470
- /*
471
- * save_post_revision
472
- *
473
- * @description: simple copy and paste of fields
474
- * @since 3.4.4
475
- * @created: 4/09/12
476
- */
477
-
478
- function save_post_revision( $parent_id, $revision_id )
479
- {
480
-
481
- // load from post
482
- if( !isset($_POST['fields']) )
483
- {
484
- return false;
485
- }
486
-
487
-
488
- // field data was posted. Find all values (not references) and copy / paste them over.
489
-
490
- global $wpdb;
491
-
492
-
493
- // get field from postmeta
494
- $rows = $wpdb->get_results( $wpdb->prepare(
495
- "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = %d AND meta_key NOT LIKE %s",
496
- $parent_id,
497
- '\_%'
498
- ), ARRAY_A);
499
-
500
-
501
- if( $rows )
502
- {
503
- foreach( $rows as $row )
504
- {
505
- $wpdb->insert(
506
- $wpdb->postmeta,
507
- array(
508
- 'post_id' => $revision_id,
509
- 'meta_key' => $row['meta_key'],
510
- 'meta_value' => $row['meta_value']
511
- )
512
- );
513
- }
514
  }
 
515
 
516
- return true;
 
 
 
517
  }
518
 
519
 
520
 
521
  /*--------------------------------------------------------------------------------------
522
  *
523
- * acf_head_input
524
  *
525
- * This is fired from an action: acf_head-input
526
  *
527
  * @author Elliot Condon
528
  * @since 3.0.6
529
  *
530
  *-------------------------------------------------------------------------------------*/
531
 
532
- function acf_head_input()
533
  {
534
  // global
535
  global $wp_version, $post;
@@ -550,6 +476,7 @@ class acf_input
550
  acf.post_id = <?php echo $post_id; ?>;
551
  acf.nonce = "<?php echo wp_create_nonce( 'acf_nonce' ); ?>";
552
  acf.admin_url = "<?php echo admin_url(); ?>";
 
553
  acf.wp_version = "<?php echo $wp_version; ?>";
554
 
555
 
@@ -566,9 +493,6 @@ acf.fields.file.text.title_add = "Select File";
566
  acf.fields.file.text.title_edit = "Edit File";
567
  acf.fields.file.text.button_add = "Select File";
568
 
569
- acf.fields.gallery.title_add = "<?php _e("Add Image to Gallery",'acf'); ?>";
570
- acf.fields.gallery.title_edit = "<?php _e("Edit Image",'acf'); ?>";
571
-
572
 
573
  // WYSIWYG
574
  <?php
@@ -590,26 +514,20 @@ endif;
590
  ?>
591
  </script>
592
  <?php
593
-
594
-
595
- foreach($this->parent->fields as $field)
596
- {
597
- $field->admin_head();
598
- }
599
  }
600
 
601
 
602
- /*--------------------------------------------------------------------------------------
603
- *
604
- * acf_print_scripts
605
  *
606
- * @author Elliot Condon
607
- * @since 3.1.8
608
- *
609
- *-------------------------------------------------------------------------------------*/
610
 
611
- function acf_print_scripts_input()
612
  {
 
613
  wp_enqueue_script(array(
614
  'jquery',
615
  'jquery-ui-core',
@@ -623,31 +541,14 @@ endif;
623
  ));
624
 
625
 
626
- foreach($this->parent->fields as $field)
627
- {
628
- $field->admin_print_scripts();
629
- }
630
-
631
-
632
  // 3.5 media gallery
633
  if( function_exists('wp_enqueue_media') && !did_action( 'wp_enqueue_media' ))
634
  {
635
  wp_enqueue_media();
636
  }
637
- }
638
-
639
-
640
- /*--------------------------------------------------------------------------------------
641
- *
642
- * acf_print_styles
643
- *
644
- * @author Elliot Condon
645
- * @since 3.1.8
646
- *
647
- *-------------------------------------------------------------------------------------*/
648
-
649
- function acf_print_styles_input()
650
- {
651
  wp_enqueue_style(array(
652
  'thickbox',
653
  'farbtastic',
@@ -655,11 +556,6 @@ endif;
655
  'acf-input',
656
  'acf-datepicker',
657
  ));
658
-
659
- foreach($this->parent->fields as $field)
660
- {
661
- $field->admin_print_styles();
662
- }
663
  }
664
 
665
 
@@ -863,10 +759,10 @@ html.wp-toolbar {
863
  return $fields;
864
 
865
  }
866
-
867
-
868
-
869
 
 
870
  }
871
 
 
 
872
  ?>
3
  /*
4
  * Input
5
  *
6
+ * @description: controller for adding field HTML to edit screens
7
+ * @since: 3.6
8
+ * @created: 25/01/13
9
  */
10
+
11
  class acf_input
12
  {
13
+
14
+ var $action;
15
+
 
16
 
17
  /*
18
  * __construct
22
  * @created: 23/06/12
23
  */
24
 
25
+ function __construct()
26
  {
 
 
 
 
 
27
  // actions
28
+ add_action('admin_enqueue_scripts', array($this,'admin_enqueue_scripts'));
 
 
29
 
30
 
31
  // save
32
+ add_action('save_post', array($this, 'save_post'), 10, 1);
33
+
34
+
35
+ // actions
36
+ add_action('acf/input/admin_head', array($this, 'input_admin_head'));
37
+ add_action('acf/input/admin_enqueue_scripts', array($this, 'input_admin_enqueue_scripts'));
38
 
39
 
 
 
 
 
40
  add_action('wp_restore_post_revision', array($this, 'wp_restore_post_revision'), 10, 2 );
41
+
42
+
43
+ // filters
44
  add_filter('_wp_post_revision_fields', array($this, 'wp_post_revision_fields') );
45
 
46
+
47
+ // ajax acf/update_field_groups
48
+ add_action('wp_ajax_acf/input/render_fields', array($this, 'ajax_render_fields'));
49
+ add_action('wp_ajax_acf/input/get_style', array($this, 'ajax_get_style'));
50
 
51
 
52
  // edit attachment hooks (used by image / file / gallery)
53
  add_action('admin_head-media.php', array($this, 'admin_head_media'));
54
  add_action('admin_head-upload.php', array($this, 'admin_head_upload'));
 
55
  }
56
 
57
 
101
 
102
 
103
  /*
104
+ * admin_enqueue_scripts
105
  *
106
+ * @description: run after post query but before any admin script / head actions. A good place to register all actions.
107
+ * @since: 3.6
108
+ * @created: 26/01/13
109
  */
110
 
111
+ function admin_enqueue_scripts()
112
  {
113
  // validate page
114
+ if( ! $this->validate_page() ){ return; }
115
+
 
 
 
116
 
117
  // only "edit post" input pages need the ajax
118
  wp_enqueue_script(array(
119
  'acf-input-ajax',
120
  ));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
+
123
+ // actions
124
+ do_action('acf/input/admin_enqueue_scripts');
125
+ add_action('admin_head', array($this,'admin_head'));
126
  }
127
 
128
 
136
 
137
  function admin_head()
138
  {
 
 
 
 
139
  // globals
140
  global $post, $pagenow, $typenow;
141
 
164
  $style = '';
165
  if( isset($metabox_ids[0]) )
166
  {
167
+ $style = $this->ajax_get_style( $metabox_ids[0] );
168
  }
169
 
170
 
174
 
175
 
176
  // add user js + css
177
+ do_action('acf/input/admin_head');
178
 
179
 
180
+ // get field groups
181
+ $acfs = apply_filters('acf/get_field_groups', array());
182
 
183
 
184
+ if( $acfs )
185
  {
186
+ foreach( $acfs as $acf )
187
  {
188
+ // load options
189
+ $acf['options'] = apply_filters('acf/field_group/get_options', array(), $acf['id']);
190
+
191
+
192
+ // vars
193
+ $show = in_array( $acf['id'], $metabox_ids ) ? 1 : 0;
194
  $priority = 'high';
195
  if( $acf['options']['position'] == 'side' )
196
  {
206
  $typenow,
207
  $acf['options']['position'],
208
  $priority,
209
+ array( 'field_group' => $acf, 'show' => $show, 'post_id' => $post_id )
210
  );
211
 
212
  }
217
 
218
 
219
  /*
220
+ * ajax_get_style
221
  *
222
  * @description: called by admin_head to generate acf css style (hide other metaboxes)
223
  * @since 2.0.5
224
  * @created: 23/06/12
225
  */
226
 
227
+ function ajax_get_style( $acf_id )
228
  {
229
+ // global
230
+ global $acf_field_group;
231
+
232
+
233
  // vars
234
+ $options = apply_filters('acf/field_group/get_options', array(), $acf_id);
235
+ $html = '';
236
+
237
 
238
+ // add style to html
239
+ if( in_array('the_content',$options['hide_on_screen']) )
240
  {
241
+ $html .= '#postdivrich {display: none;} ';
242
+ }
243
+ if( in_array('excerpt',$options['hide_on_screen']) )
244
+ {
245
+ $html .= '#postexcerpt, #screen-meta label[for=postexcerpt-hide] {display: none;} ';
246
+ }
247
+ if( in_array('custom_fields',$options['hide_on_screen']) )
248
+ {
249
+ $html .= '#postcustom, #screen-meta label[for=postcustom-hide] { display: none; } ';
250
+ }
251
+ if( in_array('discussion',$options['hide_on_screen']) )
252
+ {
253
+ $html .= '#commentstatusdiv, #screen-meta label[for=commentstatusdiv-hide] {display: none;} ';
254
+ }
255
+ if( in_array('comments',$options['hide_on_screen']) )
256
+ {
257
+ $html .= '#commentsdiv, #screen-meta label[for=commentsdiv-hide] {display: none;} ';
258
+ }
259
+ if( in_array('slug',$options['hide_on_screen']) )
260
+ {
261
+ $html .= '#slugdiv, #screen-meta label[for=slugdiv-hide] {display: none;} ';
262
+ }
263
+ if( in_array('author',$options['hide_on_screen']) )
264
+ {
265
+ $html .= '#authordiv, #screen-meta label[for=authordiv-hide] {display: none;} ';
266
+ }
267
+ if( in_array('format',$options['hide_on_screen']) )
268
+ {
269
+ $html .= '#formatdiv, #screen-meta label[for=formatdiv-hide] {display: none;} ';
270
+ }
271
+ if( in_array('featured_image',$options['hide_on_screen']) )
272
+ {
273
+ $html .= '#postimagediv, #screen-meta label[for=postimagediv-hide] {display: none;} ';
274
+ }
275
+ if( in_array('revisions',$options['hide_on_screen']) )
276
+ {
277
+ $html .= '#revisionsdiv, #screen-meta label[for=revisionsdiv-hide] {display: none;} ';
278
+ }
279
+ if( in_array('categories',$options['hide_on_screen']) )
280
+ {
281
+ $html .= '#categorydiv, #screen-meta label[for=categorydiv-hide] {display: none;} ';
282
+ }
283
+ if( in_array('tags',$options['hide_on_screen']) )
284
+ {
285
+ $html .= '#tagsdiv-post_tag, #screen-meta label[for=tagsdiv-post_tag-hide] {display: none;} ';
286
+ }
287
+ if( in_array('send-trackbacks',$options['hide_on_screen']) )
288
+ {
289
+ $html .= '#trackbacksdiv, #screen-meta label[for=trackbacksdiv-hide] {display: none;} ';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  }
 
291
 
292
+
293
  return $html;
294
  }
295
 
296
 
297
  /*
298
+ * ajax_get_input_style
299
  *
300
  * @description: called by input-actions.js to hide / show other metaboxes
301
  * @since 2.0.5
304
 
305
  function ajax_get_input_style()
306
  {
307
+ // vars
308
+ $options = array(
309
+ 'post_id' => 0,
310
+ 'nonce' => ''
311
+ );
312
+
313
+ // load post options
314
+ $options = array_merge($options, $_POST);
315
+
316
+
317
+ // verify nonce
318
+ if( ! wp_verify_nonce($options['nonce'], 'acf_nonce') )
319
  {
320
+ die(0);
321
  }
322
 
323
+
324
+ // return style
325
+ echo $this->get_input_style( $options['post_id'] );
326
+
327
+
328
+ // die
329
  die;
330
  }
331
 
338
  * @created: 23/06/12
339
  */
340
 
341
+ function meta_box_input( $post, $args )
342
  {
343
  // vars
344
+ $options = $args['args'];
 
 
 
 
 
 
 
 
345
 
346
+ echo '<input type="hidden" name="acf_nonce" value="' . wp_create_nonce( 'input' ) . '" />';
347
+ echo '<div class="options" data-layout="' . $options['field_group']['options']['layout'] . '" data-show="' . $options['show'] . '" style="display:none"></div>';
348
 
349
+ if( $options['show'] )
 
350
  {
351
+ $fields = apply_filters('acf/field_group/get_fields', array(), $options['field_group']['id']);
352
+
353
+ do_action('acf/create_fields', $fields, $options['post_id']);
354
+ }
355
+ else
356
+ {
357
+ echo '<div class="acf-replace-with-fields"><div class="acf-loading"></div></div>';
 
 
 
 
 
358
  }
359
  }
360
 
361
 
362
  /*
363
+ * ajax_render_fields
364
  *
365
  * @description:
366
  * @since 3.1.6
367
  * @created: 23/06/12
368
  */
369
 
370
+ function ajax_render_fields()
371
  {
372
 
373
  // defaults
374
+ $options = array(
375
+ 'acf_id' => 0,
376
+ 'post_id' => 0,
377
+ 'nonce' => ''
378
  );
379
 
380
+
381
  // load post options
382
+ $options = array_merge($options, $_POST);
383
 
384
+
385
+ // verify nonce
386
+ if( ! wp_verify_nonce($options['nonce'], 'acf_nonce') )
387
  {
388
+ die(0);
 
389
  }
390
 
391
+
392
  // get acfs
393
+ $acfs = apply_filters('acf/get_field_groups', array());
394
  if( $acfs )
395
  {
396
  foreach( $acfs as $acf )
397
  {
398
  if( $acf['id'] == $options['acf_id'] )
399
  {
400
+ $fields = apply_filters('acf/field_group/get_fields', array(), $acf['id']);
401
+
402
+ do_action('acf/create_fields', $fields, $options['post_id']);
403
 
404
  break;
405
  }
419
  * @created: 23/06/12
420
  */
421
 
422
+ function save_post( $post_id )
423
  {
424
 
425
  // do not save if this is an auto save routine
426
+ if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
 
 
 
 
427
  {
428
  return $post_id;
429
  }
430
 
431
 
432
+ // verify nonce
433
+ if( !isset($_POST['acf_nonce']) || !wp_verify_nonce($_POST['acf_nonce'], 'input') )
 
434
  {
435
+ return $post_id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
  }
437
+
438
 
439
+ // update the post (may even be a revision / autosave preview)
440
+ do_action('acf/save_post', $post_id);
441
+
442
+
443
  }
444
 
445
 
446
 
447
  /*--------------------------------------------------------------------------------------
448
  *
449
+ * input_admin_head
450
  *
451
+ * This is fired from an action: acf/input/admin_head
452
  *
453
  * @author Elliot Condon
454
  * @since 3.0.6
455
  *
456
  *-------------------------------------------------------------------------------------*/
457
 
458
+ function input_admin_head()
459
  {
460
  // global
461
  global $wp_version, $post;
476
  acf.post_id = <?php echo $post_id; ?>;
477
  acf.nonce = "<?php echo wp_create_nonce( 'acf_nonce' ); ?>";
478
  acf.admin_url = "<?php echo admin_url(); ?>";
479
+ acf.ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
480
  acf.wp_version = "<?php echo $wp_version; ?>";
481
 
482
 
493
  acf.fields.file.text.title_edit = "Edit File";
494
  acf.fields.file.text.button_add = "Select File";
495
 
 
 
 
496
 
497
  // WYSIWYG
498
  <?php
514
  ?>
515
  </script>
516
  <?php
 
 
 
 
 
 
517
  }
518
 
519
 
520
+ /*
521
+ * input_admin_enqueue_scripts
 
522
  *
523
+ * @description:
524
+ * @since: 3.6
525
+ * @created: 30/01/13
526
+ */
527
 
528
+ function input_admin_enqueue_scripts()
529
  {
530
+ // scripts
531
  wp_enqueue_script(array(
532
  'jquery',
533
  'jquery-ui-core',
541
  ));
542
 
543
 
 
 
 
 
 
 
544
  // 3.5 media gallery
545
  if( function_exists('wp_enqueue_media') && !did_action( 'wp_enqueue_media' ))
546
  {
547
  wp_enqueue_media();
548
  }
549
+
550
+
551
+ // styles
 
 
 
 
 
 
 
 
 
 
 
552
  wp_enqueue_style(array(
553
  'thickbox',
554
  'farbtastic',
556
  'acf-input',
557
  'acf-datepicker',
558
  ));
 
 
 
 
 
559
  }
560
 
561
 
759
  return $fields;
760
 
761
  }
 
 
 
762
 
763
+
764
  }
765
 
766
+ new acf_input();
767
+
768
  ?>
core/controllers/location.php CHANGED
@@ -1,19 +1,16 @@
1
  <?php
2
 
3
  /*
4
- * acf_location
5
  *
6
- * @description:
7
- * @since: 3.5.7
8
- * @created: 3/01/13
9
  */
10
 
11
  class acf_location
12
  {
13
 
14
- var $parent,
15
- $data;
16
-
17
  /*
18
  * __construct
19
  *
@@ -22,12 +19,8 @@ class acf_location
22
  * @created: 23/06/12
23
  */
24
 
25
- function __construct($parent)
26
  {
27
- // vars
28
- $this->parent = $parent;
29
-
30
-
31
  // ajax
32
  add_action('wp_ajax_acf/location/match_field_groups_ajax', array($this, 'match_field_groups_ajax'));
33
 
@@ -59,11 +52,8 @@ class acf_location
59
 
60
  // Options Page
61
  add_filter('acf/location/rule_match/options_page', array($this, 'rule_match_options_page'), 10, 3);
62
-
63
-
64
-
65
  }
66
-
67
 
68
  /*
69
  * match_field_groups_ajax
@@ -117,6 +107,7 @@ class acf_location
117
 
118
  function match_field_groups( $return, $options )
119
  {
 
120
  // vars
121
  $defaults = array(
122
  'post_id' => 0,
@@ -140,7 +131,7 @@ class acf_location
140
 
141
 
142
  // Parse values
143
- $options = apply_filters( 'acf_parse_value', $options );
144
 
145
 
146
  // WPML
@@ -154,8 +145,8 @@ class acf_location
154
 
155
 
156
  // find all acf objects
157
- $acfs = apply_filters('acf/get_field_groups', false);
158
-
159
 
160
  // blank array to hold acfs
161
  $return = array();
@@ -165,6 +156,10 @@ class acf_location
165
  {
166
  foreach( $acfs as $acf )
167
  {
 
 
 
 
168
  // vars
169
  $add_box = false;
170
 
@@ -196,6 +191,7 @@ class acf_location
196
  $match = apply_filters( 'acf/location/rule_match/' . $rule['param'] , $match, $rule, $options );
197
 
198
 
 
199
  if( $acf['location']['allorany'] == 'all' && !$match )
200
  {
201
  // if all of the rules are required to match and this rule did not, don't add this box!
@@ -210,11 +206,13 @@ class acf_location
210
  }
211
  }
212
 
 
213
 
214
  // add ID to array
215
  if( $add_box )
216
  {
217
  $return[] = $acf['id'];
 
218
  }
219
 
220
  }
@@ -247,7 +245,7 @@ class acf_location
247
  $post_type = get_post_type( $options['post_id'] );
248
  }
249
 
250
-
251
  if( $rule['operator'] == "==" )
252
  {
253
  $match = ( $post_type === $rule['value'] );
@@ -256,7 +254,7 @@ class acf_location
256
  {
257
  $match = ( $post_type !== $rule['value'] );
258
  }
259
-
260
 
261
  return $match;
262
  }
@@ -350,6 +348,25 @@ class acf_location
350
  $match = ( $posts_page != $post->ID );
351
  }
352
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  }
354
  elseif( $rule['value'] == 'parent')
355
  {
@@ -542,6 +559,7 @@ class acf_location
542
  }
543
  }
544
  }
 
545
 
546
 
547
  if($rule['operator'] == "==")
@@ -573,7 +591,7 @@ class acf_location
573
 
574
 
575
  return $match;
576
-
577
  }
578
 
579
 
@@ -688,7 +706,7 @@ class acf_location
688
  }
689
  }
690
  }
691
-
692
 
693
  if($rule['operator'] == "==")
694
  {
@@ -701,8 +719,8 @@ class acf_location
701
  }
702
 
703
 
704
- return $match;
705
 
 
706
 
707
  }
708
 
@@ -825,7 +843,7 @@ class acf_location
825
  $match = ( $ef_taxonomy == $rule['value'] );
826
 
827
  // override for "all"
828
- if( $rule['value'] === "all" )
829
  {
830
  $match = true;
831
  }
@@ -836,7 +854,7 @@ class acf_location
836
  $match = ( $ef_taxonomy != $rule['value'] );
837
 
838
  // override for "all"
839
- if( $rule['value'] === "all" )
840
  {
841
  $match = false;
842
  }
@@ -880,12 +898,12 @@ class acf_location
880
  $match = true;
881
  }
882
  }
883
- elseif($rule['operator'] === "!=")
884
  {
885
  $match = ( !user_can($ef_user, $rule['value']) );
886
 
887
  // override for "all"
888
- if( $rule['value'] == "all" )
889
  {
890
  $match = false;
891
  }
@@ -947,7 +965,10 @@ class acf_location
947
  return $match;
948
 
949
  }
950
-
 
951
  }
952
 
 
 
953
  ?>
1
  <?php
2
 
3
  /*
4
+ * Locations
5
  *
6
+ * @description: controller for location match functionality
7
+ * @since: 3.6
8
+ * @created: 25/01/13
9
  */
10
 
11
  class acf_location
12
  {
13
 
 
 
 
14
  /*
15
  * __construct
16
  *
19
  * @created: 23/06/12
20
  */
21
 
22
+ function __construct()
23
  {
 
 
 
 
24
  // ajax
25
  add_action('wp_ajax_acf/location/match_field_groups_ajax', array($this, 'match_field_groups_ajax'));
26
 
52
 
53
  // Options Page
54
  add_filter('acf/location/rule_match/options_page', array($this, 'rule_match_options_page'), 10, 3);
 
 
 
55
  }
56
+
57
 
58
  /*
59
  * match_field_groups_ajax
107
 
108
  function match_field_groups( $return, $options )
109
  {
110
+
111
  // vars
112
  $defaults = array(
113
  'post_id' => 0,
131
 
132
 
133
  // Parse values
134
+ $options = apply_filters( 'acf/parse_types', $options );
135
 
136
 
137
  // WPML
145
 
146
 
147
  // find all acf objects
148
+ $acfs = apply_filters('acf/get_field_groups', array());
149
+
150
 
151
  // blank array to hold acfs
152
  $return = array();
156
  {
157
  foreach( $acfs as $acf )
158
  {
159
+ // load location
160
+ $acf['location'] = apply_filters('acf/field_group/get_location', array(), $acf['id']);
161
+
162
+
163
  // vars
164
  $add_box = false;
165
 
191
  $match = apply_filters( 'acf/location/rule_match/' . $rule['param'] , $match, $rule, $options );
192
 
193
 
194
+
195
  if( $acf['location']['allorany'] == 'all' && !$match )
196
  {
197
  // if all of the rules are required to match and this rule did not, don't add this box!
206
  }
207
  }
208
 
209
+
210
 
211
  // add ID to array
212
  if( $add_box )
213
  {
214
  $return[] = $acf['id'];
215
+
216
  }
217
 
218
  }
245
  $post_type = get_post_type( $options['post_id'] );
246
  }
247
 
248
+
249
  if( $rule['operator'] == "==" )
250
  {
251
  $match = ( $post_type === $rule['value'] );
254
  {
255
  $match = ( $post_type !== $rule['value'] );
256
  }
257
+
258
 
259
  return $match;
260
  }
348
  $match = ( $posts_page != $post->ID );
349
  }
350
 
351
+ }
352
+ elseif( $rule['value'] == 'top_level')
353
+ {
354
+ $post_parent = $post->post_parent;
355
+ if( $options['page_parent'] )
356
+ {
357
+ $post_parent = $options['page_parent'];
358
+ }
359
+
360
+
361
+ if($rule['operator'] == "==")
362
+ {
363
+ $match = ( $post_parent == 0 );
364
+ }
365
+ elseif($rule['operator'] == "!=")
366
+ {
367
+ $match = ( $post_parent != 0 );
368
+ }
369
+
370
  }
371
  elseif( $rule['value'] == 'parent')
372
  {
559
  }
560
  }
561
  }
562
+
563
 
564
 
565
  if($rule['operator'] == "==")
591
 
592
 
593
  return $match;
594
+
595
  }
596
 
597
 
706
  }
707
  }
708
  }
709
+
710
 
711
  if($rule['operator'] == "==")
712
  {
719
  }
720
 
721
 
 
722
 
723
+ return $match;
724
 
725
  }
726
 
843
  $match = ( $ef_taxonomy == $rule['value'] );
844
 
845
  // override for "all"
846
+ if( $rule['value'] == "all" )
847
  {
848
  $match = true;
849
  }
854
  $match = ( $ef_taxonomy != $rule['value'] );
855
 
856
  // override for "all"
857
+ if( $rule['value'] == "all" )
858
  {
859
  $match = false;
860
  }
898
  $match = true;
899
  }
900
  }
901
+ elseif($rule['operator'] == "!=")
902
  {
903
  $match = ( !user_can($ef_user, $rule['value']) );
904
 
905
  // override for "all"
906
+ if( $rule['value'] === "all" )
907
  {
908
  $match = false;
909
  }
965
  return $match;
966
 
967
  }
968
+
969
+
970
  }
971
 
972
+ new acf_location();
973
+
974
  ?>
core/controllers/options_page.php DELETED
@@ -1,318 +0,0 @@
1
- <?php
2
-
3
- class acf_options_page
4
- {
5
-
6
- /*
7
- * Vars
8
- *
9
- * @description:
10
- * @since: 2.0.4
11
- * @created: 5/12/12
12
- */
13
-
14
- var $parent,
15
- $dir,
16
- $data;
17
-
18
-
19
- /*
20
- * construct
21
- *
22
- * @description:
23
- * @since: 2.0.4
24
- * @created: 5/12/12
25
- */
26
-
27
- function __construct($parent)
28
- {
29
- // vars
30
- $this->parent = $parent;
31
- $this->dir = $parent->dir;
32
-
33
-
34
- // data for passing variables
35
- $this->data = array();
36
-
37
-
38
- // actions
39
- add_action('admin_menu', array($this,'admin_menu'));
40
-
41
- }
42
-
43
-
44
- /*
45
- * admin_menu
46
- *
47
- * @description:
48
- * @since: 2.0.4
49
- * @created: 5/12/12
50
- */
51
-
52
- function admin_menu()
53
- {
54
- // validate
55
- if( !$this->parent->is_field_unlocked('options_page') )
56
- {
57
- return true;
58
- }
59
-
60
-
61
- // vars
62
- $defaults = $this->parent->defaults['options_page'];
63
- $parent_slug = 'acf-options';
64
- $parent_title = $defaults['title'];
65
- $parent_menu = $defaults['title'];
66
-
67
-
68
- // redirect to first child
69
- if( !empty($defaults['pages']) )
70
- {
71
- $parent_title = $defaults['pages'][0];
72
- $parent_slug = 'acf-options-' . sanitize_title( $parent_title );
73
- }
74
-
75
-
76
- // Parent
77
- $parent_page = add_menu_page($parent_title, $parent_menu, $defaults['capability'], $parent_slug, array($this, 'html'));
78
-
79
-
80
- // some fields require js + css
81
- add_action('admin_print_scripts-'.$parent_page, array($this, 'admin_print_scripts'));
82
- add_action('admin_print_styles-'.$parent_page, array($this, 'admin_print_styles'));
83
-
84
-
85
- // Add admin head
86
- add_action('admin_head-'.$parent_page, array($this,'admin_head'));
87
- add_action('admin_footer-'.$parent_page, array($this,'admin_footer'));
88
-
89
-
90
- if( !empty($defaults['pages']) )
91
- {
92
- foreach($defaults['pages'] as $c)
93
- {
94
- $sub_title = $c;
95
- $sub_slug = 'acf-options-' . sanitize_title( $sub_title );
96
-
97
- $child_page = add_submenu_page($parent_slug, $sub_title, $sub_title, $defaults['capability'], $sub_slug, array($this, 'html'));
98
-
99
- // some fields require js + css
100
- add_action('admin_print_scripts-'.$child_page, array($this, 'admin_print_scripts'));
101
- add_action('admin_print_styles-'.$child_page, array($this, 'admin_print_styles'));
102
-
103
- // Add admin head
104
- add_action('admin_head-'.$child_page, array($this,'admin_head'));
105
- add_action('admin_footer-'.$child_page, array($this,'admin_footer'));
106
- }
107
- }
108
-
109
- }
110
-
111
-
112
- /*
113
- * admin_head
114
- *
115
- * @description:
116
- * @since: 2.0.4
117
- * @created: 5/12/12
118
- */
119
-
120
- function admin_head()
121
- {
122
-
123
- // save
124
- if( isset($_POST['acf_options_page']) )
125
- {
126
- if( wp_verify_nonce($_POST['acf_options_page'], 'acf_options_page') )
127
- {
128
- do_action('acf_save_post', 'options');
129
-
130
- $this->data['admin_message'] = __("Options Updated",'acf');
131
- }
132
- }
133
-
134
-
135
- // get field groups
136
- $filter = array();
137
- $metabox_ids = array();
138
- $metabox_ids = apply_filters( 'acf/location/match_field_groups', $metabox_ids, $filter );
139
-
140
-
141
- if(empty($metabox_ids))
142
- {
143
- $this->data['no_fields'] = true;
144
- return false;
145
- }
146
-
147
- // Style
148
- echo '<style type="text/css">#side-sortables.empty-container { border: 0 none; }</style>';
149
-
150
-
151
- // add user js + css
152
- do_action('acf_head-input');
153
-
154
-
155
- // get acf's
156
- $acfs = apply_filters('acf/get_field_groups', false);
157
- if($acfs)
158
- {
159
- foreach($acfs as $acf)
160
- {
161
- // hide / show
162
- $show = in_array($acf['id'], $metabox_ids) ? 1 : 0;
163
-
164
- if( $show )
165
- {
166
- // add meta box
167
- add_meta_box(
168
- 'acf_' . $acf['id'],
169
- $acf['title'],
170
- array($this->parent->input, 'meta_box_input'),
171
- 'acf_options_page',
172
- $acf['options']['position'],
173
- 'high',
174
- array( 'fields' => $acf['fields'], 'options' => $acf['options'], 'show' => $show, 'post_id' => "options" )
175
- );
176
- }
177
- }
178
- }
179
-
180
- }
181
-
182
-
183
- /*
184
- * admin_footer
185
- *
186
- * @description:
187
- * @since: 2.0.4
188
- * @created: 5/12/12
189
- */
190
-
191
- function admin_footer()
192
- {
193
- // add togle open / close postbox
194
- ?>
195
- <script type="text/javascript">
196
- (function($){
197
-
198
- $('.postbox .handlediv').live('click', function(){
199
-
200
- var postbox = $(this).closest('.postbox');
201
-
202
- if( postbox.hasClass('closed') )
203
- {
204
- postbox.removeClass('closed');
205
- }
206
- else
207
- {
208
- postbox.addClass('closed');
209
- }
210
-
211
- });
212
-
213
- })(jQuery);
214
- </script>
215
- <?php
216
- }
217
-
218
-
219
- /*
220
- * admin_print_scripts
221
- *
222
- * @description:
223
- * @since: 2.0.4
224
- * @created: 5/12/12
225
- */
226
-
227
- function admin_print_scripts()
228
- {
229
- do_action('acf_print_scripts-input');
230
- }
231
-
232
-
233
- /*
234
- * admin_print_styles
235
- *
236
- * @description:
237
- * @since: 2.0.4
238
- * @created: 5/12/12
239
- */
240
-
241
- function admin_print_styles()
242
- {
243
- do_action('acf_print_styles-input');
244
- }
245
-
246
-
247
- /*
248
- * html
249
- *
250
- * @description:
251
- * @since: 2.0.4
252
- * @created: 5/12/12
253
- */
254
-
255
- function html()
256
- {
257
- ?>
258
- <div class="wrap no_move">
259
-
260
- <div class="icon32" id="icon-options-general"><br></div>
261
- <h2><?php echo get_admin_page_title(); ?></h2>
262
-
263
- <?php if(isset($this->data['admin_message'])): ?>
264
- <div id="message" class="updated"><p><?php echo $this->data['admin_message']; ?></p></div>
265
- <?php endif; ?>
266
-
267
- <?php if(isset($this->data['no_fields'])): ?>
268
- <div id="message" class="updated"><p><?php _e("No Custom Field Group found for the options page",'acf'); ?>. <a href="<?php echo admin_url(); ?>post-new.php?post_type=acf"><?php _e("Create a Custom Field Group",'acf'); ?></a></p></div>
269
- <?php else: ?>
270
-
271
- <form id="post" method="post" name="post">
272
- <div class="metabox-holder has-right-sidebar" id="poststuff">
273
-
274
- <!-- Sidebar -->
275
- <div class="inner-sidebar" id="side-info-column">
276
-
277
- <!-- Update -->
278
- <div class="postbox">
279
- <h3 class="hndle"><span><?php _e("Publish",'acf'); ?></span></h3>
280
- <div class="inside">
281
- <input type="hidden" name="HTTP_REFERER" value="<?php echo $_SERVER['HTTP_REFERER'] ?>" />
282
- <input type="hidden" name="acf_options_page" value="<?php echo wp_create_nonce( 'acf_options_page' ); ?>" />
283
- <input type="submit" class="acf-button" value="<?php _e("Save Options",'acf'); ?>" />
284
- </div>
285
- </div>
286
-
287
- <?php $meta_boxes = do_meta_boxes('acf_options_page', 'side', null); ?>
288
-
289
- </div>
290
-
291
- <!-- Main -->
292
- <div id="post-body">
293
- <div id="post-body-content">
294
- <?php $meta_boxes = do_meta_boxes('acf_options_page', 'normal', null); ?>
295
- <script type="text/javascript">
296
- (function($){
297
-
298
- $('#poststuff .postbox[id*="acf_"]').addClass('acf_postbox');
299
-
300
- })(jQuery);
301
- </script>
302
- </div>
303
- </div>
304
-
305
- </div>
306
- </form>
307
-
308
- <?php endif; ?>
309
-
310
- </div>
311
-
312
- <?php
313
-
314
- }
315
-
316
- }
317
-
318
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/controllers/settings.php DELETED
@@ -1,684 +0,0 @@
1
- <?php
2
-
3
- /*
4
- * Settings
5
- *
6
- * @description: All the functionality for ACF Settings
7
- * @since 3.2.6
8
- * @created: 23/06/12
9
- */
10
-
11
-
12
- class acf_settings
13
- {
14
-
15
- var $parent;
16
-
17
-
18
- /*
19
- * __construct
20
- *
21
- * @description:
22
- * @since 3.1.8
23
- * @created: 23/06/12
24
- */
25
-
26
- function __construct($parent)
27
- {
28
-
29
- // vars
30
- $this->parent = $parent;
31
-
32
-
33
- // actions
34
- add_action('admin_menu', array($this,'admin_menu'), 11);
35
-
36
- }
37
-
38
-
39
- /*
40
- * admin_menu
41
- *
42
- * @description:
43
- * @since 3.1.8
44
- * @created: 23/06/12
45
- */
46
-
47
- function admin_menu()
48
- {
49
- $page = add_submenu_page('edit.php?post_type=acf', __('Settings','acf'), __('Settings','acf'), 'manage_options','acf-settings',array($this,'html'));
50
-
51
- add_action('load-' . $page, array($this,'load'));
52
-
53
- add_action('admin_print_scripts-' . $page, array($this, 'admin_print_scripts'));
54
- add_action('admin_print_styles-' . $page, array($this, 'admin_print_styles'));
55
-
56
- add_action('admin_head-' . $page, array($this,'admin_head'));
57
-
58
- }
59
-
60
-
61
- /*
62
- * load
63
- *
64
- * @description:
65
- * @since 3.5.2
66
- * @created: 16/11/12
67
- * @thanks: Kevin Biloski and Charlie Eriksen via Secunia SVCRP
68
- */
69
-
70
- function load()
71
- {
72
- // vars
73
- $defaults = array(
74
- 'action' => ''
75
- );
76
- $options = array_merge($defaults, $_POST);
77
-
78
-
79
- if( $options['action'] == "export_xml" )
80
- {
81
- include_once($this->parent->path . 'core/actions/export.php');
82
- die;
83
- }
84
- }
85
-
86
-
87
- /*
88
- * admin_print_scripts
89
- *
90
- * @description:
91
- * @since 3.1.8
92
- * @created: 23/06/12
93
- */
94
-
95
- function admin_print_scripts()
96
- {
97
- wp_enqueue_script( 'wp-pointer' );
98
- }
99
-
100
-
101
- /*
102
- * admin_print_styles
103
- *
104
- * @description:
105
- * @since 3.1.8
106
- * @created: 23/06/12
107
- */
108
-
109
- function admin_print_styles()
110
- {
111
- wp_enqueue_style(array(
112
- 'wp-pointer',
113
- 'acf-global',
114
- 'acf',
115
- ));
116
- }
117
-
118
-
119
- /*
120
- * admin_head
121
- *
122
- * @description:
123
- * @since 3.1.8
124
- * @created: 23/06/12
125
- */
126
-
127
- function admin_head()
128
- {
129
-
130
- // Activate / Deactivate Add-ons
131
- if( isset($_POST['acf_field_deactivate']) )
132
- {
133
- // vars
134
- $message = "";
135
- $field = $_POST['acf_field_deactivate'];
136
-
137
- // delete field
138
- delete_option('acf_'.$field.'_ac');
139
-
140
- //set message
141
- if($field == "repeater")
142
- {
143
- $message = '<p>' . __("Repeater field deactivated",'acf') . '</p>';
144
- }
145
- elseif($field == "options_page")
146
- {
147
- $message = '<p>' . __("Options page deactivated",'acf') . '</p>';
148
- }
149
- elseif($field == "flexible_content")
150
- {
151
- $message = '<p>' . __("Flexible Content field deactivated",'acf') . '</p>';
152
- }
153
- elseif($field == "gallery")
154
- {
155
- $message = '<p>' . __("Gallery field deactivated",'acf') . '</p>';
156
- }
157
-
158
- // show message on page
159
- $this->parent->admin_message($message);
160
- }
161
-
162
-
163
- if( isset($_POST['acf_field_activate']) && isset($_POST['key']) )
164
- {
165
- // vars
166
- $message = "";
167
- $field = $_POST['acf_field_activate'];
168
- $key = trim($_POST['key']);
169
-
170
- // update option
171
- update_option('acf_'.$field.'_ac', $key);
172
-
173
- // did it unlock?
174
- if($this->parent->is_field_unlocked($field))
175
- {
176
- //set message
177
- if($field == "repeater")
178
- {
179
- $message = '<p>' . __("Repeater field activated",'acf') . '</p>';
180
- }
181
- elseif($field == "options_page")
182
- {
183
- $message = '<p>' . __("Options page activated",'acf') . '</p>';
184
- }
185
- elseif($field == "flexible_content")
186
- {
187
- $message = '<p>' . __("Flexible Content field activated",'acf') . '</p>';
188
- }
189
- elseif($field == "gallery")
190
- {
191
- $message = '<p>' . __("Gallery field activated",'acf') . '</p>';
192
- }
193
- }
194
- else
195
- {
196
- $message = '<p>' . __("License key unrecognised",'acf') . '</p>';
197
- }
198
-
199
- $this->parent->admin_message($message);
200
- }
201
- }
202
-
203
-
204
- /*
205
- * html_index
206
- *
207
- * @description:
208
- * @created: 9/08/12
209
- */
210
-
211
- function html_index()
212
- {
213
- // vars
214
- $acfs = get_posts(array(
215
- 'numberposts' => -1,
216
- 'post_type' => 'acf',
217
- 'orderby' => 'menu_order title',
218
- 'order' => 'asc',
219
- ));
220
-
221
- // blank array to hold acfs
222
- $choices = array();
223
-
224
- if($acfs)
225
- {
226
- foreach($acfs as $acf)
227
- {
228
- // find title. Could use get_the_title, but that uses get_post(), so I think this uses less Memory
229
- $title = apply_filters( 'the_title', $acf->post_title, $acf->ID );
230
-
231
- $choices[$acf->ID] = $title;
232
- }
233
- }
234
-
235
- ?>
236
- <table class="form-table acf-form-table">
237
- <tbody>
238
- <tr>
239
- <th scope="row">
240
- <h3><?php _e("Activate Add-ons.",'acf'); ?></h3>
241
- <p><?php _e("Add-ons can be unlocked by purchasing a license key. Each key can be used on multiple sites.",'acf'); ?></p>
242
- <p><a target="_blank" href="http://www.advancedcustomfields.com/add-ons/"><?php _e("Find Add-ons",'acf'); ?></a></p>
243
- </th>
244
- <td>
245
- <div class="wp-box">
246
- <table class="acf_activate widefat">
247
- <thead>
248
- <tr>
249
- <th><?php _e("Field Type",'acf'); ?></th>
250
- <th><?php _e("Status",'acf'); ?></th>
251
- <th style="width:50%;"><?php _e("Activation Code",'acf'); ?></th>
252
- </tr>
253
- </thead>
254
- <tbody>
255
- <tr>
256
- <td><?php _e("Repeater Field",'acf'); ?></td>
257
- <td><?php echo $this->parent->is_field_unlocked('repeater') ? __("Active",'acf') : __("Inactive",'acf'); ?></td>
258
- <td>
259
- <form action="" method="post">
260
- <?php if($this->parent->is_field_unlocked('repeater')){
261
- echo '<span class="activation_code">XXXX-XXXX-XXXX-'.substr($this->parent->get_license_key('repeater'),-4) .'</span>';
262
- echo '<input type="hidden" name="acf_field_deactivate" value="repeater" />';
263
- echo '<input type="submit" class="button" value="' . __("Deactivate",'acf') . '" />';
264
- }
265
- else
266
- {
267
- echo '<input type="text" name="key" value="" />';
268
- echo '<input type="hidden" name="acf_field_activate" value="repeater" />';
269
- echo '<input type="submit" class="button" value="' . __("Activate",'acf') . '" />';
270
- } ?>
271
- </form>
272
- </td>
273
- </tr>
274
- <tr>
275
- <td><?php _e("Flexible Content Field",'acf'); ?></td>
276
- <td><?php echo $this->parent->is_field_unlocked('flexible_content') ? __("Active",'acf') : __("Inactive",'acf'); ?></td>
277
- <td>
278
- <form action="" method="post">
279
- <?php if($this->parent->is_field_unlocked('flexible_content')){
280
- echo '<span class="activation_code">XXXX-XXXX-XXXX-'.substr($this->parent->get_license_key('flexible_content'),-4) .'</span>';
281
- echo '<input type="hidden" name="acf_field_deactivate" value="flexible_content" />';
282
- echo '<input type="submit" class="button" value="' . __("Deactivate",'acf') . '" />';
283
- }
284
- else
285
- {
286
- echo '<input type="text" name="key" value="" />';
287
- echo '<input type="hidden" name="acf_field_activate" value="flexible_content" />';
288
- echo '<input type="submit" class="button" value="' . __("Activate",'acf') . '" />';
289
- } ?>
290
- </form>
291
- </td>
292
- </tr>
293
- <tr>
294
- <td><?php _e("Gallery Field",'acf'); ?></td>
295
- <td><?php echo $this->parent->is_field_unlocked('gallery') ? __("Active",'acf') : __("Inactive",'acf'); ?></td>
296
- <td>
297
- <form action="" method="post">
298
- <?php if($this->parent->is_field_unlocked('gallery')){
299
- echo '<span class="activation_code">XXXX-XXXX-XXXX-'.substr($this->parent->get_license_key('gallery'),-4) .'</span>';
300
- echo '<input type="hidden" name="acf_field_deactivate" value="gallery" />';
301
- echo '<input type="submit" class="button" value="' . __("Deactivate",'acf') . '" />';
302
- }
303
- else
304
- {
305
- echo '<input type="text" name="key" value="" />';
306
- echo '<input type="hidden" name="acf_field_activate" value="gallery" />';
307
- echo '<input type="submit" class="button" value="' . __("Activate",'acf') . '" />';
308
- } ?>
309
- </form>
310
- </td>
311
- </tr>
312
- <tr>
313
- <td><?php _e("Options Page",'acf'); ?></td>
314
- <td><?php echo $this->parent->is_field_unlocked('options_page') ? __("Active",'acf') : __("Inactive",'acf'); ?></td>
315
- <td>
316
- <form action="" method="post">
317
- <?php if($this->parent->is_field_unlocked('options_page')){
318
- echo '<span class="activation_code">XXXX-XXXX-XXXX-'.substr($this->parent->get_license_key('options_page'),-4) .'</span>';
319
- echo '<input type="hidden" name="acf_field_deactivate" value="options_page" />';
320
- echo '<input type="submit" class="button" value="' . __("Deactivate",'acf') . '" />';
321
- }
322
- else
323
- {
324
- echo '<input type="text" name="key" value="" />';
325
- echo '<input type="hidden" name="acf_field_activate" value="options_page" />';
326
- echo '<input type="submit" class="button" value="' . __("Activate",'acf') . '" />';
327
- } ?>
328
- </form>
329
- </td>
330
- </tr>
331
- </tbody>
332
- </table>
333
- </div>
334
- </td>
335
- </tr>
336
- <tr>
337
- <th scope="row">
338
- <h3><?php _e("Export Field Groups to XML",'acf'); ?></h3>
339
- <p><?php _e("ACF will create a .xml export file which is compatible with the native WP import plugin.",'acf'); ?></p>
340
- <p><a href="#" class="show-pointer" rel="xml-import-instructions-html"><?php _e("Instructions",'acf'); ?></a></p>
341
- <div id="xml-import-instructions-html" style="display:none;">
342
- <h3><?php _e("Import Field Groups",'acf'); ?></h3>
343
- <p><?php _e("Imported field groups <b>will</b> appear in the list of editable field groups. This is useful for migrating fields groups between Wp websites.",'acf'); ?></p>
344
- <ol>
345
- <li><?php _e("Select field group(s) from the list and click \"Export XML\"",'acf'); ?></li>
346
- <li><?php _e("Save the .xml file when prompted",'acf'); ?></li>
347
- <li><?php _e("Navigate to Tools &raquo; Import and select WordPress",'acf'); ?></li>
348
- <li><?php _e("Install WP import plugin if prompted",'acf'); ?></li>
349
- <li><?php _e("Upload and import your exported .xml file",'acf'); ?></li>
350
- <li><?php _e("Select your user and ignore Import Attachments",'acf'); ?></li>
351
- <li><?php _e("That's it! Happy WordPressing",'acf'); ?></li>
352
- </ol>
353
- </div>
354
- </th>
355
- <td>
356
- <form class="acf-export-form" method="post">
357
- <input type="hidden" name="action" value="export_xml" />
358
- <?php
359
-
360
- do_action('acf/create_field', array(
361
- 'type' => 'select',
362
- 'name' => 'acf_posts',
363
- 'value' => '',
364
- 'choices' => $choices,
365
- 'multiple' => 1,
366
- ));
367
-
368
- ?>
369
- <ul class="hl clearfix">
370
- <li class="right"><input type="submit" class="acf-button" value="<?php _e("Export XML",'acf'); ?>" /></li>
371
- </ul>
372
- </form>
373
- </td>
374
- </tr>
375
- <tr>
376
- <th scope="row">
377
- <h3><?php _e("Export Field Groups to PHP",'acf'); ?></h3>
378
- <p><?php _e("ACF will create the PHP code to include in your theme.",'acf'); ?></p>
379
- <p><a href="#" class="show-pointer" rel="php-import-instructions-html"><?php _e("Instructions",'acf'); ?></a></p>
380
- <div id="php-import-instructions-html" style="display:none;">
381
- <h3><?php _e("Register Field Groups",'acf'); ?></h3>
382
- <p><?php _e("Registered field groups <b>will not</b> appear in the list of editable field groups. This is useful for including fields in themes.",'acf'); ?></p>
383
- <p><?php _e("Please note that if you export and register field groups within the same WP, you will see duplicate fields on your edit screens. To fix this, please move the origional field group to the trash or remove the code from your functions.php file.",'acf'); ?></p>
384
- <ol>
385
- <li><?php _e("Select field group(s) from the list and click \"Create PHP\"",'acf'); ?></li>
386
- <li><?php _e("Copy the PHP code generated",'acf'); ?></li>
387
- <li><?php _e("Paste into your functions.php file",'acf'); ?></li>
388
- <li><?php _e("To activate any Add-ons, edit and use the code in the first few lines.",'acf'); ?></li>
389
- </ol>
390
- </div>
391
- </th>
392
- <td>
393
- <form class="acf-export-form" method="post">
394
- <input type="hidden" name="action" value="export_php" />
395
- <?php
396
-
397
- do_action('acf/create_field', array(
398
- 'type' => 'select',
399
- 'name' => 'acf_posts',
400
- 'value' => '',
401
- 'choices' => $choices,
402
- 'multiple' => 1,
403
- ));
404
-
405
- ?>
406
- <ul class="hl clearfix">
407
- <li class="right"><input type="submit" class="acf-button" value="<?php esc_attr_e("Create PHP",'acf'); ?>" /></li>
408
- </ul>
409
- </form>
410
- </td>
411
- </tr>
412
- </tbody>
413
- </table>
414
- <script type="text/javascript">
415
- (function($){
416
-
417
- $(document).ready(function(){
418
-
419
- $('a.show-pointer').each(function(){
420
-
421
- // vars
422
- var a = $(this),
423
- html = a.attr('rel');
424
-
425
-
426
- // create pointer
427
- a.pointer({
428
- content: $('#' + html).html(),
429
- position: {
430
- my: 'left bottom',
431
- at: 'left top',
432
- edge: 'bottom',
433
- },
434
- close: function() {
435
-
436
- a.removeClass('open');
437
-
438
- }
439
- });
440
-
441
-
442
- // click
443
- a.click(function(){
444
-
445
- if( a.hasClass('open') )
446
- {
447
- a.removeClass('open');
448
- }
449
- else
450
- {
451
- a.addClass('open');
452
- }
453
-
454
- });
455
-
456
-
457
- // show on hover
458
- a.hover(function(){
459
-
460
- $(this).pointer('open');
461
-
462
- }, function(){
463
-
464
- if( ! a.hasClass('open') )
465
- {
466
- $(this).pointer('close');
467
- }
468
-
469
- });
470
-
471
- });
472
-
473
- });
474
-
475
- })(jQuery);
476
- </script>
477
- <?php
478
-
479
- }
480
-
481
-
482
- /*
483
- * html_php
484
- *
485
- * @description:
486
- * @created: 9/08/12
487
- */
488
-
489
- function html_php()
490
- {
491
-
492
- ?>
493
- <p><a href="">&laquo; <?php _e("Back to settings",'acf'); ?></a></p>
494
- <table class="form-table acf-form-table">
495
- <tbody>
496
- <tr>
497
- <th scope="row">
498
- <h3><?php _e("Register Field Groups",'acf'); ?></h3>
499
- <p><?php _e("Registered field groups <b>will not</b> appear in the list of editable field groups. This is useful for including fields in themes.",'acf'); ?></p>
500
- <p><?php _e("Please note that if you export and register field groups within the same WP, you will see duplicate fields on your edit screens. To fix this, please move the origional field group to the trash or remove the code from your functions.php file.",'acf'); ?></p>
501
- <ol>
502
- <li><?php _e("Copy the PHP code generated",'acf'); ?></li>
503
- <li><?php _e("Paste into your functions.php file",'acf'); ?></li>
504
- <li><?php _e("To activate any Add-ons, edit and use the code in the first few lines.",'acf'); ?></li>
505
- </ol>
506
-
507
- <br />
508
-
509
- <h3><?php _e("ACF Lite",'acf'); ?></h3>
510
- <p><?php _e("Advanced Custom Fields has a lite version to be included in premium themes. You can find out more on github",'acf'); ?> <a href="https://github.com/elliotcondon/acf/" target="_blank"><?php _e("here",'acf'); ?></a>.</p>
511
-
512
- </th>
513
- <td valign="top">
514
- <div class="wp-box">
515
- <div class="inner">
516
- <textarea class="pre" readonly="true"><?php
517
-
518
- $acfs = array();
519
-
520
- if(isset($_POST['acf_posts']))
521
- {
522
- $acfs = get_posts(array(
523
- 'numberposts' => -1,
524
- 'post_type' => 'acf',
525
- 'orderby' => 'menu_order title',
526
- 'order' => 'asc',
527
- 'include' => $_POST['acf_posts'],
528
- ));
529
- }
530
- if($acfs)
531
- {
532
- ?>
533
- <?php _e("/**
534
- * Activate Add-ons
535
- * Here you can enter your activation codes to unlock Add-ons to use in your theme.
536
- * Since all activation codes are multi-site licenses, you are allowed to include your key in premium themes.
537
- */",'acf'); ?>
538
-
539
-
540
- function my_acf_settings( $options )
541
- {
542
- // activate add-ons
543
- $options['activation_codes']['repeater'] = 'XXXX-XXXX-XXXX-XXXX';
544
- $options['activation_codes']['options_page'] = 'XXXX-XXXX-XXXX-XXXX';
545
- $options['activation_codes']['flexible_content'] = 'XXXX-XXXX-XXXX-XXXX';
546
- $options['activation_codes']['gallery'] = 'XXXX-XXXX-XXXX-XXXX';
547
-
548
- // setup other options (http://www.advancedcustomfields.com/docs/filters/acf_settings/)
549
-
550
- return $options;
551
-
552
- }
553
- add_filter('acf_settings', 'my_acf_settings');
554
-
555
-
556
- <?php _e("/**
557
- * Register field groups
558
- * The register_field_group function accepts 1 array which holds the relevant data to register a field group
559
- * You may edit the array as you see fit. However, this may result in errors if the array is not compatible with ACF
560
- * This code must run every time the functions.php file is read
561
- */",'acf'); ?>
562
-
563
-
564
- if(function_exists("register_field_group"))
565
- {
566
- <?php
567
- foreach($acfs as $acf)
568
- {
569
- $var = array(
570
- 'id' => uniqid(),
571
- 'title' => get_the_title($acf->ID),
572
- 'fields' => $this->parent->get_acf_fields($acf->ID),
573
- 'location' => $this->parent->get_acf_location($acf->ID),
574
- 'options' => $this->parent->get_acf_options($acf->ID),
575
- 'menu_order' => $acf->menu_order,
576
- );
577
-
578
- $html = var_export($var, true);
579
-
580
- // change double spaces to tabs
581
- $html = str_replace(" ", "\t", $html);
582
-
583
- // add extra tab at start of each line
584
- $html = str_replace("\n", "\n\t", $html);
585
-
586
- ?> register_field_group(<?php echo $html ?>);
587
- <?php
588
- }
589
- ?>
590
- }
591
- <?php
592
- }
593
- else
594
- {
595
- _e("No field groups were selected",'acf');
596
- }
597
- ?></textarea>
598
- </div>
599
- </div>
600
- </td>
601
- </tr>
602
- </tbody>
603
- </table>
604
- <script type="text/javascript">
605
- (function($){
606
-
607
- var i = 0;
608
-
609
- $('textarea.pre').live( 'mousedown', function (){
610
-
611
- if( i == 0 )
612
- {
613
- i++;
614
-
615
- $(this).focus().select();
616
-
617
- return false;
618
- }
619
-
620
- });
621
-
622
-
623
- $('textarea.pre').live( 'keyup', function (){
624
- $(this).height( 0 );
625
- $(this).height( this.scrollHeight );
626
- });
627
-
628
-
629
- $(document).ready(function(){
630
-
631
- $('textarea.pre').trigger('keyup');
632
-
633
- });
634
-
635
- })(jQuery);
636
- </script>
637
- <?php
638
- }
639
-
640
-
641
- /*
642
- * html
643
- *
644
- * @description:
645
- * @since 3.1.8
646
- * @created: 23/06/12
647
- */
648
-
649
- function html()
650
- {
651
- // vars
652
- $defaults = array(
653
- 'action' => ''
654
- );
655
- $options = array_merge($defaults, $_POST);
656
-
657
- ?>
658
- <div class="wrap">
659
-
660
- <div class="icon32" id="icon-acf"><br></div>
661
- <h2 style="margin: 4px 0 25px;"><?php _e("Advanced Custom Fields Settings",'acf'); ?></h2>
662
- <?php
663
-
664
- if( $options['action'] == "export_php" )
665
- {
666
- $this->html_php();
667
- }
668
- else
669
- {
670
- $this->html_index();
671
- }
672
-
673
- ?>
674
- </div>
675
- <?php
676
-
677
- return;
678
-
679
- }
680
-
681
-
682
- }
683
-
684
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/controllers/third_party.php CHANGED
@@ -1,20 +1,15 @@
1
  <?php
2
 
3
  /*
4
- * third_party
5
  *
6
- * @description:
7
- * @since 3.5.1
8
- * @created: 23/06/12
9
  */
10
-
11
- class acf_third_party
12
- {
13
 
14
- var $parent,
15
- $data;
16
-
17
-
18
  /*
19
  * __construct
20
  *
@@ -23,13 +18,8 @@ class acf_third_party
23
  * @created: 23/06/12
24
  */
25
 
26
- function __construct($parent)
27
  {
28
- // vars
29
- $this->parent = $parent;
30
- $this->data['metaboxes'] = array();
31
-
32
-
33
  // Tabify Edit Screen - http://wordpress.org/extend/plugins/tabify-edit-screen/
34
  add_action('admin_head-settings_page_tabify-edit-screen', array($this,'admin_head_tabify'));
35
 
@@ -40,15 +30,10 @@ class acf_third_party
40
 
41
  // Post Type Switcher - http://wordpress.org/extend/plugins/post-type-switcher/
42
  add_filter('pts_post_type_filter', array($this, 'pts_post_type_filter'));
43
-
44
-
45
- // WordPres Importer
46
- add_filter('import_post_meta_key', array($this, 'import_post_meta_key'), 10, 1);
47
- add_action('import_post_meta', array($this, 'import_post_meta'), 10, 3);
48
-
49
  }
50
 
51
 
 
52
  /*
53
  * pts_allowed_pages
54
  *
@@ -127,7 +112,7 @@ class acf_third_party
127
  function tabify_add_meta_boxes( $post_type )
128
  {
129
  // get acf's
130
- $acfs = apply_filters('acf/get_field_groups', false);
131
 
132
  if($acfs)
133
  {
@@ -170,22 +155,25 @@ class acf_third_party
170
 
171
  // update keys
172
  $metas = get_post_custom( $new_post_id );
173
-
 
174
  if( $metas )
175
  {
176
  foreach( $metas as $field_key => $field )
177
  {
178
  if( strpos($field_key, 'field_') !== false )
179
  {
180
- $field = maybe_unserialize($field[0]);
 
 
181
 
182
  // delete old field
183
  delete_post_meta($new_post_id, $field_key);
184
 
185
-
186
  // set new keys (recursive for sub fields)
187
- $field = $this->create_new_field_keys( $field );
188
-
189
 
190
  // save it!
191
  update_post_meta($new_post_id, $field['key'], $field);
@@ -208,72 +196,39 @@ class acf_third_party
208
  * @created: 9/10/12
209
  */
210
 
211
- function create_new_field_keys( $field )
212
  {
213
- // get next id
214
- $next_id = (int) get_option('acf_next_field_id', 1);
215
-
216
-
217
- // update the acf_next_field_id
218
- update_option('acf_next_field_id', ($next_id + 1) );
219
-
220
-
221
  // update key
222
- $field['key'] = 'field_' . $next_id;
223
 
224
 
225
- // update sub field's keys
226
- if( isset( $field['sub_fields'] ) )
227
  {
228
- foreach( $field['sub_fields'] as $k => $v )
229
  {
230
- $field['sub_fields'][ $k ] = $this->create_new_field_keys( $v );
231
  }
232
  }
233
-
234
-
235
- return $field;
236
- }
237
-
238
-
239
- /*
240
- * import_post_meta
241
- *
242
- * @description:
243
- * @since: 3.5.5
244
- * @created: 31/12/12
245
- */
246
-
247
- function import_post_meta_key( $meta_key )
248
- {
249
- if( strpos($meta_key, 'field_') !== false )
250
  {
251
- $meta_key = 'field_' . $this->parent->get_next_field_id();
 
 
 
 
 
 
 
 
 
 
252
  }
253
-
254
- return $meta_key;
255
  }
256
 
257
 
258
- /*
259
- * import_post_meta
260
- *
261
- * @description:
262
- * @since: 3.5.5
263
- * @created: 1/01/13
264
- */
265
-
266
- function import_post_meta( $post_id, $key, $value )
267
- {
268
- if( strpos($key, 'field_') !== false )
269
- {
270
- $value['key'] = $key;
271
 
272
- update_post_meta( $post_id, $key, $value );
273
- }
274
- }
275
-
276
-
277
  }
278
 
 
 
279
  ?>
1
  <?php
2
 
3
  /*
4
+ * acf_third_party
5
  *
6
+ * @description: controller for add-ons sub menu page
7
+ * @since: 3.6
8
+ * @created: 25/01/13
9
  */
 
 
 
10
 
11
+ class acf_third_party
12
+ {
 
 
13
  /*
14
  * __construct
15
  *
18
  * @created: 23/06/12
19
  */
20
 
21
+ function __construct()
22
  {
 
 
 
 
 
23
  // Tabify Edit Screen - http://wordpress.org/extend/plugins/tabify-edit-screen/
24
  add_action('admin_head-settings_page_tabify-edit-screen', array($this,'admin_head_tabify'));
25
 
30
 
31
  // Post Type Switcher - http://wordpress.org/extend/plugins/post-type-switcher/
32
  add_filter('pts_post_type_filter', array($this, 'pts_post_type_filter'));
 
 
 
 
 
 
33
  }
34
 
35
 
36
+
37
  /*
38
  * pts_allowed_pages
39
  *
112
  function tabify_add_meta_boxes( $post_type )
113
  {
114
  // get acf's
115
+ $acfs = apply_filters('acf/get_field_groups', array());
116
 
117
  if($acfs)
118
  {
155
 
156
  // update keys
157
  $metas = get_post_custom( $new_post_id );
158
+
159
+
160
  if( $metas )
161
  {
162
  foreach( $metas as $field_key => $field )
163
  {
164
  if( strpos($field_key, 'field_') !== false )
165
  {
166
+ $field = $field[0];
167
+ $field = maybe_unserialize( $field );
168
+ $field = maybe_unserialize( $field ); // just to be sure!
169
 
170
  // delete old field
171
  delete_post_meta($new_post_id, $field_key);
172
 
173
+
174
  // set new keys (recursive for sub fields)
175
+ $this->create_new_field_keys( $field );
176
+
177
 
178
  // save it!
179
  update_post_meta($new_post_id, $field['key'], $field);
196
  * @created: 9/10/12
197
  */
198
 
199
+ function create_new_field_keys( &$field )
200
  {
 
 
 
 
 
 
 
 
201
  // update key
202
+ $field['key'] = 'field_' . uniqid();
203
 
204
 
205
+ if( isset($field['sub_fields']) && is_array($field['sub_fields']) )
 
206
  {
207
+ foreach( $field['sub_fields'] as $f )
208
  {
209
+ $this->create_new_field_keys( $f );
210
  }
211
  }
212
+ elseif( isset($field['layouts']) && is_array($field['layouts']) )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  {
214
+ foreach( $field['layouts'] as $layout )
215
+ {
216
+ if( isset($layout['sub_fields']) && is_array($layout['sub_fields']) )
217
+ {
218
+ foreach( $layout['sub_fields'] as $f )
219
+ {
220
+ $this->create_new_field_keys( $f );
221
+ }
222
+ }
223
+
224
+ }
225
  }
 
 
226
  }
227
 
228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
 
 
 
 
 
 
230
  }
231
 
232
+ new acf_third_party();
233
+
234
  ?>
core/controllers/upgrade.php CHANGED
@@ -12,9 +12,6 @@
12
  class acf_upgrade
13
  {
14
 
15
- var $parent;
16
-
17
-
18
  /*
19
  * __construct
20
  *
@@ -23,15 +20,9 @@ class acf_upgrade
23
  * @created: 23/06/12
24
  */
25
 
26
- function __construct($parent)
27
  {
28
-
29
- // vars
30
- $this->parent = $parent;
31
-
32
-
33
  // actions
34
- add_action('init', array($this,'init'));
35
  add_action('admin_menu', array($this,'admin_menu'), 11);
36
  add_action('wp_ajax_acf_upgrade', array($this, 'upgrade_ajax'));
37
 
@@ -48,37 +39,35 @@ class acf_upgrade
48
 
49
  function admin_menu()
50
  {
51
- add_submenu_page('edit.php?post_type=acf', __('Upgrade','acf'), __('Upgrade','acf'), 'manage_options','acf-upgrade', array($this,'html') );
52
- }
53
-
54
-
55
- /*
56
- * init
57
- *
58
- * @description:
59
- * @since 3.1.8
60
- * @created: 23/06/12
61
- */
62
-
63
- function init()
64
- {
65
- $version = get_option('acf_version', false);
66
- if( $version )
67
  {
68
- if( $version < $this->parent->upgrade_version )
 
 
69
  {
70
- $this->parent->admin_message('<p>' . __("Advanced Custom Fields",'acf') . ' v' . $this->parent->version . ' ' . __("requires a database upgrade",'acf') .' (<a class="thickbox" href="' . admin_url() . 'plugin-install.php?tab=plugin-information&plugin=advanced-custom-fields&section=changelog&TB_iframe=true&width=640&height=559">' . __("why?",'acf') .'</a>). ' . __("Please",'acf') .' <a href="http://codex.wordpress.org/Backing_Up_Your_Database">' . __("backup your database",'acf') .'</a>, '. __("then click",'acf') . ' <a href="' . admin_url() . 'edit.php?post_type=acf&page=acf-upgrade" class="button">' . __("Upgrade Database",'acf') . '</a></p>');
71
-
72
  }
73
- elseif( $version < $this->parent->version)
74
  {
75
- update_option('acf_version', $this->parent->version );
 
 
 
 
 
 
 
 
 
 
76
  }
77
  }
78
- else
79
- {
80
- update_option('acf_version', $this->parent->version );
81
- }
82
  }
83
 
84
 
@@ -827,4 +816,6 @@ class acf_upgrade
827
 
828
  }
829
 
 
 
830
  ?>
12
  class acf_upgrade
13
  {
14
 
 
 
 
15
  /*
16
  * __construct
17
  *
20
  * @created: 23/06/12
21
  */
22
 
23
+ function __construct()
24
  {
 
 
 
 
 
25
  // actions
 
26
  add_action('admin_menu', array($this,'admin_menu'), 11);
27
  add_action('wp_ajax_acf_upgrade', array($this, 'upgrade_ajax'));
28
 
39
 
40
  function admin_menu()
41
  {
42
+ // vars
43
+ $new_version = apply_filters('acf/get_info', 'version');
44
+ $old_version = get_option('acf_version', false);
45
+
46
+ if( $new_version != $old_version )
 
 
 
 
 
 
 
 
 
 
 
47
  {
48
+ update_option('acf_version', $new_version );
49
+
50
+ if( !$old_version )
51
  {
52
+ // do nothing, this is a fresh install
 
53
  }
54
+ elseif( $new_version > $old_version )
55
  {
56
+ // this is a newer version (update)
57
+ $url = admin_url('edit.php?post_type=acf&info=changelog');
58
+
59
+ if( $new_version == '4.0.0' )
60
+ {
61
+ $url = admin_url('edit.php?post_type=acf&info=whats-new');
62
+ }
63
+
64
+ wp_redirect( $url );
65
+ exit;
66
+
67
  }
68
  }
69
+
70
+ add_submenu_page('edit.php?post_type=acf', __('Upgrade','acf'), __('Upgrade','acf'), 'manage_options','acf-upgrade', array($this,'html') );
 
 
71
  }
72
 
73
 
816
 
817
  }
818
 
819
+ new acf_upgrade();
820
+
821
  ?>
core/fields/_base.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * acf_field
5
+ *
6
+ * @description: This is the base class for all fields.
7
+ * @since: 3.6
8
+ * @created: 30/01/13
9
+ */
10
+
11
+ class acf_field
12
+ {
13
+ /*
14
+ * Vars
15
+ *
16
+ * @description:
17
+ * @since: 3.6
18
+ * @created: 30/01/13
19
+ */
20
+
21
+ var $name,
22
+ $title,
23
+ $category;
24
+
25
+
26
+ /*
27
+ * __construct()
28
+ *
29
+ * Adds neccessary Actions / Filters
30
+ *
31
+ * @since 3.6
32
+ * @date 30/01/13
33
+ */
34
+
35
+ function __construct()
36
+ {
37
+ // register field
38
+ add_filter('acf/registered_fields', array($this, 'registered_fields'), 10, 1);
39
+
40
+
41
+ // value
42
+ $this->add_filter('acf/load_value/type=' . $this->name, array($this, 'load_value'), 10, 3);
43
+ $this->add_filter('acf/update_value/type=' . $this->name, array($this, 'update_value'), 10, 3);
44
+ $this->add_filter('acf/format_value/type=' . $this->name, array($this, 'format_value'), 10, 3);
45
+ $this->add_filter('acf/format_value_for_api/type=' . $this->name, array($this, 'format_value_for_api'), 10, 3);
46
+
47
+
48
+ // field
49
+ $this->add_filter('acf/load_field/type=' . $this->name, array($this, 'load_field'), 10, 3);
50
+ $this->add_filter('acf/update_field/type=' . $this->name, array($this, 'update_field'), 10, 2);
51
+ $this->add_action('acf/create_field/type=' . $this->name, array($this, 'create_field'), 10, 1);
52
+ $this->add_action('acf/create_field_options/type=' . $this->name, array($this, 'create_options'), 10, 1);
53
+
54
+
55
+ // input actions
56
+ $this->add_action('acf/input/admin_enqueue_scripts', array($this, 'input_admin_enqueue_scripts'), 10, 0);
57
+ $this->add_action('acf/input/admin_head', array($this, 'input_admin_head'), 10, 0);
58
+
59
+
60
+ // field group actions
61
+ $this->add_action('acf/field_group/admin_enqueue_scripts', array($this, 'field_group_admin_enqueue_scripts'), 10, 0);
62
+ $this->add_action('acf/field_group/admin_head', array($this, 'field_group_admin_head'), 10, 0);
63
+
64
+ }
65
+
66
+
67
+ /*
68
+ * add_filter
69
+ *
70
+ * @description: checks if the function is_callable before adding the filter
71
+ * @since: 3.6
72
+ * @created: 30/01/13
73
+ */
74
+
75
+ function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1)
76
+ {
77
+ if( is_callable($function_to_add) )
78
+ {
79
+ add_filter($tag, $function_to_add, $priority, $accepted_args);
80
+ }
81
+ }
82
+
83
+
84
+ /*
85
+ * add_action
86
+ *
87
+ * @description: checks if the function is_callable before adding the action
88
+ * @since: 3.6
89
+ * @created: 30/01/13
90
+ */
91
+
92
+ function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1)
93
+ {
94
+ if( is_callable($function_to_add) )
95
+ {
96
+ add_action($tag, $function_to_add, $priority, $accepted_args);
97
+ }
98
+ }
99
+
100
+
101
+ /*
102
+ * registered_fields()
103
+ *
104
+ * Adds this field to the select list when creating a new field
105
+ *
106
+ * @type filter
107
+ * @since 3.6
108
+ * @date 23/01/13
109
+ *
110
+ * @param $fields - the array of all registered fields
111
+ *
112
+ * @return $fields - the array of all registered fields
113
+ */
114
+
115
+ function registered_fields( $fields )
116
+ {
117
+ // defaults
118
+ if( !$this->category )
119
+ {
120
+ $this->category = __('Basic', 'acf');
121
+ }
122
+
123
+
124
+ // add to array
125
+ $fields[ $this->category ][ $this->name ] = $this->label;
126
+
127
+
128
+ // return array
129
+ return $fields;
130
+ }
131
+
132
+
133
+ }
134
+
135
+ ?>
core/fields/_functions.php ADDED
@@ -0,0 +1,574 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * Field Functions
5
+ *
6
+ * @description: The API for all fields
7
+ * @since: 3.6
8
+ * @created: 23/01/13
9
+ */
10
+
11
+ class acf_field_functions
12
+ {
13
+
14
+ /*
15
+ * __construct
16
+ *
17
+ * @description:
18
+ * @since 3.1.8
19
+ * @created: 23/06/12
20
+ */
21
+
22
+ function __construct()
23
+ {
24
+ //value
25
+ add_filter('acf/load_value', array($this, 'load_value'), 5, 3);
26
+ add_action('acf/update_value', array($this, 'update_value'), 5, 3);
27
+ add_action('acf/delete_value', array($this, 'delete_value'), 5, 2);
28
+ add_action('acf/format_value', array($this, 'format_value'), 5, 3);
29
+ add_action('acf/format_value_for_api', array($this, 'format_value_for_api'), 5, 3);
30
+
31
+
32
+ // field
33
+ add_filter('acf/load_field', array($this, 'load_field'), 5, 3);
34
+ add_action('acf/update_field', array($this, 'update_field'), 5, 2);
35
+ add_action('acf/delete_field', array($this, 'delete_field'), 5, 2);
36
+ add_action('acf/create_field', array($this, 'create_field'), 5, 1);
37
+ add_action('acf/create_field_options', array($this, 'create_field_options'), 5, 1);
38
+
39
+
40
+ // extra
41
+ add_filter('acf/load_field_defaults', array($this, 'load_field_defaults'), 5, 1);
42
+ }
43
+
44
+
45
+ /*
46
+ * load_value
47
+ *
48
+ * @description: loads basic value from the db
49
+ * @since: 3.6
50
+ * @created: 23/01/13
51
+ */
52
+
53
+ function load_value($value, $post_id, $field)
54
+ {
55
+ $cache = wp_cache_get( 'load_value/post_id=' . $post_id . '/name=' . $field['name'], 'acf' );
56
+ if( $cache )
57
+ {
58
+ return $cache;
59
+ }
60
+
61
+
62
+ // if $post_id is a string, then it is used in the everything fields and can be found in the options table
63
+ if( is_numeric($post_id) )
64
+ {
65
+ $value = get_post_meta( $post_id, $field['name'], false );
66
+
67
+ // value is an array, check and assign the real value / default value
68
+ if( !isset($value[0]) )
69
+ {
70
+ if( isset($field['default_value']) )
71
+ {
72
+ $value = $field['default_value'];
73
+ }
74
+ else
75
+ {
76
+ $value = false;
77
+ }
78
+ }
79
+ else
80
+ {
81
+ $value = $value[0];
82
+ }
83
+
84
+ }
85
+ elseif( strpos($post_id, 'user_') !== false )
86
+ {
87
+ $post_id = str_replace('user_', '', $post_id);
88
+
89
+ $value = get_user_meta( $post_id, $field['name'], false );
90
+
91
+ // value is an array, check and assign the real value / default value
92
+ if( !isset($value[0]) )
93
+ {
94
+ if( isset($field['default_value']) )
95
+ {
96
+ $value = $field['default_value'];
97
+ }
98
+ else
99
+ {
100
+ $value = false;
101
+ }
102
+ }
103
+ else
104
+ {
105
+ $value = $value[0];
106
+ }
107
+ }
108
+ else
109
+ {
110
+ $value = get_option( $post_id . '_' . $field['name'], null );
111
+
112
+ if( is_null($value) )
113
+ {
114
+ if( isset($field['default_value']) )
115
+ {
116
+ $value = $field['default_value'];
117
+ }
118
+ else
119
+ {
120
+ $value = false;
121
+ }
122
+ }
123
+
124
+ }
125
+
126
+
127
+ // if value was duplicated, it may now be a serialized string!
128
+ $value = maybe_unserialize($value);
129
+
130
+
131
+ // apply filters
132
+ foreach( array('type', 'name', 'key') as $key )
133
+ {
134
+ // run filters
135
+ $value = apply_filters('acf/load_value/' . $key . '=' . $field[ $key ], $value, $post_id, $field); // new filter
136
+ }
137
+
138
+
139
+ //update cache
140
+ wp_cache_set( 'load_value/post_id=' . $post_id . '/name=' . $field['name'], $value, 'acf' );
141
+
142
+
143
+ return $value;
144
+ }
145
+
146
+
147
+ /*
148
+ * format_value
149
+ *
150
+ * @description: uses the basic value and allows the field type to format it
151
+ * @since: 3.6
152
+ * @created: 26/01/13
153
+ */
154
+
155
+ function format_value( $value, $post_id, $field )
156
+ {
157
+ $value = apply_filters('acf/format_value/type=' . $field['type'], $value, $post_id, $field);
158
+
159
+ return $value;
160
+ }
161
+
162
+
163
+ /*
164
+ * format_value_for_api
165
+ *
166
+ * @description: uses the basic value and allows the field type to format it or the api functions
167
+ * @since: 3.6
168
+ * @created: 26/01/13
169
+ */
170
+
171
+ function format_value_for_api( $value, $post_id, $field )
172
+ {
173
+ $value = apply_filters('acf/format_value_for_api/type=' . $field['type'], $value, $post_id, $field);
174
+
175
+ return $value;
176
+ }
177
+
178
+
179
+ /*
180
+ * update_value
181
+ *
182
+ * @description: updates a value into the db
183
+ * @since: 3.6
184
+ * @created: 23/01/13
185
+ */
186
+
187
+ function update_value( $value, $post_id, $field )
188
+ {
189
+ // strip slashes
190
+ // - not needed? http://support.advancedcustomfields.com/discussion/3168/backslashes-stripped-in-wysiwyg-filed
191
+ //if( get_magic_quotes_gpc() )
192
+ //{
193
+ $value = stripslashes_deep($value);
194
+ //}
195
+
196
+
197
+ // apply filters
198
+ foreach( array('type', 'name', 'key') as $key )
199
+ {
200
+ // run filters
201
+ $value = apply_filters('acf/update_value/' . $key . '=' . $field[ $key ], $value, $post_id, $field); // new filter
202
+ }
203
+
204
+
205
+ // if $post_id is a string, then it is used in the everything fields and can be found in the options table
206
+ if( is_numeric($post_id) )
207
+ {
208
+ // allow ACF to save to revision!
209
+ update_metadata('post', $post_id, $field['name'], $value );
210
+ update_metadata('post', $post_id, '_' . $field['name'], $field['key']);
211
+ }
212
+ elseif( strpos($post_id, 'user_') !== false )
213
+ {
214
+ $user_id = str_replace('user_', '', $post_id);
215
+ update_metadata('user', $user_id, $field['name'], $value);
216
+ update_metadata('user', $user_id, '_' . $field['name'], $field['key']);
217
+ }
218
+ else
219
+ {
220
+ // for some reason, update_option does not use stripslashes_deep.
221
+ // update_metadata -> http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/meta.php#L82: line 101 (does use stripslashes_deep)
222
+ // update_option -> http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/option.php#L0: line 215 (does not use stripslashes_deep)
223
+ $value = stripslashes_deep($value);
224
+
225
+ update_option( $post_id . '_' . $field['name'], $value );
226
+ update_option( '_' . $post_id . '_' . $field['name'], $field['key'] );
227
+ }
228
+
229
+
230
+ // update the cache
231
+ wp_cache_set( 'load_value/post_id=' . $post_id . '/name=' . $field['name'], $value, 'acf' );
232
+ }
233
+
234
+
235
+ /*
236
+ * delete_value
237
+ *
238
+ * @description: deletes a value from the database
239
+ * @since: 3.6
240
+ * @created: 23/01/13
241
+ */
242
+
243
+ function delete_value( $post_id, $key )
244
+ {
245
+ // if $post_id is a string, then it is used in the everything fields and can be found in the options table
246
+ if( is_numeric($post_id) )
247
+ {
248
+ delete_post_meta( $post_id, $key );
249
+ delete_post_meta( $post_id, '_' . $key );
250
+ }
251
+ elseif( strpos($post_id, 'user_') !== false )
252
+ {
253
+ $post_id = str_replace('user_', '', $post_id);
254
+ delete_user_meta( $post_id, $key );
255
+ delete_user_meta( $post_id, '_' . $key );
256
+ }
257
+ else
258
+ {
259
+ delete_option( $post_id . '_' . $key );
260
+ delete_option( '_' . $post_id . '_' . $key );
261
+ }
262
+
263
+ wp_cache_delete( 'load_value/post_id=' . $post_id . '/name=' . $key, 'acf' );
264
+ }
265
+
266
+
267
+ /*
268
+ * load_field
269
+ *
270
+ * @description: loads a field from the database
271
+ * @since 3.5.1
272
+ * @created: 14/10/12
273
+ */
274
+
275
+ function load_field( $field, $field_key, $post_id = false )
276
+ {
277
+ // load cache
278
+ if( !$field )
279
+ {
280
+ $field = wp_cache_get( 'load_field/key=' . $field_key, 'acf' );
281
+ }
282
+
283
+
284
+ // load from DB
285
+ if( !$field )
286
+ {
287
+ // vars
288
+ global $wpdb;
289
+
290
+
291
+ // get field from postmeta
292
+ $sql = $wpdb->prepare("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s", $field_key);
293
+
294
+ if( $post_id )
295
+ {
296
+ $sql .= $wpdb->prepare("AND post_id = %d", $post_id);
297
+ }
298
+
299
+ $rows = $wpdb->get_results( $sql, ARRAY_A );
300
+
301
+
302
+
303
+ // nothing found?
304
+ if( !empty($rows) )
305
+ {
306
+ $row = $rows[0];
307
+
308
+
309
+ /*
310
+ * WPML compatibility
311
+ *
312
+ * If WPML is active, and the $post_id (Field group ID) was not defined,
313
+ * it is assumed that the load_field functio has been called from the API (front end).
314
+ * In this case, the field group ID is never known and we can check for the correct translated field group
315
+ */
316
+
317
+ if( defined('ICL_LANGUAGE_CODE') && !$post_id )
318
+ {
319
+ $wpml_post_id = icl_object_id($row['post_id'], 'acf', true, ICL_LANGUAGE_CODE);
320
+
321
+ foreach( $rows as $r )
322
+ {
323
+ if( $r['post_id'] == $wpml_post_id )
324
+ {
325
+ // this row is a field from the translated field group
326
+ $row = $r;
327
+ }
328
+ }
329
+ }
330
+
331
+
332
+ // return field if it is not in a trashed field group
333
+ if( get_post_status( $row['post_id'] ) != "trash" )
334
+ {
335
+ $field = $row['meta_value'];
336
+ $field = maybe_unserialize( $field );
337
+ $field = maybe_unserialize( $field ); // run again for WPML
338
+ }
339
+ }
340
+ }
341
+
342
+
343
+ // apply filters
344
+ $field = apply_filters('acf/load_field_defaults', $field);
345
+
346
+
347
+ // apply filters
348
+ foreach( array('type', 'name', 'key') as $key )
349
+ {
350
+ // run filters
351
+ $field = apply_filters('acf/load_field/' . $key . '=' . $field[ $key ], $field); // new filter
352
+ }
353
+
354
+
355
+ // set cache
356
+ wp_cache_set( 'load_field/key=' . $field_key, $field, 'acf' );
357
+
358
+ return $field;
359
+ }
360
+
361
+
362
+ /*
363
+ * load_field_defaults
364
+ *
365
+ * @description: applies default values to the field after it has been loaded
366
+ * @since 3.5.1
367
+ * @created: 14/10/12
368
+ */
369
+
370
+ function load_field_defaults( $field )
371
+ {
372
+ // validate $field
373
+ if( ! $field )
374
+ {
375
+ $field = array();
376
+ }
377
+
378
+
379
+ // defaults
380
+ $defaults = array(
381
+ 'key' => '',
382
+ 'label' => '',
383
+ 'name' => '',
384
+ 'type' => 'text',
385
+ 'order_no' => 1,
386
+ 'instructions' => '',
387
+ 'required' => 0,
388
+ 'id' => '',
389
+ 'class' => '',
390
+ 'conditional_logic' => array(
391
+ 'status' => 0,
392
+ 'allorany' => 'all',
393
+ 'rules' => 0
394
+ ),
395
+ );
396
+ $field = array_merge($defaults, $field);
397
+
398
+
399
+ // Parse Values
400
+ $field = apply_filters( 'acf/parse_types', $field );
401
+
402
+
403
+ // class
404
+ if( !$field['class'] )
405
+ {
406
+ $field['class'] = $field['type'];
407
+ }
408
+
409
+
410
+ // id
411
+ if( !$field['id'] )
412
+ {
413
+ $id = $field['name'];
414
+ $id = str_replace('][', '_', $id);
415
+ $id = str_replace('fields[', '', $id);
416
+ $id = str_replace('[', '-', $id); // location rules (select) does'nt have "fields[" in it
417
+ $id = str_replace(']', '', $id);
418
+
419
+ $field['id'] = 'acf-' . $id;
420
+ }
421
+
422
+
423
+ // return
424
+ return $field;
425
+ }
426
+
427
+
428
+ /*
429
+ * update_field
430
+ *
431
+ * @description: updates a field in the database
432
+ * @since: 3.6
433
+ * @created: 24/01/13
434
+ */
435
+
436
+ function update_field( $field, $post_id )
437
+ {
438
+ // filters
439
+ $field = apply_filters('acf/update_field/type=' . $field['type'], $field, $post_id ); // new filter
440
+
441
+
442
+ // save
443
+ update_post_meta( $post_id, $field['key'], $field );
444
+ }
445
+
446
+
447
+ /*
448
+ * delete_field
449
+ *
450
+ * @description: deletes a field in the database
451
+ * @since: 3.6
452
+ * @created: 24/01/13
453
+ */
454
+
455
+ function delete_field( $post_id, $field_key )
456
+ {
457
+ // delete
458
+ delete_post_meta($post_id, $field_key);
459
+ }
460
+
461
+
462
+ /*
463
+ * create_field
464
+ *
465
+ * @description: renders a field into a HTML interface
466
+ * @since: 3.6
467
+ * @created: 23/01/13
468
+ */
469
+
470
+ function create_field( $field )
471
+ {
472
+ // load defaults
473
+ // if field was loaded from db, these default will already be appield
474
+ // if field was written by hand, it may be missing keys
475
+ $field = apply_filters('acf/load_field_defaults', $field);
476
+
477
+
478
+ // create field specific html
479
+ do_action('acf/create_field/type=' . $field['type'], $field);
480
+
481
+
482
+ // conditional logic
483
+ // - isset is needed for the edit field group page where fields are created without many parameters
484
+ if( $field['conditional_logic']['status'] ):
485
+
486
+ $join = ' && ';
487
+ if( $field['conditional_logic']['allorany'] == "any" )
488
+ {
489
+ $join = ' || ';
490
+ }
491
+
492
+ ?>
493
+ <script type="text/javascript">
494
+ (function($){
495
+
496
+ // create the conditional function
497
+ $(document).live('acf/conditional_logic/<?php echo $field['key']; ?>', function(){
498
+
499
+ var field = $('.field_key-<?php echo $field['key']; ?>');
500
+
501
+ <?php
502
+
503
+ $if = array();
504
+ foreach( $field['conditional_logic']['rules'] as $rule )
505
+ {
506
+ $if[] = 'acf.conditional_logic.calculate({ field : "'. $field['key'] .'", toggle : "' . $rule['field'] . '", operator : "' . $rule['operator'] .'", value : "' . $rule['value'] . '"})' ;
507
+ }
508
+
509
+ ?>
510
+ if(<?php echo implode( $join, $if ); ?>)
511
+ {
512
+ field.removeClass('acf-conditional_logic-hide').addClass('acf-conditional_logic-show');
513
+ }
514
+ else
515
+ {
516
+ field.removeClass('acf-conditional_logic-show').addClass('acf-conditional_logic-hide');
517
+ }
518
+
519
+ });
520
+
521
+
522
+ // add change events to all fields
523
+ <?php
524
+
525
+ $already_added = array();
526
+
527
+ foreach( $field['conditional_logic']['rules'] as $rule ):
528
+
529
+ if( in_array( $rule['field'], $already_added) )
530
+ {
531
+ continue;
532
+ }
533
+ else
534
+ {
535
+ $already_added[] = $rule['field'];
536
+ }
537
+
538
+ ?>
539
+ $('.field_key-<?php echo $rule['field']; ?> *[name]').live('change', function(){
540
+ $(document).trigger('acf/conditional_logic/<?php echo $field['key']; ?>');
541
+ });
542
+ <?php endforeach; ?>
543
+
544
+ $(document).live('acf/setup_fields', function(e, postbox){
545
+ $(document).trigger('acf/conditional_logic/<?php echo $field['key']; ?>');
546
+ });
547
+
548
+ })(jQuery);
549
+ </script>
550
+ <?php
551
+ endif;
552
+ }
553
+
554
+
555
+ /*
556
+ * create_field_options
557
+ *
558
+ * @description: renders a field into a HTML interface
559
+ * @since: 3.6
560
+ * @created: 23/01/13
561
+ */
562
+
563
+ function create_field_options($field)
564
+ {
565
+ do_action('acf/create_field_options/type=' . $field['type'], $field);
566
+ }
567
+
568
+
569
+
570
+ }
571
+
572
+ new acf_field_functions();
573
+
574
+ ?>
core/fields/acf_field.php DELETED
@@ -1,313 +0,0 @@
1
- <?php
2
-
3
- /*
4
- * This is the base acf field frow which
5
- * all other fields extend. Here you can
6
- * find every function for your field
7
- *
8
- */
9
-
10
- class acf_Field
11
- {
12
- var $name;
13
- var $title;
14
- var $parent;
15
-
16
-
17
- /*--------------------------------------------------------------------------------------
18
- *
19
- * Constructor
20
- * - $parent is passed buy reference so you can play with the acf functions
21
- *
22
- * @author Elliot Condon
23
- * @since 2.2.0
24
- *
25
- *-------------------------------------------------------------------------------------*/
26
-
27
- function __construct($parent)
28
- {
29
- $this->parent = $parent;
30
- }
31
-
32
-
33
- /*--------------------------------------------------------------------------------------
34
- *
35
- * create_field
36
- * - called in lots of places to create the html version of the field
37
- *
38
- * @author Elliot Condon
39
- * @since 2.2.0
40
- *
41
- *-------------------------------------------------------------------------------------*/
42
-
43
- function create_field($field)
44
- {
45
-
46
- }
47
-
48
-
49
- /*--------------------------------------------------------------------------------------
50
- *
51
- * create_options
52
- * - called from core/field_meta_box.php to create special options
53
- *
54
- * @params : $key (int) - neccessary to group field data together for saving
55
- * $field (array) - the field data from the database
56
- * @author Elliot Condon
57
- * @since 2.2.0
58
- *
59
- *-------------------------------------------------------------------------------------*/
60
-
61
- function create_options($key, $field)
62
- {
63
-
64
- }
65
-
66
-
67
- /*--------------------------------------------------------------------------------------
68
- *
69
- * admin_head
70
- *
71
- * @author Elliot Condon
72
- * @since 2.2.0
73
- *
74
- *-------------------------------------------------------------------------------------*/
75
-
76
- function admin_head()
77
- {
78
-
79
- }
80
-
81
-
82
-
83
- /*--------------------------------------------------------------------------------------
84
- *
85
- * admin_print_scripts / admin_print_styles
86
- *
87
- * @author Elliot Condon
88
- * @since 3.0.0
89
- *
90
- *-------------------------------------------------------------------------------------*/
91
-
92
- function admin_print_scripts()
93
- {
94
-
95
- }
96
-
97
- function admin_print_styles()
98
- {
99
-
100
- }
101
-
102
-
103
- /*--------------------------------------------------------------------------------------
104
- *
105
- * update_value
106
- *
107
- * @author Elliot Condon
108
- * @since 2.2.0
109
- *
110
- *-------------------------------------------------------------------------------------*/
111
-
112
- function update_value($post_id, $field, $value)
113
- {
114
- // strip slashes
115
- // - not needed? http://support.advancedcustomfields.com/discussion/3168/backslashes-stripped-in-wysiwyg-filed
116
- if( get_magic_quotes_gpc() )
117
- {
118
- $value = stripslashes_deep($value);
119
- }
120
-
121
-
122
- // apply filters
123
- $value = apply_filters('acf_update_value', $value, $field, $post_id );
124
-
125
- $keys = array('type', 'name', 'key');
126
- foreach( $keys as $key )
127
- {
128
- if( isset($field[ $key ]) )
129
- {
130
- $value = apply_filters('acf_update_value-' . $field[ $key ], $value, $field, $post_id);
131
- }
132
- }
133
-
134
-
135
- // if $post_id is a string, then it is used in the everything fields and can be found in the options table
136
- if( is_numeric($post_id) )
137
- {
138
- // allow ACF to save to revision!
139
- update_metadata('post', $post_id, $field['name'], $value );
140
- update_metadata('post', $post_id, '_' . $field['name'], $field['key']);
141
- }
142
- elseif( strpos($post_id, 'user_') !== false )
143
- {
144
- $user_id = str_replace('user_', '', $post_id);
145
- update_metadata('user', $user_id, $field['name'], $value);
146
- update_metadata('user', $user_id, '_' . $field['name'], $field['key']);
147
- }
148
- else
149
- {
150
- // for some reason, update_option does not use stripslashes_deep.
151
- // update_metadata -> http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/meta.php#L82: line 101 (does use stripslashes_deep)
152
- // update_option -> http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/option.php#L0: line 215 (does not use stripslashes_deep)
153
- $value = stripslashes_deep($value);
154
-
155
- update_option( $post_id . '_' . $field['name'], $value );
156
- update_option( '_' . $post_id . '_' . $field['name'], $field['key'] );
157
- }
158
-
159
-
160
- //clear the cache for this field
161
- wp_cache_delete('acf_get_field_' . $post_id . '_' . $field['name']);
162
-
163
- }
164
-
165
-
166
- /*
167
- * delete_value
168
- *
169
- * @description:
170
- * @since: 3.5.8
171
- * @created: 19/01/13
172
- */
173
-
174
- function delete_value($post_id, $key)
175
- {
176
- // if $post_id is a string, then it is used in the everything fields and can be found in the options table
177
- if( is_numeric($post_id) )
178
- {
179
- delete_post_meta( $post_id, $key );
180
- delete_post_meta( $post_id, '_' . $key );
181
- }
182
- elseif( strpos($post_id, 'user_') !== false )
183
- {
184
- $post_id = str_replace('user_', '', $post_id);
185
- delete_user_meta( $post_id, $key );
186
- delete_user_meta( $post_id, '_' . $key );
187
- }
188
- else
189
- {
190
- delete_option( $post_id . '_' . $key );
191
- delete_option( '_' . $post_id . '_' . $key );
192
- }
193
-
194
- }
195
-
196
-
197
-
198
- /*--------------------------------------------------------------------------------------
199
- *
200
- * get_value
201
- *
202
- * @author Elliot Condon
203
- * @since 2.2.0
204
- *
205
- *-------------------------------------------------------------------------------------*/
206
-
207
- function get_value($post_id, $field)
208
- {
209
- $value = false;
210
-
211
- // if $post_id is a string, then it is used in the everything fields and can be found in the options table
212
- if( is_numeric($post_id) )
213
- {
214
- $value = get_post_meta( $post_id, $field['name'], false );
215
-
216
- // value is an array, check and assign the real value / default value
217
- if( !isset($value[0]) )
218
- {
219
- if( isset($field['default_value']) )
220
- {
221
- $value = $field['default_value'];
222
- }
223
- else
224
- {
225
- $value = false;
226
- }
227
- }
228
- else
229
- {
230
- $value = $value[0];
231
- }
232
- }
233
- elseif( strpos($post_id, 'user_') !== false )
234
- {
235
- $post_id = str_replace('user_', '', $post_id);
236
-
237
- $value = get_user_meta( $post_id, $field['name'], false );
238
-
239
- // value is an array, check and assign the real value / default value
240
- if( !isset($value[0]) )
241
- {
242
- if( isset($field['default_value']) )
243
- {
244
- $value = $field['default_value'];
245
- }
246
- else
247
- {
248
- $value = false;
249
- }
250
- }
251
- else
252
- {
253
- $value = $value[0];
254
- }
255
- }
256
- else
257
- {
258
- $value = get_option( $post_id . '_' . $field['name'], null );
259
-
260
- if( is_null($value) )
261
- {
262
- if( isset($field['default_value']) )
263
- {
264
- $value = $field['default_value'];
265
- }
266
- else
267
- {
268
- $value = false;
269
- }
270
- }
271
-
272
- }
273
-
274
-
275
- // if value was duplicated, it may now be a serialized string!
276
- $value = maybe_unserialize($value);
277
-
278
-
279
- // apply filters
280
- $value = apply_filters('acf_load_value', $value, $field, $post_id );
281
-
282
- $keys = array('type', 'name', 'key');
283
- foreach( $keys as $key )
284
- {
285
- if( isset($field[ $key ]) )
286
- {
287
- $value = apply_filters('acf_load_value-' . $field[ $key ], $value, $field, $post_id);
288
- }
289
- }
290
-
291
-
292
-
293
- return $value;
294
- }
295
-
296
-
297
- /*--------------------------------------------------------------------------------------
298
- *
299
- * get_value_for_api
300
- *
301
- * @author Elliot Condon
302
- * @since 3.0.0
303
- *
304
- *-------------------------------------------------------------------------------------*/
305
-
306
- function get_value_for_api($post_id, $field)
307
- {
308
- return $this->get_value($post_id, $field);
309
- }
310
-
311
- }
312
-
313
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/fields/checkbox.php CHANGED
@@ -1,96 +1,100 @@
1
  <?php
2
 
3
- class acf_Checkbox extends acf_Field
4
  {
5
 
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'checkbox';
21
- $this->title = __("Checkbox",'acf');
22
 
23
- }
24
-
25
-
26
- /*--------------------------------------------------------------------------------------
 
 
 
 
27
  *
28
- * create_field
29
  *
30
- * @author Elliot Condon
31
- * @since 2.0.5
32
- * @updated 2.2.0
33
- *
34
- *-------------------------------------------------------------------------------------*/
 
35
 
36
- function create_field($field)
37
  {
38
- // defaults
39
- if(empty($field['value']))
40
- {
41
- $field['value'] = array();
42
- }
 
 
43
 
44
 
45
- // single value to array conversion
46
  if( !is_array($field['value']) )
47
  {
48
  $field['value'] = array( $field['value'] );
49
  }
50
 
51
 
52
- // no choices
53
- if(empty($field['choices']))
54
- {
55
- echo '<p>' . __("No choices to choose from",'acf') . '</p>';
56
- return false;
57
- }
58
 
59
 
60
- // html
61
- echo '<ul class="checkbox_list '.$field['class'].'">';
62
- echo '<input type="hidden" name="'.$field['name'].'" value="" />';
63
  // checkbox saves an array
64
  $field['name'] .= '[]';
65
 
 
66
  // foreach choices
67
  foreach($field['choices'] as $key => $value)
68
  {
69
  $selected = '';
70
- if(in_array($key, $field['value']))
71
  {
72
  $selected = 'checked="yes"';
73
  }
 
 
74
  echo '<li><label><input id="' . $field['id'] . '-' . $key . '" type="checkbox" class="' . $field['class'] . '" name="' . $field['name'] . '" value="' . $key . '" ' . $selected . ' />' . $value . '</label></li>';
75
  }
76
 
77
  echo '</ul>';
78
-
79
  }
80
-
81
-
82
- /*--------------------------------------------------------------------------------------
 
83
  *
84
- * create_options
 
85
  *
86
- * @author Elliot Condon
87
- * @since 2.0.6
88
- * @updated 2.2.0
89
- *
90
- *-------------------------------------------------------------------------------------*/
 
91
 
92
- function create_options($key, $field)
93
- {
94
  // vars
95
  $defaults = array(
96
  'default_value' => '',
@@ -98,6 +102,7 @@ class acf_Checkbox extends acf_Field
98
  );
99
 
100
  $field = array_merge($defaults, $field);
 
101
 
102
 
103
  // implode checkboxes so they work in a textarea
@@ -153,7 +158,11 @@ class acf_Checkbox extends acf_Field
153
  </td>
154
  </tr>
155
  <?php
156
- }
157
 
 
 
158
  }
 
 
 
159
  ?>
1
  <?php
2
 
3
+ class acf_field_checkbox extends acf_field
4
  {
5
 
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'checkbox';
19
+ $this->label = __("Checkbox",'acf');
20
+ $this->category = __("Choice",'acf');
21
 
22
+
23
+ // do not delete!
24
+ parent::__construct();
25
+ }
26
+
27
+
28
+ /*
29
+ * create_field()
30
  *
31
+ * Create the HTML interface for your field
32
  *
33
+ * @param $field - an array holding all the field's data
34
+ *
35
+ * @type action
36
+ * @since 3.6
37
+ * @date 23/01/13
38
+ */
39
 
40
+ function create_field( $field )
41
  {
42
+ // vars
43
+ $defaults = array(
44
+ 'layout' => 'vertical',
45
+ 'choices' => array(),
46
+ );
47
+
48
+ $field = array_merge($defaults, $field);
49
 
50
 
51
+ // value must be array
52
  if( !is_array($field['value']) )
53
  {
54
  $field['value'] = array( $field['value'] );
55
  }
56
 
57
 
58
+ echo '<input type="hidden" name="' . $field['name'] . '" value="" />';
59
+ echo '<ul class="checkbox_list ' . $field['class'] . '">';
 
 
 
 
60
 
61
 
 
 
 
62
  // checkbox saves an array
63
  $field['name'] .= '[]';
64
 
65
+
66
  // foreach choices
67
  foreach($field['choices'] as $key => $value)
68
  {
69
  $selected = '';
70
+ if( in_array($key, $field['value']) )
71
  {
72
  $selected = 'checked="yes"';
73
  }
74
+
75
+
76
  echo '<li><label><input id="' . $field['id'] . '-' . $key . '" type="checkbox" class="' . $field['class'] . '" name="' . $field['name'] . '" value="' . $key . '" ' . $selected . ' />' . $value . '</label></li>';
77
  }
78
 
79
  echo '</ul>';
 
80
  }
81
+
82
+
83
+ /*
84
+ * create_options()
85
  *
86
+ * Create extra options for your field. This is rendered when editing a field.
87
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
88
  *
89
+ * @type action
90
+ * @since 3.6
91
+ * @date 23/01/13
92
+ *
93
+ * @param $field - an array holding all the field's data
94
+ */
95
 
96
+ function create_options( $field )
97
+ {
98
  // vars
99
  $defaults = array(
100
  'default_value' => '',
102
  );
103
 
104
  $field = array_merge($defaults, $field);
105
+ $key = $field['name'];
106
 
107
 
108
  // implode checkboxes so they work in a textarea
158
  </td>
159
  </tr>
160
  <?php
 
161
 
162
+ }
163
+
164
  }
165
+
166
+ new acf_field_checkbox();
167
+
168
  ?>
core/fields/color_picker.php CHANGED
@@ -1,57 +1,63 @@
1
  <?php
2
 
3
- class acf_Color_picker extends acf_Field
4
  {
5
-
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'color_picker';
21
- $this->title = __("Color Picker",'acf');
 
22
 
23
- }
24
-
 
 
25
 
26
- /*--------------------------------------------------------------------------------------
 
 
 
 
27
  *
28
- * create_field
29
  *
30
- * @author Elliot Condon
31
- * @since 2.0.5
32
- * @updated 2.2.0
33
- *
34
- *-------------------------------------------------------------------------------------*/
35
 
36
- function create_field($field)
37
- {
38
- // html
39
- echo '<input type="text" value="' . $field['value'] . '" class="acf_color_picker" name="' . $field['name'] . '" id="' . $field['id'] . '" />';
40
-
41
  }
42
 
43
 
44
- /*--------------------------------------------------------------------------------------
 
45
  *
46
- * create_options
 
47
  *
48
- * @author Elliot Condon
49
- * @since 2.0.6
50
- * @updated 2.2.0
51
- *
52
- *-------------------------------------------------------------------------------------*/
 
53
 
54
- function create_options($key, $field)
55
  {
56
  // vars
57
  $defaults = array(
@@ -59,28 +65,30 @@ class acf_Color_picker extends acf_Field
59
  );
60
 
61
  $field = array_merge($defaults, $field);
62
-
63
 
64
  ?>
65
- <tr class="field_option field_option_<?php echo $this->name; ?>">
66
- <td class="label">
67
- <label><?php _e("Default Value",'acf'); ?></label>
68
- <p class="description"><?php _e("eg: #ffffff",'acf'); ?></p>
69
- </td>
70
- <td>
71
- <?php
72
- do_action('acf/create_field', array(
73
- 'type' => 'text',
74
- 'name' => 'fields['.$key.'][default_value]',
75
- 'value' => $field['default_value'],
76
- ));
77
- ?>
78
- </td>
79
- </tr>
80
  <?php
 
81
  }
82
 
83
-
84
  }
85
 
 
 
86
  ?>
1
  <?php
2
 
3
+ class acf_field_color_picker extends acf_field
4
  {
5
+
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'color_picker';
19
+ $this->label = __("Color Picker",'acf');
20
+ $this->category = __("jQuery",'acf');
21
+
22
 
23
+ // do not delete!
24
+ parent::__construct();
25
+
26
+ }
27
 
28
+
29
+ /*
30
+ * create_field()
31
+ *
32
+ * Create the HTML interface for your field
33
  *
34
+ * @param $field - an array holding all the field's data
35
  *
36
+ * @type action
37
+ * @since 3.6
38
+ * @date 23/01/13
39
+ */
 
40
 
41
+ function create_field( $field )
42
+ {
43
+ echo '<input type="text" value="' . $field['value'] . '" id="' . $field['id'] . '" class="acf_color_picker" name="' . $field['name'] . '" />';
 
 
44
  }
45
 
46
 
47
+ /*
48
+ * create_options()
49
  *
50
+ * Create extra options for your field. This is rendered when editing a field.
51
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
52
  *
53
+ * @type action
54
+ * @since 3.6
55
+ * @date 23/01/13
56
+ *
57
+ * @param $field - an array holding all the field's data
58
+ */
59
 
60
+ function create_options( $field )
61
  {
62
  // vars
63
  $defaults = array(
65
  );
66
 
67
  $field = array_merge($defaults, $field);
68
+ $key = $field['name'];
69
 
70
  ?>
71
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
72
+ <td class="label">
73
+ <label><?php _e("Default Value",'acf'); ?></label>
74
+ <p class="description"><?php _e("eg: #ffffff",'acf'); ?></p>
75
+ </td>
76
+ <td>
77
+ <?php
78
+ do_action('acf/create_field', array(
79
+ 'type' => 'text',
80
+ 'name' => 'fields[' .$key.'][default_value]',
81
+ 'value' => $field['default_value'],
82
+ ));
83
+ ?>
84
+ </td>
85
+ </tr>
86
  <?php
87
+
88
  }
89
 
 
90
  }
91
 
92
+ new acf_field_color_picker();
93
+
94
  ?>
core/fields/date_picker/date_picker.php CHANGED
@@ -1,39 +1,43 @@
1
  <?php
2
 
3
- class acf_Date_picker extends acf_Field
4
  {
5
-
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'date_picker';
21
- $this->title = __("Date Picker",'acf');
22
 
23
- }
 
 
 
24
 
25
 
26
- /*--------------------------------------------------------------------------------------
 
27
  *
28
- * create_field
29
  *
30
- * @author Elliot Condon
31
- * @since 2.0.5
32
- * @updated 2.2.0
33
- *
34
- *-------------------------------------------------------------------------------------*/
 
35
 
36
- function create_field($field)
37
  {
38
  // defaults
39
  $defaults = array(
@@ -62,53 +66,69 @@ class acf_Date_picker extends acf_Field
62
  }
63
 
64
 
65
- /*--------------------------------------------------------------------------------------
 
 
 
 
66
  *
67
- * create_options
 
 
68
  *
69
- * @author Elliot Condon
70
- * @since 2.0.6
71
- * @updated 2.2.0
72
- *
73
- *-------------------------------------------------------------------------------------*/
74
 
75
- function create_options($key, $field)
76
  {
77
- // defaults
78
  $defaults = array(
79
  'date_format' => 'yymmdd',
80
  'display_format' => 'dd/mm/yy',
81
  );
82
 
83
  $field = array_merge($defaults, $field);
84
-
85
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  ?>
87
- <tr class="field_option field_option_<?php echo $this->name; ?>">
88
- <td class="label">
89
- <label><?php _e("Save format",'acf'); ?></label>
90
- <p class="description"><?php _e("This format will determin the value saved to the database and returned via the API",'acf'); ?></p>
91
- <p><?php _e("\"yymmdd\" is the most versatile save format. Read more about",'acf'); ?> <a href="http://docs.jquery.com/UI/Datepicker/formatDate"><?php _e("jQuery date formats",'acf'); ?></a></p>
92
- </td>
93
- <td>
94
- <input type="text" name="fields[<?php echo $key; ?>][date_format]" value="<?php echo $field['date_format']; ?>" />
95
- </td>
96
- </tr>
97
- <tr class="field_option field_option_<?php echo $this->name; ?>">
98
- <td class="label">
99
- <label><?php _e("Display format",'acf'); ?></label>
100
- <p class="description"><?php _e("This format will be seen by the user when entering a value",'acf'); ?></p>
101
- <p><?php _e("\"dd/mm/yy\" or \"mm/dd/yy\" are the most used display formats. Read more about",'acf'); ?> <a href="http://docs.jquery.com/UI/Datepicker/formatDate" target="_blank"><?php _e("jQuery date formats",'acf'); ?></a></p>
102
- </td>
103
- <td>
104
- <input type="text" name="fields[<?php echo $key; ?>][display_format]" value="<?php echo $field['display_format']; ?>" />
105
- </td>
106
- </tr>
107
- <?php
108
- }
109
 
110
-
111
 
112
  }
113
 
 
 
114
  ?>
1
  <?php
2
 
3
+ class acf_field_date_picker extends acf_field
4
  {
5
+
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'date_picker';
19
+ $this->label = __("Date Picker",'acf');
20
+ $this->category = __("jQuery",'acf');
21
 
22
+
23
+ // do not delete!
24
+ parent::__construct();
25
+ }
26
 
27
 
28
+ /*
29
+ * create_field()
30
  *
31
+ * Create the HTML interface for your field
32
  *
33
+ * @param $field - an array holding all the field's data
34
+ *
35
+ * @type action
36
+ * @since 3.6
37
+ * @date 23/01/13
38
+ */
39
 
40
+ function create_field( $field )
41
  {
42
  // defaults
43
  $defaults = array(
66
  }
67
 
68
 
69
+ /*
70
+ * create_options()
71
+ *
72
+ * Create extra options for your field. This is rendered when editing a field.
73
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
74
  *
75
+ * @type action
76
+ * @since 3.6
77
+ * @date 23/01/13
78
  *
79
+ * @param $field - an array holding all the field's data
80
+ */
 
 
 
81
 
82
+ function create_options( $field )
83
  {
84
+ // vars
85
  $defaults = array(
86
  'date_format' => 'yymmdd',
87
  'display_format' => 'dd/mm/yy',
88
  );
89
 
90
  $field = array_merge($defaults, $field);
91
+ $key = $field['name'];
92
+
93
+ ?>
94
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
95
+ <td class="label">
96
+ <label><?php _e("Save format",'acf'); ?></label>
97
+ <p class="description"><?php _e("This format will determin the value saved to the database and returned via the API",'acf'); ?></p>
98
+ <p><?php _e("\"yymmdd\" is the most versatile save format. Read more about",'acf'); ?> <a href="http://docs.jquery.com/UI/Datepicker/formatDate"><?php _e("jQuery date formats",'acf'); ?></a></p>
99
+ </td>
100
+ <td>
101
+ <?php
102
+ do_action('acf/create_field', array(
103
+ 'type' => 'text',
104
+ 'name' => 'fields[' .$key.'][date_format]',
105
+ 'value' => $field['date_format'],
106
+ ));
107
  ?>
108
+ </td>
109
+ </tr>
110
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
111
+ <td class="label">
112
+ <label><?php _e("Display format",'acf'); ?></label>
113
+ <p class="description"><?php _e("This format will be seen by the user when entering a value",'acf'); ?></p>
114
+ <p><?php _e("\"dd/mm/yy\" or \"mm/dd/yy\" are the most used display formats. Read more about",'acf'); ?> <a href="http://docs.jquery.com/UI/Datepicker/formatDate" target="_blank"><?php _e("jQuery date formats",'acf'); ?></a></p>
115
+ </td>
116
+ <td>
117
+ <?php
118
+ do_action('acf/create_field', array(
119
+ 'type' => 'text',
120
+ 'name' => 'fields[' .$key.'][display_format]',
121
+ 'value' => $field['display_format'],
122
+ ));
123
+ ?>
124
+ </td>
125
+ </tr>
126
+ <?php
 
 
 
127
 
128
+ }
129
 
130
  }
131
 
132
+ new acf_field_date_picker();
133
+
134
  ?>
core/fields/dummy.php ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class acf_field_dummy extends acf_field
4
+ {
5
+
6
+ /*
7
+ * __construct
8
+ *
9
+ * Set name / label needed for actions / filters
10
+ *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
14
+
15
+ function __construct()
16
+ {
17
+ // vars
18
+ $this->name = 'dummy';
19
+ $this->label = __('Dummy');
20
+
21
+
22
+ // do not delete!
23
+ parent::__construct();
24
+ }
25
+
26
+
27
+ /*
28
+ * load_value()
29
+ *
30
+ * This filter is appied to the $value after it is loaded from the db
31
+ *
32
+ * @type filter
33
+ * @since 3.6
34
+ * @date 23/01/13
35
+ *
36
+ * @param $value - the value found in the database
37
+ * @param $post_id - the $post_id from which the value was loaded from
38
+ * @param $field - the field array holding all the field options
39
+ *
40
+ * @return $value - the value to be saved in te database
41
+ */
42
+
43
+ function load_value( $value, $post_id, $field )
44
+ {
45
+ return $value;
46
+ }
47
+
48
+
49
+ /*
50
+ * format_value()
51
+ *
52
+ * This filter is appied to the $value after it is loaded from the db and before it is passed to the create_field action
53
+ *
54
+ * @type filter
55
+ * @since 3.6
56
+ * @date 23/01/13
57
+ *
58
+ * @param $value - the value which was loaded from the database
59
+ * @param $post_id - the $post_id from which the value was loaded
60
+ * @param $field - the field array holding all the field options
61
+ *
62
+ * @return $value - the modified value
63
+ */
64
+
65
+ function format_value( $value, $post_id, $field )
66
+ {
67
+ return $value;
68
+ }
69
+
70
+
71
+ /*
72
+ * format_value_for_api()
73
+ *
74
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
75
+ *
76
+ * @type filter
77
+ * @since 3.6
78
+ * @date 23/01/13
79
+ *
80
+ * @param $value - the value which was loaded from the database
81
+ * @param $post_id - the $post_id from which the value was loaded
82
+ * @param $field - the field array holding all the field options
83
+ *
84
+ * @return $value - the modified value
85
+ */
86
+
87
+ function format_value_for_api( $value, $post_id, $field )
88
+ {
89
+ return $value;
90
+ }
91
+
92
+
93
+ /*
94
+ * update_value()
95
+ *
96
+ * This filter is appied to the $value before it is updated in the db
97
+ *
98
+ * @type filter
99
+ * @since 3.6
100
+ * @date 23/01/13
101
+ *
102
+ * @param $value - the value which will be saved in the database
103
+ * @param $field - the field array holding all the field options
104
+ * @param $post_id - the $post_id of which the value will be saved
105
+ *
106
+ * @return $value - the modified value
107
+ */
108
+
109
+ function update_value( $value, $post_id, $field )
110
+ {
111
+ return $value;
112
+ }
113
+
114
+
115
+ /*
116
+ * load_field()
117
+ *
118
+ * This filter is appied to the $field after it is loaded from the database
119
+ *
120
+ * @type filter
121
+ * @since 3.6
122
+ * @date 23/01/13
123
+ *
124
+ * @param $field - the field array holding all the field options
125
+ *
126
+ * @return $field - the field array holding all the field options
127
+ */
128
+
129
+ function load_field( $field )
130
+ {
131
+ return $field;
132
+ }
133
+
134
+
135
+ /*
136
+ * update_field()
137
+ *
138
+ * This filter is appied to the $field before it is saved to the database
139
+ *
140
+ * @type filter
141
+ * @since 3.6
142
+ * @date 23/01/13
143
+ *
144
+ * @param $field - the field array holding all the field options
145
+ * @param $post_id - the field group ID (post_type = acf)
146
+ *
147
+ * @return $field - the modified field
148
+ */
149
+
150
+ function update_field( $field, $post_id )
151
+ {
152
+ return $field;
153
+ }
154
+
155
+
156
+ /*
157
+ * create_field()
158
+ *
159
+ * Create the HTML interface for your field
160
+ *
161
+ * @type action
162
+ * @since 3.6
163
+ * @date 23/01/13
164
+ *
165
+ * @param $field - an array holding all the field's data
166
+ */
167
+
168
+ function create_field( $field )
169
+ {
170
+
171
+ }
172
+
173
+
174
+ /*
175
+ * create_options()
176
+ *
177
+ * Create extra options for your field. This is rendered when editing a field.
178
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
179
+ *
180
+ * @type action
181
+ * @since 3.6
182
+ * @date 23/01/13
183
+ *
184
+ * @param $field - an array holding all the field's data
185
+ */
186
+
187
+ function create_options( $field )
188
+ {
189
+
190
+ }
191
+
192
+
193
+ /*
194
+ * input_admin_enqueue_scripts()
195
+ *
196
+ * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created.
197
+ * Use this action to add css + javascript to assist your create_field() action.
198
+ *
199
+ * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
200
+ * @type action
201
+ * @since 3.6
202
+ * @date 23/01/13
203
+ */
204
+
205
+ function input_admin_enqueue_scripts()
206
+ {
207
+
208
+ }
209
+
210
+
211
+ /*
212
+ * input_admin_head()
213
+ *
214
+ * This action is called in the admin_head action on the edit screen where your field is created.
215
+ * Use this action to add css and javascript to assist your create_field() action.
216
+ *
217
+ * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head
218
+ * @type action
219
+ * @since 3.6
220
+ * @date 23/01/13
221
+ */
222
+
223
+ function input_admin_head()
224
+ {
225
+
226
+ }
227
+
228
+
229
+ /*
230
+ * field_group_admin_enqueue_scripts()
231
+ *
232
+ * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited.
233
+ * Use this action to add css + javascript to assist your create_field_options() action.
234
+ *
235
+ * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
236
+ * @type action
237
+ * @since 3.6
238
+ * @date 23/01/13
239
+ */
240
+
241
+ function field_group_admin_enqueue_scripts()
242
+ {
243
+
244
+ }
245
+
246
+
247
+ /*
248
+ * field_group_admin_head()
249
+ *
250
+ * This action is called in the admin_head action on the edit screen where your field is edited.
251
+ * Use this action to add css and javascript to assist your create_field_options() action.
252
+ *
253
+ * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head
254
+ * @type action
255
+ * @since 3.6
256
+ * @date 23/01/13
257
+ */
258
+
259
+ function field_group_admin_head()
260
+ {
261
+
262
+ }
263
+ }
264
+
265
+
266
+ // create field
267
+ new acf_field_dummy();
268
+
269
+
270
+ /*--------------------------------------- fuctions.php ----------------------------------------------------*/
271
+
272
+ add_action('acf/register_fields', 'my_register_fields');
273
+
274
+ function my_register_fields()
275
+ {
276
+ include_once('fields/dummy.php');
277
+ }
278
+
279
+ ?>
core/fields/email.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class acf_field_email extends acf_field
4
+ {
5
+
6
+ /*
7
+ * __construct
8
+ *
9
+ * Set name / label needed for actions / filters
10
+ *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
14
+
15
+ function __construct()
16
+ {
17
+ // vars
18
+ $this->name = 'email';
19
+ $this->label = __("Email",'acf');
20
+
21
+
22
+ // do not delete!
23
+ parent::__construct();
24
+ }
25
+
26
+
27
+ /*
28
+ * create_field()
29
+ *
30
+ * Create the HTML interface for your field
31
+ *
32
+ * @param $field - an array holding all the field's data
33
+ *
34
+ * @type action
35
+ * @since 3.6
36
+ * @date 23/01/13
37
+ */
38
+
39
+ function create_field( $field )
40
+ {
41
+ echo '<input type="email" value="' . esc_attr( $field['value'] ) . '" id="' . esc_attr( $field['id'] ) . '" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" />';
42
+ }
43
+
44
+
45
+ /*
46
+ * create_options()
47
+ *
48
+ * Create extra options for your field. This is rendered when editing a field.
49
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
50
+ *
51
+ * @type action
52
+ * @since 3.6
53
+ * @date 23/01/13
54
+ *
55
+ * @param $field - an array holding all the field's data
56
+ */
57
+
58
+ function create_options( $field )
59
+ {
60
+ // vars
61
+ $defaults = array(
62
+ 'default_value' => '',
63
+ );
64
+
65
+ $field = array_merge($defaults, $field);
66
+ $key = $field['name'];
67
+
68
+ ?>
69
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
70
+ <td class="label">
71
+ <label><?php _e("Default Value",'acf'); ?></label>
72
+ </td>
73
+ <td>
74
+ <?php
75
+
76
+ do_action('acf/create_field', array(
77
+ 'type' => 'text',
78
+ 'name' => 'fields['.$key.'][default_value]',
79
+ 'value' => $field['default_value'],
80
+ ));
81
+
82
+ ?>
83
+ </td>
84
+ </tr>
85
+ <?php
86
+ }
87
+
88
+ }
89
+
90
+ new acf_field_email();
91
+
92
+ ?>
core/fields/file.php CHANGED
@@ -1,34 +1,227 @@
1
  <?php
2
 
3
- class acf_File extends acf_Field
4
  {
5
-
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'file';
21
- $this->title = __('File','acf');
22
 
23
- add_action('admin_head-media-upload-popup', array($this, 'popup_head'));
24
- add_filter('get_media_item_args', array($this, 'allow_file_insertion'));
25
- add_action('acf_head-update_attachment-file', array($this, 'acf_head_update_attachment'));
26
 
 
 
 
 
 
 
 
27
  add_action('wp_ajax_acf/fields/file/get_files', array($this, 'ajax_get_files'));
28
- }
29
-
30
-
31
- /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  * acf_head_update_attachment
33
  *
34
  * @description:
@@ -54,9 +247,9 @@ class acf_File extends acf_Field
54
  </script>
55
  <?php
56
  }
57
-
58
-
59
- /*
60
  * ajax_get_files
61
  *
62
  * @description:
@@ -108,130 +301,9 @@ class acf_File extends acf_Field
108
  die;
109
 
110
  }
111
-
112
-
113
- /*--------------------------------------------------------------------------------------
114
- *
115
- * allow_file_insertion
116
- *
117
- * @author Elliot Condon
118
- * @since 3.0.1
119
- *
120
- *-------------------------------------------------------------------------------------*/
121
-
122
- function allow_file_insertion($vars)
123
- {
124
- $vars['send'] = true;
125
- return($vars);
126
- }
127
-
128
-
129
- /*--------------------------------------------------------------------------------------
130
- *
131
- * create_field
132
- *
133
- * @author Elliot Condon
134
- * @since 2.0.5
135
- * @updated 2.2.0
136
- *
137
- *-------------------------------------------------------------------------------------*/
138
-
139
- function create_field($field)
140
- {
141
-
142
- // vars
143
- $options = array(
144
- 'class' => '',
145
- 'icon' => '',
146
- 'file_name' => ''
147
- );
148
-
149
- if( $field['value'] )
150
- {
151
- $file_src = wp_get_attachment_url( $field['value'] );
152
- preg_match("~[^/]*$~", $file_src, $file_name);
153
-
154
- $options['class'] = 'active';
155
- $options['icon'] = wp_mime_type_icon( $field['value'] );
156
- $options['file_name'] = $file_name[0];
157
- }
158
-
159
- ?>
160
- <div class="acf-file-uploader <?php echo $options['class']; ?>">
161
- <input class="acf-file-value" type="hidden" name="<?php echo $field['name']; ?>" value="<?php echo $field['value']; ?>" />
162
- <div class="has-file">
163
- <ul class="hl clearfix">
164
- <li>
165
- <img class="acf-file-icon" src="<?php echo $options['icon']; ?>" alt=""/>
166
- </li>
167
- <li>
168
- <span class="acf-file-name"><?php echo $options['file_name']; ?></span><br />
169
- <a href="#" class="edit-file"><?php _e('Edit','acf'); ?></a>
170
- <a href="#" class="remove-file"><?php _e('Remove','acf'); ?></a>
171
- </li>
172
- </ul>
173
- </div>
174
- <div class="no-file">
175
- <ul class="hl clearfix">
176
- <li>
177
- <span><?php _e('No File Selected','acf'); ?></span>. <a href="#" class="button add-file"><?php _e('Add File','acf'); ?></a>
178
- </li>
179
- </ul>
180
- </div>
181
- </div>
182
- <?php
183
-
184
- }
185
-
186
-
187
-
188
- /*--------------------------------------------------------------------------------------
189
- *
190
- * create_options
191
- *
192
- * @author Elliot Condon
193
- * @since 2.0.6
194
- * @updated 2.2.0
195
- *
196
- *-------------------------------------------------------------------------------------*/
197
-
198
- function create_options($key, $field)
199
- {
200
- // vars
201
- $defaults = array(
202
- 'save_format' => 'id',
203
- );
204
-
205
- $field = array_merge($defaults, $field);
206
-
207
- ?>
208
- <tr class="field_option field_option_<?php echo $this->name; ?>">
209
- <td class="label">
210
- <label><?php _e("Return Value",'acf'); ?></label>
211
- </td>
212
- <td>
213
- <?php
214
-
215
- do_action('acf/create_field', array(
216
- 'type' => 'radio',
217
- 'name' => 'fields['.$key.'][save_format]',
218
- 'value' => $field['save_format'],
219
- 'layout' => 'horizontal',
220
- 'choices' => array(
221
- 'object' => __("File Object",'acf'),
222
- 'url' => __("File URL",'acf'),
223
- 'id' => __("File ID",'acf')
224
- )
225
- ));
226
-
227
- ?>
228
- </td>
229
- </tr>
230
- <?php
231
- }
232
-
233
-
234
- /*
235
  * popup_head
236
  *
237
  * @description: css + js for thickbox
@@ -637,66 +709,8 @@ class acf_File extends acf_Field
637
 
638
  }
639
 
640
-
641
- /*--------------------------------------------------------------------------------------
642
- *
643
- * get_value_for_api
644
- *
645
- * @author Elliot Condon
646
- * @since 3.0.0
647
- *
648
- *-------------------------------------------------------------------------------------*/
649
-
650
- function get_value_for_api($post_id, $field)
651
- {
652
- // vars
653
- $defaults = array(
654
- 'save_format' => 'object',
655
- );
656
-
657
- $field = array_merge($defaults, $field);
658
-
659
- $value = parent::get_value($post_id, $field);
660
-
661
-
662
- // validate
663
- if( !$value )
664
- {
665
- return false;
666
- }
667
-
668
-
669
- // format
670
- if( $field['save_format'] == 'url' )
671
- {
672
- $value = wp_get_attachment_url($value);
673
- }
674
- elseif( $field['save_format'] == 'object' )
675
- {
676
- $attachment = get_post( $value );
677
-
678
-
679
- // validate
680
- if( !$attachment )
681
- {
682
- return false;
683
- }
684
-
685
-
686
- // create array to hold value data
687
- $value = array(
688
- 'id' => $attachment->ID,
689
- 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
690
- 'title' => $attachment->post_title,
691
- 'caption' => $attachment->post_excerpt,
692
- 'description' => $attachment->post_content,
693
- 'url' => wp_get_attachment_url( $attachment->ID ),
694
- );
695
- }
696
-
697
- return $value;
698
- }
699
-
700
  }
701
 
702
- ?>
 
 
1
  <?php
2
 
3
+ class acf_field_file extends acf_field
4
  {
5
+
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'file';
19
+ $this->label = __("File",'acf');
20
+ $this->category = __("Content",'acf');
21
 
 
 
 
22
 
23
+ // do not delete!
24
+ parent::__construct();
25
+
26
+
27
+ // extra
28
+ add_filter('get_media_item_args', array($this, 'get_media_item_args'));
29
+ add_action('acf_head-update_attachment-' . $this->name, array($this, 'acf_head_update_attachment'));
30
  add_action('wp_ajax_acf/fields/file/get_files', array($this, 'ajax_get_files'));
31
+ add_action('admin_head-media-upload-popup', array($this, 'popup_head'));
32
+ }
33
+
34
+
35
+ /*
36
+ * create_field()
37
+ *
38
+ * Create the HTML interface for your field
39
+ *
40
+ * @param $field - an array holding all the field's data
41
+ *
42
+ * @type action
43
+ * @since 3.6
44
+ * @date 23/01/13
45
+ */
46
+
47
+ function create_field( $field )
48
+ {
49
+ // vars
50
+ $options = array(
51
+ 'class' => '',
52
+ 'icon' => '',
53
+ 'file_name' => ''
54
+ );
55
+
56
+ if( $field['value'] )
57
+ {
58
+ $file_src = wp_get_attachment_url( $field['value'] );
59
+ preg_match("~[^/]*$~", $file_src, $file_name);
60
+
61
+ $options['class'] = 'active';
62
+ $options['icon'] = wp_mime_type_icon( $field['value'] );
63
+ $options['file_name'] = $file_name[0];
64
+ }
65
+
66
+ ?>
67
+ <div class="acf-file-uploader <?php echo $options['class']; ?>">
68
+ <input class="acf-file-value" type="hidden" name="<?php echo $field['name']; ?>" value="<?php echo $field['value']; ?>" />
69
+ <div class="has-file">
70
+ <ul class="hl clearfix">
71
+ <li>
72
+ <img class="acf-file-icon" src="<?php echo $options['icon']; ?>" alt=""/>
73
+ </li>
74
+ <li>
75
+ <span class="acf-file-name"><?php echo $options['file_name']; ?></span><br />
76
+ <a href="#" class="edit-file"><?php _e('Edit','acf'); ?></a>
77
+ <a href="#" class="remove-file"><?php _e('Remove','acf'); ?></a>
78
+ </li>
79
+ </ul>
80
+ </div>
81
+ <div class="no-file">
82
+ <ul class="hl clearfix">
83
+ <li>
84
+ <span><?php _e('No File Selected','acf'); ?></span>. <a href="#" class="button add-file"><?php _e('Add File','acf'); ?></a>
85
+ </li>
86
+ </ul>
87
+ </div>
88
+ </div>
89
+ <?php
90
+ }
91
+
92
+
93
+ /*
94
+ * create_options()
95
+ *
96
+ * Create extra options for your field. This is rendered when editing a field.
97
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
98
+ *
99
+ * @type action
100
+ * @since 3.6
101
+ * @date 23/01/13
102
+ *
103
+ * @param $field - an array holding all the field's data
104
+ */
105
+
106
+ function create_options( $field )
107
+ {
108
+ // vars
109
+ $defaults = array(
110
+ 'save_format' => 'id',
111
+ );
112
+
113
+ $field = array_merge($defaults, $field);
114
+ $key = $field['name'];
115
+
116
+ ?>
117
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
118
+ <td class="label">
119
+ <label><?php _e("Return Value",'acf'); ?></label>
120
+ </td>
121
+ <td>
122
+ <?php
123
+
124
+ do_action('acf/create_field', array(
125
+ 'type' => 'radio',
126
+ 'name' => 'fields['.$key.'][save_format]',
127
+ 'value' => $field['save_format'],
128
+ 'layout' => 'horizontal',
129
+ 'choices' => array(
130
+ 'object' => __("File Object",'acf'),
131
+ 'url' => __("File URL",'acf'),
132
+ 'id' => __("File ID",'acf')
133
+ )
134
+ ));
135
+
136
+ ?>
137
+ </td>
138
+ </tr>
139
+ <?php
140
+
141
+ }
142
+
143
+
144
+ /*
145
+ * format_value_for_api()
146
+ *
147
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
148
+ *
149
+ * @type filter
150
+ * @since 3.6
151
+ * @date 23/01/13
152
+ *
153
+ * @param $value - the value which was loaded from the database
154
+ * @param $post_id - the $post_id from which the value was loaded
155
+ * @param $field - the field array holding all the field options
156
+ *
157
+ * @return $value - the modified value
158
+ */
159
+
160
+ function format_value_for_api( $value, $post_id, $field )
161
+ {
162
+ // vars
163
+ $defaults = array(
164
+ 'save_format' => 'url',
165
+ );
166
+
167
+ $field = array_merge($defaults, $field);
168
+
169
+
170
+ // validate
171
+ if( !$value )
172
+ {
173
+ return false;
174
+ }
175
+
176
+
177
+ // format
178
+ if( $field['save_format'] == 'url' )
179
+ {
180
+ $value = wp_get_attachment_url($value);
181
+ }
182
+ elseif( $field['save_format'] == 'object' )
183
+ {
184
+ $attachment = get_post( $value );
185
+
186
+
187
+ // validate
188
+ if( !$attachment )
189
+ {
190
+ return false;
191
+ }
192
+
193
+
194
+ // create array to hold value data
195
+ $value = array(
196
+ 'id' => $attachment->ID,
197
+ 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
198
+ 'title' => $attachment->post_title,
199
+ 'caption' => $attachment->post_excerpt,
200
+ 'description' => $attachment->post_content,
201
+ 'url' => wp_get_attachment_url( $attachment->ID ),
202
+ );
203
+ }
204
+
205
+ return $value;
206
+ }
207
+
208
+
209
+ /*
210
+ * get_media_item_args
211
+ *
212
+ * @description:
213
+ * @since: 3.6
214
+ * @created: 27/01/13
215
+ */
216
+
217
+ function get_media_item_args( $vars )
218
+ {
219
+ $vars['send'] = true;
220
+ return($vars);
221
+ }
222
+
223
+
224
+ /*
225
  * acf_head_update_attachment
226
  *
227
  * @description:
247
  </script>
248
  <?php
249
  }
250
+
251
+
252
+ /*
253
  * ajax_get_files
254
  *
255
  * @description:
301
  die;
302
 
303
  }
304
+
305
+
306
+ /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  * popup_head
308
  *
309
  * @description: css + js for thickbox
709
 
710
  }
711
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
712
  }
713
 
714
+ new acf_field_file();
715
+
716
+ ?>
core/fields/flexible_content.php DELETED
@@ -1,952 +0,0 @@
1
- <?php
2
-
3
- class acf_Flexible_content extends acf_Field
4
- {
5
-
6
- /*--------------------------------------------------------------------------------------
7
- *
8
- * Constructor
9
- * - $parent is passed buy reference so you can play with the acf functions
10
- *
11
- * @author Elliot Condon
12
- * @since 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
-
16
- function __construct($parent)
17
- {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'flexible_content';
21
- $this->title = __("Flexible Content",'acf');
22
-
23
-
24
- // filters
25
- add_filter('acf_save_field-' . $this->name, array($this, 'acf_save_field'));
26
- add_filter('acf_load_field-' . $this->name, array($this, 'acf_load_field'));
27
- }
28
-
29
-
30
- /*
31
- * acf_load_field
32
- *
33
- * @description:
34
- * @since: 3.6
35
- * @created: 21/02/13
36
- */
37
-
38
- function acf_load_field( $field )
39
- {
40
- // apply_load field to all sub fields
41
- if( isset($field['layouts']) && is_array($field['layouts']) )
42
- {
43
- foreach( $field['layouts'] as $k => $layout )
44
- {
45
- if( isset($layout['sub_fields']) && is_array($layout['sub_fields']) )
46
- {
47
- foreach( $layout['sub_fields'] as $i => $sub_field )
48
- {
49
- // apply filters
50
- $sub_field = apply_filters('acf_load_field', $sub_field);
51
-
52
-
53
- $keys = array('type', 'name', 'key');
54
- $called = array(); // field[type] && field[name] may be the same! Don't run the same filter twice!
55
- foreach( $keys as $key )
56
- {
57
- // validate
58
- if( !isset($field[ $key ]) ){ continue; }
59
- if( in_array($field[ $key ], $called) ){ continue; }
60
-
61
-
62
- // add to $called
63
- $action = $field[ $key ] . '-' . $layout['name'] . '-' . $sub_field[ $key ];
64
- $called[] = $action;
65
-
66
-
67
- // run filters
68
- $sub_field = apply_filters('acf_load_field-' . $action, $sub_field); // old filter
69
-
70
- }
71
-
72
-
73
- // update sub field
74
- $field['layouts'][ $k ]['sub_fields'][ $i ] = $sub_field;
75
-
76
- }
77
- // foreach( $layout['sub_fields'] as $i => $sub_field )
78
- }
79
- // if( isset($layout['sub_fields']) && is_array($layout['sub_fields']) )
80
- }
81
- // foreach( $field['layouts'] as $k => $layout )
82
- }
83
- // if( isset($field['layouts']) && is_array($field['layouts']) )
84
-
85
- return $field;
86
-
87
- return $field;
88
- }
89
-
90
-
91
- /*--------------------------------------------------------------------------------------
92
- *
93
- * create_field
94
- * - called in lots of places to create the html version of the field
95
- *
96
- * @author Elliot Condon
97
- * @since 2.2.0
98
- *
99
- *-------------------------------------------------------------------------------------*/
100
-
101
- function create_field($field)
102
- {
103
- $button_label = ( isset($field['button_label']) && $field['button_label'] != "" ) ? $field['button_label'] : __("+ Add Row",'acf');
104
- $layouts = array();
105
- foreach($field['layouts'] as $l)
106
- {
107
- $layouts[$l['name']] = $l;
108
- }
109
-
110
- ?>
111
- <div class="acf_flexible_content">
112
-
113
- <div class="no_value_message" <?php if($field['value']){echo 'style="display:none;"';} ?>>
114
- <?php _e("Click the \"$button_label\" button below to start creating your layout",'acf'); ?>
115
- </div>
116
-
117
- <div class="clones">
118
- <?php $i = -1; ?>
119
- <?php foreach($layouts as $layout): $i++; ?>
120
-
121
- <div class="layout" data-layout="<?php echo $layout['name']; ?>">
122
-
123
- <input type="hidden" name="<?php echo $field['name']; ?>[acfcloneindex][acf_fc_layout]" value="<?php echo $layout['name']; ?>" />
124
-
125
- <a class="ir fc-delete-layout" href="#"></a>
126
- <p class="menu-item-handle"><span class="fc-layout-order"><?php echo $i+1; ?></span>. <?php echo $layout['label']; ?></p>
127
-
128
- <table class="widefat acf-input-table <?php if( $layout['display'] == 'row' ): ?>row_layout<?php endif; ?>">
129
- <?php if( $layout['display'] == 'table' ): ?>
130
- <thead>
131
- <tr>
132
- <?php foreach( $layout['sub_fields'] as $sub_field):
133
-
134
- // add width attr
135
- $attr = "";
136
-
137
- if( count($layout['sub_fields']) > 1 && isset($sub_field['column_width']) && $sub_field['column_width'] )
138
- {
139
- $attr = 'width="' . $sub_field['column_width'] . '%"';
140
- }
141
-
142
- ?>
143
- <th class="acf-th-<?php echo $sub_field['name']; ?>" <?php echo $attr; ?>>
144
- <span><?php echo $sub_field['label']; ?></span>
145
- <?php if( isset($sub_field['instructions']) ): ?>
146
- <span class="sub-field-instructions"><?php echo $sub_field['instructions']; ?></span>
147
- <?php endif; ?>
148
- </th><?php
149
- endforeach; ?>
150
- </tr>
151
- </thead>
152
- <?php endif; ?>
153
- <tbody>
154
- <tr>
155
- <?php
156
-
157
- // layout: Row
158
-
159
- if( $layout['display'] == 'row' ): ?>
160
- <td class="acf_input-wrap">
161
- <table class="widefat acf_input">
162
- <?php endif; ?>
163
-
164
-
165
- <?php
166
-
167
- // loop though sub fields
168
-
169
- foreach( $layout['sub_fields'] as $sub_field ): ?>
170
-
171
- <?php
172
-
173
- // layout: Row
174
-
175
- if( $layout['display'] == 'row' ): ?>
176
- <tr>
177
- <td class="label">
178
- <label><?php echo $sub_field['label']; ?></label>
179
- <?php if( isset($sub_field['instructions']) ): ?>
180
- <span class="sub-field-instructions"><?php echo $sub_field['instructions']; ?></span>
181
- <?php endif; ?>
182
- </td>
183
- <?php endif; ?>
184
-
185
- <td>
186
- <?php
187
-
188
- // add value
189
- $sub_field['value'] = isset($sub_field['default_value']) ? $sub_field['default_value'] : false;
190
-
191
- // add name
192
- $sub_field['name'] = $field['name'] . '[acfcloneindex][' . $sub_field['key'] . ']';
193
-
194
- // create field
195
- do_action('acf/create_field', $sub_field);
196
-
197
- ?>
198
- </td>
199
-
200
- <?php
201
-
202
- // layout: Row
203
-
204
- if( $layout['display'] == 'row' ): ?>
205
- </tr>
206
- <?php endif; ?>
207
-
208
-
209
- <?php endforeach; ?>
210
-
211
- <?php
212
-
213
- // layout: Row
214
-
215
- if( $layout['display'] == 'row' ): ?>
216
- </table>
217
- </td>
218
- <?php endif; ?>
219
-
220
- </tr>
221
- </tbody>
222
-
223
- </table>
224
- </div>
225
- <?php endforeach; ?>
226
- </div>
227
- <div class="values">
228
- <?php
229
-
230
- if($field['value']):
231
-
232
- foreach($field['value'] as $i => $value):
233
-
234
- // validate layout
235
- if( !isset($layouts[$value['acf_fc_layout']]) )
236
- {
237
- continue;
238
- }
239
-
240
-
241
- // vars
242
- $layout = $layouts[$value['acf_fc_layout']];
243
-
244
-
245
- ?>
246
- <div class="layout" data-layout="<?php echo $layout['name']; ?>">
247
-
248
- <input type="hidden" name="<?php echo $field['name'] ?>[<?php echo $i ?>][acf_fc_layout]" value="<?php echo $layout['name']; ?>" />
249
-
250
- <a class="ir fc-delete-layout" href="#"></a>
251
- <p class="menu-item-handle"><span class="fc-layout-order"><?php echo $i+1; ?></span>. <?php echo $layout['label']; ?></p>
252
-
253
-
254
- <table class="widefat acf-input-table <?php if( $layout['display'] == 'row' ): ?>row_layout<?php endif; ?>">
255
- <?php if( $layout['display'] == 'table' ): ?>
256
- <thead>
257
- <tr>
258
- <?php foreach( $layout['sub_fields'] as $sub_field):
259
-
260
- // add width attr
261
- $attr = "";
262
-
263
- if( count($layout['sub_fields']) > 1 && isset($sub_field['column_width']) && $sub_field['column_width'] )
264
- {
265
- $attr = 'width="' . $sub_field['column_width'] . '%"';
266
- }
267
-
268
- ?>
269
- <th class="acf-th-<?php echo $sub_field['name']; ?>" <?php echo $attr; ?>>
270
- <span><?php echo $sub_field['label']; ?></span>
271
- <?php if( isset($sub_field['instructions']) ): ?>
272
- <span class="sub-field-instructions"><?php echo $sub_field['instructions']; ?></span>
273
- <?php endif; ?>
274
- </th><?php
275
- endforeach; ?>
276
- </tr>
277
- </thead>
278
- <?php endif; ?>
279
- <tbody>
280
- <tr>
281
- <?php
282
-
283
- // layout: Row
284
-
285
- if( $layout['display'] == 'row' ): ?>
286
- <td class="acf_input-wrap">
287
- <table class="widefat acf_input">
288
- <?php endif; ?>
289
-
290
-
291
- <?php
292
-
293
- // loop though sub fields
294
-
295
- foreach( $layout['sub_fields'] as $sub_field ): ?>
296
-
297
- <?php
298
-
299
- // layout: Row
300
-
301
- if( $layout['display'] == 'row' ): ?>
302
- <tr>
303
- <td class="label">
304
- <label><?php echo $sub_field['label']; ?></label>
305
- <?php if( isset($sub_field['instructions']) ): ?>
306
- <span class="sub-field-instructions"><?php echo $sub_field['instructions']; ?></span>
307
- <?php endif; ?>
308
- </td>
309
- <?php endif; ?>
310
-
311
- <td>
312
- <?php
313
-
314
- // add value
315
- $sub_field['value'] = isset($value[$sub_field['key']]) ? $value[$sub_field['key']] : false;
316
-
317
- // add name
318
- $sub_field['name'] = $field['name'] . '[' . $i . '][' . $sub_field['key'] . ']';
319
-
320
- // create field
321
- do_action('acf/create_field', $sub_field);
322
-
323
- ?>
324
- </td>
325
-
326
- <?php
327
-
328
- // layout: Row
329
-
330
- if( $layout['display'] == 'row' ): ?>
331
- </tr>
332
- <?php endif; ?>
333
-
334
-
335
- <?php endforeach; ?>
336
-
337
- <?php
338
-
339
- // layout: Row
340
-
341
- if( $layout['display'] == 'row' ): ?>
342
- </table>
343
- </td>
344
- <?php endif; ?>
345
-
346
- </tr>
347
- </tbody>
348
-
349
- </table>
350
- </div>
351
- <?php
352
-
353
- endforeach;
354
- // foreach($field['value'] as $i => $value)
355
-
356
- endif;
357
- // if($field['value']):
358
-
359
- ?>
360
- </div>
361
-
362
- <ul class="hl clearfix flexible-footer">
363
- <li class="right">
364
- <a href="javascript:;" class="add-row-end acf-button"><?php echo $button_label; ?></a>
365
- <div class="acf-popup">
366
- <ul>
367
- <?php foreach($field['layouts'] as $layout): $i++; ?>
368
- <li><a href="javascript:;" data-layout="<?php echo $layout['name']; ?>"><?php echo $layout['label']; ?></a></li>
369
- <?php endforeach; ?>
370
- </ul>
371
- <div class="bit"></div>
372
- </div>
373
- </li>
374
- </ul>
375
-
376
- </div>
377
- <?php
378
- }
379
-
380
-
381
- /*--------------------------------------------------------------------------------------
382
- *
383
- * create_options
384
- * - called from core/field_meta_box.php to create special options
385
- *
386
- * @params : $key (int) - neccessary to group field data together for saving
387
- * $field (array) - the field data from the database
388
- * @author Elliot Condon
389
- * @since 2.2.0
390
- *
391
- *-------------------------------------------------------------------------------------*/
392
-
393
- function create_options($key, $field)
394
- {
395
- // vars
396
- $fields_names = array();
397
- $defaults = array(
398
- 'layouts' => array(),
399
- 'button_label' => __("Add Row",'acf'),
400
- );
401
-
402
- $field = array_merge($defaults, $field);
403
-
404
-
405
- // load default layout
406
- if(empty($field['layouts']))
407
- {
408
- $field['layouts'][] = array(
409
- 'name' => '',
410
- 'label' => '',
411
- 'display' => 'row',
412
- 'sub_fields' => array(),
413
- );
414
- }
415
-
416
-
417
- // get name of all fields for use in field type
418
- foreach($this->parent->fields as $f)
419
- {
420
- if( $f->name )
421
- {
422
- $fields_names[$f->name] = $f->title;
423
- }
424
- }
425
- unset( $fields_names['flexible_content'], $fields_names['tab'] );
426
-
427
-
428
- // loop through layouts and create the options for them
429
- if($field['layouts']):
430
- foreach($field['layouts'] as $layout_key => $layout):
431
-
432
- $layout['sub_fields'][] = array(
433
- 'key' => 'field_clone',
434
- 'label' => __("New Field",'acf'),
435
- 'name' => __("new_field",'acf'),
436
- 'type' => 'text',
437
- 'order_no' => 1,
438
- 'instructions' => '',
439
- );
440
-
441
- ?>
442
- <tr class="field_option field_option_<?php echo $this->name; ?>" data-id="<?php echo $layout_key; ?>">
443
- <td class="label">
444
- <label><?php _e("Layout",'acf'); ?></label>
445
- <p class="desription">
446
- <span><a class="acf_fc_reorder" title="<?php _e("Reorder Layout",'acf'); ?>" href="javascript:;"><?php _e("Reorder",'acf'); ?></a> | </span>
447
- <span><a class="acf_fc_delete" title="<?php _e("Delete Layout",'acf'); ?>" href="javascript:;"><?php _e("Delete",'acf'); ?></a>
448
-
449
- <br />
450
-
451
- <span><a class="acf_fc_add" title="<?php _e("Add New Layout",'acf'); ?>" href="javascript:;"><?php _e("Add New",'acf'); ?></a> | </span>
452
- <span><a class="acf_fc_duplicate" title="<?php _e("Duplicate Layout",'acf'); ?>" href="javascript:;"><?php _e("Duplicate",'acf'); ?></a></span>
453
- </p>
454
- </td>
455
- <td>
456
- <div class="repeater">
457
-
458
- <table class="acf_cf_meta">
459
- <tbody>
460
- <tr>
461
- <td class="acf_fc_label" style="padding-left:0;">
462
- <label><?php _e('Label','acf'); ?></label>
463
- <?php
464
- do_action('acf/create_field', array(
465
- 'type' => 'text',
466
- 'name' => 'fields['.$key.'][layouts][' . $layout_key . '][label]',
467
- 'value' => $layout['label'],
468
- ));
469
- ?>
470
- </td>
471
- <td class="acf_fc_name">
472
- <label><?php _e('Name','acf'); ?></label>
473
- <?php
474
- do_action('acf/create_field', array(
475
- 'type' => 'text',
476
- 'name' => 'fields['.$key.'][layouts][' . $layout_key . '][name]',
477
- 'value' => $layout['name'],
478
- ));
479
- ?>
480
- </td>
481
- <td class="acf_fc_display" style="padding-right:0;">
482
- <label><?php _e('Display','acf'); ?></label>
483
- <?php
484
- do_action('acf/create_field', array(
485
- 'type' => 'select',
486
- 'name' => 'fields['.$key.'][layouts][' . $layout_key . '][display]',
487
- 'value' => $layout['display'],
488
- 'choices' => array(
489
- 'row' => __("Row",'acf'),
490
- 'table' => __("Table",'acf'),
491
- )
492
- ));
493
- ?>
494
- </td>
495
- </tr>
496
- </tbody>
497
- </table>
498
-
499
- <div class="fields_header">
500
- <table class="acf widefat">
501
- <thead>
502
- <tr>
503
- <th class="field_order"><?php _e('Field Order','acf'); ?></th>
504
- <th class="field_label"><?php _e('Field Label','acf'); ?></th>
505
- <th class="field_name"><?php _e('Field Name','acf'); ?></th>
506
- <th class="field_type"><?php _e('Field Type','acf'); ?></th>
507
- </tr>
508
- </thead>
509
- </table>
510
- </div>
511
- <div class="fields">
512
-
513
- <div class="no_fields_message" <?php if(count($layout['sub_fields']) > 1){ echo 'style="display:none;"'; } ?>>
514
- <?php _e("No fields. Click the \"+ Add Sub Field button\" to create your first field.",'acf'); ?>
515
- </div>
516
-
517
- <?php foreach($layout['sub_fields'] as $sub_field): ?>
518
- <div class="field field-<?php echo $sub_field['key']; ?> sub_field" data-id="<?php echo $sub_field['key']; ?>">
519
- <div class="field_meta">
520
- <table class="acf widefat">
521
- <tr>
522
- <td class="field_order"><span class="circle"><?php echo (int)$sub_field['order_no'] + 1; ?></span></td>
523
- <td class="field_label">
524
- <strong>
525
- <a class="acf_edit_field" title="<?php _e("Edit this Field",'acf'); ?>" href="javascript:;"><?php echo $sub_field['label']; ?></a>
526
- </strong>
527
- <div class="row_options">
528
- <span><a class="acf_edit_field" title="<?php _e("Edit this Field",'acf'); ?>" href="javascript:;"><?php _e("Edit",'acf'); ?></a> | </span>
529
- <span><a title="<?php _e("Read documentation for this field",'acf'); ?>" href="http://www.advancedcustomfields.com/docs/field-types/" target="_blank"><?php _e("Docs",'acf'); ?></a> | </span>
530
- <span><a class="acf_duplicate_field" title="<?php _e("Duplicate this Field",'acf'); ?>" href="javascript:;"><?php _e("Duplicate",'acf'); ?></a> | </span>
531
- <span><a class="acf_delete_field" title="<?php _e("Delete this Field",'acf'); ?>" href="javascript:;"><?php _e("Delete",'acf'); ?></a>
532
- </div>
533
- </td>
534
- <td class="field_name"><?php echo $sub_field['name']; ?></td>
535
- <td class="field_type"><?php echo $sub_field['type']; ?></td>
536
- </tr>
537
- </table>
538
- </div>
539
-
540
- <div class="field_form_mask">
541
- <div class="field_form">
542
- <table class="acf_input widefat">
543
- <tbody>
544
- <tr class="field_label">
545
- <td class="label">
546
- <label><span class="required">*</span><?php _e("Field Label",'acf'); ?></label>
547
- <p class="description"><?php _e("This is the name which will appear on the EDIT page",'acf'); ?></p>
548
- </td>
549
- <td>
550
- <?php
551
- do_action('acf/create_field', array(
552
- 'type' => 'text',
553
- 'name' => 'fields['.$key.'][layouts][' . $layout_key . '][sub_fields]['.$sub_field['key'].'][label]',
554
- 'value' => $sub_field['label'],
555
- 'class' => 'label',
556
- ));
557
- ?>
558
- </td>
559
- </tr>
560
- <tr class="field_name">
561
- <td class="label">
562
- <label><span class="required">*</span><?php _e("Field Name",'acf'); ?></label>
563
- <p class="description"><?php _e("Single word, no spaces. Underscores and dashes allowed",'acf'); ?></p>
564
- </td>
565
- <td>
566
- <?php
567
- do_action('acf/create_field', array(
568
- 'type' => 'text',
569
- 'name' => 'fields['.$key.'][layouts][' . $layout_key . '][sub_fields]['.$sub_field['key'].'][name]',
570
- 'value' => $sub_field['name'],
571
- 'class' => 'name',
572
- ));
573
- ?>
574
- </td>
575
- </tr>
576
- <tr class="field_type">
577
- <td class="label"><label><span class="required">*</span><?php _e("Field Type",'acf'); ?></label></td>
578
- <td>
579
- <?php
580
- do_action('acf/create_field', array(
581
- 'type' => 'select',
582
- 'name' => 'fields['.$key.'][layouts][' . $layout_key . '][sub_fields]['.$sub_field['key'].'][type]',
583
- 'value' => $sub_field['type'],
584
- 'class' => 'type',
585
- 'choices' => $fields_names
586
- ));
587
- ?>
588
- </td>
589
- </tr>
590
- <tr class="field_instructions">
591
- <td class="label"><label><?php _e("Field Instructions",'acf'); ?></label></td>
592
- <td>
593
- <?php
594
-
595
- if( !isset($sub_field['instructions']) )
596
- {
597
- $sub_field['instructions'] = "";
598
- }
599
-
600
- do_action('acf/create_field', array(
601
- 'type' => 'text',
602
- 'name' => 'fields['.$key.'][layouts][' . $layout_key . '][sub_fields]['.$sub_field['key'].'][instructions]',
603
- 'value' => $sub_field['instructions'],
604
- 'class' => 'instructions',
605
- ));
606
- ?>
607
- </td>
608
- </tr>
609
- <tr class="field_column_width">
610
- <td class="label">
611
- <label><?php _e("Column Width",'acf'); ?></label>
612
- <p class="description"><?php _e("Leave blank for auto",'acf'); ?></p>
613
- </td>
614
- <td>
615
- <?php
616
-
617
- if( !isset($sub_field['column_width']) )
618
- {
619
- $sub_field['column_width'] = "";
620
- }
621
-
622
- do_action('acf/create_field', array(
623
- 'type' => 'number',
624
- 'name' => 'fields['.$key.'][layouts][' . $layout_key . '][sub_fields]['.$sub_field['key'].'][column_width]',
625
- 'value' => $sub_field['column_width'],
626
- 'class' => 'column_width',
627
- ));
628
- ?> %
629
- </td>
630
- </tr>
631
- <?php
632
-
633
- if( isset($this->parent->fields[ $sub_field['type'] ]) )
634
- {
635
- $this->parent->fields[$sub_field['type']]->create_options($key.'][layouts][' . $layout_key . '][sub_fields]['.$sub_field['key'], $sub_field);
636
- }
637
-
638
- ?>
639
- <tr class="field_save">
640
- <td class="label">
641
- <!-- <label><?php _e("Save Field",'acf'); ?></label> -->
642
- </td>
643
- <td>
644
- <ul class="hl clearfix">
645
- <li>
646
- <a class="acf_edit_field acf-button grey" title="<?php _e("Close Field",'acf'); ?>" href="javascript:;"><?php _e("Close Sub Field",'acf'); ?></a>
647
- </li>
648
- </ul>
649
- </td>
650
- </tr>
651
- </tbody>
652
- </table>
653
- </div><!-- End Form -->
654
- </div><!-- End Form Mask -->
655
-
656
- </div>
657
- <?php endforeach; ?>
658
- </div>
659
- <div class="table_footer">
660
- <div class="order_message"><?php _e('Drag and drop to reorder','acf'); ?></div>
661
- <a href="javascript:;" id="add_field" class="acf-button"><?php _e('+ Add Sub Field','acf'); ?></a>
662
- </div>
663
- </div>
664
- </td>
665
- </tr><?php endforeach; endif; ?>
666
- <tr class="field_option field_option_<?php echo $this->name; ?>">
667
- <td class="label">
668
- <label><?php _e("Button Label",'acf'); ?></label>
669
- </td>
670
- <td>
671
- <?php
672
- do_action('acf/create_field', array(
673
- 'type' => 'text',
674
- 'name' => 'fields['.$key.'][button_label]',
675
- 'value' => $field['button_label'],
676
- ));
677
- ?>
678
- </td>
679
- </tr><?php
680
- }
681
-
682
-
683
- /*--------------------------------------------------------------------------------------
684
- *
685
- * update_value
686
- *
687
- * @author Elliot Condon
688
- * @since 2.2.0
689
- *
690
- *-------------------------------------------------------------------------------------*/
691
-
692
- function update_value($post_id, $field, $value)
693
- {
694
- $sub_fields = array();
695
-
696
- foreach($field['layouts'] as $layout)
697
- {
698
- foreach($layout['sub_fields'] as $sub_field)
699
- {
700
- $sub_fields[$sub_field['key']] = $sub_field;
701
- }
702
- }
703
-
704
- $total = array();
705
-
706
- if($value)
707
- {
708
- // remove dummy field
709
- unset($value['acfcloneindex']);
710
-
711
- $i = -1;
712
-
713
- // loop through rows
714
- foreach($value as $row)
715
- {
716
- $i++;
717
-
718
- // increase total
719
- $total[] = $row['acf_fc_layout'];
720
- unset($row['acf_fc_layout']);
721
-
722
- // loop through sub fields
723
- foreach($row as $field_key => $v)
724
- {
725
- $sub_field = $sub_fields[$field_key];
726
-
727
- // update full name
728
- $sub_field['name'] = $field['name'] . '_' . $i . '_' . $sub_field['name'];
729
-
730
- // save sub field value
731
- $this->parent->update_value($post_id, $sub_field, $v);
732
- }
733
- }
734
- }
735
-
736
-
737
- /*
738
- * Remove Old Data
739
- *
740
- * @credit: http://support.advancedcustomfields.com/discussion/1994/deleting-single-repeater-fields-does-not-remove-entry-from-database
741
- */
742
-
743
- $old_total = parent::get_value($post_id, $field);
744
- $old_total = count( $old_total );
745
- $new_total = count( $total );
746
-
747
- if( $old_total > $new_total )
748
- {
749
- foreach( $sub_fields as $sub_field )
750
- {
751
- for ( $j = $new_total; $j < $old_total; $j++ )
752
- {
753
- parent::delete_value( $post_id, $field['name'] . '_' . $j . '_' . $sub_field['name'] );
754
- }
755
- }
756
- }
757
-
758
- parent::update_value($post_id, $field, $total);
759
-
760
- }
761
-
762
-
763
- /*--------------------------------------------------------------------------------------
764
- *
765
- * pre_save_field
766
- * - called just before saving the field to the database.
767
- *
768
- * @author Elliot Condon
769
- * @since 2.2.0
770
- *
771
- *-------------------------------------------------------------------------------------*/
772
-
773
- function acf_save_field( $field )
774
- {
775
-
776
- // format sub_fields
777
- if( $field['layouts'] )
778
- {
779
- $layouts = array();
780
-
781
- // loop through and save fields
782
- foreach($field['layouts'] as $layout_key => $layout)
783
- {
784
-
785
- if( $layout['sub_fields'] )
786
- {
787
- // remove dummy field
788
- unset( $layout['sub_fields']['field_clone'] );
789
-
790
-
791
- // loop through and save fields
792
- $i = -1;
793
- $sub_fields = array();
794
-
795
-
796
- foreach( $layout['sub_fields'] as $key => $f )
797
- {
798
- $i++;
799
-
800
-
801
- // order + key
802
- $f['order_no'] = $i;
803
- $f['key'] = $key;
804
-
805
-
806
- // apply filters
807
- $f = apply_filters('acf_save_field', $f );
808
- $f = apply_filters('acf_save_field-' . $f['type'], $f );
809
-
810
-
811
- $sub_fields[] = $f;
812
-
813
- }
814
-
815
-
816
- // update sub fields
817
- $layout['sub_fields'] = $sub_fields;
818
-
819
- }
820
-
821
- $layouts[] = $layout;
822
-
823
- }
824
-
825
- // clean array keys
826
- $field['layouts'] = $layouts;
827
-
828
- }
829
-
830
-
831
- // return updated repeater field
832
- return $field;
833
-
834
- }
835
-
836
-
837
- /*--------------------------------------------------------------------------------------
838
- *
839
- * get_value
840
- * - called from the input edit page to get the value.
841
- *
842
- * @author Elliot Condon
843
- * @since 2.2.0
844
- *
845
- *-------------------------------------------------------------------------------------*/
846
-
847
- function get_value($post_id, $field)
848
- {
849
- $layouts = array();
850
- foreach($field['layouts'] as $l)
851
- {
852
- $layouts[$l['name']] = $l;
853
- }
854
-
855
- // vars
856
- $values = array();
857
- $layout_order = false;
858
-
859
-
860
- // get total rows
861
- $layout_order = parent::get_value($post_id, $field);
862
-
863
-
864
- if( !empty( $layout_order) )
865
- {
866
- $i = -1;
867
- // loop through rows
868
- foreach($layout_order as $layout)
869
- {
870
- $i++;
871
- $values[$i]['acf_fc_layout'] = $layout;
872
-
873
- // check if layout still exists
874
- if(isset($layouts[$layout]))
875
- {
876
- // loop through sub fields
877
- foreach($layouts[$layout]['sub_fields'] as $sub_field)
878
- {
879
- // update full name
880
- $sub_field['name'] = $field['name'] . '_' . $i . '_' . $sub_field['name'];
881
-
882
- $values[$i][ $sub_field['key'] ] = $this->parent->get_value($post_id, $sub_field);
883
- }
884
- }
885
- }
886
- }
887
- else
888
- {
889
- $values = false;
890
- }
891
-
892
- return $values;
893
- }
894
-
895
-
896
- /*--------------------------------------------------------------------------------------
897
- *
898
- * get_value_for_api
899
- *
900
- * @author Elliot Condon
901
- * @since 3.0.0
902
- *
903
- *-------------------------------------------------------------------------------------*/
904
-
905
- function get_value_for_api($post_id, $field)
906
- {
907
- $layouts = array();
908
- foreach($field['layouts'] as $l)
909
- {
910
- $layouts[$l['name']] = $l;
911
- }
912
-
913
- // vars
914
- $values = array();
915
- $layout_order = false;
916
-
917
-
918
- // get total rows
919
- $layout_order = parent::get_value($post_id, $field);
920
-
921
-
922
- if($layout_order)
923
- {
924
- $i = -1;
925
- // loop through rows
926
- foreach($layout_order as $layout)
927
- {
928
- $i++;
929
- $values[$i]['acf_fc_layout'] = $layout;
930
-
931
- // loop through sub fields
932
- foreach($layouts[$layout]['sub_fields'] as $sub_field)
933
- {
934
- // store name
935
- $field_name = $sub_field['name'];
936
-
937
- // update full name
938
- $sub_field['name'] = $field['name'] . '_' . $i . '_' . $field_name;
939
-
940
- $values[$i][$field_name] = $this->parent->get_value_for_api($post_id, $sub_field);
941
- }
942
- }
943
-
944
- return $values;
945
- }
946
-
947
- return array();
948
- }
949
-
950
- }
951
-
952
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/fields/gallery.php DELETED
@@ -1,796 +0,0 @@
1
- <?php
2
-
3
- /*
4
- * Gallery Field
5
- *
6
- * @description:
7
- * @created: 28/06/12
8
- */
9
-
10
- class acf_Gallery extends acf_Field
11
- {
12
-
13
- /*
14
- * Constructer
15
- *
16
- * @description:
17
- * @created: 5/07/12
18
- */
19
-
20
- function __construct($parent)
21
- {
22
- parent::__construct($parent);
23
-
24
- $this->name = 'gallery';
25
- $this->title = __("Gallery",'acf');
26
-
27
-
28
- // actions
29
- add_action('admin_head-media-upload-popup', array($this, 'popup_head'));
30
- add_action('acf_head-update_attachment-gallery', array($this, 'acf_head_update_attachment'));
31
- add_action('wp_ajax_acf/fields/gallery/get_image', array($this, 'get_image'));
32
- }
33
-
34
-
35
- /*
36
- * get_image
37
- *
38
- * @description:
39
- * @since: 3.5.8
40
- * @created: 18/01/13
41
- */
42
-
43
- function get_image()
44
- {
45
-
46
- // vars
47
- $options = array(
48
- 'nonce' => '',
49
- 'id' => '',
50
- 'preview_size' => 'full'
51
- );
52
- $return = array();
53
-
54
-
55
- // load post options
56
- $options = array_merge($options, $_POST);
57
-
58
-
59
- // verify nonce
60
- if( ! wp_verify_nonce($options['nonce'], 'acf_nonce') )
61
- {
62
- die(0);
63
- }
64
-
65
-
66
- // get attachment object
67
- $attachment = get_post( $options['id'] );
68
-
69
- $src = wp_get_attachment_image_src( $attachment->ID, $options['preview_size'] );
70
-
71
- $return = array(
72
- 'id' => $attachment->ID,
73
- 'src' => $src[0],
74
- 'title'=> $attachment->post_title,
75
- 'caption'=> $attachment->post_excerpt,
76
- 'alt'=> get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
77
- 'description'=> $attachment->post_content,
78
- );
79
-
80
-
81
- echo json_encode($return);
82
- die;
83
- }
84
-
85
-
86
- /*--------------------------------------------------------------------------------------
87
- *
88
- * create_options
89
- * - this function is called from core/field_meta_box.php to create extra options
90
- * for your field
91
- *
92
- * @params
93
- * - $key (int) - the $_POST obejct key required to save the options to the field
94
- * - $field (array) - the field object
95
- *
96
- * @author Elliot Condon
97
- * @since 2.2.0
98
- *
99
- *-------------------------------------------------------------------------------------*/
100
-
101
- function create_options($key, $field)
102
- {
103
- // vars
104
- $defaults = array(
105
- 'preview_size' => 'thumbnail',
106
- );
107
-
108
- $field = array_merge($defaults, $field);
109
-
110
- ?>
111
- <tr class="field_option field_option_<?php echo $this->name; ?>">
112
- <td class="label">
113
- <label><?php _e("Preview Size",'acf'); ?></label>
114
- <p class="description"><?php _e("Thumbnail is advised",'acf'); ?></p>
115
- </td>
116
- <td>
117
- <?php
118
-
119
- $image_sizes = $this->parent->get_all_image_sizes();
120
-
121
- do_action('acf/create_field', array(
122
- 'type' => 'radio',
123
- 'name' => 'fields['.$key.'][preview_size]',
124
- 'value' => $field['preview_size'],
125
- 'layout' => 'horizontal',
126
- 'choices' => $image_sizes
127
- ));
128
-
129
- ?>
130
- </td>
131
- </tr>
132
- <?php
133
-
134
- }
135
-
136
-
137
- function acf_head_update_attachment()
138
- {
139
- ?>
140
- <script type="text/javascript">
141
- (function($){
142
-
143
- // vars
144
- var div = self.parent.acf.media.div;
145
-
146
-
147
- self.parent.acf.fields.gallery.update_image();
148
-
149
-
150
- // add message
151
- self.parent.acf.helpers.add_message('<?php _e("Image Updated",'acf'); ?>.', div);
152
-
153
-
154
- })(jQuery);
155
- </script>
156
- <?php
157
- }
158
-
159
-
160
- /*--------------------------------------------------------------------------------------
161
- *
162
- * create_field
163
- * - this function is called on edit screens to produce the html for this field
164
- *
165
- * @author Elliot Condon
166
- * @since 2.2.0
167
- *
168
- *-------------------------------------------------------------------------------------*/
169
-
170
- function create_field($field)
171
- {
172
- // vars
173
- $defaults = array(
174
- 'value' => false,
175
- 'preview_size' => 'thumbnail',
176
- );
177
-
178
- $field = array_merge($defaults, $field);
179
-
180
- ?>
181
- <div class="acf-gallery" data-preview_size="<?php echo $field['preview_size']; ?>">
182
-
183
- <input type="hidden" name="<?php echo $field['name']; ?>" value="" />
184
-
185
- <div class="thumbnails">
186
- <div class="inner clearfix">
187
- <?php if( $field['value'] ): foreach( $field['value'] as $attachment ):
188
-
189
- $src = wp_get_attachment_image_src( $attachment['id'], $field['preview_size'] );
190
- $src = $src[0];
191
-
192
- ?>
193
- <div class="thumbnail" data-id="<?php echo $attachment['id']; ?>">
194
- <input class="acf-image-value" type="hidden" name="<?php echo $field['name']; ?>[]" value="<?php echo $attachment['id']; ?>" />
195
- <div class="inner clearfix">
196
- <img src="<?php echo $src; ?>" alt="" />
197
- <div class="list-data">
198
- <table>
199
- <tbody>
200
- <tr>
201
- <th><label><?php _e("Title",'acf'); ?>:</label></th>
202
- <td><?php echo $attachment['title']; ?></td>
203
- </tr>
204
- <tr>
205
- <th><label><?php _e("Alternate Text",'acf'); ?>:</label></th>
206
- <td><?php echo $attachment['alt']; ?></td>
207
- </tr>
208
- <tr>
209
- <th><label><?php _e("Caption",'acf'); ?>:</label></th>
210
- <td><?php echo $attachment['caption']; ?></td>
211
- </tr>
212
- <tr>
213
- <th><label><?php _e("Description",'acf'); ?>:</label></th>
214
- <td><?php echo $attachment['description']; ?></td>
215
- </tr>
216
- </tbody>
217
- </table>
218
- </div>
219
- </div>
220
- <div class="hover">
221
- <ul class="bl">
222
- <li><a href="#" class="acf-button-delete ir"><?php _e("Remove",'acf'); ?></a></li>
223
- <li><a href="#" class="acf-button-edit ir"><?php _e("Edit",'acf'); ?></a></li>
224
- </ul>
225
- </div>
226
-
227
- </div>
228
- <?php endforeach; endif; ?>
229
- </div>
230
- </div>
231
-
232
- <div class="toolbar">
233
- <ul class="hl clearfix">
234
- <li class="add-image-li"><a class="acf-button add-image" href="#"><?php _e("Add Image",'acf'); ?></a></li>
235
- <li class="gallery-li view-grid-li active"><div class="divider divider-left"></div><a class="ir view-grid" href="#"><?php _e("Grid",'acf'); ?></a><div class="divider"></div></li>
236
- <li class="gallery-li view-list-li"><a class="ir view-list" href="#"><?php _e("List",'acf'); ?></a><div class="divider"></div></li>
237
- <li class="gallery-li count-li right">
238
- <span class="count" data-0="<?php _e("No images selected",'acf'); ?>" data-1="<?php _e("1 image selected",'acf'); ?>" data-2="<?php _e("{count} images selected",'acf'); ?>"></span>
239
- </li>
240
- </ul>
241
- </div>
242
-
243
- <script type="text/html" class="tmpl-thumbnail">
244
- <div class="thumbnail" data-id="{id}">
245
- <input type="hidden" class="acf-image-value" name="<?php echo $field['name']; ?>[]" value="{id}" />
246
- <div class="inner clearfix">
247
- <img src="{src}" alt="{alt}" />
248
- <div class="list-data">
249
- <table>
250
- <tbody>
251
- <tr>
252
- <th><label><?php _e("Title",'acf'); ?>:</label></th>
253
- <td class="td-title">{title}</td>
254
- </tr>
255
- <tr>
256
- <th><label><?php _e("Alternate Text",'acf'); ?>:</label></th>
257
- <td class="td-alt">{alt}</td>
258
- </tr>
259
- <tr>
260
- <th><label><?php _e("Caption",'acf'); ?>:</label></th>
261
- <td class="td-caption">{caption}</td>
262
- </tr>
263
- <tr>
264
- <th><label><?php _e("Description",'acf'); ?>:</label></th>
265
- <td class="td-description">{description}</td>
266
- </tr>
267
- </tbody>
268
- </table>
269
- </div>
270
- </div>
271
- <div class="hover">
272
- <ul class="bl">
273
- <li><a href="#" class="acf-button-delete ir"><?php _e("Remove",'acf'); ?></a></li>
274
- <li><a href="#" class="acf-button-edit ir"><?php _e("Edit",'acf'); ?></a></li>
275
- </ul>
276
- </div>
277
-
278
- </div>
279
- </script>
280
-
281
- </div>
282
- <?php
283
- }
284
-
285
-
286
- /*--------------------------------------------------------------------------------------
287
- *
288
- * get_value
289
- * - called from the edit page to get the value of your field. This function is useful
290
- * if your field needs to collect extra data for your create_field() function.
291
- *
292
- * @params
293
- * - $post_id (int) - the post ID which your value is attached to
294
- * - $field (array) - the field object.
295
- *
296
- * @author Elliot Condon
297
- * @since 2.2.0
298
- *
299
- *-------------------------------------------------------------------------------------*/
300
-
301
- function get_value($post_id, $field)
302
- {
303
- // get value
304
- $value = parent::get_value($post_id, $field);
305
- $new_value = array();
306
-
307
-
308
- // empty?
309
- if( empty($value) )
310
- {
311
- return $value;
312
- }
313
-
314
-
315
- // find attachments (DISTINCT POSTS)
316
- $attachments = get_posts(array(
317
- 'post_type' => 'attachment',
318
- 'numberposts' => -1,
319
- 'post_status' => null,
320
- 'post__in' => $value,
321
- ));
322
-
323
- $ordered_attachments = array();
324
- foreach( $attachments as $attachment)
325
- {
326
- // create array to hold value data
327
- $ordered_attachments[ $attachment->ID ] = array(
328
- 'id' => $attachment->ID,
329
- 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
330
- 'title' => $attachment->post_title,
331
- 'caption' => $attachment->post_excerpt,
332
- 'description' => $attachment->post_content,
333
- );
334
- }
335
-
336
-
337
- // override value array with attachments
338
- foreach( $value as $v)
339
- {
340
- if( isset($ordered_attachments[ $v ]) )
341
- {
342
- $new_value[] = $ordered_attachments[ $v ];
343
- }
344
- }
345
-
346
-
347
- /*
348
- // format attachments
349
- $ordered_attachments = array();
350
- foreach( $attachments as $attachment )
351
- {
352
- $ordered_attachments[ $attachment->ID ] = $attachment;
353
- }
354
-
355
-
356
- // update value with corisponding attachments
357
- foreach( $value as $k => $v)
358
- {
359
- // get the attachment onject for this value (attachment id)
360
- $attachment = $ordered_attachments[ $v ];
361
-
362
- // create array to hold value data
363
- $value[ $k ] = array(
364
- 'id' => $attachment->ID,
365
- 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
366
- 'title' => $attachment->post_title,
367
- 'caption' => $attachment->post_excerpt,
368
- 'description' => $attachment->post_content,
369
- );
370
- }
371
-
372
- */
373
-
374
- // return value
375
- return $new_value;
376
- }
377
-
378
-
379
- /*--------------------------------------------------------------------------------------
380
- *
381
- * get_value_for_api
382
- * - called from your template file when using the API functions (get_field, etc).
383
- * This function is useful if your field needs to format the returned value
384
- *
385
- * @params
386
- * - $post_id (int) - the post ID which your value is attached to
387
- * - $field (array) - the field object.
388
- *
389
- * @author Elliot Condon
390
- * @since 3.0.0
391
- *
392
- *-------------------------------------------------------------------------------------*/
393
-
394
- function get_value_for_api($post_id, $field)
395
- {
396
- // get value
397
- $value = $this->get_value($post_id, $field);
398
-
399
-
400
- // find all image sizes
401
- $image_sizes = get_intermediate_image_sizes();
402
-
403
-
404
- if( $value )
405
- {
406
- foreach( $value as $k => $v )
407
- {
408
- // full url
409
- $src = wp_get_attachment_image_src( $v['id'], 'full' );
410
- $value[$k]['url'] = $src[0];
411
- $value[$k]['width'] = $src[1];
412
- $value[$k]['height'] = $src[2];
413
-
414
- // sizes
415
- if( $image_sizes )
416
- {
417
- $value[$k]['sizes'] = array();
418
-
419
- foreach( $image_sizes as $image_size )
420
- {
421
- // find src
422
- $src = wp_get_attachment_image_src( $v['id'], $image_size );
423
-
424
- // add src
425
- $value[$k]['sizes'][ $image_size ] = $src[0];
426
- $value[$k]['sizes'][ $image_size . '-width' ] = $src[1];
427
- $value[$k]['sizes'][ $image_size . '-height' ] = $src[2];
428
-
429
- }
430
- // foreach( $image_sizes as $image_size )
431
- }
432
- // if( $image_sizes )
433
- }
434
- // foreach( $value as $k => $v )
435
- }
436
- // if( $value )
437
-
438
-
439
- // return value
440
- return $value;
441
-
442
- }
443
-
444
-
445
- /*
446
- * popup_head
447
- *
448
- * @description:
449
- * @since 3.2.8
450
- * @created: 6/07/12
451
- */
452
-
453
- function popup_head()
454
- {
455
- // options
456
- $defaults = array(
457
- 'acf_type' => '',
458
- 'acf_gallery_id' => '',
459
- 'acf_preview_size' => 'thumbnail',
460
- 'tab' => 'type',
461
- );
462
-
463
- $options = array_merge($defaults, $_GET);
464
-
465
-
466
- // validate
467
- if( $options['acf_type'] != 'gallery' )
468
- {
469
- return;
470
- }
471
-
472
-
473
- ?><style type="text/css">
474
- #media-upload-header #sidemenu li#tab-type_url,
475
- #media-items .media-item a.toggle,
476
- #media-items .media-item tr.image-size,
477
- #media-items .media-item tr.align,
478
- #media-items .media-item tr.url,
479
- #media-items .media-item .slidetoggle {
480
- display: none !important;
481
- }
482
-
483
- #media-items .media-item {
484
- position: relative;
485
- overflow: hidden;
486
- }
487
-
488
- #media-items .media-item .acf-checkbox {
489
- float: left;
490
- margin: 28px 10px 0;
491
- }
492
-
493
- #media-items .media-item .pinkynail {
494
- max-width: 64px;
495
- max-height: 64px;
496
- display: block !important;
497
- margin: 2px;
498
- }
499
-
500
- #media-items .media-item .filename.new {
501
- min-height: 0;
502
- padding: 20px 10px 10px 10px;
503
- line-height: 15px;
504
- }
505
-
506
- #media-items .media-item .title {
507
- line-height: 14px;
508
- }
509
-
510
- #media-items .media-item .acf-select {
511
- float: right;
512
- margin: 22px 12px 0 10px;
513
- }
514
-
515
- #media-upload .ml-submit {
516
- display: none !important;
517
- }
518
-
519
- #media-upload .acf-submit {
520
- margin: 1em 0;
521
- padding: 1em 0;
522
- position: relative;
523
- overflow: hidden;
524
- display: none; /* default is hidden */
525
- clear: both;
526
- }
527
-
528
- #media-upload .acf-submit a {
529
- float: left;
530
- margin: 0 10px 0 0;
531
- }
532
-
533
- .acf-message-wrapper .message {
534
- margin: 2px 2px 0;
535
- }
536
-
537
- #media-items .media-item.media-item-added {
538
- background: #F9F9F9;
539
- }
540
-
541
- #wpcontent {
542
- margin-left: 0 !important;
543
- }
544
-
545
- <?php if( $options['tab'] == 'gallery' ): ?>
546
- #sort-buttons,
547
- #gallery-form > .widefat,
548
- #media-items .menu_order,
549
- #gallery-settings {
550
- display: none !important;
551
- }
552
- <?php endif; ?>
553
-
554
- </style>
555
- <script type="text/javascript">
556
- (function($){
557
-
558
-
559
- /*
560
- * Exists
561
- *
562
- * @description: returns true / false
563
- * @created: 1/03/2011
564
- */
565
-
566
- $.fn.exists = function()
567
- {
568
- return $(this).length>0;
569
- };
570
-
571
-
572
- /*
573
- * global vars
574
- *
575
- * @description:
576
- * @created: 16/08/12
577
- */
578
- var gallery,
579
- tmpl_thumbnail;
580
-
581
-
582
- /*
583
- * Disable / Enable image
584
- *
585
- * @description:
586
- * @created: 16/08/12
587
- */
588
-
589
- function disable_image( div )
590
- {
591
- // add class
592
- div.addClass('media-item-added');
593
-
594
-
595
- // change button text
596
- div.find('.acf-select').addClass('disabled').text("<?php _e("Added",'acf'); ?>");
597
-
598
- }
599
-
600
-
601
- /*
602
- * Select Image
603
- *
604
- * @created : 28/03/2012
605
- */
606
-
607
- $('#media-items .media-item a.acf-select').live('click', function(){
608
-
609
- var attachment_id = $(this).attr('href'),
610
- div = $(this).closest('.media-item');
611
-
612
-
613
- // does this image already exist in the gallery?
614
- if( gallery.find('.thumbnail[data-id="' + attachment_id + '"]').length > 0 )
615
- {
616
- alert("<?php _e("Image already exists in gallery",'acf'); ?>");
617
- return false;
618
- }
619
-
620
-
621
- // show added message
622
- disable_image( div );
623
-
624
-
625
- // add image
626
- add_image( attachment_id );
627
-
628
-
629
- return false;
630
-
631
- });
632
-
633
-
634
- // edit toggle
635
- $('#media-items .media-item a.acf-toggle-edit').live('click', function(){
636
-
637
- if( $(this).hasClass('active') )
638
- {
639
- $(this).removeClass('active');
640
- $(this).closest('.media-item').find('.slidetoggle').attr('style', 'display: none !important');
641
- return false;
642
- }
643
- else
644
- {
645
- $(this).addClass('active');
646
- $(this).closest('.media-item').find('.slidetoggle').attr('style', 'display: table !important');
647
- return false;
648
- }
649
-
650
- });
651
-
652
-
653
- // set a interval function to add buttons to media items
654
- function acf_add_buttons()
655
- {
656
-
657
- // add buttons to media items
658
- $('#media-items .media-item:not(.acf-active)').each(function(){
659
-
660
- // needs attachment ID
661
- if($(this).children('input[id*="type-of-"]').length == 0){ return false; }
662
-
663
- // only once!
664
- $(this).addClass('acf-active');
665
-
666
- // find id
667
- var id = $(this).children('input[id*="type-of-"]').attr('id').replace('type-of-', '');
668
-
669
- // Add edit button
670
- $(this).find('.filename.new').append('<br /><a href="#" class="acf-toggle-edit">Edit</a>');
671
-
672
- // Add select button
673
- $(this).find('.filename.new').before('<a href="' + id + '" class="button acf-select"><?php _e("Add Image",'acf'); ?></a>');
674
-
675
- // add save changes button
676
- $(this).find('tr.submit input.button').hide().before('<input type="submit" value="<?php _e("Update Image",'acf'); ?>" class="button savebutton" />');
677
-
678
-
679
- });
680
-
681
-
682
- // disable images
683
- gallery.find('.thumbnails .thumbnail input[type="hidden"]').each(function(){
684
-
685
- var div = $('#media-item-' + $(this).val());
686
-
687
- if( div.exists() )
688
- {
689
- disable_image( div );
690
- }
691
-
692
- });
693
- }
694
- <?php
695
-
696
- // run the acf_add_buttons ever 500ms when on the image upload tab
697
- if($options['tab'] == 'type'): ?>
698
- var acf_t = setInterval(function(){
699
-
700
- acf_add_buttons();
701
-
702
- // auto add images
703
- $('#media-items .media-item:not(.media-item-added)').each(function(){
704
- $(this).find('a.acf-select').trigger('click');
705
- });
706
-
707
-
708
- }, 500);
709
- <?php endif; ?>
710
-
711
-
712
- // add acf input filters to allow for tab navigation
713
- $(document).ready(function(){
714
-
715
- // vars
716
- gallery = self.parent.acf.media.div;
717
- tmpl_thumbnail = gallery.find('.tmpl-thumbnail').html();
718
-
719
-
720
- // add buttins
721
- setTimeout(function(){
722
-
723
- acf_add_buttons();
724
-
725
- }, 1);
726
-
727
-
728
- $('form#filter').each(function(){
729
-
730
- $(this).append('<input type="hidden" name="acf_preview_size" value="<?php echo $options['acf_preview_size']; ?>" />');
731
- $(this).append('<input type="hidden" name="acf_type" value="gallery" />');
732
-
733
- });
734
-
735
- $('form#image-form, form#library-form').each(function(){
736
-
737
- var action = $(this).attr('action');
738
- action += "&acf_type=gallery&acf_preview_size=<?php $options['acf_preview_size']; ?>";
739
- $(this).attr('action', action);
740
-
741
- });
742
-
743
-
744
- });
745
-
746
-
747
- /*
748
- * add_image
749
- *
750
- * @description:
751
- * @created: 2/07/12
752
- */
753
-
754
- function add_image( id )
755
- {
756
- var ajax_data = {
757
- action : 'acf/fields/gallery/get_image',
758
- nonce : self.parent.acf.nonce,
759
- id : id,
760
- preview_size : "<?php echo $options['acf_preview_size']; ?>"
761
- };
762
-
763
-
764
- // ajax
765
- $.ajax({
766
- url: ajaxurl,
767
- type: 'post',
768
- data : ajax_data,
769
- cache: false,
770
- dataType: "json",
771
- success: function( json ) {
772
-
773
- // validate
774
- if( !json )
775
- {
776
- return false;
777
- }
778
-
779
-
780
- // add file
781
- self.parent.acf.fields.gallery.add( json );
782
-
783
- }
784
- });
785
-
786
- }
787
-
788
-
789
- })(jQuery);
790
- </script><?php
791
-
792
- }
793
-
794
- }
795
-
796
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/fields/image.php CHANGED
@@ -1,143 +1,53 @@
1
  <?php
2
 
3
- class acf_Image extends acf_Field
4
  {
5
 
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'image';
21
- $this->title = __('Image','acf');
 
22
 
 
 
 
 
 
 
 
23
  add_action('admin_head-media-upload-popup', array($this, 'popup_head'));
24
- add_filter('get_media_item_args', array($this, 'allow_img_insertion'));
25
- add_action('acf_head-update_attachment-image', array($this, 'acf_head_update_attachment'));
26
 
27
- add_action('wp_ajax_acf/fields/image/get_images', array($this, 'ajax_get_images'));
28
- //add_filter('image_size_names_choose', array($this, 'image_size_names_choose'));
29
  add_action('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
30
-
31
- }
32
-
33
-
34
- /*
35
- * acf_head_update_attachment
36
- *
37
- * @description:
38
- * @since: 3.2.7
39
- * @created: 4/07/12
40
- */
41
-
42
- function acf_head_update_attachment()
43
- {
44
- ?>
45
- <script type="text/javascript">
46
- (function($){
47
-
48
- // vars
49
- var div = self.parent.acf.media.div;
50
-
51
-
52
- // add message
53
- self.parent.acf.helpers.add_message("<?php _e("Image Updated.",'acf'); ?>", div);
54
-
55
-
56
- })(jQuery);
57
- </script>
58
- <?php
59
  }
60
 
61
 
62
  /*
63
- * ajax_get_images
64
- *
65
- * @description:
66
- * @since: 3.5.7
67
- * @created: 13/01/13
68
- */
69
-
70
- function ajax_get_images()
71
- {
72
- // vars
73
- $options = array(
74
- 'nonce' => '',
75
- 'images' => array(),
76
- 'preview_size' => 'thumbnail'
77
- );
78
- $return = array();
79
-
80
-
81
- // load post options
82
- $options = array_merge($options, $_POST);
83
-
84
-
85
- // verify nonce
86
- if( ! wp_verify_nonce($options['nonce'], 'acf_nonce') )
87
- {
88
- die(0);
89
- }
90
-
91
-
92
- if( $options['images'] )
93
- {
94
- foreach( $options['images'] as $id )
95
- {
96
- $src = wp_get_attachment_image_src( $id, $options['preview_size'] );
97
-
98
-
99
- $return[] = array(
100
- 'id' => $id,
101
- 'src' => $src[0],
102
- );
103
- }
104
- }
105
-
106
-
107
- // return json
108
- echo json_encode( $return );
109
- die;
110
-
111
- }
112
-
113
-
114
- /*--------------------------------------------------------------------------------------
115
  *
116
- * admin_print_scripts / admin_print_styles
117
  *
118
- * @author Elliot Condon
119
- * @since 3.0.1
120
- *
121
- *-------------------------------------------------------------------------------------*/
122
-
123
- function allow_img_insertion($vars)
124
- {
125
- $vars['send'] = true;
126
- return($vars);
127
- }
128
-
129
-
130
- /*--------------------------------------------------------------------------------------
131
- *
132
- * create_field
133
  *
134
- * @author Elliot Condon
135
- * @since 2.0.5
136
- * @updated 2.2.0
137
- *
138
- *-------------------------------------------------------------------------------------*/
139
 
140
- function create_field($field)
141
  {
142
  // vars
143
  $class = "";
@@ -176,18 +86,21 @@ class acf_Image extends acf_Field
176
  }
177
 
178
 
179
- /*--------------------------------------------------------------------------------------
 
180
  *
181
- * create_options
 
182
  *
183
- * @author Elliot Condon
184
- * @since 2.0.6
185
- * @updated 2.2.0
186
- *
187
- *-------------------------------------------------------------------------------------*/
188
-
189
- function create_options($key, $field)
190
- {
 
191
  // vars
192
  $defaults = array(
193
  'save_format' => 'id',
@@ -195,6 +108,7 @@ class acf_Image extends acf_Field
195
  );
196
 
197
  $field = array_merge($defaults, $field);
 
198
 
199
  ?>
200
  <tr class="field_option field_option_<?php echo $this->name; ?>">
@@ -224,24 +138,210 @@ class acf_Image extends acf_Field
224
  <td>
225
  <?php
226
 
227
- $image_sizes = $this->parent->get_all_image_sizes();
228
-
229
  do_action('acf/create_field', array(
230
  'type' => 'radio',
231
  'name' => 'fields['.$key.'][preview_size]',
232
  'value' => $field['preview_size'],
233
  'layout' => 'horizontal',
234
- 'choices' => $image_sizes
235
  ));
236
 
237
  ?>
238
  </td>
239
  </tr>
240
  <?php
 
241
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
 
 
 
 
 
 
243
 
244
  /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  * popup_head
246
  *
247
  * @description: css + js for thickbox
@@ -655,87 +755,6 @@ class acf_Image extends acf_Field
655
 
656
  }
657
 
658
-
659
- /*--------------------------------------------------------------------------------------
660
- *
661
- * get_value_for_api
662
- *
663
- * @author Elliot Condon
664
- * @since 3.0.0
665
- *
666
- *-------------------------------------------------------------------------------------*/
667
-
668
- function get_value_for_api($post_id, $field)
669
- {
670
- // vars
671
- $format = isset($field['save_format']) ? $field['save_format'] : 'url';
672
- $value = parent::get_value($post_id, $field);
673
-
674
-
675
- // validate
676
- if( !$value )
677
- {
678
- return false;
679
- }
680
-
681
-
682
- // format
683
- if($format == 'url')
684
- {
685
- $value = wp_get_attachment_url($value);
686
- }
687
- elseif($format == 'object')
688
- {
689
- $attachment = get_post( $value );
690
-
691
-
692
- // validate
693
- if( !$attachment )
694
- {
695
- return false;
696
- }
697
-
698
-
699
- // create array to hold value data
700
- $src = wp_get_attachment_image_src( $attachment->ID, 'full' );
701
-
702
- $value = array(
703
- 'id' => $attachment->ID,
704
- 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
705
- 'title' => $attachment->post_title,
706
- 'caption' => $attachment->post_excerpt,
707
- 'description' => $attachment->post_content,
708
- 'url' => $src[0],
709
- 'width' => $src[1],
710
- 'height' => $src[2],
711
- 'sizes' => array(),
712
- );
713
-
714
-
715
- // find all image sizes
716
- $image_sizes = get_intermediate_image_sizes();
717
-
718
- if( $image_sizes )
719
- {
720
- foreach( $image_sizes as $image_size )
721
- {
722
- // find src
723
- $src = wp_get_attachment_image_src( $attachment->ID, $image_size );
724
-
725
- // add src
726
- $value[ 'sizes' ][ $image_size ] = $src[0];
727
- $value[ 'sizes' ][ $image_size . '-width' ] = $src[1];
728
- $value[ 'sizes' ][ $image_size . '-height' ] = $src[2];
729
- }
730
- // foreach( $image_sizes as $image_size )
731
- }
732
- // if( $image_sizes )
733
-
734
- }
735
-
736
- return $value;
737
- }
738
-
739
 
740
  /*
741
  * image_size_names_choose
@@ -813,7 +832,8 @@ class acf_Image extends acf_Field
813
  return $response;
814
  }
815
 
816
-
817
  }
818
 
819
- ?>
 
 
1
  <?php
2
 
3
+ class acf_field_image extends acf_field
4
  {
5
 
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'image';
19
+ $this->label = __("Image",'acf');
20
+ $this->category = __("Content",'acf');
21
+
22
 
23
+ // do not delete!
24
+ parent::__construct();
25
+
26
+
27
+ // extra
28
+ add_filter('get_media_item_args', array($this, 'get_media_item_args'));
29
+ add_action('acf_head-update_attachment-' . $this->name, array($this, 'acf_head_update_attachment'));
30
  add_action('admin_head-media-upload-popup', array($this, 'popup_head'));
 
 
31
 
32
+ add_action('wp_ajax_acf/fields/image/get_images', array($this, 'ajax_get_images'), 10, 1);
33
+ add_action('wp_ajax_nopriv_acf/fields/image/get_images', array($this, 'ajax_get_images'), 10, 1);
34
  add_action('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  }
36
 
37
 
38
  /*
39
+ * create_field()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  *
41
+ * Create the HTML interface for your field
42
  *
43
+ * @param $field - an array holding all the field's data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  *
45
+ * @type action
46
+ * @since 3.6
47
+ * @date 23/01/13
48
+ */
 
49
 
50
+ function create_field( $field )
51
  {
52
  // vars
53
  $class = "";
86
  }
87
 
88
 
89
+ /*
90
+ * create_options()
91
  *
92
+ * Create extra options for your field. This is rendered when editing a field.
93
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
94
  *
95
+ * @type action
96
+ * @since 3.6
97
+ * @date 23/01/13
98
+ *
99
+ * @param $field - an array holding all the field's data
100
+ */
101
+
102
+ function create_options( $field )
103
+ {
104
  // vars
105
  $defaults = array(
106
  'save_format' => 'id',
108
  );
109
 
110
  $field = array_merge($defaults, $field);
111
+ $key = $field['name'];
112
 
113
  ?>
114
  <tr class="field_option field_option_<?php echo $this->name; ?>">
138
  <td>
139
  <?php
140
 
 
 
141
  do_action('acf/create_field', array(
142
  'type' => 'radio',
143
  'name' => 'fields['.$key.'][preview_size]',
144
  'value' => $field['preview_size'],
145
  'layout' => 'horizontal',
146
+ 'choices' => apply_filters('acf/get_image_sizes', array())
147
  ));
148
 
149
  ?>
150
  </td>
151
  </tr>
152
  <?php
153
+
154
  }
155
+
156
+
157
+ /*
158
+ * format_value_for_api()
159
+ *
160
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
161
+ *
162
+ * @type filter
163
+ * @since 3.6
164
+ * @date 23/01/13
165
+ *
166
+ * @param $value - the value which was loaded from the database
167
+ * @param $post_id - the $post_id from which the value was loaded
168
+ * @param $field - the field array holding all the field options
169
+ *
170
+ * @return $value - the modified value
171
+ */
172
+
173
+ function format_value_for_api( $value, $post_id, $field )
174
+ {
175
+ // vars
176
+ $defaults = array(
177
+ 'save_format' => 'url',
178
+ );
179
+
180
+ $field = array_merge($defaults, $field);
181
+
182
+
183
+ // validate
184
+ if( !$value )
185
+ {
186
+ return false;
187
+ }
188
+
189
+
190
+ // format
191
+ if( $field['save_format'] == 'url' )
192
+ {
193
+ $value = wp_get_attachment_url( $value );
194
+ }
195
+ elseif( $field['save_format'] == 'object' )
196
+ {
197
+ $attachment = get_post( $value );
198
+
199
+
200
+ // validate
201
+ if( !$attachment )
202
+ {
203
+ return false;
204
+ }
205
+
206
+
207
+ // create array to hold value data
208
+ $src = wp_get_attachment_image_src( $attachment->ID, 'full' );
209
+
210
+ $value = array(
211
+ 'id' => $attachment->ID,
212
+ 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
213
+ 'title' => $attachment->post_title,
214
+ 'caption' => $attachment->post_excerpt,
215
+ 'description' => $attachment->post_content,
216
+ 'url' => $src[0],
217
+ 'width' => $src[1],
218
+ 'height' => $src[2],
219
+ 'sizes' => array(),
220
+ );
221
+
222
+
223
+ // find all image sizes
224
+ $image_sizes = get_intermediate_image_sizes();
225
+
226
+ if( $image_sizes )
227
+ {
228
+ foreach( $image_sizes as $image_size )
229
+ {
230
+ // find src
231
+ $src = wp_get_attachment_image_src( $attachment->ID, $image_size );
232
+
233
+ // add src
234
+ $value[ 'sizes' ][ $image_size ] = $src[0];
235
+ $value[ 'sizes' ][ $image_size . '-width' ] = $src[1];
236
+ $value[ 'sizes' ][ $image_size . '-height' ] = $src[2];
237
+ }
238
+ // foreach( $image_sizes as $image_size )
239
+ }
240
+ // if( $image_sizes )
241
+
242
+ }
243
+
244
+ return $value;
245
+
246
+ }
247
+
248
+
249
+ /*
250
+ * get_media_item_args
251
+ *
252
+ * @description:
253
+ * @since: 3.6
254
+ * @created: 27/01/13
255
+ */
256
+
257
+ function get_media_item_args( $vars )
258
+ {
259
+ $vars['send'] = true;
260
+ return($vars);
261
+ }
262
+
263
+
264
+ /*
265
+ * acf_head_update_attachment
266
+ *
267
+ * @description:
268
+ * @since: 3.2.7
269
+ * @created: 4/07/12
270
+ */
271
+
272
+ function acf_head_update_attachment()
273
+ {
274
+ ?>
275
+ <script type="text/javascript">
276
+ (function($){
277
+
278
+ // vars
279
+ var div = self.parent.acf.media.div;
280
+
281
+
282
+ // add message
283
+ self.parent.acf.helpers.add_message("<?php _e("Image Updated.",'acf'); ?>", div);
284
+
285
 
286
+ })(jQuery);
287
+ </script>
288
+ <?php
289
+ }
290
+
291
 
292
  /*
293
+ * ajax_get_images
294
+ *
295
+ * @description:
296
+ * @since: 3.5.7
297
+ * @created: 13/01/13
298
+ */
299
+
300
+ function ajax_get_images()
301
+ {
302
+ // vars
303
+ $options = array(
304
+ 'nonce' => '',
305
+ 'images' => array(),
306
+ 'preview_size' => 'thumbnail'
307
+ );
308
+ $return = array();
309
+
310
+
311
+ // load post options
312
+ $options = array_merge($options, $_POST);
313
+
314
+
315
+ // verify nonce
316
+ if( ! wp_verify_nonce($options['nonce'], 'acf_nonce') )
317
+ {
318
+ die(0);
319
+ }
320
+
321
+
322
+ if( $options['images'] )
323
+ {
324
+ foreach( $options['images'] as $id )
325
+ {
326
+ $src = wp_get_attachment_image_src( $id, $options['preview_size'] );
327
+
328
+
329
+ $return[] = array(
330
+ 'id' => $id,
331
+ 'src' => $src[0],
332
+ );
333
+ }
334
+ }
335
+
336
+
337
+ // return json
338
+ echo json_encode( $return );
339
+ die;
340
+
341
+ }
342
+
343
+
344
+ /*
345
  * popup_head
346
  *
347
  * @description: css + js for thickbox
755
 
756
  }
757
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
758
 
759
  /*
760
  * image_size_names_choose
832
  return $response;
833
  }
834
 
 
835
  }
836
 
837
+ new acf_field_image();
838
+
839
+ ?>
core/fields/message.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class acf_field_message extends acf_field
4
+ {
5
+
6
+ /*
7
+ * __construct
8
+ *
9
+ * Set name / label needed for actions / filters
10
+ *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
14
+
15
+ function __construct()
16
+ {
17
+ // vars
18
+ $this->name = 'message';
19
+ $this->label = __("Message",'acf');
20
+ $this->category = __("Layout",'acf');
21
+
22
+ // do not delete!
23
+ parent::__construct();
24
+ }
25
+
26
+
27
+ /*
28
+ * create_field()
29
+ *
30
+ * Create the HTML interface for your field
31
+ *
32
+ * @param $field - an array holding all the field's data
33
+ *
34
+ * @type action
35
+ * @since 3.6
36
+ * @date 23/01/13
37
+ */
38
+
39
+ function create_field( $field )
40
+ {
41
+ echo wpautop( $field['message'] );
42
+ }
43
+
44
+
45
+ /*
46
+ * create_options()
47
+ *
48
+ * Create extra options for your field. This is rendered when editing a field.
49
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
50
+ *
51
+ * @param $field - an array holding all the field's data
52
+ *
53
+ * @type action
54
+ * @since 3.6
55
+ * @date 23/01/13
56
+ */
57
+
58
+ function create_options( $field )
59
+ {
60
+ // vars
61
+ $defaults = array(
62
+ 'message' => '',
63
+ );
64
+
65
+ $field = array_merge($defaults, $field);
66
+ $key = $field['name'];
67
+
68
+ ?>
69
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
70
+ <td class="label">
71
+ <label for=""><?php _e("Message",'acf'); ?></label>
72
+ <p class="description"><?php _e("Text &amp; HTML entered here will appear inline with the fields",'acf'); ?><br /><br />
73
+ <?php _e("Please note that all text will first be passed through the wp function ",'acf'); ?><a href="http://codex.wordpress.org/Function_Reference/wpautop" target="_blank">wpautop</a></p>
74
+ </td>
75
+ <td>
76
+ <?php
77
+ do_action('acf/create_field', array(
78
+ 'type' => 'textarea',
79
+ 'class' => 'textarea',
80
+ 'name' => 'fields['.$key.'][message]',
81
+ 'value' => $field['message'],
82
+ ));
83
+ ?>
84
+ </td>
85
+ </tr>
86
+ <?php
87
+
88
+ }
89
+
90
+ }
91
+
92
+ new acf_field_message();
93
+
94
+ ?>
core/fields/number.php CHANGED
@@ -1,55 +1,61 @@
1
  <?php
2
 
3
- class acf_Number extends acf_Field
4
  {
5
 
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'number';
21
- $this->title = __("Number",'acf');
22
 
23
- }
24
-
25
-
26
- /*--------------------------------------------------------------------------------------
 
 
 
 
27
  *
28
- * create_field
29
  *
30
- * @author Elliot Condon
31
- * @since 2.0.5
32
- * @updated 2.2.0
33
- *
34
- *-------------------------------------------------------------------------------------*/
 
35
 
36
- function create_field($field)
37
  {
38
- echo '<input type="number" step="any" value="' . $field['value'] . '" id="' . $field['id'] . '" class="' . $field['class'] . '" name="' . $field['name'] . '" />';
39
  }
40
 
41
 
42
- /*--------------------------------------------------------------------------------------
 
 
 
 
43
  *
44
- * create_options
 
 
45
  *
46
- * @author Elliot Condon
47
- * @since 2.0.6
48
- * @updated 2.2.0
49
- *
50
- *-------------------------------------------------------------------------------------*/
51
 
52
- function create_options($key, $field)
53
  {
54
  // vars
55
  $defaults = array(
@@ -57,7 +63,7 @@ class acf_Number extends acf_Field
57
  );
58
 
59
  $field = array_merge($defaults, $field);
60
-
61
 
62
  ?>
63
  <tr class="field_option field_option_<?php echo $this->name; ?>">
@@ -79,16 +85,24 @@ class acf_Number extends acf_Field
79
  <?php
80
  }
81
 
82
- /*--------------------------------------------------------------------------------------
 
 
 
 
 
 
 
 
83
  *
84
- * update_value
 
 
85
  *
86
- * @author Elliot Condon
87
- * @since 2.2.0
88
- *
89
- *-------------------------------------------------------------------------------------*/
90
 
91
- function update_value($post_id, $field, $value)
92
  {
93
  // remove ','
94
  $value = str_replace(',', '', $value);
@@ -102,11 +116,12 @@ class acf_Number extends acf_Field
102
  $value = (string) $value;
103
 
104
 
105
- // update value
106
- parent::update_value($post_id, $field, $value);
107
-
108
  }
109
 
 
110
  }
111
 
 
 
112
  ?>
1
  <?php
2
 
3
+ class acf_field_number extends acf_field
4
  {
5
 
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'number';
19
+ $this->label = __("Number",'acf');
 
20
 
21
+
22
+ // do not delete!
23
+ parent::__construct();
24
+ }
25
+
26
+
27
+ /*
28
+ * create_field()
29
  *
30
+ * Create the HTML interface for your field
31
  *
32
+ * @param $field - an array holding all the field's data
33
+ *
34
+ * @type action
35
+ * @since 3.6
36
+ * @date 23/01/13
37
+ */
38
 
39
+ function create_field( $field )
40
  {
41
+ echo '<input type="number" step="any" value="' . esc_attr( $field['value'] ) . '" id="' . esc_attr( $field['id'] ) . '" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" />';
42
  }
43
 
44
 
45
+ /*
46
+ * create_options()
47
+ *
48
+ * Create extra options for your field. This is rendered when editing a field.
49
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
50
  *
51
+ * @type action
52
+ * @since 3.6
53
+ * @date 23/01/13
54
  *
55
+ * @param $field - an array holding all the field's data
56
+ */
 
 
 
57
 
58
+ function create_options( $field )
59
  {
60
  // vars
61
  $defaults = array(
63
  );
64
 
65
  $field = array_merge($defaults, $field);
66
+ $key = $field['name'];
67
 
68
  ?>
69
  <tr class="field_option field_option_<?php echo $this->name; ?>">
85
  <?php
86
  }
87
 
88
+
89
+ /*
90
+ * update_value()
91
+ *
92
+ * This filter is appied to the $value before it is updated in the db
93
+ *
94
+ * @type filter
95
+ * @since 3.6
96
+ * @date 23/01/13
97
  *
98
+ * @param $value - the value which will be saved in the database
99
+ * @param $field - the field array holding all the field options
100
+ * @param $post_id - the $post_id of which the value will be saved
101
  *
102
+ * @return $value - the modified value
103
+ */
 
 
104
 
105
+ function update_value( $value, $post_id, $field )
106
  {
107
  // remove ','
108
  $value = str_replace(',', '', $value);
116
  $value = (string) $value;
117
 
118
 
119
+ return $value;
 
 
120
  }
121
 
122
+
123
  }
124
 
125
+ new acf_field_number();
126
+
127
  ?>
core/fields/page_link.php CHANGED
@@ -1,60 +1,67 @@
1
  <?php
2
 
3
- class acf_Page_link extends acf_Field
4
  {
5
 
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'page_link';
21
- $this->title = __('Page Link','acf');
22
 
23
- }
24
-
 
 
 
25
 
26
- /*--------------------------------------------------------------------------------------
 
 
 
 
27
  *
28
- * create_field
29
  *
30
- * @author Elliot Condon
31
- * @since 2.0.5
32
- * @updated 2.2.0
33
- *
34
- *-------------------------------------------------------------------------------------*/
35
 
36
- function create_field($field)
37
  {
38
  // let post_object create the field
39
  $field['type'] = 'post_object';
40
 
41
  do_action('acf/create_field', $field );
42
-
43
  }
44
 
45
-
46
- /*--------------------------------------------------------------------------------------
 
 
 
 
47
  *
48
- * create_options
 
 
49
  *
50
- * @author Elliot Condon
51
- * @since 2.0.6
52
- * @updated 2.2.0
53
- *
54
- *-------------------------------------------------------------------------------------*/
55
 
56
- function create_options($key, $field)
57
- {
58
  // defaults
59
  $defaults = array(
60
  'post_type' => '',
@@ -63,107 +70,113 @@ class acf_Page_link extends acf_Field
63
  );
64
 
65
  $field = array_merge($defaults, $field);
66
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  ?>
68
- <tr class="field_option field_option_<?php echo $this->name; ?>">
69
- <td class="label">
70
- <label for=""><?php _e("Post Type",'acf'); ?></label>
71
- </td>
72
- <td>
73
- <?php
74
-
75
- $choices = array(
76
- '' => __("All",'acf')
77
- );
78
- $choices = array_merge( $choices, $this->parent->get_post_types() );
79
-
80
-
81
- do_action('acf/create_field', array(
82
- 'type' => 'select',
83
- 'name' => 'fields['.$key.'][post_type]',
84
- 'value' => $field['post_type'],
85
- 'choices' => $choices,
86
- 'multiple' => 1,
87
- ));
88
-
89
- ?>
90
- </td>
91
- </tr>
92
- <tr class="field_option field_option_<?php echo $this->name; ?>">
93
- <td class="label">
94
- <label><?php _e("Allow Null?",'acf'); ?></label>
95
- </td>
96
- <td>
97
- <?php
98
-
99
- do_action('acf/create_field', array(
100
- 'type' => 'radio',
101
- 'name' => 'fields['.$key.'][allow_null]',
102
- 'value' => $field['allow_null'],
103
- 'choices' => array(
104
- 1 => __("Yes",'acf'),
105
- 0 => __("No",'acf'),
106
- ),
107
- 'layout' => 'horizontal',
108
- ));
109
-
110
- ?>
111
- </td>
112
- </tr>
113
- <tr class="field_option field_option_<?php echo $this->name; ?>">
114
- <td class="label">
115
- <label><?php _e("Select multiple values?",'acf'); ?></label>
116
- </td>
117
- <td>
118
- <?php
119
-
120
- do_action('acf/create_field', array(
121
- 'type' => 'radio',
122
- 'name' => 'fields['.$key.'][multiple]',
123
- 'value' => $field['multiple'],
124
- 'choices' => array(
125
- 1 => __("Yes",'acf'),
126
- 0 => __("No",'acf'),
127
- ),
128
- 'layout' => 'horizontal',
129
- ));
130
-
131
- ?>
132
- </td>
133
- </tr>
134
  <?php
 
135
  }
136
 
137
 
138
- /*--------------------------------------------------------------------------------------
 
 
 
 
 
 
 
139
  *
140
- * get_value_for_api
 
 
141
  *
142
- * @author Elliot Condon
143
- * @since 3.0.0
144
- *
145
- *-------------------------------------------------------------------------------------*/
146
 
147
- function get_value_for_api($post_id, $field)
148
  {
149
- // get value
150
- $value = parent::get_value($post_id, $field);
151
-
152
- if(!$value)
153
  {
154
  return false;
155
  }
156
 
157
- if($value == 'null')
158
  {
159
  return false;
160
  }
161
 
162
- if(is_array($value))
163
  {
164
- foreach($value as $k => $v)
165
  {
166
- $value[$k] = get_permalink($v);
167
  }
168
  }
169
  else
@@ -174,8 +187,8 @@ class acf_Page_link extends acf_Field
174
  return $value;
175
  }
176
 
177
-
178
-
179
  }
180
 
 
 
181
  ?>
1
  <?php
2
 
3
+ class acf_field_page_link extends acf_field
4
  {
5
 
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'page_link';
19
+ $this->label = __("Page Link",'acf');
20
+ $this->category = __("Relational",'acf');
21
 
22
+
23
+ // do not delete!
24
+ parent::__construct();
25
+
26
+ }
27
 
28
+
29
+ /*
30
+ * create_field()
31
+ *
32
+ * Create the HTML interface for your field
33
  *
34
+ * @param $field - an array holding all the field's data
35
  *
36
+ * @type action
37
+ * @since 3.6
38
+ * @date 23/01/13
39
+ */
 
40
 
41
+ function create_field( $field )
42
  {
43
  // let post_object create the field
44
  $field['type'] = 'post_object';
45
 
46
  do_action('acf/create_field', $field );
 
47
  }
48
 
49
+
50
+ /*
51
+ * create_options()
52
+ *
53
+ * Create extra options for your field. This is rendered when editing a field.
54
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
55
  *
56
+ * @type action
57
+ * @since 3.6
58
+ * @date 23/01/13
59
  *
60
+ * @param $field - an array holding all the field's data
61
+ */
 
 
 
62
 
63
+ function create_options( $field )
64
+ {
65
  // defaults
66
  $defaults = array(
67
  'post_type' => '',
70
  );
71
 
72
  $field = array_merge($defaults, $field);
73
+ $key = $field['name'];
74
+
75
+ ?>
76
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
77
+ <td class="label">
78
+ <label for=""><?php _e("Post Type",'acf'); ?></label>
79
+ </td>
80
+ <td>
81
+ <?php
82
+
83
+ $choices = array(
84
+ '' => __("All",'acf')
85
+ );
86
+ $choices = apply_filters('acf/get_post_types', $choices);
87
+
88
+
89
+ do_action('acf/create_field', array(
90
+ 'type' => 'select',
91
+ 'name' => 'fields['.$key.'][post_type]',
92
+ 'value' => $field['post_type'],
93
+ 'choices' => $choices,
94
+ 'multiple' => 1,
95
+ ));
96
+
97
+ ?>
98
+ </td>
99
+ </tr>
100
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
101
+ <td class="label">
102
+ <label><?php _e("Allow Null?",'acf'); ?></label>
103
+ </td>
104
+ <td>
105
+ <?php
106
+
107
+ do_action('acf/create_field', array(
108
+ 'type' => 'radio',
109
+ 'name' => 'fields['.$key.'][allow_null]',
110
+ 'value' => $field['allow_null'],
111
+ 'choices' => array(
112
+ 1 => __("Yes",'acf'),
113
+ 0 => __("No",'acf'),
114
+ ),
115
+ 'layout' => 'horizontal',
116
+ ));
117
+
118
+ ?>
119
+ </td>
120
+ </tr>
121
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
122
+ <td class="label">
123
+ <label><?php _e("Select multiple values?",'acf'); ?></label>
124
+ </td>
125
+ <td>
126
+ <?php
127
+
128
+ do_action('acf/create_field', array(
129
+ 'type' => 'radio',
130
+ 'name' => 'fields['.$key.'][multiple]',
131
+ 'value' => $field['multiple'],
132
+ 'choices' => array(
133
+ 1 => __("Yes",'acf'),
134
+ 0 => __("No",'acf'),
135
+ ),
136
+ 'layout' => 'horizontal',
137
+ ));
138
+
139
  ?>
140
+ </td>
141
+ </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  <?php
143
+
144
  }
145
 
146
 
147
+ /*
148
+ * format_value_for_api()
149
+ *
150
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
151
+ *
152
+ * @type filter
153
+ * @since 3.6
154
+ * @date 23/01/13
155
  *
156
+ * @param $value - the value which was loaded from the database
157
+ * @param $post_id - the $post_id from which the value was loaded
158
+ * @param $field - the field array holding all the field options
159
  *
160
+ * @return $value - the modified value
161
+ */
 
 
162
 
163
+ function format_value_for_api( $value, $post_id, $field )
164
  {
165
+ if( !$value )
 
 
 
166
  {
167
  return false;
168
  }
169
 
170
+ if( $value == 'null' )
171
  {
172
  return false;
173
  }
174
 
175
+ if( is_array($value) )
176
  {
177
+ foreach( $value as $k => $v )
178
  {
179
+ $value[ $k ] = get_permalink($v);
180
  }
181
  }
182
  else
187
  return $value;
188
  }
189
 
 
 
190
  }
191
 
192
+ new acf_field_page_link();
193
+
194
  ?>
core/fields/password.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class acf_field_password extends acf_field
4
+ {
5
+
6
+ /*
7
+ * __construct
8
+ *
9
+ * Set name / label needed for actions / filters
10
+ *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
14
+
15
+ function __construct()
16
+ {
17
+ // vars
18
+ $this->name = 'password';
19
+ $this->label = __("Password",'acf');
20
+
21
+
22
+ // do not delete!
23
+ parent::__construct();
24
+ }
25
+
26
+
27
+ /*
28
+ * create_field()
29
+ *
30
+ * Create the HTML interface for your field
31
+ *
32
+ * @param $field - an array holding all the field's data
33
+ *
34
+ * @type action
35
+ * @since 3.6
36
+ * @date 23/01/13
37
+ */
38
+
39
+ function create_field( $field )
40
+ {
41
+ echo '<input type="password" value="' . esc_attr( $field['value'] ) . '" id="' . esc_attr( $field['id'] ) . '" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" />';
42
+ }
43
+
44
+ }
45
+
46
+ new acf_field_password();
47
+
48
+ ?>
core/fields/post_object.php CHANGED
@@ -1,39 +1,44 @@
1
  <?php
2
 
3
- class acf_Post_object extends acf_Field
4
  {
5
 
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'post_object';
21
- $this->title = __("Post Object",'acf');
22
-
23
- }
24
-
25
-
26
- /*--------------------------------------------------------------------------------------
 
 
 
 
 
 
 
27
  *
28
- * create_field
29
  *
30
- * @author Elliot Condon
31
- * @since 2.0.5
32
- * @updated 2.2.0
33
- *
34
- *-------------------------------------------------------------------------------------*/
35
 
36
- function create_field($field)
37
  {
38
  // vars
39
  $args = array(
@@ -65,7 +70,7 @@ class acf_Post_object extends acf_Field
65
  // load all post types by default
66
  if( !$field['post_type'] || !is_array($field['post_type']) || $field['post_type'][0] == "" )
67
  {
68
- $field['post_type'] = $this->parent->get_post_types();
69
  }
70
 
71
 
@@ -190,24 +195,25 @@ class acf_Post_object extends acf_Field
190
 
191
  // create field
192
  do_action('acf/create_field', $field );
193
-
194
-
195
  }
196
 
197
 
198
- /*--------------------------------------------------------------------------------------
 
 
 
 
199
  *
200
- * create_options
 
 
201
  *
202
- * @author Elliot Condon
203
- * @since 2.0.6
204
- * @updated 2.2.0
205
- *
206
- *-------------------------------------------------------------------------------------*/
207
 
208
- function create_options($key, $field)
209
- {
210
- // defaults
211
  $defaults = array(
212
  'post_type' => '',
213
  'multiple' => 0,
@@ -216,118 +222,124 @@ class acf_Post_object extends acf_Field
216
  );
217
 
218
  $field = array_merge($defaults, $field);
219
-
 
220
  ?>
221
- <tr class="field_option field_option_<?php echo $this->name; ?>">
222
- <td class="label">
223
- <label for=""><?php _e("Post Type",'acf'); ?></label>
224
- </td>
225
- <td>
226
- <?php
227
-
228
- $choices = array(
229
- '' => __("All",'acf')
230
- );
231
- $choices = array_merge( $choices, $this->parent->get_post_types() );
232
-
233
-
234
- do_action('acf/create_field', array(
235
- 'type' => 'select',
236
- 'name' => 'fields['.$key.'][post_type]',
237
- 'value' => $field['post_type'],
238
- 'choices' => $choices,
239
- 'multiple' => 1,
240
- ));
241
-
242
- ?>
243
- </td>
244
- </tr>
245
- <tr class="field_option field_option_<?php echo $this->name; ?>">
246
- <td class="label">
247
- <label><?php _e("Filter from Taxonomy",'acf'); ?></label>
248
- </td>
249
- <td>
250
- <?php
251
- $choices = array(
252
- '' => array(
253
- 'all' => __("All",'acf')
254
- )
255
- );
256
- $choices = array_merge($choices, $this->parent->get_taxonomies_for_select());
257
-
258
- do_action('acf/create_field', array(
259
- 'type' => 'select',
260
- 'name' => 'fields['.$key.'][taxonomy]',
261
- 'value' => $field['taxonomy'],
262
- 'choices' => $choices,
263
- 'optgroup' => true,
264
- 'multiple' => 1,
265
- ));
266
-
267
- ?>
268
- </td>
269
- </tr>
270
- <tr class="field_option field_option_<?php echo $this->name; ?>">
271
- <td class="label">
272
- <label><?php _e("Allow Null?",'acf'); ?></label>
273
- </td>
274
- <td>
275
- <?php
276
-
277
- do_action('acf/create_field', array(
278
- 'type' => 'radio',
279
- 'name' => 'fields['.$key.'][allow_null]',
280
- 'value' => $field['allow_null'],
281
- 'choices' => array(
282
- 1 => __("Yes",'acf'),
283
- 0 => __("No",'acf'),
284
- ),
285
- 'layout' => 'horizontal',
286
- ));
287
-
288
- ?>
289
- </td>
290
- </tr>
291
- <tr class="field_option field_option_<?php echo $this->name; ?>">
292
- <td class="label">
293
- <label><?php _e("Select multiple values?",'acf'); ?></label>
294
- </td>
295
- <td>
296
- <?php
297
-
298
- do_action('acf/create_field', array(
299
- 'type' => 'radio',
300
- 'name' => 'fields['.$key.'][multiple]',
301
- 'value' => $field['multiple'],
302
- 'choices' => array(
303
- 1 => __("Yes",'acf'),
304
- 0 => __("No",'acf'),
305
- ),
306
- 'layout' => 'horizontal',
307
- ));
308
-
309
- ?>
310
- </td>
311
- </tr>
312
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  }
314
 
315
 
316
- /*--------------------------------------------------------------------------------------
 
 
 
317
  *
318
- * get_value_for_api
 
 
319
  *
320
- * @author Elliot Condon
321
- * @since 3.0.0
322
- *
323
- *-------------------------------------------------------------------------------------*/
 
 
324
 
325
- function get_value_for_api($post_id, $field)
326
  {
327
- // get value
328
- $value = parent::get_value($post_id, $field);
329
-
330
-
331
  // no value?
332
  if( !$value )
333
  {
@@ -349,7 +361,7 @@ class acf_Post_object extends acf_Field
349
  $posts = get_posts(array(
350
  'numberposts' => -1,
351
  'post__in' => $value,
352
- 'post_type' => $this->parent->get_post_types(),
353
  'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
354
  ));
355
 
@@ -386,7 +398,9 @@ class acf_Post_object extends acf_Field
386
  // return the value
387
  return $value;
388
  }
389
-
390
  }
391
 
 
 
392
  ?>
1
  <?php
2
 
3
+ class acf_field_post_object extends acf_field
4
  {
5
 
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'post_object';
19
+ $this->label = __("Post Object",'acf');
20
+ $this->category = __("Relational",'acf');
21
+
22
+
23
+ // do not delete!
24
+ parent::__construct();
25
+
26
+ }
27
+
28
+
29
+ /*
30
+ * create_field()
31
+ *
32
+ * Create the HTML interface for your field
33
  *
34
+ * @param $field - an array holding all the field's data
35
  *
36
+ * @type action
37
+ * @since 3.6
38
+ * @date 23/01/13
39
+ */
 
40
 
41
+ function create_field( $field )
42
  {
43
  // vars
44
  $args = array(
70
  // load all post types by default
71
  if( !$field['post_type'] || !is_array($field['post_type']) || $field['post_type'][0] == "" )
72
  {
73
+ $field['post_type'] = apply_filters('acf/get_post_types', array());
74
  }
75
 
76
 
195
 
196
  // create field
197
  do_action('acf/create_field', $field );
 
 
198
  }
199
 
200
 
201
+ /*
202
+ * create_options()
203
+ *
204
+ * Create extra options for your field. This is rendered when editing a field.
205
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
206
  *
207
+ * @type action
208
+ * @since 3.6
209
+ * @date 23/01/13
210
  *
211
+ * @param $field - an array holding all the field's data
212
+ */
 
 
 
213
 
214
+ function create_options( $field )
215
+ {
216
+ // vars
217
  $defaults = array(
218
  'post_type' => '',
219
  'multiple' => 0,
222
  );
223
 
224
  $field = array_merge($defaults, $field);
225
+ $key = $field['name'];
226
+
227
  ?>
228
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
229
+ <td class="label">
230
+ <label for=""><?php _e("Post Type",'acf'); ?></label>
231
+ </td>
232
+ <td>
233
+ <?php
234
+
235
+ $choices = array(
236
+ '' => __("All",'acf')
237
+ );
238
+ $choices = apply_filters('acf/get_post_types', $choices);
239
+
240
+
241
+ do_action('acf/create_field', array(
242
+ 'type' => 'select',
243
+ 'name' => 'fields['.$key.'][post_type]',
244
+ 'value' => $field['post_type'],
245
+ 'choices' => $choices,
246
+ 'multiple' => 1,
247
+ ));
248
+
249
+ ?>
250
+ </td>
251
+ </tr>
252
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
253
+ <td class="label">
254
+ <label><?php _e("Filter from Taxonomy",'acf'); ?></label>
255
+ </td>
256
+ <td>
257
+ <?php
258
+ $choices = array(
259
+ '' => array(
260
+ 'all' => __("All",'acf')
261
+ )
262
+ );
263
+ $simple_value = false;
264
+ $choices = apply_filters('acf/get_taxonomies_for_select', $choices, $simple_value);
265
+
266
+ do_action('acf/create_field', array(
267
+ 'type' => 'select',
268
+ 'name' => 'fields['.$key.'][taxonomy]',
269
+ 'value' => $field['taxonomy'],
270
+ 'choices' => $choices,
271
+ 'optgroup' => true,
272
+ 'multiple' => 1,
273
+ ));
274
+
275
+ ?>
276
+ </td>
277
+ </tr>
278
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
279
+ <td class="label">
280
+ <label><?php _e("Allow Null?",'acf'); ?></label>
281
+ </td>
282
+ <td>
283
+ <?php
284
+
285
+ do_action('acf/create_field', array(
286
+ 'type' => 'radio',
287
+ 'name' => 'fields['.$key.'][allow_null]',
288
+ 'value' => $field['allow_null'],
289
+ 'choices' => array(
290
+ 1 => __("Yes",'acf'),
291
+ 0 => __("No",'acf'),
292
+ ),
293
+ 'layout' => 'horizontal',
294
+ ));
295
+
296
+ ?>
297
+ </td>
298
+ </tr>
299
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
300
+ <td class="label">
301
+ <label><?php _e("Select multiple values?",'acf'); ?></label>
302
+ </td>
303
+ <td>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
  <?php
305
+
306
+ do_action('acf/create_field', array(
307
+ 'type' => 'radio',
308
+ 'name' => 'fields['.$key.'][multiple]',
309
+ 'value' => $field['multiple'],
310
+ 'choices' => array(
311
+ 1 => __("Yes",'acf'),
312
+ 0 => __("No",'acf'),
313
+ ),
314
+ 'layout' => 'horizontal',
315
+ ));
316
+
317
+ ?>
318
+ </td>
319
+ </tr>
320
+ <?php
321
+
322
  }
323
 
324
 
325
+ /*
326
+ * format_value_for_api()
327
+ *
328
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
329
  *
330
+ * @type filter
331
+ * @since 3.6
332
+ * @date 23/01/13
333
  *
334
+ * @param $value - the value which was loaded from the database
335
+ * @param $post_id - the $post_id from which the value was loaded
336
+ * @param $field - the field array holding all the field options
337
+ *
338
+ * @return $value - the modified value
339
+ */
340
 
341
+ function format_value_for_api( $value, $post_id, $field )
342
  {
 
 
 
 
343
  // no value?
344
  if( !$value )
345
  {
361
  $posts = get_posts(array(
362
  'numberposts' => -1,
363
  'post__in' => $value,
364
+ 'post_type' => apply_filters('acf/get_post_types', array()),
365
  'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
366
  ));
367
 
398
  // return the value
399
  return $value;
400
  }
401
+
402
  }
403
 
404
+ new acf_field_post_object();
405
+
406
  ?>
core/fields/radio.php CHANGED
@@ -1,39 +1,44 @@
1
  <?php
2
 
3
- class acf_Radio extends acf_Field
4
  {
5
 
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'radio';
21
- $this->title = __('Radio Button','acf');
 
22
 
23
- }
24
-
25
-
26
- /*--------------------------------------------------------------------------------------
 
 
 
 
 
 
27
  *
28
- * create_field
29
  *
30
- * @author Elliot Condon
31
- * @since 2.0.5
32
- * @updated 2.2.0
33
- *
34
- *-------------------------------------------------------------------------------------*/
35
 
36
- function create_field($field)
37
  {
38
  // vars
39
  $defaults = array(
@@ -44,54 +49,51 @@ class acf_Radio extends acf_Field
44
  $field = array_merge($defaults, $field);
45
 
46
 
47
- // no choices
48
- if( empty($field['choices']) )
49
- {
50
- echo '<p>' . __("No choices to choose from",'acf') . '</p>';
51
- return false;
52
- }
53
-
54
-
55
  echo '<ul class="radio_list ' . $field['class'] . ' ' . $field['layout'] . '">';
56
 
57
  $i = 0;
58
- foreach($field['choices'] as $key => $value)
59
  {
60
- $i++;
61
-
62
- // if there is no value and this is the first of the choices and there is no "0" choice, select this on by default
63
- // the 0 choice would normally match a no value. This needs to remain possible for the create new field to work.
64
- if(!$field['value'] && $i == 1 && !isset($field['choices'][0]))
65
  {
66
- $field['value'] = $key;
67
- }
68
-
69
- $selected = '';
70
-
71
- if($key == $field['value'])
72
- {
73
- $selected = 'checked="checked" data-checked="checked"';
 
 
 
 
 
 
 
 
 
74
  }
75
-
76
- echo '<li><label><input id="' . $field['id'] . '-' . $key . '" type="radio" name="' . $field['name'] . '" value="' . $key . '" ' . $selected . ' />' . $value . '</label></li>';
77
  }
78
 
79
  echo '</ul>';
80
-
81
  }
82
-
83
-
84
- /*--------------------------------------------------------------------------------------
 
85
  *
86
- * create_options
 
87
  *
88
- * @author Elliot Condon
89
- * @since 2.0.6
90
- * @updated 2.2.0
91
- *
92
- *-------------------------------------------------------------------------------------*/
 
93
 
94
- function create_options($key, $field)
95
  {
96
  // vars
97
  $defaults = array(
@@ -101,7 +103,7 @@ class acf_Radio extends acf_Field
101
  );
102
 
103
  $field = array_merge($defaults, $field);
104
-
105
 
106
  // implode checkboxes so they work in a textarea
107
  if( is_array($field['choices']) )
@@ -177,10 +179,11 @@ class acf_Radio extends acf_Field
177
  </td>
178
  </tr>
179
  <?php
 
180
  }
181
-
182
-
183
 
184
  }
185
 
 
 
186
  ?>
1
  <?php
2
 
3
+ class acf_field_radio extends acf_field
4
  {
5
 
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'radio';
19
+ $this->label = __("Radio Button",'acf');
20
+ $this->category = __("Choice",'acf');
21
+
22
 
23
+ // do not delete!
24
+ parent::__construct();
25
+
26
+ }
27
+
28
+
29
+ /*
30
+ * create_field()
31
+ *
32
+ * Create the HTML interface for your field
33
  *
34
+ * @param $field - an array holding all the field's data
35
  *
36
+ * @type action
37
+ * @since 3.6
38
+ * @date 23/01/13
39
+ */
 
40
 
41
+ function create_field( $field )
42
  {
43
  // vars
44
  $defaults = array(
49
  $field = array_merge($defaults, $field);
50
 
51
 
 
 
 
 
 
 
 
 
52
  echo '<ul class="radio_list ' . $field['class'] . ' ' . $field['layout'] . '">';
53
 
54
  $i = 0;
55
+ if( $field['choices'] )
56
  {
57
+ foreach($field['choices'] as $key => $value)
 
 
 
 
58
  {
59
+ $i++;
60
+
61
+ // if there is no value and this is the first of the choices and there is no "0" choice, select this on by default
62
+ // the 0 choice would normally match a no value. This needs to remain possible for the create new field to work.
63
+ if(!$field['value'] && $i == 1 && !isset($field['choices'][0]))
64
+ {
65
+ $field['value'] = $key;
66
+ }
67
+
68
+ $selected = '';
69
+
70
+ if($key == $field['value'])
71
+ {
72
+ $selected = 'checked="checked" data-checked="checked"';
73
+ }
74
+
75
+ echo '<li><label><input id="' . $field['id'] . '-' . $key . '" type="radio" name="' . $field['name'] . '" value="' . $key . '" ' . $selected . ' />' . $value . '</label></li>';
76
  }
 
 
77
  }
78
 
79
  echo '</ul>';
 
80
  }
81
+
82
+
83
+ /*
84
+ * create_options()
85
  *
86
+ * Create extra options for your field. This is rendered when editing a field.
87
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
88
  *
89
+ * @type action
90
+ * @since 3.6
91
+ * @date 23/01/13
92
+ *
93
+ * @param $field - an array holding all the field's data
94
+ */
95
 
96
+ function create_options( $field )
97
  {
98
  // vars
99
  $defaults = array(
103
  );
104
 
105
  $field = array_merge($defaults, $field);
106
+ $key = $field['name'];
107
 
108
  // implode checkboxes so they work in a textarea
109
  if( is_array($field['choices']) )
179
  </td>
180
  </tr>
181
  <?php
182
+
183
  }
 
 
184
 
185
  }
186
 
187
+ new acf_field_radio();
188
+
189
  ?>
core/fields/relationship.php CHANGED
@@ -1,35 +1,37 @@
1
  <?php
2
 
3
- class acf_Relationship extends acf_Field
4
  {
5
 
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'relationship';
21
- $this->title = __("Relationship",'acf');
22
-
23
 
24
- // actions
25
- add_action('wp_ajax_acf_get_relationship_results', array($this, 'acf_get_relationship_results'));
26
- add_action('wp_ajax_nopriv_acf_get_relationship_results', array($this, 'acf_get_relationship_results'));
27
 
28
- }
29
-
30
-
31
- /*
32
- * my_posts_where
 
 
 
 
 
 
 
33
  *
34
  * @description:
35
  * @created: 3/09/12
@@ -48,17 +50,15 @@ class acf_Relationship extends acf_Field
48
  }
49
 
50
 
51
- /*--------------------------------------------------------------------------------------
52
- *
53
- * acf_get_relationship_results
54
  *
55
- * @author Elliot Condon
56
- * @description: Generates HTML for Left column relationship results
57
- * @created: 5/07/12
58
- *
59
- *-------------------------------------------------------------------------------------*/
60
 
61
- function acf_get_relationship_results()
62
  {
63
  // vars
64
  $options = array(
@@ -74,15 +74,17 @@ class acf_Relationship extends acf_Field
74
  'lang' => false,
75
  'update_post_meta_cache' => false,
76
  'field_name' => '',
77
- 'field_key' => ''
 
78
  );
79
- $ajax = isset( $_POST['action'] ) ? true : false;
80
 
 
81
 
82
- // override options with posted values
83
- if( $ajax )
 
84
  {
85
- $options = array_merge($options, $_POST);
86
  }
87
 
88
 
@@ -103,7 +105,7 @@ class acf_Relationship extends acf_Field
103
  // load all post types by default
104
  if( !$options['post_type'] || !is_array($options['post_type']) || $options['post_type'][0] == "" )
105
  {
106
- $options['post_type'] = $this->parent->get_post_types();
107
  }
108
 
109
 
@@ -217,28 +219,24 @@ class acf_Relationship extends acf_Field
217
 
218
 
219
  echo $results;
220
-
221
-
222
- // die?
223
- if( $ajax )
224
- {
225
- die();
226
- }
227
-
228
  }
229
-
230
 
231
- /*--------------------------------------------------------------------------------------
 
 
 
 
232
  *
233
- * create_field
234
  *
235
- * @author Elliot Condon
236
- * @since 2.0.5
237
- * @updated 2.2.0
238
- *
239
- *-------------------------------------------------------------------------------------*/
240
 
241
- function create_field($field)
242
  {
243
  // vars
244
  $defaults = array(
@@ -264,7 +262,7 @@ class acf_Relationship extends acf_Field
264
  // load all post types by default
265
  if( !$field['post_type'] || !is_array($field['post_type']) || $field['post_type'][0] == "" )
266
  {
267
- $field['post_type'] = $this->parent->get_post_types();
268
  }
269
 
270
 
@@ -313,13 +311,7 @@ class acf_Relationship extends acf_Field
313
  {
314
  foreach( $field['value'] as $post )
315
  {
316
- // check that post exists (my have been trashed)
317
- if( !is_object($post) )
318
- {
319
- continue;
320
- }
321
-
322
-
323
  // right aligned info
324
  $title = '<span class="relationship-item-info">';
325
 
@@ -333,9 +325,11 @@ class acf_Relationship extends acf_Field
333
 
334
  $title .= '</span>';
335
 
 
336
  // find title. Could use get_the_title, but that uses get_post(), so I think this uses less Memory
337
  $title .= apply_filters( 'the_title', $post->post_title, $post->ID );
338
 
 
339
  // status
340
  if($post->post_status != "publish")
341
  {
@@ -365,22 +359,23 @@ class acf_Relationship extends acf_Field
365
 
366
  </div>
367
  <?php
368
-
369
-
370
  }
371
 
372
 
373
- /*--------------------------------------------------------------------------------------
 
374
  *
375
- * create_options
 
376
  *
377
- * @author Elliot Condon
378
- * @since 2.0.6
379
- * @updated 2.2.0
380
- *
381
- *-------------------------------------------------------------------------------------*/
 
382
 
383
- function create_options($key, $field)
384
  {
385
  // vars
386
  $defaults = array(
@@ -390,6 +385,7 @@ class acf_Relationship extends acf_Field
390
  );
391
 
392
  $field = array_merge($defaults, $field);
 
393
 
394
 
395
  // validate taxonomy
@@ -400,91 +396,93 @@ class acf_Relationship extends acf_Field
400
 
401
 
402
  ?>
403
- <tr class="field_option field_option_<?php echo $this->name; ?>">
404
- <td class="label">
405
- <label for=""><?php _e("Post Type",'acf'); ?></label>
406
- </td>
407
- <td>
408
- <?php
409
-
410
- $choices = array(
411
- '' => __("All",'acf')
412
- );
413
-
414
- $post_types = $this->parent->get_post_types();
415
-
416
- foreach( $post_types as $post_type )
417
- {
418
- $choices[$post_type] = $post_type;
419
- }
420
-
421
- do_action('acf/create_field', array(
422
- 'type' => 'select',
423
- 'name' => 'fields['.$key.'][post_type]',
424
- 'value' => $field['post_type'],
425
- 'choices' => $choices,
426
- 'multiple' => 1,
427
- ));
428
-
429
- ?>
430
- </td>
431
- </tr>
432
- <tr class="field_option field_option_<?php echo $this->name; ?>">
433
- <td class="label">
434
- <label><?php _e("Filter from Taxonomy",'acf'); ?></label>
435
- </td>
436
- <td>
437
- <?php
438
- $choices = array(
439
- '' => array(
440
- 'all' => __("All",'acf')
441
- )
442
- );
443
- $choices = array_merge($choices, $this->parent->get_taxonomies_for_select());
444
- do_action('acf/create_field', array(
445
- 'type' => 'select',
446
- 'name' => 'fields['.$key.'][taxonomy]',
447
- 'value' => $field['taxonomy'],
448
- 'choices' => $choices,
449
- 'optgroup' => true,
450
- 'multiple' => 1,
451
- ));
452
- ?>
453
- </td>
454
- </tr>
455
- <tr class="field_option field_option_<?php echo $this->name; ?>">
456
- <td class="label">
457
- <label><?php _e("Maximum posts",'acf'); ?></label>
458
- </td>
459
- <td>
460
- <?php
461
- do_action('acf/create_field', array(
462
- 'type' => 'text',
463
- 'name' => 'fields['.$key.'][max]',
464
- 'value' => $field['max'],
465
- ));
466
- ?>
467
- </td>
468
- </tr>
469
  <?php
 
470
  }
471
 
472
 
473
- /*--------------------------------------------------------------------------------------
 
 
 
 
 
 
 
474
  *
475
- * get_value
 
 
476
  *
477
- * @author Elliot Condon
478
- * @since 3.3.3
479
- *
480
- *-------------------------------------------------------------------------------------*/
481
 
482
- function get_value($post_id, $field)
483
  {
484
- // get value
485
- $value = parent::get_value($post_id, $field);
486
-
487
-
488
  // empty?
489
  if( !$value )
490
  {
@@ -510,7 +508,7 @@ class acf_Relationship extends acf_Field
510
  $posts = get_posts(array(
511
  'numberposts' => -1,
512
  'post__in' => $value,
513
- 'post_type' => $this->parent->get_post_types(),
514
  'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
515
  ));
516
 
@@ -542,8 +540,30 @@ class acf_Relationship extends acf_Field
542
  return $value;
543
  }
544
 
545
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546
 
547
  }
548
 
 
 
549
  ?>
1
  <?php
2
 
3
+ class acf_field_relationship extends acf_field
4
  {
5
 
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'relationship';
19
+ $this->label = __("Relationship",'acf');
20
+ $this->category = __("Relational",'acf');
 
21
 
 
 
 
22
 
23
+ // do not delete!
24
+ parent::__construct();
25
+
26
+
27
+ // extra
28
+ add_action('wp_ajax_acf/fields/relationship/query_posts', array($this, 'query_posts'));
29
+ add_action('wp_ajax_nopriv_acf/fields/relationship/query_posts', array($this, 'query_posts'));
30
+ }
31
+
32
+
33
+ /*
34
+ * posts_where
35
  *
36
  * @description:
37
  * @created: 3/09/12
50
  }
51
 
52
 
53
+ /*
54
+ * query_posts
 
55
  *
56
+ * @description:
57
+ * @since: 3.6
58
+ * @created: 27/01/13
59
+ */
 
60
 
61
+ function query_posts()
62
  {
63
  // vars
64
  $options = array(
74
  'lang' => false,
75
  'update_post_meta_cache' => false,
76
  'field_name' => '',
77
+ 'field_key' => '',
78
+ 'nonce' => ''
79
  );
 
80
 
81
+ $options = array_merge( $options, $_POST );
82
 
83
+
84
+ // validate
85
+ if( !wp_verify_nonce($options['nonce'], 'acf_nonce') )
86
  {
87
+ die(0);
88
  }
89
 
90
 
105
  // load all post types by default
106
  if( !$options['post_type'] || !is_array($options['post_type']) || $options['post_type'][0] == "" )
107
  {
108
+ $options['post_type'] = apply_filters('acf/get_post_types', array());
109
  }
110
 
111
 
219
 
220
 
221
  echo $results;
222
+ die();
223
+
 
 
 
 
 
 
224
  }
 
225
 
226
+
227
+ /*
228
+ * create_field()
229
+ *
230
+ * Create the HTML interface for your field
231
  *
232
+ * @param $field - an array holding all the field's data
233
  *
234
+ * @type action
235
+ * @since 3.6
236
+ * @date 23/01/13
237
+ */
 
238
 
239
+ function create_field( $field )
240
  {
241
  // vars
242
  $defaults = array(
262
  // load all post types by default
263
  if( !$field['post_type'] || !is_array($field['post_type']) || $field['post_type'][0] == "" )
264
  {
265
+ $field['post_type'] = apply_filters('acf/get_post_types', array());
266
  }
267
 
268
 
311
  {
312
  foreach( $field['value'] as $post )
313
  {
314
+
 
 
 
 
 
 
315
  // right aligned info
316
  $title = '<span class="relationship-item-info">';
317
 
325
 
326
  $title .= '</span>';
327
 
328
+
329
  // find title. Could use get_the_title, but that uses get_post(), so I think this uses less Memory
330
  $title .= apply_filters( 'the_title', $post->post_title, $post->ID );
331
 
332
+
333
  // status
334
  if($post->post_status != "publish")
335
  {
359
 
360
  </div>
361
  <?php
 
 
362
  }
363
 
364
 
365
+ /*
366
+ * create_options()
367
  *
368
+ * Create extra options for your field. This is rendered when editing a field.
369
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
370
  *
371
+ * @type action
372
+ * @since 3.6
373
+ * @date 23/01/13
374
+ *
375
+ * @param $field - an array holding all the field's data
376
+ */
377
 
378
+ function create_options( $field )
379
  {
380
  // vars
381
  $defaults = array(
385
  );
386
 
387
  $field = array_merge($defaults, $field);
388
+ $key = $field['name'];
389
 
390
 
391
  // validate taxonomy
396
 
397
 
398
  ?>
399
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
400
+ <td class="label">
401
+ <label for=""><?php _e("Post Type",'acf'); ?></label>
402
+ </td>
403
+ <td>
404
+ <?php
405
+
406
+ $choices = array(
407
+ '' => __("All",'acf')
408
+ );
409
+ $choices = apply_filters('acf/get_post_types', $choices);
410
+
411
+
412
+ do_action('acf/create_field', array(
413
+ 'type' => 'select',
414
+ 'name' => 'fields['.$key.'][post_type]',
415
+ 'value' => $field['post_type'],
416
+ 'choices' => $choices,
417
+ 'multiple' => 1,
418
+ ));
419
+
420
+ ?>
421
+ </td>
422
+ </tr>
423
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
424
+ <td class="label">
425
+ <label><?php _e("Filter from Taxonomy",'acf'); ?></label>
426
+ </td>
427
+ <td>
428
+ <?php
429
+ $choices = array(
430
+ '' => array(
431
+ 'all' => __("All",'acf')
432
+ )
433
+ );
434
+ $simple_value = false;
435
+ $choices = apply_filters('acf/get_taxonomies_for_select', $choices, $simple_value);
436
+
437
+
438
+ do_action('acf/create_field', array(
439
+ 'type' => 'select',
440
+ 'name' => 'fields['.$key.'][taxonomy]',
441
+ 'value' => $field['taxonomy'],
442
+ 'choices' => $choices,
443
+ 'optgroup' => true,
444
+ 'multiple' => 1,
445
+ ));
446
+ ?>
447
+ </td>
448
+ </tr>
449
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
450
+ <td class="label">
451
+ <label><?php _e("Maximum posts",'acf'); ?></label>
452
+ </td>
453
+ <td>
454
+ <?php
455
+ do_action('acf/create_field', array(
456
+ 'type' => 'text',
457
+ 'name' => 'fields['.$key.'][max]',
458
+ 'value' => $field['max'],
459
+ ));
460
+ ?>
461
+ </td>
462
+ </tr>
 
 
463
  <?php
464
+
465
  }
466
 
467
 
468
+ /*
469
+ * format_value()
470
+ *
471
+ * This filter is appied to the $value after it is loaded from the db and before it is passed to the create_field action
472
+ *
473
+ * @type filter
474
+ * @since 3.6
475
+ * @date 23/01/13
476
  *
477
+ * @param $value - the value which was loaded from the database
478
+ * @param $post_id - the $post_id from which the value was loaded
479
+ * @param $field - the field array holding all the field options
480
  *
481
+ * @return $value - the modified value
482
+ */
 
 
483
 
484
+ function format_value( $value, $post_id, $field )
485
  {
 
 
 
 
486
  // empty?
487
  if( !$value )
488
  {
508
  $posts = get_posts(array(
509
  'numberposts' => -1,
510
  'post__in' => $value,
511
+ 'post_type' => apply_filters('acf/get_post_types', array()),
512
  'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
513
  ));
514
 
540
  return $value;
541
  }
542
 
543
+
544
+ /*
545
+ * format_value_for_api()
546
+ *
547
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
548
+ *
549
+ * @type filter
550
+ * @since 3.6
551
+ * @date 23/01/13
552
+ *
553
+ * @param $value - the value which was loaded from the database
554
+ * @param $post_id - the $post_id from which the value was loaded
555
+ * @param $field - the field array holding all the field options
556
+ *
557
+ * @return $value - the modified value
558
+ */
559
+
560
+ function format_value_for_api( $value, $post_id, $field )
561
+ {
562
+ return $this->format_value( $value, $post_id, $field );
563
+ }
564
 
565
  }
566
 
567
+ new acf_field_relationship();
568
+
569
  ?>
core/fields/repeater.php DELETED
@@ -1,820 +0,0 @@
1
- <?php
2
-
3
- class acf_Repeater extends acf_Field
4
- {
5
-
6
- /*--------------------------------------------------------------------------------------
7
- *
8
- * Constructor
9
- *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
-
16
- function __construct($parent)
17
- {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'repeater';
21
- $this->title = __("Repeater",'acf');
22
-
23
-
24
- // filters
25
- add_filter('acf_save_field-' . $this->name, array($this, 'acf_save_field'));
26
- add_filter('acf_load_field-' . $this->name, array($this, 'acf_load_field'));
27
- }
28
-
29
-
30
- /*
31
- * acf_load_field
32
- *
33
- * @description:
34
- * @since: 3.6
35
- * @created: 21/02/13
36
- */
37
-
38
- function acf_load_field( $field )
39
- {
40
- // apply_load field to all sub fields
41
- if( isset($field['sub_fields']) && is_array($field['sub_fields']) )
42
- {
43
- foreach( $field['sub_fields'] as $k => $sub_field )
44
- {
45
- // apply filters
46
- $sub_field = apply_filters('acf_load_field', $sub_field);
47
-
48
-
49
- $keys = array('type', 'name', 'key');
50
- $called = array(); // field[type] && field[name] may be the same! Don't run the same filter twice!
51
- foreach( $keys as $key )
52
- {
53
- // validate
54
- if( !isset($field[ $key ]) ){ continue; }
55
- if( in_array($field[ $key ], $called) ){ continue; }
56
-
57
-
58
- // add to $called
59
- $action = $field[ $key ] . '-' . $sub_field[ $key ];
60
- $called[] = $action;
61
-
62
-
63
- // run filters
64
- $sub_field = apply_filters('acf_load_field-' . $action, $sub_field); // old filter
65
-
66
- }
67
-
68
-
69
- // update sub field
70
- $field['sub_fields'][ $k ] = $sub_field;
71
- }
72
- }
73
-
74
- return $field;
75
- }
76
-
77
- /*--------------------------------------------------------------------------------------
78
- *
79
- * create_field
80
- *
81
- * @author Elliot Condon
82
- * @since 2.0.5
83
- * @updated 2.2.0
84
- *
85
- *-------------------------------------------------------------------------------------*/
86
-
87
- function create_field($field)
88
- {
89
- // vars
90
- $defaults = array(
91
- 'row_limit' => 0,
92
- 'row_min' => 0,
93
- 'layout' => 'table',
94
- 'sub_fields' => array(),
95
- 'button_label' => __("Add Row",'acf'),
96
- 'value' => array(),
97
- );
98
-
99
- $field = array_merge($defaults, $field);
100
-
101
-
102
- // validate types
103
- $field['row_limit'] = (int) $field['row_limit'];
104
- $field['row_min'] = (int) $field['row_min'];
105
-
106
-
107
- // value may be false
108
- if( !$field['value'] )
109
- {
110
- $field['value'] = array();
111
- }
112
-
113
-
114
- // row limit = 0?
115
- if( $field['row_limit'] < 1 )
116
- {
117
- $field['row_limit'] = 999;
118
- }
119
-
120
-
121
-
122
- // min rows
123
- if( $field['row_min'] > count($field['value']) )
124
- {
125
- for( $i = 0; $i < $field['row_min']; $i++ )
126
- {
127
- // already have a value? continue...
128
- if( isset($field['value'][$i]) )
129
- {
130
- continue;
131
- }
132
-
133
- // populate values
134
- $field['value'][$i] = array();
135
-
136
- foreach( $field['sub_fields'] as $sub_field)
137
- {
138
- $sub_value = isset($sub_field['default_value']) ? $sub_field['default_value'] : false;
139
- $field['value'][$i][ $sub_field['key'] ] = $sub_value;
140
- }
141
-
142
- }
143
- }
144
-
145
-
146
- // max rows
147
- if( $field['row_limit'] < count($field['value']) )
148
- {
149
- for( $i = 0; $i < count($field['value']); $i++ )
150
- {
151
- if( $i >= $field['row_limit'] )
152
- {
153
- unset( $field['value'][$i] );
154
- }
155
- }
156
- }
157
-
158
-
159
- // setup values for row clone
160
- $field['value']['acfcloneindex'] = array();
161
- foreach( $field['sub_fields'] as $sub_field)
162
- {
163
- $sub_value = isset($sub_field['default_value']) ? $sub_field['default_value'] : false;
164
- $field['value']['acfcloneindex'][ $sub_field['key'] ] = $sub_value;
165
- }
166
-
167
- ?>
168
- <div class="repeater" data-min_rows="<?php echo $field['row_min']; ?>" data-max_rows="<?php echo $field['row_limit']; ?>">
169
- <table class="widefat acf-input-table <?php if( $field['layout'] == 'row' ): ?>row_layout<?php endif; ?>">
170
- <?php if( $field['layout'] == 'table' ): ?>
171
- <thead>
172
- <tr>
173
- <?php
174
-
175
- // order th
176
-
177
- if( $field['row_limit'] > 1 ): ?>
178
- <th class="order"></th>
179
- <?php endif; ?>
180
-
181
- <?php foreach( $field['sub_fields'] as $sub_field_i => $sub_field):
182
-
183
- // add width attr
184
- $attr = "";
185
-
186
- if( count($field['sub_fields']) > 1 && isset($sub_field['column_width']) && $sub_field['column_width'] )
187
- {
188
- $attr = 'width="' . $sub_field['column_width'] . '%"';
189
- }
190
-
191
- ?>
192
- <th class="acf-th-<?php echo $sub_field['name']; ?>" <?php echo $attr; ?>>
193
- <span><?php echo $sub_field['label']; ?></span>
194
- <?php if( isset($sub_field['instructions']) ): ?>
195
- <span class="sub-field-instructions"><?php echo $sub_field['instructions']; ?></span>
196
- <?php endif; ?>
197
- </th><?php
198
- endforeach; ?>
199
-
200
- <?php
201
-
202
- // remove th
203
-
204
- if( $field['row_min'] < $field['row_limit'] ): ?>
205
- <th class="remove"></th>
206
- <?php endif; ?>
207
- </tr>
208
- </thead>
209
- <?php endif; ?>
210
- <tbody>
211
- <?php if( $field['value'] ): foreach( $field['value'] as $i => $value ): ?>
212
-
213
- <tr class="<?php echo ( (string) $i == 'acfcloneindex') ? "row-clone" : "row"; ?>">
214
-
215
- <?php
216
-
217
- // row number
218
-
219
- if( $field['row_limit'] > 1 ): ?>
220
- <td class="order"><?php echo $i+1; ?></td>
221
- <?php endif; ?>
222
-
223
- <?php
224
-
225
- // layout: Row
226
-
227
- if( $field['layout'] == 'row' ): ?>
228
- <td class="acf_input-wrap">
229
- <table class="widefat acf_input">
230
- <?php endif; ?>
231
-
232
-
233
- <?php
234
-
235
- // loop though sub fields
236
-
237
- foreach( $field['sub_fields'] as $j => $sub_field ): ?>
238
-
239
- <?php
240
-
241
- // layout: Row
242
-
243
- if( $field['layout'] == 'row' ): ?>
244
- <tr>
245
- <td class="label">
246
- <label><?php echo $sub_field['label']; ?></label>
247
- <?php if( isset($sub_field['instructions']) ): ?>
248
- <span class="sub-field-instructions"><?php echo $sub_field['instructions']; ?></span>
249
- <?php endif; ?>
250
- </td>
251
- <?php endif; ?>
252
-
253
- <td>
254
- <?php
255
-
256
- // add value
257
- $sub_field['value'] = isset($value[$sub_field['key']]) ? $value[$sub_field['key']] : '';
258
-
259
- // add name
260
- $sub_field['name'] = $field['name'] . '[' . $i . '][' . $sub_field['key'] . ']';
261
-
262
- // create field
263
- do_action('acf/create_field', $sub_field);
264
-
265
- ?>
266
- </td>
267
-
268
- <?php
269
-
270
- // layout: Row
271
-
272
- if( $field['layout'] == 'row' ): ?>
273
- </tr>
274
- <?php endif; ?>
275
-
276
- <?php endforeach; ?>
277
-
278
- <?php
279
-
280
- // layout: Row
281
-
282
- if( $field['layout'] == 'row' ): ?>
283
- </table>
284
- </td>
285
- <?php endif; ?>
286
-
287
- <?php
288
-
289
- // delete row
290
-
291
- if( $field['row_min'] < $field['row_limit'] ): ?>
292
- <td class="remove">
293
- <a class="acf-button-add add-row-before" href="javascript:;"></a>
294
- <a class="acf-button-remove" href="javascript:;"></a>
295
- </td>
296
- <?php endif; ?>
297
-
298
- </tr>
299
- <?php endforeach; endif; ?>
300
- </tbody>
301
- </table>
302
- <?php if( $field['row_min'] < $field['row_limit'] ): ?>
303
-
304
- <ul class="hl clearfix repeater-footer">
305
- <li class="right">
306
- <a href="javascript:;" class="add-row-end acf-button"><?php echo $field['button_label']; ?></a>
307
- </li>
308
- </ul>
309
-
310
- <?php endif; ?>
311
- </div>
312
- <?php
313
- }
314
-
315
-
316
-
317
- /*--------------------------------------------------------------------------------------
318
- *
319
- * create_options
320
- *
321
- * @author Elliot Condon
322
- * @since 2.0.6
323
- * @updated 2.2.0
324
- *
325
- *-------------------------------------------------------------------------------------*/
326
-
327
- function create_options($key, $field)
328
- {
329
- // vars
330
- $fields_names = array();
331
- $defaults = array(
332
- 'row_limit' => '',
333
- 'row_min' => 0,
334
- 'layout' => 'table',
335
- 'sub_fields' => array(),
336
- 'button_label' => __("Add Row",'acf'),
337
- 'value' => array(),
338
- );
339
-
340
- $field = array_merge($defaults, $field);
341
-
342
-
343
- // validate types
344
- $field['row_min'] = (int) $field['row_min'];
345
-
346
-
347
- // add clone
348
- $field['sub_fields'][] = array(
349
- 'key' => 'field_clone',
350
- 'label' => __("New Field",'acf'),
351
- 'name' => __("new_field",'acf'),
352
- 'type' => 'text',
353
- 'order_no' => 1,
354
- 'instructions' => '',
355
- );
356
-
357
-
358
- // get name of all fields for use in field type
359
- foreach($this->parent->fields as $f)
360
- {
361
- if( $f->name )
362
- {
363
- $fields_names[$f->name] = $f->title;
364
- }
365
- }
366
- unset( $fields_names['tab'] );
367
-
368
- ?>
369
- <tr class="field_option field_option_<?php echo $this->name; ?> field_option_<?php echo $this->name; ?>_fields">
370
- <td class="label">
371
- <label><?php _e("Repeater Fields",'acf'); ?></label>
372
- </td>
373
- <td>
374
- <div class="repeater">
375
- <div class="fields_header">
376
- <table class="acf widefat">
377
- <thead>
378
- <tr>
379
- <th class="field_order"><?php _e('Field Order','acf'); ?></th>
380
- <th class="field_label"><?php _e('Field Label','acf'); ?></th>
381
- <th class="field_name"><?php _e('Field Name','acf'); ?></th>
382
- <th class="field_type"><?php _e('Field Type','acf'); ?></th>
383
- </tr>
384
- </thead>
385
- </table>
386
- </div>
387
- <div class="fields">
388
-
389
- <div class="no_fields_message" <?php if(count($field['sub_fields']) > 1){ echo 'style="display:none;"'; } ?>>
390
- <?php _e("No fields. Click the \"+ Add Sub Field button\" to create your first field.",'acf'); ?>
391
- </div>
392
-
393
- <?php foreach($field['sub_fields'] as $sub_field): ?>
394
- <div class="field field-<?php echo $sub_field['key']; ?> sub_field" data-id="<?php echo $sub_field['key']; ?>">
395
- <div class="field_meta">
396
- <table class="acf widefat">
397
- <tr>
398
- <td class="field_order"><span class="circle"><?php echo (int)$sub_field['order_no'] + 1; ?></span></td>
399
- <td class="field_label">
400
- <strong>
401
- <a class="acf_edit_field" title="<?php _e("Edit this Field",'acf'); ?>" href="javascript:;"><?php echo $sub_field['label']; ?></a>
402
- </strong>
403
- <div class="row_options">
404
- <span><a class="acf_edit_field" title="<?php _e("Edit this Field",'acf'); ?>" href="javascript:;"><?php _e("Edit",'acf'); ?></a> | </span>
405
- <span><a title="<?php _e("Read documentation for this field",'acf'); ?>" href="http://www.advancedcustomfields.com/docs/field-types/" target="_blank"><?php _e("Docs",'acf'); ?></a> | </span>
406
- <span><a class="acf_duplicate_field" title="<?php _e("Duplicate this Field",'acf'); ?>" href="javascript:;"><?php _e("Duplicate",'acf'); ?></a> | </span>
407
- <span><a class="acf_delete_field" title="<?php _e("Delete this Field",'acf'); ?>" href="javascript:;"><?php _e("Delete",'acf'); ?></a>
408
- </div>
409
- </td>
410
- <td class="field_name"><?php echo $sub_field['name']; ?></td>
411
- <td class="field_type"><?php echo $sub_field['type']; ?></td>
412
- </tr>
413
- </table>
414
- </div>
415
-
416
- <div class="field_form_mask">
417
- <div class="field_form">
418
-
419
- <table class="acf_input widefat">
420
- <tbody>
421
- <tr class="field_label">
422
- <td class="label">
423
- <label><span class="required">*</span><?php _e("Field Label",'acf'); ?></label>
424
- <p class="description"><?php _e("This is the name which will appear on the EDIT page",'acf'); ?></p>
425
- </td>
426
- <td>
427
- <?php
428
- do_action('acf/create_field', array(
429
- 'type' => 'text',
430
- 'name' => 'fields['.$key.'][sub_fields]['.$sub_field['key'].'][label]',
431
- 'value' => $sub_field['label'],
432
- 'class' => 'label',
433
- ));
434
- ?>
435
- </td>
436
- </tr>
437
- <tr class="field_name">
438
- <td class="label">
439
- <label><span class="required">*</span><?php _e("Field Name",'acf'); ?></label>
440
- <p class="description"><?php _e("Single word, no spaces. Underscores and dashes allowed",'acf'); ?></p>
441
- </td>
442
- <td>
443
- <?php
444
- do_action('acf/create_field', array(
445
- 'type' => 'text',
446
- 'name' => 'fields['.$key.'][sub_fields]['.$sub_field['key'].'][name]',
447
- 'value' => $sub_field['name'],
448
- 'class' => 'name',
449
- ));
450
- ?>
451
- </td>
452
- </tr>
453
- <tr class="field_type">
454
- <td class="label"><label><span class="required">*</span><?php _e("Field Type",'acf'); ?></label></td>
455
- <td>
456
- <?php
457
- do_action('acf/create_field', array(
458
- 'type' => 'select',
459
- 'name' => 'fields['.$key.'][sub_fields]['.$sub_field['key'].'][type]',
460
- 'value' => $sub_field['type'],
461
- 'class' => 'type',
462
- 'choices' => $fields_names
463
- ));
464
- ?>
465
- </td>
466
- </tr>
467
- <tr class="field_instructions">
468
- <td class="label"><label><?php _e("Field Instructions",'acf'); ?></label></td>
469
- <td>
470
- <?php
471
-
472
- if( !isset($sub_field['instructions']) )
473
- {
474
- $sub_field['instructions'] = "";
475
- }
476
-
477
- do_action('acf/create_field', array(
478
- 'type' => 'text',
479
- 'name' => 'fields['.$key.'][sub_fields]['.$sub_field['key'].'][instructions]',
480
- 'value' => $sub_field['instructions'],
481
- 'class' => 'instructions',
482
- ));
483
- ?>
484
- </td>
485
- </tr>
486
- <tr class="field_column_width">
487
- <td class="label">
488
- <label><?php _e("Column Width",'acf'); ?></label>
489
- <p class="description"><?php _e("Leave blank for auto",'acf'); ?></p>
490
- </td>
491
- <td>
492
- <?php
493
-
494
- if( !isset($sub_field['column_width']) )
495
- {
496
- $sub_field['column_width'] = "";
497
- }
498
-
499
- do_action('acf/create_field', array(
500
- 'type' => 'number',
501
- 'name' => 'fields['.$key.'][sub_fields]['.$sub_field['key'].'][column_width]',
502
- 'value' => $sub_field['column_width'],
503
- 'class' => 'column_width',
504
- ));
505
- ?> %
506
- </td>
507
- </tr>
508
- <?php
509
-
510
- if( isset($this->parent->fields[ $sub_field['type'] ]) )
511
- {
512
- $this->parent->fields[$sub_field['type']]->create_options($key.'][sub_fields]['.$sub_field['key'], $sub_field);
513
- }
514
-
515
- ?>
516
- <tr class="field_save">
517
- <td class="label">
518
- <!-- <label><?php _e("Save Field",'acf'); ?></label> -->
519
- </td>
520
- <td>
521
- <ul class="hl clearfix">
522
- <li>
523
- <a class="acf_edit_field acf-button grey" title="<?php _e("Close Field",'acf'); ?>" href="javascript:;"><?php _e("Close Sub Field",'acf'); ?></a>
524
- </li>
525
- </ul>
526
- </td>
527
- </tr>
528
- </tbody>
529
- </table>
530
-
531
- </div><!-- End Form -->
532
- </div><!-- End Form Mask -->
533
-
534
- </div>
535
- <?php endforeach; ?>
536
- </div>
537
- <div class="table_footer">
538
- <div class="order_message"><?php _e('Drag and drop to reorder','acf'); ?></div>
539
- <a href="javascript:;" id="add_field" class="acf-button"><?php _e('+ Add Sub Field','acf'); ?></a>
540
- </div>
541
- </div>
542
- </td>
543
- </tr>
544
- <tr class="field_option field_option_<?php echo $this->name; ?>">
545
- <td class="label">
546
- <label><?php _e("Minimum Rows",'acf'); ?></label>
547
- </td>
548
- <td>
549
- <?php
550
- do_action('acf/create_field', array(
551
- 'type' => 'text',
552
- 'name' => 'fields['.$key.'][row_min]',
553
- 'value' => $field['row_min'],
554
- ));
555
- ?>
556
- </td>
557
- </tr>
558
- <tr class="field_option field_option_<?php echo $this->name; ?>">
559
- <td class="label">
560
- <label><?php _e("Maximum Rows",'acf'); ?></label>
561
- </td>
562
- <td>
563
- <?php
564
- do_action('acf/create_field', array(
565
- 'type' => 'text',
566
- 'name' => 'fields['.$key.'][row_limit]',
567
- 'value' => $field['row_limit'],
568
- ));
569
- ?>
570
- </td>
571
- </tr>
572
- <tr class="field_option field_option_<?php echo $this->name; ?> field_option_<?php echo $this->name; ?>_layout">
573
- <td class="label">
574
- <label><?php _e("Layout",'acf'); ?></label>
575
- </td>
576
- <td>
577
- <?php
578
- do_action('acf/create_field', array(
579
- 'type' => 'radio',
580
- 'name' => 'fields['.$key.'][layout]',
581
- 'value' => $field['layout'],
582
- 'layout' => 'horizontal',
583
- 'choices' => array(
584
- 'table' => __("Table (default)",'acf'),
585
- 'row' => __("Row",'acf')
586
- )
587
- ));
588
- ?>
589
- </td>
590
- </tr>
591
- <tr class="field_option field_option_<?php echo $this->name; ?>">
592
- <td class="label">
593
- <label><?php _e("Button Label",'acf'); ?></label>
594
- </td>
595
- <td>
596
- <?php
597
- do_action('acf/create_field', array(
598
- 'type' => 'text',
599
- 'name' => 'fields['.$key.'][button_label]',
600
- 'value' => $field['button_label'],
601
- ));
602
- ?>
603
- </td>
604
- </tr>
605
- <?php
606
- }
607
-
608
-
609
- /*--------------------------------------------------------------------------------------
610
- *
611
- * pre_save_field
612
- * - called just before saving the field to the database.
613
- *
614
- * @author Elliot Condon
615
- * @since 2.2.0
616
- *
617
- *-------------------------------------------------------------------------------------*/
618
-
619
- function acf_save_field($field)
620
- {
621
- // format sub_fields
622
- if( $field['sub_fields'] )
623
- {
624
- // remove dummy field
625
- unset( $field['sub_fields']['field_clone'] );
626
-
627
-
628
- // loop through and save fields
629
- $i = -1;
630
- $sub_fields = array();
631
-
632
-
633
- foreach( $field['sub_fields'] as $key => $f )
634
- {
635
- $i++;
636
-
637
-
638
- // order
639
- $f['order_no'] = $i;
640
- $f['key'] = $key;
641
-
642
-
643
- // apply filters
644
- $f = apply_filters('acf_save_field', $f );
645
- $f = apply_filters('acf_save_field-' . $f['type'], $f );
646
-
647
-
648
- // add
649
- $sub_fields[] = $f;
650
- }
651
-
652
-
653
- // update sub fields
654
- $field['sub_fields'] = $sub_fields;
655
- }
656
-
657
-
658
- // return updated repeater field
659
- return $field;
660
-
661
- }
662
-
663
-
664
- /*--------------------------------------------------------------------------------------
665
- *
666
- * update_value
667
- *
668
- * @author Elliot Condon
669
- * @since 2.2.0
670
- *
671
- *-------------------------------------------------------------------------------------*/
672
-
673
- function update_value($post_id, $field, $value)
674
- {
675
- $total = 0;
676
-
677
- if( is_array( $value ) )
678
- {
679
- // remove dummy field
680
- unset($value['acfcloneindex']);
681
-
682
- $i = -1;
683
-
684
- // loop through rows
685
- foreach($value as $row)
686
- {
687
- $i++;
688
-
689
- // increase total
690
- $total++;
691
-
692
- // loop through sub fields
693
- foreach( $field['sub_fields'] as $sub_field )
694
- {
695
- // get sub field data
696
- $v = isset($row[$sub_field['key']]) ? $row[$sub_field['key']] : '';
697
-
698
- // update full name
699
- $sub_field['name'] = $field['name'] . '_' . $i . '_' . $sub_field['name'];
700
-
701
- // save sub field value
702
- $this->parent->update_value($post_id, $sub_field, $v);
703
- }
704
- }
705
- }
706
-
707
-
708
- /*
709
- * Remove Old Data
710
- *
711
- * @credit: http://support.advancedcustomfields.com/discussion/1994/deleting-single-repeater-fields-does-not-remove-entry-from-database
712
- */
713
-
714
- $old_total = (int) parent::get_value($post_id, $field);
715
-
716
- if( $old_total > $total )
717
- {
718
- foreach( $field['sub_fields'] as $sub_field )
719
- {
720
- for ( $j = $total; $j < $old_total; $j++ )
721
- {
722
- parent::delete_value( $post_id, $field['name'] . '_' . $j . '_' . $sub_field['name'] );
723
- }
724
- }
725
- }
726
-
727
-
728
- // update repeater count
729
- parent::update_value($post_id, $field, $total);
730
-
731
- }
732
-
733
-
734
- /*--------------------------------------------------------------------------------------
735
- *
736
- * get_value
737
- *
738
- * @author Elliot Condon
739
- * @since 2.2.0
740
- *
741
- *-------------------------------------------------------------------------------------*/
742
-
743
- function get_value($post_id, $field)
744
- {
745
- // vars
746
- $values = array();
747
- $total = 0;
748
-
749
-
750
- // get total rows
751
- $total = (int) parent::get_value($post_id, $field);
752
-
753
-
754
- if($total > 0)
755
- {
756
- // loop through rows
757
- for($i = 0; $i < $total; $i++)
758
- {
759
- // loop through sub fields
760
- foreach($field['sub_fields'] as $sub_field)
761
- {
762
- // update full name
763
- $sub_field['name'] = $field['name'] . '_' . $i . '_' . $sub_field['name'];
764
-
765
- $values[$i][ $sub_field['key'] ] = $this->parent->get_value($post_id, $sub_field);
766
- }
767
- }
768
-
769
- }
770
-
771
- return $values;
772
- }
773
-
774
- /*--------------------------------------------------------------------------------------
775
- *
776
- * get_value_for_api
777
- *
778
- * @author Elliot Condon
779
- * @since 3.0.0
780
- *
781
- *-------------------------------------------------------------------------------------*/
782
-
783
- function get_value_for_api($post_id, $field)
784
- {
785
- // vars
786
- $values = array();
787
- $total = 0;
788
-
789
-
790
- // get total rows
791
- $total = (int) parent::get_value($post_id, $field);
792
-
793
-
794
- if($total > 0)
795
- {
796
- // loop through rows
797
- for($i = 0; $i < $total; $i++)
798
- {
799
- // loop through sub fields
800
- foreach($field['sub_fields'] as $sub_field)
801
- {
802
- // store name
803
- $field_name = $sub_field['name'];
804
-
805
- // update full name
806
- $sub_field['name'] = $field['name'] . '_' . $i . '_' . $field_name;
807
-
808
- $values[$i][$field_name] = $this->parent->get_value_for_api($post_id, $sub_field);
809
- }
810
- }
811
-
812
- return $values;
813
- }
814
-
815
- return array();
816
- }
817
-
818
- }
819
-
820
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/fields/select.php CHANGED
@@ -1,45 +1,49 @@
1
  <?php
2
 
3
- class acf_Select extends acf_Field
4
  {
5
-
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'select';
21
- $this->title = __("Select",'acf');
22
 
23
 
24
- // filters (for all fields with choices)
25
- add_filter('acf_save_field-select', array($this, 'acf_save_field'));
26
- add_filter('acf_save_field-checkbox', array($this, 'acf_save_field'));
27
- add_filter('acf_save_field-radio', array($this, 'acf_save_field'));
28
- }
29
-
 
 
 
30
 
31
 
32
- /*--------------------------------------------------------------------------------------
 
33
  *
34
- * create_field
35
  *
36
- * @author Elliot Condon
37
- * @since 2.0.5
38
- * @updated 2.2.0
39
- *
40
- *-------------------------------------------------------------------------------------*/
 
41
 
42
- function create_field($field)
43
  {
44
  // vars
45
  $defaults = array(
@@ -51,14 +55,6 @@ class acf_Select extends acf_Field
51
  );
52
 
53
  $field = array_merge($defaults, $field);
54
-
55
-
56
- // no choices
57
- if(empty($field['choices']))
58
- {
59
- echo '<p>' . __("No choices to choose from",'acf') . '</p>';
60
- return false;
61
- }
62
 
63
 
64
  // multiple select
@@ -84,76 +80,79 @@ class acf_Select extends acf_Field
84
  }
85
 
86
  // loop through values and add them as options
87
- foreach($field['choices'] as $key => $value)
88
  {
89
- if($field['optgroup'])
90
  {
91
- // this select is grouped with optgroup
92
- if($key != '') echo '<optgroup label="'.$key.'">';
93
-
94
- if($value)
95
  {
96
- foreach($value as $id => $label)
 
 
 
97
  {
98
- $selected = '';
99
- if(is_array($field['value']) && in_array($id, $field['value']))
100
  {
101
- // 2. If the value is an array (multiple select), loop through values and check if it is selected
102
- $selected = 'selected="selected"';
103
- }
104
- else
105
- {
106
- // 3. this is not a multiple select, just check normaly
107
- if($id == $field['value'])
108
  {
 
109
  $selected = 'selected="selected"';
110
  }
111
- }
112
- echo '<option value="'.$id.'" '.$selected.'>'.$label.'</option>';
 
 
 
 
 
 
 
 
113
  }
114
- }
115
-
116
- if($key != '') echo '</optgroup>';
117
- }
118
- else
119
- {
120
- $selected = '';
121
- if(is_array($field['value']) && in_array($key, $field['value']))
122
- {
123
- // 2. If the value is an array (multiple select), loop through values and check if it is selected
124
- $selected = 'selected="selected"';
125
  }
126
  else
127
  {
128
- // 3. this is not a multiple select, just check normaly
129
- if($key == $field['value'])
130
  {
 
131
  $selected = 'selected="selected"';
132
  }
133
- }
134
- echo '<option value="'.$key.'" '.$selected.'>'.$value.'</option>';
 
 
 
 
 
 
 
 
135
  }
136
-
137
-
138
-
139
  }
140
 
141
  echo '</select>';
142
  }
143
 
144
 
145
- /*--------------------------------------------------------------------------------------
 
 
 
 
146
  *
147
- * create_options
 
 
148
  *
149
- * @author Elliot Condon
150
- * @since 2.0.6
151
- * @updated 2.2.0
152
- *
153
- *-------------------------------------------------------------------------------------*/
154
 
155
- function create_options($key, $field)
156
- {
157
  // vars
158
  $defaults = array(
159
  'multiple' => 0,
@@ -163,114 +162,144 @@ class acf_Select extends acf_Field
163
  );
164
 
165
  $field = array_merge($defaults, $field);
 
166
 
167
 
168
- // implode selects so they work in a textarea
169
- if(isset($field['choices']) && is_array($field['choices']))
170
  {
171
- foreach($field['choices'] as $choice_key => $choice_val)
172
  {
173
- $field['choices'][$choice_key] = $choice_key.' : '.$choice_val;
174
  }
175
  $field['choices'] = implode("\n", $field['choices']);
176
  }
177
- else
178
- {
179
- $field['choices'] = "";
180
- }
181
 
182
  ?>
183
- <tr class="field_option field_option_<?php echo $this->name; ?>">
184
- <td class="label">
185
- <label for=""><?php _e("Choices",'acf'); ?></label>
186
- <p class="description"><?php _e("Enter your choices one per line",'acf'); ?><br />
187
- <br />
188
- <?php _e("Red",'acf'); ?><br />
189
- <?php _e("Blue",'acf'); ?><br />
190
- <br />
191
- <?php _e("red : Red",'acf'); ?><br />
192
- <?php _e("blue : Blue",'acf'); ?><br />
193
- </p>
194
- </td>
195
- <td>
196
- <?php
197
- do_action('acf/create_field', array(
198
- 'type' => 'textarea',
199
- 'class' => 'textarea field_option-choices',
200
- 'name' => 'fields['.$key.'][choices]',
201
- 'value' => $field['choices'],
202
- ));
203
- ?>
204
- </td>
205
- </tr>
206
- <tr class="field_option field_option_<?php echo $this->name; ?>">
207
- <td class="label">
208
- <label><?php _e("Default Value",'acf'); ?></label>
209
- </td>
210
- <td>
211
- <?php
212
- do_action('acf/create_field', array(
213
- 'type' => 'text',
214
- 'name' => 'fields['.$key.'][default_value]',
215
- 'value' => $field['default_value'],
216
- ));
217
- ?>
218
- </td>
219
- </tr>
220
- <tr class="field_option field_option_<?php echo $this->name; ?>">
221
- <td class="label">
222
- <label><?php _e("Allow Null?",'acf'); ?></label>
223
- </td>
224
- <td>
225
- <?php
226
- do_action('acf/create_field', array(
227
- 'type' => 'radio',
228
- 'name' => 'fields['.$key.'][allow_null]',
229
- 'value' => $field['allow_null'],
230
- 'choices' => array(
231
- 1 => __("Yes",'acf'),
232
- 0 => __("No",'acf'),
233
- ),
234
- 'layout' => 'horizontal',
235
- ));
236
- ?>
237
- </td>
238
- </tr>
239
- <tr class="field_option field_option_<?php echo $this->name; ?>">
240
- <td class="label">
241
- <label><?php _e("Select multiple values?",'acf'); ?></label>
242
- </td>
243
- <td>
244
- <?php
245
- do_action('acf/create_field', array(
246
- 'type' => 'radio',
247
- 'name' => 'fields['.$key.'][multiple]',
248
- 'value' => $field['multiple'],
249
- 'choices' => array(
250
- 1 => __("Yes",'acf'),
251
- 0 => __("No",'acf'),
252
- ),
253
- 'layout' => 'horizontal',
254
- ));
255
- ?>
256
- </td>
257
- </tr>
258
-
259
- <?php
260
  }
261
 
262
 
263
- /*--------------------------------------------------------------------------------------
 
 
 
 
 
 
 
264
  *
265
- * pre_save_field
266
- * - called just before saving the field to the database.
 
267
  *
268
- * @author Elliot Condon
269
- * @since 2.2.0
270
- *
271
- *-------------------------------------------------------------------------------------*/
272
 
273
- function acf_save_field( $field )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  {
275
  // vars
276
  $defaults = array(
@@ -325,38 +354,15 @@ class acf_Select extends acf_Field
325
  }
326
 
327
 
328
-
329
  // update choices
330
  $field['choices'] = $new_choices;
331
 
332
 
333
- // return updated field
334
  return $field;
335
-
336
- }
337
-
338
-
339
- /*--------------------------------------------------------------------------------------
340
- *
341
- * get_value_for_api
342
- *
343
- * @author Elliot Condon
344
- * @since 3.1.2
345
- *
346
- *-------------------------------------------------------------------------------------*/
347
-
348
- function get_value_for_api($post_id, $field)
349
- {
350
- $value = parent::get_value($post_id, $field);
351
-
352
- if($value == 'null')
353
- {
354
- $value = false;
355
- }
356
-
357
- return $value;
358
  }
359
 
360
  }
361
 
 
 
362
  ?>
1
  <?php
2
 
3
+ class acf_field_select extends acf_field
4
  {
5
+
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'select';
19
+ $this->label = __("Select",'acf');
20
+ $this->category = __("Choice",'acf');
21
 
22
 
23
+ // do not delete!
24
+ parent::__construct();
25
+
26
+
27
+ // extra
28
+ //add_filter('acf/update_field/type=select', array($this, 'update_field'), 5, 2);
29
+ add_filter('acf/update_field/type=checkbox', array($this, 'update_field'), 5, 2);
30
+ add_filter('acf/update_field/type=radio', array($this, 'update_field'), 5, 2);
31
+ }
32
 
33
 
34
+ /*
35
+ * create_field()
36
  *
37
+ * Create the HTML interface for your field
38
  *
39
+ * @param $field - an array holding all the field's data
40
+ *
41
+ * @type action
42
+ * @since 3.6
43
+ * @date 23/01/13
44
+ */
45
 
46
+ function create_field( $field )
47
  {
48
  // vars
49
  $defaults = array(
55
  );
56
 
57
  $field = array_merge($defaults, $field);
 
 
 
 
 
 
 
 
58
 
59
 
60
  // multiple select
80
  }
81
 
82
  // loop through values and add them as options
83
+ if( $field['choices'] )
84
  {
85
+ foreach($field['choices'] as $key => $value)
86
  {
87
+ if($field['optgroup'])
 
 
 
88
  {
89
+ // this select is grouped with optgroup
90
+ if($key != '') echo '<optgroup label="'.$key.'">';
91
+
92
+ if($value)
93
  {
94
+ foreach($value as $id => $label)
 
95
  {
96
+ $selected = '';
97
+ if(is_array($field['value']) && in_array($id, $field['value']))
 
 
 
 
 
98
  {
99
+ // 2. If the value is an array (multiple select), loop through values and check if it is selected
100
  $selected = 'selected="selected"';
101
  }
102
+ else
103
+ {
104
+ // 3. this is not a multiple select, just check normaly
105
+ if($id == $field['value'])
106
+ {
107
+ $selected = 'selected="selected"';
108
+ }
109
+ }
110
+ echo '<option value="'.$id.'" '.$selected.'>'.$label.'</option>';
111
+ }
112
  }
113
+
114
+ if($key != '') echo '</optgroup>';
 
 
 
 
 
 
 
 
 
115
  }
116
  else
117
  {
118
+ $selected = '';
119
+ if(is_array($field['value']) && in_array($key, $field['value']))
120
  {
121
+ // 2. If the value is an array (multiple select), loop through values and check if it is selected
122
  $selected = 'selected="selected"';
123
  }
124
+ else
125
+ {
126
+ // 3. this is not a multiple select, just check normaly
127
+ if($key == $field['value'])
128
+ {
129
+ $selected = 'selected="selected"';
130
+ }
131
+ }
132
+ echo '<option value="'.$key.'" '.$selected.'>'.$value.'</option>';
133
+ }
134
  }
 
 
 
135
  }
136
 
137
  echo '</select>';
138
  }
139
 
140
 
141
+ /*
142
+ * create_options()
143
+ *
144
+ * Create extra options for your field. This is rendered when editing a field.
145
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
146
  *
147
+ * @type action
148
+ * @since 3.6
149
+ * @date 23/01/13
150
  *
151
+ * @param $field - an array holding all the field's data
152
+ */
 
 
 
153
 
154
+ function create_options( $field )
155
+ {
156
  // vars
157
  $defaults = array(
158
  'multiple' => 0,
162
  );
163
 
164
  $field = array_merge($defaults, $field);
165
+ $key = $field['name'];
166
 
167
 
168
+ // implode choices so they work in a textarea
169
+ if( is_array($field['choices']) )
170
  {
171
+ foreach( $field['choices'] as $k => $v )
172
  {
173
+ $field['choices'][ $k ] = $k . ' : ' . $v;
174
  }
175
  $field['choices'] = implode("\n", $field['choices']);
176
  }
 
 
 
 
177
 
178
  ?>
179
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
180
+ <td class="label">
181
+ <label for=""><?php _e("Choices",'acf'); ?></label>
182
+ <p class="description"><?php _e("Enter your choices one per line",'acf'); ?><br />
183
+ <br />
184
+ <?php _e("Red",'acf'); ?><br />
185
+ <?php _e("Blue",'acf'); ?><br />
186
+ <br />
187
+ <?php _e("red : Red",'acf'); ?><br />
188
+ <?php _e("blue : Blue",'acf'); ?><br />
189
+ </p>
190
+ </td>
191
+ <td>
192
+ <?php
193
+ do_action('acf/create_field', array(
194
+ 'type' => 'textarea',
195
+ 'class' => 'textarea field_option-choices',
196
+ 'name' => 'fields['.$key.'][choices]',
197
+ 'value' => $field['choices'],
198
+ ));
199
+ ?>
200
+ </td>
201
+ </tr>
202
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
203
+ <td class="label">
204
+ <label><?php _e("Default Value",'acf'); ?></label>
205
+ </td>
206
+ <td>
207
+ <?php
208
+ do_action('acf/create_field', array(
209
+ 'type' => 'text',
210
+ 'name' => 'fields['.$key.'][default_value]',
211
+ 'value' => $field['default_value'],
212
+ ));
213
+ ?>
214
+ </td>
215
+ </tr>
216
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
217
+ <td class="label">
218
+ <label><?php _e("Allow Null?",'acf'); ?></label>
219
+ </td>
220
+ <td>
221
+ <?php
222
+ do_action('acf/create_field', array(
223
+ 'type' => 'radio',
224
+ 'name' => 'fields['.$key.'][allow_null]',
225
+ 'value' => $field['allow_null'],
226
+ 'choices' => array(
227
+ 1 => __("Yes",'acf'),
228
+ 0 => __("No",'acf'),
229
+ ),
230
+ 'layout' => 'horizontal',
231
+ ));
232
+ ?>
233
+ </td>
234
+ </tr>
235
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
236
+ <td class="label">
237
+ <label><?php _e("Select multiple values?",'acf'); ?></label>
238
+ </td>
239
+ <td>
240
+ <?php
241
+ do_action('acf/create_field', array(
242
+ 'type' => 'radio',
243
+ 'name' => 'fields['.$key.'][multiple]',
244
+ 'value' => $field['multiple'],
245
+ 'choices' => array(
246
+ 1 => __("Yes",'acf'),
247
+ 0 => __("No",'acf'),
248
+ ),
249
+ 'layout' => 'horizontal',
250
+ ));
251
+ ?>
252
+ </td>
253
+ </tr>
254
+ <?php
255
+
256
  }
257
 
258
 
259
+ /*
260
+ * format_value_for_api()
261
+ *
262
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
263
+ *
264
+ * @type filter
265
+ * @since 3.6
266
+ * @date 23/01/13
267
  *
268
+ * @param $value - the value which was loaded from the database
269
+ * @param $post_id - the $post_id from which the value was loaded
270
+ * @param $field - the field array holding all the field options
271
  *
272
+ * @return $value - the modified value
273
+ */
 
 
274
 
275
+ function format_value_for_api( $value, $post_id, $field )
276
+ {
277
+ if( $value == 'null' )
278
+ {
279
+ $value = false;
280
+ }
281
+
282
+
283
+ return $value;
284
+ }
285
+
286
+
287
+ /*
288
+ * update_field()
289
+ *
290
+ * This filter is appied to the $field before it is saved to the database
291
+ *
292
+ * @type filter
293
+ * @since 3.6
294
+ * @date 23/01/13
295
+ *
296
+ * @param $field - the field array holding all the field options
297
+ * @param $post_id - the field group ID (post_type = acf)
298
+ *
299
+ * @return $field - the modified field
300
+ */
301
+
302
+ function update_field( $field, $post_id )
303
  {
304
  // vars
305
  $defaults = array(
354
  }
355
 
356
 
 
357
  // update choices
358
  $field['choices'] = $new_choices;
359
 
360
 
 
361
  return $field;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  }
363
 
364
  }
365
 
366
+ new acf_field_select();
367
+
368
  ?>
core/fields/tab.php CHANGED
@@ -1,55 +1,62 @@
1
  <?php
2
 
3
- class acf_Tab extends acf_Field
4
  {
5
 
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'tab';
21
- $this->title = __("Tab",'acf');
22
 
23
- }
24
-
25
-
26
- /*--------------------------------------------------------------------------------------
 
 
 
 
 
27
  *
28
- * create_field
29
  *
30
- * @author Elliot Condon
31
- * @since 2.0.5
32
- * @updated 2.2.0
33
- *
34
- *-------------------------------------------------------------------------------------*/
35
 
36
- function create_field($field)
37
  {
38
  echo '<div class="acf-tab" data-id="' . $field['key'] . '">' . $field['label'] . '</div>';
39
  }
40
 
41
 
42
- /*--------------------------------------------------------------------------------------
 
 
 
 
 
43
  *
44
- * create_options
45
  *
46
- * @author Elliot Condon
47
- * @since 2.0.6
48
- * @updated 2.2.0
49
- *
50
- *-------------------------------------------------------------------------------------*/
51
 
52
- function create_options($key, $field)
53
  {
54
  ?>
55
  <tr class="field_option field_option_<?php echo $this->name; ?>">
@@ -62,8 +69,11 @@ class acf_Tab extends acf_Field
62
  </td>
63
  </tr>
64
  <?php
 
65
  }
66
 
67
  }
68
 
 
 
69
  ?>
1
  <?php
2
 
3
+ class acf_field_tab extends acf_field
4
  {
5
 
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'tab';
19
+ $this->label = __("Tab",'acf');
20
+ $this->category = __("Layout",'acf');
21
 
22
+ // do not delete!
23
+ parent::__construct();
24
+ }
25
+
26
+
27
+ /*
28
+ * create_field()
29
+ *
30
+ * Create the HTML interface for your field
31
  *
32
+ * @param $field - an array holding all the field's data
33
  *
34
+ * @type action
35
+ * @since 3.6
36
+ * @date 23/01/13
37
+ */
 
38
 
39
+ function create_field( $field )
40
  {
41
  echo '<div class="acf-tab" data-id="' . $field['key'] . '">' . $field['label'] . '</div>';
42
  }
43
 
44
 
45
+
46
+ /*
47
+ * create_options()
48
+ *
49
+ * Create extra options for your field. This is rendered when editing a field.
50
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
51
  *
52
+ * @param $field - an array holding all the field's data
53
  *
54
+ * @type action
55
+ * @since 3.6
56
+ * @date 23/01/13
57
+ */
 
58
 
59
+ function create_options( $field )
60
  {
61
  ?>
62
  <tr class="field_option field_option_<?php echo $this->name; ?>">
69
  </td>
70
  </tr>
71
  <?php
72
+
73
  }
74
 
75
  }
76
 
77
+ new acf_field_tab();
78
+
79
  ?>
core/fields/taxonomy.php ADDED
@@ -0,0 +1,480 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class acf_field_taxonomy extends acf_field
4
+ {
5
+
6
+ var $defaults;
7
+
8
+
9
+ /*
10
+ * __construct
11
+ *
12
+ * Set name / label needed for actions / filters
13
+ *
14
+ * @since 3.6
15
+ * @date 23/01/13
16
+ */
17
+
18
+ function __construct()
19
+ {
20
+ // vars
21
+ $this->name = 'taxonomy';
22
+ $this->label = __("Taxonomy",'acf');
23
+ $this->category = __("Relational",'acf');
24
+
25
+
26
+ // settings
27
+ $this->defaults = array(
28
+ 'taxonomy' => 'category',
29
+ 'field_type' => 'checkbox',
30
+ 'allow_null' => 0,
31
+ 'load_save_terms' => 0,
32
+ 'return_format' => 'id'
33
+ );
34
+
35
+
36
+ // do not delete!
37
+ parent::__construct();
38
+
39
+ }
40
+
41
+
42
+ /*
43
+ * load_value()
44
+ *
45
+ * This filter is appied to the $value after it is loaded from the db
46
+ *
47
+ * @type filter
48
+ * @since 3.6
49
+ * @date 23/01/13
50
+ *
51
+ * @param $value - the value found in the database
52
+ * @param $post_id - the $post_id from which the value was loaded from
53
+ * @param $field - the field array holding all the field options
54
+ *
55
+ * @return $value - the value to be saved in te database
56
+ */
57
+
58
+ function load_value( $value, $post_id, $field )
59
+ {
60
+ // vars
61
+ $field = array_merge($this->defaults, $field);
62
+
63
+
64
+ if( $field['load_save_terms'] )
65
+ {
66
+ $value = array();
67
+
68
+ $terms = get_the_terms( $post_id, $field['taxonomy'] );
69
+
70
+ if( is_array($terms) ){ foreach( $terms as $term ){
71
+
72
+ $value[] = $term->term_id;
73
+
74
+ }}
75
+
76
+ }
77
+
78
+
79
+ return $value;
80
+ }
81
+
82
+
83
+ /*
84
+ * update_value()
85
+ *
86
+ * This filter is appied to the $value before it is updated in the db
87
+ *
88
+ * @type filter
89
+ * @since 3.6
90
+ * @date 23/01/13
91
+ *
92
+ * @param $value - the value which will be saved in the database
93
+ * @param $field - the field array holding all the field options
94
+ * @param $post_id - the $post_id of which the value will be saved
95
+ *
96
+ * @return $value - the modified value
97
+ */
98
+
99
+ function update_value( $value, $post_id, $field )
100
+ {
101
+ // vars
102
+ $field = array_merge($this->defaults, $field);
103
+ if( is_array($value) )
104
+ {
105
+ $value = array_filter($value);
106
+ }
107
+
108
+
109
+ if( $field['load_save_terms'] )
110
+ {
111
+ wp_set_object_terms( $post_id, $value, $field['taxonomy'], false );
112
+ }
113
+
114
+
115
+ return $value;
116
+ }
117
+
118
+
119
+ /*
120
+ * format_value_for_api()
121
+ *
122
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
123
+ *
124
+ * @type filter
125
+ * @since 3.6
126
+ * @date 23/01/13
127
+ *
128
+ * @param $value - the value which was loaded from the database
129
+ * @param $post_id - the $post_id from which the value was loaded
130
+ * @param $field - the field array holding all the field options
131
+ *
132
+ * @return $value - the modified value
133
+ */
134
+
135
+ function format_value_for_api( $value, $post_id, $field )
136
+ {
137
+ // defaults
138
+ $field = array_merge($this->defaults, $field);
139
+
140
+
141
+ // temp convert to array
142
+ $is_array = true;
143
+
144
+ if( !is_array($value) )
145
+ {
146
+ $is_array = false;
147
+ $value = array( $value );
148
+ }
149
+
150
+
151
+ // format
152
+ if( $field['return_format'] == 'object' )
153
+ {
154
+ foreach( $value as $k => $v )
155
+ {
156
+ $value[ $k ] = get_term( $v, $field['taxonomy'] );
157
+ }
158
+ }
159
+
160
+
161
+ // de-convert from array
162
+ if( !$is_array && isset($value[0]) )
163
+ {
164
+ $value = $value[0];
165
+ }
166
+
167
+ // Note: This function can be removed if not used
168
+ return $value;
169
+ }
170
+
171
+
172
+ /*
173
+ * create_field()
174
+ *
175
+ * Create the HTML interface for your field
176
+ *
177
+ * @type action
178
+ * @since 3.6
179
+ * @date 23/01/13
180
+ *
181
+ * @param $field - an array holding all the field's data
182
+ */
183
+
184
+ function create_field( $field )
185
+ {
186
+ // vars
187
+ $field = array_merge($this->defaults, $field);
188
+ $single_name = $field['name'];
189
+
190
+
191
+ // multi select?
192
+ if( $field['field_type'] == 'multi_select' )
193
+ {
194
+ $field['multiple'] = 1;
195
+ $field['field_type'] = 'select';
196
+ $field['name'] .= '[]';
197
+ }
198
+ elseif( $field['field_type'] == 'checkbox' )
199
+ {
200
+ $field['name'] .= '[]';
201
+ }
202
+
203
+ // value must be array!
204
+ if( !is_array($field['value']) )
205
+ {
206
+ $field['value'] = array( $field['value'] );
207
+ }
208
+
209
+ ?>
210
+ <div class="acf-taxonomy-field">
211
+ <input type="hidden" name="<?php echo $single_name; ?>" value="" />
212
+
213
+ <?php if( $field['field_type'] == 'select' ): ?>
214
+
215
+ <select name="<?php echo $field['name']; ?>" <?php if( $field['multiple'] ): ?>multiple="multiple" size="5"<?php endif; ?>>
216
+ <?php if( $field['allow_null'] ): ?>
217
+ <option value=""><?php _e("None", 'acf'); ?></option>
218
+ <?php endif; ?>
219
+
220
+ <?php else: ?>
221
+ <div class="categorychecklist-holder">
222
+ <ul class="categorychecklist">
223
+ <?php if( $field['allow_null'] ): ?>
224
+ <li>
225
+ <label class="selectit">
226
+ <input type="<?php echo $field['field_type']; ?>" name="<?php echo $field['name']; ?>" value="" /> <?php _e("None", 'acf'); ?>
227
+ </label>
228
+ </li>
229
+ <?php endif; ?>
230
+
231
+ <?php endif; ?>
232
+
233
+ <?php
234
+
235
+ wp_list_categories( array(
236
+ 'taxonomy' => $field['taxonomy'],
237
+ 'hide_empty' => false,
238
+ 'style' => 'none',
239
+ 'walker' => new acf_taxonomy_field_walker( $field ),
240
+ ));
241
+
242
+ ?>
243
+
244
+ <?php if( $field['field_type'] == 'select' ): ?>
245
+
246
+ </select>
247
+
248
+ <?php else: ?>
249
+
250
+ </ul>
251
+ </div>
252
+
253
+ <?php endif; ?>
254
+
255
+ </div>
256
+ <?php
257
+
258
+ }
259
+
260
+
261
+ /*
262
+ * create_options()
263
+ *
264
+ * Create extra options for your field. This is rendered when editing a field.
265
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
266
+ *
267
+ * @type action
268
+ * @since 3.6
269
+ * @date 23/01/13
270
+ *
271
+ * @param $field - an array holding all the field's data
272
+ */
273
+
274
+ function create_options( $field )
275
+ {
276
+ // vars
277
+ $field = array_merge($this->defaults, $field);
278
+ $key = $field['name'];
279
+
280
+ ?>
281
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
282
+ <td class="label">
283
+ <label><?php _e("Taxonomy",'acf'); ?></label>
284
+ </td>
285
+ <td>
286
+ <?php
287
+
288
+ $choices = array();
289
+ $taxonomies = get_taxonomies( array('public' => true), 'objects' );
290
+
291
+ foreach($taxonomies as $taxonomy)
292
+ {
293
+ $choices[ $taxonomy->name ] = $taxonomy->labels->name;
294
+ }
295
+
296
+ // unset post_format (why is this a public taxonomy?)
297
+ if( isset($choices['post_format']) )
298
+ {
299
+ unset( $choices['post_format']) ;
300
+ }
301
+
302
+ do_action('acf/create_field', array(
303
+ 'type' => 'select',
304
+ 'name' => 'fields['.$key.'][taxonomy]',
305
+ 'value' => $field['taxonomy'],
306
+ 'choices' => $choices,
307
+ ));
308
+ ?>
309
+ </td>
310
+ </tr>
311
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
312
+ <td class="label">
313
+ <label><?php _e("Field Type",'acf'); ?></label>
314
+ </td>
315
+ <td>
316
+ <?php
317
+ do_action('acf/create_field', array(
318
+ 'type' => 'select',
319
+ 'name' => 'fields['.$key.'][field_type]',
320
+ 'value' => $field['field_type'],
321
+ 'optgroup' => true,
322
+ 'choices' => array(
323
+ __("Multiple Values",'acf') => array(
324
+ 'checkbox' => __('Checkbox', 'acf'),
325
+ 'multi_select' => __('Multi Select', 'acf')
326
+ ),
327
+ __("Single Value",'acf') => array(
328
+ 'radio' => __('Radio Buttons', 'acf'),
329
+ 'select' => __('Select', 'acf')
330
+ )
331
+ )
332
+ ));
333
+ ?>
334
+ </td>
335
+ </tr>
336
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
337
+ <td class="label">
338
+ <label><?php _e("Allow Null?",'acf'); ?></label>
339
+ </td>
340
+ <td>
341
+ <?php
342
+ do_action('acf/create_field', array(
343
+ 'type' => 'radio',
344
+ 'name' => 'fields['.$key.'][allow_null]',
345
+ 'value' => $field['allow_null'],
346
+ 'choices' => array(
347
+ 1 => __("Yes",'acf'),
348
+ 0 => __("No",'acf'),
349
+ ),
350
+ 'layout' => 'horizontal',
351
+ ));
352
+ ?>
353
+ </td>
354
+ </tr>
355
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
356
+ <td class="label">
357
+ <label><?php _e("Load & Save Terms to Post",'acf'); ?></label>
358
+ </td>
359
+ <td>
360
+ <?php
361
+ do_action('acf/create_field', array(
362
+ 'type' => 'true_false',
363
+ 'name' => 'fields['.$key.'][load_save_terms]',
364
+ 'value' => $field['load_save_terms'],
365
+ 'message' => __("Load value based on the post's terms and update the post's terms on save",'acf')
366
+ ));
367
+ ?>
368
+ </td>
369
+ </tr>
370
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
371
+ <td class="label">
372
+ <label><?php _e("Return Value",'acf'); ?></label>
373
+ </td>
374
+ <td>
375
+ <?php
376
+ do_action('acf/create_field', array(
377
+ 'type' => 'radio',
378
+ 'name' => 'fields['.$key.'][return_format]',
379
+ 'value' => $field['return_format'],
380
+ 'layout' => 'horizontal',
381
+ 'choices' => array(
382
+ 'object' => __("Term Object",'acf'),
383
+ 'id' => __("Term ID",'acf')
384
+ )
385
+ ));
386
+ ?>
387
+ </td>
388
+ </tr>
389
+ <?php
390
+
391
+ }
392
+
393
+
394
+ }
395
+
396
+ new acf_field_taxonomy();
397
+
398
+
399
+ class acf_taxonomy_field_walker extends Walker
400
+ {
401
+ // vars
402
+ var $field = null,
403
+ $tree_type = 'category',
404
+ $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' );
405
+
406
+
407
+ // construct
408
+ function __construct( $field )
409
+ {
410
+ $this->field = $field;
411
+ }
412
+
413
+
414
+ // start_el
415
+ function start_el( &$output, $term, $depth, $args = array() )
416
+ {
417
+ // vars
418
+ $selected = in_array( $term->term_id, $this->field['value'] );
419
+
420
+ if( $this->field['field_type'] == 'checkbox' )
421
+ {
422
+ $output .= '<li><label class="selectit"><input type="checkbox" name="' . $this->field['name'] . '" value="' . $term->term_id . '" ' . ($selected ? 'checked="checked"' : '') . ' /> ' . $term->name . '</span>';
423
+ }
424
+ elseif( $this->field['field_type'] == 'radio' )
425
+ {
426
+ $output .= '<li><label class="selectit"><input type="radio" name="' . $this->field['name'] . '" value="' . $term->term_id . '" ' . ($selected ? 'checked="checkbox"' : '') . ' /> ' . $term->name . '</span>';
427
+ }
428
+ elseif( $this->field['field_type'] == 'select' )
429
+ {
430
+ $indent = str_repeat("&mdash;", $depth);
431
+ $output .= '<option value="' . $term->term_id . '" ' . ($selected ? 'selected="selected"' : '') . '>' . $indent . ' ' . $term->name . '</option>';
432
+ }
433
+
434
+ }
435
+
436
+
437
+ //end_el
438
+ function end_el( &$output, $term, $depth, $args = array() )
439
+ {
440
+ if( in_array($this->field['field_type'], array('checkbox', 'radio')) )
441
+ {
442
+ $output .= '</li>';
443
+ }
444
+
445
+ $output .= "\n";
446
+ }
447
+
448
+
449
+ // start_lvl
450
+ function start_lvl( &$output, $depth = 0, $args = array() )
451
+ {
452
+ // indent
453
+ //$output .= str_repeat( "\t", $depth);
454
+
455
+
456
+ // wrap element
457
+ if( in_array($this->field['field_type'], array('checkbox', 'radio')) )
458
+ {
459
+ $output .= '<li><ul class="children">' . "\n";
460
+ }
461
+ }
462
+
463
+
464
+ // end_lvl
465
+ function end_lvl( &$output, $depth = 0, $args = array() )
466
+ {
467
+ // indent
468
+ //$output .= str_repeat( "\t", $depth);
469
+
470
+
471
+ // wrap element
472
+ if( in_array($this->field['field_type'], array('checkbox', 'radio')) )
473
+ {
474
+ $output .= '</ul></li>' . "\n";
475
+ }
476
+ }
477
+
478
+ }
479
+
480
+ ?>
core/fields/text.php CHANGED
@@ -1,55 +1,62 @@
1
  <?php
2
 
3
- class acf_Text extends acf_Field
4
  {
5
 
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'text';
21
- $this->title = __("Text",'acf');
22
 
23
- }
24
-
25
-
26
- /*--------------------------------------------------------------------------------------
 
 
 
 
 
 
 
27
  *
28
- * create_field
29
  *
30
- * @author Elliot Condon
31
- * @since 2.0.5
32
- * @updated 2.2.0
33
- *
34
- *-------------------------------------------------------------------------------------*/
35
 
36
- function create_field($field)
37
  {
38
  echo '<input type="text" value="' . esc_attr( $field['value'] ) . '" id="' . esc_attr( $field['id'] ) . '" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" />';
39
  }
40
 
41
 
42
- /*--------------------------------------------------------------------------------------
 
 
 
 
43
  *
44
- * create_options
45
  *
46
- * @author Elliot Condon
47
- * @since 2.0.6
48
- * @updated 2.2.0
49
- *
50
- *-------------------------------------------------------------------------------------*/
51
 
52
- function create_options($key, $field)
53
  {
54
  // vars
55
  $defaults = array(
@@ -58,73 +65,88 @@ class acf_Text extends acf_Field
58
  );
59
 
60
  $field = array_merge($defaults, $field);
61
-
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  ?>
63
- <tr class="field_option field_option_<?php echo $this->name; ?>">
64
- <td class="label">
65
- <label><?php _e("Default Value",'acf'); ?></label>
66
- </td>
67
- <td>
68
- <?php
69
- do_action('acf/create_field', array(
70
- 'type' => 'text',
71
- 'name' => 'fields['.$key.'][default_value]',
72
- 'value' => $field['default_value'],
73
- ));
74
- ?>
75
- </td>
76
- </tr>
77
- <tr class="field_option field_option_<?php echo $this->name; ?>">
78
- <td class="label">
79
- <label><?php _e("Formatting",'acf'); ?></label>
80
- <p class="description"><?php _e("Define how to render html tags",'acf'); ?></p>
81
- </td>
82
- <td>
83
- <?php
84
- do_action('acf/create_field', array(
85
- 'type' => 'select',
86
- 'name' => 'fields['.$key.'][formatting]',
87
- 'value' => $field['formatting'],
88
- 'choices' => array(
89
- 'none' => __("None",'acf'),
90
- 'html' => __("HTML",'acf')
91
- )
92
- ));
93
- ?>
94
- </td>
95
- </tr>
96
  <?php
 
97
  }
98
 
99
 
100
- /*--------------------------------------------------------------------------------------
 
 
 
101
  *
102
- * get_value
 
 
103
  *
104
- * @author Elliot Condon
105
- * @since 2.2.0
106
- *
107
- *-------------------------------------------------------------------------------------*/
 
 
108
 
109
- function get_value($post_id, $field)
110
  {
111
- $value = parent::get_value($post_id, $field);
112
-
113
  $value = htmlspecialchars($value, ENT_QUOTES);
114
 
115
  return $value;
116
  }
117
 
118
- /*--------------------------------------------------------------------------------------
 
 
119
  *
120
- * get_value_for_api
121
  *
122
- * @author Elliot Condon
123
- * @since 3.0.0
124
- *
125
- *-------------------------------------------------------------------------------------*/
 
 
 
 
 
 
126
 
127
- function get_value_for_api($post_id, $field)
128
  {
129
  // vars
130
  $defaults = array(
@@ -134,10 +156,6 @@ class acf_Text extends acf_Field
134
  $field = array_merge($defaults, $field);
135
 
136
 
137
- // load value
138
- $value = parent::get_value($post_id, $field);
139
-
140
-
141
  // validate type
142
  if( !is_string($value) )
143
  {
@@ -154,9 +172,12 @@ class acf_Text extends acf_Field
154
  $value = nl2br($value);
155
  }
156
 
 
157
  return $value;
158
  }
159
 
160
  }
161
 
 
 
162
  ?>
1
  <?php
2
 
3
+ class acf_field_text extends acf_field
4
  {
5
 
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'text';
19
+ $this->label = __("Text",'acf');
 
20
 
21
+
22
+ // do not delete!
23
+ parent::__construct();
24
+ }
25
+
26
+
27
+
28
+ /*
29
+ * create_field()
30
+ *
31
+ * Create the HTML interface for your field
32
  *
33
+ * @param $field - an array holding all the field's data
34
  *
35
+ * @type action
36
+ * @since 3.6
37
+ * @date 23/01/13
38
+ */
 
39
 
40
+ function create_field( $field )
41
  {
42
  echo '<input type="text" value="' . esc_attr( $field['value'] ) . '" id="' . esc_attr( $field['id'] ) . '" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" />';
43
  }
44
 
45
 
46
+ /*
47
+ * create_options()
48
+ *
49
+ * Create extra options for your field. This is rendered when editing a field.
50
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
51
  *
52
+ * @param $field - an array holding all the field's data
53
  *
54
+ * @type action
55
+ * @since 3.6
56
+ * @date 23/01/13
57
+ */
 
58
 
59
+ function create_options( $field )
60
  {
61
  // vars
62
  $defaults = array(
65
  );
66
 
67
  $field = array_merge($defaults, $field);
68
+ $key = $field['name'];
69
+
70
+ ?>
71
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
72
+ <td class="label">
73
+ <label><?php _e("Default Value",'acf'); ?></label>
74
+ </td>
75
+ <td>
76
+ <?php
77
+ do_action('acf/create_field', array(
78
+ 'type' => 'text',
79
+ 'name' => 'fields[' .$key.'][default_value]',
80
+ 'value' => $field['default_value'],
81
+ ));
82
  ?>
83
+ </td>
84
+ </tr>
85
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
86
+ <td class="label">
87
+ <label><?php _e("Formatting",'acf'); ?></label>
88
+ <p class="description"><?php _e("Define how to render html tags",'acf'); ?></p>
89
+ </td>
90
+ <td>
91
+ <?php
92
+ do_action('acf/create_field', array(
93
+ 'type' => 'select',
94
+ 'name' => 'fields['.$key.'][formatting]',
95
+ 'value' => $field['formatting'],
96
+ 'choices' => array(
97
+ 'none' => __("None",'acf'),
98
+ 'html' => __("HTML",'acf')
99
+ )
100
+ ));
101
+ ?>
102
+ </td>
103
+ </tr>
 
 
 
 
 
 
 
 
 
 
 
 
104
  <?php
105
+
106
  }
107
 
108
 
109
+ /*
110
+ * format_value()
111
+ *
112
+ * This filter is appied to the $value after it is loaded from the db and before it is passed to the create_field action
113
  *
114
+ * @type filter
115
+ * @since 3.6
116
+ * @date 23/01/13
117
  *
118
+ * @param $value - the value which was loaded from the database
119
+ * @param $post_id - the $post_id from which the value was loaded
120
+ * @param $field - the field array holding all the field options
121
+ *
122
+ * @return $value - the modified value
123
+ */
124
 
125
+ function format_value( $value, $post_id, $field )
126
  {
 
 
127
  $value = htmlspecialchars($value, ENT_QUOTES);
128
 
129
  return $value;
130
  }
131
 
132
+
133
+ /*
134
+ * format_value_for_api()
135
  *
136
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
137
  *
138
+ * @type filter
139
+ * @since 3.6
140
+ * @date 23/01/13
141
+ *
142
+ * @param $value - the value which was loaded from the database
143
+ * @param $post_id - the $post_id from which the value was loaded
144
+ * @param $field - the field array holding all the field options
145
+ *
146
+ * @return $value - the modified value
147
+ */
148
 
149
+ function format_value_for_api( $value, $post_id, $field )
150
  {
151
  // vars
152
  $defaults = array(
156
  $field = array_merge($defaults, $field);
157
 
158
 
 
 
 
 
159
  // validate type
160
  if( !is_string($value) )
161
  {
172
  $value = nl2br($value);
173
  }
174
 
175
+
176
  return $value;
177
  }
178
 
179
  }
180
 
181
+ new acf_field_text();
182
+
183
  ?>
core/fields/textarea.php CHANGED
@@ -1,112 +1,129 @@
1
  <?php
2
 
3
- class acf_Textarea extends acf_Field
4
  {
5
-
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'textarea';
21
- $this->title = __("Text Area",'acf');
22
 
23
- }
24
-
25
-
26
- /*--------------------------------------------------------------------------------------
 
 
 
27
  *
28
- * create_field
29
  *
30
- * @author Elliot Condon
31
- * @since 2.0.5
32
- * @updated 2.2.0
33
- *
34
- *-------------------------------------------------------------------------------------*/
 
35
 
36
- function create_field($field)
37
  {
38
- // remove unwanted <br /> tags
39
- //$field['value'] = str_replace('<br />','',$field['value']);
40
  $field['value'] = esc_textarea($field['value']);
41
 
42
  echo '<textarea id="' . $field['id'] . '" rows="4" class="' . $field['class'] . '" name="' . $field['name'] . '" >' . $field['value'] . '</textarea>';
43
  }
44
 
45
-
46
- /*--------------------------------------------------------------------------------------
 
 
 
47
  *
48
- * create_options
49
  *
50
- * @author Elliot Condon
51
- * @since 2.0.6
52
- *
53
- *-------------------------------------------------------------------------------------*/
54
 
55
- function create_options($key, $field)
56
  {
57
- // defaults
58
- $field['default_value'] = isset($field['default_value']) ? $field['default_value'] : '';
59
- $field['formatting'] = isset($field['formatting']) ? $field['formatting'] : 'br';
 
 
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  ?>
62
- <tr class="field_option field_option_<?php echo $this->name; ?>">
63
- <td class="label">
64
- <label><?php _e("Default Value",'acf'); ?></label>
65
- </td>
66
- <td>
67
- <?php
68
- do_action('acf/create_field', array(
69
- 'type' => 'textarea',
70
- 'name' => 'fields['.$key.'][default_value]',
71
- 'value' => $field['default_value'],
72
- ));
73
- ?>
74
- </td>
75
- </tr>
76
- <tr class="field_option field_option_<?php echo $this->name; ?>">
77
- <td class="label">
78
- <label><?php _e("Formatting",'acf'); ?></label>
79
- <p class="description"><?php _e("Define how to render html tags / new lines",'acf'); ?></p>
80
- </td>
81
- <td>
82
- <?php
83
- do_action('acf/create_field', array(
84
- 'type' => 'select',
85
- 'name' => 'fields['.$key.'][formatting]',
86
- 'value' => $field['formatting'],
87
- 'choices' => array(
88
- 'none' => __("None",'acf'),
89
- 'br' => __("auto &lt;br /&gt;",'acf'),
90
- 'html' => __("HTML",'acf'),
91
- )
92
- ));
93
- ?>
94
- </td>
95
- </tr>
96
  <?php
 
97
  }
98
 
99
 
100
- /*--------------------------------------------------------------------------------------
 
101
  *
102
- * get_value_for_api
103
  *
104
- * @author Elliot Condon
105
- * @since 3.0.0
106
- *
107
- *-------------------------------------------------------------------------------------*/
 
 
 
 
 
 
108
 
109
- function get_value_for_api($post_id, $field)
110
  {
111
  // vars
112
  $defaults = array(
@@ -116,10 +133,6 @@ class acf_Textarea extends acf_Field
116
  $field = array_merge($defaults, $field);
117
 
118
 
119
- // load value
120
- $value = parent::get_value($post_id, $field);
121
-
122
-
123
  // validate type
124
  if( !is_string($value) )
125
  {
@@ -127,23 +140,27 @@ class acf_Textarea extends acf_Field
127
  }
128
 
129
 
130
- if($field['formatting'] == 'none')
131
  {
132
  $value = htmlspecialchars($value, ENT_QUOTES);
133
  }
134
- elseif($field['formatting'] == 'html')
135
  {
136
  //$value = html_entity_decode($value);
137
  //$value = nl2br($value);
138
  }
139
- elseif($field['formatting'] == 'br')
140
  {
141
  $value = htmlspecialchars($value, ENT_QUOTES);
142
  $value = nl2br($value);
143
  }
144
-
 
145
  return $value;
146
  }
 
147
  }
148
 
 
 
149
  ?>
1
  <?php
2
 
3
+ class acf_field_textarea extends acf_field
4
  {
5
+
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'textarea';
19
+ $this->label = __("Text Area",'acf');
20
+
21
 
22
+ // do not delete!
23
+ parent::__construct();
24
+ }
25
+
26
+
27
+ /*
28
+ * create_field()
29
  *
30
+ * Create the HTML interface for your field
31
  *
32
+ * @param $field - an array holding all the field's data
33
+ *
34
+ * @type action
35
+ * @since 3.6
36
+ * @date 23/01/13
37
+ */
38
 
39
+ function create_field( $field )
40
  {
 
 
41
  $field['value'] = esc_textarea($field['value']);
42
 
43
  echo '<textarea id="' . $field['id'] . '" rows="4" class="' . $field['class'] . '" name="' . $field['name'] . '" >' . $field['value'] . '</textarea>';
44
  }
45
 
46
+ /*
47
+ * create_options()
48
+ *
49
+ * Create extra options for your field. This is rendered when editing a field.
50
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
51
  *
52
+ * @param $field - an array holding all the field's data
53
  *
54
+ * @type action
55
+ * @since 3.6
56
+ * @date 23/01/13
57
+ */
58
 
59
+ function create_options( $field )
60
  {
61
+ // vars
62
+ $defaults = array(
63
+ 'default_value' => '',
64
+ 'formatting' => 'br',
65
+ );
66
 
67
+ $field = array_merge($defaults, $field);
68
+ $key = $field['name'];
69
+
70
+ ?>
71
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
72
+ <td class="label">
73
+ <label><?php _e("Default Value",'acf'); ?></label>
74
+ </td>
75
+ <td>
76
+ <?php
77
+ do_action('acf/create_field', array(
78
+ 'type' => 'textarea',
79
+ 'name' => 'fields['.$key.'][default_value]',
80
+ 'value' => $field['default_value'],
81
+ ));
82
  ?>
83
+ </td>
84
+ </tr>
85
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
86
+ <td class="label">
87
+ <label><?php _e("Formatting",'acf'); ?></label>
88
+ <p class="description"><?php _e("Define how to render html tags / new lines",'acf'); ?></p>
89
+ </td>
90
+ <td>
91
+ <?php
92
+ do_action('acf/create_field', array(
93
+ 'type' => 'select',
94
+ 'name' => 'fields['.$key.'][formatting]',
95
+ 'value' => $field['formatting'],
96
+ 'choices' => array(
97
+ 'none' => __("None",'acf'),
98
+ 'br' => __("auto &lt;br /&gt;",'acf'),
99
+ 'html' => __("HTML",'acf'),
100
+ )
101
+ ));
102
+ ?>
103
+ </td>
104
+ </tr>
 
 
 
 
 
 
 
 
 
 
 
 
105
  <?php
106
+
107
  }
108
 
109
 
110
+ /*
111
+ * format_value_for_api()
112
  *
113
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
114
  *
115
+ * @type filter
116
+ * @since 3.6
117
+ * @date 23/01/13
118
+ *
119
+ * @param $value - the value which was loaded from the database
120
+ * @param $post_id - the $post_id from which the value was loaded
121
+ * @param $field - the field array holding all the field options
122
+ *
123
+ * @return $value - the modified value
124
+ */
125
 
126
+ function format_value_for_api( $value, $post_id, $field )
127
  {
128
  // vars
129
  $defaults = array(
133
  $field = array_merge($defaults, $field);
134
 
135
 
 
 
 
 
136
  // validate type
137
  if( !is_string($value) )
138
  {
140
  }
141
 
142
 
143
+ if( $field['formatting'] == 'none' )
144
  {
145
  $value = htmlspecialchars($value, ENT_QUOTES);
146
  }
147
+ elseif( $field['formatting'] == 'html' )
148
  {
149
  //$value = html_entity_decode($value);
150
  //$value = nl2br($value);
151
  }
152
+ elseif( $field['formatting'] == 'br' )
153
  {
154
  $value = htmlspecialchars($value, ENT_QUOTES);
155
  $value = nl2br($value);
156
  }
157
+
158
+
159
  return $value;
160
  }
161
+
162
  }
163
 
164
+ new acf_field_textarea();
165
+
166
  ?>
core/fields/true_false.php CHANGED
@@ -1,42 +1,52 @@
1
  <?php
2
 
3
- class acf_True_false extends acf_Field
4
  {
5
 
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'true_false';
21
- $this->title = __("True / False",'acf');
22
 
23
- }
24
-
25
-
26
- /*--------------------------------------------------------------------------------------
 
 
 
 
 
27
  *
28
- * create_field
29
  *
30
- * @author Elliot Condon
31
- * @since 2.0.5
32
- * @updated 2.2.0
33
- *
34
- *-------------------------------------------------------------------------------------*/
 
35
 
36
- function create_field($field)
37
  {
38
  // vars
39
- $field['message'] = isset($field['message']) ? $field['message'] : '';
 
 
 
 
 
40
 
41
  // html
42
  echo '<ul class="checkbox_list ' . $field['class'] . '">';
@@ -45,22 +55,24 @@ class acf_True_false extends acf_Field
45
  echo '<li><label><input id="' . $field['id'] . '-1" type="checkbox" name="'.$field['name'].'" value="1" ' . $selected . ' />' . $field['message'] . '</label></li>';
46
 
47
  echo '</ul>';
48
-
49
  }
50
 
51
 
52
- /*--------------------------------------------------------------------------------------
 
 
 
 
53
  *
54
- * create_options
 
 
55
  *
56
- * @author Elliot Condon
57
- * @since 2.0.6
58
- * @updated 2.2.0
59
- *
60
- *-------------------------------------------------------------------------------------*/
61
 
62
- function create_options($key, $field)
63
- {
64
  // vars
65
  $defaults = array(
66
  'default_value' => 0,
@@ -68,6 +80,7 @@ class acf_True_false extends acf_Field
68
  );
69
 
70
  $field = array_merge($defaults, $field);
 
71
 
72
 
73
  ?>
@@ -103,33 +116,35 @@ class acf_True_false extends acf_Field
103
  </td>
104
  </tr>
105
  <?php
 
106
  }
107
-
108
-
109
- /*--------------------------------------------------------------------------------------
 
 
 
 
 
 
 
110
  *
111
- * get_value_for_api
 
 
112
  *
113
- * @author Elliot Condon
114
- * @since 3.0.0
115
- *
116
- *-------------------------------------------------------------------------------------*/
117
 
118
- function get_value_for_api($post_id, $field)
119
  {
120
- // get value
121
- $value = parent::get_value($post_id, $field);
122
 
123
- if($value == 1)
124
- {
125
- return true;
126
- }
127
- else
128
- {
129
- return false;
130
- }
131
  }
132
-
133
  }
134
 
 
 
135
  ?>
1
  <?php
2
 
3
+ class acf_field_true_false extends acf_field
4
  {
5
 
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'true_false';
19
+ $this->label = __("True / False",'acf');
20
+ $this->category = __("Choice",'acf');
21
 
22
+
23
+ // do not delete!
24
+ parent::__construct();
25
+
26
+ }
27
+
28
+
29
+ /*
30
+ * create_field()
31
  *
32
+ * Create the HTML interface for your field
33
  *
34
+ * @param $field - an array holding all the field's data
35
+ *
36
+ * @type action
37
+ * @since 3.6
38
+ * @date 23/01/13
39
+ */
40
 
41
+ function create_field( $field )
42
  {
43
  // vars
44
+ $defaults = array(
45
+ 'message' => '',
46
+ );
47
+
48
+ $field = array_merge($defaults, $field);
49
+
50
 
51
  // html
52
  echo '<ul class="checkbox_list ' . $field['class'] . '">';
55
  echo '<li><label><input id="' . $field['id'] . '-1" type="checkbox" name="'.$field['name'].'" value="1" ' . $selected . ' />' . $field['message'] . '</label></li>';
56
 
57
  echo '</ul>';
 
58
  }
59
 
60
 
61
+ /*
62
+ * create_options()
63
+ *
64
+ * Create extra options for your field. This is rendered when editing a field.
65
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
66
  *
67
+ * @type action
68
+ * @since 3.6
69
+ * @date 23/01/13
70
  *
71
+ * @param $field - an array holding all the field's data
72
+ */
 
 
 
73
 
74
+ function create_options( $field )
75
+ {
76
  // vars
77
  $defaults = array(
78
  'default_value' => 0,
80
  );
81
 
82
  $field = array_merge($defaults, $field);
83
+ $key = $field['name'];
84
 
85
 
86
  ?>
116
  </td>
117
  </tr>
118
  <?php
119
+
120
  }
121
+
122
+
123
+ /*
124
+ * format_value_for_api()
125
+ *
126
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
127
+ *
128
+ * @type filter
129
+ * @since 3.6
130
+ * @date 23/01/13
131
  *
132
+ * @param $value - the value which was loaded from the database
133
+ * @param $post_id - the $post_id from which the value was loaded
134
+ * @param $field - the field array holding all the field options
135
  *
136
+ * @return $value - the modified value
137
+ */
 
 
138
 
139
+ function format_value_for_api( $value, $post_id, $field )
140
  {
141
+ $value = ($value == 1) ? true : false;
 
142
 
143
+ return $value;
 
 
 
 
 
 
 
144
  }
145
+
146
  }
147
 
148
+ new acf_field_true_false();
149
+
150
  ?>
core/fields/user.php ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class acf_field_user extends acf_field
4
+ {
5
+
6
+ var $defaults;
7
+
8
+
9
+ /*
10
+ * __construct
11
+ *
12
+ * Set name / label needed for actions / filters
13
+ *
14
+ * @since 3.6
15
+ * @date 23/01/13
16
+ */
17
+
18
+ function __construct()
19
+ {
20
+ // vars
21
+ $this->name = 'user';
22
+ $this->label = __("User",'acf');
23
+ $this->category = __("Relational",'acf');
24
+
25
+
26
+ // settings
27
+ $this->defaults = array(
28
+ 'role' => 'all',
29
+ 'field_type' => 'select',
30
+ 'allow_null' => 0,
31
+ );
32
+
33
+
34
+ // do not delete!
35
+ parent::__construct();
36
+
37
+ }
38
+
39
+
40
+ /*
41
+ * format_value_for_api()
42
+ *
43
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
44
+ *
45
+ * @type filter
46
+ * @since 3.6
47
+ * @date 23/01/13
48
+ *
49
+ * @param $value - the value which was loaded from the database
50
+ * @param $field - the field array holding all the field options
51
+ *
52
+ * @return $value - the modified value
53
+ */
54
+
55
+ function format_value_for_api( $value, $field )
56
+ {
57
+
58
+ // format value
59
+ if( !$value || $value == 'null' )
60
+ {
61
+ return false;
62
+ }
63
+
64
+
65
+ // temp convert to array
66
+ $is_array = true;
67
+
68
+ if( !is_array($value) )
69
+ {
70
+ $is_array = false;
71
+ $value = array( $value );
72
+ }
73
+
74
+
75
+ foreach( $value as $k => $v )
76
+ {
77
+ $user_data = get_userdata( $v );
78
+
79
+ //cope with deleted users by @adampope
80
+ if( !is_object($user_data) )
81
+ {
82
+ unset( $value[$k] );
83
+ continue;
84
+ }
85
+
86
+
87
+ $value[ $k ] = array();
88
+ $value[ $k ]['ID'] = $v;
89
+ $value[ $k ]['user_firstname'] = $user_data->user_firstname;
90
+ $value[ $k ]['user_lastname'] = $user_data->user_lastname;
91
+ $value[ $k ]['nickname'] = $user_data->nickname;
92
+ $value[ $k ]['user_nicename'] = $user_data->user_nicename;
93
+ $value[ $k ]['display_name'] = $user_data->display_name;
94
+ $value[ $k ]['user_email'] = $user_data->user_email;
95
+ $value[ $k ]['user_url'] = $user_data->user_url;
96
+ $value[ $k ]['user_registered'] = $user_data->user_registered;
97
+ $value[ $k ]['user_description'] = $user_data->user_description;
98
+ $value[ $k ]['user_avatar'] = get_avatar( $v );
99
+
100
+ }
101
+
102
+
103
+ // de-convert from array
104
+ if( !$is_array && isset($value[0]) )
105
+ {
106
+ $value = $value[0];
107
+ }
108
+
109
+
110
+ // return value
111
+ return $value;
112
+
113
+ }
114
+
115
+
116
+ /*
117
+ * input_admin_head()
118
+ *
119
+ * This action is called in the admin_head action on the edit screen where your field is created.
120
+ * Use this action to add css and javascript to assist your create_field() action.
121
+ *
122
+ * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head
123
+ * @type action
124
+ * @since 3.6
125
+ * @date 23/01/13
126
+ */
127
+
128
+ function input_admin_head()
129
+ {
130
+ if( ! function_exists( 'get_editable_roles' ) )
131
+ {
132
+ // if using front-end forms then we need to add this core file
133
+ require_once( ABSPATH . '/wp-admin/includes/user.php' );
134
+ }
135
+ }
136
+
137
+
138
+ /*
139
+ * create_field()
140
+ *
141
+ * Create the HTML interface for your field
142
+ *
143
+ * @type action
144
+ * @since 3.6
145
+ * @date 23/01/13
146
+ *
147
+ * @param $field - an array holding all the field's data
148
+ */
149
+
150
+ function create_field( $field )
151
+ {
152
+ // vars
153
+ $field = array_merge($this->defaults, $field);
154
+ $field['choices'] = array();
155
+ $args = array();
156
+ $editable_roles = get_editable_roles();
157
+
158
+
159
+ // roles
160
+ if( !$field['role'] || !is_array( $field['role'] ) || $field['role'][0] == 'all' )
161
+ {
162
+ $field['role'] = array();
163
+
164
+
165
+ foreach( $editable_roles as $role => $details )
166
+ {
167
+ // only translate the output not the value
168
+ $field['role'][] = $role;
169
+ }
170
+ }
171
+
172
+
173
+ // choices
174
+ foreach( $field['role'] as $role )
175
+ {
176
+ $label = translate_user_role( $editable_roles[ $role ]['name'] );
177
+
178
+ // get users
179
+ $users = get_users(array(
180
+ 'role' => $role
181
+ ));
182
+
183
+
184
+ if( $users )
185
+ {
186
+ $field['choices'][ $label ] = array();
187
+
188
+ foreach( $users as $user )
189
+ {
190
+ $field['choices'][ $label ][ $user->ID ] = ucfirst( $user->display_name );
191
+ }
192
+ }
193
+ }
194
+
195
+
196
+ // modify field
197
+ if( $field['field_type'] == 'multi_select' )
198
+ {
199
+ $field['multiple'] = 1;
200
+ }
201
+
202
+
203
+ $field['type'] = 'select';
204
+ $field['optgroup'] = true;
205
+
206
+
207
+ do_action('acf/create_field', $field);
208
+
209
+ }
210
+
211
+
212
+ /*
213
+ * create_options()
214
+ *
215
+ * Create extra options for your field. This is rendered when editing a field.
216
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
217
+ *
218
+ * @type action
219
+ * @since 3.6
220
+ * @date 23/01/13
221
+ *
222
+ * @param $field - an array holding all the field's data
223
+ */
224
+
225
+ function create_options( $field )
226
+ {
227
+ // vars
228
+ $field = array_merge($this->defaults, $field);
229
+ $key = $field['name'];
230
+
231
+ ?>
232
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
233
+ <td class="label">
234
+ <label><?php _e( "Filter by role", 'acf' ); ?></label>
235
+ </td>
236
+ <td>
237
+ <?php
238
+
239
+ $choices = array('all' => __('All', 'acf'));
240
+ $editable_roles = get_editable_roles();
241
+
242
+ foreach( $editable_roles as $role => $details )
243
+ {
244
+ // only translate the output not the value
245
+ $choices[$role] = translate_user_role( $details['name'] );
246
+ }
247
+
248
+ do_action('acf/create_field', array(
249
+ 'type' => 'select',
250
+ 'name' => 'fields[' . $key . '][role]',
251
+ 'value' => $field['role'],
252
+ 'choices' => $choices,
253
+ 'multiple' => '1',
254
+ ));
255
+
256
+ ?>
257
+ </td>
258
+ </tr>
259
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
260
+ <td class="label">
261
+ <label><?php _e("Field Type",'acf'); ?></label>
262
+ </td>
263
+ <td>
264
+ <?php
265
+ do_action('acf/create_field', array(
266
+ 'type' => 'select',
267
+ 'name' => 'fields['.$key.'][field_type]',
268
+ 'value' => $field['field_type'],
269
+ 'optgroup' => true,
270
+ 'choices' => array(
271
+ __("Multiple Values",'acf') => array(
272
+ //'checkbox' => __('Checkbox', 'acf'),
273
+ 'multi_select' => __('Multi Select', 'acf')
274
+ ),
275
+ __("Single Value",'acf') => array(
276
+ //'radio' => __('Radio Buttons', 'acf'),
277
+ 'select' => __('Select', 'acf')
278
+ )
279
+ )
280
+ ));
281
+ ?>
282
+ </td>
283
+ </tr>
284
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
285
+ <td class="label">
286
+ <label><?php _e("Allow Null?",'acf'); ?></label>
287
+ </td>
288
+ <td>
289
+ <?php
290
+ do_action('acf/create_field', array(
291
+ 'type' => 'radio',
292
+ 'name' => 'fields['.$key.'][allow_null]',
293
+ 'value' => $field['allow_null'],
294
+ 'choices' => array(
295
+ 1 => __("Yes",'acf'),
296
+ 0 => __("No",'acf'),
297
+ ),
298
+ 'layout' => 'horizontal',
299
+ ));
300
+ ?>
301
+ </td>
302
+ </tr>
303
+ <?php
304
+
305
+ }
306
+
307
+
308
+ }
309
+
310
+ new acf_field_user();
311
+
312
+ ?>
core/fields/wysiwyg.php CHANGED
@@ -1,44 +1,53 @@
1
  <?php
2
 
3
- class acf_Wysiwyg extends acf_Field
4
  {
5
 
6
- /*--------------------------------------------------------------------------------------
 
7
  *
8
- * Constructor
9
  *
10
- * @author Elliot Condon
11
- * @since 1.0.0
12
- * @updated 2.2.0
13
- *
14
- *-------------------------------------------------------------------------------------*/
15
 
16
- function __construct($parent)
17
  {
18
- parent::__construct($parent);
19
-
20
- $this->name = 'wysiwyg';
21
- $this->title = __("Wysiwyg Editor",'acf');
22
 
23
- add_action( 'acf_head-input', array( $this, 'acf_head') );
24
 
25
- add_filter( 'acf/fields/wysiwyg/toolbars', array( $this, 'toolbars'), 1, 1 );
26
-
27
- }
28
-
29
-
30
- /*
31
- * get_toolbars
32
- *
33
- * @description:
34
- * @since: 3.5.7
35
- * @created: 10/01/13
36
- */
37
-
 
 
 
 
 
 
 
 
 
 
38
  function toolbars( $toolbars )
39
  {
40
  $editor_id = 'acf_settings';
41
 
 
42
  // Full
43
  $toolbars['Full'] = array();
44
  $toolbars['Full'][1] = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'justifyleft', 'justifycenter', 'justifyright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' ), $editor_id);
@@ -54,162 +63,51 @@ class acf_Wysiwyg extends acf_Field
54
 
55
  // Custom - can be added with acf/fields/wysiwyg/toolbars filter
56
 
 
57
  return $toolbars;
58
  }
59
 
60
-
61
-
62
- /*--------------------------------------------------------------------------------------
63
  *
64
- * admin_head
65
- * - Add the settings for a WYSIWYG editor (as used in wp_editor / wp_tiny_mce)
66
  *
67
- * @author Elliot Condon
68
- * @since 3.2.3
69
- *
70
- *-------------------------------------------------------------------------------------*/
71
-
72
- function acf_head()
 
73
  {
74
  add_action( 'admin_footer', array( $this, 'admin_footer') );
75
  }
76
 
77
-
78
  function admin_footer()
79
  {
80
  ?>
81
- <div style="display:none;">
82
- <?php wp_editor( '', 'acf_settings' ); ?>
83
- </div>
84
  <?php
85
  }
86
 
87
-
88
-
89
- /*--------------------------------------------------------------------------------------
90
  *
91
- * create_options
92
  *
93
- * @author Elliot Condon
94
- * @since 2.0.6
95
- * @updated 2.2.0
96
- *
97
- *-------------------------------------------------------------------------------------*/
98
-
99
- function create_options($key, $field)
100
- {
101
- // vars
102
- $defaults = array(
103
- 'toolbar' => 'full',
104
- 'media_upload' => 'yes',
105
- 'the_content' => 'yes',
106
- 'default_value' => '',
107
- );
108
-
109
- $field = array_merge($defaults, $field);
110
-
111
- ?>
112
- <tr class="field_option field_option_<?php echo $this->name; ?>">
113
- <td class="label">
114
- <label><?php _e("Default Value",'acf'); ?></label>
115
- </td>
116
- <td>
117
- <?php
118
- do_action('acf/create_field', array(
119
- 'type' => 'textarea',
120
- 'name' => 'fields['.$key.'][default_value]',
121
- 'value' => $field['default_value'],
122
- ));
123
- ?>
124
- </td>
125
- </tr>
126
- <tr class="field_option field_option_<?php echo $this->name; ?>">
127
- <td class="label">
128
- <label><?php _e("Toolbar",'acf'); ?></label>
129
- </td>
130
- <td>
131
- <?php
132
-
133
- $toolbars = apply_filters( 'acf/fields/wysiwyg/toolbars', array() );
134
- $choices = array();
135
-
136
- if( is_array($toolbars) )
137
- {
138
- foreach( $toolbars as $k => $v )
139
- {
140
- $label = $k;
141
- $name = sanitize_title( $label );
142
- $name = str_replace('-', '_', $name);
143
-
144
- $choices[ $name ] = $label;
145
- }
146
- }
147
-
148
- do_action('acf/create_field', array(
149
- 'type' => 'radio',
150
- 'name' => 'fields['.$key.'][toolbar]',
151
- 'value' => $field['toolbar'],
152
- 'layout' => 'horizontal',
153
- 'choices' => $choices
154
- ));
155
- ?>
156
- </td>
157
- </tr>
158
- <tr class="field_option field_option_<?php echo $this->name; ?>">
159
- <td class="label">
160
- <label><?php _e("Show Media Upload Buttons?",'acf'); ?></label>
161
- </td>
162
- <td>
163
- <?php
164
- do_action('acf/create_field', array(
165
- 'type' => 'radio',
166
- 'name' => 'fields['.$key.'][media_upload]',
167
- 'value' => $field['media_upload'],
168
- 'layout' => 'horizontal',
169
- 'choices' => array(
170
- 'yes' => __("Yes",'acf'),
171
- 'no' => __("No",'acf'),
172
- )
173
- ));
174
- ?>
175
- </td>
176
- </tr>
177
- <tr class="field_option field_option_<?php echo $this->name; ?>">
178
- <td class="label">
179
- <label><?php _e("Run filter \"the_content\"?",'acf'); ?></label>
180
- <p class="description"><?php _e("Enable this filter to use shortcodes within the WYSIWYG field",'acf'); ?></p>
181
- <p class="description"><?php _e("Disable this filter if you encounter recursive template problems with plugins / themes",'acf'); ?></p>
182
- </td>
183
- <td>
184
- <?php
185
- do_action('acf/create_field', array(
186
- 'type' => 'radio',
187
- 'name' => 'fields['.$key.'][the_content]',
188
- 'value' => $field['the_content'],
189
- 'layout' => 'horizontal',
190
- 'choices' => array(
191
- 'yes' => __("Yes",'acf'),
192
- 'no' => __("No",'acf'),
193
- )
194
- ));
195
- ?>
196
- </td>
197
- </tr>
198
- <?php
199
- }
200
-
201
-
202
- /*--------------------------------------------------------------------------------------
203
- *
204
- * create_field
205
  *
206
- * @author Elliot Condon
207
- * @since 2.0.5
208
- * @updated 2.2.0
209
- *
210
- *-------------------------------------------------------------------------------------*/
211
 
212
- function create_field($field)
213
  {
214
  global $wp_version;
215
 
@@ -247,44 +145,131 @@ class acf_Wysiwyg extends acf_Field
247
  </div>
248
 
249
  <?php
250
-
251
  }
252
 
253
 
254
- /*--------------------------------------------------------------------------------------
 
 
 
 
255
  *
256
- * get_value_for_api
 
 
257
  *
258
- * @author Elliot Condon
259
- * @since 3.0.0
260
- *
261
- *-------------------------------------------------------------------------------------*/
262
 
263
- function get_value_for_api($post_id, $field)
264
  {
265
  // vars
266
  $defaults = array(
267
- 'the_content' => 'yes',
 
 
268
  );
 
269
  $field = array_merge($defaults, $field);
270
- $value = parent::get_value($post_id, $field);
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
 
273
- // filter
274
- if( $field['the_content'] == 'yes' )
275
- {
276
- $value = apply_filters('the_content',$value);
277
- }
278
- else
279
  {
280
- $value = wpautop( $value );
 
 
 
 
 
 
 
281
  }
282
-
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  return $value;
285
  }
286
 
287
-
288
  }
289
 
 
 
290
  ?>
1
  <?php
2
 
3
+ class acf_field_wysiwyg extends acf_field
4
  {
5
 
6
+ /*
7
+ * __construct
8
  *
9
+ * Set name / label needed for actions / filters
10
  *
11
+ * @since 3.6
12
+ * @date 23/01/13
13
+ */
 
 
14
 
15
+ function __construct()
16
  {
17
+ // vars
18
+ $this->name = 'wysiwyg';
19
+ $this->label = __("Wysiwyg Editor",'acf');
20
+ $this->category = __("Content",'acf');
21
 
 
22
 
23
+ // do not delete!
24
+ parent::__construct();
25
+
26
+
27
+ // filters
28
+ add_filter( 'acf/fields/wysiwyg/toolbars', array( $this, 'toolbars'), 1, 1 );
29
+ }
30
+
31
+
32
+ /*
33
+ * toolbars()
34
+ *
35
+ * This filter allowsyou to customize the WYSIWYG toolbars
36
+ *
37
+ * @param $toolbars - an array of toolbars
38
+ *
39
+ * @return $toolbars - the modified $toolbars
40
+ *
41
+ * @type filter
42
+ * @since 3.6
43
+ * @date 23/01/13
44
+ */
45
+
46
  function toolbars( $toolbars )
47
  {
48
  $editor_id = 'acf_settings';
49
 
50
+
51
  // Full
52
  $toolbars['Full'] = array();
53
  $toolbars['Full'][1] = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'justifyleft', 'justifycenter', 'justifyright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' ), $editor_id);
63
 
64
  // Custom - can be added with acf/fields/wysiwyg/toolbars filter
65
 
66
+
67
  return $toolbars;
68
  }
69
 
70
+
71
+ /*
72
+ * input_admin_head()
73
  *
74
+ * This action is called in the admin_head action on the edit screen where your field is created.
75
+ * Use this action to add css and javascript to assist your create_field() action.
76
  *
77
+ * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head
78
+ * @type action
79
+ * @since 3.6
80
+ * @date 23/01/13
81
+ */
82
+
83
+ function input_admin_head()
84
  {
85
  add_action( 'admin_footer', array( $this, 'admin_footer') );
86
  }
87
 
 
88
  function admin_footer()
89
  {
90
  ?>
91
+ <div style="display:none;">
92
+ <?php wp_editor( '', 'acf_settings' ); ?>
93
+ </div>
94
  <?php
95
  }
96
 
97
+
98
+ /*
99
+ * create_field()
100
  *
101
+ * Create the HTML interface for your field
102
  *
103
+ * @param $field - an array holding all the field's data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  *
105
+ * @type action
106
+ * @since 3.6
107
+ * @date 23/01/13
108
+ */
 
109
 
110
+ function create_field( $field )
111
  {
112
  global $wp_version;
113
 
145
  </div>
146
 
147
  <?php
 
148
  }
149
 
150
 
151
+ /*
152
+ * create_options()
153
+ *
154
+ * Create extra options for your field. This is rendered when editing a field.
155
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
156
  *
157
+ * @type action
158
+ * @since 3.6
159
+ * @date 23/01/13
160
  *
161
+ * @param $field - an array holding all the field's data
162
+ */
 
 
163
 
164
+ function create_options( $field )
165
  {
166
  // vars
167
  $defaults = array(
168
+ 'toolbar' => 'full',
169
+ 'media_upload' => 'yes',
170
+ 'default_value' => '',
171
  );
172
+
173
  $field = array_merge($defaults, $field);
174
+ $key = $field['name'];
175
 
176
+ ?>
177
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
178
+ <td class="label">
179
+ <label><?php _e("Default Value",'acf'); ?></label>
180
+ </td>
181
+ <td>
182
+ <?php
183
+ do_action('acf/create_field', array(
184
+ 'type' => 'textarea',
185
+ 'name' => 'fields['.$key.'][default_value]',
186
+ 'value' => $field['default_value'],
187
+ ));
188
+ ?>
189
+ </td>
190
+ </tr>
191
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
192
+ <td class="label">
193
+ <label><?php _e("Toolbar",'acf'); ?></label>
194
+ </td>
195
+ <td>
196
+ <?php
197
 
198
+ $toolbars = apply_filters( 'acf/fields/wysiwyg/toolbars', array() );
199
+ $choices = array();
200
+
201
+ if( is_array($toolbars) )
 
 
202
  {
203
+ foreach( $toolbars as $k => $v )
204
+ {
205
+ $label = $k;
206
+ $name = sanitize_title( $label );
207
+ $name = str_replace('-', '_', $name);
208
+
209
+ $choices[ $name ] = $label;
210
+ }
211
  }
 
212
 
213
+ do_action('acf/create_field', array(
214
+ 'type' => 'radio',
215
+ 'name' => 'fields['.$key.'][toolbar]',
216
+ 'value' => $field['toolbar'],
217
+ 'layout' => 'horizontal',
218
+ 'choices' => $choices
219
+ ));
220
+ ?>
221
+ </td>
222
+ </tr>
223
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
224
+ <td class="label">
225
+ <label><?php _e("Show Media Upload Buttons?",'acf'); ?></label>
226
+ </td>
227
+ <td>
228
+ <?php
229
+ do_action('acf/create_field', array(
230
+ 'type' => 'radio',
231
+ 'name' => 'fields['.$key.'][media_upload]',
232
+ 'value' => $field['media_upload'],
233
+ 'layout' => 'horizontal',
234
+ 'choices' => array(
235
+ 'yes' => __("Yes",'acf'),
236
+ 'no' => __("No",'acf'),
237
+ )
238
+ ));
239
+ ?>
240
+ </td>
241
+ </tr>
242
+ <?php
243
+ }
244
+
245
+
246
+ /*
247
+ * format_value_for_api()
248
+ *
249
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
250
+ *
251
+ * @type filter
252
+ * @since 3.6
253
+ * @date 23/01/13
254
+ *
255
+ * @param $value - the value which was loaded from the database
256
+ * @param $post_id - the $post_id from which the value was loaded
257
+ * @param $field - the field array holding all the field options
258
+ *
259
+ * @return $value - the modified value
260
+ */
261
+
262
+ function format_value_for_api( $value, $post_id, $field )
263
+ {
264
+ // filters
265
+ $value = wpautop( $value );
266
+ $value = do_shortcode( $value );
267
+
268
  return $value;
269
  }
270
 
 
271
  }
272
 
273
+ new acf_field_wysiwyg();
274
+
275
  ?>
core/views/meta_box_fields.php CHANGED
@@ -1,49 +1,49 @@
1
  <?php
2
 
3
  /*
4
- * Meta Box: Fields
5
  *
6
- * @description: This file creates the HTML for a list of fields within a Field Group
7
- * @created: 23/06/12
 
8
  */
9
 
10
 
11
  // global
12
- global $post;
13
-
14
-
15
- // vars
16
- $fields_names = array();
17
 
18
 
19
  // get fields
20
- $fields = $this->parent->get_acf_fields( $post->ID );
21
 
22
 
23
  // add clone
24
- $fields[] = array(
25
  'key' => 'field_clone',
26
  'label' => __("New Field",'acf'),
27
  'name' => __("new_field",'acf'),
28
  'type' => 'text',
29
- 'order_no' => 1,
30
- 'instructions' => '',
31
- 'required' => 0,
32
- 'conditional_logic' => array(
33
- 'status' => 0,
34
- 'allorany' => 'all',
35
- 'rules' => 0
36
- )
37
- );
38
 
39
 
40
  // get name of all fields for use in field type drop down
41
- foreach($this->parent->fields as $f)
 
 
 
 
42
  {
43
- if( $f->name )
 
 
44
  {
45
- $fields_names[$f->name] = $f->title;
 
 
 
46
  }
 
 
47
  }
48
 
49
 
@@ -54,6 +54,8 @@ $conditional_logic_rule = array(
54
  'value' => ''
55
  );
56
 
 
 
57
  ?>
58
 
59
  <!-- Hidden Fields -->
@@ -62,9 +64,9 @@ $conditional_logic_rule = array(
62
  acf.text.move_to_trash = "<?php _e("Move to trash. Are you sure?",'acf'); ?>";
63
  acf.text.checked = "<?php _e("checked",'acf'); ?>";
64
  acf.text.conditional_no_fields = "<?php _e('No toggle fields available','acf'); ?>";
65
- acf.text.flexible_content_no_fields = "<?php _e('Flexible Content requires at least 1 layout','acf'); ?>";
66
  </script>
67
- <input type="hidden" name="acf_field_group" value="<?php echo wp_create_nonce( 'acf_field_group' ); ?>" />
68
  </div>
69
  <!-- / Hidden Fields -->
70
 
@@ -94,8 +96,11 @@ $conditional_logic_rule = array(
94
  </div>
95
  <!-- / No Fields Message -->
96
 
97
- <?php foreach($fields as $field): ?>
98
- <div class="field field-<?php echo $field['type']; ?> field-<?php echo $field['key']; ?>" data-type="<?php echo $field['type']; ?>" data-id="<?php echo $field['key']; ?>">
 
 
 
99
  <div class="field_meta">
100
  <table class="acf widefat">
101
  <tr>
@@ -112,7 +117,7 @@ $conditional_logic_rule = array(
112
  </div>
113
  </td>
114
  <td class="field_name"><?php echo $field['name']; ?></td>
115
- <td class="field_type"><?php echo $fields_names[$field['type']]; ?></td>
116
  <td class="field_key"><?php echo $field['key']; ?></td>
117
  </tr>
118
  </table>
@@ -131,7 +136,7 @@ $conditional_logic_rule = array(
131
  <?php
132
  do_action('acf/create_field', array(
133
  'type' => 'text',
134
- 'name' => 'fields['.$field['key'].'][label]',
135
  'value' => $field['label'],
136
  'class' => 'label',
137
  ));
@@ -147,7 +152,7 @@ $conditional_logic_rule = array(
147
  <?php
148
  do_action('acf/create_field', array(
149
  'type' => 'text',
150
- 'name' => 'fields['.$field['key'].'][name]',
151
  'value' => $field['name'],
152
  'class' => 'name',
153
  ));
@@ -157,12 +162,13 @@ $conditional_logic_rule = array(
157
  <tr class="field_type">
158
  <td class="label"><label><span class="required">*</span><?php _e("Field Type",'acf'); ?></label></td>
159
  <td>
160
- <?php
161
  do_action('acf/create_field', array(
162
  'type' => 'select',
163
- 'name' => 'fields['.$field['key'].'][type]',
164
  'value' => $field['type'],
165
- 'choices' => $fields_names,
 
166
  ));
167
  ?>
168
  </td>
@@ -174,7 +180,7 @@ $conditional_logic_rule = array(
174
  <?php
175
  do_action('acf/create_field', array(
176
  'type' => 'textarea',
177
- 'name' => 'fields['.$field['key'].'][instructions]',
178
  'value' => $field['instructions'],
179
  ));
180
  ?>
@@ -186,7 +192,7 @@ $conditional_logic_rule = array(
186
  <?php
187
  do_action('acf/create_field', array(
188
  'type' => 'radio',
189
- 'name' => 'fields['.$field['key'].'][required]',
190
  'value' => $field['required'],
191
  'choices' => array(
192
  1 => __("Yes",'acf'),
@@ -199,10 +205,8 @@ $conditional_logic_rule = array(
199
  </tr>
200
  <?php
201
 
202
- if( isset($this->parent->fields[ $field['type'] ]) )
203
- {
204
- $this->parent->fields[$field['type']]->create_options($field['key'], $field);
205
- }
206
 
207
  ?>
208
  <tr class="conditional-logic" data-field_name="<?php echo $field['key']; ?>">
1
  <?php
2
 
3
  /*
4
+ * Html: Fields
5
  *
6
+ * @description:
7
+ * @since: 3.6
8
+ * @created: 26/01/13
9
  */
10
 
11
 
12
  // global
13
+ global $post, $field_types;
 
 
 
 
14
 
15
 
16
  // get fields
17
+ $fields = apply_filters('acf/field_group/get_fields', array(), $post->ID);
18
 
19
 
20
  // add clone
21
+ $fields[] = apply_filters('acf/load_field_defaults', array(
22
  'key' => 'field_clone',
23
  'label' => __("New Field",'acf'),
24
  'name' => __("new_field",'acf'),
25
  'type' => 'text',
26
+ ));
 
 
 
 
 
 
 
 
27
 
28
 
29
  // get name of all fields for use in field type drop down
30
+ $field_types = apply_filters('acf/registered_fields', array());
31
+
32
+
33
+ // helper function
34
+ function field_type_exists( $name )
35
  {
36
+ global $field_types;
37
+
38
+ foreach( $field_types as $category )
39
  {
40
+ if( isset( $category[ $name ] ) )
41
+ {
42
+ return $category[ $name ];
43
+ }
44
  }
45
+
46
+ return false;
47
  }
48
 
49
 
54
  'value' => ''
55
  );
56
 
57
+ $error_field_type = '<b>' . __('Error', 'acf') . '</b> ' . __('Field type does not exist', 'acf');
58
+
59
  ?>
60
 
61
  <!-- Hidden Fields -->
64
  acf.text.move_to_trash = "<?php _e("Move to trash. Are you sure?",'acf'); ?>";
65
  acf.text.checked = "<?php _e("checked",'acf'); ?>";
66
  acf.text.conditional_no_fields = "<?php _e('No toggle fields available','acf'); ?>";
67
+ acf.text.copy = "<?php _e('copy','acf'); ?>";
68
  </script>
69
+ <input type="hidden" name="acf_nonce" value="<?php echo wp_create_nonce( 'field_group' ); ?>" />
70
  </div>
71
  <!-- / Hidden Fields -->
72
 
96
  </div>
97
  <!-- / No Fields Message -->
98
 
99
+ <?php foreach($fields as $field):
100
+ $fake_name = $field['key'];
101
+ ?>
102
+ <div class="field field_type-<?php echo $field['type']; ?> field_key-<?php echo $field['key']; ?>" data-type="<?php echo $field['type']; ?>" data-id="<?php echo $field['key']; ?>">
103
+ <input type="hidden" class="input-field_key" name="fields[<?php echo $field['key']; ?>][key]" value="<?php echo $field['key']; ?>" />
104
  <div class="field_meta">
105
  <table class="acf widefat">
106
  <tr>
117
  </div>
118
  </td>
119
  <td class="field_name"><?php echo $field['name']; ?></td>
120
+ <td class="field_type"><?php $l = field_type_exists( $field['type'] ); if( $l ){ echo $l; }else{ echo $error_field_type; } ?></td>
121
  <td class="field_key"><?php echo $field['key']; ?></td>
122
  </tr>
123
  </table>
136
  <?php
137
  do_action('acf/create_field', array(
138
  'type' => 'text',
139
+ 'name' => 'fields[' .$fake_name . '][label]',
140
  'value' => $field['label'],
141
  'class' => 'label',
142
  ));
152
  <?php
153
  do_action('acf/create_field', array(
154
  'type' => 'text',
155
+ 'name' => 'fields[' .$fake_name . '][name]',
156
  'value' => $field['name'],
157
  'class' => 'name',
158
  ));
162
  <tr class="field_type">
163
  <td class="label"><label><span class="required">*</span><?php _e("Field Type",'acf'); ?></label></td>
164
  <td>
165
+ <?php
166
  do_action('acf/create_field', array(
167
  'type' => 'select',
168
+ 'name' => 'fields[' .$fake_name . '][type]',
169
  'value' => $field['type'],
170
+ 'choices' => $field_types,
171
+ 'optgroup' => true
172
  ));
173
  ?>
174
  </td>
180
  <?php
181
  do_action('acf/create_field', array(
182
  'type' => 'textarea',
183
+ 'name' => 'fields[' .$fake_name . '][instructions]',
184
  'value' => $field['instructions'],
185
  ));
186
  ?>
192
  <?php
193
  do_action('acf/create_field', array(
194
  'type' => 'radio',
195
+ 'name' => 'fields[' .$fake_name . '][required]',
196
  'value' => $field['required'],
197
  'choices' => array(
198
  1 => __("Yes",'acf'),
205
  </tr>
206
  <?php
207
 
208
+ $field['name'] = $fake_name;
209
+ do_action('acf/create_field_options', $field );
 
 
210
 
211
  ?>
212
  <tr class="conditional-logic" data-field_name="<?php echo $field['key']; ?>">
core/views/meta_box_location.php CHANGED
@@ -12,7 +12,7 @@ global $post;
12
 
13
 
14
  // vars
15
- $location = $this->parent->get_acf_location($post->ID);
16
 
17
 
18
  // at lease 1 location rule
@@ -61,18 +61,20 @@ if( empty($location['rules']) )
61
  'taxonomy' => __("Taxonomy",'acf'),
62
  ),
63
  __("Other",'acf') => array(
64
- 'ef_taxonomy' => __("Taxonomy (Add / Edit)",'acf'),
65
  'ef_user' => __("User (Add / Edit)",'acf'),
66
- 'ef_media' => __("Media (Edit)",'acf')
67
  )
68
  );
69
 
70
 
71
  // validate
72
- if($this->parent->is_field_unlocked('options_page'))
 
73
  {
74
  $choices[__("Options Page",'acf')]['options_page'] = __("Options Page",'acf');
75
  }
 
76
 
77
 
78
  // allow custom location rules
@@ -114,7 +116,7 @@ if( empty($location['rules']) )
114
  ?></td>
115
  <td class="value"><?php
116
 
117
- $this->ajax_acf_location(array(
118
  'key' => $k,
119
  'value' => $rule['value'],
120
  'param' => $rule['param'],
12
 
13
 
14
  // vars
15
+ $location = apply_filters('acf/field_group/get_location', array(), $post->ID);
16
 
17
 
18
  // at lease 1 location rule
61
  'taxonomy' => __("Taxonomy",'acf'),
62
  ),
63
  __("Other",'acf') => array(
64
+ 'ef_taxonomy' => __("Taxonomy Term (Add / Edit)",'acf'),
65
  'ef_user' => __("User (Add / Edit)",'acf'),
66
+ 'ef_media' => __("Media Attachment (Edit)",'acf')
67
  )
68
  );
69
 
70
 
71
  // validate
72
+ /*
73
+ if($this->parent->is_field_unlocked('options_page'))
74
  {
75
  $choices[__("Options Page",'acf')]['options_page'] = __("Options Page",'acf');
76
  }
77
+ */
78
 
79
 
80
  // allow custom location rules
116
  ?></td>
117
  <td class="value"><?php
118
 
119
+ $this->ajax_render_location(array(
120
  'key' => $k,
121
  'value' => $rule['value'],
122
  'param' => $rule['param'],
core/views/meta_box_options.php CHANGED
@@ -13,7 +13,7 @@ global $post;
13
 
14
 
15
  // vars
16
- $options = $this->parent->get_acf_options($post->ID);
17
 
18
 
19
  ?>
13
 
14
 
15
  // vars
16
+ $options = apply_filters('acf/field_group/get_options', array(), $post->ID);
17
 
18
 
19
  ?>
css/acf.css CHANGED
@@ -47,9 +47,9 @@
47
 
48
  h3.h2 {
49
  font-family: "HelveticaNeue-Light","Helvetica Neue Light","Helvetica Neue",sans-serif;
50
- font-size: 23px;
51
  line-height: 29px;
52
- padding: 9px 15px 4px 0;
53
  margin: 0;
54
  font-weight: normal;
55
  }
@@ -66,51 +66,6 @@ h3.h2 span {
66
 
67
 
68
 
69
- table.acf_activate {
70
- border: 0 none;
71
- border-collapse:separate;
72
- border-spacing:0;
73
- vertical-align:top;
74
- width: 100%;
75
- background: #FEFEFE;
76
- border-radius: 0;
77
- }
78
-
79
- table.acf_activate tr:nth-child(even) {
80
- background: #F9F9F9
81
- }
82
-
83
- table.acf_activate tr:nth-child(odd) {
84
- background: transparent;
85
- }
86
-
87
- table.acf_activate tr.field_save {
88
- background: #EAF2FA;
89
- }
90
-
91
- table.acf_activate tr td,
92
- table.acf_activate tr th {
93
- padding: 8px;
94
- }
95
-
96
- table.acf_activate tr:last-child td {
97
- border-bottom: 0 none;
98
- }
99
-
100
- table.acf_activate tr td:last-child {
101
- border-right: 0 none;
102
- }
103
-
104
- table.acf_activate input[type="text"] {
105
- padding: 7px;
106
- width: 200px;
107
- }
108
-
109
- table.acf_activate input[type="submit"] {
110
- margin-left: 5px;
111
- margin-right: 5px;
112
- }
113
-
114
  .acf-form-table {
115
  max-width: 1100px;
116
  }
@@ -166,6 +121,177 @@ body.custom-fields_page_acf-settings .wp-pointer-arrow {
166
  }
167
 
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  /*--------------------------------------------------------------------------
170
  *
171
  * Retina
@@ -181,7 +307,8 @@ only screen and ( min-resolution: 192dpi),
181
  only screen and ( min-resolution: 2dppx) {
182
 
183
  #icon-edit,
184
- #icon-acf {
 
185
  background-image: url(../images/sprite@2x.png);
186
  background-size: 100px 600px;
187
  }
47
 
48
  h3.h2 {
49
  font-family: "HelveticaNeue-Light","Helvetica Neue Light","Helvetica Neue",sans-serif;
50
+ font-size: 25px;
51
  line-height: 29px;
52
+ padding: 5px 0 4px 0;
53
  margin: 0;
54
  font-weight: normal;
55
  }
66
 
67
 
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  .acf-form-table {
70
  max-width: 1100px;
71
  }
121
  }
122
 
123
 
124
+ /*--------------------------------------------------------------------------
125
+ *
126
+ * Add-Ons
127
+ *
128
+ *-------------------------------------------------------------------------*/
129
+
130
+ #add-ons {
131
+
132
+ }
133
+
134
+ #add-ons .add-on {
135
+ float: left;
136
+ width: 220px;
137
+ margin: 10px;
138
+ }
139
+
140
+ #add-ons .add-on h3 {
141
+ margin-top: 0.5em;
142
+ }
143
+
144
+ #add-ons .add-on-active .button {
145
+ padding-left: 4px;
146
+ }
147
+
148
+ #add-ons .add-on-active .tick {
149
+ width: 14px;
150
+ height: 14px;
151
+ display: block;
152
+ float: left;
153
+ margin: 4px 5px 0 0;
154
+ background: url(../images/sprite.png) -18px -318px no-repeat;
155
+ }
156
+
157
+
158
+ /*--------------------------------------------------------------------------
159
+ *
160
+ * About (post update information)
161
+ *
162
+ *-------------------------------------------------------------------------*/
163
+
164
+ .acf-content {
165
+ font-size: 15px;
166
+ margin: 25px 40px 0 20px;
167
+ max-width: 1050px;
168
+ position: relative;
169
+ }
170
+
171
+
172
+ /*
173
+ * Title
174
+ */
175
+
176
+ .acf-content-title h1 {
177
+ color: #333333;
178
+ font-size: 2.8em;
179
+ font-weight: 200;
180
+ line-height: 1.2em;
181
+ margin: 0.2em 0 0;
182
+ }
183
+
184
+ .acf-content-title h2 {
185
+ color: #777777;
186
+ font-size: 24px;
187
+ font-weight: normal;
188
+ line-height: 1.6em;
189
+ margin: 1em 0 1.4em;
190
+ font-family: "HelveticaNeue-Light","Helvetica Neue Light","Helvetica Neue",sans-serif;
191
+ }
192
+
193
+
194
+ /*
195
+ * Tabs
196
+ */
197
+
198
+ .acf-content .nav-tab-wrapper {
199
+ padding-left: 6px;
200
+ margin-bottom: 30px;
201
+ }
202
+
203
+ .acf-content .nav-tab-wrapper .nav-tab {
204
+ color: #21759B;
205
+ font-size: 18px;
206
+ margin: 0 3px -1px 0;
207
+ padding: 4px 10px 6px;
208
+ vertical-align: top;
209
+ }
210
+
211
+ .acf-tab-content {
212
+ display: none;
213
+ }
214
+
215
+ .acf-tab-content.active {
216
+ display: block;
217
+ }
218
+
219
+
220
+
221
+ /*
222
+ * Body
223
+ */
224
+
225
+ .acf-content-body {
226
+ margin: 0 0 30px;
227
+ }
228
+
229
+ .acf-content-body hr {
230
+ border: 0 none;
231
+ border-top: #DFDFDF solid 1px;
232
+ background: transparent;
233
+ margin: 30px 0;
234
+ clear: both;
235
+ }
236
+
237
+ .acf-content-body h3 {
238
+ font-size: 24px;
239
+ margin: 2em 0 1em;
240
+ }
241
+
242
+ .acf-content-body h4 {
243
+ color: #464646;
244
+ font-size: 1em;
245
+ margin: 2em 0 0.6em;
246
+ }
247
+
248
+ .acf-content-body h4 + p {
249
+ margin-top: 0.6em;
250
+ }
251
+
252
+ .acf-content-body p {
253
+ line-height: 1.6em;
254
+
255
+ }
256
+
257
+ #acf-add-ons-table {
258
+ margin-left: 100px;
259
+ }
260
+
261
+ #acf-add-ons-table img {
262
+ display: block;
263
+ width: 120px;
264
+ }
265
+
266
+
267
+ /*
268
+ * Footer
269
+ */
270
+
271
+ .acf-content-footer {
272
+ margin: 60px 0 30px;
273
+ }
274
+
275
+
276
+ /*
277
+ * Cangelog
278
+ */
279
+
280
+ .acf-content-body ul {
281
+ list-style: disc outside none;
282
+ padding-left: 30px;
283
+ }
284
+
285
+ .acf-content-body ul li {
286
+ margin: 12px 0;
287
+ }
288
+
289
+ .acf-content-body ul li a {
290
+
291
+ }
292
+
293
+
294
+
295
  /*--------------------------------------------------------------------------
296
  *
297
  * Retina
307
  only screen and ( min-resolution: 2dppx) {
308
 
309
  #icon-edit,
310
+ #icon-acf,
311
+ #add-ons .add-on.active .tick {
312
  background-image: url(../images/sprite@2x.png);
313
  background-size: 100px 600px;
314
  }
css/field-group.css CHANGED
@@ -261,7 +261,7 @@ table.widefat.acf td {
261
  background: #FCFCFC;
262
  }
263
 
264
- .fields .field-field_clone {
265
  display: none;
266
  }
267
 
@@ -534,42 +534,6 @@ ul.checkbox_list li input {
534
  }
535
 
536
 
537
- /*---------------------------------------------------------------------------------------------
538
- *
539
- * Flexible Content
540
- *
541
- *---------------------------------------------------------------------------------------------*/
542
- table.acf_input table.acf_cf_meta {
543
- width: 100%;
544
- border: 0 none;
545
- }
546
-
547
- table.acf_input table.acf_cf_meta td {
548
- border: 0 none;
549
- width: 33%;
550
- }
551
-
552
- table.acf_input table.acf_cf_meta label {
553
- width: 20%;
554
- color: #333333;
555
- font-weight: bold;
556
- }
557
-
558
- table.acf_input table.acf_cf_meta input {
559
- width: 80%;
560
- }
561
-
562
- table.acf_input table.acf_cf_meta select {
563
- width: 75%;
564
- }
565
-
566
- .acf_fc_reorder {
567
- cursor: move;
568
- }
569
-
570
-
571
-
572
-
573
 
574
  /*---------------------------------------------------------------------------------------------
575
  *
@@ -637,12 +601,12 @@ table.acf_input table.acf_cf_meta select {
637
 
638
  #acf_fields select optgroup,
639
  #acf_location select optgroup {
640
- padding: 5px 2px;
641
  background: #fff;
642
  }
643
 
644
- #acf_fields select optgroup:first-child,
645
- #acf_location select optgroup:first-child {
646
 
647
  }
648
 
@@ -653,7 +617,7 @@ table.acf_input table.acf_cf_meta select {
653
 
654
  #acf_fields select optgroup option,
655
  #acf_location select optgroup option {
656
- padding-left: 6px;
657
  }
658
 
659
  #acf_fields select optgroup:nth-child(2n),
@@ -686,14 +650,28 @@ table.conditional-logic-rules tbody td {
686
  *
687
  *---------------------------------------------------------------------------------------------*/
688
 
 
 
 
 
 
689
 
690
- #acf_fields .fields .field-tab tr.field_name,
691
- #acf_fields .fields .field-tab tr.field_instructions,
692
- #acf_fields .fields .field-tab tr.required,
693
- #acf_fields .fields .field-tab tr.conditional-logic {
 
 
 
 
 
 
694
  display: none;
695
  }
696
 
 
 
 
697
 
698
  /*--------------------------------------------------------------------------
699
  *
@@ -715,14 +693,6 @@ only screen and ( min-resolution: 2dppx) {
715
  background-size: 100px 600px;
716
  }
717
 
718
-
719
- /*
720
- #toplevel_page_edit-post_type-acf .wp-menu-image {
721
- background-image: url("../../../../wp-admin/images/menu-2x.png") !important;
722
- }
723
- */
724
-
725
-
726
  }
727
 
728
 
261
  background: #FCFCFC;
262
  }
263
 
264
+ .fields .field_key-field_clone {
265
  display: none;
266
  }
267
 
534
  }
535
 
536
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
537
 
538
  /*---------------------------------------------------------------------------------------------
539
  *
601
 
602
  #acf_fields select optgroup,
603
  #acf_location select optgroup {
604
+ padding: 5px 5px;
605
  background: #fff;
606
  }
607
 
608
+ #acf_fields select optgroup option:first-child,
609
+ #acf_location select optgroup option:first-child{
610
 
611
  }
612
 
617
 
618
  #acf_fields select optgroup option,
619
  #acf_location select optgroup option {
620
+ padding-left: 5px;
621
  }
622
 
623
  #acf_fields select optgroup:nth-child(2n),
650
  *
651
  *---------------------------------------------------------------------------------------------*/
652
 
653
+ #acf_fields .fields .field_type-tab tr.field_name,
654
+ #acf_fields .fields .field_type-tab tr.field_instructions,
655
+ #acf_fields .fields .field_type-tab tr.required {
656
+ display: none;
657
+ }
658
 
659
+
660
+ /*---------------------------------------------------------------------------------------------
661
+ *
662
+ * Field: Message
663
+ *
664
+ *---------------------------------------------------------------------------------------------*/
665
+
666
+ #acf_fields .fields .field_type-message tr.field_name,
667
+ #acf_fields .fields .field_type-message tr.field_instructions,
668
+ #acf_fields .fields .field_type-message tr.required {
669
  display: none;
670
  }
671
 
672
+ #acf_fields .fields .field_type-message textarea {
673
+ height: 175px;
674
+ }
675
 
676
  /*--------------------------------------------------------------------------
677
  *
693
  background-size: 100px 600px;
694
  }
695
 
 
 
 
 
 
 
 
 
696
  }
697
 
698
 
css/global.css CHANGED
@@ -56,6 +56,28 @@ input.ir { border: 0 none; background: none; }
56
  opacity: 0;
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  /*--------------------------------------------------------------------------------------------
60
  *
61
  * WP Box
@@ -68,8 +90,28 @@ input.ir { border: 0 none; background: none; }
68
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
69
  position: relative;
70
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  .wp-box .inner {
72
- padding: 10px;
73
  }
74
  .wp-box .footer {
75
  background: none repeat scroll 0 0 #F5F5F5;
@@ -102,6 +144,7 @@ input.ir { border: 0 none; background: none; }
102
 
103
  .wp-box h3 {
104
  margin: 1.5em 0 0;
 
105
  }
106
 
107
  .wp-box p {
@@ -232,6 +275,10 @@ table.acf_input select {
232
  padding: 2px;
233
  }
234
 
 
 
 
 
235
  table.acf_input input[type=text]:focus,
236
  table.acf_input textarea:focus,
237
  table.acf_input select:focus {
@@ -241,12 +288,15 @@ table.acf_input select:focus {
241
 
242
  ul.radio_list {
243
  position: relative;
244
- overflow: hidden;
245
  display: block;
246
- padding: 3px 0;
247
  margin: 0;
248
  }
249
 
 
 
 
 
250
  ul.radio_list.horizontal li {
251
  float: left;
252
  margin-right: 20px;
@@ -359,6 +409,10 @@ input[type="submit"].acf-button[disabled]:hover {
359
 
360
  }
361
 
 
 
 
 
362
 
363
  /*--------------------------------------------------------------------------
364
  *
56
  opacity: 0;
57
  }
58
 
59
+ .acf-alert {
60
+ background: #FCF8E3;
61
+ border: 1px solid #FBEED5;
62
+ border-radius: 4px 4px 4px 4px;
63
+ margin: 20px 0px;
64
+ padding: 8px 14px;
65
+ text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
66
+ color: #C09853;
67
+ }
68
+
69
+ .acf-alert p {
70
+ color: inherit;
71
+ margin: 0.5em 0;
72
+ }
73
+
74
+ .acf-alert.acf-alert-error {
75
+ background-color: #F2DEDE;
76
+ border-color: #EED3D7;
77
+ color: #B94A48;
78
+ }
79
+
80
+
81
  /*--------------------------------------------------------------------------------------------
82
  *
83
  * WP Box
90
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
91
  position: relative;
92
  }
93
+ .wp-box .title {
94
+ background: #f1f1f1;
95
+ background-image: -webkit-gradient(linear, left bottom, left top, from(#ececec), to(#f9f9f9));
96
+ background-image: -webkit-linear-gradient(bottom, #ececec, #f9f9f9);
97
+ background-image: -moz-linear-gradient(bottom, #ececec, #f9f9f9);
98
+ background-image: -o-linear-gradient(bottom, #ececec, #f9f9f9);
99
+ background-image: linear-gradient(to top, #ececec, #f9f9f9);
100
+ }
101
+ .wp-box .title h3 {
102
+ font-size: 15px;
103
+ font-weight: normal;
104
+ line-height: 1;
105
+ margin: 0;
106
+ padding: 7px 10px;
107
+ color: #464646;
108
+ border-bottom: #DFDFDF solid 1px;
109
+ box-shadow: 0 1px 0 #FFFFFF;
110
+ text-shadow: 0 1px 0 #FFFFFF;
111
+ font-family: Georgia,"Times New Roman","Bitstream Charter",Times,serif;
112
+ }
113
  .wp-box .inner {
114
+ padding: 15px;
115
  }
116
  .wp-box .footer {
117
  background: none repeat scroll 0 0 #F5F5F5;
144
 
145
  .wp-box h3 {
146
  margin: 1.5em 0 0;
147
+
148
  }
149
 
150
  .wp-box p {
275
  padding: 2px;
276
  }
277
 
278
+ table.acf_input select option {
279
+ padding: 3px;
280
+ }
281
+
282
  table.acf_input input[type=text]:focus,
283
  table.acf_input textarea:focus,
284
  table.acf_input select:focus {
288
 
289
  ul.radio_list {
290
  position: relative;
 
291
  display: block;
292
+ padding: 1px;
293
  margin: 0;
294
  }
295
 
296
+ ul.radio_list.horizontal {
297
+ overflow: hidden;
298
+ }
299
+
300
  ul.radio_list.horizontal li {
301
  float: left;
302
  margin-right: 20px;
409
 
410
  }
411
 
412
+ a.acf-button-big {
413
+ font-size: 16px;
414
+ padding: 13px;
415
+ }
416
 
417
  /*--------------------------------------------------------------------------
418
  *
css/input.css CHANGED
@@ -112,6 +112,9 @@
112
  padding-top: 0;
113
  }
114
 
 
 
 
115
 
116
  /*---------------------------------------------------------------------------------------------
117
  *
@@ -122,6 +125,7 @@
122
  .acf_postbox .field input[type="text"],
123
  .acf_postbox .field input[type="number"],
124
  .acf_postbox .field input[type="password"],
 
125
  .acf_postbox .field textarea{
126
  width: 100%;
127
  padding: 5px;
@@ -139,10 +143,11 @@
139
  resize: none;
140
  }
141
 
 
 
142
  .acf_postbox .field select optgroup {
143
  padding: 5px;
144
  background: #fff;
145
- border-top: #DFDFDF solid 1px;
146
  }
147
 
148
  .acf_postbox .field select option {
@@ -150,21 +155,13 @@
150
  }
151
 
152
  .acf_postbox .field select optgroup option {
153
- padding-left: 6px;
154
  }
155
 
156
  .acf_postbox .field select optgroup:nth-child(2n) {
157
  background: #F9F9F9;
158
  }
159
 
160
- .acf_postbox .field select[multiple] {
161
- padding: 0;
162
- }
163
-
164
- .acf_postbox .field select[multiple] > optgroup:first-child {
165
- border-top: 0 none;
166
- }
167
-
168
 
169
  /*---------------------------------------------------------------------------------------------
170
  *
@@ -361,7 +358,7 @@ ul.checkbox_list {
361
 
362
  /*---------------------------------------------------------------------------------------------
363
  *
364
- * Field: Repeater / Flexible Content (.acf-input-table)
365
  *
366
  *---------------------------------------------------------------------------------------------*/
367
 
@@ -379,10 +376,6 @@ ul.checkbox_list {
379
  border-right: 1px solid #e1e1e1;
380
  }
381
 
382
- .repeater > table > thead > tr > th:last-child {
383
- border-right: 0 none;
384
- }
385
-
386
  .acf-input-table > tbody {}
387
 
388
  .acf-input-table > tbody > tr {
@@ -424,105 +417,6 @@ ul.checkbox_list {
424
  }
425
 
426
 
427
- /*---------------------------------------------------------------------------------------------
428
- *
429
- * Field: Repeater
430
- *
431
- *---------------------------------------------------------------------------------------------*/
432
-
433
- .repeater > .acf-input-table > tbody > tr:hover > td.remove > a.acf-button-add,
434
- .repeater > .acf-input-table > tbody > tr:hover > td.remove > a.acf-button-remove {
435
-
436
- -webkit-transition-delay:0s;
437
- -moz-transition-delay:0s;
438
- -o-transition-delay:0s;
439
- transition-delay:0s;
440
-
441
- visibility: visible;
442
- opacity: 1;
443
- }
444
-
445
- .repeater.disabled > .acf-input-table > tbody > tr:hover > td.remove > a.acf-button-add {
446
- visibility: hidden !important;
447
- }
448
-
449
- .repeater a.acf-button-add,
450
- .repeater a.acf-button-remove {
451
- position: absolute;
452
-
453
- -webkit-transition: opacity 0.25s 0s ease-in-out, visibility 0s linear 0.25s;
454
- -moz-transition: opacity 0.25s 0s ease-in-out, visibility 0s linear 0.25s;
455
- -o-transition: opacity 0.25s 0s ease-in-out, visibility 0s linear 0.25s;
456
- transition: opacity 0.25s 0s ease-in-out, visibility 0s linear 0.25s;
457
-
458
- visibility: hidden;
459
- opacity: 0;
460
- }
461
-
462
- .repeater a.acf-button-remove {
463
- position: relative;
464
- }
465
-
466
- .repeater > table > thead > tr > th.order,
467
- .repeater > table > tbody > tr > td.order{
468
- width: 16px !important;
469
- text-align: center !important;
470
- vertical-align: middle;
471
- color: #aaa;
472
- text-shadow: #fff 0 1px 0;
473
-
474
- cursor: move;
475
- }
476
-
477
- .repeater > table > tbody > tr > td.order {
478
- border-right-color: #E1E1E1;
479
- background: #f4f4f4;
480
- }
481
-
482
- .repeater > table > tbody > tr > td.remove {
483
- background: #F9F9F9;
484
- }
485
-
486
-
487
- .repeater > table > thead > tr > th.order:hover,
488
- .repeater > table > tbody > tr > td.order:hover {
489
- color: #666;
490
- }
491
-
492
- .repeater > table > thead > tr > th.remove,
493
- .repeater > table > tbody > tr > td.remove{
494
- width: 16px;
495
- vertical-align: middle;
496
- }
497
-
498
- .repeater .repeater-footer {
499
- margin: 8px 0;
500
- }
501
-
502
- .repeater tr.row-clone {
503
- display: none;
504
- }
505
-
506
- .repeater > table > tbody > tr.ui-sortable-helper {
507
- box-shadow: 0 1px 5px rgba(0,0,0,0.2);
508
- }
509
-
510
- .repeater > table > tbody > tr.ui-sortable-placeholder {
511
- visibility: visible !important;
512
- }
513
-
514
- .repeater > table > tbody > tr.ui-sortable-placeholder td {
515
- border: 0 none !important;
516
- box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
517
- background: rgba(0,0,0,0.075);
518
- }
519
-
520
-
521
- /* empty repeater */
522
- .repeater.empty table thead th {
523
- border-bottom: 0 none;
524
- }
525
-
526
  td.acf_input-wrap {
527
  padding: 0 !important;;
528
  }
@@ -685,535 +579,46 @@ td.acf_input-wrap {
685
 
686
  /*---------------------------------------------------------------------------------------------
687
  *
688
- * Field: Flexible Content
689
  *
690
  *---------------------------------------------------------------------------------------------*/
691
 
692
- .acf_flexible_content {
693
- position: relative;
694
- }
695
-
696
- .acf_flexible_content .layout {
697
- margin: 20px 0 0;
698
- position: relative;
699
-
700
- border-radius: 0;
701
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
702
- background: #fff;
703
- }
704
-
705
- .acf_flexible_content .layout:first-child {
706
- margin-top: 0;
707
- }
708
-
709
- .acf_flexible_content .layout .menu-item-handle {
710
- display: block;
711
- position: relative;
712
- border-radius: 0;
713
- width: auto;
714
- margin: 0;
715
-
716
- color: #666;
717
- }
718
-
719
- .acf_flexible_content .layout .fc-delete-layout {
720
- width: 35px;
721
- height: 35px;
722
-
723
- position: absolute;
724
- top: 1px;
725
- right: 1px;
726
- z-index: 1;
727
-
728
- display: none;
729
-
730
- background: url(../images/sprite.png) no-repeat scroll -57px -208px;
731
- }
732
-
733
- .acf_flexible_content .layout:hover .fc-delete-layout {
734
- display: block;
735
- }
736
-
737
- .acf_flexible_content .layout .fc-delete-layout:hover {
738
- background-position: -57px -258px;
739
- }
740
-
741
- .acf_flexible_content .clones {
742
- display: none;
743
- }
744
-
745
- .acf_flexible_content > .values > .ui-sortable-placeholder {
746
- visibility: visible !important;
747
- border: #DFDFDF dashed 2px;
748
- border-radius: 3px;
749
- box-shadow: none;
750
- }
751
-
752
- .acf_flexible_content .layout > .acf-input-table {
753
- border-top: 0 none;
754
- box-shadow: none;
755
- }
756
-
757
- .acf_flexible_content .layout > .acf-input-table > tbody > tr {
758
- background: #fff;
759
- }
760
-
761
- .acf_flexible_content .layout > .acf-input-table > thead > tr > th {
762
- background: none repeat scroll 0 0 #F9F9F9;
763
- border-bottom: 1px solid #E1E1E1;
764
- border-right: 1px solid #E1E1E1;
765
-
766
- font-size: 12px;
767
- font-family: sans-serif;
768
- font-weight: bold;
769
- }
770
-
771
- .acf_flexible_content .layout > .acf-input-table > thead > tr > th:last-child {
772
- border-right: 0 none;
773
- }
774
-
775
- .acf-popup {
776
- position: absolute;
777
- bottom: 25px;
778
- right: 0;
779
- background: #464646;
780
- border-radius: 5px;
781
- box-shadow: rgba(0,0,0,0.4) 0 0 13px;
782
- margin-right: -5px;
783
- min-width: 135px;
784
- z-index: 99;
785
-
786
- -webkit-transition: bottom 0.25s 0s, opacity 0.25s 0s ease-in-out, visibility 0s linear 0.25s;
787
- -moz-transition: bottom 0.25s 0s, opacity 0.25s 0s ease-in-out, visibility 0s linear 0.25s;
788
- -o-transition: bottom 0.25s 0s, opacity 0.25s 0s ease-in-out, visibility 0s linear 0.25s;
789
- transition: bottom 0.25s 0s, opacity 0.25s 0s ease-in-out, visibility 0s linear 0.25s;
790
 
791
- visibility: hidden;
792
- opacity: 0;
793
  }
794
 
795
- .acf-popup.active {
796
- visibility: visible;
797
- opacity: 1;
798
- bottom: 35px;
799
 
800
- -webkit-transition-delay:0s;
801
- -moz-transition-delay:0s;
802
- -o-transition-delay:0s;
803
- transition-delay:0s;
804
- }
805
-
806
- .has-right-sidebar .acf-popup {
807
- margin-right: -17px;
808
- }
809
-
810
- .has-right-sidebar .acf-popup .bit {
811
- right: 37px;
812
- }
813
-
814
- .acf-popup .bit {
815
- position: absolute;
816
- width: 56px;
817
- height: 25px;
818
- right: 17px;
819
- margin: -1px 0 0;
820
- background: url(../images/sprite.png) 0 -50px no-repeat;
821
- }
822
-
823
- .acf-popup ul {
824
- display: block;
825
- margin: 0;
826
- padding: 0;
827
- }
828
-
829
- .acf-popup ul li {
830
- display: block;
831
- position: relative;
832
- margin: -1px 0 0;
833
- padding: 0;
834
- float: none;
835
- }
836
-
837
- .acf-popup ul li:first-child {
838
- margin: 0;
839
- }
840
-
841
- .acf-popup ul li a {
842
- color: #cccccc;
843
- font-size: 12px;
844
- line-height: 14px;
845
- padding: 7px 11px;
846
- display: block;
847
- border: 1px solid #333333;
848
- box-shadow: inset 0 1px 0 #555555;
849
- text-decoration: none;
850
- min-width: 100px;
851
- text-shadow: 0 1px 0 #222222;
852
- }
853
-
854
- .acf-popup ul li:first-child a {
855
- border-radius: 5px 5px 0 0;
856
- }
857
-
858
- .acf-popup ul li:last-child a {
859
- border-radius: 0 0 5px 5px;
860
- }
861
-
862
- .acf-popup ul li:only-child a {
863
- border-radius: 5px 5px 5px 5px;
864
- }
865
-
866
- .acf-popup ul li a:hover {
867
- background: #2b8ab8;
868
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#3da0d1', endColorstr='#1f81b2'); /* for IE */
869
- background: -webkit-gradient(linear, left top, left bottom, from(#3da0d1), to(#1f81b2)); /* for webkit browsers */
870
- background: -moz-linear-gradient(top, #3da0d1, #1f81b2); /* for firefox 3.6+ */
871
- border: 1px solid #195572 !important;
872
- box-shadow: inset 0 1px 0 #54b5e5;
873
- color: #FFFFFF;
874
- text-shadow: 0 1px 0 #082e40;
875
- cursor: pointer;
876
- }
877
-
878
- .acf_flexible_content .no_value_message {
879
- padding: 19px;
880
- border: #ccc dashed 1px;
881
- text-align: center;
882
- }
883
-
884
- #acf_color_picker {
885
- position: absolute;
886
- top: 0;
887
- left: 0;
888
- display: none;
889
- background: #fff;
890
- border: #AAAAAA solid 1px;
891
- border-radius: 4px;
892
- }
893
-
894
- .acf_flexible_content .flexible-footer {
895
- margin: 20px 0 0;
896
- }
897
-
898
- /*---------------------------------------------------------------------------------------------
899
- Taxonomy Edit Error
900
- ---------------------------------------------------------------------------------------------*/
901
-
902
- .form-table {
903
- margin-left: 1px; /* Needed to show the left border - WP has an overflow hidden */
904
- }
905
- .form-table .field.error th,
906
- .form-table .field.error td {
907
- background: #FFEBE8;
908
- border: #CC0000 solid 1px;
909
- }
910
-
911
- .form-table .field.error th{
912
- border-right: 0 none;
913
  }
914
- .form-table .field.error td{
915
- border-left: 0 none;
916
- }
917
-
918
-
919
- .form-table .field.error label {
920
- color: #CC0000;
921
- }
922
-
923
-
924
- /*---------------------------------------------------------------------------------------------
925
- *
926
- * Everythign Field fixes
927
- *
928
- *---------------------------------------------------------------------------------------------*/
929
-
930
- .media-item .describe .repeater > table > thead > tr > th {
931
- width: auto;
932
- }
933
-
934
-
935
- /*---------------------------------------------------------------------------------------------
936
- *
937
- * Gallery Field
938
- *
939
- *---------------------------------------------------------------------------------------------*/
940
 
941
- .acf-gallery {
942
- position: relative;
943
- overflow: hidden;
944
  border: #DFDFDF solid 1px;
945
  border-radius: 3px;
 
 
946
  }
947
 
948
- .acf-gallery .thumbnails {
949
- background-color:#f9f9f9;
950
-
951
- box-shadow: inset 0px 1px 5px rgba(0,0,0,0.06);
952
-
953
- min-height: 400px;
954
- margin: 0 0 0 0;
955
-
956
- position: relative;
957
- z-index: 1;
958
-
959
-
960
- }
961
-
962
- .acf-gallery .thumbnails .inner {
963
  padding: 10px;
964
- position: relative;
965
- }
966
-
967
- .acf-gallery .thumbnail {
968
- margin: 10px;
969
- position: relative;
970
- float: left;
971
-
972
- background: #fff;
973
- box-shadow: 0 1px 2px rgba(0,0,0,0.2);
974
-
975
- cursor: move;
976
- }
977
-
978
- .acf-gallery .thumbnail .inner {
979
- padding: 5px;
980
- }
981
-
982
- .acf-gallery .thumbnail img {
983
- display: block;
984
- }
985
-
986
- .acf-gallery .thumbnail.ui-sortable-placeholder {
987
- visibility: visible !important;
988
- background: transparent;
989
- box-shadow: none;
990
- border: #DFDFDF dashed 2px;
991
- border-radius: 3px;
992
- }
993
-
994
-
995
- /*
996
- * Toolbar
997
- */
998
-
999
- .acf-gallery .toolbar {
1000
- border-top: #DFDFDF solid 1px;
1001
-
1002
- background-color: #F1F1F1;
1003
- background-image: -webkit-gradient(linear, left top, left bottom, from(#F9F9F9), to(#ECECEC)); /* Saf4+, Chrome */
1004
- background-image: -webkit-linear-gradient(top, #F9F9F9, #ECECEC); /* Chrome 10+, Saf5.1+, iOS 5+ */
1005
- background-image: -moz-linear-gradient(top, #F9F9F9, #ECECEC); /* FF3.6+ */
1006
- background-image: -o-linear-gradient(top, #F9F9F9, #ECECEC); /* Opera 11.10+ */
1007
- background-image: linear-gradient(to bottom, #F9F9F9, #ECECEC);
1008
-
1009
- }
1010
-
1011
- .acf-gallery .toolbar li {
1012
- font-size: 12px;
1013
- line-height: 1em;
1014
- position: relative;
1015
- min-height: 36px;
1016
- }
1017
-
1018
- .acf-gallery .toolbar li.view-grid-li:hover,
1019
- .acf-gallery .toolbar li.view-grid-li.active,
1020
- .acf-gallery .toolbar li.view-list-li:hover,
1021
- .acf-gallery .toolbar li.view-list-li.active {
1022
- background-color: #F9F9F9;
1023
- background-image: -webkit-gradient(linear, left top, left bottom, from(#ECECEC), to(#F9F9F9)); /* Saf4+, Chrome */
1024
- background-image: -webkit-linear-gradient(top, #ECECEC, #F9F9F9); /* Chrome 10+, Saf5.1+, iOS 5+ */
1025
- background-image: -moz-linear-gradient(top, #ECECEC, #F9F9F9); /* FF3.6+ */
1026
- background-image: -o-linear-gradient(top, #ECECEC, #F9F9F9); /* Opera 11.10+ */
1027
- background-image: linear-gradient(to bottom, #ECECEC, #F9F9F9);
1028
- }
1029
-
1030
- .acf-gallery .toolbar li.gallery-li a,
1031
- .acf-gallery .toolbar li.gallery-li span {
1032
- display: block;
1033
- padding: 1em;
1034
-
1035
- color: #333333;
1036
- text-shadow: #fff 0 1px 0;
1037
-
1038
- text-decoration: none;
1039
- }
1040
-
1041
- .acf-gallery .toolbar li.gallery-li span {
1042
- color: #8d8d8d;
1043
- }
1044
-
1045
- .acf-gallery .toolbar li .divider {
1046
- position: absolute;
1047
- height: 100%;
1048
- width: 1px;
1049
- background: #dfdfdf;
1050
- border-right: #fff solid 1px;
1051
-
1052
- top: 0;
1053
- right: 0;
1054
- margin-right: -1px;
1055
- }
1056
-
1057
- .acf-gallery .toolbar li .divider-left {
1058
- right: auto;
1059
- margin-right: 0;
1060
- left: 0;
1061
- margin-left: -1px;
1062
- }
1063
-
1064
- .acf-gallery .toolbar .view-grid,
1065
- .acf-gallery .toolbar .view-list {
1066
- width: 36px;
1067
- height: 36px;
1068
- background: url(../images/sprite.png) -8px -307px no-repeat;
1069
- }
1070
-
1071
- .acf-gallery .toolbar .view-list {
1072
- background-position: -58px -307px;
1073
- }
1074
-
1075
- .acf-gallery .toolbar .view-grid-li,
1076
- .acf-gallery .toolbar .view-list-li {
1077
- position: absolute;
1078
- left: 50%;
1079
- }
1080
-
1081
- .acf-gallery .toolbar .view-grid-li {
1082
- margin-left: -36px;
1083
- }
1084
-
1085
- .acf-gallery .toolbar .acf-button {
1086
- margin: 4px 0 0 4px;
1087
- }
1088
-
1089
-
1090
- /*
1091
- * Hover
1092
- */
1093
-
1094
- .acf-gallery .hover {
1095
- position: absolute;
1096
- top: -11px;
1097
- right: -11px;
1098
-
1099
- -webkit-transition: opacity 0.25s 0s ease-in-out, visibility 0s linear 0.25s;
1100
- -moz-transition: opacity 0.25s 0s ease-in-out, visibility 0s linear 0.25s;
1101
- -o-transition: opacity 0.25s 0s ease-in-out, visibility 0s linear 0.25s;
1102
- transition: opacity 0.25s 0s ease-in-out, visibility 0s linear 0.25s;
1103
-
1104
- visibility: hidden;
1105
- opacity: 0;
1106
  }
1107
 
1108
- .acf-gallery .thumbnail:hover .hover {
1109
- -webkit-transition-delay:0s;
1110
- -moz-transition-delay:0s;
1111
- -o-transition-delay:0s;
1112
- transition-delay:0s;
1113
 
1114
- visibility: visible;
1115
- opacity: 1;
1116
- }
1117
-
1118
- .acf-gallery .hover ul {
1119
- display: block;
1120
- margin: 0;
1121
- padding: 0;
1122
- }
1123
-
1124
- .acf-gallery .hover ul li {
1125
- margin: 0 0 5px 0;
1126
- }
1127
-
1128
-
1129
-
1130
- /*
1131
- * List Data
1132
- */
1133
-
1134
- .acf-gallery .list-data {
1135
- display: none;
1136
- }
1137
-
1138
- .acf-gallery.view-list .thumbnail {
1139
- float: none;
1140
- }
1141
-
1142
- .acf-gallery.view-list .thumbnail .list-data {
1143
- display: block;
1144
- margin: 0 0 0 127px;
1145
- }
1146
-
1147
- .acf-gallery.view-list .thumbnail img {
1148
- float: left;
1149
- max-width: 122px;
1150
- height: auto;
1151
- }
1152
-
1153
- .acf-gallery .list-data table {
1154
- text-align: left;
1155
- width: 100%;
1156
- border-collapse: collapse;
1157
  }
1158
 
1159
- .acf-gallery .list-data table th,
1160
- .acf-gallery .list-data table td {
1161
- border: 1px solid #F1F1F1;
1162
- padding: 6px;
1163
- }
1164
-
1165
- .acf-gallery .list-data table th {
1166
- width: 110px;
1167
- }
1168
-
1169
-
1170
- /*
1171
- * Edit Image Message
1172
- */
1173
-
1174
- .acf-gallery .acf-message-wrapper {
1175
- margin: 0;
1176
- position: absolute;
1177
- z-index: 1;
1178
- width: 100%;
1179
- background: #fff;
1180
- }
1181
-
1182
- .acf-gallery .acf-message-wrapper .message {
1183
- margin: 5px !important;
1184
- }
1185
-
1186
- .acf-gallery.view-list .acf-message-wrapper {
1187
- padding: 5px 5px 0;
1188
- position: relative;
1189
- width: auto;
1190
- }
1191
-
1192
- .acf-gallery.view-list .acf-message-wrapper .message {
1193
- margin: 0px !important;
1194
- }
1195
-
1196
-
1197
- /*
1198
- * 3.5 Media Selected images
1199
- */
1200
-
1201
- .attachment.acf-selected {
1202
- opacity: 0.3;
1203
- }
1204
-
1205
- .attachment.acf-selected .check {
1206
- display: block;
1207
  }
1208
 
1209
 
1210
  /*---------------------------------------------------------------------------------------------
1211
  *
1212
- * Tab
1213
  *
1214
  *---------------------------------------------------------------------------------------------*/
1215
 
1216
- .field-tab {
1217
  display: none !important;
1218
 
1219
  }
@@ -1285,6 +690,22 @@ td.acf_input-wrap {
1285
  }
1286
 
1287
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1288
  /*--------------------------------------------------------------------------
1289
  *
1290
  * Tab Group
@@ -1329,6 +750,20 @@ tr.acf-conditional_logic-show {
1329
  display: none;
1330
  }
1331
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1332
 
1333
 
1334
  /*--------------------------------------------------------------------------
112
  padding-top: 0;
113
  }
114
 
115
+ #poststuff .acf_postbox .field_type-message p.label {
116
+ display: none !important;
117
+ }
118
 
119
  /*---------------------------------------------------------------------------------------------
120
  *
125
  .acf_postbox .field input[type="text"],
126
  .acf_postbox .field input[type="number"],
127
  .acf_postbox .field input[type="password"],
128
+ .acf_postbox .field input[type="email"],
129
  .acf_postbox .field textarea{
130
  width: 100%;
131
  padding: 5px;
143
  resize: none;
144
  }
145
 
146
+
147
+
148
  .acf_postbox .field select optgroup {
149
  padding: 5px;
150
  background: #fff;
 
151
  }
152
 
153
  .acf_postbox .field select option {
155
  }
156
 
157
  .acf_postbox .field select optgroup option {
158
+ padding-left: 5px;
159
  }
160
 
161
  .acf_postbox .field select optgroup:nth-child(2n) {
162
  background: #F9F9F9;
163
  }
164
 
 
 
 
 
 
 
 
 
165
 
166
  /*---------------------------------------------------------------------------------------------
167
  *
358
 
359
  /*---------------------------------------------------------------------------------------------
360
  *
361
+ * Input Table
362
  *
363
  *---------------------------------------------------------------------------------------------*/
364
 
376
  border-right: 1px solid #e1e1e1;
377
  }
378
 
 
 
 
 
379
  .acf-input-table > tbody {}
380
 
381
  .acf-input-table > tbody > tr {
417
  }
418
 
419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
  td.acf_input-wrap {
421
  padding: 0 !important;;
422
  }
579
 
580
  /*---------------------------------------------------------------------------------------------
581
  *
582
+ * Field: Taxonomy
583
  *
584
  *---------------------------------------------------------------------------------------------*/
585
 
586
+ .acf-taxonomy-field {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
587
 
 
 
588
  }
589
 
590
+ .acf-taxonomy-field ul {
 
 
 
591
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
593
 
594
+ .acf-taxonomy-field .categorychecklist-holder {
 
 
595
  border: #DFDFDF solid 1px;
596
  border-radius: 3px;
597
+ max-height: 200px;
598
+ overflow: auto;
599
  }
600
 
601
+ .acf-taxonomy-field .categorychecklist {
602
+ margin: 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
603
  padding: 10px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
  }
605
 
606
+ .acf-taxonomy-field ul li {
 
 
 
 
607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608
  }
609
 
610
+ .acf-taxonomy-field ul.children {
611
+ padding-left: 18px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
612
  }
613
 
614
 
615
  /*---------------------------------------------------------------------------------------------
616
  *
617
+ * Field: Tab
618
  *
619
  *---------------------------------------------------------------------------------------------*/
620
 
621
+ .field_type-tab {
622
  display: none !important;
623
 
624
  }
690
  }
691
 
692
 
693
+ /*---------------------------------------------------------------------------------------------
694
+ *
695
+ * Other
696
+ *
697
+ *---------------------------------------------------------------------------------------------*/
698
+
699
+ .form-field.field input[type="checkbox"],
700
+ .form-field.field input[type="radio"] {
701
+ width: auto !important;
702
+ }
703
+
704
+ #createuser input,
705
+ #your-profile input {
706
+ max-width: 25em;
707
+ }
708
+
709
  /*--------------------------------------------------------------------------
710
  *
711
  * Tab Group
750
  display: none;
751
  }
752
 
753
+ .hl.acf-tab-group > li.acf-conditional_logic-hide {
754
+ display: none;
755
+ }
756
+
757
+
758
+ #acf_color_picker {
759
+ position: absolute;
760
+ top: 0;
761
+ left: 0;
762
+ display: none;
763
+ background: #fff;
764
+ border: #AAAAAA solid 1px;
765
+ border-radius: 4px;
766
+ }
767
 
768
 
769
  /*--------------------------------------------------------------------------
images/add-ons/flexible-content-field-thumb.jpg ADDED
Binary file
images/add-ons/gallery-field-thumb.jpg ADDED
Binary file
images/add-ons/options-page-thumb.jpg ADDED
Binary file
images/add-ons/repeater-field-thumb.jpg ADDED
Binary file
images/sprite.png CHANGED
Binary file
images/sprite@2x.png CHANGED
Binary file
js/field-group.js CHANGED
@@ -1,18 +1,27 @@
1
  var acf = {
2
  post_id : 0,
 
3
  text : {
4
  'move_to_trash' : "Move to trash. Are you sure?",
5
  'checked' : 'checked',
6
  'conditional_no_fields' : 'No "toggle" fields available',
7
- 'flexible_content_no_fields' : 'Flexible Content requires at least 1 layout'
 
8
  },
9
- fields : [],
10
- sortable_helper : null,
11
- nonce : ''
 
 
 
 
 
 
12
  };
13
 
14
  (function($){
15
 
 
16
  /*
17
  * Exists
18
  *
@@ -34,7 +43,7 @@ var acf = {
34
  * @created: 10/11/12
35
  */
36
 
37
- acf.sortable_helper = function(e, ui)
38
  {
39
  ui.children().each(function(){
40
  $(this).width($(this).width());
@@ -44,19 +53,89 @@ var acf = {
44
 
45
 
46
  /*
47
- * uniqid
48
- *
49
- * @since 3.1.6
50
- * @description Returns a unique ID (secconds of time)
 
51
  */
52
 
53
- function uniqid()
54
  {
55
- var newDate = new Date;
56
- return newDate.getTime();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  }
 
58
 
59
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  /*
61
  * Place Confirm message on Publish trash button
62
  *
@@ -66,8 +145,8 @@ var acf = {
66
 
67
  $('#submit-delete').live('click', function(){
68
 
69
- var response = confirm(acf.text.move_to_trash);
70
- if(!response)
71
  {
72
  return false;
73
  }
@@ -95,7 +174,7 @@ var acf = {
95
 
96
 
97
  // update data atts
98
- field.removeClass('field-' + field_type).addClass('field-' + val);
99
  field.attr('data-type', val);
100
 
101
 
@@ -136,7 +215,7 @@ var acf = {
136
 
137
 
138
  var ajax_data = {
139
- 'action' : 'acf_field_options',
140
  'post_id' : acf.post_id,
141
  'field_key' : select.attr('name'),
142
  'field_type' : val,
@@ -152,7 +231,8 @@ var acf = {
152
 
153
  if( ! html )
154
  {
155
- alert('Error: Could not load field options');
 
156
  }
157
 
158
  tr.replaceWith(html);
@@ -176,14 +256,10 @@ var acf = {
176
  {
177
  var field = $(this),
178
  old_id = field.attr('data-id'),
179
- new_id = uniqid();
180
 
181
 
182
- // temp give field unique ID for id / name.
183
- // Because this is an AJAX call, it will take some time to get back the new_id.
184
- // in this time, the new field will be added and the origional, and duplicate field
185
- // will both use the same ID! This will cause browsers to remove the input settings on the first field
186
-
187
  field.attr('data-id', new_id);
188
 
189
 
@@ -206,52 +282,6 @@ var acf = {
206
  $(this).attr('name', $(this).attr('name').replace(old_id, new_id) );
207
  });
208
 
209
-
210
- // onld_id is now the unique_id() value
211
- old_id = new_id;
212
-
213
-
214
- // load location html
215
- $.ajax({
216
- url: ajaxurl,
217
- data: {
218
- 'action' : 'acf_next_field_id',
219
- 'nonce' : acf.nonce
220
- },
221
- type: 'post',
222
- dataType: 'html',
223
- success: function( new_id ){
224
-
225
- // remove phantom new lines...
226
- new_id = new_id.replace(/(\r\n|\n|\r)/gm,"");
227
-
228
-
229
- // give field a new id
230
- field.attr('data-id', new_id);
231
-
232
-
233
- // update class
234
- field.attr('class', field.attr('class').replace(old_id, new_id) );
235
-
236
-
237
- // update field key column
238
- field.find('.field_meta td.field_key').text( new_id );
239
-
240
-
241
- // update attributes
242
- field.find('[id*="' + old_id + '"]').each(function()
243
- {
244
- $(this).attr('id', $(this).attr('id').replace(old_id, new_id) );
245
- });
246
-
247
- field.find('[name*="' + old_id + '"]').each(function()
248
- {
249
- $(this).attr('name', $(this).attr('name').replace(old_id, new_id) );
250
- });
251
-
252
- }
253
- });
254
-
255
  }
256
 
257
 
@@ -283,7 +313,7 @@ var acf = {
283
  */
284
 
285
  $('#acf_fields a.acf_edit_field').live('click', function(){
286
-
287
  var field = $(this).closest('.field');
288
 
289
  if( field.hasClass('form_open') )
@@ -299,7 +329,6 @@ var acf = {
299
 
300
  field.children('.field_form_mask').animate({'height':'toggle'}, 500);
301
 
302
-
303
  });
304
 
305
 
@@ -361,12 +390,24 @@ var acf = {
361
  // vars
362
  var a = $(this),
363
  field = a.closest('.field'),
364
- new_field = field.clone();
365
 
366
 
 
 
 
 
 
 
 
 
 
367
 
368
  // update names
369
  new_field.update_names();
 
 
 
370
 
371
 
372
  // add new field
@@ -384,6 +425,22 @@ var acf = {
384
  }
385
 
386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  // update order numbers
388
  update_order_numbers();
389
 
@@ -400,24 +457,23 @@ var acf = {
400
 
401
  $('#acf_fields #add_field').live('click',function(){
402
 
403
- var table_footer = $(this).closest('.table_footer');
404
- var fields = table_footer.siblings('.fields');
405
 
406
 
407
  // clone last tr
408
- var new_field = fields.children('.field-field_clone').clone();
409
 
410
 
411
  // update names
412
  new_field.update_names();
413
 
414
 
415
- // show (update_names will remove the field_clone field, but not for a few seconds)
416
  new_field.show();
417
 
418
 
419
  // append to table
420
- fields.children('.field-field_clone').before(new_field);
421
 
422
 
423
  // remove no fields message
@@ -428,11 +484,17 @@ var acf = {
428
 
429
 
430
  // clear name
431
- new_field.find('.field_form input[type="text"]').val('');
432
- new_field.find('.field_form input[type="text"]').first().focus();
433
  new_field.find('tr.field_type select').trigger('change');
 
434
 
435
 
 
 
 
 
 
 
 
436
  // open up form
437
  new_field.find('a.acf_edit_field').first().trigger('click');
438
 
@@ -491,11 +553,7 @@ var acf = {
491
  var val = $(this).val();
492
  var label = $(this).find('option[value="' + val + '"]').html();
493
 
494
- // update field type (if not a clone field)
495
- if($(this).closest('.field_clone').length == 0)
496
- {
497
- $(this).closest('.field').find('td.field_type').first().html(label);
498
- }
499
 
500
  });
501
 
@@ -555,7 +613,8 @@ var acf = {
555
  var tr = $(this).closest('tr'),
556
  i = tr.attr('data-i'),
557
  ajax_data = {
558
- 'action' : "acf_location",
 
559
  'key' : i,
560
  'value' : '',
561
  'param' : $(this).val()
@@ -677,236 +736,6 @@ var acf = {
677
  });
678
 
679
 
680
- /*
681
- * Flexible Content
682
- *
683
- * @description: extra javascript for the flexible content field
684
- * @created: 3/03/2011
685
- */
686
-
687
- /*----------------------------------------------------------------------
688
- *
689
- * Add Layout Option
690
- *
691
- *---------------------------------------------------------------------*/
692
-
693
- $('#acf_fields .acf_fc_add').live('click', function(){
694
-
695
- // vars
696
- var tr = $(this).closest('tr.field_option_flexible_content'),
697
- new_tr = tr.clone(false),
698
- id = new_tr.attr('data-id'),
699
- new_id = uniqid();
700
-
701
-
702
- // remove sub fields
703
- new_tr.find('.field:not(.field-field_clone)').remove();
704
-
705
- // show add new message
706
- new_tr.find('.no_fields_message').show();
707
-
708
- // reset layout meta values
709
- new_tr.find('.acf_cf_meta input[type="text"]').val('');
710
-
711
-
712
- // update id / names
713
- new_tr.find('[name]').each(function(){
714
-
715
- var name = $(this).attr('name').replace('[layouts]['+id+']','[layouts]['+new_id+']');
716
- $(this).attr('name', name);
717
- $(this).attr('id', name);
718
-
719
- });
720
-
721
- // update data-id
722
- new_tr.attr('data-id', new_id);
723
-
724
- // add new tr
725
- tr.after(new_tr);
726
-
727
- // display
728
- new_tr.find('.acf_cf_meta select').val('row').trigger('change');
729
-
730
-
731
- return false;
732
- });
733
-
734
-
735
- /*----------------------------------------------------------------------
736
- *
737
- * Duplicate Layout
738
- *
739
- *---------------------------------------------------------------------*/
740
-
741
- $('#acf_fields .acf_fc_duplicate').live('click', function(){
742
-
743
- // vars
744
- var tr = $(this).closest('tr.field_option_flexible_content'),
745
- new_tr = tr.clone(false),
746
- id = new_tr.attr('data-id'),
747
- new_id = uniqid();
748
-
749
-
750
- // reset layout meta values
751
- new_tr.find('.acf_cf_meta input[type="text"]').val('');
752
- new_tr.find('.acf_cf_meta select').val('row').trigger('change');
753
-
754
-
755
- // update id / names
756
- new_tr.find('[name]').each(function(){
757
-
758
- var name = $(this).attr('name').replace('[layouts]['+id+']','[layouts]['+new_id+']');
759
- $(this).attr('name', name);
760
- $(this).attr('id', name);
761
-
762
- });
763
-
764
-
765
- // update data-id
766
- new_tr.attr('data-id', new_id);
767
-
768
-
769
- // add new tr
770
- tr.after(new_tr);
771
-
772
-
773
- return false;
774
- });
775
-
776
-
777
- /*----------------------------------------------------------------------
778
- *
779
- * Delete Layout Option
780
- *
781
- *---------------------------------------------------------------------*/
782
-
783
- $('#acf_fields .acf_fc_delete').live('click', function(){
784
-
785
- var tr = $(this).closest('tr.field_option_flexible_content'),
786
- tr_count = tr.siblings('tr.field_option.field_option_flexible_content').length;
787
-
788
- if( tr_count <= 1 )
789
- {
790
- alert( acf.text.flexible_content_no_fields );
791
- return false;
792
- }
793
-
794
- tr.animate({'left' : '50px', 'opacity' : 0}, 250, function(){
795
- tr.remove();
796
- });
797
-
798
- });
799
-
800
-
801
- /*----------------------------------------------------------------------
802
- *
803
- * Sortable Layout Option
804
- *
805
- *---------------------------------------------------------------------*/
806
-
807
- $('#acf_fields .acf_fc_reorder').live('mouseover', function(){
808
-
809
- var table = $(this).closest('table.acf_field_form_table');
810
-
811
- if(table.hasClass('sortable')) return false;
812
-
813
- table.addClass('sortable').children('tbody').sortable({
814
- items: ".field_option_flexible_content",
815
- handle: 'a.acf_fc_reorder',
816
- helper: acf.sortable_helper,
817
- forceHelperSize : true,
818
- forcePlaceholderSize : true,
819
- scroll : true,
820
- start : function (event, ui) {
821
-
822
- // add markup to the placeholder
823
- var td_count = ui.item.children('td').length;
824
- ui.placeholder.html('<td colspan="' + td_count + '"></td>');
825
-
826
- }
827
- });
828
-
829
- });
830
-
831
-
832
- /*----------------------------------------------------------------------
833
- *
834
- * Label update name
835
- *
836
- *---------------------------------------------------------------------*/
837
-
838
- $('#acf_fields .acf_fc_label input[type="text"]').live('blur', function(){
839
-
840
- var label = $(this);
841
- var name = $(this).parents('td').siblings('td.acf_fc_name').find('input[type="text"]');
842
-
843
- if(name.val() == '')
844
- {
845
- var val = label.val().toLowerCase().split(' ').join('_').split('\'').join('');
846
- name.val(val);
847
- name.trigger('keyup');
848
- }
849
-
850
- });
851
-
852
-
853
- /*
854
- * Repeater CHange layout display (Row | Table)
855
- *
856
- * @description:
857
- * @since 3.5.2
858
- * @created: 18/11/12
859
- */
860
-
861
- $('#acf_fields .field_option_repeater_layout input[type="radio"]').live('click', function(){
862
-
863
- // vars
864
- var radio = $(this);
865
-
866
-
867
- // Set class
868
- radio.closest('.field_option_repeater').siblings('.field_option_repeater_fields').find('.repeater:first').removeClass('layout-row').removeClass('layout-table').addClass( 'layout-' + radio.val() );
869
-
870
- });
871
-
872
- $(document).live('acf/field_form-open', function(e, field){
873
-
874
- $(field).find('.field_option_repeater_layout input[type="radio"]:checked').each(function(){
875
- $(this).trigger('click');
876
- });
877
-
878
- });
879
-
880
-
881
-
882
- /*
883
- * Flexible Content CHange layout display (Row | Table)
884
- *
885
- * @description:
886
- * @since 3.5.2
887
- * @created: 18/11/12
888
- */
889
-
890
- $('#acf_fields .acf_fc_display select').live('change', function(){
891
-
892
- // vars
893
- var select = $(this);
894
-
895
-
896
- // Set class
897
- select.closest('.repeater').removeClass('layout-row').removeClass('layout-table').addClass( 'layout-' + select.val() );
898
-
899
- });
900
-
901
- $(document).live('acf/field_form-open', function(e, field){
902
-
903
- $(field).find('.acf_fc_display select').each(function(){
904
- $(this).trigger('change');
905
- });
906
-
907
- });
908
-
909
-
910
 
911
  /*
912
  * Screen Options
@@ -937,7 +766,7 @@ var acf = {
937
  * @created: 11/10/12
938
  */
939
 
940
- acf.create_field = function( options ){
941
 
942
  // dafaults
943
  var defaults = {
@@ -983,7 +812,7 @@ var acf = {
983
  $(document).live('acf/field_form-open', function(e, field){
984
 
985
  // populate fields
986
- acf.setup_conditional_fields();
987
 
988
 
989
  $(field).find('.conditional-logic-field').each(function(){
@@ -994,13 +823,13 @@ var acf = {
994
 
995
 
996
  // populate choices
997
- if( acf.fields )
998
  {
999
- for( i = 0; i < acf.fields.length; i++ )
1000
  {
1001
  choices.push({
1002
- value : acf.fields[i].id,
1003
- label : acf.fields[i].label
1004
  });
1005
  }
1006
  }
@@ -1017,7 +846,7 @@ var acf = {
1017
 
1018
 
1019
  // create select
1020
- select = acf.create_field({
1021
  'type' : 'select',
1022
  'class' : 'conditional-logic-field',
1023
  'name' : name,
@@ -1070,8 +899,8 @@ var acf = {
1070
 
1071
  // vars
1072
  var id = $(this).val(),
1073
- field = $('#acf_fields .field-' + id),
1074
- type = field.find('tr.field_type select').val(),
1075
  conditional_function = $(this).closest('tr').find('.conditional-logic-value');
1076
 
1077
 
@@ -1114,7 +943,7 @@ var acf = {
1114
 
1115
 
1116
  // create select
1117
- select = acf.create_field({
1118
  'type' : 'select',
1119
  'class' : 'conditional-logic-value',
1120
  'name' : conditional_function.attr('name'),
@@ -1137,20 +966,25 @@ var acf = {
1137
  * @created: 15/10/12
1138
  */
1139
 
1140
- acf.setup_conditional_fields = function()
1141
  {
1142
- acf.fields = [];
 
 
1143
 
1144
- $('#acf_fields > .inside > .fields > .field').each(function(){
 
1145
 
1146
  var field = $(this),
1147
- id = field.attr('data-id');
1148
- type = field.find('tr.field_type select').val(),
 
1149
  label = field.find('tr.field_label input').val();
1150
 
 
1151
  if( type == 'select' || type == 'checkbox' || type == 'true_false' || type == 'radio' )
1152
  {
1153
- acf.fields.push({
1154
  id : id,
1155
  type : type,
1156
  label : label
1
  var acf = {
2
  post_id : 0,
3
+ nonce : '',
4
  text : {
5
  'move_to_trash' : "Move to trash. Are you sure?",
6
  'checked' : 'checked',
7
  'conditional_no_fields' : 'No "toggle" fields available',
8
+ 'title' : 'Field group title is required',
9
+ 'copy' : 'copy'
10
  },
11
+ helpers : {
12
+ uniqid : function(){},
13
+ sortable : function(){},
14
+ create_field : function(){}
15
+ },
16
+ conditional_logic : {
17
+ fields : [],
18
+ setup : function(){}
19
+ }
20
  };
21
 
22
  (function($){
23
 
24
+
25
  /*
26
  * Exists
27
  *
43
  * @created: 10/11/12
44
  */
45
 
46
+ acf.helpers.sortable = function(e, ui)
47
  {
48
  ui.children().each(function(){
49
  $(this).width($(this).width());
53
 
54
 
55
  /*
56
+ * acf.helpers.uniqid
57
+ *
58
+ * @description: JS equivelant of PHP uniqid
59
+ * @since: 3.6
60
+ * @created: 7/03/13
61
  */
62
 
63
+ acf.helpers.uniqid = function(prefix, more_entropy)
64
  {
65
+ // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
66
+ // + revised by: Kankrelune (http://www.webfaktory.info/)
67
+ // % note 1: Uses an internal counter (in php_js global) to avoid collision
68
+ // * example 1: uniqid();
69
+ // * returns 1: 'a30285b160c14'
70
+ // * example 2: uniqid('foo');
71
+ // * returns 2: 'fooa30285b1cd361'
72
+ // * example 3: uniqid('bar', true);
73
+ // * returns 3: 'bara20285b23dfd1.31879087'
74
+ if (typeof prefix == 'undefined') {
75
+ prefix = "";
76
+ }
77
+
78
+ var retId;
79
+ var formatSeed = function (seed, reqWidth) {
80
+ seed = parseInt(seed, 10).toString(16); // to hex str
81
+ if (reqWidth < seed.length) { // so long we split
82
+ return seed.slice(seed.length - reqWidth);
83
+ }
84
+ if (reqWidth > seed.length) { // so short we pad
85
+ return Array(1 + (reqWidth - seed.length)).join('0') + seed;
86
+ }
87
+ return seed;
88
+ };
89
+
90
+ // BEGIN REDUNDANT
91
+ if (!this.php_js) {
92
+ this.php_js = {};
93
+ }
94
+ // END REDUNDANT
95
+ if (!this.php_js.uniqidSeed) { // init seed with big random int
96
+ this.php_js.uniqidSeed = Math.floor(Math.random() * 0x75bcd15);
97
+ }
98
+ this.php_js.uniqidSeed++;
99
+
100
+ retId = prefix; // start with prefix, add current milliseconds hex string
101
+ retId += formatSeed(parseInt(new Date().getTime() / 1000, 10), 8);
102
+ retId += formatSeed(this.php_js.uniqidSeed, 5); // add seed hex string
103
+ if (more_entropy) {
104
+ // for more entropy we add a float lower to 10
105
+ retId += (Math.random() * 10).toFixed(8).toString();
106
+ }
107
+
108
+ return retId;
109
+
110
  }
111
+
112
 
113
+ /*
114
+ * Form Submit
115
+ *
116
+ * @description:
117
+ * @since: 3.6
118
+ * @created: 2/02/13
119
+ */
120
+
121
+ $('#post').live('submit', function(){
122
+
123
+ // validate post title
124
+ var title = $('#titlewrap #title');
125
+
126
+ if( !title.val() )
127
+ {
128
+ alert( acf.text.title );
129
+
130
+ title.focus();
131
+
132
+ return false;
133
+ }
134
+
135
+
136
+ });
137
+
138
+
139
  /*
140
  * Place Confirm message on Publish trash button
141
  *
145
 
146
  $('#submit-delete').live('click', function(){
147
 
148
+ var response = confirm( acf.text.move_to_trash );
149
+ if( !response )
150
  {
151
  return false;
152
  }
174
 
175
 
176
  // update data atts
177
+ field.removeClass('field_type-' + field_type).addClass('field_type-' + val);
178
  field.attr('data-type', val);
179
 
180
 
215
 
216
 
217
  var ajax_data = {
218
+ 'action' : 'acf/field_group/render_options',
219
  'post_id' : acf.post_id,
220
  'field_key' : select.attr('name'),
221
  'field_type' : val,
231
 
232
  if( ! html )
233
  {
234
+ tr.remove();
235
+ return;
236
  }
237
 
238
  tr.replaceWith(html);
256
  {
257
  var field = $(this),
258
  old_id = field.attr('data-id'),
259
+ new_id = 'field_' + acf.helpers.uniqid();
260
 
261
 
262
+ // give field a new id
 
 
 
 
263
  field.attr('data-id', new_id);
264
 
265
 
282
  $(this).attr('name', $(this).attr('name').replace(old_id, new_id) );
283
  });
284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  }
286
 
287
 
313
  */
314
 
315
  $('#acf_fields a.acf_edit_field').live('click', function(){
316
+
317
  var field = $(this).closest('.field');
318
 
319
  if( field.hasClass('form_open') )
329
 
330
  field.children('.field_form_mask').animate({'height':'toggle'}, 500);
331
 
 
332
  });
333
 
334
 
390
  // vars
391
  var a = $(this),
392
  field = a.closest('.field'),
393
+ new_field = null;
394
 
395
 
396
+ // save select values
397
+ field.find('select').each(function(){
398
+ $(this).attr( 'data-val', $(this).val() );
399
+ });
400
+
401
+
402
+ // clone field
403
+ new_field = field.clone();
404
+
405
 
406
  // update names
407
  new_field.update_names();
408
+ new_field.find('.field:not(.field_key-field_clone)').each(function(){
409
+ $(this).update_names();
410
+ });
411
 
412
 
413
  // add new field
425
  }
426
 
427
 
428
+ // update new_field label / name
429
+ var label = new_field.find('tr.field_label:first input[type="text"]'),
430
+ name = new_field.find('tr.field_name:first input[type="text"]');
431
+
432
+
433
+ // set select values
434
+ new_field.find('select').each(function(){
435
+ $(this).val( $(this).attr('data-val') ).trigger('change');
436
+ });
437
+
438
+
439
+ name.val('');
440
+ label.val( label.val() + ' (' + acf.text.copy + ')' );
441
+ label.trigger('blur').trigger('keyup');
442
+
443
+
444
  // update order numbers
445
  update_order_numbers();
446
 
457
 
458
  $('#acf_fields #add_field').live('click',function(){
459
 
460
+ var fields = $(this).closest('.table_footer').siblings('.fields');
 
461
 
462
 
463
  // clone last tr
464
+ var new_field = fields.children('.field_key-field_clone').clone();
465
 
466
 
467
  // update names
468
  new_field.update_names();
469
 
470
 
471
+ // show
472
  new_field.show();
473
 
474
 
475
  // append to table
476
+ fields.children('.field_key-field_clone').before(new_field);
477
 
478
 
479
  // remove no fields message
484
 
485
 
486
  // clear name
 
 
487
  new_field.find('tr.field_type select').trigger('change');
488
+ new_field.find('.field_form input[type="text"]').val('');
489
 
490
 
491
+ // focus after form has dropped down
492
+ // - this prevents a strange rendering bug in Firefox
493
+ setTimeout(function(){
494
+ new_field.find('.field_form input[type="text"]').first().focus();
495
+ }, 500);
496
+
497
+
498
  // open up form
499
  new_field.find('a.acf_edit_field').first().trigger('click');
500
 
553
  var val = $(this).val();
554
  var label = $(this).find('option[value="' + val + '"]').html();
555
 
556
+ $(this).closest('.field').find('td.field_type').first().html(label);
 
 
 
 
557
 
558
  });
559
 
613
  var tr = $(this).closest('tr'),
614
  i = tr.attr('data-i'),
615
  ajax_data = {
616
+ 'action' : "acf/field_group/render_location",
617
+ 'nonce' : acf.nonce,
618
  'key' : i,
619
  'value' : '',
620
  'param' : $(this).val()
736
  });
737
 
738
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
739
 
740
  /*
741
  * Screen Options
766
  * @created: 11/10/12
767
  */
768
 
769
+ acf.helpers.create_field = function( options ){
770
 
771
  // dafaults
772
  var defaults = {
812
  $(document).live('acf/field_form-open', function(e, field){
813
 
814
  // populate fields
815
+ acf.conditional_logic.setup();
816
 
817
 
818
  $(field).find('.conditional-logic-field').each(function(){
823
 
824
 
825
  // populate choices
826
+ if( acf.conditional_logic.fields )
827
  {
828
+ for( i = 0; i < acf.conditional_logic.fields.length; i++ )
829
  {
830
  choices.push({
831
+ value : acf.conditional_logic.fields[i].id,
832
+ label : acf.conditional_logic.fields[i].label
833
  });
834
  }
835
  }
846
 
847
 
848
  // create select
849
+ select = acf.helpers.create_field({
850
  'type' : 'select',
851
  'class' : 'conditional-logic-field',
852
  'name' : name,
899
 
900
  // vars
901
  var id = $(this).val(),
902
+ field = $('#acf_fields .field_key-' + id),
903
+ type = field.attr('data-type'),
904
  conditional_function = $(this).closest('tr').find('.conditional-logic-value');
905
 
906
 
943
 
944
 
945
  // create select
946
+ select = acf.helpers.create_field({
947
  'type' : 'select',
948
  'class' : 'conditional-logic-value',
949
  'name' : conditional_function.attr('name'),
966
  * @created: 15/10/12
967
  */
968
 
969
+ acf.conditional_logic.setup = function()
970
  {
971
+ // reset
972
+ acf.conditional_logic.fields = [];
973
+
974
 
975
+ // loop through fields
976
+ $('#acf_fields > .inside > .fields > .field:not(.field_key-field_clone)').each(function(){
977
 
978
  var field = $(this),
979
+ id = field.attr('data-id'),
980
+ key = field.children('.input-field_key').val(),
981
+ type = field.attr('data-type'),
982
  label = field.find('tr.field_label input').val();
983
 
984
+
985
  if( type == 'select' || type == 'checkbox' || type == 'true_false' || type == 'radio' )
986
  {
987
+ acf.conditional_logic.fields.push({
988
  id : id,
989
  type : type,
990
  label : label
js/input.php CHANGED
@@ -9,11 +9,8 @@ $files = array(
9
  'color-picker.js',
10
  'date-picker.js',
11
  'file.js',
12
- 'flexible-content.js',
13
- 'gallery.js',
14
  'image.js',
15
  'relationship.js',
16
- 'repeater.js',
17
  'tab.js',
18
  'validation.js',
19
  'wysiwyg.js'
9
  'color-picker.js',
10
  'date-picker.js',
11
  'file.js',
 
 
12
  'image.js',
13
  'relationship.js',
 
14
  'tab.js',
15
  'validation.js',
16
  'wysiwyg.js'
js/input/actions.js CHANGED
@@ -7,6 +7,7 @@
7
  */
8
 
9
  var acf = {
 
10
  admin_url : '',
11
  wp_version : '0',
12
  post_id : 0,
@@ -23,7 +24,8 @@ var acf = {
23
  uniqid : function(){},
24
  sortable : function(){},
25
  add_message : function(){},
26
- is_clone_field : function(){}
 
27
  },
28
  conditional_logic : {},
29
  media : {
@@ -75,24 +77,6 @@ var acf = {
75
  text : {
76
  max : "Maximum values reached ( {max} values )"
77
  }
78
- },
79
- repeater : {
80
- update_order : function(){},
81
- set_column_widths : function(){},
82
- add_sortable : function(){},
83
- update_classes : function(){},
84
- add_row : function(){},
85
- remove_row : function(){},
86
- text : {
87
- min : "Minimum rows reached ( {min} rows )",
88
- max : "Maximum rows reached ( {max} rows )"
89
- }
90
- },
91
- flexible_content : {
92
- add_sortable : function(){},
93
- update_order : function(){},
94
- add_layout : function(){},
95
- remove_layout : function(){}
96
  }
97
  }
98
  };
@@ -145,7 +129,7 @@ var acf = {
145
 
146
 
147
  /*
148
- * Helper uniqid
149
  *
150
  * @description:
151
  * @since: 3.5.8
@@ -156,7 +140,33 @@ var acf = {
156
  {
157
  var newDate = new Date;
158
  return newDate.getTime();
159
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
 
162
  /*
@@ -276,8 +286,8 @@ var acf = {
276
  * @created: 17/01/13
277
  */
278
 
279
- $('form#post').live("submit", function(){
280
-
281
  if( ! save_post )
282
  {
283
  // do validation
@@ -304,7 +314,7 @@ var acf = {
304
  // remove hidden postboxes
305
  $('.acf_postbox.acf-hidden').remove();
306
 
307
-
308
  // submit the form
309
  return true;
310
 
@@ -386,13 +396,13 @@ var acf = {
386
  acf.conditional_logic.calculate = function( options )
387
  {
388
  // vars
389
- var field = $('.field-' + options.field),
390
- toggle = $('.field-' + options.toggle),
391
  r = false;
392
 
393
 
394
  // compare values
395
- if( toggle.hasClass('field-true_false') || toggle.hasClass('field-checkbox') || toggle.hasClass('field-radio') )
396
  {
397
  if( options.operator == "==" )
398
  {
@@ -455,6 +465,7 @@ var acf = {
455
  // one of the objects was 'undefined'...
456
  }
457
 
 
458
 
459
  // setup fields
460
  $(document).trigger('acf/setup_fields', $('#poststuff'));
7
  */
8
 
9
  var acf = {
10
+ ajaxurl : '',
11
  admin_url : '',
12
  wp_version : '0',
13
  post_id : 0,
24
  uniqid : function(){},
25
  sortable : function(){},
26
  add_message : function(){},
27
+ is_clone_field : function(){},
28
+ url_to_object : function(){}
29
  },
30
  conditional_logic : {},
31
  media : {
77
  text : {
78
  max : "Maximum values reached ( {max} values )"
79
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  }
81
  }
82
  };
129
 
130
 
131
  /*
132
+ * Helper: uniqid
133
  *
134
  * @description:
135
  * @since: 3.5.8
140
  {
141
  var newDate = new Date;
142
  return newDate.getTime();
143
+ };
144
+
145
+
146
+ /*
147
+ * Helper: url_to_object
148
+ *
149
+ * @description:
150
+ * @since: 4.0.0
151
+ * @created: 17/01/13
152
+ */
153
+
154
+ acf.helpers.url_to_object = function( url ){
155
+
156
+ // vars
157
+ var obj = {},
158
+ pairs = url.split('&');
159
+
160
+
161
+ for( i in pairs )
162
+ {
163
+ var split = pairs[i].split('=');
164
+ obj[decodeURIComponent(split[0])] = decodeURIComponent(split[1]);
165
+ }
166
+
167
+ return obj;
168
+
169
+ };
170
 
171
 
172
  /*
286
  * @created: 17/01/13
287
  */
288
 
289
+ $('form#post').live('submit', function(){
290
+
291
  if( ! save_post )
292
  {
293
  // do validation
314
  // remove hidden postboxes
315
  $('.acf_postbox.acf-hidden').remove();
316
 
317
+
318
  // submit the form
319
  return true;
320
 
396
  acf.conditional_logic.calculate = function( options )
397
  {
398
  // vars
399
+ var field = $('.field_key-' + options.field),
400
+ toggle = $('.field_key-' + options.toggle),
401
  r = false;
402
 
403
 
404
  // compare values
405
+ if( toggle.hasClass('field_type-true_false') || toggle.hasClass('field_type-checkbox') || toggle.hasClass('field_type-radio') )
406
  {
407
  if( options.operator == "==" )
408
  {
465
  // one of the objects was 'undefined'...
466
  }
467
 
468
+
469
 
470
  // setup fields
471
  $(document).trigger('acf/setup_fields', $('#poststuff'));
js/input/ajax.js CHANGED
@@ -126,9 +126,10 @@
126
  $.ajax({
127
  url: ajaxurl,
128
  data: {
129
- action : 'acf_input',
130
  acf_id : v,
131
- post_id : acf.post_id
 
132
  },
133
  type: 'post',
134
  dataType: 'html',
@@ -148,8 +149,9 @@
148
  $.ajax({
149
  url: ajaxurl,
150
  data: {
151
- action : 'get_input_style',
152
- acf_id : result[0]
 
153
  },
154
  type: 'post',
155
  dataType: 'html',
126
  $.ajax({
127
  url: ajaxurl,
128
  data: {
129
+ action : 'acf/input/render_fields',
130
  acf_id : v,
131
+ post_id : acf.post_id,
132
+ nonce : acf.nonce
133
  },
134
  type: 'post',
135
  dataType: 'html',
149
  $.ajax({
150
  url: ajaxurl,
151
  data: {
152
+ action : 'acf/input/get_style',
153
+ acf_id : result[0],
154
+ nonce : acf.nonce
155
  },
156
  type: 'post',
157
  dataType: 'html',
js/input/flexible-content.js DELETED
@@ -1,261 +0,0 @@
1
- /*
2
- * Flexible Content
3
- *
4
- * @description:
5
- * @since: 3.5.8
6
- * @created: 17/01/13
7
- */
8
-
9
- (function($){
10
-
11
- var _flex = acf.fields.flexible_content;
12
-
13
-
14
- /*
15
- * Add Sortable
16
- *
17
- * @description:
18
- * @since: 3.5.8
19
- * @created: 17/01/13
20
- */
21
-
22
- _flex.add_sortable = function( div )
23
- {
24
-
25
- // remove (if clone) and add sortable
26
- div.children('.values').unbind('sortable').sortable({
27
- items : '> .layout',
28
- handle : '> .menu-item-handle',
29
- forceHelperSize : true,
30
- forcePlaceholderSize : true,
31
- scroll : true,
32
- start : function (event, ui) {
33
-
34
- $(document).trigger('acf/sortable_start', ui.item);
35
- $(document).trigger('acf/sortable_start_flex', ui.item);
36
-
37
- },
38
- stop : function (event, ui) {
39
-
40
- $(document).trigger('acf/sortable_stop', ui.item);
41
- $(document).trigger('acf/sortable_stop_flex', ui.item);
42
-
43
- // update order numbers
44
- _flex.update_order( div );
45
- }
46
- });
47
-
48
- };
49
-
50
-
51
- /*
52
- * Update Order
53
- *
54
- * @description:
55
- * @since: 3.5.8
56
- * @created: 17/01/13
57
- */
58
-
59
- _flex.update_order = function( div )
60
- {
61
- div.find('> .values .layout').each(function(i){
62
- $(this).find('> .menu-item-handle .fc-layout-order').html(i+1);
63
- });
64
-
65
- };
66
-
67
-
68
- /*
69
- * Add Layout
70
- *
71
- * @description:
72
- * @since: 3.5.8
73
- * @created: 17/01/13
74
- */
75
-
76
- _flex.add_layout = function( layout, div )
77
- {
78
- // vars
79
- var new_id = acf.helpers.uniqid(),
80
- new_field_html = div.find('> .clones > .layout[data-layout="' + layout + '"]').html().replace(/(=["]*[\w-\[\]]*?)(acfcloneindex)/g, '$1' + new_id),
81
- new_field = $('<div class="layout" data-layout="' + layout + '"></div>').append( new_field_html );
82
-
83
-
84
- // hide no values message
85
- div.children('.no_value_message').hide();
86
-
87
-
88
- // add row
89
- div.children('.values').append(new_field);
90
-
91
-
92
- // acf/setup_fields
93
- $(document).trigger('acf/setup_fields',new_field);
94
-
95
-
96
- // update order numbers
97
- _flex.update_order( div );
98
-
99
-
100
- // validation
101
- div.closest('.field').removeClass('error');
102
- }
103
-
104
-
105
- /*
106
- * Remove Layout
107
- *
108
- * @description:
109
- * @since: 3.5.8
110
- * @created: 17/01/13
111
- */
112
-
113
- _flex.remove_layout = function( layout )
114
- {
115
- // vars
116
- var div = layout.closest('.acf_flexible_content');
117
- var temp = $('<div style="height:' + layout.height() + 'px"></div>');
118
-
119
-
120
- // animate out tr
121
- layout.addClass('acf-remove-item');
122
- setTimeout(function(){
123
-
124
- layout.before(temp).remove();
125
-
126
- temp.animate({'height' : 0 }, 250, function(){
127
- temp.remove();
128
- });
129
-
130
- if( !div.children('.values').children('.layout').exists() )
131
- {
132
- div.children('.no_value_message').show();
133
- }
134
-
135
- }, 400);
136
-
137
- }
138
-
139
-
140
- /*
141
- * acf/setup_fields
142
- *
143
- * @description:
144
- * @since: 3.5.8
145
- * @created: 17/01/13
146
- */
147
-
148
- $(document).live('acf/setup_fields', function(e, postbox){
149
-
150
- $(postbox).find('.acf_flexible_content').each(function(){
151
-
152
- var div = $(this);
153
-
154
- // sortable
155
- _flex.add_sortable( div );
156
-
157
-
158
- // set column widths
159
- $(div).find('.layout').each(function(){
160
- acf.fields.repeater.set_column_widths( $(this) );
161
- });
162
-
163
-
164
- });
165
-
166
- });
167
-
168
-
169
- /*
170
- * Show / Hide popup
171
- *
172
- * @description:
173
- * @since: 3.5.8
174
- * @created: 17/01/13
175
- */
176
-
177
- $('.acf_flexible_content .flexible-footer .add-row-end').live('click', function()
178
- {
179
- $(this).trigger('focus');
180
-
181
- }).live('focus', function()
182
- {
183
- $(this).siblings('.acf-popup').addClass('active');
184
-
185
- }).live('blur', function()
186
- {
187
- var button = $(this);
188
- setTimeout(function(){
189
- button.siblings('.acf-popup').removeClass('active');
190
- }, 250);
191
-
192
- });
193
-
194
-
195
- /*
196
- * Delete Layout Button
197
- *
198
- * @description:
199
- * @since: 3.5.8
200
- * @created: 17/01/13
201
- */
202
-
203
- $('.acf_flexible_content .fc-delete-layout').live('click', function(){
204
-
205
- var layout = $(this).closest('.layout');
206
-
207
- _flex.remove_layout( layout );
208
-
209
- return false;
210
- });
211
-
212
-
213
- /*
214
- * Add Layout Button
215
- *
216
- * @description:
217
- * @since: 3.5.8
218
- * @created: 17/01/13
219
- */
220
-
221
- $('.acf_flexible_content .acf-popup ul li a').live('click', function(){
222
-
223
- var layout = $(this).attr('data-layout'),
224
- div = $(this).closest('.acf_flexible_content');
225
-
226
- _flex.add_layout( layout, div );
227
-
228
- return false;
229
-
230
- });
231
-
232
-
233
- /*
234
- * Hide Show Flexible Content
235
- *
236
- * @description:
237
- * @since 3.5.2
238
- * @created: 11/11/12
239
- */
240
-
241
- $('.acf_flexible_content .layout .menu-item-handle').live('click', function(){
242
-
243
- // vars
244
- var layout = $(this).closest('.layout');
245
-
246
-
247
- if( layout.attr('data-toggle') == 'closed' )
248
- {
249
- layout.attr('data-toggle', 'open');
250
- layout.children('.acf-input-table').show();
251
- }
252
- else
253
- {
254
- layout.attr('data-toggle', 'closed');
255
- layout.children('.acf-input-table').hide();
256
- }
257
-
258
- });
259
-
260
-
261
- })(jQuery);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/input/gallery.js DELETED
@@ -1,530 +0,0 @@
1
- /*
2
- * Gallery
3
- *
4
- * @description:
5
- * @since: 3.5.8
6
- * @created: 17/01/13
7
- */
8
-
9
- (function($){
10
-
11
- var _gallery = acf.fields.gallery,
12
- _media = acf.media;
13
-
14
-
15
- /*
16
- * Add
17
- *
18
- * @description:
19
- * @since: 3.5.8
20
- * @created: 17/01/13
21
- */
22
-
23
- _gallery.add = function( image ){
24
-
25
-
26
- // vars
27
- var gallery = _media.div,
28
- tpml = gallery.find('.tmpl-thumbnail').html();
29
-
30
-
31
-
32
- // update vars on tmpl
33
- $.each(image, function( k, v ){
34
- var regex = new RegExp('{' + k + '}', 'g');
35
- tpml = tpml.replace(regex, v);
36
- });
37
-
38
-
39
- // add div
40
- gallery.find('.thumbnails > .inner').append( tpml );
41
-
42
-
43
- // update gallery count
44
- _gallery.update_count( gallery );
45
-
46
-
47
- // validation
48
- gallery.closest('.field').removeClass('error');
49
-
50
- };
51
-
52
-
53
- /*
54
- * Edit
55
- *
56
- * @description:
57
- * @since: 3.5.8
58
- * @created: 17/01/13
59
- */
60
-
61
- _gallery.edit_image = function(){
62
-
63
-
64
- // vars
65
- var div = _media.div,
66
- id = div.attr('data-id');
67
-
68
-
69
- // show edit attachment
70
- tb_show( acf.fields.image.text.title_edit , acf.admin_url + 'media.php?attachment_id=' + id + '&action=edit&acf_action=edit_attachment&acf_field=gallery&TB_iframe=1');
71
-
72
-
73
- };
74
-
75
-
76
- /*
77
- * Update Image
78
- *
79
- * @description:
80
- * @since: 3.5.8
81
- * @created: 17/01/13
82
- */
83
-
84
- _gallery.update_image = function(){
85
-
86
-
87
- // vars
88
- var div = acf.media.div,
89
- id = div.attr('data-id'),
90
- ajax_data = {
91
- action : 'acf/fields/gallery/get_metadata',
92
- id : id,
93
- nonce : acf.nonce
94
- };
95
-
96
-
97
- // ajax find new list data
98
- $.ajax({
99
- url: ajaxurl,
100
- type: 'post',
101
- data : ajax_data,
102
- cache: false,
103
- dataType: "json",
104
- success: function( json ) {
105
-
106
-
107
- // validate
108
- if( !json )
109
- {
110
- return false;
111
- }
112
-
113
-
114
- // update list-item html
115
- $.each(json, function( k, v ){
116
- if( div.find('.td-' + k).exists() )
117
- {
118
- div.find('.td-' + k).text( v );
119
- }
120
- });
121
-
122
- }
123
- });
124
-
125
-
126
- };
127
-
128
-
129
- /*
130
- * Update Count
131
- *
132
- * @description:
133
- * @since: 3.5.8
134
- * @created: 17/01/13
135
- */
136
-
137
- _gallery.update_count = function( div )
138
- {
139
- // vars
140
- var count = div.find('.thumbnails .thumbnail').length,
141
- max_count = ( count > 2 ) ? 2 : count,
142
- span = div.find('.toolbar .count');
143
-
144
-
145
- span.html( span.attr('data-' + max_count).replace('{count}', count) );
146
-
147
- }
148
-
149
-
150
- /*
151
- * View: Grid
152
- *
153
- * @description:
154
- * @since: 3.5.8
155
- * @created: 17/01/13
156
- */
157
-
158
- $('.acf-gallery .toolbar .view-grid').live('click', function(){
159
-
160
- // vars
161
- var gallery = $(this).closest('.acf-gallery');
162
-
163
-
164
- // active class
165
- $(this).parent().addClass('active').siblings('.view-list-li').removeClass('active');
166
-
167
-
168
- // gallery class
169
- gallery.removeClass('view-list');
170
-
171
-
172
- return false;
173
-
174
- });
175
-
176
-
177
- /*
178
- * View: List
179
- *
180
- * @description:
181
- * @since: 3.5.8
182
- * @created: 17/01/13
183
- */
184
-
185
- $('.acf-gallery .toolbar .view-list').live('click', function(){
186
-
187
- // vars
188
- var gallery = $(this).closest('.acf-gallery');
189
-
190
-
191
- // active class
192
- $(this).parent().addClass('active').siblings('.view-grid-li').removeClass('active');
193
-
194
-
195
- // gallery class
196
- gallery.addClass('view-list');
197
-
198
-
199
- return false;
200
-
201
- });
202
-
203
-
204
- /*
205
- * Add Button
206
- *
207
- * @description:
208
- * @since: 3.5.8
209
- * @created: 17/01/13
210
- */
211
-
212
- // add image
213
- $('.acf-gallery .toolbar .add-image').live('click', function(){
214
-
215
- // vars
216
- var div = _media.div = $(this).closest('.acf-gallery'),
217
- preview_size = div.attr('data-preview_size');
218
-
219
-
220
- // show the thickbox
221
- // show the thickbox
222
- if( _media.type() == 'backbone' )
223
- {
224
- // clear the frame
225
- _media.clear_frame();
226
-
227
-
228
- // acf.media.frame.content.get().options.filters=true;
229
-
230
- // Create the media frame. Leave options blank for defaults
231
- _media.frame = wp.media({
232
- title : _gallery.text.title_add,
233
- multiple : true,
234
- library : {
235
- //type : 'image'
236
- }
237
- });
238
-
239
-
240
- // add filter by overriding the option when the title is being created. This is an evet fired before the rendering / creating of the library content so it works but is a bit of a hack. In the future, this should be changed to an init / options event
241
- _media.frame.on('title:create', function(){
242
- var state = _media.frame.state();
243
- state.set('filterable', 'uploaded');
244
- });
245
-
246
-
247
- // When an image is selected, run a callback.
248
- _media.frame.on( 'select', function() {
249
-
250
- // get selected images
251
- selection = _media.frame.state().get('selection');
252
-
253
- if( selection )
254
- {
255
- selection.each(function(attachment){
256
-
257
- // is image already in gallery?
258
- if( div.find('.thumbnails .thumbnail[data-id="' + attachment.id + '"]').exists() )
259
- {
260
- return;
261
- }
262
-
263
-
264
- var image = {
265
- id : attachment.id,
266
- src : attachment.attributes.url,
267
- title : attachment.attributes.title,
268
- caption : attachment.attributes.caption,
269
- alt : attachment.attributes.alt,
270
- description : attachment.attributes.description
271
- };
272
-
273
-
274
- // file?
275
- if( attachment.attributes.type != 'image' )
276
- {
277
- image.src = attachment.attributes.icon;
278
- }
279
-
280
-
281
- // is preview size available?
282
- if( attachment.attributes.sizes && attachment.attributes.sizes[ preview_size ] )
283
- {
284
- image.src = attachment.attributes.sizes[ preview_size ].url;
285
- }
286
-
287
-
288
- // add image to field
289
- _gallery.add( image );
290
-
291
- });
292
- // selection.each(function(attachment){
293
- }
294
- // if( selection )
295
- });
296
- // _media.frame.on( 'select', function() {
297
-
298
- _media.frame.on('content:create:browse', function( e ){
299
-
300
- /*
301
- acf.media.frame.content.get().collection.on( 'all', function( e ){
302
- console.log( 'collection: ' + e );
303
- });
304
- */
305
-
306
- });
307
-
308
- // log all events
309
- _media.frame.on('all', function( e ){
310
-
311
- //console.log( 'frame: ' + e );
312
- });
313
-
314
- _media.frame.on('content:activate:browse', function(){
315
-
316
- _gallery.hide_selected_items();
317
-
318
- acf.media.frame.content.get().collection.on( 'reset add', function(){
319
-
320
- _gallery.hide_selected_items();
321
-
322
- });
323
-
324
- // event fired after a search
325
-
326
- /*
327
- acf.media.frame.content.get().collection.on( 'all', function( e ){
328
- console.log( 'collection: ' + e );
329
- });
330
- */
331
-
332
-
333
-
334
- });
335
-
336
- // Finally, open the modal
337
- _media.frame.open();
338
-
339
-
340
- /* // event fired when viewing "Media Library"
341
-
342
-
343
-
344
-
345
-
346
- // event fired when viewing "Upload Files"
347
- acf.media.frame.on('content:activate:upload', function(){
348
- $(document).trigger('acf/media/upload');
349
- });
350
-
351
- // event fired when opening the media popup
352
- acf.media.frame.on('open', function( e ){
353
-
354
- acf.media.frame.content.get().attachments.render();
355
- acf.media.frame.reset();
356
- $(document).trigger('acf/media/open');
357
-
358
-
359
- });
360
-
361
- acf.media.frame.on('reset', function( e ){
362
- $(document).trigger('acf/media/reset');
363
-
364
- console.log('main reset');
365
- });
366
-
367
-
368
- // event fired when closing the media popup
369
- acf.media.frame.on('close', function( e ){
370
-
371
- // clear the div
372
- $(document).trigger('acf/media/close');
373
- });
374
-
375
-
376
- // When an image is selected, run a callback.
377
- acf.media.frame.on('select', function()
378
- {
379
- $(document).trigger('acf/media/select', [acf.media.frame.state().get('selection')]);
380
- }); */
381
- }
382
- else
383
- {
384
- tb_show( _gallery.text.title_add , acf.admin_url + 'media-upload.php?post_id=' + acf.post_id + '&post_ID=' + acf.post_id + '&type=image&acf_type=gallery&acf_preview_size=' + preview_size + 'TB_iframe=1');
385
- }
386
-
387
-
388
- return false;
389
-
390
- });
391
-
392
-
393
- /*
394
- * Edit Button
395
- *
396
- * @description:
397
- * @since: 3.5.8
398
- * @created: 17/01/13
399
- */
400
-
401
- $('.acf-gallery .thumbnail .acf-button-edit').live('click', function(){
402
-
403
- // vars
404
- _media.div = $(this).closest('.thumbnail');
405
-
406
- _gallery.edit_image();
407
-
408
- return false;
409
-
410
- });
411
-
412
-
413
- /*
414
- * Remove Button
415
- *
416
- * @description:
417
- * @since: 3.5.8
418
- * @created: 17/01/13
419
- */
420
-
421
- $('.acf-gallery .thumbnail .acf-button-delete').live('click', function(){
422
-
423
- // vars
424
- var thumbnail = $(this).closest('.thumbnail'),
425
- gallery = thumbnail.closest('.acf-gallery');
426
-
427
-
428
- thumbnail.animate({
429
- opacity : 0
430
- }, 250, function(){
431
-
432
- thumbnail.remove();
433
-
434
- _gallery.update_count( gallery );
435
-
436
- });
437
-
438
- return false;
439
-
440
- });
441
-
442
-
443
-
444
- _gallery.hide_selected_items = function(){
445
-
446
- // set timeout for 0, then it will always run last after the add event
447
- setTimeout(function(){
448
-
449
-
450
- // vars
451
- var gallery = _media.div,
452
- div = _media.frame.content.get().$el;
453
- collection = _media.frame.content.get().collection || null,
454
- i = -1;
455
-
456
-
457
- if( collection )
458
- {
459
- collection.each(function( item ){
460
-
461
- i++;
462
-
463
- var attachment = div.find('.attachments > .attachment:eq(' + i + ')');
464
-
465
-
466
- // if image is already inside the gallery, disable it!
467
- if( gallery.find('.thumbnails .thumbnail[data-id="' + item.id + '"]').exists() )
468
- {
469
- item.off('selection:single');
470
- attachment.addClass('acf-selected');
471
- }
472
-
473
- });
474
- }
475
-
476
-
477
- }, 0);
478
-
479
- }
480
-
481
-
482
- /*
483
- * acf/setup_fields
484
- *
485
- * @description:
486
- * @since: 3.5.8
487
- * @created: 17/01/13
488
- */
489
-
490
- $(document).live('acf/setup_fields', function(e, postbox){
491
-
492
- $(postbox).find('.acf-gallery').each(function(i){
493
-
494
- // is clone field?
495
- if( acf.helpers.is_clone_field($(this).children('input[type="hidden"]')) )
496
- {
497
- return;
498
- }
499
-
500
-
501
- // vars
502
- var div = $(this),
503
- thumbnails = div.find('.thumbnails');
504
-
505
-
506
- // update count
507
- _gallery.update_count( div );
508
-
509
-
510
- // sortable
511
- thumbnails.find('> .inner').sortable({
512
- items : '> .thumbnail',
513
- /* handle: '> td.order', */
514
- forceHelperSize: true,
515
- forcePlaceholderSize: true,
516
- scroll: true,
517
- start: function (event, ui) {
518
-
519
- // alter width / height to allow for 2px border
520
- ui.placeholder.width( ui.placeholder.width() - 4 );
521
- ui.placeholder.height( ui.placeholder.height() - 4 );
522
- }
523
- });
524
-
525
-
526
- });
527
-
528
- });
529
-
530
- })(jQuery);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/input/image.js CHANGED
@@ -115,9 +115,9 @@
115
  multiple : multiple,
116
  library : {
117
  type : 'image'
118
- }
119
  });
120
-
121
 
122
  // add filter by overriding the option when the title is being created. This is an evet fired before the rendering / creating of the library content so it works but is a bit of a hack. In the future, this should be changed to an init / options event
123
  _media.frame.on('title:create', function(){
@@ -244,4 +244,4 @@
244
  });
245
 
246
 
247
- })(jQuery);
115
  multiple : multiple,
116
  library : {
117
  type : 'image'
118
+ },
119
  });
120
+
121
 
122
  // add filter by overriding the option when the title is being created. This is an evet fired before the rendering / creating of the library content so it works but is a bit of a hack. In the future, this should be changed to an init / options event
123
  _media.frame.on('title:create', function(){
244
  });
245
 
246
 
247
+ })(jQuery);
js/input/relationship.js CHANGED
@@ -234,36 +234,50 @@
234
 
235
 
236
  // vars
237
- var s = div.attr('data-s'),
238
- paged = parseInt( div.attr('data-paged') ),
239
- taxonomy = div.attr('data-taxonomy'),
240
- post_type = div.attr('data-post_type'),
241
- lang = div.attr('data-lang'),
242
  left = div.find('.relationship_left .relationship_list'),
243
- right = div.find('.relationship_right .relationship_list');
244
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
 
246
  // get results
247
  $.ajax({
248
  url: ajaxurl,
249
  type: 'post',
250
  dataType: 'html',
251
- data: {
252
- 'action' : 'acf_get_relationship_results',
253
- 's' : s,
254
- 'paged' : paged,
255
- 'taxonomy' : taxonomy,
256
- 'post_type' : post_type,
257
- 'lang' : lang,
258
- 'field_name' : div.parent().attr('data-field_name'),
259
- 'field_key' : div.parent().attr('data-field_key')
260
- },
261
  success: function( html ){
262
 
263
  div.removeClass('no-results').removeClass('loading');
264
 
265
  // new search?
266
- if( paged == 1 )
267
  {
268
  left.find('li:not(.load-more)').remove();
269
  }
@@ -294,6 +308,7 @@
294
 
295
  }
296
  });
297
- };
 
298
 
299
  })(jQuery);
234
 
235
 
236
  // vars
237
+ var attributes = {},
 
 
 
 
238
  left = div.find('.relationship_left .relationship_list'),
239
+ right = div.find('.relationship_right .relationship_list');
240
+
241
+
242
+ // find attributes
243
+ $.each( div[0].attributes, function( index, attr ) {
244
+
245
+ // must have 'data-'
246
+ if( attr.name.substr(0, 5) != 'data-' )
247
+ {
248
+ return;
249
+ }
250
+
251
+
252
+ // ignore
253
+ if( attr.name == 'data-max' )
254
+ {
255
+ return;
256
+ }
257
+
258
+
259
+ // add to attributes
260
+ attributes[ attr.name.replace('data-', '') ] = attr.value;
261
+ });
262
+
263
 
264
  // get results
265
  $.ajax({
266
  url: ajaxurl,
267
  type: 'post',
268
  dataType: 'html',
269
+ data: $.extend( attributes, {
270
+ action : 'acf/fields/relationship/query_posts',
271
+ field_name : div.parent().attr('data-field_name'),
272
+ field_key : div.parent().attr('data-field_key'),
273
+ nonce : acf.nonce
274
+ }),
 
 
 
 
275
  success: function( html ){
276
 
277
  div.removeClass('no-results').removeClass('loading');
278
 
279
  // new search?
280
+ if( attributes.paged == 1 )
281
  {
282
  left.find('li:not(.load-more)').remove();
283
  }
308
 
309
  }
310
  });
311
+ };
312
+
313
 
314
  })(jQuery);
js/input/repeater.js DELETED
@@ -1,388 +0,0 @@
1
- /*
2
- * Repeater
3
- *
4
- * @description:
5
- * @since: 3.5.8
6
- * @created: 17/01/13
7
- */
8
-
9
- (function($){
10
-
11
- var _repeater = acf.fields.repeater;
12
-
13
-
14
- /*
15
- * update_order
16
- *
17
- * @description:
18
- * @since: 3.5.8
19
- * @created: 17/01/13
20
- */
21
-
22
- _repeater.update_order = function( repeater )
23
- {
24
- repeater.find('> table > tbody > tr.row').each(function(i){
25
- $(this).children('td.order').html( i+1 );
26
- });
27
-
28
- };
29
-
30
-
31
- /*
32
- * set_column_widths
33
- *
34
- * @description:
35
- * @since: 3.5.8
36
- * @created: 17/01/13
37
- */
38
-
39
- _repeater.set_column_widths = function( repeater )
40
- {
41
- // validate
42
- if( repeater.children('.acf-input-table').hasClass('row_layout') )
43
- {
44
- return;
45
- }
46
-
47
-
48
- // accomodate for order / remove
49
- var column_width = 100;
50
- if( repeater.find('> .acf-input-table > thead > tr > th.order').exists() )
51
- {
52
- column_width = 93;
53
- }
54
-
55
-
56
- // find columns that already have a width and remove these amounts from the column_width var
57
- repeater.find('> .acf-input-table > thead > tr > th[width]').each(function( i ){
58
-
59
- column_width -= parseInt( $(this).attr('width') );
60
- });
61
-
62
-
63
- var ths = repeater.find('> .acf-input-table > thead > tr > th').not('[width]').has('span');
64
- if( ths.length > 1 )
65
- {
66
- column_width = column_width / ths.length;
67
-
68
- ths.each(function( i ){
69
-
70
- // dont add width to last th
71
- if( (i+1) == ths.length )
72
- {
73
- return;
74
- }
75
-
76
- $(this).attr('width', column_width + '%');
77
-
78
- });
79
- }
80
-
81
- }
82
-
83
-
84
- /*
85
- * add_sortable
86
- *
87
- * @description:
88
- * @since 3.5.2
89
- * @created: 11/11/12
90
- */
91
-
92
- _repeater.add_sortable = function( repeater ){
93
-
94
- // vars
95
- var max_rows = parseFloat( repeater.attr('data-max_rows') );
96
-
97
-
98
- // validate
99
- if( max_rows <= 1 )
100
- {
101
- return;
102
- }
103
-
104
- repeater.find('> table > tbody').unbind('sortable').sortable({
105
- items : '> tr.row',
106
- handle : '> td.order',
107
- helper : acf.helpers.sortable,
108
- forceHelperSize : true,
109
- forcePlaceholderSize : true,
110
- scroll : true,
111
- start : function (event, ui) {
112
-
113
- $(document).trigger('acf/sortable_start', ui.item);
114
- $(document).trigger('acf/sortable_start_repeater', ui.item);
115
-
116
- // add markup to the placeholder
117
- var td_count = ui.item.children('td').length;
118
- ui.placeholder.html('<td colspan="' + td_count + '"></td>');
119
-
120
- },
121
- stop : function (event, ui) {
122
-
123
- $(document).trigger('acf/sortable_stop', ui.item);
124
- $(document).trigger('acf/sortable_stop_repeater', ui.item);
125
-
126
- // update order numbers
127
- _repeater.update_order( repeater );
128
-
129
- }
130
- });
131
- };
132
-
133
-
134
- /*
135
- * update_classes
136
- *
137
- * @description:
138
- * @since 3.5.2
139
- * @created: 11/11/12
140
- */
141
-
142
- _repeater.update_classes = function( repeater )
143
- {
144
- // vars
145
- var max_rows = parseFloat( repeater.attr('data-max_rows') ),
146
- row_count = repeater.find('> table > tbody > tr.row').length;
147
-
148
-
149
- // empty?
150
- if( row_count == 0 )
151
- {
152
- repeater.addClass('empty');
153
- }
154
- else
155
- {
156
- repeater.removeClass('empty');
157
- }
158
-
159
-
160
- // row limit reached
161
- if( row_count >= max_rows )
162
- {
163
- repeater.addClass('disabled');
164
- repeater.find('> .repeater-footer .acf-button').addClass('disabled');
165
- }
166
- else
167
- {
168
- repeater.removeClass('disabled');
169
- repeater.find('> .repeater-footer .acf-button').removeClass('disabled');
170
- }
171
-
172
- }
173
-
174
-
175
- /*
176
- * acf/setup_fields
177
- *
178
- * @description:
179
- * @since 3.5.2
180
- * @created: 11/11/12
181
- */
182
-
183
- $(document).live('acf/setup_fields', function(e, postbox){
184
-
185
- $(postbox).find('.repeater').each(function(){
186
-
187
- var repeater = $(this)
188
-
189
-
190
- // set column widths
191
- _repeater.set_column_widths( repeater );
192
-
193
-
194
- // update classes based on row count
195
- _repeater.update_classes( repeater );
196
-
197
-
198
- // add sortable
199
- _repeater.add_sortable( repeater );
200
-
201
- });
202
-
203
- });
204
-
205
-
206
-
207
- /*
208
- * Add Row
209
- *
210
- * @description:
211
- * @since: 3.5.8
212
- * @created: 17/01/13
213
- */
214
-
215
- _repeater.add_row = function( repeater, before )
216
- {
217
- // vars
218
- var max_rows = parseInt( repeater.attr('data-max_rows') ),
219
- row_count = repeater.find('> table > tbody > tr.row').length;
220
-
221
-
222
- // validate
223
- if( row_count >= max_rows )
224
- {
225
- alert( _repeater.text.max.replace('{max}', max_rows) );
226
- return false;
227
- }
228
-
229
-
230
- // create and add the new field
231
- var new_id = acf.helpers.uniqid(),
232
- new_field_html = repeater.find('> table > tbody > tr.row-clone').html().replace(/(=["]*[\w-\[\]]*?)(acfcloneindex)/g, '$1' + new_id),
233
- new_field = $('<tr class="row"></tr>').append( new_field_html );
234
-
235
-
236
- // add row
237
- if( !before )
238
- {
239
- before = repeater.find('> table > tbody > .row-clone');
240
- }
241
-
242
- before.before( new_field );
243
-
244
-
245
- // trigger mouseenter on parent repeater to work out css margin on add-row button
246
- repeater.closest('tr').trigger('mouseenter');
247
-
248
-
249
- // update order
250
- _repeater.update_order( repeater );
251
-
252
-
253
- // update classes based on row count
254
- _repeater.update_classes( repeater );
255
-
256
-
257
- // setup fields
258
- $(document).trigger('acf/setup_fields', new_field);
259
-
260
-
261
- // validation
262
- repeater.closest('.field').removeClass('error');
263
- }
264
-
265
-
266
- /*
267
- * Add Button
268
- *
269
- * @description:
270
- * @since: 3.5.8
271
- * @created: 17/01/13
272
- */
273
-
274
- $('.repeater .repeater-footer .add-row-end').live('click', function(){
275
-
276
- var repeater = $(this).closest('.repeater');
277
-
278
- _repeater.add_row( repeater, false );
279
-
280
- return false;
281
- });
282
-
283
-
284
- /*
285
- * Add Before Button
286
- *
287
- * @description:
288
- * @since: 3.5.8
289
- * @created: 17/01/13
290
- */
291
-
292
- $('.repeater td.remove .add-row-before').live('click', function(){
293
-
294
- var repeater = $(this).closest('.repeater'),
295
- before = $(this).closest('tr');
296
-
297
- _repeater.add_row( repeater, before );
298
-
299
- return false;
300
- });
301
-
302
-
303
- /*
304
- * Remove Row
305
- *
306
- * @description:
307
- * @since: 3.5.8
308
- * @created: 17/01/13
309
- */
310
-
311
- _repeater.remove_row = function( tr )
312
- {
313
- // vars
314
- var repeater = tr.closest('.repeater'),
315
- min_rows = parseInt( repeater.attr('data-min_rows') ),
316
- row_count = repeater.find('> table > tbody > tr.row').length,
317
- column_count = tr.children('tr.row').length,
318
- row_height = tr.height();
319
-
320
-
321
- // validate
322
- if( row_count <= min_rows )
323
- {
324
- alert( _repeater.text.min.replace('{min}', row_count) );
325
- return false;
326
- }
327
-
328
-
329
- // animate out tr
330
- tr.addClass('acf-remove-item');
331
- setTimeout(function(){
332
-
333
- tr.remove();
334
-
335
-
336
- // trigger mouseenter on parent repeater to work out css margin on add-row button
337
- repeater.closest('tr').trigger('mouseenter');
338
-
339
-
340
- // update order
341
- _repeater.update_order( repeater );
342
-
343
-
344
- // update classes based on row count
345
- _repeater.update_classes( repeater );
346
-
347
- }, 400);
348
-
349
- }
350
-
351
-
352
- /*
353
- * Remove Row
354
- *
355
- * @description:
356
- * @since: 3.5.8
357
- * @created: 17/01/13
358
- */
359
-
360
- $('.repeater td.remove .acf-button-remove').live('click', function(){
361
-
362
- var tr = $(this).closest('tr');
363
-
364
- _repeater.remove_row( tr );
365
-
366
- return false;
367
- });
368
-
369
-
370
- /*
371
- * hover over tr, align add-row button to top
372
- *
373
- * @description:
374
- * @since: 3.5.8
375
- * @created: 17/01/13
376
- */
377
-
378
- $('.repeater tr').live('mouseenter', function(){
379
-
380
- var button = $(this).find('> td.remove > a.acf-button-add');
381
- var margin = ( button.parent().height() / 2 ) + 9; // 9 = padding + border
382
-
383
- button.css('margin-top', '-' + margin + 'px' );
384
-
385
- });
386
-
387
-
388
- })(jQuery);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/input/tab.js CHANGED
@@ -18,13 +18,14 @@
18
 
19
  $(document).live('acf/setup_fields', function(e, postbox){
20
 
21
- $(postbox).find('.acf-tab').each(function(){
22
 
23
  // vars
24
- var tab = $(this),
 
25
  id = tab.attr('data-id'),
26
  label = tab.html(),
27
- postbox = tab.closest('.acf_postbox'),
28
  inside = postbox.children('.inside');
29
 
30
 
@@ -40,12 +41,12 @@
40
  // create tab group if it doesnt exist
41
  if( ! inside.children('.acf-tab-group').exists() )
42
  {
43
- inside.children('.field-tab:first').before('<ul class="hl clearfix acf-tab-group"></ul>');
44
  }
45
 
46
 
47
  // add tab
48
- inside.children('.acf-tab-group').append('<li><a class="acf-tab-button" href="#" data-id="' + id + '">' + label + '</a></li>');
49
 
50
 
51
  });
@@ -85,17 +86,17 @@
85
 
86
 
87
  // hide / show
88
- inside.children('.field-tab').each(function(){
89
 
90
  var tab = $(this);
91
 
92
- if( tab.hasClass('field-' + id) )
93
  {
94
- tab.nextUntil('.field-tab').removeClass('acf-tab_group-hide').addClass('acf-tab_group-show');
95
  }
96
  else
97
  {
98
- tab.nextUntil('.field-tab').removeClass('acf-tab_group-show').addClass('acf-tab_group-hide');
99
  }
100
 
101
  });
18
 
19
  $(document).live('acf/setup_fields', function(e, postbox){
20
 
21
+ $(postbox).find('.field_type-tab').each(function(){
22
 
23
  // vars
24
+ var field = $(this),
25
+ tab = field.find('.acf-tab'),
26
  id = tab.attr('data-id'),
27
  label = tab.html(),
28
+ postbox = field.closest('.acf_postbox'),
29
  inside = postbox.children('.inside');
30
 
31
 
41
  // create tab group if it doesnt exist
42
  if( ! inside.children('.acf-tab-group').exists() )
43
  {
44
+ inside.children('.field_type-tab:first').before('<ul class="hl clearfix acf-tab-group"></ul>');
45
  }
46
 
47
 
48
  // add tab
49
+ inside.children('.acf-tab-group').append('<li data-field_key="' + id + '"><a class="acf-tab-button" href="#" data-id="' + id + '">' + label + '</a></li>');
50
 
51
 
52
  });
86
 
87
 
88
  // hide / show
89
+ inside.children('.field_type-tab').each(function(){
90
 
91
  var tab = $(this);
92
 
93
+ if( tab.hasClass('field_key-' + id) )
94
  {
95
+ tab.nextUntil('.field_type-tab').removeClass('acf-tab_group-hide').addClass('acf-tab_group-show');
96
  }
97
  else
98
  {
99
+ tab.nextUntil('.field_type-tab').removeClass('acf-tab_group-show').addClass('acf-tab_group-hide');
100
  }
101
 
102
  });
js/input/validation.js CHANGED
@@ -55,6 +55,7 @@
55
  var id = div.find('.wp-editor-area').attr('id'),
56
  editor = tinyMCE.get( id );
57
 
 
58
  if( editor && !editor.getContent() )
59
  {
60
  div.data('validation', false);
@@ -139,7 +140,7 @@
139
  div.closest('.field').addClass('error');
140
  }
141
 
142
-
143
  });
144
 
145
 
55
  var id = div.find('.wp-editor-area').attr('id'),
56
  editor = tinyMCE.get( id );
57
 
58
+
59
  if( editor && !editor.getContent() )
60
  {
61
  div.data('validation', false);
140
  div.closest('.field').addClass('error');
141
  }
142
 
143
+
144
  });
145
 
146
 
js/input/wysiwyg.js CHANGED
@@ -42,6 +42,7 @@
42
 
43
  $(document).live('acf/wysiwyg_activate', function(e, div){
44
 
 
45
  // validate tinymce
46
  if( ! _wysiwyg.has_tinymce() )
47
  {
@@ -137,6 +138,7 @@
137
  $(document).trigger('acf/wysiwyg/blur', id);
138
  });
139
 
 
140
  };
141
 
142
 
@@ -162,17 +164,14 @@
162
  // vars
163
  var textarea = $(this),
164
  id = textarea.attr('id'),
165
- wysiwyg = tinyMCE.get( id );
166
 
167
 
168
  // if wysiwyg was found (should be always...), remove its functionality and set the value (to keep line breaks)
169
- if( wysiwyg )
170
  {
171
- var val = wysiwyg.getContent();
172
-
173
  tinyMCE.execCommand("mceRemoveControl", false, id);
174
-
175
- textarea.val( val );
176
  }
177
 
178
  });
42
 
43
  $(document).live('acf/wysiwyg_activate', function(e, div){
44
 
45
+
46
  // validate tinymce
47
  if( ! _wysiwyg.has_tinymce() )
48
  {
138
  $(document).trigger('acf/wysiwyg/blur', id);
139
  });
140
 
141
+
142
  };
143
 
144
 
164
  // vars
165
  var textarea = $(this),
166
  id = textarea.attr('id'),
167
+ editor = tinyMCE.get( id );
168
 
169
 
170
  // if wysiwyg was found (should be always...), remove its functionality and set the value (to keep line breaks)
171
+ if( editor )
172
  {
173
+ editor.save();
 
174
  tinyMCE.execCommand("mceRemoveControl", false, id);
 
 
175
  }
176
 
177
  });
readme.txt CHANGED
@@ -1,42 +1,42 @@
1
  === Advanced Custom Fields ===
2
  Contributors: Elliot Condon
3
  Tags: custom, field, custom field, advanced, simple fields, magic fields, more fields, repeater, matrix, post, type, text, textarea, file, image, edit, admin
4
- Requires at least: 3.3.0
5
  Tested up to: 3.5.1
6
  License: GPLv2 or later
7
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
 
9
- Fully customise WordPress edit screens with powerful fields. Boasting a professional interface and a powerful 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, and more!
10
 
11
  == Description ==
12
 
13
- Advanced Custom Fields is the perfect solution for any WordPress website that needs more flexible data types, 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, date picker, true / false, repeater, flexible content, gallery, and more to come!)
17
  * Assign your fields to multiple edit pages (via custom location rules)
18
- * Easily load data through a simple, friendly API
19
  * Uses the native WordPress custom post type for ease of use and fast processing
20
- * Uses native WordPress metadata for ease of use and fast processing
21
 
22
  = Field Types =
23
- * Tab (group fields into tabs)
24
- * Text (enter text, API returns the text)
25
- * Text Area (enter text, API returns the text with `<br />` tags)
26
- * WYSIWYG (the WordPress WYSIWYG editor, API returns HTML)
27
- * Image (upload an image, API returns its URL)
28
- * File (upload a file, API returns its URL)
29
- * Select (drop-down list of choices, API returns the chosen item)
30
- * Checkbox (check for a list of choices, API returns an array of choices)
31
- * Page Link (select 1 or more page, post, or custom post type, API returns the URLs)
32
- * Post Object (select 1 or more page, post, or custom post type, API returns post objects)
33
- * Date Picker (jQuery date picker, options for formatting, API returns string)
34
- * True / False (check box with message, API returns true or false)
35
  * Relationship (select and order post objects with a tidy interface)
36
  * Color Picker (Farbtastic!)
37
- * Repeater (ability to create repeatable blocks of fields)
38
- * Flexible Content (ability to create flexible blocks of fields)
39
- * Gallery (add, edit, and order multiple images in 1 simple field)
40
 
41
  = Tested on =
42
  * Mac Firefox :)
@@ -72,7 +72,7 @@ Your votes really make a difference! Thanks.
72
 
73
  == Frequently Asked Questions ==
74
 
75
- = Q. I have a question. =
76
  A. Chances are, someone else has asked it. Check out the support forum at:
77
  http://support.advancedcustomfields.com/
78
 
@@ -90,12 +90,27 @@ http://support.advancedcustomfields.com/
90
 
91
  == Changelog ==
92
 
93
- = 3.5.8.2 =
94
- * [Fixed] Fix field data not saving caused by Types 1.2
95
- * [Fixed] Fix featured image issue - http://support.advancedcustomfields.com/discussion/5032/featured-image-broken
96
- * [Fixed] Fix WP 3.5 uploader not attaching images to posts - http://support.advancedcustomfields.com/discussion/4960/image-photo039s-uploaded-through-image-field-not-attached-to-post
97
- * [Added] Add filter 'acf_load_field' for sub field - http://support.advancedcustomfields.com/discussion/4153/select-an-image-from-a-drop-down-list
98
- * [Fixed] Fix WYSWYG field showing the upload image button in full screen - http://support.advancedcustomfields.com/discussion/4981/media-button-on-fullscreen-wysiwyg-editor
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
  = 3.5.8.1 =
101
  * [Fixed] Fix PHP error in text / textarea fields
@@ -720,4 +735,4 @@ http://support.advancedcustomfields.com/
720
  * Editor is broken in WordPress 3.3
721
 
722
  = 2.1.4 =
723
- * Adds post_id column back into acf_values
1
  === Advanced Custom Fields ===
2
  Contributors: Elliot Condon
3
  Tags: custom, field, custom field, advanced, simple fields, magic fields, more fields, repeater, matrix, post, type, text, textarea, file, image, edit, admin
4
+ Requires at least: 3.0.0
5
  Tested up to: 3.5.1
6
  License: GPLv2 or later
7
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
 
9
+ 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 and more!
10
 
11
  == Description ==
12
 
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, date picker, true / false, repeater, flexible content, gallery and more to come!)
17
  * Assign your fields to multiple edit pages (via custom location rules)
18
+ * Easily load data through a simple and friendly API
19
  * Uses the native WordPress custom post type for ease of use and fast processing
20
+ * Uses the native WordPress metadata for ease of use and fast processing
21
 
22
  = Field Types =
23
+ * Tab (Group fields into tabs)
24
+ * Text (type text, api returns text)
25
+ * Text Area (type text, api returns text with `<br />` tags)
26
+ * WYSIWYG (a wordpress wysiwyg editor, api returns html)
27
+ * Image (upload an image, api returns the url)
28
+ * File (upload a file, api returns the url)
29
+ * Select (drop down list of choices, api returns chosen item)
30
+ * Checkbox (tick for a list of choices, api returns array of choices)
31
+ * Page Link (select 1 or more page, post or custom post types, api returns the url)
32
+ * Post Object (select 1 or more page, post or custom post types, api returns post objects)
33
+ * Date Picker (jquery date picker, options for format, api returns string)
34
+ * True / False (tick box with message, api returns true or false)
35
  * Relationship (select and order post objects with a tidy interface)
36
  * Color Picker (Farbtastic!)
37
+ * Repeater (ability to create repeatable blocks of fields!)
38
+ * Flexible Content (ability to create flexible blocks of fields!)
39
+ * Gallery (Add, edit and order multiple images in 1 simple field)
40
 
41
  = Tested on =
42
  * Mac Firefox :)
72
 
73
  == Frequently Asked Questions ==
74
 
75
+ = Q. I have a question =
76
  A. Chances are, someone else has asked it. Check out the support forum at:
77
  http://support.advancedcustomfields.com/
78
 
90
 
91
  == Changelog ==
92
 
93
+ = 4.0.0 =
94
+ * [Optimized] Optimize performance by removing heavy class structure and implementing light weight hooks & filters!
95
+ * [Changed] Remove all Add-on code from the core plugin and separate into individual plugins with self hosted updates
96
+ * [Added] Add field 'Taxonomy'
97
+ * [Added] Add field 'User'
98
+ * [Added] Add field 'Email'
99
+ * [Added] Add field 'Password'
100
+ * [Added] Add field group title validation
101
+ * [Fixed] Fix issue where get_field_object returns the wrong field when using WPML
102
+ * [Fixed] Fix duplicate functionality - http://support.advancedcustomfields.com/discussion/4471/duplicate-fields-in-admin-doesn039t-replicate-repeater-fields
103
+ * [Added] Add conditional statements to tab field - http://support.advancedcustomfields.com/discussion/4674/conditional-tabs
104
+ * [Fixed] Fix issue with Preview / Draft where preview would not save custom field data - http://support.advancedcustomfields.com/discussion/4401/cannot-preview-or-schedule-content-to-be-published
105
+ * [Added] Add function get_field_groups()
106
+ * [Added] Add function delete_field() - http://support.advancedcustomfields.com/discussion/4788/deleting-a-field-through-php
107
+ * [Added] Add get_sub_field_object function - http://support.advancedcustomfields.com/discussion/4991/select-inside-repeaterfield
108
+ * [Added] Add 'Top Level' option to page type location rule
109
+ * [Fixed] Fix taxonomy location rule - http://support.advancedcustomfields.com/discussion/5004/field-group-rules-issue
110
+ * [Fixed] Fix tab field with conditional logic - https://github.com/elliotcondon/acf4/issues/14
111
+ * [Fixed] Revert back to original field_key idea. attractive field key's cause too many issues with import / export
112
+ * [Added] Add message field - http://support.advancedcustomfields.com/discussion/5263/additional-description-field
113
+ * [Removed] Removed the_content filter from WYSIWYG field
114
 
115
  = 3.5.8.1 =
116
  * [Fixed] Fix PHP error in text / textarea fields
735
  * Editor is broken in WordPress 3.3
736
 
737
  = 2.1.4 =
738
+ * Adds post_id column back into acf_values