Skip to content

Commit d0fa55f

Browse files
committed
Add support for ngrok
1 parent 66420eb commit d0fa55f

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ 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` for all your links instead of your site URL. No configuration needed.
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.
99

10-
We like [ForwardHQ](https://fwd.wf) for this, along with a `ForwardFile` in your WordPress root.
10+
We like to use [NGrok](http://ngrok.com/) for this.
1111

1212
### Subscriptions (v1.5.x and v2.x.x)
1313

@@ -46,6 +46,7 @@ Download and install just like any other WordPress plugin. If you want to be rea
4646

4747
### 1.0.0 - 2018-11-06
4848
* Refactor - Use namespaces and rename classes
49+
* Tweak - Add support for ngrok
4950

5051
### 0.8.1 - 2017.12.13
5152
* Fix - Remove WC 3.3+ "Connect to WooCommerce" notice when official plugins are active

includes/Forwarded_URLs.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
*
1313
* @package WC-Dev-Helper/Classes
1414
* @author SkyVerge
15-
* @copyright Copyright (c) 2015-2017, SkyVerge, Inc.
15+
* @copyright Copyright (c) 2015-2018, SkyVerge, Inc.
1616
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
1717
*/
1818

19+
namespace SkyVerge\WooCommerce\DevHelper;
20+
1921
defined( 'ABSPATH' ) or exit;
2022

2123
/**
@@ -26,7 +28,7 @@
2628
*
2729
* @since 0.1.0
2830
*/
29-
class WC_Dev_Helper_Use_Forwarded_URLs {
31+
class Forwarded_URLs {
3032

3133

3234
/** @var string non-forwarded host as defined in the siteurl option */
@@ -116,7 +118,7 @@ public function __construct() {
116118
*/
117119
private function has_forwarded_host() {
118120

119-
return array_key_exists( 'HTTP_X_FORWARDED_HOST', $_SERVER );
121+
return array_key_exists( 'HTTP_X_FORWARDED_HOST', $_SERVER ) || array_key_exists( 'HTTP_X_ORIGINAL_HOST', $_SERVER );
120122
}
121123

122124

@@ -128,7 +130,13 @@ private function has_forwarded_host() {
128130
*/
129131
public function get_forwarded_host() {
130132

131-
return $_SERVER['HTTP_X_FORWARDED_HOST'];
133+
// are we using Forward HQ?
134+
$host = $_SERVER['HTTP_X_FORWARDED_HOST'] ?? false;
135+
136+
// if not, check if we're using ngrok
137+
$host = ! $host && isset( $_SERVER['HTTP_X_ORIGINAL_HOST'] ) ? $_SERVER['HTTP_X_ORIGINAL_HOST'] : $_SERVER['HTTP_HOST'];
138+
139+
return $host;
132140
}
133141

134142

0 commit comments

Comments
 (0)