Skip to content

Fix pattern metadata and template part references when saving themes - #888

Open
elphizu wants to merge 1 commit into
WordPress:trunkfrom
elphizu:fix/pattern-references
Open

elphizu wants to merge 1 commit into
WordPress:trunkfrom
elphizu:fix/pattern-references

Conversation

@elphizu

@elphizu elphizu commented Oct 16, 2026

Copy link
Copy Markdown

What?

Closes #872

Fixes Save Patterns leaving metadata.patternName behind and missing synced pattern references inside template parts.

Why?

Unsynced pattern copies retained editor metadata referencing the authoring site or plugin patterns. Template parts were also searched under template-parts/ instead of using WordPress’s theme folder mapping.

How?

  • Use get_block_theme_folders() when locating templates and template parts.
  • Include customized templates containing unsynced pattern copies before clearing their database customizations.
  • Remove patternName in one cleanup pass, including when no saved user patterns remain.
  • Preserve PHP fragments, other metadata, and unrelated attribute formatting through verified text removal.
  • Add regression tests for template parts, unsynced copies, PHP attributes, empty metadata, and cleanup without user patterns.
  • Use distinct test theme names to avoid cached template-path collisions.

Testing Instructions

  1. Create a user pattern and insert a synced reference into a template part.
  2. Insert an unsynced copy into a template.
  3. Run Save Patterns.
  4. Verify synced references become wp:pattern references using the exported theme pattern slug.
  5. Verify metadata.patternName is removed while other metadata and content remain intact.
  6. Repeat with no saved user patterns and confirm stale metadata is still removed.

Automated verification:

  • All 32 pattern tests pass.
  • PHP, JavaScript, CSS, and Markdown linters pass.
  • Build passes with existing warnings.
  • The full PHP suite reports the same five failures and one error on clean trunk and this branch.

Use of AI Tools

AI assistance: Yes
Tool: OpenAI Codex
Used for: Reviewing the issue, implementing changes, adding regression tests, and PR Description.

Remove editor-added pattern names without re-encoding block attributes, and use WordPress's template folder mapping when replacing local references.

Add regression coverage for PHP attributes, metadata-only exports, and test theme isolation.

Fixes WordPress#872
@elphizu
elphizu marked this pull request as ready for review October 16, 2026 10:25
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.

Save Patterns leaves patternName metadata behind and doesn't search the parts folder

1 participant