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/activecampaign/includes/triggers/user-added.php +206 -0 5.7.6 → 6.0.3 View file →
@@ -1,0 +1,206 @@
1 +<?php
2 +/**
3 + * User Added
4 + *
5 + * @package AutomatorWP\Integrations\ActiveCampaign\Triggers\User_Added
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_ActiveCampaign_User_Added extends AutomatorWP_Integration_Trigger {
13 +
14 + public $integration = 'activecampaign';
15 + public $trigger = 'activecampaign_user_added';
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 added to ActiveCampaign', 'automatorwp' ),
27 + 'select_option' => __( '<strong>User</strong> added to ActiveCampaign', 'automatorwp' ),
28 + 'edit_label' => __( 'User added to ActiveCampaign', 'automatorwp' ),
29 + 'log_label' => __( 'User added to ActiveCampaign', 'automatorwp' ),
30 + 'action' => 'automatorwp_activecampaign_contact_subscribed',
31 + 'function' => array( $this, 'listener' ),
32 + 'priority' => 10,
33 + 'accepted_args' => 2,
34 + 'options' => array(
35 + // No options
36 + ),
37 + 'tags' => array_merge(
38 + automatorwp_activecampaign_get_webhook_tags()
39 + )
40 + ) );
41 +
42 + }
43 +
44 + /**
45 + * Trigger listener
46 + *
47 + * @since 1.0.0
48 + *
49 + * @param array $params Data received
50 + * @param int $user_id User ID
51 + */
52 + public function listener( $params, $user_id ) {
53 +
54 + // Bail if no user
55 + if ( $user_id === 0) {
56 + return;
57 + }
58 +
59 + $email = sanitize_email ( $params['contact']['email'] );
60 +
61 + /* translators: %1$s: Email. */
62 + $this->result = sprintf( __( '%1$s was added to ActiveCampaign', 'automatorwp' ), $email );
63 +
64 + // Trigger the user is subscribed to ActiveCampaign
65 + automatorwp_trigger_event( array(
66 + 'trigger' => $this->trigger,
67 + 'user_id' => $user_id,
68 + 'action_type' => $params['type'],
69 + 'date_time' => $params['date_time'],
70 + 'email' => $params['contact']['email'],
71 + 'first_name' => $params['contact']['first_name'],
72 + 'last_name' => $params['contact']['last_name'],
73 + ) );
74 +
75 + }
76 +
77 + /**
78 + * Register required hooks
79 + *
80 + * @since 1.0.0
81 + */
82 + public function hooks() {
83 +
84 + // Configuration notice
85 + add_filter( 'automatorwp_automation_ui_after_item_label', array( $this, 'configuration_notice' ), 10, 2 );
86 +
87 + // Log meta data
88 + add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
89 +
90 + // Log fields
91 + add_filter( 'automatorwp_log_fields', array( $this, 'log_fields' ), 10, 5 );
92 +
93 + parent::hooks();
94 +
95 + }
96 +
97 + /**
98 + * Configuration notice
99 + *
100 + * @since 1.0.0
101 + *
102 + * @param stdClass $object The trigger/action object
103 + * @param string $item_type The object type (trigger|action)
104 + */
105 + public function configuration_notice( $object, $item_type ) {
106 +
107 + // Bail if action type don't match this action
108 + if( $item_type !== 'trigger' || $object->type !== $this->trigger ) {
109 + return;
110 + }
111 +
112 + automatorwp_activecampaign_trigger_notice();
113 +
114 + }
115 +
116 + /**
117 + * Trigger custom log meta
118 + *
119 + * @since 1.0.0
120 + *
121 + * @param array $log_meta Log meta data
122 + * @param stdClass $trigger The trigger object
123 + * @param int $user_id The user ID
124 + * @param array $action_options The action's stored options (with tags already passed)
125 + * @param stdClass $automation The action's automation object
126 + *
127 + * @return array
128 + */
129 + public function log_meta( $log_meta, $trigger, $user_id, $event, $trigger_options, $automation ) {
130 +
131 + // Bail if trigger type don't match this action
132 + if( $trigger->type !== $this->trigger ) {
133 + return $log_meta;
134 + }
135 +
136 + // Store the action's result
137 + $log_meta['result'] = $this->result;
138 + $log_meta['action_type'] = ( isset( $event['action_type'] ) ? $event['action_type'] : '' );
139 + $log_meta['date_time'] = ( isset( $event['date_time'] ) ? $event['date_time'] : '' );
140 + $log_meta['email'] = ( isset( $event['email'] ) ? $event['email'] : '' );
141 + $log_meta['first_name'] = ( isset( $event['first_name'] ) ? $event['first_name'] : '' );
142 + $log_meta['last_name'] = ( isset( $event['last_name'] ) ? $event['last_name'] : '' );
143 +
144 + return $log_meta;
145 + }
146 +
147 + /**
148 + * Action custom log fields
149 + *
150 + * @since 1.0.0
151 + *
152 + * @param array $log_fields The log fields
153 + * @param stdClass $log The log object
154 + * @param stdClass $object The trigger/action/automation object attached to the log
155 + *
156 + * @return array
157 + */
158 + public function log_fields( $log_fields, $log, $object ) {
159 +
160 + // Bail if log is not assigned to an trigger
161 + if( $log->type !== 'trigger' ) {
162 + return $log_fields;
163 + }
164 +
165 + // Bail if trigger type don't match this action
166 + if( $object->type !== $this->trigger ) {
167 + return $log_fields;
168 + }
169 +
170 + $log_fields['result'] = array(
171 + 'name' => __( 'Result:', 'automatorwp' ),
172 + 'type' => 'text',
173 + );
174 +
175 + $log_fields['action_type'] = array(
176 + 'name' => __( 'Action type:', 'automatorwp' ),
177 + 'type' => 'text',
178 + );
179 +
180 + $log_fields['date_time'] = array(
181 + 'name' => __( 'Date:', 'automatorwp' ),
182 + 'type' => 'text',
183 + );
184 +
185 + $log_fields['email'] = array(
186 + 'name' => __( 'Email contact:', 'automatorwp' ),
187 + 'type' => 'text',
188 + );
189 +
190 + $log_fields['first_name'] = array(
191 + 'name' => __( 'First Name:', 'automatorwp' ),
192 + 'type' => 'text',
193 + );
194 +
195 + $log_fields['last_name'] = array(
196 + 'name' => __( 'Last_name:', 'automatorwp' ),
197 + 'type' => 'text',
198 + );
199 +
200 + return $log_fields;
201 + }
202 +
203 +
204 +}
205 +
206 +new AutomatorWP_ActiveCampaign_User_Added();