Repository navigation
Cross-page admin-link clicks: state, destructive actions, referer hint - #195
Merged
AllTerrainDeveloper merged 2 commits intoMay 13, 2026
Merged
AllTerrainDeveloper merged 2 commits into
AllTerrainDeveloper merged 2 commits into
Conversation
…dispatching to handle cross-bundle actions
Contributor
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
AllTerrainDeveloper
deleted the
fix/iframe-bridge-cross-bundle-and-destructive-actions
branch
May 13, 2026 10:14
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 you'll notice
wp.desktop.registerDestructiveAdminAction(...).Why this needs fixing
Three real bugs were stacked on top of each other. They mask each other; you have to peel them off one at a time.
1. Cross-page admin-link clicks weren't being intercepted at all
Click any in-iframe admin link that goes to a different page — say, an Edit link on a Posts row — and the click was silently swallowed. No new window. No navigation. Nothing.
The shell's window code lives in one JavaScript bundle, and the main desktop code lives in another. Both bundles import the same dispatch module — but each bundle ends up with its own private copy of that module's state. The main bundle was correctly wiring the dispatcher; the window bundle was reading its own never-populated copy and doing nothing. The fix: stash that state on a single shared object both bundles read from.
2. Trash was opening a new window… on the Dashboard
Once #1 was fixed and cross-page clicks worked again, Trash had a new problem: it opened a fresh window, and that window showed the Dashboard, not the Posts list.
Why? When you open a brand-new iframe and immediately point it at
post.php?action=trash, the iframe has no prior page in its history. The browser'sRefererheader falls back to the embedder's URL — i.e., whichever page the desktop shell is currently displaying (often the Dashboard after login). WordPress's trash handler reads thatRefererto decide where to send the user after the deletion. So the post got trashed correctly, then WordPress sent the user "back" to the Dashboard, because that's where it thought they came from.This isn't a vanilla WordPress problem because in vanilla WP, Trash is a same-tab navigation — the
Refereris the Posts list URL, exactly what WP needs.The proper fix is to stop opening a new window for these actions entirely. In real WordPress, the Trash row click never opens a new tab — the list just refreshes in place with an Undo notice. We now do the same thing: the destructive action runs against the source iframe, so the iframe's existing URL becomes the
Referer, and WP redirects right back to the list as it should.3. The Referer header itself is unreliable
Even with #2 in place — even when the action runs against the source iframe whose URL is correct — many environments set a
Referrer-Policyheader that strips the path off theReferer(sending onlyhttp://your-site.com, without the/wp-admin/edit.phppart). That breaks WordPress's "send me back where I came from" logic just as effectively as #2 did.Belt-and-braces fix: we attach
_wp_http_referer=<source-page>as a query parameter on the action URL. WordPress checks that parameter before falling back to the rawRefererheader — it's the same hint WordPress itself uses for form posts viawp_nonce_field(). So the redirect destination is deterministic regardless of what header the browser ends up sending.4. Plugins should be able to opt in to the same behavior
Built-in WordPress has a fixed set of redirect-back action names:
trash,untrash,delete,spamcomment, etc. We hard-code those for zero-config coverage. But plenty of plugins introduce their own destructive actions (WooCommerce order trash, for example). Without an extension point, those would keep opening stray windows.New stable API:
Predicate-based (rather than a name list) so plugins can match on whatever combination of path / query / nonce uniquely identifies their action. Symmetric with the existing
registerNativeUrlRemapso authors recognize the pattern. Returns an unregister function. CompanionunregisterDestructiveAdminAction(id)andlistDestructiveAdminActions()for completeness.Files
src/window/iframe-bridge.ts_wp_http_refererstamping in both branches.src/native-url-remap.tssrc/destructive-admin-actions.tssrc/api/facade.tswp.desktop.src/desktop.tssrc/window/iframe-bridge.test.tssrc/destructive-admin-actions.test.tsdocs/javascript-reference.mdTest plan
npm run test:js— 1153 tests pass.npm run lint,tsc --noEmit,npm run build— clean across all bundles.