function alo_em_ajax_recipient_list_ajaxloop() { global $user_ID; check_ajax_referer("alo-easymail"); $response = array(); $response['error'] = ''; if (isset($_POST['newsletter'])) { $newsletter = (int) $_POST['newsletter']; if (get_post_type($newsletter) != "newsletter") { $response['error'] = esc_js(__('The required newsletter does not exist', "alo-easymail")); } if (!get_post($newsletter)) { $response['error'] = esc_js(__('The required newsletter does not exist', "alo-easymail")); } if (!alo_em_user_can_edit_newsletter($newsletter)) { $response['error'] = esc_js(__('Cheatin’ uh?')); } $post_status = get_post_status($newsletter); if ($post_status == "draft" || $post_status == "pending") { $response['error'] = esc_js(__('A newsletter cannot be sent if its status is draft or pending review')); } } else { $response['error'] = esc_js(__('Cheatin’ uh?')); } if ($response['error'] == '') { // If missing prepare cache if (!alo_em_get_cache_recipients($newsletter)) { alo_em_create_cache_recipients($newsletter); } else { // Now add a part of recipients into the db table $sendnow = isset($_POST['sendnow']) && $_POST['sendnow'] == "yes" ? true : false; $limit = apply_filters('alo_easymail_ajaxloop_recipient_limit', 15); // Hook alo_em_add_recipients_from_cache_to_db($newsletter, $limit, $sendnow); } $response['n_done'] = alo_em_count_newsletter_recipients($newsletter); $response['n_tot'] = alo_em_count_recipients_from_meta($newsletter); $response['perc'] = $response['n_done'] > 0 && $response['n_tot'] > 0 ? round($response['n_done'] * 100 / $response['n_tot']) : 0; } header("Content-Type: application/json"); die(json_encode($response)); }
<?php // If archived if ($archived_raw = alo_em_is_newsletter_recipients_archived($newsletter)) { $archived_meta = $archived_raw[0]; $tot_recipients = $archived_meta['tot']; $already_sent = $archived_meta['sent']; $sent_with_success = $archived_meta['success']; $sent_with_error = $archived_meta['error']; $unique_views = $archived_meta['uniqview']; $unique_clicks = $archived_meta['uniqclick']; // If regular, not archived } else { // List of recipients, paged $recipients = alo_em_get_newsletter_recipients($newsletter, false, $offset, $per_page); // Total number of recipients $tot_recipients = alo_em_count_newsletter_recipients($newsletter); // Other info $already_sent = alo_em_count_newsletter_recipients_already_sent($newsletter); $sent_with_success = alo_em_count_newsletter_recipients_already_sent_with_success($newsletter); $sent_with_error = alo_em_count_newsletter_recipients_already_sent_with_error($newsletter); $unique_views = count(alo_em_all_newsletter_trackings($newsletter, '')); $unique_clicks = count(alo_em_all_newsletter_trackings_except_views($newsletter)); } ?> <?php // Archive (delete) detailed info of recipients if (isset($_GET['archive']) && alo_em_get_newsletter_status($newsletter) == "sent") { $archived_recipients = array('tot' => $tot_recipients, 'sent' => $already_sent, 'success' => $sent_with_success, 'error' => $sent_with_error, 'uniqview' => $unique_views, 'uniqclick' => $unique_clicks); add_post_meta($newsletter, "_easymail_archived_recipients", $archived_recipients);