Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MemberPerks mp_get_member_level
<?php
// Function to get the member level
function mp_get_member_level(){
// Get current user's ID
$memberID = get_current_user_id();
if( $memberID != 0 ):
// Get member's info
$memberInfo = get_userdata($memberID);
$memberName = $memberInfo->first_name;
if(empty($memberName)):
$memberName = $memberInfo->user_login;
endif;
// Registration date
$memberRegistered = $memberInfo->user_registered;
$registrationDate = new DateTime($memberRegistered);
// Current Date
$currentDate = new DateTime("now", new DateTimeZone('Europe/Madrid'));
//https://stackoverflow.com/questions/4233605/elegant-way-to-get-the-count-of-months-between-two-dates
$memberLevel = $registrationDate->diff($currentDate)->m + ($registrationDate->diff($currentDate)->y*12) + 1;
$output = array(
'member_name' => $memberName,
'member_level' => $memberLevel
);
return $output;
else:
return; // User is not logged in
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.