PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.9.2.7
Advanced Custom Fields: Extended v0.9.2.7
0.9.2.7 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 / acfe-field-group-functions.php
acf-extended / includes Last commit date
admin 3 months ago field-groups 3 months ago fields 1 week ago fields-settings 3 months ago forms 3 months ago locations 3 months ago modules 1 week ago screens 3 months ago acfe-deprecated-functions.php 2 years ago acfe-field-functions.php 3 months ago acfe-field-group-functions.php 3 months ago acfe-file-functions.php 1 year ago acfe-form-functions.php 3 months ago acfe-helper-array-functions.php 3 months ago acfe-helper-functions.php 3 months ago acfe-helper-multi-functions.php 3 months ago acfe-helper-string-functions.php 3 months ago acfe-meta-functions.php 3 months ago acfe-post-functions.php 3 months ago acfe-screen-functions.php 3 months ago acfe-template-functions.php 3 months ago acfe-term-functions.php 3 months ago acfe-user-functions.php 3 months ago acfe-wp-functions.php 3 years ago assets.php 3 months ago compatibility-acf-5.8.php 4 months ago compatibility-acf-5.9.php 3 months ago compatibility-acf-6.5.php 3 months ago compatibility-acf-6.8.6.php 1 week ago compatibility.php 3 months ago field-extend.php 4 months ago field.php 4 months ago hooks.php 3 months ago init.php 3 months ago local-meta.php 3 years ago media.php 3 months ago module-acf.php 3 months ago module-db.php 3 months ago module-l10n.php 3 months ago module-legacy.php 3 years ago module-manager.php 4 months ago module-post.php 3 months ago module-posts.php 4 months ago module-upgrades.php 3 years ago module.php 3 months ago multilang.php 3 months ago revisions.php 4 months ago screen.php 3 months ago settings.php 3 months ago template-tags.php 3 months ago third-party.php 3 years ago upgrades.php 3 months ago
acfe-field-group-functions.php
648 lines
1 <?php
2
3 if(!defined('ABSPATH')){
4 exit;
5 }
6
7 /**
8 * acfe_get_post_id_field_groups
9 *
10 * Get all field groups for a specific Post ID
11 *
12 * @param int $post_id
13 *
14 * @return array
15 */
16 function acfe_get_post_id_field_groups($post_id = 0){
17
18 /**
19 * @string $post_id 12 | term_46 | user_22 | my-option | comment_89 | widget_56 | menu_74 | menu_item_96 | block_my-block | blog_55 | site_36 | attachment_24
20 * @string $id 12 | 46 | 22 | my-option | 89 | widget_56 | 74 | 96 | block_my-block | 55 | 36 | 24
21 * @string $type post | term | user | option | comment | option | term | post | block | blog | blog | post
22 */
23 $post_id = acf_get_valid_post_id($post_id);
24
25 // extract
26 extract(acf_decode_post_id($post_id));
27
28 /** @var $type */
29 /** @var $id */
30
31 // vars
32 $field_groups = array();
33 $post_type = '';
34 $taxonomy = '';
35
36 // check post id is attachment
37 if($type === 'post' && get_post_type($id) === 'attachment'){
38 $post_id = "attachment_{$id}";
39 }
40
41 // override attachment
42 if($type === 'post' && acfe_starts_with($post_id, 'attachment_')){
43
44 $type = 'attachment';
45
46 // override menu
47 }elseif($type === 'term' && acfe_starts_with($post_id, 'menu_')){
48
49 $type = 'menu';
50
51 // override user list
52 }elseif($post_id === 'user_options'){
53
54 $type = 'user_list';
55
56 // override attachment list
57 }elseif($post_id === 'attachment_options'){
58
59 $type = 'attachment_list';
60
61 // override post type list
62 }elseif($type === 'option' && strpos($post_id, 'tax_') === false && strpos($post_id, '_options') !== false){
63
64 // check post types for post_type_list
65 $post_types = acf_get_post_types();
66 $found = false;
67
68 // loop
69 foreach($post_types as $_post_type){
70
71 if($post_id !== "{$_post_type}_options") continue;
72
73 $found = $_post_type;
74 break;
75
76 }
77
78 if($found){
79
80 $post_type = $found;
81 $type = 'post_type_list';
82
83 }
84
85 // override taxonomy list
86 }elseif($type === 'option' && strpos($post_id, 'tax_') === 0 && strpos($post_id, '_options') !== false){
87
88 // check taxonomies for taxonomy_list
89 $taxonomies = acf_get_taxonomies();
90 $found = false;
91
92 // loop
93 foreach($taxonomies as $_taxonomy){
94
95 if($post_id !== "tax_{$_taxonomy}_options") continue;
96
97 $found = $_taxonomy;
98 break;
99
100 }
101
102 if($found){
103
104 $taxonomy = $found;
105 $type = 'taxonomy_list';
106
107 }
108
109 // override settings page
110 }elseif($type === 'option' && in_array($post_id, array('options-general', 'options-writing', 'options-reading', 'options-discussion', 'options-media', 'options-permalink'))){
111
112 $type = 'settings_page';
113
114 }
115
116 // user
117 if($type === 'user'){
118
119 $keys = array();
120
121 foreach(array('edit', 'new') as $user_form){
122
123 $_field_groups = acf_get_field_groups(array(
124 'user_id' => $id,
125 'user_form' => $user_form,
126 ));
127
128 foreach($_field_groups as $_field_group){
129
130 if(in_array($_field_group['key'], $keys)) continue;
131
132 $keys[] = $_field_group['key'];
133 $field_groups[] = $_field_group;
134
135 }
136
137 }
138
139 // attachment
140 }elseif($type === 'attachment'){
141
142 $field_groups = acf_get_field_groups(array(
143 'attachment_id' => $id,
144 'attachment' => $id,
145 ));
146
147 // taxonomy
148 }elseif($type === 'term'){
149
150 $term = get_term($id);
151
152 if($term && !is_wp_error($term)){
153
154 $taxonomy = $term->taxonomy;
155
156 $field_groups = acf_get_field_groups(array(
157 'taxonomy' => $taxonomy,
158 'term_id' => $id,
159 ));
160
161 }
162
163 // post type
164 }elseif($type === 'post'){
165
166 $post_type = get_post_type($post_id);
167
168 $field_groups = acf_get_field_groups(array(
169 'post_id' => $post_id,
170 'post_type' => $post_type,
171 ));
172
173 // options page
174 }elseif($type === 'option'){
175
176 // vars
177 $keys = array();
178 $options_pages = array();
179
180 // get all options pages using the post id
181 foreach(acf_get_options_pages() as $page){
182
183 if($page['post_id'] !== $id) continue;
184
185 $options_pages[] = $page;
186
187 }
188
189 foreach($options_pages as $page){
190
191 $_field_groups = acf_get_field_groups(array(
192 'options_page' => $page['menu_slug'],
193 ));
194
195 foreach($_field_groups as $_field_group){
196
197 if(in_array($_field_group['key'], $keys)) continue;
198
199 $keys[] = $_field_group['key'];
200 $field_groups[] = $_field_group;
201
202 }
203
204 }
205
206 // nav menu
207 }elseif($type === 'menu'){
208
209 $field_groups = acf_get_field_groups(array(
210 'screen' => 'nav_menu',
211 'post_id' => $id,
212 ));
213
214 // user list
215 }elseif($type === 'user_list'){
216
217 $field_groups = acf_get_field_groups(array(
218 'user_list' => 1,
219 ));
220
221 // attachment list
222 }elseif($type === 'attachment_list'){
223
224 $field_groups = acf_get_field_groups(array(
225 'attachment_list' => 1,
226 ));
227
228 // post type list
229 }elseif($type === 'post_type_list'){
230
231 $field_groups = acf_get_field_groups(array(
232 'post_type_list' => $post_type,
233 ));
234
235 // taxonomy list
236 }elseif($type === 'taxonomy_list'){
237
238 $field_groups = acf_get_field_groups(array(
239 'taxonomy_list' => $taxonomy,
240 ));
241
242 // settings page
243 }elseif($type === 'settings_page'){
244
245 $field_groups = acf_get_field_groups(array(
246 'wp_settings' => $post_id
247 ));
248
249 }
250
251 return $field_groups;
252
253 }
254
255 /**
256 * acfe_get_locations_array
257 *
258 * Legacy way to retrieve Field Groups Locations data in ACF 5.8
259 *
260 * @param $locations
261 *
262 * @return array
263 */
264 function acfe_get_locations_array($locations){
265
266 $return = array();
267 $types = acf_get_location_rule_types();
268
269 if(!$locations || !$types){
270 return $return;
271 }
272
273 $icon_default = 'admin-generic';
274
275 $icons = array(
276 'edit' => array(
277 'post_type',
278 'post_template',
279 'post_status',
280 'post_format',
281 'post',
282 ),
283 'media-default' => array(
284 'page_template',
285 'page_type',
286 'page_parent',
287 'page',
288 ),
289 'admin-users' => array(
290 'current_user',
291 'user_form',
292 ),
293 'welcome-widgets-menus' => array(
294 'widget',
295 'nav_menu',
296 'nav_menu_item',
297 ),
298 'category' => array(
299 'taxonomy',
300 'post_category',
301 'post_taxonomy',
302 ),
303 'admin-comments' => array(
304 'comment',
305 ),
306 'paperclip' => array(
307 'attachment',
308 ),
309 'admin-settings' => array(
310 'options_page',
311 ),
312 'businessman' => array(
313 'current_user_role',
314 'user_role',
315 ),
316 'admin-appearance' => array(
317 'acfe_template'
318 )
319 );
320
321 $rules = array();
322
323 foreach($types as $key => $type){
324
325 foreach($type as $slug => $name){
326
327 $icon = $icon_default;
328
329 foreach($icons as $_icon => $icon_slugs){
330
331 if(!in_array($slug, $icon_slugs)){
332 continue;
333 }
334
335 $icon = $_icon;
336 break;
337
338 }
339
340 $rules[ $slug ] = array(
341 'name' => $slug,
342 'label' => $name,
343 'icon' => $icon
344 );
345
346 }
347
348 }
349
350 foreach($locations as $group){
351
352 if(!acfe_get($rules, $group['param']) || !acfe_get($group, 'value')){
353 continue;
354 }
355
356 // init
357 $rule = $rules[ $group['param'] ];
358
359 // vars
360 $icon = $rule['icon'];
361 $name = $rule['name'];
362 $label = $rule['label'];
363 $operator = $group['operator'] === '==' ? '=' : $group['operator'];
364 $value = $group['value'];
365
366 // Exception for Post/Page/page Parent ID
367 if(in_array($group['param'], array('post', 'page', 'page_parent'))){
368
369 $value = get_the_title((int) $value);
370
371 }else{
372
373 // Validate value
374 $values = acf_get_location_rule_values($group);
375
376 if(!empty($values) && is_array($values)){
377
378 foreach($values as $value_slug => $value_name){
379
380 if($value != $value_slug){
381 continue;
382 }
383
384 $value = $value_name;
385
386 if(is_array($value_name) && isset($value_name[$value_slug])){
387 $value = $value_name[$value_slug];
388 }
389
390 break;
391
392 }
393
394 }
395
396 }
397
398 // html
399 $title = $label . ' ' . $operator . ' ' . $value;
400
401 $atts = array(
402 'class' => 'acf-js-tooltip dashicons dashicons-' . $icon,
403 'title' => $title
404 );
405
406 if($operator === '!='){
407
408 $atts['style'] = 'color: #ccc;';
409
410 }
411
412 $html = '<span ' . acf_esc_atts($atts) . '></span>';
413
414 $return[] = array(
415 'html' => $html,
416 'icon' => $icon,
417 'title' => $title,
418 'name' => $name,
419 'label' => $label,
420 'operator' => $operator,
421 'value' => $value,
422 );
423
424 }
425
426 return $return;
427
428 }
429
430 /**
431 * acfe_render_field_group_locations_html
432 *
433 * Legacy way to display Field Groups Locations in ACF 5.8
434 *
435 * @param $field_group
436 */
437 function acfe_render_field_group_locations_html($field_group){
438
439 foreach($field_group['location'] as $groups){
440
441 $html = acfe_get_locations_array($groups);
442
443 if($html){
444
445 $array = array();
446
447 foreach($html as $location){
448 $array[] = $location['html'];
449 }
450
451 echo implode(' ', $array);
452
453 }
454
455 }
456
457 }
458
459 /**
460 * acfe_add_field_groups_metabox
461 *
462 * @param array $args
463 */
464 function acfe_add_field_groups_metabox($args = array()){
465
466 $args = wp_parse_args($args, array(
467 'id' => 'acfe-field-groups',
468 'title' => __('Field Groups', 'acfe'),
469 'screen' => '',
470 'context' => 'normal',
471 'priority' => 'default',
472 'field_groups' => array(),
473 ));
474
475 add_meta_box($args['id'], $args['title'], function($object, $data) use($args){
476
477 $field_groups = $data['args'];
478
479 acfe_render_field_groups_details($field_groups);
480
481 ?><script type="text/javascript">
482 (function($){
483
484 if(typeof acf === 'undefined'){
485 return;
486 }
487
488 var metabox = acf.newPostbox(<?php echo wp_json_encode(array(
489 'id' => $args['id'],
490 'key' => '',
491 'style' => 'default',
492 'label' => 'left',
493 'edit' => false
494 )); ?>);
495
496 <?php if(empty($field_groups)){ ?>
497 metabox.hide();
498 <?php } ?>
499
500 })(jQuery);
501 </script>
502 <?php
503
504 }, $args['screen'], $args['context'], $args['priority'], $args['field_groups']);
505
506 }
507
508
509 /**
510 * acfe_render_field_groups_details
511 *
512 * @param $field_groups
513 *
514 * @return void
515 */
516 function acfe_render_field_groups_details($field_groups){
517
518 foreach($field_groups as $field_group){
519
520 // no field group ID found
521 if(empty($field_group['ID'])){
522
523 // get raw field group from db
524 $raw_field_group = acf_get_raw_field_group($field_group['key']);
525
526 // raw field group found
527 if($raw_field_group && !empty($raw_field_group['ID'])){
528 $field_group['ID'] = $raw_field_group['ID'];
529 }
530
531 }
532
533 // vars
534 $fields = acf_get_fields($field_group);
535 $url = $field_group['ID'] ? admin_url("post.php?post={$field_group['ID']}&action=edit") : false;
536 $edit = $url ? '(<a href="' . $url . '">' . __('edit'). '</a>)' : '';
537 ?>
538
539 <div class="acf-field">
540
541 <div class="acf-label">
542 <label><?php echo $field_group['title']; ?> <?php echo $edit; ?></label>
543 <p class="description"><code style="font-size:12px;"><?php echo $field_group['key']; ?></code></p>
544 </div>
545
546 <div class="acf-input">
547 <?php if(!empty($fields)){ ?>
548
549 <?php $details = acfe_get_fields_details_recursive($fields); ?>
550
551 <table class="acf-table">
552 <thead>
553 <th class="acf-th" width="25%" style="background: #fcfcfc;"><strong><?php _e('Label', 'acfe'); ?></strong></th>
554 <th class="acf-th" width="25%" style="background: #fcfcfc;"><strong><?php _e('Name', 'acfe'); ?></strong></th>
555 <th class="acf-th" width="25%" style="background: #fcfcfc;"><strong><?php _e('Key', 'acfe'); ?></strong></th>
556 <th class="acf-th" width="25%" style="background: #fcfcfc;"><strong><?php _e('Type', 'acfe'); ?></strong></th>
557 </thead>
558
559 <tbody>
560 <?php foreach($details as $field){ ?>
561
562 <?php
563 $field_name = $field['name'] ? '<code style="font-size:12px;">' . $field['name'] . '</code>' : '';
564 $field_key = $field['key'] ? '<code style="font-size:12px;">' . $field['key'] . '</code>' : '';
565 ?>
566
567 <tr class="acf-row">
568 <td width="25%" style="border-color:#e1e1e1;"><?php echo $field['label']; ?></td>
569 <td width="25%" style="border-color:#e1e1e1;"><?php echo $field_name; ?></td>
570 <td width="25%" style="border-color:#e1e1e1;"><?php echo $field_key; ?></td>
571 <td width="25%" style="border-color:#e1e1e1;"><?php echo $field['type']; ?></td>
572 </tr>
573 <?php } ?>
574 </tbody>
575 </table>
576
577 <?php } ?>
578 </div>
579
580 </div>
581
582 <?php }
583
584 }
585
586
587 /**
588 * acfe_render_group_setting
589 *
590 * Render field group settings, compatible with dot notation and nested settings
591 *
592 * @param $field_group
593 * @param $setting
594 * @param $element
595 * @param $instruction
596 * @param $is_field_setting
597 *
598 * @return void
599 */
600 function acfe_render_group_setting($field_group, $setting, $element = 'div', $instruction = 'label', $is_field_setting = false){
601
602 // use key as name
603 if(isset($setting['key']) && !isset($setting['name'])){
604 $setting['name'] = $setting['key'];
605 }
606
607 // default vars
608 $key = $setting['name'];
609 $parents = array();
610
611 // name has path
612 if(acfe_has($setting['name'], '.')){
613 $parents = explode('.', $setting['name']); // retrieve parents
614 $key = array_pop($parents); // key is last part
615 }
616
617 // default key
618 if(!isset($setting['key']) && isset($setting['name'])){
619 $setting['key'] = $key;
620 }
621
622 // default prefix
623 if(!isset($setting['prefix'])){
624
625 $setting['prefix'] = 'acf_field_group';
626 if($parents){
627 foreach($parents as $parent){
628 $setting['prefix'] .= "[{$parent}]";
629 }
630 }
631
632 }
633
634 // default value
635 if(!isset($setting['value']) && isset($setting['key'])){
636
637 $path = implode('.', $parents);
638 $path = !empty($path) ? "{$path}." : '';
639 $path = $path . $setting['key'];
640
641 $setting['value'] = acfe_get($field_group, $path);
642
643 }
644
645 // render field setting
646 acf_render_field_wrap($setting, $element, $instruction, $is_field_setting);
647
648 }