/** * AJAX send test email */ public static function send_test_email() { $_POST = array_map('stripslashes_deep', $_POST); $id = absint($_POST['id']); $recipient = sanitize_email($_POST['email']); $email = new FUE_Email($id); $subject = isset($_POST['subject']) ? $_POST['subject'] : $email->subject; $message = $_POST['message']; $order_id = isset($_POST['order_id']) ? $_POST['order_id'] : ''; $product_id = isset($_POST['product_id']) ? $_POST['product_id'] : ''; $email_data = array('test' => true, 'username' => 'jdoe', 'first_name' => 'John', 'last_name' => 'Doe', 'cname' => 'John Doe', 'user_id' => '0', 'order_id' => $order_id, 'product_id' => $product_id, 'email_to' => $recipient, 'tracking_code' => $email->tracking_code, 'store_url' => home_url(), 'store_url_secure' => home_url(null, 'https'), 'store_name' => get_bloginfo('name'), 'unsubscribe' => fue_get_unsubscribe_url(), 'subject' => $subject, 'message' => $message, 'meta' => array()); Follow_Up_Emails::instance()->mailer->send_test_email($email_data, $email); }
/** * Process unsubscribe request. Add the submitted email address to the Excluded Emails list */ public static function process_unsubscribe_request() { global $wpdb; if (isset($_POST['fue_action']) && $_POST['fue_action'] == 'fue_unsubscribe') { $email = str_replace(' ', '+', $_POST['fue_email']); $email_id = $_POST['fue_eid']; $error = ''; if (empty($email) || !is_email($email)) { $error = urlencode(__('Please enter a valid email address', 'follow_up_emails')); } $order_id = !empty($_POST['unsubscribe_order_id']) ? absint($_POST['unsubscribe_order_id']) : 0; $unsubscribe = !empty($_POST['unsubscribe_all']) && $_POST['unsubscribe_all'] == 'yes' ? true : false; if (fue_is_email_excluded($email, 0, $order_id)) { if ($order_id > 0) { $error = sprintf(__('The email (%s) is already unsubscribed from receiving emails regarding Order %d', 'follow_up_emails'), $email, $order_id); } else { $error = sprintf(__('The email (%s) is already unsubscribed from receiving emails', 'follow_up_emails'), $email); } } if (!empty($error)) { $url = add_query_arg(array('fueid' => $_POST['fue_eid'], 'qid' => !empty($_POST['fue_qid']) ? $_POST['fue_qid'] : '', 'error' => urlencode($error)), fue_get_unsubscribe_url()); wp_redirect($url); exit; } if ($unsubscribe) { fue_exclude_email_address($email, $email_id, 0); if (isset($_GET['fue'])) { do_action('fue_user_unsubscribed', $_GET['fue']); } } elseif ($order_id > 0) { fue_exclude_email_address($email, $email_id, $order_id); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}followup_email_orders WHERE user_email = %s AND order_id = %d AND is_sent = 0", $email, $order_id)); } wp_redirect(add_query_arg('fue_unsubscribed', 1, Follow_Up_Emails::get_account_url())); exit; } elseif (isset($_GET['fue_unsubscribed'])) { Follow_Up_Emails::show_message(__('Thank you. Your email settings have been saved.', 'follow_up_emails')); } }
/** * Add manual emails to the email queue * * $args keys: * email_id - ID of FUE_Email * recipients - Array of recipients ( format: [ [user_id, user_email, user_name] ] ) * subject - Email Subject * message - Email Message * tracking - Analytics tracking code (e.g. ?utm_campaign=xxx) * send_again - Whether or not to send another email after a specific interval (bool) * interval - If send_again is true, the time to wait before sending the next email (int) * interval_duration - If send_again is true, the duration type of interval (e.g. minutes/hours/weeks/months) * * @param array $args * @return array Array of Queue Item IDs created */ public static function queue_manual_emails($args = array()) { ignore_user_abort(true); set_time_limit(0); $item_ids = array(); $args = wp_parse_args($args, array('email_id' => 0, 'recipients' => array(), 'subject' => '', 'message' => '', 'tracking' => '', 'schedule_email' => false, 'schedule_date' => '', 'schedule_hour' => '', 'schedule_minute' => '', 'schedule_ampm' => '', 'send_again' => false, 'interval' => '', 'interval_duration' => '')); extract($args); if (empty($recipients)) { return; } // process variable replacements $codes = array(); if (!empty($tracking)) { parse_str($tracking, $codes); foreach ($codes as $key => $val) { $codes[$key] = urlencode($val); } } $store_url = home_url(); $store_name = get_bloginfo('name'); $orig_message = $message; $orig_subject = $subject; $recipient_num = 0; $send_time = current_time('timestamp'); $email = new FUE_Email($email_id); $email_batch_enabled = get_option('fue_email_batches', 0); $emails_per_batch = get_option('fue_emails_per_batch', 100); $email_batch_interval = get_option('fue_batch_interval', 10); $schedule_emails = false; // figure out the sending schedule if ($schedule_email) { $send_time = strtotime($schedule_date . ' ' . $schedule_hour . ':' . $schedule_minute . ' ' . $schedule_ampm); $schedule_emails = true; } // if splitting emails into batches is enabled and more than one // batch is going to be queued, schedule the emails if ($email_batch_enabled && count($recipients) > $emails_per_batch) { $schedule_emails = true; } foreach ($recipients as $recipient) { $recipient_num++; // determine when to send this email if (1 == $email_batch_enabled) { if ($recipient_num == $emails_per_batch) { $send_time += $email_batch_interval * 60; $recipient_num = 0; } } // create an email order $user_id = $recipient[0]; $email_address = $recipient[1]; $user_name = $recipient[2]; $unsubscribe = add_query_arg('fue', $email_address, fue_get_unsubscribe_url()); $_message = $orig_message; $_subject = $orig_subject; $meta = array('recipient' => $recipient, 'user_id' => $recipient[0], 'email_address' => $recipient[1], 'user_name' => $recipient[2], 'subject' => $_subject, 'message' => $_message, 'codes' => $codes); $insert = array('user_id' => $user_id, 'email_id' => $email_id, 'user_email' => $email_address, 'send_on' => $send_time, 'email_trigger' => 'Manual Email', 'meta' => $meta); $queue_id = FUE_Sending_Scheduler::queue_email($insert, $email, $schedule_emails); if (!is_wp_error($queue_id)) { $item_ids[] = $queue_id; } if ($send_again && !empty($interval) && $interval > 0) { $add = FUE_Sending_Scheduler::get_time_to_add($interval, $interval_duration); // create an email order $email_data = array('user_id' => $user_id, 'email_id' => $email_id, 'user_email' => $email_address, 'send_on' => $send_time + $add, 'email_trigger' => 'Manual Email', 'meta' => serialize($meta)); $queue_id = FUE_Sending_Scheduler::queue_email($email_data, $email, true); if (!is_wp_error($queue_id)) { $item_ids[] = $queue_id; } } } return $item_ids; }
/** * Get the URL of the unsubscribe page * * @return bool|string */ private function get_unsubscribe_page_url() { return fue_get_unsubscribe_url(); }