PluginProbe ʕ •ᴥ•ʔ
Check & Log Email – Easy Email Testing & Mail logging / trunk
Check & Log Email – Easy Email Testing & Mail logging vtrunk
1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 2.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.13.1 2.0.13.2 2.0.14 2.0.2 2.0.3 2.0.4 2.0.5 2.0.5.1 2.0.6 2.0.7 2.0.8 2.0.9 trunk 0.5.7 0.6.0 0.6.1 0.6.2 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.12.1 1.0.13 1.0.13.1 1.0.2 1.0.3
check-email / include / Core / Check_Email_From_Handler.php
check-email / include / Core Last commit date
DB 1 month ago Request 1 month ago UI 1 month ago Auth.php 1 month ago Check_Email_Admin_Capability_Giver.php 1 month ago Check_Email_Export_Log.php 1 month ago Check_Email_From_Handler.php 1 month ago Check_Email_Log.php 1 month ago Check_Email_Logger.php 1 month ago Check_Email_Multisite.php 1 month ago Check_Email_Review.php 1 month ago Loadie.php 1 month ago
Check_Email_From_Handler.php
103 lines
1 <?php namespace CheckEmail\Core;
2
3 defined( 'ABSPATH' ) || exit; // Exit if accessed directly
4
5 class Check_Email_From_Handler {
6
7 public $options;
8 /**
9 * Constructor
10 */
11 public function __construct() {
12
13 $this->options = get_option('check-email-log-core', false);
14 if (is_multisite()) {
15 $smtp_options = get_site_option( 'check-email-log-global-smtp');
16 if ( isset($smtp_options['enable_global']) && ! empty($smtp_options['enable_global'] ) ) {
17 $this->options = $smtp_options;
18 }
19 }
20
21
22 add_filter( 'wp_mail', array( $this, 'override_values'), 15 );
23 add_filter( 'wp_mail_from', array($this, 'set_wp_mail_from' ), 99 );
24 add_filter( 'wp_mail_from_name', array($this, 'set_wp_mail_from_name' ), 99 );
25 }
26
27
28 /**
29 * Overrides the current wp_mail_from with the one from settings.
30 *
31 * @param String $email - Wordpress current mail from address.
32 * @return String $email - "From" email address set in settings if it exists, else return the $email unchanged
33 *
34 * @since 1.0.5
35 */
36 public function set_wp_mail_from( $email ){
37 if( $this->override_enabled() && isset( $this->options['email_from_email'] ) && '' != $this->options['email_from_email']){
38 return $this->options['email_from_email'];
39 }
40
41 return $email;
42 }
43
44 /**
45 * Overrides the current wp_mail_from_name with the one from settings.
46 *
47 * @param String $name - Wordpress current mail from name.
48 * @return String $name - "From" name set in settings if it exists, else return the $name unchanged
49 *
50 * @since 1.0.5
51 */
52 public function set_wp_mail_from_name( $name ){
53 if( $this->override_enabled() && isset( $this->options['email_from_name'] ) && '' != $this->options['email_from_name']){
54 return $this->options['email_from_name'];
55 }
56
57 return $name;
58 }
59 /**
60 * Check if the setting to override the default from email and from name is active.
61 *
62 * @since 1.0.5
63 */
64 public function override_enabled(){
65
66 if( $this->options && isset( $this->options['override_emails_from'] ) && $this->options['override_emails_from'] ){
67 return true;
68 }
69
70 return false;
71 }
72
73 /**
74 * Replaces the current wp_mail $headers with the values from settings.
75 *
76 * @param Array $headers - Wordpress current mail headers
77 * @return Array $headers - New headers from settings
78 *
79 * @since 1.0.5
80 */
81 public function override_values( $headers ) {
82 if( $this->override_enabled() && isset( $this->options['email_from_email'] ) && '' != $this->options['email_from_email']){
83
84 $headers['headers'] = "MIME-Version: 1.0\r\n";
85
86 $email = $this->options['email_from_email'];
87
88 if( $this->override_enabled() && isset( $this->options['email_from_name'] ) && '' != $this->options['email_from_name'] ){
89
90 $headers['headers'] .= "From: " . $this->options['email_from_name'] . " <". $email .">\r\n" ;
91 }else{
92
93 $headers['headers'] .= "From: <". $email .">\r\n" ;
94 }
95
96 $headers['headers'] .= "Content-Type: text/html; charset=\"UTF-8\"\r\n";
97 }
98
99
100 return $headers;
101 }
102 }
103