| @@ -3,13 +3,8 @@ | ||
| 3 | 3 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 4 | 4 | exit(); |
| 5 | 5 | } |
| 6 | 6 | |
| 7 | -if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { | |
| 8 | - // php 5.2 does not need uninstall. | |
| 9 | - return; | |
| 10 | -} | |
| 11 | - | |
| 12 | 7 | /** |
| 13 | 8 | * Drop custom tables. |
| 14 | 9 | * |
| 15 | 10 | * @since 2.4 |
| @@ -17,8 +12,12 @@ | ||
| 17 | 12 | function defender_drop_custom_tables() { |
| 18 | 13 | global $wpdb; |
| 19 | 14 | |
| 20 | 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' ); | |
| 21 | 20 | |
| 22 | 21 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_email_log" ); |
| 23 | 22 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_scan_item" ); |
| 24 | 23 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_scan" ); |
| @@ -24,11 +23,40 @@ | ||
| 24 | 23 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_scan" ); |
| 25 | 24 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_lockout_log" ); |
| 26 | 25 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}defender_lockout" ); |
| 27 | 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 ); | |
| 28 | 31 | } |
| 29 | 32 | |
| 30 | -include_once __DIR__ . DIRECTORY_SEPARATOR . 'wp-defender.php'; | |
| 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(); | |
| 31 | 59 | $settings = wd_di()->get( \WP_Defender\Model\Setting\Main_Setting::class ); |
| 32 | 60 | $uninstall_data = isset( $settings->uninstall_data ) && 'remove' === $settings->uninstall_data; |
| 33 | 61 | $uninstall_settings = isset( $settings->uninstall_settings ) && 'reset' === $settings->uninstall_settings; |
| 34 | 62 | |
| @@ -36,62 +64,85 @@ | ||
| 36 | 64 | // Turn off Audit_Logging so that hooks are not processed after deleting the table or resetting settings. |
| 37 | 65 | $audit = wd_di()->get( \WP_Defender\Model\Setting\Audit_Logging::class ); |
| 38 | 66 | $audit->enabled = false; |
| 39 | 67 | $audit->save(); |
| 40 | - $advanced_tools = wd_di()->get( \WP_Defender\Controller\Advanced_Tools::class ); | |
| 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 | + } | |
| 41 | 129 | } |
| 42 | -// Only Settings. | |
| 43 | -if ( $uninstall_settings ) { | |
| 44 | - $advanced_tools->remove_settings(); | |
| 45 | - wd_di()->get( \WP_Defender\Controller\Audit_Logging::class )->remove_settings(); | |
| 46 | - wd_di()->get( \WP_Defender\Controller\Dashboard::class )->remove_settings(); | |
| 47 | - wd_di()->get( \WP_Defender\Controller\Security_Tweaks::class )->remove_settings(); | |
| 48 | - wd_di()->get( \WP_Defender\Controller\Scan::class )->remove_settings(); | |
| 49 | - wd_di()->get( \WP_Defender\Controller\Firewall::class )->remove_settings(); | |
| 50 | - wd_di()->get( \WP_Defender\Controller\Firewall_Logs::class )->remove_settings(); | |
| 51 | - wd_di()->get( \WP_Defender\Controller\Login_Lockout::class )->remove_settings(); | |
| 52 | - wd_di()->get( \WP_Defender\Controller\Nf_Lockout::class )->remove_settings(); | |
| 53 | - wd_di()->get( \WP_Defender\Controller\Mask_Login::class )->remove_settings(); | |
| 54 | - wd_di()->get( \WP_Defender\Controller\Tutorial::class )->remove_settings(); | |
| 55 | - wd_di()->get( \WP_Defender\Controller\Notification::class )->remove_settings(); | |
| 56 | - wd_di()->get( \WP_Defender\Controller\Two_Factor::class )->remove_settings(); | |
| 57 | - wd_di()->get( \WP_Defender\Controller\Blocklist_Monitor::class )->remove_settings(); | |
| 58 | - wd_di()->get( \WP_Defender\Controller\Main_Setting::class )->remove_settings(); | |
| 59 | - // Delete plugin options. | |
| 60 | - delete_option( 'wp_defender' ); | |
| 61 | - delete_site_option( 'wp_defender' ); | |
| 62 | - delete_option( 'wd_db_version' ); | |
| 63 | - delete_site_option( 'wd_db_version' ); | |
| 64 | - delete_site_option( 'wpdefender_config_clear_active_tag' ); | |
| 65 | - delete_site_option( 'wpdefender_preset_configs_transient_time' ); | |
| 66 | - delete_site_option( 'wp_defender_config_default' ); | |
| 67 | - // Because not call remove_settings from WAF and Onboard controllers. | |
| 68 | - delete_site_transient( 'def_waf_status' ); | |
| 69 | - delete_site_option( 'wp_defender_is_activated' ); | |
| 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(); | |
| 70 | 133 | } |
| 71 | -// Only Data. | |
| 72 | -if ( $uninstall_data ) { | |
| 73 | - wd_di()->get( \WP_Defender\Controller\Audit_Logging::class )->remove_data(); | |
| 74 | - wd_di()->get( \WP_Defender\Controller\Dashboard::class )->remove_data(); | |
| 75 | - wd_di()->get( \WP_Defender\Controller\Security_Tweaks::class )->remove_data(); | |
| 76 | - wd_di()->get( \WP_Defender\Controller\Scan::class )->remove_data(); | |
| 77 | - wd_di()->get( \WP_Defender\Controller\Firewall::class )->remove_data(); | |
| 78 | - wd_di()->get( \WP_Defender\Controller\Firewall_Logs::class )->remove_data(); | |
| 79 | - wd_di()->get( \WP_Defender\Controller\Login_Lockout::class )->remove_data(); | |
| 80 | - wd_di()->get( \WP_Defender\Controller\Nf_Lockout::class )->remove_data(); | |
| 81 | - wd_di()->get( \WP_Defender\Controller\Mask_Login::class )->remove_data(); | |
| 82 | - wd_di()->get( \WP_Defender\Controller\Notification::class )->remove_data(); | |
| 83 | - wd_di()->get( \WP_Defender\Controller\Tutorial::class )->remove_data(); | |
| 84 | - wd_di()->get( \WP_Defender\Controller\Two_Factor::class )->remove_data(); | |
| 85 | - wd_di()->get( \WP_Defender\Controller\Webauthn::class )->remove_data(); | |
| 86 | - wd_di()->get( \WP_Defender\Component\Backup_Settings::class )->clear_configs(); | |
| 87 | - $advanced_tools->remove_data(); | |
| 88 | - defender_drop_custom_tables(); | |
| 89 | -} | |
| 134 | + | |
| 90 | 135 | // Complete cleaning. |
| 91 | 136 | if ( $uninstall_settings && $uninstall_data ) { |
| 92 | 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 ); | |
| 93 | 145 | } |
| 94 | 146 | // Remains from old versions. |
| 95 | 147 | delete_site_option( 'wd_audit_cached' ); |
| 96 | -// Remove BF notice. | |
| 97 | -delete_site_option( 'wp_defender_show_black_friday' ); | |
| 148 | +delete_site_option( 'wd_show_ip_detection_notice' ); | |