PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 4.9.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v4.9.0
4.9.0 0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / assets / js / smtp-recommendations.js
wp-mail-smtp / assets / js Last commit date
vendor 5 days ago connect.js 5 days ago connect.min.js 5 days ago smtp-about.js 5 days ago smtp-about.min.js 5 days ago smtp-activelayer-wc.js 5 days ago smtp-activelayer-wc.min.js 5 days ago smtp-admin-notices.js 5 days ago smtp-admin-notices.min.js 5 days ago smtp-admin.js 5 days ago smtp-admin.min.js 5 days ago smtp-ai-mcp.js 5 days ago smtp-ai-mcp.min.js 5 days ago smtp-code-snippets.js 5 days ago smtp-code-snippets.min.js 5 days ago smtp-dashboard-widget.js 5 days ago smtp-dashboard-widget.min.js 5 days ago smtp-notifications.js 5 days ago smtp-notifications.min.js 5 days ago smtp-recommendations.js 5 days ago smtp-recommendations.min.js 5 days ago smtp-tools-debug-events.js 5 days ago smtp-tools-debug-events.min.js 5 days ago
smtp-recommendations.js
283 lines
1 /* global wp_mail_smtp_recommendations, wp_mail_smtp */
2
3 /**
4 * @param wp_mail_smtp_recommendations.plugin_page.activated
5 * @param wp_mail_smtp_recommendations.plugin_page.activated_pro
6 * @param wp_mail_smtp_recommendations.plugin_page.download_now
7 * @param wp_mail_smtp_recommendations.plugin_page.error_could_not_activate
8 * @param wp_mail_smtp_recommendations.plugin_page.error_could_not_install
9 * @param wp_mail_smtp_recommendations.plugin_page.is_activated
10 * @param wp_mail_smtp_recommendations.plugin_page.license_level
11 * @param wp_mail_smtp_recommendations.plugin_page.result_status
12 * @param wp_mail_smtp_recommendations.plugin_page.plugins_page
13 * @param wp_mail_smtp_recommendations.plugin_page.setup_status
14 * @param wp_mail_smtp_recommendations.plugin_page.step3_button_url
15 * @param wp_mail_smtp_recommendations.plugin_page.manual_activate_url
16 * @param wp_mail_smtp_recommendations.plugin_page.manual_install_url
17 */
18
19 'use strict';
20
21 const WPMailSMTPRecommendations = {};
22
23 /**
24 * Plugin recommendation page.
25 *
26 * @since 4.9.0
27 */
28 WPMailSMTPRecommendations.plugin_page = ( function( document, window, $ ) {
29
30 /**
31 * Elements.
32 *
33 * @since 4.9.0
34 *
35 * @type {object}
36 */
37 let el = {};
38
39 /**
40 * Public functions and properties.
41 *
42 * @since 4.9.0
43 *
44 * @type {object}
45 */
46 const app = {
47
48 /**
49 * Start the engine.
50 *
51 * @since 4.9.0
52 */
53 init: () => {
54 $( app.ready );
55 },
56
57 /**
58 * Document ready.
59 *
60 * @since 4.9.0
61 */
62 ready: () => {
63 app.initVars();
64 app.events();
65 },
66
67 /**
68 * Init variables.
69 *
70 * @since 4.9.0
71 */
72 initVars: () => {
73 el = {
74 $stepInstall: $( 'section.step-install' ),
75 $stepInstallNum: $( 'section.step-install .num img' ),
76 $stepSetup: $( 'section.step-setup' ),
77 $stepSetupNum: $( 'section.step-setup .num img' ),
78 $stepResult: $( 'section.step-result' ),
79 $stepResultNum: $( 'section.step-result .num img' ),
80 };
81 },
82
83 /**
84 * Register JS events.
85 *
86 * @since 4.9.0
87 */
88 events: () => {
89
90 // Step the 'Install' button click.
91 el.$stepInstall.on( 'click', 'button', app.stepInstallClick );
92
93 // Step 'Setup' button click.
94 el.$stepSetup.on( 'click', 'button', app.gotoURL );
95
96 // Step the 'Addon' button click.
97 el.$stepResult.on( 'click', 'button', app.gotoURL );
98 },
99
100 /**
101 * Step the 'Install' button click.
102 *
103 * @since 4.9.0
104 *
105 * @param {Event} e Event object.
106 */
107 stepInstallClick: ( e ) => {
108 const $btn = $( e.currentTarget );
109
110 if ( $btn.hasClass( 'disabled' ) ) {
111 return;
112 }
113
114 const action = $btn.attr( 'data-action' );
115
116 let task = '';
117
118 switch ( action ) {
119 case 'activate':
120 task = 'about_plugin_activate';
121 $btn.html( wp_mail_smtp_recommendations.plugin_page.activating );
122 break;
123
124 case 'install':
125 task = 'about_plugin_install';
126 $btn.html( wp_mail_smtp_recommendations.plugin_page.installing );
127 break;
128
129 case 'goto-url':
130 window.location.href = $btn.attr( 'data-url' );
131 return;
132
133 default:
134 return;
135 }
136
137 $btn.addClass( 'disabled' );
138 app.showSpinner( el.$stepInstallNum );
139
140 const plugin = $btn.attr( 'data-plugin' );
141
142 const data = {
143 action: 'wp_mail_smtp_ajax',
144 task,
145 nonce : wp_mail_smtp.nonce,
146 plugin,
147 };
148 $.post( wp_mail_smtp.ajax_url, data )
149 .done( function( res ) {
150 app.stepInstallDone( res, $btn, action );
151 } )
152 .always( function() {
153 app.hideSpinner( el.$stepInstallNum );
154 } );
155 },
156
157 /**
158 * Done part of the step 'Install'.
159 *
160 * @since 4.9.0
161 *
162 * @param {object} res Result of $.post() query.
163 * @param {jQuery} $btn Button.
164 * @param {string} action Action (for more info look at the app.stepInstallClick() function).
165 */
166 stepInstallDone: ( res, $btn, action ) => { // eslint-disable-line complexity
167 const success = 'install' === action ? res.success && res.data.is_activated : res.success,
168 provider = $btn.data( 'provider' );
169
170 if ( success ) {
171 el.$stepInstallNum.attr( 'src', el.$stepInstallNum.attr( 'src' ).replace( 'step-1.', 'complete.' ) );
172 $btn.addClass( 'grey' ).removeClass( 'button-primary' ).html( wp_mail_smtp_recommendations.plugin_page.activated );
173 app.stepInstallPluginStatus( provider );
174 } else {
175 const activationFail = ( 'install' === action && res.success && ! res.data.is_activated ) || 'activate' === action,
176 installUrl = wp_mail_smtp_recommendations.plugin_page[ provider + '_manual_install_url' ] || '',
177 activateUrl = wp_mail_smtp_recommendations.plugin_page[ provider + '_manual_activate_url' ] || '',
178 url = ! activationFail ? installUrl : activateUrl,
179 msg = ! activationFail ? wp_mail_smtp_recommendations.plugin_page.error_could_not_install : wp_mail_smtp_recommendations.plugin_page.error_could_not_activate,
180 btn = ! activationFail ? wp_mail_smtp_recommendations.plugin_page.download_now : wp_mail_smtp_recommendations.plugin_page.plugins_page;
181
182 $btn.removeClass( 'grey disabled' ).html( btn ).attr( 'data-action', 'goto-url' ).attr( 'data-url', url );
183 $btn.after( '<p class="error">' + msg + '</p>' );
184 }
185 },
186
187 /**
188 * Callback for step 'Install' completion.
189 *
190 * @since 4.9.0
191 *
192 * @param {string} plugin Plugin name.
193 */
194 stepInstallPluginStatus: ( plugin ) => {
195 const data = {
196 action: 'wp_mail_smtp_page_check_' + plugin + '_status',
197 nonce: wp_mail_smtp.nonce,
198 provider: plugin,
199 };
200 $.post( wp_mail_smtp.ajax_url, data ).done( app.stepInstallPluginStatusDone );
201 },
202
203 /**
204 * Done part of the callback for step 'Install' completion.
205 *
206 * @since 4.9.0
207 *
208 * @param {object} res Result of $.post() query.
209 */
210 stepInstallPluginStatusDone: ( res ) => {
211 if ( ! res.success ) {
212 return;
213 }
214
215 el.$stepSetup.removeClass( 'grey' );
216 el.$stepSetupBtn = el.$stepSetup.find( 'button' );
217
218 if ( res.data.setup_status > 0 ) {
219 el.$stepSetupNum.attr( 'src', el.$stepSetupNum.attr( 'src' ).replace( 'step-2.svg', 'complete.svg' ) );
220 el.$stepResult.removeClass( 'grey' );
221 el.$stepResultBtn = el.$stepResult.find( 'button' );
222
223 if ( res.data.license_level === 'pro' && res.data.result_status === true ) {
224 el.$stepResultBtn.html( wp_mail_smtp_recommendations.plugin_page.activated_pro );
225 el.$stepResultNum.attr( 'src', el.$stepResultNum.attr( 'src' ).replace( 'step-3.svg', 'complete.svg' ) );
226 } else {
227 el.$stepResultBtn.attr( 'data-url', res.data.step3_button_url );
228 el.$stepResultBtn.removeClass( 'grey disabled' ).addClass( 'button-primary' );
229 }
230 } else {
231 el.$stepSetupBtn.removeClass( 'grey disabled' ).addClass( 'button-primary' );
232 }
233 },
234
235 /**
236 * Go to URL.
237 *
238 * @since 4.9.0
239 *
240 * @param {Event} e Event object.
241 */
242 gotoURL: ( e ) => { // eslint-disable-line no-unused-vars
243 const $btn = $( e.currentTarget ),
244 url = $btn.attr( 'data-url' );
245
246 if ( $btn.hasClass( 'disabled' ) || ! url ) {
247 return;
248 }
249
250 window.open( url, '_blank' );
251 },
252
253 /**
254 * Show spinner.
255 *
256 * @since 4.9.0
257 *
258 * @param {jQuery} $el Element.
259 */
260 showSpinner: ( $el ) => {
261 $el.siblings( 'i.loader' ).removeClass( 'hidden' );
262 },
263
264 /**
265 * Hide spinner.
266 *
267 * @since 4.9.0
268 *
269 * @param {jQuery} $el Element.
270 */
271 hideSpinner: ( $el ) => {
272 $el.show();
273 $el.siblings( 'i.loader' ).addClass( 'hidden' );
274 },
275 };
276
277 // Provide public access to functions and properties.
278 return app;
279 }( document, window, jQuery ) );
280
281 // Initialize.
282 WPMailSMTPRecommendations.plugin_page.init();
283