Created
August 1, 2012 01:36
-
-
Save yasyf/3222500 to your computer and use it in GitHub Desktop.
WP-Subscription Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related Blog Post: http://blog.yasyf.com/2012/07/31/using-wordpress-as-a-pay-for-access-system/