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