Merge pull request #462 from timwiel/timwiel-pluginbanners
Use plugin banners from the local "assets" directory.
This commit is contained in:
commit
12cff18273
|
|
@ -47,6 +47,7 @@ if ( !class_exists('Puc_v4p11_Vcs_PluginUpdateChecker') ):
|
||||||
|
|
||||||
$this->setInfoFromHeader($this->package->getPluginHeader(), $info);
|
$this->setInfoFromHeader($this->package->getPluginHeader(), $info);
|
||||||
$this->setIconsFromLocalAssets($info);
|
$this->setIconsFromLocalAssets($info);
|
||||||
|
$this->setBannersFromLocalAssets($info);
|
||||||
|
|
||||||
//Pick a branch or tag.
|
//Pick a branch or tag.
|
||||||
$updateSource = $api->chooseReference($this->branch);
|
$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) {
|
public function setBranch($branch) {
|
||||||
$this->branch = $branch;
|
$this->branch = $branch;
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue