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