Skip to content

Instantly share code, notes, and snippets.

@yasyf
Created August 1, 2012 01:36
Show Gist options
  • Save yasyf/3222500 to your computer and use it in GitHub Desktop.
Save yasyf/3222500 to your computer and use it in GitHub Desktop.
WP-Subscription Example
<?php
header('HTTP/1.1 200 OK');
/**
* @package WordPress
* @var bool
*/
define('WP_USE_THEMES', false);
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
$current_user = wp_get_current_user();
if($_REQUEST['paid'] == "yes")
{
//successful payment
update_usermeta($current_user->ID, 'subscription', "true");
update_usermeta($current_user->ID, 'trialDone', 0); //to remove from user_meta
update_usermeta($current_user->ID, 'trialDays', 0); //to remove from user_meta
}
else {
$subscription = get_user_meta($current_user->ID, 'subscription', true);
$trialDays = get_user_meta($current_user->ID, 'trialDays', true);
$trialDone = get_user_meta($current_user->ID, 'trialDone', true);
if ($current_user->ID == 0) {
//not logged in
}
if($subscription != "true")
{
if($trialDone == "true")
{
//trial has ended in a previous session
}
else {
if(empty($trialDays))
{
//give 5 days for a trial
}
else if (intval($trialDays) < 1)
{
//trial has ended in a previous session
}
else if((intval(time()) - intval($_COOKIE['seshCurrent'])) > 80000) //24 hours
{
$newTrialDays = intval($trialDays) -1;
if($newTrialDays == 0)
{
//trial has now ended
}
else {
//$trialDays remaining
setcookie("seshCurrent",time(), time()+3600*24*7);
}
}
}
}
}
?>
@yasyf
Copy link
Author

yasyf commented Aug 4, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment