Skip to content

Core: uninstall from uninstall.php instead of register_uninstall_hook() - #1078

Merged
hi-hai merged 1 commit into
litespeedtech:devfrom
Contributolo:perf/uninstall-php
Oct 23, 2026
Merged

hi-hai merged 1 commit into
litespeedtech:devfrom
Contributolo:perf/uninstall-php

Conversation

@Contributolo

Copy link
Copy Markdown
Contributor

What

Core::init() no longer calls register_uninstall_hook(). A new uninstall.php in the plugin root runs the same cleanup:

defined( 'WP_UNINSTALL_PLUGIN' ) || exit();
require_once __DIR__ . '/litespeed-cache.php';
\LiteSpeed\Activation::uninstall_litespeed_cache();

Why

register_uninstall_hook() reads the uninstall_plugins option every time it is called. Core keeps that option out of autoload on purpose (the comment in wp-includes/plugin.php says "Emphasis should be put on using the 'uninstall.php' way"). Since the call sits in Core::init(), every request, including every uncached front-end page view, paid one extra database query for it. The Plugin Handbook lists uninstall.php as 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.php exists, uninstall_plugin() removes the old uninstall_plugins entry, defines WP_UNINSTALL_PLUGIN and includes the file. The file includes the main plugin file first, as core did for the hook, so Activation::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:

dev this branch
Queries on an uncached page view 37 36
Reads of uninstall_plugins per page view 1 0
uninstall_plugin() after deactivation: litespeed% options left 0 of 196 0 of 196
LiteSpeed tables left none none
uninstall_plugins entry afterwards removed removed

vendor/bin/phpcs --standard=phpcs.ruleset.xml uninstall.php src/core.cls.php reports nothing.

@hi-hai
hi-hai merged commit 245e20f into litespeedtech:dev Oct 23, 2026
1 check passed
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.

2 participants