-
-
Save ipokkel/26b9f78f46b8eccd50dd339768c199a0 to your computer and use it in GitHub Desktop.
Show the user's start date.
This file contains hidden or 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 date( 'F j, 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 ); | |
$user_startdate = strtotime( $startdate[0] ); | |
return date( 'F j, Y', $user_startdate ); | |
} 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