From 256e7eb8aa0915bab298b2b072e3cc236f99eb94 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Fri, 11 Jul 2025 13:06:39 +0530 Subject: [PATCH 1/6] refactor: plugin install steps --- assets/css/style-wizard.css | 5 ++ assets/js/scripts-admin.js | 40 +++++++-- .../classes/wp-maintenance-mode-admin.php | 21 +++-- views/wizard.php | 84 ++++++++++--------- 4 files changed, 98 insertions(+), 52 deletions(-) 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..cedb547 100644 --- a/assets/js/scripts-admin.js +++ b/assets/js/scripts-admin.js @@ -482,16 +482,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 +528,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 +570,10 @@ jQuery( function( $ ) { * @param {Function} callback */ function addToPage( data, callback ) { + if ($('.wpmm-templates-radio').hasClass('disabled')) { + data.category = ''; + } + data.action = 'wpmm_insert_template'; $.post( wpmmVars.ajaxURL, data, function( response ) { if ( ! response.success ) { @@ -579,6 +592,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 +608,20 @@ jQuery( function( $ ) { }); } + if ( otterBlockCheckbox.length && otterBlockCheckbox.is( ':checked' ) ) { + promiseChain = promiseChain + .then(() => handleOtter()) + .then(() => { + if ( ! wpmmVars.isOtterInstalled ) { + return installPlugin( 'otter-blocks' ).then( () => activatePlugin( 'otter-blocks' ) ); + } + + if ( ! wpmmVars.isOtterActive ) { + return activatePlugin( 'otter-blocks' ); + } + }); + } + 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..522d96d 100644 --- a/includes/classes/wp-maintenance-mode-admin.php +++ b/includes/classes/wp-maintenance-mode-admin.php @@ -692,9 +692,9 @@ 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' ) ); - } + // 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'] ) ) { @@ -712,10 +712,14 @@ public function insert_template() { } $template_slug = $_POST['template_slug']; - $category = $_POST['category']; - $template = json_decode( file_get_contents( WPMM_TEMPLATES_PATH . $category . '/' . $template_slug . '/blocks-export.json' ) ); + $blocks = ''; + $category = 'maintenance'; + if ( ! empty( $_POST['category'] ) ) { + $category = $_POST['category']; + $template = json_decode( file_get_contents( WPMM_TEMPLATES_PATH . $category . '/' . $template_slug . '/blocks-export.json' ) ); - $blocks = str_replace( '\n', '', $template->content ); + $blocks = str_replace( '\n', '', $template->content ); + } $post_arr = array( 'post_type' => 'page', @@ -737,7 +741,10 @@ public function insert_template() { } $this->plugin_settings['design']['page_id'] = $page_id; - CSS_Handler::generate_css_file( $page_id ); + + if ( is_plugin_active( 'otter-blocks/otter-blocks.php' ) ) { + CSS_Handler::generate_css_file( $page_id ); + } if ( 'wizard' === $_POST['source'] ) { $this->plugin_settings['general']['status'] = 1; diff --git a/views/wizard.php b/views/wizard.php index f3f7f0b..47e9803 100644 --- a/views/wizard.php +++ b/views/wizard.php @@ -19,47 +19,53 @@
-

-

- Otter%2$s.', 'wp-maintenance-mode' ), - wpmm_translated_string_allowed_html() - ), - tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/', $this->plugin_slug, 'wizard' ), - $this->get_external_link_icon() - ); - ?> -
- -

-
-
- $label ) { - $slug = $default_templates[ $category ]['slug']; - $thumbnail_url = $default_templates[ $category ]['thumbnail']; +

+ +
+
+ + + + + +
+

+ Pick a template to get started. Otter Blocks plugin will be installed and activated to support and customize your layout. It also unlocks tools like forms and popups - if you need them later.', 'wp-maintenance-mode' ), + wpmm_translated_string_allowed_html() + ), + tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/', $this->plugin_slug, 'wizard' ), + ); ?> -

-
- > - -
+

+
+
+ - -
+ $categories = WP_Maintenance_Mode::get_page_categories(); + foreach ( $categories as $category => $label ) { + $slug = $default_templates[ $category ]['slug']; + $thumbnail_url = $default_templates[ $category ]['thumbnail']; + ?> +
+
+ > + +
+ + +
+
From 60fbdc1c279abfe1a375f54161ffbf02bafe7963 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Fri, 11 Jul 2025 14:15:24 +0530 Subject: [PATCH 2/6] refactor: move translatable strings outside HTML --- views/wizard.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/views/wizard.php b/views/wizard.php index 47e9803..7550286 100644 --- a/views/wizard.php +++ b/views/wizard.php @@ -31,14 +31,16 @@

Pick a template to get started. Otter Blocks plugin will be installed and activated to support and customize your layout. It also unlocks tools like forms and popups - if you need them later.', 'wp-maintenance-mode' ), - wpmm_translated_string_allowed_html() - ), + echo wp_kses( + sprintf( + '%1$s %3$s %4$s', + __( 'Pick a template to get started.', 'wp-maintenance-mode' ), tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/', $this->plugin_slug, 'wizard' ), - ); + __( 'Otter Blocks', 'wp-maintenance-mode' ), + __( 'It also unlocks tools like forms and popups - if you need them later.', 'wp-maintenance-mode' ), + ), + wpmm_translated_string_allowed_html() + ); ?>

