Advanced Custom Fields: Extended - Version 0.8.7.2

Version Description

  • Module: AutoSync - Reworked codebase, enhanced Field Groups Columns and added more information about files/folders detection
  • Module: AutoSync - Added filters to target a specific field group for the PHP & Json save
  • Module: AutoSync - Fixed an issue where "Available Json Sync" wouldn't be visible if the field group was using PHP Sync
  • Module: Dynamic Forms - Fixed missing "Log User" icon in the Forms List screen
  • Module: Dynamic Forms - Added {current}, {get_field}, {get_option}, {query_var}, {request} mapping in the "Custom Form Render" setting
  • Module: Dynamic Forms - Added acfe-form to available post types in Polylang
  • Module: Dynamic Forms - Local Field Groups can now be mapped
  • Field Groups: Added Export PHP & Export Json to bulk actions
  • Field Groups: Description column is now hidden by default
  • Field Groups: Local - Added Export PHP, Export Json & Sync to database to bulk actions
  • Field Groups: Categories - Added acfe/modules/categories setting to disable the custom taxonomy
  • Field: Post Object - Fixed undefined PHP function when using the "Allow custom value" setting with ACF version below 5.8.10
  • Field: Columns - Fixed "Endpoint" description typo
  • General: Settings - Fixed postbox header CSS
  • General: Compatibility - Fixed Post Type Order plugin which automatically drag&drop on ACF Field Groups UI
  • General: Bumped minimum ACF Pro version to 5.8
Download this release

Release Info

Developer hwk-fr
Plugin Icon 128x128 Advanced Custom Fields: Extended
Version 0.8.7.2
Comparing to
See all releases

Code changes from version 0.8.7.1 to 0.8.7.2

acf-extended.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: Advanced Custom Fields: Extended
4
  * Description: Enhancement Suite which improves Advanced Custom Fields administration
5
- * Version: 0.8.7.1
6
  * Author: ACF Extended
7
  * Author URI: https://www.acf-extended.com
8
  * Text Domain: acfe
@@ -15,57 +15,30 @@ if(!class_exists('ACFE')):
15
 
