-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-from-email.php
More file actions
156 lines (127 loc) · 4.68 KB
/
wp-from-email.php
File metadata and controls
156 lines (127 loc) · 4.68 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/*
Plugin Name: Change From Email
Description: Override the default From: 'WordPress <wordpress@mydomain.com>' name and email address
Version: 1.2.1
Author: Marian Kadanka
Author URI: https://kadanka.net/
Text Domain: wp-from-email
Domain Path: /languages
License: GPL-2.0+
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
GitHub Plugin URI: https://github.com/marian-kadanka/wp-from-email
*/
/**
* Change From Email
* Copyright (C) 2008-2017 Skullbit.com. All rights reserved.
* Copyright (C) 2017-2020 Marian Kadanka. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WPFromEmail' ) ):
class WPFromEmail {
function __construct() {
if ( is_admin() ) {
add_filter( 'plugin_action_links', array( $this, 'action_links' ), 10, 4 );
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
add_action( 'admin_init', array( $this, 'settings_init' ) );
}
add_filter('wp_mail_from', array( $this, 'get_from_email' ) );
add_filter('wp_mail_from_name', array( $this, 'get_from_name' ) );
load_plugin_textdomain( 'wp-from-email', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
function action_links( $links, $file ) {
if ( $file == plugin_basename( __FILE__ ) ) {
array_unshift( $links, '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=marian.kadanka@gmail.com&item_name=Donation+for+Marian+Kadanka" title="' . esc_attr__( 'Donate', 'wp-from-email' ) . '" target="_blank">' . esc_html__( 'Donate', 'wp-from-email' ) . '</a>' );
array_unshift( $links, '<a href="' . network_admin_url( 'options-general.php?page=wp_from_email' ) . '" title="' . esc_attr__( 'Settings', 'wp-from-email' ) . '">' . esc_html__( 'Settings', 'wp-from-email' ) . '</a>' );
}
return $links;
}
function add_admin_menu() {
add_options_page( esc_html__( 'Change From Email Settings', 'wp-from-email' ), esc_html__( 'Change From Email', 'wp-from-email' ), 'manage_options', 'wp_from_email', array( $this, 'options_page' ) );
}
function settings_init() {
register_setting( 'wp_from_email_settings', 'wp_from_email' );
add_settings_section(
'wp_from_email_settings_section',
__( 'Change From Email Settings', 'wp-from-email' ),
array( $this, 'settings_section_callback' ),
'wp_from_email_settings'
);
add_settings_field(
'email',
__( 'From Email', 'wp-from-email' ),
array( $this, 'email_render' ),
'wp_from_email_settings',
'wp_from_email_settings_section'
);
add_settings_field(
'name',
__( 'From Name', 'wp-from-email' ),
array( $this, 'name_render' ),
'wp_from_email_settings',
'wp_from_email_settings_section'
);
}
function email_render() {
$options = get_option( 'wp_from_email' );
?>
<input type='text' name='wp_from_email[email]' value='<?php echo $options['email']; ?>'>
<?php
}
function name_render() {
$options = get_option( 'wp_from_email' );
?>
<input type='text' name='wp_from_email[name]' value='<?php echo $options['name']; ?>'>
<?php
}
function settings_section_callback() {
_e( 'Override the default From: WordPress <wordpress@mydomain.com> name and email address', 'wp-from-email' );
}
function options_page() {
?>
<div class="wrap">
<form action='options.php' method='post'>
<?php
settings_fields( 'wp_from_email_settings' );
do_settings_sections( 'wp_from_email_settings' );
submit_button();
?>
</form>
</div>
<?php
}
function get_from_email( $email ) {
$options = get_option( 'wp_from_email' );
if ( $options && ! empty( $options['email'] ) ) {
return $options['email'];
}
else {
return $email;
}
}
function get_from_name( $name ) {
$options = get_option( 'wp_from_email' );
if ( $options && ! empty( $options['name'] ) ) {
return $options['name'];
}
else {
return $name;
}
}
}
endif;
new WPFromEmail();