Advanced Custom Fields - Version 1.1.4

Version Description

  • Fixed Image / File upload issues
  • Location now supports category names
  • Improved API - now it doesn't need any custom fields!
  • Fixed table encoding issue
  • Small CSS / Field changes to ACF edit screen
Download this release

Release Info

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

Code changes from version 1.1.3 to 1.1.4

acf.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Advanced Custom Fields
4
  Plugin URI: http://plugins.elliotcondon.com/advanced-custom-fields/
5
  Description: Completely Customise your edit pages with an assortment of field types: Wysiwyg, text, image, select, checkbox and more! Hide unwanted metaboxes and assign to any edit page!
6
- Version: 1.1.3
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
@@ -33,7 +33,7 @@ class Acf
33
  $this->dir = plugins_url('',__FILE__);
34
  $this->siteurl = get_bloginfo('url');
35
  $this->wpadminurl = admin_url();
36
- $this->version = '1.1.3';
37
 
38
  // set text domain
39
  load_plugin_textdomain('acf', false, $this->path.'/lang' );
@@ -464,6 +464,7 @@ class Acf
464
  $location->post_ids = unserialize($location->post_ids);
465
  $location->page_templates = unserialize($location->page_templates);
466
  $location->page_parents = unserialize($location->page_parents);
 
467
 
468
 
469
  // if empty
@@ -473,7 +474,8 @@ class Acf
473
  if(empty($location->post_ids)){$location->post_ids = array();}
474
  if(empty($location->page_templates)){$location->page_templates = array();}
475
  if(empty($location->page_parents)){$location->page_parents = array();}
476
- if(empty($location->page_parents)){$location->page_parents = array();}
 
477
 
478
 
479
  // return location
3
  Plugin Name: Advanced Custom Fields
4
  Plugin URI: http://plugins.elliotcondon.com/advanced-custom-fields/
5
  Description: Completely Customise your edit pages with an assortment of field types: Wysiwyg, text, image, select, checkbox and more! Hide unwanted metaboxes and assign to any edit page!
6
+ Version: 1.1.4
7
  Author: Elliot Condon
8
  Author URI: http://www.elliotcondon.com/
9
  License: GPL
33
  $this->dir = plugins_url('',__FILE__);
34
  $this->siteurl = get_bloginfo('url');
35
  $this->wpadminurl = admin_url();
36
+ $this->version = '1.1.4';
37
 
38
  // set text domain
39
  load_plugin_textdomain('acf', false, $this->path.'/lang' );
464
  $location->post_ids = unserialize($location->post_ids);
465
  $location->page_templates = unserialize($location->page_templates);
466
  $location->page_parents = unserialize($location->page_parents);
467
+ $location->category_names = unserialize($location->category_names);
468
 
469
 
470
  // if empty
474
  if(empty($location->post_ids)){$location->post_ids = array();}
475
  if(empty($location->page_templates)){$location->page_templates = array();}
476
  if(empty($location->page_parents)){$location->page_parents = array();}
477
+ if(empty($location->category_names)){$location->category_names = array();}
478
+
479
 
480
 
481
  // return location
core/admin_head.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
 
3
  global $post;
 
4
 
5
  // shows hidden custom fields
6
  //echo "<style type='text/css'>#postcustom .hidden { display: table-row; }</style>";
@@ -27,7 +28,7 @@ elseif(get_post_type($post) == 'acf')
27
  echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.options.css" />';
28
 
29
  add_meta_box('acf_fields', 'Fields', array($this, '_fields_meta_box'), 'acf', 'normal', 'high');
30
- add_meta_box('acf_location', 'Assign to edit page</span><span class="description">- Specify exactly where you want your Advanced Custom Fields fields to appear', array($this, '_location_meta_box'), 'acf', 'normal', 'high');
31
  add_meta_box('acf_options', 'Advanced Options</span><span class="description">- Customise the edit page', array($this, '_options_meta_box'), 'acf', 'normal', 'high');
32
  }
33
  else
@@ -76,6 +77,17 @@ else
76
  // page parents
77
  if(in_array($post->post_parent, $location->page_parents)) {$add_box = true; }
78
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  // current user role
81
  global $current_user;
1
  <?php
2
 
3
  global $post;
4
+
5
 
6
  // shows hidden custom fields
7
  //echo "<style type='text/css'>#postcustom .hidden { display: table-row; }</style>";
28
  echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.options.css" />';
29
 
30
  add_meta_box('acf_fields', 'Fields', array($this, '_fields_meta_box'), 'acf', 'normal', 'high');
31
+ add_meta_box('acf_location', 'Assign to edit page</span><span class="description">- Create rules to show your advanced custom fields on edit pages', array($this, '_location_meta_box'), 'acf', 'normal', 'high');
32
  add_meta_box('acf_options', 'Advanced Options</span><span class="description">- Customise the edit page', array($this, '_options_meta_box'), 'acf', 'normal', 'high');
33
  }
34
  else
77
  // page parents
78
  if(in_array($post->post_parent, $location->page_parents)) {$add_box = true; }
79
 
80
+ // category names
81
+ $cats = get_the_category();
82
+ if($cats)
83
+ {
84
+ foreach($cats as $cat)
85
+ {
86
+ if(in_array($cat->name, $location->category_names)) {$add_box = true; }
87
+ }
88
+ }
89
+
90
+
91
 
92
  // current user role
93
  global $current_user;
core/api.php CHANGED
@@ -48,30 +48,19 @@ function get_acf($post_id = false)
48
  }
