PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.1
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.1
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
automatorwp / integrations / thrive-leads / includes / triggers / anonymous-submit-form.php

anonymous-submit-form.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.1, at integrations/thrive-leads/includes/triggers/anonymous-submit-form.php

163 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Anonymous Submit Form
4 *
5 * @package AutomatorWP\Integrations\Thrive_Leads\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_Thrive_Leads_Anonymous_Submit_Form extends AutomatorWP_Integration_Trigger {
13
14 public $integration = 'thrive_leads';
15 public $trigger = 'thrive_leads_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. %2$s: Number of times. */
30 'edit_label' => sprintf( __( 'Guest submits %1$s %2$s time(s)', 'automatorwp' ), '{post}', '{times}' ),
31 /* translators: %1$s: Post title. */
32 'log_label' => sprintf( __( 'Guest submits %1$s', 'automatorwp' ), '{post}' ),
33 'action' => 'tcb_api_form_submit',
34 'function' => array( $this, 'listener' ),
35 'priority' => 10,
36 'accepted_args' => 1,
37 'options' => array(
38 'post' => automatorwp_utilities_ajax_selector_option( array(
39 'field' => 'post',
40 'name' => __( 'Form:', 'automatorwp' ),
41 'option_none_value' => 'any',
42 'option_none_label' => __( 'any form', 'automatorwp' ),
43 'action_cb' => 'automatorwp_thrive_leads_get_forms',
44 'options_cb' => 'automatorwp_thrive_leads_options_cb_form',
45 'default' => 'any'
46 ) ),
47 'times' => automatorwp_utilities_times_option(),
48 ),
49 'tags' => array_merge(
50 automatorwp_thrive_leads_tags(),
51 automatorwp_utilities_times_tag()
52 )
53 ) );
54
55 }
56
57 /**
58 * Trigger listener
59 *
60 * @since 1.0.0
61 *
62 * @param array $post
63 */
64 public function listener( $post ) {
65
66 // Login is required
67 if ( is_user_logged_in() ) {
68 return;
69 }
70
71 $user_id = get_current_user_id();
72
73 $form_id = $post['thrive_leads']['tl_data']['_key'];
74 $form_name = $post['thrive_leads']['tl_data']['form_name'];
75 $group_id = $post['thrive_leads']['tl_data']['main_group_id'];
76 $group_name = $post['thrive_leads']['tl_data']['main_group_name'];
77
78 // Trigger submit form event
79 automatorwp_trigger_event( array(
80 'trigger' => $this->trigger,
81 'form_id' => $form_id,
82 'form_name' => $form_name,
83 'group_id' => $group_id,
84 'group_name' => $group_name,
85 ) );
86
87 }
88
89 /**
90 * User deserves check
91 *
92 * @since 1.0.0
93 *
94 * @param bool $deserves_trigger True if user deserves trigger, false otherwise
95 * @param stdClass $trigger The trigger object
96 * @param array $event Event information
97 * @param array $trigger_options The trigger's stored options
98 * @param stdClass $automation The trigger's automation object
99 *
100 * @return bool True if user deserves trigger, false otherwise
101 */
102 public function anonymous_deserves_trigger( $deserves_trigger, $trigger, $event, $trigger_options, $automation ) {
103
104 // Don't deserve if post is not received
105 if( ! isset( $event['form_id'] ) ) {
106 return false;
107 }
108
109 // Bail if post doesn't match with the trigger option
110 if( $trigger_options['post'] !== 'any' && absint( $event['form_id'] ) !== absint( $trigger_options['post'] ) ) {
111 return false;
112 }
113
114 return $deserves_trigger;
115
116 }
117
118 /**
119 * Register the required hooks
120 *
121 * @since 1.0.0
122 */
123 public function hooks() {
124
125 // Log meta data
126 add_filter( 'automatorwp_anonymous_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 5 );
127
128 parent::hooks();
129 }
130
131 /**
132 * Trigger custom log meta
133 *
134 * @since 1.0.0
135 *
136 * @param array $log_meta Log meta data
137 * @param stdClass $trigger The trigger object
138 * @param array $event Event information
139 * @param array $trigger_options The trigger's stored options
140 * @param stdClass $automation The trigger's automation object
141 *
142 * @return array
143 */
144 function log_meta( $log_meta, $trigger, $event, $trigger_options, $automation ) {
145
146 // Bail if action type don't match this action
147 if( $trigger->type !== $this->trigger ) {
148 return $log_meta;
149 }
150
151 $log_meta['form_id'] = ( isset( $event['form_id'] ) ? $event['form_id'] : 0 );
152 $log_meta['form_name'] = ( isset( $event['form_name'] ) ? $event['form_name'] : '' );
153 $log_meta['group_id'] = ( isset( $event['group_id'] ) ? $event['group_id'] : 0 );
154 $log_meta['group_name'] = ( isset( $event['group_name'] ) ? $event['group_name'] : '' );
155
156
157 return $log_meta;
158
159 }
160
161 }
162
163 new AutomatorWP_Thrive_Leads_Anonymous_Submit_Form();