function alo_em_save_profile_optin($user_id) { if (!current_user_can('edit_user', $user_id)) { return false; } $user_info = get_userdata($user_id); $user_email = $user_info->user_email; if (isset($_POST['alo_easymail_option'])) { if ($_POST['alo_easymail_option'] == "yes") { // if changed name and lastname if (isset($_POST['first_name']) && $user_info->first_name != $_POST['first_name']) { $user_first_name = stripslashes(trim($_POST['first_name'])); } else { $user_first_name = $user_info->first_name; } if (isset($_POST['last_name']) && $user_info->last_name != $_POST['last_name']) { $user_last_name = stripslashes(trim($_POST['last_name'])); } else { $user_last_name = $user_info->last_name; } $fullname = $user_first_name . " " . $user_last_name; // if changed email if (isset($_POST['email']) && is_email($_POST['email']) && $user_email != $_POST['email']) { $user_email = stripslashes(trim($_POST['email'])); } $fields = array(); //edit : added all this foreach $alo_em_cf = alo_easymail_get_custom_fields(); if ($alo_em_cf) { foreach ($alo_em_cf as $key => $value) { //check if custom fields have been changed if (isset($_POST["alo_em_" . $key])) { $fields[$key] = stripslashes(trim($_POST["alo_em_" . $key])); } } } // Is already subscriber? update or insert $todo_update = alo_em_is_subscriber($user_info->user_email) > 0 ? true : false; if ($todo_update) { //alo_em_update_subscriber_by_email ( $user_info->user_email, $user_email, $fullname, 1, alo_em_get_language(true) ); //$fields['old_email'] = $user_info->user_email; //edit : added all this line $fields['email'] = $user_email; //edit : added all this line $fields['name'] = $fullname; //edit : added all this line if (alo_em_update_subscriber_by_email($user_info->user_email, $fields, 1, alo_em_get_language(true))) { //edit : orig : if ( alo_em_update_subscriber_by_email ( $user_info->user_email, $user_email, $fullname, 1, alo_em_get_language(true) ) ) { $subscriber = alo_em_get_subscriber($user_email); alo_em_update_subscriber_last_act($user_email); do_action('alo_easymail_subscriber_updated', $subscriber, $user_info->user_email); } } else { $fields['email'] = $user_email; //edit : added all this line $fields['name'] = $fullname; //edit : added all this line alo_em_add_subscriber($fields, 1, alo_em_get_language(true)); //edit : orig: alo_em_add_subscriber( $user_email, $fullname, 1, alo_em_get_language(true) ); do_action('alo_easymail_new_subscriber_added', alo_em_is_subscriber($user_email), $user_id); } // if subscribing, save also lists $mailinglists = alo_em_get_mailinglists('public'); if ($mailinglists) { $subscriber_id = alo_em_is_subscriber($user_email); foreach ($mailinglists as $mailinglist => $val) { if (isset($_POST['alo_em_profile_lists']) && is_array($_POST['alo_em_profile_lists']) && in_array($mailinglist, $_POST['alo_em_profile_lists'])) { alo_em_add_subscriber_to_list($subscriber_id, $mailinglist); // add to list } else { alo_em_delete_subscriber_from_list($subscriber_id, $mailinglist); // remove from list } } } } else { alo_em_delete_subscriber_by_id(alo_em_is_subscriber($user_email)); alo_em_add_email_in_unsubscribed($user_email); } } }
function alo_em_handle_bounces($report = false) { global $wpdb; $output = ''; $bounce_settings = alo_em_bounce_settings(); $conn = alo_em_bounce_connect(); if (!$conn) { return FALSE; } $num_msgs = imap_num_msg($conn); // start bounce class require_once 'inc/bouncehandler/bounce_driver.class.php'; $bouncehandler = new Bouncehandler(); // get the failures $email_addresses = array(); $delete_addresses = array(); $max_msgs = min($num_msgs, $bounce_settings['bounce_maxmsg']); if ($report) { $output .= 'Bounces handled in: ' . $bounce_settings['bounce_email']; } for ($n = 1; $n <= $max_msgs; $n++) { $msg_headers = imap_fetchheader($conn, $n); $msg_body = imap_body($conn, $n); $bounce = $msg_headers . $msg_body; //entire message $multiArray = $bouncehandler->get_the_facts($bounce); if (!empty($multiArray[0]['action']) && !empty($multiArray[0]['status']) && !empty($multiArray[0]['recipient'])) { if ($report) { $output .= '<br /> - MSG #' . $n . ' - Bounce response: ' . $multiArray[0]['action']; } // If delivery permanently failed, unsubscribe if ($multiArray[0]['action'] == 'failed') { $email = trim($multiArray[0]['recipient']); // Unsubscribe email address if ($s_id = alo_em_is_subscriber($email)) { alo_em_delete_subscriber_by_id($s_id); do_action('alo_easymail_bounce_email_unsubscribed', $email); // Hook if ($report) { $output .= ' - ' . $email . ' UNSUBSCRIBED'; } } } // If delivery temporary or permanently failed, mark recipient as bounced if ($multiArray[0]['action'] == 'failed' || $multiArray[0]['action'] == 'transient' || $multiArray[0]['action'] == 'autoreply') { // TODO maybe use: $bouncehandler->x_header_search_1 = 'ALO-EM-Newsletter'; // Look fo EasyMail custom headers: Newsletter and Recipient // NOTE: searching in body because IDs are inside original message included in body $newsletter_id = 0; $recipient_id = 0; if (preg_match('/X-ALO-EM-Newsletter: (\\d+)/i', $bounce, $matches)) { if (!empty($matches[1]) && is_numeric($matches[1])) { $newsletter_id = (int) $matches[1]; } } if (preg_match('/X-ALO-EM-Recipient: (\\d+)/i', $bounce, $matches)) { if (!empty($matches[1]) && is_numeric($matches[1])) { $recipient_id = (int) $matches[1]; } } // Mark recipient as bounced only if not a debug to author if ($newsletter_id > 0 && $recipient_id > 0 && strpos($msg_headers, "( DEBUG - TO: ") === false) { $wpdb->update("{$wpdb->prefix}easymail_recipients", array('result' => -3), array('ID' => $recipient_id, 'newsletter' => $newsletter_id, 'email' => $email)); } if ($report) { $output .= ' - Recipient ID #' . $recipient_id . ' marked as not delivered'; } // mark msg for deletion imap_delete($conn, $n); } } else { if ($report) { $output .= '<br /><span class="description"> - MSG #' . $n . ' - Not a bounce</span>'; } } } //for loop // delete messages imap_expunge($conn); // close imap_close($conn); if ($report) { return $output; } }