Skip to content

Instantly share code, notes, and snippets.

@scottsousa
Created February 6, 2014 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scottsousa/8847073 to your computer and use it in GitHub Desktop.
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 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