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
← All changes | integrations/fluentcrm/includes/triggers/anonymous-list-added.php +155 -0 5.8.3 → 6.0.4 View file →
@@ -1,0 +1,155 @@
1 +<?php
2 +/**
3 + * Anonymous List Added
4 + *
5 + * @package AutomatorWP\Integrations\FluentCRM\Triggers\Anonymous_List_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_FluentCRM_Anonymous_List_Added extends AutomatorWP_Integration_Trigger {
13 +
14 + public $integration = 'fluentcrm';
15 + public $trigger = 'fluentcrm_anonymous_list_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 + 'anonymous' => true,
27 + 'label' => __( 'Contact gets added to list', 'automatorwp' ),
28 + 'select_option' => __( 'Contact gets added to <strong>list</strong>', 'automatorwp' ),
29 + /* translators: %1$s: List. %2$s: Number of times. */
30 + 'edit_label' => sprintf( __( 'Contact gets added to %1$s %2$s time(s)', 'automatorwp' ), '{list}', '{times}' ),
31 + /* translators: %1$s: List. */
32 + 'log_label' => sprintf( __( 'Contact gets added to %1$s', 'automatorwp' ), '{list}' ),
33 + 'action' => 'fluentcrm_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_fluentcrm_get_lists',
44 + 'options_cb' => 'automatorwp_fluentcrm_options_cb_list',
45 + 'default' => 'any'
46 + ) ),
47 + 'times' => automatorwp_utilities_times_option(),
48 + ),
49 + 'tags' => array_merge(
50 + automatorwp_fluentcrm_contact_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 $lists_ids
63 + * @param \FluentCrm\App\Models\Subscriber $subscriber
64 + */
65 + public function listener( $lists_ids, $subscriber ) {
66 +
67 + $user_id = automatorwp_fluentcrm_get_subscriber_user_id( $subscriber );
68 +
69 + // Make sure subscriber has not a user ID assigned
70 + if ( $user_id !== 0 ) {
71 + return;
72 + }
73 +
74 + foreach( $lists_ids as $list_id ) {
75 + // Trigger the list added
76 + automatorwp_trigger_event( array(
77 + 'trigger' => $this->trigger,
78 + 'list_id' => $list_id,
79 + 'subscriber_email' => $subscriber->email,
80 + ) );
81 + }
82 +
83 + }
84 +
85 + /**
86 + * Guest deserves check
87 + *
88 + * @since 1.0.0
89 + *
90 + * @param bool $deserves_trigger True if guest deserves trigger, false otherwise
91 + * @param stdClass $trigger The trigger object
92 + * @param array $event Event information
93 + * @param array $trigger_options The trigger's stored options
94 + * @param stdClass $automation The trigger's automation object
95 + *
96 + * @return bool True if guest deserves trigger, false otherwise
97 + */
98 + public function anonymous_deserves_trigger( $deserves_trigger, $trigger, $event, $trigger_options, $automation ) {
99 +
100 + // Don't deserve if post is not received
101 + if( ! isset( $event['list_id'] ) ) {
102 + return false;
103 + }
104 +
105 + // Don't deserve if post doesn't match with the trigger option
106 + if( $trigger_options['list'] !== 'any' && absint( $trigger_options['list'] ) !== absint( $event['list_id'] ) ) {
107 + return false;
108 + }
109 +
110 + return $deserves_trigger;
111 +
112 + }
113 +
114 + /**
115 + * Register the required hooks
116 + *
117 + * @since 1.0.0
118 + */
119 + public function hooks() {
120 +
121 + // Log meta data
122 + add_filter( 'automatorwp_anonymous_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 5 );
123 +
124 + parent::hooks();
125 + }
126 +
127 + /**
128 + * Trigger custom log meta
129 + *
130 + * @since 1.0.0
131 + *
132 + * @param array $log_meta Log meta data
133 + * @param stdClass $trigger The trigger object
134 + * @param array $event Event information
135 + * @param array $trigger_options The trigger's stored options
136 + * @param stdClass $automation The trigger's automation object
137 + *
138 + * @return array
139 + */
140 + function log_meta( $log_meta, $trigger, $event, $trigger_options, $automation ) {
141 +
142 + // Bail if action type don't match this action
143 + if( $trigger->type !== $this->trigger ) {
144 + return $log_meta;
145 + }
146 +
147 + $log_meta['subscriber_email'] = ( isset( $event['subscriber_email'] ) ? $event['subscriber_email'] : '' );
148 +
149 + return $log_meta;
150 +
151 + }
152 +
153 +}
154 +
155 +new AutomatorWP_FluentCRM_Anonymous_List_Added();