Skip to content

Instantly share code, notes, and snippets.

@femiyb
Created November 29, 2019 18:35
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 femiyb/7b2bd225325c5cc076a00feb7b9d539c to your computer and use it in GitHub Desktop.
Save femiyb/7b2bd225325c5cc076a00feb7b9d539c to your computer and use it in GitHub Desktop.
* Show the user's start date.
<?php
/**
* Show the user's start date.
* Show the user's previously membership start date if they were cancelled, expired or cancelled by an admin.
* If none of thhe above is found, the string 'nothing found' will be returned.
*/
function my_show_user_startdate(){
if ( is_user_logged_in() && function_exists( 'pmpro_hasMembershipLevel' ) && pmpro_hasMembershipLevel() ){
global $current_user;
$current_user->membership_level = pmpro_getMembershipLevelForUser( $current_user->ID );
$user_startdate = $current_user->membership_level->startdate;
if( !$user_startdate == 0){
return 'Membership start date: ' . date('d-m-Y', $user_startdate);
}
} elseif ( ! pmpro_hasMembershipLevel() ) {
//try to see if they had a previous membership level.
global $wpdb, $current_user;
$sql = "SELECT startdate FROM $wpdb->pmpro_memberships_users WHERE `user_id` = $current_user->ID AND `status` in ('cancelled', 'expired', 'admin_cancelled') ORDER BY startdate ASC LIMIT 1";
$results = $wpdb->get_results( $sql );
if ( ! empty( $results[0] ) ) {
$startdate = explode( " ", $results[0]->startdate );
return $startdate[0]; //return the date only, not time of expiration.
}else{
return 'nothing found';
}
}
}
add_shortcode( 'show_startdate', 'my_show_user_startdate' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment