function s2member_eot($user_id = 0, $check_gateway = true, $favor = 'fixed') { return c_ws_plugin__s2member_utils_users::get_user_eot($user_id, $check_gateway, $favor); }
/** * Handles the Shortcode for: `[s2Eot /]`. * * @package s2Member\s2Eot * @since 150713 * * @attaches-to ``add_shortcode('s2Eot');`` * * @param array $attr An array of Attributes. * @param string $content Content inside the Shortcode. * @param string $shortcode The actual Shortcode name itself. * * @return string Value of the requested data. */ public static function sc_eot_details($attr = array(), $content = '', $shortcode = '') { foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_before_sc_eot_details', get_defined_vars()); unset($__refs, $__v); // Allow variables to be modified by reference. c_ws_plugin__s2member_no_cache::no_cache_constants(true); $mode = ''; // Initialize shortcode mode and validate. if (!empty($attr['mode']) && in_array(strtolower($attr['mode']), array('fixed', 'next'), TRUE)) { $mode = strtolower($attr['mode']); } // A specific mode; i.e., `fixed`, `next`. if (empty($attr['user_id']) || !(int) $attr['user_id']) { $attr['user_id'] = $user_id = get_current_user_id(); } else { $user_id = (int) $attr['user_id']; } $subscr_gateway = get_user_option('s2member_subscr_gateway', $user_id); $subscr_id = get_user_option('s2member_subscr_id', $user_id); $subscr_cid = get_user_option('s2member_subscr_cid', $user_id); $auto_eot_time = get_user_option('s2member_auto_eot_time', $user_id); $attr = shortcode_atts(array('debug' => 'no', 'user_id' => '0', 'date_format' => 'M jS, Y, g:i a T', 'round_to' => '', 'offset' => '0', 'timezone' => '', 'future_format' => $mode ? '%%date%%' : '<strong class="s2member-sc-eot-label -future">' . _x('Access Expires:', 's2member-front', 's2member') . '</strong> <span class="s2member-sc-eot-date -future">%%date%%</span>', 'past_format' => $mode ? '%%date%%' : '<strong class="s2member-sc-eot-label -past">' . _x('Access Expired:', 's2member-front', 's2member') . '</strong> <span class="s2member-sc-eot-date -past">%%date%%</span>', 'next_format' => $mode ? '%%date%%' : '<strong class="s2member-sc-eot-label -next">' . _x('Next Payment:', 's2member-front', 's2member') . '</strong> <span class="s2member-sc-eot-date -next">%%date%%</span>', 'empty_format' => $mode ? in_array($subscr_gateway, array('stripe', 'paypal', 'clickbank'), TRUE) ? _x('N/A', 's2member-front', 's2member') : _x('—', 's2member-front', 's2member') : ''), c_ws_plugin__s2member_utils_strings::trim_qts_deep((array) $attr)); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_before_sc_eot_details_after_shortcode_atts', get_defined_vars()); unset($__refs, $__v); // Allow variables to be modified by reference. // Collect and cache the EOT for this user. $prefix = 's2m_eot_'; // Transient prefix for this shortcode. $hash_vars = $user_id . $subscr_gateway . $subscr_id . $subscr_cid . $auto_eot_time; $transient = $prefix . md5('s2member_sc_eot_' . $mode . serialize($attr) . $hash_vars); if (!is_array($eot = get_transient($transient))) { $eot = c_ws_plugin__s2member_utils_users::get_user_eot($user_id, true, $mode); set_transient($transient, $eot, DAY_IN_SECONDS / 2); } if ($eot['time'] && (int) $attr['offset']) { $eot['time'] = $eot['time'] + (int) $attr['offset']; } // Initialize EOT details/output format. if ($eot['type'] === 'fixed' && $eot['time'] && $eot['tense'] === 'past') { $details = $attr['past_format']; } else { if ($eot['type'] === 'fixed' && $eot['time'] && $eot['tense'] === 'future') { $details = $attr['future_format']; } else { if ($eot['type'] === 'next' && $eot['time'] && $eot['tense'] === 'future') { $details = $attr['next_format']; } else { $details = $attr['empty_format']; } } } // Initialize EOT details/output date format. $time = null; // Initialize the time calculation. if ($eot['time']) { $time = new DateTime(date('Y-m-d H:i:s', $eot['time'])); if ($attr['timezone'] && strtoupper($attr['timezone']) !== 'UTC') { $time->setTimezone(new DateTimeZone($attr['timezone'])); } if ($attr['round_to']) { $time->modify($attr['round_to']); } } if ($time && $attr['date_format'] === 'timestamp') { $date = (string) $time->getTimestamp(); } else { if ($time && $attr['date_format'] === 'default') { $date = $time->format(get_option('date_format')); } else { if ($time && $attr['date_format']) { $date = $time->format($attr['date_format']); } else { if ($time) { // Default date/time format. $date = $time->format('M jS, Y, g:i a T'); } else { $date = ''; } } } } // Default date; i.e., nothing. $details = str_ireplace('%%date%%', esc_html($date), $details); // Check special considerations and the current mode. if ($eot['type'] === 'fixed' && !$GLOBALS['WS_PLUGIN__']['s2member']['o']['auto_eot_system_enabled']) { $details = $attr['empty_format']; // EOTs are disabled on this site. $eot['debug'] = 's2Member\'s Auto-EOT System is disabled on this site.'; } else { if ($eot['type'] === 'fixed' && $mode === 'next') { $details = $attr['empty_format']; // Empty this. $eot['debug'] = 'No fixed EOT time was found for this user.'; } else { if ($eot['type'] === 'next' && $mode === 'fixed') { $details = $attr['empty_format']; // Empty this. $eot['debug'] = 'No more payments needed from this user.'; } } } // Wrapper and debug info... if ($details) { // Wrapper for CSS styling. $details = '<span class="ws-plugin--s2member-sc-eot">' . $details . '</span>'; } if (filter_var($attr['debug'], FILTER_VALIDATE_BOOLEAN)) { $details .= '<pre>' . esc_html($eot['debug'] ? $eot['debug'] : 'Unknown error.') . '</pre>'; } // Return the details/output from this shortcode. return apply_filters('ws_plugin__s2member_sc_eot_details', $details, get_defined_vars()); }
/** * Remind. * * @since 151202 Reminders. * * @attaches-to ``add_action('ws_plugin__s2member_after_auto_eot_system');`` * * @param array $vars Expects an array of defined variables. */ public static function remind($vars = array()) { global $wpdb; // WP database class. $options =& $GLOBALS['WS_PLUGIN__']['s2member']['o']; if (!$options['pro_eot_reminder_email_enable']) { return; // Nothing to do here. } if (!isset($options['pro_eot_reminder_email_days'][0])) { return; // Nothing to do here. } self::$now = time(); // Current UTC timestamp. self::$recipients = json_decode($options['pro_eot_reminder_email_recipients']); self::$subject = json_decode($options['pro_eot_reminder_email_subject']); self::$message = json_decode($options['pro_eot_reminder_email_message']); if (!is_object(self::$recipients) || !is_object(self::$subject) || !is_object(self::$message)) { return; // Not possible. Possible corruption in the DB. } if (!$GLOBALS['WS_PLUGIN__']['s2member']['o']['reg_email_from_name'] || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['reg_email_from_email']) { return; // Not possible. Email configuration is incomplete. } $days = preg_split('/[;,\\s]+/', trim($options['pro_eot_reminder_email_days']), -1, PREG_SPLIT_NO_EMPTY); $scan_time = apply_filters('ws_plugin__s2member_pro_eot_reminders_scan_time', strtotime('-1 day', self::$now), get_defined_vars()); $per_process = apply_filters('ws_plugin__s2member_pro_eot_reminders_per_process', $vars['per_process'], get_defined_vars()); $message_bytes_in_log = apply_filters('ws_plugin__s2member_pro_eot_reminder_email_message_bytes_in_log', 100); $mail_from = '"' . str_replace('"', "'", $GLOBALS['WS_PLUGIN__']['s2member']['o']['reg_email_from_name']) . '"' . ' <' . $GLOBALS['WS_PLUGIN__']['s2member']['o']['reg_email_from_email'] . '>'; $user_ids_to_exclude = ' SELECT DISTINCT `user_id` AS `ID` FROM `' . $wpdb->usermeta . '` WHERE (`meta_key` = \'' . $wpdb->prefix . 's2member_last_reminder_scan\' AND `meta_value` >= \'' . esc_sql($scan_time) . '\') OR (`meta_key` = \'' . $wpdb->prefix . 's2member_reminders_enable\' AND `meta_value` = \'0\') '; $additional_user_ids_to_exclude = apply_filters('ws_plugin__s2member_pro_eot_reminders_exclude_user_ids', array(), get_defined_vars()); $sql = ' SELECT DISTINCT `user_id` AS `ID` FROM `' . $wpdb->usermeta . '` WHERE `user_id` NOT IN(' . $user_ids_to_exclude . ') ' . ($additional_user_ids_to_exclude ? 'AND `user_id` NOT IN(\'' . implode("','", $additional_user_ids_to_exclude) . '\')' : '') . ' AND ( (`meta_key` = \'' . $wpdb->prefix . 's2member_subscr_gateway\' AND `meta_value` != \'\') OR (`meta_key` = \'' . $wpdb->prefix . 's2member_auto_eot_time\' AND `meta_value` != \'\') OR (`meta_key` = \'' . $wpdb->prefix . 's2member_last_auto_eot_time\' AND `meta_value` != \'\') ) LIMIT ' . esc_sql($per_process) . ' '; if (!($user_ids = $wpdb->get_col($sql))) { return; // Nothing to do here. } $email_configs_were_on = c_ws_plugin__s2member_email_configs::email_config_status(); c_ws_plugin__s2member_email_configs::email_config(); foreach ($user_ids as $_user_id) { $_eot = $_day = $_recipients = $_subject = $_message = null; if (!($_user = new WP_User($_user_id)) || !$_user->ID) { continue; // Possible DB corruption. } update_user_option($_user->ID, 's2member_last_reminder_scan', self::$now); $_eot = c_ws_plugin__s2member_utils_users::get_user_eot($_user->ID); if (!$_eot || !$_eot['type'] || !$_eot['time'] || !$_eot['tense']) { continue; // Nothing to do; i.e., no EOT or NPT time. } elseif ($_eot['type'] === 'next' && !$options['pro_eot_reminder_email_on_npt_also']) { continue; // Nothing to do; i.e., not an EOT time and no NPTs. } elseif (!($_day = self::calculate_day($_eot['time'])) && $_day !== '0') { continue; // Unable to calculate day. } elseif (!in_array($_day, $days, true)) { continue; // Nothing on this day. } elseif (!($_recipients = self::get_recipients_for_day($_day))) { continue; // No recipients. } elseif (!($_subject = self::get_subject_for_day($_day))) { continue; // No subject. } elseif (!($_message = self::get_message_for_day($_day))) { continue; // No message. } // self::fill_replacement_codes($_user, $_eot, $_recipients, $_subject, $_message); $_mail_from = apply_filters('ws_plugin__s2member_pro_eot_reminder_email_from', $mail_from, get_defined_vars()); $_recipients = apply_filters('ws_plugin__s2member_pro_eot_reminder_email_recipients', $_recipients, get_defined_vars()); $_subject = apply_filters('ws_plugin__s2member_pro_eot_reminder_email_subject', $_subject, get_defined_vars()); $_message = apply_filters('ws_plugin__s2member_pro_eot_reminder_email_message', $_message, get_defined_vars()); if (!$_recipients || !$_subject || !$_message || !$_mail_from) { continue; // Final validation must not fail. } foreach (c_ws_plugin__s2member_utils_strings::parse_emails($_recipients) as $_recipient) { wp_mail($_recipient, $_subject, $_message, 'From: ' . $_mail_from . "\r\n" . 'Content-Type: text/plain; charset=utf-8'); $_log_entry = array('eot' => $_eot, 'eot_rfc822' => date(DATE_RFC822, $_eot['time']), 'day' => $_day, 'now' => self::$now, 'user_id' => $_user->ID, 'user_login' => $_user->user_login, 'user_email' => $_user->user_email, 'user_first_name' => $_user->first_name, 'user_last_name' => $_user->last_name, 'mail_from' => $_mail_from, 'recipient' => $_recipient, 'subject' => $_subject); if (strlen($_message) > $message_bytes_in_log) { $_log_entry['message_clip'] = substr($_message, 0, $message_bytes_in_log) . '...'; } else { $_log_entry['message'] = $_message; // Full message. } c_ws_plugin__s2member_utils_logs::log_entry('eot-reminders', $_log_entry); } } unset($_user_id, $_user, $_eot, $_day, $_mail_from, $_recipients, $_recipient, $_subject, $_message, $_log_entry); if (!$email_configs_were_on) { c_ws_plugin__s2member_email_configs::email_config_release(); } }