16
  class ACFE{
17
 
18
- // Version
19
- var $version = '0.8.7.1';
20
-
21
- // Settings
22
- var $settings = array();
23
-
24
- // ACF
25
  var $acf = false;
26
 
27
- /**
28
- * ACFE: Construct
29
  */
30
  function __construct(){
31
  // ...
32
  }
33
 
34
- /**
35
- * ACFE: Initialize
36
  */
37
  function initialize(){
38
 
39
  // Constants
40
- $this->define('ACFE', true);
41
- $this->define('ACFE_FILE', __FILE__);
42
- $this->define('ACFE_PATH', plugin_dir_path(__FILE__));
43
- $this->define('ACFE_VERSION', $this->version);
44
- $this->define('ACFE_BASENAME', plugin_basename(__FILE__));
45
-
46
- // Settings
47
- $this->settings = array(
48
- 'url' => plugin_dir_url(__FILE__),
49
- 'theme_path' => get_stylesheet_directory(),
50
- 'theme_url' => get_stylesheet_directory_uri(),
51
- 'theme_folder' => false,
52
- 'php' => true,
53
- 'php_save' => false,
54
- 'php_load' => false,
55
- 'php_found' => false,
56
- 'json_found' => false,
57
- 'dev' => false,
58
- 'modules/author' => true,
59
- 'modules/dynamic_block_types' => true,
60
- 'modules/dynamic_forms' => true,
61
- 'modules/dynamic_options_pages' => true,
62
- 'modules/dynamic_post_types' => true,
63
- 'modules/dynamic_taxonomies' => true,
64
- 'modules/multilang' => true,
65
- 'modules/options' => true,
66
- 'modules/single_meta' => false,
67
- 'modules/ui' => true,
68
- );
69
 
70
  // Init
71
  include_once(ACFE_PATH . 'init.php');
@@ -75,42 +48,56 @@ class ACFE{
75
 
76
  }
77
 
78
- /**
79
- * ACFE: Load
80
  */
81
  function load(){
82
 
83
  if(!$this->has_acf())
84
  return;
85
 
 
 
 
 
86
  // Settings
87
- foreach($this->settings as $name => $value){
88
 
89
- // update
90
- acf_update_setting("acfe/{$name}", $value);
91
-
92
- // filter
93
- if(!has_filter("acfe/settings/{$name}"))
94
- continue;
95
-
96
- add_filter("acf/settings/acfe/{$name}", function($v) use($name){
97
-
98
- return apply_filters("acfe/settings/{$name}", $v);
99
-
100
- }, 5);
101
 
102
- }
103
-
104
- // Theme
105
- $theme_path = acf_get_setting('acfe/theme_path');
106
- $theme_url = acf_get_setting('acfe/theme_url');
107
-
108
- // Additional Settings
109
- acf_update_setting('acfe/php_save', "{$theme_path}/acfe-php");
110
- acf_update_setting('acfe/php_load', array("{$theme_path}/acfe-php"));
111
- acf_update_setting('acfe/theme_folder', parse_url($theme_url, PHP_URL_PATH));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
- // Load
114
  add_action('acf/init', array($this, 'includes'), 99);
115
 
116
  // AutoSync
@@ -131,25 +118,30 @@ class ACFE{
131
 
132
  }
133
 
134
- /**
135
- * ACFE: includes
136
  */
137
  function includes(){
138
 
139
- /**
 
 
 
 
 
140
  * Core
141
  */
142
  acfe_include('includes/core/enqueue.php');
143
  acfe_include('includes/core/menu.php');
144
 
145
- /**
146
  * Admin Pages
147
  */
148
  acfe_include('includes/admin/options.php');
149
  acfe_include('includes/admin/plugins.php');
150
  acfe_include('includes/admin/settings.php');
151
 
152
- /**
153
  * Fields
154
  */
155
  acfe_include('includes/fields/field-checkbox.php');
@@ -163,7 +155,7 @@ class ACFE{
163
  acfe_include('includes/fields/field-select.php');
164
  acfe_include('includes/fields/field-textarea.php');
165
 
166
- /**
167
  * Fields settings
168
  */
169
  acfe_include('includes/fields-settings/bidirectional.php');
@@ -173,7 +165,7 @@ class ACFE{
173
  acfe_include('includes/fields-settings/settings.php');
174
  acfe_include('includes/fields-settings/validation.php');
175
 
176
- /**
177
  * Field Groups
178
  */
179
  acfe_include('includes/field-groups/field-group.php');
@@ -181,7 +173,7 @@ class ACFE{
181
  acfe_include('includes/field-groups/field-groups.php');
182
  acfe_include('includes/field-groups/field-groups-local.php');
183
 
184
- /**
185
  * Locations
186
  */
187
  acfe_include('includes/locations/post-type-all.php');
@@ -189,7 +181,7 @@ class ACFE{
189
  acfe_include('includes/locations/post-type-list.php');
190
  acfe_include('includes/locations/taxonomy-list.php');
191
 
192
- /**
193
  * Modules
194
  */
195
  acfe_include('includes/modules/author.php');
@@ -206,8 +198,8 @@ class ACFE{
206
 
207
  }
208
 
209
- /**
210
- * ACFE: AutoSync
211
  */
212
  function autosync(){
213
 
@@ -215,8 +207,8 @@ class ACFE{
215
 
216
  }
217
 
218
- /**
219
- * ACFE: Fields
220
  */
221
  function fields(){
222
 
@@ -237,8 +229,8 @@ class ACFE{
237
 
238
  }
239
 
240
- /**
241
- * ACFE: Tools
242
  */
243
  function tools(){
244
 
@@ -258,28 +250,49 @@ class ACFE{
258
 
259
  }
260
 
261
- /**
262
- * ACFE: Define
263
- *
264
- * @param $name
265
- * @param bool $value
 
 
 
 
 
 
 
 
 
 
 
266
  */
267
- function define($name, $value = true){
268
 
269
- if(!defined($name))
270
- define($name, $value);
 
 
 
 
 
 
 
 
 
 
271
 
272
  }
273
 
274
- /**
275
- * ACFE: Has ACF
276
  */
277
  function has_acf(){
278
 
279
  if($this->acf)
280
  return true;
281
 
282
- $this->acf = class_exists('ACF') && defined('ACF_PRO') && defined('ACF_VERSION') && version_compare(ACF_VERSION, '5.7.10', '>=');
283
 
284
  return $this->acf;
285
 
@@ -287,7 +300,6 @@ class ACFE{
287
 
288
  }
289
 
290
-
291
  function acfe(){
292
 
293
  global $acfe;
@@ -303,7 +315,6 @@ function acfe(){
303
 
304
  }
305
 
306
- // Instantiate.
307
  acfe();
308
 
309
  endif;
2
  /**
3
  * Plugin Name: Advanced Custom Fields: Extended
4
  * Description: Enhancement Suite which improves Advanced Custom Fields administration
5
+ * Version: 0.8.7.2
6
  * Author: ACF Extended
7
  * Author URI: https://www.acf-extended.com
8
  * Text Domain: acfe
15
 
16
  class ACFE{
17
 
18
+ // Vars
19
+ var $version = '0.8.7.2';
 
 
 
 
 
20
  var $acf = false;
21
 
22
+ /*
23
+ * Construct
24
  */
25
  function __construct(){
26
  // ...
27
  }
28
 
29
+ /*
30
+ * Initialize
31
  */
32
  function initialize(){
33
 
34
  // Constants
35
+ $this->constants(array(
36
+ 'ACFE' => true,
37
+ 'ACFE_FILE' => __FILE__,
38
+ 'ACFE_PATH' => plugin_dir_path(__FILE__),
39
+ 'ACFE_VERSION' => $this->version,
40
+ 'ACFE_BASENAME' => plugin_basename(__FILE__),
41
+ ));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  // Init
44
  include_once(ACFE_PATH . 'init.php');
48
 
49
  }
50
 
51
+ /*
52
+ * Load
53
  */
54
  function load(){
55
 
56
  if(!$this->has_acf())
57
  return;
58
 
59
+ // Vars
60
+ $theme_path = acf_get_setting('acfe/theme_path', get_stylesheet_directory());
61
+ $theme_url = acf_get_setting('acfe/theme_url', get_stylesheet_directory_uri());
62
+
63
  // Settings
64
+ $this->settings(array(
65
 
66
+ // General
67
+ 'url' => plugin_dir_url(__FILE__),
68
+ 'theme_path' => $theme_path,
69
+ 'theme_url' => $theme_url,
70
+ 'theme_folder' => parse_url($theme_url, PHP_URL_PATH),
 
 
 
 
 
 
 
71
 
72
+ // Php
73
+ 'php' => true,
74
+ 'php_save' => "{$theme_path}/acfe-php",
75
+ 'php_load' => array("{$theme_path}/acfe-php"),
76
+ 'php_found' => false,
77
+
78
+ // Json
79
+ 'json' => acf_get_setting('json'),
80
+ 'json_save' => acf_get_setting('save_json'),
81
+ 'json_load' => acf_get_setting('load_json'),
82
+ 'json_found' => false,
83
+
84
+ // Modules
85
+ 'dev' => false,
86
+ 'modules/author' => true,
87
+ 'modules/categories' => true,
88
+ 'modules/dynamic_block_types' => true,
89
+ 'modules/dynamic_forms' => true,
90
+ 'modules/dynamic_options_pages' => true,
91
+ 'modules/dynamic_post_types' => true,
92
+ 'modules/dynamic_taxonomies' => true,
93
+ 'modules/multilang' => true,
94
+ 'modules/options' => true,
95
+ 'modules/single_meta' => false,
96
+ 'modules/ui' => true,
97
+
98
+ ));
99
 
100
+ // Includes
101
  add_action('acf/init', array($this, 'includes'), 99);
102
 
103
  // AutoSync
118
 
119
  }
120
 
121
+ /*
122
+ * Includes
123
  */
124
  function includes(){
125
 
126
+ /*
127
+ * Action
128
+ */
129
+ do_action('acfe/init');
130
+
131
+ /*
132
  * Core
133
  */
134
  acfe_include('includes/core/enqueue.php');
135
  acfe_include('includes/core/menu.php');
136
 
137
+ /*
138
  * Admin Pages
139
  */
140
  acfe_include('includes/admin/options.php');
141
  acfe_include('includes/admin/plugins.php');
142
  acfe_include('includes/admin/settings.php');
143
 
144
+ /*
145
  * Fields
146
  */
147
  acfe_include('includes/fields/field-checkbox.php');
155
  acfe_include('includes/fields/field-select.php');
156
  acfe_include('includes/fields/field-textarea.php');
157
 
158
+ /*
159
  * Fields settings
160
  */
161
  acfe_include('includes/fields-settings/bidirectional.php');
165
  acfe_include('includes/fields-settings/settings.php');
166
  acfe_include('includes/fields-settings/validation.php');
167
 
168
+ /*
169
  * Field Groups
170
  */
171
  acfe_include('includes/field-groups/field-group.php');
173
  acfe_include('includes/field-groups/field-groups.php');
174
  acfe_include('includes/field-groups/field-groups-local.php');
175
 
176
+ /*
177
  * Locations
178
  */
179
  acfe_include('includes/locations/post-type-all.php');
181
  acfe_include('includes/locations/post-type-list.php');
182
  acfe_include('includes/locations/taxonomy-list.php');
183
 
184
+ /*
185
  * Modules
186
  */
187
  acfe_include('includes/modules/author.php');
198
 
199
  }
200
 
201
+ /*
202
+ * AutoSync
203
  */
204
  function autosync(){
205
 
207
 
208
  }
209
 
210
+ /*
211
+ * Fields
212
  */
213
  function fields(){
214
 
229
 
230
  }
231
 
232
+ /*
233
+ * Tools
234
  */
235
  function tools(){
236
 
250
 
251
  }
252
 
253
+ /*
254
+ * Set Constants
255
+ */
256
+ function constants($array = array()){
257
+
258
+ foreach($array as $name => $value){
259
+
260
+ if(!defined($name))
261
+ define($name, $value);
262
+
263
+ }
264
+
265
+ }
266
+
267
+ /*
268
+ * Set Settings
269
  */
270
+ function settings($array = array()){
271
 
272
+ foreach($array as $name => $value){
273
+
274
+ // update
275
+ acf_update_setting("acfe/{$name}", $value);
276
+
277
+ add_filter("acf/settings/acfe/{$name}", function($value) use($name){
278
+
279
+ return apply_filters("acfe/settings/{$name}", $value);
280
+
281
+ }, 5);
282
+
283
+ }
284
 
285
  }
286
 
287
+ /*
288
+ * Has ACF
289
  */
290
  function has_acf(){
291
 
292
  if($this->acf)
293
  return true;
294
 
295
+ $this->acf = class_exists('ACF') && defined('ACF_PRO') && defined('ACF_VERSION') && version_compare(ACF_VERSION, '5.8', '>=');
296
 
297
  return $this->acf;
298
 
300
 
301
  }
302
 
 
303
  function acfe(){
304
 
305
  global $acfe;
315
 
316
  }
317
 
 
318
  acfe();
319
 
320
  endif;
assets/acf-extended-admin.css CHANGED
@@ -469,8 +469,9 @@ body.post-type-acfe-form.post-new-php #major-publishing-actions{
469
  padding: 1px 5px;
470
  border-radius: 4px;
471
  color: #fff;
472
- margin-left: 3px;
473
  font-size: 12px;
 
474
  }
475
 
476
  /*
469
  padding: 1px 5px;
470
  border-radius: 4px;
471
  color: #fff;
472
+ margin-left: 7px;
473
  font-size: 12px;
474
+ margin-right:auto;
475
  }
476
 
477
  /*
assets/acf-extended-fg.css CHANGED
@@ -114,6 +114,15 @@ body:not(.acf-admin-5-3) .acf-repeater.-block > table > tbody > tr > td:last-of-
114
  width:auto !important;
115
  }
116
 
 
 
 
 
 
 
 
 
 
117
  .column-acf-field-group-category{
118
  width:125px;
119
  }
@@ -127,10 +136,15 @@ td.acf-field-group-category a{
127
  color:#23282d;
128
  }
129
 
130
- .column-acfe-locations{
131
  width:100px;
132
  }
133
 
 
 
 
 
 
134
  #acf-field-group-wrap .wp-list-table .column-acf-fg-status{
135
  width:70px;
136
  }
@@ -144,7 +158,12 @@ td.acf-field-group-category a{
144
  color:#a0a5aa;
145
  }
146
 
147
- .column-acfe-local{
 
 
 
 
 
148
  width:70px;
149
  }
150
 
@@ -155,13 +174,48 @@ td.acf-field-group-category a{
155
  .column-acfe-autosync-php,
156
  .column-acfe-autosync-json{
157
  width:90px;
158
- text-align:center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  }
160
 
161
  .acf-field-image[data-name="acfe_flexible_thumbnail"] > .acf-input > .acf-image-uploader.has-value > .show-if-value.image-wrap{
162
  max-width:85px !important;
163
  }
164
 
 
 
 
 
 
 
 
165
  /*
166
  * ACFE: Flexible Content
167
  *
114
  width:auto !important;
115
  }
116
 
117
+ .status-acf-disabled .column-title a,
118
+ .status-acf-disabled .column-title code {
119
+ color: #555 !important;
120
+ }
121
+
122
+ .status-acf-disabled .column-title strong{
123
+ color: #a0a5aa;
124
+ }
125
+
126
  .column-acf-field-group-category{
127
  width:125px;
128
  }
136
  color:#23282d;
137
  }
138
 
139
+ .column-acfe-location{
140
  width:100px;
141
  }
142
 
143
+ .column-acf-location,
144
+ .column-acf-description{
145
+ width:230px;
146
+ }
147
+
148
  #acf-field-group-wrap .wp-list-table .column-acf-fg-status{
149
  width:70px;
150
  }
158
  color:#a0a5aa;
159
  }
160
 
161
+ .column-title .acfe-key{
162
+ color:#555;
163
+ font-size:12px;
164
+ }
165
+
166
+ .column-acfe-load{
167
  width:70px;
168
  }
169
 
174
  .column-acfe-autosync-php,
175
  .column-acfe-autosync-json{
176
  width:90px;
177
+ text-align:center !important;
178
+ }
179
+
180
+ .column-acfe-autosync-php .secondary,
181
+ .column-acfe-autosync-json .secondary{
182
+ color:#ccc;
183
+ }
184
+
185
+ .column-acfe-autosync-php .dashicons-warning,
186
+ .column-acfe-autosync-json .dashicons-warning{
187
+ font-size:15px;
188
+ vertical-align:middle;
189
+ }
190
+
191
+ .acf-field[data-name="acfe_autosync"] .dashicons-warning{
192
+ color:#ccc;
193
+ font-size:15px;
194
+ height: 15px;
195
+ vertical-align: text-bottom;
196
+ }
197
+
198
+ .column-acfe-autosync-php .dashicons-update,
199
+ .column-acfe-autosync-json .dashicons-update{
200
+ font-size:18px;
201
+ }
202
+
203
+ .column-acfe-autosync-php .dashicons + .dashicons-warning,
204
+ .column-acfe-autosync-json .dashicons + .dashicons-warning{
205
+ margin-left:-3px;
206
  }
207
 
208
  .acf-field-image[data-name="acfe_flexible_thumbnail"] > .acf-input > .acf-image-uploader.has-value > .show-if-value.image-wrap{
209
  max-width:85px !important;
210
  }
211
 
212
+ /*
213
+ * Fix Sync Review Modal column size
214
+ */
215
+ .acf-diff-content table.diff tbody tr td:nth-child(2){
216
+ width: auto;
217
+ }
218
+
219
  /*
220
  * ACFE: Flexible Content
221
  *
includes/admin/settings.php CHANGED
@@ -26,7 +26,9 @@ function acfe_admin_settings_html(){
26
  <div id="poststuff">
27
 
28
  <div class="postbox acf-postbox">
29
- <h2 class="hndle ui-sortable-handle"><span><?php _e('Settings'); ?></span></h2>
 
 
30
  <div class="inside acf-fields -left">
31
 
32
  <?php
@@ -37,12 +39,6 @@ function acfe_admin_settings_html(){
37
  ?>
38
 
39
  <?php
40
-
41
- $load_json = acf_get_setting('load_json');
42
- $load_json_text = '';
43
-
44
- if(!empty($load_json))
45
- $load_json_text = implode("<br />", $load_json);
46
 
47
  $settings = array(
48
  array(
@@ -90,7 +86,7 @@ function acfe_admin_settings_html(){
90
  array(
91
  'name' => 'load_json',
92
  'label' => 'Json folder (load)',
93
- 'value' => '<code>' . $load_json_text . '</code>',
94
  'description' => 'Array of absolutes paths to folders where field group json files can be read.<br />Defaults to an array containing at index 0, the ‘acf-json’ folder within current theme'
95
  ),
96
  array(
@@ -238,19 +234,21 @@ function acfe_admin_settings_html(){
238
 
239
  <?php
240
 
241
- $load_php = acf_get_setting('acfe/php_load');
242
- $load_php_text = '';
243
-
244
- if(!empty($load_php))
245
- $load_php_text = implode("<br />", $load_php);
246
-
247
  $settings = array(
 
 
248
  array(
249
  'name' => 'acfe/modules/author',
250
  'label' => 'Module: Author',
251
  'value' => '<code>' . (acf_get_setting('acfe/modules/author', true) ? __('True'): __('False')) . '</code>',
252
  'description' => 'Show/hide the Author module. Defaults to true'
253
  ),
 
 
 
 
 
 
254
  array(
255
  'name' => 'acfe/modules/dynamic_block_types',
256
  'label' => 'Module: Dynamic Block Types',
@@ -305,6 +303,8 @@ function acfe_admin_settings_html(){
305
  'value' => '<code>' . (acf_get_setting('acfe/modules/ui', true) ? __('True'): __('False')) . '</code>',
306
  'description' => 'Show/hide the UI enhancements module. Defaults to true'
307
  ),
 
 
308
  array(
309
  'name' => 'acfe/field/recaptcha/site_key',
310
  'label' => 'Field: reCaptcha site key',
@@ -347,6 +347,8 @@ function acfe_admin_settings_html(){
347
  'value' => '<code>' . (acf_get_setting('acfe/dev') ? __('True'): __('False')) . '</code>',
348
  'description' => 'Show/hide the advanced WP post meta box. Defaults to false'
349
  ),
 
 
350
  array(
351
  'name' => 'acfe/php',
352
  'label' => 'PHP',
@@ -368,15 +370,37 @@ function acfe_admin_settings_html(){
368
  array(
369
  'name' => 'acfe/php_load',
370
  'label' => 'PHP: Load',
371
- 'value' => '<code>' . $load_php_text . '</code>',
372
  'description' => 'PHP AutoSync loading path'
373
  ),
 
 
 
 
 
 
 
 
374
  array(
375
  'name' => 'acfe/json_found',
376
  'label' => 'Json: Found',
377
  'value' => '<code>' . (acf_get_setting('acfe/json_found') ? __('True'): __('False')) . '</code>',
378
- 'description' => 'Whenever Json Sync folder has been found, based on load_json setting'
 
 
 
 
 
 
 
 
 
 
 
 
379
  ),
 
 
380
  array(
381
  'name' => 'acfe/theme_path',
382
  'label' => 'Theme: Path',
26
  <div id="poststuff">
27
 
28
  <div class="postbox acf-postbox">
29
+ <div class="postbox-header">
30
+ <h2 class="hndle ui-sortable-handle"><span><?php _e('Settings'); ?></span></h2>
31
+ </div>
32
  <div class="inside acf-fields -left">
33
 
34
  <?php
39
  ?>
40
 
41
  <?php
 
 
 
 
 
 
42
 
43
  $settings = array(
44
  array(
86
  array(
87
  'name' => 'load_json',
88
  'label' => 'Json folder (load)',
89
+ 'value' => '<code>' . implode("<br />", (array) acf_get_setting('load_json')) . '</code>',
90
  'description' => 'Array of absolutes paths to folders where field group json files can be read.<br />Defaults to an array containing at index 0, the ‘acf-json’ folder within current theme'
91
  ),
92
  array(
234
 
235
  <?php
236
 
 
 
 
 
 
 
237
  $settings = array(
238
+
239
+ // Modules
240
  array(
241
  'name' => 'acfe/modules/author',
242
  'label' => 'Module: Author',
243
  'value' => '<code>' . (acf_get_setting('acfe/modules/author', true) ? __('True'): __('False')) . '</code>',
244
  'description' => 'Show/hide the Author module. Defaults to true'
245
  ),
246
+ array(
247
+ 'name' => 'acfe/modules/categories',
248
+ 'label' => 'Module: Categories',
249
+ 'value' => '<code>' . (acf_get_setting('acfe/modules/categories', true) ? __('True'): __('False')) . '</code>',
250
+ 'description' => 'Enable/disable the Field Group Categories taxonomy. Defaults to true'
251
+ ),
252
  array(
253
  'name' => 'acfe/modules/dynamic_block_types',
254
  'label' => 'Module: Dynamic Block Types',
303
  'value' => '<code>' . (acf_get_setting('acfe/modules/ui', true) ? __('True'): __('False')) . '</code>',
304
  'description' => 'Show/hide the UI enhancements module. Defaults to true'
305
  ),
306
+
307
+ // Recaptcha
308
  array(
309
  'name' => 'acfe/field/recaptcha/site_key',
310
  'label' => 'Field: reCaptcha site key',
347
  'value' => '<code>' . (acf_get_setting('acfe/dev') ? __('True'): __('False')) . '</code>',
348
  'description' => 'Show/hide the advanced WP post meta box. Defaults to false'
349
  ),
350
+
351
+ // PHP
352
  array(
353
  'name' => 'acfe/php',
354
  'label' => 'PHP',
370
  array(
371
  'name' => 'acfe/php_load',
372
  'label' => 'PHP: Load',
373
+ 'value' => '<code>' . implode("<br />", (array) acf_get_setting('acfe/php_load')) . '</code>',
374
  'description' => 'PHP AutoSync loading path'
375
  ),
376
+
377
+ // Json
378
+ array(
379
+ 'name' => 'acfe/json',
380
+ 'label' => 'Json',
381
+ 'value' => '<code>' . (acf_get_setting('acfe/json') ? __('True'): __('False')) . '</code>',
382
+ 'description' => 'Whenever Json AutoSync is enabled'
383
+ ),
384
  array(
385
  'name' => 'acfe/json_found',
386
  'label' => 'Json: Found',
387
  'value' => '<code>' . (acf_get_setting('acfe/json_found') ? __('True'): __('False')) . '</code>',
388
+ 'description' => 'Whenever Json AutoSync folder has been found, based on acfe/json_load setting'
389
+ ),
390
+ array(
391
+ 'name' => 'acfe/json_save',
392
+ 'label' => 'Json: Save',
393
+ 'value' => '<code>' . acf_get_setting('acfe/json_save') . '</code>',
394
+ 'description' => 'Json AutoSync saving path'
395
+ ),
396
+ array(
397
+ 'name' => 'acfe/json_load',
398
+ 'label' => 'Json: Load',
399
+ 'value' => '<code>' . implode("<br />", (array) acf_get_setting('acfe/json_load')) . '</code>',
400
+ 'description' => 'Json AutoSync loading paths'
401
  ),
402
+
403
+ // Theme
404
  array(
405
  'name' => 'acfe/theme_path',
406
  'label' => 'Theme: Path',
includes/admin/tools/fg-local.php CHANGED
@@ -20,7 +20,7 @@ class ACFE_Admin_Tool_FG_Local extends ACF_Admin_Tool{
20
 
21
  if($ids = acf_maybe_get_GET('acfe-fg-local-sync')){
22
 
23
- $ids = explode('+', $ids);
24
 
25
  // Count number of imported field groups.
26
  $total = count($ids);
@@ -76,23 +76,23 @@ class ACFE_Admin_Tool_FG_Local extends ACF_Admin_Tool{
76
  // Sync
77
  elseif($action === 'sync'){
78
 
79
- if(isset($array['key']))
80
- $array = array($array);
81
 
82
  // Remeber imported field group ids.
83
  $ids = array();
84
 
85
  // Loop over json
86
- foreach( $array as $field_group ) {
87
 
88
  // Search database for existing field group.
89
- $post = acf_get_field_group_post( $field_group['key'] );
90
- if( $post ) {
 
91
  $field_group['ID'] = $post->ID;
92
- }
93
 
94
  // Import field group.
95
- $field_group = acf_import_field_group( $field_group );
96
 
97
  // append message
98
  $ids[] = $field_group['ID'];
@@ -260,6 +260,15 @@ class ACFE_Admin_Tool_FG_Local extends ACF_Admin_Tool{
260
  // Disable fitler: clone
261
  acf_disable_filter('clone');
262
 
 
 
 
 
 
 
 
 
 
263
  foreach($selected as $field_group_key){
264
 
265
  $field_group = acf_get_field_group($field_group_key);
20
 
21
  if($ids = acf_maybe_get_GET('acfe-fg-local-sync')){
22
 
23
+ $ids = explode(' ', $ids);
24
 
25
  // Count number of imported field groups.
26
  $total = count($ids);
76
  // Sync
77
  elseif($action === 'sync'){
78
 
79
+ // Force array
80
+ $array = acf_array($array);
81
 
82
  // Remeber imported field group ids.
83
  $ids = array();
84
 
85
  // Loop over json
86
+ foreach($array as $field_group){
87
 
88
  // Search database for existing field group.
89
+ $post = acf_get_field_group_post($field_group['key']);
90
+
91
+ if($post)
92
  $field_group['ID'] = $post->ID;
 
93
 
94
  // Import field group.
95
+ $field_group = acf_import_field_group($field_group);
96
 
97
  // append message
98
  $ids[] = $field_group['ID'];
260
  // Disable fitler: clone
261
  acf_disable_filter('clone');
262
 
263
+ // Get desync PHP Field Groups
264
+ $desync_php_field_groups = acfe_get_desync_php_field_groups();
265
+
266
+ foreach($desync_php_field_groups as $file_key => $file_path){
267
+
268
+ require_once($file_path);
269
+
270
+ }
271
+
272
  foreach($selected as $field_group_key){
273
 
274
  $field_group = acf_get_field_group($field_group_key);
includes/core/compatibility.php CHANGED
@@ -15,57 +15,59 @@ class acfe_compatibility{
15
 
16
  function init(){
17
 
18
- /**
19
- * ACF Extended: 0.8.6.3
20
- * Settings: Renamed 'acfe/modules/taxonomies' to 'acfe/modules/ui'
21
- */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  if(acf_get_setting('acfe/modules/taxonomies') !== null){
23
  acf_update_setting('acfe/modules/ui', acf_get_setting('acfe/modules/taxonomies'));
24
  }
25
 
26
- /**
27
- * ACF Extended: 0.8
28
- * Settings: Renamed 'acfe_php*' to 'acfe/php*'
29
- */
30
  if(acf_get_setting('acfe_php') !== null){
31
  acf_update_setting('acfe/php', acf_get_setting('acfe_php'));
32
  }
33
-
34
  if(acf_get_setting('php_save') !== null){
35
  acf_update_setting('acfe/php_save', acf_get_setting('php_save'));
36
  }
37
-
38
  if(acf_get_setting('php_load') !== null){
39
  acf_update_setting('acfe/php_load', acf_get_setting('php_load'));
40
  }
41
-
42
  if(acf_get_setting('php_found') !== null){
43
  acf_update_setting('acfe/php_found', acf_get_setting('php_found'));
44
  }
45
-
46
- add_filter('acf/validate_field_group', array($this, 'field_group_location_list'), 20);
47
- add_filter('acf/validate_field', array($this, 'field_acfe_update'), 20);
48
-
49
- add_filter('acf/validate_field/type=group', array($this, 'field_seamless_style'), 20);
50
- add_filter('acf/validate_field/type=clone', array($this, 'field_seamless_style'), 20);
51
- add_filter('acfe/load_fields/type=flexible_content', array($this, 'field_flexible_settings_title'), 20, 2);
52
-
53
- add_filter('acf/prepare_field/name=acfe_flexible_category', array($this, 'field_flexible_layout_categories'), 10, 2);
54
-
55
- add_filter('pto/posts_orderby/ignore', array($this, 'pto_acf_field_group'), 10, 3);
56
- add_action('admin_menu', array($this, 'cotto_submenu'), 999);
57
- add_filter('rank_math/metabox/priority', array($this, 'rankmath_metaboxes_priority'));
58
- add_filter('wpseo_metabox_prio', array($this, 'yoast_metaboxes_priority'));
59
-
60
  }
61
 
62
  /**
63
  * ACF Extended: 0.8
64
  * Field Group Location: Archive renamed to List
65
- *
66
- * @param $field_group
67
- *
68
- * @return mixed
69
  */
70
  function field_group_location_list($field_group){
71
 
@@ -106,10 +108,6 @@ class acfe_compatibility{
106
  /**
107
  * ACF Extended: 0.8
108
  * Field Filter Value: Removed from this version
109
- *
110
- * @param $field
111
- *
112
- * @return mixed
113
  */
114
  function field_acfe_update($field){
115
 
@@ -125,10 +123,6 @@ class acfe_compatibility{
125
  /**
126
  * ACF Extended: 0.8.5
127
  * Field Group/Clone: Fixed typo "Seamless"
128
- *
129
- * @param $field
130
- *
131
- * @return mixed
132
  */
133
  function field_seamless_style($field){
134
 
@@ -145,11 +139,6 @@ class acfe_compatibility{
145
  /**
146
  * ACF Extended: 0.8.4.5
147
  * Field Flexible Content: Fix duplicated "layout_settings" & "layout_title"
148
- *
149
- * @param $fields
150
- * @param $parent
151
- *
152
- * @return mixed
153
  */
154
  function field_flexible_settings_title($fields, $parent){
155
 
@@ -211,13 +200,7 @@ class acfe_compatibility{
211
  /**
212
  * Plugin: Post Types Order
213
  * https://wordpress.org/plugins/post-types-order/
214
- * The plugin apply custom order to 'acf-field-group' Post Type. We have to fix this
215
- *
216
- * @param $ignore
217
- * @param $orderby
218
- * @param $query
219
- *
220
- * @return bool
221
  */
222
  function pto_acf_field_group($ignore, $orderby, $query){
223
 
@@ -228,6 +211,19 @@ class acfe_compatibility{
228
 
229
  }
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  /**
232
  * Plugin: Category Order and Taxonomy Terms Order
233
  * https://wordpress.org/plugins/taxonomy-terms-order/
@@ -261,6 +257,27 @@ class acfe_compatibility{
261
 
262
  }
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  }
265
 
266
  new acfe_compatibility();
15
 
16
  function init(){
17
 
18
+ $this->update_settings();
19
+
20
+ add_filter('acf/validate_field_group', array($this, 'field_group_location_list'), 20);
21
+ add_filter('acf/validate_field', array($this, 'field_acfe_update'), 20);
22
+
23
+ add_filter('acf/validate_field/type=group', array($this, 'field_seamless_style'), 20);
24
+ add_filter('acf/validate_field/type=clone', array($this, 'field_seamless_style'), 20);
25
+ add_filter('acfe/load_fields/type=flexible_content', array($this, 'field_flexible_settings_title'), 20, 2);
26
+
27
+ add_filter('acf/prepare_field/name=acfe_flexible_category', array($this, 'field_flexible_layout_categories'), 10, 2);
28
+
29
+ add_filter('pto/posts_orderby/ignore', array($this, 'pto_acf_field_group'), 10, 3);
30
+ add_filter('pto/get_options', array($this, 'pto_options_acf_field_group'));
31
+
32
+ add_action('admin_menu', array($this, 'cotto_submenu'), 999);
33
+ add_filter('rank_math/metabox/priority', array($this, 'rankmath_metaboxes_priority'));
34
+ add_filter('wpseo_metabox_prio', array($this, 'yoast_metaboxes_priority'));
35
+ add_filter('pll_get_post_types', array($this, 'polylang'), 10, 2 );
36
+
37
+ }
38
+
39
+ /**
40
+ * ACF Extended: Settings
41
+ */
42
+ function update_settings(){
43
+
44
+ // ACF Extended: 0.8.6.3 - Renamed 'acfe/modules/taxonomies' to 'acfe/modules/ui'
45
  if(acf_get_setting('acfe/modules/taxonomies') !== null){
46
  acf_update_setting('acfe/modules/ui', acf_get_setting('acfe/modules/taxonomies'));
47
  }
48
 
49
+ // ACF Extended: 0.8 - Renamed 'acfe_php*' to 'acfe/php*'
 
 
 
50
  if(acf_get_setting('acfe_php') !== null){
51
  acf_update_setting('acfe/php', acf_get_setting('acfe_php'));
52
  }
53
+
54
  if(acf_get_setting('php_save') !== null){
55
  acf_update_setting('acfe/php_save', acf_get_setting('php_save'));
56
  }
57
+
58
  if(acf_get_setting('php_load') !== null){
59
  acf_update_setting('acfe/php_load', acf_get_setting('php_load'));
60
  }
61
+
62
  if(acf_get_setting('php_found') !== null){
63
  acf_update_setting('acfe/php_found', acf_get_setting('php_found'));
64
  }
65
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  }
67
 
68
  /**
69
  * ACF Extended: 0.8
70
  * Field Group Location: Archive renamed to List
 
 
 
 
71
  */
72
  function field_group_location_list($field_group){
73
 
108
  /**
109
  * ACF Extended: 0.8
110
  * Field Filter Value: Removed from this version
 
 
 
 
111
  */
112
  function field_acfe_update($field){
113
 
123
  /**
124
  * ACF Extended: 0.8.5
125
  * Field Group/Clone: Fixed typo "Seamless"
 
 
 
 
126
  */
127
  function field_seamless_style($field){
128
 
139
  /**
140
  * ACF Extended: 0.8.4.5
141
  * Field Flexible Content: Fix duplicated "layout_settings" & "layout_title"
 
 
 
 
 
142
  */
143
  function field_flexible_settings_title($fields, $parent){
144
 
200
  /**
201
  * Plugin: Post Types Order
202
  * https://wordpress.org/plugins/post-types-order/
203
+ * The plugin apply custom order to ACF Field Group Post Type. We have to fix this
 
 
 
 
 
 
204
  */
205
  function pto_acf_field_group($ignore, $orderby, $query){
206
 
211
 
212
  }
213
 
214
+ /**
215
+ * Plugin: Post Types Order
216
+ * https://wordpress.org/plugins/post-types-order/
217
+ * The plugin apply a drag & drop UI on ACF Field Group UI. We have to fix this
218
+ */
219
+ function pto_options_acf_field_group($options){
220
+
221
+ $options['show_reorder_interfaces']['acf-field-group'] = 'hide';
222
+
223
+ return $options;
224
+
225
+ }
226
+
227
  /**
228
  * Plugin: Category Order and Taxonomy Terms Order
229
  * https://wordpress.org/plugins/taxonomy-terms-order/
257
 
258
  }
259
 
260
+ /**
261
+ * ACF Extended: 0.8.3
262
+ * Modules: Enable PolyLang Translation for ACFE Form Module
263
+ * https://polylang.pro/doc/filter-reference/
264
+ */
265
+ function polylang($post_types, $is_settings){
266
+
267
+ if($is_settings){
268
+
269
+ unset($post_types['acfe-form']);
270
+
271
+ }else{
272
+
273
+ $post_types['acfe-form'] = 'acfe-form';
274
+
275
+ }
276
+
277
+ return $post_types;
278
+
279
+ }
280
+
281
  }
282
 
283
  new acfe_compatibility();
includes/core/helpers.php CHANGED
@@ -723,7 +723,6 @@ function acfe_get_abs_path_to_url($path = ''){
723
  */
724
  function acfe_get_roles($filtered_user_roles = array()){
725
 
726
-
727
  $list = array();
728
 
729
  global $wp_roles;
@@ -1062,8 +1061,6 @@ function acfe_add_validation_error($selector = '', $message = ''){
1062
 
1063
  }
1064
 
1065
-
1066
-
1067
  // Field not found: General error
1068
  if(!$field)
1069
  return acf_add_validation_error('', $message);
@@ -1095,40 +1092,37 @@ function acfe_get_taxonomy_terms_ids($taxonomies = array()){
1095
  foreach( array_keys($taxonomies) as $taxonomy ) {
1096
 
1097
  // vars
1098
- $label = $taxonomies[ $taxonomy ];
1099
  $is_hierarchical = is_taxonomy_hierarchical( $taxonomy );
 
1100
  $terms = acf_get_terms(array(
1101
  'taxonomy' => $taxonomy,
1102
  'hide_empty' => false
1103
  ));
1104
 
1105
-
1106
- // bail early i no terms
1107
- if( empty($terms) ) continue;
1108
-
1109
 
1110
  // sort into hierachial order!
1111
- if( $is_hierarchical ) {
1112
 
1113
  $terms = _get_term_children( 0, $terms, $taxonomy );
1114
 
1115
  }
1116
 
1117
-
1118
  // add placeholder
1119
  $r[ $label ] = array();
1120
 
1121
-
1122
  // add choices
1123
- foreach( $terms as $term ) {
1124
 
1125
  $k = "{$term->term_id}";
1126
- $r[ $label ][ $k ] = acf_get_term_title( $term );
1127
 
1128
  }
1129
 
1130
  }
1131
-
1132
 
1133
  // return
1134
  return $r;
@@ -1260,34 +1254,19 @@ function acfe_is_super_dev(){
1260
 
1261
  function acfe_update_setting($name, $value){
1262
 
1263
- $name = "acfe/{$name}";
1264
-
1265
- return acf_update_setting($name, $value);
1266
 
1267
  }
1268
 
1269
- function acfe_get_setting($name, $value = null){
1270
-
1271
- $_name = $name;
1272
- $name = "acfe/{$name}";
1273
-
1274
- // validate name
1275
- $name = acf_validate_setting($name);
1276
-
1277
- // check settings
1278
- if(acf_has_setting($name)){
1279
-
1280
- $value = acf_raw_setting($name);
1281
-
1282
- }
1283
 
1284
- // ACF filter
1285
- $value = apply_filters("acf/settings/{$name}", $value);
1286
 
1287
- // ACFE filter
1288
- $value = apply_filters("acfe/settings/{$_name}", $value);
 
1289
 
1290
- return $value;
1291
 
1292
  }
1293
 
@@ -1477,4 +1456,17 @@ function acfe_render_field_group_locations_html($field_group){
1477
 
1478
  }
1479
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1480
  }
723
  */
724
  function acfe_get_roles($filtered_user_roles = array()){
725
 
 
726
  $list = array();
727
 
728
  global $wp_roles;
1061
 
1062
  }
1063
 
 
 
1064
  // Field not found: General error
1065
  if(!$field)
1066
  return acf_add_validation_error('', $message);
1092
  foreach( array_keys($taxonomies) as $taxonomy ) {
1093
 
1094
  // vars
1095
+ $label = $taxonomies[$taxonomy];
1096
  $is_hierarchical = is_taxonomy_hierarchical( $taxonomy );
1097
+
1098
  $terms = acf_get_terms(array(
1099
  'taxonomy' => $taxonomy,
1100
  'hide_empty' => false
1101
  ));
1102
 
1103
+ // bail early if no terms
1104
+ if(empty($terms))
1105
+ continue;
 
1106
 
1107
  // sort into hierachial order!
1108
+ if($is_hierarchical){
1109
 
1110
  $terms = _get_term_children( 0, $terms, $taxonomy );
1111
 
1112
  }
1113
 
 
1114
  // add placeholder
1115
  $r[ $label ] = array();
1116
 
 
1117
  // add choices
1118
+ foreach($terms as $term){
1119
 
1120
  $k = "{$term->term_id}";
1121
+ $r[$label][$k] = acf_get_term_title($term);
1122
 
1123
  }
1124
 
1125
  }
 
1126
 
1127
  // return
1128
  return $r;
1254
 
1255
  function acfe_update_setting($name, $value){
1256
 
1257
+ return acf_update_setting("acfe/{$name}", $value);
 
 
1258
 
1259
  }
1260
 
1261
+ function acfe_append_setting($name, $value){
 
 
 
 
 
 
 
 
 
 
 
 
 
1262
 
1263
+ return acf_append_setting("acfe/{$name}", $value);
 
1264
 
1265
+ }
1266
+
1267
+ function acfe_get_setting($name, $value = null){
1268
 
1269
+ return acf_get_setting("acfe/{$name}", $value);
1270
 
1271
  }
1272
 
1456
 
1457
  }
1458
 
1459
+ }
1460
+
1461
+ function acfe_unset(&$array, $key){
1462
+
1463
+ if(isset($array[$key]))
1464
+ unset($array[$key]);
1465
+
1466
+ }
1467
+
1468
+ function acfe_get_post_id(){
1469
+
1470
+ return acf_get_valid_post_id();
1471
+
1472
  }
includes/field-groups/field-group-category.php CHANGED
@@ -3,6 +3,10 @@
3
  if(!defined('ABSPATH'))
4
  exit;
5
 
 
 
 
 
6
  add_action('init', 'acfe_field_group_category_register', 9);
7
  function acfe_field_group_category_register(){
8
 
3
  if(!defined('ABSPATH'))
4
  exit;
5
 
6
+ // Check setting
7
+ if(!acf_get_setting('acfe/modules/categories'))
8
+ return;
9
+
10
  add_action('init', 'acfe_field_group_category_register', 9);
11
  function acfe_field_group_category_register(){
12
 
includes/field-groups/field-group.php CHANGED
@@ -3,135 +3,163 @@
3
  if(!defined('ABSPATH'))
4
  exit;
5
 
6
- add_action('acf/update_field_group', 'acfe_field_group_update', 0);
7
- function acfe_field_group_update($field_group){
8
-
9
- // Get Fields
10
- $fields = acf_get_fields($field_group);
11
- if(empty($fields))
12
- return;
13
-
14
- // Add acfe_form
15
- if(acf_maybe_get($field_group, 'acfe_form')){
16
 
17
- // Update Fields
18
- acfe_field_group_fields_add_fields_form($fields);
19
-
20
- }
21
 
22
- // Remove acfe_form
23
- else{
 
 
24
 
25
- // Update Fields
26
- acfe_field_group_fields_add_fields_form($fields, false);
27
 
28
- }
 
29
 
30
- }
31
-
32
- function acfe_field_group_fields_add_fields_form($fields, $add = true){
 
 
 
 
 
 
 
 
 
 
 
33
 
34
- if(empty($fields))
35
- return;
 
 
 
36
 
37
- foreach($fields as $field){
 
 
 
 
 
 
38
 
39
- // bypass clone
40
- if($field['type'] === 'clone')
41
- continue;
42
 
43
- // Group / Clone
44
- if(isset($field['sub_fields']) && !empty($field['sub_fields'])){
 
 
 
 
 
45
 
46
- acfe_field_group_fields_add_fields_form($field['sub_fields'], $add);
47
 
48
  }
49
 
50
- // Flexible Content
51
- elseif(isset($field['layouts']) && !empty($field['layouts'])){
 
 
 
 
 
 
 
 
 
52
 
53
- foreach($field['layouts'] as $layout){
 
 
 
 
 
 
 
54
 
55
- if(isset($layout['sub_fields']) && !empty($layout['sub_fields'])){
 
 
 
 
 
56
 
57
- acfe_field_group_fields_add_fields_form($layout['sub_fields'], $add);
 
 
 
 
58
 
59
  }
 
60
  }
61
 
62
- }
63
-
64
- // Add
65
- if($add){
66
-
67
- if(acf_maybe_get($field, 'acfe_form'))
68
- continue;
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
- $field['acfe_form'] = true;
71
 
72
  }
73
 
74
- // Remove
75
- else{
76
-
77
- if(!acf_maybe_get($field, 'acfe_form'))
78
- continue;
79
-
80
- unset($field['acfe_form']);
81
-
82
- if(isset($field['acfe_settings']))
83
- unset($field['acfe_settings']);
84
-
85
- if(isset($field['acfe_validate']))
86
- unset($field['acfe_validate']);
87
-
88
- }
89
 
90
- acf_update_field($field);
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
  }
93
 
94
- }
95
-
96
- add_filter('acf/prepare_field/name=acfe_meta', 'acfe_field_group_meta_fix_repeater');
97
- add_filter('acf/prepare_field/name=acfe_meta_key', 'acfe_field_group_meta_fix_repeater');
98
- add_filter('acf/prepare_field/name=acfe_meta_value', 'acfe_field_group_meta_fix_repeater');
99
- function acfe_field_group_meta_fix_repeater($field){
100
-
101
- $field['prefix'] = str_replace('row-', '', $field['prefix']);
102
- $field['name'] = str_replace('row-', '', $field['name']);
103
-
104
- return $field;
105
-
106
- }
107
-
108
- add_action('acf/render_field_group_settings', 'acfe_render_field_group_settings_acfe_form');
109
- function acfe_render_field_group_settings_acfe_form($field_group){
110
-
111
- // Form settings
112
- acf_render_field_wrap(array(
113
- 'label' => __('Advanced settings'),
114
- 'name' => 'acfe_form',
115
- 'prefix' => 'acf_field_group',
116
- 'type' => 'true_false',
117
- 'ui' => 1,
118
- 'instructions' => __('Enable advanced fields settings & validation'),
119
- 'value' => (isset($field_group['acfe_form'])) ? $field_group['acfe_form'] : '',
120
- 'required' => false,
121
- 'wrapper' => array(
122
- 'data-after' => 'active'
123
- )
124
- ));
125
 
126
- }
127
-
128
- /**
129
- * Field Group Options: Data
130
- */
131
- add_action('acf/field_group/admin_head', 'acfe_render_field_group_settings');
132
- function acfe_render_field_group_settings(){
133
 
134
- add_meta_box('acf-field-group-acfe', __('Field group', 'acf'), function(){
135
 
136
  global $field_group;
137
 
@@ -205,149 +233,181 @@ function acfe_render_field_group_settings(){
205
  'value' => (isset($field_group['acfe_note'])) ? $field_group['acfe_note'] : '',
206
  'required' => false,
207
  ));
208
-
209
  ?>
210
  <script type="text/javascript">
211
- if(typeof acf !== 'undefined'){
212
- acf.postbox.render({
213
- 'id': 'acf-field-group-acfe',
214
- 'label': 'left'
215
- });
216
- }
217
-
218
- jQuery(document).ready(function($){
219
- $('#post_name').on('keyup', function(){
220
- var val = $(this).val();
221
- if(!val.startsWith('group_')){
222
- var val = 'group_' + val;
223
- $(this).val(val);
224
- }
225
-
226
- $('[name="acf_field_group[key]"]').val(val);
227
- $('.misc-pub-acfe-field-group-key code').html(val);
 
 
 
 
228
  });
229
- });
230
  </script>
231
  <?php
232
- }, 'acf-field-group', 'normal');
233
-
234
- }
235
-
236
- /**
237
- * Field Group Options: Sidebar - Submit Div
238
- */
239
- add_action('post_submitbox_misc_actions', 'acfe_render_field_group_submitbox', 11);
240
- function acfe_render_field_group_submitbox($post){
241
-
242
- if($post->post_type !== 'acf-field-group')
243
- return;
244
-
245
- global $field_group;
246
- ?>
247
- <div class="misc-pub-section misc-pub-acfe-field-group-key" style="padding-top:2px;">
248
- <span style="font-size:16px;color: #82878c;width: 20px;margin-right: 2px;" class="dashicons dashicons-tag"></span> <code style="font-size: 12px;"><?php echo $field_group['key']; ?></code>
249
- </div>
250
- <div class="misc-pub-section misc-pub-acfe-field-group-export" style="padding-top:2px;">
251
- <span style="font-size:17px;color: #82878c;line-height: 1.3;width: 20px;margin-right: 2px;" class="dashicons dashicons-editor-code"></span> Export: <a href="<?php echo admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=export&action=php&keys=' . $field_group['key']); ?>">PHP</a> <a href="<?php echo admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=export&action=json&keys=' . $field_group['key']); ?>">Json</a>
252
- </div>
253
- <script type="text/javascript">
254
- (function($) {
255
- $('.misc-pub-acfe-field-group-key').insertAfter('.misc-pub-post-status');
256
- $('.misc-pub-acfe-field-group-export').insertAfter('.misc-pub-post-status');
257
- })(jQuery);
258
- </script>
259
- <?php
260
-
261
- }
262
-
263
- /**
264
- * Field Group Options: Sidebar
265
- */
266
- add_action('acf/field_group/admin_head', 'acfe_render_field_group_settings_side');
267
- function acfe_render_field_group_settings_side(){
268
 
269
- add_meta_box('acf-field-group-acfe-side', __('Advanced Settings', 'acfe'), function(){
270
 
271
  // Global
272
  global $field_group;
273
 
274
- // Proxy
275
- $_field_group = $field_group;
276
-
277
  acf_render_field_wrap(array(
278
  'label' => __('Display title', 'acfe'),
279
  'instructions' => __('Render this title on edit post screen', 'acfe'),
280
  'type' => 'text',
281
  'name' => 'acfe_display_title',
282
  'prefix' => 'acf_field_group',
283
- 'value' => (isset($field_group['acfe_display_title'])) ? $field_group['acfe_display_title'] : '',
284
  'placeholder' => '',
285
  'prepend' => '',
286
  'append' => ''
287
  ));
288
 
289
- if(acfe_is_field_group_json_desync($field_group)){
 
 
 
290
 
291
- acf_render_field_wrap(array(
292
- 'label' => __('Json Desync'),
293
- 'instructions' => __('Local json file is different from this version. If you manually synchronize it, you will lose your current field group settings'),
294
- 'type' => 'acfe_dynamic_message',
295
- 'name' => 'acfe_sync_available',
296
- 'prefix' => 'acf_field_group',
297
- 'value' => $field_group['key'],
298
- ));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
 
300
  }
301
 
 
 
 
 
302
 
303
- $force_json_sync = false;
304
- $json_text = 'Json';
305
 
306
- if(acfe_has_field_group_autosync_file($_field_group, 'json')){
307
-
308
- if(isset($_field_group['acfe_autosync']) && is_array($_field_group['acfe_autosync']))
309
- $_field_group['acfe_autosync'][] = 'json';
310
- else
311
- $_field_group['acfe_autosync'] = array('json');
 
 
 
 
 
 
 
 
 
312
 
313
- $json_text = '<span class="acf-js-tooltip" title="To disable the Json Sync you must manually delete the file: '.$_field_group['key'].'.json">Json</span>';
 
 
 
314
 
315
- $force_json_sync = true;
 
316
 
317
- }
318
-
319
- $force_php_sync = false;
320
- $php_text = 'PHP';
321
- acf_enable_filter('local');
322
-
323
- if(acfe_has_field_group_autosync_file($_field_group, 'php')){
324
 
325
- acf_disable_filter('local');
326
 
327
- if(isset($_field_group['acfe_autosync']) && is_array($_field_group['acfe_autosync']))
328
- $_field_group['acfe_autosync'][] = 'php';
329
- else
330
- $_field_group['acfe_autosync'] = array('php');
331
 
332
- $php_text = '<span class="acf-js-tooltip" title="To disable the PHP Sync you must manually delete the file: '.$_field_group['key'].'.php">PHP</span>';
 
 
 
 
 
 
 
 
 
 
 
333
 
334
- $force_php_sync = true;
335
 
336
  }
337
 
 
 
 
338
  acf_render_field_wrap(array(
339
  'label' => __('Auto Sync'),
340
  'instructions' => '',
341
  'type' => 'checkbox',
342
  'name' => 'acfe_autosync',
343
  'prefix' => 'acf_field_group',
344
- 'value' => (isset($_field_group['acfe_autosync']) && !empty($_field_group['acfe_autosync'])) ? $_field_group['acfe_autosync'] : array(),
345
  'choices' => array(
346
- 'php' => $php_text,
347
- 'json' => $json_text,
348
  )
349
  ));
350
 
 
 
 
351
  acf_render_field_wrap(array(
352
  'label' => __('Permissions'),
353
  'name' => 'acfe_permissions',
@@ -357,422 +417,436 @@ function acfe_render_field_group_settings_side(){
357
  'required' => false,
358
  'default_value' => false,
359
  'choices' => acfe_get_roles(),
360
- 'value' => (isset($field_group['acfe_permissions'])) ? $field_group['acfe_permissions'] : array(),
361
  'layout' => 'vertical'
362
  ));
363
 
364
  ?>
365
  <script type="text/javascript">
366
- if(typeof acf !== 'undefined'){
367
- acf.postbox.render({
368
- 'id': 'acf-field-group-acfe-side',
369
- 'label': 'top'
370
- });
371
- }
372
-
373
- (function($){
374
-
375
- <?php if($force_json_sync){ ?>
 
 
376
 
377
- $('#acf_field_group-acfe_autosync-json').prop('readonly', true).addClass('disabled').click(function(){
 
 
378
  return false;
379
  });
 
 
380
 
381
- $('#acf_field_group-acfe_autosync-json').closest('label').css('color', '#999');
382
-
383
- <?php } ?>
384
-
385
- <?php if($force_php_sync){ ?>
386
 
387
- $('#acf_field_group-acfe_autosync-php').prop('readonly', true).addClass('disabled').click(function(){
 
 
388
  return false;
389
  });
 
 
390
 
391
- $('#acf_field_group-acfe_autosync-php').closest('label').css('color', '#999');
392
-
393
- <?php } ?>
394
-
395
- if($('[data-name=acfe_sync_available]').length){
396
-
397
- if($('[data-name=acfe_sync_available]').find('[data-acfe-autosync-json-active]').attr('data-acfe-autosync-json-active') === '0'){
398
- $('#acf_field_group-acfe_autosync-json').change(function(e){
399
- if($(this).prop('checked')){
400
- if(!confirm('Local json file was found and is different from this version.' + "\n" + 'Enabling json auto sync will erase the local file with the current field group settings')){
401
- $(this).prop('checked', false);
402
- return false;
 
 
 
403
  }
404
- }
405
- });
 
 
 
 
 
 
 
 
 
 
406
  }
407
-
408
- else{
409
-
410
- $('#publish').click(function(e){
411
- if(!confirm('Local json file was found and is different from this version.' + "\n" + 'Proceed to erase the local file with the current field group settings'))
412
- e.preventDefault();
 
 
413
  });
414
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
  }
416
- }
417
- })(jQuery);
418
- </script>
419
- <?php
420
- }, 'acf-field-group', 'side');
421
-
422
- }
423
 
424
- /**
425
- * Render: Sync Available
426
- */
427
- add_action('acf/render_field/name=acfe_sync_available', 'acfe_render_field_sync_available');
428
- function acfe_render_field_sync_available($field){
429
-
430
- $field_group = acf_get_field_group($field['value']);
431
-
432
- $acfe_autosync_active = 0;
433
- if(isset($field_group['acfe_autosync']) && is_array($field_group['acfe_autosync']) && in_array('json', $field_group['acfe_autosync']))
434
- $acfe_autosync_active = 1;
435
-
436
- $nonce = wp_create_nonce('bulk-posts');
437
- echo '<a data-acfe-autosync-json-active="'.$acfe_autosync_active.'" class="button" href="'.admin_url('edit.php?post_type=acf-field-group&post_status=sync&acfsync=' . $field['value'] . '&_wpnonce=' . $nonce).'">Synchronize</a>';
438
-
439
- }
440
 
441
- /**
442
- * Render: Sync Warnings
443
- */
444
- add_action('acf/render_field', 'acfe_render_field_acfe_sync_warnings', 5);
445
- function acfe_render_field_acfe_sync_warnings($field){
446
-
447
- if($field['_name'] !== 'acfe_autosync')
448
- return;
449
-
450
- global $field_group;
451
-
452
- // PHP
453
-
454
- // Fix to load local field groups
455
- acf_enable_filters();
456
 
457
- if(acfe_has_field_group_autosync($field_group, 'php') && !acf_get_setting('acfe/php_found')){
458
- echo '<p class="description"><span style="color:#ccc;font-size:16px;vertical-align:text-top;" class="dashicons dashicons-warning"></span> Folder <code style="font-size:11px;">/acfe-php</code> was not found in your theme. You must create it to activate PHP Sync</p>';
459
- }
 
460
 
461
- elseif(!acfe_has_field_group_autosync($field_group, 'php') && acfe_has_field_group_autosync_file($field_group, 'php')){
462
- echo '<p class="description"><span style="color:#ccc;font-size:16px;vertical-align:text-top;" class="dashicons dashicons-warning"></span> This field group is registered via a third-party PHP code</p>';
463
- }
464
 
465
- elseif(acfe_has_field_group_autosync($field_group, 'php') && !acfe_has_field_group_autosync_file($field_group, 'php')){
466
- echo '<p class="description"><span style="color:#ccc;font-size:16px;vertical-align:text-top;" class="dashicons dashicons-warning"></span> <code style="font-size:11px;">' . $field_group['key'] . '.php</code> will be created upon update</p>';
467
- }
468
-
469
- // Re-disable filters, as natively
470
- acf_disable_filters();
 
 
 
 
 
 
 
 
 
 
 
471
 
472
- // Json
473
- if(acfe_has_field_group_autosync($field_group, 'json') && !acfe_has_field_group_autosync_file($field_group, 'json')){
 
 
 
 
 
474
 
475
- if(!acf_get_setting('acfe/json_found')){
476
 
477
- echo '<p class="description"><span style="color:#ccc;font-size:16px;vertical-align:text-top;" class="dashicons dashicons-warning"></span> Folder <code style="font-size:11px;">/acf-json</code> was not found in your theme. You must create it to activate Json Sync.</p>';
 
478
 
479
  }
480
 
481
- else{
 
482
 
483
- echo '<p class="description"><span style="color:#ccc;font-size:16px;vertical-align:text-top;" class="dashicons dashicons-warning"></span> <code style="font-size:11px;">' . $field_group['key'] . '.json</code> will be created upon update.</p>';
484
-
485
- }
486
  }
487
 
488
- }
489
-
490
- /**
491
- * Render: Data button
492
- */
493
- add_action('acf/render_field/name=acfe_data', 'acfe_render_field_group_data');
494
- function acfe_render_field_group_data($field){
495
-
496
- $field_group = acf_get_field_group($field['value']);
497
- $field_group_raw = get_post($field_group['ID']);
498
-
499
- if(!$field_group){
500
 
501
- echo '<a href="#" class="button disabled" disabled>' . __('Data') . '</a>';
502
- return;
503
 
504
- }
505
-
506
- echo '<a href="#" class="acf-button button acfe_modal_open" data-modal-key="' . $field_group['key'] . '">' . __('Data') . '</a>';
507
- echo '<div class="acfe-modal" data-modal-key="' . $field_group['key'] . '"><div style="padding:15px;"><pre style="margin-bottom:15px;">' . print_r($field_group, true) . '</pre><pre>' . print_r($field_group_raw, true) . '</pre></div></div>';
508
-
509
- }
510
-
511
- /**
512
- * Hooks: Display title (post edit)
513
- */
514
- add_filter('acf/load_field_groups', 'acfe_render_field_groups', 999);
515
- function acfe_render_field_groups($field_groups){
516
-
517
- if(!is_admin())
518
- return $field_groups;
519
-
520
- if(acfe_is_admin_screen())
521
- return $field_groups;
522
-
523
- foreach($field_groups as &$field_group){
524
 
525
- if(!acf_maybe_get($field_group, 'acfe_display_title'))
526
- continue;
 
 
 
 
 
 
527
 
528
- $field_group['title'] = $field_group['acfe_display_title'];
529
 
530
  }
531
 
532
- return $field_groups;
533
-
534
- }
535
-
536
- /**
537
- * Hooks: Permissions (post edit)
538
- */
539
- add_filter('acf/load_field_groups', 'acfe_permissions_field_groups', 999);
540
- function acfe_permissions_field_groups($field_groups){
541
-
542
- if(!is_admin())
543
- return $field_groups;
544
-
545
- if(acfe_is_admin_screen())
546
- return $field_groups;
547
-
548
- $current_user_roles = acfe_get_current_user_roles();
549
-
550
- foreach($field_groups as $key => $field_group){
551
 
552
- if(!acf_maybe_get($field_group, 'acfe_permissions'))
553
- continue;
554
 
555
- $render_field_group = false;
556
 
557
- foreach($current_user_roles as $current_user_role){
 
 
 
558
 
559
- foreach($field_group['acfe_permissions'] as $field_group_role){
 
 
560
 
561
- if($current_user_role !== $field_group_role)
562
- continue;
 
 
 
 
 
 
 
563
 
564
- $render_field_group = true;
565
- break;
566
 
567
  }
568
 
569
- if($render_field_group)
570
- break;
571
 
572
  }
573
 
574
- if(!$render_field_group)
575
- unset($field_groups[$key]);
576
 
577
  }
578
 
579
- return $field_groups;
580
-
581
- }
582
-
583
- add_filter('acf/prepare_field/name=instruction_placement', 'acfe_field_group_instruction_placement');
584
- function acfe_field_group_instruction_placement($field){
585
-
586
- $field['choices'] = array_merge($field['choices'], array('acfe_instructions_tooltip' => 'Tooltip'));
587
-
588
- return $field;
589
-
590
- }
591
-
592
- /**
593
- * Validate field group
594
- */
595
- add_filter('acf/validate_field_group', 'acfc_field_group_default_options');
596
- function acfc_field_group_default_options($field_group){
597
-
598
- // Only new field groups
599
- if(!acf_maybe_get($field_group, 'location')){
600
-
601
- // Default label placement: Left
602
- $field_group['label_placement'] = 'left';
603
 
604
- // AutoSync
605
- $acfe_autosync = array();
606
-
607
- if(acf_get_setting('acfe/json_found', false)){
608
 
609
- $acfe_autosync[] = 'json';
610
 
611
- }
612
 
613
- if(acf_get_setting('acfe/php_found', false)){
614
-
615
- $acfe_autosync[] = 'php';
 
616
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
617
  }
618
-
619
- if(!empty($acfe_autosync)){
620
 
621
- $field_group['acfe_autosync'] = $acfe_autosync;
622
-
623
- }
624
 
625
  }
626
 
627
-
628
-
629
- return $field_group;
630
-
631
- }
632
-
633
- /**
634
- * Field Group: Hide on screen
635
- */
636
- add_filter('acf/prepare_field/name=hide_on_screen', 'acfc_field_group_hide_on_screen');
637
- function acfc_field_group_hide_on_screen($field){
638
-
639
- $choices = array();
640
-
641
- foreach($field['choices'] as $key => $value){
642
 
643
- if($key == 'the_content'){
 
 
 
 
 
 
 
644
 
645
- $choices['block_editor'] = __('Block Editor');
646
 
647
  }
648
 
 
649
 
650
- $choices[$key] = $value;
651
 
652
  }
653
 
654
- $field['choices'] = $choices;
655
-
656
- return $field;
657
-
658
- }
659
-
660
- add_filter('acf/prepare_field_group_for_export', 'acfc_field_group_export_categories');
661
- function acfc_field_group_export_categories($field_group){
662
-
663
- $_field_group = acf_get_field_group($field_group['key']);
664
-
665
- if(empty($_field_group))
666
- return $field_group;
667
-
668
- if(!acf_maybe_get($_field_group, 'ID'))
669
- return $field_group;
670
-
671
- $categories = get_the_terms($_field_group['ID'], 'acf-field-group-category');
672
-
673
- if(empty($categories) || is_wp_error($categories))
674
- return $field_group;
675
-
676
- $field_group['acfe_categories'] = array();
677
-
678
- foreach($categories as $term){
679
 
680
- $field_group['acfe_categories'][$term->slug] = $term->name;
 
 
 
 
 
 
 
 
 
 
 
 
 
681
 
682
  }
683
 
684
- return $field_group;
685
-
686
- }
687
-
688
- add_action('acf/import_field_group', 'acfc_field_group_import_categories');
689
- function acfc_field_group_import_categories($field_group){
690
-
691
- if(!$categories = acf_maybe_get($field_group, 'acfe_categories'))
692
- return;
693
 
694
- foreach($categories as $term_slug => $term_name){
695
 
696
- $new_term_id = false;
697
- $get_term = get_term_by('slug', $term_slug, 'acf-field-group-category');
698
 
699
- // Term doesn't exists
700
- if(empty($get_term)){
701
 
702
- $new_term = wp_insert_term($term_name, 'acf-field-group-category', array(
703
- 'slug' => $term_slug
704
- ));
705
 
706
- if(!is_wp_error($new_term)){
 
707
 
708
- $new_term_id = $new_term['term_id'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709
 
710
  }
711
 
712
  }
713
 
714
- // Term already exists
715
- else{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
716
 
717
- $new_term_id = $get_term->term_id;
 
 
 
 
718
 
719
  }
720
 
721
- if($new_term_id){
722
 
723
- wp_set_post_terms($field_group['ID'], array($new_term_id), 'acf-field-group-category', true);
724
 
725
  }
726
 
727
  }
728
 
729
- }
730
-
731
- add_action('load-post.php', 'acfe_field_group_disable_editor');
732
- add_action('load-post-new.php', 'acfe_field_group_disable_editor');
733
- function acfe_field_group_disable_editor(){
734
-
735
- // globals
736
- global $typenow;
737
-
738
- // restrict specific post types
739
- $restricted = array('acf-field-group', 'attachment');
740
- if( in_array($typenow, $restricted) ) {
741
- return;
742
- }
743
-
744
- $post_type = $typenow;
745
- $post_id = 0;
746
-
747
- if ( isset( $_GET['post'] ) ) {
748
- $post_id = (int) $_GET['post'];
749
- } elseif ( isset( $_POST['post_ID'] ) ) {
750
- $post_id = (int) $_POST['post_ID'];
751
- }
752
-
753
- $field_groups = acf_get_field_groups(array(
754
- 'post_id' => $post_id,
755
- 'post_type' => $post_type
756
- ));
757
-
758
- $hide_block_editor = false;
759
-
760
- foreach($field_groups as $field_group){
761
-
762
- $hide_on_screen = acf_get_array($field_group['hide_on_screen']);
763
-
764
- if(!in_array('block_editor', $hide_on_screen))
765
- continue;
766
-
767
- $hide_block_editor = true;
768
- break;
769
 
770
- }
771
-
772
- if($hide_block_editor){
773
 
774
- add_filter('use_block_editor_for_post_type', '__return_false');
775
 
776
  }
777
 
778
- }
 
 
 
 
3
  if(!defined('ABSPATH'))
4
  exit;
5
 
6
+ if(!class_exists('ACFE_Field_Group')):
 
 
 
 
 
 
 
 
 
7
 
8
+ class ACFE_Field_Group{
 
 
 
9
 
10
+ /*
11
+ * Construct
12
+ */
13
+ function __construct(){
14
 
15
+ // Actions
16
+ add_action('acf/update_field_group', array($this, 'update_field_group'), 0);
17
 
18
+ add_action('acf/field_group/admin_head', array($this, 'render_field_group_settings'));
19
+ add_action('post_submitbox_misc_actions', array($this, 'submitbox'), 11);
20
 
21
+ add_action('acf/render_field_group_settings', array($this, 'render_field_group_advanced_settings'));
22
+ add_action('acf/render_field/name=acfe_data', array($this, 'render_field_group_data'));
23
+
24
+ add_filter('acf/load_field_groups', array($this, 'render_field_group_alternative_title'), 999);
25
+ add_filter('acf/load_field_groups', array($this, 'render_field_group_permissions'), 999);
26
+
27
+ add_filter('acf/prepare_field/name=instruction_placement', array($this, 'render_field_group_instructions_settings'));
28
+ add_filter('acf/prepare_field/name=hide_on_screen', array($this, 'render_field_group_hide_on_screen_settings'));
29
+ add_filter('acf/validate_field_group', array($this, 'render_field_group_default_autosync'));
30
+
31
+ add_filter('acf/prepare_field_group_for_export', array($this, 'prepare_field_group_export_categories'));
32
+ add_action('acf/import_field_group', array($this, 'prepare_field_group_import_categories'));
33
+ add_action('load-post.php', array($this, 'render_disable_block_editor'));
34
+ add_action('load-post-new.php', array($this, 'render_disable_block_editor'));
35
 
36
+ add_filter('acf/prepare_field/name=acfe_meta', array($this, 'prepare_repeater'));
37
+ add_filter('acf/prepare_field/name=acfe_meta_key', array($this, 'prepare_repeater'));
38
+ add_filter('acf/prepare_field/name=acfe_meta_value', array($this, 'prepare_repeater'));
39
+
40
+ }
41
 
42
+ /*
43
+ * Update Field Group
44
+ */
45
+ function update_field_group($field_group){
46
+
47
+ // Get Fields
48
+ $fields = acf_get_fields($field_group);
49
 
50
+ if(empty($fields))
51
+ return;
 
52
 
53
+ // Add acfe_form
54
+ if(acf_maybe_get($field_group, 'acfe_form')){
55
+
56
+ $this->add_field_advanced_settings($fields);
57
+
58
+ // Remove acfe_form
59
+ }else{
60
 
61
+ $this->add_field_advanced_settings($fields, false);
62
 
63
  }
64
 
65
+ }
66
+
67
+ /*
68
+ * Add Field Advanced Settings
69
+ */
70
+ function add_field_advanced_settings($fields, $add = true){
71
+
72
+ if(empty($fields))
73
+ return;
74
+
75
+ foreach($fields as $field){
76
 
77
+ // bypass clone
78
+ if($field['type'] === 'clone')
79
+ continue;
80
+
81
+ // Group / Clone
82
+ if(isset($field['sub_fields']) && !empty($field['sub_fields'])){
83
+
84
+ $this->add_field_advanced_settings($field['sub_fields'], $add);
85
 
86
+ }
87
+
88
+ // Flexible Content
89
+ elseif(isset($field['layouts']) && !empty($field['layouts'])){
90
+
91
+ foreach($field['layouts'] as $layout){
92
 
93
+ if(isset($layout['sub_fields']) && !empty($layout['sub_fields'])){
94
+
95
+ $this->add_field_advanced_settings($layout['sub_fields'], $add);
96
+
97
+ }
98
 
99
  }
100
+
101
  }
102
 
103
+ // Add
104
+ if($add){
105
+
106
+ if(acf_maybe_get($field, 'acfe_form'))
107
+ continue;
108
+
109
+ $field['acfe_form'] = true;
110
+
111
+ // Remove
112
+ }else{
113
+
114
+ if(!acf_maybe_get($field, 'acfe_form'))
115
+ continue;
116
+
117
+ acfe_unset($field, 'acfe_form');
118
+ acfe_unset($field, 'acfe_settings');
119
+ acfe_unset($field, 'acfe_validate');
120
+
121
+ }
122
 
123
+ acf_update_field($field);
124
 
125
  }
126
 
127
+ }
128
+
129
+ /*
130
+ * Advanced Settings
131
+ */
132
+ function render_field_group_advanced_settings($field_group){
 
 
 
 
 
 
 
 
 
133
 
134
+ // Form settings
135
+ acf_render_field_wrap(array(
136
+ 'label' => __('Advanced settings'),
137
+ 'name' => 'acfe_form',
138
+ 'prefix' => 'acf_field_group',
139
+ 'type' => 'true_false',
140
+ 'ui' => 1,
141
+ 'instructions' => __('Enable advanced fields settings & validation'),
142
+ 'value' => (isset($field_group['acfe_form'])) ? $field_group['acfe_form'] : '',
143
+ 'required' => false,
144
+ 'wrapper' => array(
145
+ 'data-after' => 'active'
146
+ )
147
+ ));
148
 
149
  }
150
 
151
+ /**
152
+ * Metabox
153
+ */
154
+ function render_field_group_settings(){
155
+
156
+ add_meta_box('acf-field-group-acfe', __('Field group', 'acf'), array($this, 'render_field_group_setting_metabox'), 'acf-field-group', 'normal');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
+ add_meta_box('acf-field-group-acfe-side', __('Advanced Settings', 'acfe'), array($this, 'render_field_group_setting_sidebar_metabox'), 'acf-field-group', 'side');
159
+
160
+ }
 
 
 
 
161
 
162
+ function render_field_group_setting_metabox(){
163
 
164
  global $field_group;
165
 
233
  'value' => (isset($field_group['acfe_note'])) ? $field_group['acfe_note'] : '',
234
  'required' => false,
235
  ));
236
+
237
  ?>
238
  <script type="text/javascript">
239
+ if(typeof acf !== 'undefined'){
240
+ acf.postbox.render({
241
+ 'id': 'acf-field-group-acfe',
242
+ 'label': 'left'
243
+ });
244
+ }
245
+
246
+ jQuery(document).ready(function($){
247
+
248
+ $('#post_name').on('keyup', function(){
249
+ var val = $(this).val();
250
+
251
+ if(!val.startsWith('group_')){
252
+ val = 'group_' + val;
253
+ $(this).val(val);
254
+ }
255
+
256
+ $('[name="acf_field_group[key]"]').val(val);
257
+ $('.misc-pub-acfe-field-group-key code').html(val);
258
+ });
259
+
260
  });
 
261
  </script>
262
  <?php
263
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
 
265
+ function render_field_group_setting_sidebar_metabox(){
266
 
267
  // Global
268
  global $field_group;
269
 
270
+ /*
271
+ * Alternative Title
272
+ */
273
  acf_render_field_wrap(array(
274
  'label' => __('Display title', 'acfe'),
275
  'instructions' => __('Render this title on edit post screen', 'acfe'),
276
  'type' => 'text',
277
  'name' => 'acfe_display_title',
278
  'prefix' => 'acf_field_group',
279
+ 'value' => acf_maybe_get($field_group, 'acfe_display_title'),
280
  'placeholder' => '',
281
  'prepend' => '',
282
  'append' => ''
283
  ));
284
 
285
+ /*
286
+ * Sync available
287
+ */
288
+ if(acfe_is_sync_available($field_group)){
289
 
290
+ $json_already_active = 0;
291
+
292
+ if(in_array('json', acf_maybe_get($field_group, 'acfe_autosync', array())))
293
+ $json_already_active = 1;
294
+
295
+ ?>
296
+ <div class="acf-field" data-name="acfe_sync_available">
297
+ <div class="acf-label">
298
+ <label><?php _e('Sync available', 'acf'); ?></label>
299
+ <p class="description"><?php _e('Local json file is different from the version in database.', 'acf'); ?></p>
300
+ </div>
301
+ <div class="acf-input">
302
+
303
+ <?php
304
+
305
+ if(acf_version_compare(acf_get_setting('version'), '<', '5.9')){
306
+
307
+ $url = admin_url('edit.php?post_type=acf-field-group&post_status=sync&acfsync=' . $field_group['key'] . '&_wpnonce=' . wp_create_nonce('bulk-posts'));
308
+ ?>
309
+ <a href="<?php echo esc_url($url); ?>" class="button" data-acfe-autosync-json-active="<?php echo $json_already_active; ?>">
310
+ <?php _e('Synchronize', 'acf'); ?>
311
+ </a>
312
+ <?php
313
+
314
+ }else{
315
+
316
+ $url = admin_url('edit.php?post_type=acf-field-group&acfsync=' . $field_group['key'] . '&_wpnonce=' . wp_create_nonce('bulk-posts'));
317
+ ?>
318
+ <a href="#" data-event="review-sync" data-id="<?php echo esc_attr($field_group['ID']); ?>" data-href="<?php echo esc_url($url); ?>" class="button" data-acfe-autosync-json-active="<?php echo $json_already_active; ?>">
319
+ <?php _e('Review changes', 'acf'); ?>
320
+ </a>
321
+ <?php
322
+
323
+ }
324
+
325
+ ?>
326
+ </div>
327
+ </div>
328
+ <?php
329
 
330
  }
331
 
332
+ /*
333
+ * AutoSync: Prepare
334
+ */
335
+ acf_enable_filter('local');
336
 
337
+ $disable_json = acfe_get_local_json_file($field_group) ? true : false;
338
+ $disable_php = acfe_get_local_php_file($field_group) ? true : false;
339
 
340
+ $data = array(
341
+ 'php' => acf_get_instance('ACFE_Field_Groups')->get_php_data($field_group),
342
+ 'json' => acf_get_instance('ACFE_Field_Groups')->get_json_data($field_group),
343
+ );
344
+
345
+ acf_disable_filter('local');
346
+
347
+ $choices = array(
348
+ 'php' => 'PHP',
349
+ 'json' => 'Json',
350
+ );
351
+
352
+ global $pagenow;
353
+
354
+ foreach($data as $type => $info){
355
 
356
+ $wrapper = array(
357
+ 'class' => 'acf-js-tooltip',
358
+ 'title' => $info['file'],
359
+ );
360
 
361
+ if($info['class'])
362
+ $wrapper['class'] .= ' ' . $info['class'];
363
 
364
+ if($info['message']){
365
+
366
+ $wrapper['title'] = $info['message'];
367
+
368
+ }
 
 
369
 
370
+ $icons = array();
371
 
372
+ if($info['warning'] && $pagenow !== 'post-new.php')
373
+ $icons[] = '<span class="dashicons dashicons-warning"></span>';
 
 
374
 
375
+ ob_start();
376
+ ?>
377
+ <span <?php echo acf_esc_atts($wrapper); ?>>
378
+
379
+ <?php echo $choices[$type]; ?>
380
+
381
+ <?php if(!empty($icons)){ ?>
382
+ <?php echo implode('', $icons); ?>
383
+ <?php } ?>
384
+
385
+ </span>
386
+ <?php
387
 
388
+ $choices[$type] = ob_get_clean();
389
 
390
  }
391
 
392
+ /*
393
+ * AutoSync
394
+ */
395
  acf_render_field_wrap(array(
396
  'label' => __('Auto Sync'),
397
  'instructions' => '',
398
  'type' => 'checkbox',
399
  'name' => 'acfe_autosync',
400
  'prefix' => 'acf_field_group',
401
+ 'value' => acf_maybe_get($field_group, 'acfe_autosync', array()),
402
  'choices' => array(
403
+ 'php' => $choices['php'],
404
+ 'json' => $choices['json'],
405
  )
406
  ));
407
 
408
+ /*
409
+ * Permissions
410
+ */
411
  acf_render_field_wrap(array(
412
  'label' => __('Permissions'),
413
  'name' => 'acfe_permissions',
417
  'required' => false,
418
  'default_value' => false,
419
  'choices' => acfe_get_roles(),
420
+ 'value' => acf_maybe_get($field_group, 'acfe_permissions', array()),
421
  'layout' => 'vertical'
422
  ));
423
 
424
  ?>
425
  <script type="text/javascript">
426
+ if(typeof acf !== 'undefined'){
427
+ acf.postbox.render({
428
+ 'id': 'acf-field-group-acfe-side',
429
+ 'label': 'top'
430
+ });
431
+ }
432
+
433
+ (function($){
434
+
435
+ var $json = $('#acf_field_group-acfe_autosync-json');
436
+ var $php = $('#acf_field_group-acfe_autosync-php');
437
+ var $sync_available = $('[data-name=acfe_sync_available]');
438
 
439
+ <?php if($disable_json){ ?>
440
+
441
+ $json.prop('readonly', true).addClass('disabled').click(function(){
442
  return false;
443
  });
444
+
445
+ $json.closest('label').css('color', '#999');
446
 
447
+ <?php } ?>
 
 
 
 
448
 
449
+ <?php if($disable_php){ ?>
450
+
451
+ $php.prop('readonly', true).addClass('disabled').click(function(){
452
  return false;
453
  });
454
+
455
+ $php.closest('label').css('color', '#999');
456
 
457
+ <?php } ?>
458
+
459
+ if($sync_available.length){
460
+
461
+ if($sync_available.find('[data-acfe-autosync-json-active]').attr('data-acfe-autosync-json-active') === '0'){
462
+
463
+ $json.change(function(){
464
+
465
+ if($(this).prop('checked')){
466
+
467
+ if(!confirm('Local json file was found and is different from the version in database.' + "\n" + 'Enabling Json Sync will replace the local file with the current settings' + "\n\n" + 'Do you want to continue?')){
468
+ $(this).prop('checked', false);
469
+ return false;
470
+ }
471
+
472
  }
473
+
474
+ });
475
+
476
+ }else{
477
+
478
+ $('#publish').click(function(e){
479
+ if(!confirm('Local json file is different from the version in database.' + "\n" + 'Do you want to replace the local file with the current settings?'))
480
+ e.preventDefault();
481
+ });
482
+
483
+ }
484
+
485
  }
486
+
487
+ // Displays a modal comparing local changes.
488
+ function reviewSync( props ) {
489
+
490
+ var modal = acf.newModal({
491
+ title: acf.__('Review local JSON changes'),
492
+ content: '<p class="acf-modal-feedback"><i class="acf-loading"></i> ' + acf.__('Loading diff') + '</p>',
493
+ toolbar: '<a href="' + props.href + '" class="button button-primary button-sync-changes disabled">' + acf.__('Sync changes') + '</a>',
494
  });
495
+
496
+ // Call AJAX.
497
+ var xhr = $.ajax({
498
+ url: acf.get('ajaxurl'),
499
+ method: 'POST',
500
+ dataType: 'json',
501
+ data: acf.prepareForAjax({
502
+ action: 'acf/ajax/local_json_diff',
503
+ id: props.id
504
+ })
505
+ })
506
+ .done(function( data, textStatus, jqXHR ) {
507
+ modal.content( data.html );
508
+ modal.$('.button-sync-changes').removeClass('disabled');
509
+ })
510
+ .fail(function( jqXHR, textStatus, errorThrown ) {
511
+ if( error = acf.getXhrError(jqXHR) ) {
512
+ modal.content( '<p class="acf-modal-feedback error">' + error + '</p>' );
513
+ }
514
+ });
515
+
516
  }
 
 
 
 
 
 
 
517
 
518
+ // Add event listener.
519
+ $(document).on('click', 'a[data-event="review-sync"]', function(e){
520
+ e.preventDefault();
521
+ reviewSync( $(this).data() );
522
+ });
 
 
 
 
 
 
 
 
 
 
 
523
 
524
+ })(jQuery);
525
+ </script>
526
+ <?php
527
+ }
 
 
 
 
 
 
 
 
 
 
 
528
 
529
+ /**
530
+ * Submit Box
531
+ */
532
+ function submitbox($post){
533
 
534
+ if($post->post_type !== 'acf-field-group')
535
+ return;
 
536
 
537
+ global $field_group;
538
+ ?>
539
+ <div class="misc-pub-section misc-pub-acfe-field-group-key" style="padding-top:2px;">
540
+ <span style="font-size:16px;color: #82878c;width: 20px;margin-right: 2px;" class="dashicons dashicons-tag"></span> <code style="font-size: 12px;"><?php echo $field_group['key']; ?></code>
541
+ </div>
542
+ <div class="misc-pub-section misc-pub-acfe-field-group-export" style="padding-top:2px;">
543
+ <span style="font-size:17px;color: #82878c;line-height: 1.3;width: 20px;margin-right: 2px;" class="dashicons dashicons-editor-code"></span> Export: <a href="<?php echo admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=export&action=php&keys=' . $field_group['key']); ?>">PHP</a> <a href="<?php echo admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=export&action=json&keys=' . $field_group['key']); ?>">Json</a>
544
+ </div>
545
+ <script type="text/javascript">
546
+ (function($) {
547
+ $('.misc-pub-acfe-field-group-key').insertAfter('.misc-pub-post-status');
548
+ $('.misc-pub-acfe-field-group-export').insertAfter('.misc-pub-post-status');
549
+ })(jQuery);
550
+ </script>
551
+ <?php
552
+
553
+ }
554
 
555
+ /**
556
+ * Render: Data button
557
+ */
558
+ function render_field_group_data($field){
559
+
560
+ $field_group = acf_get_field_group($field['value']);
561
+ $field_group_raw = get_post($field_group['ID']);
562
 
563
+ if(!$field_group){
564
 
565
+ echo '<a href="#" class="button disabled" disabled>' . __('Data') . '</a>';
566
+ return;
567
 
568
  }
569
 
570
+ echo '<a href="#" class="acf-button button acfe_modal_open" data-modal-key="' . $field_group['key'] . '">' . __('Data') . '</a>';
571
+ echo '<div class="acfe-modal" data-modal-key="' . $field_group['key'] . '"><div style="padding:15px;"><pre style="margin-bottom:15px;">' . print_r($field_group, true) . '</pre><pre>' . print_r($field_group_raw, true) . '</pre></div></div>';
572
 
 
 
 
573
  }
574
 
575
+ /**
576
+ * Alternative Title
577
+ */
578
+ function render_field_group_alternative_title($field_groups){
 
 
 
 
 
 
 
 
579
 
580
+ if(!is_admin())
581
+ return $field_groups;
582
 
583
+ if(acfe_is_admin_screen())
584
+ return $field_groups;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
585
 
586
+ foreach($field_groups as &$field_group){
587
+
588
+ if(!acf_maybe_get($field_group, 'acfe_display_title'))
589
+ continue;
590
+
591
+ $field_group['title'] = $field_group['acfe_display_title'];
592
+
593
+ }
594
 
595
+ return $field_groups;
596
 
597
  }
598
 
599
+ /**
600
+ * Permissions
601
+ */
602
+ function render_field_group_permissions($field_groups){
603
+
604
+ if(!is_admin())
605
+ return $field_groups;
 
 
 
 
 
 
 
 
 
 
 
 
606
 
607
+ if(acfe_is_admin_screen())
608
+ return $field_groups;
609
 
610
+ $current_user_roles = acfe_get_current_user_roles();
611
 
612
+ foreach($field_groups as $key => $field_group){
613
+
614
+ if(!acf_maybe_get($field_group, 'acfe_permissions'))
615
+ continue;
616
 
617
+ $render_field_group = false;
618
+
619
+ foreach($current_user_roles as $current_user_role){
620
 
621
+ foreach($field_group['acfe_permissions'] as $field_group_role){
622
+
623
+ if($current_user_role !== $field_group_role)
624
+ continue;
625
+
626
+ $render_field_group = true;
627
+ break;
628
+
629
+ }
630
 
631
+ if($render_field_group)
632
+ break;
633
 
634
  }
635
 
636
+ if(!$render_field_group)
637
+ unset($field_groups[$key]);
638
 
639
  }
640
 
641
+ return $field_groups;
 
642
 
643
  }
644
 
645
+ /*
646
+ * Instructions
647
+ */
648
+ function render_field_group_instructions_settings($field){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
649
 
650
+ $field['choices'] = array_merge($field['choices'], array('acfe_instructions_tooltip' => 'Tooltip'));
 
 
 
651
 
652
+ return $field;
653
 
654
+ }
655
 
656
+ /**
657
+ * Default AutoSync
658
+ */
659
+ function render_field_group_default_autosync($field_group){
660
 
661
+ // Only new field groups
662
+ if(!acf_maybe_get($field_group, 'location')){
663
+
664
+ // Default label placement: Left
665
+ $field_group['label_placement'] = 'left';
666
+
667
+ // AutoSync
668
+ $acfe_autosync = array();
669
+
670
+ if(acf_get_setting('acfe/json_found', false)){
671
+
672
+ $acfe_autosync[] = 'json';
673
+
674
+ }
675
+
676
+ if(acf_get_setting('acfe/php_found', false)){
677
+
678
+ $acfe_autosync[] = 'php';
679
+
680
+ }
681
+
682
+ if(!empty($acfe_autosync)){
683
+
684
+ $field_group['acfe_autosync'] = $acfe_autosync;
685
+
686
+ }
687
+
688
  }
 
 
689
 
690
+ return $field_group;
 
 
691
 
692
  }
693
 
694
+ /**
695
+ * Hide on Screen Settings
696
+ */
697
+ function render_field_group_hide_on_screen_settings($field){
698
+
699
+ $choices = array();
 
 
 
 
 
 
 
 
 
700
 
701
+ foreach($field['choices'] as $key => $value){
702
+
703
+ if($key == 'the_content'){
704
+
705
+ $choices['block_editor'] = __('Block Editor');
706
+
707
+ }
708
+
709
 
710
+ $choices[$key] = $value;
711
 
712
  }
713
 
714
+ $field['choices'] = $choices;
715
 
716
+ return $field;
717
 
718
  }
719
 
720
+ /*
721
+ * Prepare Export Categories
722
+ */
723
+ function prepare_field_group_export_categories($field_group){
724
+
725
+ $_field_group = acf_get_field_group($field_group['key']);
726
+
727
+ if(empty($_field_group))
728
+ return $field_group;
729
+
730
+ if(!acf_maybe_get($_field_group, 'ID'))
731
+ return $field_group;
 
 
 
 
 
 
 
 
 
 
 
 
 
732
 
733
+ $categories = get_the_terms($_field_group['ID'], 'acf-field-group-category');
734
+
735
+ if(empty($categories) || is_wp_error($categories))
736
+ return $field_group;
737
+
738
+ $field_group['acfe_categories'] = array();
739
+
740
+ foreach($categories as $term){
741
+
742
+ $field_group['acfe_categories'][$term->slug] = $term->name;
743
+
744
+ }
745
+
746
+ return $field_group;
747
 
748
  }
749
 
 
 
 
 
 
 
 
 
 
750
 
751
+ function prepare_field_group_import_categories($field_group){
752
 
753
+ if(!$categories = acf_maybe_get($field_group, 'acfe_categories'))
754
+ return;
755
 
756
+ foreach($categories as $term_slug => $term_name){
 
757
 
758
+ $new_term_id = false;
759
+ $get_term = get_term_by('slug', $term_slug, 'acf-field-group-category');
 
760
 
761
+ // Term doesn't exists
762
+ if(empty($get_term)){
763
 
764
+ $new_term = wp_insert_term($term_name, 'acf-field-group-category', array(
765
+ 'slug' => $term_slug
766
+ ));
767
+
768
+ if(!is_wp_error($new_term)){
769
+
770
+ $new_term_id = $new_term['term_id'];
771
+
772
+ }
773
+
774
+ // Term already exists
775
+ }else{
776
+
777
+ $new_term_id = $get_term->term_id;
778
+
779
+ }
780
+
781
+ if($new_term_id){
782
+
783
+ wp_set_post_terms($field_group['ID'], array($new_term_id), 'acf-field-group-category', true);
784
 
785
  }
786
 
787
  }
788
 
789
+ }
790
+
791
+
792
+ function render_disable_block_editor(){
793
+
794
+ // globals
795
+ global $typenow;
796
+
797
+ // Restrict
798
+ $restricted = array('acf-field-group', 'attachment');
799
+
800
+ if(in_array($typenow, $restricted))
801
+ return;
802
+
803
+ $post_type = $typenow;
804
+ $post_id = 0;
805
+
806
+ if ( isset( $_GET['post'] ) ) {
807
+ $post_id = (int) $_GET['post'];
808
+ } elseif ( isset( $_POST['post_ID'] ) ) {
809
+ $post_id = (int) $_POST['post_ID'];
810
+ }
811
+
812
+ $field_groups = acf_get_field_groups(array(
813
+ 'post_id' => $post_id,
814
+ 'post_type' => $post_type
815
+ ));
816
+
817
+ $hide_block_editor = false;
818
+
819
+ foreach($field_groups as $field_group){
820
+
821
+ $hide_on_screen = acf_get_array($field_group['hide_on_screen']);
822
 
823
+ if(!in_array('block_editor', $hide_on_screen))
824
+ continue;
825
+
826
+ $hide_block_editor = true;
827
+ break;
828
 
829
  }
830
 
831
+ if($hide_block_editor){
832
 
833
+ add_filter('use_block_editor_for_post_type', '__return_false');
834
 
835
  }
836
 
837
  }
838
 
839
+ function prepare_repeater($field){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
840
 
841
+ $field['prefix'] = str_replace('row-', '', $field['prefix']);
842
+ $field['name'] = str_replace('row-', '', $field['name']);
 
843
 
844
+ return $field;
845
 
846
  }
847
 
848
+ }
849
+
850
+ acf_new_instance('ACFE_Field_Group');
851
+
852
+ endif;
includes/field-groups/field-groups-local.php CHANGED
@@ -3,196 +3,363 @@
3
  if(!defined('ABSPATH'))
4
  exit;
5
 
6
- add_filter('views_edit-acf-field-group', 'acfe_field_groups_third_party_views', 99);
7
- function acfe_field_groups_third_party_views($views){
8
-
9
- // Total
10
- $total = count(acfe_get_third_party_field_groups());
11
 
12
- // Bail early if empty
13
- if($total === 0)
14
- return $views;
 
 
15
 
16
- // Class
17
- $class = '';
 
 
 
 
 
 
 
18
 
19
- // active
20
- if(acf_maybe_get_GET('post_status') === 'acfe-local'){
 
 
21
 
22
- // actions
23
- add_action('admin_footer', 'acfe_field_groups_third_party_footer', 5);
 
 
 
 
 
24
 
25
- // set active class
26
- $class = ' class="current"';
 
27
 
28
- // global
29
- global $wp_list_table;
30
 
31
- // update pagination
32
- $wp_list_table->set_pagination_args(array(
33
- 'total_items' => $total,
34
- 'total_pages' => 1,
35
- 'per_page' => $total
36
- ));
 
37
 
38
  }
39
 
40
- // add view
41
- $views['acfe-local'] = '<a' . $class . ' href="' . admin_url('edit.php?post_type=acf-field-group&post_status=acfe-local') . '">' . __('Local', 'acfe') . ' <span class="count">(' . $total . ')</span></a>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
- // return
44
- return $views;
 
 
45
 
46
- }
47
-
48
- function acfe_field_groups_third_party_footer(){
49
-
50
- // vars
51
- $i = -1;
52
- $columns = array(
53
- 'acfe-source',
54
- 'acfe-count',
55
- 'acfe-locations',
56
- 'acfe-local'
57
- );
58
-
59
- ?>
60
- <script type="text/html" id="tmpl-acfe-local-tbody">
61
- <?php
62
-
63
- foreach(acfe_get_third_party_field_groups() as $field_group ):
64
-
65
  // vars
66
- $i++;
67
- $key = $field_group['key'];
68
- $title = $field_group['title'];
69
- $local = $field_group['local'];
 
 
 
 
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  ?>
72
- <tr <?php if($i%2 == 0): ?>class="alternate"<?php endif; ?>>
73
- <td class="post-title page-title column-title">
74
- <strong>
75
- <span class="row-title"><?php echo esc_html($title); ?></span>
76
- </strong>
77
- <div class="row-actions">
 
 
 
 
78
 
79
- <span>
80
- <a href="<?php echo add_query_arg(array('action' => 'php', 'keys' => $key), acf_get_admin_tool_url('acfe-fg-local')); ?>">PHP</a> |
81
- </span>
82
-
83
- <span>
84
- <a href="<?php echo add_query_arg(array('action' => 'json', 'keys' => $key), acf_get_admin_tool_url('acfe-fg-local')); ?>">Json</a> |
85
- </span>
86
 
87
- <span>
88
- <a href="<?php echo add_query_arg(array('action' => 'sync', 'keys' => $key), acf_get_admin_tool_url('acfe-fg-local')); ?>">Sync</a> |
89
- </span>
90
 
91
- <span class="acfe-key">
92
- <span style="color:#555;">
93
- <code style="font-size: 12px;"><?php echo esc_html($key); ?></code>
94
- </span>
95
- </span>
96
-
97
- </div>
98
- </td>
99
- <?php foreach($columns as $column): ?>
100
- <td class="column-<?php echo esc_attr($column); ?>">
101
- <?php echo acfe_field_groups_column_html($column, $key); ?>
102
- </td>
103
- <?php endforeach; ?>
104
- </tr>
105
- <?php endforeach; ?>
106
- </script>
107
-
108
- <script type="text/javascript">
109
- (function($){
110
-
111
- // update table HTML
112
- $('#the-list').html($('#tmpl-acfe-local-tbody').html());
113
 
114
- })(jQuery);
115
- </script>
116
- <?php
117
-
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
- function acfe_get_third_party_field_groups(){
 
 
 
 
 
 
 
 
121
 
122
- $get_local_field_groups = acf_get_local_field_groups();
123
- if(empty($get_local_field_groups))
124
- return array();
125
 
126
- $locals = array();
 
 
 
 
127
 
128
- foreach($get_local_field_groups as $field_group){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
- // Exclude ACFE Field Groups
 
 
 
 
 
131
 
132
- if(!acfe_is_super_dev()){
133
-
134
- if(stripos($field_group['key'], 'group_acfe_') === 0)
135
- continue;
136
-
137
- }
138
 
 
 
 
139
 
140
- $locals[] = $field_group;
141
 
142
  }
143
 
144
- // Bail early if no local fields
145
- if(empty($locals))
146
- return $locals;
 
147
 
148
- // Get DB field groups
149
- $get_db_field_groups = acfe_get_db_field_groups();
 
 
 
150
 
151
- // Bail early if no DB field groups
152
- if(empty($get_db_field_groups))
153
- return $locals;
 
 
 
 
 
 
 
 
 
154
 
155
- foreach($get_db_field_groups as $field_group){
 
 
 
 
156
 
157
- foreach($locals as $k => $local){
 
158
 
159
- if($local['key'] === $field_group['key'])
160
- unset($locals[$k]);
161
 
 
 
 
 
162
  }
163
 
 
 
164
  }
165
 
166
- return $locals;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
  }
169
 
170
- function acfe_get_db_field_groups(){
171
-
172
- acf_disable_filters();
173
-
174
- $get_db_field_groups = acf_get_field_groups();
175
-
176
- acf_enable_filters();
177
-
178
- return $get_db_field_groups;
179
-
180
- }
181
 
182
- add_filter('bulk_actions-edit-acf-field-group', function($actions){
183
-
184
- if(acf_maybe_get_GET('post_status') === 'acfe-local')
185
- return array();
186
-
187
- return $actions;
188
-
189
- }, 99);
190
 
191
- add_filter('manage_edit-acf-field-group_sortable_columns', function($sortable_columns){
 
 
 
192
 
193
- if(acf_maybe_get_GET('post_status') === 'acfe-local')
194
- return array();
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
- return $sortable_columns;
197
 
198
- }, 99);
3
  if(!defined('ABSPATH'))
4
  exit;
5
 
6
+ if(!class_exists('ACFE_Field_Groups_Local')):
7
+
8
+ class ACFE_Field_Groups_Local{
 
 
9
 
10
+ var $view = '';
11
+ var $local_field_groups = array();
12
+ var $autosync_field_groups = array();
13
+ var $old_version = false;
14
+ var $acfe_admin_field_groups = '';
15
 
16
+ /*
17
+ * Construct
18
+ */
19
+ function __construct(){
20
+
21
+ // Actions
22
+ add_action('current_screen', array($this, 'current_screen'));
23
+
24
+ }
25
 
26
+ /*
27
+ * Current Screen
28
+ */
29
+ function current_screen(){
30
 
31
+ // Bail early if not Field Groups admin page.
32
+ if(!acf_is_screen('edit-acf-field-group'))
33
+ return;
34
+
35
+ // Old Compatibility
36
+ if(acf_version_compare(acf_get_setting('version'), '<', '5.9'))
37
+ $this->old_version = true;
38
 
39
+ // Get ACF instance
40
+ $this->acfe_admin_field_groups = acf_get_instance('ACFE_Field_Groups');
41
+ $this->view = $this->acfe_admin_field_groups->view;
42
 
43
+ // Hooks
44
+ add_filter('views_edit-acf-field-group', array($this, 'views'), 20);
45
 
46
+ if($this->view === 'acfe-local'){
47
+
48
+ add_filter('admin_footer', array($this, 'admin_footer'));
49
+ add_filter('bulk_actions-edit-acf-field-group', array($this, 'bulk_actions'));
50
+ add_filter('handle_bulk_actions-edit-acf-field-group', array($this, 'handle_bulk_actions'), 10, 3);
51
+
52
+ }
53
 
54
  }
55
 
56
+ /*
57
+ * Views
58
+ */
59
+ function views($views){
60
+
61
+ // Total
62
+ $count = count($this->get_local_field_groups());
63
+
64
+ // Bail early
65
+ if($count === 0)
66
+ return $views;
67
+
68
+ $views['acfe-local'] = sprintf(
69
+ '<a %s href="%s">%s <span class="count">(%s)</span></a>',
70
+ ($this->view === 'acfe-local' ? 'class="current"' : ''),
71
+ esc_url(admin_url('edit.php?post_type=acf-field-group&post_status=acfe-local')),
72
+ esc_html(__('Local', 'acf')),
73
+ $count
74
+ );
75
+
76
+ if($this->view === 'acfe-local'){
77
+
78
+ global $wp_list_table;
79
+
80
+ $wp_list_table->set_pagination_args(array(
81
+ 'total_items' => $count,
82
+ 'total_pages' => 1,
83
+ 'per_page' => $count
84
+ ));
85
+
86
+ }
87
+
88
+ return $views;
89
+
90
+ }
91
 
92
+ /*
93
+ * Admin Footer
94
+ */
95
+ function admin_footer(){
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  // vars
98
+ $i = -1;
99
+
100
+ $columns = array(
101
+ 'acfe-source',
102
+ 'acf-count',
103
+ 'acf-location',
104
+ 'acfe-load',
105
+ );
106
 
107
+ if($this->old_version){
108
+
109
+ $columns = array(
110
+ 'acfe-source',
111
+ 'acfe-count',
112
+ 'acfe-location',
113
+ 'acfe-load'
114
+ );
115
+
116
+ }
117
+
118
+ if(acf_get_setting('acfe/php'))
119
+ $columns[] = 'acfe-autosync-php';
120
+
121
+ if(acf_get_setting('json'))
122
+ $columns[] = 'acfe-autosync-json';
123
+
124
  ?>
125
+ <script type="text/html" id="tmpl-acfe-local-tbody">
126
+ <?php
127
+
128
+ foreach($this->local_field_groups as $field_group):
129
+
130
+ // vars
131
+ $i++;
132
+ $field_group['ID'] = 0;
133
+ $key = $field_group['key'];
134
+ $title = $field_group['title'];
135
 
136
+ if(isset($this->autosync_field_groups[$field_group['key']])){
 
 
 
 
 
 
137
 
138
+ $field_group['acfe_local_source'] = $this->autosync_field_groups[$field_group['key']];
 
 
139
 
140
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
+ ?>
143
+ <tr <?php if($i%2 == 0): ?>class="alternate"<?php endif; ?>>
144
+
145
+ <th class="check-column" data-colname="">
146
+ <label for="cb-select-<?php echo $field_group['key']; ?>" class="screen-reader-text"><?php echo esc_html( sprintf( __( 'Select %s', 'acf' ), $field_group['title'] ) ); ?></label>
147
+ <input id="cb-select-<?php echo $field_group['key']; ?>" type="checkbox" value="<?php echo $field_group['key']; ?>" name="post[]">
148
+ </th>
149
+
150
+ <td class="post-title page-title column-title">
151
+ <strong>
152
+ <span class="row-title"><?php echo esc_html($title); ?></span>
153
+ </strong>
154
+ <div class="row-actions">
155
+
156
+ <span>
157
+ <a href="<?php echo add_query_arg(array('action' => 'php', 'keys' => $key), acf_get_admin_tool_url('acfe-fg-local')); ?>">PHP</a> |
158
+ </span>
159
+
160
+ <span>
161
+ <a href="<?php echo add_query_arg(array('action' => 'json', 'keys' => $key), acf_get_admin_tool_url('acfe-fg-local')); ?>">Json</a> |
162
+ </span>
163
+
164
+ <span>
165
+ <a href="<?php echo add_query_arg(array('action' => 'sync', 'keys' => $key), acf_get_admin_tool_url('acfe-fg-local')); ?>">Sync to database</a> |
166
+ </span>
167
+
168
+ <span class="acfe-key">
169
+ <code><?php echo esc_html($key); ?></code>
170
+ </span>
171
 
172
+ </div>
173
+ </td>
174
+
175
+ <?php foreach($columns as $column): ?>
176
+ <td class="column-<?php echo esc_attr($column); ?>">
177
+
178
+ <?php
179
+
180
+ if($this->old_version){
181
 
182
+ $this->acfe_admin_field_groups->render_table_column($column, $field_group);
183
+
184
+ }else{
185
 
186
+ if(strpos($column, 'acfe') === 0){
187
+
188
+ $this->acfe_admin_field_groups->render_table_column($column, $field_group);
189
+
190
+ }else{
191
 
192
+ acf_get_instance('ACF_Admin_Field_Groups')->render_admin_table_column($column, $field_group);
193
+
194
+ }
195
+
196
+ }
197
+
198
+ ?>
199
+
200
+ </td>
201
+ <?php endforeach; ?>
202
+ </tr>
203
+ <?php endforeach; ?>
204
+ </script>
205
+
206
+ <script type="text/javascript">
207
+ (function($){
208
+
209
+ $('#the-list').html($('#tmpl-acfe-local-tbody').html());
210
+
211
+ })(jQuery);
212
+ </script>
213
+ <?php
214
 
215
+ }
216
+
217
+ /*
218
+ * Bulk Actions
219
+ */
220
+ function bulk_actions($actions){
221
 
222
+ $actions = array();
 
 
 
 
 
223
 
224
+ $actions['acfe_local_php'] = __( 'Export PHP', 'acf' );
225
+ $actions['acfe_local_json'] = __( 'Export Json', 'acf' );
226
+ $actions['acfe_local_sync'] = __( 'Sync to database', 'acf' );
227
 
228
+ return $actions;
229
 
230
  }
231
 
232
+ /*
233
+ * Handle Bulk Actions
234
+ */
235
+ function handle_bulk_actions($redirect, $action, $post_ids){
236
 
237
+ if(!isset($_REQUEST['post']) || empty($_REQUEST['post']))
238
+ return $redirect;
239
+
240
+ // PHP
241
+ if($action === 'acfe_local_php'){
242
 
243
+ $post_ids = $_REQUEST['post'];
244
+
245
+ $url = admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=acfe-fg-local&action=php&keys=' . implode('+', $post_ids));
246
+ wp_redirect($url);
247
+ exit;
248
+
249
+ }
250
+
251
+ // Json
252
+ elseif($action === 'acfe_local_json'){
253
+
254
+ $post_ids = $_REQUEST['post'];
255
 
256
+ $url = admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=acfe-fg-local&action=json&keys=' . implode('+', $post_ids));
257
+ wp_redirect($url);
258
+ exit;
259
+
260
+ }
261
 
262
+ // Sync DB
263
+ elseif($action === 'acfe_local_sync'){
264
 
265
+ $post_ids = $_REQUEST['post'];
 
266
 
267
+ $url = admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=acfe-fg-local&action=sync&keys=' . implode('+', $post_ids));
268
+ wp_redirect($url);
269
+ exit;
270
+
271
  }
272
 
273
+ return $redirect;
274
+
275
  }
276
 
277
+ function get_local_field_groups(){
278
+
279
+ $local_field_groups = acf_get_local_field_groups();
280
+
281
+ if(empty($local_field_groups))
282
+ return array();
283
+
284
+ $locals = array();
285
+
286
+ foreach($local_field_groups as $field_group){
287
+
288
+ // local PHP
289
+ if(acf_maybe_get($field_group, 'local') !== 'php')
290
+ continue;
291
+
292
+ // Exclude ACFE Field Groups
293
+ if(!acfe_is_super_dev() && stripos($field_group['key'], 'group_acfe_') === 0)
294
+ continue;
295
+
296
+ $locals[] = $field_group;
297
+
298
+ }
299
+
300
+ // Get desync PHP Field Groups
301
+ $desync_php_field_groups = acfe_get_desync_php_field_groups();
302
+
303
+ foreach($desync_php_field_groups as $file_key => $file_path){
304
+
305
+ require_once($file_path);
306
+
307
+ $this->autosync_field_groups[$file_key] = $file_path;
308
+ $locals[] = acf_get_field_group($file_key);
309
+
310
+ }
311
+
312
+ $order = 'ASC';
313
+ if(isset($_REQUEST['orderby']) && $_REQUEST['orderby'] === 'title' && isset($_REQUEST['order']) && $_REQUEST['order'] === 'desc')
314
+ $order = 'DESC';
315
+
316
+ // Sort Title ASC
317
+ if($order === 'ASC'){
318
+
319
+ usort($locals, function($a, $b){
320
+ return strcmp($a['title'], $b['title']);
321
+ });
322
+
323
+ }else{
324
+
325
+ usort($locals, function($a, $b){
326
+ return strcmp($b['title'], $a['title']);
327
+ });
328
+
329
+ }
330
+
331
+ $this->local_field_groups = $locals;
332
+
333
+ return $locals;
334
+
335
+ }
336
 
337
  }
338
 
339
+ acf_new_instance('ACFE_Field_Groups_Local');
 
 
 
 
 
 
 
 
 
 
340
 
341
+ endif;
 
 
 
 
 
 
 
342
 
343
+ function acfe_get_desync_php_field_groups(){
344
+
345
+ $file_field_groups = acfe_get_local_php_files();
346
+ $db_field_groups = acf_get_raw_field_groups();
347
 
348
+ foreach($file_field_groups as $file_key => $file_path){
349
+
350
+ foreach($db_field_groups as $db){
351
+
352
+ if($db['key'] === $file_key){
353
+
354
+ unset($file_field_groups[$file_key]);
355
+ break;
356
+
357
+ }
358
+
359
+ }
360
+
361
+ }
362
 
363
+ return (array) $file_field_groups;
364
 
365
+ }
includes/field-groups/field-groups.php CHANGED
@@ -3,409 +3,872 @@
3
  if(!defined('ABSPATH'))
4
  exit;
5
 
6
- /**
7
- * Display Title (post states)
8
- */
9
- add_filter('display_post_states', 'acfe_field_groups_states', 10, 2);
10
- function acfe_field_groups_states($states, $post){
11
-
12
- if(!acf_is_screen('edit-acf-field-group'))
13
- return $states;
14
-
15
- if(get_post_type($post->ID) != 'acf-field-group')
16
- return $states;
17
-
18
- $field_group = acf_get_field_group($post->ID);
19
-
20
- if(!$field_group || !isset($field_group['acfe_display_title']) || empty($field_group['acfe_display_title']))
21
- return $states;
22
-
23
- $states[] = $field_group['acfe_display_title'];
24
-
25
- return $states;
26
-
27
- }
28
 
29
- /**
30
- * Table Columns
31
- */
32
- add_filter('manage_edit-acf-field-group_columns', 'acfe_field_groups_column', 999);
33
- function acfe_field_groups_column($columns){
34
 
35
- // Locations
36
- if(acf_version_compare(acf_get_setting('version'), '<', '5.9')){
 
37
 
38
- $columns['acfe-locations'] = __('Locations');
 
 
 
 
 
 
 
39
 
40
  }
41
 
42
- if(acf_version_compare(acf_get_setting('version'), '<', '5.9')){
43
-
44
- // Load
45
- $columns['acfe-local'] = __('Load');
46
 
47
- }
 
 
 
 
 
 
 
 
 
48
 
49
- // PHP sync
50
- if(acf_get_setting('acfe/php')){
 
 
 
51
 
52
- $columns['acfe-autosync-php'] = __('PHP Sync');
 
 
 
53
 
54
- }
 
 
55
 
56
- if(acf_version_compare(acf_get_setting('version'), '>=', '5.9')){
 
 
 
 
57
 
58
- // Load
59
- $columns['acfe-local'] = __('Load');
 
 
 
 
60
 
61
  }
62
 
63
- // Json sync
64
- if(acf_get_setting('json') && acf_version_compare(acf_get_setting('version'), '<', '5.9')){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- $columns['acfe-autosync-json'] = __('Json Sync');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
- // Fix 'Sync' screen columns
71
- if(acf_maybe_get_GET('post_status') === 'sync'){
72
 
73
- unset($columns['acf-field-group-category']);
 
 
 
 
74
 
75
- unset($columns['acfe-locations']);
76
- unset($columns['acfe-local']);
77
 
78
- if(isset($columns['acfe-autosync-php']))
79
- unset($columns['acfe-autosync-php']);
 
 
 
80
 
81
- if(isset($columns['acfe-autosync-json']))
82
- unset($columns['acfe-autosync-json']);
83
 
84
  }
85
 
86
- // Fix 'Third party' screen columns
87
- elseif(acf_maybe_get_GET('post_status') === 'acfe-local'){
 
 
88
 
89
- $columns = array(
90
- 'title' => __('Title', 'acf'),
91
- 'acfe-source' => __('Source', 'acf'),
92
- 'acf-fg-count' => __('Fields', 'acf'),
93
- 'acfe-locations' => __('Locations', 'acf'),
94
- 'acfe-local' => __('Load', 'acf'),
95
- );
96
 
97
  }
98
 
99
- // Remove 'Field Group Category' column if there is no terms
100
- $categories = get_terms(array(
101
- 'taxonomy' => 'acf-field-group-category',
102
- 'hide_empty' => false,
103
- ));
104
 
105
- if(empty($categories) && isset($columns['acf-field-group-category']))
106
- unset($columns['acf-field-group-category']);
107
 
108
- return $columns;
 
109
 
110
- }
111
-
112
- /**
113
- * Table Columns HTML
114
- */
115
- add_action('manage_acf-field-group_posts_custom_column', 'acfe_field_groups_column_html', 10, 2);
116
- function acfe_field_groups_column_html($column, $post_id){
117
-
118
- /**
119
- * Count
120
- */
121
- if($column === 'acfe-count'){
122
 
123
- $field_group = acf_get_field_group($post_id);
124
- echo esc_html(acf_get_field_count($field_group));
125
 
126
- }
 
127
 
128
- /**
129
- * Count
130
- */
131
- elseif($column === 'acfe-source'){
132
 
133
- $field_group = acf_get_field_group($post_id);
 
 
 
 
 
134
 
135
- $source = false;
 
 
 
 
 
136
 
137
- // ACF Extended
138
- if(strpos($post_id, 'group_acfe_') === 0){
 
 
 
 
 
 
139
 
140
- $source = 'ACF Extended';
 
 
 
 
 
141
 
142
  }
143
 
144
- // Advanced Forms
145
- elseif($post_id === 'group_form_settings' || $post_id === 'group_entry_data'){
 
 
 
 
 
 
 
 
 
 
 
146
 
 
 
 
147
  $source = 'Advanced Forms';
148
-
149
- }
150
 
151
- else{
 
 
 
152
 
153
- $source = __('Local', 'acf');
154
 
155
  }
156
-
157
- $source = apply_filters('acfe/field_groups_third_party/source', $source, $post_id, $field_group);
158
-
159
- echo $source;
160
 
 
 
 
 
161
  }
162
 
163
- /**
164
- * Locations
165
  */
166
- elseif($column === 'acfe-locations'){
 
 
 
167
 
168
- $field_group = acf_get_field_group($post_id);
 
169
 
170
- acfe_render_field_group_locations_html($field_group);
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
  }
173
 
174
- /**
175
- * Load
176
  */
177
- elseif($column === 'acfe-local'){
178
-
179
- if(!$field_group = acf_get_field_group($post_id))
180
- return;
181
 
182
- $local_field_group = acf_get_local_field_group($field_group['key']);
183
- $local_field_group_type = acf_maybe_get($local_field_group, 'local', false);
 
184
 
185
- if($local_field_group_type === 'php'){
186
-
187
- echo '<span class="acf-js-tooltip" title="' . $field_group['key'] . ' is registered locally">php</span>';
 
188
 
189
- return;
 
190
 
191
  }
192
 
193
- elseif($local_field_group_type === 'json'){
194
-
195
- echo '<span class="acf-js-tooltip" title="' . $field_group['key'] . ' is registered locally">json</span>';
196
-
197
- return;
198
-
199
- }
200
 
201
- else{
 
 
 
 
202
 
203
- echo '<span class="acf-js-tooltip" title="' . $field_group['key'] . ' is not registered locally">DB</span>';
 
204
 
205
- return;
206
 
207
- }
 
 
 
 
 
 
 
208
 
209
  }
210
 
211
- /**
212
- * PHP sync
213
- */
214
- elseif($column === 'acfe-autosync-php'){
215
 
216
- if(!$field_group = acf_get_field_group($post_id))
217
- return;
 
 
 
 
 
 
 
 
 
 
 
218
 
219
- if(!acfe_has_field_group_autosync($field_group, 'php')){
 
220
 
221
- echo '<span style="color:#ccc" class="dashicons dashicons-no-alt"></span>';
222
 
223
- if(acfe_has_field_group_autosync_file($field_group, 'php')){
224
- echo '<span style="color:#ccc;font-size:16px;vertical-align:text-top;" class="acf-js-tooltip dashicons dashicons-warning" title="Field group: ' . $field_group['key'] . ' is registered via a third-party PHP code"></span>';
225
- }
226
 
227
- return;
 
 
 
228
 
229
- }
230
-
231
- if(!acf_get_setting('acfe/php_found')){
 
 
232
 
233
- echo '<span style="color:#ccc" class="dashicons dashicons-yes"></span>';
 
 
 
 
 
 
 
 
234
 
235
- echo '<span style="color:#ccc;font-size:16px;vertical-align:text-top;" class="acf-js-tooltip dashicons dashicons-warning" title="Folder \'/acfe-php\' was not found in your theme.<br />You must create it to activate this setting"></span>';
236
 
237
- }
238
-
239
- elseif(!acfe_has_field_group_autosync_file($field_group, 'php')){
240
 
241
- echo '<span style="color:#ccc" class="dashicons dashicons-yes"></span>';
242
- echo '<span style="color:#ccc;font-size:16px;vertical-align:text-top;" class="acf-js-tooltip dashicons dashicons-warning" title="Local file ' . $field_group['key'] . '.php will be created upon update"></span>';
 
 
 
 
 
243
 
 
 
 
 
 
 
 
 
244
  }
245
 
246
- else{
 
 
 
 
247
 
248
- echo '<span class="dashicons dashicons-yes"></span>';
 
249
 
250
  }
251
 
 
 
252
  }
253
 
254
- /**
255
- * Json sync
256
  */
257
- elseif($column === 'acfe-autosync-json'){
258
-
259
- if(!$field_group = acf_get_field_group($post_id))
260
- return;
 
 
 
 
 
 
 
 
 
 
 
261
 
262
- if(acfe_has_field_group_autosync_file($field_group, 'json')){
 
 
 
 
 
 
 
 
 
 
 
263
 
264
- echo '<span class="dashicons dashicons-yes"></span>';
265
 
266
- }
 
 
 
 
 
 
 
267
 
268
- else{
 
 
269
 
270
- if(!acfe_has_field_group_autosync($field_group, 'json')){
271
-
272
- echo '<span style="color:#ccc" class="dashicons dashicons-no-alt"></span>';
273
-
274
- }else{
 
 
 
 
 
 
 
 
 
 
 
 
 
275
 
276
- echo '<span style="color:#ccc" class="dashicons dashicons-yes"></span>';
 
277
 
278
- if(!acf_get_setting('acfe/json_found')){
279
-
280
- echo '<span style="color:#ccc;font-size:16px;vertical-align:text-top;" class="acf-js-tooltip dashicons dashicons-warning" title="Folder \'/acf-json\' was not found in your theme.<br />You must create it to activate this setting"></span>';
281
 
282
- }
283
-
284
- else{
285
 
286
- echo '<span style="color:#ccc;font-size:16px;vertical-align:text-top;" class="acf-js-tooltip dashicons dashicons-warning" title="Local file ' . $field_group['key'] . '.json will be created upon update."></span>';
 
 
 
 
 
 
 
 
 
287
 
288
  }
 
 
 
 
 
 
 
 
289
 
 
 
 
 
 
 
 
290
 
291
-
 
 
 
 
 
 
 
292
  }
293
 
294
- }
295
-
296
- }
297
- }
298
-
299
- /**
300
- * Table Row Actions
301
- */
302
- add_filter('page_row_actions', 'hwk_post_type_exemple_row_actions', 10, 2);
303
- function hwk_post_type_exemple_row_actions($actions, $post){
304
 
305
- if(!isset($post->post_type) || $post->post_type != 'acf-field-group')
306
- return $actions;
 
 
 
 
 
307
 
308
- $field_group = acf_get_field_group($post->ID);
 
 
309
 
310
- $actions['acfe-export-php'] = '<a href="' . admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=export&action=php&keys=' . $field_group['key']) . '">PHP</a>';
311
- $actions['acfe-export-json'] = '<a href="' . admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=export&action=json&keys=' . $field_group['key']) . '">Json</a>';
 
 
 
 
 
312
 
313
- if(acf_version_compare(acf_get_setting('version'), '<', '5.9')){
 
 
 
 
 
 
314
 
315
- $actions['acfe-key'] = '<span style="color:#555;"><code style="font-size: 12px;">' . $field_group['key'] . '</code></span>';
 
 
 
 
 
 
 
 
 
 
 
316
 
317
  }
318
 
319
- //$actions['acfe-id'] = '<span style="color:#555;">ID: ' . $field_group['ID'] . '</span>';
 
 
 
 
 
 
 
 
 
320
 
321
- return $actions;
 
 
 
 
 
 
 
322
 
323
- }
324
-
325
- /**
326
- * Sidebar
327
- */
328
- add_action('current_screen', function(){
 
 
 
 
 
 
 
 
 
329
 
330
- if(!acf_is_screen('edit-acf-field-group'))
331
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
 
333
- add_action('admin_footer', function(){
 
 
 
 
 
334
 
335
- $categories = get_terms(array(
336
- 'taxonomy' => 'acf-field-group-category',
337
- 'hide_empty' => false,
338
- ));
339
 
340
- $cols = !empty($categories) ? 9 : 8;
 
 
 
 
341
 
342
- ?>
343
 
 
 
 
 
 
 
 
 
344
  <!-- ACFE: Label -->
345
  <script type="text/html" id="tmpl-acfe-label">
346
  <span style="word-wrap: break-word;padding: 2px 6px;margin-left:1px;border-radius:2px;background:#ca4a1f;color: #fff; font-size: 14px;vertical-align: text-bottom;font-style: italic;">Extended</span>
347
  </script>
348
-
349
  <!-- ACFE: Debug -->
350
  <script type="text/html" id="tmpl-acfe-debug">
351
  <div class="acf-box">
 
352
  </div>
353
  </script>
354
-
355
  <script type="text/javascript">
356
- (function($){
357
-
358
- // ACFE: Label
359
- $('.acf-column-2 > .acf-box > .inner > h2').append($('#tmpl-acfe-label').html());
360
-
361
- // ACFE: Debug
362
- //$('#posts-filter').append($('#tmpl-acfe-debug').html());
363
-
364
- // Fix no field groups found
365
- $('#the-list tr.no-items td').attr('colspan', $('.wp-list-table > thead > tr > .manage-column:visible').length);
366
-
367
- })(jQuery);
368
  </script>
369
  <?php
370
- });
371
 
372
- });
373
-
374
- /**
375
- * Hooks: Posts per page
376
- */
377
- add_filter('edit_acf-field-group_per_page', 'acfe_field_groups_posts_per_page');
378
- function acfe_field_groups_posts_per_page(){
 
 
 
 
379
 
380
- return 999;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
 
382
- }
383
-
384
- add_action('acf/add_meta_boxes', 'acfe_field_groups_seamless', 10, 3);
385
- function acfe_field_groups_seamless($post_type, $post, $field_groups){
 
 
 
 
 
 
 
 
 
 
 
 
386
 
387
- foreach($field_groups as $field_group){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
388
 
389
- add_filter("postbox_classes_{$post_type}_acf-{$field_group['key']}", function($classes) use($field_group){
 
 
 
390
 
391
- $classes[] = 'acf-postbox';
392
 
393
- // Seamless
394
- if($field_group['style'] === 'seamless')
395
- $classes[] = 'seamless';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
 
397
- // Left
398
- if($field_group['label_placement'] === 'left')
399
- $classes[] = 'acfe-postbox-left';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
 
401
- // Top
402
- if($field_group['label_placement'] === 'top')
403
- $classes[] = 'acfe-postbox-top';
404
 
405
- return $classes;
 
 
 
 
 
406
 
407
- });
 
 
408
 
409
  }
410
 
411
- }
 
 
 
 
3
  if(!defined('ABSPATH'))
4
  exit;
5
 
6
+ if(!class_exists('ACFE_Field_Groups')):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ class ACFE_Field_Groups{
 
 
 
 
9
 
10
+ var $view = '';
11
+ var $sync = '';
12
+ var $old_version = false;
13
 
14
+ /*
15
+ * Construct
16
+ */
17
+ function __construct(){
18
+
19
+ // Actions
20
+ add_action('current_screen', array($this, 'current_screen'));
21
+ add_action('acf/add_meta_boxes', array($this, 'seamless_metabox'), 10, 3);
22
 
23
  }
24
 
25
+ /*
26
+ * Current Screen
27
+ */
28
+ function current_screen(){
29
 
30
+ // Bail early if not Field Groups admin page.
31
+ if(!acf_is_screen('edit-acf-field-group'))
32
+ return;
33
+
34
+ // Old Compatibility
35
+ if(acf_version_compare(acf_get_setting('version'), '<', '5.9'))
36
+ $this->old_version = true;
37
+
38
+ // ACF < 5.9
39
+ if($this->old_version){
40
 
41
+ $this->view = isset($_GET['post_status']) ? sanitize_text_field($_GET['post_status']) : '';
42
+ $this->sync = $this->get_sync_compatibility();
43
+
44
+ // ACF >= 5.9
45
+ }else{
46
 
47
+ $this->view = acf_get_instance('ACF_Admin_Field_Groups')->view;
48
+ $this->sync = acf_get_instance('ACF_Admin_Field_Groups')->sync;
49
+
50
+ }
51
 
52
+ // Hooks
53
+ add_filter('manage_edit-acf-field-group_columns', array($this, 'table_columns'), 20);
54
+ add_action('manage_acf-field-group_posts_custom_column', array($this, 'table_columns_html'), 10, 2);
55
 
56
+ add_filter('default_hidden_columns', array($this, 'default_hidden_columns'), 10, 2);
57
+ add_filter('edit_acf-field-group_per_page', array($this, 'posts_per_page'));
58
+ add_filter('page_row_actions', array($this, 'row_actions'), 20, 2);
59
+ add_filter('display_post_states', array($this, 'post_states'), 20, 2);
60
+ add_action('admin_footer', array($this, 'admin_footer'));
61
 
62
+ if($this->view !== 'sync'){
63
+
64
+ add_filter('bulk_actions-edit-acf-field-group', array($this, 'bulk_actions'));
65
+ add_filter('handle_bulk_actions-edit-acf-field-group', array($this, 'handle_bulk_actions'), 10, 3);
66
+
67
+ }
68
 
69
  }
70
 
71
+ /*
72
+ * Table Columns
73
+ */
74
+ function table_columns($columns){
75
+
76
+ switch($this->view){
77
+
78
+ // View: Sync
79
+ case('sync'):
80
+
81
+ acfe_unset($columns, 'acf-field-group-category');
82
+
83
+ break;
84
+
85
+ // View: Local
86
+ case('acfe-local'):
87
+
88
+ if($this->old_version){
89
+
90
+ $columns = array(
91
+ 'cb' => '<input type="checkbox" />',
92
+ 'title' => __('Title', 'acf'),
93
+ 'acfe-source' => __('Source', 'acf'),
94
+ 'acf-count' => __('Fields', 'acf'),
95
+ 'acfe-location' => __('Location', 'acf'),
96
+ 'acfe-load' => __('Load', 'acf'),
97
+ );
98
+
99
+ }else{
100
+
101
+ $columns = array(
102
+ 'cb' => '<input type="checkbox" />',
103
+ 'title' => __('Title', 'acf'),
104
+ 'acfe-source' => __('Source', 'acf'),
105
+ 'acf-count' => __('Fields', 'acf'),
106
+ 'acf-location' => __('Location', 'acf'),
107
+ 'acfe-load' => __('Load', 'acf'),
108
+ );
109
+
110
+ }
111
+
112
+ if(acf_get_setting('acfe/php'))
113
+ $columns['acfe-autosync-php'] = __('PHP Sync');
114
 
115
+ if(acf_get_setting('json'))
116
+ $columns['acfe-autosync-json'] = __('Json Sync', 'acf');
117
+
118
+ break;
119
+
120
+ // View: Active/Trash
121
+ default:
122
+
123
+ // ACF < 5.9
124
+ if($this->old_version){
125
+
126
+ acfe_unset($columns, 'acf-fg-status');
127
+
128
+ $columns['acfe-location'] = __('Location', 'acf');
129
+ $columns['acfe-load'] = __('Load', 'acf');
130
 
131
+ if(acf_get_setting('acfe/php'))
132
+ $columns['acfe-autosync-php'] = __('PHP');
133
+
134
+ if(acf_get_setting('json'))
135
+ $columns['acfe-autosync-json'] = __('Json');
136
+
137
+ // ACF >= 5.9
138
+ }else{
139
+
140
+ // Re-order
141
+ acfe_unset($columns, 'acf-key');
142
+ acfe_unset($columns, 'acf-location');
143
+ acfe_unset($columns, 'acf-count');
144
+ acfe_unset($columns, 'acf-json');
145
+
146
+ $columns['acf-count'] = __('Fields', 'acf');
147
+ $columns['acf-location'] = __('Location', 'acf');
148
+
149
+ $columns['acfe-load'] = __('Load', 'acf');
150
+
151
+ if(acf_get_setting('acfe/php'))
152
+ $columns['acfe-autosync-php'] = __('PHP');
153
+
154
+ if(acf_get_setting('json'))
155
+ $columns['acfe-autosync-json'] = __('Json', 'acf');
156
+
157
+ }
158
 
159
+ // Remove Category column if empty
160
+ if(isset($columns['acf-field-group-category'])){
161
 
162
+ $categories_count = get_terms(array(
163
+ 'taxonomy' => 'acf-field-group-category',
164
+ 'hide_empty' => false,
165
+ 'fields' => 'count'
166
+ ));
167
 
168
+ if(empty($categories_count))
169
+ unset($columns['acf-field-group-category']);
170
 
171
+ }
172
+
173
+ break;
174
+
175
+ }
176
 
177
+ return $columns;
 
178
 
179
  }
180
 
181
+ /*
182
+ * Table Columns HTML
183
+ */
184
+ function table_columns_html($column, $post_id){
185
 
186
+ $field_group = acf_get_field_group($post_id);
187
+
188
+ if(!$field_group)
189
+ return;
190
+
191
+ $this->render_table_column($column, $field_group);
 
192
 
193
  }
194
 
195
+ function render_table_column($column, $field_group){
 
 
 
 
196
 
197
+ switch($column){
 
198
 
199
+ // Source
200
+ case 'acfe-source':
201
 
202
+ $this->render_admin_table_column_source_html($field_group);
 
 
 
 
 
 
 
 
 
 
 
203
 
204
+ break;
 
205
 
206
+ // Count
207
+ case 'acfe-count':
208
 
209
+ echo esc_html( acf_get_field_count($field_group));
 
 
 
210
 
211
+ break;
212
+
213
+ // Location
214
+ case 'acfe-location':
215
+
216
+ acfe_render_field_group_locations_html($field_group);
217
 
218
+ break;
219
+
220
+ // Load
221
+ case 'acfe-load':
222
+
223
+ $this->render_admin_table_column_load_html($field_group);
224
 
225
+ break;
226
+
227
+ // PHP Sync
228
+ case 'acfe-autosync-php':
229
+
230
+ $this->render_admin_table_column_php_html($field_group);
231
+
232
+ break;
233
 
234
+ // New Json Sync
235
+ case 'acfe-autosync-json':
236
+
237
+ $this->render_admin_table_column_json_html($field_group);
238
+
239
+ break;
240
 
241
  }
242
 
243
+ }
244
+
245
+ /*
246
+ * Column: Source
247
+ */
248
+ function render_admin_table_column_source_html($field_group){
249
+
250
+ $source = __('Theme/Plugin', 'acf');
251
+
252
+ // ACF Extended
253
+ if(strpos($field_group['key'], 'group_acfe_') === 0){
254
+
255
+ $source = 'ACF Extended';
256
 
257
+ // Advanced Forms
258
+ }elseif($field_group['key'] === 'group_form_settings' || $field_group['key'] === 'group_entry_data'){
259
+
260
  $source = 'Advanced Forms';
 
 
261
 
262
+ }elseif(acf_maybe_get($field_group, 'acfe_local_source')){
263
+
264
+ $file = acf_maybe_get($field_group, 'acfe_local_source');
265
+ $file_readable = $this->get_human_readable_file_location($file);
266
 
267
+ $source = '<span class="acf-js-tooltip" title="' . $file_readable . '">AutoSync</span>';
268
 
269
  }
 
 
 
 
270
 
271
+ $source = apply_filters('acfe/field_groups_third_party/source', $source, $field_group['key'], $field_group);
272
+
273
+ echo $source;
274
+
275
  }
276
 
277
+ /*
278
+ * Column: Load
279
  */
280
+ function render_admin_table_column_load_html($field_group){
281
+
282
+ $php = acfe_get_local_php_files();
283
+ $local_field_group = acf_get_local_field_group($field_group['key']);
284
 
285
+ // PHP
286
+ if(isset($php[$field_group['key']]) || acf_maybe_get($local_field_group, 'local') === 'php'){
287
 
288
+ echo '<span>php</span>';
289
+
290
+ // Json
291
+ }elseif(acf_maybe_get($local_field_group, 'local') === 'json'){
292
+
293
+ echo '<span>Json</span>';
294
+
295
+ // DB
296
+ }else{
297
+
298
+ echo '<span>DB</span>';
299
+
300
+ }
301
 
302
  }
303
 
304
+ /*
305
+ * Column: PHP Sync HTML
306
  */
307
+ function render_admin_table_column_php_html($field_group){
308
+
309
+ $return = $this->get_php_data($field_group);
 
310
 
311
+ $wrapper = array(
312
+ 'class' => ''
313
+ );
314
 
315
+ if($return['class'])
316
+ $wrapper['class'] = $return['class'];
317
+
318
+ if($return['message']){
319
 
320
+ $wrapper['class'] .= ' acf-js-tooltip';
321
+ $wrapper['title'] = $return['message'];
322
 
323
  }
324
 
325
+ $icons = array();
 
 
 
 
 
 
326
 
327
+ if($return['icon'])
328
+ $icons[] = '<span class="dashicons dashicons-' . $return['icon'] . '"></span>';
329
+
330
+ if($return['warning'])
331
+ $icons[] = '<span class="dashicons dashicons-warning"></span>';
332
 
333
+ ?>
334
+ <span <?php echo acf_esc_atts($wrapper); ?>>
335
 
336
+ <?php if($return['wrapper_start']){ echo $return['wrapper_start']; } ?>
337
 
338
+ <?php if(!empty($icons)){ ?>
339
+ <?php echo implode('', $icons); ?>
340
+ <?php } ?>
341
+
342
+ <?php if($return['wrapper_end']){ echo $return['wrapper_end']; } ?>
343
+
344
+ </span>
345
+ <?php
346
 
347
  }
348
 
349
+ function get_php_data($field_group){
 
 
 
350
 
351
+ $return = array(
352
+ 'message' => false,
353
+ 'file' => false,
354
+ 'wrapper_start' => '',
355
+ 'wrapper_end' => '',
356
+ 'class' => false,
357
+ 'warning' => false,
358
+ 'icon' => false,
359
+ );
360
+
361
+ $php = acfe_get_local_php_files();
362
+
363
+ if(isset($php[$field_group['key']])){
364
 
365
+ $file = $php[$field_group['key']];
366
+ $file_readable = $this->get_human_readable_file_location($file);
367
 
368
+ $local_field_group = acf_get_local_field_group($field_group['key']);
369
 
370
+ if(acf_maybe_get($local_field_group, 'local') === 'php'){
 
 
371
 
372
+ $return['message'] = __('Synchronized', 'acf') . '. ' . $file_readable . '<br/><br/>' . __('Warning: Duplicated PHP code found in theme/plugin.', 'acf');
373
+ $return['file'] = $file_readable . '<br/><br/>' . __('Warning: Duplicated PHP code found in theme/plugin.', 'acf');
374
+ $return['icon'] = 'yes';
375
+ $return['warning'] = true;
376
 
377
+ }else{
378
+
379
+ $return['message'] = __('Synchronized', 'acf') . '. ' . $file_readable;
380
+ $return['file'] = $file_readable;
381
+ $return['icon'] = 'yes';
382
 
383
+ }
384
+
385
+ }else{
386
+
387
+ $path = untrailingslashit(acf_get_setting('acfe/php_save'));
388
+
389
+ $path = apply_filters("acfe/settings/php_save/all", $path, $field_group);
390
+ $path = apply_filters("acfe/settings/php_save/ID={$field_group['ID']}", $path, $field_group);
391
+ $path = apply_filters("acfe/settings/php_save/key={$field_group['key']}", $path, $field_group);
392
 
393
+ $found = (bool) is_dir($path) && wp_is_writable($path);
394
 
395
+ $folder = $this->get_human_readable_file_location($path, $found, false);
 
 
396
 
397
+ if(acfe_has_php_sync($field_group)){
398
+
399
+ $return['message'] = __('Awaiting save', 'acf') . '. <br />' . __('Save path', 'acf') . ' ' . lcfirst($folder);
400
+ $return['file'] = __('Save path', 'acf') . ' ' . lcfirst($folder);
401
+ $return['class'] = 'secondary';
402
+ $return['icon'] = 'yes';
403
+ $return['warning'] = true;
404
 
405
+ }else{
406
+
407
+ $return['file'] = __('Save path', 'acf') . ' ' . lcfirst($folder);
408
+ $return['class'] = 'secondary';
409
+ $return['icon'] = 'no-alt';
410
+
411
+ }
412
+
413
  }
414
 
415
+ if($this->view === 'acfe-local'){
416
+
417
+ $return['message'] = false;
418
+ $return['warning'] = false;
419
+ $return['class'] = false;
420
 
421
+ if($return['icon'] !== 'yes')
422
+ $return['class'] = 'secondary';
423
 
424
  }
425
 
426
+ return $return;
427
+
428
  }
429
 
430
+ /*
431
+ * Column: Json Sync HTML
432
  */
433
+ function render_admin_table_column_json_html($field_group){
434
+
435
+ $return = $this->get_json_data($field_group);
436
+
437
+ $wrapper = array(
438
+ 'class' => ''
439
+ );
440
+
441
+ if($return['class'])
442
+ $wrapper['class'] = $return['class'];
443
+
444
+ if($return['message']){
445
+
446
+ $wrapper['class'] .= ' acf-js-tooltip';
447
+ $wrapper['title'] = $return['message'];
448
 
449
+ }
450
+
451
+ $icons = array();
452
+
453
+ if($return['icon'])
454
+ $icons[] = '<span class="dashicons dashicons-' . $return['icon'] . '"></span>';
455
+
456
+ if($return['warning'])
457
+ $icons[] = '<span class="dashicons dashicons-warning"></span>';
458
+
459
+ ?>
460
+ <span <?php echo acf_esc_atts($wrapper); ?>>
461
 
462
+ <?php if($return['wrapper_start']){ echo $return['wrapper_start']; } ?>
463
 
464
+ <?php if(!empty($icons)){ ?>
465
+ <?php echo implode('', $icons); ?>
466
+ <?php } ?>
467
+
468
+ <?php if($return['wrapper_end']){ echo $return['wrapper_end']; } ?>
469
+
470
+ </span>
471
+ <?php
472
 
473
+ }
474
+
475
+ function get_json_data($field_group){
476
 
477
+ $return = array(
478
+ 'message' => false,
479
+ 'file' => false,
480
+ 'wrapper_start' => false,
481
+ 'wrapper_end' => false,
482
+ 'class' => false,
483
+ 'warning' => false,
484
+ 'icon' => false,
485
+ );
486
+
487
+ $json = acf_get_local_json_files();
488
+
489
+ if(isset($json[$field_group['key']])){
490
+
491
+ $file = $json[$field_group['key']];
492
+ $file_readable = $this->get_human_readable_file_location($file);
493
+
494
+ if(isset($this->sync[$field_group['key']])){
495
 
496
+ // vars
497
+ $nonce = wp_create_nonce('bulk-posts');
498
 
499
+ if($this->old_version){
 
 
500
 
501
+ $url = admin_url('edit.php?post_type=acf-field-group&post_status=sync&acfsync=' . $field_group['key'] . '&_wpnonce=' . $nonce );
502
+ $text = $field_group['ID'] ? __('Sync', 'acf') : __('Import', 'acf');
 
503
 
504
+ $wrapper_start = '<a href="' . esc_url($url) . '">';
505
+ $wrapper_end = '<div class="row-actions"><span class="review" style="color:#006799;">' . $text . '</span></div></a>';
506
+
507
+ }else{
508
+
509
+ $url = admin_url('edit.php?post_type=acf-field-group&acfsync=' . $field_group['key'] . '&_wpnonce=' . $nonce);
510
+ $text = $field_group['ID'] ? __('Review', 'acf') : __('Import', 'acf');
511
+
512
+ $wrapper_start = '<a href="#" data-event="review-sync" data-id="' . esc_attr($field_group['ID']) . '" data-href="' . esc_url($url) . '">';
513
+ $wrapper_end = '<div class="row-actions"><span class="review" style="color:#006799;">' . $text . '</span></div></a>';
514
 
515
  }
516
+
517
+ if($field_group['ID']){
518
+
519
+ $return['message'] = __('Sync available', 'acf') . '. ' . $file_readable;
520
+ $return['file'] = $file_readable;
521
+ $return['icon'] = 'update';
522
+ $return['wrapper_start'] = $wrapper_start;
523
+ $return['wrapper_end'] = $wrapper_end;
524
 
525
+ }else{
526
+
527
+ $return['message'] = __('Sync available', 'acf') . '. ' . $file_readable;
528
+ $return['file'] = $file_readable;
529
+ $return['icon'] = 'update';
530
+ $return['wrapper_start'] = $wrapper_start;
531
+ $return['wrapper_end'] = $wrapper_end;
532
 
533
+ }
534
+
535
+ }else{
536
+
537
+ $return['message'] = __('Synchronized', 'acf') . '. ' . $file_readable;
538
+ $return['file'] = $file_readable;
539
+ $return['icon'] = 'yes';
540
+
541
  }
542
 
543
+ }else{
 
 
 
 
 
 
 
 
 
544
 
545
+ $path = untrailingslashit(acf_get_setting('save_json'));
546
+
547
+ $path = apply_filters("acfe/settings/json_save/all", $path, $field_group);
548
+ $path = apply_filters("acfe/settings/json_save/ID={$field_group['ID']}", $path, $field_group);
549
+ $path = apply_filters("acfe/settings/json_save/key={$field_group['key']}", $path, $field_group);
550
+
551
+ $found = (bool) is_dir($path) && wp_is_writable($path);
552
 
553
+ $folder = $this->get_human_readable_file_location($path, $found, false);
554
+
555
+ if(acfe_has_json_sync($field_group)){
556
 
557
+ $return['message'] = __('Awaiting save', 'acf') . '. <br />' . __('Save path', 'acf') . ' ' . lcfirst($folder);
558
+ $return['file'] = __('Save path', 'acf') . ' ' . lcfirst($folder);
559
+ $return['class'] = 'secondary';
560
+ $return['icon'] = 'yes';
561
+ $return['warning'] = 'true';
562
+
563
+ }else{
564
 
565
+ $return['file'] = __('Save path', 'acf') . ' ' . lcfirst($folder);
566
+ $return['class'] = 'secondary';
567
+ $return['icon'] = 'no-alt';
568
+
569
+ }
570
+
571
+ }
572
 
573
+ if($this->view === 'acfe-local'){
574
+
575
+ $return['message'] = false;
576
+ $return['warning'] = false;
577
+ $return['class'] = false;
578
+
579
+ if($return['icon'] !== 'yes')
580
+ $return['class'] = 'secondary';
581
+
582
+ }
583
+
584
+ return $return;
585
 
586
  }
587
 
588
+ /*
589
+ * Hide Default Columns
590
+ */
591
+ function default_hidden_columns($hidden, $screen){
592
+
593
+ $hidden[] = 'acf-description';
594
+
595
+ return $hidden;
596
+
597
+ }
598
 
599
+ /*
600
+ * Posts Per Page
601
+ */
602
+ function posts_per_page(){
603
+
604
+ return 999;
605
+
606
+ }
607
 
608
+ /*
609
+ * Row Actions
610
+ */
611
+ function row_actions($actions, $post){
612
+
613
+ $field_group = acf_get_field_group($post->ID);
614
+
615
+ $actions['acfe-export-php'] = '<a href="' . admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=export&action=php&keys=' . $field_group['key']) . '">PHP</a>';
616
+ $actions['acfe-export-json'] = '<a href="' . admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=export&action=json&keys=' . $field_group['key']) . '">Json</a>';
617
+ $actions['acfe-key'] = '<code>' . $field_group['key'] . '</code>';
618
+ //$actions['acfe-id'] = '<span style="color:#555;">ID: ' . $field_group['ID'] . '</span>';
619
+
620
+ return $actions;
621
+
622
+ }
623
 
624
+ /*
625
+ * Post States
626
+ */
627
+ function post_states($states, $post){
628
+
629
+ // Vars
630
+ $field_group = acf_get_field_group($post->ID);
631
+
632
+ // ACF < 5.9
633
+ if($this->old_version){
634
+
635
+ // Disabled
636
+ if($post->post_status === 'acf-disabled'){
637
+
638
+ $states['acf-disabled'] = '<span class="dashicons dashicons-hidden acf-js-tooltip" title="' . _x('Disabled', 'post status', 'acf') . '"></span>';
639
+
640
+ }
641
+
642
+ // ACF > 5.9
643
+ }else{
644
+
645
+ if(isset($states['acf-disabled'])){
646
 
647
+ unset($states['acf-disabled']);
648
+ $states['acf-disabled'] = '<span class="dashicons dashicons-hidden acf-js-tooltip" title="' . _x('Disabled', 'post status', 'acf') . '"></span>';
649
+
650
+ }
651
+
652
+ }
653
 
654
+ // Alternative Title
655
+ $display_title = acf_maybe_get($field_group, 'acfe_display_title');
 
 
656
 
657
+ if(!empty($display_title)){
658
+
659
+ $states['acfe-title'] = '<span class="acf-js-tooltip" title="' . __('Alternative title', 'acf') . '">' . $display_title . '</span>';
660
+
661
+ }
662
 
663
+ return $states;
664
 
665
+ }
666
+
667
+ /*
668
+ * Admin Footer
669
+ */
670
+ function admin_footer(){
671
+ ?>
672
+
673
  <!-- ACFE: Label -->
674
  <script type="text/html" id="tmpl-acfe-label">
675
  <span style="word-wrap: break-word;padding: 2px 6px;margin-left:1px;border-radius:2px;background:#ca4a1f;color: #fff; font-size: 14px;vertical-align: text-bottom;font-style: italic;">Extended</span>
676
  </script>
677
+
678
  <!-- ACFE: Debug -->
679
  <script type="text/html" id="tmpl-acfe-debug">
680
  <div class="acf-box">
681
+
682
  </div>
683
  </script>
684
+
685
  <script type="text/javascript">
686
+ (function($){
687
+
688
+ // ACFE: Label
689
+ $('.acf-column-2 > .acf-box > .inner > h2').append($('#tmpl-acfe-label').html());
690
+
691
+ // ACFE: Debug
692
+ //$('#posts-filter').append($('#tmpl-acfe-debug').html());
693
+
694
+ // Fix no field groups found
695
+ $('#the-list tr.no-items td').attr('colspan', $('.wp-list-table > thead > tr > .manage-column:visible').length);
696
+
697
+ })(jQuery);
698
  </script>
699
  <?php
700
+ }
701
 
702
+ /*
703
+ * Bulk Actions
704
+ */
705
+ function bulk_actions($actions){
706
+
707
+ $actions['acfe_php'] = __( 'Export PHP', 'acf' );
708
+ $actions['acfe_json'] = __( 'Export Json', 'acf' );
709
+
710
+ return $actions;
711
+
712
+ }
713
 
714
+ /*
715
+ * Handle Bulk Actions
716
+ */
717
+ function handle_bulk_actions($redirect, $action, $post_ids){
718
+
719
+ if(!isset($_REQUEST['post']) || empty($_REQUEST['post']))
720
+ return $redirect;
721
+
722
+ // PHP
723
+ if($action === 'acfe_php'){
724
+
725
+ $post_ids = $_REQUEST['post'];
726
+
727
+ foreach($post_ids as &$post_id){
728
+
729
+ $field_group = acf_get_field_group($post_id);
730
+ $post_id = $field_group['key'];
731
+
732
+ }
733
+
734
+ $url = admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=export&action=php&keys=' . implode('+', $post_ids));
735
+ wp_redirect($url);
736
+ exit;
737
+
738
+ }
739
+
740
+ // Json
741
+ elseif($action === 'acfe_json'){
742
+
743
+ $post_ids = $_REQUEST['post'];
744
 
745
+ foreach($post_ids as &$post_id){
746
+
747
+ $field_group = acf_get_field_group($post_id);
748
+ $post_id = $field_group['key'];
749
+
750
+ }
751
+
752
+ $url = admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=export&action=json&keys=' . implode('+', $post_ids));
753
+ wp_redirect($url);
754
+ exit;
755
+
756
+ }
757
+
758
+ return $redirect;
759
+
760
+ }
761
 
762
+ /*
763
+ * Helper: Human Readable File
764
+ */
765
+ function get_human_readable_file_location($file, $found = true, $br = true, $prefix = true){
766
+
767
+ // Generate friendly file path.
768
+ $theme_path = get_stylesheet_directory();
769
+ $located = '';
770
+
771
+ if( strpos($file, $theme_path) !== false ) {
772
+ $rel_file = str_replace( $theme_path, '', $file );
773
+
774
+ if($prefix){
775
+ $located .= __($found ? 'Located' : 'Not found', 'acf');
776
+ }
777
+
778
+ $located .= ' ' . __('in theme:', 'acf') . (($br) ? "<br/>" : ' ');
779
+ $located .= $rel_file;
780
+
781
+ } elseif( strpos($file, WP_PLUGIN_DIR) !== false ) {
782
+ $rel_file = str_replace( WP_PLUGIN_DIR, '', $file );
783
+
784
+ if($prefix){
785
+ $located .= __($found ? 'Located' : 'Not found', 'acf');
786
+ }
787
+
788
+ $located .= ' ' . __('in plugin:', 'acf') . (($br) ? "<br/>" : ' ');
789
+ $located .= $rel_file;
790
+
791
+ } else {
792
+ $rel_file = str_replace( ABSPATH, '', $file );
793
+
794
+ if($prefix){
795
+ $located .= __($found ? 'Located' : 'Not found', 'acf');
796
+ }
797
+
798
+ $located .= ' ' . __('in:', 'acf') . (($br) ? "<br/>" : ' ');
799
+ $located .= $rel_file;
800
+ }
801
+
802
+ return $located;
803
+
804
+ }
805
 
806
+ /*
807
+ * Seamless Metabox
808
+ */
809
+ function seamless_metabox($post_type, $post, $field_groups){
810
 
811
+ foreach($field_groups as $field_group){
812
 
813
+ add_filter("postbox_classes_{$post_type}_acf-{$field_group['key']}", function($classes) use($field_group){
814
+
815
+ $classes[] = 'acf-postbox';
816
+
817
+ // Seamless
818
+ if($field_group['style'] === 'seamless')
819
+ $classes[] = 'seamless';
820
+
821
+ // Left
822
+ if($field_group['label_placement'] === 'left')
823
+ $classes[] = 'acfe-postbox-left';
824
+
825
+ // Top
826
+ if($field_group['label_placement'] === 'top')
827
+ $classes[] = 'acfe-postbox-top';
828
+
829
+ return $classes;
830
+
831
+ });
832
 
833
+ }
834
+
835
+ }
836
+
837
+ function get_sync_compatibility(){
838
+
839
+ $sync = array();
840
+
841
+ if(!acf_get_local_json_files())
842
+ return $sync;
843
+
844
+ $field_groups = acf_get_field_groups();
845
+
846
+ foreach($field_groups as $field_group){
847
+
848
+ // Vars
849
+ $local = acf_maybe_get($field_group, 'local');
850
+ $modified = acf_maybe_get($field_group, 'modified');
851
+ $private = acf_maybe_get($field_group, 'private');
852
 
853
+ // Bail early
854
+ if($private || $local !== 'json')
855
+ continue;
856
 
857
+ // If field group doesn't exists in DB or modified file date more recent than DB
858
+ if(!$field_group['ID'] || ($modified && $modified > get_post_modified_time('U', true, $field_group['ID']))){
859
+
860
+ $sync[$field_group['key']] = $field_group;
861
+
862
+ }
863
 
864
+ }
865
+
866
+ return $sync;
867
 
868
  }
869
 
870
+ }
871
+
872
+ acf_new_instance('ACFE_Field_Groups');
873
+
874
+ endif;
includes/fields/field-advanced-link.php CHANGED
@@ -473,10 +473,10 @@ function my_acf_advanced_link_sub_fields($sub_fields, $field, $value){
473
  $value = $this->get_value($value);
474
 
475
  // clean
476
- unset($value['type']);
477
- unset($value['post']);
478
- unset($value['term']);
479
- unset($value['url_title']);
480
 
481
  return $value;
482
 
473
  $value = $this->get_value($value);
474
 
475
  // clean
476
+ acfe_unset($value, 'type');
477
+ acfe_unset($value, 'post');
478
+ acfe_unset($value, 'term');
479
+ acfe_unset($value, 'url_title');
480
 
481
  return $value;
482
 
includes/fields/field-code-editor.php CHANGED
@@ -3,7 +3,7 @@
3
  if(!defined('ABSPATH'))
4
  exit;
5
 
6
- if(version_compare($GLOBALS['wp_version'], '4.9', '<'))
7
  return;
8
 
9
  if(!class_exists('acfe_field_code_editor')):
3
  if(!defined('ABSPATH'))
4
  exit;
5
 
6
+ if(acf_version_compare($GLOBALS['wp_version'], '<', '4.9'))
7
  return;
8
 
9
  if(!class_exists('acfe_field_code_editor')):
includes/fields/field-column.php CHANGED
@@ -53,7 +53,7 @@ class acfe_field_column extends acf_field{
53
  // endpoint
54
  acf_render_field_setting( $field, array(
55
  'label' => __('Endpoint','acf'),
56
- 'instructions' => __('Define an endpoint for the previous tabs to stop. This will start a new group of columns.', 'acf'),
57
  'name' => 'endpoint',
58
  'type' => 'true_false',
59
  'ui' => 1,
53
  // endpoint
54
  acf_render_field_setting( $field, array(
55
  'label' => __('Endpoint','acf'),
56
+ 'instructions' => __('Define an endpoint for the previous columns to stop.', 'acf'),
57
  'name' => 'endpoint',
58
  'type' => 'true_false',
59
  'ui' => 1,
includes/fields/field-flexible-content.php CHANGED
@@ -1252,11 +1252,11 @@ class acfe_field_flexible_content extends acf_field_flexible_content{
1252
 
1253
  }
1254
 
1255
- $div = '<div ' . acf_esc_attrs($div) . '></div>';
1256
 
1257
  }
1258
 
1259
- $layout['label'] = $div . '<span ' . acf_esc_attrs($span) . '>' . $layout['label'] . '</span>';
1260
 
1261
  }
1262
 
@@ -2433,19 +2433,11 @@ class acfe_field_flexible_content extends acf_field_flexible_content{
2433
  if($remove_actions){
2434
 
2435
  // Add
2436
- if(isset($icons['add'])) unset($icons['add']);
2437
-
2438
- // Duplicate
2439
- if(isset($icons['duplicate'])) unset($icons['duplicate']);
2440
-
2441
- // Delete
2442
- if(isset($icons['delete'])) unset($icons['delete']);
2443
-
2444
- // Clone
2445
- if(isset($icons['clone'])) unset($icons['clone']);
2446
-
2447
- // Copy/Paste
2448
- if(isset($icons['copy'])) unset($icons['copy']);
2449
 
2450
  }
2451
 
1252
 
1253
  }
1254
 
1255
+ $div = '<div ' . acf_esc_atts($div) . '></div>';
1256
 
1257
  }
1258
 
1259
+ $layout['label'] = $div . '<span ' . acf_esc_atts($span) . '>' . $layout['label'] . '</span>';
1260
 
1261
  }
1262
 
2433
  if($remove_actions){
2434
 
2435
  // Add
2436
+ acfe_unset($icons, 'add');
2437
+ acfe_unset($icons, 'duplicate');
2438
+ acfe_unset($icons, 'delete');
2439
+ acfe_unset($icons, 'clone');
2440
+ acfe_unset($icons, 'copy');
 
 
 
 
 
 
 
 
2441
 
2442
  }
2443
 
includes/fields/field-post-object.php CHANGED
@@ -199,8 +199,8 @@ function my_acf_post_object_new_post_action($new_post_id, $title, $post_id, $fie
199
 
200
  }
201
 
202
- if(!$is_array)
203
- $value = acf_unarray($value);
204
 
205
  return $value;
206
 
199
 
200
  }
201
 
202
+ if(!$is_array && is_array($value))
203
+ reset($value);
204
 
205
  return $value;
206
 
includes/modules/autosync.php CHANGED
@@ -3,351 +3,717 @@
3
  if(!defined('ABSPATH'))
4
  exit;
5
 
6
- /**
7
- * Auto Sync: Includes
8
- */
9
- $acfe_php = acf_get_setting('acfe/php');
10
- $acfe_php_load = acf_get_setting('acfe/php_load');
11
 
12
- if(!empty($acfe_php) && !empty($acfe_php_load)){
 
 
 
13
 
14
- foreach($acfe_php_load as $path){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- if(!is_readable($path))
17
- continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- acf_update_setting('acfe/php_found', true);
 
20
 
21
- $files = glob($path . '/group_*.php');
22
- if(empty($files))
23
- continue;
24
 
25
- foreach($files as $file){
 
 
 
 
 
 
 
 
 
26
 
27
- require_once($file);
 
28
 
 
 
 
 
 
 
 
 
 
29
  }
30
 
31
  }
32
 
33
- }
34
-
35
- $acfe_json = acf_get_setting('json');
36
- $acfe_json_load = acf_get_setting('load_json');
37
-
38
- if(!empty($acfe_json) && !empty($acfe_json_load)){
39
-
40
- foreach($acfe_json_load as $path){
41
 
42
- if(!is_dir($path))
43
- continue;
44
 
45
- acf_update_setting('acfe/json_found', true);
 
46
 
47
- break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  }
50
 
51
- }
52
-
53
- /**
54
- * Auto Sync: Disable json
55
- */
56
- add_action('acf/update_field_group', 'acfe_autosync_json_update_field_group', 9);
57
- function acfe_autosync_json_update_field_group($field_group){
58
-
59
- // Validate
60
- if(!acf_get_setting('json'))
61
- return;
62
 
63
- // Disable json sync for this field group
64
- if(!acfe_has_field_group_autosync($field_group, 'json'))
65
- add_filter('acf/settings/json', 'acfe_autosync_temp_disable_json');
66
-
67
- }
68
-
69
- /**
70
- * Auto Sync: Re-enable json
71
- */
72
- add_action('acf/update_field_group', 'acfe_autosync_json_after_update_field_group', 11);
73
- function acfe_autosync_json_after_update_field_group($field_group){
74
 
75
- // Validate
76
- if(!acf_get_setting('json'))
77
- return;
 
 
 
 
78
 
79
- remove_filter('acf/settings/json', 'acfe_autosync_temp_disable_json');
 
 
 
 
 
80
 
81
- }
82
-
83
- /**
84
- * Auto Sync: Disable json (function)
85
- */
86
- function acfe_autosync_temp_disable_json(){
87
- return false;
88
- }
89
-
90
- /**
91
- * Auto Sync: PHP
92
- */
93
- add_action('acf/update_field_group', 'acfe_autosync_php_update_field_group');
94
- add_action('acf/untrash_field_group', 'acfe_autosync_php_update_field_group');
95
- function acfe_autosync_php_update_field_group($field_group){
96
 
97
- // Validate
98
- if(!acf_get_setting('acfe/php'))
99
- return;
 
100
 
101
- if(!acfe_has_field_group_autosync($field_group, 'php'))
102
- return;
103
 
104
- acfe_autosync_write_php($field_group);
 
 
 
 
 
105
 
106
- }
107
-
108
- add_action('acf/trash_field_group', 'acfe_autosync_php_delete_field_group');
109
- add_action('acf/delete_field_group', 'acfe_autosync_php_delete_field_group');
110
- function acfe_autosync_php_delete_field_group($field_group){
111
 
112
- // validate
113
- if(!acf_get_setting('acfe/php'))
114
- return;
115
 
116
- if(!acfe_has_field_group_autosync($field_group, 'php'))
117
- return;
118
 
119
- // WP appends '__trashed' to end of 'key' (post_name)
120
- $field_group['key'] = str_replace('__trashed', '', $field_group['key']);
121
 
122
- // delete
123
- acfe_autosync_delete_php($field_group['key']);
 
 
 
 
 
 
124
 
125
- }
126
-
127
- /**
128
- * Auto Sync: Write PHP
129
- */
130
- function acfe_autosync_write_php($field_group){
131
 
132
- $path = acf_get_setting('acfe/php_save');
133
- if(empty($path))
134
- return false;
135
-
136
- // vars
137
- $path = untrailingslashit($path);
138
- $file = $field_group['key'] . '.php';
139
-
140
- // bail early if dir does not exist
141
- if(!is_writable($path))
142
- return false;
143
 
144
- // Translation
145
- $l10n = acf_get_setting('l10n');
146
- $l10n_textdomain = acf_get_setting('l10n_textdomain');
 
 
 
147
 
148
- if(!$l10n || !$l10n_textdomain){
 
 
 
 
 
 
 
149
 
150
- $field_group['fields'] = acf_get_fields($field_group);
 
 
151
 
152
- }else{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
- acf_update_setting('l10n_var_export', true);
 
 
 
155
 
156
- $field_group = acf_translate_field_group($field_group);
 
 
157
 
158
- // Reset store to allow fields translation
159
- $store = acf_get_store('fields');
160
- $store->reset();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
- $field_group['fields'] = acf_get_fields($field_group);
 
 
163
 
164
- acf_update_setting('l10n_var_export', false);
165
 
166
- }
167
-
168
- // prepare for export
169
- $id = acf_extract_var($field_group, 'ID');
170
- $field_group = acf_prepare_field_group_for_export($field_group);
171
-
172
- // add modified time
173
- $field_group['modified'] = get_post_modified_time('U', true, $id, true);
174
-
175
- // Prepare
176
- $str_replace = array(
177
- " " => "\t",
178
- "'!!__(!!\'" => "__('",
179
- "!!\', !!\'" => "', '",
180
- "!!\')!!'" => "')",
181
- "array (" => "array("
182
- );
183
-
184
- $preg_replace = array(
185
- '/([\t\r\n]+?)array/' => 'array',
186
- '/[0-9]+ => array/' => 'array'
187
- );
188
-
189
- ob_start();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
 
191
  echo "<?php " . "\r\n" . "\r\n";
192
  echo "if( function_exists('acf_add_local_field_group') ):" . "\r\n" . "\r\n";
193
-
194
  // code
195
  $code = var_export($field_group, true);
196
-
197
  // change double spaces to tabs
198
  $code = str_replace( array_keys($str_replace), array_values($str_replace), $code );
199
-
200
  // correctly formats "=> array("
201
  $code = preg_replace( array_keys($preg_replace), array_values($preg_replace), $code );
202
-
203
  // echo
204
  echo "acf_add_local_field_group({$code});" . "\r\n" . "\r\n";
205
-
206
  echo "endif;";
207
 
208
- $output = ob_get_clean();
209
-
210
- // write file
211
- $f = fopen("{$path}/{$file}", 'w');
212
- fwrite($f, $output);
213
- fclose($f);
214
-
215
- // return
216
- return true;
217
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  }
219
 
220
- function acfe_autosync_delete_php($key){
221
-
222
- // vars
223
- $path = acf_get_setting('acfe/php_save');
224
- $file = $key . '.php';
225
-
226
- // remove trailing slash
227
- $path = untrailingslashit($path);
228
-
229
- // bail early if file does not exist
230
- if(!is_readable("{$path}/{$file}"))
231
- return false;
232
-
233
- // remove file
234
- unlink("{$path}/{$file}");
235
-
236
- // return
237
- return true;
238
-
239
  }
240
 
241
  /**
242
- * Auto Sync: Helper - is field group json desync
243
  */
244
- function acfe_is_field_group_json_desync($field_group){
 
 
 
 
 
 
 
245
 
246
  acf_enable_filter('local');
247
- $group = acf_get_local_field_group($field_group['key']);
 
 
248
  acf_disable_filter('local');
249
 
250
- $private = acf_maybe_get($group, 'private', false);
251
- $local = acf_maybe_get($group, 'local', false);
252
- $modified = acf_maybe_get($group, 'modified', 0);
 
 
 
253
 
254
- if($private){
255
  return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  }
257
 
258
- elseif($local !== 'json'){
259
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  }
261
 
262
- elseif($modified && $modified > get_post_modified_time('U', true, $field_group['ID'], true)){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
  return true;
264
- }
265
 
266
  return false;
267
 
268
  }
269
 
270
- /**
271
- * Auto Sync: Helper - Has field group autosync
272
- */
273
  function acfe_has_field_group_autosync($field_group, $type = false){
274
 
275
- $acfe_autosync = acf_maybe_get($field_group, 'acfe_autosync', array());
 
 
 
 
 
 
 
 
 
 
276
 
277
- if(!$type)
278
- return acf_is_array($acfe_autosync);
 
279
 
280
- if($type === 'json')
281
- return is_array($acfe_autosync) && in_array('json', $acfe_autosync);
282
 
283
- elseif($type === 'php')
284
- return is_array($acfe_autosync) && in_array('php', $acfe_autosync);
285
 
 
 
286
  return false;
287
 
288
  }
289
 
290
- /**
291
- * Auto Sync: Helper - Has field group autosync found register/file
292
- */
293
  function acfe_has_field_group_autosync_file($field_group, $type = 'json'){
294
 
295
  if($type === 'json'){
296
 
297
- // acf_is_local_field_group = true if json file found
298
  $found = false;
299
-
 
 
300
  if(acf_is_local_field_group($field_group['key'])){
301
 
302
  $local_field_group = acf_get_local_field_group($field_group['key']);
303
  $get_local = acf_maybe_get($local_field_group, 'local', false);
304
 
305
- if($get_local === 'json'){
306
-
307
  $found = true;
308
-
309
- }else{
310
-
311
- $paths = acf_get_setting('load_json');
312
-
313
- if(!empty($paths)){
314
- foreach($paths as $path){
315
-
316
- $path = untrailingslashit($path);
317
- $file = $field_group['key'] . '.json';
318
-
319
- if(is_readable("{$path}/{$file}")){
320
-
321
- $found = true;
322
- break;
323
-
324
- }
325
-
326
- }
327
- }
328
-
329
- }
330
 
331
  }
332
 
333
- else{
334
-
335
- $paths = acf_get_setting('load_json');
336
-
337
- if(!empty($paths)){
338
- foreach($paths as $path){
339
-
340
- $path = untrailingslashit($path);
341
- $file = $field_group['key'] . '.json';
342
-
343
- if(is_readable("{$path}/{$file}")){
344
-
345
- $found = true;
346
- break;
347
-
348
- }
349
-
350
- }
351
  }
352
 
353
  }
@@ -358,23 +724,19 @@ function acfe_has_field_group_autosync_file($field_group, $type = 'json'){
358
 
359
  elseif($type === 'php'){
360
 
361
- // acf_is_local_field_group = true if php registered
362
- $found = false;
 
 
 
363
 
364
- if(acf_is_local_field_group($field_group['key'])){
365
-
366
- $local_field_group = acf_get_local_field_group($field_group['key']);
367
- $get_local = acf_maybe_get($local_field_group, 'local', false);
368
-
369
- if($get_local === 'php')
370
- $found = true;
371
-
372
  }
373
 
374
- return $found;
375
 
376
  }
377
-
378
  return false;
379
 
380
- }
 
3
  if(!defined('ABSPATH'))
4
  exit;
5
 
6
+ if(!class_exists('ACFE_AutoSync')):
 
 
 
 
7
 
8
+ class ACFE_AutoSync{
9
+
10
+ private $php_files = array();
11
+ private $json_files = array();
12
 
13
+ function __construct(){
14
+
15
+ // PHP Save
16
+ add_action('acf/update_field_group', array($this, 'update_field_group'));
17
+ add_action('acf/untrash_field_group', array($this, 'update_field_group'));
18
+
19
+ // PHP Delete
20
+ add_action('acf/trash_field_group', array($this, 'delete_field_group'));
21
+ add_action('acf/delete_field_group', array($this, 'delete_field_group'));
22
+
23
+
24
+ // Json Save
25
+ add_action('acf/update_field_group', array($this, 'pre_update_field_group_json'), 9);
26
+ add_action('acf/untrash_field_group', array($this, 'pre_update_field_group_json'), 9);
27
+
28
+ add_action('acf/update_field_group', array($this, 'post_update_field_group_json'), 11);
29
+ add_action('acf/untrash_field_group', array($this, 'post_update_field_group_json'), 11);
30
+
31
+ // Override Json
32
+ add_filter('acf/settings/json', array($this, 'override_json'), 5);
33
+ add_filter('acf/settings/save_json', array($this, 'override_json_save'), 5);
34
+ add_filter('acf/settings/load_json', array($this, 'override_json_load'), 5);
35
+
36
+ // Setup
37
+ $this->setup_php();
38
+ $this->setup_json();
39
 
40
+ }
41
+
42
+ /*
43
+ * Override: Json
44
+ */
45
+ function override_json($value){
46
+ return apply_filters('acfe/settings/json', $value);
47
+ }
48
+
49
+ /*
50
+ * Override: Json Save
51
+ */
52
+ function override_json_save($path){
53
+ return apply_filters('acfe/settings/json_save', $path);
54
+ }
55
+
56
+ /*
57
+ * Override: Json Load
58
+ */
59
+ function override_json_load($paths){
60
+ return (array) apply_filters('acfe/settings/json_load', $paths);
61
+ }
62
+
63
+ /*
64
+ * Json Enabled
65
+ */
66
+ function is_json_enabled(){
67
+ return (bool) acf_get_setting('json');
68
+ }
69
+
70
+ /*
71
+ * Json: Setup
72
+ */
73
+ function setup_json(){
74
 
75
+ if(!$this->is_json_enabled())
76
+ return;
77
 
78
+ $this->scan_json_folders();
 
 
79
 
80
+ }
81
+
82
+ /*
83
+ * Json: Scan
84
+ */
85
+ function scan_json_folders(){
86
+
87
+ $paths = (array) acf_get_setting('load_json');
88
+
89
+ foreach($paths as $path){
90
 
91
+ if(!is_dir($path))
92
+ continue;
93
 
94
+ acf_update_setting('acfe/json_found', true);
95
+ break;
96
+
97
+ }
98
+
99
+ if(acf_version_compare(acf_get_setting('version'), '<', '5.9')){
100
+
101
+ $this->scan_json_folders_compatibility();
102
+
103
  }
104
 
105
  }
106
 
107
+ /*
108
+ * Json: Scan - Compatibility (ACF < 5.9)
109
+ */
110
+ function scan_json_folders_compatibility(){
 
 
 
 
111
 
112
+ $json_files = array();
 
113
 
114
+ // Get paths
115
+ $paths = (array) acf_get_setting('load_json');
116
 
117
+ foreach($paths as $path){
118
+
119
+ if(!is_dir($path))
120
+ continue;
121
+
122
+ $files = scandir($path);
123
+ if(!$files)
124
+ continue;
125
+
126
+ foreach($files as $filename){
127
+
128
+ // Ignore hidden files.
129
+ if($filename[0] === '.')
130
+ continue;
131
+
132
+ // Ignore sub directories.
133
+ $file = untrailingslashit( $path ) . '/' . $filename;
134
+ if(is_dir($file))
135
+ continue;
136
+
137
+ // Ignore non JSON files.
138
+ $ext = pathinfo($filename, PATHINFO_EXTENSION);
139
+ if($ext !== 'json')
140
+ continue;
141
+
142
+ // Read JSON data.
143
+ $json = json_decode(file_get_contents($file), true);
144
+ if(!is_array($json) || !isset($json['key']))
145
+ continue;
146
+
147
+ // Append data.
148
+ $json_files[$json['key']] = $file;
149
+
150
+ }
151
+
152
+ }
153
+
154
+ // Store data and return.
155
+ $this->json_files = $json_files;
156
+
157
+ return $json_files;
158
 
159
  }
160
 
161
+ /*
162
+ * Json: Get Files
163
+ */
164
+ function get_json_files(){
165
+ return $this->json_files;
166
+ }
 
 
 
 
 
167
 
168
+ /*
169
+ * PHP Enabled
170
+ */
171
+ function is_php_enabled(){
172
+ return (bool) acf_get_setting('acfe/php');
173
+ }
 
 
 
 
 
174
 
175
+ /*
176
+ * PHP: Setup
177
+ */
178
+ function setup_php(){
179
+
180
+ if(!$this->is_php_enabled())
181
+ return;
182
 
183
+ global $pagenow;
184
+ $files = $this->scan_php_folders();
185
+
186
+ // Do not include PHP files in ACF Admin
187
+ if(($pagenow === 'edit.php' && acf_maybe_get_GET('post_type') === 'acf-field-group') || ($pagenow === 'post.php' && get_post_type(acf_maybe_get_GET('post')) === 'acf-field-group'))
188
+ return;
189
 
190
+ foreach($files as $key => $file){
191
+
192
+ require_once($file);
193
+
194
+ }
195
+
196
+ }
 
 
 
 
 
 
 
 
197
 
198
+ /*
199
+ * PHP: Scan
200
+ */
201
+ function scan_php_folders(){
202
 
203
+ $php_files = array();
204
+ $paths = (array) acf_get_setting('acfe/php_load');
205
 
206
+ foreach($paths as $path){
207
+
208
+ $path = untrailingslashit($path);
209
+
210
+ if(!is_dir($path))
211
+ continue;
212
 
213
+ acf_update_setting('acfe/php_found', true);
 
 
 
 
214
 
215
+ $files = glob($path . '/group_*.php');
 
 
216
 
217
+ if(!$files)
218
+ continue;
219
 
220
+ foreach($files as $file){
 
221
 
222
+ $key = pathinfo($file, PATHINFO_FILENAME);
223
+
224
+ // Append data.
225
+ $php_files[$key] = $file;
226
+
227
+ }
228
+
229
+ }
230
 
231
+ // Store data and return.
232
+ $this->php_files = $php_files;
 
 
 
 
233
 
234
+ return $php_files;
235
+
236
+ }
 
 
 
 
 
 
 
 
237
 
238
+ /*
239
+ * PHP: Get Files
240
+ */
241
+ public function get_php_files(){
242
+ return $this->php_files;
243
+ }
244
 
245
+ /*
246
+ * PHP: Update Field Group
247
+ */
248
+ function update_field_group($field_group){
249
+
250
+ // Bail early
251
+ if(!$this->is_php_enabled())
252
+ return;
253
 
254
+ // Bail early
255
+ if(!acfe_has_php_sync($field_group))
256
+ return;
257
 
258
+ // Vars
259
+ $id = $field_group['ID'];
260
+ $key = $field_group['key'];
261
+ $path = untrailingslashit(acf_get_setting('acfe/php_save'));
262
+
263
+ // Backup path
264
+ $new_path = $path;
265
+
266
+ // Filters
267
+ $new_path = apply_filters("acfe/settings/php_save/all", $new_path, $field_group);
268
+ $new_path = apply_filters("acfe/settings/php_save/ID={$id}", $new_path, $field_group);
269
+ $new_path = apply_filters("acfe/settings/php_save/key={$key}", $new_path, $field_group);
270
+
271
+ $diff = $path !== $new_path;
272
+
273
+ // Custom path
274
+ if($diff)
275
+ acf_update_setting('acfe/php_save', $new_path);
276
+
277
+ // Save File
278
+ $this->save_file($key, $field_group);
279
+
280
+ // Restore
281
+ if($diff)
282
+ acf_update_setting('acfe/php_save', $path);
283
+
284
+ }
285
 
286
+ /*
287
+ * PHP: Delete Field Group
288
+ */
289
+ function delete_field_group($field_group){
290
 
291
+ // Bail early
292
+ if(!$this->is_php_enabled())
293
+ return;
294
 
295
+ // Bail early
296
+ if(!acfe_has_php_sync($field_group))
297
+ return;
298
+
299
+ // WP appends '__trashed' to end of 'key' (post_name).
300
+ $key = str_replace('__trashed', '', $field_group['key']);
301
+
302
+ // Delete file.
303
+ $this->delete_file($key);
304
+
305
+ }
306
+
307
+ /*
308
+ * PHP: Save File
309
+ */
310
+ function save_file($key, $field_group){
311
+
312
+ // Determine save location.
313
+ if(isset($this->php_files[$key])){
314
+
315
+ $file = $this->php_files[$key];
316
+
317
+ }else{
318
+
319
+ $path = untrailingslashit(acf_get_setting('acfe/php_save'));
320
+
321
+ if(!is_writable($path))
322
+ return false;
323
+
324
+ $file = "$path/$key.php";
325
+
326
+ }
327
 
328
+ // Translation
329
+ $l10n = acf_get_setting('l10n');
330
+ $l10n_textdomain = acf_get_setting('l10n_textdomain');
331
 
332
+ if(!$l10n || !$l10n_textdomain){
333
 
334
+ $field_group['fields'] = acf_get_fields($field_group);
335
+
336
+ }else{
337
+
338
+ acf_update_setting('l10n_var_export', true);
339
+
340
+ $field_group = acf_translate_field_group($field_group);
341
+
342
+ // Reset store to allow fields translation
343
+ $store = acf_get_store('fields');
344
+ $store->reset();
345
+
346
+ $field_group['fields'] = acf_get_fields($field_group);
347
+
348
+ acf_update_setting('l10n_var_export', false);
349
+
350
+ }
351
+
352
+ // prepare for export
353
+ $id = acf_extract_var($field_group, 'ID');
354
+ $field_group = acf_prepare_field_group_for_export($field_group);
355
+
356
+ // add modified time
357
+ $field_group['modified'] = get_post_modified_time('U', true, $id, true);
358
+
359
+ // Prepare
360
+ $str_replace = array(
361
+ " " => "\t",
362
+ "'!!__(!!\'" => "__('",
363
+ "!!\', !!\'" => "', '",
364
+ "!!\')!!'" => "')",
365
+ "array (" => "array("
366
+ );
367
+
368
+ $preg_replace = array(
369
+ '/([\t\r\n]+?)array/' => 'array',
370
+ '/[0-9]+ => array/' => 'array'
371
+ );
372
+
373
+ ob_start();
374
 
375
  echo "<?php " . "\r\n" . "\r\n";
376
  echo "if( function_exists('acf_add_local_field_group') ):" . "\r\n" . "\r\n";
377
+
378
  // code
379
  $code = var_export($field_group, true);
380
+
381
  // change double spaces to tabs
382
  $code = str_replace( array_keys($str_replace), array_values($str_replace), $code );
383
+
384
  // correctly formats "=> array("
385
  $code = preg_replace( array_keys($preg_replace), array_values($preg_replace), $code );
386
+
387
  // echo
388
  echo "acf_add_local_field_group({$code});" . "\r\n" . "\r\n";
389
+
390
  echo "endif;";
391
 
392
+ $output = ob_get_clean();
393
+
394
+ // Save and return true if bytes were written.
395
+ $result = file_put_contents($file, $output);
396
+
397
+ return is_int($result);
398
+
399
+ }
400
+
401
+ /*
402
+ * PHP: Delete File
403
+ */
404
+ function delete_file($key){
405
+
406
+ if(isset($this->php_files[$key]) && is_readable($this->php_files[$key])){
407
+
408
+ unlink($this->php_files[$key]);
409
+
410
+ return true;
411
+
412
+ }else{
413
+
414
+ $path = untrailingslashit(acf_get_setting('acfe/php_save'));
415
+
416
+ if(!is_dir($path))
417
+ return false;
418
+
419
+ $file = "$path/$key.php";
420
+
421
+ if(is_readable($file)){
422
+
423
+ unlink($file);
424
+
425
+ return true;
426
+
427
+ }
428
+
429
+ }
430
+
431
+ return false;
432
+
433
+ }
434
+
435
+ /*
436
+ * Json: Pre update Field Group
437
+ */
438
+ function pre_update_field_group_json($field_group){
439
+
440
+ if(!$this->is_json_enabled())
441
+ return;
442
+
443
+ if(!acfe_has_json_sync($field_group)){
444
+
445
+ // Do not save json
446
+ add_filter('acf/settings/json', array($this, '__return_false'));
447
+ return;
448
+
449
+ }
450
+
451
+ // Vars
452
+ $id = $field_group['ID'];
453
+ $key = $field_group['key'];
454
+ $path = untrailingslashit(acf_get_setting('save_json'));
455
+
456
+ // Backup
457
+ $new_path = $path;
458
+
459
+ // Filters
460
+ $new_path = apply_filters("acfe/settings/json_save/all", $new_path, $field_group);
461
+ $new_path = apply_filters("acfe/settings/json_save/ID={$id}", $new_path, $field_group);
462
+ $new_path = apply_filters("acfe/settings/json_save/key={$key}", $new_path, $field_group);
463
+
464
+ // Set custom saving point
465
+ if($path !== $new_path){
466
+
467
+ // Backup original path
468
+ $GLOBALS['acfe_json_original_path'] = $path;
469
+
470
+ // Set custom path
471
+ acf_update_setting('save_json', $new_path);
472
+
473
+ }
474
+
475
+ }
476
+
477
+ /*
478
+ * Json: Post Update Field Group
479
+ */
480
+ function post_update_field_group_json($field_group){
481
+
482
+ if(!$this->is_json_enabled())
483
+ return;
484
+
485
+ // Json
486
+ if(!acfe_has_json_sync($field_group)){
487
+
488
+ // Original json setting
489
+ remove_filter('acf/settings/json', array($this, '__return_false'));
490
+ return;
491
+
492
+ }
493
+
494
+ if(isset($GLOBALS['acfe_json_original_path']) && !empty($GLOBALS['acfe_json_original_path'])){
495
+
496
+ // Restore original path
497
+ acf_update_setting('save_json', $GLOBALS['acfe_json_original_path']);
498
+
499
+ // Remove backup
500
+ unset($GLOBALS['acfe_json_original_path']);
501
+
502
+ }
503
+
504
+ }
505
+
506
+ /*
507
+ * Custom Return False
508
+ */
509
+ function __return_false(){
510
+ return false;
511
+ }
512
+
513
+ }
514
+
515
+ acf_new_instance('ACFE_AutoSync');
516
+
517
+ endif;
518
+
519
+ /*
520
+ * Helper: Get PHP Files
521
+ */
522
+ function acfe_get_local_php_files(){
523
+ return acf_get_instance('ACFE_AutoSync')->get_php_files();
524
+ }
525
+
526
+ /*
527
+ * Helper: Get Json Files
528
+ */
529
+ if(!function_exists('acf_get_local_json_files') && acf_version_compare(acf_get_setting('version'), '<', '5.9')){
530
+
531
+ function acf_get_local_json_files(){
532
+ return acf_get_instance('ACFE_AutoSync')->get_json_files();
533
  }
534
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
535
  }
536
 
537
  /**
538
+ * Helper: Sync available
539
  */
540
+ function acfe_is_sync_available($field_group){
541
+
542
+ $key = acf_maybe_get($field_group, 'key');
543
+ $id = acf_maybe_get($field_group, 'ID');
544
+
545
+ // Bail early
546
+ if(empty($key) || empty($id))
547
+ return false;
548
 
549
  acf_enable_filter('local');
550
+
551
+ $field_group = acf_get_local_field_group($key);
552
+
553
  acf_disable_filter('local');
554
 
555
+ if(!$field_group)
556
+ return false;
557
+
558
+ $private = acf_maybe_get($field_group, 'private', false);
559
+ $local = acf_maybe_get($field_group, 'local', false);
560
+ $modified = acf_maybe_get($field_group, 'modified', 0);
561
 
562
+ if($private || $local !== 'json')
563
  return false;
564
+
565
+ if($modified && $modified > get_post_modified_time('U', true, $id, true))
566
+ return true;
567
+
568
+ return false;
569
+
570
+ }
571
+
572
+ function acfe_has_json_sync($field_group){
573
+ return in_array('json', (array) acf_maybe_get($field_group, 'acfe_autosync', array()));
574
+ }
575
+
576
+ function acfe_has_php_sync($field_group){
577
+ return in_array('php', (array) acf_maybe_get($field_group, 'acfe_autosync', array()));
578
+ }
579
+
580
+ function acfe_get_local_php_file($field_group){
581
+
582
+ $key = $field_group;
583
+
584
+ if(is_array($field_group) && isset($field_group['key']))
585
+ $key = $field_group['key'];
586
+
587
+ $php_files = acfe_get_local_php_files();
588
+
589
+ if(isset($php_files[$key])){
590
+
591
+ return $php_files[$key];
592
+
593
  }
594
 
595
+ return false;
596
+
597
+ }
598
+
599
+ function acfe_get_local_json_file($field_group){
600
+
601
+ $key = $field_group;
602
+
603
+ if(is_array($field_group) && isset($field_group['key']))
604
+ $key = $field_group['key'];
605
+
606
+ $json_files = acf_get_local_json_files();
607
+
608
+ if(isset($json_files[$key])){
609
+
610
+ return $json_files[$key];
611
+
612
  }
613
 
614
+ return false;
615
+
616
+ }
617
+
618
+ /*
619
+ function acfe_is_local_json($field_group){
620
+
621
+ $key = $field_group;
622
+
623
+ if(is_array($field_group) && isset($field_group['key']))
624
+ $key = $field_group['key'];
625
+
626
+ if(!acf_is_local_field_group($key))
627
+ return false;
628
+
629
+ $field_group = acf_get_local_field_group($key);
630
+
631
+ if(acf_maybe_get($field_group, 'local') === 'json')
632
+ return true;
633
+
634
+ return false;
635
+
636
+ }
637
+
638
+ function acfe_is_local_php($field_group){
639
+
640
+ $key = $field_group;
641
+
642
+ if(is_array($field_group) && isset($field_group['key']))
643
+ $key = $field_group['key'];
644
+
645
+ if(!acf_is_local_field_group($key))
646
+ return false;
647
+
648
+ $field_group = acf_get_local_field_group($key);
649
+
650
+ if(acf_maybe_get($field_group, 'local') === 'php')
651
  return true;
 
652
 
653
  return false;
654
 
655
  }
656
 
 
 
 
657
  function acfe_has_field_group_autosync($field_group, $type = false){
658
 
659
+ $acfe_autosync = (array) acf_maybe_get($field_group, 'acfe_autosync', array());
660
+
661
+ // Has something
662
+ if(!$type){
663
+
664
+ return !empty($acfe_autosync);
665
+
666
+ }
667
+
668
+ // Has Json
669
+ elseif($type === 'json'){
670
 
671
+ return in_array('json', $acfe_autosync);
672
+
673
+ }
674
 
675
+ // Has PHP
676
+ elseif($type === 'php'){
677
 
678
+ return in_array('php', $acfe_autosync);
 
679
 
680
+ }
681
+
682
  return false;
683
 
684
  }
685
 
 
 
 
686
  function acfe_has_field_group_autosync_file($field_group, $type = 'json'){
687
 
688
  if($type === 'json'){
689
 
 
690
  $found = false;
691
+ $paths = (array) acf_get_setting('load_json', array());
692
+
693
+ // True if json file found
694
  if(acf_is_local_field_group($field_group['key'])){
695
 
696
  $local_field_group = acf_get_local_field_group($field_group['key']);
697
  $get_local = acf_maybe_get($local_field_group, 'local', false);
698
 
699
+ if($get_local === 'json')
 
700
  $found = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
701
 
702
  }
703
 
704
+ if(!$found){
705
+
706
+ foreach($paths as $path){
707
+
708
+ $path = untrailingslashit($path);
709
+ $file = $field_group['key'] . '.json';
710
+
711
+ if(!is_readable("{$path}/{$file}"))
712
+ continue;
713
+
714
+ $found = true;
715
+ break;
716
+
 
 
 
 
 
717
  }
718
 
719
  }
724
 
725
  elseif($type === 'php'){
726
 
727
+ $php_files = acfe_get_local_php_files();
728
+
729
+ if(isset($php_files[$field_group['key']])){
730
+
731
+ return $php_files[$field_group['key']];
732
 
 
 
 
 
 
 
 
 
733
  }
734
 
735
+ return false;
736
 
737
  }
738
+
739
  return false;
740
 
741
+ }
742
+ */
includes/modules/dynamic-block-type.php CHANGED
@@ -7,12 +7,6 @@ if(!defined('ABSPATH'))
7
  if(!acf_get_setting('acfe/modules/dynamic_block_types'))
8
  return;
9
 
10
- /**
11
- * Require ACF Pro 5.8
12
- */
13
- if(version_compare(ACF_VERSION, '5.8', '<'))
14
- return;
15
-
16
  /**
17
  * Register Dynamic Block Type
18
  */
@@ -354,8 +348,7 @@ function acfe_dbt_filter_status_trash($post){
354
  $option = acfe_settings('modules.dynamic_block_type.data');
355
 
356
  // Check ACFE option
357
- if(isset($option[$name]))
358
- unset($option[$name]);
359
 
360
  // Update ACFE option
361
  acfe_settings('modules.dynamic_block_type.data', $option, true);
@@ -381,8 +374,7 @@ function acfe_dbt_filter_status_publish($post){
381
  add_filter('manage_edit-acfe-dbt_columns', 'acfe_dbt_admin_columns');
382
  function acfe_dbt_admin_columns($columns){
383
 
384
- if(isset($columns['date']))
385
- unset($columns['date']);
386
 
387
  $columns['name'] = __('Name');
388
  $columns['category'] = __('Category');
7
  if(!acf_get_setting('acfe/modules/dynamic_block_types'))
8
  return;
9
 
 
 
 
 
 
 
10
  /**
11
  * Register Dynamic Block Type
12
  */
348
  $option = acfe_settings('modules.dynamic_block_type.data');
349
 
350
  // Check ACFE option
351
+ acfe_unset($option, $name);
 
352
 
353
  // Update ACFE option
354
  acfe_settings('modules.dynamic_block_type.data', $option, true);
374
  add_filter('manage_edit-acfe-dbt_columns', 'acfe_dbt_admin_columns');
375
  function acfe_dbt_admin_columns($columns){
376
 
377
+ acfe_unset($columns, 'date');
 
378
 
379
  $columns['name'] = __('Name');
380
  $columns['category'] = __('Category');
includes/modules/dynamic-options-page.php CHANGED
@@ -324,8 +324,7 @@ function acfe_dop_filter_status_trash($post){
324
  $option = acfe_settings('modules.dynamic_option.data');
325
 
326
  // Check ACFE option
327
- if(isset($option[$name]))
328
- unset($option[$name]);
329
 
330
  // Update ACFE option
331
  acfe_settings('modules.dynamic_option.data', $option, true);
@@ -351,8 +350,7 @@ function acfe_dop_filter_status_publish($post){
351
  add_filter('manage_edit-acfe-dop_columns', 'acfe_dop_admin_columns');
352
  function acfe_dop_admin_columns($columns){
353
 
354
- if(isset($columns['date']))
355
- unset($columns['date']);
356
 
357
  $columns['name'] = __('Menu slug');
358
  $columns['post_id'] = __('Post ID');
324
  $option = acfe_settings('modules.dynamic_option.data');
325
 
326
  // Check ACFE option
327
+ acfe_unset($option, $name);
 
328
 
329
  // Update ACFE option
330
  acfe_settings('modules.dynamic_option.data', $option, true);
350
  add_filter('manage_edit-acfe-dop_columns', 'acfe_dop_admin_columns');
351
  function acfe_dop_admin_columns($columns){
352
 
353
+ acfe_unset($columns, 'date');
 
354
 
355
  $columns['name'] = __('Menu slug');
356
  $columns['post_id'] = __('Post ID');
includes/modules/form/admin.php CHANGED
@@ -539,11 +539,11 @@ class acfe_form{
539
  foreach($this->fields_groups as $field_group){ ?>
540
 
541
  <?php
542
- acf_disable_filters();
543
 
544
  $field_group_db = acf_get_field_group($field_group['key']);
545
 
546
- acf_enable_filters();
547
  ?>
548
 
549
  <div class="acf-field">
@@ -646,7 +646,7 @@ class acfe_form{
646
  // Field groups choices
647
  function field_groups_choices($field){
648
 
649
- acf_disable_filters();
650
 
651
  $field_groups = acf_get_field_groups();
652
  if(empty($field_groups))
@@ -654,11 +654,14 @@ class acfe_form{
654
 
655
  foreach($field_groups as $field_group){
656
 
 
 
 
657
  $field['choices'][$field_group['key']] = $field_group['title'];
658
 
659
  }
660
 
661
- acf_enable_filters();
662
 
663
  return $field;
664
 
@@ -1201,6 +1204,21 @@ class acfe_form{
1201
  }
1202
 
1203
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1204
 
1205
  return $content;
1206
 
@@ -1520,9 +1538,8 @@ class acfe_form{
1520
  * List: Columns
1521
  */
1522
  function admin_columns($columns){
1523
-
1524
- if(isset($columns['date']))
1525
- unset($columns['date']);
1526
 
1527
  $columns['name'] = __('Name');
1528
  $columns['field_groups'] = __('Field groups', 'acf');
@@ -1561,13 +1578,24 @@ class acfe_form{
1561
 
1562
  foreach($field_groups as $field_group_key){
1563
 
1564
- acf_disable_filters();
1565
 
1566
- $field_group = acf_get_field_group($field_group_key);
1567
 
1568
- acf_enable_filters();
1569
 
1570
- $fg[] = '<a href="' . admin_url('post.php?post=' . $field_group['ID'] . '&action=edit') . '">' . $field_group['title'] . '</a>';
 
 
 
 
 
 
 
 
 
 
 
1571
 
1572
  }
1573
 
@@ -1669,6 +1697,14 @@ class acfe_form{
1669
 
1670
  }
1671
 
 
 
 
 
 
 
 
 
1672
  }
1673
 
1674
  endwhile;
539
  foreach($this->fields_groups as $field_group){ ?>
540
 
541
  <?php
542
+ //acf_disable_filters();
543
 
544
  $field_group_db = acf_get_field_group($field_group['key']);
545
 
546
+ //acf_enable_filters();
547
  ?>
548
 
549
  <div class="acf-field">
646
  // Field groups choices
647
  function field_groups_choices($field){
648
 
649
+ //acf_disable_filters();
650
 
651
  $field_groups = acf_get_field_groups();
652
  if(empty($field_groups))
654
 
655
  foreach($field_groups as $field_group){
656
 
657
+ if(strpos($field_group['key'], 'group_acfe_') === 0)
658
+ continue;
659
+
660
  $field['choices'][$field_group['key']] = $field_group['title'];
661
 
662
  }
663
 
664
+ //acf_enable_filters();
665
 
666
  return $field;
667
 
1204
  }
1205
 
1206
  }
1207
+
1208
+ // Match current_post {current:post:id}
1209
+ $content = acfe_form_map_current($content, $post_id, $args);
1210
+
1211
+ // Match {get_field:name} {get_field:name:123}
1212
+ $content = acfe_form_map_get_field($content, $post_id);
1213
+
1214
+ // Match {get_option:name}
1215
+ $content = acfe_form_map_get_option($content);
1216
+
1217
+ // Match {query_var:name} {query_var:name:key}
1218
+ $content = acfe_form_map_query_var($content);
1219
+
1220
+ // Match {request:name}
1221
+ $content = acfe_form_map_request($content);
1222
 
1223
  return $content;
1224
 
1538
  * List: Columns
1539
  */
1540
  function admin_columns($columns){
1541
+
1542
+ acfe_unset($columns, 'date');
 
1543
 
1544
  $columns['name'] = __('Name');
1545
  $columns['field_groups'] = __('Field groups', 'acf');
1578
 
1579
  foreach($field_groups as $field_group_key){
1580
 
1581
+ //acf_disable_filters();
1582
 
1583
+ $field_group = acf_get_field_group($field_group_key);
1584
 
1585
+ //acf_enable_filters();
1586
 
1587
+ if(!$field_group)
1588
+ continue;
1589
+
1590
+ if($field_group['ID']){
1591
+
1592
+ $fg[] = '<a href="' . admin_url('post.php?post=' . $field_group['ID'] . '&action=edit') . '">' . $field_group['title'] . '</a>';
1593
+
1594
+ }else{
1595
+
1596
+ $fg[] = $field_group['title'];
1597
+
1598
+ }
1599
 
1600
  }
1601
 
1697
 
1698
  }
1699
 
1700
+ // Update
1701
+ elseif($action === 'log_user'){
1702
+
1703
+ $users[] = '<span class="acf-js-tooltip dashicons dashicons-migrate" title="Log user"></span>';
1704
+ $found = true;
1705
+
1706
+ }
1707
+
1708
  }
1709
 
1710
  endwhile;
init.php CHANGED
@@ -51,6 +51,10 @@ function acfe_plugin_row($plugin_file, $plugin_data, $status){
51
  if(acfe()->has_acf())
52
  return;
53
 
 
 
 
 
54
  ?>
55
 
56
  <style>
@@ -73,9 +77,9 @@ function acfe_plugin_row($plugin_file, $plugin_data, $status){
73
  </style>
74
 
75
  <tr class="plugin-update-tr active acfe-plugin-tr">
76
- <td colspan="3" class="plugin-update colspanchange">
77
  <div class="update-message notice inline notice-error notice-alt">
78
- <p><?php _e('ACF Extended requires Advanced Custom Fields PRO (minimum: 5.7.10).', 'acfe'); ?></p>
79
  </div>
80
  </td>
81
  </tr>
51
  if(acfe()->has_acf())
52
  return;
53
 
54
+ $colspan = 4;
55
+ if(acf_version_compare($GLOBALS['wp_version'], '<', '5.5'))
56
+ $colspan = 3;
57
+
58
  ?>
59
 
60
  <style>
77
  </style>
78
 
79
  <tr class="plugin-update-tr active acfe-plugin-tr">
80
+ <td colspan="<?php echo $colspan; ?>" class="plugin-update colspanchange">
81
  <div class="update-message notice inline notice-error notice-alt">
82
+ <p><?php _e('ACF Extended requires <a href="https://www.advancedcustomfields.com/pro/" target="_blank">Advanced Custom Fields PRO</a> (minimum: 5.8).', 'acfe'); ?></p>
83
  </div>
84
  </td>
85
  </tr>
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: acf, custom fields, meta, admin, fields, form, repeater, content
5
  Requires at least: 4.9
6
  Tested up to: 5.5
7
  Requires PHP: 5.6
8
- Stable tag: 0.8.7.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -48,7 +48,7 @@ All-in-one enhancement suite that improves WordPress & Advanced Custom Fields.
48
  * [GitHub](https://github.com/acf-extended/ACF-Extended)
49
  * [Twitter](https://twitter.com/ACFExtended)
50
  * [Twitter](https://twitter.com/hwkfr) (Personal)
51
- * [Slack](https://join.slack.com/t/wpacf/shared_invite/enQtODc2MjczMzM3NzQ1LTQxNmY2ZGY3OTU2NDkxNTliYmNhMmY1NDMwZGM4NmYxNzgwZTI5MDUzMDFlMGQ5YzcwNDc0ZWM0MDVmODI4NmI)
52
 
53
  == 🧰 Tools ==
54
 
@@ -64,7 +64,7 @@ All-in-one enhancement suite that improves WordPress & Advanced Custom Fields.
64
 
65
  == 📝 Requirements ==
66
 
67
- **This plugin requires at least ACF Pro 5.7.10.** If you don't already own [ACF Pro](https://www.advancedcustomfields.com/pro/), you should consider it. It's one of the most powerful WordPress plugin available.
68
 
69
  == 📁 Field Groups ==
70
 
@@ -250,12 +250,12 @@ The Taxonomy, User profile & Settings views have been enhanced for a more consis
250
  **[WordPress Options](https://www.acf-extended.com/features/wordpress/options)**
251
  Manage WordPress Options from the Settings > Options page. Options values (strings, serialized & Json) will be displayed in a readable form. Values can be edited or deleted.
252
 
253
- == 🗺️ Multilangual ==
254
 
255
- **[Polylang](https://www.acf-extended.com/features/multilangual/polylang)**
256
  ACF Extended adds a new layer of compatibility for Polylang. ACF Options Pages and all ACF Extended Modules (Dynamic Post Type, Taxonomy, Options Pages, Block Type) are compatible.
257
 
258
- **[WPML](https://www.acf-extended.com/features/multilangual/wpml)**
259
  ACF Extended adds a new layer of compatibility for WPML. ACF Options Pages and all ACF Extended Modules (Dynamic Post Type, Taxonomy, Options Pages, Block Type) are compatible.
260
 
261
  == ❤️ Early Supporters ==
@@ -651,7 +651,7 @@ function my_acfe_modules(){
651
  // Disable Enhanced UI (Taxonomies, Users, Settings)
652
  acfe_update_setting('modules/ui', false);
653
 
654
- // Disable Multilangual Compatibility
655
  acfe_update_setting('modules/multilang', false);
656
 
657
  }
@@ -670,6 +670,24 @@ function my_acfe_modules(){
670
 
671
  == Changelog ==
672
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673
  = 0.8.7.1 =
674
  * General: WordPress 5.5 Compatibility - Fixed the new "Postbox Order Icons" size & only display them on postbox hover
675
  * General: ACF 5.9 Compatibility - Added missing legacy ACF 2 columns CSS
@@ -682,12 +700,12 @@ function my_acfe_modules(){
682
  * Module: Multilang - Added `filter('acfe/modules/multilang/options', $options_pages_id)` allowing to allow/exclude specific Options Pages Post ID
683
  * Module: Dynamic Forms - Email Action - Fixed 'Reply-to' headers which weren't correctly set
684
  * Module: Dynamic Forms - Fixed `{field:my_field:false}` Template Tag to disable value format
685
- * Module: Options - Fixed "Serialized" typo on edit screen
686
  * Module: Dynamic Post Types - Added additional check before `register_post_type()`
687
  * Module: Dynamic Post Types - Added "Show in menu (text)" to allow string value
688
  * Module: Dynamic Post Types - Fixed "Archive Slug" incorrectly set when empty while using the Import Tool
689
  * Module: Dynamic Block Types - Added additional check for Template, Script & Styles arguments before `register_block_type()`
690
  * Module: Dynamic Taxonomies - Added additional check before `register_taxonomy()`
 
691
  * Field: Button - Fixed typo in "Button Type" setting instructions
692
  * Field: Button - Added default class value `button button-secondary`
693
  * Field: Clone - Fixed "Edit in modal" setting to be available only when the "Display" setting is set to "Group"
@@ -804,7 +822,7 @@ function my_acfe_modules(){
804
  * General: Compatibility - Fixed WPML PHP notices in Field Groups
805
  * General: Compatibility - Fixed Advanced Forms PHP notice during ACF Extended: Forms submission
806
  * General: Readme - Added Field Bi-directional instructions to migrate already existing data
807
- * General: Readme - Added Multilangual section
808
  * General: Readme - Added Donators section
809
 
810
  = 0.8.6.3 =
5
  Requires at least: 4.9
6
  Tested up to: 5.5
7
  Requires PHP: 5.6
8
+ Stable tag: 0.8.7.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
48
  * [GitHub](https://github.com/acf-extended/ACF-Extended)
49
  * [Twitter](https://twitter.com/ACFExtended)
50
  * [Twitter](https://twitter.com/hwkfr) (Personal)
51
+ * [Slack Community](https://join.slack.com/t/wpacf/shared_invite/enQtODc2MjczMzM3NzQ1LTQxNmY2ZGY3OTU2NDkxNTliYmNhMmY1NDMwZGM4NmYxNzgwZTI5MDUzMDFlMGQ5YzcwNDc0ZWM0MDVmODI4NmI)
52
 
53
  == 🧰 Tools ==
54
 
64
 
65
  == 📝 Requirements ==
66
 
67
+ **This plugin requires at least ACF Pro 5.8.** If you don't already own [ACF Pro](https://www.advancedcustomfields.com/pro/), you should consider it. It's one of the most powerful WordPress plugin available.
68
 
69
  == 📁 Field Groups ==
70
 
250
  **[WordPress Options](https://www.acf-extended.com/features/wordpress/options)**
251
  Manage WordPress Options from the Settings > Options page. Options values (strings, serialized & Json) will be displayed in a readable form. Values can be edited or deleted.
252
 
253
+ == 🗺️ Multilingual ==
254
 
255
+ **[Polylang](https://www.acf-extended.com/features/multilingual/polylang)**
256
  ACF Extended adds a new layer of compatibility for Polylang. ACF Options Pages and all ACF Extended Modules (Dynamic Post Type, Taxonomy, Options Pages, Block Type) are compatible.
257
 
258
+ **[WPML](https://www.acf-extended.com/features/multilingual/wpml)**
259
  ACF Extended adds a new layer of compatibility for WPML. ACF Options Pages and all ACF Extended Modules (Dynamic Post Type, Taxonomy, Options Pages, Block Type) are compatible.
260
 
261
  == ❤️ Early Supporters ==
651
  // Disable Enhanced UI (Taxonomies, Users, Settings)
652
  acfe_update_setting('modules/ui', false);
653
 
654
+ // Disable Multilingual Compatibility
655
  acfe_update_setting('modules/multilang', false);
656
 
657
  }
670
 
671
  == Changelog ==
672
 
673
+ = 0.8.7.2 =
674
+ * Module: AutoSync - Reworked codebase, enhanced Field Groups Columns and added more information about files/folders detection
675
+ * Module: AutoSync - Added filters to target a specific field group for the PHP & Json save
676
+ * Module: AutoSync - Fixed an issue where "Available Json Sync" wouldn't be visible if the field group was using PHP Sync
677
+ * Module: Dynamic Forms - Fixed missing "Log User" icon in the Forms List screen
678
+ * Module: Dynamic Forms - Added `{current}`, `{get_field}`, `{get_option}`, `{query_var}`, `{request}` mapping in the "Custom Form Render" setting
679
+ * Module: Dynamic Forms - Added `acfe-form` to available post types in Polylang
680
+ * Module: Dynamic Forms - Local Field Groups can now be mapped
681
+ * Field Groups: Added Export PHP & Export Json to bulk actions
682
+ * Field Groups: Description column is now hidden by default
683
+ * Field Groups: Local - Added Export PHP, Export Json & Sync to database to bulk actions
684
+ * Field Groups: Categories - Added `acfe/modules/categories` setting to disable the custom taxonomy
685
+ * Field: Post Object - Fixed undefined PHP function when using the "Allow custom value" setting with ACF version below 5.8.10
686
+ * Field: Columns - Fixed "Endpoint" description typo
687
+ * General: Settings - Fixed postbox header CSS
688
+ * General: Compatibility - Fixed Post Type Order plugin which automatically drag&drop on ACF Field Groups UI
689
+ * General: Bumped minimum ACF Pro version to 5.8
690
+
691
  = 0.8.7.1 =
692
  * General: WordPress 5.5 Compatibility - Fixed the new "Postbox Order Icons" size & only display them on postbox hover
693
  * General: ACF 5.9 Compatibility - Added missing legacy ACF 2 columns CSS
700
  * Module: Multilang - Added `filter('acfe/modules/multilang/options', $options_pages_id)` allowing to allow/exclude specific Options Pages Post ID
701
  * Module: Dynamic Forms - Email Action - Fixed 'Reply-to' headers which weren't correctly set
702
  * Module: Dynamic Forms - Fixed `{field:my_field:false}` Template Tag to disable value format
 
703
  * Module: Dynamic Post Types - Added additional check before `register_post_type()`
704
  * Module: Dynamic Post Types - Added "Show in menu (text)" to allow string value
705
  * Module: Dynamic Post Types - Fixed "Archive Slug" incorrectly set when empty while using the Import Tool
706
  * Module: Dynamic Block Types - Added additional check for Template, Script & Styles arguments before `register_block_type()`
707
  * Module: Dynamic Taxonomies - Added additional check before `register_taxonomy()`
708
+ * Module: Options - Fixed "Serialized" typo on edit screen
709
  * Field: Button - Fixed typo in "Button Type" setting instructions
710
  * Field: Button - Added default class value `button button-secondary`
711
  * Field: Clone - Fixed "Edit in modal" setting to be available only when the "Display" setting is set to "Group"
822
  * General: Compatibility - Fixed WPML PHP notices in Field Groups
823
  * General: Compatibility - Fixed Advanced Forms PHP notice during ACF Extended: Forms submission
824
  * General: Readme - Added Field Bi-directional instructions to migrate already existing data
825
+ * General: Readme - Added Multilingual section
826
  * General: Readme - Added Donators section
827
 
828
  = 0.8.6.3 =