Created
June 15, 2022 10:20
-
-
Save champsupertramp/126176cfdb7ae08913c5154da9087e45 to your computer and use it in GitHub Desktop.
Ultimate Member - Upcoming Birthday future age as tag line in the Member Directory
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
add_filter("um_ajax_get_members_data","um_061522_future_age_birthdays", 10, 3 ); | |
function um_061522_future_age_birthdays( $data_array, $user_id, $directory_data ){ | |
$directory_id = $directory_data['form_id']; | |
if( 325 !== $directory_id ) return $data_array; | |
um_fetch_user( $user_id ); | |
$hours_in_day = 24; | |
$minutes_in_hour= 60; | |
$seconds_in_mins= 60; | |
$birth_date = new DateTime( um_user("birth_date") ); | |
$current_date = new DateTime(); | |
$diff = $birth_date->diff($current_date); | |
$years = $diff->y + 1; | |
$months = ($diff->y * 12) + $diff->m + 1; | |
$weeks = floor($diff->days/7) + 1; | |
$days = $diff->days + 1; | |
$turns_text = __("Turning",'ultimate-member'); | |
if( $days < 7 ){ | |
$data_array['birth_date'] = $turns_text . ' '. $days . ' ' . _n( 'day old', 'days old', $days, 'ultimate-member' ); | |
}else if( $days >= 7 && $weeks < 4 ){ | |
$data_array['birth_date'] = $turns_text . ' '. $weeks . ' ' . _n( 'week old', 'weeks old', $weeks, 'ultimate-member' ); | |
}else if( $weeks >=4 && $months < 12 ){ | |
$data_array['birth_date'] = $turns_text . ' '. $months . ' ' . _n( 'month old', 'months old', $months, 'ultimate-member' ); | |
}else if( $months >= 12 || $years > 1 ){ | |
$data_array['birth_date'] = $turns_text . ' '. $years . ' ' . _n( 'year old', 'years old', $years, 'ultimate-member' ); | |
} | |
return $data_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code doesn't work, it's confusing people