Skip to content

Add deactivation modal #822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions assets/css/litespeed.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ input[type='checkbox'].litespeed-tiny-toggle {
background: none;
box-shadow: none;
}

input[type='checkbox'].litespeed-tiny-toggle:focus {
box-shadow: none;
}

input[type='checkbox'].litespeed-tiny-toggle:after {
content: '';
font-size: 8px;
Expand All @@ -74,6 +76,7 @@ input[type='checkbox'].litespeed-tiny-toggle:after {
border-radius: 72px;
box-shadow: 0 0 12px rgb(0 0 0 / 15%) inset;
}

input[type='checkbox'].litespeed-tiny-toggle:before {
content: '';
width: 14px;
Expand All @@ -100,6 +103,7 @@ input[type='checkbox'].litespeed-tiny-toggle:checked:before,
input[type='checkbox'].litespeed-tiny-toggle:checked:after {
transition: ease 0.15s;
}

input[type='checkbox'].litespeed-tiny-toggle:checked:after {
/*content: 'ON';*/
background-color: #2271b1;
Expand All @@ -108,10 +112,12 @@ input[type='checkbox'].litespeed-tiny-toggle:checked:after {
.block-editor__container input[type='checkbox'].litespeed-tiny-toggle {
border: 0 !important;
}

.block-editor__container input[type='checkbox'].litespeed-tiny-toggle:before {
top: 5px;
left: 7px;
}

.block-editor__container input[type='checkbox'].litespeed-tiny-toggle:checked:before {
left: 23px;
}
Expand Down Expand Up @@ -3663,6 +3669,7 @@ p.litespeed-dashboard-unlock-footer {
.litespeed-body tbody > tr > th.litespeed-padding-left {
padding-left: 3em;
}

@media screen and (max-width: 680px) {
.litespeed-body tbody > tr > th.litespeed-padding-left {
padding-left: 10px;
Expand Down Expand Up @@ -4417,3 +4424,30 @@ a.litespeed-media-href svg:hover {
color: #dbdbdb;
font-size: 1rem;
}

/* =======================================
Deactivate modal
======================================= */
#litespeed-modal-deactivate {
padding: 20px;
}

#litespeed-modal-deactivate h2 {
margin: 0px;
}

#litespeed-modal-deactivate .litespeed-wrap {
margin: 10px 0px;
}

#litespeed-modal-deactivate .deactivate-clear-settings-wrapper,
#litespeed-modal-deactivate .deactivate-actions {
margin-top: 30px;
}

#litespeed-modal-deactivate .deactivate-reason-wrapper label,
#litespeed-modal-deactivate .deactivate-clear-settings-wrapper label {
width: 100%;
display: block;
margin-bottom: 5px;
}
51 changes: 41 additions & 10 deletions src/activation.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,61 @@ public static function register_activation() {
* Uninstall plugin
*
* @since 1.1.0
* @since 7.3 fix uninstall to remove all settings.
*/
public static function uninstall_litespeed_cache() {
Task::destroy();

// Delete options
foreach (Conf::cls()->load_default_vals() as $k => $v) {
Base::delete_option($k);
}
if (is_multisite() ) {
// Save main site id
$current_blog = get_current_blog_id();

// Delete site options
if (is_multisite()) {
foreach (Conf::cls()->load_default_site_vals() as $k => $v) {
Base::delete_site_option($k);
// get all sites
$sub_sites = get_sites();

// clear foreach site
foreach ($sub_sites as $sub_site) {
$sub_blog_id = (int) $sub_site->blog_id;
if ($sub_blog_id != $current_blog) {
// Switch to blog
switch_to_blog($sub_blog_id);

// Delete site options
self::delete_settings();

// Delete site tables
Data::cls()->tables_del();
}
}

// Return to main site
switch_to_blog($current_blog);
}

// Delete avatar table
// Delete current blog/site
// Delete options
self::delete_settings();

// Delete site tables
Data::cls()->tables_del();


if (file_exists(LITESPEED_STATIC_DIR)) {
File::rrmdir(LITESPEED_STATIC_DIR);
}

Cloud::version_check('uninstall');
}

/**
* Remove all litespeed settings.
*
* @since 7.3
*/
private static function delete_settings() {
global $wpdb;

// Files has been deleted when deactivated
$wpdb->query($wpdb->prepare("DELETE FROM `$wpdb->options` WHERE option_name LIKE '%s'", array( 'litespeed.%' )));
}

/**
Expand Down Expand Up @@ -258,6 +287,8 @@ public static function register_deactivation() {

self::_del_conf_data_file();

/* 6) delete option lscwp_whm_install */

// delete in case it's not deleted prior to deactivation.
GUI::dismiss_whm();
}
Expand Down
23 changes: 22 additions & 1 deletion src/admin-display.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ public function enqueue_style() {
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
* @since 1.0.0
* @since 7.3 - added deactivation modal code
* @access public
*/
public function enqueue_scripts() {
Expand Down Expand Up @@ -237,13 +238,33 @@ public function enqueue_scripts() {
}
}

// Load iziModal JS and CSS
$show_deactivation_modal = is_multisite() && !is_network_admin() ? false : true;
if ($show_deactivation_modal && $pagenow == 'plugins.php') {
wp_enqueue_script(Core::PLUGIN_NAME . '-iziModal', LSWCP_PLUGIN_URL . 'assets/js/iziModal.min.js', array(), Core::VER, 'all');
wp_enqueue_style(Core::PLUGIN_NAME . '-iziModal', LSWCP_PLUGIN_URL . 'assets/css/iziModal.min.css', array(), Core::VER, 'all');
add_action('admin_footer', array($this, 'add_deactivation_html'));
}

if ($localize_data) {
wp_localize_script(Core::PLUGIN_NAME, 'litespeed_data', $localize_data);
}

wp_enqueue_script(Core::PLUGIN_NAME);
}

/**
* Add modal html.
*
* @since 7.3
* @access public
* @return void
*/
public function add_deactivation_html()
{
require LSCWP_DIR . 'tpl/inc/modal.deactivation.php';
}

/**
* Babel type for crawler
*
Expand Down
2 changes: 1 addition & 1 deletion tpl/img_optm/summary.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
</div>
<div class="inside litespeed-postbox-footer litespeed-postbox-footer--compact">
<p>
<a href="<?php echo esc_url( Utility::build_url( Router::ACTION_IMG_OPTM, Img_Optm::TYPE_DESTROY ) ); ?>" class="litespeed-link-with-icon litespeed-danger" data-litespeed-cfm="<?php esc_html_e( 'Are you sure to destroy all optimized images?', 'litespeed-cache' ); ?>">
<a href="<?php echo esc_url( Utility::build_url( Router::ACTION_IMG_OPTM, Img_Optm::TYPE_DESTROY ) ); ?>" class="litespeed-link-with-icon litespeed-danger" data-litespeed-cfm="<?php esc_html_e( 'Are you sure to destroy all optimized images?', 'litespeed-cache' ); ?>" id="litespeed-imageopt-destroy">
<span class="dashicons dashicons-dismiss"></span><?php esc_html_e( 'Destroy All Optimization Data', 'litespeed-cache' ); ?>
</a>
</p>
Expand Down
170 changes: 170 additions & 0 deletions tpl/inc/modal.deactivation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php
/**
* LiteSpeed Cache Deactivation Modal
*
* Renders the deactivation modal interface for LiteSpeed Cache, allowing users to send reason of deactivation.
*
* @package LiteSpeed
* @since 7.3
*/

namespace LiteSpeed;

defined( 'WPINC' ) || exit;

// Modal data
$_title = esc_html__('Deactivate LiteSpeed Cache', 'litespeed');
$_id = 'litespeed-modal-deactivate';

$reasons = array(
array(
'value' => 'Temporary',
'text' => esc_html__('The deactivation is temporary', 'litespeed-cache'),
'id' => 'temp',
'selected' => true,
),
array(
'value' => 'Performance worse',
'text' => esc_html__('Site performance is worse', 'litespeed-cache'),
'id' => 'performance',
),
array(
'value' => 'Plugin complicated',
'text' => esc_html__('Plugin is too complicated', 'litespeed-cache'),
'id' => 'complicated',
),
array(
'value' => 'Other',
'text' => esc_html__('Other', 'litespeed-cache'),
'id' => 'other',
),
);
?>
<div style="display: none">
<div id="litespeed-deactivation" class="iziModal">
<div id="litespeed-modal-deactivate">
<form id="litespeed-deactivation-form" method="post">
<p><?php esc_attr_e('Why are you deactivating the plugin?', 'litespeed-cache'); ?></p>
<div class="deactivate-reason-wrapper">
<?php
foreach ($reasons as $reason) {
echo '<label for="litespeed-deactivate-reason-' .
esc_html__( $reason['id'] ) .
'">
<input type="radio"
id="litespeed-deactivate-reason-' .
esc_html__( $reason['id'] ) .
'"
value="' .
esc_html__( $reason['value'] ) .
'"
' .
(isset($reason['selected']) && $reason['selected'] ? ' checked="checked"' : '') .
'
name="litespeed-reason"
/>
' .
esc_html__( $reason['text'] ) .
'
</label>';
}
?>
</div>
<div class="deactivate-clear-settings-wrapper">
<i style="font-size: 0.9em;">
<?php
esc_html_e('On uninstall, all plugin settings will be deleted.', 'litespeed-cache');
?>
</i>
<br />
<i style="font-size: 0.9em;">

<?php
printf(
esc_html__('If you have used Image Optimization, please %sDestroy All Optimization Data%s first. NOTE: this does not remove your optimized images.', 'litespeed-cache'),
'<a href="admin.php?page=litespeed-img_optm#litespeed-imageopt-destroy" target="_blank">',
'</a>'
);
?>
</i>
</div>
<div class="deactivate-actions">
<input
type="button"
id="litespeed-deactivation-form-cancel"
class="button litespeed-btn-warning"
value="<?php esc_attr_e('Cancel', 'litespeed-cache'); ?>"
title="<?php esc_attr_e('Close popup', 'litespeed-cache'); ?>" />
<input
type="submit"
id="litespeed-deactivation-form-submit"
class="button button-primary"
value="<?php esc_attr_e('Deactivate', 'litespeed-cache'); ?>"
title="<?php esc_attr_e('Deactivate plugin', 'litespeed-cache'); ?>" />
<br />
</div>
</form>
</div>
</div>
</div>
<script>
(function ($) {
'use strict';
jQuery(document).ready(function () {
var lscId = '<?php echo home_url(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>';
var modalesc_attr_element = $('#litespeed-deactivation');
var deactivateesc_attr_element = $('#deactivate-litespeed-cache');

if (deactivateesc_attr_element.length > 0 && modalesc_attr_element.length > 0) {
// Variables
var modal_formElement = $('#litespeed-deactivation-form');

deactivateesc_attr_element.on('click', function (e) {
e.preventDefault();
e.stopImmediatePropagation();
modal_formElement.attr('action', decodeURI($(this).attr('href')));
modalesc_attr_element.iziModal({
radius: '.5rem',
width: 550,
autoOpen: true,
});
});

$(document).on('submit', '#litespeed-deactivation-form', function (e) {
e.preventDefault();
$('#litespeed-deactivation-form-submit').attr('disabled', true);
var container = $('#litespeed-deactivation-form');

// Save selected data
var data = {
id: lscId,
siteLink: window.location.hostname,
reason: $(container).find('[name=litespeed-reason]:checked').val()
};

$.ajax({
url: 'https://wpapi.quic.cloud/survey',
dataType: 'json',
method: 'POST',
cache: false,
data: data,
beforeSend: function (xhr) {
//xhr.setRequestHeader('X-WP-Nonce', litespeed_data.nonce);
},
success: function (data) {
console.log('QC data sent.');
},
error: function (xhr, error) {
console.log('Error sending data to QC.');
},
});

$('#litespeed-deactivation-form')[0].submit();
});
$(document).on('click', '#litespeed-deactivation-form-cancel', function (e) {
modalesc_attr_element.iziModal('close');
});
}
});
})(jQuery);
</script>