forked from BjornW/admin-email-as-from-address
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin-email-as-from-address.php
73 lines (66 loc) · 2.28 KB
/
admin-email-as-from-address.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
<?php
/**
* Plugin Name: Use Admin Email as From Address
* Plugin URI: https://burobjorn.nl
* Description: Use the admin email address set in Settings->General as from email address
* Author: Björn Wijers <[email protected]>
* Version: 1.1
* Author URI: https://burobjorn.nl
* License: GPL2 or later
**/
/**
* NOTE:
* This plugin fixes a bug in WordPress 4.6 (and possible version 4.5.3):
*
* If a From email address is *NOT* set *AND* the $_SERVER[ 'SERVER_NAME' ] is empty
* WordPress will generate an invalid email address 'wordpress@'
*
* by explicitly setting the From email address we prevent this bug from
* happening.
*
* See also issue #25239:
* https://core.trac.wordpress.org/ticket/25239
**/
if( ! class_exists( 'AdminEmailAsFromAddress' ) ) {
class AdminEmailAsFromAddress {
function __construct() {
add_filter( 'wp_mail_from', array( $this, 'set_from_email' ) );
add_filter( 'wp_mail_from_name', array( $this, 'set_from_name' ) );
}
/**
* Called by 'wp_mail_from' filter
* Allows setting the From email address
* uses the admin_email option by design, so we're not adding
* more settings. If the email address needs to be changed
* you need to change the 'admin_email' in Settings->General
*
*
* @param string current email address used as from address
* @return string new email address used for from address
*
**/
function set_from_email( $email ) {
$admin_email = get_bloginfo( 'admin_email' );
$mail = empty( $admin_email ) ? $email : $admin_email;
return apply_filters( 'aeafa_mail_from', $mail);
}
/**
* Called by filter 'wp_mail_from_name'
* Allows setting the name used in the From email header
* defaults to WordPress
*
* @param string current name
* @return string new name, defaults to WordPress
*
* @TODO allow to set this in General->Settings under 'admin email'
*
**/
function set_from_name( $name ){
return apply_filters( 'aeafa_mail_from_name', 'WordPress');
}
}
$admin_email_as_from_address = new AdminEmailAsFromAddress;
} else {
error_log( 'Class AdminEmailAsFromAddress already exists. Plugin activation failed' );
}
?>