Skip to content

wpcomsh: Replace JSON-escaped URLs during Playground restores - #55041

Closed
chubes4 wants to merge 3 commits into
trunkfrom
fix/issue-55039-jetpack
Closed

chubes4 wants to merge 3 commits into
trunkfrom
fix/issue-55039-jetpack

Conversation

@chubes4

@chubes4 chubes4 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #55039

Proposed changes

  • When a Playground backup (such as a WordPress Studio preview) is restored, SQL_Postprocessor::replace_urls() swaps the old site URL for the new one with wp search-replace. URLs stored as raw JSON are written with escaped slashes (http:\/\/localhost:8881\/wp-content\/...), which is how page builders like Elementor store each page's layout (_elementor_data). Before v2.1.10 of wp-cli/search-replace-command, search-replace does not match that form, so images, links and buttons on those pages keep pointing at the old local address even though the files were restored.
  • search-replace handles the JSON form itself since wp-cli/search-replace-command#213 (released in v2.1.10). The latest stable WP-CLI release, 2.12.0, predates that change and bundles an older version of the command.
  • This PR applies the same rule from the caller side: a small replace_url() helper runs the existing replacement for the URL, then again for its JSON-encoded form with the surrounding quotes removed, which is the encoding the upstream fix uses (json_encode_strip_quotes()). The second pass is skipped when the encoded form is identical to the URL. It is used for the site URL, a differing home URL and the Playground app scope, and nothing in it is specific to Elementor.
  • On a WP-CLI that already includes the upstream fix, the second pass finds nothing to change. Once the hosting WP-CLI includes it, this helper can be reduced back to a single call.
  • Trade-off: each URL now costs a second search-replace scan over the temporary tables when the encoded form differs.

Other information

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable?

Testing instructions

  • Build a Studio preview (or restore a Playground backup) from a local site whose pages are built with Elementor and include images.
  • Before this change: the restored site's images and internal links point at http://localhost:<port>/....
  • After this change: they point at the site's own domain.
  • PlaygroundPostprocessTest::test_replace_urls_in_plain_text_and_json checks the exact commands issued for the site URL, a differing home URL and the app scope, including that backslashes reach WP-CLI intact.

Verification

End to end, on a throwaway WordPress 7.1.4 install with MySQL: Playground temporary tables seeded with siteurl/home = http://localhost:8881, an Elementor-shaped _elementor_data JSON value, a plain URL and a serialized URL, then the real SQL_Postprocessor::replace_urls() run through wp eval-file so it calls the real wp search-replace.

WP-CLI Code _elementor_data image URL after restore Rows still containing localhost:8881
2.12.0 (latest stable) trunk http://localhost:8881/wp-content/uploads/... 1
2.12.0 (latest stable) this PR https://example.wpcomstaging.com/wp-content/uploads/... 0
3.0 alpha (includes the upstream fix) trunk https://example.wpcomstaging.com/... 0
3.0 alpha (includes the upstream fix) this PR https://example.wpcomstaging.com/... 0

Plain and serialized URLs are replaced in every case.

PHPUnit: PlaygroundPostprocessTest passes (10 tests, 32 assertions) against WordPress 7.1.4 and its matching test library. The new test fails on trunk's class-sql-postprocessor.php and passes with this change.

This change was finalized directly with git and gh rather than through the usual automated pipeline, because that pipeline's test runner was unavailable.

AI disclosure

Written by OpenAI GPT (Pi coding agent via Homeboy Cook) and revised and tested by Claude Fable 5.1 (Pi coding agent, via Roadie). Chris Huber directed the work.

The restore replaced the old site URL with wp search-replace, which
misses URLs stored in JSON with escaped slashes, such as Elementor's
_elementor_data. Images and links on those pages kept pointing at the
old local address. Replace the escaped form of each URL too.
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (WordPress.com Site Helper), and enable the fix/issue-55039-jetpack branch.

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • 🔴 Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so:

## Does this pull request change what data or activity we track or use?

My PR adds *x* and *y*.

Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Wpcomsh plugin:

  • Next scheduled release: Atomic deploys happen twice daily on weekdays (p9o2xV-2EN-p2)

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Nov 17, 2026
@jp-launch-control

jp-launch-control Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/plugins/wpcomsh/imports/playground/class-sql-postprocessor.php 165/200 (82.50%) 3.01% -5 💚

Full summary · PHP report

A mock without expectations raises a PHPUnit notice.
Use the JSON encoding with the quotes stripped, as wp-cli/search-replace-command
does since v2.1.10, and skip the second pass when the encoded form is
the same as the URL.
@chubes4

chubes4 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of fixing this at the platform level. wp search-replace already handles JSON-encoded URLs since wp-cli/search-replace-command#213 (v2.1.10); working around an older WP-CLI here would add a second full scan to every restore. Keeping #55039 open until the hosting WP-CLI includes that fix.

Written by Claude Fable 5.1 (Pi coding agent, via Roadie). Chris Huber directed the work.

@chubes4 chubes4 closed this Nov 17, 2026
@chubes4
chubes4 deleted the fix/issue-55039-jetpack branch November 17, 2026 09:33
@github-actions github-actions Bot removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Nov 17, 2026
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.

wpcomsh: Playground restores leave JSON-escaped old URLs (e.g. Elementor data) unreplaced

1 participant