PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
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
← All changes | integrations/contact-form-7/includes/functions.php +155 -0 5.7.2 → 6.0.3 View file →
@@ -1,0 +1,155 @@
1 +<?php
2 +/**
3 + * Functions
4 + *
5 + * @package AutomatorWP\Contact_form_7\Functions
6 + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]>
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 WPCF7_ContactForm $form
18 + * @param WPCF7_Submission $submission
19 + *
20 + * @return array
21 + */
22 +function automatorwp_contact_form_7_get_form_fields_values( $form, $submission ) {
23 +
24 + $form_fields = array();
25 +
26 + // Check if form submission is correctly setup
27 + if ( ! $submission ) {
28 + return $form_fields;
29 + }
30 +
31 + // Check if posted data is correctly setup
32 + $posted_data = $submission->get_posted_data();
33 +
34 + if ( ! $posted_data ) {
35 + return $form_fields;
36 + }
37 +
38 + // Bail if not is a correct form object
39 + if ( ! $form instanceof WPCF7_ContactForm ) {
40 + return $form_fields;
41 + }
42 +
43 + $fields = $form->scan_form_tags();
44 +
45 + foreach ( (array) $fields as $field ) {
46 +
47 + // Skip empty field names
48 + if ( empty( $field->name ) ) {
49 + continue;
50 + }
51 +
52 + $field_name = $field->name;
53 + $field_value = ( isset( $posted_data[$field->name] ) ? $posted_data[$field->name] : '' );
54 +
55 + $form_fields[$field_name] = $field_value;
56 +
57 + }
58 +
59 + // Check for AutomatorWP 1.4.4
60 + if( function_exists( 'automatorwp_utilities_pull_array_values' ) ) {
61 + $form_fields = automatorwp_utilities_pull_array_values( $form_fields );
62 + }
63 +
64 + return $form_fields;
65 +
66 +}
67 +
68 +/**
69 + * Custom tags replacements
70 + *
71 + * @since 1.0.0
72 + *
73 + * @param string $parsed_content Content parsed
74 + * @param array $replacements Automation replacements
75 + * @param int $automation_id The automation ID
76 + * @param int $user_id The user ID
77 + * @param string $content The content to parse
78 + *
79 + * @return string
80 + */
81 +function automatorwp_contact_form_7_parse_automation_tags( $parsed_content, $replacements, $automation_id, $user_id, $content ) {
82 +
83 + $new_replacements = array();
84 +
85 + // Get automation triggers to pass their tags
86 + $triggers = automatorwp_get_automation_triggers( $automation_id );
87 +
88 + foreach( $triggers as $trigger ) {
89 +
90 + $trigger_args = automatorwp_get_trigger( $trigger->type );
91 +
92 + // Skip if trigger is not from this integration
93 + if( $trigger_args['integration'] !== 'contact_form_7' ) {
94 + continue;
95 + }
96 +
97 + // Get the last trigger log (where data for tags replacement will be get
98 + $log = automatorwp_get_user_last_completion( $trigger->id, $user_id, 'trigger' );
99 +
100 + if( ! $log ) {
101 + continue;
102 + }
103 +
104 + ct_setup_table( 'automatorwp_logs' );
105 + $form_fields = ct_get_object_meta( $log->id, 'form_fields', true );
106 + ct_reset_setup_table();
107 +
108 + // Skip if not form fields
109 + if( ! is_array( $form_fields ) ) {
110 + continue;
111 + }
112 +
113 + // Look for form field tags
114 + preg_match_all( "/\{t:" . $trigger->id . ":form_field:\s*(.*?)\s*\}/", $parsed_content, $matches );
115 +
116 + if( is_array( $matches ) && isset( $matches[1] ) ) {
117 +
118 + foreach( $matches[1] as $field_name ) {
119 + // Replace {t:ID:form_field:NAME} by the field value
120 + if( isset( $form_fields[$field_name] ) ) {
121 + $new_replacements['{t:' . $trigger->id . ':form_field:' . $field_name . '}'] = $form_fields[$field_name];
122 + }
123 + }
124 +
125 + }
126 +
127 + // Look for form field tags
128 + preg_match_all( "/\{" . $trigger->id . ":form_field:\s*(.*?)\s*\}/", $parsed_content, $matches );
129 +
130 + if( is_array( $matches ) && isset( $matches[1] ) ) {
131 +
132 + foreach( $matches[1] as $field_name ) {
133 + // Replace {ID:form_field:NAME} by the field value
134 + if( isset( $form_fields[$field_name] ) ) {
135 + $new_replacements['{' . $trigger->id . ':form_field:' . $field_name . '}'] = $form_fields[$field_name];
136 + }
137 + }
138 +
139 + }
140 +
141 + }
142 +
143 + if( count( $new_replacements ) ) {
144 +
145 + $tags = array_keys( $new_replacements );
146 +
147 + // Replace all tags by their replacements
148 + $parsed_content = str_replace( $tags, $new_replacements, $parsed_content );
149 +
150 + }
151 +
152 + return $parsed_content;
153 +
154 +}
155 +add_filter( 'automatorwp_parse_automation_tags', 'automatorwp_contact_form_7_parse_automation_tags', 10, 5 );