• Resolved dwcouch

    (@dwcouch)


    I recently thought I’d simplify the process of migrating updates to sites from my local to a staging and finally to a production server by adding a switch to the wp-config to switch DB’s and in some cases FTP settings. This works great when using FTP alone.

    However I’ve discovered that Duplicator ignores my switch case’s and updates every instance of DB_NAME, DB_USER, DB_PASSWORD, etc…

    I’m considering just creating a wp-config.switch file and then just copying and pasting the contents each time I migrate. Not elegant but….

    Would y’all consider some logic to NOT override the switch? Or perhaps there’s a setting I’m missing?

    // ** MySQL settings - You can get this info from your web host ** //
    switch($_SERVER['HTTP_HOST']) {
    	/* DEVELOPMENT */
        case 'dev.mysite.com':
    		/** The name of the database for WordPress */
    		define('DB_NAME', 'wpdev_mysite');
    
    		/** MySQL database username */
    		define('DB_USER', 'dev_username');
    
    		/** MySQL database password */
    		define('DB_PASSWORD', 'dev_password');
    
    		/** MySQL hostname */
    		define('DB_HOST', 'localhost');
        break;
        /* STAGING */
        case 'stage.mysite.com':
    		/** The name of the database for WordPress */
    		define('DB_NAME', 'wpstage_mysite');
    
    		/** MySQL database username */
    		define('DB_USER', 'stage_username');
    
    		/** MySQL database password */
    		define('DB_PASSWORD', 'stage_password');
    
    		/** MySQL hostname */
    		define('DB_HOST', 'localhost');
        break;
        /* PRODUCTION */
        case 'mysite.com':
    		/** The name of the database for WordPress */
    		define('DB_NAME', 'wpprod_mysite');
    
    		/** MySQL database username */
    		define('DB_USER', 'username');
    
    		/** MySQL database password */
    		define('DB_PASSWORD', 'password');
    
    		/** MySQL hostname */
    		define('DB_HOST', 'localhost');
        break;
        default:
        break;

    https://www.ads-software.com/plugins/duplicator/

Viewing 1 replies (of 1 total)
  • Hey dwcouch,

    That probably won’t work… Trying to create a state engine that even knows about a case statement would be pretty difficult… I think a better option might be to have an option where the the wp-config.php wasn’t even replaced and then you could manually update.

    Another possible work around would be to just leave the switch vars that you want the plugin to replace and the put the other two case statements into separate include files then call include_once, or if you don’t any then put them all in includes…

    Example:

    /* DEV */
    case 'dev.mysite.com':
    	incluce_once('wp-config-dev.php');
    	break;
    /* STAGING */
    case 'stage.mysite.com':
    	incluce_once('wp-config-qa.php');
    	break;
    /* PRODUCTION */
    case 'mysite.com':
    	incluce_once('wp-config-prod.php');
    	break;

    I have used similar code on other projects…

    Cheers~

Viewing 1 replies (of 1 total)
  • The topic ‘wp-config switch’ is closed to new replies.