I get all the users. If for any users whose expiration date is coming close to 365 he/she should get an email alert 15 days before to their registered mail ids.
With this function I am able to get the right result for 1st Year But from the next year on-wards the user registration date will be same so it wont be calculating with 365 days.
I don’t know what to do. Please Help Me on this.
<?php
if (!function_exists('nopaymentmade')) {
function nopaymentmade($user_id) {
$blogusers = get_users('role=paid-membership');
// Array of WP_User objects.
foreach ($blogusers as $user) {
//$user->user_registered;
// $user_id=$user->ID;
$user->user_registered;
$user_id = $user->ID;
$user_login = $user->user_login;
$user_email = $user->user_email;
$devabirthdate = $user->user_registered;
/* input birthday date format -> Y-m-d */
list($y, $m, $d) = explode('-', $devabirthdate);
$nowdate = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
$nextbirthday = mktime(0, 0, 0, $m, $d, date("Y"));
if ($nextbirthday < $nowdate)
$nextbirthday = $nextbirthday + (60 * 60 * 24 * 365);
$daycount = intval(($nextbirthday - $nowdate) / (60 * 60 * 24));
//echo $daycount;
if ($daycount < 349) {
/* echo $user->user_registered;
echo "<br/>";
echo $user_id=$user->ID;
echo "<br/>";
echo $user_login=$user->user_login;
echo "<br/>";
echo $user_email=$user->user_email;
echo "<br/>"; */
$message = sprintf(__('your Account will be expired in next 15 days %s:'), get_option('blogname')) . "rnrn";
$message .= sprintf(__('Username: %s'), $user_login) . "rnrn";
$message .= sprintf(__('E-mail: %s'), $user_email) . "rn";
@wp_mail(
$user_email, sprintf(__('[%s] Account Expiration alert'), get_option('blogname')), $message
);
}
}
}
?>
A better approach.