PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.8
Advanced Custom Fields: Extended v0.8
0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.9 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1 0.9.1.1 0.9.2 0.9.2.1 0.9.2.2 0.9.2.3 0.9.2.4 trunk 0.5 0.5.1 0.5.2 0.5.2.1 0.5.2.3 0.5.5 0.5.5.1 0.5.8 0.5.8.1 0.6 0.6.0.1 0.6.0.2 0.6.1 0.6.3 0.6.5 0.6.7 0.6.7.2 0.7 0.7.0.3 0.7.5 0.7.5.5 0.7.8 0.7.9 0.7.9.3 0.7.9.4 0.7.9.9.8 0.7.9.9.9 0.8 0.8.1 0.8.2 0.8.3 0.8.3.1 0.8.4 0.8.4.1 0.8.4.5 0.8.4.6 0.8.5 0.8.5.5
acf-extended / includes / fields-settings / settings.php
acf-extended / includes / fields-settings Last commit date
bidirectional.php 6 years ago data.php 6 years ago fields.php 6 years ago permissions.php 6 years ago settings.php 6 years ago validation.php 6 years ago
settings.php
417 lines
1 <?php
2
3 if(!defined('ABSPATH'))
4 exit;
5
6 if(!class_exists('acfe_field_settings')):
7
8 class acfe_field_settings{
9
10 function __construct(){
11
12 // Actions
13 add_action('load-post.php', array($this, 'load'));
14 add_action('wp_ajax_acf/field_group/render_field_settings', array($this, 'field_types_action'), 5);
15
16 // Filters
17 add_filter('acfe/load_field', array($this, 'load_field'));
18 add_filter('acf/prepare_field', array($this, 'prepare_field'));
19
20 }
21
22 /**
23 * Load
24 */
25 function load(){
26
27 if(!acf_is_screen('acf-field-group'))
28 return;
29
30 $this->field_types_action();
31
32 // Fix: Repeater
33 add_filter('acf/prepare_field/name=acfe_settings', array($this, 'fix_repeater'));
34 add_filter('acf/prepare_field/name=acfe_settings_location', array($this, 'fix_repeater'));
35 add_filter('acf/prepare_field/name=acfe_settings_settings', array($this, 'fix_repeater'));
36 add_filter('acf/prepare_field/name=acfe_settings_setting_type', array($this, 'fix_repeater'));
37 add_filter('acf/prepare_field/name=acfe_settings_setting_name', array($this, 'fix_repeater'));
38 add_filter('acf/prepare_field/name=acfe_settings_setting_operator', array($this, 'fix_repeater'));
39 add_filter('acf/prepare_field/name=acfe_settings_setting_value', array($this, 'fix_repeater'));
40
41 // Fix: Clone
42 add_filter('acf/update_field', array($this, 'fix_clone'));
43
44 }
45
46 /**
47 * Get field types
48 */
49 function field_types_action(){
50
51 // Get Fields Types
52 foreach(acf_get_field_types_info() as $field){
53
54 // Field type
55 $field_type = $field['name'];
56
57 // Exclude
58 if(in_array($field_type, array('message', 'accordion', 'tab', 'acfe_button', 'acfe_column', 'acfe_dynamic_message')))
59 continue;
60
61 add_action('acf/render_field_settings/type=' . $field_type, array($this, 'render_field_settings'), 990);
62
63 }
64
65 }
66
67 /**
68 * Add Setting
69 */
70 function render_field_settings($field){
71
72 $valid = false;
73
74 // Ajax
75 if(acf_verify_ajax()){
76
77 $field_group = acfe_get_field_group_from_field($field);
78
79 if(acf_maybe_get($field_group, 'acfe_form'))
80 $valid = true;
81
82 }
83
84 // Display
85 else{
86
87 if(acf_maybe_get($field, 'acfe_form'))
88 $valid = true;
89
90 if(!$valid && acf_maybe_get($field, '_name') === 'new_field'){
91
92 $field_group_id = get_the_ID();
93
94 if($field_group_id){
95
96 $field_group = acf_get_field_group($field_group_id);
97
98 if(acf_maybe_get($field_group, 'acfe_form'))
99 $valid = true;
100
101 }
102
103 }
104
105 }
106
107 if(!$valid)
108 return;
109
110 // Settings
111 acf_render_field_setting($field, array(
112 'label' => __('Advanced settings', 'acf'),
113 'name' => 'acfe_settings',
114 'key' => 'acfe_settings',
115 'instructions' => __('Change field settings based on location'),
116 'type' => 'repeater',
117 'button_label' => __('Add settings'),
118 'required' => false,
119 'layout' => 'row',
120 'sub_fields' => array(
121 array(
122 'label' => 'Location',
123 'name' => 'acfe_settings_location',
124 'key' => 'acfe_settings_location',
125 'type' => 'select',
126 'instructions' => '',
127 'required' => 0,
128 'conditional_logic' => 0,
129 'wrapper' => array(
130 'width' => '',
131 'class' => '',
132 'id' => '',
133 ),
134 'choices' => array(
135 'admin' => 'Administration',
136 'front' => 'Front-end',
137 ),
138 'allow_null' => true,
139 'multiple' => 0,
140 'ui' => 0,
141 'return_format' => 'value',
142 'ajax' => 0,
143 'placeholder' => 'Everywhere',
144 ),
145 array(
146 'label' => __('Settings'),
147 'name' => 'acfe_settings_settings',
148 'key' => 'acfe_settings_settings',
149 'instructions' => '',
150 'type' => 'repeater',
151 'button_label' => __('+'),
152 'required' => false,
153 'layout' => 'table',
154 'sub_fields' => array(
155 array(
156 'label' => 'Setting',
157 'name' => 'acfe_settings_setting_type',
158 'key' => 'acfe_settings_setting_type',
159 'prefix' => '',
160 '_name' => '',
161 '_prepare' => '',
162 'type' => 'select',
163 'instructions' => false,
164 'required' => false,
165 'wrapper' => array(
166 'width' => '',
167 'class' => '',
168 'id' => '',
169 ),
170 'choices' => array(
171 'required' => 'Required',
172 'hide_field' => 'Hide field',
173 'hide_label' => 'Hide label',
174 'default_value' => 'Default value',
175 'placeholder' => 'Placeholder',
176 'instructions' => 'Instructions',
177 'custom' => 'Custom setting',
178 )
179 ),
180 array(
181 'label' => 'Setting name',
182 'name' => 'acfe_settings_setting_name',
183 'key' => 'acfe_settings_setting_name',
184 'prefix' => '',
185 '_name' => '',
186 '_prepare' => '',
187 'type' => 'text',
188 'instructions' => false,
189 'required' => false,
190 'wrapper' => array(
191 'width' => '',
192 'class' => '',
193 'id' => '',
194 ),
195 'conditional_logic' => array(
196 array(
197 array(
198 'field' => 'acfe_settings_setting_type',
199 'operator' => '==',
200 'value' => 'custom',
201 )
202 )
203 )
204 ),
205 array(
206 'label' => 'Operator / Value',
207 'name' => 'acfe_settings_setting_operator',
208 'key' => 'acfe_settings_setting_operator',
209 'prefix' => '',
210 '_name' => '',
211 '_prepare' => '',
212 'type' => 'select',
213 'choices' => array(
214 'Values' => array(
215 'true' => '= true',
216 'false' => '= false',
217 'empty' => '= (empty)',
218 ),
219 'Operators' => array(
220 '=' => '=',
221 ),
222 ),
223 'instructions' => false,
224 'required' => false,
225 'wrapper' => array(
226 'width' => '',
227 'class' => '',
228 'id' => '',
229 ),
230 ),
231 array(
232 'label' => 'Value',
233 'name' => 'acfe_settings_setting_value',
234 'key' => 'acfe_settings_setting_value',
235 'prefix' => '',
236 '_name' => '',
237 '_prepare' => '',
238 'type' => 'text',
239 'instructions' => false,
240 'placeholder' => '',
241 'required' => false,
242 'wrapper' => array(
243 'width' => '',
244 'class' => '',
245 'id' => '',
246 ),
247 'conditional_logic' => array(
248 array(
249 array(
250 'field' => 'acfe_settings_setting_operator',
251 'operator' => '==',
252 'value' => '=',
253 )
254 ),
255 )
256 ),
257 )
258 ),
259 )
260 ), false);
261
262 }
263
264 /**
265 * Load field
266 */
267 function load_field($field){
268
269 if(!acf_maybe_get($field, 'acfe_settings'))
270 return $field;
271
272 $exclude = apply_filters('acfe/settings/exclude', false, $field);
273 if($exclude)
274 return $field;
275
276 foreach($field['acfe_settings'] as $k => $rule){
277
278 // Fix possible ACF Clone Index
279 if($k === 'acfcloneindex')
280 continue;
281
282 // Screen
283 $screen = isset($rule['acfe_settings_location']) ? $rule['acfe_settings_location'] : '';
284 $screen_allow = false;
285
286 // Screen: All
287 if(empty($screen)){
288
289 $screen_allow = true;
290
291 }
292
293 // Screen: Admin
294 elseif($screen === 'admin' && acfe_form_is_admin()){
295
296 $screen_allow = true;
297
298 }
299
300 // Screen: Front
301 elseif($screen === 'front' && acfe_form_is_front()){
302
303 $screen_allow = true;
304
305 }
306
307 if(!$screen_allow)
308 continue;
309
310 if(!acf_maybe_get($rule, 'acfe_settings_settings'))
311 continue;
312
313 // Properties
314 $properties = $rule['acfe_settings_settings'];
315
316 foreach($properties as $property){
317
318 // Required / Hide field / Hide label / Default value / Placeholder / Instructions
319 $property_name = $property['acfe_settings_setting_type'];
320
321 // Custom
322 if($property['acfe_settings_setting_type'] === 'custom'){
323
324 if(!isset($property['acfe_settings_setting_name']) || empty($property['acfe_settings_setting_name']))
325 continue;
326
327 $property_name = $property['acfe_settings_setting_name'];
328
329 }
330
331 // = value
332 if($property['acfe_settings_setting_operator'] === '='){
333
334 $field[$property_name] = $property['acfe_settings_setting_value'];
335
336 }
337
338 // = true
339 elseif($property['acfe_settings_setting_operator'] === 'true'){
340
341 $field[$property_name] = true;
342
343 }
344
345 // = false
346 elseif($property['acfe_settings_setting_operator'] === 'false'){
347
348 $field[$property_name] = false;
349
350 }
351
352 // = empty
353 elseif($property['acfe_settings_setting_operator'] === 'empty'){
354
355 $field[$property_name] = '';
356
357 }
358
359 }
360
361 }
362
363 return $field;
364
365 }
366
367 /*
368 * Additional settings
369 */
370 function prepare_field($field){
371
372 if(isset($field['hide_field']) && !empty($field['hide_field'])){
373
374 return false;
375
376 }
377
378 if(isset($field['hide_label']) && !empty($field['hide_label'])){
379
380 $field['label'] = '';
381
382 }
383
384 return $field;
385
386 }
387
388 /**
389 * Process Setting
390 */
391 function fix_repeater($field){
392
393 $field['prefix'] = str_replace('row-', '', $field['prefix']);
394 $field['name'] = str_replace('row-', '', $field['name']);
395
396 return $field;
397
398 }
399
400 /**
401 * Setting: ACF Clone Index fix for flexible duplicate
402 */
403 function fix_clone($field){
404
405 if(isset($field['acfe_settings']['acfcloneindex']))
406 $field['acfe_settings'] = false;
407
408 return $field;
409
410 }
411
412 }
413
414 // initialize
415 new acfe_field_settings();
416
417 endif;