data = $email; foreach ($email['options'] as $name => $value) { $controls->data['options_' . $name] = $value; } } // Always required $email = $module->get_email($_GET['id'], ARRAY_A); if (empty($email)) { echo 'Wrong email identifier'; return; } $email_id = $email['id']; /* Satus changes which require a reload */ if ($controls->is_action('pause')) { $wpdb->update(NEWSLETTER_EMAILS_TABLE, array('status' => 'paused'), array('id' => $email_id)); $email = $module->get_email($_GET['id'], ARRAY_A); tnp_prepare_controls($email, $controls); } if ($controls->is_action('continue')) { $wpdb->update(NEWSLETTER_EMAILS_TABLE, array('status' => 'sending'), array('id' => $email_id)); $email = $module->get_email($_GET['id'], ARRAY_A); tnp_prepare_controls($email, $controls); } if ($controls->is_action('abort')) { $wpdb->query("update " . NEWSLETTER_EMAILS_TABLE . " set last_id=0, sent=0, status='new' where id=" . $email_id); $email = $module->get_email($_GET['id'], ARRAY_A); tnp_prepare_controls($email, $controls); $controls->messages = __('Delivery definitively cancelled', 'newsletter'); } if ($controls->is_action('change-private')) { $data = array(); $data['private'] = $controls->data['private'] ? 1 : 0; $data['id'] = $email['id']; $email = Newsletter::instance()->save_email($data, ARRAY_A); $controls->add_message_saved(); tnp_prepare_controls($email, $controls); } $editor_type = $module->get_editor_type($email); // Backward compatibility: preferences conversion if (!$controls->is_action()) { if (!isset($email['options']['lists'])) { $options_profile = get_option('newsletter_profile'); if (empty($controls->data['preferences_status_operator'])) { $email['options']['lists_operator'] = 'or'; } else { $email['options']['lists_operator'] = 'and'; } $controls->data['options_lists'] = array(); $controls->data['options_lists_exclude'] = array(); if (!empty($email['preferences'])) { $preferences = explode(',', $email['preferences']); $value = empty($email['options']['preferences_status']) ? 'on' : 'off'; foreach ($preferences as $x) { if ($value == 'on') { $controls->data['options_lists'][] = $x; } else { $controls->data['options_lists_exclude'][] = $x; } } } } } // End backward compatibility if (!$controls->is_action()) { tnp_prepare_controls($email, $controls); } if ($controls->is_action('html')) { $data = array(); $data['editor'] = NewsletterEmails::EDITOR_HTML; $data['id'] = $email_id; // Backward compatibility: clean up the composer flag $data['options'] = $email['options']; unset($data['options']['composer']); // End backward compatibility $email = Newsletter::instance()->save_email($data, ARRAY_A); $controls->messages = 'You can now edit the newsletter as pure HTML'; tnp_prepare_controls($email, $controls); $editor_type = NewsletterEmails::EDITOR_HTML; } if ($controls->is_action('test') || $controls->is_action('save') || $controls->is_action('send') || $controls->is_action('schedule')) { $email['subject'] = $controls->data['subject']; $email['track'] = $controls->data['track']; $email['editor'] = $editor_type; $email['private'] = $controls->data['private']; $email['message_text'] = $controls->data['message_text']; if ($controls->is_action('send')) { $email['send_on'] = time(); } else { $email['send_on'] = $controls->data['send_on']; } // Reset and refill the options $email['options'] = array(); foreach ($controls->data as $name => $value) { if (strpos($name, 'options_') === 0) { $email['options'][substr($name, 8)] = $value; } } // Before send, we build the query to extract subscriber, so the delivery engine does not // have to worry about the email parameters if ($email['options']['status'] == 'S') { $query = "select * from " . NEWSLETTER_USERS_TABLE . " where status='S'"; } else { $query = "select * from " . NEWSLETTER_USERS_TABLE . " where status='C'"; } if ($email['options']['wp_users'] == '1') { $query .= " and wp_user_id<>0"; } $list_where = array(); if (isset($email['options']['lists']) && count($email['options']['lists'])) { foreach ($email['options']['lists'] as $list) { $list = (int) $list; $list_where[] = 'list_' . $list . '=1'; } } if (!empty($list_where)) { if (isset($email['options']['lists_operator']) && $email['options']['lists_operator'] == 'and') { $query .= ' and (' . implode(' and ', $list_where) . ')'; } else { $query .= ' and (' . implode(' or ', $list_where) . ')'; } } // Excluded lists $list_where = array(); if (isset($email['options']['lists_exclude']) && count($email['options']['lists_exclude'])) { foreach ($email['options']['lists_exclude'] as $list) { $list = (int) $list; $list_where[] = 'list_' . $list . '=0'; } } if (!empty($list_where)) { // Must not be in one of the excluded lists $query .= ' and (' . implode(' and ', $list_where) . ')'; } // Gender if (isset($email['options']['sex'])) { $sex = $email['options']['sex']; if (is_array($sex) && count($sex)) { $query .= " and sex in ("; foreach ($sex as $x) { $query .= "'" . esc_sql((string) $x) . "', "; } $query = substr($query, 0, -2); $query .= ")"; } } // Temporary save to have an object and call the query filter $e = Newsletter::instance()->save_email($email); $query = apply_filters('newsletter_emails_email_query', $query, $e); $email['query'] = $query; if ($email['status'] == 'sent') { $email['total'] = $email['sent']; } else { $email['total'] = $wpdb->get_var(str_replace('*', 'count(*)', $query)); } if ($controls->is_action('send') && $controls->data['send_on'] < time()) { $controls->data['send_on'] = time(); } $email = Newsletter::instance()->save_email($email, ARRAY_A); tnp_prepare_controls($email, $controls); if ($email === false) { $controls->errors = 'Unable to save. Try to deactivate and reactivate the plugin may be the database is out of sync.'; } $controls->add_message_saved(); } if ($controls->is_action('send') || $controls->is_action('schedule')) { NewsletterStatistics::instance()->reset_stats($email); if ($email['subject'] == '') { $controls->errors = __('A subject is required to send', 'newsletter'); } else { $wpdb->update(NEWSLETTER_EMAILS_TABLE, array('status' => 'sending'), array('id' => $email_id)); $email['status'] = 'sending'; if ($controls->is_action('send')) { $controls->messages = __( 'Now sending.', 'newsletter' ); } else { $controls->messages = __( 'Scheduled.', 'newsletter' ); } } } if (isset($email['options']['status']) && $email['options']['status'] == 'S') { $controls->warnings[] = __('This newsletter will be sent to not confirmed subscribers.', 'newsletter'); } if (strpos($email['message'], '{profile_url}') === false && strpos($email['message'], '{unsubscription_url}') === false && strpos($email['message'], '{unsubscription_confirm_url}') === false) { $controls->warnings[] = __('The message is missing the subscriber profile or cancellation link.', 'newsletter'); } if ($email['status'] != 'sent') { $subscriber_count = $wpdb->get_var(str_replace('*', 'count(*)', $email['query'])); } else { $subscriber_count = $email['sent']; } ?>

