prefix). @return string[] */ public static function tables() { return array( 'guardpress_security_log', 'guardpress_blocked_ips', 'guardpress_attack_log', 'guardpress_file_changes', 'guardpress_scan_results', 'guardpress_quarantine_index', 'guardpress_login_attempts', 'guardpress_login_log', 'guardpress_achievements', ); } /** Every cron hook the plugin (FREE + PRO) may schedule. @return string[] */ public static function cron_hooks() { return array( 'guardpress_scheduled_scan', 'guardpress_daily_scan', 'guardpress_hourly_check', 'guardpress_backup_schedule', 'guardpress_cleanup_logs', 'guardpress_check_updates', 'guardpress_security_check', 'guardpress_realtime_monitor', 'guardpress_threat_feed_update', 'guardpress_cleanup_login_records', 'guardpress_cleanup_quarantine', 'guardpress_refresh_sites_data', 'guardpress_cleanup_security_log', 'guardpress_daily_cron', 'guardpress_weekly_cron', 'guardpress_hourly_cron', 'guardpress_check_blacklist', 'guardpress_check_uptime', 'guardpress_calculate_security_score', 'guardpress_daily_breach_check', 'guardpress_realtime_microscan', 'guardpress_cron_scan_v1', ); } /** * Apply the full DB + cache purge. Shared by Reset and Uninstall. Idempotent * and defensive: every step is guarded, so a missing class/function or a query * error can never fatal the caller (uninstall already wraps in try/catch; Reset * runs while active and must keep working). */ public static function purge_state() { global $wpdb; // 1) Core + PRO options. foreach ( self::option_keys() as $key ) { delete_option( $key ); } // 2) Per-type scan-lock options (prefix sweep). if ( isset( $wpdb ) ) { $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'guardpress_scan_lock_%'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query on the plugin's own table; live security data must not be cached // ACG-047-008: Admin Rescue claim rows are OPTIONS (not transients), so the transient sweep below // never catches them — remove abandoned/expired gp_rescue_claim_* rows by prefix. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'gp_rescue_claim_%'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query on the plugin's own option rows; live security data must not be cached // ACG-054-004 / ACG-055-006 (audit 2026-06): the privacy export/erase cursor options (gp_priv_*) are // durable OPTIONS that carry the last processed IP of an interrupted run — sweep the whole family so none // lingers. The LIKE wildcard (_) is escaped so only the exact gp_priv_ prefix matches. $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like( 'gp_priv_' ) . '%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query on the plugin's own privacy-cursor options; live security data must not be cached // ACG-033-011 (audit 2026-06-20): CAPTCHA single-use claim rows // (gp_cap_used_*), their bounded index (gp_cap_claim_index) and the // atomic fail-open slot rows (gp_cap_fo_*). These are prefix/random // option rows the captcha module creates; sweep them so a Reset / // Uninstall leaves none behind. // ACG-036-010: also the per-source claim counters (gp_cap_ipc_*). $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'gp_cap_used_%' OR option_name = 'gp_cap_claim_index' OR option_name LIKE 'gp_cap_fo_%' OR option_name LIKE 'gp_cap_ipc_%'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query on the plugin's own option rows; live security data must not be cached } // 3) FREE-Plus module data (its own options + 2FA user-meta + crons + transients). if ( class_exists( 'GuardPress_FreePlus_Registry' ) ) { GuardPress_FreePlus_Registry::purge_all(); } // 4) Core per-user meta (across all users). foreach ( self::user_meta_keys() as $meta_key ) { if ( function_exists( 'delete_metadata' ) ) { delete_metadata( 'user', 0, $meta_key, '', true ); } elseif ( isset( $wpdb ) ) { $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = %s", $meta_key ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query on the plugin's own table; live security data must not be cached } } // 5) Custom tables. Use the login-security dropper too (it also clears the // migration flag so the tables re-create cleanly while the plugin stays // active after a Reset). if ( isset( $wpdb ) ) { foreach ( self::tables() as $suffix ) { $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}{$suffix}" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter -- table name is a trusted internal constant, not user input; direct query on the plugin's own table; live security data must not be cached } } if ( class_exists( 'GuardPress_Login_Security' ) && method_exists( 'GuardPress_Login_Security', 'drop_tables' ) ) { GuardPress_Login_Security::drop_tables(); } // 6) Cron hooks (every plugin schedule). foreach ( self::cron_hooks() as $hook ) { wp_clear_scheduled_hook( $hook ); } // 7) Transients. When the Registry is present, step 3's purge_all() already // ran cleanup_transients() (both 'guardpress_' and 'gpfp_' prefixes), so // we only sweep directly here as a FALLBACK when it is absent — avoids a // redundant double sweep on the normal path. if ( ! class_exists( 'GuardPress_FreePlus_Registry' ) && isset( $wpdb ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query on the plugin's own table; live security data must not be cached $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_guardpress_%' OR option_name LIKE '_transient_timeout_guardpress_%' OR option_name LIKE '_transient_gpfp_%' OR option_name LIKE '_transient_timeout_gpfp_%'" ); } // 8) Drop persistent-object-cache copies of everything just removed. if ( function_exists( 'wp_cache_flush' ) ) { wp_cache_flush(); } } } }