Skip to content

Commit

Permalink
Merge pull request #106 from disqus/check-host
Browse files Browse the repository at this point in the history
Check that host key exists before using in dsq_filter_rest_url
  • Loading branch information
hlgott1593 authored May 26, 2021
2 parents 7aacf83 + dc4ea77 commit 6d43e80
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions disqus/admin/class-disqus-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,17 @@ public function enqueue_scripts() {
*/
public function dsq_filter_rest_url( $rest_url ) {
$rest_url_parts = parse_url( $rest_url );
$rest_host = $rest_url_parts['host'];
if ( array_key_exists( 'port', $rest_url_parts ) ) {
$rest_host .= ':' . $rest_url_parts['port'];
}
if ( array_key_exists( 'host', $rest_url_parts ) ) {
$rest_host = $rest_url_parts['host'];
if ( array_key_exists( 'port', $rest_url_parts ) ) {
$rest_host .= ':' . $rest_url_parts['port'];
}

$current_host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : $rest_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 );
if ( $rest_host !== $current_host ) {
$rest_url = preg_replace( '/' . $rest_host . '/', $current_host, $rest_url, 1 );
}
}

return $rest_url;
Expand Down

0 comments on commit 6d43e80

Please sign in to comment.