Fix cases where $_SERVER['HTTP_HOST'] is used inside wp-config.php #730

Closed
scribu opened this Issue Aug 27, 2013 · 1 comment

Projects

None yet

2 participants

@scribu
Member
scribu commented Aug 27, 2013

Defining certain constants to be domain-agnostic is a sufficiently common practice to warrant consideration.

For example, the config file in markjaquith/WordPress-Skeleton has the following line:

define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/content' );

If you run wp without passing a --url parameter, you will get a warning:

Notice: Undefined index: HTTP_HOST in /Users/User/.composer/vendor/wp-cli/wp-cli/php/wp-cli.php(20) : eval()'d code on line 19

Several workarounds were discussed in #676 (comment).

We already try to guess the URL by doing some ugly wp-config.php parsing via regular expressions.

A more reliable way would be to do a database query:

  • need to account for the case where WP isn't installed yet; see #663
  • need to account for multisite
@scribu
Member
scribu commented Aug 31, 2013

A more reliable way would be to do a database query:

There's a logical problem with that: we want to do a query before loading the wp-config.php file, but the database credentials are inside the wp-config.php file.

@jeremyfelt jeremyfelt added a commit to washingtonstateuniversity/WSUWP-Platform that referenced this issue Oct 30, 2013
@jeremyfelt jeremyfelt Set a default HTTP_HOST for use with wp-cli
Our sunrise.php (and ms-settings.php if that's not around) require `HTTP_HOST` to be set in order to determine what domain and path are being requested.

If a wp-cli command is run without `--url` specified, `$_SERVER['HTTP_HOST']` is not available. This causes things to get confused on our end. Luckily, we can assume a default at the moment, wp.wsu.edu, and just specify it if the `WP_CLI_PHP_USED` server variable has been set.

See wp-cli/wp-cli#730 for possible future changes.
bbbed47
@danielbachhuber danielbachhuber added this to the 0.25.0 milestone Aug 23, 2016
@danielbachhuber danielbachhuber referenced this issue in wp-cli/wp-cli.github.com Aug 23, 2016
Merged

Mention `$_SERVER['HTTP_HOST']` in common issues #204

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment