updated plugin WP Mail SMTP
version 2.0.0
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
/* globals jQuery, wp_mail_smtp */
|
||||
/* globals wp_mail_smtp, ajaxurl */
|
||||
'use strict';
|
||||
|
||||
var WPMailSMTP = window.WPMailSMTP || {};
|
||||
WPMailSMTP.Admin = WPMailSMTP.Admin || {};
|
||||
|
||||
@ -7,32 +9,22 @@ WPMailSMTP.Admin = WPMailSMTP.Admin || {};
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, window, $ ) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Private functions and properties.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
var __private = {};
|
||||
WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @type {Object}
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* State attribute showing if one of the plugin settings
|
||||
* changed and was not yet saved.
|
||||
*
|
||||
* @since {VERSION}
|
||||
* @since 1.9.0
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
@ -43,7 +35,7 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
init: function () {
|
||||
init: function() {
|
||||
|
||||
// Do that when DOM is ready.
|
||||
$( document ).ready( app.ready );
|
||||
@ -54,7 +46,7 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
ready: function () {
|
||||
ready: function() {
|
||||
|
||||
app.pageHolder = $( '.wp-mail-smtp-tab-settings' );
|
||||
|
||||
@ -69,17 +61,18 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
bindActions: function () {
|
||||
bindActions: function() {
|
||||
|
||||
// Mailer selection.
|
||||
$( '.wp-mail-smtp-mailer-image', app.pageHolder ).click( function () {
|
||||
$( '.wp-mail-smtp-mailer-image', app.pageHolder ).click( function() {
|
||||
$( this ).parents( '.wp-mail-smtp-mailer' ).find( 'input' ).trigger( 'click' );
|
||||
} );
|
||||
|
||||
$( '.wp-mail-smtp-mailer input', app.pageHolder ).click( function () {
|
||||
$( '.wp-mail-smtp-mailer input', app.pageHolder ).click( function() {
|
||||
var $input = $( this );
|
||||
|
||||
if ( $input.prop( 'disabled' ) ) {
|
||||
|
||||
// Educational Popup.
|
||||
if ( $input.hasClass( 'educate' ) ) {
|
||||
app.education.upgradeMailer( $input );
|
||||
@ -90,6 +83,7 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
|
||||
// Deselect the current mailer.
|
||||
$( '.wp-mail-smtp-mailer', app.pageHolder ).removeClass( 'active' );
|
||||
|
||||
// Select the correct one.
|
||||
$( this ).parents( '.wp-mail-smtp-mailer' ).addClass( 'active' );
|
||||
|
||||
@ -101,23 +95,23 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
app.mailers.smtp.bindActions();
|
||||
|
||||
// Dismiss Pro banner at the bottom of the page.
|
||||
$( '#wp-mail-smtp-pro-banner-dismiss', app.pageHolder ).on( 'click', function () {
|
||||
$( '#wp-mail-smtp-pro-banner-dismiss', app.pageHolder ).on( 'click', function() {
|
||||
$.ajax( {
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wp_mail_smtp_ajax',
|
||||
task: 'pro_banner_dismiss'
|
||||
}
|
||||
} )
|
||||
.always( function () {
|
||||
$( '#wp-mail-smtp-pro-banner', app.pageHolder ).fadeOut( 'fast' );
|
||||
} );
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wp_mail_smtp_ajax',
|
||||
task: 'pro_banner_dismiss'
|
||||
}
|
||||
} )
|
||||
.always( function() {
|
||||
$( '#wp-mail-smtp-pro-banner', app.pageHolder ).fadeOut( 'fast' );
|
||||
} );
|
||||
} );
|
||||
|
||||
// Dismis educational notices for certain mailers.
|
||||
$( '.js-wp-mail-smtp-mailer-notice-dismiss', app.pageHolder ).on( 'click', function ( e ) {
|
||||
// Dissmis educational notices for certain mailers.
|
||||
$( '.js-wp-mail-smtp-mailer-notice-dismiss', app.pageHolder ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
var $btn = $( this ),
|
||||
@ -128,28 +122,28 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
}
|
||||
|
||||
$.ajax( {
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wp_mail_smtp_ajax',
|
||||
task: 'notice_dismiss',
|
||||
notice: $notice.data( 'notice' ),
|
||||
mailer: $notice.data( 'mailer' )
|
||||
},
|
||||
beforeSend: function () {
|
||||
$btn.addClass( 'disabled' );
|
||||
}
|
||||
} )
|
||||
.always( function () {
|
||||
$notice.fadeOut( 'fast', function () {
|
||||
$btn.removeClass( 'disabled' );
|
||||
} );
|
||||
} );
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wp_mail_smtp_ajax',
|
||||
task: 'notice_dismiss',
|
||||
notice: $notice.data( 'notice' ),
|
||||
mailer: $notice.data( 'mailer' )
|
||||
},
|
||||
beforeSend: function() {
|
||||
$btn.addClass( 'disabled' );
|
||||
}
|
||||
} )
|
||||
.always( function() {
|
||||
$notice.fadeOut( 'fast', function() {
|
||||
$btn.removeClass( 'disabled' );
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
// Show/hide debug output.
|
||||
$( '#wp-mail-smtp-debug .error-log-toggle' ).on( 'click', function ( e ) {
|
||||
$( '#wp-mail-smtp-debug .error-log-toggle' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
$( '#wp-mail-smtp-debug .error-log-toggle' ).find( '.dashicons' ).toggleClass( 'dashicons-arrow-right-alt2 dashicons-arrow-down-alt2' );
|
||||
@ -158,12 +152,12 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
} );
|
||||
|
||||
// Remove mailer connection.
|
||||
$( '.js-wp-mail-smtp-provider-remove', app.pageHolder ).on( 'click', function () {
|
||||
$( '.js-wp-mail-smtp-provider-remove', app.pageHolder ).on( 'click', function() {
|
||||
return confirm( wp_mail_smtp.text_provider_remove );
|
||||
} );
|
||||
|
||||
// Copy input text to clipboard.
|
||||
$( '.wp-mail-smtp-setting-copy', app.pageHolder ).click( function ( e ) {
|
||||
$( '.wp-mail-smtp-setting-copy', app.pageHolder ).click( function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
var target = $( '#' + $( this ).data( 'source_id' ) ).get( 0 );
|
||||
@ -177,7 +171,7 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
},
|
||||
|
||||
education: {
|
||||
upgradeMailer: function ( $input ) {
|
||||
upgradeMailer: function( $input ) {
|
||||
|
||||
$.alert( {
|
||||
backgroundDismiss: true,
|
||||
@ -192,7 +186,7 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
icon: '"></i>' + wp_mail_smtp.education.upgrade_icon_lock + '<i class="',
|
||||
content: $( '.wp-mail-smtp-mailer-options .wp-mail-smtp-mailer-option-' + $input.val() + ' .wp-mail-smtp-setting-field' ).html(),
|
||||
boxWidth: '550px',
|
||||
onOpenBefore: function () {
|
||||
onOpenBefore: function() {
|
||||
this.$btnc.after( '<div class="discount-note">' + wp_mail_smtp.education.upgrade_bonus + wp_mail_smtp.education.upgrade_doc + '</div>' );
|
||||
},
|
||||
buttons: {
|
||||
@ -200,7 +194,7 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
text: wp_mail_smtp.education.upgrade_button,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
action: function () {
|
||||
action: function() {
|
||||
window.open( wp_mail_smtp.education.upgrade_url + '&utm_content=' + encodeURI( $input.val() ), '_blank' );
|
||||
}
|
||||
}
|
||||
@ -216,15 +210,15 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
*/
|
||||
mailers: {
|
||||
smtp: {
|
||||
bindActions: function () {
|
||||
bindActions: function() {
|
||||
|
||||
// Hide SMTP-specific user/pass when Auth disabled.
|
||||
$( '#wp-mail-smtp-setting-smtp-auth' ).change( function () {
|
||||
$( '#wp-mail-smtp-setting-smtp-auth' ).change( function() {
|
||||
$( '#wp-mail-smtp-setting-row-smtp-user, #wp-mail-smtp-setting-row-smtp-pass' ).toggleClass( 'inactive' );
|
||||
} );
|
||||
|
||||
// Port default values based on encryption type.
|
||||
$( '#wp-mail-smtp-setting-row-smtp-encryption input' ).change( function () {
|
||||
$( '#wp-mail-smtp-setting-row-smtp-encryption input' ).change( function() {
|
||||
|
||||
var $input = $( this ),
|
||||
$smtpPort = $( '#wp-mail-smtp-setting-smtp-port', app.pageHolder );
|
||||
@ -232,12 +226,10 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
if ( 'tls' === $input.val() ) {
|
||||
$smtpPort.val( '587' );
|
||||
$( '#wp-mail-smtp-setting-row-smtp-autotls' ).addClass( 'inactive' );
|
||||
}
|
||||
else if ( 'ssl' === $input.val() ) {
|
||||
} else if ( 'ssl' === $input.val() ) {
|
||||
$smtpPort.val( '465' );
|
||||
$( '#wp-mail-smtp-setting-row-smtp-autotls' ).removeClass( 'inactive' );
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$smtpPort.val( '25' );
|
||||
$( '#wp-mail-smtp-setting-row-smtp-autotls' ).removeClass( 'inactive' );
|
||||
}
|
||||
@ -249,26 +241,26 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
/**
|
||||
* Exit notice JS code when plugin settings are not saved.
|
||||
*
|
||||
* @since {VERSION}
|
||||
* @since 1.9.0
|
||||
*/
|
||||
triggerExitNotice: function () {
|
||||
triggerExitNotice: function() {
|
||||
|
||||
var $settingPages = $( '.wp-mail-smtp-page-general:not( .wp-mail-smtp-tab-test )' );
|
||||
|
||||
// Display an exit notice, if settings are not saved.
|
||||
$( window ).on( 'beforeunload', function () {
|
||||
$( window ).on( 'beforeunload', function() {
|
||||
if ( app.pluginSettingsChanged ) {
|
||||
return wp_mail_smtp.text_settings_not_saved;
|
||||
}
|
||||
} );
|
||||
|
||||
// Set settings changed attribute, if any input was changed.
|
||||
$( ':input:not( #wp-mail-smtp-setting-license-key )', $settingPages ).on( 'change', function () {
|
||||
$( ':input:not( #wp-mail-smtp-setting-license-key )', $settingPages ).on( 'change', function() {
|
||||
app.pluginSettingsChanged = true;
|
||||
} );
|
||||
|
||||
// Clear the settings changed attribute, if the settings are about to be saved.
|
||||
$( 'form', $settingPages ).on( 'submit', function () {
|
||||
$( 'form', $settingPages ).on( 'submit', function() {
|
||||
app.pluginSettingsChanged = false;
|
||||
} );
|
||||
}
|
||||
@ -276,7 +268,7 @@ WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || (function ( document, w
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
})( document, window, jQuery );
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPMailSMTP.Admin.Settings.init();
|
||||
|
Reference in New Issue
Block a user