diff --git a/Puc/v4p3/Plugin/Info.php b/Puc/v4p3/Plugin/Info.php index 01d2939..cfaa411 100644 --- a/Puc/v4p3/Plugin/Info.php +++ b/Puc/v4p3/Plugin/Info.php @@ -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; } diff --git a/Puc/v4p3/Plugin/Update.php b/Puc/v4p3/Plugin/Update.php index f50feed..7f7d2be 100644 --- a/Puc/v4p3/Plugin/Update.php +++ b/Puc/v4p3/Plugin/Update.php @@ -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; } } diff --git a/examples/plugin.json b/examples/plugin.json index 685b943..fea211a 100644 --- a/examples/plugin.json +++ b/examples/plugin.json @@ -18,6 +18,11 @@ "changelog": "(Recommended) Changelog.
This section will be displayed by default when the user clicks 'View version x.y.z details'.
", "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",