Skip to content

Plugins: Show the output of a plugin that fails to activate - #16084

Open
huzaifaalmesbah wants to merge 2 commits into
WordPress:trunkfrom
huzaifaalmesbah:fix/60373-activation-error-iframe
Open

huzaifaalmesbah wants to merge 2 commits into
WordPress:trunkfrom
huzaifaalmesbah:fix/60373-activation-error-iframe

Conversation

@huzaifaalmesbah

@huzaifaalmesbah huzaifaalmesbah commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Description

When a plugin triggers a fatal error or exits during activation, wp-admin/plugins.php appends an error_scrape iframe to the "Plugin could not be activated because it triggered a fatal error." notice, so the plugin's output (the reason for the failure) is shown.

Since r56573 (WordPress 6.4) that notice is printed with wp_admin_notice(), which passes the message through wp_kses_post(). <iframe> is not an allowed post tag, so the iframe is stripped and only the generic message is shown.

This PR allows the iframe for this one notice only. Instead of calling wp_admin_notice(), which sanitizes with wp_kses_post(), it does the same two steps locally:

  1. fires the wp_admin_notice action, as wp_admin_notice() does;
  2. echoes wp_get_admin_notice() through wp_kses() with the post allowlist plus iframe (src, style, width, height). The iframe entry is only added when the iframe is actually appended.
  • The global post kses rules are not changed, so other notices, and any wp_kses_post() call made by a wp_admin_notice callback or a notice filter, still strip iframes. This is the difference from 60373.patch, which allowed iframes in every notice printed through wp_admin_notice().
  • The wp_admin_notice action and the wp_admin_notice_args / wp_admin_notice_markup filters still run.
  • The iframe URL is built by core and escaped with esc_url(). The plugin's output loads inside the iframe as a separate document, not in the admin page.

Related: #36406 / #16082 fixes the $network_wide value passed during the same error_scrape request. That fix is only visible in the UI once this iframe is shown again. The two PRs touch nearby lines but are independent.

Follow-up to r56573.

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.

  1. Add this plugin:
    <?php
    /* Plugin Name: Test 60373 */
    register_activation_hook( __FILE__, function () {
    	exit( 'Test 60373: this plugin always fails to activate.' );
    } );
  2. Optional control: add this mu-plugin to check that other output is still filtered, including inside a wp_admin_notice callback:
    <?php
    add_action( 'wp_admin_notice', function () {
    	echo '<p>HOOK:' . wp_kses_post( '[<iframe src="https://example.org/"></iframe>]' ) . '</p>';
    } );
    add_action( 'pre_current_active_plugins', function () {
    	echo '<p>CONTROL:' . wp_kses_post( '[<iframe src="https://example.org/"></iframe>]' ) . '</p>';
    } );
  3. Go to Plugins and click Activate on "Test 60373".

Before: only "Plugin could not be activated because it triggered a fatal error." is shown, and the page contains no <iframe>.
After: the notice contains the iframe, and it shows "Test 60373: this plugin always fails to activate."
Control (both before and after): the paragraphs show HOOK:[] and CONTROL:[], so wp_kses_post() still strips iframes outside this notice.

The other error notices on this screen (unexpected output, "cannot delete a plugin while it is active on the main site", and "could not be resumed") have no iframe and render as before.

Tested on a local multisite install, from a site admin and from the network admin. Together with #16082, a network activation also shows the plugin's output, and the hook receives $network_wide = true.

Trac ticket: https://core.trac.wordpress.org/ticket/60373

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.

When a plugin triggers a fatal error or exits during activation, the error notice appends an `error_scrape` iframe that shows the plugin's output. Since r56573 that notice is printed with `wp_admin_notice()`, which passes the message through `wp_kses_post()`. `<iframe>` is not an allowed post tag, so the iframe was stripped and the reason for the failure was no longer shown.

Allow the iframe through kses for this one notice only, by adding a `wp_kses_allowed_html` filter just around the `wp_admin_notice()` call. Other notices are still filtered as before.

Follow-up to r56573.

See #60373.

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.

🟡 Changes recommended

The temporary global allowlist change permits iframes in unrelated sanitization performed by notice callbacks, so it must be scoped to this notice while preserving its hooks.

1 open issue
What changed in this PR

Restores plugin activation failure output by allowing the error-scrape iframe through admin notice sanitization. This complements the separate fix for network activation context.

Changes:

  • Adds an iframe allowlist filter when the activation error notice includes an iframe.
  • Removes the filter after rendering the notice.
File Description
src/​wp-admin/​plugins.php Temporarily allows iframe markup while rendering the plugin activation error notice.

Review effort: Balanced

Comment thread src/wp-admin/plugins.php Resolved
@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.

Instead of temporarily filtering `wp_kses_allowed_html` while `wp_admin_notice()` runs, which also allowed iframes in any `wp_kses_post()` call made by a `wp_admin_notice` callback or notice filter, fire the `wp_admin_notice` action and sanitize this notice's markup with a local allowlist that adds the iframe.

See #60373.

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 are recorded for the localized change restoring plugin activation error output.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@huzaifaalmesbah
huzaifaalmesbah marked this pull request as ready for review November 18, 2026 10:01
@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