init(array('cookie_name' => 'newsletter_emails_edit_tab')); ?>
button_back('?page=newsletter_emails_index') ?> button_save(); ?> button_confirm('send', __('Send now', 'newsletter'), __('Start real delivery?', 'newsletter')); ?> button_confirm('pause', __('Pause', 'newsletter'), __('Pause the delivery?', 'newsletter')); ?> button_confirm('continue', __('Continue', 'newsletter'), 'Continue the delivery?'); ?> button_confirm('abort', __('Stop', 'newsletter'), __('This totally stop the delivery, ok?', 'newsletter')); ?>
text('subject', null, 'Subject'); ?>
show_email_status_label($email) ?> show_email_progress_bar($email, array('numbers' => $email['status'] == 'sent' ? false : true)) ?>
format_date( $email['send_on']); } else if ($email['status'] == 'sending' && $email['send_on'] > time()) { echo __('Scheduled on'), ' ', $module->format_date( $email['send_on']); } ?>
:

panel_help('https://www.thenewsletterplugin.com/documentation/newsletter-targeting') ?>

get_list_options(); ?> select('options_lists_operator', array('or' => __('Match at least one of', 'newsletter'), 'and' => __('Match all of', 'newsletter'))); ?> select2('options_lists', $lists, null, true, null, __('All', 'newsletter')); ?>
select2('options_lists_exclude', $lists, null, true, null, __('None', 'newsletter')); ?>
checkboxes_group('options_sex', array('f' => 'Women', 'm' => 'Men', 'n' => 'Not specified')); ?>
select('options_status', array('C' => __('Confirmed', 'newsletter'), 'S' => __('Not confirmed', 'newsletter'))); ?>
yesno('options_wp_users'); ?>
get_email($email_id), $controls) ?>
yesno('private'); ?> button('change-private', __('Toggle')) ?>

: Newsletter Archive Extension

yesno('track'); ?>
get_email($email_id), $controls) ?>
Query (tech)
Token (tech)
This is the textual version of your newsletter. If you empty it, only an HTML version will be sent but is an anti-spam best practice to include a text only version. options['phpmailer'] == 0) { ?>

The text part is sent only when Newsletter manages directly the sending process. See the main settings.

textarea_fixed('message_text', '100%', '500'); ?>

button_confirm('html', __('Convert to HTML newsletter', 'newsletter'), 'Attention: no way back!'); ?>