PluginProbe
Advanced Custom Fields: Extended / 0.8.6.3
Advanced Custom Fields: Extended v0.8.6.3
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 All 92 releases
acf-extended / includes / modules / form / admin.php
admin.php
3,261 lines 108.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if(!defined('ABSPATH'))
4 exit;
5
6 // Register notices store.
7 acf_register_store('acfe/form')->prop('multisite', true);
8
9 if(!class_exists('acfe_form')):
10
11 class acfe_form{
12
13 public $post_type = '';
14 public $fields_groups = array();
15
16 public $posts = array();
17 public $users = array();
18
19 public $query_vars = array();
20
21 function __construct(){
22
23 // Post Type
24 $this->post_type = 'acfe-form';
25
26 // Admin
27 add_action('init', array($this, 'init'));
28 add_action('admin_menu', array($this, 'admin_menu'));
29 add_action('current_screen', array($this, 'current_screen'));
30 add_filter('post_row_actions', array($this, 'row_actions'), 10, 2);
31
32 // ACF
33 add_filter('acf/get_post_types', array($this, 'filter_post_type'), 10, 2);
34 add_filter('acf/pre_load_post_id', array($this, 'validate_post_id'), 10, 2);
35
36 // Fields
37 add_filter('acf/load_value/name=acfe_form_custom_html_enable', array($this, 'prepare_custom_html'), 10, 3);
38 add_filter('acf/prepare_field/name=acfe_form_actions', array($this, 'prepare_actions'));
39 add_filter('acf/prepare_field/name=acfe_form_field_groups', array($this, 'field_groups_choices'));
40
41 // Format values
42 add_filter('acfe/form/format_value/type=post_object', array($this, 'format_value_post_object'), 5, 4);
43 add_filter('acfe/form/format_value/type=relationship', array($this, 'format_value_post_object'), 5, 4);
44 add_filter('acfe/form/format_value/type=user', array($this, 'format_value_user'), 5, 4);
45 add_filter('acfe/form/format_value/type=taxonomy', array($this, 'format_value_taxonomy'), 5, 4);
46 add_filter('acfe/form/format_value/type=image', array($this, 'format_value_file'), 5, 4);
47 add_filter('acfe/form/format_value/type=file', array($this, 'format_value_file'), 5, 4);
48 add_filter('acfe/form/format_value/type=select', array($this, 'format_value_select'), 5, 4);
49 add_filter('acfe/form/format_value/type=checkbox', array($this, 'format_value_select'), 5, 4);
50 add_filter('acfe/form/format_value/type=radio', array($this, 'format_value_select'), 5, 4);
51 add_filter('acfe/form/format_value/type=google_map', array($this, 'format_value_google_map'), 5, 4);
52
53 add_action('acf/render_field/name=acfe_form_validation_advanced_field_validation', array($this, 'doc_validation_field'));
54 add_action('acf/render_field/name=acfe_form_validation_advanced_form_validation', array($this, 'doc_validation_form'));
55 add_action('acf/render_field/name=acfe_form_submission_advanced_submission', array($this, 'doc_submission'));
56
57 add_action('acf/render_field/name=acfe_form_cheatsheet_field', array($this, 'doc_field'));
58 add_action('acf/render_field/name=acfe_form_cheatsheet_fields', array($this, 'doc_fields'));
59 add_action('acf/render_field/name=acfe_form_cheatsheet_get_field', array($this, 'doc_get_field'));
60 add_action('acf/render_field/name=acfe_form_cheatsheet_get_option', array($this, 'doc_get_option'));
61 add_action('acf/render_field/name=acfe_form_cheatsheet_query_var', array($this, 'doc_query_var'));
62 add_action('acf/render_field/name=acfe_form_cheatsheet_request', array($this, 'doc_request'));
63 add_action('acf/render_field/name=acfe_form_cheatsheet_current_post', array($this, 'doc_current_post'));
64 add_action('acf/render_field/name=acfe_form_cheatsheet_current_term', array($this, 'doc_current_term'));
65 add_action('acf/render_field/name=acfe_form_cheatsheet_current_user', array($this, 'doc_current_user'));
66 add_action('acf/render_field/name=acfe_form_cheatsheet_current_author', array($this, 'doc_current_author'));
67 add_action('acf/render_field/name=acfe_form_cheatsheet_current_form', array($this, 'doc_current_form'));
68
69 // Ajax
70 /*
71 add_action('wp_ajax_acf/fields/select/query', array($this, 'ajax_query_post'), 5);
72 add_action('wp_ajax_nopriv_acf/fields/select/query', array($this, 'ajax_query_post'), 5);
73
74 add_action('wp_ajax_acf/fields/select/query', array($this, 'ajax_query_user'), 5);
75 add_action('wp_ajax_nopriv_acf/fields/select/query', array($this, 'ajax_query_user'), 5);
76
77 add_action('wp_ajax_acf/fields/select/query', array($this, 'ajax_query_term'), 5);
78 add_action('wp_ajax_nopriv_acf/fields/select/query', array($this, 'ajax_query_term'), 5);
79 */
80 }
81
82 function init(){
83
84 // Post Type
85 register_post_type($this->post_type, array(
86 'label' => __('Forms', 'acf'),
87 'description' => __('Forms', 'acf'),
88 'labels' => array(
89 'name' => __('Forms', 'acf'),
90 'singular_name' => __('Form', 'acf'),
91 'menu_name' => __('Forms', 'acf'),
92 'edit_item' => 'Edit Form',
93 'add_new_item' => 'New Form',
94 ),
95 'supports' => array('title'),
96 'hierarchical' => false,
97 'public' => false,
98 'show_ui' => true,
99 'show_in_menu' => false,
100 'menu_icon' => 'dashicons-feedback',
101 'show_in_admin_bar' => false,
102 'show_in_nav_menus' => false,
103 'can_export' => false,
104 'has_archive' => false,
105 'rewrite' => false,
106 'exclude_from_search' => true,
107 'publicly_queryable' => false,
108 'capabilities' => array(
109 'publish_posts' => acf_get_setting('capability'),
110 'edit_posts' => acf_get_setting('capability'),
111 'edit_others_posts' => acf_get_setting('capability'),
112 'delete_posts' => acf_get_setting('capability'),
113 'delete_others_posts' => acf_get_setting('capability'),
114 'read_private_posts' => acf_get_setting('capability'),
115 'edit_post' => acf_get_setting('capability'),
116 'delete_post' => acf_get_setting('capability'),
117 'read_post' => acf_get_setting('capability'),
118 ),
119 'acfe_admin_ppp' => 999,
120 'acfe_admin_orderby' => 'title',
121 'acfe_admin_order' => 'ASC',
122 ));
123
124 }
125
126 function admin_menu(){
127
128 if(!acf_get_setting('show_admin'))
129 return;
130
131 add_submenu_page('edit.php?post_type=acf-field-group', __('Forms', 'acf'), __('Forms', 'acf'), acf_get_setting('capability'), 'edit.php?post_type=' . $this->post_type);
132
133 }
134
135 function current_screen(){
136
137 global $typenow;
138
139 if($typenow !== $this->post_type)
140 return;
141
142 // customize post_status
143 global $wp_post_statuses;
144
145 // modify publish post status
146 $wp_post_statuses['publish']->label_count = _n_noop('Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', 'acf');
147
148 add_action('load-edit.php', array($this, 'load_list'));
149 add_action('load-post.php', array($this, 'load_post'));
150 add_action('load-post-new.php', array($this, 'load_post_new'));
151
152 add_action('load-post.php', array($this, 'load'));
153 add_action('load-post-new.php', array($this, 'load'));
154
155 }
156
157 function load_list(){
158
159 // Columns
160 add_filter('manage_edit-' . $this->post_type . '_columns', array($this, 'admin_columns'));
161 add_action('manage_' . $this->post_type . '_posts_custom_column', array($this, 'admin_columns_html'), 10, 2);
162
163 }
164
165 function load_post(){
166
167 // vars
168 $this->fields_groups = $this->get_fields_groups();
169
170 add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
171
172 // Misc actions
173 add_action('post_submitbox_misc_actions', array($this, 'misc_actions'));
174
175 // Actions
176 if(isset($_REQUEST['post']) && !empty($_REQUEST['post'])){
177
178 $form_id = $_REQUEST['post'];
179
180 if(have_rows('acfe_form_actions', $form_id)):
181
182 while(have_rows('acfe_form_actions', $form_id)): the_row();
183
184 $action = get_row_layout();
185
186 // Custom Action
187 if($action === 'custom')
188 continue;
189
190 $alias = get_sub_field('acfe_form_custom_alias');
191 $query_var = get_sub_field('acfe_form_custom_query_var');
192
193 $action_label = '';
194 $action_type = '';
195
196 if($action === 'post'){
197
198 $action_label = 'Post';
199
200 $post_action = get_sub_field('acfe_form_post_action');
201
202 if($post_action === 'insert_post'){
203
204 $action_type = 'Create Post';
205
206 }elseif($post_action === 'update_post'){
207
208 $action_type = 'Update Post';
209
210 }
211
212
213 }elseif($action === 'term'){
214
215 $action_label = 'Term';
216
217 $term_action = get_sub_field('acfe_form_term_action');
218
219 if($term_action === 'insert_term'){
220
221 $action_type = 'Create Term';
222
223 }elseif($term_action === 'update_term'){
224
225 $action_type = 'Update Term';
226
227 }
228
229 }elseif($action === 'user'){
230
231 $action_label = 'User';
232
233 $term_action = get_sub_field('acfe_form_user_action');
234
235 if($term_action === 'insert_user'){
236
237 $action_type = 'Create User';
238
239 }elseif($term_action === 'update_user'){
240
241 $action_type = 'Update User';
242
243 }elseif($term_action === 'log_user'){
244
245 $action_type = 'Log User';
246
247 }
248
249 }elseif($action === 'email'){
250
251 $action_label = 'E-mail';
252 $action_type = 'Send';
253
254 }
255
256 if(empty($alias) || empty($query_var))
257 continue;
258
259 $this->query_vars[] = array(
260 'action' => $action,
261 'action_label' => $action_label,
262 'action_type' => $action_type,
263 'alias' => $alias
264 );
265
266 endwhile;
267 endif;
268
269 }
270
271 }
272
273 function load_post_new(){
274
275 // ...
276
277 }
278
279 function load(){
280
281 // Save Post
282 add_action('acf/save_post', array($this, 'save_form'), 20);
283
284 // Metaboxes
285 remove_meta_box('slugdiv', $this->post_type, 'normal');
286
287 // Menu
288 add_filter('parent_file', function(){
289 return 'edit.php?post_type=acf-field-group';
290 });
291
292 // Submenu
293 add_filter('submenu_file', function(){
294 return 'edit.php?post_type=' . $this->post_type;
295 });
296
297 // Footer
298 add_action('admin_footer', array($this, 'load_footer'));
299
300 }
301
302 function misc_actions($post){
303
304 $name = get_field('acfe_form_name', $post->ID);
305
306 ?>
307 <div class="misc-pub-section misc-pub-acfe-field-group-export" style="padding-top:2px;">
308 <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=acfe_tool_form_export&action=json&keys=' . $name); ?>">Json</a>
309 </div>
310 <?php
311
312 }
313
314 function load_footer(){
315 ?>
316 <script type="text/javascript">
317 (function($){
318
319 if(typeof acf === 'undefined')
320 return;
321
322 $('#post').submit(function(e){
323
324 // vars
325 var $title = $('#titlewrap #title');
326
327 // empty
328 if(!$title.val()){
329
330 // prevent default
331 e.preventDefault();
332
333 // alert
334 alert('Form title is required.');
335
336 // focus
337 $title.focus();
338
339 }
340
341 });
342
343 })(jQuery);
344 </script>
345 <?php
346 }
347
348 function filter_post_type($post_types, $args){
349
350 if(empty($post_types))
351 return $post_types;
352
353 foreach($post_types as $k => $post_type){
354
355 if($post_type !== $this->post_type)
356 continue;
357
358 unset($post_types[$k]);
359
360 }
361
362 return $post_types;
363
364 }
365
366 function row_actions($actions, $post){
367
368 if($post->post_type !== $this->post_type || $post->post_status !== 'publish')
369 return $actions;
370
371 $post_id = $post->ID;
372 $name = get_field('acfe_form_name', $post_id);
373
374 $actions['acfe_form_export_json'] = '<a href="' . admin_url('edit.php?post_type=acf-field-group&page=acf-tools&tool=acfe_tool_form_export&action=json&keys=' . $name) . '">' . __('Json') . '</a>';
375
376 return $actions;
377
378 }
379
380 function get_fields_groups($form_id = false){
381
382 if(!$form_id)
383 $form_id = get_the_ID();
384
385 if(!$form_id && isset($_REQUEST['post']))
386 $form_id = $_REQUEST['post'];
387
388 if(!$form_id)
389 return false;
390
391 $return = array();
392
393 // Field Groups
394 $field_groups = get_field('acfe_form_field_groups', $form_id);
395
396 if(!empty($field_groups)){
397
398 foreach($field_groups as $field_group_key){
399
400 $field_group = acf_get_field_group($field_group_key);
401 if(!$field_group)
402 continue;
403
404 $field_group['fields'] = acf_get_fields($field_group);
405
406 $return[] = $field_group;
407
408 }
409
410 }
411
412 // return
413 return $return;
414
415 }
416
417 function save_form($post_id){
418
419 // Get Post
420 $name = get_field('acfe_form_name', $post_id);
421
422 // Update post
423 wp_update_post(array(
424 'ID' => $post_id,
425 'post_name' => $name,
426 ));
427
428 $new_name = get_post_field('post_name', $post_id);
429
430 if($new_name !== $name)
431 update_field('acfe_form_name', $new_name, $post_id);
432
433 }
434
435 function add_meta_boxes(){
436
437 // Add Instructions
438 add_meta_box(
439
440 // ID
441 'acfe-form-integration',
442
443 // Title
444 'Integration',
445
446 // Render
447 array($this, 'render_form_integration_meta_box'),
448
449 // Screen
450 $this->post_type,
451
452 // Position
453 'side',
454
455 // Priority
456 'core'
457
458 );
459
460 $data = $this->fields_groups;
461
462 if(!empty($data)){
463
464 add_meta_box(
465
466 // ID
467 'acfe-form-details',
468
469 // Title
470 __('Fields', 'acf'),
471
472 // Render
473 array($this, 'render_form_details_meta_box'),
474
475 // Screen
476 $this->post_type,
477
478 // Position
479 'normal',
480
481 // Priority
482 'default'
483
484 );
485
486 }
487
488 }
489
490 function render_form_integration_meta_box($post){
491
492 $form_id = $post->ID;
493 $form_name = get_field('acfe_form_name', $form_id);
494
495 ?>
496 <div class="acf-field">
497
498 <div class="acf-label">
499 <label>Shortcodes:</label>
500 </div>
501
502 <div class="acf-input">
503
504 <code>[acfe_form ID="<?php echo $form_id; ?>"]</code><br /><br />
505 <code>[acfe_form name="<?php echo $form_name; ?>"]</code>
506
507 </div>
508
509 </div>
510
511 <div class="acf-field">
512
513 <div class="acf-label">
514 <label>PHP code:</label>
515 </div>
516
517 <div class="acf-input">
518
519 <pre>&lt;?php get_header(); ?&gt;
520
521 &lt;!-- <?php echo get_the_title($form_id); ?> --&gt;
522 &lt;?php acfe_form(&apos;<?php echo $form_name; ?>&apos;); ?&gt;
523
524 &lt;?php get_footer(); ?&gt;</pre>
525
526 </div>
527
528 </div>
529
530 <script type="text/javascript">
531 if(typeof acf !== 'undefined'){
532
533 acf.newPostbox(<?php echo wp_json_encode(array(
534 'id' => 'acfe-form-integration',
535 'key' => '',
536 'style' => 'default',
537 'label' => 'top',
538 'edit' => false
539 )); ?>);
540
541 }
542 </script>
543 <?php
544 }
545
546 function render_form_details_meta_box($array, $data){
547
548 foreach($this->fields_groups as $field_group){ ?>
549
550 <?php
551 acf_disable_filters();
552
553 $field_group_db = acf_get_field_group($field_group['key']);
554
555 acf_enable_filters();
556 ?>
557
558 <div class="acf-field">
559
560 <div class="acf-label">
561 <label><a href="<?php echo admin_url('post.php?post=' . $field_group_db['ID'] . '&action=edit'); ?>"><?php echo $field_group['title']; ?></a></label>
562 <p class="description"><?php echo $field_group['key']; ?></p>
563 </div>
564
565 <div class="acf-input">
566
567 <?php if(!empty($field_group['fields'])){ ?>
568
569 <table class="acf-table">
570 <thead>
571 <th class="acf-th" width="25%"><strong>Label</strong></th>
572 <th class="acf-th" width="25%"><strong>Name</strong></th>
573 <th class="acf-th" width="25%"><strong>Key</strong></th>
574 <th class="acf-th" width="25%"><strong>Type</strong></th>
575 </thead>
576
577 <tbody>
578 <?php
579
580 $array = array();
581 foreach($field_group['fields'] as $field){
582
583 $this->get_fields_labels_recursive($array, $field);
584
585 }
586
587 foreach($array as $field_key => $field_label){
588
589 $field = acf_get_field($field_key);
590 $type = acf_get_field_type($field['type']);
591 $type_label = '-';
592 if(isset($type->label))
593 $type_label = $type->label;
594 ?>
595
596 <tr class="acf-row">
597 <td width="25%"><?php echo $field_label; ?></td>
598 <td width="25%"><code style="font-size:12px;"><?php echo $field['name']; ?></code></td>
599 <td width="25%"><code style="font-size:12px;"><?php echo $field_key; ?></code></td>
600 <td width="25%"><?php echo $type_label; ?></td>
601 </tr>
602
603 <?php } ?>
604 </tbody>
605 </table>
606
607 <?php } ?>
608 </div>
609
610 </div>
611
612 <?php } ?>
613
614 <script type="text/javascript">
615 if(typeof acf !== 'undefined'){
616
617 acf.newPostbox(<?php echo wp_json_encode(array(
618 'id' => 'acfe-form-details',
619 'key' => '',
620 'style' => 'default',
621 'label' => 'left',
622 'edit' => false
623 )); ?>);
624
625 }
626 </script>
627 <?php
628
629 }
630
631 function get_fields_labels_recursive(&$array, $field){
632
633 $label = '';
634
635 $ancestors = isset($field['ancestors']) ? $field['ancestors'] : count(acf_get_field_ancestors($field));
636 $label = str_repeat('- ', $ancestors) . $label;
637
638 $label .= !empty($field['label']) ? $field['label'] : '(' . __('no label', 'acf') . ')';
639 $label .= $field['required'] ? ' <span class="acf-required">*</span>' : '';
640
641 $array[$field['key']] = $label;
642
643 if(isset($field['sub_fields']) && !empty($field['sub_fields'])){
644
645 foreach($field['sub_fields'] as $s_field){
646
647 $this->get_fields_labels_recursive($array, $s_field);
648
649 }
650
651 }
652
653 }
654
655 // Field groups choices
656 function field_groups_choices($field){
657
658 acf_disable_filters();
659
660 $field_groups = acf_get_field_groups();
661 if(empty($field_groups))
662 return $field;
663
664 foreach($field_groups as $field_group){
665
666 $field['choices'][$field_group['key']] = $field_group['title'];
667
668 }
669
670 acf_enable_filters();
671
672 return $field;
673
674 }
675
676 function map_field_groups($field){
677
678 $post_id = get_the_ID();
679
680 $field_groups = get_field('acfe_form_field_groups', $post_id);
681
682 if(empty($field_groups))
683 return false;
684
685 foreach($field_groups as $field_group_key){
686
687 $field_group = acf_get_field_group($field_group_key);
688 if(!$field_group)
689 continue;
690
691 $field['choices'][$field_group_key] = $field_group['title'];
692
693 }
694
695 return $field;
696
697 }
698
699 function prepare_custom_html($value, $post_id, $field){
700
701 $custom_html = trim(get_field('acfe_form_custom_html', $post_id));
702
703 if($value === false && !empty($custom_html))
704 $value = true;
705
706 return $value;
707
708 }
709
710 function prepare_actions($field){
711
712 $field['instructions'] = 'Add actions on form submission';
713
714 $data = $this->fields_groups;
715
716 if(empty($data)){
717
718 $field['instructions'] .= '<br /><u>No field groups are currently mapped</u>';
719
720 }
721
722 return $field;
723
724 }
725
726 function map_fields_deep_no_custom($field){
727
728 $choices = array();
729
730 if(!empty($field['choices'])){
731
732 $generic = true;
733
734 if(is_array($field['choices']) && count($field['choices']) === 1){
735
736 reset($field['choices']);
737 $key = key($field['choices']);
738
739 if(acf_is_field_key($key))
740 $generic = false;
741
742 }
743
744 if($generic)
745 $choices['Generic'] = $field['choices'];
746
747 }
748
749 $fields_choices = $this->get_fields_choices(true, $field);
750
751 if(!empty($fields_choices)){
752
753 $field['choices'] = array_merge($choices, $fields_choices);
754
755 }
756
757 return $field;
758
759 }
760
761 function map_fields_deep($field){
762
763 // Map Fields
764 $fields_choices = $this->get_fields_choices(true, $field);
765
766 if(!empty($fields_choices)){
767
768 $field['choices'] = array_merge($field['choices'], $fields_choices);
769
770 }
771
772 if($field['type'] === 'select'){
773
774 // Query Vars
775 if(!empty($this->query_vars)){
776
777 parse_str($field['prefix'], $output);
778 $keys = acfe_array_keys_r($output);
779
780 if(acf_maybe_get($keys, 1) !== 'field_acfe_form_actions')
781 return $field;
782
783 foreach($this->query_vars as $row => $query_var){
784
785 $field_row = acf_maybe_get($keys, 2);
786 $field_row = str_replace('row-', '', $field_row);
787
788 if((is_numeric($field_row) && $field_row > $row) || $field_row === 'acfcloneindex'){
789
790 $action = $query_var['action'];
791 $action_label = $query_var['action_label'];
792 $action_type = $query_var['action_type'];
793 $alias = $query_var['alias'];
794
795 $tags = array();
796
797 if($action === 'post'){
798
799 $tags = array(
800 "{query_var:$alias:ID}" => 'Post ID',
801 "{query_var:$alias:post_title}" => 'Title',
802 "{query_var:$alias:permalink}" => 'Permalink',
803 "{query_var:$alias:admin_url}" => 'Admin URL',
804 );
805
806 }
807
808 elseif($action === 'term'){
809
810 $tags = array(
811 "{query_var:$alias:ID}" => 'Term ID',
812 "{query_var:$alias:name}" => 'Name',
813 "{query_var:$alias:permalink}" => 'Permalink',
814 "{query_var:$alias:admin_url}" => 'Admin URL',
815 );
816
817 }
818
819 elseif($action === 'user'){
820
821 $tags = array(
822 "{query_var:$alias:ID}" => 'User ID',
823 "{query_var:$alias:user_email}" => 'E-mail',
824 "{query_var:$alias:permalink}" => 'Permalink',
825 );
826
827 }
828
829 elseif($action === 'email'){
830
831 $tags = array(
832 "{query_var:$alias:from}" => 'From',
833 "{query_var:$alias:to}" => 'To',
834 "{query_var:$alias:content}" => 'Content',
835 );
836
837 }
838
839 foreach($tags as $tag_key => $tag_value){
840
841 $field['choices']["Action: $action_type ($alias)"][$tag_key] = $tag_value . ' ' . $tag_key;
842
843 }
844
845 }
846
847 }
848 }
849
850 // Templates Tags Examples
851 $field['choices']["Current: Post"]['{current:post:ID}'] = 'Post ID {current:post:ID}';
852 $field['choices']["Current: Post"]['{current:post:post_title}'] = 'Title {current:post:post_title}';
853 $field['choices']["Current: Post"]['{current:post:permalink}'] = 'Permalink {current:post:permalink}';
854 $field['choices']["Current: Post"]['{current:post:post_author}'] = 'Author {current:post:post_author}';
855
856 $field['choices']["Current: Term"]['{current:term:ID}'] = 'Term ID {current:term:ID}';
857 $field['choices']["Current: Term"]['{current:term:name}'] = 'Name {current:term:name}';
858 $field['choices']["Current: Term"]['{current:term:permalink}'] = 'Permalink {current:term:permalink}';
859
860 $field['choices']["Current: User"]['{current:user:ID}'] = 'User ID {current:user:ID}';
861 $field['choices']["Current: User"]['{current:user:user_email}'] = 'E-mail {current:user:user_email}';
862 $field['choices']["Current: User"]['{current:user:permalink}'] = 'Permalink {current:user:permalink}';
863
864 $field['choices']["Current: Author"]['{current:author:ID}'] = 'Author ID {current:author:ID}';
865 $field['choices']["Current: Author"]['{current:author:user_email}'] = 'E-mail {current:author:user_email}';
866 $field['choices']["Current: Author"]['{current:author:permalink}'] = 'Permalink {current:author:permalink}';
867
868 $field['choices']["Current: Form"]['{current:form:ID}'] = 'Form ID {current:form:ID}';
869 $field['choices']["Current: Form"]['{current:form:title}'] = 'Title {current:form:title}';
870 $field['choices']["Current: Form"]['{current:form:name}'] = 'Name {current:form:name}';
871
872 }
873
874 // Clean Choices
875 if(!empty($field['choices'])){
876
877 $sub_values = array();
878
879 foreach($field['choices'] as $category => $values){
880
881 // Generate available values
882 if(is_array($values)){
883
884 $sub_values = array_merge($sub_values, $values);
885
886 // Generate 'Generic'
887 }else{
888
889 unset($field['choices'][$category]);
890
891 $field['choices']['Generic'][$category] = $values;
892
893 }
894
895 }
896
897 // Compare available vs Generic
898 if(isset($field['choices']['Generic'])){
899
900 foreach($field['choices']['Generic'] as $k => $generic){
901
902 if(!isset($sub_values[$k]))
903 continue;
904
905 // Cleanup
906 unset($field['choices']['Generic'][$k]);
907
908 }
909
910 if(empty($field['choices']['Generic']))
911 unset($field['choices']['Generic']);
912
913 }
914
915 // Move Generic to Top
916 if(isset($field['choices']['Generic'])){
917
918 $new_generic = array(
919 'Generic' => $field['choices']['Generic']
920 );
921
922 unset($field['choices']['Generic']);
923
924 $field['choices'] = array_merge($new_generic, $field['choices']);
925
926 }
927
928 }
929
930 return $field;
931
932 }
933
934 function map_fields($field){
935
936 $fields_choices = $this->get_fields_choices();
937
938 if(empty($fields_choices))
939 return false;
940
941 $field['choices'] = $fields_choices;
942
943 return $field;
944
945 }
946
947 function get_fields_choices($deep = false, $original_field = array()){
948
949 $data = $this->fields_groups;
950 $choices = array();
951
952 if(empty($data))
953 return false;
954
955 $field_groups = array();
956
957 foreach($data as $field_group){
958
959 if(empty($field_group['fields']))
960 continue;
961
962 foreach($field_group['fields'] as $s_field){
963
964 $field_groups[$field_group['title']][] = $s_field;
965
966 }
967
968 }
969
970 if(!empty($field_groups)){
971
972 foreach($field_groups as $field_group_title => $fields){
973
974 foreach($fields as $field){
975
976 if(isset($choices[$field_group_title][$field['key']]))
977 continue;
978
979 // First level
980 if(!$deep){
981
982 $label = !empty($field['label']) ? $field['label'] : '(' . __('no label', 'acf') . ')';
983 $label .= $field['required'] ? ' *' : '';
984
985 $choices[$field_group_title][$field['key']] = $label. ' (' . $field['key'] . ')';
986
987 // Deep
988 }else{
989
990 $this->get_fields_choices_recursive($choices[$field_group_title], $field, $original_field);
991
992 }
993
994 }
995
996 }
997
998 }
999
1000 return $choices;
1001
1002 }
1003
1004 function get_fields_choices_recursive(&$choices, $field, $original_field){
1005
1006 $label = '';
1007
1008 $ancestors = isset($field['ancestors']) ? $field['ancestors'] : count(acf_get_field_ancestors($field));
1009 $label = str_repeat('- ', $ancestors) . $label;
1010
1011 $label .= !empty($field['label']) ? $field['label'] : '(' . __('no label', 'acf') . ')';
1012 $label .= $field['required'] ? ' *' : '';
1013
1014 /*
1015 if(acf_maybe_get($original_field, 'type') === 'select'){
1016
1017 $label = $label . ' <code style="font-size:12px;">{field:' . $field['name'] . '}</code>';
1018
1019 }else{
1020
1021 $label = $label . ' (' . $field['key'] . ')';
1022
1023 }
1024 */
1025
1026 $label = $label . ' (' . $field['key'] . ')';
1027
1028 $choices[$field['key']] = $label;
1029
1030 if(isset($field['sub_fields']) && !empty($field['sub_fields'])){
1031
1032 foreach($field['sub_fields'] as $s_field){
1033
1034 $this->get_fields_choices_recursive($choices, $s_field, $original_field);
1035
1036 }
1037
1038 }
1039
1040 }
1041
1042 function render_fields($content, $post_id, $args){
1043
1044 // Mapping
1045 $form_id = $args['form_id'];
1046 $form_name = $args['form_name'];
1047
1048 $mapped_field_groups = $this->get_fields_groups($form_id);
1049 $mapped_field_groups_keys = wp_list_pluck($mapped_field_groups, 'key');
1050 $mapped_fields = array();
1051
1052 if(!empty($mapped_field_groups)){
1053
1054 $post = acf_get_post_id_info($post_id);
1055
1056 // Apply Field Groups Rules
1057 if($post['type'] === 'post' && $args['field_groups_rules']){
1058
1059 $filter = array(
1060 'post_id' => $post_id,
1061 'post_type' => get_post_type($post_id),
1062 );
1063
1064 $filtered = array();
1065
1066 foreach($mapped_field_groups as $field_group){
1067
1068 // Deleted field group
1069 if(!isset($field_group['location']))
1070 continue;
1071
1072 // Force active
1073 $field_group['active'] = true;
1074
1075 if(acf_get_field_group_visibility($field_group, $filter)){
1076
1077 $filtered[] = $field_group;
1078
1079 }
1080
1081 }
1082
1083 $mapped_field_groups = $filtered;
1084
1085 }
1086
1087 if(!empty($mapped_field_groups)){
1088
1089 $mapped_field_groups_keys = wp_list_pluck($mapped_field_groups, 'key');
1090
1091 foreach($mapped_field_groups as $field_group){
1092
1093 if(empty($field_group['fields']))
1094 continue;
1095
1096 foreach($field_group['fields'] as $field){
1097
1098 $mapped_fields[] = $field;
1099
1100 }
1101
1102 }
1103
1104 }
1105
1106 }
1107
1108 // Match {field:key}
1109 if(preg_match_all('/{field:(.*?)}/', $content, $matches)){
1110
1111 foreach($matches[1] as $i => $field_key){
1112
1113 $field = false;
1114
1115 // Field key
1116 if(strpos($field_key, 'field_') === 0){
1117
1118 $field = acf_get_field($field_key);
1119
1120 // Field name
1121 }else{
1122
1123 if(!empty($mapped_fields)){
1124
1125 foreach($mapped_fields as $mapped_field){
1126
1127 if($mapped_field['name'] !== $field_key)
1128 continue;
1129
1130 $field = $mapped_field;
1131 break;
1132
1133 }
1134
1135 }
1136
1137 }
1138
1139 if(!$field){
1140
1141 $content = str_replace('{field:' . $field_key . '}', '', $content);
1142 continue;
1143
1144 }
1145
1146 $fields = array();
1147 $fields[] = $field;
1148
1149 ob_start();
1150
1151 acf_render_fields($fields, acf_uniqid('acfe_form'), $args['field_el'], $args['instruction_placement']);
1152
1153 $render_field = ob_get_clean();
1154
1155 $content = str_replace('{field:' . $field_key . '}', $render_field, $content);
1156
1157 }
1158
1159 }
1160
1161 // Match {field_group:key}
1162 if(preg_match_all('/{field_group:(.*?)}/', $content, $matches)){
1163
1164 //$field_groups = acf_get_field_groups();
1165
1166 foreach($matches[1] as $i => $field_group_key){
1167
1168 $fields = false;
1169
1170 if(!empty($mapped_field_groups)){
1171
1172 // Field group key
1173 if(strpos($field_group_key, 'group_') === 0){
1174
1175 if(in_array($field_group_key, $mapped_field_groups_keys))
1176 $fields = acf_get_fields($field_group_key);
1177
1178 // Field group title
1179 }else{
1180
1181 foreach($mapped_field_groups as $field_group){
1182
1183 if($field_group['title'] !== $field_group_key)
1184 continue;
1185
1186 $fields = acf_get_fields($field_group['key']);
1187 break;
1188
1189 }
1190
1191 }
1192
1193 }
1194
1195 if(!$fields){
1196
1197 $content = str_replace('{field_group:' . $field_group_key . '}', '', $content);
1198 continue;
1199
1200 }
1201
1202 ob_start();
1203
1204 acf_render_fields($fields, acf_uniqid('acfe_form'), $args['field_el'], $args['instruction_placement']);
1205
1206 $render_fields = ob_get_clean();
1207
1208 $content = str_replace('{field_group:' . $field_group_key . '}', $render_fields, $content);
1209
1210 }
1211
1212 }
1213
1214 return $content;
1215
1216 }
1217
1218 // Post Object & Relationship
1219 function format_value_post_object($value, $_value, $post_id, $field){
1220
1221 $value = acf_get_array($_value);
1222 $array = array();
1223
1224 foreach($value as $p_id){
1225
1226 $array[] = get_the_title($p_id);
1227
1228 }
1229
1230 return implode(', ', $array);
1231
1232 }
1233
1234 // Google Map
1235 function format_value_google_map($value, $_value, $post_id, $field){
1236
1237 if(is_string($value)){
1238
1239 $value = json_decode(wp_unslash($value), true);
1240
1241 }
1242
1243 $value = acf_get_array($value);
1244
1245 $address = acf_maybe_get($value, 'address');
1246
1247 return $address;
1248
1249 }
1250
1251 // User
1252 function format_value_user($value, $_value, $post_id, $field){
1253
1254 $value = acf_get_array($_value);
1255 $array = array();
1256
1257 foreach($value as $user_id){
1258
1259 $user_data = get_userdata($user_id);
1260 $array[] = $user_data->user_nicename;
1261
1262 }
1263
1264 return implode(', ', $array);
1265
1266 }
1267
1268 // Taxonomy
1269 function format_value_taxonomy($value, $_value, $post_id, $field){
1270
1271 $value = acf_get_array($_value);
1272 $array = array();
1273
1274 foreach($value as $term_id){
1275
1276 $term = get_term($term_id);
1277 $array[] = $term->name;
1278
1279 }
1280
1281 return implode(', ', $array);
1282
1283 }
1284
1285 // Image / File
1286 function format_value_file($value, $_value, $post_id, $field){
1287
1288 if(isset($_value['title']))
1289 return $_value['title'];
1290
1291 return $value;
1292
1293 }
1294
1295 // Select / Checkbox / Radio
1296 function format_value_select($value, $_value, $post_id, $field){
1297
1298 $value = acf_get_array($_value);
1299 $array = array();
1300
1301 foreach($value as $v){
1302
1303 $array[] = acf_maybe_get($field['choices'], $v, $v);
1304
1305 }
1306
1307 return implode(', ', $array);
1308
1309 }
1310
1311 function format_value_array($value){
1312
1313 if(!is_array($value))
1314 return $value;
1315
1316 $return = array();
1317
1318 foreach($value as $i => $v){
1319
1320 $key = '';
1321 if(!is_numeric($i))
1322 $key = $i . ': ';
1323
1324 $return[] = $key . $this->format_value_array($v);
1325
1326 }
1327
1328 return implode(', ', $return);
1329
1330 }
1331
1332 function format_value($value, $post_id = 0, $field){
1333
1334 $_value = $value;
1335
1336 $value = acf_format_value($value, $post_id, $field);
1337
1338 $value = apply_filters('acfe/form/format_value', $value, $_value, $post_id, $field);
1339 $value = apply_filters('acfe/form/format_value/type=' . $field['type'], $value, $_value, $post_id, $field);
1340 $value = apply_filters('acfe/form/format_value/key=' . $field['key'], $value, $_value, $post_id, $field);
1341 $value = apply_filters('acfe/form/format_value/name=' . $field['name'], $value, $_value, $post_id, $field);
1342
1343 // Is Array? Fallback
1344 if(is_array($value)){
1345
1346 $value = $this->format_value_array($value);
1347
1348 }
1349
1350 return $value;
1351
1352 }
1353
1354 function map_fields_values(&$data = array(), $array = array()){
1355
1356 if(empty($array)){
1357
1358 if(!acf_maybe_get_POST('acf'))
1359 return array();
1360
1361 $array = $_POST['acf'];
1362
1363 }
1364
1365 foreach($array as $field_key => $value){
1366
1367 if(!acf_is_field_key($field_key))
1368 continue;
1369
1370 $field = acf_get_field($field_key);
1371
1372 // bypass _validate_email (honeypot)
1373 if(!$field || !isset($field['name']) || $field['name'] === '_validate_email')
1374 continue;
1375
1376 $data[] = array(
1377 'label' => $field['label'],
1378 'name' => $field['name'],
1379 'key' => $field['key'],
1380 'field' => $field,
1381 'value' => $value,
1382 );
1383
1384 if(is_array($value) && !empty($value)){
1385
1386 $this->map_fields_values($data, $value);
1387
1388 }
1389
1390 }
1391
1392 return $data;
1393
1394 }
1395
1396 function map_field_value($content, $post_id = 0, $form = array()){
1397
1398 // Get store
1399 $store = acf_get_store('acfe/form');
1400
1401 // Store found
1402 if(!$store->has('data')){
1403
1404 $data = $this->map_fields_values();
1405
1406 // Set Store: ACF meta
1407 $store->set('data', $data);
1408
1409 }
1410
1411 $is_array = false;
1412
1413 if(is_array($content)){
1414
1415 $is_array = true;
1416
1417 }
1418
1419 $content = acf_array($content);
1420
1421 foreach($content as &$c){
1422
1423 // Match field_abcdef123456
1424 $c = acfe_form_map_field_key($c);
1425
1426 // Match {field:name} {field:key}
1427 $c = acfe_form_map_field($c);
1428
1429 // Match {fields}
1430 $c = acfe_form_map_fields($c);
1431
1432 // Match current_post {current:post:id}
1433 $c = acfe_form_map_current($c, $post_id, $form);
1434
1435 // Match {get_field:name} {get_field:name:123}
1436 $c = acfe_form_map_get_field($c, $post_id);
1437
1438 // Match {get_option:name}
1439 $c = acfe_form_map_get_option($c);
1440
1441 // Match {query_var:name} {query_var:name:key}
1442 $c = acfe_form_map_query_var($c);
1443
1444 // Match {request:name}
1445 $c = acfe_form_map_request($c);
1446
1447 }
1448
1449 if($is_array)
1450 return $content;
1451
1452 if(isset($content[0]))
1453 return $content[0];
1454
1455 return false;
1456
1457 }
1458
1459 function map_field_value_load($content, $post_id = 0, $form = array()){
1460
1461 $is_array = false;
1462
1463 if(is_array($content)){
1464
1465 $is_array = true;
1466
1467 }
1468
1469 $content = acf_array($content);
1470
1471 foreach($content as &$c) {
1472
1473 // Match current_post {current:post:id}
1474 $c = acfe_form_map_current($c, $post_id, $form);
1475
1476 // Match {get_field:name} {get_field:name:123}
1477 $c = acfe_form_map_get_field($c, $post_id);
1478
1479 // Match {get_option:name}
1480 $c = acfe_form_map_get_option($c);
1481
1482 // Match {query_var:name} {query_var:name:key}
1483 $c = acfe_form_map_query_var($c);
1484
1485 // Match {request:name}
1486 $c = acfe_form_map_request($c);
1487
1488 }
1489
1490 if($is_array)
1491 return $content;
1492
1493 if(isset($content[0]))
1494 return $content[0];
1495
1496 return false;
1497
1498 }
1499
1500 function filter_meta($meta, $acf){
1501
1502 if(empty($meta) || empty($acf))
1503 return false;
1504
1505 foreach($acf as $field_key => $value){
1506
1507 if(in_array($field_key, $meta))
1508 continue;
1509
1510 unset($acf[$field_key]);
1511
1512 }
1513
1514 return $acf;
1515
1516 }
1517
1518 // Allow form post_id null
1519 function validate_post_id($null, $post_id){
1520
1521 if($post_id === null)
1522 return false;
1523
1524 return $null;
1525
1526 }
1527
1528 /**
1529 * List: Columns
1530 */
1531 function admin_columns($columns){
1532
1533 if(isset($columns['date']))
1534 unset($columns['date']);
1535
1536 $columns['name'] = __('Name');
1537 $columns['field_groups'] = __('Field groups', 'acf');
1538 $columns['actions'] = __('Actions');
1539 $columns['shortcode'] = __('Shortcode');
1540
1541 return $columns;
1542
1543 }
1544
1545 /**
1546 * List: Columns HTML
1547 */
1548 function admin_columns_html($column, $post_id){
1549
1550 // Name
1551 if($column == 'name'){
1552
1553 echo '<code style="font-size: 12px;">' . get_field('acfe_form_name', $post_id) . '</code>';
1554
1555 }
1556
1557 // Field groups
1558 elseif($column == 'field_groups'){
1559
1560 $field_groups = get_field('acfe_form_field_groups', $post_id);
1561
1562 if(empty($field_groups)){
1563
1564 echo '—';
1565 return;
1566
1567 }
1568
1569 $fg = array();
1570
1571 foreach($field_groups as $field_group_key){
1572
1573 acf_disable_filters();
1574
1575 $field_group = acf_get_field_group($field_group_key);
1576
1577 acf_enable_filters();
1578
1579 $fg[] = '<a href="' . admin_url('post.php?post=' . $field_group['ID'] . '&action=edit') . '">' . $field_group['title'] . '</a>';
1580
1581 }
1582
1583 echo implode(', ', $fg);
1584
1585 }
1586
1587 // Actions
1588 elseif($column == 'actions'){
1589
1590 $customs = $emails = $posts = $terms = $users = array();
1591 $found = false;
1592
1593 if(have_rows('acfe_form_actions', $post_id)):
1594 while(have_rows('acfe_form_actions', $post_id)): the_row();
1595
1596 // Custom
1597 if(get_row_layout() === 'custom'){
1598
1599 $action_name = get_sub_field('acfe_form_custom_action');
1600
1601 $customs[] = '<span class="acf-js-tooltip dashicons dashicons-editor-code" title="Custom action: ' . $action_name . '"></span>';
1602 $found = true;
1603
1604 }
1605
1606 // E-mail
1607 elseif(get_row_layout() === 'email'){
1608
1609 $emails[] = '<span class="acf-js-tooltip dashicons dashicons-email" title="E-mail"></span>';
1610 $found = true;
1611
1612 }
1613
1614 // Post
1615 elseif(get_row_layout() === 'post'){
1616
1617 $action = get_sub_field('acfe_form_post_action');
1618
1619 // Insert
1620 if($action === 'insert_post'){
1621
1622 $posts[] = '<span class="acf-js-tooltip dashicons dashicons-edit" title="Create post"></span>';
1623 $found = true;
1624
1625 }
1626
1627 // Update
1628 elseif($action === 'update_post'){
1629
1630 $posts[] = '<span class="acf-js-tooltip dashicons dashicons-update" title="Update post"></span>';
1631 $found = true;
1632
1633 }
1634
1635 }
1636
1637 // Term
1638 elseif(get_row_layout() === 'term'){
1639
1640 $action = get_sub_field('acfe_form_term_action');
1641
1642 // Insert
1643 if($action === 'insert_term'){
1644
1645 $terms[] = '<span class="acf-js-tooltip dashicons dashicons-category" title="Create term"></span>';
1646 $found = true;
1647
1648 }
1649
1650 // Update
1651 elseif($action === 'update_term'){
1652
1653 $terms[] = '<span class="acf-js-tooltip dashicons dashicons-category" title="Update term"></span>';
1654 $found = true;
1655
1656 }
1657
1658 }
1659
1660 // User
1661 elseif(get_row_layout() === 'user'){
1662
1663 $action = get_sub_field('acfe_form_user_action');
1664
1665 // Insert
1666 if($action === 'insert_user'){
1667
1668 $users[] = '<span class="acf-js-tooltip dashicons dashicons-admin-users" title="Create user"></span>';
1669 $found = true;
1670
1671 }
1672
1673 // Update
1674 elseif($action === 'update_user'){
1675
1676 $users[] = '<span class="acf-js-tooltip dashicons dashicons-admin-users" title="Update user"></span>';
1677 $found = true;
1678
1679 }
1680
1681 }
1682
1683 endwhile;
1684 endif;
1685
1686 if(!empty($customs))
1687 echo implode('', $customs);
1688
1689 if(!empty($emails))
1690 echo implode('', $emails);
1691
1692 if(!empty($posts))
1693 echo implode('', $posts);
1694
1695 if(!empty($terms))
1696 echo implode('', $terms);
1697
1698 if(!empty($users))
1699 echo implode('', $users);
1700
1701 if(!$found)
1702 echo '—';
1703
1704 }
1705
1706 // Field groups
1707 elseif($column == 'shortcode'){
1708
1709 echo '<code style="font-size: 12px;">[acfe_form name="' . get_field('acfe_form_name', $post_id) . '"]</code>';
1710
1711 }
1712
1713 }
1714
1715 function doc_validation_field($field){
1716
1717 $form_name = 'my_form';
1718
1719 if(acf_maybe_get($field, 'value'))
1720 $form_name = get_field('acfe_form_name', $field['value']);
1721
1722 ?>You may use the following hooks:<br /><br />
1723
1724 <pre>/**
1725 * Perform custom validation on a field's value
1726 * Reference: <a href="https://www.advancedcustomfields.com/resources/acf-validate_value/" target="_blank">https://www.advancedcustomfields.com/resources/acf-validate_value/</a>
1727 */
1728 add_filter(&apos;acf/validate_value/name=my_field&apos;, &apos;my_field_validation&apos;, 10, 4);
1729 function my_field_validation($valid, $value, $field, $input){
1730
1731 if(!$valid)
1732 return $valid;
1733
1734 if($value === &apos;Hello&apos;)
1735 $valid = &apos;Hello is not allowed&apos;;
1736
1737 return $valid;
1738
1739 }</pre>
1740 <?php
1741
1742 }
1743
1744 function doc_validation_form($field){
1745
1746 $form_name = 'my_form';
1747
1748 if(acf_maybe_get($field, 'value'))
1749 $form_name = get_field('acfe_form_name', $field['value']);
1750
1751 ?>You may use the following hooks:<br /><br />
1752
1753 <pre>/**
1754 * @array $form Form arguments
1755 * @int/string $post_id Current post id
1756 */
1757 add_action(&apos;acfe/form/validation/form=<?php echo $form_name; ?>&apos;, &apos;my_form_validation&apos;, 10, 2);
1758 function my_form_validation($form, $post_id){
1759
1760 /**
1761 * Get the form input value named 'my_field'
1762 * This is the value entered by the user during the form submission
1763 */
1764 $my_field = get_field(&apos;my_field&apos;);
1765 $my_field_unformatted = get_field(&apos;my_field&apos;, false, false);
1766
1767 if($my_field === &apos;Hello&apos;){
1768
1769 // Add validation error
1770 acfe_add_validation_error(&apos;my_field&apos;, &apos;Hello is not allowed&apos;);
1771
1772 // Add general validation error
1773 acfe_add_validation_error(&apos;&apos;, &apos;There is an error&apos;);
1774
1775 }
1776
1777
1778 /**
1779 * Get the field value 'my_field' from the post ID 145
1780 */
1781 $post_my_field = get_field(&apos;my_field&apos;, 145);
1782 $post_my_field_unformatted = get_field(&apos;my_field&apos;, 145, false);
1783
1784 }</pre>
1785 <?php
1786
1787 }
1788
1789 function doc_submission($field){
1790
1791 $form_name = 'my_form';
1792
1793 if(acf_maybe_get($field, 'value'))
1794 $form_name = get_field('acfe_form_name', $field['value']);
1795
1796 ?>You may use the following hooks:<br /><br />
1797
1798 <pre>
1799 add_action(&apos;acfe/form/submit&apos;, &apos;my_form_submit&apos;, 10, 2);
1800 add_action(&apos;acfe/form/submit/form=<?php echo $form_name; ?>&apos;, &apos;my_form_submit&apos;, 10, 2);</pre>
1801
1802 <br />
1803
1804 <pre>/**
1805 * @array $form Form arguments
1806 * @int/string $post_id Current post id
1807 */
1808 add_action(&apos;acfe/form/submit/form=<?php echo $form_name; ?>&apos;, &apos;my_form_submit&apos;, 10, 2);
1809 function my_form_submit($form, $post_id){
1810
1811 /**
1812 * Get the form input value named 'my_field'
1813 * This is the value entered by the user during the form submission
1814 */
1815 $my_field = get_field(&apos;my_field&apos;);
1816 $my_field_unformatted = get_field(&apos;my_field&apos;, false, false);
1817
1818 if($my_field === &apos;Hello&apos;){
1819
1820 // Do something
1821
1822 }
1823
1824
1825 /**
1826 * Get the field value 'my_field' from the post ID 145
1827 */
1828 $post_my_field = get_field(&apos;my_field&apos;, 145);
1829 $post_my_field_unformatted = get_field(&apos;my_field&apos;, 145, false);
1830
1831 }</pre>
1832 <?php
1833
1834 }
1835
1836 function doc_field($field){
1837 ?>
1838 <table class="acf-table">
1839 <tbody>
1840 <tr class="acf-row">
1841 <td width="35%"><code>{field:field_5e5c07b6dfae9}</code></td>
1842 <td>User input</td>
1843 </tr>
1844 <tr class="acf-row">
1845 <td width="35%"><code>{field:my_field}</code></td>
1846 <td>User input</td>
1847 </tr>
1848 <tr class="acf-row">
1849 <td width="35%"><code>{field:my_field:false}</code></td>
1850 <td>User input (unformatted)</td>
1851 </tr>
1852 </tbody>
1853 </table>
1854 <?php
1855 }
1856
1857 function doc_fields($field){
1858 ?>
1859 <table class="acf-table">
1860 <tbody>
1861 <tr class="acf-row">
1862 <td width="35%"><code>{fields}</code></td>
1863 <td>My text: User input<br /><br />My textarea: User input<br /><br />My date: 2020-03-01</td>
1864 </tr>
1865 </tbody>
1866 </table>
1867 <?php
1868 }
1869
1870 function doc_get_field($field){
1871 ?>
1872 <table class="acf-table">
1873 <tbody>
1874 <tr class="acf-row">
1875 <td width="35%"><code>{get_field:my_field}</code></td>
1876 <td>DB value (current post)</td>
1877 </tr>
1878 <tr class="acf-row">
1879 <td width="35%"><code>{get_field:my_field:current}</code></td>
1880 <td>DB value (current post)</td>
1881 </tr>
1882 <tr class="acf-row">
1883 <td width="35%"><code>{get_field:my_field:128}</code></td>
1884 <td>DB value (post:128)</td>
1885 </tr>
1886 <tr class="acf-row">
1887 <td width="35%"><code>{get_field:my_field:128:false}</code></td>
1888 <td>DB value (post:128 - unformatted)</td>
1889 </tr>
1890 </tbody>
1891 </table>
1892 <?php
1893 }
1894
1895 function doc_get_option($field){
1896 ?>
1897 <table class="acf-table">
1898 <tbody>
1899 <tr class="acf-row">
1900 <td width="35%"><code>{get_option:my_option}</code></td>
1901 <td>DB value</td>
1902 </tr>
1903 <tr class="acf-row">
1904 <td width="35%"><code>{get_option:my_option_array:key}</code></td>
1905 <td>DB value</td>
1906 </tr>
1907 </tbody>
1908 </table>
1909 <?php
1910 }
1911
1912 function doc_query_var($field){
1913 ?>
1914 <table class="acf-table">
1915 <tbody>
1916 <tr class="acf-row">
1917 <td width="35%"><code>{query_var:name}</code></td>
1918 <td>value</td>
1919 </tr>
1920 <tr class="acf-row">
1921 <td width="35%"><code>{query_var:name:key}</code></td>
1922 <td>Array value</td>
1923 </tr>
1924 </tbody>
1925 </table>
1926
1927 <br />
1928
1929 <table class="acf-table">
1930 <tbody>
1931 <tr class="acf-row">
1932 <td width="35%"><code>{query_var:my-post-action:ID}</code></td>
1933 <td>128</td>
1934 </tr>
1935 <tr class="acf-row">
1936 <td width="35%"><code>{query_var:my-post-action:post_title}</code></td>
1937 <td>Title</td>
1938 </tr>
1939 <tr class="acf-row">
1940 <td width="35%"><code>{query_var:my-post-action:permalink}</code></td>
1941 <td><?php echo home_url('my-post'); ?></td>
1942 </tr>
1943 <tr class="acf-row">
1944 <td width="35%"><code>{query_var:my-post-action:...}</code></td>
1945 <td>(See <code>{current:post}</code> tags)</td>
1946 </tr>
1947 </tbody>
1948 </table>
1949
1950 <br />
1951
1952 <table class="acf-table">
1953 <tbody>
1954 <tr class="acf-row">
1955 <td width="35%"><code>{query_var:my-term-action:ID}</code></td>
1956 <td>23</td>
1957 </tr>
1958 <tr class="acf-row">
1959 <td width="35%"><code>{query_var:my-term-action:name}</code></td>
1960 <td>Term</td>
1961 </tr>
1962 <tr class="acf-row">
1963 <td width="35%"><code>{query_var:my-term-action:permalink}</code></td>
1964 <td><?php echo home_url('taxonomy/term'); ?></td>
1965 </tr>
1966 <tr class="acf-row">
1967 <td width="35%"><code>{query_var:my-term-action:...}</code></td>
1968 <td>(See <code>{current:term}</code> tags)</td>
1969 </tr>
1970 </tbody>
1971 </table>
1972
1973 <br />
1974
1975 <table class="acf-table">
1976 <tbody>
1977 <tr class="acf-row">
1978 <td width="35%"><code>{query_var:my-user-action:ID}</code></td>
1979 <td>1</td>
1980 </tr>
1981 <tr class="acf-row">
1982 <td width="35%"><code>{query_var:my-user-action:user_email}</code></td>
1983 <td>user@domain.com</td>
1984 </tr>
1985 <tr class="acf-row">
1986 <td width="35%"><code>{query_var:my-user-action:display_name}</code></td>
1987 <td>John Doe</td>
1988 </tr>
1989 <tr class="acf-row">
1990 <td width="35%"><code>{query_var:my-user-action:...}</code></td>
1991 <td>(See <code>{current:user}</code> tags)</td>
1992 </tr>
1993 </tbody>
1994 </table>
1995
1996 <br />
1997
1998 <table class="acf-table">
1999 <tbody>
2000 <tr class="acf-row">
2001 <td width="35%"><code>{query_var:my-email-action:from}</code></td>
2002 <td>Website <email@domain.com></td>
2003 </tr>
2004 <tr class="acf-row">
2005 <td width="35%"><code>{query_var:my-email-action:to}</code></td>
2006 <td>email@domain.com</td>
2007 </tr>
2008 <tr class="acf-row">
2009 <td width="35%"><code>{query_var:my-email-action:subject}</code></td>
2010 <td>Subject</td>
2011 </tr>
2012 <tr class="acf-row">
2013 <td width="35%"><code>{query_var:my-user-action:content}</code></td>
2014 <td>Content</td>
2015 </tr>
2016 </tbody>
2017 </table>
2018 <?php
2019 }
2020
2021 function doc_request($field){
2022 ?>
2023 <table class="acf-table">
2024 <tbody>
2025 <tr class="acf-row">
2026 <td width="35%"><code>{request:name}</code></td>
2027 <td><code>$_REQUEST['name']</code> (including <code>$_GET</code> & <code>$_POST</code>)</td>
2028 </tr>
2029 <tr class="acf-row">
2030 <td width="35%"><code>{request:name:key}</code></td>
2031 <td><code>$_REQUEST['name']['key']</code> (including <code>$_GET</code> & <code>$_POST</code>)</td>
2032 </tr>
2033 </tbody>
2034 </table>
2035 <?php
2036 }
2037
2038 function doc_current_post($field){
2039 ?>
2040 <table class="acf-table">
2041 <tbody>
2042 <tr class="acf-row">
2043 <td width="35%"><code>{current:post}</code></td>
2044 <td>128</td>
2045 </tr>
2046 <tr class="acf-row">
2047 <td width="35%"><code>{current:post:ID}</code></td>
2048 <td>128</td>
2049 </tr>
2050 <tr class="acf-row">
2051 <td width="35%"><code>{current:post:post_author}</code></td>
2052 <td>1</td>
2053 </tr>
2054 <tr class="acf-row">
2055 <td width="35%"><code>{current:post:post_date}</code></td>
2056 <td>2020-03-01 20:07:48</td>
2057 </tr>
2058 <tr class="acf-row">
2059 <td width="35%"><code>{current:post:post_date_gmt}</code></td>
2060 <td>2020-03-01 19:07:48</td>
2061 </tr>
2062 <tr class="acf-row">
2063 <td width="35%"><code>{current:post:post_content}</code></td>
2064 <td>Content</td>
2065 </tr>
2066 <tr class="acf-row">
2067 <td width="35%"><code>{current:post:post_title}</code></td>
2068 <td>Title</td>
2069 </tr>
2070 <tr class="acf-row">
2071 <td width="35%"><code>{current:post:post_excerpt}</code></td>
2072 <td>Excerpt</td>
2073 </tr>
2074 <tr class="acf-row">
2075 <td width="35%"><code>{current:post:permalink}</code></td>
2076 <td><?php echo home_url('my-post'); ?></td>
2077 </tr>
2078 <tr class="acf-row">
2079 <td width="35%"><code>{current:post:admin_url}</code></td>
2080 <td><?php echo admin_url('post.php?post=128&action=edit'); ?></td>
2081 </tr>
2082 <tr class="acf-row">
2083 <td width="35%"><code>{current:post:post_status}</code></td>
2084 <td>publish</td>
2085 </tr>
2086 <tr class="acf-row">
2087 <td width="35%"><code>{current:post:comment_status}</code></td>
2088 <td>closed</td>
2089 </tr>
2090 <tr class="acf-row">
2091 <td width="35%"><code>{current:post:ping_status}</code></td>
2092 <td>closed</td>
2093 </tr>
2094 <tr class="acf-row">
2095 <td width="35%"><code>{current:post:post_password}</code></td>
2096 <td>password</td>
2097 </tr>
2098 <tr class="acf-row">
2099 <td width="35%"><code>{current:post:post_name}</code></td>
2100 <td>name</td>
2101 </tr>
2102 <tr class="acf-row">
2103 <td width="35%"><code>{current:post:to_ping}</code></td>
2104 <td></td>
2105 </tr>
2106 <tr class="acf-row">
2107 <td width="35%"><code>{current:post:pinged}</code></td>
2108 <td></td>
2109 </tr>
2110 <tr class="acf-row">
2111 <td width="35%"><code>{current:post:post_modified}</code></td>
2112 <td>2020-03-01 20:07:48</td>
2113 </tr>
2114 <tr class="acf-row">
2115 <td width="35%"><code>{current:post:post_modified_gmt}</code></td>
2116 <td>2020-03-01 19:07:48</td>
2117 </tr>
2118 <tr class="acf-row">
2119 <td width="35%"><code>{current:post:post_content_filtered}</code></td>
2120 <td></td>
2121 </tr>
2122 <tr class="acf-row">
2123 <td width="35%"><code>{current:post:post_parent}</code></td>
2124 <td>0</td>
2125 </tr>
2126 <tr class="acf-row">
2127 <td width="35%"><code>{current:post:guid}</code></td>
2128 <td><?php echo home_url('?page_id=128'); ?></td>
2129 </tr>
2130 <tr class="acf-row">
2131 <td width="35%"><code>{current:post:menu_order}</code></td>
2132 <td>0</td>
2133 </tr>
2134 <tr class="acf-row">
2135 <td width="35%"><code>{current:post:post_type}</code></td>
2136 <td>page</td>
2137 </tr>
2138 <tr class="acf-row">
2139 <td width="35%"><code>{current:post:post_mime_type}</code></td>
2140 <td></td>
2141 </tr>
2142 <tr class="acf-row">
2143 <td width="35%"><code>{current:post:comment_count}</code></td>
2144 <td>0</td>
2145 </tr>
2146 <tr class="acf-row">
2147 <td width="35%"><code>{current:post:filter}</code></td>
2148 <td>raw</td>
2149 </tr>
2150
2151 </tbody>
2152 </table>
2153 <?php
2154 }
2155
2156 function doc_current_term($field){
2157 ?>
2158 <table class="acf-table">
2159 <tbody>
2160 <tr class="acf-row">
2161 <td width="35%"><code>{current:term}</code></td>
2162 <td>23</td>
2163 </tr>
2164 <tr class="acf-row">
2165 <td width="35%"><code>{current:term:ID}</code></td>
2166 <td>23</td>
2167 </tr>
2168 <tr class="acf-row">
2169 <td width="35%"><code>{current:term:term_id}</code></td>
2170 <td>23</td>
2171 </tr>
2172 <tr class="acf-row">
2173 <td width="35%"><code>{current:term:name}</code></td>
2174 <td>Term</td>
2175 </tr>
2176 <tr class="acf-row">
2177 <td width="35%"><code>{current:term:slug}</code></td>
2178 <td>term</td>
2179 </tr>
2180 <tr class="acf-row">
2181 <td width="35%"><code>{current:term:permalink}</code></td>
2182 <td><?php echo home_url('taxonomy/term'); ?></td>
2183 </tr>
2184 <tr class="acf-row">
2185 <td width="35%"><code>{current:term:admin_url}</code></td>
2186 <td><?php echo admin_url('term.php?tag_ID=23'); ?></td>
2187 </tr>
2188 <tr class="acf-row">
2189 <td width="35%"><code>{current:term:term_group}</code></td>
2190 <td>0</td>
2191 </tr>
2192 <tr class="acf-row">
2193 <td width="35%"><code>{current:term:term_taxonomy_id}</code></td>
2194 <td>23</td>
2195 </tr>
2196 <tr class="acf-row">
2197 <td width="35%"><code>{current:term:taxonomy}</code></td>
2198 <td>taxonomy</td>
2199 </tr>
2200 <tr class="acf-row">
2201 <td width="35%"><code>{current:term:description}</code></td>
2202 <td>Content</td>
2203 </tr>
2204 <tr class="acf-row">
2205 <td width="35%"><code>{current:term:parent}</code></td>
2206 <td>0</td>
2207 </tr>
2208 <tr class="acf-row">
2209 <td width="35%"><code>{current:term:count}</code></td>
2210 <td>0</td>
2211 </tr>
2212 <tr class="acf-row">
2213 <td width="35%"><code>{current:term:filter}</code></td>
2214 <td>raw</td>
2215 </tr>
2216 </tbody>
2217 </table>
2218 <?php
2219 }
2220
2221 function doc_current_user($field){
2222 ?>
2223 <table class="acf-table">
2224 <tbody>
2225 <tr class="acf-row">
2226 <td width="35%"><code>{current:user}</code></td>
2227 <td>1</td>
2228 </tr>
2229 <tr class="acf-row">
2230 <td width="35%"><code>{current:user:ID}</code></td>
2231 <td>1</td>
2232 </tr>
2233 <tr class="acf-row">
2234 <td width="35%"><code>{current:user:user_login}</code></td>
2235 <td>login</td>
2236 </tr>
2237 <tr class="acf-row">
2238 <td width="35%"><code>{current:user:user_pass}</code></td>
2239 <td>password_hash</td>
2240 </tr>
2241 <tr class="acf-row">
2242 <td width="35%"><code>{current:user:user_nicename}</code></td>
2243 <td>nicename</td>
2244 </tr>
2245 <tr class="acf-row">
2246 <td width="35%"><code>{current:user:user_email}</code></td>
2247 <td>user@domain.com</td>
2248 </tr>
2249 <tr class="acf-row">
2250 <td width="35%"><code>{current:user:user_url}</code></td>
2251 <td>https://www.website.com</td>
2252 </tr>
2253 <tr class="acf-row">
2254 <td width="35%"><code>{current:user:permalink}</code></td>
2255 <td><?php echo home_url('author/johndoe'); ?></td>
2256 </tr>
2257 <tr class="acf-row">
2258 <td width="35%"><code>{current:user:admin_url}</code></td>
2259 <td><?php echo admin_url('user-edit.php?user_id=1'); ?></td>
2260 </tr>
2261 <tr class="acf-row">
2262 <td width="35%"><code>{current:user:user_registered}</code></td>
2263 <td>2020-02-22 22:10:02</td>
2264 </tr>
2265 <tr class="acf-row">
2266 <td width="35%"><code>{current:user:user_activation_key}</code></td>
2267 <td></td>
2268 </tr>
2269 <tr class="acf-row">
2270 <td width="35%"><code>{current:user:user_status}</code></td>
2271 <td>0</td>
2272 </tr>
2273 <tr class="acf-row">
2274 <td width="35%"><code>{current:user:display_name}</code></td>
2275 <td>John Doe</td>
2276 </tr>
2277 <tr class="acf-row">
2278 <td width="35%"><code>{current:user:nickname}</code></td>
2279 <td>JohnDoe</td>
2280 </tr>
2281 <tr class="acf-row">
2282 <td width="35%"><code>{current:user:first_name}</code></td>
2283 <td>John</td>
2284 </tr>
2285 <tr class="acf-row">
2286 <td width="35%"><code>{current:user:last_name}</code></td>
2287 <td>Doe</td>
2288 </tr>
2289 <tr class="acf-row">
2290 <td width="35%"><code>{current:user:description}</code></td>
2291 <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
2292 </tr>
2293 <tr class="acf-row">
2294 <td width="35%"><code>{current:user:rich_editing}</code></td>
2295 <td>true</td>
2296 </tr>
2297 <tr class="acf-row">
2298 <td width="35%"><code>{current:user:syntax_highlighting}</code></td>
2299 <td>true</td>
2300 </tr>
2301 <tr class="acf-row">
2302 <td width="35%"><code>{current:user:comment_shortcuts}</code></td>
2303 <td>false</td>
2304 </tr>
2305 <tr class="acf-row">
2306 <td width="35%"><code>{current:user:admin_color}</code></td>
2307 <td>fresh</td>
2308 </tr>
2309 <tr class="acf-row">
2310 <td width="35%"><code>{current:user:use_ssl}</code></td>
2311 <td>1</td>
2312 </tr>
2313 <tr class="acf-row">
2314 <td width="35%"><code>{current:user:show_admin_bar_front}</code></td>
2315 <td>true</td>
2316 </tr>
2317 <tr class="acf-row">
2318 <td width="35%"><code>{current:user:locale}</code></td>
2319 <td></td>
2320 </tr>
2321 <tr class="acf-row">
2322 <td width="35%"><code>{current:user:wp_capabilities}</code></td>
2323 <td>a:1:{s:13:"administrator";b:1;}</td>
2324 </tr>
2325 <tr class="acf-row">
2326 <td width="35%"><code>{current:user:wp_user_level}</code></td>
2327 <td>10</td>
2328 </tr>
2329 <tr class="acf-row">
2330 <td width="35%"><code>{current:user:dismissed_wp_pointers}</code></td>
2331 <td></td>
2332 </tr>
2333 <tr class="acf-row">
2334 <td width="35%"><code>{current:user:show_welcome_panel}</code></td>
2335 <td>1</td>
2336 </tr>
2337 </tbody>
2338 </table>
2339 <?php
2340 }
2341
2342 function doc_current_author($field){
2343 ?>
2344 <table class="acf-table">
2345 <tbody>
2346 <tr class="acf-row">
2347 <td width="35%"><code>{current:author}</code></td>
2348 <td>1</td>
2349 </tr>
2350 <tr class="acf-row">
2351 <td width="35%"><code>{current:author:ID}</code></td>
2352 <td>1</td>
2353 </tr>
2354 <tr class="acf-row">
2355 <td width="35%"><code>{current:author:user_login}</code></td>
2356 <td>login</td>
2357 </tr>
2358 <tr class="acf-row">
2359 <td width="35%"><code>{current:author:user_pass}</code></td>
2360 <td>password_hash</td>
2361 </tr>
2362 <tr class="acf-row">
2363 <td width="35%"><code>{current:author:user_nicename}</code></td>
2364 <td>nicename</td>
2365 </tr>
2366 <tr class="acf-row">
2367 <td width="35%"><code>{current:author:user_email}</code></td>
2368 <td>user@domain.com</td>
2369 </tr>
2370 <tr class="acf-row">
2371 <td width="35%"><code>{current:author:user_url}</code></td>
2372 <td>https://www.website.com</td>
2373 </tr>
2374 <tr class="acf-row">
2375 <td width="35%"><code>{current:author:permalink}</code></td>
2376 <td><?php echo home_url('author/johndoe'); ?></td>
2377 </tr>
2378 <tr class="acf-row">
2379 <td width="35%"><code>{current:author:admin_url}</code></td>
2380 <td><?php echo admin_url('user-edit.php?user_id=1'); ?></td>
2381 </tr>
2382 <tr class="acf-row">
2383 <td width="35%"><code>{current:author:user_registered}</code></td>
2384 <td>2020-02-22 22:10:02</td>
2385 </tr>
2386 <tr class="acf-row">
2387 <td width="35%"><code>{current:author:user_activation_key}</code></td>
2388 <td></td>
2389 </tr>
2390 <tr class="acf-row">
2391 <td width="35%"><code>{current:author:user_status}</code></td>
2392 <td>0</td>
2393 </tr>
2394 <tr class="acf-row">
2395 <td width="35%"><code>{current:author:display_name}</code></td>
2396 <td>John Doe</td>
2397 </tr>
2398 <tr class="acf-row">
2399 <td width="35%"><code>{current:author:nickname}</code></td>
2400 <td>JohnDoe</td>
2401 </tr>
2402 <tr class="acf-row">
2403 <td width="35%"><code>{current:author:first_name}</code></td>
2404 <td>John</td>
2405 </tr>
2406 <tr class="acf-row">
2407 <td width="35%"><code>{current:author:last_name}</code></td>
2408 <td>Doe</td>
2409 </tr>
2410 <tr class="acf-row">
2411 <td width="35%"><code>{current:author:description}</code></td>
2412 <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
2413 </tr>
2414 <tr class="acf-row">
2415 <td width="35%"><code>{current:author:rich_editing}</code></td>
2416 <td>true</td>
2417 </tr>
2418 <tr class="acf-row">
2419 <td width="35%"><code>{current:author:syntax_highlighting}</code></td>
2420 <td>true</td>
2421 </tr>
2422 <tr class="acf-row">
2423 <td width="35%"><code>{current:author:comment_shortcuts}</code></td>
2424 <td>false</td>
2425 </tr>
2426 <tr class="acf-row">
2427 <td width="35%"><code>{current:author:admin_color}</code></td>
2428 <td>fresh</td>
2429 </tr>
2430 <tr class="acf-row">
2431 <td width="35%"><code>{current:author:use_ssl}</code></td>
2432 <td>1</td>
2433 </tr>
2434 <tr class="acf-row">
2435 <td width="35%"><code>{current:author:show_admin_bar_front}</code></td>
2436 <td>true</td>
2437 </tr>
2438 <tr class="acf-row">
2439 <td width="35%"><code>{current:author:locale}</code></td>
2440 <td></td>
2441 </tr>
2442 <tr class="acf-row">
2443 <td width="35%"><code>{current:author:wp_capabilities}</code></td>
2444 <td>a:1:{s:13:"administrator";b:1;}</td>
2445 </tr>
2446 <tr class="acf-row">
2447 <td width="35%"><code>{current:author:wp_user_level}</code></td>
2448 <td>10</td>
2449 </tr>
2450 <tr class="acf-row">
2451 <td width="35%"><code>{current:author:dismissed_wp_pointers}</code></td>
2452 <td></td>
2453 </tr>
2454 <tr class="acf-row">
2455 <td width="35%"><code>{current:author:show_welcome_panel}</code></td>
2456 <td>1</td>
2457 </tr>
2458 </tbody>
2459 </table>
2460 <?php
2461 }
2462
2463 function doc_current_form($field){
2464 ?>
2465 <table class="acf-table">
2466 <tbody>
2467 <tr class="acf-row">
2468 <td width="35%"><code>{current:form}</code></td>
2469 <td>11<br/></td>
2470 </tr>
2471 <tr class="acf-row">
2472 <td width="35%"><code>{current:form:ID}</code></td>
2473 <td>11<br/></td>
2474 </tr>
2475 <tr class="acf-row">
2476 <td width="35%"><code>{current:form:title}</code></td>
2477 <td>Form<br/></td>
2478 </tr>
2479 <tr class="acf-row">
2480 <td width="35%"><code>{current:form:name}</code></td>
2481 <td>form<br/></td>
2482 </tr>
2483 </tbody>
2484 </table>
2485 <?php
2486 }
2487
2488 }
2489
2490 // initialize
2491 acfe()->acfe_form = new acfe_form();
2492
2493 endif;
2494
2495 function acfe_form_render_fields($content, $post_id, $args){
2496
2497 return acfe()->acfe_form->render_fields($content, $post_id, $args);
2498
2499 }
2500
2501 function acfe_form_map_field_value($field, $post_id = 0, $form = array()){
2502
2503 return acfe()->acfe_form->map_field_value($field, $post_id, $form);
2504
2505 }
2506
2507 function acfe_form_map_field_value_load($field, $post_id = 0, $form = array()){
2508
2509 return acfe()->acfe_form->map_field_value_load($field, $post_id, $form);
2510
2511 }
2512
2513 function acfe_form_filter_meta($meta, $acf){
2514
2515 return acfe()->acfe_form->filter_meta($meta, $acf);
2516
2517 }
2518
2519 function acfe_form_format_value($value, $post_id = 0, $field){
2520
2521 return acfe()->acfe_form->format_value($value, $post_id, $field);
2522
2523 }
2524
2525 // Match field_abcdef123456
2526 function acfe_form_map_field_key($content){
2527
2528 if(empty($content) || !is_string($content))
2529 return $content;
2530
2531 if(!acf_is_field_key($content))
2532 return $content;
2533
2534 // Setup data
2535 $data = array();
2536
2537 $store = acf_get_store('acfe/form');
2538
2539 if($store->has('data')){
2540
2541 $data = $store->get('data');
2542
2543 }
2544
2545 if(!empty($data)){
2546
2547 foreach($data as $field){
2548
2549 if($field['key'] !== $content)
2550 continue;
2551
2552 return $field['value'];
2553
2554 }
2555
2556 }
2557
2558 return false;
2559
2560 }
2561
2562 function acfe_form_map_current($content, $post_id = 0, $form = array()){
2563
2564 if(empty($content) || !is_string($content))
2565 return $content;
2566
2567 // init
2568 $value = 0;
2569
2570 // Post
2571 $post = acf_get_post_id_info($post_id);
2572
2573 // Match current_post
2574 if($content === 'current_post'){
2575
2576 if($post['type'] === 'post')
2577 $value = $post['id'];
2578
2579 return $value;
2580
2581 }
2582
2583 // Match current_post_parent
2584 elseif($content === 'current_post_parent'){
2585
2586 if($post['type'] === 'post')
2587 $value = get_post_field('post_parent', $post['id']);
2588
2589 return $value;
2590
2591 }
2592
2593 // Match current_post_author
2594 elseif($content === 'current_post_author'){
2595
2596 if($post['type'] === 'post')
2597 $value = get_post_field('post_author', $post['id']);
2598
2599 return $value;
2600
2601 }
2602
2603 // Match current_term
2604 if($content === 'current_term'){
2605
2606 if($post['type'] === 'term')
2607 $value = $post['id'];
2608
2609 return $value;
2610
2611 }
2612
2613 // Match current_term_parent
2614 elseif($content === 'current_term_parent'){
2615
2616 if($post['type'] === 'term')
2617 $value = get_term_field('parent', $post['id']);
2618
2619 return $value;
2620
2621 }
2622
2623 // Match current_user
2624 elseif($content === 'current_user'){
2625
2626 return get_current_user_id();
2627
2628 }
2629
2630 // Match generate_password
2631 elseif($content === 'generate_password'){
2632
2633 return wp_generate_password(8, false);
2634
2635 }
2636
2637 // Match {current:post:id}
2638 elseif(strpos($content, '{current:') !== false){
2639
2640 // Match {current:name}
2641 if(preg_match_all('/{current:(.*?)}/', $content, $matches)){
2642
2643 foreach($matches[1] as $i => $name){
2644
2645 $value = false;
2646
2647 if(strpos($name, ':') !== false){
2648
2649 $explode = explode(':', $name);
2650
2651 $type = $explode[0]; // post, term, user
2652 $field = $explode[1]; // id, post_parent, post_title
2653
2654 // {current:post:id}
2655 if($type === 'post' && $post['type'] === 'post'){
2656
2657 // id
2658 if(strtolower($field) === 'id' || strtolower($field) === 'post_id'){
2659
2660 $value = $post['id'];
2661
2662 }
2663
2664 // permalink
2665 elseif(strtolower($field) === 'permalink'){
2666
2667 $value = get_permalink($post['id']);
2668
2669 }
2670
2671 // admin url
2672 elseif(strtolower($field) === 'admin_url'){
2673
2674 $value = admin_url('post.php?post=' . $post['id'] . '&action=edit');
2675
2676 }
2677
2678 // other
2679 else{
2680
2681 $value = get_post_field($field, $post['id']);
2682
2683 }
2684
2685 }
2686
2687 // {current:term:id}
2688 elseif($type === 'term' && $post['type'] === 'term'){
2689
2690 // id
2691 if(strtolower($field) === 'id' || strtolower($field) === 'term_id'){
2692
2693 $value = $post['id'];
2694
2695 }
2696
2697 // permalink
2698 elseif(strtolower($field) === 'permalink'){
2699
2700 $value = get_term_link($post['id']);
2701
2702 }
2703
2704 // admin url
2705 elseif(strtolower($field) === 'admin_url'){
2706
2707 $value = admin_url('term.php?tag_ID=' . $post['id']);
2708
2709 }
2710
2711 // other
2712 else{
2713
2714 $value = get_term_field($field, $post['id']);
2715
2716 }
2717
2718 }
2719
2720 // {current:user:id}
2721 elseif($type === 'user'){
2722
2723 if(is_user_logged_in()){
2724
2725 $user_id = get_current_user_id();
2726
2727 // id
2728 if(strtolower($field) === 'id' || strtolower($field) === 'user_id'){
2729
2730 $value = $user_id;
2731
2732 }
2733
2734 // permalink
2735 elseif(strtolower($field) === 'permalink'){
2736
2737 $value = get_author_posts_url($user_id);
2738
2739 }
2740
2741 // admin url
2742 elseif(strtolower($field) === 'admin_url'){
2743
2744 $value = admin_url('user-edit.php?user_id=' . $user_id);
2745
2746 }
2747
2748 // other
2749 else{
2750
2751 $value = false;
2752
2753 $user_object = get_user_by('ID', $user_id);
2754
2755 if(isset($user_object->data)){
2756
2757 // return array
2758 $user = json_decode(json_encode($user_object->data), true);
2759
2760 $user_object_meta = get_user_meta($user_id);
2761
2762 $user_meta = array();
2763
2764 foreach($user_object_meta as $k => $v){
2765
2766 if(!isset($v[0]))
2767 continue;
2768
2769 $user_meta[$k] = $v[0];
2770
2771 }
2772
2773 $user = array_merge($user, $user_meta);
2774
2775 $value = acf_maybe_get($user, $field);
2776
2777 }
2778
2779 }
2780
2781 }
2782
2783 }
2784
2785 // {current:author:id}
2786 elseif($type === 'author' && $post['type'] === 'post'){
2787
2788 $user_id = get_post_field('post_author', $post['id']);
2789
2790 if($user_id){
2791
2792 // id
2793 if(strtolower($field) === 'id' || strtolower($field) === 'user_id'){
2794
2795 $value = $user_id;
2796
2797 }
2798
2799 // permalink
2800 elseif(strtolower($field) === 'permalink'){
2801
2802 $value = get_author_posts_url($user_id);
2803
2804 }
2805
2806 // admin url
2807 elseif(strtolower($field) === 'admin_url'){
2808
2809 $value = admin_url('user-edit.php?user_id=' . $user_id);
2810
2811 }
2812
2813 // other
2814 else{
2815
2816 $value = false;
2817
2818 $user_object = get_user_by('ID', $user_id);
2819
2820 if(isset($user_object->data)){
2821
2822 // return array
2823 $user = json_decode(json_encode($user_object->data), true);
2824
2825 $user_object_meta = get_user_meta($user_id);
2826
2827 $user_meta = array();
2828
2829 foreach($user_object_meta as $k => $v){
2830
2831 if(!isset($v[0]))
2832 continue;
2833
2834 $user_meta[$k] = $v[0];
2835
2836 }
2837
2838 $user = array_merge($user, $user_meta);
2839
2840 $value = acf_maybe_get($user, $field);
2841
2842 }
2843
2844 }
2845
2846 }
2847
2848
2849 }
2850
2851 // {current:form:id}
2852 elseif($type === 'form'){
2853
2854 if(strtolower($field) === 'id' || strtolower($field) === 'form_id'){
2855
2856 $value = acf_maybe_get($form, 'form_id');
2857
2858 }
2859
2860 elseif(strtolower($field) === 'name' || strtolower($field) === 'form_name'){
2861
2862 $value = acf_maybe_get($form, 'form_name');
2863
2864 }
2865
2866 elseif(strtolower($field) === 'title' || strtolower($field) === 'form_title'){
2867
2868 $form_id = acf_maybe_get($form, 'form_id');
2869
2870 if($form_id)
2871 $value = get_the_title($form_id);
2872
2873 }else{
2874
2875 $value = acf_maybe_get($form, $field);
2876
2877 }
2878
2879 }
2880
2881 }
2882
2883 // {current:post}
2884 elseif($name === 'post' && $post['type'] === 'post'){
2885
2886 $value = $post['id'];
2887
2888 }
2889
2890 // {current:term}
2891 elseif($name === 'term' && $post['type'] === 'term'){
2892
2893 $value = $post['id'];
2894
2895 }
2896
2897 // {current:user}
2898 elseif($name === 'user'){
2899
2900 $value = get_current_user_id();
2901
2902 }
2903
2904 // {current:author}
2905 elseif($name === 'author' && $post['type'] === 'post'){
2906
2907 $value = get_post_field('post_author', $post['id']);
2908
2909 }
2910
2911 // {current:form}
2912 elseif($name === 'form'){
2913
2914 $value = acf_maybe_get($form, 'form_id');
2915
2916 }
2917
2918 $content = str_replace('{current:' . $name . '}', $value, $content);
2919
2920 }
2921
2922 }
2923
2924 }
2925
2926 return $content;
2927
2928 }
2929
2930 // Match {query_var:name} {query_var:name:key}
2931 function acfe_form_map_query_var($content){
2932
2933 if(empty($content) || !is_string($content))
2934 return $content;
2935
2936 if(strpos($content, '{query_var:') === false)
2937 return $content;
2938
2939 // Match {query_var:name}
2940 if(preg_match_all('/{query_var:(.*?)}/', $content, $matches)){
2941
2942 foreach($matches[1] as $i => $name){
2943
2944 $query_var = get_query_var($name);
2945
2946 if(strpos($name, ':') !== false){
2947
2948 $explode = explode(':', $name);
2949
2950 $query_var = get_query_var($explode[0]);
2951
2952 if(is_array($query_var) && isset($query_var[$explode[1]])){
2953
2954 $query_var = $query_var[$explode[1]];
2955
2956 if(is_array($query_var) && isset($query_var[$explode[2]])){
2957
2958 $query_var = $query_var[$explode[2]];
2959
2960 }
2961
2962 }
2963
2964 }
2965
2966 $content = str_replace('{query_var:' . $name . '}', $query_var, $content);
2967
2968 }
2969
2970 }
2971
2972 return $content;
2973
2974 }
2975
2976 // Match {request:name} {request:name:key}
2977 function acfe_form_map_request($content){
2978
2979 if(empty($content) || !is_string($content))
2980 return $content;
2981
2982 if(strpos($content, '{request:') === false)
2983 return $content;
2984
2985 // Match {request:name}
2986 if(preg_match_all('/{request:(.*?)}/', $content, $matches)){
2987
2988 foreach($matches[1] as $i => $name){
2989
2990 $request = false;
2991
2992 if(isset($_REQUEST[$name]))
2993 $request = $_REQUEST[$name];
2994
2995 if(strpos($name, ':') !== false){
2996
2997 $explode = explode(':', $name);
2998
2999 if(isset($_REQUEST[$explode[0]]))
3000 $request = $_REQUEST[$explode[0]];
3001
3002 if(is_array($request) && isset($request[$explode[1]])){
3003
3004 $request = $request[$explode[1]];
3005
3006 }
3007
3008 }
3009
3010 $content = str_replace('{request:' . $name . '}', $request, $content);
3011
3012 }
3013
3014 }
3015
3016 return $content;
3017
3018 }
3019
3020 // Match {get_field:name} {get_field:name:123}
3021 function acfe_form_map_get_field($content, $post_id = 0){
3022
3023 if(empty($content) || !is_string($content))
3024 return $content;
3025
3026 if(strpos($content, '{get_field:') === false)
3027 return $content;
3028
3029 // Match {get_field:name}
3030 if(preg_match_all('/{get_field:(.*?)}/', $content, $matches)){
3031
3032 foreach($matches[1] as $i => $name){
3033
3034 if(strpos($name, ':') === false){
3035
3036 $get_field = get_field($name, $post_id);
3037
3038 }else{
3039
3040 $explode = explode(':', $name);
3041
3042 // Field
3043 $field = $explode[0];
3044
3045 // ID
3046 $id = $explode[1];
3047
3048 if($id === 'current')
3049 $id = $post_id;
3050
3051 // Format
3052 $format = true;
3053
3054 if(acf_maybe_get($explode, 2) === 'false')
3055 $format = false;
3056
3057 $get_field = get_field($field, $id, $format);
3058
3059 }
3060
3061 $content = str_replace('{get_field:' . $name . '}', $get_field, $content);
3062
3063 }
3064
3065 }
3066
3067 return $content;
3068
3069 }
3070
3071 // Match {get_option:name} {get_option:name:key}
3072 function acfe_form_map_get_option($content){
3073
3074 if(empty($content) || !is_string($content))
3075 return $content;
3076
3077 if(strpos($content, '{get_option:') === false)
3078 return $content;
3079
3080 // Match {get_option:name}
3081 if(preg_match_all('/{get_option:(.*?)}/', $content, $matches)){
3082
3083 foreach($matches[1] as $i => $name){
3084
3085 if(strpos($name, ':') === false){
3086
3087 $get_option = get_option($name);
3088
3089 }else{
3090
3091 $explode = explode(':', $name);
3092
3093 $get_option = get_option($explode[0]);
3094
3095 if(is_array($get_option) && isset($get_option[$explode[1]])){
3096
3097 $get_option = $get_option[$explode[1]];
3098
3099 }
3100
3101 }
3102
3103 $content = str_replace('{get_option:' . $name . '}', $get_option, $content);
3104
3105 }
3106
3107 }
3108
3109 return $content;
3110
3111 }
3112
3113 // Match {field:name} {field:key}
3114 function acfe_form_map_field($content){
3115
3116 if(empty($content) || !is_string($content))
3117 return $content;
3118
3119 if(strpos($content, '{field:') === false)
3120 return $content;
3121
3122 if(preg_match_all('/{field:(.*?)}/', $content, $matches)){
3123
3124 // Setup data
3125 $data = array();
3126
3127 $store = acf_get_store('acfe/form');
3128
3129 if($store->has('data')){
3130
3131 $data = $store->get('data');
3132
3133 }
3134
3135 foreach($matches[1] as $i => $field_key){
3136
3137 $format = true;
3138
3139 if(strpos($field_key, ':') !== false){
3140
3141 $explode = explode(':', $field_key);
3142
3143 $field_key = $explode[0]; // field_123abc
3144 $format = $explode[1]; // true / false
3145
3146 if($format === 'false')
3147 $format = false;
3148
3149 }
3150
3151 if(!empty($data)){
3152
3153 foreach($data as $field){
3154
3155 if($field['name'] !== $field_key && $field['key'] !== $field_key)
3156 continue;
3157
3158 // Value
3159 $value = $field['value'];
3160
3161 if($format)
3162 $value = acfe_form_format_value($field['value'], 0, $field['field']);
3163
3164 // Replace
3165 $content = str_replace('{field:' . $field_key . '}', $value, $content);
3166
3167 break;
3168
3169 }
3170
3171 }
3172
3173 // Fallback (clean)
3174 $content = str_replace('{field:' . $field_key . '}', '', $content);
3175
3176 }
3177
3178 }
3179
3180 // Return
3181 return $content;
3182
3183 }
3184
3185 // Match {fields}
3186 function acfe_form_map_fields($content){
3187
3188 if(empty($content) || !is_string($content))
3189 return $content;
3190
3191 if(strpos($content, '{fields}') === false)
3192 return $content;
3193
3194 // Match {fields}
3195 if(preg_match('/{fields}/', $content, $matches)){
3196
3197 // Setup data
3198 $data = array();
3199
3200 $store = acf_get_store('acfe/form');
3201
3202 if($store->has('data')){
3203
3204 $data = $store->get('data');
3205
3206 }
3207
3208 $content_html = '';
3209
3210 if(!empty($data)){
3211
3212 foreach($data as $field){
3213
3214 // Label
3215 $label = !empty($field['label']) ? $field['label'] : $field['name'];
3216
3217 // Value
3218 $value = acfe_form_format_value($field['value'], 0, $field['field']);
3219
3220 // Add
3221 $content_html .= $label . ': ' . $value . "<br/>\n";
3222
3223 }
3224
3225 }
3226
3227 // Replace
3228 $content = str_replace('{fields}', $content_html, $content);
3229
3230 }
3231
3232 // Return
3233 return $content;
3234
3235 }
3236
3237 function acfe_form_map_vs_fields($map, $fields, $post_id = 0, $form = array()){
3238
3239 $return = array();
3240
3241 foreach($map as $mkey => $mval){
3242
3243 if(empty($mval))
3244 continue;
3245
3246 $return[$mkey] = acfe_form_map_field_value($mval, $post_id, $form);
3247
3248 }
3249
3250 foreach($fields as $fkey => $fvalue){
3251
3252 if(isset($return[$fkey]))
3253 continue;
3254
3255 $return[$fkey] = acfe_form_map_field_value($fvalue, $post_id, $form);
3256
3257 }
3258
3259 return $return;
3260
3261 }