Skip to content

Resolve: the plugin deletion error issue on QM - #2115

Merged
rudrakshi-gupta merged 2 commits into
developfrom
fix/plugin-deletion-issue
Sep 14, 2026
Merged

rudrakshi-gupta merged 2 commits into
developfrom
fix/plugin-deletion-issue

Conversation

@rudrakshi-gupta

Copy link
Copy Markdown
Member

Fix: Plugin deletion error (502 / "Deletion failed") when GoDAM is deleted

Closes #1146

Problem

Deleting the GoDAM plugin threw an error — a 502 Bad Gateway (openresty), or under Query Monitor a "Deletion failed: … Class ActionScheduler_Lock not found" — even though the plugin was actually removed (a page refresh confirmed it). Other plugins deleted cleanly; only GoDAM failed.

Root cause

GoDAM cleaned up on delete via register_uninstall_hook(), which makes WordPress include and fully bootstrap godam.php during deletion — loading the bundled WooCommerce Action Scheduler and registering its shutdown callback / autoloaders. WordPress then deletes the plugin's files, so on shutdown those now-dangling references fatally autoload classes that no longer exist. Query Monitor appends that fatal to the delete AJAX response (corrupting the JSON), and on buffered servers the FPM worker dies before the response flushes, returning a 502.

Fix

  • Added an uninstall.php. WordPress runs it in isolation (with WP_UNINSTALL_PLUGIN defined) and does not bootstrap the plugin, so Action Scheduler is never loaded during deletion and no dangling references exist at shutdown. Moved the option cleanup here and removed register_uninstall_hook().
  • Added a delete_plugin guard in godam.php that detaches Action Scheduler's shutdown dispatch as a safety net for the case where GoDAM is loaded during the delete request.

Testing

  • Deleting a fixed test copy on a local site (Query Monitor active) returns a clean {success:true} and removes immediately — no fatal, no 502, no refresh needed.
  • Verified working on a separate environment.
  • Non-GoDAM plugins unaffected.

Changed files

  • godam.php
  • uninstall.php (new)

Demo

Screenshot 2026-09-10 at 5 22 25 PM

Copilot AI balanced review requested due to automatic review settings September 11, 2026 07:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Multisite cleanup currently processes only the first 100 sites.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Moves deletion cleanup into WordPress’s isolated uninstall flow and prevents Action Scheduler shutdown errors.

Changes:

  • Adds uninstall.php for option/transient cleanup.
  • Detaches Action Scheduler during plugin deletion.
File summaries
File Description
godam.php Replaces uninstall hook with deletion safeguard.
uninstall.php Performs standalone cleanup across sites.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread uninstall.php Resolved
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
16 0 16

⚠️ Warnings (16)

📁 composer.json (1 warning)
📍 Line 🔖 Check 💬 Message
0 missing_composer_json_file The "/vendor" directory using composer exists, but "composer.json" file is missing.
📁 readme.txt (2 warnings)
📍 Line 🔖 Check 💬 Message
0 mismatched_plugin_name Plugin name "GoDAM - Organize WordPress Media Library & File Manager with Unlimited Folders for Images, Videos & more" is different from the name declared in plugin header "GoDAM".
0 trademarked_term The plugin name includes a restricted term. Your chosen plugin name - "GoDAM - Organize WordPress Media Library & File Manager with Unlimited Folders for Images, Videos & more" - contains the restricted term "wordpress" which cannot be used at all in your plugin name.
📁 assets/build/blocks/godam-gallery-v2/render.php (2 warnings)
📍 Line 🔖 Check 💬 Message
15 WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound Global variables defined by a theme/plugin should start with the theme/plugin prefix. Found: "$inner_block_video_ids".
23 WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound Global variables defined by a theme/plugin should start with the theme/plugin prefix. Found: "$inner_block_video_ids".
📁 assets/build/css/main.css (1 warning)
📍 Line 🔖 Check 💬 Message
0 EnqueuedStylesScope This style is being loaded in all contexts.
📁 assets/src/libs/analytics.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/09/14/hello-world/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/sample-page/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
📁 assets/build/js/main.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/09/14/hello-world/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/sample-page/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.

🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

@KMchaudhary

Copy link
Copy Markdown
Collaborator

Code review — regression check

Reviewed the diff (godam.php, new uninstall.php) against the merge-base of develop. Overall the fix is sound and I don't see a regression risk in the normal delete flow. Verified the core mechanics:

  • Both Action Scheduler APIs the guard relies on exist in the bundled copy — unhook_dispatch_async_request() and the maybe_dispatch_async_request shutdown callback (vendor/woocommerce/action-scheduler/classes/ActionScheduler_QueueRunner.php:95,101), so both the primary path and the remove_action fallback are correct.
  • uninstall.php's option/transient list matches the old rtgodam_plugin_delete() cleanup exactly (8 options + rtgodam_show_whats_new/rtgodam_release_data transients) — no cleanup coverage is lost. All of these are stored per-site via update_option/set_transient, so the per-site delete_option/delete_transient inside the switch_to_blog loop is correct.
  • .distignore is a denylist and does not exclude uninstall.php, so it ships in the release build — cleanup won't silently stop after register_uninstall_hook() removal.
  • The delete_plugin guard is correctly gated on plugin_basename( __FILE__ ), so bulk-deleting other plugins is unaffected.

A few things worth addressing (none block the fix):

1. Multisite cleanup silently caps at 100 sites — uninstall.php:63
get_sites( array( 'fields' => 'ids' ) ) inherits WP_Site_Query's default 'number' => 100. On a network with more than 100 sites, rtgodam_* options/transients are left behind on every site past the first 100. This isn't new (the removed register_uninstall_hook code had the same bug), but since the loop is being rewritten here it's a good moment to fix it:

$rtgodam_blog_ids = get_sites( array( 'fields' => 'ids', 'number' => 0 ) );

2. Guard removes only one of AS's two shutdown callbacks — godam.php:186
ActionScheduler_FatalErrorMonitor::handle_unexpected_shutdown is also hooked on shutdown (ActionScheduler_FatalErrorMonitor.php:45), attached while a queue batch is running. In the narrow case where GoDAM is deleted while active and a queue run is in flight (e.g. wp plugin delete during a batch), that callback stays hooked and could dangle the same way. Very edge — the monitor is detached outside a run — but flagging since it's the same failure class the guard targets.

3. Minor: the closure in uninstall.php:50 — uninstall.php runs once in isolation, so the "avoids redeclaration concerns" rationale doesn't really apply; a plain inline loop would be simpler. Purely cosmetic.

Nice, well-documented fix overall — the isolation rationale in both files is very clear. 👍

@rudrakshi-gupta
rudrakshi-gupta merged commit 3241354 into develop Sep 14, 2026
5 of 6 checks passed
@rudrakshi-gupta
rudrakshi-gupta deleted the fix/plugin-deletion-issue branch September 14, 2026 08:07
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.

3 participants