I want to create a wordpress user registration function so that both user and admin should get email alert after every year

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.

Read More

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
                            );
                        }
                    }
                }

?>

Related posts

1 comment

  1. A better approach.

    • Make sure your cron runs once every day.
    • Always store the next birthday in the usermeta , so that for every user you can check the same meta key for the value and make sure when the cron runs and when conditions become true your update the next birthday after sending the mail.
      • In the above statement the condition I am talking about will include condition to check that is current date with 15 days difference to the next birthday which is stored in usermeta.

Comments are closed.