Created
November 29, 2019 18:35
-
-
Save femiyb/7b2bd225325c5cc076a00feb7b9d539c to your computer and use it in GitHub Desktop.
* Show the user's start date.
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 | |
/** | |
* 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