Skip to content

Add proper uninstall.php and extract shared Cleanup class#1166

Open
yoav-cloud wants to merge 1 commit intocloudinary:masterfrom
yoav-cloud:proper-uninstall
Open

Add proper uninstall.php and extract shared Cleanup class#1166
yoav-cloud wants to merge 1 commit intocloudinary:masterfrom
yoav-cloud:proper-uninstall

Conversation

@yoav-cloud
Copy link
Copy Markdown

Background
Previously, the plugin had no uninstall.php. All data removal logic lived exclusively inside Deactivation::cleanup(), which was only reachable when a user chose "Remove all plugin data" from the deactivation modal. WordPress's standard uninstall hook — triggered when a user clicks Delete in the Plugins screen — was never wired up, meaning plugin data (options, post meta, term meta, custom tables, cron jobs) was left behind after a full uninstall.

What changed
uninstall.php (new)
Registers the plugin's uninstall handler with WordPress. The file guards against direct execution via WP_UNINSTALL_PLUGIN, then bootstraps the minimum plugin runtime needed for component-aware cleanup (init → plugins_loaded → setup_settings) before delegating to Cleanup::run().

php/class-cleanup.php (new)
Extracts all data-removal routines from Deactivation into a standalone Cleanup class so the same logic can be invoked from both the deactivation modal path and the uninstall path without duplication. The class:

Accepts an optional Plugin instance and Settings instance (with a fallback to $plugin->settings)
Guards every settings-dependent branch with instanceof checks so it degrades gracefully if settings are not available
Exposes a static Cleanup::run() factory entry point
Owns the CLEANING_KEY constant (previously on Deactivation), since it is Cleanup that reads and deletes this option
Adds array_unique( array_filter(...) ) around the option-key list in cleanup_options() to prevent redundant or empty-key deletes
Adds cloudinary_cleanup_event to cleanup_legacy_cron() so that the deactivation-modal's scheduled retry hook is always cleared, regardless of which code path triggered cleanup
php/class-deactivation.php (modified)
Removes the CLEANING_KEY constant (now on Cleanup) and updates both references to Cleanup::CLEANING_KEY
Removes all private cleanup methods (moved to Cleanup)
Removes the unused use imports (Global_Transformations, Storage) that were only needed by those methods
Simplifies cleanup() to: set the cleaning flag → Cleanup::run() → clear the cron hook

Refactor Deactivation class to utilize Cleanup class for data cleanup and remove redundant methods. Update constant reference for cleaning key.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant