Skip to content

Commit 60d0715

Browse files
committed
Add smart URL transformation support for search-replace
1 parent a1c38e4 commit 60d0715

5 files changed

Lines changed: 1081 additions & 16 deletions

File tree

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contr
1010
## Using
1111

1212
~~~
13-
wp search-replace <old> <new> [<table>...] [--dry-run] [--network] [--all-tables-with-prefix] [--all-tables] [--export[=<file>]] [--export_insert_size=<rows>] [--skip-tables=<tables>] [--skip-columns=<columns>] [--include-columns=<columns>] [--precise] [--recurse-objects] [--verbose] [--regex] [--regex-flags=<regex-flags>] [--regex-delimiter=<regex-delimiter>] [--regex-limit=<regex-limit>] [--format=<format>] [--report] [--report-changed-only] [--log[=<file>]] [--before_context=<num>] [--after_context=<num>]
13+
wp search-replace <old> <new> [<table>...] [--dry-run] [--network] [--all-tables-with-prefix] [--all-tables] [--export[=<file>]] [--export_insert_size=<rows>] [--skip-tables=<tables>] [--skip-columns=<columns>] [--include-columns=<columns>] [--smart-url] [--analyze-tables] [--precise] [--recurse-objects] [--verbose] [--regex] [--regex-flags=<regex-flags>] [--regex-delimiter=<regex-delimiter>] [--regex-limit=<regex-limit>] [--format=<format>] [--report] [--report-changed-only] [--log[=<file>]] [--before_context=<num>] [--after_context=<num>]
1414
~~~
1515

1616
Searches through all rows in a selection of tables and replaces
@@ -73,6 +73,23 @@ change primary key values.
7373
Perform the replacement on specific columns. Use commas to
7474
specify multiple columns.
7575

76+
[--smart-url]
77+
Enable smart URL mode. Automatically skips 75+ WordPress core columns
78+
that cannot contain URLs (like post_type, post_status, user_pass, etc.),
79+
significantly improving performance for URL replacements. This is
80+
particularly useful when migrating sites or changing domain names.
81+
Performance: ~34% faster on large databases.
82+
Note: This flag is automatically enabled when the search string starts
83+
with http:// or https://. Use --verbose to see which columns are skipped.
84+
85+
[--analyze-tables]
86+
Enable advanced table analysis mode. Analyzes MySQL column datatypes
87+
to automatically skip non-text columns (integers, dates, enums, etc.)
88+
and columns matching common WordPress-style naming patterns (e.g. `*_id`,
89+
`*_count`, `*_status`, etc.) in addition to the static skip list. Useful
90+
for plugin tables with custom schemas. Requires --smart-url to be enabled.
91+
Note: Adds a small overhead for table introspection.
92+
7693
[--precise]
7794
Force the use of PHP (instead of SQL) which is more thorough,
7895
but slower.
@@ -139,6 +156,12 @@ change primary key values.
139156
# Search/replace to a SQL file without transforming the database
140157
$ wp search-replace foo bar --export=database.sql
141158

159+
# URL replacement with smart column skipping (faster for URL changes)
160+
$ wp search-replace 'http://example.test' 'http://example.com' --smart-url
161+
162+
# URL replacement with advanced table analysis for plugin tables
163+
$ wp search-replace 'http://old.test' 'http://new.test' --smart-url --analyze-tables
164+
142165
# Bash script: Search/replace production to development url (multisite compatible)
143166
#!/bin/bash
144167
if $(wp --url=http://example.com core is-installed --network); then

0 commit comments

Comments
 (0)