PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.2.1
Defender Security – Malware Scanner, Login Security & Firewall v6.2.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / component / class-mail.php

class-mail.php in Defender Security – Malware Scanner, Login Security & Firewall 6.2.1, at src/component/class-mail.php

104 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles the generation of email headers and the retrieval of sender names based on notification slugs.
4 *
5 * @package WP_Defender\Component
6 * @since 4.5.0
7 */
8
9 namespace WP_Defender\Component;
10
11 use WP_Defender\Component;
12 use WP_Defender\Model\Notification\Audit_Report;
13 use WP_Defender\Model\Notification\Malware_Report;
14 use WP_Defender\Model\Notification\Tweak_Reminder;
15 use WP_Defender\Integrations\Dashboard_Whitelabel;
16 use WP_Defender\Model\Notification\Firewall_Report;
17 use WP_Defender\Component\Config\Config_Hub_Helper;
18 use WP_Defender\Model\Notification\Malware_Notification;
19 use WP_Defender\Model\Notification\Firewall_Notification;
20
21 /**
22 * Handles email functionalities for WP Defender.
23 */
24 class Mail extends Component {
25
26 /**
27 * Get sender name.
28 *
29 * @param string $notification_slug The slug of the notification.
30 *
31 * @return string The sender's name.
32 */
33 public function get_sender_name( $notification_slug ): string {
34 $whitelabel = new Dashboard_Whitelabel();
35 if ( $whitelabel->can_whitelabel() ) {
36 $plugin_label = $whitelabel->get_plugin_name( Config_Hub_Helper::WDP_ID );
37 if ( false === $plugin_label || '' === $plugin_label ) {
38 $plugin_label = $this->find_feature_name_by_slug( $notification_slug );
39 }
40 } else {
41 $plugin_label = esc_html__( 'Defender', 'defender-security' );
42 }
43
44 return $plugin_label;
45 }
46
47 /**
48 * Finds the feature name associated with a given notification slug.
49 *
50 * @param string $slug The notification slug.
51 *
52 * @return string The feature name associated with the slug.
53 */
54 protected function find_feature_name_by_slug( $slug ) {
55 switch ( $slug ) {
56 case Tweak_Reminder::SLUG:
57 return esc_html__( 'Recommendations', 'defender-security' );
58 case Malware_Notification::SLUG:
59 case Malware_Report::SLUG:
60 return esc_html__( 'Malware Scanning', 'defender-security' );
61 case Firewall_Notification::SLUG:
62 case Firewall_Report::SLUG:
63 return esc_html__( 'Firewall', 'defender-security' );
64 case Audit_Report::SLUG:
65 return esc_html__( 'Audit Logging', 'defender-security' );
66 case 'subscription':
67 return esc_html__( 'Subscription', 'defender-security' );
68 case 'subscribe_confimed':
69 return esc_html__( 'Subscription Confirmed', 'defender-security' );
70 case 'unsubscription':
71 return esc_html__( 'Unsubscription', 'defender-security' );
72 case 'totp':
73 return esc_html__( 'Two-Factor Authentication', 'defender-security' );
74 case Unlock_Me::SLUG_UNLOCK:
75 return Unlock_Me::get_feature_title();
76 default:
77 return '';
78 }
79 }
80
81 /**
82 * No reply email header.
83 * Generate no reply email header with HTML UTF-8 support.
84 *
85 * @param string $from_email The email address to use in the "From" field.
86 * @param string $notification_slug The notification slug used to determine the sender's name.
87 *
88 * @return array An array of headers for the email.
89 */
90 public function get_headers( $from_email, $notification_slug = '' ): array {
91 $from_label = $this->get_sender_name( $notification_slug );
92 $from_email = str_replace( array( "\r", "\n" ), '', $from_email );
93 $from_label = str_replace( array( "\r", "\n" ), '', $from_label );
94 $headers = array(
95 'From: ' . $from_label . ' <' . $from_email . '>',
96 'Content-Type: text/html; charset=UTF-8',
97 );
98
99 return $headers;
100 }
101
102 // Todo: move defender_noreply_email() from functions.php.
103 }
104