public function task($offset = 0) { global $ym_sys; if (!$ym_sys->email_reminder_enable) { echo 'Not Enabled in YM SYS'; return; } $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : $offset; if (is_null($offset)) { $offset = 0; } if ($offset == -1) { // no pagination $offset = 0; $this->limit = null; } $this->limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : $this->limit; // use API Exposed Element for search $users = get_users(array('offset' => $offset, 'number' => $this->limit, 'meta_key' => 'ym_status', 'meta_value' => YM_STATUS_EXPIRED, 'meta_compare' => '!=')); $current_time = time(); // set to now + days so a future $limit_date = time() + $ym_sys->email_reminder_limit * 86400; $postarray = array(); //Drip Feed Email if ($ym_sys->email_drip_reminder_enable) { global $wpdb; //Get all posts $args = array('meta_key' => '_ym_account_min_duration', 'post_status' => 'publish'); $posts = get_posts($args); foreach ($posts as $post) { $drip = get_post_meta($post->ID, '_ym_account_min_duration', true); $new_array = array(); if ($drip) { $drip = explode(';', $drip); if ($drip) { foreach ($drip as $d) { $array = explode('=', $d); $new_array[$array[0]] = $array[1]; } } } $postarray[$post->ID] = array_filter($new_array); } $postarray = array_filter($postarray); } $total = count($users); if ($total) { $counter = 0; foreach ($users as $user) { $counter++; $user = new YourMember_User($user->ID); $expire_date = $user->expire_date; // user has expire date // user has not been sent a reminder // expire_date is less that the limit date // expire date is in the future if ($user->expire_date && !$user->reminder_email_sent && $user->expire_date < $limit_date && $user->expire_date > $current_time) { // lock $user->update(array('reminder_email_sent' => true), true); // send $subject = $ym_sys->email_reminder_subject; $message = $ym_sys->email_reminder_message; $pack = ym_get_pack_by_id($user->pack_id); if ($pack['num_cycles'] != 1) { // so 0 or many ie recurring $subject = $ym_sys->email_reminder_subject_recur; $message = $ym_sys->email_reminder_message_recur; } $subject = str_replace('[site_name]', get_bloginfo(), $subject); $message = ym_apply_filter_the_content($message); ym_email($user->data->user_email, $subject, $message); @ym_log_transaction(YM_USER_STATUS_UPDATE, __('Email Reminder Sent', 'ym'), $user->ID); do_action('ym_cron_email_reminder_sent', $user->ID); echo '1'; } else { echo '.'; } if (substr($counter, -1, 1) == '0') { echo ' ' . $counter . '/' . $total . "\n"; } $reminders = array(); foreach ($postarray as $post => $type) { foreach ($type as $ac_type => $days) { if ($ac_type == $act) { $reminders[$post] = array('post_id' => $post, 'days' => $days); } } } if ($reminders) { $users_reminders = unserialize(get_user_meta($user->ID, 'drip_email_reminders', true)); if (!$users_reminders || !is_array($users_reminders)) { $users_reminders = array(); } foreach ($reminders as $reminder) { if (!in_array($reminder['post_id'], $users_reminders)) { //The post ID is not marked as already sent so we may need to send it //need to determine if we should send it. $reg = $user->data->user_registered; if ($sys->post_delay_start == 'pack_join') { if ($pack_join = $user->account_type_join_date) { $reg = date('Y-m-d', $pack_join); } } $reg = mktime(0, 0, 0, substr($reg, 5, 2), substr($reg, 8, 2), substr($reg, 0, 4)); $user_at = $reg + 86400 * $reminder['days']; if ($user_at <= time() && $user_at >= time() - 86400 * 7) { //If the time is not in the future, and no older then 10 days, we should send an email //send email $subject = $ym_sys->email_drip_subject; $message = $ym_sys->email_drip_message; $subject = str_replace('[site_name]', get_bloginfo(), $subject); $message = ym_apply_filter_the_content($message); ym_email($target, $subject, $message); $users_reminders[] = $reminder['post_id']; @ym_log_transaction(USER_STATUS_UPDATE, __('Drip Content Email for post' . $reminder['post_id'], 'ym'), $user->ID); do_action('ym_cron_email_drip_sent', $user->ID, $reminder['post_id']); } } } update_user_meta($user->ID, 'drip_email_reminders', serialize($users_reminders)); } } echo ' ' . $counter . '/' . $total . "\n"; // loop echo 'Loop Complete From ' . $offset . "\n"; if ($this->call_type == 'auto') { if ($this->limit != NULL) { echo 'Schedule Next Step' . "\n"; wp_schedule_single_event(time(), 'ym_cron_email_reminder', array($offset + $this->limit)); } else { echo 'Full Call Occured' . "\n"; } } else { // reload echo 'Sleeping' . "\n"; echo '<form action="" method="post"><input type="hidden" name="run_cron_job" value="ym_cron_email_reminder" /><input type="hidden" name="offset" value="' . ($offset + $this->limit) . '" /></form>'; echo '<script type="text/javascript">jQuery(document).ready(function() { setTimeout(\'ym_fire()\', 5000) }); function ym_fire() { jQuery(\'form\').submit(); }</script>'; } } else { echo 'Nothing to do Job Complete' . "\n"; do_action('ym_cron_email_reminder_complete'); } }
<?php global $ym_formgen, $ym_res, $ym_sys, $wpdb, $allowed_extensions; global $current_user; get_currentuserinfo(); $target = $current_user->user_email; if (isset($_POST['send_test']) && !empty($_POST['send_test'])) { $ym_sys->email_reminder_subject = str_replace('[site_name]', get_bloginfo(), $ym_sys->email_reminder_subject); $message = ym_apply_filter_the_content($ym_sys->email_reminder_message); ym_email($target, $ym_sys->email_reminder_subject, $message); ym_display_message(__('Sent test Email Reminder test email to you', 'ym')); } if (isset($_POST['send_test_recur']) && !empty($_POST['send_test_recur'])) { $ym_sys->email_reminder_subject_recur = str_replace('[site_name]', get_bloginfo(), $ym_sys->email_reminder_subject_recur); $message = ym_apply_filter_the_content($ym_sys->email_reminder_message_recur); ym_email($target, $ym_sys->email_reminder_subject_recur, $message); ym_display_message(__('Sent test Email Reminder test email to you', 'ym')); } if (isset($_POST['settings_update']) && !empty($_POST['settings_update'])) { $ym_sys->update_from_post(); update_option('ym_sys', $ym_sys); ym_display_message(__('System Updated', 'ym')); } echo '<div class="wrap" id="poststuff">'; echo ym_box_top(__('Email Configuration', 'ym')); echo '<p>' . sprintf(__('These from settings will also be used for all YM initiated emails, instead of the WordPress default, normally wordpress@%s', 'ym'), $_SERVER['HTTP_HOST']) . '</p>'; echo '<form action="" method="post"> <table class="form-table">'; $ym_formgen->render_form_table_text_row(__('From Name', 'ym'), 'from_name', $ym_sys->from_name, __('Name of the sender (you or your site's name)', 'ym')); $ym_formgen->render_form_table_text_row(__('From Email', 'ym'), 'from_email', $ym_sys->from_email, __('The email address where site emails will come from', 'ym')); $ym_formgen->render_form_table_radio_row(__('All Emails', 'ym'), 'filter_all_emails', $ym_sys->filter_all_emails, __('Apply these filters to <strong>ALL</strong> Emails WordPress Sends', 'ym'));