From ca326592a5a1c5f171361d04e58340293e428be6 Mon Sep 17 00:00:00 2001 From: meloniq Date: Fri, 7 Oct 2016 23:02:51 +0200 Subject: [PATCH] use WP native functions wp_remote_(get|post) instead of custom dsq_urlopen() --- disqus/lib/api/disqus/disqus.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/disqus/lib/api/disqus/disqus.php b/disqus/lib/api/disqus/disqus.php index bbf44f8..0f25217 100644 --- a/disqus/lib/api/disqus/disqus.php +++ b/disqus/lib/api/disqus/disqus.php @@ -115,11 +115,23 @@ function call($method, $args=array(), $post=false) { $args = null; } - if (!($response = dsq_urlopen($url, $args)) || !$response['code']) { - $this->last_error = 'Unable to connect to the Disqus API servers'; + if ( null === $args ) { + $response_raw = wp_remote_get( $url ); + } else { + $response_raw = wp_remote_post( $url, array( 'body' => $args ) ); + } + + if ( is_wp_error( $response_raw ) ) { + $this->last_error = $response_raw->get_error_message(); return false; } + $response = array( + 'code' => wp_remote_retrieve_response_code( $response_raw ), + 'data' => wp_remote_retrieve_body( $response_raw ), + 'headers' => wp_remote_retrieve_headers( $response_raw ), + ); + if ($response['code'] != 200) { if ($response['code'] == 500) { // Try to grab the exception ID for better reporting