ideas
ideas copied to clipboard
Command for changing the domain of a site
Describe your use case and the problem you are facing
As discussed during the WP-CLI office hours chat today (discussion starts here), several people expressed interest in a command that specifically handles changing the domain name of a site. Currently wp search-replace can be used for this but there are pitfalls, for example if the search value is a substring of the replacement then the command cannot be repeated without causing further unwanted replacements, and being able to reliably replace all instances of full URLs.
Related links:
- https://github.com/Automattic/go-search-replace
Describe the solution you'd like
Introduce a dedicated command for changing the domain name of a site which performs a search and replace across the database, but with more knowledge of the underlying data structure used by WordPress to avoid pitfalls mentioned above and to be as fast as possible.
Lots to consider here, I'll add notes to this issue that were raised during the chat.
Considerations
- Handling the scheme. Need options for ignoring the scheme, and forcing it to
httpsorhttp. - Input format. Does this just accept a host name or a URL including scheme?
- Multisite behaviour. Will this be a network-wide change by default?
- Which core tables and columns should be included by default? Assuming all others can be ignored because they'll never contain a domain name.
wp_commentmeta.meta_valuewp_comments.comment_author- maybewp_comments.comment_author_emailwp_comments.comment_author_urlwp_comments.comment_contentwp_links.link_urlwp_options.option_valuewp_postmeta.meta_valuewp_posts.post_contentwp_posts.post_title- maybewp_posts.post_excerptwp_posts.post_content_filteredwp_posts.guid- see notes belowwp_terms.name- maybewp_termmeta.meta_valuewp_usermeta.meta_valuewp_users.user_email- see notes belowwp_users.user_urlwp_users.display_name- maybe- Any others?
- Non-core database tables. Included by default? Likely yes.
- GUIDs. There's a use case for both changing these and retaining them.
- Email addresses. Same as above.
- Subdomain (or possibly more generally, substring) matching behaviour. If you want to replace
example.comwithmydev.localhost, shouldsubdomain.example.combe affected or not? - Considerations outside of the database, eg. any of the constants in
wp-config.php. - Use the current site address or the domain in
--urlas the "from" domain, is there a need for it to be included as a separate flag in the command?- What about broken sites?
- What about importing a database from elsewhere and
WP_HOMEandWP_SITEURLare defined in the config with a different domain.
Great idea. This will simplify a lot of people lives. :) I would like to add another consideration:
- Make sure we do not replace email domain like @example.com (covered by substring, but wanted to make sure).
This comes up again and again.
As it stands this issue feels quite epic to me (and probably others) and hence feels intimidating. Since it's been some time without any movement - can this maybe be broken up into smaller chunks so it is easier to tackle?