49
 
50
 
51
- // get ID's for this post
52
- $acf_id = explode(',',get_post_meta($post_id, '_acf_id', true));
53
-
54
-
55
- // checkpoint: If no id's exist for this page, get out of here!
56
- if(empty($acf_id)){return null;}
57
-
58
-
59
- // loop through ID's
60
- foreach($acf_id as $id)
61
- {
62
- $this_fields = $acf->get_fields($id);
63
- if(empty($this_fields)){return null;}
64
-
65
- foreach($this_fields as $this_field)
66
- {
67
- $fields[] = $this_field;
68
- }
69
- }
70
 
71
-
72
- // checkpoint: If no fields, get out of here!
73
- if(empty($fields)){return null;}
74
-
75
 
76
  foreach($fields as $field)
77
  {
@@ -195,8 +184,12 @@ class ACF_WP_Query extends WP_Query
195
 
196
  function posts_join($join)
197
  {
198
- $join .= "LEFT JOIN wp_acf_values v ON v.post_id=wp_posts.ID
199
- LEFT JOIN wp_acf_fields f ON f.id=v.field_id";
 
 
 
 
200
 
201
  return $join;
202
  }
48
  }
49
 
50
 
51
+ global $wpdb;
52
+ $acf_fields = $wpdb->prefix.'acf_fields';
53
+ $acf_values = $wpdb->prefix.'acf_values';
54
+
55
+
56
+ // get fields
57
+ $fields = $wpdb->get_results("SELECT DISTINCT f.* FROM $acf_fields f
58
+ LEFT JOIN $acf_values v ON v.field_id=f.id
59
+ WHERE v.post_id = '$post_id'");
60
+
 
 
 
 
 
 
 
 
 
61
 
62
+ if(empty($fields)){return null;}
63
+
 
 
64
 
65
  foreach($fields as $field)
66
  {
184
 
185
  function posts_join($join)
186
  {
187
+ global $wpdb;
188
+ $acf_fields = $wpdb->prefix.'acf_fields';
189
+ $acf_values = $wpdb->prefix.'acf_values';
190
+
191
+ $join .= "LEFT JOIN $acf_values v ON v.post_id=wp_posts.ID
192
+ LEFT JOIN $acf_fields f ON f.id=v.field_id";
193
 
194
  return $join;
195
  }
core/fields/file.php CHANGED
@@ -11,9 +11,18 @@ class File
11
  $this->title = __('File','acf');
12
 
13
  add_action("admin_head-media-upload-popup", array($this, 'popup_head'));
 
 
14
  }
15
 
16
 
 
 
 
 
 
 
 
17
  function popup_head()
18
  {
19
  if($_GET['acf_type'] == 'file')
@@ -45,17 +54,77 @@ class File
45
  }
46
 
47
  </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  <script type="text/javascript">
49
- (function($){
50
- $(document).ready(function(){
51
- $('input[value="Insert into Post"]').attr('value','<?php _e('Select File','acf'); ?>');
52
- });
53
- })(jQuery);
 
 
 
 
 
54
  </script>
55
  <?php
 
 
 
 
 
56
  }
 
57
  }
58
-
59
 
60
  function html($field)
61
  {
11
  $this->title = __('File','acf');
12
 
13
  add_action("admin_head-media-upload-popup", array($this, 'popup_head'));
14
+ add_filter('media_send_to_editor', array($this, 'media_send_to_editor'), 15, 2 );
15
+ add_action('admin_init', array($this, 'admin_init'));
16
  }
17
 
18
 
19
+ /*---------------------------------------------------------------------------------------------
20
+ * popup_head - STYLES MEDIA THICKBOX
21
+ *
22
+ * @author Elliot Condon
23
+ * @since 1.1.4
24
+ *
25
+ ---------------------------------------------------------------------------------------------*/
26
  function popup_head()
27
  {
28
  if($_GET['acf_type'] == 'file')
54
  }
55
 
56
  </style>
57
+
58
+ <?php
59
+ }
60
+ }
61
+
62
+
63
+ /*---------------------------------------------------------------------------------------------
64
+ * rename_buttons - RENAMES MEDIA THICKBOX BUTTONS
65
+ *
66
+ * @author Elliot Condon
67
+ * @since 1.1.4
68
+ *
69
+ ---------------------------------------------------------------------------------------------*/
70
+ function admin_init()
71
+ {
72
+ if(isset($_GET["acf_type"]) && $_GET["acf_type"] == "file")
73
+ {
74
+ add_filter('gettext', array($this, 'rename_buttons'), 1, 3);
75
+ }
76
+ }
77
+
78
+ function rename_buttons($translated_text, $source_text, $domain) {
79
+ if(isset($_GET["acf_type"]) && $_GET["acf_type"] == "file")
80
+ {
81
+ if ($source_text == 'Insert into Post') {
82
+ return __('Select File', 'acf' );
83
+ }
84
+ }
85
+ return $translated_text;
86
+ }
87
+
88
+
89
+ /*---------------------------------------------------------------------------------------------
90
+ * media_send_to_editor - SEND IMAGE TO ACF DIV
91
+ *
92
+ * @author Elliot Condon
93
+ * @since 1.1.4
94
+ *
95
+ ---------------------------------------------------------------------------------------------*/
96
+ function media_send_to_editor($html, $id)
97
+ {
98
+ parse_str($_POST["_wp_http_referer"], $arr_postinfo);
99
+
100
+ if(isset($arr_postinfo["acf_type"]) && $arr_postinfo["acf_type"] == "file")
101
+ {
102
+
103
+ $file_src = wp_get_attachment_url($id);
104
+
105
+ ?>
106
  <script type="text/javascript">
107
+
108
+ self.parent.acf_div.find('input.value').val('<?php echo $file_src; ?>');
109
+ self.parent.acf_div.find('p.file span').html('<?php echo $file_src; ?>');
110
+ self.parent.acf_div.addClass('active');
111
+
112
+ // reset acf_div and return false
113
+ self.parent.acf_div = null;
114
+
115
+ self.parent.tb_remove();
116
+
117
  </script>
118
  <?php
119
+ exit;
120
+ }
121
+ else
122
+ {
123
+ return $html;
124
  }
125
+
126
  }
