PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 7.2.0
Admin and Site Enhancements (ASE) v7.2.0
9.1.0 9.0.2 9.0.1 9.0.0 8.9.2 8.9.1 8.9.0 8.8.8 8.8.7 8.8.6 8.8.5 8.8.4 8.8.3 8.8.2 8.8.1 8.8.0 8.7.3 8.7.2 8.7.1 8.2.1 8.2.2 8.2.3 8.3.0 8.3.1 8.3.2 8.4.0 8.4.1 8.4.2 8.5.0 8.5.1 8.5.2 8.6.0 8.6.1 8.6.2 8.7.0 5.0.1 5.0.2 5.0.2.1 5.0.2.2 5.0.2.3 5.0.2.4 5.1.0 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.8.0 5.8.1 6.0.0 6.0.3 6.0.4 6.0.5 6.0.5.1 6.0.6 6.0.7 6.0.8.1 6.1.0 6.1.3 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.3.0 6.3.1 6.3.2 6.4.0 6.5.0 6.5.1 6.6.0 6.7.0 6.8.0 6.8.2 6.8.3 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13.1 6.9.13.2 6.9.2 6.9.3 6.9.4 6.9.5 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.2 7.0.2.1 7.0.2.2 7.0.2.3 7.0.3 7.1.0 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2.0 7.2.1 7.3.0 7.3.1 7.3.2 7.3.3 7.4.0 7.4.2 7.4.4 7.4.5 7.4.6 7.4.7 7.4.8 7.5.0 7.5.1 7.5.2 7.5.3 7.5.4 7.6.0 7.6.1 7.6.1.1 7.6.10 7.6.11 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.7.1 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / classes / class-email-delivery.php
admin-site-enhancements / classes Last commit date
class-activation.php 2 years ago class-admin-columns-manager.php 2 years ago class-admin-menu-organizer.php 2 years ago class-auto-publish-posts-with-missed-schedule.php 2 years ago class-avif-upload.php 2 years ago class-change-login-url.php 2 years ago class-cleanup-admin-bar.php 2 years ago class-code-snippets-manager.php 2 years ago class-common-methods.php 2 years ago class-content-duplication.php 2 years ago class-content-order.php 2 years ago class-custom-admin-footer-text.php 2 years ago class-custom-body-class.php 2 years ago class-custom-content-types.php 2 years ago class-custom-css.php 2 years ago class-custom-nav-menu-items-in-new-tab.php 2 years ago class-deactivation.php 2 years ago class-disable-comments.php 2 years ago class-disable-dashboard-widgets.php 2 years ago class-disable-feeds.php 2 years ago class-disable-gutenberg.php 2 years ago class-disable-rest-api.php 2 years ago class-disable-smaller-components.php 2 years ago class-disable-updates.php 2 years ago class-disable-xml-rpc.php 2 years ago class-display-system-summary.php 2 years ago class-email-address-obfuscator.php 2 years ago class-email-delivery.php 2 years ago class-enhance-list-tables.php 2 years ago class-external-permalinks.php 2 years ago class-heartbeat-control.php 2 years ago class-hide-admin-bar.php 2 years ago class-hide-admin-notices.php 2 years ago class-image-sizes-panel.php 2 years ago class-image-upload-control.php 2 years ago class-insert-head-body-footer-code.php 2 years ago class-last-login-column.php 2 years ago class-limit-login-attempts.php 2 years ago class-login-id-type.php 2 years ago class-login-logout-menu.php 2 years ago class-maintenance-mode.php 2 years ago class-manage-ads-appads-txt.php 2 years ago class-manage-robots-txt.php 2 years ago class-media-replacement.php 2 years ago class-multiple-user-roles.php 2 years ago class-obfuscate-author-slugs.php 2 years ago class-open-external-links-in-new-tab.php 2 years ago class-password-protection.php 2 years ago class-redirect-after-login.php 2 years ago class-redirect-after-logout.php 2 years ago class-redirect-fourofour.php 2 years ago class-revisions-control.php 2 years ago class-search-engines-visibility.php 2 years ago class-settings-fields-render.php 2 years ago class-settings-sanitization.php 2 years ago class-settings-sections-fields.php 2 years ago class-show-custom-taxonomy-filters.php 2 years ago class-site-identity-on-login-page.php 2 years ago class-svg-upload.php 2 years ago class-various-admin-ui-enhancements.php 2 years ago class-view-admin-as-role.php 2 years ago class-wider-admin-menu.php 2 years ago
class-email-delivery.php
469 lines
1 <?php
2
3 namespace ASENHA\Classes;
4
5 use WP_Error;
6 use ASENHA\EmailDelivery\Email_Log_Table;
7 /**
8 * Class for Email Delivery module
9 *
10 * @since 6.9.5
11 */
12 class Email_Delivery {
13 private $log_entry_id;
14
15 /**
16 * Send emails using external SMTP service
17 *
18 * @since 4.6.0
19 */
20 public function deliver_email_via_smtp( $phpmailer ) {
21 $options = get_option( ASENHA_SLUG_U, array() );
22 $smtp_host = $options['smtp_host'];
23 $smtp_port = $options['smtp_port'];
24 $smtp_security = $options['smtp_security'];
25 $smtp_username = $options['smtp_username'];
26 $smtp_password = $options['smtp_password'];
27 $smtp_default_from_name = $options['smtp_default_from_name'];
28 $smtp_default_from_email = $options['smtp_default_from_email'];
29 $smtp_force_from = $options['smtp_force_from'];
30 $smtp_bypass_ssl_verification = $options['smtp_bypass_ssl_verification'];
31 $smtp_debug = $options['smtp_debug'];
32 // Do nothing if host or password is empty
33 // if ( empty( $smtp_host ) || empty( $smtp_password ) ) {
34 // return;
35 // }
36 // Maybe override FROM email and/or name if the sender is "WordPress <wordpress@sitedomain.com>", the default from WordPress core and not yet overridden by another plugin.
37 $from_name = $phpmailer->FromName;
38 $from_email_beginning = substr( $phpmailer->From, 0, 9 );
39 // Get the first 9 characters of the current FROM email
40 if ( $smtp_force_from ) {
41 $phpmailer->FromName = $smtp_default_from_name;
42 $phpmailer->From = $smtp_default_from_email;
43 } else {
44 if ( 'WordPress' === $from_name && !empty( $smtp_default_from_name ) ) {
45 $phpmailer->FromName = $smtp_default_from_name;
46 }
47 if ( 'wordpress' === $from_email_beginning && !empty( $smtp_default_from_email ) ) {
48 $phpmailer->From = $smtp_default_from_email;
49 }
50 }
51 // Only attempt to send via SMTP if all the required info is present. Otherwise, use default PHP Mailer settings as set by wp_mail()
52 if ( !empty( $smtp_host ) && !empty( $smtp_port ) && !empty( $smtp_security ) && !empty( $smtp_username ) && !empty( $smtp_password ) ) {
53 // Send using SMTP
54 $phpmailer->isSMTP();
55 // phpcs:ignore
56 // Enanble SMTP authentication
57 $phpmailer->SMTPAuth = true;
58 // phpcs:ignore
59 // Set some other defaults
60 // $phpmailer->CharSet = 'utf-8'; // phpcs:ignore
61 $phpmailer->XMailer = 'Admin and Site Enhancements v' . ASENHA_VERSION . ' - a WordPress plugin';
62 // phpcs:ignore
63 $phpmailer->Host = $smtp_host;
64 // phpcs:ignore
65 $phpmailer->Port = $smtp_port;
66 // phpcs:ignore
67 $phpmailer->SMTPSecure = $smtp_security;
68 // phpcs:ignore
69 $phpmailer->Username = trim( $smtp_username );
70 // phpcs:ignore
71 $phpmailer->Password = trim( $smtp_password );
72 // phpcs:ignore
73 }
74 // If verification of SSL certificate is bypassed
75 // Reference: https://www.php.net/manual/en/context.ssl.php & https://stackoverflow.com/a/30803024
76 if ( $smtp_bypass_ssl_verification ) {
77 $phpmailer->SMTPOptions = [
78 'ssl' => [
79 'verify_peer' => false,
80 'verify_peer_name' => false,
81 'allow_self_signed' => true,
82 ],
83 ];
84 }
85 // If debug mode is enabled, send debug info (SMTP::DEBUG_CONNECTION) to WordPress debug.log file set in wp-config.php
86 // Reference: https://github.com/PHPMailer/PHPMailer/wiki/SMTP-Debugging
87 if ( $smtp_debug ) {
88 $phpmailer->SMTPDebug = 4;
89 //phpcs:ignore
90 $phpmailer->Debugoutput = 'error_log';
91 //phpcs:ignore
92 }
93 }
94
95 /**
96 * Send a test email and use SMTP host if defined in settings
97 *
98 * @since 5.3.0
99 */
100 public function send_test_email() {
101 if ( isset( $_REQUEST ) ) {
102 $content = array(
103 array(
104 'title' => 'Hey... are you getting this?',
105 'body' => '<p><strong>Looks like you did!</strong></p>',
106 ),
107 array(
108 'title' => 'There\'s a message for you...',
109 'body' => '<p><strong>Here it is:</strong></p>',
110 ),
111 array(
112 'title' => 'Is it working?',
113 'body' => '<p><strong>Yes, it\'s working!</strong></p>',
114 ),
115 array(
116 'title' => 'Hope you\'re getting this...',
117 'body' => '<p><strong>Looks like this was sent out just fine and you got it.</strong></p>',
118 ),
119 array(
120 'title' => 'Testing delivery configuration...',
121 'body' => '<p><strong>Everything looks good!</strong></p>',
122 ),
123 array(
124 'title' => 'Testing email delivery',
125 'body' => '<p><strong>Looks good!</strong></p>',
126 ),
127 array(
128 'title' => 'Config is looking good',
129 'body' => '<p><strong>Seems like everything has been set up properly!</strong></p>',
130 ),
131 array(
132 'title' => 'All set up',
133 'body' => '<p><strong>Your configuration is working properly.</strong></p>',
134 ),
135 array(
136 'title' => 'Good to go',
137 'body' => '<p><strong>Config is working great.</strong></p>',
138 ),
139 array(
140 'title' => 'Good job',
141 'body' => '<p><strong>Everything is set.</strong></p>',
142 )
143 );
144 $random_number = rand( 0, count( $content ) - 1 );
145 $to = $_REQUEST['email_to'];
146 $title = $content[$random_number]['title'];
147 $body = $content[$random_number]['body'] . '<p>This message was sent from <a href="' . get_bloginfo( 'url' ) . '">' . get_bloginfo( 'url' ) . '</a> on ' . wp_date( 'F j, Y' ) . ' at ' . wp_date( 'H:i:s' ) . ' via ASE.</p>';
148 $headers = array('Content-Type: text/html; charset=UTF-8');
149 $success = wp_mail(
150 $to,
151 $title,
152 $body,
153 $headers
154 );
155 if ( $success ) {
156 $response = array(
157 'status' => 'success',
158 );
159 } else {
160 $response = array(
161 'status' => 'failed',
162 );
163 }
164 echo json_encode( $response );
165 }
166 }
167
168 /**
169 * Perform additional logging for data that are not properly logged via wp_mail hook
170 *
171 * @since 7.1.0
172 */
173 public function additional_logging__premium_onlly( $phpmailer ) {
174 // Set custom Message-ID header, e.g. // e.g. <message-3@subdomain.domain.com>>
175 // The number here is the ID of the message in the email delivery log table
176 $message_id = '<message-' . $this->log_entry_id . '@' . parse_url( get_site_url(), PHP_URL_HOST ) . '>';
177 $phpmailer->MessageID = $message_id;
178 // Get headers
179 // Reference: https://plugins.trac.wordpress.org/browser/mailarchiver/tags/4.0.0/includes/listeners/class-corelistener.php#L216
180 if ( method_exists( $phpmailer, 'createHeader' ) ) {
181 $headers = $phpmailer->createHeader();
182 if ( !is_array( $headers ) ) {
183 $headers = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
184 }
185 // Remove empty elements and get sender info (name and email)
186 $sender = '';
187 $headers_array = array();
188 $sender = '';
189 $reply_to = '';
190 if ( !empty( $headers ) ) {
191 foreach ( $headers as $header ) {
192 if ( '' !== $header ) {
193 $headers_array[] = $header;
194 }
195 if ( false !== strpos( $header, 'From:' ) ) {
196 $sender_array = explode( ': ', $header );
197 $sender = ( isset( $sender_array[1] ) ? $sender_array[1] : '' );
198 }
199 if ( false !== strpos( $header, 'Reply-To:' ) ) {
200 $reply_to_array = explode( ': ', $header );
201 $reply_to = ( isset( $reply_to_array[1] ) ? $reply_to_array[1] : '' );
202 }
203 if ( false !== strpos( $header, 'Content-Type:' ) ) {
204 $content_type_array = explode( ': ', $header );
205 $content_type_maybe_with_charset = ( isset( $content_type_array[1] ) ? $content_type_array[1] : '' );
206 // e.g. text/html; charset=UTF-8
207 if ( false !== strpos( $content_type_maybe_with_charset, 'charset' ) ) {
208 $content_type_array = explode( '; ', $content_type_maybe_with_charset );
209 $content_type = ( isset( $content_type_array[0] ) ? $content_type_array[0] : '' );
210 } else {
211 $content_type = trim( $content_type_maybe_with_charset );
212 }
213 }
214 }
215 }
216 // Add sender and headers info to the existing log entry for the mail
217 // https://developer.wordpress.org/reference/classes/wpdb/update/
218 global $wpdb;
219 $result = $wpdb->update(
220 $wpdb->prefix . 'asenha_email_delivery',
221 // Log table name
222 array(
223 'sender' => sanitize_text_field( str_replace( array('<', '>'), array('(', ')'), $sender ) ),
224 'reply_to' => sanitize_text_field( str_replace( array('<', '>'), array('(', ')'), $reply_to ) ),
225 'content_type' => sanitize_text_field( $content_type ),
226 'headers' => serialize( $headers_array ),
227 ),
228 array(
229 'id' => $this->log_entry_id,
230 ),
231 array(
232 '%s',
233 // string - sender
234 '%s',
235 ),
236 array('%d')
237 );
238 }
239 }
240
241 /**
242 * Trigger scheduling of email delivery log clean up event
243 *
244 * @since 7.1.1
245 */
246 public function trigger_clear_or_schedule_log_clean_up_by_amount( $option_name ) {
247 if ( 'smtp_email_log_schedule_cleanup_by_amount' == $option_name ) {
248 $this->clear_or_schedule_log_clean_up_by_amount();
249 }
250 }
251
252 /**
253 * Schedule email delivery log clean up event
254 *
255 * @link https://plugins.trac.wordpress.org/browser/lana-email-logger/tags/1.1.0/lana-email-logger.php#L750
256 * @since 7.1.1
257 */
258 public function clear_or_schedule_log_clean_up_by_amount() {
259 $options = get_option( ASENHA_SLUG_U, array() );
260 $smtp_email_log_schedule_cleanup_by_amount = ( isset( $options['smtp_email_log_schedule_cleanup_by_amount'] ) ? $options['smtp_email_log_schedule_cleanup_by_amount'] : false );
261 // If scheduled clean up is not enabled, let's clear the schedule
262 if ( !$smtp_email_log_schedule_cleanup_by_amount ) {
263 wp_clear_scheduled_hook( 'asenha_email_log_cleanup_by_amount' );
264 return;
265 }
266 // If there's no next scheduled clean up event, let's schedule one
267 if ( !wp_next_scheduled( 'asenha_email_log_cleanup_by_amount' ) ) {
268 wp_schedule_event( time(), 'hourly', 'asenha_email_log_cleanup_by_amount' );
269 }
270 }
271
272 /**
273 * Perform clean up of email delivery log by the amount of entries to keep
274 *
275 * @link https://plugins.trac.wordpress.org/browser/lana-email-logger/tags/1.1.0/lana-email-logger.php#L768
276 * @since 7.1.1
277 */
278 public function perform_email_log_clean_up_by_amount() {
279 global $wpdb;
280 $options = get_option( ASENHA_SLUG_U, array() );
281 $smtp_email_log_schedule_cleanup_by_amount = ( isset( $options['smtp_email_log_schedule_cleanup_by_amount'] ) ? $options['smtp_email_log_schedule_cleanup_by_amount'] : false );
282 $smtp_email_log_entries_amount_to_keep = ( isset( $options['smtp_email_log_entries_amount_to_keep'] ) ? $options['smtp_email_log_entries_amount_to_keep'] : 1000 );
283 // Bail if scheduled clean up by amount is not enabled
284 if ( !$smtp_email_log_schedule_cleanup_by_amount ) {
285 return;
286 }
287 $table_name = $wpdb->prefix . 'asenha_email_delivery';
288 $wpdb->query( "DELETE email_log_entries FROM " . $table_name . " \n AS email_log_entries JOIN ( SELECT id FROM " . $table_name . " ORDER BY id DESC LIMIT 1 OFFSET " . $smtp_email_log_entries_amount_to_keep . " ) \n AS email_log_entries_limit ON email_log_entries.id <= email_log_entries_limit.id;" );
289 }
290
291 /**
292 * Resend email that failed on the first attempt and marked as such
293 *
294 * @since 7.1.3
295 */
296 public function resend_email() {
297 if ( isset( $_REQUEST['action'] ) && 'resend_email' == $_REQUEST['action'] && isset( $_REQUEST['message_id'] ) && !empty( $_REQUEST['message_id'] ) && is_numeric( $_REQUEST['message_id'] ) && isset( $_REQUEST['resend_to'] ) && !empty( $_REQUEST['resend_to'] ) && isset( $_REQUEST['nonce'] ) && !empty( $_REQUEST['nonce'] ) ) {
298 $db_row_id = intval( sanitize_text_field( $_REQUEST['message_id'] ) );
299 $send_to = sanitize_text_field( $_REQUEST['resend_to'] );
300 $nonce = sanitize_text_field( $_REQUEST['nonce'] );
301 // $nonce_check = wp_verify_nonce( $nonce, 'email-delivery-log' . get_current_user_id() );
302 if ( wp_verify_nonce( $nonce, 'email-delivery-log' . get_current_user_id() ) ) {
303 global $wpdb;
304 $table_name = $wpdb->prefix . 'asenha_email_delivery';
305 $email = $wpdb->get_row( 'SELECT * FROM ' . $table_name . '
306 WHERE id = "' . $db_row_id . '"', ARRAY_A );
307 // Set conte type to text/html. Default is text/plain.
308 add_filter( 'wp_mail_content_type', array($this, 'return_html_email_type') );
309 // $email_sent = true; // For testing
310 $email_sent = wp_mail(
311 $send_to,
312 $email['subject'],
313 $email['message'],
314 '',
315 $email['attachments']
316 );
317 // Reset content-type to avoid conflicts -- https://core.trac.wordpress.org/ticket/23578
318 remove_filter( 'wp_mail_content_type', array($this, 'return_html_email_type') );
319 if ( $email_sent ) {
320 $response = array(
321 'resend_status' => 'successful',
322 'send_to' => $send_to,
323 'notice_message' => '<span class="dashicons dashicons-yes-alt"></span>' . __( 'Email was sent. This page will reload now...', 'admin-site-enhancements' ),
324 );
325 echo json_encode( $response );
326 } else {
327 $response = array(
328 'resend_status' => 'failed',
329 'send_to' => $send_to,
330 'notice_message' => '<span class="dashicons dashicons-warning"></span>' . __( 'Something went wrong. Please check the latest log entry for details. This page will reload now...', 'admin-site-enhancements' ),
331 );
332 echo json_encode( $response );
333 }
334 }
335 }
336 }
337
338 /**
339 * Return 'text/html' email content type for wp_mail_content_type filter hook
340 *
341 * @since 7.1.3
342 */
343 public function return_html_email_type() {
344 return 'text/html';
345 }
346
347 /**
348 * Delete individual email archive
349 *
350 * @since 7.1.4
351 */
352 public function delete_email() {
353 if ( isset( $_REQUEST['action'] ) && 'delete_email' == $_REQUEST['action'] && isset( $_REQUEST['message-id'] ) && !empty( $_REQUEST['message-id'] ) && is_numeric( $_REQUEST['message-id'] ) && isset( $_REQUEST['nonce'] ) && !empty( $_REQUEST['nonce'] ) ) {
354 $db_row_id = intval( sanitize_text_field( $_REQUEST['message-id'] ) );
355 $nonce = sanitize_text_field( $_REQUEST['nonce'] );
356 if ( wp_verify_nonce( $nonce, 'asenha-delete-email-' . $db_row_id ) ) {
357 global $wpdb;
358 $table_name = $wpdb->prefix . 'asenha_email_delivery';
359 // https://developer.wordpress.org/reference/classes/wpdb/delete/
360 $result = $wpdb->delete( $table_name, array(
361 'id' => $db_row_id,
362 ), array('%d') );
363 if ( 1 === $result ) {
364 wp_redirect( admin_url( 'tools.php?page=email-delivery-log&email-deletion=successful&message-id=' . $db_row_id ) );
365 } else {
366 wp_redirect( admin_url( 'tools.php?page=email-delivery-log&email-deletion=failed&message-id=' . $db_row_id ) );
367 }
368 }
369 }
370 }
371
372 /**
373 * Show email deletion notice on deletion success
374 *
375 * @since 7.1.4
376 */
377 public function maybe_show_email_deletion_notice() {
378 $screen = get_current_screen();
379 if ( 'tools_page_email-delivery-log' === $screen->id ) {
380 if ( isset( $_REQUEST['email-deletion'] ) && in_array( $_REQUEST['email-deletion'], array('successful', 'failed') ) && isset( $_REQUEST['message-id'] ) && is_numeric( intval( $_REQUEST['message-id'] ) ) ) {
381 if ( 'successful' == sanitize_text_field( $_REQUEST['email-deletion'] ) ) {
382 ?>
383 <div class="notice notice-success is-dismissible">
384 <p><?php
385 printf(
386 /* translators: %s: email message ID */
387 __( 'Email delivery log entry with the ID %s was successfully deleted.', 'admin-site-enhancements' ),
388 intval( $_REQUEST['message-id'] )
389 );
390 ?>
391 </p>
392 </div>
393 <?php
394 } else {
395 if ( 'failed' == sanitize_text_field( $_REQUEST['email-deletion'] ) ) {
396 ?>
397 <div class="notice notice-error is-dismissible">
398 <p><?php
399 printf(
400 /* translators: %s: email message ID */
401 __( 'Something went wrong. Unable to delete email delivery log entry with the ID %s.', 'admin-site-enhancements' ),
402 intval( $_REQUEST['message-id'] )
403 );
404 ?>
405 </p>
406 </div>
407 <?php
408 }
409 }
410 }
411 }
412 }
413
414 /**
415 * Clear the email delivery log. This will delete all data.
416 *
417 * @since 7.1.4
418 */
419 public function clear_log() {
420 if ( isset( $_REQUEST['action'] ) && 'clear_log' == $_REQUEST['action'] && isset( $_REQUEST['nonce'] ) && !empty( $_REQUEST['nonce'] ) ) {
421 $nonce = sanitize_text_field( $_REQUEST['nonce'] );
422 if ( wp_verify_nonce( $nonce, 'asenha-clear-log-' . get_current_user_id() ) ) {
423 global $wpdb;
424 $table_name = $wpdb->prefix . 'asenha_email_delivery';
425 // https://developer.wordpress.org/reference/classes/wpdb/query/
426 $result = $wpdb->query( "TRUNCATE {$table_name}" );
427 if ( $result ) {
428 wp_redirect( admin_url( 'tools.php?page=email-delivery-log&clear-log=successful' ) );
429 } else {
430 wp_redirect( admin_url( 'tools.php?page=email-delivery-log&clear-log=failed' ) );
431 }
432 }
433 }
434 }
435
436 /**
437 * Show clear log notice on clearing success
438 *
439 * @since 7.1.4
440 */
441 public function maybe_show_clear_log_notice() {
442 $screen = get_current_screen();
443 if ( 'tools_page_email-delivery-log' === $screen->id ) {
444 if ( isset( $_REQUEST['clear-log'] ) && in_array( $_REQUEST['clear-log'], array('successful', 'failed') ) ) {
445 if ( 'successful' == sanitize_text_field( $_REQUEST['clear-log'] ) ) {
446 ?>
447 <div class="notice notice-success is-dismissible">
448 <p><?php
449 echo __( 'Log has been successfully cleared.', 'admin-site-enhancements' );
450 ?></p>
451 </div>
452 <?php
453 } else {
454 if ( 'failed' == sanitize_text_field( $_REQUEST['clear-log'] ) ) {
455 ?>
456 <div class="notice notice-error is-dismissible">
457 <p><?php
458 echo __( 'Something went wrong. Log was not cleared.', 'admin-site-enhancements' );
459 ?></p>
460 </div>
461 <?php
462 }
463 }
464 }
465 }
466 }
467
468 }
469