Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ multisite, this will just be the tables for the current site unless
Search/replace intelligently handles PHP serialized data, and does not
change primary key values.

Note: URLs stored inside JSON-encoded data (such as block attributes or
form configurations) often have forward slashes escaped with backslashes
(e.g. `https:\/\/example.com`). Standard search/replace with unescaped
URLs will not match these. To replace URLs in JSON-encoded strings, run
an additional search/replace with escaped slashes (e.g.
`wp search-replace 'https:\/\/example.com' 'https:\/\/example.test'`).
The JSON-encoded form of the search string is replaced as well, so a
search for `https://example.com` also matches `https:\/\/example.com`
in JSON stored in the database. This does not apply with `--regex`,
where the pattern itself has to account for escaped slashes.

Tables without a primary key are skipped. To check whether a table has a
primary key, run `wp db query 'DESCRIBE <table>'` and look for 'PRI' in
Expand Down Expand Up @@ -151,9 +149,6 @@ the Key column.
# Search and replace but skip one column
$ wp search-replace 'http://example.test' 'http://example.com' --skip-columns=guid

# Search/replace JSON-encoded URLs (where forward slashes are escaped with backslashes)
$ wp search-replace 'https:\/\/example.com' 'https:\/\/example.test'

# Run search/replace operation but dont save in database
$ wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run

Expand Down
13 changes: 4 additions & 9 deletions src/Search_Replace_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,10 @@ class Search_Replace_Command extends WP_CLI_Command {
* Search/replace intelligently handles PHP serialized data, and does not
* change primary key values.
*
* Note: URLs stored inside JSON-encoded data (such as block attributes or
* form configurations) often have forward slashes escaped with backslashes
* (e.g. `https:\/\/example.com`). Standard search/replace with unescaped
* URLs will not match these. To replace URLs in JSON-encoded strings, run
* an additional search/replace with escaped slashes (e.g.
* `wp search-replace 'https:\/\/example.com' 'https:\/\/example.test'`).
* The JSON-encoded form of the search string is replaced as well, so a
* search for `https://example.com` also matches `https:\/\/example.com`
* in JSON stored in the database. This does not apply with `--regex`,
* where the pattern itself has to account for escaped slashes.
*
* Tables without a primary key are skipped. To check whether a table has a
* primary key, run `wp db query 'DESCRIBE <table>'` and look for 'PRI' in
Expand Down Expand Up @@ -268,9 +266,6 @@ class Search_Replace_Command extends WP_CLI_Command {
* # Search and replace but skip one column
* $ wp search-replace 'http://example.test' 'http://example.com' --skip-columns=guid
*
* # Search/replace JSON-encoded URLs (where forward slashes are escaped with backslashes)
* $ wp search-replace 'https:\/\/example.com' 'https:\/\/example.test'
*
* # Run search/replace operation but dont save in database
* $ wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run
*
Expand Down
Loading