From 4f8bac34b45e0d2426ea9d94f58577bbaec667ab Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 24 Feb 2016 11:49:27 -0600 Subject: [PATCH] Make filters more surgical Previously, the filters globally impacted all `wp_remote_get` requests. --- updater.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/updater.php b/updater.php index 7966354..02aa5f9 100644 --- a/updater.php +++ b/updater.php @@ -92,11 +92,6 @@ public function __construct( $config = array() ) { add_filter( 'plugins_api', array( $this, 'get_plugin_info' ), 10, 3 ); add_filter( 'upgrader_post_install', array( $this, 'upgrader_post_install' ), 10, 3 ); - // set timeout - add_filter( 'http_request_timeout', array( $this, 'http_request_timeout' ) ); - - // set sslverify for zip download - add_filter( 'http_request_args', array( $this, 'http_request_sslverify' ), 10, 2 ); } public function has_minimum_config() { @@ -266,13 +261,21 @@ public function get_new_version() { * @return mixed */ public function remote_get( $query ) { + // set timeout + add_filter( 'http_request_timeout', array( $this, 'http_request_timeout' ) ); + + // set sslverify for zip download + add_filter( 'http_request_args', array( $this, 'http_request_sslverify' ), 10, 2 ); + if ( ! empty( $this->config['access_token'] ) ) $query = add_query_arg( array( 'access_token' => $this->config['access_token'] ), $query ); $raw_response = wp_remote_get( $query, array( 'sslverify' => $this->config['sslverify'] ) ); - + // Remove filters so we don't globally impact http requets. + remove_filter( 'http_request_timeout', array( $this, 'http_request_timeout' ) ); + remove_filter( 'http_request_args', array( $this, 'http_request_sslverify' ) ); return $raw_response; } @@ -437,4 +440,4 @@ public function upgrader_post_install( $true, $hook_extra, $result ) { return $result; } -} \ No newline at end of file +}