Skip to content

Conversation

@scruffian
Copy link
Contributor

@scruffian scruffian commented Dec 3, 2025

Enables saving all patterns (both synced and unsynced) to the theme, not just synced patterns. Previously, only synced patterns would be exported when using the "Save Patterns" option.

What Changed

User-Facing Changes:

  • The "Save Synced Patterns" option has been renamed to "Save Patterns"
  • All patterns created in the Editor (both synced and unsynced) will now be saved to the theme when this option is enabled
  • Unsynced patterns are now included in the export and removal process

Technical Changes:

  • Refactored pattern processing to store raw content first, then wrap in PHP file structure after processing
  • Options are now threaded through to replace_local_pattern_references() to ensure consistent processing
  • Removed the sync status check that previously filtered out unsynced patterns

Why?

This allows theme designers to create their own patterns for themes.

Testing Instructions

Test Case 1: Save All Pattern Types

  1. Go to Appearance → Editor → Patterns
  2. Create 2 patterns - a synced and an unsynced.
  3. Go to Create Block Theme in the editor
  4. Save Changes to Theme
  5. Enable "Save Patterns" checkbox
  6. Click "Save Changes"
  7. ✅ Expected: Both patterns should be saved to /patterns/ directory as .php files
  8. ✅ Expected: Both patterns should be deleted from the Editor
  9. ✅ Expected: Patterns should now load from the theme instead of the database

Test Case 2: Duplicate Pattern Names

  1. Manually create a pattern file: wp-content/themes/your-theme/patterns/test-pattern.php
  2. In the Editor, create a new pattern with the title "Test Pattern" (same slug)
  3. Try to save patterns using Create Block Theme
  4. ✅ Expected: Should show an error: "A pattern with this name already exists: test-pattern"

Test Case 3: Localization Options

  1. Create a pattern with text content: "Hello World"
  2. Go to Create Block Theme overwrite screen
  3. Enable both:
    - ✅ "Save Patterns"
    - ✅ "Localize Text"
  4. Save changes
  5. Inspect the pattern file
  6. ✅ Expected: Text should be wrapped in localization functions:

Test Case 4: Image Localization

  1. Create a pattern with an image from the Media Library
  2. Enable both:
    - ✅ "Save Patterns"
    - ✅ "Localize Images"
  3. Save changes
  4. ✅ Expected: Image should be copied to /assets/ directory
  5. ✅ Expected: Pattern should reference the local image path

Test Case 5: Templates Referencing Patterns

  1. Create a pattern and add it to a template
  2. Modify the template (add a paragraph block)
  3. Save with both "Save Template Changes" and "Save Patterns" enabled
  4. ✅ Expected: Both the template and pattern should be saved
  5. ✅ Expected: Template changes should be preserved
  6. ✅ Expected: Pattern reference should be updated correctly

Test Case 6: UI Label Update

  1. Go to Create Block Theme overwrite screen
  2. ✅ Expected: Checkbox should read "Save Patterns" (not "Save Synced Patterns")
  3. ✅ Expected: Help text should say "All patterns created in the Editor will be moved to the theme..."

@scruffian scruffian marked this pull request as ready for review December 3, 2025 17:05
@scruffian scruffian self-assigned this Dec 3, 2025
@bph bph added the Patterns about pattern management label Dec 3, 2025
Copy link
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

Most test cases are working well:

  • Test Case 1: Save All Pattern Types ✅
  • Test Case 2: Duplicate Pattern Names ✅
  • Test Case 3: Localization Options ✅
  • Test Case 4: Image Localization ✅
  • Test Case 6: UI Label Update ✅

But Test Case 5: Templates Referencing Patterns seems to break the template file. When I insert a pattern into a template and then save to the theme with localization, the template .html file is updated with <!-- wp:pattern {"slug":"pixl/page"} /-->, but the new template pattern isn't created (pixl/page in this case), which breaks the template in the editor as it can't find the template pattern. The new pattern referenced in the template is added to the theme with the correct contents.

@scruffian scruffian mentioned this pull request Dec 4, 2025
2 tasks
Copy link
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

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

I've reset my local env and I'm no longer seeing the issue with saving a pattern to a template. Test Case 5 is working well for me now ✅

I think we should bring this in! 🚢

@scruffian scruffian merged commit 9f57ccd into trunk Dec 5, 2025
2 checks passed
@scruffian scruffian deleted the save/patterns branch December 5, 2025 11:59
@JiveDig
Copy link

JiveDig commented Dec 12, 2025

This is great! I'm curious what the expectation is when using a synced pattern with overrides? I do this all the time but haven't tested with the latest update yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Patterns about pattern management

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants