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