Skip to content

Commit 54d3e08

Browse files
Document replacing JSON-serialized URLs with escaped slashes (#248)
Closes #45
1 parent aacb1af commit 54d3e08

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ multisite, this will just be the tables for the current site unless
2323
Search/replace intelligently handles PHP serialized data, and does not
2424
change primary key values.
2525

26+
Note: URLs stored inside JSON-encoded data (such as block attributes or
27+
form configurations) often have forward slashes escaped with backslashes
28+
(e.g. `https:\/\/example.com`). Standard search/replace with unescaped
29+
URLs will not match these. To replace URLs in JSON-encoded strings, run
30+
an additional search/replace with escaped slashes (e.g.
31+
`wp search-replace 'https:\/\/example.com' 'https:\/\/example.test'`).
32+
2633
Tables without a primary key are skipped. To check whether a table has a
2734
primary key, run `wp db query 'DESCRIBE <table>'` and look for 'PRI' in
2835
the Key column.
@@ -144,6 +151,9 @@ the Key column.
144151
# Search and replace but skip one column
145152
$ wp search-replace 'http://example.test' 'http://example.com' --skip-columns=guid
146153

154+
# Search/replace JSON-encoded URLs (where forward slashes are escaped with backslashes)
155+
$ wp search-replace 'https:\/\/example.com' 'https:\/\/example.test'
156+
147157
# Run search/replace operation but dont save in database
148158
$ wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run
149159

‎src/Search_Replace_Command.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ class Search_Replace_Command extends WP_CLI_Command {
140140
* Search/replace intelligently handles PHP serialized data, and does not
141141
* change primary key values.
142142
*
143+
* Note: URLs stored inside JSON-encoded data (such as block attributes or
144+
* form configurations) often have forward slashes escaped with backslashes
145+
* (e.g. `https:\/\/example.com`). Standard search/replace with unescaped
146+
* URLs will not match these. To replace URLs in JSON-encoded strings, run
147+
* an additional search/replace with escaped slashes (e.g.
148+
* `wp search-replace 'https:\/\/example.com' 'https:\/\/example.test'`).
149+
*
143150
* Tables without a primary key are skipped. To check whether a table has a
144151
* primary key, run `wp db query 'DESCRIBE <table>'` and look for 'PRI' in
145152
* the Key column.
@@ -261,6 +268,9 @@ class Search_Replace_Command extends WP_CLI_Command {
261268
* # Search and replace but skip one column
262269
* $ wp search-replace 'http://example.test' 'http://example.com' --skip-columns=guid
263270
*
271+
* # Search/replace JSON-encoded URLs (where forward slashes are escaped with backslashes)
272+
* $ wp search-replace 'https:\/\/example.com' 'https:\/\/example.test'
273+
*
264274
* # Run search/replace operation but dont save in database
265275
* $ wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run
266276
*

0 commit comments

Comments
 (0)