| 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 |
$fk_checks = $wpdb->get_var( 'SELECT @@FOREIGN_KEY_CHECKS' ); |
| 17 |
$fk_checks = null === $fk_checks ? 1 : (int) $fk_checks; |
| 18 |
$wpdb->query( 'SET FOREIGN_KEY_CHECKS = 0' ); |
| 19 |
defender_drop_custom_fk_constraint( $wpdb->prefix . 'defender_quarantine' ); |
| 20 |
|
| 21 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_email_log" ); |
| 22 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_scan_item" ); |
| 23 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_scan" ); |
| 24 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_lockout_log" ); |
| 25 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_lockout" ); |
| 26 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_audit_log" ); |
| 27 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_unlockout" ); |
| 28 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_antibot" ); |
| 29 |
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_quarantine" ); |
| 30 |
$wpdb->query( 'SET FOREIGN_KEY_CHECKS = ' . $fk_checks ); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Drop custom tables. |
| 35 |
* |
| 36 |
* @since 4.0.0 |
| 37 |
*/ |
| 38 |
function defender_drop_custom_fk_constraint( string $table_name ): void { |
| 39 |
global $wpdb; |
| 40 |
|
| 41 |
$results = $wpdb->get_results( |
| 42 |
"SELECT CONSTRAINT_NAME |
| 43 |
FROM information_schema.TABLE_CONSTRAINTS |
| 44 |
WHERE CONSTRAINT_SCHEMA = '{$wpdb->dbname}' |
| 45 |
AND CONSTRAINT_TYPE = 'FOREIGN KEY' |
| 46 |
AND TABLE_NAME = '{$table_name}'" |
| 47 |
); |
| 48 |
|
| 49 |
if ( $results ) { |
| 50 |
foreach ( $results as $fk ) { |
| 51 |
$wpdb->query( "ALTER TABLE {$table_name} DROP FOREIGN KEY {$fk->CONSTRAINT_NAME}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
require_once __DIR__ . DIRECTORY_SEPARATOR . 'wp-defender.php'; |
| 57 |
require_once __DIR__ . DIRECTORY_SEPARATOR . 'extra/hub-connector/connector.php'; |
| 58 |
\WPMUDEV\Hub\Connector::get(); |
| 59 |
$settings = wd_di()->get( \WP_Defender\Model\Setting\Main_Setting::class ); |
| 60 |
$uninstall_data = isset( $settings->uninstall_data ) && 'remove' === $settings->uninstall_data; |
| 61 |
$uninstall_settings = isset( $settings->uninstall_settings ) && 'reset' === $settings->uninstall_settings; |
| 62 |
|
| 63 |
if ( $uninstall_settings || $uninstall_data ) { |
| 64 |
// Turn off Audit_Logging so that hooks are not processed after deleting the table or resetting settings. |
| 65 |
$audit = wd_di()->get( \WP_Defender\Model\Setting\Audit_Logging::class ); |
| 66 |
$audit->enabled = false; |
| 67 |
$audit->save(); |
| 68 |
$login_access = wd_di()->get( \WP_Defender\Controller\Login_Access::class ); |
| 69 |
|
| 70 |
// Only Settings. |
| 71 |
if ( $uninstall_settings ) { |
| 72 |
// Remove all settings of 'Login & Access'. |
| 73 |
$login_access->remove_settings(); |
| 74 |
wd_di()->get( \WP_Defender\Controller\Audit_Logging::class )->remove_settings(); |
| 75 |
wd_di()->get( \WP_Defender\Controller\Dashboard::class )->remove_settings(); |
| 76 |
wd_di()->get( \WP_Defender\Controller\Security_Tweaks::class )->remove_settings(); |
| 77 |
wd_di()->get( \WP_Defender\Controller\Scan::class )->remove_settings(); |
| 78 |
// Start of Firewall parent and submodules. |
| 79 |
wd_di()->get( \WP_Defender\Controller\Firewall::class )->remove_settings(); |
| 80 |
// End. |
| 81 |
wd_di()->get( \WP_Defender\Controller\Notification::class )->remove_settings(); |
| 82 |
wd_di()->get( \WP_Defender\Controller\Two_Factor::class )->remove_settings(); |
| 83 |
wd_di()->get( \WP_Defender\Controller\Blocklist_Monitor::class )->remove_settings(); |
| 84 |
wd_di()->get( \WP_Defender\Controller\Main_Setting::class )->remove_settings(); |
| 85 |
wd_di()->get( \WP_Defender\Controller\Setup_Wizard::class )->remove_settings(); |
| 86 |
wd_di()->get( \WP_Defender\Controller\Activity_Log::class )->remove_settings(); |
| 87 |
wd_di()->get( \WP_Defender\Controller\Data_Tracking::class )->remove_settings(); |
| 88 |
|
| 89 |
// Delete plugin options. |
| 90 |
delete_option( 'wp_defender' ); |
| 91 |
delete_site_option( 'wp_defender' ); |
| 92 |
delete_option( 'wd_db_version' ); |
| 93 |
delete_site_option( 'wd_db_version' ); |
| 94 |
delete_site_option( 'wpdefender_config_clear_active_tag' ); |
| 95 |
delete_site_option( 'wpdefender_preset_configs_transient_time' ); |
| 96 |
delete_site_option( 'wp_defender_config_default' ); |
| 97 |
delete_site_option( 'disable-xml-rpc' ); |
| 98 |
|
| 99 |
// Because not call remove_settings from WAF controller. |
| 100 |
delete_site_transient( 'def_waf_status' ); |
| 101 |
delete_site_option( 'wp_defender_is_activated' ); |
| 102 |
delete_site_transient( \WP_Defender\Component\Blacklist_Lockout::IP_LIST_KEY ); |
| 103 |
|
| 104 |
// Ensure a clean installation of the plugin. |
| 105 |
delete_site_option( 'wp_defender_shown_activator' ); |
| 106 |
delete_site_option( 'wp_defender_is_free_activated' ); |
| 107 |
delete_site_option( 'wd_wizard_setup_resume_notice' ); |
| 108 |
delete_site_option( 'wd_onboarding_data' ); |
| 109 |
delete_site_option( 'wp_defender_onboarding_step' ); |
| 110 |
delete_site_option( 'wp_defender_onboard_antibot_reminder' ); |
| 111 |
} |
| 112 |
// Only Data. |
| 113 |
if ( $uninstall_data ) { |
| 114 |
wd_di()->get( \WP_Defender\Controller\Audit_Logging::class )->remove_data(); |
| 115 |
wd_di()->get( \WP_Defender\Controller\Dashboard::class )->remove_data(); |
| 116 |
wd_di()->get( \WP_Defender\Controller\Security_Tweaks::class )->remove_data(); |
| 117 |
wd_di()->get( \WP_Defender\Controller\Scan::class )->remove_data(); |
| 118 |
// Remove all data of Firewall. |
| 119 |
wd_di()->get( \WP_Defender\Controller\Firewall::class )->remove_data(); |
| 120 |
wd_di()->get( \WP_Defender\Controller\Notification::class )->remove_data(); |
| 121 |
wd_di()->get( \WP_Defender\Controller\Two_Factor::class )->remove_data(); |
| 122 |
wd_di()->get( \WP_Defender\Component\Backup_Settings::class )->clear_configs(); |
| 123 |
// Remove all data of 'Login & Access'. |
| 124 |
$login_access->remove_data(); |
| 125 |
defender_drop_custom_tables(); |
| 126 |
wd_di()->get( \WP_Defender\Component\Network_Cron_Manager::class )->remove_data(); |
| 127 |
wd_di()->get( \WP_Defender\Controller\Data_Tracking::class )->remove_data(); |
| 128 |
} |
| 129 |
} |
| 130 |
if ( class_exists( 'WP_Defender\Controller\Quarantine' ) ) { |
| 131 |
// All decision-making logic added inside the quarantine component core method on_uninstall. |
| 132 |
wd_di()->get( \WP_Defender\Controller\Quarantine::class )->remove_data(); |
| 133 |
} |
| 134 |
|
| 135 |
// Complete cleaning. |
| 136 |
if ( $uninstall_settings && $uninstall_data ) { |
| 137 |
delete_site_option( 'wd_nofresh_install' ); |
| 138 |
delete_site_option( 'wd_pro_tables_created' ); |
| 139 |
|
| 140 |
\WP_Defender\Component\Feature_Modal::delete_modal_key(); |
| 141 |
\WP_Defender\Controller\Data_Tracking::delete_modal_key(); |
| 142 |
wd_di()->get( \WP_Defender\Controller\Rate::class )->remove_data(); |
| 143 |
\WP_Defender\Component\Firewall::delete_slugs(); |
| 144 |
delete_site_option( \WP_Defender\Helper\Analytics\Deactivation_Survey::EVENT_DATA_OPTION ); |
| 145 |
} |
| 146 |
// Remains from old versions. |
| 147 |
delete_site_option( 'wd_audit_cached' ); |
| 148 |
delete_site_option( 'wd_show_ip_detection_notice' ); |
| 149 |
|