PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.2
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.2
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 5.6.2 All 33 releases
automatorwp / integrations / wpforms / includes / functions.php

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

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