1

I'd like to set a cron job on my server to run an automated script that would tell Wordpress to:

  • Check the users that have signed-up but not logged-in in the last 2 hours.
  • Resend the welcome email to only the users who signed-up in the last 2 hours.
  • On the next cron job it will ignore the users which have already been sent another welcome email in the previous cron runs - you could even delete the users who haven't logged-in within the 2 hour limit if that's easier.

Really appreciate some advice or pointers on how to set this up. I've been searching the net for an answer to no avail. Hopefully someone can help.

0

wp_users table has user_registered and user_activation_key field that you should use for this.

For the cron job, you should use wp_schedule_event(). It has one disadvantage though.

The action will trigger when someone visits your WordPress site, if the scheduled time has passed.

For a busy site that's not a problem. But if your site doesn't have any visitor for 2 hours, then that cron task won't trigger. There isn't anything that you can do about it if you need to use wordpress cron job.

In your cron function, you need to query for the users who have registered, but account didn't activated in the last 2 hours with the help of those two fields.

EDIT:

You can check for users who have registered, but didn't activate their account in the last hour with the following code -

global $wpdb;
$users = $wpdb->select_results("SELECT * FROM $wpdb->users
                               WHERE user_activation_key = ''
                                 AND user_registered >= NOW() - INTERVAL 2 HOUR"
                               );
foreach( $users as $user ) {
    //Send activation mail
}

If you need help with email template, you have to ask the plugin author in Wordpress forum support. Plugin support is off topic here.

  • Thanks for the pointer. I don't suppose you could give me a code example of how to achieve checking these users and then resending the email in my functions.php file? I'd also like to use a custom HTML email for the welcome email, which I know 'SB Welcome Email' plugin can achieve. – user1249523 Aug 19 '14 at 22:29
  • @user1249523 See the edit. – sakibmoon Aug 20 '14 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.