Skip to content

Plugins: Pass the correct $network_wide value when scraping a network activation error - #16082

Open
huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:fix/36406-network-wide-error-scrape
Open

huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:fix/36406-network-wide-error-scrape

Conversation

@huzaifaalmesbah

Copy link
Copy Markdown
Member

Description

When a plugin fails during network activation, the error notice loads the error_scrape action in an iframe to show the plugin's output. That iframe URL is built with admin_url( 'plugins.php' ), so the scrape request runs in the site admin. There is_network_admin() is false, and since r62931 the scrape fires activate_{$plugin} with is_network_admin(), so the hook receives $network_wide = false for 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 receives true. Activation from a site admin is unchanged, because self_admin_url() returns admin_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 through wp_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_wide value 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:

  1. Allow the iframe through kses for this test (works around #60373), for example in an mu-plugin:
    add_filter( 'wp_kses_allowed_html', function ( $tags, $context ) {
    	if ( 'post' === $context ) {
    		$tags['iframe'] = array( 'style' => true, 'width' => true, 'height' => true, 'src' => true );
    	}
    	return $tags;
    }, 10, 2 );
  2. Add this plugin, which refuses network activation and logs what it receives:
    <?php
    /* Plugin Name: Test 36406 */
    register_activation_hook( __FILE__, function ( $network_wide ) {
    	error_log( sprintf( 'action=%s network_wide=%s', $_GET['action'] ?? '-', var_export( $network_wide, true ) ) );
    	if ( $network_wide ) {
    		exit( 'This plugin cannot be network activated.' );
    	}
    } );
  3. Go to Network Admin → Plugins and click Network Activate.

Before: the iframe points to wp-admin/plugins.php?action=error_scrape…, it stays empty, and the log shows action=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 shows action=error_scrape network_wide=true.

Control: activate a plugin that always fails from a site admin. The iframe still uses wp-admin/plugins.php and $network_wide is still false.

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.

…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.
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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

@huzaifaalmesbah
huzaifaalmesbah marked this pull request as ready for review November 18, 2026 09:59
@github-actions

Copy link
Copy Markdown

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:

Props huzaifaalmesbah.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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