Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Forked from femiyb/my-show-user-start.php
Last active November 16, 2020 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/26b9f78f46b8eccd50dd339768c199a0 to your computer and use it in GitHub Desktop.
Save ipokkel/26b9f78f46b8eccd50dd339768c199a0 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 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