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 / fluentcrm / includes / triggers / status-change.php

status-change.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.1, at integrations/fluentcrm/includes/triggers/status-change.php

170 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Status Change
4 *
5 * @package AutomatorWP\Integrations\FluentCRM\Triggers\Status_Change
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_FluentCRM_Status_Change extends AutomatorWP_Integration_Trigger {
13
14 public $integration = 'fluentcrm';
15 public $trigger = 'fluentcrm_status_change';
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 status changes to a status', 'automatorwp' ),
27 'select_option' => __( 'User status changes to <strong>a status</strong>', 'automatorwp' ),
28 /* translators: %1$s: List. %2$s: Number of times. */
29 'edit_label' => sprintf( __( 'User status changes to %1$s %2$s time(s)', 'automatorwp' ), '{status}', '{times}' ),
30 /* translators: %1$s: List. */
31 'log_label' => sprintf( __( 'User status changes to %1$s', 'automatorwp' ), '{status}' ),
32 'action' => array(
33 'fluentcrm_subscriber_status_to_subscribed',
34 'fluentcrm_subscriber_status_to_pending',
35 'fluentcrm_subscriber_status_to_unsubscribed',
36 'fluentcrm_subscriber_status_to_bounced',
37 'fluentcrm_subscriber_status_to_complained',
38 ),
39 'function' => array( $this, 'listener' ),
40 'priority' => 10,
41 'accepted_args' => 2,
42 'options' => array(
43 'status' => array(
44 'from' => 'status',
45 'fields' => array(
46 'status' => array(
47 'name' => __( 'Status:', 'automatorwp' ),
48 'type' => 'select',
49 'options' => array(
50 'any' => __( 'any status', 'automatorwp' ),
51 'subscribed' => __( 'Subscribed', 'automatorwp' ),
52 'pending' => __( 'Pending', 'automatorwp' ),
53 'unsubscribed' => __( 'Unsubscribed', 'automatorwp' ),
54 'bounced' => __( 'Bounced', 'automatorwp' ),
55 'complained' => __( 'Complained', 'automatorwp' ),
56 ),
57 'default' => 'any'
58 ),
59 )
60 ),
61 'times' => automatorwp_utilities_times_option(),
62 ),
63 'tags' => array_merge(
64 automatorwp_fluentcrm_contact_tags(),
65 automatorwp_utilities_times_tag()
66 )
67 ) );
68
69 }
70
71 /**
72 * Trigger listener
73 *
74 * @since 1.0.0
75 *
76 * @param \FluentCrm\App\Models\Subscriber $subscriber
77 * @param string $old_status
78 */
79 public function listener( $subscriber, $old_status ) {
80
81 $user_id = automatorwp_fluentcrm_get_subscriber_user_id( $subscriber );
82
83 // Make sure subscriber has a user ID assigned
84 if ( $user_id === 0 ) {
85 return;
86 }
87
88 // Trigger the status change
89 automatorwp_trigger_event( array(
90 'trigger' => $this->trigger,
91 'user_id' => $user_id,
92 'status' => $subscriber->status,
93 'subscriber_email' => $subscriber->email,
94 ) );
95
96 }
97
98 /**
99 * User deserves check
100 *
101 * @since 1.0.0
102 *
103 * @param bool $deserves_trigger True if user deserves trigger, false otherwise
104 * @param stdClass $trigger The trigger object
105 * @param int $user_id The user ID
106 * @param array $event Event information
107 * @param array $trigger_options The trigger's stored options
108 * @param stdClass $automation The trigger's automation object
109 *
110 * @return bool True if user deserves trigger, false otherwise
111 */
112 public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
113
114 // Don't deserve if status is not received
115 if( ! isset( $event['status'] ) ) {
116 return false;
117 }
118
119 // Don't deserve if post doesn't match with the trigger option
120 if( $trigger_options['status'] !== 'any' && $trigger_options['status'] !== $event['status'] ) {
121 return false;
122 }
123
124 return $deserves_trigger;
125
126 }
127
128 /**
129 * Register the required hooks
130 *
131 * @since 1.0.0
132 */
133 public function hooks() {
134
135 // Log meta data
136 add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
137
138 parent::hooks();
139 }
140
141 /**
142 * Trigger custom log meta
143 *
144 * @since 1.0.0
145 *
146 * @param array $log_meta Log meta data
147 * @param stdClass $trigger The trigger object
148 * @param int $user_id The user ID
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, $user_id, $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['subscriber_email'] = ( isset( $event['subscriber_email'] ) ? $event['subscriber_email'] : '' );
163
164 return $log_meta;
165
166 }
167
168 }
169
170 new AutomatorWP_FluentCRM_Status_Change();