-
-
Save kristarella/bc75708b0b74c9b031aa to your computer and use it in GitHub Desktop.
Sends users an email to notify of upcoming renewal in s2member
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
<?php | |
/* | |
* Sends users an email to notify of upcoming renewal | |
* | |
*/ | |
add_action('wp', 'iart_eot_notify_set'); | |
function iart_eot_notify_set() { | |
global $current_user, $wpdb; | |
$time_to_sub = 1209600; # The amount to substract from s2Member's EOT time to get notification time. 604800 = 1 week | |
/**/ | |
if(!is_user_logged_in() || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['auto_eot_system_enabled']) # If the user isn't logged in, or the Automatic EOT system is disabled... | |
return; # ...we don't need to do anything | |
/* Otherwise... */ | |
if(($eot = get_user_meta($current_user->ID, $wpdb->prefix.'s2member_auto_eot_time', true)) && !($neot = get_user_meta($current_user->ID, 's2_eot_notify_date', true))): | |
$neot = $eot - $time_to_sub; | |
/**/ | |
if($neot > time()) # If the Notification EOT time is in the future | |
add_user_meta($current_user->ID, 's2_eot_notify_date', $neot); # Add the Notification EOT time | |
endif; | |
if($GLOBALS['WS_PLUGIN__']['s2member']['o']['auto_eot_system_enabled'] && !wp_next_scheduled('s2hack_eot_notify')) | |
wp_schedule_event(current_time('timestamp'), 'daily', 's2hack_eot_notify'); | |
} | |
add_action('s2hack_eot_notify', 'iart_eot_notification'); | |
function iart_eot_notification() { | |
$n_eot = time(); | |
if(is_array($eots = $wpdb->get_results("SELECT 'user_id' AS 'ID' FROM '".$wpdb->usermeta."' WHERE 'meta_key' = 's2_eot_notify_date' AND 'meta_value' != '' AND 'meta_value' <=". escape($n_eot)."' LIMIT 3"))): | |
foreach($eots as $eot): # We need to loop through all of the IDs to send the data | |
if(($user_id = $eot->ID) && is_object($user = new WP_User($user_id)) && $user->ID && !$user->has_cap('administrator')): # Set up variables | |
mail_user_eot($user_id); | |
delete_user_meta($user_id, 's2_eot_notify_date'); | |
endif; | |
endforeach; | |
endif; | |
} | |
function iart_mail_user_eot($user_id) { | |
$user = get_user_by('id',$user_id); | |
$email = $user->user_email; | |
$headers = 'From: Tim Strawn @ IART <tim@gssalliance.com>' . "\r\n"; | |
add_filter( 'wp_mail_content_type', 'iart_html_content_type' ); | |
$message = ' | |
<p>Dear '.$user->user_firstname.',</p> | |
<p><strong>Thank you</strong> for being a part of the IART community.<br /> | |
Your membership will be up for renewal within 2 weeks. This means that the annual IART membership fee needs to be paid for you to maintain access to our exclusive reviews, directories, and forums.</p> | |
<p>Please log in and renew your membership <a href="http://gssalliance.com/renew">on the IART website</a>. If you choose not to renew your account will be demoted to <em>Consumer</em> level, where you will have access to consumer-relevant articles.</p> | |
<p>In 2013 we changed the software that runs the IART website, which means that we now have the ability to accept PayPal subscriptions, so following an initial renewal in our new system your membership will auto-renew in future years.<br /> | |
You will be notified when your renewal is impending so that you have time to make any changes to your membership, if required.</p> | |
<p>Sincerly,<br /> | |
Tim & the IART team</p> | |
'; | |
remove_filter( 'wp_mail_content_type', 'iart_html_content_type' ); | |
wp_mail( $email, 'IART membership nearing renewal', $message, $headers ); | |
} | |
function iart_html_content_type() { | |
return 'text/html'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should try using the full name of the mail function in line 33, iart_mail_user_eot