Skip to content

Commit

Permalink
[BUGS-7678] update multisite install instructions to use `PANTHEON_HO…
Browse files Browse the repository at this point in the history
…STNAME` constant (#42)

* add a fallback $hostname and use that if SERVER['HTTP_HOST'] is not set

* simplify the config_file_contents and add a docblock for the filter

* remove the else condition

* use HTTP_HOST if available for lower environments, too

* remove complicated hostname configuration
replace with PANTHEON_HOSTNAME constant

* remove unused $hostname var

* update DOMAIN_CURRENT_SITE to only use PANTHEON_HOSTNAME if it's defined
  • Loading branch information
jazzsequence authored Apr 30, 2024
1 parent fd19dc2 commit c2b5e81
Showing 1 changed file with 10 additions and 30 deletions.
40 changes: 10 additions & 30 deletions inc/network/includes-network.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ function network_step1( $errors = false ) {
function network_step2( $errors = false ) {
global $wpdb, $is_nginx;

$hostname = get_clean_basedomain();
$slashed_home = trailingslashit( get_option( 'home' ) );
$base = parse_url( $slashed_home, PHP_URL_PATH );
$document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
Expand Down Expand Up @@ -459,40 +458,21 @@ function network_step2( $errors = false ) {
</label></p>
<textarea id="network-wpconfig-rules" class="code" readonly="readonly" cols="100" rows="31" aria-describedby="network-wpconfig-rules-description">
<?php ob_start(); ?>
if ( !empty( $_ENV['PANTHEON_ENVIRONMENT'] )) {
$site_name = $_ENV['PANTHEON_SITE_NAME'];
// Override $hostname value as needed.
switch ( $_ENV['PANTHEON_ENVIRONMENT'] ) {
case 'live':
$hostname = $_SERVER['HTTP_HOST'];
break;
case 'test':
$hostname = 'test-' . $site_name . '.pantheonsite.io';
break;
case 'dev':
$hostname = 'dev-' . $site_name . '.pantheonsite.io';
break;
case 'lando':
$hostname = $site_name . '.lndo.site';
break;
default:
$hostname = $_ENV['PANTHEON_ENVIRONMENT'] . '-' . $site_name . '.pantheonsite.io';
break;
}
} else {
// Override with a default hostname.
$hostname = '<?php echo $hostname; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>';
}
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?> );
define( 'DOMAIN_CURRENT_SITE', $hostname );
define( 'PATH_CURRENT_SITE', '<?php echo $base; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>' );
// Use PANTHEON_HOSTNAME if in a Pantheon environment, otherwise use HTTP_HOST.
define( 'DOMAIN_CURRENT_SITE', defined( 'PANTHEON_HOSTNAME' ) ? PANTHEON_HOSTNAME : $_SERVER['HTTP_HOST'] );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
<?php
$config_file_contents = ob_get_contents();
ob_end_clean();
$config_file_contents = apply_filters( 'pantheon.multisite.config_contents', $config_file_contents );
/**
* Filters the contents of the network configuration rules for WordPress configuration files.
*
* This allows this screen to be modified for different environments or configurations (e.g. Composer-based WordPress multisite).
*
* @param string $config_file_contents The contents of the network configuration rules.
*/
$config_file_contents = apply_filters( 'pantheon.multisite.config_contents', ob_get_clean() );
echo $config_file_contents; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</textarea>
Expand Down

0 comments on commit c2b5e81

Please sign in to comment.