Skip to content

Commit fdb1b66

Browse files
committed
[BUGS-7620] define WP_HOME (pantheon-systems#115)
* require a new application.pantheon.php file * use application.pantheon.php to define WP_HOME and make it available for future application.php modifications * ignore internal errors in phpcs rulesets * linting * ignore application.pantheon.php filename pattern * bump actions/cache to v4 * patch set-output with environment var see https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ * add the WP_HOME and WP_SITEURL values to the environment after we define them if they're already defined, we don't run this code path * look for the LANDO environment variable to check for Lando * use the lando environment variable in application.php, too * fix spacing * ignore the putenv that we added
1 parent 6f00fa9 commit fdb1b66

File tree

4 files changed

+38
-45
lines changed

4 files changed

+38
-45
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ jobs:
2525

2626
- name: Cache Composer dependencies
2727
id: composer-cache
28-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
28+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
2929

30-
- uses: actions/cache@v2
30+
- uses: actions/cache@v4
3131
with:
3232
path: ${{ steps.composer-cache.outputs.dir }}
3333
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}

config/application.pantheon.php

+20-29
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,30 @@
1313
use Roots\WPConfig\Config;
1414
use function Env\env;
1515

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

22-
$scheme = 'http';
23-
if ( isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ) {
24-
$scheme = 'https';
25-
}
21+
$scheme = 'http';
22+
if ( isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ) {
23+
$scheme = 'https';
24+
}
2625

27-
// Define the WP_HOME and WP_SITEURL constants if they aren't already defined.
28-
if ( ! env( 'WP_HOME' ) ) {
29-
// If HTTP_HOST is set, use that as the base URL. It's probably more accurate.
30-
if ( isset( $_SERVER['HTTP_HOST'] ) ) {
31-
$baseurl = $_SERVER['HTTP_HOST'];
32-
}
26+
// Define the WP_HOME and WP_SITEURL constants if they aren't already defined.
27+
if ( ! env( 'WP_HOME' ) ) {
28+
// If HTTP_HOST is set, use that as the base URL. It's probably more accurate.
29+
if ( isset( $_SERVER['HTTP_HOST'] ) ) {
30+
$baseurl = $_SERVER['HTTP_HOST'];
31+
}
3332

34-
$homeurl = $scheme . '://' . $baseurl;
35-
Config::define( 'WP_HOME', $homeurl );
36-
putenv( 'WP_HOME=' . $homeurl );
33+
$homeurl = $scheme . '://' . $baseurl;
34+
Config::define( 'WP_HOME', $homeurl );
35+
putenv( 'WP_HOME=' . $homeurl );
3736

38-
if ( ! env( 'WP_SITEURL' ) ) {
39-
Config::define( 'WP_SITEURL', $homeurl . '/wp' );
40-
putenv( 'WP_SITEURL=' . $homeurl . '/wp' );
41-
}
37+
if ( ! env( 'WP_SITEURL' ) ) {
38+
Config::define( 'WP_SITEURL', $homeurl . '/wp' );
39+
putenv( 'WP_SITEURL=' . $homeurl . '/wp' );
4240
}
4341
}
44-
45-
if ( ! defined( 'PANTHEON_HOSTNAME' ) ) {
46-
$site_name = $_ENV['PANTHEON_SITE_NAME'];
47-
$hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : $_ENV['PANTHEON_ENVIRONMENT'] . "-{$site_name}.pantheonsite.io";
48-
$hostname = isset( $_ENV['LANDO'] ) ? "{$site_name}.lndo.site" : $hostname;
49-
define( 'PANTHEON_HOSTNAME', $hostname );
50-
}
5142
}

config/application.php

+4-14
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// Check if a .env file exists.
3838
file_exists( $root_dir . '/.env' ) ||
3939
// Also check if we're using Lando and a .env.local file exists.
40-
( file_exists( $root_dir . '/.env.local' ) && 'lando' === $_ENV['PANTHEON_ENVIRONMENT'] )
40+
( file_exists( $root_dir . '/.env.local' ) && isset( $_ENV['LANDO'] ) && 'ON' === $_ENV['LANDO'] )
4141
) {
4242
$dotenv->load();
4343
if ( ! env( 'DATABASE_URL' ) ) {
@@ -46,19 +46,9 @@
4646
}
4747

4848
/**
49-
* Pantheon modifications
49+
* Include Pantheon application settings.
5050
*/
51-
if (isset($_ENV['PANTHEON_ENVIRONMENT']) && 'lando' !== $_ENV['PANTHEON_ENVIRONMENT']) {
52-
Config::define('DB_HOST', $_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT']);
53-
} else {
54-
/**
55-
* URLs
56-
*/
57-
Config::define('WP_HOME', env('WP_HOME'));
58-
Config::define('WP_SITEURL', env('WP_SITEURL'));
59-
Config::define('DB_HOST', env('DB_HOST') ?: 'localhost');
60-
Config::define('DISABLE_WP_CRON', env('DISABLE_WP_CRON') ?: false);
61-
}
51+
require_once __DIR__ . '/application.pantheon.php';
6252

6353
/**
6454
* Set up our global environment constant and load its config first
@@ -96,7 +86,7 @@
9686
/**
9787
* Pantheon modifications
9888
*/
99-
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && 'lando' !== $_ENV['PANTHEON_ENVIRONMENT'] ) {
89+
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && ! isset( $_ENV['LANDO'] ) ) {
10090
Config::define( 'DB_HOST', $_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT'] );
10191
} else {
10292
/**

phpcs.xml

+12
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,21 @@
3838
<exclude name="WordPress.WP.GlobalVariablesOverride.Prohibited">
3939
<exclude-pattern>config/application.php</exclude-pattern>
4040
</exclude>
41+
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase">
42+
<exclude-pattern>config/application.pantheon.php</exclude-pattern>
43+
</exclude>
44+
<exclude name="WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv">
45+
<exclude-pattern>config/application.pantheon.php</exclude-pattern>
46+
</exclude>
4147
</rule>
4248
<!-- End Pantheon addition -->
4349

50+
<!--
51+
Prevent errors caused by WordPress Coding Standards not supporting PHP 8.0+.
52+
See https://github.com/WordPress/WordPress-Coding-Standards/issues/2035
53+
-->
54+
<ini name="error_reporting" value="E_ALL &#38; ~E_DEPRECATED" />
55+
4456
<!-- Show colors in console -->
4557
<arg value="-colors"/>
4658

0 commit comments

Comments
 (0)