PluginProbe
Check & Log Email – Easy Email Testing & Mail logging / 2.0.16
Check & Log Email – Easy Email Testing & Mail logging v2.0.16
2.0.16 2.0.15 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 All 41 releases
check-email / include / Core / Check_Email_From_Handler.php
Check_Email_From_Handler.php
103 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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