Skip to content

Commit

Permalink
support plugin images, closes #1 and implement a better latest versio…
Browse files Browse the repository at this point in the history
…n selector
  • Loading branch information
Arcath committed Jul 6, 2018
1 parent f59e52d commit ef29ca6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
60 changes: 44 additions & 16 deletions lib/wup-client.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<?php
// if you change this make sure you change the class name below (0.0.1 becomes WUPClient0_0_1).
$classVersion = "0.1.0";

if(!defined('WUP_CLIENT_CLASS_VERSION')){
define('WUP_CLIENT_CLASS_VERSION', $classVersion);
}else{
if(Composer\Semver\Comparator::greaterThan($classVersion, WUP_CLIENT_CLASS_VERSION)){
define('WUP_CLIENT_CLASS_VERSION', $classVersion);
}
}

class WUPClient{
public function __construct($type, $slug, $url){
$className = 'WUPClient' . str_replace('.', '_', WUP_CLIENT_CLASS_VERSION);
$classes = get_declared_classes();
$versions = array();
foreach($classes as $class){
if(strpos($class, 'WUPClient') !== false){
$version = str_replace('_', '.', substr($class, 9));
if(strlen($version) > 0){
$versions[] = $version;
}
}
}

$sorted = Composer\Semver\Semver::rsort($versions);

$className = 'WUPClient' . str_replace('.', '_', $sorted[0]);

new $className($type, $slug, $url);
new $className($type, $slug, $url);
}
}


class WUPClient0_1_0{
class WUPClient0_1_1{
public $url;
public $type;
public $slug;
Expand Down Expand Up @@ -114,6 +115,23 @@ public function updateResponse($state){
$update->package = $state->downloadUrl;
$update->url = $state->detailsUrl;

if(
isset($state->image_svg)
||
isset($state->image_2x)
||
isset($state->image_1x)
||
isset($state->image_default)
){
$update->icons = array(
'svg' => $state->image_svg,
'2x' => $state->image_2x,
'1x' => $state->image_1x,
'default' => $state->image_default
);
}

return $update;
}
}
Expand All @@ -128,6 +146,10 @@ public function checkForUpdates(){
$state->wupVersion = null;
$state->detailsUrl = '';
$state->downloadUrl = '';
$state->image_svg = '';
$state->image_2x = '';
$state->image_1x = '';
$state->image_default = '';
}

$state->lastCheck = time();
Expand All @@ -142,9 +164,15 @@ public function checkForUpdates(){
update_option($this->settingName, $state);

$data = $this->getWUPData($state->localVersion);

$state->wupVersion = $data->version;
$state->detailsUrl = $data->detailsUrl;
$state->downloadUrl = $data->downloadUrl;
$state->image_svg = $data->image_svg;
$state->image_2x = $data->image_2x;
$state->image_1x = $data->image_1x;
$state->image_default = $data->image_default;

update_option($this->settingName, $state);
}

Expand All @@ -160,7 +188,7 @@ public function getLocalPluginVersion(){
}

public function getLocalThemeVersion(){
$theme = wp_get_theme($this->theme);
$theme = wp_get_theme();
return $theme->get('Version');
}

Expand Down
4 changes: 2 additions & 2 deletions wup-client.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
require_once('lib/wup-client.php');

function wup_client($type, $slug, $url){
if($type != 'theme' && $type != 'plugin'){
throw "WUPClient must be theme or plugin";
}

require_once('lib/wup-client.php');

$client = new WUPClient($type, $slug, $url);
}

Expand Down

0 comments on commit ef29ca6

Please sign in to comment.