Skip to content

Instantly share code, notes, and snippets.

@sethetter
Created July 1, 2015 00:11
Show Gist options
  • Save sethetter/420a7234be1ebd91a29b to your computer and use it in GitHub Desktop.
Save sethetter/420a7234be1ebd91a29b to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Renewal Reminder
* Plugin URI: http://www.sethetter.com
* Description: Sends email reminders for members to renew memberships 30 days in advanced and when it has expired.
* Version: 0.0.0
* Author: Seth Etter
* Author URI: http://www.sethetter.com
* License: GPL2
*/
register_activation_hook(__FILE__, 'rr_activate_reminders');
register_deactivation_hook(__FILE__, 'rr_deactivate_reminders');
add_action('check_for_renewal_reminders', 'rr_perform_renewal_reminder_check');
add_action('plugins_loaded', 'rr_perform_renewal_reminder_check');
/**
* Function that checks for email reminders to be sent
*/
function rr_perform_renewal_reminder_check() {
$users = get_users('orderby=username');
foreach ($users as $user) {
// get user name, email and EOT date
$email = $user->user_email;
$headers = 'From: [email protected]';
$renewal_timestamp = get_user_meta($user->ID, 'wpag_s2member_auto_eot_time', true);
if (!$renewal_timestamp) continue;
$now_timestamp = time();
$days_to_expiration = floor(($now_timestamp - $renewal_timestamp) / (60 * 60 * 24));
if ($days_to_expiration == -30) {
// If 30 days from renewal date, send 30 days reminder email
$subject = 'Your membership expires in 30 days!';
$message = 'Just so you know, your G.A.N.G. membership expires in 30 days. You might want to renew it soon!';
wp_mail($email, $subject, $message, $headers);
}
if ($days_to_expiration == 0) {
// If on renewal date, send membership expired email
$subject = 'Your membership has expired!';
$message = 'Your G.A.N.G. membership has expired! You will need to renew to gain access to member features.';
wp_mail($email, $subject, $message, $headers);
}
}
}
function rr_activate_reminders() {
wp_schedule_event(time(), 'daily', 'check_for_renewal_reminders');
}
function rr_deactivate_reminders() {
wp_clear_scheduled_hook('check_for_renewal_reminders');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment