增强套件,可改进"高级自定义字段"管理
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1886 lines
70 KiB

  1. <?php
  2. if(!defined('ABSPATH'))
  3. exit;
  4. if(!class_exists('acfe_dynamic_forms')):
  5. class acfe_dynamic_forms extends acfe_dynamic_module{
  6. // vars
  7. public $field_groups = array();
  8. /*
  9. * Initialize
  10. */
  11. function initialize(){
  12. $this->active = acf_get_setting('acfe/modules/forms');
  13. $this->post_type = 'acfe-form';
  14. $this->label = 'Form Title';
  15. $this->tool = 'acfe_dynamic_forms_export';
  16. $this->tools = array('json');
  17. $this->columns = array(
  18. 'name' => __('Name', 'acf'),
  19. 'field_groups' => __('Field groups', 'acf'),
  20. 'actions' => __('Actions', 'acf'),
  21. 'shortcode' => __('Shortcode', 'acf'),
  22. );
  23. }
  24. /*
  25. * Actions
  26. */
  27. function actions(){
  28. // Validate
  29. add_filter('acf/validate_value/name=acfe_form_name', array($this, 'validate_name'), 10, 4);
  30. // Save
  31. add_action('acfe/form/save', array($this, 'save'), 10, 2);
  32. // Import
  33. add_action('acfe/form/import_fields', array($this, 'import_fields'), 10, 3);
  34. // Includes
  35. acfe_include('includes/modules/forms-cheatsheet.php');
  36. acfe_include('includes/modules/forms-front.php');
  37. acfe_include('includes/modules/forms-helpers.php');
  38. acfe_include('includes/modules/forms-hooks.php');
  39. acfe_include('includes/modules/forms-action-custom.php');
  40. acfe_include('includes/modules/forms-action-email.php');
  41. acfe_include('includes/modules/forms-action-post.php');
  42. acfe_include('includes/modules/forms-action-redirect.php');
  43. acfe_include('includes/modules/forms-action-term.php');
  44. acfe_include('includes/modules/forms-action-user.php');
  45. do_action('acfe/include_form_actions');
  46. }
  47. /*
  48. * Get Name
  49. */
  50. function get_name($post_id){
  51. return get_field('acfe_form_name', $post_id);
  52. }
  53. /*
  54. * Init
  55. */
  56. function init(){
  57. $capability = acf_get_setting('capability');
  58. if(!acf_get_setting('show_admin'))
  59. $capability = false;
  60. register_post_type($this->post_type, array(
  61. 'label' => __('Forms', 'acf'),
  62. 'description' => __('Forms', 'acf'),
  63. 'labels' => array(
  64. 'name' => __('Forms', 'acf'),
  65. 'singular_name' => __('Form', 'acf'),
  66. 'menu_name' => __('Forms', 'acf'),
  67. 'edit_item' => 'Edit Form',
  68. 'add_new_item' => 'New Form',
  69. ),
  70. 'supports' => array('title'),
  71. 'hierarchical' => false,
  72. 'public' => false,
  73. 'show_ui' => true,
  74. 'show_in_menu' => 'edit.php?post_type=acf-field-group',
  75. 'menu_icon' => 'dashicons-feedback',
  76. 'show_in_admin_bar' => false,
  77. 'show_in_nav_menus' => false,
  78. 'can_export' => false,
  79. 'has_archive' => false,
  80. 'rewrite' => false,
  81. 'exclude_from_search' => true,
  82. 'publicly_queryable' => false,
  83. 'capabilities' => array(
  84. 'publish_posts' => $capability,
  85. 'edit_posts' => $capability,
  86. 'edit_others_posts' => $capability,
  87. 'delete_posts' => $capability,
  88. 'delete_others_posts' => $capability,
  89. 'read_private_posts' => $capability,
  90. 'edit_post' => $capability,
  91. 'delete_post' => $capability,
  92. 'read_post' => $capability,
  93. ),
  94. 'acfe_admin_ppp' => 999,
  95. 'acfe_admin_orderby' => 'title',
  96. 'acfe_admin_order' => 'ASC',
  97. ));
  98. }
  99. /*
  100. * Post Head
  101. */
  102. function post_head(){
  103. global $pagenow;
  104. if($pagenow === 'post-new.php')
  105. return;
  106. $this->field_groups = acf_get_instance('acfe_dynamic_forms_helpers')->get_field_groups();
  107. // Add Instructions
  108. add_meta_box('acfe-form-integration', 'Integration', array($this, 'meta_box_side'), $this->post_type,'side', 'core');
  109. if($this->field_groups){
  110. add_meta_box('acfe-form-details', __('Fields', 'acf'), array($this, 'meta_box_field_groups'), $this->post_type, 'normal');
  111. }
  112. }
  113. /*
  114. * Metabox: Sidebar
  115. */
  116. function meta_box_side($post){
  117. $form_id = $post->ID;
  118. $form_name = $this->get_name($form_id);
  119. ?>
  120. <div class="acf-field">
  121. <div class="acf-label">
  122. <label>Shortcodes:</label>
  123. </div>
  124. <div class="acf-input">
  125. <code>[acfe_form ID="<?php echo $form_id; ?>"]</code><br /><br />
  126. <code>[acfe_form name="<?php echo $form_name; ?>"]</code>
  127. </div>
  128. </div>
  129. <div class="acf-field">
  130. <div class="acf-label">
  131. <label>PHP code:</label>
  132. </div>
  133. <div class="acf-input">
  134. <pre>&lt;?php get_header(); ?&gt;
  135. &lt;!-- <?php echo get_the_title($form_id); ?> --&gt;
  136. &lt;?php acfe_form(&apos;<?php echo $form_name; ?>&apos;); ?&gt;
  137. &lt;?php get_footer(); ?&gt;</pre>
  138. </div>
  139. </div>
  140. <script type="text/javascript">
  141. if(typeof acf !== 'undefined'){
  142. acf.newPostbox(<?php echo wp_json_encode(array(
  143. 'id' => 'acfe-form-integration',
  144. 'key' => '',
  145. 'style' => 'default',
  146. 'label' => 'top',
  147. 'edit' => false
  148. )); ?>);
  149. }
  150. </script>
  151. <?php
  152. }
  153. /*
  154. * Metabox: Field Groups
  155. */
  156. function meta_box_field_groups(){
  157. foreach($this->field_groups as $field_group){ ?>
  158. <div class="acf-field">
  159. <div class="acf-label">
  160. <label><a href="<?php echo admin_url("post.php?post={$field_group['ID']}&action=edit"); ?>"><?php echo $field_group['title']; ?></a></label>
  161. <p class="description"><?php echo $field_group['key']; ?></p>
  162. </div>
  163. <div class="acf-input">
  164. <?php if(acf_maybe_get($field_group, 'fields')){ ?>
  165. <table class="acf-table">
  166. <thead>
  167. <th class="acf-th" width="25%"><strong>Label</strong></th>
  168. <th class="acf-th" width="25%"><strong>Name</strong></th>
  169. <th class="acf-th" width="25%"><strong>Key</strong></th>
  170. <th class="acf-th" width="25%"><strong>Type</strong></th>
  171. </thead>
  172. <tbody>
  173. <?php
  174. $array = array();
  175. foreach($field_group['fields'] as $field){
  176. $this->get_fields_labels_recursive($array, $field);
  177. }
  178. foreach($array as $field_key => $field_label){
  179. $field = acf_get_field($field_key);
  180. $type = acf_get_field_type($field['type']);
  181. $type_label = '-';
  182. if(isset($type->label))
  183. $type_label = $type->label;
  184. ?>
  185. <tr class="acf-row">
  186. <td width="25%"><?php echo $field_label; ?></td>
  187. <td width="25%"><code style="font-size:12px;"><?php echo $field['name']; ?></code></td>
  188. <td width="25%"><code style="font-size:12px;"><?php echo $field_key; ?></code></td>
  189. <td width="25%"><?php echo $type_label; ?></td>
  190. </tr>
  191. <?php } ?>
  192. </tbody>
  193. </table>
  194. <?php } ?>
  195. </div>
  196. </div>
  197. <?php } ?>
  198. <script type="text/javascript">
  199. if(typeof acf !== 'undefined'){
  200. acf.newPostbox(<?php echo wp_json_encode(array(
  201. 'id' => 'acfe-form-details',
  202. 'key' => '',
  203. 'style' => 'default',
  204. 'label' => 'left',
  205. 'edit' => false
  206. )); ?>);
  207. }
  208. </script>
  209. <?php
  210. }
  211. /*
  212. * Edit Columns HTML
  213. */
  214. function edit_columns_html($column, $post_id){
  215. switch($column){
  216. // Name
  217. case 'name':
  218. echo '<code style="font-size: 12px;">' . $this->get_name($post_id) . '</code>';
  219. break;
  220. // Field Groups
  221. case 'field_groups':
  222. $return = '—';
  223. $field_groups = acf_get_array(get_field('acfe_form_field_groups', $post_id));
  224. if(!empty($field_groups)){
  225. $links = array();
  226. foreach($field_groups as $key){
  227. $field_group = acf_get_field_group($key);
  228. if(!$field_group)
  229. continue;
  230. if(acf_maybe_get($field_group, 'ID')){
  231. $links[] = '<a href="' . admin_url("post.php?post={$field_group['ID']}&action=edit") . '">' . $field_group['title'] . '</a>';
  232. }else{
  233. $links[] = $field_group['title'];
  234. }
  235. }
  236. $return = implode(', ', $links);
  237. }
  238. echo $return;
  239. break;
  240. // Actions
  241. case 'actions':
  242. $return = '—';
  243. $icons = array();
  244. if(have_rows('acfe_form_actions', $post_id)):
  245. while(have_rows('acfe_form_actions', $post_id)): the_row();
  246. // Custom
  247. if(get_row_layout() === 'custom'){
  248. $action_name = get_sub_field('acfe_form_custom_action');
  249. $icons[] = '<span class="acf-js-tooltip dashicons dashicons-editor-code" title="Custom action: ' . $action_name . '"></span>';
  250. }
  251. // E-mail
  252. elseif(get_row_layout() === 'email'){
  253. $icons[] = '<span class="acf-js-tooltip dashicons dashicons-email" title="E-mail"></span>';
  254. }
  255. // Post
  256. elseif(get_row_layout() === 'post'){
  257. $action = get_sub_field('acfe_form_post_action');
  258. // Insert
  259. if($action === 'insert_post'){
  260. $icons[] = '<span class="acf-js-tooltip dashicons dashicons-edit" title="Create post"></span>';
  261. }
  262. // Update
  263. elseif($action === 'update_post'){
  264. $icons[] = '<span class="acf-js-tooltip dashicons dashicons-update" title="Update post"></span>';
  265. }
  266. }
  267. // Term
  268. elseif(get_row_layout() === 'term'){
  269. $action = get_sub_field('acfe_form_term_action');
  270. // Insert
  271. if($action === 'insert_term'){
  272. $icons[] = '<span class="acf-js-tooltip dashicons dashicons-category" title="Create term"></span>';
  273. }
  274. // Update
  275. elseif($action === 'update_term'){
  276. $icons[] = '<span class="acf-js-tooltip dashicons dashicons-category" title="Update term"></span>';
  277. }
  278. }
  279. // User
  280. elseif(get_row_layout() === 'user'){
  281. $action = get_sub_field('acfe_form_user_action');
  282. // Insert
  283. if($action === 'insert_user'){
  284. $icons[] = '<span class="acf-js-tooltip dashicons dashicons-admin-users" title="Create user"></span>';
  285. }
  286. // Update
  287. elseif($action === 'update_user'){
  288. $icons[] = '<span class="acf-js-tooltip dashicons dashicons-admin-users" title="Update user"></span>';
  289. }
  290. // Update
  291. elseif($action === 'log_user'){
  292. $icons[] = '<span class="acf-js-tooltip dashicons dashicons-migrate" title="Log user"></span>';
  293. }
  294. }
  295. endwhile;
  296. endif;
  297. if(!empty($icons)){
  298. $return = implode('', $icons);
  299. }
  300. echo $return;
  301. break;
  302. // Shortcode
  303. case 'shortcode':
  304. echo '<code style="font-size: 12px;">[acfe_form name="' . $this->get_name($post_id) . '"]</code>';
  305. break;
  306. }
  307. }
  308. /*
  309. * ACF Save post
  310. */
  311. function save_post($post_id){
  312. // Get Post
  313. $name = $this->get_name($post_id);
  314. // Actions
  315. do_action("acfe/form/save", $name, $post_id);
  316. do_action("acfe/form/save/name={$name}", $name, $post_id);
  317. do_action("acfe/form/save/id={$post_id}", $name, $post_id);
  318. }
  319. /*
  320. * Save
  321. */
  322. function save($name, $post_id){
  323. // Update post
  324. wp_update_post(array(
  325. 'ID' => $post_id,
  326. 'post_name' => $name,
  327. ));
  328. // Get generated post name (possible name-2)
  329. $_name = get_post_field('post_name', $post_id);
  330. // Update the meta if different
  331. if($_name !== $name)
  332. update_field('acfe_form_name', $_name, $post_id);
  333. }
  334. /*
  335. * Validate Name
  336. */
  337. function validate_name($valid, $value, $field, $input){
  338. if($valid !== true)
  339. return $valid;
  340. // Check current name
  341. $post_id = acfe_get_post_id();
  342. if(empty($post_id))
  343. return $valid;
  344. $name = get_field($field['name'], $post_id);
  345. if($value === $name)
  346. return $valid;
  347. $get_posts = get_posts(array(
  348. 'post_type' => $this->post_type,
  349. 'name' => $value,
  350. 'post__not_in' => array($post_id),
  351. 'fields' => 'ids',
  352. 'post_status' => array('publish', 'acf-disabled'),
  353. 'posts_per_page' => 1
  354. ));
  355. if(!empty($get_posts))
  356. $valid = 'This form name already exists';
  357. return $valid;
  358. }
  359. /*
  360. * Import
  361. */
  362. function import($name, $args){
  363. // Vars
  364. $title = acf_extract_var($args, 'title');
  365. $name = $args['acfe_form_name'];
  366. // Already exists
  367. if(get_page_by_path($name, OBJECT, $this->post_type)){
  368. return new WP_Error('acfe_form_import_already_exists', __("Form \"{$title}\" already exists. Import aborted."));
  369. }
  370. // Import Post
  371. $post_id = false;
  372. $post = array(
  373. 'post_title' => $title,
  374. 'post_name' => $name,
  375. 'post_type' => $this->post_type,
  376. 'post_status' => 'publish'
  377. );
  378. $post = apply_filters("acfe/form/import_post", $post, $name);
  379. $post = apply_filters("acfe/form/import_post/name={$name}", $post, $name);
  380. if($post !== false){
  381. $post_id = wp_insert_post($post);
  382. }
  383. if(!$post_id || is_wp_error($post_id)){
  384. return new WP_Error('acfe_form_import_error', __("Something went wrong with the form \"{$title}\". Import aborted."));
  385. }
  386. // Import Args
  387. $args = apply_filters("acfe/form/import_args", $args, $name, $post_id);
  388. $args = apply_filters("acfe/form/import_args/name={$name}", $args, $name, $post_id);
  389. $args = apply_filters("acfe/form/import_args/id={$post_id}", $args, $name, $post_id);
  390. if($args === false)
  391. return $post_id;
  392. // Import Fields
  393. acf_enable_filter('local');
  394. do_action("acfe/form/import_fields", $name, $args, $post_id);
  395. do_action("acfe/form/import_fields/name={$name}", $name, $args, $post_id);
  396. do_action("acfe/form/import_fields/id={$post_id}", $name, $args, $post_id);
  397. acf_disable_filter('local');
  398. // Save
  399. $this->save_post($post_id);
  400. return $post_id;
  401. }
  402. /*
  403. * Import Fields
  404. */
  405. function import_fields($name, $args, $post_id){
  406. // Update
  407. acf_update_values($args, $post_id);
  408. }
  409. /*
  410. * Export: Choices
  411. */
  412. function export_choices(){
  413. $choices = array();
  414. $get_posts = get_posts(array(
  415. 'post_type' => 'acfe-form',
  416. 'posts_per_page' => -1,
  417. 'fields' => 'ids'
  418. ));
  419. if(!$get_posts)
  420. return $choices;
  421. foreach($get_posts as $post_id){
  422. $name = $this->get_name($post_id);
  423. $choices[$name] = esc_html(get_the_title($post_id));
  424. }
  425. return $choices;
  426. }
  427. /*
  428. * Export: Data
  429. */
  430. function export_data($name){
  431. if(!$form = get_page_by_path($name, OBJECT, $this->post_type))
  432. return false;
  433. acf_enable_filter('local');
  434. $args = array_merge(array('title' => get_the_title($form->ID)), get_fields($form->ID, false));
  435. // Filters
  436. $args = apply_filters("acfe/form/export_args", $args, $name);
  437. $args = apply_filters("acfe/form/export_args/name={$name}", $args, $name);
  438. acf_disable_filter('local');
  439. return $args;
  440. }
  441. /*
  442. * Add Local Field Group
  443. */
  444. function add_local_field_group(){
  445. $actions_layouts = apply_filters('acfe/form/actions', array());
  446. ksort($actions_layouts);
  447. acf_add_local_field_group(array(
  448. 'key' => 'group_acfe_dynamic_form',
  449. 'title' => 'Dynamic Form',
  450. 'acfe_display_title' => '',
  451. 'fields' => array(
  452. /*
  453. * Actions
  454. */
  455. array(
  456. 'key' => 'field_acfe_form_tab_general',
  457. 'label' => 'General',
  458. 'name' => '',
  459. 'type' => 'tab',
  460. 'instructions' => '',
  461. 'required' => 0,
  462. 'conditional_logic' => 0,
  463. 'wrapper' => array(
  464. 'width' => '',
  465. 'class' => '',
  466. 'id' => '',
  467. 'data-no-preference' => true,
  468. ),
  469. 'acfe_permissions' => '',
  470. 'placement' => 'top',
  471. 'endpoint' => 0,
  472. ),
  473. array(
  474. 'key' => 'field_acfe_form_name',
  475. 'label' => 'Form name',
  476. 'name' => 'acfe_form_name',
  477. 'type' => 'acfe_slug',
  478. 'instructions' => 'The unique form slug',
  479. 'required' => 1,
  480. 'conditional_logic' => 0,
  481. 'wrapper' => array(
  482. 'width' => '',
  483. 'class' => '',
  484. 'id' => '',
  485. ),
  486. 'acfe_permissions' => '',
  487. 'default_value' => '',
  488. 'placeholder' => '',
  489. 'prepend' => '',
  490. 'append' => '',
  491. 'maxlength' => '',
  492. ),
  493. array(
  494. 'key' => 'field_acfe_form_field_groups',
  495. 'label' => 'Field groups',
  496. 'name' => 'acfe_form_field_groups',
  497. 'type' => 'select',
  498. 'instructions' => 'Render & map fields of the following field groups',
  499. 'required' => 0,
  500. 'conditional_logic' => 0,
  501. 'wrapper' => array(
  502. 'width' => '',
  503. 'class' => '',
  504. 'id' => '',
  505. ),
  506. 'acfe_permissions' => '',
  507. 'choices' => array(
  508. ),
  509. 'default_value' => array(
  510. ),
  511. 'allow_null' => 0,
  512. 'multiple' => 1,
  513. 'ui' => 1,
  514. 'ajax' => 0,
  515. 'return_format' => 'value',
  516. 'placeholder' => '',
  517. ),
  518. array(
  519. 'key' => 'field_acfe_form_actions',
  520. 'label' => 'Actions',
  521. 'name' => 'acfe_form_actions',
  522. 'type' => 'flexible_content',
  523. 'instructions' => 'Add actions on form submission',
  524. 'required' => 0,
  525. 'conditional_logic' => 0,
  526. 'wrapper' => array(
  527. 'width' => '',
  528. 'class' => '',
  529. 'id' => '',
  530. ),
  531. 'acfe_flexible_stylised_button' => 1,
  532. 'layouts' => $actions_layouts,
  533. 'button_label' => 'Add action',
  534. 'min' => '',
  535. 'max' => '',
  536. ),
  537. /*
  538. * Settings
  539. */
  540. array(
  541. 'key' => 'field_acfe_form_tab_settings',
  542. 'label' => 'Settings',
  543. 'name' => '',
  544. 'type' => 'tab',
  545. 'instructions' => '',
  546. 'required' => 0,
  547. 'conditional_logic' => 0,
  548. 'wrapper' => array(
  549. 'width' => '',
  550. 'class' => '',
  551. 'id' => '',
  552. ),
  553. 'acfe_permissions' => '',
  554. 'placement' => 'top',
  555. 'endpoint' => 0,
  556. ),
  557. array(
  558. 'key' => 'field_acfe_form_field_groups_rules',
  559. 'label' => 'Field groups locations rules',
  560. 'name' => 'acfe_form_field_groups_rules',
  561. 'type' => 'true_false',
  562. 'instructions' => 'Apply field groups locations rules for front-end display',
  563. 'required' => 0,
  564. 'wrapper' => array(
  565. 'width' => '',
  566. 'class' => '',
  567. 'id' => '',
  568. ),
  569. 'acfe_permissions' => '',
  570. 'message' => '',
  571. 'default_value' => 0,
  572. 'ui' => 1,
  573. 'ui_on_text' => '',
  574. 'ui_off_text' => '',
  575. ),
  576. array(
  577. 'key' => 'field_acfe_form_form_element',
  578. 'label' => 'Form element',
  579. 'name' => 'acfe_form_form_element',
  580. 'type' => 'true_false',
  581. 'instructions' => 'Whether or not to create a <code>&lt;form&gt;</code> element',
  582. 'required' => 0,
  583. 'conditional_logic' => 0,
  584. 'wrapper' => array(
  585. 'width' => '',
  586. 'class' => '',
  587. 'id' => '',
  588. ),
  589. 'acfe_permissions' => '',
  590. 'message' => '',
  591. 'default_value' => 1,
  592. 'ui' => 1,
  593. 'ui_on_text' => '',
  594. 'ui_off_text' => '',
  595. ),
  596. array(
  597. 'key' => 'field_acfe_form_attributes',
  598. 'label' => 'Form attributes',
  599. 'name' => 'acfe_form_attributes',
  600. 'type' => 'group',
  601. 'instructions' => 'Form class and id',
  602. 'required' => 0,
  603. 'wrapper' => array(
  604. 'width' => '',
  605. 'class' => '',
  606. 'id' => '',
  607. ),
  608. 'acfe_permissions' => '',
  609. 'layout' => 'block',
  610. 'acfe_seamless_style' => true,
  611. 'acfe_group_modal' => 0,
  612. 'conditional_logic' => array(
  613. array(
  614. array(
  615. 'field' => 'field_acfe_form_form_element',
  616. 'operator' => '==',
  617. 'value' => '1',
  618. ),
  619. ),
  620. ),
  621. 'sub_fields' => array(
  622. array(
  623. 'key' => 'field_acfe_form_attributes_class',
  624. 'label' => '',
  625. 'name' => 'acfe_form_attributes_class',
  626. 'type' => 'text',
  627. 'instructions' => '',
  628. 'required' => 0,
  629. 'conditional_logic' => array(),
  630. 'wrapper' => array(
  631. 'width' => '33',
  632. 'class' => '',
  633. 'id' => '',
  634. ),
  635. 'acfe_permissions' => '',
  636. 'default_value' => 'acf-form',
  637. 'placeholder' => '',
  638. 'prepend' => 'class',
  639. 'append' => '',
  640. 'maxlength' => '',
  641. ),
  642. array(
  643. 'key' => 'field_acfe_form_attributes_id',
  644. 'label' => '',
  645. 'name' => 'acfe_form_attributes_id',
  646. 'type' => 'text',
  647. 'instructions' => '',
  648. 'required' => 0,
  649. 'conditional_logic' => array(),
  650. 'wrapper' => array(
  651. 'width' => '33',
  652. 'class' => '',
  653. 'id' => '',
  654. ),
  655. 'acfe_permissions' => '',
  656. 'default_value' => '',
  657. 'placeholder' => '',
  658. 'prepend' => 'id',
  659. 'append' => '',
  660. 'maxlength' => '',
  661. ),
  662. ),
  663. ),
  664. array(
  665. 'key' => 'field_acfe_form_fields_attributes',
  666. 'label' => 'Fields class',
  667. 'name' => 'acfe_form_fields_attributes',
  668. 'type' => 'group',
  669. 'instructions' => 'Add class to all fields',
  670. 'required' => 0,
  671. 'wrapper' => array(
  672. 'width' => '',
  673. 'class' => '',
  674. 'id' => '',
  675. ),
  676. 'acfe_permissions' => '',
  677. 'layout' => 'block',
  678. 'acfe_seamless_style' => true,
  679. 'acfe_group_modal' => 0,
  680. 'conditional_logic' => array(),
  681. 'sub_fields' => array(
  682. array(
  683. 'key' => 'field_acfe_form_fields_wrapper_class',
  684. 'label' => '',
  685. 'name' => 'acfe_form_fields_wrapper_class',
  686. 'type' => 'text',
  687. 'instructions' => '',
  688. 'required' => 0,
  689. 'conditional_logic' => array(),
  690. 'wrapper' => array(
  691. 'width' => '33',
  692. 'class' => '',
  693. 'id' => '',
  694. ),
  695. 'acfe_permissions' => '',
  696. 'default_value' => '',
  697. 'placeholder' => '',
  698. 'prepend' => 'wrapper class',
  699. 'append' => '',
  700. 'maxlength' => '',
  701. ),
  702. array(
  703. 'key' => 'field_acfe_form_fields_class',
  704. 'label' => '',
  705. 'name' => 'acfe_form_fields_class',
  706. 'type' => 'text',
  707. 'instructions' => '',
  708. 'required' => 0,
  709. 'conditional_logic' => array(),
  710. 'wrapper' => array(
  711. 'width' => '33',
  712. 'class' => '',
  713. 'id' => '',
  714. ),
  715. 'acfe_permissions' => '',
  716. 'default_value' => '',
  717. 'placeholder' => '',
  718. 'prepend' => 'input class',
  719. 'append' => '',
  720. 'maxlength' => '',
  721. ),
  722. ),
  723. ),
  724. array(
  725. 'key' => 'field_acfe_form_form_submit',
  726. 'label' => 'Submit button',
  727. 'name' => 'acfe_form_form_submit',
  728. 'type' => 'true_false',
  729. 'instructions' => 'Whether or not to create a form submit button. Defaults to true',
  730. 'required' => 0,
  731. 'conditional_logic' => 0,
  732. 'wrapper' => array(
  733. 'width' => '',
  734. 'class' => '',
  735. 'id' => '',
  736. ),
  737. 'acfe_permissions' => '',
  738. 'message' => '',
  739. 'default_value' => 1,
  740. 'ui' => 1,
  741. 'ui_on_text' => '',
  742. 'ui_off_text' => '',
  743. ),
  744. array(
  745. 'key' => 'field_acfe_form_submit_value',
  746. 'label' => 'Submit value',
  747. 'name' => 'acfe_form_submit_value',
  748. 'type' => 'text',
  749. 'instructions' => 'The text displayed on the submit button',
  750. 'required' => 0,
  751. 'conditional_logic' => array(
  752. array(
  753. array(
  754. 'field' => 'field_acfe_form_form_submit',
  755. 'operator' => '==',
  756. 'value' => '1',
  757. ),
  758. ),
  759. ),
  760. 'wrapper' => array(
  761. 'width' => '',
  762. 'class' => '',
  763. 'id' => '',
  764. ),
  765. 'acfe_permissions' => '',
  766. 'default_value' => 'Submit',
  767. 'placeholder' => '',
  768. 'prepend' => '',
  769. 'append' => '',
  770. 'maxlength' => '',
  771. ),
  772. array(
  773. 'key' => 'field_acfe_form_html_submit_button',
  774. 'label' => 'Submit button',
  775. 'name' => 'acfe_form_html_submit_button',
  776. 'type' => 'acfe_code_editor',
  777. 'instructions' => 'HTML used to render the submit button.',
  778. 'required' => 0,
  779. 'conditional_logic' => array(
  780. array(
  781. array(
  782. 'field' => 'field_acfe_form_form_submit',
  783. 'operator' => '==',
  784. 'value' => '1',
  785. ),
  786. ),
  787. ),
  788. 'wrapper' => array(
  789. 'width' => '',
  790. 'class' => '',
  791. 'id' => '',
  792. ),
  793. 'acfe_permissions' => '',
  794. 'default_value' => '<input type="submit" class="acf-button button button-primary button-large" value="%s" />',
  795. 'placeholder' => '',
  796. 'maxlength' => '',
  797. 'rows' => 2,
  798. ),
  799. array(
  800. 'key' => 'field_acfe_form_html_submit_spinner',
  801. 'label' => 'Submit spinner',
  802. 'name' => 'acfe_form_html_submit_spinner',
  803. 'type' => 'acfe_code_editor',
  804. 'instructions' => 'HTML used to render the submit button loading spinner.',
  805. 'required' => 0,
  806. 'conditional_logic' => array(
  807. array(
  808. array(
  809. 'field' => 'field_acfe_form_form_submit',
  810. 'operator' => '==',
  811. 'value' => '1',
  812. ),
  813. ),
  814. ),
  815. 'wrapper' => array(
  816. 'width' => '',
  817. 'class' => '',
  818. 'id' => '',
  819. ),
  820. 'acfe_permissions' => '',
  821. 'default_value' => '<span class="acf-spinner"></span>',
  822. 'placeholder' => '',
  823. 'maxlength' => '',
  824. 'rows' => 2,
  825. ),
  826. array(
  827. 'key' => 'field_acfe_form_honeypot',
  828. 'label' => 'Honeypot',
  829. 'name' => 'acfe_form_honeypot',
  830. 'type' => 'true_false',
  831. 'instructions' => 'Whether to include a hidden input field to capture non human form submission. Defaults to true.',
  832. 'required' => 0,
  833. 'conditional_logic' => 0,
  834. 'wrapper' => array(
  835. 'width' => '',
  836. 'class' => '',
  837. 'id' => '',
  838. ),
  839. 'acfe_permissions' => '',
  840. 'message' => '',
  841. 'default_value' => 1,
  842. 'ui' => 1,
  843. 'ui_on_text' => '',
  844. 'ui_off_text' => '',
  845. ),
  846. array(
  847. 'key' => 'field_acfe_form_kses',
  848. 'label' => 'Kses',
  849. 'name' => 'acfe_form_kses',
  850. 'type' => 'true_false',
  851. 'instructions' => 'Whether or not to sanitize all $_POST data with the wp_kses_post() function. Defaults to true.',
  852. 'required' => 0,
  853. 'conditional_logic' => 0,
  854. 'wrapper' => array(
  855. 'width' => '',
  856. 'class' => '',
  857. 'id' => '',
  858. ),
  859. 'acfe_permissions' => '',
  860. 'message' => '',
  861. 'default_value' => 1,
  862. 'ui' => 1,
  863. 'ui_on_text' => '',
  864. 'ui_off_text' => '',
  865. ),
  866. array(
  867. 'key' => 'field_acfe_form_uploader',
  868. 'label' => 'Uploader',
  869. 'name' => 'acfe_form_uploader',
  870. 'type' => 'radio',
  871. 'instructions' => 'Whether to use the WP uploader or a basic input for image and file fields. Defaults to \'wp\'
  872. Choices of \'wp\' or \'basic\'.',
  873. 'required' => 0,
  874. 'conditional_logic' => 0,
  875. 'wrapper' => array(
  876. 'width' => '',
  877. 'class' => '',
  878. 'id' => '',
  879. ),
  880. 'acfe_permissions' => '',
  881. 'choices' => array(
  882. 'default' => 'Default',
  883. 'wp' => 'WordPress',
  884. 'basic' => 'Browser',
  885. ),
  886. 'allow_null' => 0,
  887. 'other_choice' => 0,
  888. 'default_value' => 'default',
  889. 'layout' => 'vertical',
  890. 'return_format' => 'value',
  891. 'save_other_choice' => 0,
  892. ),
  893. array(
  894. 'key' => 'field_acfe_form_form_field_el',
  895. 'label' => 'Field element',
  896. 'name' => 'acfe_form_form_field_el',
  897. 'type' => 'radio',
  898. 'instructions' => 'Determines element used to wrap a field. Defaults to \'div\'',
  899. 'required' => 0,
  900. 'conditional_logic' => 0,
  901. 'wrapper' => array(
  902. 'width' => '',
  903. 'class' => '',
  904. 'id' => '',
  905. ),
  906. 'acfe_permissions' => '',
  907. 'choices' => array(
  908. 'div' => '&lt;div&gt;',
  909. 'tr' => '&lt;tr&gt;',
  910. 'td' => '&lt;td&gt;',
  911. 'ul' => '&lt;ul&gt;',
  912. 'ol' => '&lt;ol&gt;',
  913. 'dl' => '&lt;dl&gt;',
  914. ),
  915. 'allow_null' => 0,
  916. 'other_choice' => 0,
  917. 'default_value' => 'div',
  918. 'layout' => 'vertical',
  919. 'return_format' => 'value',
  920. 'save_other_choice' => 0,
  921. ),
  922. array(
  923. 'key' => 'field_acfe_form_label_placement',
  924. 'label' => 'Label placement',
  925. 'name' => 'acfe_form_label_placement',
  926. 'type' => 'radio',
  927. 'instructions' => 'Determines where field labels are places in relation to fields. Defaults to \'top\'. <br />
  928. Choices of \'top\' (Above fields) or \'left\' (Beside fields)',
  929. 'required' => 0,
  930. 'conditional_logic' => 0,
  931. 'wrapper' => array(
  932. 'width' => '',
  933. 'class' => '',
  934. 'id' => '',
  935. ),
  936. 'acfe_permissions' => '',
  937. 'choices' => array(
  938. 'top' => 'Top',
  939. 'left' => 'Left',
  940. 'hidden' => 'Hidden',
  941. ),
  942. 'allow_null' => 0,
  943. 'other_choice' => 0,
  944. 'default_value' => 'top',
  945. 'layout' => 'vertical',
  946. 'return_format' => 'value',
  947. 'save_other_choice' => 0,
  948. ),
  949. array(
  950. 'key' => 'field_acfe_form_instruction_placement',
  951. 'label' => 'Instruction placement',
  952. 'name' => 'acfe_form_instruction_placement',
  953. 'type' => 'radio',
  954. 'instructions' => 'Determines where field instructions are places in relation to fields. Defaults to \'label\'. <br />
  955. Choices of \'label\' (Below labels) or \'field\' (Below fields)',
  956. 'required' => 0,
  957. 'conditional_logic' => 0,
  958. 'wrapper' => array(
  959. 'width' => '',
  960. 'class' => '',
  961. 'id' => '',
  962. ),
  963. 'acfe_permissions' => '',
  964. 'choices' => array(
  965. 'label' => 'Label',
  966. 'field' => 'Field',
  967. ),
  968. 'allow_null' => 0,
  969. 'other_choice' => 0,
  970. 'default_value' => 'label',
  971. 'layout' => 'vertical',
  972. 'return_format' => 'value',
  973. 'save_other_choice' => 0,
  974. ),
  975. /*
  976. * HTML
  977. */
  978. array(
  979. 'key' => 'field_acfe_form_tab_html',
  980. 'label' => 'HTML',
  981. 'name' => '',
  982. 'type' => 'tab',
  983. 'instructions' => '',
  984. 'required' => 0,
  985. 'conditional_logic' => 0,
  986. 'wrapper' => array(
  987. 'width' => '',
  988. 'class' => '',
  989. 'id' => '',
  990. ),
  991. 'acfe_permissions' => '',
  992. 'placement' => 'top',
  993. 'endpoint' => 0,
  994. ),
  995. array(
  996. 'key' => 'field_acfe_form_custom_html_enable',
  997. 'label' => 'Override Form render',
  998. 'name' => 'acfe_form_custom_html_enable',
  999. 'type' => 'true_false',
  1000. 'instructions' => 'Override the native field groups HTML render',
  1001. 'required' => 0,
  1002. 'conditional_logic' => 0,
  1003. 'wrapper' => array(
  1004. 'width' => '',
  1005. 'class' => '',
  1006. 'id' => '',
  1007. ),
  1008. 'acfe_permissions' => '',
  1009. 'message' => '',
  1010. 'default_value' => false,
  1011. 'ui' => 1,
  1012. 'ui_on_text' => '',
  1013. 'ui_off_text' => '',
  1014. ),
  1015. array(
  1016. 'key' => 'field_acfe_form_html_before_fields',
  1017. 'label' => 'HTML Before render',
  1018. 'name' => 'acfe_form_html_before_fields',
  1019. 'type' => 'acfe_code_editor',
  1020. 'instructions' => 'Extra HTML to add before the fields',
  1021. 'required' => 0,
  1022. 'conditional_logic' => 0,
  1023. 'wrapper' => array(
  1024. 'width' => '',
  1025. 'class' => '',
  1026. 'id' => '',
  1027. ),
  1028. 'acfe_permissions' => '',
  1029. 'default_value' => '',
  1030. 'placeholder' => '',
  1031. 'maxlength' => '',
  1032. 'rows' => 2,
  1033. ),
  1034. array(
  1035. 'key' => 'field_acfe_form_custom_html',
  1036. 'label' => 'HTML Form render',
  1037. 'name' => 'acfe_form_custom_html',
  1038. 'type' => 'acfe_code_editor',
  1039. 'instructions' => 'Render your own customized HTML.<br /><br />
  1040. Field groups may be included using <code>{field_group:group_key}</code><br/><code>{field_group:Group title}</code><br/><br/>
  1041. Fields may be included using <code>{field:field_key}</code><br/><code>{field:field_name}</code>',
  1042. 'required' => 0,
  1043. 'wrapper' => array(
  1044. 'width' => '',
  1045. 'class' => '',
  1046. 'id' => '',
  1047. ),
  1048. 'acfe_permissions' => '',
  1049. 'default_value' => '',
  1050. 'placeholder' => '',
  1051. 'maxlength' => '',
  1052. 'rows' => 12,
  1053. 'conditional_logic' => array(
  1054. array(
  1055. array(
  1056. 'field' => 'field_acfe_form_custom_html_enable',
  1057. 'operator' => '==',
  1058. 'value' => '1',
  1059. ),
  1060. ),
  1061. ),
  1062. ),
  1063. array(
  1064. 'key' => 'field_acfe_form_html_after_fields',
  1065. 'label' => 'HTML After render',
  1066. 'name' => 'acfe_form_html_after_fields',
  1067. 'type' => 'acfe_code_editor',
  1068. 'instructions' => 'Extra HTML to add after the fields',
  1069. 'required' => 0,
  1070. 'conditional_logic' => 0,
  1071. 'wrapper' => array(
  1072. 'width' => '',
  1073. 'class' => '',
  1074. 'id' => '',
  1075. ),
  1076. 'acfe_permissions' => '',
  1077. 'default_value' => '',
  1078. 'placeholder' => '',
  1079. 'maxlength' => '',
  1080. 'rows' => 2,
  1081. ),
  1082. /*
  1083. * Validation
  1084. */
  1085. array(
  1086. 'key' => 'field_acfe_form_tab_validation',
  1087. 'label' => 'Validation',
  1088. 'name' => '',
  1089. 'type' => 'tab',
  1090. 'instructions' => '',
  1091. 'required' => 0,
  1092. 'conditional_logic' => 0,
  1093. 'wrapper' => array(
  1094. 'width' => '',
  1095. 'class' => '',
  1096. 'id' => '',
  1097. ),
  1098. 'acfe_permissions' => '',
  1099. 'placement' => 'top',
  1100. 'endpoint' => 0,
  1101. ),
  1102. array(
  1103. 'key' => 'field_acfe_form_hide_error',
  1104. 'label' => 'Hide general error',
  1105. 'name' => 'acfe_form_hide_error',
  1106. 'type' => 'true_false',
  1107. 'instructions' => 'Hide the general error message: "Validation failed. 1 field requires attention"',
  1108. 'required' => 0,
  1109. 'conditional_logic' => 0,
  1110. 'wrapper' => array(
  1111. 'width' => '',
  1112. 'class' => '',
  1113. 'id' => '',
  1114. ),
  1115. 'acfe_permissions' => '',
  1116. 'message' => '',
  1117. 'default_value' => 0,
  1118. 'ui' => 1,
  1119. 'ui_on_text' => '',
  1120. 'ui_off_text' => '',
  1121. ),
  1122. array(
  1123. 'key' => 'field_acfe_form_hide_revalidation',
  1124. 'label' => 'Hide successful re-validation',
  1125. 'name' => 'acfe_form_hide_revalidation',
  1126. 'type' => 'true_false',
  1127. 'instructions' => 'Hide the successful notice when an error has been thrown',
  1128. 'required' => 0,
  1129. 'conditional_logic' => 0,
  1130. 'wrapper' => array(
  1131. 'width' => '',
  1132. 'class' => '',
  1133. 'id' => '',
  1134. ),
  1135. 'acfe_permissions' => '',
  1136. 'message' => '',
  1137. 'default_value' => 0,
  1138. 'ui' => 1,
  1139. 'ui_on_text' => '',
  1140. 'ui_off_text' => '',
  1141. ),
  1142. array(
  1143. 'key' => 'field_acfe_form_hide_unload',
  1144. 'label' => 'Hide confirmation on exit',
  1145. 'name' => 'acfe_form_hide_unload',
  1146. 'type' => 'true_false',
  1147. 'instructions' => 'Do not prompt user on page refresh',
  1148. 'required' => 0,
  1149. 'conditional_logic' => 0,
  1150. 'wrapper' => array(
  1151. 'width' => '',
  1152. 'class' => '',
  1153. 'id' => '',
  1154. ),
  1155. 'acfe_permissions' => '',
  1156. 'message' => '',
  1157. 'default_value' => 0,
  1158. 'ui' => 1,
  1159. 'ui_on_text' => '',
  1160. 'ui_off_text' => '',
  1161. ),
  1162. array(
  1163. 'key' => 'field_acfe_form_errors_position',
  1164. 'label' => 'Fields errors position',
  1165. 'name' => 'acfe_form_errors_position',
  1166. 'type' => 'radio',
  1167. 'instructions' => 'Choose where to display field errors',
  1168. 'required' => 0,
  1169. 'conditional_logic' => 0,
  1170. 'wrapper' => array(
  1171. 'width' => '',
  1172. 'class' => '',
  1173. 'id' => '',
  1174. ),
  1175. 'acfe_permissions' => '',
  1176. 'choices' => array(
  1177. 'above' => 'Above fields',
  1178. 'below' => 'Below fields',
  1179. 'group' => 'Group errors',
  1180. 'hide' => 'Hide errors',
  1181. ),
  1182. 'allow_null' => 0,
  1183. 'other_choice' => 0,
  1184. 'default_value' => 'above',
  1185. 'layout' => 'vertical',
  1186. 'return_format' => 'value',
  1187. 'save_other_choice' => 0,
  1188. ),
  1189. array(
  1190. 'key' => 'field_acfe_form_errors_class',
  1191. 'label' => 'Fields errors class',
  1192. 'name' => 'acfe_form_errors_class',
  1193. 'type' => 'text',
  1194. 'instructions' => 'Add class to error message',
  1195. 'required' => 0,
  1196. 'conditional_logic' => array(
  1197. array(
  1198. array(
  1199. 'field' => 'field_acfe_form_errors_position',
  1200. 'operator' => '!=',
  1201. 'value' => 'group',
  1202. ),
  1203. array(
  1204. 'field' => 'field_acfe_form_errors_position',
  1205. 'operator' => '!=',
  1206. 'value' => 'hide',
  1207. ),
  1208. )
  1209. ),
  1210. 'wrapper' => array(
  1211. 'width' => '',
  1212. 'class' => '',
  1213. 'id' => '',
  1214. ),
  1215. 'acfe_permissions' => '',
  1216. 'default_value' => '',
  1217. 'placeholder' => '',
  1218. 'prepend' => '',
  1219. 'append' => '',
  1220. 'maxlength' => '',
  1221. ),
  1222. /*
  1223. * Submission
  1224. */
  1225. array(
  1226. 'key' => 'field_acfe_form_tab_submission',
  1227. 'label' => 'Success Page',
  1228. 'name' => '',
  1229. 'type' => 'tab',
  1230. 'instructions' => '',
  1231. 'required' => 0,
  1232. 'conditional_logic' => 0,
  1233. 'wrapper' => array(
  1234. 'width' => '',
  1235. 'class' => '',
  1236. 'id' => '',
  1237. ),
  1238. 'acfe_permissions' => '',
  1239. 'placement' => 'top',
  1240. 'endpoint' => 0,
  1241. ),
  1242. array(
  1243. 'key' => 'field_acfe_form_return',
  1244. 'label' => 'Redirection',
  1245. 'name' => 'acfe_form_return',
  1246. 'type' => 'text',
  1247. 'instructions' => 'The URL to be redirected to after the form is submitted. See "Cheatsheet" tab for all available template tags.<br/><br/><u>This setting is deprecated, use the new "Redirect Action" instead.</u>',
  1248. 'required' => 0,
  1249. 'conditional_logic' => 0,
  1250. 'wrapper' => array(
  1251. 'width' => '',
  1252. 'class' => '',
  1253. 'id' => '',
  1254. 'data-enable-switch' => true
  1255. ),
  1256. 'acfe_permissions' => '',
  1257. 'default_value' => '',
  1258. 'placeholder' => '',
  1259. 'prepend' => '',
  1260. 'append' => '',
  1261. 'maxlength' => '',
  1262. ),
  1263. array(
  1264. 'key' => 'field_acfe_form_updated_hide_form',
  1265. 'label' => 'Hide form',
  1266. 'name' => 'acfe_form_updated_hide_form',
  1267. 'type' => 'true_false',
  1268. 'instructions' => 'Hide form on successful submission',
  1269. 'conditional_logic' => array(
  1270. array(
  1271. array(
  1272. 'field' => 'field_acfe_form_return',
  1273. 'operator' => '==',
  1274. 'value' => '',
  1275. ),
  1276. ),
  1277. ),
  1278. 'wrapper' => array(
  1279. 'width' => '',
  1280. 'class' => '',
  1281. 'id' => '',
  1282. ),
  1283. 'acfe_permissions' => '',
  1284. 'message' => '',
  1285. 'default_value' => 0,
  1286. 'ui' => 1,
  1287. 'ui_on_text' => '',
  1288. 'ui_off_text' => '',
  1289. ),
  1290. array(
  1291. 'key' => 'field_acfe_form_updated_message',
  1292. 'label' => 'Success message',
  1293. 'name' => 'acfe_form_updated_message',
  1294. 'type' => 'wysiwyg',
  1295. 'instructions' => 'A message displayed above the form after being redirected. See "Cheatsheet" tab for all available template tags.',
  1296. 'required' => 0,
  1297. 'conditional_logic' => array(
  1298. array(
  1299. array(
  1300. 'field' => 'field_acfe_form_return',
  1301. 'operator' => '==',
  1302. 'value' => '',
  1303. ),
  1304. ),
  1305. ),
  1306. 'wrapper' => array(
  1307. 'width' => '',
  1308. 'class' => '',
  1309. 'id' => '',
  1310. 'data-instruction-placement' => 'field'
  1311. ),
  1312. 'acfe_permissions' => '',
  1313. 'default_value' => __('Post updated', 'acf'),
  1314. 'tabs' => 'all',
  1315. 'toolbar' => 'full',
  1316. 'media_upload' => 1,
  1317. 'delay' => 0,
  1318. ),
  1319. array(
  1320. 'key' => 'field_acfe_form_html_updated_message',
  1321. 'label' => 'Success wrapper HTML',
  1322. 'name' => 'acfe_form_html_updated_message',
  1323. 'type' => 'acfe_code_editor',
  1324. 'instructions' => 'HTML used to render the updated message.<br />
  1325. If used, you have to include the following code <code>%s</code> to print the actual "Success message" above.',
  1326. 'required' => 0,
  1327. 'conditional_logic' => array(
  1328. array(
  1329. array(
  1330. 'field' => 'field_acfe_form_return',
  1331. 'operator' => '==',
  1332. 'value' => '',
  1333. ),
  1334. ),
  1335. ),
  1336. 'wrapper' => array(
  1337. 'width' => '',
  1338. 'class' => '',
  1339. 'id' => '',
  1340. 'data-instruction-placement' => 'field'
  1341. ),
  1342. 'acfe_permissions' => '',
  1343. 'default_value' => '<div id="message" class="updated">%s</div>',
  1344. 'placeholder' => '',
  1345. 'maxlength' => '',
  1346. 'rows' => 2,
  1347. ),
  1348. /*
  1349. * Cheatsheet
  1350. */
  1351. array(
  1352. 'key' => 'field_acfe_form_tab_cheatsheet',
  1353. 'label' => 'Cheatsheet',
  1354. 'name' => '',
  1355. 'type' => 'tab',
  1356. 'instructions' => '',
  1357. 'required' => 0,
  1358. 'conditional_logic' => 0,
  1359. 'wrapper' => array(
  1360. 'width' => '',
  1361. 'class' => '',
  1362. 'id' => '',
  1363. ),
  1364. 'acfe_permissions' => '',
  1365. 'placement' => 'top',
  1366. 'endpoint' => 0,
  1367. ),
  1368. array(
  1369. 'key' => 'field_acfe_form_cheatsheet_field',
  1370. 'label' => 'Field',
  1371. 'name' => 'acfe_form_cheatsheet_field',
  1372. 'type' => 'acfe_dynamic_message',
  1373. 'instructions' => 'Retrieve user input from the current form',
  1374. 'required' => 0,
  1375. 'conditional_logic' => 0,
  1376. 'wrapper' => array(
  1377. 'width' => '',
  1378. 'class' => '',
  1379. 'id' => '',
  1380. ),
  1381. ),
  1382. array(
  1383. 'key' => 'field_acfe_form_cheatsheet_fields',
  1384. 'label' => 'Fields',
  1385. 'name' => 'acfe_form_cheatsheet_fields',
  1386. 'type' => 'acfe_dynamic_message',
  1387. 'instructions' => 'Retrieve all user inputs from the current form',
  1388. 'required' => 0,
  1389. 'conditional_logic' => 0,
  1390. 'wrapper' => array(
  1391. 'width' => '',
  1392. 'class' => '',
  1393. 'id' => '',
  1394. ),
  1395. ),
  1396. array(
  1397. 'key' => 'field_acfe_form_cheatsheet_get_field',
  1398. 'label' => 'Get Field',
  1399. 'name' => 'acfe_form_cheatsheet_get_field',
  1400. 'type' => 'acfe_dynamic_message',
  1401. 'instructions' => 'Retrieve ACF field value from database',
  1402. 'required' => 0,
  1403. 'conditional_logic' => 0,
  1404. 'wrapper' => array(
  1405. 'width' => '',
  1406. 'class' => '',
  1407. 'id' => '',
  1408. ),
  1409. ),
  1410. array(
  1411. 'key' => 'field_acfe_form_cheatsheet_get_option',
  1412. 'label' => 'Get Option',
  1413. 'name' => 'acfe_form_cheatsheet_get_option',
  1414. 'type' => 'acfe_dynamic_message',
  1415. 'value' => '',
  1416. 'instructions' => 'Retrieve option value from database',
  1417. 'required' => 0,
  1418. 'conditional_logic' => 0,
  1419. 'wrapper' => array(
  1420. 'width' => '',
  1421. 'class' => '',
  1422. 'id' => '',
  1423. ),
  1424. ),
  1425. array(
  1426. 'key' => 'field_acfe_form_cheatsheet_request',
  1427. 'label' => 'Request',
  1428. 'name' => 'acfe_form_cheatsheet_request',
  1429. 'type' => 'acfe_dynamic_message',
  1430. 'value' => '',
  1431. 'instructions' => 'Retrieve <code>$_REQUEST</code> value',
  1432. 'required' => 0,
  1433. 'conditional_logic' => 0,
  1434. 'wrapper' => array(
  1435. 'width' => '',
  1436. 'class' => '',
  1437. 'id' => '',
  1438. ),
  1439. ),
  1440. array(
  1441. 'key' => 'field_acfe_form_cheatsheet_query_var',
  1442. 'label' => 'Query Var',
  1443. 'name' => 'acfe_form_cheatsheet_query_var',
  1444. 'type' => 'acfe_dynamic_message',
  1445. 'instructions' => 'Retrieve query var values. Can be used to get data from previous action',
  1446. 'required' => 0,
  1447. 'conditional_logic' => 0,
  1448. 'wrapper' => array(
  1449. 'width' => '',
  1450. 'class' => '',
  1451. 'id' => '',
  1452. ),
  1453. ),
  1454. array(
  1455. 'key' => 'field_acfe_form_cheatsheet_current_form',
  1456. 'label' => 'Form Settings',
  1457. 'name' => 'acfe_form_cheatsheet_current_form',
  1458. 'type' => 'acfe_dynamic_message',
  1459. 'instructions' => 'Retrieve current Dynamic Form data',
  1460. 'required' => 0,
  1461. 'conditional_logic' => 0,
  1462. 'wrapper' => array(
  1463. 'width' => '',
  1464. 'class' => '',
  1465. 'id' => '',
  1466. ),
  1467. ),
  1468. array(
  1469. 'key' => 'field_acfe_form_cheatsheet_actions_post',
  1470. 'label' => 'Action Output: Post',
  1471. 'name' => 'acfe_form_cheatsheet_actions_post',
  1472. 'type' => 'acfe_dynamic_message',
  1473. 'instructions' => 'Retrieve actions output',
  1474. 'required' => 0,
  1475. 'conditional_logic' => 0,
  1476. 'wrapper' => array(
  1477. 'width' => '',
  1478. 'class' => '',
  1479. 'id' => '',
  1480. ),
  1481. ),
  1482. array(
  1483. 'key' => 'acfe_form_cheatsheet_actions_term',
  1484. 'label' => 'Action Output: Term',
  1485. 'name' => 'acfe_form_cheatsheet_actions_term',
  1486. 'type' => 'acfe_dynamic_message',
  1487. 'instructions' => 'Retrieve actions output',
  1488. 'required' => 0,
  1489. 'conditional_logic' => 0,
  1490. 'wrapper' => array(
  1491. 'width' => '',
  1492. 'class' => '',
  1493. 'id' => '',
  1494. ),
  1495. ),
  1496. array(
  1497. 'key' => 'acfe_form_cheatsheet_actions_user',
  1498. 'label' => 'Action Output: User',
  1499. 'name' => 'acfe_form_cheatsheet_actions_user',
  1500. 'type' => 'acfe_dynamic_message',
  1501. 'instructions' => 'Retrieve actions output',
  1502. 'required' => 0,
  1503. 'conditional_logic' => 0,
  1504. 'wrapper' => array(
  1505. 'width' => '',
  1506. 'class' => '',
  1507. 'id' => '',
  1508. ),
  1509. ),
  1510. array(
  1511. 'key' => 'acfe_form_cheatsheet_actions_email',
  1512. 'label' => 'Action Output: Email',
  1513. 'name' => 'acfe_form_cheatsheet_actions_email',
  1514. 'type' => 'acfe_dynamic_message',
  1515. 'instructions' => 'Retrieve actions output',
  1516. 'required' => 0,
  1517. 'conditional_logic' => 0,
  1518. 'wrapper' => array(
  1519. 'width' => '',
  1520. 'class' => '',
  1521. 'id' => '',
  1522. ),
  1523. ),
  1524. array(
  1525. 'key' => 'field_acfe_form_cheatsheet_current_post',
  1526. 'label' => 'Current Post',
  1527. 'name' => 'acfe_form_cheatsheet_current_post',
  1528. 'type' => 'acfe_dynamic_message',
  1529. 'instructions' => 'Retrieve current post data (where the form is being printed)',
  1530. 'required' => 0,
  1531. 'conditional_logic' => 0,
  1532. 'wrapper' => array(
  1533. 'width' => '',
  1534. 'class' => '',
  1535. 'id' => '',
  1536. ),
  1537. ),
  1538. array(
  1539. 'key' => 'field_acfe_form_cheatsheet_current_term',
  1540. 'label' => 'Current Term',
  1541. 'name' => 'acfe_form_cheatsheet_current_term',
  1542. 'type' => 'acfe_dynamic_message',
  1543. 'instructions' => 'Retrieve current term data (where the form is being printed)',
  1544. 'required' => 0,
  1545. 'conditional_logic' => 0,
  1546. 'wrapper' => array(
  1547. 'width' => '',
  1548. 'class' => '',
  1549. 'id' => '',
  1550. ),
  1551. ),
  1552. array(
  1553. 'key' => 'field_acfe_form_cheatsheet_current_user',
  1554. 'label' => 'Current User',
  1555. 'name' => 'acfe_form_cheatsheet_current_user',
  1556. 'type' => 'acfe_dynamic_message',
  1557. 'instructions' => 'Retrieve currently logged user data',
  1558. 'required' => 0,
  1559. 'conditional_logic' => 0,
  1560. 'wrapper' => array(
  1561. 'width' => '',
  1562. 'class' => '',
  1563. 'id' => '',
  1564. ),
  1565. ),
  1566. array(
  1567. 'key' => 'field_acfe_form_cheatsheet_current_author',
  1568. 'label' => 'Current Author',
  1569. 'name' => 'acfe_form_cheatsheet_current_author',
  1570. 'type' => 'acfe_dynamic_message',
  1571. 'instructions' => 'Retrieve current post author data (where the form is being printed)',
  1572. 'required' => 0,
  1573. 'conditional_logic' => 0,
  1574. 'wrapper' => array(
  1575. 'width' => '',
  1576. 'class' => '',
  1577. 'id' => '',
  1578. ),
  1579. ),
  1580. ),
  1581. 'location' => array(
  1582. array(
  1583. array(
  1584. 'param' => 'post_type',
  1585. 'operator' => '==',
  1586. 'value' => $this->post_type,
  1587. ),
  1588. ),
  1589. ),
  1590. 'menu_order' => 0,
  1591. 'position' => 'acf_after_title',
  1592. 'style' => 'default',
  1593. 'label_placement' => 'left',
  1594. 'instruction_placement' => 'label',
  1595. 'hide_on_screen' => '',
  1596. 'active' => true,
  1597. 'description' => '',
  1598. 'acfe_permissions' => '',
  1599. 'acfe_form' => 0,
  1600. 'acfe_meta' => '',
  1601. 'acfe_note' => '',
  1602. ));
  1603. }
  1604. }
  1605. acf_new_instance('acfe_dynamic_forms');
  1606. endif;
  1607. /*
  1608. * ACFE: Import Form
  1609. */
  1610. function acfe_import_form($args){
  1611. // json
  1612. if(is_string($args))
  1613. $args = json_decode($args, true);
  1614. if(!is_array($args) || empty($args))
  1615. return new WP_Error('acfe_import_form_invalid_input', __("Input is invalid: Must be a json string or an array."));
  1616. // Instance
  1617. $instance = acf_get_instance('acfe_dynamic_forms');
  1618. // Single
  1619. if(acf_maybe_get($args, 'title')){
  1620. $name = acf_maybe_get($args, 'acfe_form_name');
  1621. $args = array(
  1622. $name => $args
  1623. );
  1624. }
  1625. $result = array();
  1626. foreach($args as $name => $data){
  1627. // Import
  1628. $post_id = $instance->import($name, $data);
  1629. $return = array(
  1630. 'success' => true,
  1631. 'post_id' => $post_id,
  1632. 'message' => 'Form "' . acf_maybe_get($data, 'title') . '" successfully imported.',
  1633. );
  1634. // Error
  1635. if(is_wp_error($post_id)){
  1636. $return['post_id'] = 0;
  1637. $return['success'] = false;
  1638. $return['message'] = $post_id->get_error_message();
  1639. if($post_id->get_error_code() === 'acfe_form_import_already_exists'){
  1640. $get_post = get_page_by_path($name, OBJECT, $instance->post_type);
  1641. if($get_post){
  1642. $return['post_id'] = $get_post->ID;
  1643. }
  1644. }
  1645. }
  1646. $result[] = $return;
  1647. }
  1648. if(count($result) === 1){
  1649. $result = $result[0];
  1650. }
  1651. return $result;
  1652. }
  1653. /*
  1654. * Deprecated ACFE: Import Forms
  1655. */
  1656. function acfe_import_forms($forms){
  1657. return acfe_import_form($forms);
  1658. }
  1659. /*
  1660. * Deprecated ACFE: Import Dynamic Form
  1661. */
  1662. function acfe_import_dynamic_form($forms = false){
  1663. return acfe_import_form($forms);
  1664. }