If you're looking for a way to notify users their EOT date is coming up, or that they have reached their EOT date, this can be done fairly easily with a few lines of code and the use of the WordPress function
wp_schedule_event(). The following can be done within a Must-Use Plugin, or mu-plugin. If you don't have a /wp-content/mu-plugins/ directory, create it. I called my mu-plugin s2hack_eot_notify.php.
Depending on what functionality you're looking for, this hack takes either 1 or 2 steps. If you're looking to notify users of an upcoming EOT date, you need to check out the functions outlined below. One of the below functions sets the EOT Notification date, and the other tells users when they are getting close to their EOT through the EOT Notification date.
If you're looking to simply send an email, or notify the user when they have reached their EOT date, the approach is much simpler.
Notify Users of an Upcoming EOT Date
When notifying users of an upcoming EOT date, you need to set up 2 functions to get this functionality. The first being a way to add a User Meta
value for each user that has an EOT date based on the s2Member user meta value
These functions (which we have named
s2hack_eot_notify()) hook into two WordPress functionalities which are the
wp_loaded hook and
wp_schedule_event / WP_Cron functionality.
Set Notification Timestamp
After we've created our Must Use plugin, the first function we want to create is
s2hack_eot_notify_set(). This function will set a user meta value called
s2_eot_notify_date which houses a timestamp. This function uses the wp_loaded hook which fires every time WordPress loads. Because this will be fired every time WordPress loads we want to make sure to waste as little memory as possible.
This version of this function sets up the Notification EOT date as 1 week before s2Member Automatically demotes/deletes the member. If you'd like to change the amount of time the user has, you can change the variable
global $current_user, $wpdb;
$time_to_sub = 604800; # 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
if(!wp_next_scheduled('s2hack_eot_notify') && $GLOBALS['WS_PLUGIN__']['s2member']['o']['auto_eot_system_enabled'])
wp_schedule_event(current_time('timestamp'), 'daily', 's2hack_eot_notify');
Set Up the Notification Function
After we've set up the Notification EOT Times, we can then use these times to Notify Users. Within the above function we also set up a WP_Cron event. We'll use this event to notify users (Notice that this function doesn't do anything really other than delete the User Meta value as of yet. You can use wp_mail() within this function to notify users):
if(has_action('s2hack_eot_notify')) # Add action only if it exists
function s2hack_eot_notification() # Function to be called daily
$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
* Here is where you would notify users of their EOT
* Suggest using wp_mail() link: http://codex.wordpress.org/Function_Reference/wp_mail
* User's details available through $user
* $user object WP_User link: http://codex.wordpress.org/Class_Reference/WP_User_Query
Tip: These functions are only to point you in the right direction. These functions as they are now will not function correctly. If you cannot set up your notifications, we recommend getting a Freelance developer to help you out, or creating a Forum topic (or both!). :-)
Notify Users They Have Reached their EOT Date
Notifying users when they reach their EOT date is much simpler. The way you would need to do this is to simply hook into the s2Member action hook
the variables s2Member was using:
user_firstname.' '.$user->last_name.'" user_email.'>';
$message = 'Uh-oh! You ran out of time! You were demoted from '.$existing_role.' to '.$demotion_role.'.';
wp_mail($to, $subject, $message, $headers);
Tip: this function is only meant to point you in the right direction. You still need to change this function to suit your WordPress installation. If you cannot set up your notifications, we recommend getting a Freelance developer to help you out, or creating a Forum topic (or both!). :-)