This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfromEmail.php
88 lines (75 loc) · 2.04 KB
/
fromEmail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace Rolandinsh;
/**
Plugin Name: From the info email
Plugin URI: https://rolandinsh.lv
Description: Simple replacement for wordpress@example.com to info@example.com
Version: 1.1.0
Requires at least: 3.3
Tested up to: 5.2.2
Author: Rolands Umbrovskis
Author URI: https://umbrovskis.com
License: simplemediacode
License URI: https://simplemediacode.com/license/gpl/
Copyright (C) 2008-2019, Rolands Umbrovskis
*/
try {
new fromEmail();
} catch (Exception $e) {
$eartfromemail_debug = 'Caught exception: fromEmail ' . $e->getMessage() . "\n";
if (apply_filters('eartfromemail_debug_log', defined('WP_DEBUG_LOG') && WP_DEBUG_LOG)) {
error_log(print_r(compact('eartfromemail_debug'), true));
}
}
/*
* fromEmail class
* @since 2.0
*/
class fromEmail
{
var $sitename;
var $sitemail;
var $fromname;
public function __construct()
{
add_filter("wp_mail_from", [&$this, 'mailFrom'], 15);
add_filter("wp_mail_from_name", [&$this, 'fromName'], 15);
$this->sitename = $this->siteName();
$this->sitemail = $this->mailFrom();
$this->fromname = $this->fromName();
}
/**
* Set site name to domain name
* @return string
*/
public function siteName()
{
$sitename = strtolower($_SERVER['SERVER_NAME']);
if (substr($sitename, 0, 4) == 'www.') { // wild guess
$sitename = substr($sitename, 4);
}
return $sitename;
}
/**
* Set email address in "From:" to "info@..."
* @param string $email
* @return string
*/
public function mailFrom($email = '')
{
$sitefront = 'info@';
$siteback = $this->sitename;
$sitefrom = $sitefront . $siteback;
return $sitefrom;
}
/**
* Domain name in "From" part
* @param string $from_name
* @return string
*/
public function fromName($from_name = 'WordPress')
{
$sitename = $this->sitename;
return $sitename ? '[' . $sitename . ']' : $from_name;
}
}