diff --git a/assets/css/style-wizard.css b/assets/css/style-wizard.css index 5520128..133c527 100644 --- a/assets/css/style-wizard.css +++ b/assets/css/style-wizard.css @@ -353,6 +353,11 @@ input.invalid:focus { color: #d63638; } +.wpmm-templates-radio.disabled { + opacity: .5; + pointer-events: none; +} + @keyframes abs-spin { from { transform: translate(-50%, -50%) rotate(0deg); diff --git a/assets/js/scripts-admin.js b/assets/js/scripts-admin.js index cc8b904..cdd5f72 100644 --- a/assets/js/scripts-admin.js +++ b/assets/js/scripts-admin.js @@ -387,22 +387,17 @@ jQuery( function( $ ) { $( this ).addClass( 'is-busy' ); $( this ).trigger( 'blur' ); - handlePlugins().then( function() { - $.post( wpmmVars.ajaxURL, { - action: 'wpmm_skip_wizard', - _wpnonce: wpmmVars.wizardNonce, - }, function( response ) { - if ( ! response.success ) { - addErrorMessage(); - return; - } + $.post( wpmmVars.ajaxURL, { + action: 'wpmm_skip_wizard', + _wpnonce: wpmmVars.wizardNonce, + }, function( response ) { + if ( ! response.success ) { + addErrorMessage(); + return; + } - skipWizard = true; - moveToStep( 'import', 'subscribe' ); - } ); - } ).catch( function() { - addErrorMessage(); - $( '.button-skip' ).removeClass( 'is-busy' ); + skipWizard = true; + moveToStep( 'import', 'subscribe' ); } ); } ); @@ -482,16 +477,26 @@ jQuery( function( $ ) { } } ); + $( '#wizard-otter-block-checkbox' ).on( 'change', function() { + if ( ! $(this).is(':checked') ) { + $( '.wpmm-templates-radio' ).addClass( 'disabled' ); + } else { + $( '.wpmm-templates-radio' ).removeClass( 'disabled' ); + } + } ); + /** * Adds elements and CSS when importing from wizard * * @param {string} slug The template that will be imported */ function importInProgress( slug ) { - const template = $( 'input[value=' + slug + '] + .wpmm-template' ); - - template.addClass( 'loading' ); - template.append( '
' + wpmmVars.loadingString + '
' ); + if ( ! $('.wpmm-templates-radio').hasClass('disabled') ) { + const template = $( 'input[value=' + slug + '] + .wpmm-template' ); + + template.addClass( 'loading' ); + template.append( '' + wpmmVars.loadingString + '
' ); + } $( '.button-import' ).attr( 'disabled', 'disabled' ); $( '#wpmm-wizard-wrapper .button-skip' ).addClass( 'disabled' ); @@ -518,8 +523,7 @@ jQuery( function( $ ) { * @param {Function} callback */ function importTemplate( data, callback ) { - handleOtter() - .then( () => handlePlugins() ) + handlePlugins() .then( () => addToPage( data, callback ) ) .catch( ( error ) => { // eslint-disable-next-line no-console @@ -561,6 +565,22 @@ jQuery( function( $ ) { * @param {Function} callback */ function addToPage( data, callback ) { + if ($('.wpmm-templates-radio').hasClass('disabled')) { + $.post( wpmmVars.ajaxURL, { + action: 'wpmm_skip_insert_template', + _wpnonce: wpmmVars.wizardNonce, + }, function( response ) { + if ( ! response.success ) { + addErrorMessage(); + return; + } + + skipWizard = true; + moveToStep( 'import', 'subscribe' ); + } ); + return Promise.resolve(); + } + data.action = 'wpmm_insert_template'; $.post( wpmmVars.ajaxURL, data, function( response ) { if ( ! response.success ) { @@ -579,6 +599,7 @@ jQuery( function( $ ) { */ function handlePlugins() { const optimoleCheckbox = $( '#wizard-optimole-checkbox' ); + const otterBlockCheckbox = $( '#wizard-otter-block-checkbox' ); let promiseChain = Promise.resolve(); if ( optimoleCheckbox.length && optimoleCheckbox.is( ':checked' ) ) { @@ -594,6 +615,11 @@ jQuery( function( $ ) { }); } + if ( otterBlockCheckbox.length && otterBlockCheckbox.is( ':checked' ) ) { + promiseChain = promiseChain + .then(() => handleOtter()); + } + return promiseChain.catch( ( error ) => { console.error( 'Error in plugin installation or activation:', error ); }); diff --git a/includes/classes/wp-maintenance-mode-admin.php b/includes/classes/wp-maintenance-mode-admin.php index 7a91c23..7721e34 100644 --- a/includes/classes/wp-maintenance-mode-admin.php +++ b/includes/classes/wp-maintenance-mode-admin.php @@ -59,6 +59,7 @@ private function __construct() { add_action( 'wp_ajax_wpmm_reset_settings', array( $this, 'reset_plugin_settings' ) ); add_action( 'wp_ajax_wpmm_select_page', array( $this, 'select_page' ) ); add_action( 'wp_ajax_wpmm_insert_template', array( $this, 'insert_template' ) ); + add_action( 'wp_ajax_wpmm_skip_insert_template', array( $this, 'skip_insert_template' ) ); add_action( 'wp_ajax_wpmm_skip_wizard', array( $this, 'skip_wizard' ) ); add_action( 'wp_ajax_wpmm_subscribe', array( $this, 'subscribe_newsletter' ) ); add_action( 'wp_ajax_wpmm_change_template_category', array( $this, 'change_template_category' ) ); @@ -692,10 +693,6 @@ public function select_page() { * @return void */ public function insert_template() { - if ( ! is_plugin_active( 'otter-blocks/otter-blocks.php' ) ) { - wp_send_json_error( array( 'error' => 'Otter Blocks is not activated' ) ); - } - // check nonce existence if ( empty( $_POST['_wpnonce'] ) ) { die( esc_html__( 'The nonce field must not be empty.', 'wp-maintenance-mode' ) ); @@ -749,6 +746,26 @@ public function insert_template() { wp_send_json_success( array( 'pageEditURL' => get_edit_post_link( $page_id ) ) ); } + /** + * Skip importing a template. + * + * @return void + */ + public function skip_insert_template() { + // check nonce existence + if ( empty( $_POST['_wpnonce'] ) ) { + die( esc_html__( 'The nonce field must not be empty.', 'wp-maintenance-mode' ) ); + } + + // check nonce validation + if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'wizard' ) ) { + die( esc_html__( 'Security check.', 'wp-maintenance-mode' ) ); + } + + update_option( 'wpmm_fresh_install', false ); + wp_send_json_success(); + } + /** * Skip importing a template (and installing Otter) from the wizard * diff --git a/views/wizard.php b/views/wizard.php index f3f7f0b..59ef19d 100644 --- a/views/wizard.php +++ b/views/wizard.php @@ -19,47 +19,60 @@