Permalink
Browse files

fixed potential timeout

  • Loading branch information...
1 parent 37b5657 commit fd33fbe5075789468f6653eb7ef01945a56cea4d Joachim Kudish committed Sep 21, 2011
Showing with 34 additions and 22 deletions.
  1. +17 −12 README.md
  2. +17 −10 updater.php
View
@@ -14,22 +14,24 @@ Usage instructions
<pre>
<?php
- $config = array(
- 'slug' => plugin_basename(__FILE__), // this is the slug of your plugin
- 'proper_folder_name' => 'plugin-name', // this is the name of the folder your plugin lives in
- 'api_url' => 'https://api.github.com/repos/jkudish/WordPress-GitHub-Plugin-Updater', // the github API url of your github repo
- 'raw_url' => 'https://raw.github.com/jkudish/WordPress-GitHub-Plugin-Updater', // the github raw url of your github repo
- 'github_url' => 'https://github.com/jkudish/WordPress-GitHub-Plugin-Updater', // the github url of your github repo
- 'zip_url' => 'https://github.com/jkudish/JigoShop-Software-Add-on/zipball/master', // the zip url of the github repo
- 'requires' => '3.0', // which version of WordPress does your plugin require?
- 'tested' => '3.3', // which version of WordPress is your plugin tested up to?
- );
- new wp_github_updater($config);
+ if (is_admin()) { // note the use of is_admin() to double check that this is happening in the admin
+ $config = array(
+ 'slug' => plugin_basename(__FILE__), // this is the slug of your plugin
+ 'proper_folder_name' => 'plugin-name', // this is the name of the folder your plugin lives in
+ 'api_url' => 'https://api.github.com/repos/jkudish/WordPress-GitHub-Plugin-Updater', // the github API url of your github repo
+ 'raw_url' => 'https://raw.github.com/jkudish/WordPress-GitHub-Plugin-Updater', // the github raw url of your github repo
+ 'github_url' => 'https://github.com/jkudish/WordPress-GitHub-Plugin-Updater', // the github url of your github repo
+ 'zip_url' => 'https://github.com/jkudish/JigoShop-Software-Add-on/zipball/master', // the zip url of the github repo
+ 'requires' => '3.0', // which version of WordPress does your plugin require?
+ 'tested' => '3.3', // which version of WordPress is your plugin tested up to?
+ );
+ new wp_github_updater($config);
+ }
</pre>
* In your Github repository, you will need to include the following line (formatted exactly like this) anywhere in your Readme file:
- `~Current Version:1.0.1~`
+ `~Current Version:1.0.2~`
* You will need to update the version number anytime you update the plugin, this will ultimately let the plugin know that a new version is available.
@@ -39,6 +41,9 @@ Usage instructions
Changelog
===========
+### 1.0.2
+* Fixed potential timeout
+
### 1.0.1
* Fixed potential fatal error with wp_error
View
@@ -1,7 +1,7 @@
<?php
/**
- * @version 1.0.1
+ * @version 1.0.2
* @author Joachim Kudish <info@jkudish.com>
* @link http://jkudish.com
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
@@ -65,12 +65,16 @@ function __construct($config = array()) {
// Hook into the plugin details screen
add_filter('plugins_api', array(&$this, 'get_plugin_info'), 10, 3);
-
-
add_filter('upgrader_post_install', array(&$this, 'upgrader_post_install'), 10, 3);
+ // set timeout
+ add_filter('http_request_timeout', array(&$this, 'http_request_timeout'));
+
}
+ function http_request_timeout() {
+ return 2;
+ }
// For testing purpose, the site transient will be reset on each page load
@@ -84,12 +88,12 @@ function delete_transients() {
function get_new_version() {
$version = get_site_transient($this->config['slug'].'_new_version');
if (!isset($version) || !$version || $version == '') {
-
+
$raw_response = wp_remote_get($this->config['raw_url'].'/README.md');
-
- if (is_wp_error($raw_response))
+
+ if (is_wp_error($raw_response))
return false;
-
+
$__version = explode('~Current Version:', $raw_response['body']);
$_version = explode('~', $__version[1]);
$version = $_version[0];
@@ -102,9 +106,12 @@ function get_github_data() {
$github_data = get_site_transient($this->config['slug'].'_github_data');
if (!isset($github_data) || !$github_data || $github_data == '') {
$github_data = wp_remote_get($this->config['api_url']);
- if (!is_wp_error($github_data)) {
- $github_data = json_decode($github_data['body']);
- }
+
+ if (is_wp_error($github_data))
+ return false;
+
+ $github_data = json_decode($github_data['body']);
+
set_site_transient($this->config['slug'].'_github_data', $github_data, 60*60*60*6); // refresh every 6 hours
}
return $github_data;

0 comments on commit fd33fbe

Please sign in to comment.