Skip to content

Instantly share code, notes, and snippets.

@smallfri
Created December 10, 2014 15:52
Show Gist options
  • Save smallfri/d3c39fb8caab003cd3b1 to your computer and use it in GitHub Desktop.
Save smallfri/d3c39fb8caab003cd3b1 to your computer and use it in GitHub Desktop.
<?php
if(isset($_GET['debug']) AND $_GET['debug']==1)
{
set_site_transient('update_plugins',null);
ini_set('display_errors','On');
error_reporting(E_ALL);
}
DEFINE('test_software_39',basename(dirname(__FILE__)));
DEFINE('test_software_api_39','http://www.licenseengine.com/updates');
class test_software_39_updater
{
function __construct()
{
$this->hook();
}
private function hook()
{
add_filter('pre_set_site_transient_update_plugins',array(&$this,'check_for_plugin_update'));
//add_filter('plugins_api',array(&$this,'plugin_api_call'),10,3);
if(isset($_GET['debug']) AND $_GET['debug']==1)
{
add_filter('plugins_api_result',array(&$this,'debug_result'));
}
}
function plugin_api_call($def,$action,$args)
{
global $wp_version;
if(!isset($args->slug)||($args->slug!=test-software))
{
return false;
}
// Get the current version
$plugin_info = get_site_transient('update_plugins');
$current_version = $plugin_info->checked['test-software/test-software.php'];
$args->version = $current_version;
$request_string = array('body' => array('action' => $action,'request' => serialize($args),'api-key' => md5(get_bloginfo('url'))),'user-agent' => 'WordPress/'.$wp_version.'; '.get_bloginfo('url'));
$request = wp_remote_post(test_software_api_39,$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']);
}
}
return $res;
}
function check_for_plugin_update($checked_data)
{
global $wp_version;
$response = null;
if(empty($checked_data->checked))
{
return $checked_data;
}
$args = array('slug' =>'test-software','version' => $checked_data->checked['test-software/test-software.php'],);
$request_string = array('body' => array('action' => 'basic_check','request' => serialize($args),'api-key' => md5(get_bloginfo('url'))),'user-agent' => 'WordPress/'.$wp_version.'; '.get_bloginfo('url'));
$raw_response = wp_remote_post(test_software_api_39,$request_string);
if(!is_wp_error($raw_response)&&($raw_response['response']['code']==200))
{
$response = unserialize($raw_response['body']);
}
if(is_object($response)&&!empty($response)) // Feed the update data into WP updater
{
$checked_data->response['test-software/test-software.php'] = $response;
}
return $checked_data;
}
function debug_result($res)
{
echo '<pre>'.print_r($res,true).'</pre>';
return $res;
}
}
$test_software_39__updater = new test_software_39_updater();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment