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/zoom/includes/actions/add-user-meeting.php +396 -0 5.7.4 → 6.0.4 View file →
@@ -1,0 +1,396 @@
1 +<?php
2 +/**
3 + * Add User Meeting
4 + *
5 + * @package AutomatorWP\Integrations\Zoom\Actions\Add_User_Meeting
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_Zoom_Add_User_Meeting extends AutomatorWP_Integration_Action {
13 +
14 + public $integration = 'zoom';
15 + public $action = 'zoom_add_user_meeting';
16 +
17 + /**
18 + * Registrant First Name
19 + *
20 + * @since 1.0.0
21 + *
22 + * @var string $registrant_first_name
23 + */
24 + public $registrant_first_name = '';
25 +
26 + /**
27 + * Registrant Last Name
28 + *
29 + * @since 1.0.0
30 + *
31 + * @var string $registrant_last_name
32 + */
33 + public $registrant_last_name = '';
34 +
35 + /**
36 + * Registrant Email
37 + *
38 + * @since 1.0.0
39 + *
40 + * @var string $registrant_email
41 + */
42 + public $registrant_email = '';
43 +
44 + /**
45 + * Registrant Status
46 + *
47 + * @since 1.0.0
48 + *
49 + * @var string $registrant_status
50 + */
51 + public $registrant_status = '';
52 +
53 + /**
54 + * Meeting ID
55 + *
56 + * @since 1.0.0
57 + *
58 + * @var string $meeting_id
59 + */
60 + public $meeting_id = '';
61 +
62 + /**
63 + * Registrant ID
64 + *
65 + * @since 1.0.0
66 + *
67 + * @var string $registrant_id
68 + */
69 + public $registrant_id = '';
70 +
71 + /**
72 + * Join URL
73 + *
74 + * @since 1.0.0
75 + *
76 + * @var string $join_url
77 + */
78 + public $join_url = '';
79 +
80 + /**
81 + * Store the action result
82 + *
83 + * @since 1.0.0
84 + *
85 + * @var string $result
86 + */
87 + public $result = '';
88 +
89 + /**
90 + * Register the trigger
91 + *
92 + * @since 1.0.0
93 + */
94 + public function register() {
95 +
96 + automatorwp_register_action( $this->action, array(
97 + 'integration' => $this->integration,
98 + 'label' => __( 'Add user to meeting', 'automatorwp' ),
99 + 'select_option' => __( 'Add user to <strong>meeting</strong>', 'automatorwp' ),
100 + /* translators: %1$s: Meeting. */
101 + 'edit_label' => sprintf( __( 'Add user to %1$s', 'automatorwp' ), '{meeting}' ),
102 + /* translators: %1$s: Meeting. */
103 + 'log_label' => sprintf( __( 'Add user to %1$s', 'automatorwp' ), '{meeting}' ),
104 + 'options' => array(
105 + 'meeting' => array(
106 + 'from' => 'meeting',
107 + 'default' => __( 'meeting', 'automatorwp' ),
108 + 'fields' => array(
109 + 'meeting' => automatorwp_utilities_ajax_selector_field( array(
110 + 'field' => 'meeting',
111 + 'option_default' => __( 'meeting', 'automatorwp' ),
112 + 'placeholder' => __( 'Select a meeting', 'automatorwp' ),
113 + 'name' => __( 'Meeting:', 'automatorwp' ),
114 + 'action_cb' => 'automatorwp_zoom_get_meetings',
115 + 'options_cb' => 'automatorwp_zoom_options_cb_meetings',
116 + 'default' => ''
117 + ) ),
118 + 'registrant_status' => array(
119 + 'name' => __( 'Status:', 'automatorwp' ),
120 + 'desc' => __( 'The registrant status.', 'automatorwp' ),
121 + 'type' => 'select',
122 + 'options' => array(
123 + 'approved' => __( 'Approved', 'automatorwp' ),
124 + 'denied' => __( 'Denied', 'automatorwp' ),
125 + 'pending' => __( 'Pending', 'automatorwp' ),
126 + ),
127 + ),
128 + )
129 + )
130 + ),
131 + ) );
132 +
133 + }
134 +
135 + /**
136 + * Action execution function
137 + *
138 + * @since 1.0.0
139 + *
140 + * @param stdClass $action The action object
141 + * @param int $user_id The user ID
142 + * @param array $action_options The action's stored options (with tags already passed)
143 + * @param stdClass $automation The action's automation object
144 + */
145 + public function execute( $action, $user_id, $action_options, $automation ) {
146 +
147 + $prefix = '_automatorwp_zoom_meetings_';
148 +
149 + $this->registrant_first_name = '';
150 + $this->registrant_last_name = '';
151 + $this->registrant_email = '';
152 + $this->registrant_status = '';
153 + $this->meeting_id = '';
154 + $this->registrant_id = '';
155 + $this->join_url = '';
156 + $this->result = '';
157 +
158 + // Shorthand
159 + $meeting_id = $action_options['meeting'];
160 +
161 + // Bail if empty meeting to assign
162 + if( empty( $meeting_id ) ) {
163 + $this->result = __( 'Could not add registrant to meeting, missing meeting', 'automatorwp' );
164 + return;
165 + }
166 +
167 + $params = automatorwp_zoom_get_request_parameters( 'meetings' );
168 +
169 + // Bail if the authorization has not been setup from settings
170 + if( $params === false ) {
171 + $this->result = __( 'Could not add registrant to meeting, Zoom authentication failed', 'automatorwp' );
172 + return;
173 + }
174 +
175 + $user = get_userdata( $user_id );
176 +
177 + $this->registrant_first_name = $user->first_name;
178 + $this->registrant_last_name = $user->last_name;
179 + $this->registrant_email = $user->user_email;
180 + $this->registrant_status = $action_options['registrant_status'];
181 +
182 + if( $this->registrant_status === '' ) {
183 + $this->registrant_status = 'approved';
184 + }
185 +
186 + // Setup the request parameters
187 + $body_params = array(
188 + 'first_name' => $this->registrant_first_name,
189 + 'last_name' => $this->registrant_last_name,
190 + 'email' => $this->registrant_email,
191 + 'status' => $this->registrant_status,
192 + );
193 +
194 + // Force auto approval
195 + if( $this->registrant_status === 'approved' ) {
196 + $body_params['auto_approve'] = true;
197 + }
198 +
199 + $params['body'] = json_encode( $body_params );
200 +
201 + // Setup the URL
202 + $url = 'https://api.zoom.us/v2/meetings/' . $meeting_id . '/registrants';
203 +
204 + // Execute the request
205 + $response = wp_remote_post( $url, $params );
206 +
207 + if ( is_wp_error( $response ) ) {
208 + $this->result = sprintf( __( 'Could not add registrant to meeting, error received: %1$s', 'automatorwp' ), $response->get_error_message() );
209 + return;
210 + }
211 +
212 + $response_code = wp_remote_retrieve_response_code( $response );
213 + $body = json_decode( $response['body'], true, 512, JSON_BIGINT_AS_STRING );
214 +
215 + if ( $response_code === 201 ) {
216 +
217 + if ( isset( $body['join_url'] ) ) {
218 +
219 + // Update user metas with information from this meeting
220 + update_user_meta( $user_id, $prefix . $meeting_id . '_id', $body['id'] );
221 + update_user_meta( $user_id, $prefix . $meeting_id . '_registrant_id', $body['registrant_id'] );
222 + update_user_meta( $user_id, $prefix . $meeting_id . '_join_url', $body['join_url'] );
223 +
224 + // Update trigger vars with information from this meeting
225 + $this->meeting_id = $body['id'];
226 + $this->registrant_id = $body['registrant_id'];
227 + $this->join_url = $body['join_url'];
228 + $this->result = __( 'Registrant successfully registered', 'automatorwp' );
229 + }
230 + } else {
231 + $this->result = sprintf( __( 'Could not add registrant to meeting, error received: %1$s', 'automatorwp' ), $body['message'] );
232 + }
233 +
234 + }
235 +
236 + /**
237 + * Register required hooks
238 + *
239 + * @since 1.0.0
240 + */
241 + public function hooks() {
242 +
243 + // Configuration notice
244 + add_filter( 'automatorwp_automation_ui_after_item_label', array( $this, 'configuration_notice' ), 10, 2 );
245 +
246 + // Log meta data
247 + add_filter( 'automatorwp_user_completed_action_log_meta', array( $this, 'log_meta' ), 10, 5 );
248 +
249 + // Log fields
250 + add_filter( 'automatorwp_log_fields', array( $this, 'log_fields' ), 10, 5 );
251 +
252 + parent::hooks();
253 + }
254 +
255 + /**
256 + * Configuration notice
257 + *
258 + * @since 1.0.0
259 + *
260 + * @param stdClass $object The trigger/action object
261 + * @param string $item_type The object type (trigger|action)
262 + */
263 + public function configuration_notice( $object, $item_type ) {
264 +
265 + // Bail if action type don't match this action
266 + if( $item_type !== 'action' ) {
267 + return;
268 + }
269 +
270 + if( $object->type !== $this->action ) {
271 + return;
272 + }
273 +
274 + $params = automatorwp_zoom_get_request_parameters( 'meetings' );
275 +
276 + // Warn user if the authorization has not been setup from settings
277 + if( $params === false ) : ?>
278 + <div class="automatorwp-notice-warning" style="margin-top: 10px; margin-bottom: 0;">
279 + <?php echo sprintf(
280 + __( 'You need to configure the <a href="%s" target="_blank">Zoom Meetings settings</a> to get this action to work.', 'automatorwp' ),
281 + get_admin_url() . 'admin.php?page=automatorwp_settings&tab=opt-tab-zoom'
282 + ); ?>
283 + <?php echo sprintf(
284 + __( '<a href="%s" target="_blank">Documentation</a>', 'automatorwp' ),
285 + 'https://automatorwp.com/docs/zoom/'
286 + ); ?>
287 + </div>
288 + <?php endif;
289 +
290 + }
291 +
292 + /**
293 + * Action custom log meta
294 + *
295 + * @since 1.0.0
296 + *
297 + * @param array $log_meta Log meta data
298 + * @param stdClass $action The action object
299 + * @param int $user_id The user ID
300 + * @param array $action_options The action's stored options (with tags already passed)
301 + * @param stdClass $automation The action's automation object
302 + *
303 + * @return array
304 + */
305 + public function log_meta( $log_meta, $action, $user_id, $action_options, $automation ) {
306 +
307 + // Bail if action type don't match this action
308 + if( $action->type !== $this->action ) {
309 + return $log_meta;
310 + }
311 +
312 + // Store the action's result
313 + $log_meta['registrant_first_name'] = $this->registrant_first_name;
314 + $log_meta['registrant_last_name'] = $this->registrant_last_name;
315 + $log_meta['registrant_email'] = $this->registrant_email;
316 + $log_meta['registrant_status'] = $this->registrant_status;
317 + $log_meta['meeting_id'] = $this->meeting_id;
318 + $log_meta['registrant_id'] = $this->registrant_id;
319 + $log_meta['join_url'] = $this->join_url;
320 + $log_meta['result'] = $this->result;
321 +
322 + return $log_meta;
323 + }
324 +
325 + /**
326 + * Action custom log fields
327 + *
328 + * @since 1.0.0
329 + *
330 + * @param array $log_fields The log fields
331 + * @param stdClass $log The log object
332 + * @param stdClass $object The trigger/action/automation object attached to the log
333 + *
334 + * @return array
335 + */
336 + public function log_fields( $log_fields, $log, $object ) {
337 +
338 + // Bail if log is not assigned to an action
339 + if( $log->type !== 'action' ) {
340 + return $log_fields;
341 + }
342 +
343 + // Bail if action type don't match this action
344 + if( $object->type !== $this->action ) {
345 + return $log_fields;
346 + }
347 +
348 + $log_fields['registrant_first_name'] = array(
349 + 'name' => __( 'Registrant First Name:', 'automatorwp' ),
350 + 'type' => 'text',
351 + );
352 +
353 + $log_fields['registrant_last_name'] = array(
354 + 'name' => __( 'Registrant Last Name:', 'automatorwp' ),
355 + 'type' => 'text',
356 + );
357 +
358 + $log_fields['registrant_email'] = array(
359 + 'name' => __( 'Registrant Email:', 'automatorwp' ),
360 + 'type' => 'text',
361 + );
362 +
363 + $log_fields['registrant_status'] = array(
364 + 'name' => __( 'Registrant Status:', 'automatorwp' ),
365 + 'type' => 'text',
366 + );
367 +
368 + $log_fields['meeting_id'] = array(
369 + 'name' => __( 'Meeting ID:', 'automatorwp' ),
370 + 'desc' => __( 'Unique identifier for the meeting.', 'automatorwp' ),
371 + 'type' => 'text',
372 + );
373 +
374 + $log_fields['registrant_id'] = array(
375 + 'name' => __( 'Registrant ID:', 'automatorwp' ),
376 + 'desc' => __( 'Unique identifier assigned to the registrant.', 'automatorwp' ),
377 + 'type' => 'text',
378 + );
379 +
380 + $log_fields['join_url'] = array(
381 + 'name' => __( 'Join URL:', 'automatorwp' ),
382 + 'desc' => __( 'Unique URL for this registrant to join the meeting.', 'automatorwp' ),
383 + 'type' => 'text',
384 + );
385 +
386 + $log_fields['result'] = array(
387 + 'name' => __( 'Result:', 'automatorwp' ),
388 + 'type' => 'text',
389 + );
390 +
391 + return $log_fields;
392 + }
393 +
394 +}
395 +
396 +new AutomatorWP_Zoom_Add_User_Meeting();