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 | classes/integration-trigger.php +250 -0 5.7.9.1 → 6.0.3 View file →
@@ -1,0 +1,250 @@
1 +<?php
2 +/**
3 + * Integration Trigger
4 + *
5 + * @package AutomatorWP\Classes\Integration_Trigger
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_Integration_Trigger {
13 +
14 + /**
15 + * Integration
16 + *
17 + * @since 1.0.0
18 + *
19 + * @var string $integration
20 + */
21 + public $integration = '';
22 +
23 + /**
24 + * Trigger
25 + *
26 + * @since 1.0.0
27 + *
28 + * @var string $trigger
29 + */
30 + public $trigger = '';
31 +
32 + /**
33 + * Filter result
34 + *
35 + * @since 1.0.0
36 + *
37 + * @var string $result
38 + */
39 + public $result = '';
40 +
41 + public function __construct() {
42 +
43 + $this->hooks();
44 +
45 + }
46 +
47 + /**
48 + * Register the required hooks
49 + *
50 + * @since 1.0.0
51 + */
52 + public function hooks() {
53 +
54 + if ( ! did_action( 'automatorwp_init' ) ) {
55 + // Default hook to register
56 + add_action('automatorwp_init', array( $this, 'register' ) );
57 + add_action('init', array( $this, 'register_labels' ) );
58 + } else {
59 + // Hook for triggers registered from the theme's functions
60 + add_action( 'after_setup_theme', array( $this, 'register' ) );
61 + }
62 +
63 + if ( ! did_action( 'automatorwp_post_init' ) ) {
64 + // Default hook to register listener hook
65 + add_action('automatorwp_post_init', array( $this, 'register_listener_hook' ) );
66 + } else {
67 + // Hook for triggers registered from the theme's functions
68 + add_action( 'after_setup_theme', array( $this, 'register_listener_hook' ) );
69 + }
70 +
71 + // Guest deserves trigger hook
72 + add_filter( 'automatorwp_anonymous_deserves_trigger', array( $this, 'maybe_anonymous_deserves_trigger' ), 10, 5 );
73 +
74 + // User deserves trigger hook
75 + add_filter( 'automatorwp_user_deserves_trigger', array( $this, 'maybe_user_deserves_trigger' ), 10, 6 );
76 + }
77 +
78 + /**
79 + * Register the trigger
80 + *
81 + * @since 1.0.0
82 + */
83 + public function register() {
84 + // Override
85 + }
86 +
87 + public function register_labels() {
88 + $this->register();
89 + }
90 +
91 + /**
92 + * Register the trigger listener hook
93 + *
94 + * @since 1.0.0
95 + */
96 + public function register_listener_hook() {
97 +
98 + // Bail if this trigger is not in use
99 + if( ! automatorwp_is_trigger_in_use( $this->trigger ) ) {
100 + return;
101 + }
102 +
103 + // Get the trigger args
104 + $trigger = automatorwp_get_trigger( $this->trigger );
105 +
106 + // Bail if trigger not registered
107 + if( ! $trigger ) {
108 + return;
109 + }
110 +
111 + // Bail if not action or filter is provided
112 + if( empty( $trigger['action'] ) && empty( $trigger['filter'] ) ) {
113 + return;
114 + }
115 +
116 + // Bail if not callback function is provided
117 + if( empty( $trigger['function'] ) ) {
118 + return;
119 + }
120 +
121 + // Register the trigger hook (action or filter)
122 + if( ! empty( $trigger['action'] ) ) {
123 +
124 + // Ensure that is an array
125 + if( ! is_array( $trigger['action'] ) ) {
126 + $trigger['action'] = array( $trigger['action'] );
127 + }
128 +
129 + // Add all the actions
130 + foreach( $trigger['action'] as $action ) {
131 + add_action( $action, $trigger['function'], $trigger['priority'], $trigger['accepted_args'] );
132 + }
133 +
134 + } else if( ! empty( $trigger['filter'] ) ) {
135 +
136 + // Ensure that is an array
137 + if( ! is_array( $trigger['filter'] ) ) {
138 + $trigger['filter'] = array( $trigger['filter'] );
139 + }
140 +
141 + // Add all triggers
142 + foreach( $trigger['filter'] as $filter ) {
143 + add_filter( $filter, $trigger['function'], $trigger['priority'], $trigger['accepted_args'] );
144 + }
145 +
146 + }
147 +
148 + }
149 +
150 + /**
151 + * Checks if maybe should call or not to the user_deserves_trigger() function
152 + *
153 + * @since 1.0.0
154 + *
155 + * @param bool $deserves_trigger True if user deserves trigger, false otherwise
156 + * @param stdClass $trigger The trigger object
157 + * @param int $user_id The user ID
158 + * @param array $event Event information
159 + * @param array $trigger_options The trigger's stored options
160 + * @param stdClass $automation The trigger's automation object
161 + *
162 + * @return bool True if user deserves trigger, false otherwise
163 + */
164 + public function maybe_user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
165 +
166 + // Bail if trigger has not be deserved
167 + if( ! $deserves_trigger ) {
168 + return $deserves_trigger;
169 + }
170 +
171 + // Bail if trigger type don't match this trigger
172 + if( $trigger->type !== $this->trigger ) {
173 + return $deserves_trigger;
174 + }
175 +
176 + return $this->user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation );
177 +
178 + }
179 +
180 + /**
181 + * User deserves check
182 + *
183 + * @since 1.0.0
184 + *
185 + * @param bool $deserves_trigger True if user deserves trigger, false otherwise
186 + * @param stdClass $trigger The trigger object
187 + * @param int $user_id The user ID
188 + * @param array $event Event information
189 + * @param array $trigger_options The trigger's stored options
190 + * @param stdClass $automation The trigger's automation object
191 + *
192 + * @return bool True if user deserves trigger, false otherwise
193 + */
194 + public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
195 +
196 + // Override
197 + return $deserves_trigger;
198 +
199 + }
200 +
201 + /**
202 + * Checks if maybe should call or not to the anonymous_deserves_trigger() function
203 + *
204 + * @since 1.0.0
205 + *
206 + * @param bool $deserves_trigger True if anonymous deserves trigger, false otherwise
207 + * @param stdClass $trigger The trigger object
208 + * @param array $event Event information
209 + * @param array $trigger_options The trigger's stored options
210 + * @param stdClass $automation The trigger's automation object
211 + *
212 + * @return bool True if anonymous deserves trigger, false otherwise
213 + */
214 + public function maybe_anonymous_deserves_trigger( $deserves_trigger, $trigger, $event, $trigger_options, $automation ) {
215 +
216 + // Bail if event has not be deserved
217 + if( ! $deserves_trigger ) {
218 + return $deserves_trigger;
219 + }
220 +
221 + // Bail if trigger type don't match this trigger
222 + if( $trigger->type !== $this->trigger ) {
223 + return $deserves_trigger;
224 + }
225 +
226 + return $this->anonymous_deserves_trigger( $deserves_trigger, $trigger, $event, $trigger_options, $automation );
227 +
228 + }
229 +
230 + /**
231 + * Guest deserves check
232 + *
233 + * @since 1.0.0
234 + *
235 + * @param bool $deserves_trigger True if anonymous deserves trigger, false otherwise
236 + * @param stdClass $trigger The trigger object
237 + * @param array $event Event information
238 + * @param array $trigger_options The trigger's stored options
239 + * @param stdClass $automation The trigger's automation object
240 + *
241 + * @return bool True if anonymous deserves trigger, false otherwise
242 + */
243 + public function anonymous_deserves_trigger( $deserves_trigger, $trigger, $event, $trigger_options, $automation ) {
244 +
245 + // Override
246 + return $deserves_trigger;
247 +
248 + }
249 +
250 +}