Skip to content

Commit

Permalink
Initial release.
Browse files Browse the repository at this point in the history
  • Loading branch information
benleivian committed Jul 24, 2015
1 parent 8990832 commit 8581b0d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
6 changes: 6 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,9 @@ function forward_scripts() {
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';

/**
* Enable automatic theme updates.
*/
require_once('wp-updates-theme.php');
new WPUpdatesThemeUpdater_1511( 'http://wp-updates.com/api/2/theme', basename( get_template_directory() ) );
4 changes: 2 additions & 2 deletions style.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*!
Theme Name: Forward
Theme URI: http://drawbackwards.com
Theme URI: http://design.org
Author: Drawbackwards
Author URI: http://drawbackwards.com
Description: Forward by Drawbackwards
Version: 1.0
Version: 1.0.0
Text Domain: forward
Tags: two-columns, right-sidebar, responsive-layout, accessibility-ready, threaded-comments
License: GNU General Public License v2 or later
Expand Down
68 changes: 68 additions & 0 deletions wp-updates-theme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/*
WPUpdates Theme Updater Class
http://wp-updates.com
v2.0
Example Usage:
require_once('wp-updates-theme.php');
new WPUpdatesThemeUpdater_1511( 'http://wp-updates.com/api/2/theme', basename(get_template_directory()) );
*/

if( !class_exists('WPUpdatesThemeUpdater_1511') ) {
class WPUpdatesThemeUpdater_1511 {

var $api_url;
var $theme_id = 1511;
var $theme_slug;
var $license_key;

function __construct( $api_url, $theme_slug, $license_key = null ) {
$this->api_url = $api_url;
$this->theme_slug = $theme_slug;
$this->license_key = $license_key;

add_filter( 'pre_set_site_transient_update_themes', array(&$this, 'check_for_update') );

// This is for testing only!
//set_site_transient('update_themes', null);
}

function check_for_update( $transient ) {
if (empty($transient->checked)) return $transient;

$request_args = array(
'id' => $this->theme_id,
'slug' => $this->theme_slug,
'version' => $transient->checked[$this->theme_slug]
);
if ($this->license_key) $request_args['license'] = $this->license_key;

$request_string = $this->prepare_request( 'theme_update', $request_args );
$raw_response = wp_remote_post( $this->api_url, $request_string );

$response = null;
if( !is_wp_error($raw_response) && ($raw_response['response']['code'] == 200) )
$response = unserialize($raw_response['body']);

if( !empty($response) ) // Feed the update data into WP updater
$transient->response[$this->theme_slug] = $response;

return $transient;
}

function prepare_request( $action, $args ) {
global $wp_version;

return array(
'body' => array(
'action' => $action,
'request' => serialize($args),
'api-key' => md5(home_url())
),
'user-agent' => 'WordPress/'. $wp_version .'; '. home_url()
);
}

}
}

0 comments on commit 8581b0d

Please sign in to comment.