Created
February 6, 2014 16:02
-
-
Save scottsousa/8847073 to your computer and use it in GitHub Desktop.
Paid Memberships Pro - This function will output the number of days left in a trial period for a user in the member links section on the account page.
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
/** | |
* This function will output the number of days left in a trial period for a user in the | |
* member links section on the account page. | |
*/ | |
add_action( 'pmpro_member_links_top', 'my_pmpro_member_links_top' ); | |
function my_pmpro_member_links_top() { | |
// Get current level details | |
$user_level = pmpro_getMembershipLevelForUser(); | |
// Make sure we have a trial | |
if ( $user_level->trial_limit != 0 ) { | |
// Trial ending time (UNIX Timestamp) | |
$trial_end_time = strtotime( '+' . $user_level->trial_limit . ' ' . $user_level->cycle_period, $user_level->startdate ); | |
// Make sure the trial end time is after the current time | |
if ( $trial_end_time > time() ) { | |
$current_date = new DateTime( 'now' ); // Current date | |
$trial_end_date = new DateTime( date( 'Y-m-d', $trial_end_time ) ); // Trial end date | |
$interval = $current_date->diff( $trial_end_date ); // Compare the two dates | |
echo '<li>Your trial period ends in: ' . $interval->format( '%a days' ) . '</li>'; // Output to user | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment