Skip to content

Conversation

@adamziel
Copy link
Collaborator

@adamziel adamziel commented Dec 6, 2025

Summary

When exporting a Playground and restoring it in a different browser tab or session, image and media URLs break because they still reference the original scope path segment (e.g., /scope:abc123/). This change fixes that by recording the site URL at export time and replacing it during import.

  • The export now includes a playground-export.json manifest containing the site URL
  • During import, if the old URL differs from the new one, we run SQL UPDATE queries to replace all occurrences across wp_posts, wp_postmeta, wp_options, wp_usermeta, wp_termmeta, and wp_comments tables

This is a simple approach using SQL REPLACE queries that handles the ASCII-based scope pattern (/scope:xxx/) reliably. It can be upgraded to use the WordPress-importer URL rewriting pipeline once it's reusable outside of the WXR import pipeline.

Fixes #2982

Test plan

  • Export a Playground with uploaded images in post content
  • Import the zip into a new Playground tab (different scope)
  • Verify images display correctly (URLs updated to new scope)
  • Run npx nx test playground-blueprints --testFile=import-wordpress-files.spec.ts

When exporting a Playground and restoring it in a different scope, image and
media URLs break because they still reference the original scope path segment
(e.g., /scope:abc123/). This change fixes that by recording the site URL at
export time and replacing it during import.

The export now includes a playground-export.json manifest containing the site
URL. During import, if the old URL differs from the new one, we run SQL UPDATE
queries to replace all occurrences across wp_posts, wp_postmeta, wp_options,
wp_usermeta, wp_termmeta, and wp_comments tables.
Inline the manifest filename constant and remove the exported interface.
When the manifest file is missing (legacy exports), infer the old site URL
from the database by querying the siteurl option directly with SQL.
When importing a Playground export into a different scope, we now replace
just the /scope:xyz/ path segment rather than the entire site URL. This is
more targeted and avoids accidentally replacing URL substrings that happen
to match but aren't scope-related.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rewrite assets urls when restoring Playground from a zip file

2 participants