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