If enabled this plugin intercepts the wp_mail() function. Instead of sending the mails directly, it stores them in the database and sends them step by step with a delay during the WP Cron.
';
echo '
Current state: ';
if ($wdm_wpma_options['enabled'] == '1') {
echo 'The plugin is enabled All Mails sent through wp_mail() are delayed by the Queue.';
} else {
echo 'The plugin is disabled. The plugin has no impact at the moment, no Mails inside the Queue are going to be sent.';
}
echo '
';
echo '
';
echo '
';
echo '
Does this plugin change the way HOW emails are sent?
';
echo '
No, don\'t worry. This plugin only affects WHEN emails are sent, not how. It delays the sending (by the Queue), nonetheless all emails are sent through the standard wp_mail() function.
';
echo '
If you use SMTP for sending, or an external service like Mailgun, everything will still work as expected.
';
echo '
';
echo '
';
echo '
Does this plugin work, if I have a Caching Plugin installed? E.g. W3 Total Cache or similar?
';
echo '
If you\'re using a Caching plugin like W3 Total Cache, WP Rocket or any other caching solution which generates static html-files and serves them to visitors, you\'ll have to make sure you\'re calling the wp-cron file manually every couple of minutes.
';
echo '
Otherwise your normal WP Cron wouldn\'t be called as often as it should be and scheduled messages would be sent with big delays.
';
echo '
';
echo '
';
echo '
What about Proxy-Caching, e.g. NGINX?
';
echo '
Same situation here. Please make sure you\'re calling the WordPress Cron by an external service or your webhoster every couple of minutes.
';
echo '
';
echo '
';
echo '
My form builder supports attachments. What about them?
';
echo '
You are covered. All attachments are stored temporarily in the queue until they are sent along with their corresponding emails.
';
echo '
';
echo '
';
echo '
What are Queue alerts?
';
echo '
This is a simple and effective way to improve the security of your WordPress installation.
Imagine: In case your website is sending spam through wp_mail(), the email Queue would fill up very quickly preventing your website from sending so many spam emails at once. This gives you time and avoids a lot of trouble.
Queue Alerts warn you, if the Queue is longer than usal. You decide at which point you want to be alerted. So you get the chance to have a look if there might be something wrong on the website.
';
echo '
Current state: ';
if ($wdm_wpma_options['alert_enabled'] == '1') {
echo 'Alerts are enabled If more than '.esc_html($wdm_wpma_options['email_amount']).' emails are waiting in the Queue, WordPress will sent an alert email to '.esc_html($wdm_wpma_options['email']).'.';
} else {
echo 'Alerting is disabled. No alerts will be sent.';
}
echo '
';
echo '
Please note: This plugin will only send one alert every six hours.
In general, this is no problem at all. We just want to remind you to make sure you\'re running the Cron manually by calling '.$url.' every couple of minutes.
';
echo '
';
if (function_exists('_get_cron_array')) {
$next_tasks = _get_cron_array();
if ($next_tasks) {
$tasks_in_past = false;
$tasks_of_mailqueue_in_past = false;
foreach($next_tasks as $key => $val) {
if (time() > intval($key) + intval($wdm_wpma_options['queue_interval'])) {
if (array_keys($val)[0] == 'wp_mail_queue_hook') { $tasks_of_mailqueue_in_past = intval($key); }
$tasks_in_past = true;
}
}
if ($tasks_in_past) {
echo '
';
echo '
Attention: It seams that your WP Cron is not running. There are some jobs waiting to be completed.
';
if ($tasks_of_mailqueue_in_past) {
echo '
The Queue wasn\'t been able to be executed since '.esc_html(human_time_diff($tasks_of_mailqueue_in_past,time())).'.
';
}
echo '
';
}
}
}
}
echo '
';
}
if(!class_exists('WP_List_Table')){
require_once( ABSPATH . 'wp-admin/includes/screen.php' );
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
class wdm_wpma_Log_Table extends WP_List_Table {
function get_log() {
global $wpdb, $wdm_wpma_options;
$tableName = $wpdb->prefix.$wdm_wpma_options['tableName'];
return $wpdb->get_results("SELECT * FROM `$tableName` WHERE `status` != 'queue' ORDER BY `timestamp` DESC",'ARRAY_A');
}
function get_queue() {
global $wpdb, $wdm_wpma_options;
$tableName = $wpdb->prefix.$wdm_wpma_options['tableName'];
return $wpdb->get_results("SELECT * FROM `$tableName` WHERE `status` = 'queue' ORDER BY `timestamp`",'ARRAY_A');
}
function get_columns() {
$columns = array(
'id' => '',
'timestamp' => 'Time',
'status' => 'Status',
'recipient' => 'Recipient',
'subject' => 'Subject',
'message' => 'Message',
'headers' => 'Headers',
'attachments' => 'Attachments',
);
return $columns;
}
public function prepare_items() {
$type = sanitize_key($_GET['page']);
$columns = $this->get_columns();
$hidden = array();
$sortable = array();
$this->_column_headers = array($columns, $hidden, $sortable);
$this->process_bulk_action();
if ($type == 'wdm_wpma_mail_queue-tab-log') {
$data = $this->get_log();
} else if ($type == 'wdm_wpma_mail_queue-tab-queue') {
$data = $this->get_queue();
}
if ($data && is_array($data)) {
$perPage = 50;
$currentPage = $this->get_pagenum();
$totalItems = count($data);
$this->set_pagination_args( array(
'total_items' => $totalItems,
'per_page' => $perPage
) );
$data = array_slice($data,(($currentPage-1)*$perPage),$perPage);
}
$this->items = $data;
}
public function column_default( $item, $column_name ) {
switch( $column_name ) {
case 'timestamp':
case 'subject':
case 'info':
return maybe_unserialize($item[$column_name]);
break;
case 'recipient':
case 'headers':
$return = maybe_unserialize($item[$column_name]);
if (is_array($return)) {
return implode(',',$return);
} else {
return $return;
}
break;
case 'attachments':
$return = maybe_unserialize($item[$column_name]);
//var_dump($return);
if (is_array($return)) {
$betterreturn = array();
foreach($return as $item) {
array_push($betterreturn,basename($item));
}
return implode(' ',$betterreturn);
} else {
return basename($return);
}
break;
case 'status':
$info = isset( $item[ 'info' ] ) && $item[ 'info' ] ? $item[ 'info' ] : '';
if ( $item[$column_name] === 'alert' ) {
$alertData = json_decode($info,/*associative*/true);
if ( $alertData ) {
$info = 'Emails in queue: '.esc_html($alertData['in_queue']);
$info .= ' Queue settings: Send max '.esc_html($alertData['queue_amount']).' email(s) every '.esc_html($alertData['queue_interval']/60).' minute(s).';
$info .= ' Alert settings: Send alert if more than '.esc_html($alertData['email_amount']).' email(s) in the queue.';
} else {
$info = '';
}
}
$htmlInfo = $info ? ''.$info.'' : '';
$cssStatus = $htmlInfo ? ' wdm-wpma-status-has-info' : '';
return ''.$item[$column_name].$htmlInfo.'';
break;
case 'message':
$message = $item[$column_name];
if ( $message ) {
$messageLen = strlen($message);
$message = htmlentities($message);
$message = preg_replace('#^(.*<body>)(\r?\n)?#ims', 'HEADER$1', $message );
$message = preg_replace('#(</body>.*)$#ims', 'FOOTER$1', $message);
$message = preg_replace('#(.*)#ims', '$1', $message);
$message = preg_replace('#\r?\n#', ' ', $message);
$return = '';
$return .= 'View message ('.esc_html($messageLen).' bytes)';
$return .= '
The other emails have been put again into the Queue.
';
$notice .= '
';
echo $notice;
}
break;
}
return;
}
}
function wdm_wpma_settings_page_navi($tab) {
echo '';
}
function wdm_wpma_settings_init() {
global $wdm_wpma_options;
register_setting('wdm_wpma_settings','wdm_wpma_settings');
add_settings_section('wdm_wpma_settings_section','',null,'wdm_wpma_settings_page');
add_settings_field('wdm_wpma_status','Queue + Log enabled','wdm_wpma_render_option_status','wdm_wpma_settings_page','wdm_wpma_settings_section');
add_settings_field('wdm_wpma_queue','Queue','wdm_wpma_render_option_queue','wdm_wpma_settings_page','wdm_wpma_settings_section');
add_settings_field('wdm_wpma_log','Log','wdm_wpma_render_option_log','wdm_wpma_settings_page','wdm_wpma_settings_section');
add_settings_field('wdm_wpma_alert_status','Alert enabled','wdm_wpma_render_option_alert_status','wdm_wpma_settings_page','wdm_wpma_settings_section');
add_settings_field('wdm_wpma_sensitivity','Alert Sensitivity','wdm_wpma_render_option_sensitivity','wdm_wpma_settings_page','wdm_wpma_settings_section');
}
add_action('admin_init','wdm_wpma_settings_init');
function wdm_wpma_render_option_status() {
global $wdm_wpma_options;
if ($wdm_wpma_options['enabled'] == '1') {
echo '';
} else {
echo ' ← Check this to enable the Queue. Otherwise this plugin won\'t have any effect on your website.';
}
}
function wdm_wpma_render_option_alert_status() {
global $wdm_wpma_options;
if ($wdm_wpma_options['alert_enabled'] == '1') {
echo '';
} else {
echo '';
}
}
function wdm_wpma_render_option_queue() {
global $wdm_wpma_options;
echo 'Send max. email(s) every minute(s) by WP Cron. ';
}
function wdm_wpma_render_option_log() {
global $wdm_wpma_options;
echo 'Delete Log entries older than days.';
}
function wdm_wpma_render_option_sensitivity() {
global $wdm_wpma_options;
echo 'Send alert to if more than email(s) in the Queue.';
}
/* ***************************************************************
Alert WordPress User if last email in log could not be sent
**************************************************************** */
function wdm_wpma_checkLogForErrors() {
global $wpdb,$wdm_wpma_options;
if ($wdm_wpma_options['enabled'] != '1') { return; }
$tableName = $wpdb->prefix.$wdm_wpma_options['tableName'];
$last_mail = $wpdb->get_row("SELECT * FROM `$tableName` WHERE `status` != 'queue' ORDER BY `id` DESC",'ARRAY_A');
if (!$last_mail) { return; }
if ($last_mail['status'] == 'error') {
if (current_user_can('manage_options')) {
$notice = '
';
$notice .= '
Attention: Your website has problems sending e-mails
';
$notice .= '
This is an important message from your Mail Queue plugin. Please take a look at your Mail Log. The last email(s) couldn\'t be sent properly.