WordPress Folder Multisite – dev, staging, www versions


I am setting up a WordPress Network Multisite solution – and expect to serve distinct domains e.g.

These will be set within the /wp-admin/network/site-info.php?id=2 page – in the "Site Address(URL)" field.

I have three environments – each on a different physical device;

  • local.* (local development)
  • uat.* (customer staging / sign off)
  • www.* (production)

I will be using GIT to push custom code, WP & plugin updates from local > dev > www

The entire database will be cloned from www > dev | local – in order to recreate issues when required.

What approach should I use to programmatically define the subdomains such that I do not need to update database tables every time I restore a backup from www to local?

I did this on standard WP using the machine the code was running on to determine the url:

//Decide which subdomain to serve
$subdomain = "local.";
$var_hostname = gethostname();
$reqDom = $_SERVER['HTTP_HOST'];
if (strrpos($var_hostname, "dev") > -1) {
    $subdomain = "uat.";   
} else if (strrpos($var_hostname, "web") > -1) {
    // web host found... must be LIVE
    $subdomain = "www";
define('WP_HOME', 'https://' . $subdomain . 'chef.com');
define('WP_SITEURL', 'https://' . $subdomain . 'chef.com');

I’ve tried the following filter but with no success:

// Derive which URL's to use - along with multisite
function my_filter_option_siteurl($siteurl) {
    // filter $siteurl here   
    return getSanitisedEnvURL($siteurl);
Wayne Foster 8 months 2020-12-01T13:10:19-05:00 0 Answers 7 views 0

Leave an answer