Created
November 17, 2020 13:53
-
-
Save contemplate/192de6465cf275c0c2ff2dea38912e55 to your computer and use it in GitHub Desktop.
PMPro show member expiration 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
/*-- Member Expiration Date Shortcode -----------------*/ | |
//[pmpro_expiration_date] | |
function pmpro_expiration_date_shortcode( $atts ) { | |
//make sure PMPro is active | |
if(!function_exists('pmpro_getMembershipLevelForUser')) | |
return; | |
//get attributes | |
$a = shortcode_atts( array( | |
'user' => '', | |
), $atts ); | |
//find user | |
if(!empty($a['user']) && is_numeric($a['user'])) { | |
$user_id = $a['user']; | |
} elseif(!empty($a['user']) && strpos($a['user'], '@') !== false) { | |
$user = get_user_by('email', $a['user']); | |
$user_id = $user->ID; | |
} elseif(!empty($a['user'])) { | |
$user = get_user_by('login', $a['user']); | |
$user_id = $user->ID; | |
} else { | |
$user_id = false; | |
} | |
//no user ID? bail | |
if(!isset($user_id)) | |
return; | |
//get the user's level | |
$level = pmpro_getMembershipLevelForUser($user_id); | |
if(!empty($level) && !empty($level->enddate)) | |
$content = date(get_option('date_format'), $level->enddate); | |
else | |
$content = "---"; | |
return $content; | |
} | |
add_shortcode('pmpro_expiration_date', 'pmpro_expiration_date_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment