Repository navigation
Plugins: Pass the correct $network_wide value when scraping a network activation error - #16082
huzaifaalmesbah wants to merge 1 commit into
Conversation
…rk activation error.
When a network activation fails, the error notice loads the `error_scrape` action in an iframe to show the plugin's output. The iframe URL was built with `admin_url()`, so the scrape ran in the site admin, `is_network_admin()` returned false, and `activate_{$plugin}` received `$network_wide = false` for a network activation.
Build the URL with `self_admin_url()` instead, so a network activation is scraped in the network admin and the hook receives `true`.
Follow-up to r62931.
See #36406.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change preserving network-admin context in plugin activation error handling.
No open issues 🎉
What changed in this PR
This PR preserves network-admin context when displaying plugin activation errors, so the scrape request passes the correct $network_wide value to the activation hook.
Changes:
- Uses
self_admin_url()for the error-scrape iframe URL, routing network activation errors through network admin. - Leaves site-admin behavior unchanged. The separate issue that strips iframes from notices remains outside this change.
| File | Description |
|---|---|
src/wp-admin/plugins.php |
Builds the error-scrape URL using the current admin context. |
Review effort: Balanced
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Description
When a plugin fails during network activation, the error notice loads the
error_scrapeaction in an iframe to show the plugin's output. That iframe URL is built withadmin_url( 'plugins.php' ), so the scrape request runs in the site admin. Thereis_network_admin()is false, and since r62931 the scrape firesactivate_{$plugin}withis_network_admin(), so the hook receives$network_wide = falsefor a network activation.This PR builds the iframe URL with
self_admin_url( 'plugins.php' ). A network activation is now scraped in the network admin, so the hook receivestrue. Activation from a site admin is unchanged, becauseself_admin_url()returnsadmin_url()there.This is the approach discussed on the ticket (comment:13 and comment:26), but without a new query argument: the network admin context already provides the flag, so there is no extra input to sanitize.
Related: since 6.4,
wp_admin_notice()passes the notice throughwp_kses_post(), which strips this<iframe>, so by default the scrape output is not shown at all (#60373). This change is independent of that: it makes sure the scrape gets the correct$network_widevalue when the iframe is shown (once #60373 is fixed, or when a site allows the iframe).Follow-up to r62931.
Testing Instructions
There is no PHPUnit test: the change is in the top-level code of
wp-admin/plugins.php, which the PHPUnit suite does not load. Manual steps on a multisite install:Before: the iframe points to
wp-admin/plugins.php?action=error_scrape…, it stays empty, and the log showsaction=error_scrape network_wide=false.After: the iframe points to
wp-admin/network/plugins.php?action=error_scrape…, it shows "This plugin cannot be network activated.", and the log showsaction=error_scrape network_wide=true.Control: activate a plugin that always fails from a site admin. The iframe still uses
wp-admin/plugins.phpand$network_wideis stillfalse.Trac ticket: https://core.trac.wordpress.org/ticket/36406
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Code archaeology, reproduction scripts, and preparing the diff and PR description; the change was reproduced before and after on a local multisite install and reviewed by me.