Repository navigation
Core: uninstall from uninstall.php instead of register_uninstall_hook() - #1078
Merged
Merged
Conversation
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.
What
Core::init()no longer callsregister_uninstall_hook(). A newuninstall.phpin the plugin root runs the same cleanup:Why
register_uninstall_hook()reads theuninstall_pluginsoption every time it is called. Core keeps that option out of autoload on purpose (the comment inwp-includes/plugin.phpsays "Emphasis should be put on using the 'uninstall.php' way"). Since the call sits inCore::init(), every request, including every uncached front-end page view, paid one extra database query for it. The Plugin Handbook listsuninstall.phpas the second method, and the user notes on the function reference point to the per-request cost (Trac #31792).Behaviour on uninstall stays the same: when
uninstall.phpexists,uninstall_plugin()removes the olduninstall_pluginsentry, definesWP_UNINSTALL_PLUGINand includes the file. The file includes the main plugin file first, as core did for the hook, soActivation::uninstall_litespeed_cache()finds the autoloader and constants.Tested
Real WordPress 7.1.3 (SQLite), PHP 8.4, with and without this branch on the same database copy:
devuninstall_pluginsper page viewuninstall_plugin()after deactivation:litespeed%options leftuninstall_pluginsentry afterwardsvendor/bin/phpcs --standard=phpcs.ruleset.xml uninstall.php src/core.cls.phpreports nothing.