Skip to content

Commit

Permalink
Update 1.3
Browse files Browse the repository at this point in the history
* Fixed all php notices
* Fixed minor bugs
* Added an example plugin that's used as a test
* Minor documentation/readme adjustments
  • Loading branch information
jkudish committed Mar 26, 2012
1 parent cf584e1 commit 44099cc
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 12 deletions.
10 changes: 8 additions & 2 deletions README.md
Expand Up @@ -18,7 +18,7 @@ Usage instructions
'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
'raw_url' => 'https://raw.github.com/jkudish/master/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
'sslverify' => true // wether WP should check the validity of the SSL cert when getting an update, see https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/2 and https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/4 for details
Expand All @@ -31,7 +31,7 @@ Usage instructions

* In your Github repository, you will need to include the following line (formatted exactly like this) anywhere in your Readme file:

`~Current Version:1.2~`
`~Current Version:1.3~`

* 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.

Expand All @@ -53,6 +53,12 @@ A: See the discussion and answer [here](https://github.com/jkudish/WordPress-Git
Changelog
===========

### 1.3
* Fixed all php notices
* Fixed minor bugs
* Added an example plugin that's used as a test
* Minor documentation/readme adjustments

### 1.2
* Added phpDoc and minor syntax/readability adjusments, props [@franz-josef-kaiser](https://github.com/franz-josef-kaiser), [@GaryJones](https://github.com/GaryJones)
* Added a die to prevent direct access, props [@franz-josef-kaiser](https://github.com/franz-josef-kaiser)
Expand Down
64 changes: 64 additions & 0 deletions plugin.php
@@ -0,0 +1,64 @@
<?php

/*
Plugin Name: WP Github Plugin Updater Test
Plugin URI: https://github.com/jkudish/WordPress-GitHub-Plugin-Updater
Description: Semi-automated test for the Github Plugin Updater
Version: 0.1
Author: Joachim Kudish
Author URI: http://jkudish.com/
License: GPLv2
*/

/**
* Note: the version # above is purposely low in order to be able to test the updater
* The real version # is below
* @package GithubUpdater
* @author Joachim Kudish @link http://jkudish.com
* @since 1.3
* @version 1.3
*/

/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/


add_action('init', 'github_plugin_updater_test_init');
function github_plugin_updater_test_init() {

include_once('updater.php');

define('WP_GITHUB_FORCE_UPDATE', true);

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__),
'proper_folder_name' => 'github-updater',
'api_url' => 'https://api.github.com/repos/jkudish/WordPress-GitHub-Plugin-Updater',
'raw_url' => 'https://raw.github.com/jkudish/WordPress-GitHub-Plugin-Updater/master',
'github_url' => 'https://github.com/jkudish/WordPress-GitHub-Plugin-Updater',
'zip_url' => 'https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/zipball/master',
'sslverify' => true,
'requires' => '3.0',
'tested' => '3.3',
);

new WPGitHubUpdater($config);

}

}
26 changes: 16 additions & 10 deletions updater.php
Expand Up @@ -7,9 +7,10 @@
if ( ! class_exists( 'WPGitHubUpdater' ) ) :

/**
* @version 1.2
* @version 1.3
* @author Joachim Kudish <info@jkudish.com>
* @link http://jkudish.com
* @package GithubUpdater
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @copyright Copyright (c) 2011, Joachim Kudish
*
Expand Down Expand Up @@ -59,7 +60,7 @@ public function __construct( $config = array() ) {

$this->set_defaults();

if ( WP_DEBUG )
if ( ( defined('WP_DEBUG') && WP_DEBUG ) || ( defined('WP_GITHUB_FORCE_UPDATE') || WP_GITHUB_FORCE_UPDATE ) )
add_action( 'init', array( $this, 'delete_transients' ) );

add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'api_check' ) );
Expand Down Expand Up @@ -143,15 +144,21 @@ public function get_new_version() {
if ( !isset( $version ) || !$version || '' == $version ) {

$raw_response = wp_remote_get(
$this->config['raw_url'].'/README.md',
$this->config['sslverify'],
trailingslashit($this->config['raw_url']).'README.md',
array(
'sslverify' => $this->config['sslverify'],
)
);

if ( is_wp_error( $raw_response ) )
return false;

$__version = explode( '~Current Version:', $raw_response['body'] );
$_version = explode( '~', $__version[1] );

if ( !isset($__version['1']) )
return false;

$_version = explode( '~', $__version['1'] );
$version = $_version[0];

// refresh every 6 hours
Expand Down Expand Up @@ -198,9 +205,7 @@ public function get_github_data() {
*/
public function get_date() {
$_date = $this->get_github_data();
$date = $_date->updated_at;
$date = date( 'Y-m-d', strtotime( $_date->updated_at ) );
return $date;
return ( !empty($_date->updated_at) ) ? date( 'Y-m-d', strtotime( $_date->updated_at ) ) : false;
}


Expand All @@ -212,7 +217,7 @@ public function get_date() {
*/
public function get_description() {
$_description = $this->get_github_data();
return $_description->description;
return ( !empty($_description->description) ) ? $_description->description : false;
}


Expand Down Expand Up @@ -243,8 +248,9 @@ public function api_check( $transient ) {
if ( empty( $transient->checked ) )
return $transient;

// check the version and make sure it's new
// check the version and decide if it's new
$update = version_compare( $this->config['new_version'], $this->config['version'] );

if ( 1 === $update ) {
$response = new stdClass;
$response->new_version = $this->config['new_version'];
Expand Down

0 comments on commit 44099cc

Please sign in to comment.