Merge pull request #462 from timwiel/timwiel-pluginbanners

Use plugin banners from the local "assets" directory.
This commit is contained in:
Yahnis Elsts 2021-09-30 19:29:10 +03:00 committed by GitHub
commit 12cff18273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 0 deletions

View File

@ -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;