For doing local development on a WordPress site (http://www.example.com), I was previously overriding the WP_SITEURL
and WP_HOME
values in wp-config.php
like so:
define('WP_SITEURL', 'http://local-example/');
define('WP_HOME', 'http://local-example/');
This would allow me to copy the database and site files to a local server, and make modifications as necessary, testing on the local install.
It was then necessary to convert the install to a WordPress Multisite so that users, authentication, plugins, etc. could be shared between the main site and a secondary site, hosted on a subdomain (http://second.example.com).
The method above to override the values in the wp_options
table no longer works, but I am unsure the proper way to set a value for the entries in wp_blogs
as well as the wp_2_options
table for the primary and subdomain.
Updating my HOSTS
file is somewhat of a workaround, but it not ideal (I am not able to compare to the live site, etc). Running a script to change the database values is another option I have tried, but is slightly more cumbersome, so my questions is whether or not there is an option in MultiSite to override these values in a settings file, such as wp-config.php
, and if so what it would look like.
Update: full updated plugin code with additional description can be found here: http://justinsilver.com/technology/wordpress/wordpress-plugins/wordpress-plugin-wp-server-migration/
I was able to come up with a solution with the help of @user916011. I needed to be able to copy the
wp_options
table(s) to my development environment as they contain configurations that are needed. To overcome the issue of not being able to set the WP_SITEURL and WP_HOME values in MultiSite, I wrote a custom filter to replace the_config_wp_siteurl()
and_config_wp_home()
functions that are available for non-multisite installs that is included in a plugin that is available network-wide and is configured inwp-config.php
. I am then able to copy all of the database tables exceptwp_site
andwp_blogs
to a local database.I highly recommend the URL Token Replacement Techniques for WordPress 3.0 article by Chris Murphy to help handle URLs in your content.
This example assumes a subdomain multisite install, with a domain of
example.com
and two subdomains,www.example.com
andsecond.example.com
. The local development URLs will bewww.example.local
andsecond.example.local
respectively.Database Changes:
Update the domain value in
wp_site
:Update the domain value(s) in
wp_blogs
:Plugin Code:
The following plugin should be installed network-wide.
Configure wp-config.php:
Add new constants to
wp-config.php
. The primary site should use the standardWP_HOME
andWP_SITEURL
and the tertiary URLs should useWP_{$blog_id}_HOME
andWP_{$blog_id}_SITEURL
You could use the update_option in functions.php
There’s a similar question being asked here: Team Development of a WordPress Site which I provided a possible solution for. In your case, you may not want to go to that extent (though it would be very flexible); however, you could always look at the portion of the answer that mentions a domain-replacement technique.
I’ve outlined that solution here: URL Token Replacement Techniques…
I had the same issue and wanted a solution as similar to defining WP_HOME & WP_SITEURL in wp-config.php as possible.
I can’t use a plugin, because I am syncing with GIT and don’t want to have that plugin in my repo and I would have to add the plugin everytime… I suppose it could be activated network wide through the wp_sitemeta table… but it wasn’t ideal for me.
I came up with this solution.
Be sure to not sync wp_blogs, wp_site, wp_sitemeta. And then add this code to your local wp-config.php somewhere below
$table_prefix
:This will make sure your sites are synced up to your local wp_blogs table.
The only drawback is that when you add a new site, you do manually need to copy it into your wp_blogs table and update its local url.
This question is too old to answer, but recently I faced a similar situation where I have to migrate my wp site from staging to production and it was painful as it is having 5 subsite.
After scratching my head for all day, I found a simple and useful solution.
Of course one have to make changes in wp-config.php.
Other then that you have to follow below steps.
Generate database dump using following command.
After that open that file in any editor.
Find and replace your old domain with new domain.
Now restore the database with dump you created.