PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.1
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.1
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
automatorwp / integrations / everest-forms / includes / functions.php

functions.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.1, at integrations/everest-forms/includes/functions.php

126 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions
4 *
5 * @package AutomatorWP\EverestForms\Functions
6 * @since 1.0.0
7 */
8 // Exit if accessed directly
9 if( !defined( 'ABSPATH' ) ) exit;
10
11 /**
12 * Get form fields values
13 *
14 * @since 1.0.0
15 *
16 * @param array $fields
17 *
18 * @return array
19 */
20 function automatorwp_everest_forms_get_form_fields_values( $fields ) {
21
22 $form_fields = array();
23
24 // Loop all fields
25 foreach ( $fields as $subfield ) {
26 $form_fields[$subfield['meta_key']]= $subfield['value'];
27 }
28
29 // Check for AutomatorWP 1.4.4
30 if( function_exists( 'automatorwp_utilities_pull_array_values' ) ) {
31 $form_fields = automatorwp_utilities_pull_array_values( $form_fields );
32 }
33
34 return $form_fields;
35
36
37 }
38
39 /**
40 * Custom tags replacements
41 *
42 * @since 1.0.0
43 *
44 * @param string $parsed_content Content parsed
45 * @param array $replacements Automation replacements
46 * @param int $automation_id The automation ID
47 * @param int $user_id The user ID
48 * @param string $content The content to parse
49 *
50 * @return string
51 */
52 function automatorwp_everest_forms_parse_automation_tags( $parsed_content, $replacements, $automation_id, $user_id, $content ) {
53
54 $new_replacements = array();
55
56 // Get automation triggers to pass their tags
57 $triggers = automatorwp_get_automation_triggers( $automation_id );
58
59 foreach( $triggers as $trigger ) {
60
61 $trigger_args = automatorwp_get_trigger( $trigger->type );
62
63 // Skip if trigger is not from this integration
64 if( $trigger_args['integration'] !== 'everest_forms' ) {
65 continue;
66 }
67
68 // Get the last trigger log (where data for tags replacement will be get
69 $log = automatorwp_get_user_last_completion( $trigger->id, $user_id, 'trigger' );
70
71 if( ! $log ) {
72 continue;
73 }
74
75 ct_setup_table( 'automatorwp_logs' );
76 $form_fields = ct_get_object_meta( $log->id, 'form_fields', true );
77 ct_reset_setup_table();
78
79 // Skip if not form fields
80 if( ! is_array( $form_fields ) ) {
81 continue;
82 }
83
84 // Look for form field tags
85 preg_match_all( "/\{t:" . $trigger->id . ":form_field:\s*(.*?)\s*\}/", $parsed_content, $matches );
86
87 if( is_array( $matches ) && isset( $matches[1] ) ) {
88
89 foreach( $matches[1] as $field_name ) {
90 // Replace {t:ID:form_field:NAME} by the field value
91 if( isset( $form_fields[$field_name] ) ) {
92 $new_replacements['{t:' . $trigger->id . ':form_field:' . $field_name . '}'] = $form_fields[$field_name];
93 }
94 }
95
96 }
97
98 // Look for form field tags
99 preg_match_all( "/\{" . $trigger->id . ":form_field:\s*(.*?)\s*\}/", $parsed_content, $matches );
100
101 if( is_array( $matches ) && isset( $matches[1] ) ) {
102
103 foreach( $matches[1] as $field_name ) {
104 // Replace {ID:form_field:NAME} by the field value
105 if( isset( $form_fields[$field_name] ) ) {
106 $new_replacements['{' . $trigger->id . ':form_field:' . $field_name . '}'] = $form_fields[$field_name];
107 }
108 }
109
110 }
111
112 }
113
114 if( count( $new_replacements ) ) {
115
116 $tags = array_keys( $new_replacements );
117
118 // Replace all tags by their replacements
119 $parsed_content = str_replace( $tags, $new_replacements, $parsed_content );
120
121 }
122
123 return $parsed_content;
124
125 }
126 add_filter( 'automatorwp_parse_automation_tags', 'automatorwp_everest_forms_parse_automation_tags', 10, 5 );