Skip to content

Themes: Display error details when theme API request fails. - #16061

Open
Mimitrz wants to merge 1 commit into
WordPress:trunkfrom
Mimitrz:66712-fix-issue
Open

Mimitrz wants to merge 1 commit into
WordPress:trunkfrom
Mimitrz:66712-fix-issue

Conversation

@Mimitrz

@Mimitrz Mimitrz commented Nov 17, 2026

Copy link
Copy Markdown

Description

When the external HTTP request to the WordPress.org Themes API fails (for example, when WP_HTTP_BLOCK_EXTERNAL is set to true), the "Add Themes" screen (wp-admin/theme-install.php) only displays a generic fallback error message without showing the underlying error details returned by the server.

This PR passes the error message from the AJAX handler and renders it inside the error notice in the UI, matching the existing error-reporting behavior used in the Plugin Installer screen:

  • src/wp-admin/includes/ajax-actions.php: Retrieves $api->get_error_data(), strips HTML tags via wp_strip_all_tags(), and includes errorData in the JSON error response when themes_api() returns a WP_Error in wp_ajax_query_themes().
  • src/js/_enqueues/wp/theme.js: Forwards the response object from both .fail() callbacks to the query:fail event and appends a paragraph with Error details: when response.errorData is present.

Screenshots

| Before |

error

| After |

resultado

Testing Instructions

  1. Add define( 'WP_HTTP_BLOCK_EXTERNAL', true ); to wp-config.php.
  2. Navigate to Appearance -> Themes -> Add New Theme (wp-admin/theme-install.php).
  3. Confirm that the error notice now displays Error details: User has blocked requests through HTTP... below the generic message.
  4. Remove define( 'WP_HTTP_BLOCK_EXTERNAL', true ); from wp-config.php and verify that the theme directory loads normally again.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Google Gemini
Used for: Guidance


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@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 mimitrz.

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.

@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.

Comment on lines +3644 to +3646
$response = array(
'errorMessage' => $api->get_error_message(),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We are including errorMessage in the AJAX response, but the JavaScript doesn't currently use it. Could we either display this message or remove it from the response to avoid sending unused data?

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