127
+
128
 
129
  function html($field)
130
  {
core/fields/image.php CHANGED
@@ -10,10 +10,19 @@ class Image
10
  $this->name = 'image';
11
  $this->title = __('Image','acf');
12
 
13
- add_action("admin_head-media-upload-popup", array($this, 'popup_head'));
 
 
14
  }
15
 
16
 
 
 
 
 
 
 
 
17
  function popup_head()
18
  {
19
  if($_GET['acf_type'] == 'image')
@@ -45,17 +54,77 @@ class Image
45
  }
46
 
47
  </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  <script type="text/javascript">
49
- (function($){
50
- $(document).ready(function(){
51
- $('input.button[value="Insert into Post"]').attr('value','<?php _e('Select Image','acf'); ?>');
52
- });
53
- })(jQuery);
 
 
 
 
 
54
  </script>
55
  <?php
 
 
 
 
 
56
  }
 
57
  }
58
-
59
 
60
  function html($field)
61
  {
10
  $this->name = 'image';
11
  $this->title = __('Image','acf');
12
 
13
+ add_action('admin_head-media-upload-popup', array($this, 'popup_head'));
14
+ add_filter('media_send_to_editor', array($this, 'media_send_to_editor'), 15, 2 );
15
+ add_action('admin_init', array($this, 'admin_init'));
16
  }
17
 
18
 
19
+ /*---------------------------------------------------------------------------------------------
20
+ * popup_head - STYLES MEDIA THICKBOX
21
+ *
22
+ * @author Elliot Condon
23
+ * @since 1.1.4
24
+ *
25
+ ---------------------------------------------------------------------------------------------*/
26
  function popup_head()
27
  {
28
  if($_GET['acf_type'] == 'image')
54
  }
55
 
56
  </style>
57
+
58
+ <?php
59
+ }
60
+ }
61
+
62
+
63
+ /*---------------------------------------------------------------------------------------------
64
+ * rename_buttons - RENAMES MEDIA THICKBOX BUTTONS
65
+ *
66
+ * @author Elliot Condon
67
+ * @since 1.1.4
68
+ *
69
+ ---------------------------------------------------------------------------------------------*/
70
+ function admin_init()
71
+ {
72
+ if(isset($_GET["acf_type"]) && $_GET["acf_type"] == "image")
73
+ {
74
+ add_filter('gettext', array($this, 'rename_buttons'), 1, 3);
75
+ }
76
+ }
77
+
78
+ function rename_buttons($translated_text, $source_text, $domain) {
79
+ if(isset($_GET["acf_type"]) && $_GET["acf_type"] == "image")
80
+ {
81
+ if ($source_text == 'Insert into Post') {
82
+ return __('Select Image', 'acf' );
83
+ }
84
+ }
85
+ return $translated_text;
86
+ }
87
+
88
+
89
+ /*---------------------------------------------------------------------------------------------
90
+ * media_send_to_editor - SEND IMAGE TO ACF DIV
91
+ *
92
+ * @author Elliot Condon
93
+ * @since 1.1.4
94
+ *
95
+ ---------------------------------------------------------------------------------------------*/
96
+ function media_send_to_editor($html, $id)
97
+ {
98
+ parse_str($_POST["_wp_http_referer"], $arr_postinfo);
99
+
100
+ if(isset($arr_postinfo["acf_type"]) && $arr_postinfo["acf_type"] == "image")
101
+ {
102
+
103
+ $file_src = wp_get_attachment_url($id);
104
+
105
+ ?>
106
  <script type="text/javascript">
107
+
108
+ self.parent.acf_div.find('input.value').val('<?php echo $file_src; ?>');
109
+ self.parent.acf_div.find('img').attr('src','<?php echo $file_src; ?>');
110
+ self.parent.acf_div.addClass('active');
111
+
112
+ // reset acf_div and return false
113
+ self.parent.acf_div = null;
114
+
115
+ self.parent.tb_remove();
116
+
117
  </script>
118
  <?php
119
+ exit;
120
+ }
121
+ else
122
+ {
123
+ return $html;
124
  }
125
+
126
  }
127
+
128
 
129
  function html($field)
130
  {
core/input_meta_box.php CHANGED
@@ -15,9 +15,7 @@
15
  {
16
  $fields[] = $this_field;
17
  }
18
-
19
- // add id to array (easy to explode it in a hidden input on line 68)
20
- $acf_ids[] = $acf->ID;
21
  }
22
 
23
  // get options from first (top level) acf
@@ -29,7 +27,6 @@
29
 
30
  <input type="hidden" name="ei_noncename" id="ei_noncename" value="<?php echo wp_create_nonce('ei-n'); ?>" />
