Skip to content

Commit

Permalink
[BUGS-7678] add PANTHEON_HOSTNAME to application.pantheon.php (#119) (#…
Browse files Browse the repository at this point in the history
…120)

* break up the PANTHEON_ENVIRONMENT conditional

so we can use the same one later for the new stuff we're adding

* define PANTHEON_HOSTNAME if it's not already defined

* add phpcbf command

* lint

* add our filter to update the config instructions
use Config::define instead of define

* return the contents

* apply changes from wp upstream
  • Loading branch information
jazzsequence authored Apr 30, 2024
1 parent 541e8b9 commit 5178b15
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
"lint:phpcs": [
"vendor/bin/phpcs -s ."
],
"lint:phpcbf": [
"vendor/bin/phpcbf ."
],
"lint:bash": [
"shellcheck private/scripts/*.sh"
],
Expand Down
55 changes: 35 additions & 20 deletions config/application.pantheon.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,45 @@
use Roots\WPConfig\Config;
use function Env\env;

if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && ! isset( $_ENV['LANDO'] ) ) {
// We can use PANTHEON_SITE_NAME here because it's safe to assume we're on a Pantheon environment if PANTHEON_ENVIRONMENT is set.
$sitename = $_ENV['PANTHEON_SITE_NAME'];
$baseurl = $_ENV['PANTHEON_ENVIRONMENT'] . '-' . $sitename . '.pantheonsite.io';

$scheme = 'http';
if ( isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ) {
$scheme = 'https';
}
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) {
if ( ! isset( $_ENV['LANDO'] ) ) {
// We can use PANTHEON_SITE_NAME here because it's safe to assume we're on a Pantheon environment if PANTHEON_ENVIRONMENT is set.
$sitename = $_ENV['PANTHEON_SITE_NAME'];
$baseurl = $_ENV['PANTHEON_ENVIRONMENT'] . '-' . $sitename . '.pantheonsite.io';

// Define the WP_HOME and WP_SITEURL constants if they aren't already defined.
if ( ! env( 'WP_HOME' ) ) {
// If HTTP_HOST is set, use that as the base URL. It's probably more accurate.
if ( isset( $_SERVER['HTTP_HOST'] ) ) {
$baseurl = $_SERVER['HTTP_HOST'];
$scheme = 'http';
if ( isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ) {
$scheme = 'https';
}

$homeurl = $scheme . '://' . $baseurl;
Config::define( 'WP_HOME', $homeurl );
putenv( 'WP_HOME=' . $homeurl );
// Define the WP_HOME and WP_SITEURL constants if they aren't already defined.
if ( ! env( 'WP_HOME' ) ) {
// If HTTP_HOST is set, use that as the base URL. It's probably more accurate.
if ( isset( $_SERVER['HTTP_HOST'] ) ) {
$baseurl = $_SERVER['HTTP_HOST'];
}

$homeurl = $scheme . '://' . $baseurl;
Config::define( 'WP_HOME', $homeurl );
putenv( 'WP_HOME=' . $homeurl );

if ( ! env( 'WP_SITEURL' ) ) {
Config::define( 'WP_SITEURL', $homeurl . '/wp' );
putenv( 'WP_SITEURL=' . $homeurl . '/wp' );
if ( ! env( 'WP_SITEURL' ) ) {
Config::define( 'WP_SITEURL', $homeurl . '/wp' );
putenv( 'WP_SITEURL=' . $homeurl . '/wp' );
}
}
}

if ( ! defined( 'PANTHEON_HOSTNAME' ) ) {
$site_name = $_ENV['PANTHEON_SITE_NAME'];
$hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : $_ENV['PANTHEON_ENVIRONMENT'] . "-{$site_name}.pantheonsite.io";
$hostname = isset( $_ENV['LANDO'] ) ? "{$site_name}.lndo.site" : $hostname;
define( 'PANTHEON_HOSTNAME', $hostname );
}
}

// Update the multisite configuration to use Config::define() instead of define.
add_filter( 'pantheon.multisite.config_contents', function ( $config_contents ) {
$config_contents = str_replace( 'define(', 'Config::define(', $config_contents );
return $config_contents;
} );

0 comments on commit 5178b15

Please sign in to comment.