query( "DROP TABLE IF EXISTS {$wpdb->prefix}itsm_issues, {$wpdb->prefix}itsm_blocks, {$wpdb->prefix}itsm_lockouts, {$wpdb->prefix}itsm_login_attempts, {$wpdb->prefix}itsm_traffic, {$wpdb->prefix}itsm_hits, {$wpdb->prefix}itsm_file_hashes, {$wpdb->prefix}itsm_quarantine, {$wpdb->prefix}itsm_audit_log, {$wpdb->prefix}itsm_geo_cache, {$wpdb->prefix}itsm_scan_log, {$wpdb->prefix}itsm_db_backups" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- removes the plugin's own tables on uninstall $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( 'itsm_' ) . '%', $wpdb->esc_like( '_transient_itsm_' ) . '%', $wpdb->esc_like( '_transient_timeout_itsm_' ) . '%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- removes every option and transient with this plugin's own "itsm_" prefix on uninstall $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE %s", $wpdb->esc_like( '_itsm_content_backup_' ) . '%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- removes this plugin's own post meta on uninstall foreach ( array( 'itsm_hourly', 'itsm_daily', 'itsm_scheduled_scan', 'itsm_scan_step', 'itsm_activity_report', 'itsm_content_guard_sweep', 'itsm_central_report', 'itsm_cg_home_notice', 'itsm_feeds', 'itsm_premium_feeds' ) as $hook ) { wp_clear_scheduled_hook( $hook ); } wp_clear_scheduled_hook( 'itsm_feeds', array( 'now' ) ); wp_clear_scheduled_hook( 'itsm_premium_feeds', array( 'now' ) ); // The plugin's block in this site's uploads/.htaccess (through insert_with_markers()) and its data folder. $uploads = wp_upload_dir( null, false ); if ( empty( $uploads['basedir'] ) ) { return; } ITSM_Firewall_Installer::remove_marker( trailingslashit( $uploads['basedir'] ) . '.htaccess', 'itsMalicious Hardening' ); $fs = new WP_Filesystem_Direct( null ); $data = trailingslashit( $uploads['basedir'] ) . 'itsmalicious'; if ( $fs->is_dir( $data ) ) { $fs->delete( $data, true ); } } if ( is_multisite() ) { foreach ( get_sites( array( 'fields' => 'ids', 'number' => 0 ) ) as $itsm_site_id ) { switch_to_blog( $itsm_site_id ); itsm_uninstall_site(); restore_current_blog(); } } else { itsm_uninstall_site(); } wp_cache_flush(); // Once for the installation: the plugin's own user meta and its blocks in the root .htaccess / PHP user ini file. global $wpdb; foreach ( array( 'itsm_2fa_secret', 'itsm_2fa_active', 'itsm_2fa_pending_secret', 'itsm_2fa_recovery', 'itsm_2fa_devices', 'itsm_2fa_grace_start', 'itsm_2fa_last_slice', 'itsm_breached_password', 'itsm_last_login' ) as $itsm_meta ) { delete_metadata( 'user', 0, $itsm_meta, '', true ); // this plugin's own user meta } $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE %s", $wpdb->esc_like( 'itsm_dismiss_' ) . '%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- removes this plugin's own dismissal flags on uninstall ITSM_Firewall_Installer::remove_marker( ITSM_Utils::root_dir() . '.htaccess', 'itsMalicious Hardening' ); ITSM_Firewall_Installer::remove_legacy_prepend(); // releases before 1.7.5: auto_prepend_file block in .htaccess and the PHP user ini file // Folder of releases before 1.7.5: only the files this plugin put there, and only while PHP no longer loads the // old firewall file from it; the folder itself goes only when it is empty. $itsm_fs = new WP_Filesystem_Direct( null ); $itsm_old = ITSM_Utils::content_dir() . '/itsmalicious'; if ( $itsm_fs->is_dir( $itsm_old ) && false === strpos( (string) ini_get( 'auto_prepend_file' ), 'itsmalicious' ) ) { foreach ( array( 'itsm-waf.php', 'waf-config.php', 'SAFE_MODE', '.htaccess', 'index.php', 'index.html', 'web.config' ) as $itsm_file ) { if ( $itsm_fs->exists( $itsm_old . '/' . $itsm_file ) ) { $itsm_fs->delete( $itsm_old . '/' . $itsm_file ); } } foreach ( array( 'quarantine', 'backups', 'reference', 'logs' ) as $itsm_sub ) { if ( $itsm_fs->is_dir( $itsm_old . '/' . $itsm_sub ) ) { $itsm_fs->delete( $itsm_old . '/' . $itsm_sub, true ); } } $itsm_fs->rmdir( $itsm_old, false ); }