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 / zoom / includes / ajax-functions.php

ajax-functions.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 5.8.6, at integrations/zoom/includes/ajax-functions.php

102 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Ajax Functions
4 *
5 * @package AutomatorWP\Zoom\Ajax_Functions
6 * @since 1.0.0
7 */
8 // Exit if accessed directly
9 if( !defined( 'ABSPATH' ) ) exit;
10
11 /**
12 * AJAX handler for the authorize action
13 *
14 * @since 1.0.0
15 */
16 function automatorwp_zoom_ajax_authorize() {
17 // Security check
18 check_ajax_referer( 'automatorwp_admin', 'nonce' );
19
20 // Permissions check
21 if( ! current_user_can( automatorwp_get_manager_capability() ) ) {
22 wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'automatorwp' ) );
23 }
24
25 $prefix = 'automatorwp_zoom_';
26
27 $client_id = sanitize_text_field( $_POST['client_id'] );
28 $client_secret = sanitize_text_field( $_POST['client_secret'] );
29 $platform = sanitize_text_field( $_POST['platform'] );
30
31 // Check parameters given
32 if( empty( $client_id ) || empty( $client_secret ) ) {
33 wp_send_json_error( array( 'message' => __( 'All fields are required to connect with Zoom', 'automatorwp' ) ) );
34 }
35
36 $settings = get_option( 'automatorwp_settings' );
37
38 // Save client id and secret
39 $settings[$prefix . $platform . '_client_id'] = $client_id;
40 $settings[$prefix . $platform . '_client_secret'] = $client_secret;
41
42 // Update settings
43 update_option( 'automatorwp_settings', $settings );
44
45 $state = $prefix . $platform;
46 $admin_url = str_replace( 'http://', 'https://', get_admin_url() ) . 'admin.php?page=automatorwp_settings&tab=opt-tab-zoom';
47 $redirect_url = 'https://zoom.us/oauth/authorize?response_type=code&client_id=' . $client_id . '&state=' . urlencode( $state ) . '&redirect_uri=' . urlencode( $admin_url );
48
49 // Return the redirect URL
50 wp_send_json_success( array(
51 'message' => __( 'Zoom settings saved successfully, redirecting to Zoom...', 'automatorwp' ),
52 'redirect_url' => $redirect_url
53 ) );
54
55 }
56 add_action( 'wp_ajax_automatorwp_zoom_authorize', 'automatorwp_zoom_ajax_authorize' );
57
58 /**
59 * Ajax function for selecting meetings
60 *
61 * @since 1.0.0
62 */
63 function automatorwp_zoom_ajax_get_meetings() {
64 // Security check, forces to die if not security passed
65 check_ajax_referer( 'automatorwp_admin', 'nonce' );
66
67 // Permissions check
68 if( ! current_user_can( automatorwp_get_manager_capability() ) ) {
69 wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'automatorwp' ) );
70 }
71
72 global $wpdb;
73
74 // Pull back the search string
75 $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( $_REQUEST['q'] ) : '';
76
77 $meetings = automatorwp_zoom_get_meetings();
78
79 // Parse meetings results to match select2 results
80 foreach ( $meetings as $meeting ) {
81
82 if( ! empty( $search ) ) {
83 if( strpos( strtolower( $meeting['name'] ), strtolower( $search ) ) === false ) {
84 continue;
85 }
86 }
87
88 $results[] = array(
89 'id' => $meeting['id'],
90 'text' => $meeting['name']
91 );
92 }
93
94 // Prepend option none
95 $results = automatorwp_ajax_get_ajax_results_option_none( $results );
96
97 // Return our results
98 wp_send_json_success( $results );
99 die;
100
101 }
102 add_action( 'wp_ajax_automatorwp_zoom_get_meetings', 'automatorwp_zoom_ajax_get_meetings' );