PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 4.9.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v4.9.0
4.9.0 0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / src / Admin / DashboardWidget.php
wp-mail-smtp / src / Admin Last commit date
DebugEvents 6 days ago EmailSendingErrors 6 days ago Pages 6 days ago Recommendations 6 days ago AdminBarMenu.php 6 days ago Area.php 6 days ago ConnectionSettings.php 6 days ago DashboardWidget.php 6 days ago DomainChecker.php 6 days ago Education.php 6 days ago FlyoutMenu.php 6 days ago Notifications.php 6 days ago PageAbstract.php 6 days ago PageInterface.php 6 days ago ParentPageAbstract.php 6 days ago PluginsInstallSkin.php 6 days ago Review.php 6 days ago SetupWizard.php 6 days ago WooCommerceActiveLayerEducation.php 6 days ago
DashboardWidget.php
780 lines
1 <?php
2
3 namespace WPMailSMTP\Admin;
4
5 use WPMailSMTP\Admin\DebugEvents\DebugEvents;
6 use WPMailSMTP\Helpers\Helpers;
7 use WPMailSMTP\Options;
8 use WPMailSMTP\WP;
9 use WPMailSMTP\Reports\Reports;
10 use WPMailSMTP\Reports\Emails\Summary as SummaryReportEmail;
11
12 /**
13 * Dashboard Widget shows the number of sent emails in WP Dashboard.
14 *
15 * @since 2.9.0
16 */
17 class DashboardWidget {
18
19 /**
20 * Instance slug.
21 *
22 * @since 2.9.0
23 *
24 * @const string
25 */
26 const SLUG = 'dash_widget_lite';
27
28 /**
29 * The WP option key for storing the total number of sent emails.
30 *
31 * @since 2.9.0
32 * @since 3.0.0 Constant moved to Reports class.
33 *
34 * @const string
35 */
36 const SENT_EMAILS_COUNTER_OPTION_KEY = Reports::SENT_EMAILS_COUNTER_OPTION_KEY;
37
38 /**
39 * Constructor.
40 *
41 * @since 2.9.0
42 */
43 public function __construct() {}
44
45 /**
46 * Init class.
47 *
48 * @since 2.9.0
49 */
50 public function init() {
51
52 // Prevent the class initialization, if the dashboard widget hidden setting is enabled.
53 if ( Options::init()->get( 'general', 'dashboard_widget_hidden' ) ) {
54 return;
55 }
56
57 add_action(
58 'admin_init',
59 function() {
60
61 // This widget should be displayed for certain high-level users only.
62 if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) {
63 return;
64 }
65
66 /**
67 * Filters whether the initialization of the dashboard widget should be allowed.
68 *
69 * @since 2.9.0
70 *
71 * @param bool $var If the dashboard widget should be initialized.
72 */
73 if ( ! apply_filters( 'wp_mail_smtp_admin_dashboard_widget', '__return_true' ) ) {
74 return;
75 }
76
77 $this->hooks();
78 }
79 );
80 }
81
82 /**
83 * Widget hooks.
84 *
85 * @since 2.9.0
86 */
87 public function hooks() {
88
89 add_action( 'admin_enqueue_scripts', [ $this, 'widget_scripts' ] );
90 add_action( 'wp_dashboard_setup', [ $this, 'widget_register' ] );
91
92 add_action( 'wp_ajax_wp_mail_smtp_' . static::SLUG . '_save_widget_meta', [ $this, 'save_widget_meta_ajax' ] );
93 add_action(
94 'wp_ajax_wp_mail_smtp_' . static::SLUG . '_enable_summary_report_email',
95 [
96 $this,
97 'enable_summary_report_email_ajax',
98 ]
99 );
100 }
101
102 /**
103 * Load widget-specific scripts.
104 * Load them only on the admin dashboard page.
105 *
106 * @since 2.9.0
107 */
108 public function widget_scripts() {
109
110 $screen = get_current_screen();
111
112 if ( ! isset( $screen->id ) || 'dashboard' !== $screen->id ) {
113 return;
114 }
115
116 $min = WP::asset_min();
117
118 wp_enqueue_style(
119 'wp-mail-smtp-dashboard-widget',
120 wp_mail_smtp()->assets_url . '/css/dashboard-widget.min.css',
121 [],
122 WPMS_PLUGIN_VER
123 );
124
125 wp_enqueue_script(
126 'wp-mail-smtp-chart',
127 wp_mail_smtp()->assets_url . '/js/vendor/chart.min.js',
128 [ 'moment' ],
129 '4.4.9',
130 true
131 );
132
133 wp_enqueue_script(
134 'wp-mail-smtp-chart-adapter',
135 wp_mail_smtp()->assets_url . '/js/vendor/chartjs-adapter-moment.min.js',
136 [ 'moment', 'wp-mail-smtp-chart' ],
137 '1.0.1',
138 true
139 );
140
141 wp_enqueue_script(
142 'wp-mail-smtp-dashboard-widget',
143 wp_mail_smtp()->assets_url . "/js/smtp-dashboard-widget{$min}.js",
144 [ 'jquery', 'wp-mail-smtp-chart', 'wp-mail-smtp-chart-adapter' ],
145 WPMS_PLUGIN_VER,
146 true
147 );
148
149 wp_localize_script(
150 'wp-mail-smtp-dashboard-widget',
151 'wp_mail_smtp_dashboard_widget',
152 [
153 'slug' => static::SLUG,
154 'nonce' => wp_create_nonce( 'wp_mail_smtp_' . static::SLUG . '_nonce' ),
155 ]
156 );
157 }
158
159 /**
160 * Register the widget.
161 *
162 * @since 2.9.0
163 */
164 public function widget_register() {
165
166 global $wp_meta_boxes;
167
168 $widget_key = 'wp_mail_smtp_reports_widget_lite';
169
170 wp_add_dashboard_widget(
171 $widget_key,
172 esc_html__( 'WP Mail SMTP', 'wp-mail-smtp' ),
173 [ $this, 'widget_content' ]
174 );
175
176 // Attempt to place the widget at the top.
177 $normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
178
179 if ( isset( $normal_dashboard[ $widget_key ] ) ) {
180 $widget_instance = [ $widget_key => $normal_dashboard[ $widget_key ] ];
181
182 unset( $normal_dashboard[ $widget_key ] );
183
184 $sorted_dashboard = array_merge( $widget_instance, $normal_dashboard );
185
186 //phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
187 $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
188 }
189 }
190
191 /**
192 * Save a widget meta for a current user using AJAX.
193 *
194 * @since 2.9.0
195 */
196 public function save_widget_meta_ajax() {
197
198 check_admin_referer( 'wp_mail_smtp_' . static::SLUG . '_nonce' );
199
200 if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) {
201 wp_send_json_error();
202 }
203
204 $meta = ! empty( $_POST['meta'] ) ? sanitize_key( $_POST['meta'] ) : '';
205 $value = ! empty( $_POST['value'] ) ? sanitize_key( $_POST['value'] ) : 0;
206
207 $this->widget_meta( 'set', $meta, $value );
208
209 wp_send_json_success();
210 }
211
212 /**
213 * Enable summary report email using AJAX.
214 *
215 * @since 3.0.0
216 */
217 public function enable_summary_report_email_ajax() {
218
219 check_admin_referer( 'wp_mail_smtp_' . static::SLUG . '_nonce' );
220
221 if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_global_options() ) ) {
222 wp_send_json_error();
223 }
224
225 $options = Options::init();
226
227 $data = [
228 'general' => [
229 SummaryReportEmail::SETTINGS_SLUG => false,
230 ],
231 ];
232
233 $options->set( $data, false, false );
234
235 wp_send_json_success();
236 }
237
238 /**
239 * Load widget content.
240 *
241 * @since 2.9.0
242 */
243 public function widget_content() {
244
245 echo '<div class="wp-mail-smtp-dash-widget wp-mail-smtp-dash-widget--lite">';
246
247 $this->widget_content_html();
248
249 echo '</div>';
250 }
251
252 /**
253 * Increment the number of total emails sent by 1.
254 *
255 * @deprecated 3.0.0
256 *
257 * @since 2.9.0
258 */
259 public function increment_sent_email_counter() {
260
261 _deprecated_function( __METHOD__, '3.0.0' );
262 }
263
264 /**
265 * Widget content HTML.
266 *
267 * @since 2.9.0
268 */
269 private function widget_content_html() {
270
271 $hide_graph = (bool) $this->widget_meta( 'get', 'hide_graph' );
272 ?>
273
274 <?php if ( ! $hide_graph ) : ?>
275 <div class="wp-mail-smtp-dash-widget-chart-block-container">
276 <div class="wp-mail-smtp-dash-widget-block wp-mail-smtp-dash-widget-chart-block">
277 <canvas id="wp-mail-smtp-dash-widget-chart" width="554" height="291"></canvas>
278 <div class="wp-mail-smtp-dash-widget-chart-upgrade">
279 <div class="wp-mail-smtp-dash-widget-modal">
280 <a href="#" class="wp-mail-smtp-dash-widget-dismiss-chart-upgrade">
281 <span class="dashicons dashicons-no-alt"></span>
282 </a>
283 <h2><?php esc_html_e( 'View Detailed Email Stats', 'wp-mail-smtp' ); ?></h2>
284 <p><?php esc_html_e( 'Automatically keep track of every email sent from your WordPress site and view valuable statistics right here in your dashboard.', 'wp-mail-smtp' ); ?></p>
285 <p>
286 <a href="<?php echo esc_url( wp_mail_smtp()->get_upgrade_link( [ 'medium' => 'dashboard-widget', 'content' => 'upgrade-to-wp-mail-smtp-pro' ] ) ); // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound ?>" target="_blank" rel="noopener noreferrer" class="button button-primary button-hero">
287 <?php esc_html_e( 'Upgrade to WP Mail SMTP Pro', 'wp-mail-smtp' ); ?>
288 </a>
289 </p>
290 </div>
291 </div>
292 <div class="wp-mail-smtp-dash-widget-overlay"></div>
293 </div>
294 </div>
295 <?php endif; ?>
296
297 <div class="wp-mail-smtp-dash-widget-block wp-mail-smtp-dash-widget-block-settings">
298 <div>
299 <?php $this->email_types_select_html(); ?>
300 </div>
301 <div>
302 <?php
303 $this->timespan_select_html();
304 $this->widget_settings_html();
305 ?>
306 </div>
307 </div>
308
309 <div id="wp-mail-smtp-dash-widget-email-stats-block" class="wp-mail-smtp-dash-widget-block wp-mail-smtp-dash-widget-email-stats-block">
310 <?php $this->email_stats_block(); ?>
311 </div>
312
313 <?php
314 $this->display_after_email_stats_block_content();
315 }
316
317 /**
318 * Display the content after the email stats block.
319 *
320 * @since 3.9.0
321 *
322 * @return void
323 */
324 private function display_after_email_stats_block_content() {
325
326 if ( empty( $this->widget_meta( 'get', 'hide_email_alerts_banner' ) ) ) {
327 // Check if we have error debug events.
328 $error_debug_events_count = DebugEvents::get_error_debug_events_count();
329
330 if ( ! is_wp_error( $error_debug_events_count ) && ! empty( $error_debug_events_count ) ) {
331 $this->show_email_alerts_banner( $error_debug_events_count );
332
333 return;
334 }
335 }
336
337 $hide_summary_report_email_block = (bool) $this->widget_meta( 'get', 'hide_summary_report_email_block' );
338
339 if (
340 SummaryReportEmail::is_disabled() &&
341 ! $hide_summary_report_email_block &&
342 current_user_can( wp_mail_smtp()->get_capability_manage_global_options() )
343 ) {
344 $this->show_summary_report_email_block();
345 }
346
347 $this->show_upgrade_footer();
348 }
349
350 /**
351 * Display the email alerts banner.
352 *
353 * @since 3.9.0
354 *
355 * @param int $error_count The number of debug events error.
356 *
357 * @return void
358 */
359 private function show_email_alerts_banner( $error_count ) {
360
361 ?>
362 <div id="wp-mail-smtp-dash-widget-email-alerts-education" class="wp-mail-smtp-dash-widget-block wp-mail-smtp-dash-widget-email-alerts-education">
363 <div class="wp-mail-smtp-dash-widget-email-alerts-education-error-icon">
364 <?php
365 printf(
366 '<img src="%s" alt="%s"/>',
367 esc_url( wp_mail_smtp()->assets_url . '/images/dash-widget/error-icon.svg' ),
368 esc_attr__( 'Error icon', 'wp-mail-smtp' )
369 );
370 ?>
371 </div>
372 <div class="wp-mail-smtp-dash-widget-email-alerts-education-content">
373 <?php
374 $error_title = sprintf(
375 /* translators: %d - number of failed emails. */
376 _n(
377 'We detected %d failed email in the last 30 days.',
378 'We detected %d failed emails in the last 30 days.',
379 $error_count,
380 'wp-mail-smtp'
381 ),
382 $error_count
383 );
384
385 $error_content = sprintf(
386 /* translators: %s - URL to WPMailSMTP.com. */
387 __( '<a href="%s" target="_blank" rel="noopener noreferrer">Upgrade to Pro</a> and get instant alert notifications when they fail.', 'wp-mail-smtp' ),
388 esc_url( wp_mail_smtp()->get_upgrade_link( [ 'medium' => 'dashboard-widget', 'content' => 'alerts-promo-upgrade-to-pro' ] ) ) // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
389 );
390 ?>
391 <p>
392 <strong><?php echo esc_html( $error_title ); ?></strong><br />
393 <?php
394 echo wp_kses(
395 $error_content,
396 [
397 'a' => [
398 'href' => [],
399 'target' => [],
400 'rel' => [],
401 ],
402 ]
403 );
404 ?>
405 </p>
406 </div>
407
408 <button type="button" id="wp-mail-smtp-dash-widget-dismiss-email-alert-block" class="wp-mail-smtp-dash-widget-dismiss-email-alert-block" title="<?php esc_attr_e( 'Dismiss email alert block', 'wp-mail-smtp' ); ?>">
409 <span class="dashicons dashicons-no-alt"></span>
410 </button>
411 </div>
412 <?php
413 }
414
415 /**
416 * Show the summary report email block.
417 *
418 * @since 3.9.0
419 *
420 * @return void
421 */
422 private function show_summary_report_email_block() {
423
424 ?>
425 <div id="wp-mail-smtp-dash-widget-summary-report-email-block" class="wp-mail-smtp-dash-widget-block wp-mail-smtp-dash-widget-summary-report-email-block">
426 <div>
427 <div class="wp-mail-smtp-dash-widget-summary-report-email-block-setting">
428 <label for="wp-mail-smtp-dash-widget-summary-report-email-enable">
429 <input type="checkbox" id="wp-mail-smtp-dash-widget-summary-report-email-enable">
430 <i class="wp-mail-smtp-dash-widget-loader"></i>
431 <span>
432 <?php
433 echo wp_kses(
434 __( '<b>NEW!</b> Enable Weekly Email Summaries', 'wp-mail-smtp' ),
435 [
436 'b' => [],
437 ]
438 );
439 ?>
440 </span>
441 </label>
442 <a href="<?php echo esc_url( SummaryReportEmail::get_preview_link() ); ?>" target="_blank">
443 <?php esc_html_e( 'View Example', 'wp-mail-smtp' ); ?>
444 </a>
445 <i class="dashicons dashicons-dismiss wp-mail-smtp-dash-widget-summary-report-email-dismiss"></i>
446 </div>
447 <div class="wp-mail-smtp-dash-widget-summary-report-email-block-applied hidden">
448 <i class="wp-mail-smtp-dashicons-yes-alt-green"></i>
449 <span><?php esc_attr_e( 'Weekly Email Summaries have been enabled', 'wp-mail-smtp' ); ?></span>
450 </div>
451 </div>
452 </div>
453 <?php
454 }
455
456 /**
457 * Show the upgrade footer.
458 *
459 * @since 3.9.0
460 *
461 * @return void
462 */
463 private function show_upgrade_footer() {
464
465 $hide_graph = (bool) $this->widget_meta( 'get', 'hide_graph' );
466 ?>
467 <div id="wp-mail-smtp-dash-widget-upgrade-footer" class="wp-mail-smtp-dash-widget-block wp-mail-smtp-dash-widget-upgrade-footer wp-mail-smtp-dash-widget-upgrade-footer--<?php echo ! $hide_graph ? 'hide' : 'show'; ?>">
468 <p>
469 <?php
470 printf(
471 wp_kses( /* translators: %s - URL to WPMailSMTP.com. */
472 __( '<a href="%s" target="_blank" rel="noopener noreferrer">Upgrade to Pro</a> for detailed stats, email logs, and more!', 'wp-mail-smtp' ),
473 [
474 'a' => [
475 'href' => [],
476 'rel' => [],
477 'target' => [],
478 ],
479 ]
480 ),
481 // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
482 esc_url( wp_mail_smtp()->get_upgrade_link( [ 'medium' => 'dashboard-widget', 'content' => 'upgrade-to-pro' ] ) )
483 );
484 ?>
485 </p>
486 </div>
487 <?php
488 }
489
490 /**
491 * Timespan select HTML.
492 *
493 * @since 2.9.0
494 */
495 private function timespan_select_html() {
496
497 ?>
498 <select id="wp-mail-smtp-dash-widget-timespan" class="wp-mail-smtp-dash-widget-select-timespan" title="<?php esc_attr_e( 'Select timespan', 'wp-mail-smtp' ); ?>">
499 <option value="all">
500 <?php esc_html_e( 'All Time', 'wp-mail-smtp' ); ?>
501 </option>
502 <?php foreach ( [ 7, 14, 30 ] as $option ) : ?>
503 <option value="<?php echo absint( $option ); ?>" disabled>
504 <?php /* translators: %d - Number of days. */ ?>
505 <?php echo esc_html( sprintf( _n( 'Last %d day', 'Last %d days', absint( $option ), 'wp-mail-smtp' ), absint( $option ) ) ); ?>
506 </option>
507 <?php endforeach; ?>
508 </select>
509
510 <?php
511 }
512
513 /**
514 * Email types select HTML.
515 *
516 * @since 2.9.0
517 */
518 private function email_types_select_html() {
519
520 $options = [
521 'delivered' => esc_html__( 'Confirmed Emails', 'wp-mail-smtp' ),
522 'sent' => esc_html__( 'Unconfirmed Emails', 'wp-mail-smtp' ),
523 'unsent' => esc_html__( 'Failed Emails', 'wp-mail-smtp' ),
524 ];
525
526 if ( Helpers::mailer_without_send_confirmation() ) {
527 unset( $options['sent'] );
528 $options['delivered'] = esc_html__( 'Sent Emails', 'wp-mail-smtp' );
529 }
530
531 ?>
532 <select id="wp-mail-smtp-dash-widget-email-type" class="wp-mail-smtp-dash-widget-select-email-type" title="<?php esc_attr_e( 'Select email type', 'wp-mail-smtp' ); ?>">
533 <option value="all">
534 <?php esc_html_e( 'All Emails', 'wp-mail-smtp' ); ?>
535 </option>
536 <?php foreach ( $options as $key => $title ) : ?>
537 <option value="<?php echo sanitize_key( $key ); ?>" disabled>
538 <?php echo esc_html( $title ); ?>
539 </option>
540 <?php endforeach; ?>
541 </select>
542
543 <?php
544 }
545
546 /**
547 * Widget settings HTML.
548 *
549 * @since 2.9.0
550 */
551 private function widget_settings_html() {
552
553 ?>
554 <div class="wp-mail-smtp-dash-widget-settings-container">
555 <button id="wp-mail-smtp-dash-widget-settings-button" class="wp-mail-smtp-dash-widget-settings-button button" type="button">
556 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19 19">
557 <path d="M18,11l-2.18,0c-0.17,0.7 -0.44,1.35 -0.81,1.93l1.54,1.54l-2.1,2.1l-1.54,-1.54c-0.58,0.36 -1.23,0.63 -1.91,0.79l0,2.18l-3,0l0,-2.18c-0.68,-0.16 -1.33,-0.43 -1.91,-0.79l-1.54,1.54l-2.12,-2.12l1.54,-1.54c-0.36,-0.58 -0.63,-1.23 -0.79,-1.91l-2.18,0l0,-2.97l2.17,0c0.16,-0.7 0.44,-1.35 0.8,-1.94l-1.54,-1.54l2.1,-2.1l1.54,1.54c0.58,-0.37 1.24,-0.64 1.93,-0.81l0,-2.18l3,0l0,2.18c0.68,0.16 1.33,0.43 1.91,0.79l1.54,-1.54l2.12,2.12l-1.54,1.54c0.36,0.59 0.64,1.24 0.8,1.94l2.17,0l0,2.97Zm-8.5,1.5c1.66,0 3,-1.34 3,-3c0,-1.66 -1.34,-3 -3,-3c-1.66,0 -3,1.34 -3,3c0,1.66 1.34,3 3,3Z"></path>
558 </svg>
559 </button>
560 <div class="wp-mail-smtp-dash-widget-settings-menu">
561 <div class="wp-mail-smtp-dash-widget-settings-menu--style">
562 <h4><?php esc_html_e( 'Graph Style', 'wp-mail-smtp' ); ?></h4>
563 <div>
564 <div class="wp-mail-smtp-dash-widget-settings-menu-item">
565 <input type="radio" id="wp-mail-smtp-dash-widget-settings-style-bar" name="style" value="bar" disabled>
566 <label for="wp-mail-smtp-dash-widget-settings-style-bar"><?php esc_html_e( 'Bar', 'wp-mail-smtp' ); ?></label>
567 </div>
568 <div class="wp-mail-smtp-dash-widget-settings-menu-item">
569 <input type="radio" id="wp-mail-smtp-dash-widget-settings-style-line" name="style" value="line" checked disabled>
570 <label for="wp-mail-smtp-dash-widget-settings-style-line"><?php esc_html_e( 'Line', 'wp-mail-smtp' ); ?></label>
571 </div>
572 </div>
573 </div>
574 <div class="wp-mail-smtp-dash-widget-settings-menu--color">
575 <h4><?php esc_html_e( 'Color Scheme', 'wp-mail-smtp' ); ?></h4>
576 <div>
577 <div class="wp-mail-smtp-dash-widget-settings-menu-item">
578 <input type="radio" id="wp-mail-smtp-dash-widget-settings-color-smtp" name="color" value="smtp" disabled>
579 <label for="wp-mail-smtp-dash-widget-settings-color-smtp"><?php esc_html_e( 'WP Mail SMTP', 'wp-mail-smtp' ); ?></label>
580 </div>
581 <div class="wp-mail-smtp-dash-widget-settings-menu-item">
582 <input type="radio" id="wp-mail-smtp-dash-widget-settings-color-wp" name="color" value="wp" checked disabled>
583 <label for="wp-mail-smtp-dash-widget-settings-color-wp"><?php esc_html_e( 'WordPress', 'wp-mail-smtp' ); ?></label>
584 </div>
585 </div>
586 </div>
587 <button type="button" class="button wp-mail-smtp-dash-widget-settings-menu-save" disabled><?php esc_html_e( 'Save Changes', 'wp-mail-smtp' ); ?></button>
588 </div>
589 </div>
590 <?php
591 }
592
593 /**
594 * Email statistics block.
595 *
596 * @since 2.9.0
597 */
598 private function email_stats_block() {
599
600 $output_data = $this->get_email_stats_data();
601 ?>
602
603 <table id="wp-mail-smtp-dash-widget-email-stats-table" cellspacing="0">
604 <tr>
605 <?php
606 $count = 0;
607 $per_row = 2;
608
609 foreach ( array_values( $output_data ) as $stats ) :
610 if ( ! is_array( $stats ) ) {
611 continue;
612 }
613
614 if ( ! isset( $stats['icon'], $stats['title'] ) ) {
615 continue;
616 }
617
618 // Make some exceptions for mailers without send confirmation functionality.
619 if ( Helpers::mailer_without_send_confirmation() ) {
620 $per_row = 3;
621 }
622
623 // Create new row after every $per_row cells.
624 if ( $count !== 0 && $count % $per_row === 0 ) {
625 echo '</tr><tr>';
626 }
627
628 $count++;
629 ?>
630 <td class="wp-mail-smtp-dash-widget-email-stats-table-cell wp-mail-smtp-dash-widget-email-stats-table-cell--<?php echo esc_attr( $stats['type'] ); ?> wp-mail-smtp-dash-widget-email-stats-table-cell--3">
631 <div class="wp-mail-smtp-dash-widget-email-stats-table-cell-container">
632 <img src="<?php echo esc_url( $stats['icon'] ); ?>" alt="<?php esc_attr_e( 'Table cell icon', 'wp-mail-smtp' ); ?>">
633 <span>
634 <?php echo esc_html( $stats['title'] ); ?>
635 </span>
636 </div>
637 </td>
638 <?php endforeach; ?>
639 </tr>
640 </table>
641
642 <?php
643 }
644
645 /**
646 * Prepare the email stats data.
647 * The text and counts of the email stats.
648 *
649 * @since 2.9.0
650 *
651 * @return array[]
652 */
653 private function get_email_stats_data() {
654
655 $reports = new Reports();
656 $total_sent = $reports->get_total_emails_sent();
657
658 $output_data = [
659 'all' => [
660 'type' => 'all',
661 'icon' => wp_mail_smtp()->assets_url . '/images/dash-widget/wp/total.svg',
662 /* translators: %d number of total emails sent. */
663 'title' => esc_html( sprintf( esc_html__( '%d total', 'wp-mail-smtp' ), $total_sent ) ),
664 ],
665 'delivered' => [
666 'type' => 'delivered',
667 'icon' => wp_mail_smtp()->assets_url . '/images/dash-widget/wp/delivered.svg',
668 /* translators: %s fixed string of 'N/A'. */
669 'title' => esc_html( sprintf( esc_html__( 'Confirmed %s', 'wp-mail-smtp' ), 'N/A' ) ),
670 ],
671 'sent' => [
672 'type' => 'sent',
673 'icon' => wp_mail_smtp()->assets_url . '/images/dash-widget/wp/sent.svg',
674 /* translators: %s fixed string of 'N/A'. */
675 'title' => esc_html( sprintf( esc_html__( 'Unconfirmed %s', 'wp-mail-smtp' ), 'N/A' ) ),
676 ],
677 'unsent' => [
678 'type' => 'unsent',
679 'icon' => wp_mail_smtp()->assets_url . '/images/dash-widget/wp/unsent.svg',
680 /* translators: %s fixed string of 'N/A'. */
681 'title' => esc_html( sprintf( esc_html__( 'Failed %s', 'wp-mail-smtp' ), 'N/A' ) ),
682 ],
683 ];
684
685 if ( Helpers::mailer_without_send_confirmation() ) {
686
687 // Skip the 'unconfirmed sent' section.
688 unset( $output_data['sent'] );
689
690 // Change the 'confirmed sent' section into a general 'sent' section.
691 $output_data['delivered']['title'] = esc_html( /* translators: %s fixed string of 'N/A'. */
692 sprintf( esc_html__( 'Sent %s', 'wp-mail-smtp' ), 'N/A' )
693 );
694 }
695
696 return $output_data;
697 }
698
699 /**
700 * Get/set a widget meta.
701 *
702 * @since 2.9.0
703 *
704 * @param string $action Possible value: 'get' or 'set'.
705 * @param string $meta Meta name.
706 * @param int $value Value to set.
707 *
708 * @return mixed
709 */
710 protected function widget_meta( $action, $meta, $value = 0 ) {
711
712 $allowed_actions = [ 'get', 'set' ];
713
714 if ( ! in_array( $action, $allowed_actions, true ) ) {
715 return false;
716 }
717
718 if ( $action === 'get' ) {
719 return $this->get_widget_meta( $meta );
720 }
721
722 $meta_key = $this->get_widget_meta_key( $meta );
723 $value = sanitize_key( $value );
724
725 if ( 'set' === $action && ! empty( $value ) ) {
726 return update_user_meta( get_current_user_id(), $meta_key, $value );
727 }
728
729 if ( 'set' === $action && empty( $value ) ) {
730 return delete_user_meta( get_current_user_id(), $meta_key );
731 }
732
733 return false;
734 }
735
736 /**
737 * Get the widget meta value.
738 *
739 * @since 3.9.0
740 *
741 * @param string $meta Meta name.
742 *
743 * @return mixed
744 */
745 private function get_widget_meta( $meta ) {
746
747 $defaults = [
748 'hide_graph' => 0,
749 'hide_summary_report_email_block' => 0,
750 'hide_email_alerts_banner' => 0,
751 ];
752
753 $meta_value = get_user_meta( get_current_user_id(), $this->get_widget_meta_key( $meta ), true );
754
755 if ( ! empty( $meta_value ) ) {
756 return $meta_value;
757 }
758
759 if ( isset( $defaults[ $meta ] ) ) {
760 return $defaults[ $meta ];
761 }
762
763 return null;
764 }
765
766 /**
767 * Retrieve the meta key.
768 *
769 * @since 3.9.0
770 *
771 * @param string $meta Meta name.
772 *
773 * @return string
774 */
775 private function get_widget_meta_key( $meta ) {
776
777 return 'wp_mail_smtp_' . static::SLUG . '_' . $meta;
778 }
779 }
780