This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
better-wordpress-notifications.php
executable file
·245 lines (187 loc) · 8.19 KB
/
better-wordpress-notifications.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
/*
Plugin Name: Better Notifications for WordPress
Plugin URI: http://wordpress.org/extend/plugins/bnfw/
Description: Send customisable HTML emails to user roles for different WordPress notifications.
Version: 0.2.1 Beta
Author: Voltronik
Author URI: http://www.voltronik.co.uk/
Author Email: [email protected]
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Copyright 2013 Voltronik Web Design ([email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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 St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
hooks which we support
*/
$GLOBALS['BNFW_ACTION_TYPES'] = array("create_term", "publish_post", "comment_post", "user_register", "trackback_post", "pingback_post", "lostpassword_post");
/*
pretty names for the hooks
*/
$GLOBALS['BNFW_ACTION_TYPES_PRETTY'] = array("create_term" => "New Category",
"publish_post" => "Publish / Update Post",
"comment_post" => "New Comment / Awaiting Moderation",
"user_register" => "New User Registration",
"trackback_post" => "New Trackback",
"pingback_post" => "New Pingback",
"lostpassword_post" => "Lost password reset");
// Load Engine
require_once ('includes/bnfw_engine.php');
// Load Settings page
if(is_admin()){
require_once ('includes/admin-page.php');
}
//add_filter('the_content', 'bnfw_debug');
add_action('wp_ajax_bnfw_mail_action', 'bnfw_mail_action');
add_action('wp_ajax_nopriv_bnfw_mail_action', 'bnfw_mail_action');
add_action('create_term', 'bnfw_term_created');
add_action('publish_post', 'bnfw_publish_post');
add_action('comment_post', 'bnfw_comment_post');
add_action('user_register', 'bnfw_user_register');
add_action('trackback_post', 'bnfw_trackback_post');
add_action('pingback_post', 'bnfw_pingback_post');
add_action('lostpassword_post', 'bnfw_lostpassword_post');
add_filter('wp_mail', 'bnfw_disable_emails');
register_activation_hook( __FILE__, 'bnfw_activate' );
function bnfw_mail_action(){
if(isset($_POST['to']))
{
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers[] = 'content-type: text/html';
$headers[] = 'Bcc: '.$to = $_POST['to'];
$headers[] = 'From: '.get_option('blogname').' <'.get_option('admin_email').'>';
wp_mail("", $subject, $message, $headers);
}
}
function bnfw_disable_emails($result = '') {
$bnfw_options = get_option('bnfw_settings');
extract($result);
if($bnfw_options['bnfw_settings_disable_wp'] === "1"){
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
if (strstr(sprintf(__('[%s] New User Registration'), $blogname), $subject)) {
$to = '';
$subject = '';
$message = '';
$headers = '';
$attachments = array ();
return compact('to', 'subject', 'message', 'headers', 'attachments');
}
else if (strstr(sprintf(__('[%s] Password Lost/Changed'), $blogname), $subject)) {
$to = '';
$subject = '';
$message = '';
$headers = '';
$attachments = array ();
return compact('to', 'subject', 'message', 'headers', 'attachments');
}
else if (strstr(sprintf(__('[%s] Comment:'), $blogname), $subject)) {
$to = '';
$subject = '';
$message = '';
$headers = '';
$attachments = array ();
return compact('to', 'subject', 'message', 'headers', 'attachments');
}
else if (strstr(sprintf(__('[%s] Please moderate:'), $blogname), $subject)) {
$to = '';
$subject = '';
$message = '';
$headers = '';
$attachments = array ();
return compact('to', 'subject', 'message', 'headers', 'attachments');
}
}
return $result;
}
function bnfw_activate(){
//set default values
$bnfw_options = get_option('bnfw_settings');
if($bnfw_options === false){
$bnfw_options = array('create_term-administrator' => '1',
'publish_post-administrator' => '1',
'comment_post-administrator' => '1',
'user_register-administrator' => '1',
'trackback_post-administrator' => '1',
'pingback_post-administrator' => '1',
'lostpassword_post-administrator' => '1',
'bnfw_settings_disable_wp' => '1'
);
update_option('bnfw_settings', $bnfw_options);
}
$bnfw_options = get_option('bnfw_custom_email_settings');
if($bnfw_options === false){
$bnfw_options = array('payload-subject-publish_post' => 'A new post has been published!',
'payload-subject-create_term' => 'New category created',
'payload-subject-comment_post' => 'This is a comment notification email',
'payload-subject-user_register' => 'A new user has registered!',
'payload-subject-trackback_post' => 'You have a new trackback!',
'payload-subject-pingback_post' => 'You have a new pingback!',
'payload-subject-lostpassword_post' => '[user_login] has lost their password!',
'payload-body-publish_post' => 'A post was published by <strong>[display_name]</strong> on <strong>[post_date]</strong>
<p>Here\'s an excerpt: <br /></p>
<em>[post_excerpt]</em>',
'payload-body-create_term' => 'A new category has been created called: <strong>[name]</strong>',
'payload-body-comment_post' => 'A new comment was posted by <strong>[comment_author_email]</strong>.
<p>It\'s status has been set to: <strong>[comment_approved]</strong>.</p>',
'payload-body-user_register' => 'Say hello to <strong>[user_login]</strong>!',
'payload-body-trackback_post' => 'From: <strong>[comment_author_url]</strong>',
'payload-body-pingback_post' => 'From: <strong>[comment_author_url]</strong>',
'payload-body-lostpassword_post' => '<strong>[user_login]</strong> has lost their password.
<p>An email has been sent to them so they can reset their password.</p>'
);
update_option('bnfw_custom_email_settings', $bnfw_options);
}
}
function bnfw_term_created($termID){
$the_term = get_term_by('id', $termID, 'category');
bnfw_launch_payload(bnfw_get_recipients_for_type('create_term'), bnfw_get_subject_for_term_created($the_term), bnfw_get_payload_for_term_created($the_term));
}
function bnfw_publish_post($postID){
$the_post = get_post($postID);
bnfw_launch_payload(bnfw_get_recipients_for_type('publish_post'), bnfw_get_subject_for_publish_post($the_post), bnfw_get_payload_for_publish_post($the_post));
}
function bnfw_comment_post($comment_id){
$the_comment = get_comment($comment_id);
if(!bnfw_check_for_spam($the_comment)){
bnfw_launch_payload(bnfw_get_recipients_for_type('comment_post'), bnfw_get_subject_for_comment_post($the_comment), bnfw_get_payload_for_comment_post($the_comment));
}
}
function bnfw_user_register($user_id){
$the_user = get_user_by('id', $user_id);
bnfw_launch_payload(bnfw_get_recipients_for_type('user_register'), bnfw_get_subject_for_user_register($the_user), bnfw_get_payload_for_user_register($the_user));
}
function bnfw_trackback_post($comment_id){
$the_comment = get_comment($comment_id);
if(!bnfw_check_for_spam($the_comment)){
bnfw_launch_payload(bnfw_get_recipients_for_type('trackback_post'), bnfw_get_subject_for_trackback_post($the_comment), bnfw_get_payload_for_trackback_post($the_comment));
}
}
function bnfw_pingback_post($comment_id){
$the_comment = get_comment($comment_id);
if(!bnfw_check_for_spam($the_comment)){
bnfw_launch_payload(bnfw_get_recipients_for_type('pingback_post'), bnfw_get_subject_for_pingback_post($the_comment), bnfw_get_payload_for_pingback_post($the_comment));
}
}
function bnfw_lostpassword_post(){
$user_data = get_user_by( 'email', trim( $_POST['user_login'] ) );
bnfw_launch_payload(bnfw_get_recipients_for_type('lostpassword_post'), bnfw_get_subject_for_lostpassword_post($user_data), bnfw_get_payload_for_lostpassword_post($user_data));
}
function bnfw_debug($content){
$bnfw_options = get_option('bnfw_settings');
if ( !isset( $wp_roles ) )
$wp_roles = new WP_Roles();
var_dump($wp_roles->get_names());
var_dump($bnfw_options);
return $content;
}