ulumi
ulumi

Reputation: 63

wp-config.php auto site urls

I've found myself needing to update the defined values in wp-config.php back and forth to reflect my auto-assigned xip.io addresses from work to home.

Then I thought of just using the php values to accommodate the different urls. I feel there must be a good reason not to do this, but while in development phases of building a website that seems like a pretty good solution.

Can anyone describe why this shouldn't be done, aside from the obvious wanting to have more flexibility in production mode?

wp-config.php
// auto site urls
$autourl = 'http://'.$_SERVER['HTTP_HOST'].'/';
define( 'WP_HOME',  $autourl);
define( 'WP_SITEURL', $autourl );

Thanks!

Upvotes: 2

Views: 335

Answers (1)

Marty
Marty

Reputation: 39456

What you've done here is a pretty common way to go about it. A more full-on method is storing the configuration in environment variables. Environment variables are obviously defined by the environment that your app runs in. This has a few advantages:

  1. Separates your configuration from your code.
  2. The environment is responsible for configuration dealing with how your app should run within it. This is more logical.
  3. You avoid having to move sensitive configuration information around with your code (e.g. database connection information).

With that said, I don't often use this approach and tend toward something akin to what you have done, just in a different format. Environment variables to me seem better suited to larger projects with multiple environments (3+) and with a lot of people involved that may accidentally leak sensitive configuration code.

Resources:

Upvotes: 1

Related Questions