31
  <input type="hidden" name="input_meta_box" value="true" />
32
- <input type="hidden" name="acf_id" value="<?php echo implode(',',$acf_ids); ?>" />
33
  <?php
34
 
35
 
15
  {
16
  $fields[] = $this_field;
17
  }
18
+
 
 
19
  }
20
 
21
  // get options from first (top level) acf
27
 
28
  <input type="hidden" name="ei_noncename" id="ei_noncename" value="<?php echo wp_create_nonce('ei-n'); ?>" />
29
  <input type="hidden" name="input_meta_box" value="true" />
 
30
  <?php
31
 
32
 
core/input_save.php CHANGED
@@ -12,10 +12,6 @@ if($_POST['input_meta_box'] == 'true')
12
  }
13
 
14
 
15
- // save which ACF's were here: for use in the api
16
- add_post_meta($post_id, '_acf_id', $_POST['acf_id']);
17
-
18
-
19
  // set table name
20
  global $wpdb;
21
  $table_name = $wpdb->prefix.'acf_values';
12
  }
13
 
14
 
 
 
 
 
15
  // set table name
16
  global $wpdb;
17
  $table_name = $wpdb->prefix.'acf_values';
core/location_meta_box.php CHANGED
@@ -16,7 +16,7 @@
16
  <h4><?php _e("Enter values in the fields below to add this ACF to an edit screen",'acf'); ?></h4>
17
  <ul>
18
  <li><?php _e("The values you enter bellow will be used to match against edit screens",'acf'); ?></li>
19
- <li><?php _e("If any of the values match the edit screen, this ACF will be used",'acf'); ?></li>
20
  <li><?php _e("Blank fields will be ignored",'acf'); ?></li>
21
  <li><?php _e("Use the override to remove all previous ACF's form an edit screen. This is useful for creating an ACF for all normal pages, and then creating a custom ACF for a home page (page title = 'Home'). Please note that the home page ACF needs a higher page order to remove ACF's before it",'acf'); ?></li>
22
  </ul>
@@ -46,22 +46,19 @@
46
  unset($post_types['acf']);
47
 
48
 
49
- $temp_field->type = 'select';
50
  $temp_field->input_name = 'acf[location][post_types]';
51
  $temp_field->input_class = '';
52
  $temp_field->input_id = 'post_types';
53
  $temp_field->value = $location->post_types;
54
  $temp_field->options = array(
55
  'choices' => $post_types,
56
- 'multiple' => '1'
57
  );
58
 
59
  $this->create_field($temp_field);
60
 
61
  ?>
