Skip to content

Commit

Permalink
Merge pull request #323 from CleanTalk/register_uninstall_hook.ag
Browse files Browse the repository at this point in the history
register_uninstall_hook
  • Loading branch information
alexandergull authored Nov 20, 2023
2 parents dc3276c + 8ee8227 commit 81a1f4d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions cleantalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,15 @@ function apbct_deactivation($network_wide)
Deactivator::deactivation($network_wide);
}

register_uninstall_hook(__FILE__, 'apbct_uninstall');
function apbct_uninstall($network_wide)
{
global $apbct;
$apbct->settings['misc__complete_deactivation'] = 1;
$apbct->saveSettings();
Deactivator::deactivation($network_wide);
}

// Hook for newly added blog
if ( version_compare($wp_version, '5.1') >= 0 ) {
add_action('wp_initialize_site', 'apbct_activation__new_blog', 10, 2);
Expand Down
18 changes: 16 additions & 2 deletions lib/Cleantalk/ApbctWP/Deactivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Cleantalk\ApbctWP;

use Cleantalk\ApbctWP\Firewall\SFWUpdateHelper;

class Deactivator
{
public static function deactivation($network_wide)
{
global $apbct, $wpdb;

if ( ! is_multisite() ) {
// Deactivation on standalone blog

Expand All @@ -17,6 +18,7 @@ public static function deactivation($network_wide)
if ( $apbct->settings['misc__complete_deactivation'] ) {
self::deleteAllOptions();
self::deleteMeta();
self::deleteSFWUpdateFolder();
}
} elseif ( $network_wide ) {
// Deactivation for network
Expand All @@ -32,6 +34,7 @@ public static function deactivation($network_wide)
self::deleteAllOptions();
self::deleteMeta();
self::deleteAllOptionsInNetwork();
self::deleteSFWUpdateFolder();
}
}
switch_to_blog($initial_blog);
Expand All @@ -44,6 +47,7 @@ public static function deactivation($network_wide)
if ( $apbct->settings['misc__complete_deactivation'] ) {
self::deleteAllOptions();
self::deleteMeta();
self::deleteSFWUpdateFolder();
}
}
}
Expand All @@ -57,7 +61,7 @@ public static function deleteAllOptions()

$wild = '%';
$find = 'cleantalk';
$like = $wpdb->esc_like($find) . $wild;
$like = $wild . $wpdb->esc_like($find) . $wild;
$sql = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE %s", $like);

$wpdb->query($sql);
Expand Down Expand Up @@ -90,6 +94,7 @@ public static function deleteTables($prefix)
); // Deleting user/comments scan result table
$wpdb->query('DROP TABLE IF EXISTS `' . $prefix . 'cleantalk_ua_bl`;'); // Deleting AC UA black lists
$wpdb->query('DROP TABLE IF EXISTS `' . $prefix . 'cleantalk_sfw_temp`;'); // Deleting temporary SFW data
$wpdb->query('DROP TABLE IF EXISTS `' . $prefix . 'cleantalk_sfw_personal_temp`;'); // Deleting temporary SFW data
$wpdb->query('DROP TABLE IF EXISTS `' . $prefix . 'cleantalk_connection_reports`;'); // Deleting connection_reports
$wpdb->query('DROP TABLE IF EXISTS `' . $prefix . 'cleantalk_wc_spam_orders`;');
}
Expand All @@ -103,5 +108,14 @@ public static function deleteMeta()
$wpdb->query(
"DELETE FROM $wpdb->usermeta WHERE meta_key IN ('ct_bad', 'ct_checked', 'ct_checked_now', 'ct_marked_as_spam', 'ct_hash');"
);
delete_post_meta_by_key('cleantalk_order_request_id');
}

private static function deleteSFWUpdateFolder()
{
$current_blog_id = get_current_blog_id();
$wp_upload_dir = wp_upload_dir();
$update_folder = $wp_upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'cleantalk_fw_files_for_blog_' . $current_blog_id . DIRECTORY_SEPARATOR;
SFWUpdateHelper::removeUpdFolder($update_folder);
}
}

0 comments on commit 81a1f4d

Please sign in to comment.