Skip to content

Instantly share code, notes, and snippets.

@smallfri
Last active August 29, 2015 14:11
Show Gist options
  • Save smallfri/85274bde5e86dade9c03 to your computer and use it in GitHub Desktop.
Save smallfri/85274bde5e86dade9c03 to your computer and use it in GitHub Desktop.
function register_settings()
{
register_setting('test_software_39','test_software_39',array($this,'plugin_maintenance'));
}
function plugin_maintenance_test_software_39($options)
{
if(isset($options) AND $options['license_key']!='')
{
$settings['license_key'] = $options['license_key'];
$license = $options['license_key'];
$api_params = array('action' => 'activate_license','license' => $license,'item_name' => urlencode('%slu2g%'),'domain' => $_SERVER['SERVER_NAME']);
$response = wp_remote_get(add_query_arg($api_params,'http://www.licenseengine.com/licenses/a/'),array('timeout' => 15,'sslverify' => false));
if(is_wp_error($response))
{
return false;
}
$license_data = json_decode(wp_remote_retrieve_body($response));
if(!empty($license_data) AND $license_data->license=='valid')
{
$data = array('timestamp' => time());
update_option('test_software_39-lks',serialize($data));
return $settings;
}
elseif(!empty($license_data) AND $license_data->license=='invalid')
{
update_option('test_software_39-lks',$license_data->license);
return $settings;
}
else
{
return false;
}
}
}
function get_all_options_test_software_39()
{
$l = get_option('test_software_39');
$v = get_option('test_software_39-lks');
$u = FALSE;
if(isset($v))
{
$data = unserialize($v);
if($data['timestamp']>time()-24*60*60)
{
return true;
}
}
if($u===FALSE)
{
$api_params = array('action' => 'activate_license','license' => $l['license_key'],'item_name' => 'test_software_39','domain' => urlencode($_SERVER['SERVER_NAME']));
$response = wp_remote_get(add_query_arg($api_params,'http://www.licenseengine.com/licenses/a/'),array('timeout' => 15,'sslverify' => false));
if(is_wp_error($response))
{
return false;
}
$license_data = json_decode(wp_remote_retrieve_body($response));
if(!empty($license_data) AND $license_data->license=='valid')
{
$data = array('timestamp' => time());
update_option('test_software_39-lks',serialize($data));
return true;
}
elseif(!empty($license_data) AND $license_data->license=='invalid')
{
update_option('test_software_39-lks',$license_data->license);
return false;
}
else
{
return false;
}
}
}
function start_up_test_software_39()
{
$status = $this->get_all_options();
if($status==false AND $_GET['post_type']=='lkp')
{
?>
<div class="alert alert-error" style="margin-top:10px;color:red">
Your License Key is NOT Valid.
</div>
<div class="hero-unit" style="padding: 15px; font-size: 14px;">
<h4><?php _e('Plugin License'); ?></h4>
<form method="post" action="options.php" enctype="multipart/form-data" id="license_key">
<?php settings_fields('test_software_39'); ?>
<div class="button-container">
<label class="contrli-label" style="padding-top:6px;text-align: left;width:25%;">License Key</label>
<input id="license_key" name="test_software_39[license_key]" type="text" class="input-xlarge" style="margin:0 15px;" placeholder="Enter Your License Key" value=""/>
<input type="submit" value="Save" id="save_button" class="button action"/>
</div>
</form>
<div style="margin-top:10px;margin-left:185px;"><img src="//www.licenseengine.com/assets/img/poweredbylicenseengineajvzoocompany.png"></div>
</div>
<?php
die();
}
}
add_action('admin_init','register_settings');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment