From d6ebc560f287b5f9f48792ba6c4054a6616e8d0a Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 25 Apr 2024 19:35:04 -0600 Subject: [PATCH 01/19] update recommended config for HTTP_HOST issue this matches what we're putting into the mu-plugin --- source/content/guides/multisite/03-config.md | 64 +++++++++++++++++--- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/source/content/guides/multisite/03-config.md b/source/content/guides/multisite/03-config.md index 217f51f6f0..29c7b6c3d8 100644 --- a/source/content/guides/multisite/03-config.md +++ b/source/content/guides/multisite/03-config.md @@ -68,20 +68,43 @@ Make sure [Terminus](/terminus) is installed and [authenticated](/terminus/insta 1. Open the `code` folder in your SFTP client, and download your site's `wp-config.php` file. -1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` from a hardcoded URL to a dynamic URL `$_SERVER['HTTP_HOST']`. This automatically detects the URL in each environment. You must replace this variable. For example: - +1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` to a hardcoded URL. You will want to default to a dynamic URL (`$_SERVER['HTTP_HOST']`), however some environments on Pantheon (notably workflows that run containerized versions of WP-CLI like search and replace) will not have a `$_SERVER` global. For this reason, we recommend using the following configuration that provides fallbacks if `$_SERVER['HTTP_HOST']` is unavailable. + ```php:title=wp-config.php - define( 'WP_ALLOW_MULTISITE', true ); + $hostname = 'www.yourdomain.com'; // The domain of the network. Use as a fallback if $_SERVER['HTTP_HOST'] is not available. + if ( !empty( $_ENV['PANTHEON_ENVIRONMENT'] )) { + $site_name = $_ENV['PANTHEON_SITE_NAME']; + // Override $hostname value as needed. + switch ( $_ENV['PANTHEON_ENVIRONMENT'] ) { + case 'live': + // Fall back to the default $hostname if $_SERVER['HTTP_HOST'] is not available. + $hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : $hostname; + break; + case 'test': + $hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'test-' . $site_name . '.pantheonsite.io'; + break; + case 'dev': + $hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'dev-' . $site_name . '.pantheonsite.io'; + break; + case 'lando': + $hostname = $site_name . '.lndo.site'; + break; + default: + $hostname = $_ENV['PANTHEON_ENVIRONMENT'] . '-' . $site_name . '.pantheonsite.io'; + break; + } + } define( 'MULTISITE', true ); - define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomains - $base = '/'; - define( 'DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST'] ); + define( 'SUBDOMAIN_INSTALL', ); + define( 'DOMAIN_CURRENT_SITE', $hostname ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 ); ``` + + This automatically detects the URL in each environment and uses that value if it's available. - Refer to the [wp-config-php documentation](/guides/php/wp-config-php#write-logic-based-on-the-pantheon-server-environment) if you have an environment specific configuration. + Refer to the [wp-config-php documentation](/guides/php/wp-config-php#write-logic-based-on-the-pantheon-server-environment) if you have an environment specific configuration. 1. Save your changes and upload the `wp-config.php` file to Pantheon's **Dev** environment. @@ -120,9 +143,32 @@ Complete the steps below after spinning up a new WPMS site from the correct Cust 1. Locate the `/* That's all, stop editing! Happy Pressing. */` line, and add the following code above this line to enable the WPMS configuration. ```php:title=wp-config.php + $hostname = 'www.yourdomain.com'; // The domain of the network. Use as a fallback if $_SERVER['HTTP_HOST'] is not available. + if ( !empty( $_ENV['PANTHEON_ENVIRONMENT'] )) { + $site_name = $_ENV['PANTHEON_SITE_NAME']; + // Override $hostname value as needed. + switch ( $_ENV['PANTHEON_ENVIRONMENT'] ) { + case 'live': + // Fall back to the default $hostname if $_SERVER['HTTP_HOST'] is not available. + $hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : $hostname; + break; + case 'test': + $hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'test-' . $site_name . '.pantheonsite.io'; + break; + case 'dev': + $hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'dev-' . $site_name . '.pantheonsite.io'; + break; + case 'lando': + $hostname = $site_name . '.lndo.site'; + break; + default: + $hostname = $_ENV['PANTHEON_ENVIRONMENT'] . '-' . $site_name . '.pantheonsite.io'; + break; + } + } define( 'MULTISITE', true ); - define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomains - define( 'DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST'] ); + define( 'SUBDOMAIN_INSTALL', ); + define( 'DOMAIN_CURRENT_SITE', $hostname ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 ); From 37909574a7b3194ce94f583dcedc52ff8c530715 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 25 Apr 2024 19:35:23 -0600 Subject: [PATCH 02/19] add undefined array key HTTP_HOST warning as a known issue --- source/content/wordpress-known-issues.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/content/wordpress-known-issues.md b/source/content/wordpress-known-issues.md index a237a41419..6f46b11823 100644 --- a/source/content/wordpress-known-issues.md +++ b/source/content/wordpress-known-issues.md @@ -51,6 +51,18 @@ Pantheon supports designated use cases for [WordPress Multisite](/guides/multisi It's especially ill-advised to use Multisite to set up many distinct/separate sites — e.g. running different plugins, for different customers — on a single code installation. +## `Undefined array key "HTTP_HOST"` PHP warnings + +If you are seeing an error like `PHP Warning: Undefined array key "HTTP_HOST"` pointing to a WP-CLI file, this is likely because there is some code in your configuration that is using `$_SERVER['HTTP_HOST']` without checking if it is set. This is a common issue with WP-CLI, as it does not have the same environment variables set as a web request. You can resolve this by checking if the key is set before using it: + +```php +if (isset($_SERVER['HTTP_HOST'])) { + // Your code here +} +``` + +The simplest solution is to search your codebase for `$_SERVER['HTTP_HOST']` and add a check for `isset()` before using it. It's generally a good idea to set a fallback value if the key is not set, to prevent unexpected behavior. There are some examples of this in our [WordPress Multisite documentation](/guides/multisite/config). + ## Plugins with Known Issues See [WordPress Plugins and Themes with Known Issues](/plugins-known-issues) for a list of WordPress plugins that are not supported and/or require workarounds. From 71c06370b616357a20212a4e8420b0510040d56a Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Thu, 25 Apr 2024 19:41:35 -0600 Subject: [PATCH 03/19] add release note for mu-plugin update --- .../2024-04-xx-pantheon-mu-plugin-1-4-1-update.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 source/releasenotes/2024-04-xx-pantheon-mu-plugin-1-4-1-update.md diff --git a/source/releasenotes/2024-04-xx-pantheon-mu-plugin-1-4-1-update.md b/source/releasenotes/2024-04-xx-pantheon-mu-plugin-1-4-1-update.md new file mode 100644 index 0000000000..cb1f1169a1 --- /dev/null +++ b/source/releasenotes/2024-04-xx-pantheon-mu-plugin-1-4-1-update.md @@ -0,0 +1,7 @@ +--- +title: Pantheon MU Plugin v1.4.1 update +published_date: "2024-04-2x" +categories: [wordpress, plugins] +--- + +The latest [1.4.1 release](https://github.com/pantheon-systems/pantheon-mu-plugin/releases) of the Pantheon MU Plugin updates the recommended configuration for WordPress multisite to handle PHP warnings that the array key `HTTP_HOST` is undefined. This change follows the best practice of checking if the key is set before using it. For more information, refer to our [WordPress Multisite configuration guide](/guides/multisite/config). \ No newline at end of file From 0c837a36a916026a48c36c153cd46dddac656561 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 26 Apr 2024 15:36:10 -0600 Subject: [PATCH 04/19] reset the SUBDOMAIN_INSTALL constant back to what it was before --- source/content/guides/multisite/03-config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/content/guides/multisite/03-config.md b/source/content/guides/multisite/03-config.md index 29c7b6c3d8..a18127b9bf 100644 --- a/source/content/guides/multisite/03-config.md +++ b/source/content/guides/multisite/03-config.md @@ -167,7 +167,7 @@ Complete the steps below after spinning up a new WPMS site from the correct Cust } } define( 'MULTISITE', true ); - define( 'SUBDOMAIN_INSTALL', ); + define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomains define( 'DOMAIN_CURRENT_SITE', $hostname ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); From ae42e7535c9ba6870559606c45091b4eaca5d779 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 26 Apr 2024 15:38:06 -0600 Subject: [PATCH 05/19] update the docs about $_SERVER being/not being available whether or not the full superglobal is available is somewhat irrelevant, we can just talk about the value we actually care about, which is HTTP_HOST --- source/content/guides/multisite/03-config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/content/guides/multisite/03-config.md b/source/content/guides/multisite/03-config.md index a18127b9bf..583c889303 100644 --- a/source/content/guides/multisite/03-config.md +++ b/source/content/guides/multisite/03-config.md @@ -68,7 +68,7 @@ Make sure [Terminus](/terminus) is installed and [authenticated](/terminus/insta 1. Open the `code` folder in your SFTP client, and download your site's `wp-config.php` file. -1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` to a hardcoded URL. You will want to default to a dynamic URL (`$_SERVER['HTTP_HOST']`), however some environments on Pantheon (notably workflows that run containerized versions of WP-CLI like search and replace) will not have a `$_SERVER` global. For this reason, we recommend using the following configuration that provides fallbacks if `$_SERVER['HTTP_HOST']` is unavailable. +1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` to a hardcoded URL. You will want to default to a dynamic URL (`$_SERVER['HTTP_HOST']`), however some environments on Pantheon (notably workflows that run containerized versions of WP-CLI like search and replace) will not have a `$_SERVER['HTTP_HOST]` value. For this reason, we recommend using the following configuration that provides fallbacks if `$_SERVER['HTTP_HOST']` is unavailable. ```php:title=wp-config.php $hostname = 'www.yourdomain.com'; // The domain of the network. Use as a fallback if $_SERVER['HTTP_HOST'] is not available. From a2c106d576b4a40ab63476e52da5dd78a4fd3f45 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Fri, 26 Apr 2024 15:40:09 -0600 Subject: [PATCH 06/19] clarify language about web/non-web requests --- source/content/guides/multisite/03-config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/content/guides/multisite/03-config.md b/source/content/guides/multisite/03-config.md index 583c889303..e771602d7b 100644 --- a/source/content/guides/multisite/03-config.md +++ b/source/content/guides/multisite/03-config.md @@ -68,7 +68,7 @@ Make sure [Terminus](/terminus) is installed and [authenticated](/terminus/insta 1. Open the `code` folder in your SFTP client, and download your site's `wp-config.php` file. -1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` to a hardcoded URL. You will want to default to a dynamic URL (`$_SERVER['HTTP_HOST']`), however some environments on Pantheon (notably workflows that run containerized versions of WP-CLI like search and replace) will not have a `$_SERVER['HTTP_HOST]` value. For this reason, we recommend using the following configuration that provides fallbacks if `$_SERVER['HTTP_HOST']` is unavailable. +1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` to a hardcoded URL. You will want to default to a dynamic URL (`$_SERVER['HTTP_HOST']`) for web requests, while providing a fallback for non-web requests (notably workflows like search and replace) that do not have a `$_SERVER['HTTP_HOST]` value. For this reason, we recommend using the following configuration that falls back to a hard-coded value if `$_SERVER['HTTP_HOST']` is unavailable. ```php:title=wp-config.php $hostname = 'www.yourdomain.com'; // The domain of the network. Use as a fallback if $_SERVER['HTTP_HOST'] is not available. From d017b354402f30684d0346c0ba0c9b2b96cd9119 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 29 Apr 2024 14:41:49 -0600 Subject: [PATCH 07/19] update docs to remove complicated switch --- source/content/guides/multisite/03-config.md | 29 ++------------------ 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/source/content/guides/multisite/03-config.md b/source/content/guides/multisite/03-config.md index e771602d7b..3f1f43ff60 100644 --- a/source/content/guides/multisite/03-config.md +++ b/source/content/guides/multisite/03-config.md @@ -68,35 +68,12 @@ Make sure [Terminus](/terminus) is installed and [authenticated](/terminus/insta 1. Open the `code` folder in your SFTP client, and download your site's `wp-config.php` file. -1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` to a hardcoded URL. You will want to default to a dynamic URL (`$_SERVER['HTTP_HOST']`) for web requests, while providing a fallback for non-web requests (notably workflows like search and replace) that do not have a `$_SERVER['HTTP_HOST]` value. For this reason, we recommend using the following configuration that falls back to a hard-coded value if `$_SERVER['HTTP_HOST']` is unavailable. +1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` to a hardcoded URL. We have provided a constant in `wp-config-pantheon.php`, `PANTHEON_HOSTNAME` that defaults to a dynamic URL (`$_SERVER['HTTP_HOST']`, when available) for web requests, while providing a fallback for non-web requests (notably workflows like search and replace) that do not have a `$_SERVER['HTTP_HOST']` value. ```php:title=wp-config.php - $hostname = 'www.yourdomain.com'; // The domain of the network. Use as a fallback if $_SERVER['HTTP_HOST'] is not available. - if ( !empty( $_ENV['PANTHEON_ENVIRONMENT'] )) { - $site_name = $_ENV['PANTHEON_SITE_NAME']; - // Override $hostname value as needed. - switch ( $_ENV['PANTHEON_ENVIRONMENT'] ) { - case 'live': - // Fall back to the default $hostname if $_SERVER['HTTP_HOST'] is not available. - $hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : $hostname; - break; - case 'test': - $hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'test-' . $site_name . '.pantheonsite.io'; - break; - case 'dev': - $hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'dev-' . $site_name . '.pantheonsite.io'; - break; - case 'lando': - $hostname = $site_name . '.lndo.site'; - break; - default: - $hostname = $_ENV['PANTHEON_ENVIRONMENT'] . '-' . $site_name . '.pantheonsite.io'; - break; - } - } define( 'MULTISITE', true ); - define( 'SUBDOMAIN_INSTALL', ); - define( 'DOMAIN_CURRENT_SITE', $hostname ); + define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomain installs. + define( 'DOMAIN_CURRENT_SITE', PANTHEON_HOSTNAME ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 ); From 2b1ff2c565f25124254d66e82db8547c4e51fbe4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 29 Apr 2024 14:50:12 -0600 Subject: [PATCH 08/19] also update the complicated switch logic for the gui instructions --- source/content/guides/multisite/03-config.md | 25 +------------------- 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/source/content/guides/multisite/03-config.md b/source/content/guides/multisite/03-config.md index 3f1f43ff60..e30572931d 100644 --- a/source/content/guides/multisite/03-config.md +++ b/source/content/guides/multisite/03-config.md @@ -120,32 +120,9 @@ Complete the steps below after spinning up a new WPMS site from the correct Cust 1. Locate the `/* That's all, stop editing! Happy Pressing. */` line, and add the following code above this line to enable the WPMS configuration. ```php:title=wp-config.php - $hostname = 'www.yourdomain.com'; // The domain of the network. Use as a fallback if $_SERVER['HTTP_HOST'] is not available. - if ( !empty( $_ENV['PANTHEON_ENVIRONMENT'] )) { - $site_name = $_ENV['PANTHEON_SITE_NAME']; - // Override $hostname value as needed. - switch ( $_ENV['PANTHEON_ENVIRONMENT'] ) { - case 'live': - // Fall back to the default $hostname if $_SERVER['HTTP_HOST'] is not available. - $hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : $hostname; - break; - case 'test': - $hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'test-' . $site_name . '.pantheonsite.io'; - break; - case 'dev': - $hostname = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'dev-' . $site_name . '.pantheonsite.io'; - break; - case 'lando': - $hostname = $site_name . '.lndo.site'; - break; - default: - $hostname = $_ENV['PANTHEON_ENVIRONMENT'] . '-' . $site_name . '.pantheonsite.io'; - break; - } - } define( 'MULTISITE', true ); define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomains - define( 'DOMAIN_CURRENT_SITE', $hostname ); + define( 'DOMAIN_CURRENT_SITE', PANTHEON_HOSTNAME ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 ); From 3a867f0144025b5ca56789826be50dac1629ae8c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 29 Apr 2024 14:50:29 -0600 Subject: [PATCH 09/19] add HTTP_HOST warning info to troublehsooting at the bottom --- source/content/guides/multisite/03-config.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/content/guides/multisite/03-config.md b/source/content/guides/multisite/03-config.md index e30572931d..ce31b2473e 100644 --- a/source/content/guides/multisite/03-config.md +++ b/source/content/guides/multisite/03-config.md @@ -164,6 +164,16 @@ After these steps are complete, both sites on the WordPress Multisite should loa Explore the WordPress Network Dashboard to become familiar with the variety of additional settings. You can review the options that are available for each site you create, manage users across WordPress Multisite, and learn about the network settings. After you explore the WordPress Network Dashboard, learn how to use the WordPress Multisite with the Pantheon Workflow. +## Troubleshooting + +### "Undefined index: HTTP_HOST" PHP Warnings + +If you see notices in your PHP logs similar to `PHP Warning: Undefined index: HTTP_HOST`, this is likely because there is some code in your configuration that is using `$_SERVER['HTTP_HOST']` without checking if it is set. This is a common issue with WP-CLI, as it does not have the same environment variables set as a web request. Instead of relying on `$_SERVER['HTTP_HOST']`, you can use the `PANTHEON_HOSTNAME` constant, which is set by Pantheon in `wp-config-pantheon.php` and is available in all environments. + +```php +define( 'DOMAIN_CURRENT_SITE', PANTHEON_HOSTNAME ); +``` + ## More Resources - [Environment-Specific Configuration for WordPress Sites](/guides/environment-configuration/environment-specific-config) From dc759c4988e94b452ed6bb54cc5f8d1ae8b8e72d Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 29 Apr 2024 14:50:42 -0600 Subject: [PATCH 10/19] detail how to override PANTHEON_HOSTNAME --- source/content/guides/php/04-wp-config-php.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/content/guides/php/04-wp-config-php.md b/source/content/guides/php/04-wp-config-php.md index f295af7d3e..9ec53daaab 100644 --- a/source/content/guides/php/04-wp-config-php.md +++ b/source/content/guides/php/04-wp-config-php.md @@ -107,6 +107,16 @@ The following example shows how to hard-code your WordPress debug configuration +### How can I override the default `PANTHEON_HOSTNAME` value? + +In your `wp-config.php`, above the line that requires `wp-config-pantheon.php`, you can set the `PANTHEON_HOSTNAME` constant to the desired value: + +```php:title=wp-config.php +define( 'PANTHEON_HOSTNAME', 'example.com' ); +``` + +Note that in most cases you shouldn't need to do this. The logic in the [`wp-config-pantheon.php`](https://github.com/pantheon-systems/WordPress/blob/default/wp-config-pantheon.php#L98) covers most instances where you might need a unique hostname. It's recommended that you only change this in very specific cases and your code has conditions to handle those. + ### How can I read the Pantheon environment configuration, like database credentials? Refer to [Reading the Pantheon Environment Configuration](/guides/environment-configuration/read-environment-config). From 2d388965645fc8bb5154919a8c57386ec87a0483 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 29 Apr 2024 15:05:32 -0600 Subject: [PATCH 11/19] re-add WP_ALLOW_MULTISITE to code blocks was pulled in the purge --- source/content/guides/multisite/03-config.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/content/guides/multisite/03-config.md b/source/content/guides/multisite/03-config.md index ce31b2473e..f9c0847216 100644 --- a/source/content/guides/multisite/03-config.md +++ b/source/content/guides/multisite/03-config.md @@ -71,6 +71,7 @@ Make sure [Terminus](/terminus) is installed and [authenticated](/terminus/insta 1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` to a hardcoded URL. We have provided a constant in `wp-config-pantheon.php`, `PANTHEON_HOSTNAME` that defaults to a dynamic URL (`$_SERVER['HTTP_HOST']`, when available) for web requests, while providing a fallback for non-web requests (notably workflows like search and replace) that do not have a `$_SERVER['HTTP_HOST']` value. ```php:title=wp-config.php + define( 'WP_ALLOW_MULTISITE', true ); define( 'MULTISITE', true ); define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomain installs. define( 'DOMAIN_CURRENT_SITE', PANTHEON_HOSTNAME ); @@ -120,6 +121,7 @@ Complete the steps below after spinning up a new WPMS site from the correct Cust 1. Locate the `/* That's all, stop editing! Happy Pressing. */` line, and add the following code above this line to enable the WPMS configuration. ```php:title=wp-config.php + define( 'WP_ALLOW_MULTISITE', true ); define( 'MULTISITE', true ); define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomains define( 'DOMAIN_CURRENT_SITE', PANTHEON_HOSTNAME ); From 4d0521f08beff6f787403d600e9e69a3ebf93931 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 29 Apr 2024 15:09:05 -0600 Subject: [PATCH 12/19] clarify the language a bit --- source/content/guides/multisite/03-config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/content/guides/multisite/03-config.md b/source/content/guides/multisite/03-config.md index f9c0847216..09da6e32d6 100644 --- a/source/content/guides/multisite/03-config.md +++ b/source/content/guides/multisite/03-config.md @@ -68,7 +68,7 @@ Make sure [Terminus](/terminus) is installed and [authenticated](/terminus/insta 1. Open the `code` folder in your SFTP client, and download your site's `wp-config.php` file. -1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` to a hardcoded URL. We have provided a constant in `wp-config-pantheon.php`, `PANTHEON_HOSTNAME` that defaults to a dynamic URL (`$_SERVER['HTTP_HOST']`, when available) for web requests, while providing a fallback for non-web requests (notably workflows like search and replace) that do not have a `$_SERVER['HTTP_HOST']` value. +1. Locate the configuration added by WP-CLI, and *modify* the line that sets `DOMAIN_CURRENT_SITE` to a hardcoded URL. We have provided a constant in `wp-config-pantheon.php`, `PANTHEON_HOSTNAME` that defaults to a dynamic URL for web requests (`$_SERVER['HTTP_HOST']`, when available), while providing a fallback for non-web requests (notably workflows like search and replace) that do not have a `$_SERVER['HTTP_HOST']` value. ```php:title=wp-config.php define( 'WP_ALLOW_MULTISITE', true ); From 7355cd779c0e45df75b7e80446d5ca52a0dd71df Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 29 Apr 2024 15:09:26 -0600 Subject: [PATCH 13/19] remove unnecessary extra line and make `wp-config.php` a code block --- source/content/guides/multisite/03-config.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/content/guides/multisite/03-config.md b/source/content/guides/multisite/03-config.md index 09da6e32d6..a5e03f87e0 100644 --- a/source/content/guides/multisite/03-config.md +++ b/source/content/guides/multisite/03-config.md @@ -80,9 +80,7 @@ Make sure [Terminus](/terminus) is installed and [authenticated](/terminus/insta define( 'BLOG_ID_CURRENT_SITE', 1 ); ``` - This automatically detects the URL in each environment and uses that value if it's available. - - Refer to the [wp-config-php documentation](/guides/php/wp-config-php#write-logic-based-on-the-pantheon-server-environment) if you have an environment specific configuration. + Refer to the [`wp-config.php` documentation](/guides/php/wp-config-php#write-logic-based-on-the-pantheon-server-environment) if you have an environment specific configuration. 1. Save your changes and upload the `wp-config.php` file to Pantheon's **Dev** environment. From 3ef8c9da48d6b6d3174836d873df392340ad379c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 29 Apr 2024 15:09:41 -0600 Subject: [PATCH 14/19] update troubleshooting info for HTTP_HOST warnings --- source/content/wordpress-known-issues.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/content/wordpress-known-issues.md b/source/content/wordpress-known-issues.md index 6f46b11823..0a590dd09b 100644 --- a/source/content/wordpress-known-issues.md +++ b/source/content/wordpress-known-issues.md @@ -61,7 +61,9 @@ if (isset($_SERVER['HTTP_HOST'])) { } ``` -The simplest solution is to search your codebase for `$_SERVER['HTTP_HOST']` and add a check for `isset()` before using it. It's generally a good idea to set a fallback value if the key is not set, to prevent unexpected behavior. There are some examples of this in our [WordPress Multisite documentation](/guides/multisite/config). +The simplest solution is to search your codebase for `$_SERVER['HTTP_HOST']` and add a check for `isset()` before using it. It's generally a good idea to set a fallback value if the key is not set, to prevent unexpected behavior. + +If you are seeing this in a WordPress multisite environment, it might be because your `DOMAIN_CURRENT_SITE` value is set to `$_SERVER['HTTP_HOST']` in your `wp-config.php`. You can set this to the `PANTHEON_HOSTNAME` constant provided by Pantheon instead. See the [WordPress Multisite documentation](/guides/multisite/config) for more information. ## Plugins with Known Issues See [WordPress Plugins and Themes with Known Issues](/plugins-known-issues) for a list of WordPress plugins that are not supported and/or require workarounds. From a3ccaeea9124039e3dc53c30dd0e952e5a099290 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 29 Apr 2024 15:10:00 -0600 Subject: [PATCH 15/19] whitespace --- source/content/guides/multisite/03-config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/content/guides/multisite/03-config.md b/source/content/guides/multisite/03-config.md index a5e03f87e0..ffa50a1382 100644 --- a/source/content/guides/multisite/03-config.md +++ b/source/content/guides/multisite/03-config.md @@ -79,7 +79,7 @@ Make sure [Terminus](/terminus) is installed and [authenticated](/terminus/insta define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 ); ``` - + Refer to the [`wp-config.php` documentation](/guides/php/wp-config-php#write-logic-based-on-the-pantheon-server-environment) if you have an environment specific configuration. 1. Save your changes and upload the `wp-config.php` file to Pantheon's **Dev** environment. From eacdd82f6780ab538560dd88a62862630db9c7bf Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 29 Apr 2024 15:14:29 -0600 Subject: [PATCH 16/19] update release note --- .../2024-04-xx-pantheon-mu-plugin-1-4-1-update.md | 7 ------- ...24-04-xx-wordpress-pantheon-mu-plugin-1-4-1-update.md | 9 +++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) delete mode 100644 source/releasenotes/2024-04-xx-pantheon-mu-plugin-1-4-1-update.md create mode 100644 source/releasenotes/2024-04-xx-wordpress-pantheon-mu-plugin-1-4-1-update.md diff --git a/source/releasenotes/2024-04-xx-pantheon-mu-plugin-1-4-1-update.md b/source/releasenotes/2024-04-xx-pantheon-mu-plugin-1-4-1-update.md deleted file mode 100644 index cb1f1169a1..0000000000 --- a/source/releasenotes/2024-04-xx-pantheon-mu-plugin-1-4-1-update.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: Pantheon MU Plugin v1.4.1 update -published_date: "2024-04-2x" -categories: [wordpress, plugins] ---- - -The latest [1.4.1 release](https://github.com/pantheon-systems/pantheon-mu-plugin/releases) of the Pantheon MU Plugin updates the recommended configuration for WordPress multisite to handle PHP warnings that the array key `HTTP_HOST` is undefined. This change follows the best practice of checking if the key is set before using it. For more information, refer to our [WordPress Multisite configuration guide](/guides/multisite/config). \ No newline at end of file diff --git a/source/releasenotes/2024-04-xx-wordpress-pantheon-mu-plugin-1-4-1-update.md b/source/releasenotes/2024-04-xx-wordpress-pantheon-mu-plugin-1-4-1-update.md new file mode 100644 index 0000000000..51c9895d46 --- /dev/null +++ b/source/releasenotes/2024-04-xx-wordpress-pantheon-mu-plugin-1-4-1-update.md @@ -0,0 +1,9 @@ +--- +title: WordPress and Pantheon MU Plugin v1.4.1 update +published_date: "2024-04-2x" +categories: [wordpress, plugins, action-required] +--- + +We have updated the WordPress core upstreams (WordPress and WordPress (Composer Managed)) to provide a new `PANTHEON_HOSTNAME` constant. This value can be helpful when defining `DOMAIN_CURRENT_SITE` on WordPress multisite installations. By default, the `PANTHEON_HOSTNAME` constant is set to the value of the `HTTP_HOST` server variable, which is the hostname of the request. However, when this value is unavailable, the `PANTHEON_HOSTNAME` provides fallback values, thereby avoiding "Undefined index: HTTP_HOST" warnings. For more information, refer to our [WordPress Multisite configuration guide](/guides/multisite/config). + +The latest [1.4.1 release](https://github.com/pantheon-systems/pantheon-mu-plugin/releases) of the Pantheon MU Plugin updates the recommended configuration for WordPress multisite to use the new `PANTHEON_HOSTNAME` constant when defining `DOMAIN_CURRENT_SITE` rather than the previous recommendation -- either `$_SERVER['HTTP_HOST']` or a complicated PHP switch. \ No newline at end of file From f2148504cd42122eee99c196a63ec840dd7f3dad Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 29 Apr 2024 15:17:24 -0600 Subject: [PATCH 17/19] add contrib --- source/content/guides/php/04-wp-config-php.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/content/guides/php/04-wp-config-php.md b/source/content/guides/php/04-wp-config-php.md index 9ec53daaab..3384fde1ae 100644 --- a/source/content/guides/php/04-wp-config-php.md +++ b/source/content/guides/php/04-wp-config-php.md @@ -10,7 +10,7 @@ audience: [development] product: [--] integration: [--] tags: [wp-config] -contributors: [masonjames] +contributors: [masonjames, jazzsequence] showtoc: true permalink: docs/guides/php/wp-config-php --- From e68b75d90ed61a9c5ec9a60f704107e25f17c584 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 30 Apr 2024 09:42:43 -0600 Subject: [PATCH 18/19] update the date --- ... => 2024-04-30-wordpress-pantheon-mu-plugin-1-4-1-update.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename source/releasenotes/{2024-04-xx-wordpress-pantheon-mu-plugin-1-4-1-update.md => 2024-04-30-wordpress-pantheon-mu-plugin-1-4-1-update.md} (97%) diff --git a/source/releasenotes/2024-04-xx-wordpress-pantheon-mu-plugin-1-4-1-update.md b/source/releasenotes/2024-04-30-wordpress-pantheon-mu-plugin-1-4-1-update.md similarity index 97% rename from source/releasenotes/2024-04-xx-wordpress-pantheon-mu-plugin-1-4-1-update.md rename to source/releasenotes/2024-04-30-wordpress-pantheon-mu-plugin-1-4-1-update.md index 51c9895d46..c56038200a 100644 --- a/source/releasenotes/2024-04-xx-wordpress-pantheon-mu-plugin-1-4-1-update.md +++ b/source/releasenotes/2024-04-30-wordpress-pantheon-mu-plugin-1-4-1-update.md @@ -1,6 +1,6 @@ --- title: WordPress and Pantheon MU Plugin v1.4.1 update -published_date: "2024-04-2x" +published_date: "2024-04-30" categories: [wordpress, plugins, action-required] --- From 11ebf42ea405c0ca4af3f445b6dbaae3e2afb173 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 30 Apr 2024 11:49:31 -0600 Subject: [PATCH 19/19] update code snippet to include fallback to `HTTP_HOST` if `$_ENV['PANTHEON_ENVIRONMENT']` is unset (e.g. in non-Lando local development environments), using PANTHEON_HOSTNAME will fatal as undefined, so we still need a fallback here. --- source/content/guides/multisite/03-config.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/content/guides/multisite/03-config.md b/source/content/guides/multisite/03-config.md index ffa50a1382..5508fe80cc 100644 --- a/source/content/guides/multisite/03-config.md +++ b/source/content/guides/multisite/03-config.md @@ -74,7 +74,8 @@ Make sure [Terminus](/terminus) is installed and [authenticated](/terminus/insta define( 'WP_ALLOW_MULTISITE', true ); define( 'MULTISITE', true ); define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomain installs. - define( 'DOMAIN_CURRENT_SITE', PANTHEON_HOSTNAME ); + // 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( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 ); @@ -122,7 +123,8 @@ Complete the steps below after spinning up a new WPMS site from the correct Cust define( 'WP_ALLOW_MULTISITE', true ); define( 'MULTISITE', true ); define( 'SUBDOMAIN_INSTALL', false ); // Set this to TRUE for Subdomains - define( 'DOMAIN_CURRENT_SITE', PANTHEON_HOSTNAME ); + // 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( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 );