PluginProbe
Mail Queue / 1.1
Mail Queue v1.1
1.6.1 1.6.0 1.5.1 trunk 1.0 1.1 1.2 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.5.0
mail-queue / mail-queue-options.php

mail-queue-options.php in Mail Queue 1.1, at mail-queue-options.php

497 lines 28.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /* ***************************************************************
4 Options Page
5 **************************************************************** */
6
7 function wdm_wpma_actionlinks ( $actions ) {
8 $links = array(
9 '<a href="'.admin_url('admin.php?page=wdm_wpma_mail_queue').'">Settings</a>',
10 '<a href="'.admin_url('admin.php?page=wdm_wpma_mail_queue-tab-log').'">Log</a>',
11 '<a href="'.admin_url('admin.php?page=wdm_wpma_mail_queue-tab-queue').'">Queue</a>',
12 '<a href="'.admin_url('admin.php?page=wdm_wpma_mail_queue-tab-faq').'">FAQs</a>',
13 );
14 return array_merge($actions,$links );
15 }
16 add_filter('plugin_action_links_mail-queue/mail-queue.php','wdm_wpma_actionlinks');
17
18 // Options Page
19 function wdm_wpma_settings_page_menuitem() {
20 add_menu_page('Mail Queue','Mail Queue','manage_options','wdm_wpma_mail_queue','wdm_wpma_settings_page','data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTc4IiBoZWlnaHQ9IjE3OCIgdmlld0JveD0iMCAwIDE3OCAxNzgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNNzguNzI0MSA1LjI1MzA5Qzc2LjkwNzQgNC43MDgxIDc0Ljk0MDEgNS4wNTQxMyA3My40MTg0IDYuMTg2MjlDNzEuODk2OCA3LjMxODQ1IDcxIDkuMTAzNDEgNzEgMTEuMDAwMVYxNjdDNzEgMTY4Ljg5NyA3MS44OTY4IDE3MC42ODIgNzMuNDE4NCAxNzEuODE0Qzc0Ljk0MDEgMTcyLjk0NiA3Ni45MDc0IDE3My4yOTIgNzguNzI0MSAxNzIuNzQ3TDE1OC43MjQgMTQ4Ljc0N0MxNjEuMjYyIDE0Ny45ODYgMTYzIDE0NS42NSAxNjMgMTQzVjM1QzE2MyAzMi4zNTA0IDE2MS4yNjIgMzAuMDE0NSAxNTguNzI0IDI5LjI1MzFMNzguNzI0MSA1LjI1MzA5Wk04NS43ODg3IDIyLjM4NDZDODcuNzg1NCAyMS40Mzk0IDkwLjE3MDMgMjIuMjkxOSA5MS4xMTU0IDI0LjI4ODdMMTIyLjg1MiA5MS4zMzc4TDE0My4zMzQgNDQuNDAwMkMxNDQuMjE3IDQyLjM3NTUgMTQ2LjU3NSA0MS40NTAzIDE0OC42IDQyLjMzMzhDMTUwLjYyNSA0My4yMTc0IDE1MS41NSA0NS41NzUgMTUwLjY2NiA0Ny41OTk4TDEyNi42NjYgMTAyLjZDMTI2LjAzOSAxMDQuMDM3IDEyNC42MjkgMTA0Ljk3NiAxMjMuMDYxIDEwNUMxMjEuNDkzIDEwNS4wMjQgMTIwLjA1NiAxMDQuMTI5IDExOS4zODUgMTAyLjcxMUw4My44ODQ2IDI3LjcxMTNDODIuOTM5NCAyNS43MTQ2IDgzLjc5MTkgMjMuMzI5NyA4NS43ODg3IDIyLjM4NDZaIiBmaWxsPSIjRkY3NTAwIi8+CjxwYXRoIGQ9Ik00OSAxM0M1Mi4zMTM3IDEzIDU1IDE1LjY4NjMgNTUgMTlWMTU5QzU1IDE2Mi4zMTQgNTIuMzEzNyAxNjUgNDkgMTY1QzQ1LjY4NjMgMTY1IDQzIDE2Mi4zMTQgNDMgMTU5VjE5QzQzIDE1LjY4NjMgNDUuNjg2MyAxMyA0OSAxM1oiIGZpbGw9IiNGRjc1MDAiLz4KPHBhdGggZD0iTTIxIDIxQzI0LjMxMzcgMjEgMjcgMjMuNjg2MyAyNyAyN1YxNTFDMjcgMTU0LjMxNCAyNC4zMTM3IDE1NyAyMSAxNTdDMTcuNjg2MyAxNTcgMTUgMTU0LjMxNCAxNSAxNTFWMjdDMTUgMjMuNjg2MyAxNy42ODYzIDIxIDIxIDIxWiIgZmlsbD0iI0ZGNzUwMCIvPgo8L3N2Zz4=');
21 add_submenu_page('wdm_wpma_mail_queue','Settings','Settings','manage_options','wdm_wpma_mail_queue','wdm_wpma_settings_page');
22 add_submenu_page('wdm_wpma_mail_queue','Log','Log','manage_options','wdm_wpma_mail_queue-tab-log','wdm_wpma_settings_page');
23 add_submenu_page('wdm_wpma_mail_queue','Queue','Queue','manage_options','wdm_wpma_mail_queue-tab-queue','wdm_wpma_settings_page');
24 add_submenu_page('wdm_wpma_mail_queue','FAQ','FAQ','manage_options','wdm_wpma_mail_queue-tab-faq','wdm_wpma_settings_page');
25 if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) {
26 add_submenu_page('wdm_wpma_mail_queue','Cron Information','Cron Information','manage_options','wdm_wpma_mail_queue-tab-croninfo','wdm_wpma_settings_page');
27 }
28 }
29 add_action('admin_menu','wdm_wpma_settings_page_menuitem');
30
31 function wdm_wpma_settings_page_assets () {
32 $screen = get_current_screen();
33 if ( preg_match( '#wdm_wpma_mail_queue#', $screen->base ) ) {
34 wp_enqueue_style( 'wdm_wpma_style', plugins_url( 'assets/css/admin.css', __FILE__ ) );
35 wp_enqueue_script( 'wdm_wpma_script', plugins_url( 'assets/js/wdm-wpma-admin.js', __FILE__ ), [ 'jquery' ], false, true );
36 }
37 }
38 add_action( 'admin_enqueue_scripts', 'wdm_wpma_settings_page_assets' );
39
40 // Options Page Settings
41 function wdm_wpma_settings_page() {
42
43 // Only Admins
44 if ( ! current_user_can( 'manage_options' ) ) { return; }
45
46 // Settings
47 global $wdm_wpma_options;
48
49 // Get the active tab from the $_GET param
50 $default_tab = null;
51 $tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : $default_tab;
52
53 echo '<div class="wrap">';
54
55 // Options Header
56 echo '<h1 class="wdm-wpma-title"><img class="wdm-wpma-logo" src="'.esc_url(plugins_url('assets/img/mail-queue-logo-wordmark.svg', __FILE__)).'" alt="Mail Queue" width="308" height="56" /></h1>';
57
58 $tab = sanitize_key($_GET['page']);
59 if ($tab != 'wdm_wpma_mail_queue-tab-croninfo' ) {
60 if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) {
61 echo '<div class="notice notice-warning notice-large">';
62 $url = esc_url(get_option('siteurl').'/wp-cron.php');
63 echo '<p><strong>Please note:</strong><br />Your normal WP Cron is disabled. Please make sure you\'re running the Cron manually by calling <a href="'.$url.'" target="_blank">'.$url.'</a> every couple of minutes.</p>';
64 echo '<p><a href="?page=wdm_wpma_mail_queue-tab-croninfo">More information</a></p>';
65 echo '</div>';
66 }
67 }
68 wdm_wpma_settings_page_navi($tab); // Tabs
69
70 // Options Page Content
71 if ($tab == 'wdm_wpma_mail_queue') {
72 echo '<form action="options.php" method="post">';
73 settings_fields('wdm_wpma_settings');
74 do_settings_sections('wdm_wpma_settings_page');
75 submit_button();
76 echo '</form>';
77 } else if ($tab == 'wdm_wpma_mail_queue-tab-log') {
78 echo '<form method="post">';
79 $logtable = new wdm_wpma_Log_Table();
80 $logtable->prepare_items();
81 $logtable->display();
82 echo '</form>';
83 } else if ($tab == 'wdm_wpma_mail_queue-tab-queue') {
84
85 if (isset($_GET['addtestmail'])) {
86 global $wpdb;
87 $tableName = $wpdb->prefix.$wdm_wpma_options['tableName'];
88 $data = array(
89 'timestamp'=>current_time('mysql',false),
90 'recipient'=>$wdm_wpma_options['email'],
91 'subject'=>'Testmail #'.time(),
92 'message'=>'This is just a test email send by the Mail Queue plugin.',
93 'status' => 'queue'
94 );
95 $wpdb->insert($tableName,$data);
96 }
97
98 $next_cron_timestamp = wp_next_scheduled('wp_mail_queue_hook');
99 if ($next_cron_timestamp) {
100 if ($next_cron_timestamp > time()) {
101 echo '<div class="notice notice-success"><p>Next Sending will be triggered in '.esc_html(human_time_diff($next_cron_timestamp)).' at '.esc_html(wp_date('H:i',$next_cron_timestamp)).'.</p></div>';
102 }
103 } else {
104 echo '<div class="notice notice-error"><p>The Queue is not enabled at the moment. Enable it in the <a href="admin.php?page=wdm_wpma_mail_queue">Settings</a>.</p></div>';
105 }
106
107 echo '<form method="post" action="admin.php?page=wdm_wpma_mail_queue-tab-queue">';
108 $queuetable = new wdm_wpma_Log_Table();
109 $queuetable->prepare_items();
110 $queuetable->display();
111 echo '</form>';
112 } else if ($tab == 'wdm_wpma_mail_queue-tab-faq') {
113 echo '<div class="wdm-wpma-box">';
114 echo '<h3>How does this Plugin work?</h3>';
115 echo '<p>If enabled this plugin intercepts the <a target="_blank" href="https://developer.wordpress.org/reference/functions/wp_mail/"><i>wp_mail()</i></a> function. Instead of sending the mails directly, it stores them in the database and sends them step by step with a delay during the <i>WP Cron</i>.</p>';
116 echo '<p>Current state: ';
117 if ($wdm_wpma_options['enabled'] == '1') {
118 echo '<b class="wdm-wpma-ok">The plugin is enabled</b> All Mails sent through <a target="_blank" href="https://developer.wordpress.org/reference/functions/wp_mail/"><i>wp_mail()</i></a> are delayed by the <a href="admin.php?page=wdm_wpma_mail_queue-tab-queue">Queue</a>.';
119 } else {
120 echo '<b>The plugin is disabled</b>. The plugin has no impact at the moment, no Mails inside the Queue are going to be sent.';
121 }
122 echo '</p>';
123 echo '</div>';
124 echo '<div class="wdm-wpma-box">';
125 echo '<h3>Does this plugin change the way <b>HOW</b> emails are sent?</h3>';
126 echo '<p>No, don\'t worry. This plugin only affects <b>WHEN</b> emails are sent, not how. It delays the sending (by the Queue), nonetheless all emails are sent through the standard <a target="_blank" href="https://developer.wordpress.org/reference/functions/wp_mail/"><i>wp_mail()</i></a> function.</p>';
127 echo '<p>If you use SMTP for sending, or an external service like Mailgun, everything will still work as expected.</p>';
128 echo '</div>';
129 echo '<div class="wdm-wpma-box">';
130 echo '<h3>Does this plugin work, if I have a Caching Plugin installed? E.g. <i>W3 Total Cache</i> or similar?</h3>';
131 echo '<p>If you\'re using a Caching plugin like <i>W3 Total Cache</i>, <i>WP Rocket</i> 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 <a href="'.esc_url(get_option('siteurl')).'/wp-cron.php" target="_blank">wp-cron file</a> manually every couple of minutes.</p>';
132 echo '<p>Otherwise your normal WP Cron wouldn\'t be called as often as it should be and scheduled messages would be sent with big delays.</p>';
133 echo '</div>';
134 echo '<div class="wdm-wpma-box">';
135 echo '<h3>What about Proxy-Caching, e.g. NGINX?</h3>';
136 echo '<p>Same situation here. Please make sure you\'re calling the <a href="'.esc_url(get_option('siteurl')).'/wp-cron.php" target="_blank">WordPress Cron</a> by an external service or your webhoster every couple of minutes.</p>';
137 echo '</div>';
138 echo '<div class="wdm-wpma-box">';
139 echo '<h3>My form builder supports attachments. What about them?</h3>';
140 echo '<p>You are covered. All attachments are stored temporarily in the queue until they are sent along with their corresponding emails.</p>';
141 echo '</div>';
142 echo '<div class="wdm-wpma-box">';
143 echo '<h3>What are Queue alerts?</h3>';
144 echo '<p>This is a simple and effective way to improve the security of your WordPress installation.</p><p>Imagine: In case your website is sending spam through <a target="_blank" href="https://developer.wordpress.org/reference/functions/wp_mail/"><i>wp_mail()</i></a>, 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.</p><p>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.</p>';
145 echo '<p>Current state: ';
146 if ($wdm_wpma_options['alert_enabled'] == '1') {
147 echo '<b class="wdm-wpma-ok">Alerts are enabled</b> If more than '.esc_html($wdm_wpma_options['email_amount']).' emails are waiting in the Queue, WordPress will sent an alert email to <i>'.esc_html($wdm_wpma_options['email']).'</i>.';
148 } else {
149 echo '<b>Alerting is disabled</b>. No alerts will be sent.';
150 }
151 echo '</p>';
152 echo '<p>Please note: This plugin will only send one alert every six hours.</p>';
153 echo '</div>';
154 echo '<div class="wdm-wpma-box">';
155 echo '<h3>Want to put a test email into the Queue?</h3>';
156 echo '<p><a class="button" href="admin.php?page=wdm_wpma_mail_queue-tab-queue&addtestmail">Sure! Put a Test Email for '.esc_html($wdm_wpma_options['email']).' into the Queue</a></p>';
157 echo '</div>';
158
159 } else if ($tab == 'wdm_wpma_mail_queue-tab-croninfo') {
160 echo '<div class="wdm-wpma-box">';
161 echo '<h3>Information: Your common WP Cron is disabled</h3>';
162 echo '<p>It look\'s like you deactived the WP Cron by <i>define( \' DISABLE_WP_CRON \' , true )</i>.</p>';
163 $url = esc_url(get_option('siteurl').'/wp-cron.php');
164 echo '<p>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 <a href="'.$url.'" target="_blank">'.$url.'</a> every couple of minutes.</p>';
165 echo '</div>';
166
167
168 if (function_exists('_get_cron_array')) {
169 $next_tasks = _get_cron_array();
170 if ($next_tasks) {
171 $tasks_in_past = false;
172 $tasks_of_mailqueue_in_past = false;
173 foreach($next_tasks as $key => $val) {
174 if (time() > intval($key) + intval($wdm_wpma_options['queue_interval'])) {
175 if (array_keys($val)[0] == 'wp_mail_queue_hook') { $tasks_of_mailqueue_in_past = intval($key); }
176 $tasks_in_past = true;
177 }
178 }
179 if ($tasks_in_past) {
180 echo '<div class="wdm-wpma-box">';
181 echo '<h3>Attention: It seams that your WP Cron is not running. There are some jobs waiting to be completed.</h3>';
182 if ($tasks_of_mailqueue_in_past) {
183 echo '<p><b>The Queue wasn\'t been able to be executed since '.esc_html(human_time_diff($tasks_of_mailqueue_in_past,time())).'.</b></p>';
184 }
185 echo '</div>';
186 }
187 }
188 }
189
190
191 }
192
193 echo '</div>';
194
195 }
196
197 if(!class_exists('WP_List_Table')){
198 require_once( ABSPATH . 'wp-admin/includes/screen.php' );
199 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
200 }
201
202 class wdm_wpma_Log_Table extends WP_List_Table {
203
204 function get_log() {
205 global $wpdb, $wdm_wpma_options;
206 $tableName = $wpdb->prefix.$wdm_wpma_options['tableName'];
207 return $wpdb->get_results("SELECT * FROM `$tableName` WHERE `status` != 'queue' ORDER BY `timestamp` DESC",'ARRAY_A');
208 }
209
210 function get_queue() {
211 global $wpdb, $wdm_wpma_options;
212 $tableName = $wpdb->prefix.$wdm_wpma_options['tableName'];
213 return $wpdb->get_results("SELECT * FROM `$tableName` WHERE `status` = 'queue' ORDER BY `timestamp`",'ARRAY_A');
214 }
215
216 function get_columns() {
217 $columns = array(
218 'id' => '<label><span class="screen-reader-text">Select all</span><input class="wdm-wpma-select-all" type="checkbox"></label>',
219 'timestamp' => 'Time',
220 'status' => 'Status',
221 'recipient' => 'Recipient',
222 'subject' => 'Subject',
223 'message' => 'Message',
224 'headers' => 'Headers',
225 'attachments' => 'Attachments',
226 );
227 return $columns;
228 }
229
230 public function prepare_items() {
231 $type = sanitize_key($_GET['page']);
232 $columns = $this->get_columns();
233 $hidden = array();
234 $sortable = array();
235 $this->_column_headers = array($columns, $hidden, $sortable);
236 $this->process_bulk_action();
237 if ($type == 'wdm_wpma_mail_queue-tab-log') {
238 $data = $this->get_log();
239 } else if ($type == 'wdm_wpma_mail_queue-tab-queue') {
240 $data = $this->get_queue();
241 }
242 if ($data && is_array($data)) {
243 $perPage = 50;
244 $currentPage = $this->get_pagenum();
245 $totalItems = count($data);
246 $this->set_pagination_args( array(
247 'total_items' => $totalItems,
248 'per_page' => $perPage
249 ) );
250 $data = array_slice($data,(($currentPage-1)*$perPage),$perPage);
251 }
252 $this->items = $data;
253 }
254
255 public function column_default( $item, $column_name ) {
256 switch( $column_name ) {
257 case 'timestamp':
258 case 'subject':
259 case 'info':
260 return maybe_unserialize($item[$column_name]);
261 break;
262 case 'recipient':
263 case 'headers':
264 $return = maybe_unserialize($item[$column_name]);
265 if (is_array($return)) {
266 return implode(',',$return);
267 } else {
268 return $return;
269 }
270 break;
271 case 'attachments':
272 $return = maybe_unserialize($item[$column_name]);
273 //var_dump($return);
274 if (is_array($return)) {
275 $betterreturn = array();
276 foreach($return as $item) {
277 array_push($betterreturn,basename($item));
278 }
279 return implode('<br />',$betterreturn);
280 } else {
281 return basename($return);
282 }
283 break;
284 case 'status':
285 $info = isset( $item[ 'info' ] ) && $item[ 'info' ] ? $item[ 'info' ] : '';
286 if ( $item[$column_name] === 'alert' ) {
287 $alertData = json_decode($info,/*associative*/true);
288 if ( $alertData ) {
289 $info = '<strong>Emails in queue</strong>: '.esc_html($alertData['in_queue']);
290 $info .= '<br /><strong>Queue settings</strong>: Send max '.esc_html($alertData['queue_amount']).' email(s) every '.esc_html($alertData['queue_interval']/60).' minute(s).';
291 $info .= '<br /><strong>Alert settings</strong>: Send alert if more than '.esc_html($alertData['email_amount']).' email(s) in the queue.';
292 } else {
293 $info = '';
294 }
295 }
296 $htmlInfo = $info ? '<span class="wdm-wpma-info">'.$info.'</span>' : '';
297 $cssStatus = $htmlInfo ? ' wdm-wpma-status-has-info' : '';
298 return '<span class="wdm-wpma-status wdm-wpma-status-'.sanitize_title($item[$column_name]).esc_html($cssStatus).'">'.$item[$column_name].$htmlInfo.'</span>';
299 break;
300 case 'message':
301 $message = $item[$column_name];
302
303 if ( $message ) {
304 $messageLen = strlen($message);
305 $message = htmlentities($message);
306 $message = preg_replace('#^(.*&lt;body&gt;)(\r?\n)?#ims', '<details class="wdm-wpma-email-source-meta"><summary>HEADER</summary><span>$1</span></details><!--wdm-wpma-start-->', $message );
307 $message = preg_replace('#(&lt;/body&gt;.*)$#ims', '<!--wdm-wpma-end--><details class="wdm-wpma-email-source-meta"><summary>FOOTER</summary><span>$1</span></details>', $message);
308 $message = preg_replace('#<!--wdm-wpma-start-->(.*)<!--wdm-wpma-end-->#ims', '<span class="wdm-wpma-email-source-body">$1</span>', $message);
309 $message = preg_replace('#\r?\n#', '<br />', $message);
310 $return = '<details>';
311 $return .= '<summary class="wdm-wpma-view-source">View message <i>('.esc_html($messageLen).' bytes)</i></summary>';
312 $return .= '<div class="wdm-wpma-email-source">'.wp_kses_post($message).'</div>';
313 $return .= '</details>';
314 } else {
315 $return = '<em>Empty</em>';
316 }
317 return $return;
318 break;
319 case 'id':
320 return '<input type="checkbox" name="id[]" value="'.esc_attr($item[$column_name]).'" />';
321 break;
322 default:
323 return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
324 }
325 }
326
327 public function get_bulk_actions() {
328 if (isset($_GET['page']) && $_GET['page'] == 'wdm_wpma_mail_queue-tab-queue') {
329 $actions = array(
330 'delete' => __( 'Delete')
331 );
332 } else {
333 $actions = array(
334 'delete' => __( 'Delete'),
335 'resend' => __( 'Resend'),
336 );
337 }
338
339 return $actions;
340 }
341
342 public function process_bulk_action() {
343
344 // security check!
345 if ( isset( $_POST['_wpnonce'] ) && ! empty( $_POST['_wpnonce'] ) ) {
346 $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
347 $action = 'bulk-' . $this->_args['plural'];
348 if ( ! wp_verify_nonce( $nonce, $action ) )
349 wp_die( 'Nope! Security check failed!' );
350 }
351
352 // get IDs
353 $request_ids = isset( $_REQUEST['id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['id'] ) ) : array();
354 if ( empty( $request_ids ) ) { return; }
355
356 global $wpdb, $wdm_wpma_options;
357 $tableName = $wpdb->prefix.$wdm_wpma_options['tableName'];
358
359 switch ( $this->current_action() ) {
360 case 'delete':
361 foreach($request_ids as $id) {
362 $wpdb->delete($tableName,array('id'=>intval($id)),'%d');
363 }
364 break;
365 case 'resend':
366 foreach($request_ids as $id) {
367 $count_resend = 0;
368 $count_error = 0;
369 $maildata = $wpdb->get_row("SELECT * FROM `$tableName` WHERE `id` = '$id'");
370 if (!$maildata->attachments || $maildata->attachments == '') {
371 $count_resend++;
372 $data = array(
373 'timestamp'=> current_time('mysql',false),
374 'recipient'=> $maildata->recipient,
375 'subject'=> $maildata->subject,
376 'message'=> $maildata->message,
377 'status' => 'queue',
378 'attachments' => '',
379 'headers' => $maildata->headers,
380 );
381 $wpdb->insert($tableName,$data);
382 } else {
383 $count_error++;
384 $notice = '<div class="notice notice-error is-dismissible">';
385 $notice .= '<p><b>Sorry, your email to '.$maildata->recipient.' can\'t be sent again.</b></p>';
386 $notice .= '<p>The email used to have attachments, which are not available anymore. Only emails without attachments can be resend.</p>';
387 $notice .= '</div>';
388 echo $notice;
389 }
390 }
391 if ($count_error == 0 && $count_resend > 0) {
392 wp_redirect('admin.php?page=wdm_wpma_mail_queue-tab-queue');
393 exit;
394 } else if ($count_error > 0 && $count_resend > 0) {
395 $notice = '<div class="notice notice-success is-dismissible">';
396 $notice .= '<p>The other emails have been put again into the <a href="admin.php?page=wdm_wpma_mail_queue-tab-queue">Queue</a>.</p>';
397 $notice .= '</div>';
398 echo $notice;
399 }
400 break;
401 }
402
403 return;
404
405 }
406
407 }
408
409 function wdm_wpma_settings_page_navi($tab) {
410 echo '<nav class="nav-tab-wrapper">';
411 echo '<a href="?page=wdm_wpma_mail_queue" class="nav-tab'; if($tab==='wdm_wpma_mail_queue') { echo ' nav-tab-active'; } echo '">Settings</a>';
412 echo '<a href="?page=wdm_wpma_mail_queue-tab-log" class="nav-tab'; if($tab==='wdm_wpma_mail_queue-tab-log') { echo ' nav-tab-active'; } echo '">Log</a>';
413 echo '<a href="?page=wdm_wpma_mail_queue-tab-queue" class="nav-tab'; if($tab==='wdm_wpma_mail_queue-tab-queue') { echo ' nav-tab-active'; } echo '">Queue</a>';
414 echo '<a href="?page=wdm_wpma_mail_queue-tab-faq" class="nav-tab'; if($tab==='wdm_wpma_mail_queue-tab-faq') { echo ' nav-tab-active'; } echo '">FAQ</a>';
415 if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) {
416 echo '<a href="?page=wdm_wpma_mail_queue-tab-croninfo" class="nav-tab'; if($tab==='wdm_wpma_mail_queue-tab-croninfo') { echo ' nav-tab-active'; } echo '">Cron Information</a>';
417 }
418 echo '</nav>';
419 }
420
421 function wdm_wpma_settings_init() {
422 global $wdm_wpma_options;
423 register_setting('wdm_wpma_settings','wdm_wpma_settings');
424 add_settings_section('wdm_wpma_settings_section','',null,'wdm_wpma_settings_page');
425 add_settings_field('wdm_wpma_status','Queue + Log enabled','wdm_wpma_render_option_status','wdm_wpma_settings_page','wdm_wpma_settings_section');
426 add_settings_field('wdm_wpma_queue','Queue','wdm_wpma_render_option_queue','wdm_wpma_settings_page','wdm_wpma_settings_section');
427 add_settings_field('wdm_wpma_log','Log','wdm_wpma_render_option_log','wdm_wpma_settings_page','wdm_wpma_settings_section');
428 add_settings_field('wdm_wpma_alert_status','Alert enabled','wdm_wpma_render_option_alert_status','wdm_wpma_settings_page','wdm_wpma_settings_section');
429 add_settings_field('wdm_wpma_sensitivity','Alert Sensitivity','wdm_wpma_render_option_sensitivity','wdm_wpma_settings_page','wdm_wpma_settings_section');
430 }
431 add_action('admin_init','wdm_wpma_settings_init');
432
433 function wdm_wpma_render_option_status() {
434 global $wdm_wpma_options;
435 if ($wdm_wpma_options['enabled'] == '1') {
436 echo '<input type="checkbox" name="wdm_wpma_settings[enabled]" value="1" checked />';
437 } else {
438 echo '<input type="checkbox" name="wdm_wpma_settings[enabled]" value="1" /> &nbsp; &nbsp; <span class="wdm-wpma-warning"> &larr; Check this to enable the Queue. </span> Otherwise this plugin won\'t have any effect on your website.';
439 }
440 }
441
442 function wdm_wpma_render_option_alert_status() {
443 global $wdm_wpma_options;
444 if ($wdm_wpma_options['alert_enabled'] == '1') {
445 echo '<input type="checkbox" name="wdm_wpma_settings[alert_enabled]" value="1" checked />';
446 } else {
447 echo '<input type="checkbox" name="wdm_wpma_settings[alert_enabled]" value="1" />';
448 }
449 }
450
451 function wdm_wpma_render_option_queue() {
452 global $wdm_wpma_options;
453 echo 'Send max. <input name="wdm_wpma_settings[queue_amount]" type="number" min="1" value="'.esc_attr($wdm_wpma_options['queue_amount']).'" /> email(s) every <input name="wdm_wpma_settings[queue_interval]" type="number" min="1" value="'.esc_attr(intval($wdm_wpma_options['queue_interval']) / 60).'" /> minute(s) by <i><a href="https://developer.wordpress.org/plugins/cron/" target="_blank">WP Cron</a></i>. ';
454 }
455
456 function wdm_wpma_render_option_log() {
457 global $wdm_wpma_options;
458 echo 'Delete Log entries older than <input name="wdm_wpma_settings[clear_queue]" type="number" min="1" value="'.esc_attr(intval($wdm_wpma_options['clear_queue']) / 24).'" /> days.';
459 }
460
461 function wdm_wpma_render_option_sensitivity() {
462 global $wdm_wpma_options;
463 echo 'Send alert to <input type="text" name="wdm_wpma_settings[email]" value="'.esc_attr(sanitize_email($wdm_wpma_options['email'])).'" /> if more than <input name="wdm_wpma_settings[email_amount]" type="number" min="1" value="'.esc_attr(intval($wdm_wpma_options['email_amount'])).'" /> email(s) in the <a href="admin.php?page=wdm_wpma_mail_queue-tab-queue">Queue</a>.';
464 }
465
466
467 /* ***************************************************************
468 Alert WordPress User if last email in log could not be sent
469 **************************************************************** */
470 function wdm_wpma_checkLogForErrors() {
471
472 global $wpdb,$wdm_wpma_options;
473 if ($wdm_wpma_options['enabled'] != '1') { return; }
474
475 $tableName = $wpdb->prefix.$wdm_wpma_options['tableName'];
476 $last_mail = $wpdb->get_row("SELECT * FROM `$tableName` WHERE `status` != 'queue' ORDER BY `id` DESC",'ARRAY_A');
477 if (!$last_mail) { return; }
478
479 if ($last_mail['status'] == 'error') {
480 if (current_user_can('manage_options')) {
481 $notice = '<div class="notice notice-error is-dismissible">';
482 $notice .= '<h1>Attention: Your website has problems sending e-mails</h1>';
483 $notice .= '<p>This is an important message from your <i>Mail Queue</i> plugin. Please take a look at your <a href="admin.php?page=wdm_wpma_mail_queue-tab-log">Mail Log</a>. The last email(s) couldn\'t be sent properly.</p>';
484 $notice .= '<p>Last error message was: <b>'.$last_mail['info'].'</b></p>';
485 $notice .= '</div>';
486 echo $notice;
487 } else if (current_user_can('edit_posts')) {
488 $notice = '<div class="notice notice-error is-dismissible">';
489 $notice .= '<h1>Attention: Your website has problems sending e-mails</h1>';
490 $notice .= '<p>Please contact your Administrator. It seems that WordPress is not able to send emails.</p>';
491 $notice .= '<p>Last error message: <b>'.$last_mail['info'].'</b></p>';
492 $notice .= '</div>';
493 echo $notice;
494 }
495 }
496 }
497 add_action('admin_notices', 'wdm_wpma_checkLogForErrors');