Skip to content

Commit 3afeb88

Browse files
committed
Use oauth url from the server side.
1 parent 1198ebb commit 3afeb88

File tree

3 files changed

+37
-39
lines changed

3 files changed

+37
-39
lines changed

includes/class-mailchimp-admin.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public function init() {
3232
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
3333
add_action( 'wp_ajax_mailchimp_sf_oauth_start', array( $this, 'start_oauth_process' ) );
3434
add_action( 'wp_ajax_mailchimp_sf_oauth_finish', array( $this, 'finish_oauth_process' ) );
35+
36+
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_page_scripts' ) );
3537
}
3638

3739

@@ -233,4 +235,36 @@ public function sanitize_data( $data ) {
233235
return is_scalar( $data ) ? sanitize_text_field( $data ) : $data;
234236
}
235237
}
238+
239+
/**
240+
* Enqueue scripts/styles for the Mailchimp admin page
241+
*
242+
* @param string $hook_suffix The current admin page.
243+
* @return void
244+
*/
245+
public function enqueue_admin_page_scripts( $hook_suffix ) {
246+
if ( 'toplevel_page_mailchimp_sf_options' !== $hook_suffix ) {
247+
return;
248+
}
249+
250+
wp_enqueue_style( 'mailchimp_sf_admin_css', MCSF_URL . 'css/admin.css', array( 'wp-jquery-ui-dialog' ), true );
251+
wp_enqueue_script( 'showMe', MCSF_URL . 'js/hidecss.js', array( 'jquery' ), MCSF_VER, true );
252+
wp_enqueue_script( 'mailchimp_sf_admin', MCSF_URL . 'js/admin.js', array( 'jquery', 'jquery-ui-dialog' ), MCSF_VER, true );
253+
254+
wp_localize_script(
255+
'mailchimp_sf_admin',
256+
'mailchimp_sf_admin_params',
257+
array(
258+
'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ),
259+
'oauth_url' => esc_url( $this->oauth_url ),
260+
'oauth_start_nonce' => wp_create_nonce( 'mailchimp_sf_oauth_start_nonce' ),
261+
'oauth_finish_nonce' => wp_create_nonce( 'mailchimp_sf_oauth_finish_nonce' ),
262+
'oauth_window_name' => esc_html__( 'Mailchimp For WordPress OAuth', 'mailchimp' ),
263+
'generic_error' => esc_html__( 'An error occurred. Please try again.', 'mailchimp' ),
264+
'modal_title' => esc_html__( 'Login Popup is blocked!', 'mailchimp' ),
265+
'modal_button_try_again' => esc_html__( 'Try again', 'mailchimp' ),
266+
'modal_button_cancel' => esc_html__( 'No, cancel!', 'mailchimp' ),
267+
)
268+
);
269+
}
236270
}

js/admin.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable prefer-template, no-console */
22
(function ($) {
33
const params = window.mailchimp_sf_admin_params || {};
4-
const oauthBaseUrl = 'https://woocommerce.mailchimpapp.com';
54
const spinner = '.mailchimp-sf-oauth-connect-wrapper .spinner';
65
const errorSelector = '.mailchimp-sf-oauth-section .oauth-error';
76

@@ -11,7 +10,7 @@
1110
* @param {string} token - Token from the Oauth service.
1211
*/
1312
function openMailchimpOauthPopup(token) {
14-
const startUrl = oauthBaseUrl + '/auth/start/' + token;
13+
const startUrl = params.oauth_url + '/auth/start/' + token;
1514
const width = 800;
1615
const height = 600;
1716
const screenSizes = window.screen || { width: 1024, height: 768 };
@@ -27,7 +26,7 @@
2726
', left=' +
2827
left +
2928
', domain=' +
30-
oauthBaseUrl.replace('https://', '');
29+
params.oauth_url.replace('https://', '');
3130

3231
// Open Mailchimp OAuth popup.
3332
const popup = window.open(startUrl, params.oauth_window_name, windowOptions);
@@ -67,7 +66,7 @@
6766
window.clearInterval(oauthInterval);
6867

6968
// Check status of OAuth connection.
70-
const statusUrl = oauthBaseUrl + '/api/status/' + token;
69+
const statusUrl = params.oauth_url + '/api/status/' + token;
7170
$.post(statusUrl, function (statusData) {
7271
if (statusData && statusData.status === 'accepted') {
7372
const finishData = {

mailchimp.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -140,41 +140,6 @@ function mailchimp_sf_load_resources() {
140140
}
141141
}
142142

143-
144-
/**
145-
* Loads resources for the Mailchimp admin page
146-
*
147-
* @param string $hook_suffix The current admin page.
148-
* @return void
149-
*/
150-
function mailchimp_admin_page_scripts( $hook_suffix ) {
151-
if ( 'toplevel_page_mailchimp_sf_options' !== $hook_suffix ) {
152-
return;
153-
}
154-
155-
wp_enqueue_style( 'mailchimp_sf_admin_css', MCSF_URL . 'css/admin.css', array( 'wp-jquery-ui-dialog' ), true );
156-
wp_enqueue_script( 'showMe', MCSF_URL . 'js/hidecss.js', array( 'jquery' ), MCSF_VER, true );
157-
wp_enqueue_script( 'mailchimp_sf_admin', MCSF_URL . 'js/admin.js', array( 'jquery', 'jquery-ui-dialog' ), MCSF_VER, true );
158-
159-
wp_localize_script(
160-
'mailchimp_sf_admin',
161-
'mailchimp_sf_admin_params',
162-
array(
163-
'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ),
164-
'oauth_start_nonce' => wp_create_nonce( 'mailchimp_sf_oauth_start_nonce' ),
165-
'oauth_finish_nonce' => wp_create_nonce( 'mailchimp_sf_oauth_finish_nonce' ),
166-
'oauth_window_name' => esc_html__( 'Mailchimp For WordPress OAuth', 'mailchimp' ),
167-
'generic_error' => esc_html__( 'An error occurred. Please try again.', 'mailchimp' ),
168-
'modal_title' => esc_html__( 'Login Popup is blocked!', 'mailchimp' ),
169-
'modal_button_try_again' => esc_html__( 'Try again', 'mailchimp' ),
170-
'modal_button_cancel' => esc_html__( 'No, cancel!', 'mailchimp' ),
171-
)
172-
);
173-
}
174-
175-
add_action( 'admin_enqueue_scripts', 'mailchimp_admin_page_scripts', 10, 1 );
176-
177-
178143
/**
179144
* Loads jQuery Datepicker for the date-pick class
180145
**/

0 commit comments

Comments
 (0)