Skip to content

Commit be35590

Browse files
Git Updater
1 parent bd24946 commit be35590

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

page-links.php

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -139,40 +139,45 @@ public function get_options()
139139
*/
140140
public function checkForUpdate($option) {
141141

142-
$slug = "page-links";
143-
$updateUrl = 'http://svn.sh/update/update.php?name='. $slug;
144142

145-
$raw = get_transient($slug . "_update");
146-
//var_dump($raw); die();
147-
if(!$raw) {
148-
$raw = wp_remote_get($updateUrl);
149-
set_transient($slug . "_update", $raw, 28800);
150-
}
151-
if ( (is_wp_error($raw)) || (200 != wp_remote_retrieve_response_code($raw))) {
152-
return $option;
153-
}
143+
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
144+
145+
$gitUriValue = 'https://github.com/studiohyperset/page-links-single-page-option/';
154146

155-
$info = json_decode(wp_remote_retrieve_body($raw));
156-
if(!$info) {
157-
return $option;
158-
}
159-
$plugin = plugin_basename(__FILE__);
160-
if(!is_object($option->response[$plugin])) {
161-
$option->response[$plugin] = new stdClass();
147+
$url = 'https://api.github.com/repos/studiohyperset/page-links-single-page-option/tags';
148+
149+
//$response = get_transient(md5($url)); // Note: WP transients fail if key is long than 45 characters
150+
$response = array(); // Note: WP transients fail if key is long than 45 characters
151+
152+
if(empty($response)){
153+
$raw_response = wp_remote_get($url, array('sslverify' => false, 'timeout' => 10));
154+
if ( is_wp_error( $raw_response ) ){
155+
return;
156+
}
157+
$response = json_decode($raw_response['body']);
158+
$response = $response[0];
159+
160+
//set cache
161+
set_transient(md5($url), $response, 6000);
162162
}
163163

164-
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
165-
$data = get_plugin_data( __FILE__ );
166-
if(!$info->is_valid || version_compare($data['Version'], $info->version, '>=')) {
164+
// check and generate download link
165+
$data = get_plugin_data( __FILE__ );
166+
$plugin = plugin_basename(__FILE__);
167+
if(version_compare($data['Version'], $response->name, '>=')){
168+
// up-to-date!
167169
unset($option->response[$plugin]);
168170
} else {
169-
$option->response[$plugin]->url = $updateUrl;
170-
$option->response[$plugin]->slug = $slug;
171-
$option->response[$plugin]->package = $info->url;
172-
$option->response[$plugin]->new_version = $info->version;
173-
$option->response[$plugin]->id = "0";
174-
}
175-
return $option;
171+
$option->response[$plugin] = (object)array(
172+
'url' => $gitUriValue,
173+
'slug' => 'page-links-single-page-option',
174+
'package' => $response->zipball_url,
175+
'new_version' => $response->name,
176+
'id' => "0"
177+
);
178+
}
179+
180+
return $option;
176181
}
177182
}
178183

0 commit comments

Comments
 (0)