$max_time ) { return false; } $path = $file->getPathname(); // SECURITY: Remove symlinks without following them if ( is_link( $path ) ) { @unlink( $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink -- direct filesystem operation required by the malware scanner/quarantine cleanup; WP_Filesystem is unsuitable here continue; } // SECURITY: Verify real path stays under our directory $real = realpath( $path ); if ( $real === false || ( $real !== $real_root && strpos( $real, $real_root_prefix ) !== 0 ) ) { continue; // Path escaped — skip } if ( $file->isDir() ) { @rmdir( $real ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir -- direct filesystem operation required by the malware scanner/quarantine cleanup; WP_Filesystem is unsuitable here } else { @unlink( $real ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink -- direct filesystem operation required by the malware scanner/quarantine cleanup; WP_Filesystem is unsuitable here } } } catch ( \Throwable $e ) { // FIX (audit 2026-06-10): catch Throwable, not just Exception, so a // TypeError/Error during iteration is also swallowed (PHP 7/8). // Directory iteration failed - not critical return false; } return @rmdir( $dir ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir -- direct filesystem operation required by the malware scanner/quarantine cleanup; WP_Filesystem is unsuitable here } // ======================================== // MAIN UNINSTALL LOGIC // ======================================== // Try to increase timeout for cleanup operations @set_time_limit( 120 ); // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged -- raising the time limit is required so large quarantine/backup directory trees can be fully removed during uninstall // Wrap everything in try-catch to prevent fatal errors during uninstall try { global $wpdb; // FIX (dev-memo 2026-06-11, Final): run the ONE shared cleanup contract so Reset // and Uninstall wipe the IDENTICAL scope and can never drift. It removes all // options, FREE-Plus data, core user-meta, custom tables, every cron hook and // transients, then flushes the object cache. The inline blocks below are kept as // a defensive no-op fallback (their lists now live only in GuardPress_Cleanup). $gp_reg = __DIR__ . '/includes/free-plus/shared/class-registry.php'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- file-scoped uninstall variable, already gp_-prefixed and not exported as a global symbol if ( file_exists( $gp_reg ) ) { require_once $gp_reg; } require_once __DIR__ . '/includes/class-cleanup.php'; if ( class_exists( 'GuardPress_Cleanup' ) ) { GuardPress_Cleanup::purge_state(); } // FIX (deep-verify 2026-06-11): all option / FREE-Plus / user-meta / table / // cron / transient cleanup is owned by GuardPress_Cleanup::purge_state() above // (the single source of truth). The block below is a minimal FALLBACK that runs // ONLY if that class failed to load (a corrupt/partial install), so the most // sensitive data is still removed. if ( ! class_exists( 'GuardPress_Cleanup' ) ) { if ( file_exists( $gp_reg ) ) { require_once $gp_reg; if ( class_exists( 'GuardPress_FreePlus_Registry' ) ) { GuardPress_FreePlus_Registry::purge_all(); } } $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 option rows during uninstall cleanup; live security data must not be cached // ACG-054-004 / ACG-055-006 (audit 2026-06): the dynamic privacy-cursor option family (gp_priv_*) carries the // last processed IP of an interrupted export/erase — remove the whole family so no IP-bearing cursor 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 during uninstall cleanup; live security data must not be cached // ACG-033-011 (audit 2026-06-20): CAPTCHA single-use claim rows + index + // fail-open slot rows (fallback path; the main GuardPress_Cleanup sweep also // removes these). $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_%' OR 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 during uninstall cleanup; live security data must not be cached -- ACG-047-008: fallback now matches the main contract (gp_cap_ipc_*, gp_rescue_claim_*) // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query on the plugin's own option rows during uninstall cleanup; 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_%'" ); } // ======================================== // DIRECTORIES (on-disk files — purge_state() deliberately does not touch these) // ======================================== $gp_upload_dir = wp_upload_dir(); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- file-scoped local $gp_base = trailingslashit( $gp_upload_dir['basedir'] ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- file-scoped local // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- file-scoped local $gp_directories = array( $gp_base . 'guardpress-baseline', $gp_base . 'guardpress-backups', $gp_base . 'guardpress-quarantine', $gp_base . 'guardpress-logs', $gp_base . 'guardpress-temp', WP_CONTENT_DIR . '/guardpress-data', // FIX: file-based scan/malware storage ); foreach ( $gp_directories as $gp_dir ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- file-scoped local if ( is_dir( $gp_dir ) ) { guardpress_delete_directory( $gp_dir ); } } // ACG-121 A2 (audit 2026-07-16): the dedicated store-MAC key is deleted HERE and NOT in // GuardPress_Cleanup::purge_state(). purge_state() is shared with the admin "Reset data" button, which // wipes options but deliberately leaves the on-disk store intact — purging the key there would make every // existing quarantine/snapshot record permanently unreadable (the very failure this key was introduced to // prevent). Uninstall is the only moment the store directories are removed too (just above), so this is // the only place where dropping the key loses nothing. // ACG-137-B1: these rows are INSTALL-WIDE — they live in {base_prefix}options, because the store they // authenticate is one install-wide directory (WP_CONTENT_DIR/guardpress-data, no blog id in the path). // delete_option() would target the CURRENT site's table ($wpdb->options — wp_2_options on site 2), so on // multisite it would leave the real rows behind. Delete them where they actually live. Same scope axis as // GuardPress_File_Storage::store_options_table(); see the note there. if ( isset( $wpdb ) && is_object( $wpdb ) && isset( $wpdb->base_prefix ) ) { $gp_opt_table = $wpdb->base_prefix . 'options'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- file-scoped local foreach ( array( 'guardpress_store_mac_key', // ACG-137-B4: the RETIRED salt pin. Never written by a shipped build, but any dev/staging site that // ran an unreleased v1.0.137 has the row — and while it exists it is a live second MAC key. 'guardpress_store_mac_legacy_salt', // ACG-137-B4: the legacy-acceptance marker. 'guardpress_store_legacy_ok', ) as $gp_opt_name ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- file-scoped local // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- delete_option() targets the per-site table; these rows are install-wide $wpdb->query( $wpdb->prepare( "DELETE FROM `{$gp_opt_table}` WHERE option_name = %s", $gp_opt_name ) ); delete_option( $gp_opt_name ); // belt-and-braces: drop any stray per-site row an older build wrote } } // Cron hooks are cleared by GuardPress_Cleanup::purge_state() above. // Clean object cache (purge_state already flushed; harmless to repeat). wp_cache_flush(); } catch ( \Throwable $e ) { // FIX (audit 2026-06-10): catch Throwable so an Error/TypeError during // uninstall is also swallowed (the previous catch(Exception) let those // escape, contradicting the "prevent fatal errors" intent). // Uninstall failed partially - not critical, plugin files will be removed anyway // User can manually clean up database if needed }