Add the ability to show a plugin icon on the "Dashboard -> Updates" page.

Usage: Add the following entry to your JSON file:

"icons" : {
	"1x" : "http://example.com/assets/icon-128x128.png",
	"2x" : "http://example.com/assets/icon-256x256.png",
	"svg": "http://example.com/assets/icon.svg"
} 

All of the keys are optional. They should point to different versions of the same icon:
- "1x": a 128x128 px image.
- "2x": a 256x256 px image for HiDPI screens.
- "svg": a vector version of the icon.

See WordPress.org for more information on supported icon sizes and image formats:  
https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-icons

Suggested in #153
This commit is contained in:
Yahnis Elsts 2017-11-21 22:11:18 +02:00
parent 150d3d8165
commit 585f60d91c
3 changed files with 33 additions and 6 deletions

View File

@ -16,10 +16,12 @@ if ( !class_exists('Puc_v4p3_Plugin_Info', false) ):
public $version;
public $homepage;
public $sections = array();
public $banners;
public $translations = array();
public $download_url;
public $banners;
public $icons = array();
public $translations = array();
public $author;
public $author_homepage;
@ -51,8 +53,9 @@ if ( !class_exists('Puc_v4p3_Plugin_Info', false) ):
return null;
}
//json_decode decodes assoc. arrays as objects. We want it as an array.
//json_decode decodes assoc. arrays as objects. We want them as arrays.
$instance->sections = (array)$instance->sections;
$instance->icons = (array)$instance->icons;
return $instance;
}

View File

@ -13,10 +13,11 @@ if ( !class_exists('Puc_v4p3_Plugin_Update', false) ):
public $homepage;
public $upgrade_notice;
public $tested;
public $icons = array();
public $filename; //Plugin filename relative to the plugins directory.
protected static $extraFields = array(
'id', 'homepage', 'tested', 'upgrade_notice', 'filename',
'id', 'homepage', 'tested', 'upgrade_notice', 'icons', 'filename',
);
/**
@ -72,7 +73,7 @@ if ( !class_exists('Puc_v4p3_Plugin_Update', false) ):
*
* @return object
*/
public function toWpFormat(){
public function toWpFormat() {
$update = parent::toWpFormat();
$update->id = $this->id;
@ -80,10 +81,28 @@ if ( !class_exists('Puc_v4p3_Plugin_Update', false) ):
$update->tested = $this->tested;
$update->plugin = $this->filename;
if ( !empty($this->upgrade_notice) ){
if ( !empty($this->upgrade_notice) ) {
$update->upgrade_notice = $this->upgrade_notice;
}
if ( !empty($this->icons) && is_array($this->icons) ) {
//This should be an array with up to 4 keys: 'svg', '1x', '2x' and 'default'.
//Docs: https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-icons
$icons = array_intersect_key(
$this->icons,
array('svg' => true, '1x' => true, '2x' => true, 'default' => true)
);
if ( !empty($icons) ) {
$update->icons = $icons;
//It appears that the 'default' icon isn't used anywhere in WordPress 4.9,
//but lets set it just in case a future release needs it.
if ( !isset($update->icons['default']) ) {
$update->icons['default'] = current($update->icons);
}
}
}
return $update;
}
}

View File

@ -18,6 +18,11 @@
"changelog": "(Recommended) Changelog. <p>This section will be displayed by default when the user clicks 'View version x.y.z details'.</p>",
"custom_section": "This is a custom section labeled 'Custom Section'."
},
"icons" : {
"1x" : "http://w-shadow.com/files/external-update-example/assets/icon-128x128.png",
"2x" : "http://w-shadow.com/files/external-update-example/assets/icon-256x256.png"
},
"banners": {
"low": "http://w-shadow.com/files/external-update-example/assets/banner-772x250.png",