Skip to content

Instantly share code, notes, and snippets.

@smallfri
Created October 11, 2016 16:35
Show Gist options
  • Save smallfri/071c2f7482b120c394715b47d58f5a41 to your computer and use it in GitHub Desktop.
Save smallfri/071c2f7482b120c394715b47d58f5a41 to your computer and use it in GitHub Desktop.
<?php
namespace JVZApprovalPlugin;
use stdClass;
use WP_Error;
DEFINE('theme_update_api', 'http://www.licenseengine.com/updates');
class themeUpdater
{
function __construct()
{
$this->hook();
}
private function hook()
{
add_filter('pre_set_site_transient_update_themes', array(&$this, 'check_for_update'));
}
public function check_for_update($transient)
{
if (empty($transient->checked))
{
return $transient;
}
global $wp_version;
$theme_data = wp_get_theme();
$theme_slug = $theme_data->get_template();
$args = ['slug' => $theme_slug, 'version' => $wp_version];
$request_string = array(
'body' => array(
'action' => 'plugin_information',
'request' => serialize($args),
'api-key' => md5(get_bloginfo('url'))
),
'user-agent' => 'WordPress/'.$wp_version.'; '.get_bloginfo('url')
);
$request = wp_remote_post(theme_update_api, $request_string);
if (is_wp_error($request))
{
$res = new WP_Error('plugins_api_failed',
__('An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'),
$request->get_error_message());
}
else
{
$res = unserialize($request['body']);
if ($res===false)
{
$res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']);
}
}
$object = new stdClass();
foreach ($res as $key => $value)
{
$object->$key = $value;
}
$transient->response[$theme_slug] = array(
'new_version' => $object->new_version,
'package' => $object->package,
'url' => $object->description
);
return $transient;
}
}
new themeUpdater();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment