PluginProbe
SMTP for SendGrid – YaySMTP / trunk
SMTP for SendGrid – YaySMTP vtrunk
trunk 1.3 1.3.1 1.4 1.5 1.5.1
smtp-sendgrid / includes / PluginCore.php

PluginCore.php in SMTP for SendGrid – YaySMTP trunk, at includes/PluginCore.php

73 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace YaySMTPSendgrid;
3
4 use YaySMTPSendgrid\Helper\Utils;
5
6 defined( 'ABSPATH' ) || exit;
7
8 class PluginCore {
9 protected static $instance = null;
10
11 public static function getInstance() {
12 if ( null == self::$instance ) {
13 self::$instance = new self();
14 self::$instance->doHooks();
15 }
16 return self::$instance;
17 }
18
19 private function doHooks() {
20 global $phpmailer;
21 $phpmailer = new PhpMailerExtends();
22 $this->getProcessor();
23 }
24
25 private function __construct() {}
26
27 public function getProcessor() {
28 add_action( 'phpmailer_init', array( $this, 'doSmtperInit' ) );
29 add_filter( 'wp_mail_from', array( $this, 'getFromAddress' ) );
30 add_filter( 'wp_mail_from_name', array( $this, 'getFromName' ) );
31 }
32
33 public function getDefaultMailFrom() {
34 $sitename = \wp_parse_url( \network_home_url(), PHP_URL_HOST );
35 if ( 'www.' === substr( $sitename, 0, 4 ) ) {
36 $sitename = substr( $sitename, 4 );
37 }
38
39 $from_email = 'wordpress@' . $sitename;
40
41 return $from_email;
42 }
43
44 public function getFromAddress( $email ) {
45 $emailDefault = $this->getDefaultMailFrom();
46 $fromEmail = Utils::getCurrentFromEmail();
47 if ( Utils::getForceFromEmail() == 1 ) {
48 return $fromEmail;
49 }
50 if ( ! empty( $emailDefault ) && $email !== $emailDefault ) {
51 return $email;
52 }
53
54 return $fromEmail;
55 }
56
57 public function getFromName( $name ) {
58 $nameDefault = 'WordPress';
59 $forceFromName = Utils::getForceFromName();
60 if ( 0 == $forceFromName && $name !== $nameDefault ) {
61 return $name;
62 }
63
64 return Utils::getCurrentFromName();
65 }
66
67 public function doSmtperInit( $obj ) {
68 $currentMailer = Utils::getCurrentMailer();
69 $obj->Mailer = $currentMailer;
70 $obj->SMTPSecure  = '';
71 }
72 }
73