Add proper uninstall.php and extract shared Cleanup class#1166
Open
yoav-cloud wants to merge 1 commit intocloudinary:masterfrom
Open
Add proper uninstall.php and extract shared Cleanup class#1166yoav-cloud wants to merge 1 commit intocloudinary:masterfrom
yoav-cloud wants to merge 1 commit intocloudinary:masterfrom
Conversation
Refactor Deactivation class to utilize Cleanup class for data cleanup and remove redundant methods. Update constant reference for cleaning key.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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