I installed the WordPress plugin LWS Optimize, which turned out to be unusably broken (which is the reason I’m not linking to it) and made my site unusable. To make matters worse, when I tried to deactivate it, it told me it deactivated… and was still active. I went in through FTP and deleted the plugin folder entirely, and then WordPress said it had been deactivated because it couldn’t be found… and it still showed as present and activated in the plugin list.
So I added this to my theme’s functions.php file:
add_action('admin_init', function() {
$active_plugins = get_option('active_plugins');
$plugin_to_remove = 'lws-optimize/lws-optimize.php';
if (($key = array_search($plugin_to_remove, $active_plugins)) !== false) {
unset($active_plugins[$key]);
update_option('active_plugins', array_values($active_plugins));
}
});
I then reloaded an admin page and removed that. That deactivated the plugin in the plugins list, but then when I hit the “delete” link, it said it was deleted, but when I reloaded the page, it was still there.
So I added this to my theme’s functions.php file:
add_action('admin_init', function() {
$all_plugins = get_option('active_plugins');
$plugin_data = get_plugins();
// Remove from the plugins data cache
if (isset($plugin_data['lws-optimize/lws-optimize.php'])) {
unset($plugin_data['lws-optimize/lws-optimize.php']);
wp_cache_delete('plugins', 'plugins');
}
// Also clean up any plugin-specific options that might remain
delete_option('lws_optimize_config'); // common option naming pattern
delete_option('lws-optimize-settings');
delete_option('lws_optimize_settings');
});
I then reloaded an admin page and removed that.
That fixed the problem. I have another plugin that looks for orphaned database tables and options, I’m going to run that to make sure, but everything seems back to normal.