Repository navigation
Conversation
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.
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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: Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Wpcomsh plugin:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
|
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.
|
Closing in favour of fixing this at the platform level. Written by Claude Fable 5.1 (Pi coding agent, via Roadie). Chris Huber directed the work. |
Fixes #55039
Proposed changes
SQL_Postprocessor::replace_urls()swaps the old site URL for the new one withwp 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 ofwp-cli/search-replace-command,search-replacedoes 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-replacehandles 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.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.search-replacescan over the temporary tables when the encoded form differs.Other information
Testing instructions
http://localhost:<port>/....PlaygroundPostprocessTest::test_replace_urls_in_plain_text_and_jsonchecks 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_dataJSON value, a plain URL and a serialized URL, then the realSQL_Postprocessor::replace_urls()run throughwp eval-fileso it calls the realwp search-replace._elementor_dataimage URL after restorelocalhost:8881http://localhost:8881/wp-content/uploads/...https://example.wpcomstaging.com/wp-content/uploads/...https://example.wpcomstaging.com/...https://example.wpcomstaging.com/...Plain and serialized URLs are replaced in every case.
PHPUnit:
PlaygroundPostprocessTestpasses (10 tests, 32 assertions) against WordPress 7.1.4 and its matching test library. The new test fails on trunk'sclass-sql-postprocessor.phpand 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.