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 | integrations/zoom/includes/admin.php +209 -0 5.7.8 → 6.0.3 View file →
@@ -1,0 +1,209 @@
1 +<?php
2 +/**
3 + * Admin
4 + *
5 + * @package AutomatorWP\Integrations\Zoom\Admin
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 +/**
13 + * Shortcut function to get plugin options
14 + *
15 + * @since 1.0.0
16 + *
17 + * @param string $option_name
18 + * @param bool $default
19 + *
20 + * @return mixed
21 + */
22 +function automatorwp_zoom_get_option( $option_name, $default = false ) {
23 +
24 + $prefix = 'automatorwp_zoom_';
25 +
26 + return automatorwp_get_option( $prefix . $option_name, $default );
27 +}
28 +
29 +/**
30 + * Register plugin settings sections
31 + *
32 + * @since 1.0.0
33 + *
34 + * @return array
35 + */
36 +function automatorwp_zoom_settings_sections( $automatorwp_settings_sections ) {
37 +
38 + $automatorwp_settings_sections['zoom'] = array(
39 + 'title' => __( 'Zoom', 'automatorwp' ),
40 + 'icon' => 'dashicons-video-alt2',
41 + );
42 +
43 + return $automatorwp_settings_sections;
44 +
45 +}
46 +add_filter( 'automatorwp_settings_sections', 'automatorwp_zoom_settings_sections' );
47 +
48 +/**
49 + * Register plugin settings meta boxes
50 + *
51 + * @since 1.0.0
52 + *
53 + * @return array
54 + */
55 +function automatorwp_zoom_settings_meta_boxes( $meta_boxes ) {
56 +
57 + $prefix = 'automatorwp_zoom_';
58 +
59 + $meta_boxes['automatorwp-zoom-meetings-settings'] = array(
60 + 'title' => automatorwp_dashicon( 'groups' ) . __( 'Zoom Meetings', 'automatorwp' ),
61 + 'fields' => apply_filters( 'automatorwp_zoom_meetings_settings_fields', array(
62 + $prefix . 'meetings_client_id' => array(
63 + 'name' => __( 'Client ID:', 'automatorwp' ),
64 + 'desc' => __( 'Your Zoom app client ID.', 'automatorwp' ),
65 + 'type' => 'text',
66 + ),
67 + $prefix . 'meetings_client_secret' => array(
68 + 'name' => __( 'Client Secret:', 'automatorwp' ),
69 + 'desc' => __( 'Your Zoom app client secret.', 'automatorwp' ),
70 + 'type' => 'text',
71 + ),
72 + $prefix . 'meetings_redirect_url' => array(
73 + 'type' => 'text',
74 + 'render_row_cb' => 'automatorwp_zoom_redirect_url_display_cb',
75 + ),
76 + $prefix . 'meetings_authorize' => array(
77 + 'type' => 'text',
78 + 'render_row_cb' => 'automatorwp_zoom_authorize_display_cb',
79 + ),
80 + ) ),
81 + );
82 +
83 + return $meta_boxes;
84 +
85 +}
86 +add_filter( "automatorwp_settings_zoom_meta_boxes", 'automatorwp_zoom_settings_meta_boxes' );
87 +
88 +/**
89 + * Display callback for the authorize setting
90 + *
91 + * @since 1.0.0
92 + *
93 + * @param array $field_args Array of field arguments.
94 + * @param CMB2_Field $field The field object
95 + */
96 +function automatorwp_zoom_redirect_url_display_cb( $field_args, $field ) {
97 + $admin_url = str_replace( 'http://', 'https://', get_admin_url() ) . 'admin.php?page=automatorwp_settings&tab=opt-tab-zoom';
98 +
99 + ?>
100 + <div class="cmb-row cmb-type-custom cmb2-id-automatorwp-zoom-redirect-url table-layout" data-fieldtype="custom">
101 + <div class="cmb-th">
102 + <label><?php echo __( 'Redirect and Whitelist URL:', 'automatorwp' ); ?></label>
103 + </div>
104 + <div class="cmb-td">
105 + <input type="text" class="regular-text" value="<?php echo $admin_url; ?>" readonly>
106 + <p class="cmb2-metabox-description"><?php echo __( 'Copy this URL and place it on your Zoom app redirect and whitelist URL fields.', 'automatorwp' ); ?></p>
107 + </div>
108 + </div>
109 + <?php
110 +}
111 +
112 +/**
113 + * Display callback for the authorize setting
114 + *
115 + * @since 1.0.0
116 + *
117 + * @param array $field_args Array of field arguments.
118 + * @param CMB2_Field $field The field object
119 + */
120 +function automatorwp_zoom_authorize_display_cb( $field_args, $field ) {
121 +
122 + $field_id = $field_args['id'];
123 + $platform = str_replace( 'automatorwp_zoom_', '', str_replace( '_authorize', '', $field_id ) );
124 + $client_id = automatorwp_zoom_get_option( $platform . '_client_id', '' );
125 + $client_secret = automatorwp_zoom_get_option( $platform . '_client_secret', '' );
126 + $auth = get_option( 'automatorwp_zoom_' . $platform . '_auth' );
127 +
128 + ?>
129 + <div class="cmb-row cmb-type-custom cmb2-id-automatorwp-zoom-authorize table-layout" data-fieldtype="custom">
130 + <div class="cmb-th">
131 + <label><?php echo __( 'Connect with Zoom:', 'automatorwp' ); ?></label>
132 + </div>
133 + <div class="cmb-td">
134 + <a id="<?php echo $field_id; ?>" class="button button-primary" href="#"><?php echo __( 'Authorize', 'automatorwp' ); ?></a>
135 + <p class="cmb2-metabox-description"><?php echo __( 'Add you Zoom app client ID and secret fields and click on "Authorize" button to generate access keys for this site.', 'automatorwp' ); ?></p>
136 + <?php if ( is_array( $auth ) ) : ?>
137 + <div class="automatorwp-notice-success"><?php echo __( 'Site connected with Zoom successfully.', 'automatorwp' ); ?></div>
138 + <p class="automatorwp-zoom-access-token"><strong><?php echo __( 'Access token:', 'automatorwp' ); ?></strong> <input type="text" value="<?php echo $auth['access_token']; ?>" readonly></p>
139 + <p class="automatorwp-zoom-refresh-token"><strong><?php echo __( 'Refresh token:', 'automatorwp' ); ?></strong> <input type="text" value="<?php echo $auth['refresh_token']; ?>" readonly></p>
140 + <?php elseif( ! empty( $client_id ) && ! empty( $client_secret ) ) : ?>
141 + <div class="automatorwp-notice-error"><?php echo __( 'Site not connected with Zoom.', 'automatorwp' ); ?></div>
142 + <?php endif; ?>
143 + </div>
144 + </div>
145 + <?php
146 +}
147 +
148 +/**
149 + * Check if authorization process has been completed
150 + *
151 + * @since 1.0.0
152 + */
153 +function automatorwp_zoom_maybe_authorize_complete() {
154 +
155 + if( isset( $_GET['code'] )
156 + && isset( $_GET['state'] )
157 + && isset( $_GET['page'] ) && $_GET['page'] == 'automatorwp_settings'
158 + && isset( $_GET['tab'] ) && $_GET['tab'] == 'opt-tab-zoom' ) {
159 +
160 + $platform = str_replace( 'automatorwp_zoom_', '', $_GET['state'] );
161 + $client_id = automatorwp_zoom_get_option( $platform . '_client_id', '' );
162 + $client_secret = automatorwp_zoom_get_option( $platform . '_client_secret', '' );
163 +
164 + $params = array(
165 + 'headers' => array(
166 + 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8',
167 + 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $client_secret ),
168 + 'Accept' => 'application/json',
169 + ),
170 + 'body' => array(
171 + 'grant_type' => 'authorization_code',
172 + 'redirect_uri' => str_replace( 'http://', 'https://', get_admin_url() ) . 'admin.php?page=automatorwp_settings&tab=opt-tab-zoom',
173 + 'code' => $_GET['code']
174 + )
175 + );
176 +
177 + $response = wp_remote_post( 'https://zoom.us/oauth/token', $params );
178 +
179 + // Bail if can't contact with the server
180 + if ( is_wp_error( $response ) ) {
181 + return;
182 + }
183 +
184 + $body = json_decode( wp_remote_retrieve_body( $response ) );
185 +
186 + // Bail on receive an error
187 + if( isset( $body->error ) ) {
188 + return;
189 + }
190 +
191 + $auth = array(
192 + 'access_token' => $body->access_token,
193 + 'refresh_token' => $body->refresh_token,
194 + 'token_type' => $body->token_type,
195 + 'expires_in' => $body->expires_in,
196 + 'scope' => $body->scope,
197 + );
198 +
199 + // Update the access and refresh tokens
200 + update_option( 'automatorwp_zoom_' . $platform . '_auth', $auth );
201 +
202 + // Redirect to settings again
203 + wp_redirect( get_admin_url() . 'admin.php?page=automatorwp_settings&tab=opt-tab-zoom' );
204 + exit;
205 +
206 + }
207 +
208 +}
209 +add_action( 'admin_init', 'automatorwp_zoom_maybe_authorize_complete' );