From c6970fd8831c79b98779cdf9032f657ae23a47c5 Mon Sep 17 00:00:00 2001 From: Yahnis Elsts Date: Tue, 3 May 2016 18:32:39 +0300 Subject: [PATCH] Extract translation update filter as a method. --- plugin-update-checker.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/plugin-update-checker.php b/plugin-update-checker.php index c1140c2..0c29d62 100644 --- a/plugin-update-checker.php +++ b/plugin-update-checker.php @@ -259,7 +259,20 @@ class PluginUpdateChecker_3_0 { } $update = PluginUpdate_3_0::fromPluginInfo($pluginInfo); - //Remove translation updates that don't apply to this site. + //Keep only those translation updates that apply to this site. + $update->translations = $this->filterApplicableTranslations($update->translations); + + return $update; + } + + /** + * Filter a list of translation updates and return a new list that contains only updates + * that apply to the current site. + * + * @param array $translations + * @return array + */ + private function filterApplicableTranslations($translations) { $languages = array_flip(array_values(get_available_languages())); $installedTranslations = wp_get_installed_translations('plugins'); if ( isset($installedTranslations[$this->slug]) ) { @@ -269,7 +282,7 @@ class PluginUpdateChecker_3_0 { } $applicableTranslations = array(); - foreach($update->translations as $translation) { + foreach($translations as $translation) { //Does it match one of the available core languages? $isApplicable = array_key_exists($translation->language, $languages); //Is it more recent than an already-installed translation? @@ -283,9 +296,8 @@ class PluginUpdateChecker_3_0 { $applicableTranslations[] = $translation; } } - $update->translations = $applicableTranslations; - return $update; + return $applicableTranslations; } /**