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