query('SET FOREIGN_KEY_CHECKS = 0'); // Delete custom tables in correct order (child tables first, then parent). $tables = [ $wpdb->prefix . 'affcf_rejections', // No foreign keys. $wpdb->prefix . 'affcf_submissions', // Has FK to forms. $wpdb->prefix . 'affcf_drafts', // Has FK to forms. $wpdb->prefix . 'affcf_forms', // Parent table. ]; foreach ($tables as $table) { $wpdb->query("DROP TABLE IF EXISTS `{$table}`"); } // Re-enable foreign key checks. $wpdb->query('SET FOREIGN_KEY_CHECKS = 1'); */ // PRESERVE OPTIONS - Only delete temporary/cache data. // Keep settings, email templates, forms configuration, etc. // Only delete temporary data. delete_option( 'affcf_activated_at' ); delete_option( 'affcf_deactivated_at' ); // Delete user meta (keep this - it's submission counts). // Commenting out to preserve user submission history. // $wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '_affcf_%'");. // Delete post meta (keep this - it tracks which form created which post). // Commenting out to preserve post-form relationships. // $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE '_affcf_%'");. // Delete transients (cache data - safe to delete). // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Bulk cleanup of plugin transients on uninstall $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_affcf_%'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Bulk cleanup of plugin transients on uninstall $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_affcf_%'" ); // PRESERVE auto-created pages. // Commenting out to keep dashboard, submit, and edit pages. /* // Delete auto-created pages. $pages = get_option('affcf_default_pages'); if ($pages) { if (!empty($pages['dashboard_page_id'])) { wp_delete_post($pages['dashboard_page_id'], true); } if (!empty($pages['submit_page_id'])) { wp_delete_post($pages['submit_page_id'], true); } if (!empty($pages['edit_page_id'])) { wp_delete_post($pages['edit_page_id'], true); } } */ /** * SUMMARY OF WHAT'S PRESERVED ON PLUGIN DELETION: * * ✅ PRESERVED (Data you keep): * - Database tables (forms, drafts, submissions, rejections) * - Plugin settings * - Email templates * - Error messages * - Security settings * - Default pages configuration * - Auto-created pages (Dashboard, Submit, Edit) * - User submission counts * - Post-form relationships * * ❌ DELETED (Temporary data only): * - Transients (cache) * - Activation/deactivation timestamps * * This means you can safely: * - Delete and reinstall the plugin ✅ * - Update to newer versions ✅ * - Test different versions ✅ * - All your forms and data will still be there! ✅ */