From e5453b52e44beac6eb9617bb809f1a8bc08b6f02 Mon Sep 17 00:00:00 2001 From: Tim Wiel Date: Wed, 29 Sep 2021 14:24:36 +1300 Subject: [PATCH] Use plugin icons from the local "assets" directory. --- Puc/v4p11/Vcs/PluginUpdateChecker.php | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Puc/v4p11/Vcs/PluginUpdateChecker.php b/Puc/v4p11/Vcs/PluginUpdateChecker.php index e76e901..51c9015 100644 --- a/Puc/v4p11/Vcs/PluginUpdateChecker.php +++ b/Puc/v4p11/Vcs/PluginUpdateChecker.php @@ -47,6 +47,7 @@ if ( !class_exists('Puc_v4p11_Vcs_PluginUpdateChecker') ): $this->setInfoFromHeader($this->package->getPluginHeader(), $info); $this->setIconsFromLocalAssets($info); + $this->setBannersFromLocalAssets($info); //Pick a branch or tag. $updateSource = $api->chooseReference($this->branch); @@ -227,6 +228,42 @@ if ( !class_exists('Puc_v4p11_Vcs_PluginUpdateChecker') ): } } + /** + * Add banners from the currently installed version to a Plugin Info object. + * + * The banners should be in a subdirectory named "assets". Supported image formats + * and file names are described here: + * @link https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-headers + * + * @param Puc_v4p11_Plugin_Info $pluginInfo + */ + protected function setBannersFromLocalAssets($pluginInfo) { + $assetDirectory = $this->package->getAbsoluteDirectoryPath() . DIRECTORY_SEPARATOR . 'assets'; + if ( !is_dir($assetDirectory) ) { + return; + } + $assetBaseUrl = trailingslashit(plugins_url('', $assetDirectory . '/imaginary.file')); + + $filesToKeys = array( + 'banner-772x250.png' => 'high', + 'banner-772x250.jpg' => 'high', + 'banner-1544x500.png' => 'low', + 'banner-1544x500.jpg' => 'low', + ); + + $banners = array(); + foreach ($filesToKeys as $fileName => $key) { + $fullBannerPath = $assetDirectory . DIRECTORY_SEPARATOR . $fileName; + if ( !isset($icons[$key]) && is_file($fullBannerPath) ) { + $banners[$key] = $assetBaseUrl . $fileName; + } + } + + if ( !empty($banners) ) { + $pluginInfo->banners = $banners; + } + } + public function setBranch($branch) { $this->branch = $branch; return $this;