Skip to content

Themes: Fix double-escaped theme and author names on the Add Themes screen - #16055

Open
shreyasikhar wants to merge 1 commit into
WordPress:trunkfrom
shreyasikhar:fix/66713-theme-name-entities
Open

shreyasikhar wants to merge 1 commit into
WordPress:trunkfrom
shreyasikhar:fix/66713-theme-name-entities

Conversation

@shreyasikhar

Copy link
Copy Markdown

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

On Appearance → Add Themes, theme names and author names that contain special characters show raw HTML entities. For example, "Olive & Ember" is displayed as "Olive & Ember".

Cause

The WordPress.org Themes API returns these fields already HTML-encoded:

  • Theme name: "name": "Olive & Ember"
  • Author: "display_name": "Weblizar - WordPress Themes & Plugin"

wp_ajax_query_themes() sanitizes both fields with wp_kses() and $themes_allowedtags, so they are sent to the browser as safe HTML. The templates in theme-install.php then print them with {{ }}, which escapes them a second time. & becomes &, and the browser shows the literal text &.

Fix

The visible theme name and the "By %s" author line in tmpl-theme and tmpl-theme-preview now use {{{ }}}, so the values sanitized by wp_kses() are not escaped again. This matches how themes.php already outputs data.name and data.author for installed themes, and how this screen already outputs data.description.

Why this is safe

  • wp_kses() runs on name and author in wp_ajax_query_themes(), after themes_api() and its filters. A filtered API response therefore cannot skip sanitization.
  • The page starts with no theme data ('themes' => false), so every theme it shows comes from the query-themes Ajax handler.
  • Only text content is changed. Attributes (aria-label, data-name) still use {{ }}, because wp_kses() output is not safe in an attribute.
  • I tested wp_kses() with $themes_allowedtags against common XSS inputs. It removed <script>, <iframe>, <svg onload>, <img onerror>, event handlers, style attributes and javascript: URLs, including entity-encoded ones.

Known limitation (out of scope)

aria-label and data-name still contain the double-encoded value, so a screen reader announces "Install Olive & Ember". Fixing this needs the value decoded in PHP or JS before it reaches the template. That can be handled in a follow-up.

Testing instructions

  1. Go to Appearance → Add Themes.
  2. Search for olive ember. The card and the preview sidebar should show "Olive & Ember".
  3. Search for medicore. The author should show "By Weblizar - WordPress Themes & Plugin".
  4. Check that other theme names and authors still display correctly, and that searching, filtering, previewing and installing still work.

Screenshots

Before After
image image
image image
image image

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Root-cause analysis, the code change, checking the Themes API data for affected names and authors, and the wp_kses() safety checks. I reviewed and tested the final change myself.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 17, 2026 •

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 shreyasikhar26, dhruvang21.

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.

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