WordPress / WordPress/create-block-theme

Improved namespace replacement logic when duplicating theme

Open
#777 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
417
Forks
66
PR merge metrics
No merged PRs in 30d

Description

When cloning a theme, we replace namespaces based on the theme name you enter.

However, in the current implementation, there have been many reported cases where incorrect code was generated as a result of the replacement. Theme names that can cause problems include symbols, non-Latin characters, emojis, numbers, etc.

The code generated from this theme name can cause critical errors by generating invalid function names, namespaces, variable names, etc. This issue does not only occur with PHP, but can occur with any file extension that is considered eligible for replacement.

Examples of reported issues:

  • #332
  • #503
  • #733
  • #772

In #503, two ideas are proposed to get around this issue:

  • Validate the theme name and not allow them to start with digits
  • Sanitize the theme name in a way that makes sure it's a valid PHP function prefix

The code and formatting that is considered invalid vary depending on the file extension. Let's explore what the best approach is.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with includes/create-theme/theme-utils.php, especially the namespace replacement logic at lines 17–37 and the eligible file-extension logic around line 79. Review the reported cases in #332, #503, #733, and #772, then define an approach that prevents invalid generated names and formatting across all eligible extensions. Done means cloning themes with symbols, non-Latin characters, emojis, or leading numbers no longer generates critical errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.