Skip to content

Commit

Permalink
Improve WP_HOME determination
Browse files Browse the repository at this point in the history
See #101
  • Loading branch information
gmazzap committed Feb 27, 2023
1 parent 876cc48 commit 1cb6f60
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/08-Custom-Steps-Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,4 @@ By using that object in combination with custom template folders that WP Starter
- [Running WP CLI Commands](07-Running-WP-CLI-Commands.md)
- ***> Custom Steps Development***
- [Settings Cheat Sheet](09-Settings-Cheat-Sheet.md)
- [WP Starter Command](10-WP-Starter-Command.md)
- [WP Starter Command](10-WP-Starter-Command.md)
13 changes: 9 additions & 4 deletions templates/wp-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,18 @@
} #@@/SSL_FIX

URL_CONSTANTS : {
// Defining WP_HOME is highly suggested. We do our best here, but this will never be 100% fine.
if (!defined('WP_HOME')) {
$home = filter_var($_SERVER['HTTPS'] ?? '', FILTER_VALIDATE_BOOLEAN) ? 'https://' : 'http://';
$port = is_numeric($_SERVER['SERVER_PORT'] ?? '') ? (int)$_SERVER['SERVER_PORT'] : 0;
$scheme = isset($_SERVER['HTTPS'])
? (filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN) ? 'https' : 'http')
: ($port === 443 ? 'https' : 'http');
$home = "{$scheme}://";
$home .= $_SERVER['SERVER_NAME'] ?? 'localhost';
$port = $_SERVER['SERVER_PORT'] ?? '';
(is_numeric($port) && (int)$port > 0) and $home .= sprintf(':%d', $port);
$ports = ['https' => 443, 'http' => 80];
(($port > 0) && ($port !== $ports[$scheme])) and $home .= sprintf(':%d', $port);
define('WP_HOME', $home);
unset($home);
unset($port, $scheme, $home, $ports);
}

/** Set WordPress other URL / path constants not set via environment variables. */
Expand Down

0 comments on commit 1cb6f60

Please sign in to comment.