Skip to content

Commit 145c454

Browse files
committed
Fix support for forwarded URLs
- Remove support for ForwardHQ - Fix support for ngrok.io
1 parent 40df905 commit 145c454

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This is a simple and opinionated plugin for helping develop/debug WooCommerce &
55

66
### Use Forwarded URLs
77

8-
Once activated, this plugin will make WordPress use `HTTP_X_FORWARDED_HOST` or `HTTP_X_ORIGINAL_HOST` for all your links instead of your site URL. No configuration needed.
8+
Once activated, this plugin will make WordPress use `HTTP_X_FORWARDED_FOR` for all your links instead of your site URL. No configuration needed.
99

1010
We like to use [NGrok](http://ngrok.com/) for this.
1111

@@ -44,8 +44,10 @@ Download and install just like any other WordPress plugin. If you want to be rea
4444

4545
## Changelog
4646

47-
### 1.0.1 - 2020.nn.nn
48-
* Tweak - Add a field at checkout when selecting the bogus payment gateway to specify the desired payment result
47+
### 1.0.1 - 2021.nn.nn
48+
* Tweak - Add a field at checkout when selecting the bogus payment gateway to specify the desired payment result
49+
* Fix - Fix support for ngrok.io
50+
* Misc - Remove support for ForwardHQ
4951

5052
### 1.0.0 - 2018-11-06
5153
* Refactor - Use namespaces and rename classes
@@ -63,7 +65,7 @@ Download and install just like any other WordPress plugin. If you want to be rea
6365
### 0.7.0 - 2017.04.12
6466
* Feature - Use the Bogus gateway for Subscriptions automatic renewals
6567
* Fix - Subscriptions integration throwing a warning in WooCommerce 3.0+
66-
68+
6769
### 0.6.0 - 2017.02.18
6870
* Feature - Adds a bogus gateway that calls `$order->payment_complete()` when used
6971

includes/Forwarded_URLs.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public function __construct() {
5151
}
5252

5353
// save for URL replacement
54-
$this->non_forwarded_host = parse_url( get_option( 'siteurl' ), PHP_URL_HOST );
54+
$host = parse_url( get_option( 'siteurl' ), PHP_URL_HOST );
55+
$port = parse_url( get_option( 'siteurl' ), PHP_URL_PORT );
56+
$this->non_forwarded_host = $host . ($port ? ':' . $port : null);
5557

5658
// from https://github.com/50east/wp-forwarded-host-urls/
5759
$filters = array(
@@ -122,7 +124,7 @@ public function __construct() {
122124
*/
123125
private function has_forwarded_host() {
124126

125-
return array_key_exists( 'HTTP_X_FORWARDED_HOST', $_SERVER ) || array_key_exists( 'HTTP_X_ORIGINAL_HOST', $_SERVER );
127+
return array_key_exists( 'HTTP_X_FORWARDED_FOR', $_SERVER );
126128
}
127129

128130

@@ -134,13 +136,7 @@ private function has_forwarded_host() {
134136
*/
135137
public function get_forwarded_host() {
136138

137-
// are we using Forward HQ?
138-
$host = isset( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
139-
140-
// if not, check if we're using ngrok
141-
$host = isset( $_SERVER['HTTP_X_ORIGINAL_HOST'] ) ? $_SERVER['HTTP_X_ORIGINAL_HOST'] : $host;
142-
143-
return $host;
139+
return $_SERVER['HTTP_HOST'];
144140
}
145141

146142

0 commit comments

Comments
 (0)