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/divi/includes/triggers/anonymous-submit-form.php +214 -0 5.7.2 → 6.0.3 View file →
@@ -1,0 +1,214 @@
1 +<?php
2 +/**
3 + * Anonymous Submit Form
4 + *
5 + * @package AutomatorWP\Integrations\Divi\Triggers\Anonymous_Submit_Form
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 +class AutomatorWP_Divi_Anonymous_Submit_Form extends AutomatorWP_Integration_Trigger {
13 +
14 + public $integration = 'divi';
15 + public $trigger = 'divi_anonymous_submit_form';
16 +
17 + /**
18 + * Register the trigger
19 + *
20 + * @since 1.0.0
21 + */
22 + public function register() {
23 +
24 + automatorwp_register_trigger( $this->trigger, array(
25 + 'integration' => $this->integration,
26 + 'anonymous' => true,
27 + 'label' => __( 'Guest submits a form', 'automatorwp' ),
28 + 'select_option' => __( 'Guest submits <strong>a form</strong>', 'automatorwp' ),
29 + /* translators: %1$s: Form name. */
30 + 'edit_label' => sprintf( __( 'Guest submits %1$s', 'automatorwp' ), '{form_id}' ),
31 + /* translators: %1$s: Form name. */
32 + 'log_label' => sprintf( __( 'Guest submits %1$s', 'automatorwp' ), '{form_id}' ),
33 + 'action' => 'et_pb_contact_form_submit',
34 + 'function' => array( $this, 'listener' ),
35 + 'priority' => 999,
36 + 'accepted_args' => 3,
37 + 'options' => array(
38 + 'form_id' => array(
39 + 'from' => 'form_id',
40 + 'default' => __( 'any form', 'automatorwp' ),
41 + 'fields' => array(
42 + 'form_id' => array(
43 + 'name' => __( 'Form ID:', 'automatorwp' ),
44 + 'type' => 'text',
45 + 'default' => ''
46 + )
47 + )
48 + ),
49 + 'times' => automatorwp_utilities_times_option(),
50 + ),
51 + 'tags' => array_merge(
52 + array(
53 + 'form_field:FIELD_ID' => array(
54 + 'label' => __( 'Form field value', 'automatorwp' ),
55 + 'type' => 'text',
56 + 'preview' => __( 'Form field value, replace "FIELD_ID" by the field id', 'automatorwp' ),
57 + ),
58 + ),
59 + automatorwp_utilities_times_tag()
60 + )
61 + ) );
62 +
63 + }
64 +
65 + /**
66 + * Trigger listener
67 + *
68 + * @since 1.0.0
69 + *
70 + * @param array $fields_values
71 + * @param bool $et_contact_error
72 + * @param array $contact_form_info
73 + */
74 + public function listener( $fields_values, $et_contact_error, $contact_form_info ) {
75 +
76 + $user_id = get_current_user_id();
77 +
78 + // Bail if user is logged in
79 + if ( $user_id !== 0 ) {
80 + return;
81 + }
82 +
83 + // Bail if submission has an error
84 + if ( $et_contact_error === true ) {
85 + return;
86 + }
87 +
88 + // Bail if form does not have an ID
89 + if ( ! isset( $contact_form_info['contact_form_unique_id'] ) ) {
90 + return;
91 + }
92 +
93 + $form_id = $contact_form_info['contact_form_unique_id'];
94 + $post_id = $contact_form_info['post_id']; // Post where form is located
95 +
96 + $form_fields = automatorwp_divi_get_form_fields_values( $fields_values );
97 +
98 + // Trigger submit form event
99 + automatorwp_trigger_event( array(
100 + 'trigger' => $this->trigger,
101 + 'form_id' => $form_id,
102 + 'form_fields' => $form_fields,
103 + ) );
104 +
105 + }
106 +
107 + /**
108 + * Anonymous deserves check
109 + *
110 + * @since 1.0.0
111 + *
112 + * @param bool $deserves_trigger True if anonymous deserves trigger, false otherwise
113 + * @param stdClass $trigger The trigger object
114 + * @param array $event Event information
115 + * @param array $trigger_options The trigger's stored options
116 + * @param stdClass $automation The trigger's automation object
117 + *
118 + * @return bool True if anonymous deserves trigger, false otherwise
119 + */
120 + public function anonymous_deserves_trigger( $deserves_trigger, $trigger, $event, $trigger_options, $automation ) {
121 +
122 + // Don't deserve if form name is not received
123 + if( ! isset( $event['form_id'] ) ) {
124 + return false;
125 + }
126 +
127 + // Don't deserve if form name doesn't match with the trigger option
128 + if( ! empty( $trigger_options['form_id'] ) && $event['form_id'] !== $trigger_options['form_id'] ) {
129 + return false;
130 + }
131 +
132 + return $deserves_trigger;
133 +
134 + }
135 +
136 + /**
137 + * Register the required hooks
138 + *
139 + * @since 1.0.0
140 + */
141 + public function hooks() {
142 +
143 + // Log meta data
144 + add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
145 +
146 + // Log fields
147 + add_filter( 'automatorwp_log_fields', array( $this, 'log_fields' ), 10, 5 );
148 +
149 + parent::hooks();
150 + }
151 +
152 + /**
153 + * Trigger custom log meta
154 + *
155 + * @since 1.0.0
156 + *
157 + * @param array $log_meta Log meta data
158 + * @param stdClass $trigger The trigger object
159 + * @param int $user_id The user ID
160 + * @param array $event Event information
161 + * @param array $trigger_options The trigger's stored options
162 + * @param stdClass $automation The trigger's automation object
163 + *
164 + * @return array
165 + */
166 + function log_meta( $log_meta, $trigger, $user_id, $event, $trigger_options, $automation ) {
167 +
168 + // Bail if action type don't match this action
169 + if( $trigger->type !== $this->trigger ) {
170 + return $log_meta;
171 + }
172 +
173 + $log_meta['form_fields'] = ( isset( $event['form_fields'] ) ? $event['form_fields'] : array() );
174 +
175 + return $log_meta;
176 +
177 + }
178 +
179 + /**
180 + * Action custom log fields
181 + *
182 + * @since 1.0.0
183 + *
184 + * @param array $log_fields The log fields
185 + * @param stdClass $log The log object
186 + * @param stdClass $object The trigger/action/automation object attached to the log
187 + *
188 + * @return array
189 + */
190 + public function log_fields( $log_fields, $log, $object ) {
191 +
192 + // Bail if log is not assigned to an trigger
193 + if( $log->type !== 'trigger' ) {
194 + return $log_fields;
195 + }
196 +
197 + // Bail if trigger type don't match this trigger
198 + if( $object->type !== $this->trigger ) {
199 + return $log_fields;
200 + }
201 +
202 + $log_fields['form_fields'] = array(
203 + 'name' => __( 'Fields Submitted', 'automatorwp' ),
204 + 'desc' => __( 'Information about the fields values sent on this form submission.', 'automatorwp' ),
205 + 'type' => 'text',
206 + );
207 +
208 + return $log_fields;
209 +
210 + }
211 +
212 +}
213 +
214 +new AutomatorWP_Divi_Anonymous_Submit_Form();