diff --git a/disqus/admin/class-disqus-admin.php b/disqus/admin/class-disqus-admin.php index 4910902..f6cdb7a 100755 --- a/disqus/admin/class-disqus-admin.php +++ b/disqus/admin/class-disqus-admin.php @@ -164,7 +164,7 @@ public function dsq_filter_rest_url( $rest_url ) { $rest_host .= ':' . $rest_url_parts['port']; } - $current_host = $_SERVER['HTTP_HOST']; + $current_host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : $rest_host; if ( $rest_host !== $current_host ) { $rest_url = preg_replace( '/' . $rest_host . '/', $current_host, $rest_url, 1 ); diff --git a/tests/test-admin.php b/tests/test-admin.php index 51889e7..ed65a46 100644 --- a/tests/test-admin.php +++ b/tests/test-admin.php @@ -42,4 +42,18 @@ function test_dsq_filter_rest_url_different_host() { $_SERVER['HTTP_HOST'] = $previous_host; } + /** + * Ensure that REST URL filter will not error when HTTP_HOST is undefined. + */ + function test_dsq_filter_rest_url_no_host() { + $admin = new Disqus_Admin( 'disqus', '0.0.0', 'foo' ); + $previous_host = $_SERVER['HTTP_HOST']; + $_SERVER['HTTP_HOST'] = NULL; + $init_url = 'https://example.org/wp-json/disqus/v1'; + + $rest_url = $admin->dsq_filter_rest_url($init_url); + + $this->assertEquals( $init_url, $rest_url ); + } + }