PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.6.1
Defender Security – Malware Scanner, Login Security & Firewall v5.6.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / uninstall.php

uninstall.php in Defender Security – Malware Scanner, Login Security & Firewall 5.6.1, at uninstall.php

133 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if uninstall is not called from WordPress.
3 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
4 exit();
5 }
6
7 /**
8 * Drop custom tables.
9 *
10 * @since 2.4
11 */
12 function defender_drop_custom_tables() {
13 global $wpdb;
14
15 $wpdb->hide_errors();
16
17 defender_drop_custom_fk_constraint( $wpdb->prefix . 'defender_quarantine' );
18
19 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_email_log" );
20 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_scan_item" );
21 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_scan" );
22 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_lockout_log" );
23 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_lockout" );
24 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_audit_log" );
25 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_unlockout" );
26 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_antibot" );
27 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_quarantine" );
28 }
29
30 /**
31 * Drop custom tables.
32 *
33 * @since 4.0.0
34 */
35 function defender_drop_custom_fk_constraint( string $table_name ): void {
36 global $wpdb;
37
38 $results = $wpdb->get_results(
39 "SELECT CONSTRAINT_NAME
40 FROM information_schema.TABLE_CONSTRAINTS
41 WHERE CONSTRAINT_SCHEMA = '{$wpdb->dbname}'
42 AND CONSTRAINT_TYPE = 'FOREIGN KEY'
43 AND TABLE_NAME = '{$table_name}'"
44 );
45
46 if ( $results ) {
47 foreach ( $results as $fk ) {
48 $wpdb->query( "ALTER TABLE {$table_name} DROP FOREIGN KEY {$fk->CONSTRAINT_NAME}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
49 }
50 }
51 }
52
53 require_once __DIR__ . DIRECTORY_SEPARATOR . 'wp-defender.php';
54 require_once __DIR__ . DIRECTORY_SEPARATOR . 'extra/hub-connector/connector.php';
55 \WPMUDEV\Hub\Connector::get();
56 $settings = wd_di()->get( \WP_Defender\Model\Setting\Main_Setting::class );
57 $uninstall_data = isset( $settings->uninstall_data ) && 'remove' === $settings->uninstall_data;
58 $uninstall_settings = isset( $settings->uninstall_settings ) && 'reset' === $settings->uninstall_settings;
59
60 if ( $uninstall_settings || $uninstall_data ) {
61 // Turn off Audit_Logging so that hooks are not processed after deleting the table or resetting settings.
62 $audit = wd_di()->get( \WP_Defender\Model\Setting\Audit_Logging::class );
63 $audit->enabled = false;
64 $audit->save();
65 $advanced_tools = wd_di()->get( \WP_Defender\Controller\Advanced_Tools::class );
66
67 // Only Settings.
68 if ( $uninstall_settings ) {
69 // Remove all settings of Advanced Tools.
70 $advanced_tools->remove_settings();
71 wd_di()->get( \WP_Defender\Controller\Audit_Logging::class )->remove_settings();
72 wd_di()->get( \WP_Defender\Controller\Dashboard::class )->remove_settings();
73 wd_di()->get( \WP_Defender\Controller\Security_Tweaks::class )->remove_settings();
74 wd_di()->get( \WP_Defender\Controller\Scan::class )->remove_settings();
75 // Start of Firewall parent and submodules.
76 wd_di()->get( \WP_Defender\Controller\Firewall::class )->remove_settings();
77 // End.
78 wd_di()->get( \WP_Defender\Controller\Notification::class )->remove_settings();
79 wd_di()->get( \WP_Defender\Controller\Two_Factor::class )->remove_settings();
80 wd_di()->get( \WP_Defender\Controller\Blocklist_Monitor::class )->remove_settings();
81 wd_di()->get( \WP_Defender\Controller\Main_Setting::class )->remove_settings();
82 wd_di()->get( \WP_Defender\Controller\Onboard::class )->remove_settings();
83 // Delete plugin options.
84 delete_option( 'wp_defender' );
85 delete_site_option( 'wp_defender' );
86 delete_option( 'wd_db_version' );
87 delete_site_option( 'wd_db_version' );
88 delete_site_option( 'wpdefender_config_clear_active_tag' );
89 delete_site_option( 'wpdefender_preset_configs_transient_time' );
90 delete_site_option( 'wp_defender_config_default' );
91 delete_site_option( 'disable-xml-rpc' );
92 // Because not call remove_settings from WAF and Onboard controllers.
93 delete_site_transient( 'def_waf_status' );
94 delete_site_option( 'wp_defender_is_activated' );
95 delete_site_transient( \WP_Defender\Component\Blacklist_Lockout::IP_LIST_KEY );
96 delete_site_transient( 'defender_run_background' );
97 }
98 // Only Data.
99 if ( $uninstall_data ) {
100 wd_di()->get( \WP_Defender\Controller\Audit_Logging::class )->remove_data();
101 wd_di()->get( \WP_Defender\Controller\Dashboard::class )->remove_data();
102 wd_di()->get( \WP_Defender\Controller\Security_Tweaks::class )->remove_data();
103 wd_di()->get( \WP_Defender\Controller\Scan::class )->remove_data();
104 // Remove all data of Firewall.
105 wd_di()->get( \WP_Defender\Controller\Firewall::class )->remove_data();
106 wd_di()->get( \WP_Defender\Controller\Notification::class )->remove_data();
107 wd_di()->get( \WP_Defender\Controller\Two_Factor::class )->remove_data();
108 wd_di()->get( \WP_Defender\Component\Backup_Settings::class )->clear_configs();
109 // Remove all data of Advanced Tools.
110 $advanced_tools->remove_data();
111 defender_drop_custom_tables();
112 wd_di()->get( \WP_Defender\Component\Network_Cron_Manager::class )->remove_data();
113 }
114 }
115
116 if ( class_exists( 'WP_Defender\Controller\Quarantine' ) ) {
117 // Quarantine.
118 // All decision making logic added inside the quarantine component core method on_uninstall.
119 wd_di()->get( \WP_Defender\Controller\Quarantine::class )->remove_data();
120 }
121
122 // Complete cleaning.
123 if ( $uninstall_settings && $uninstall_data ) {
124 delete_site_option( 'wd_nofresh_install' );
125 \WP_Defender\Component\Feature_Modal::delete_modal_key();
126 \WP_Defender\Controller\Data_Tracking::delete_modal_key();
127 wd_di()->get( \WP_Defender\Controller\Rate::class )->remove_data();
128 \WP_Defender\Component\Firewall::delete_slugs();
129 }
130 // Remains from old versions.
131 delete_site_option( 'wd_audit_cached' );
132 delete_site_option( 'wd_show_ip_detection_notice' );
133