PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.4
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.4
6.0.4 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 All 35 releases
automatorwp / integrations / autonami / includes / triggers / anonymous-contact-added-list.php

anonymous-contact-added-list.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.4, at integrations/autonami/includes/triggers/anonymous-contact-added-list.php

168 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 Contact Added List
4 *
5 * @package AutomatorWP\Integrations\Autonami\Triggers\Anonymous_Contact_Added_List
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_Autonami_Anonymous_Contact_Added_List extends AutomatorWP_Integration_Trigger {
13
14 public $integration = 'autonami';
15 public $trigger = 'autonami_anonymous_contact_added_list';
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 is added to list', 'automatorwp' ),
28 'select_option' => __( 'Contact is added to <strong>list</strong>', 'automatorwp' ),
29 /* translators: %1$s: List. %2$s: Number of times. */
30 'edit_label' => sprintf( __( 'Contact is added to %1$s %2$s time(s)', 'automatorwp' ), '{list}', '{times}' ),
31 /* translators: %1$s: List. */
32 'log_label' => sprintf( __( 'Contact is added to %1$s', 'automatorwp' ), '{list}' ),
33 'action' => 'bwfan_contact_added_to_lists',
34 'function' => array( $this, 'listener' ),
35 'priority' => 10,
36 'accepted_args' => 2,
37 'options' => array(
38 'list' => automatorwp_utilities_ajax_selector_option( array(
39 'field' => 'list',
40 'name' => __( 'List:', 'automatorwp' ),
41 'option_none_value' => 'any',
42 'option_none_label' => __( 'any list', 'automatorwp' ),
43 'action_cb' => 'automatorwp_autonami_get_lists',
44 'options_cb' => 'automatorwp_autonami_options_cb_list',
45 'default' => 'any'
46 ) ),
47 'times' => automatorwp_utilities_times_option(),
48 ),
49 'tags' => array_merge(
50 automatorwp_autonami_list_tags(),
51 automatorwp_autonami_email_tags(),
52 automatorwp_utilities_times_tag()
53 )
54 ) );
55
56 }
57
58 /**
59 * Trigger listener
60 *
61 * @since 1.0.0
62 *
63 * @param BWFCRM_Lists $lists
64 * @param BWFCRM_Contact $contact
65 */
66 public function listener( $lists, $contact ) {
67
68 // Get contact email
69 $email = $contact->contact->get_email();
70
71 if ( !is_array ( $lists ) ){
72
73 // Trigger the user added to list
74 automatorwp_trigger_event( array(
75 'trigger' => $this->trigger,
76 'list_id' => $lists->get_id(),
77 'contact_email' => $email,
78 ) );
79
80 } else {
81
82 foreach ( $lists as $list ){
83
84 // Trigger the user added to list
85 automatorwp_trigger_event( array(
86 'trigger' => $this->trigger,
87 'list_id' => $list->get_id(),
88 'contact_email' => $email,
89 ) );
90
91 }
92
93 }
94
95 }
96
97 /**
98 * Anonymous deserves check
99 *
100 * @since 1.0.0
101 *
102 * @param bool $deserves_trigger True if user 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 user deserves trigger, false otherwise
109 */
110 public function anonymous_deserves_trigger( $deserves_trigger, $trigger, $event, $trigger_options, $automation ) {
111
112 // Don't deserve if list is not received
113 if( ! isset( $event['list_id'] ) ) {
114 return false;
115 }
116
117 // Don't deserve if list doesn't match with the trigger option
118 if( $trigger_options['list'] !== 'any' && absint( $trigger_options['list'] ) !== absint( $event['list_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 parent::hooks();
137 }
138
139 /**
140 * Trigger custom log meta
141 *
142 * @since 1.0.0
143 *
144 * @param array $log_meta Log meta data
145 * @param stdClass $trigger The trigger object
146 * @param array $event Event information
147 * @param array $trigger_options The trigger's stored options
148 * @param stdClass $automation The trigger's automation object
149 *
150 * @return array
151 */
152 function log_meta( $log_meta, $trigger, $event, $trigger_options, $automation ) {
153
154 // Bail if action type don't match this action
155 if( $trigger->type !== $this->trigger ) {
156 return $log_meta;
157 }
158
159 $log_meta['contact_email'] = ( isset( $event['contact_email'] ) ? $event['contact_email'] : '' );
160 $log_meta['list_id'] = ( isset( $event['list_id'] ) ? $event['list_id'] : '' );
161
162 return $log_meta;
163
164 }
165
166 }
167
168 new AutomatorWP_Autonami_Anonymous_Contact_Added_List();