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

Open
wants to merge 1 commit into
base: v7.2
Choose a base branch
from
Open
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 @@ -53,9 +53,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 @@ -70,6 +72,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 @@ -96,6 +99,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 @@ -104,10 +108,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 @@ -3659,6 +3665,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 @@ -4413,3 +4420,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;
}
59 changes: 59 additions & 0 deletions assets/js/litespeed-cache-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,65 @@ var _litespeed_dots;
$(this).addClass('disabled');
});
}

/**
* Deactivate link
*/
var modal_element = $('#litespeed-deactivation');
if ($('#deactivate-litespeed-cache').length > 0 && modal_element.length > 0) {
// Variables
var modal_formElement = $('#litespeed-deactivation-form');

$('#deactivate-litespeed-cache').on('click', function (e) {
e.preventDefault();
e.stopImmediatePropagation();
modal_formElement.attr('action', decodeURI($(this).attr('href')));
modal_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');
let deleteSite = $(container).find('#litespeed-deactivate-clear').is(':checked');
let deleteNetwork = $(container).find('#litespeed-deactivate-network').is(':checked');

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

$.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) {
modal_element.iziModal('close');
});
}
});
})(jQuery);

Expand Down
68 changes: 54 additions & 14 deletions src/activation.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ public static function uninstall_litespeed_cache()
{
Task::destroy();

// Delete options
foreach (Conf::cls()->load_default_vals() as $k => $v) {
Base::delete_option($k);
}

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

// Delete avatar table
Data::cls()->tables_del();

Expand All @@ -109,8 +97,6 @@ public static function uninstall_litespeed_cache()
}

Cloud::version_check('uninstall');

// Files has been deleted when deactivated
}

/**
Expand Down Expand Up @@ -222,6 +208,46 @@ public static function register_deactivation()

Purge::purge_all();

// 0. Delete all sites data on request from modal
// If clear current blog
if (isset($_POST['lsc-clear']) && $_POST['lsc-clear'] == 'true') {
// Delete options
self::delete_site_settings();

// Delete avatar table
self::delete_site_tables();

// Cloud uninstall
Cloud::version_check('uninstall');
}

// if clear network wide settings
if (is_multisite() && isset($_POST['lsc-clear-network']) && $_POST['lsc-clear-network'] == 'true') {
$current_blog = get_current_blog_id();
// get all sites
$subsites = get_sites();

// clear foreach site
foreach ($subsites as $subsite) {
$sub_blog_id = (int) $subsite->blog_id;
if (isset($sub_blog_id) && $sub_blog_id != $current_blog) {
// Switch to blog
switch_to_blog($sub_blog_id);

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

// Delete avatar table
self::delete_site_tables();

// Cloud uninstall
Cloud::version_check('uninstall');
}
}

switch_to_blog($current_blog);
}

if (is_multisite()) {
if (!self::is_deactivate_last()) {
if (is_network_admin()) {
Expand Down Expand Up @@ -264,10 +290,24 @@ 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();
}

private static function delete_site_settings()
{
global $wpdb;

$wpdb->query($wpdb->prepare("DELETE FROM `$wpdb->options` WHERE option_name LIKE '%s'", array('litespeed.%')));
}

private static function delete_site_tables()
{
Data::cls()->tables_del();
}

/**
* Manage related files based on plugin latest conf
*
Expand Down
20 changes: 19 additions & 1 deletion src/admin-display.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,32 @@ public function enqueue_scripts()
}
}

// Load iziModal JS and CSS
if ($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 .
*
* @since 1.0.0
* @access public
* @return void
*/
public function add_deactivation_html()
{
require LSCWP_DIR . 'tpl/inc/modal.deactivation.php';
}

/**
* Babel type for crawler
*
Expand All @@ -291,7 +310,6 @@ public function babel_type($tag, $handle, $src)
*/
public function add_plugin_links($links)
{
// $links[] = '<a href="' . admin_url('options-general.php?page=litespeed-cache') . '">' . __('Settings', 'litespeed-cache') . '</a>';
$links[] = '<a href="' . admin_url('admin.php?page=litespeed-cache') . '">' . __('Settings', 'litespeed-cache') . '</a>';

return $links;
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 @@ -315,7 +315,7 @@
</div>
</div>
<div class="inside litespeed-postbox-footer litespeed-postbox-footer--compact">
<p><a href="<?php echo Utility::build_url(Router::ACTION_IMG_OPTM, Img_Optm::TYPE_DESTROY); ?>" class="litespeed-link-with-icon litespeed-danger" data-litespeed-cfm="<?php echo __('Are you sure to destroy all optimized images?', 'litespeed-cache'); ?>">
<p><a href="<?php echo Utility::build_url(Router::ACTION_IMG_OPTM, Img_Optm::TYPE_DESTROY); ?>" class="litespeed-link-with-icon litespeed-danger" data-litespeed-cfm="<?php echo __('Are you sure to destroy all optimized images?', 'litespeed-cache'); ?>" id="litespeed-imageopt-destroy">
<span class="dashicons dashicons-dismiss"></span><?php echo __('Destroy All Optimization Data', 'litespeed-cache'); ?>
</a></p>

Expand Down
Loading