PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 5.8.6
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v5.8.6
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 / anonymous-status-change.php

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

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