62
- <p class="description"><?php _e("Selecting a post type here will add this ACF to all edit screens of that post type.<br />(if your custom post type does not appear, make sure it is publicly query-able)<br /><br />
63
- Tip: Unselect post types and use the options below to customise your ACF location!<br />
64
- (command+click)",'acf'); ?></p>
65
  </td>
66
  </tr>
67
  <tr>
@@ -164,6 +161,26 @@
164
  <p class="description"><?php _e("eg. 1, 2, 3",'acf'); ?></p>
165
  </td>
166
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  <tr>
168
  <td class="label">
169
  <label for="page_parent"><?php _e("Overrides",'acf'); ?></label>
16
  <h4><?php _e("Enter values in the fields below to add this ACF to an edit screen",'acf'); ?></h4>
17
  <ul>
18
  <li><?php _e("The values you enter bellow will be used to match against edit screens",'acf'); ?></li>
19
+ <li><?php _e("If <strong>any</strong> of the values match the edit screen, this ACF will be used",'acf'); ?></li>
20
  <li><?php _e("Blank fields will be ignored",'acf'); ?></li>
21
  <li><?php _e("Use the override to remove all previous ACF's form an edit screen. This is useful for creating an ACF for all normal pages, and then creating a custom ACF for a home page (page title = 'Home'). Please note that the home page ACF needs a higher page order to remove ACF's before it",'acf'); ?></li>
22
  </ul>
46
  unset($post_types['acf']);
47
 
48
 
49
+ $temp_field->type = 'checkbox';
50
  $temp_field->input_name = 'acf[location][post_types]';
51
  $temp_field->input_class = '';
52
  $temp_field->input_id = 'post_types';
53
  $temp_field->value = $location->post_types;
54
  $temp_field->options = array(
55
  'choices' => $post_types,
 
56
  );
57
 
58
  $this->create_field($temp_field);
59
 
60
  ?>
61
+ <p class="description"><?php _e("Selecting a post type here will add this ACF to <strong>all</strong> edit screens of that post type.<br />(if your custom post type does not appear, make sure it is publicly query-able)",'acf'); ?></p>
 
 
62
  </td>
63
  </tr>
64
  <tr>
161
  <p class="description"><?php _e("eg. 1, 2, 3",'acf'); ?></p>
162
  </td>
163
  </tr>
164
+ <tr>
165
+ <td class="label">
166
+ <label for="category_names"><?php _e("Category Names's",'acf'); ?></label>
167
+ </td>
168
+ <td>
169
+ <?php
170
+
171
+ $temp_field->type = 'text';
172
+ $temp_field->input_name = 'acf[location][category_names]';
173
+ $temp_field->input_class = '';
174
+ $temp_field->input_id = 'category_names';
175
+ $temp_field->value = implode(', ',$location->category_names);
176
+ $temp_field->options = array();
177
+
178
+ $this->create_field($temp_field);
179
+
180
+ ?>
181
+ <p class="description"><?php _e("eg. News, Media, Uncategoriazed",'acf'); ?></p>
182
+ </td>
183
+ </tr>
184
  <tr>
185
  <td class="label">
186
  <label for="page_parent"><?php _e("Overrides",'acf'); ?></label>
core/options_meta_box.php CHANGED
@@ -46,18 +46,17 @@
46
  </tr>
47
  <tr>
48
  <td class="label">
49
- <label for="post_type"><?php _e("Filter Users",'acf'); ?></label>
50
  </td>
51
  <td>
52
  <?php
53
 
54
- $temp_field->type = 'select';
55
  $temp_field->input_name = 'acf[options][user_roles]';
56
  $temp_field->input_class = '';
57
  $temp_field->input_id = 'user_roles';
58
  $temp_field->value = $options->user_roles;
59
  $temp_field->options = array(
60
- 'multiple' => '1',
61
  'choices' => array(
62
  '10' => 'Administrator',
63
  '7' => 'Editor',
46
  </tr>
47
  <tr>
48
  <td class="label">
49
+ <label for="post_type"><?php _e("Show only for specific users",'acf'); ?></label>
50
  </td>
51
  <td>
52
  <?php
53
 
54
+ $temp_field->type = 'checkbox';
55
  $temp_field->input_name = 'acf[options][user_roles]';
56
  $temp_field->input_class = '';
57
  $temp_field->input_id = 'user_roles';
58
  $temp_field->value = $options->user_roles;
59
  $temp_field->options = array(
 
60
  'choices' => array(
61
  '10' => 'Administrator',
62
  '7' => 'Editor',
core/update.php CHANGED
@@ -2,54 +2,90 @@
2
 
3
  $version = get_option('acf_version','1.0.5');
4
 
 
 
 
 
 
 
 
 
 
 
 
5
  if(version_compare($version,'1.1.0') < 0)
6
  {
7
  // Version is less than 1.1.0
8
 
9
  global $wpdb;
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  // create acf_fields table
12
  $table_name = $wpdb->prefix.'acf_fields';
13
- $sql = "CREATE TABLE " . $table_name . " (
14
- id bigint(20) NOT NULL AUTO_INCREMENT,
15
- order_no int(9) NOT NULL DEFAULT '0',
16
- post_id bigint(20) NOT NULL DEFAULT '0',
17
- parent_id bigint(20) NOT NULL DEFAULT '0',
18
- label text NOT NULL,
19
- name text NOT NULL,
20
- type text NOT NULL,
21
- options text NOT NULL,
22
- UNIQUE KEY id (id)
23
- );";
 
 
 
 
24
 
25
 
26
  // create acf_options table
27
  $table_name = $wpdb->prefix.'acf_options';
28
- $sql .= "CREATE TABLE " . $table_name . " (
29
- id bigint(20) NOT NULL AUTO_INCREMENT,
30
- acf_id bigint(20) NOT NULL DEFAULT '0',
31
- name text NOT NULL,
32
- value text NOT NULL,
33
- type text NOT NULL,
34
- UNIQUE KEY id (id)
35
- );";
 
 
 
 
36
 
37
 
38
  // create acf_options table
39
  $table_name = $wpdb->prefix.'acf_values';
40
- $sql .= "CREATE TABLE " . $table_name . " (
41
- id bigint(20) NOT NULL AUTO_INCREMENT,
42
- order_no int(9) NOT NULL DEFAULT '0',
43
- field_id bigint(20) NOT NULL DEFAULT '0',
44
- value text NOT NULL,
45
- post_id bigint(20) NOT NULL DEFAULT '0',
46
- UNIQUE KEY id (id)
47
- );";
 
 
 
 
48
 
49
 
50
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
51
- dbDelta($sql);
52
-
53
 
54
  $acfs = get_posts(array(
55
  'numberposts' => -1,
@@ -269,6 +305,63 @@ if(version_compare($version,'1.1.0') < 0)
269
  }
270
 
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  // update to latest acf version
273
- update_option('acf_version','1.1.3');
274
  ?>
2
 
3
  $version = get_option('acf_version','1.0.5');
4
 
5
+
6
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
7
+
8
+
9
+ /*---------------------------------------------------------------------------------------------
10
+ * Update to 1.1.0 - this version needs tables!
11
+ *
12
+ * @author Elliot Condon
13
+ * @since 1.0.6
14
+ *
15
+ ---------------------------------------------------------------------------------------------*/
16
  if(version_compare($version,'1.1.0') < 0)
17
  {
18
  // Version is less than 1.1.0
19
 
20
  global $wpdb;
21
 
22
+
23
+ // set charset
24
+ if ($wpdb->has_cap('collation'))
25
+ {
26
+ if(!empty($wpdb->charset))
27
+ {
28
+ $charset_collate = " DEFAULT CHARACTER SET $wpdb->charset";
29
+ }
30
+ if(!empty($wpdb->collate))
31
+ {
32
+ $charset_collate .= " COLLATE $wpdb->collate";
33
+
34
+ }
35
+ }
36
+
37
+
38
  // create acf_fields table
39
  $table_name = $wpdb->prefix.'acf_fields';
40
+ if(!$wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
41
+ {
42
+ $sql = "CREATE TABLE " . $table_name . " (
43
+ id bigint(20) NOT NULL AUTO_INCREMENT,
44
+ order_no int(9) NOT NULL DEFAULT '0',
45
+ post_id bigint(20) NOT NULL DEFAULT '0',
46
+ parent_id bigint(20) NOT NULL DEFAULT '0',
47
+ label text NOT NULL,
48
+ name text NOT NULL,
49
+ type text NOT NULL,
50
+ options text NOT NULL,
51
+ UNIQUE KEY id (id)
52
+ ) ".$charset_collate.";";
53
+ dbDelta($sql);
54
+ }
55
 
56
 
57
  // create acf_options table
58
  $table_name = $wpdb->prefix.'acf_options';
59
+ if(!$wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
60
+ {
61
+ $sql = "CREATE TABLE " . $table_name . " (
62
+ id bigint(20) NOT NULL AUTO_INCREMENT,
63
+ acf_id bigint(20) NOT NULL DEFAULT '0',
64
+ name text NOT NULL,
65
+ value text NOT NULL,
66
+ type text NOT NULL,
67
+ UNIQUE KEY id (id)
68
+ ) ".$charset_collate.";";
69
+ dbDelta($sql);
70
+ }
71
 
72
 
73
  // create acf_options table
74
  $table_name = $wpdb->prefix.'acf_values';
75
+ if(!$wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
76
+ {
77
+ $sql = "CREATE TABLE " . $table_name . " (
78
+ id bigint(20) NOT NULL AUTO_INCREMENT,
79
+ order_no int(9) NOT NULL DEFAULT '0',
80
+ field_id bigint(20) NOT NULL DEFAULT '0',
81
+ value text NOT NULL,
82
+ post_id bigint(20) NOT NULL DEFAULT '0',
83
+ UNIQUE KEY id (id)
84
+ ) ".$charset_collate.";";
85
+ dbDelta($sql);
86
+ }
87
 
88
 
 
 
 
89
 
90
  $acfs = get_posts(array(
91
  'numberposts' => -1,
305
  }
306
 
307
 
308
+
309
+ /*---------------------------------------------------------------------------------------------
310
+ * Update to 1.1.0 - this version adds updates tables to be utf-8
311
+ *
312
+ * @author Elliot Condon
313
+ * @since 1.0.6
314
+ *
315
+ ---------------------------------------------------------------------------------------------*/
316
+
317
+ if(version_compare($version,'1.1.4') < 0)
318
+ {
319
+ // Version is less than 1.1.4
320
+
321
+ global $wpdb;
322
+
323
+
324
+ // set charset
325
+ if(!empty($wpdb->charset))
326
+ {
327
+ $char = $wpdb->charset;
328
+ }
329
+ else
330
+ {
331
+ $char = "utf8";
332
+ }
333
+
334
+
335
+
336
+ // alter acf_fields table
337
+ $table_name = $wpdb->prefix.'acf_fields';
338
+ if($wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
339
+ {
340
+ $sql = "ALTER TABLE $table_name charset=$char;";
341
+ $wpdb->query($sql);
342
+ }
343
+
344
+
345
+ // alter acf_options table
346
+ $table_name = $wpdb->prefix.'acf_options';
347
+ if($wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
348
+ {
349
+ $sql = "ALTER TABLE $table_name charset=$char;";
350
+ $wpdb->query($sql);
351
+ }
352
+
353
+
354
+ // alter acf_values table
355
+ $table_name = $wpdb->prefix.'acf_values';
356
+ if($wpdb->get_var("SHOW TABLES LIKE '".$table_name."'"))
357
+ {
358
+ $sql = "ALTER TABLE $table_name charset=$char;";
359
+ $wpdb->query($sql);
360
+ }
361
+
362
+
363
+ }
364
+
365
  // update to latest acf version
366
+ update_option('acf_version','1.1.4');
367
  ?>
css/style.input.css CHANGED
@@ -1,7 +1,8 @@
1
  .postbox#acf_input {
2
- border: #EAEAEA solid 1px;
3
- overflow: hidden;
4
  background: transparent;
 
 
5
  }
6
 
7
  table.acf_input {
@@ -135,7 +136,7 @@ table.acf_input {
135
  table.acf_input > tbody > tr > td {
136
  border-bottom: 1px solid #eaeaea;
137
  border-top: 1px solid #FFFFFF;
138
- padding: 8px;
139
  }
140
 
141
  table.acf_input > tbody > tr > td > label {
1
  .postbox#acf_input {
2
+ border: #EAEAEA solid 0px;
 
3
  background: transparent;
4
+ position: relative;
5
+ overflow: visible;
6
  }
7
 
8
  table.acf_input {
136
  table.acf_input > tbody > tr > td {
137
  border-bottom: 1px solid #eaeaea;
138
  border-top: 1px solid #FFFFFF;
139
+ padding: 8px 0;
140
  }
141
 
142
  table.acf_input > tbody > tr > td > label {
js/functions.input.js CHANGED
@@ -6,6 +6,9 @@
6
  // vars
7
  var wysiwyg_count = 0;
8
  var post_id = 0;
 
 
 
9
 
10
 
11
  /*-------------------------------------------
@@ -94,37 +97,17 @@
94
  $.fn.make_acf_image = function(){
95
 
96
  var div = $(this);
97
- var orig_send_to_editor = window.send_to_editor;
98
 
99
  div.find('input.button').click(function(){
100
 
 
 
 
101
 
102
  // show the thickbox
103
  tb_show('Add Image to field', 'media-upload.php?post_id='+post_id+'&type=image&acf_type=image&TB_iframe=1');
104
 
105
-
106
- // new window.send_to_editor function
107
- window.send_to_editor = function(html){
108
- var new_div = $('<div>'+html+'</div>');
109
- var img_src = new_div.find('a').attr('href');
110
-
111
- div.find('input.value').val(img_src);
112
- div.find('img').attr('src',img_src);
113
- div.addClass('active');
114
- tb_remove();
115
-
116
- window.send_to_editor = orig_send_to_editor;
117
- }
118
-
119
-
120
- // Thickbox close needs to reset window.send_to_editor
121
- $('#TB_overlay, a#TB_closeWindowButton').unbind('click').click(function(){
122
- window.send_to_editor = orig_send_to_editor;
123
- tb_remove();
124
- return false;
125
- });
126
-
127
-
128
  return false;
129
  });
130
 
@@ -145,36 +128,18 @@
145
  $.fn.make_acf_file = function(){
146
 
147
  var div = $(this);
148
- var orig_send_to_editor = window.send_to_editor;
149
 
150
  div.find('p.no_file input.button').click(function(){
151
 
 
 
 
 
152
  // show the thickbox
153
  tb_show('Add File to field', 'media-upload.php?post_id='+post_id+'&type=file&acf_type=file&TB_iframe=1');
154
 
155
 
156
- // new window.send_to_editor function
157
- window.send_to_editor = function(html) {
158
- var new_div = $('<div>'+html+'</div>');
159
- var file_src = new_div.find('a').attr('href');
160
-
161
- div.find('input.value').val(file_src);
162
- div.find('p.file span').html(file_src);
163
- div.addClass('active');
164
- tb_remove();
165
-
166
- window.send_to_editor = orig_send_to_editor;
167
- }
168
-
169
-
170
- // Thickbox close needs to reset window.send_to_editor
171
- $('#TB_overlay, a#TB_closeWindowButton').unbind('click').click(function(){
172
- window.send_to_editor = orig_send_to_editor;
173
- tb_remove();
174
- return false;
175
- });
176
-
177
-
178
  return false;
179
  });
180
 
@@ -191,152 +156,6 @@
191
 
192
 
193
 
194
- /*-------------------------------------------
195
- Repeaters
196
- -------------------------------------------*/
197
- $.fn.make_acf_repeater = function(){
198
-
199
- // vars
200
- var div = $(this);
201
- var add_field = div.find('a#add_field');
202
- var fields_limit = 99;
203
-
204
-
205
- /*-------------------------------------------
206
- Add Field Button
207
- -------------------------------------------*/
208
- add_field.unbind("click").click(function(){
209
-
210
- // limit fields
211
- if(div.children('table').children('tbody').children('tr').length >= fields_limit)
212
- {
213
- alert('Field limit reached!');
214
- return false;
215
- }
216
-
217
- // clone last tr
218
- var new_field = div.children('table').children('tbody').children('tr').last().clone();
219
-
220
- // append to table
221
- div.children('table').children('tbody').append(new_field);
222
-
223
- // set new field
224
- new_field.reset_values();
225
-
226
- // re make special fields
227
- new_field.make_all_fields();
228
-
229
- // update order numbers
230
- update_order_numbers();
231
-
232
-
233
- return false;
234
-
235
-
236
- });
237
- }
238
-
239
-
240
- /*-------------------------------------------
241
- Update Order Numbers
242
- -------------------------------------------*/
243
- function update_order_numbers(){
244
- $('.postbox#acf_input .repeater').each(function(){
245
- $(this).children('table').children('tbody').children('tr').each(function(i){
246
- $(this).children('td.order').html(i+1);
247
- });
248
-
249
- });
250
- }
251
-
252
- /*-------------------------------------------
253
- Sortable
254
- -------------------------------------------*/
255
- $.fn.make_sortable = function(){
256
-
257
- //alert('make sortable');
258
- var div = $(this).find('.repeater');
259
-
260
- var fixHelper = function(e, ui) {
261
- ui.children().each(function() {
262
- $(this).width($(this).width());
263
- });
264
- return ui;
265
- };
266
-
267
- div.find('table.acf_input').children('tbody').unbind('sortable').sortable({
268
- update: function(event, ui){
269
- update_order_numbers();
270
- $(this).make_all_fields();
271
- //alert('update');
272
- },
273
- handle: 'td.order',
274
- helper: fixHelper,
275
- //pre process stuff as soon as the element has been lifted
276
- start: function(event, ui)
277
- {
278
- console.log(ui.item);
279
- if(ui.item.find('.acf_wysiwyg').exists())
280
- {
281
- //console.log('aaaah, i found a wysiwyg')
282
- var id = ui.item.find('.acf_wysiwyg textarea').attr('id');
283
- //alert(tinyMCE.get(id).getContent());
284
- //tinyMCE.execCommand("mceRemoveControl", false, id);
285
- }
286
- },
287
-
288
- //post process stuff as soon as the element has been dropped
289
- stop: function(event, ui)
290
- {
291
- if(ui.item.find('.acf_wysiwyg').exists())
292
- {
293
- //var id = ui.item.find('.acf_wysiwyg textarea').attr('id');
294
- //tinyMCE.execCommand("mceAddControl", false, id);
295
- //div.make_sortable();
296
- }
297
- }
298
- });
299
- }
300
-
301
-
302
-
303
- /*-------------------------------------------
304
- Reset Values
305
- -------------------------------------------*/
306
- $.fn.reset_values = function(){
307
-
308
- if($(this).find('.acf_wysiwyg').exists())
309
- {
310
- var wysiwyg = $(this).find('.acf_wysiwyg');
311
-
312
- var name = wysiwyg.find('textarea').first().attr('name');
313
-
314
- wysiwyg.html('<textarea name="'+name+'"></textarea>');
315
- }
316
-
317
-
318
- // image upload
319
- $(this).find('img').remove();
320
- $(this).find('a.remove_image').addClass('hide');
321
- $(this).find('iframe').removeClass('hide');
322
-
323
-
324
- // total fields
325
- var total_fields = $(this).siblings('tr').length;
326
-
327
-
328
- // reset all values
329
- $(this).find('[name]').each(function()
330
- {
331
- var name = $(this).attr('name').replace('['+(total_fields-1)+']','['+(total_fields)+']');
332
- $(this).attr('name', name);
333
- $(this).val('');
334
- $(this).attr('checked','');
335
- $(this).attr('selected','');
336
- });
337
-
338
-
339
- }
340
 
341
  $.fn.make_all_fields = function()
342
  {
@@ -364,37 +183,6 @@
364
  }
365
 
366
 
367
- /*-------------------------------------------
368
- Remove Field Button
369
- -------------------------------------------*/
370
- $.fn.add_remove_buttons = function(){
371
- $(this).find('a.remove_field').unbind('click').live('click', function(){
372
-
373
- var total_fields = $(this).parents('.repeater').children('table').children('tbody').children('tr').length;
374
-
375
- // needs at least one
376
- if(total_fields <= 1)
377
- {
378
- return false;
379
- }
380
-
381
- var tr = $(this).parents('tr').first();
382
- console.log('s');
383
- tr.fadeTo(300,0,function(){
384
- tr.animate({'height':0}, 300, function(){
385
- tr.remove();
386
- update_order_numbers();
387
- });
388
- });
389
-
390
- return false;
391
-
392
- });
393
- }
394
-
395
-
396
-
397
-
398
  /*-------------------------------------------
399
  Document Ready
400
  -------------------------------------------*/
@@ -403,24 +191,17 @@
403
  post_id = $('form#post input#post_ID').val();
404
  var div = $('.postbox#acf_input');
405
 
406
- tinyMCE.settings.theme_advanced_buttons1 += ",|,add_image,add_video,add_audio,add_media";
407
- tinyMCE.settings.theme_advanced_buttons2 += ",code";
 
 
 
 
 
408
 
409
- // hide meta boxes
410
  div.hide_meta_boxes();
411
-
412
  div.make_all_fields();
413
 
414
- div.make_sortable();
415
-
416
- div.add_remove_buttons();
417
-
418
- // repeater
419
- div.find('.repeater').each(function(){
420
- $(this).make_acf_repeater();
421
- });
422
-
423
-
424
  });
425
 
426
  })(jQuery);
6
  // vars
7
  var wysiwyg_count = 0;
8
  var post_id = 0;
9
+
10
+ // global vars
11
+ window.acf_div = null;
12
 
13
 
14
  /*-------------------------------------------
97
  $.fn.make_acf_image = function(){
98
 
99
  var div = $(this);
 
100
 
101
  div.find('input.button').click(function(){
102
 
103
+ // set global var
104
+ window.acf_div = div;
105
+
106
 
107
  // show the thickbox
108
  tb_show('Add Image to field', 'media-upload.php?post_id='+post_id+'&type=image&acf_type=image&TB_iframe=1');
109
 
110
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  return false;
112
  });
113
 
128
  $.fn.make_acf_file = function(){
129
 
130
  var div = $(this);
131
+
132
 
133
  div.find('p.no_file input.button').click(function(){
134
 
135
+ // set global var
136
+ window.acf_div = div;
137
+
138
+
139
  // show the thickbox
140
  tb_show('Add File to field', 'media-upload.php?post_id='+post_id+'&type=file&acf_type=file&TB_iframe=1');
141
 
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  return false;
144
  });
145
 
156
 
157
 
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
  $.fn.make_all_fields = function()
161
  {
183
  }
184
 
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  /*-------------------------------------------
187
  Document Ready
188
  -------------------------------------------*/
191
  post_id = $('form#post input#post_ID').val();
192
  var div = $('.postbox#acf_input');
193
 
194
+
195
+ if(typeof(tinyMCE) != "undefined")
196
+ {
197
+ tinyMCE.settings.theme_advanced_buttons1 += ",|,add_image,add_video,add_audio,add_media";
198
+ tinyMCE.settings.theme_advanced_buttons2 += ",code";
199
+ }
200
+
201
 
 
202
  div.hide_meta_boxes();
 
203
  div.make_all_fields();
204
 
 
 
 
 
 
 
 
 
 
 
205
  });
206
 
207
  })(jQuery);
readme.txt CHANGED
@@ -80,6 +80,14 @@ http://support.plugins.elliotcondon.com/categories/advanced-custom-fields/
80
 
81
  == Changelog ==
82
 
 
 
 
 
 
 
 
 
83
  = 1.1.3 =
84
  * Image Field now uses WP thickbox!
85
  * File Field now uses WP thickbox!
80
 
81
  == Changelog ==
82
 
83
+ = 1.1.4 =
84
+ * Fixed Image / File upload issues
85
+ * Location now supports category names
86
+ * Improved API - now it doesn't need any custom fields!
87
+ * Fixed table encoding issue
88
+ * Small CSS / Field changes to ACF edit screen
89
+
90
+
91
  = 1.1.3 =
92
  * Image Field now uses WP thickbox!
93
  * File Field now uses WP thickbox!