PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 1.2
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v1.2
1.7.1 1.7.0 1.6.0 1.5.2 trunk 0.1 0.2.0 0.2.1 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 1.0 1.1 1.2 1.3.1 1.4.0 1.4.1 1.5.0 1.5.1 All 26 releases
flywp / includes / Admin / Email.php

Email.php in FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel 1.2, at includes/Admin/Email.php

120 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FlyWP\Admin;
4
5 use FlyWP\Admin;
6
7 class Email {
8
9 /**
10 * Class constructor.
11 */
12 public function __construct() {
13 add_action( 'load-' . Admin::SCREEN_NAME, [ $this, 'save_settings' ] );
14 add_action( 'load-' . Admin::SCREEN_NAME, [ $this, 'send_test_mail' ] );
15 }
16
17 /**
18 * Save email settings.
19 *
20 * @return void
21 */
22 public function save_settings() {
23 if ( ! isset( $_POST['flywp-email-nonce'] ) ) {
24 return;
25 }
26
27 if ( ! wp_verify_nonce( $_POST['flywp-email-nonce'], 'flywp-email-settings' ) ) {
28 return;
29 }
30
31 if ( ! current_user_can( 'manage_options' ) ) {
32 return;
33 }
34
35 $from_name = isset( $_POST['from_name'] ) ? sanitize_text_field( $_POST['from_name'] ) : '';
36 $from_email = isset( $_POST['from_email'] ) ? sanitize_email( $_POST['from_email'] ) : '';
37
38 update_option(
39 'flywp_email_settings',
40 [
41 'from_name' => $from_name,
42 'from_email' => $from_email,
43 ],
44 false
45 );
46
47 wp_safe_redirect( add_query_arg( [
48 'tab' => 'email',
49 'message' => 'email-settings-saved',
50 ], flywp()->admin->page_url() ) );
51 exit;
52 }
53
54 /**
55 * Send test email.
56 *
57 * @return void
58 */
59 public function send_test_mail() {
60 if ( ! isset( $_POST['flywp-email-test-nonce'] ) ) {
61 return;
62 }
63
64 if ( ! wp_verify_nonce( $_POST['flywp-email-test-nonce'], 'flywp-email-test' ) ) {
65 return;
66 }
67
68 if ( ! current_user_can( 'manage_options' ) ) {
69 return;
70 }
71
72 $to = isset( $_POST['to_email'] ) ? sanitize_email( $_POST['to_email'] ) : '';
73 $is_html = isset( $_POST['html_email'] ) ? true : false;
74
75 $subject = __( 'Test Email from FlyWP', 'flywp' );
76 $headers = [];
77 $message = $this->get_mail_body( $is_html );
78
79 if ( $is_html ) {
80 $headers[] = 'Content-Type: text/html; charset=UTF-8';
81 }
82
83 $sent = wp_mail( $to, $subject, $message, $headers );
84
85 wp_safe_redirect( add_query_arg( [
86 'tab' => 'email',
87 'message' => $sent ? 'test-mail-sent' : 'test-mail-failed',
88 ], flywp()->admin->page_url() ) );
89 exit;
90 }
91
92 /**
93 * Get email body.
94 *
95 * @param bool $is_html
96 *
97 * @return string
98 */
99 private function get_mail_body( $is_html = false ) {
100 if ( !$is_html ) {
101 $message = <<<EOT
102 Hello,
103
104 This is a test email sent from FlyWP to verify the email functionality of your WordPress site.
105
106 If you have received this email, it means the email sending feature is working as expected.
107
108 Thank you for using FlyWP.
109
110 Best regards,
111 FlyWP Team
112 EOT;
113 } else {
114 $message = file_get_contents( FLYWP_PLUGIN_DIR . 'views/email-template.html' );
115 }
116
117 return $message;
118 }
119 }
120