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