Skip to content

Instantly share code, notes, and snippets.

@smallfri
Last active August 29, 2015 14:11
Show Gist options
  • Save smallfri/adedc5077130facb4905 to your computer and use it in GitHub Desktop.
Save smallfri/adedc5077130facb4905 to your computer and use it in GitHub Desktop.
function register_settings()
{
register_setting('Pixel_Redirect_Single_17','Pixel_Redirect_Single','Pixel_Redirect_plugin_maintenance');
}
function Pixel_Redirect_plugin_maintenance($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('fb-pixel-redirect'),'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('Pixel_Redirect_Single_17-lks',serialize($data));
return $settings;
}
elseif(!empty($license_data) AND $license_data->license=='invalid')
{
update_option('Pixel_Redirect_Single_17-lks',$license_data->license);
return $settings;
}
else
{
return false;
}
}
}
function get_all_options()
{
$l = get_option('Pixel_Redirect_Single_17');
$v = get_option('Pixel_Redirect_Single_17-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' => 'wpsmartlinks','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('wpsmartlinks_11-lks',serialize($data));
return true;
}
elseif(!empty($license_data) AND $license_data->license=='invalid')
{
update_option('wpsmartlinks_11-lks',$license_data->license);
return false;
}
else
{
return false;
}
}
}
function in_admin_footer()
{
$PTYPE = get_post_type();
if($PTYPE=='redirect')
{
$status = get_all_options();
if($status==false)
{
echo <<<END
<div id='license' style='display:none'>
<div style="padding: 15px; font-size: 14px;">
<div class="alert alert-error" style="margin-top:10px;color:red;">
Your License Key is NOT Valid.
</div>
<h4><?php _e('Registration'); ?></h4>
<form method="post" action="options.php" enctype="multipart/form-data" id="license_key">
<?php settings_fields('wp_action_image_27'); ?>
<div class="button-container">
<input id="license_key" name="wp_action_image_27[license_key]" type="text" class="input-xlarge" placeholder="Enter Your License Key" value=""/>
<input type="submit" value="Save" id="save_button" class="button action"/>
<p>Can't find your key? Login to
<a href="//www.licenseengine.com/my-keys" target="_blank">License Engine</a> to retrieve your key.
</p>
</div>
</form>
<div style="margin-top:10px;margin-left:185px;">
<img src="//www.licenseengine.com/assets2/img/licensingpoweredbyLE.png"></div>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="application/javascript">
jQuery(document).ready(function () {
html = jQuery('#license').html();
jQuery('.wrap').first().before(html).css('display', 'none');
});
</script>
END;
}
}
}
add_action('admin_init','register_settings');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment