From a3ff7ada08c33affb6d249bfbb3c8f2aac92d794 Mon Sep 17 00:00:00 2001 From: Yahnis Elsts Date: Tue, 1 Oct 2019 14:35:16 +0300 Subject: [PATCH] Fixed a potential bug with multiple plugins using GitHub release assets. To allow WP to download a release asset from GitHub, the update checker needs to add an "Accept: application/octet-stream" header to the HTTP request. We use the "http_request_args" filter for that. Previously, we used a static variable to ensure that the filter callback is added only once. However, in PHP, static variables defined in a method are shared by all instances of the class that the method belongs to. This means that if one plugin enables release assets, adds a "http_request_args" filter, and sets ``$filterAdded` to `true`, then the next plugin that enables release assets won't add its own filter because the variable will already be `true`. Fixed by using an instance variable (`$downloadFilterAdded`) instead of a static variable. --- Puc/v4p8/Vcs/GitHubApi.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Puc/v4p8/Vcs/GitHubApi.php b/Puc/v4p8/Vcs/GitHubApi.php index b0c2fd4..364ca31 100644 --- a/Puc/v4p8/Vcs/GitHubApi.php +++ b/Puc/v4p8/Vcs/GitHubApi.php @@ -37,6 +37,11 @@ if ( !class_exists('Puc_v4p8_Vcs_GitHubApi', false) ): */ protected $assetApiBaseUrl = null; + /** + * @var bool + */ + private $downloadFilterAdded = false; + public function __construct($repositoryUrl, $accessToken = null) { $path = parse_url($repositoryUrl, PHP_URL_PATH); if ( preg_match('@^/?(?P[^/]+?)/(?P[^/#?&]+?)/?$@', $path, $matches) ) { @@ -382,10 +387,9 @@ if ( !class_exists('Puc_v4p8_Vcs_GitHubApi', false) ): * @return bool */ public function addHttpRequestFilter($result) { - static $filterAdded = false; - if ( $this->releaseAssetsEnabled && !$filterAdded && $this->isAuthenticationEnabled() ) { + if ( $this->releaseAssetsEnabled && !$this->downloadFilterAdded && $this->isAuthenticationEnabled() ) { add_filter('http_request_args', array($this, 'setReleaseDownloadHeader'), 10, 2); - $filterAdded = true; + $this->downloadFilterAdded = true; } return $result; }