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