From d1c8025cf238e72a46c80992bd04735286ddd3ae Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Fri, 11 Jul 2025 16:04:00 +0530 Subject: [PATCH 3/6] refactor: update description text --- assets/js/scripts-admin.js | 14 ++++++- .../classes/wp-maintenance-mode-admin.php | 39 ++++++++++++------- views/wizard.php | 25 +++++++----- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/assets/js/scripts-admin.js b/assets/js/scripts-admin.js index cedb547..933da4e 100644 --- a/assets/js/scripts-admin.js +++ b/assets/js/scripts-admin.js @@ -571,7 +571,19 @@ jQuery( function( $ ) { */ function addToPage( data, callback ) { if ($('.wpmm-templates-radio').hasClass('disabled')) { - data.category = ''; + $.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'; diff --git a/includes/classes/wp-maintenance-mode-admin.php b/includes/classes/wp-maintenance-mode-admin.php index 522d96d..76648e3 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' ) ); @@ -712,14 +709,10 @@ public function insert_template() { } $template_slug = $_POST['template_slug']; - $blocks = ''; - $category = 'maintenance'; - if ( ! empty( $_POST['category'] ) ) { - $category = $_POST['category']; - $template = json_decode( file_get_contents( WPMM_TEMPLATES_PATH . $category . '/' . $template_slug . '/blocks-export.json' ) ); + $category = $_POST['category']; + $template = json_decode( file_get_contents( WPMM_TEMPLATES_PATH . $category . '/' . $template_slug . '/blocks-export.json' ) ); - $blocks = str_replace( '\n', '', $template->content ); - } + $blocks = str_replace( '\n', '', $template->content ); $post_arr = array( 'post_type' => 'page', @@ -741,10 +734,8 @@ public function insert_template() { } $this->plugin_settings['design']['page_id'] = $page_id; + CSS_Handler::generate_css_file( $page_id ); - if ( is_plugin_active( 'otter-blocks/otter-blocks.php' ) ) { - CSS_Handler::generate_css_file( $page_id ); - } if ( 'wizard' === $_POST['source'] ) { $this->plugin_settings['general']['status'] = 1; @@ -756,6 +747,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 7550286..d577432 100644 --- a/views/wizard.php +++ b/views/wizard.php @@ -37,11 +37,15 @@ __( 'Pick a template to get started.', 'wp-maintenance-mode' ), tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/', $this->plugin_slug, 'wizard' ), __( 'Otter Blocks', 'wp-maintenance-mode' ), - __( 'It also unlocks tools like forms and popups - if you need them later.', 'wp-maintenance-mode' ), + __( 'plugin will be installed and activated to support and customize your layout.' , 'wp-maintenance-mode' ), ), wpmm_translated_string_allowed_html() ); ?> +
+

@@ -81,22 +85,23 @@

Optimole%2$s.', 'wp-maintenance-mode' ), - wpmm_translated_string_allowed_html() - ), + echo wp_kses( + sprintf( + '%1$s %3$s %4$s', + __( 'Templates would have pre-optimized images and all of your website’s images would be delivered via Amazon Cloudfront CDN, resulting in an ≈ 80% increase in speed.', 'wp-maintenance-mode' ), esc_url( 'https://wordpress.org/plugins/optimole-wp/' ), - $this->get_external_link_icon() - ); + 'Optimole', + __( 'plugin will be installed and activated.', 'wp-maintenance-mode' ), + ), + wpmm_translated_string_allowed_html(), + ); ?>

- +
From 4c77d3a57ee5ba9eacc4275eda91470bceee2e82 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Fri, 11 Jul 2025 16:09:18 +0530 Subject: [PATCH 4/6] fix:phpcs --- includes/classes/wp-maintenance-mode-admin.php | 5 ++--- views/wizard.php | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/includes/classes/wp-maintenance-mode-admin.php b/includes/classes/wp-maintenance-mode-admin.php index 76648e3..7721e34 100644 --- a/includes/classes/wp-maintenance-mode-admin.php +++ b/includes/classes/wp-maintenance-mode-admin.php @@ -709,8 +709,8 @@ public function insert_template() { } $template_slug = $_POST['template_slug']; - $category = $_POST['category']; - $template = json_decode( file_get_contents( WPMM_TEMPLATES_PATH . $category . '/' . $template_slug . '/blocks-export.json' ) ); + $category = $_POST['category']; + $template = json_decode( file_get_contents( WPMM_TEMPLATES_PATH . $category . '/' . $template_slug . '/blocks-export.json' ) ); $blocks = str_replace( '\n', '', $template->content ); @@ -736,7 +736,6 @@ public function insert_template() { $this->plugin_settings['design']['page_id'] = $page_id; CSS_Handler::generate_css_file( $page_id ); - if ( 'wizard' === $_POST['source'] ) { $this->plugin_settings['general']['status'] = 1; update_option( 'wpmm_fresh_install', false ); diff --git a/views/wizard.php b/views/wizard.php index d577432..59ef19d 100644 --- a/views/wizard.php +++ b/views/wizard.php @@ -33,11 +33,12 @@ %1$s %3$s %4$s', __( 'Pick a template to get started.', 'wp-maintenance-mode' ), tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/', $this->plugin_slug, 'wizard' ), __( 'Otter Blocks', 'wp-maintenance-mode' ), - __( 'plugin will be installed and activated to support and customize your layout.' , 'wp-maintenance-mode' ), + __( 'plugin will be installed and activated to support and customize your layout.', 'wp-maintenance-mode' ), ), wpmm_translated_string_allowed_html() ); @@ -87,6 +88,7 @@ %3$s %4$s', __( 'Templates would have pre-optimized images and all of your website’s images would be delivered via Amazon Cloudfront CDN, resulting in an ≈ 80% increase in speed.', 'wp-maintenance-mode' ), esc_url( 'https://wordpress.org/plugins/optimole-wp/' ), From 86dd47a4dd8b9e03fd78a09bed995777ab0d2a34 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Fri, 11 Jul 2025 17:10:19 +0530 Subject: [PATCH 5/6] fix: onboarding skip step --- assets/js/scripts-admin.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/assets/js/scripts-admin.js b/assets/js/scripts-admin.js index 933da4e..6eaa2b0 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' ); } ); } ); From 64d29c48061564f8d523394c71408c3ffe30786d Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Fri, 11 Jul 2025 18:35:53 +0530 Subject: [PATCH 6/6] refactor: install otter block plugin --- assets/js/scripts-admin.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/assets/js/scripts-admin.js b/assets/js/scripts-admin.js index 6eaa2b0..cdd5f72 100644 --- a/assets/js/scripts-admin.js +++ b/assets/js/scripts-admin.js @@ -617,16 +617,7 @@ jQuery( function( $ ) { if ( otterBlockCheckbox.length && otterBlockCheckbox.is( ':checked' ) ) { promiseChain = promiseChain - .then(() => handleOtter()) - .then(() => { - if ( ! wpmmVars.isOtterInstalled ) { - return installPlugin( 'otter-blocks' ).then( () => activatePlugin( 'otter-blocks' ) ); - } - - if ( ! wpmmVars.isOtterActive ) { - return activatePlugin( 'otter-blocks' ); - } - }); + .then(() => handleOtter()); } return promiseChain.catch( ( error ) => {