PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.3.5
MxChat – AI Chatbot & Content Generation for WordPress v2.3.5
3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 2.0.3 2.0.4 2.0.5 2.0.6 All 152 releases
← All changes | js/activation-script.js +32 -70 3.2.72.3.5 View file →
@@ -1,9 +1,8 @@
1 1 /**
2 2 * Enhanced MxChat License Activation JS
3 3 * This handles BOTH local activation AND domain tracking
4 4 * Plus deactivation functionality
5 - * VERSION: Increased timeouts for better user experience
6 5 */
7 6 jQuery(document).ready(function($) {
8 7 // Get configuration from hidden fields
9 8 const AJAX_URL = $('#mxchat-ajax-url').val() || ajaxurl;
@@ -15,35 +14,8 @@
15 14 const spinner = $('#mxchat-activation-spinner');
16 15 const submitButton = $('#activate_license_button');
17 16 const licenseStatus = $('#mxchat-license-status');
18 17
19 - // Create or get status message element
20 - var $statusMessage = $('<div id="mxchat-activation-status" style="margin-top: 12px; padding: 12px 16px; border-radius: 8px; font-size: 14px; display: none;"></div>');
21 - if ($('#mxchat-activation-status').length === 0) {
22 - spinner.after($statusMessage);
23 - } else {
24 - $statusMessage = $('#mxchat-activation-status');
25 - }
26 -
27 - function showStatus(message, type) {
28 - var bgColor = type === 'success' ? 'rgba(16, 185, 129, 0.1)' :
29 - type === 'error' ? 'rgba(239, 68, 68, 0.1)' :
30 - 'rgba(120, 115, 245, 0.1)';
31 - var textColor = type === 'success' ? '#059669' :
32 - type === 'error' ? '#dc2626' :
33 - '#7873f5';
34 - var icon = type === 'success' ? '✓' :
35 - type === 'error' ? '✗' :
36 - '<span class="dashicons dashicons-update spin" style="font-size: 14px; width: 14px; height: 14px; margin-right: 4px;"></span>';
37 -
38 - $statusMessage.html(icon + ' ' + message)
39 - .css({
40 - 'background': bgColor,
41 - 'color': textColor,
42 - 'display': 'block'
43 - });
44 - }
45 -
46 18 // Activation handling
47 19 if (form.length && licenseStatus.length && submitButton.length) {
48 20 function handleActivationResponse(response) {
49 21 if (response.success) {
@@ -48,40 +20,36 @@
48 20 function handleActivationResponse(response) {
49 21 if (response.success) {
50 22 licenseStatus.text('Active');
51 23 licenseStatus.removeClass('inactive').addClass('active');
52 -
53 - // Show linking status - keep spinner visible
54 - showStatus('License verified! Linking domain...', 'loading');
55 -
24 + form.hide();
25 +
56 26 // Track domain BEFORE showing success
57 27 trackDomainActivation()
58 28 .done(function(trackResponse) {
59 29 console.log('Domain tracking successful:', trackResponse);
60 30 spinner.hide();
61 - showStatus('License activated and domain linked successfully!', 'success');
62 -
63 - // Wait before reload
31 + alert('License activated and domain linked successfully!');
32 +
64 33 setTimeout(function() {
65 34 location.reload();
66 - }, 2000);
35 + }, 1000);
67 36 })
68 37 .fail(function(jqXHR, textStatus, errorThrown) {
69 38 console.error('Domain tracking failed:', textStatus, errorThrown);
70 39 spinner.hide();
71 -
40 +
72 41 // Still show success but warn about domain linking
73 - showStatus('License activated! Domain linking failed - you can link it manually after reload.', 'success');
74 -
75 - // Wait before reload
42 + alert('License activated successfully!\n\nNote: Domain linking failed. You may need to use the "Link Domain" button after the page reloads.');
43 +
76 44 setTimeout(function() {
77 45 location.reload();
78 - }, 3000);
46 + }, 2000);
79 47 });
80 48 } else {
81 49 spinner.hide();
82 50 licenseStatus.text('Inactive');
83 - showStatus(response.data || 'Activation failed. Please check your input.', 'error');
51 + alert(response.data || 'Activation failed. Please check your input.');
84 52 submitButton.prop('disabled', false);
85 53 }
86 54 }
87 55
@@ -97,9 +65,8 @@
97 65 email: email,
98 66 key: key,
99 67 security: NONCE
100 68 },
101 - timeout: 45000, // Increased from default to 45 seconds
102 69 success: function(response) {
103 70 if (response.is_active) {
104 71 licenseStatus.text('Active');
105 72 licenseStatus.removeClass('inactive').addClass('active');
@@ -106,21 +73,13 @@
106 73 form.hide();
107 74
108 75 // Try to track domain for timeout scenario
109 76 trackDomainActivation()
110 - .done(function(trackResponse) {
111 - console.log('Domain tracking completed after timeout check:', trackResponse);
112 - alert('Your license has been activated and domain linked successfully!');
77 + .always(function() {
78 + alert('Your license has been activated successfully!');
113 79 setTimeout(function() {
114 80 location.reload();
115 - }, 3000);
116 - })
117 - .fail(function() {
118 - console.log('Domain tracking failed after timeout check');
119 - alert('Your license has been activated successfully!\n\nNote: Domain linking may have failed. Check the "Link Domain" button after reload if needed.');
120 - setTimeout(function() {
121 - location.reload();
122 - }, 3000);
81 + }, 1500);
123 82 });
124 83 } else {
125 84 alert('License activation timed out. Please try again or contact support if the problem persists.');
126 85 submitButton.prop('disabled', false);
@@ -141,15 +100,15 @@
141 100 console.log('Attempting to track domain:', domain);
142 101
143 102 return $.ajax({
144 103 type: 'POST',
145 - url: API_URL + '/mxchat-api/link-domain', // Changed to use same endpoint as manual linking
104 + url: API_URL + '/mxchat-api/activate-license',
146 105 data: {
147 - email: email, // Changed parameter name to match manual linking
148 - license_key: key, // Changed parameter name to match manual linking
106 + mxchat_pro_email: email,
107 + mxchat_activation_key: key,
149 108 domain: domain
150 109 },
151 - timeout: 30000, // Increased from 10 seconds to 30 seconds
110 + timeout: 10000, // 10 second timeout
152 111 xhrFields: {
153 112 withCredentials: false // Ensure CORS compatibility
154 113 },
155 114 crossDomain: true
@@ -159,10 +118,9 @@
159 118 form.on('submit', function(event) {
160 119 event.preventDefault();
161 120 spinner.show();
162 121 submitButton.prop('disabled', true);
163 - showStatus('Validating license key...', 'loading');
164 -
122 +
165 123 var formData = {
166 124 action: 'mxchat_handle_activate_license',
167 125 mxchat_pro_email: $('#mxchat_pro_email').val(),
168 126 mxchat_activation_key: $('#mxchat_activation_key').val(),
@@ -167,23 +125,27 @@
167 125 mxchat_pro_email: $('#mxchat_pro_email').val(),
168 126 mxchat_activation_key: $('#mxchat_activation_key').val(),
169 127 security: NONCE
170 128 };
171 -
129 +
172 130 $.ajax({
173 131 type: 'POST',
174 132 url: AJAX_URL,
175 133 data: formData,
176 - timeout: 120000, // Increased from 70 seconds to 2 minutes (120 seconds)
134 + timeout: 70000,
177 135 success: function(response) {
178 136 handleActivationResponse(response);
179 137 },
180 138 error: function(jqXHR, textStatus) {
181 - // On any error, check if the license was actually saved successfully
182 - // This handles cases where the response format caused a parse error
183 - // but the activation actually worked
184 - showStatus('Verifying activation status...', 'loading');
185 - checkActivationStatus();
139 + if (textStatus === 'timeout') {
140 + spinner.hide();
141 + alert('Activation is taking longer than expected. Checking status...');
142 + checkActivationStatus();
143 + } else {
144 + alert('Activation failed due to a server error: ' + (jqXHR.responseText || textStatus));
145 + spinner.hide();
146 + submitButton.prop('disabled', false);
147 + }
186 148 }
187 149 });
188 150 });
189 151 }
@@ -218,9 +180,9 @@
218 180 email: email,
219 181 license_key: license_key,
220 182 domain: domain
221 183 },
222 - timeout: 30000, // Increased from 10 seconds to 30 seconds
184 + timeout: 10000,
223 185 success: function(response) {
224 186 if (response.success) {
225 187 status.html('<span style="color: green;">✓ Domain linked successfully!</span>');
226 188 button.hide();
@@ -240,9 +202,9 @@
240 202 }
241 203 });
242 204 });
243 205
244 - // License deactivation
206 + // License deactivation (unchanged)
245 207 $('#deactivate-license-button').on('click', function() {
246 208 const button = $(this);
247 209 const status = $('#deactivate-status');
248 210 const originalText = button.text();
@@ -268,9 +230,9 @@
268 230 data: {
269 231 action: 'mxchat_deactivate_license',
270 232 security: NONCE
271 233 },
272 - timeout: 45000, // Increased from 15 seconds to 45 seconds
234 + timeout: 15000,
273 235 success: function(response) {
274 236 if (response.success) {
275 237 status.html('<span style="color: green;">✓ ' + response.data.message + '</span>');
276 238