Better Notifications for WordPress - Version 1.7.3

Version Description

  • 10th April 2019 =
  • Added: New Notification - 'User Email Changed - For Admin'. This is sent to an admin after a user has successfully changed and confirmed a new email address.
  • Added: New Notification - 'User Email Changed Confirmation - For User'. This is sent to a user in order for them to confirm a change to their email address.
  • Added: You can now Enable or Disable a notification by hovering over it on the 'All Notifications' screen as well as enabling or disabling notifications in bulk from the Bulk Actions dropdown menu.
  • Fixed: The 'User Email Changed - For User' and 'User Password Changed' notifications were no longer being disabled when attempting to override it since WordPress 5.0.
  • Fixed: An issue where the new Block Editor (Gutenberg) caused double notifications upon publishing a post. Better support for Gutenberg will be coming this year. For now, it is recommended to use the Classic Editor plugin.
  • Fixed: The 'New User Registration - For Admin' and 'New User Registration - For User' notifications should work better now after the changes that were made in 1.7.
  • Fixed: The 'Send this Notification to the Author' checkbox was missing from the 'New Comment' notification.
  • Fixed: The [comment_moderation_link] shortcode was outputting blank when used on the 'Post New Comment Awaiting Moderation' notification and sent to non-Administrator user roles.
  • Fixed: The [edit_post] shortcode was escaping ampersands in the URL.
Download this release

Release Info

Developer voltronik
Plugin Icon 128x128 Better Notifications for WordPress
Version 1.7.3
Comparing to
See all releases

Code changes from version 1.7.2 to 1.7.3

README.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: voltronik
3
  Donate link: https://betternotificationsforwp.com/donate/
4
  Tags: notification, email, push, sms, alert, HTML, customize, bulk, trigger, CC, BCC
5
  Requires at least: 4.0
6
- Tested up to: 5.0
7
  Requires PHP: 5.6
8
- Stable tag: 1.7.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -52,6 +52,7 @@ The notifications that are currently available to use are:
52
  * New User Registration - For Admin
53
  * User Lost Password - For Admin
54
  * Password Changed - For Admin
 
55
  * User Role Changed - For Admin
56
  * WordPress Core Automatic Background Updates
57
  * Privacy – Confirm Action: Export Data Request – For Admin
@@ -63,6 +64,7 @@ The notifications that are currently available to use are:
63
  * New User - Post-registration Email
64
  * User Lost Password - For User
65
  * Password Changed - For User
 
66
  * User Email Changed - For User
67
  * User Role Changed - For User
68
  * Comment Reply
@@ -113,6 +115,7 @@ The notifications that are currently available to use are:
113
  * New Term
114
 
115
  **Multisite ([Multisite Add-on](https://betternotificationsforwp.com/downloads/multisite/))**
 
116
  * New Site Activated or Created - For Network Admin
117
  * New User Created - For Network Admin
118
  * Network Admin Email Change Attempted - For New Network Admin
@@ -148,6 +151,10 @@ If you'd like to see a notification in the list above, please drop me a line in
148
 
149
  > Full Documentation for BNFW can be found [here](https://betternotificationsforwp.com/documentation/ "Documentation for Better Notifications for WordPress").
150
 
 
 
 
 
151
  = What are shortcodes? Where can I use them in this plugin? =
152
 
153
  Shortcodes are text in square brackets that output content of some kind. For example, if you want to add the content of a post to a notification for 'New Post Published', you can use the `[post_content]` shortcode to display this in the email that is sent out.
@@ -209,6 +216,17 @@ Yes, of course! The plugin is completely translation-friendly and if you send me
209
 
210
  == Changelog ==
211
 
 
 
 
 
 
 
 
 
 
 
 
212
  = 1.7.2 - 21st November 2018 =
213
  * Fixed: WYSIWYG editor and meta box compatibility for Gutenberg. After the public release of WordPress 5.0 BNFW will continue to use the Classic Editor, as opposed to the new block editor.
214
  * Fixed: New Comment Awaiting Moderation notifications weren't being sent to the Post Author, where selected.
3
  Donate link: https://betternotificationsforwp.com/donate/
4
  Tags: notification, email, push, sms, alert, HTML, customize, bulk, trigger, CC, BCC
5
  Requires at least: 4.0
6
+ Tested up to: 5.1
7
  Requires PHP: 5.6
8
+ Stable tag: 1.7.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
52
  * New User Registration - For Admin
53
  * User Lost Password - For Admin
54
  * Password Changed - For Admin
55
+ * User Email Changed - For Admin
56
  * User Role Changed - For Admin
57
  * WordPress Core Automatic Background Updates
58
  * Privacy – Confirm Action: Export Data Request – For Admin
64
  * New User - Post-registration Email
65
  * User Lost Password - For User
66
  * Password Changed - For User
67
+ * User Email Changed Confirmation - For User
68
  * User Email Changed - For User
69
  * User Role Changed - For User
70
  * Comment Reply
115
  * New Term
116
 
117
  **Multisite ([Multisite Add-on](https://betternotificationsforwp.com/downloads/multisite/))**
118
+
119
  * New Site Activated or Created - For Network Admin
120
  * New User Created - For Network Admin
121
  * Network Admin Email Change Attempted - For New Network Admin
151
 
152
  > Full Documentation for BNFW can be found [here](https://betternotificationsforwp.com/documentation/ "Documentation for Better Notifications for WordPress").
153
 
154
+ = Is this plugin compatible with the new Block Editor (Gutenberg) in WordPress 5? =
155
+
156
+ Yes and no. Most notifications work but full support can't be guaranteed for all notifications at the moment. Full support is on the roadmap but for the time being, I'd recommend using the [Classic Editor plugin](https://wordpress.org/plugins/classic-editor/) with BNFW.
157
+
158
  = What are shortcodes? Where can I use them in this plugin? =
159
 
160
  Shortcodes are text in square brackets that output content of some kind. For example, if you want to add the content of a post to a notification for 'New Post Published', you can use the `[post_content]` shortcode to display this in the email that is sent out.
216
 
217
  == Changelog ==
218
 
219
+ = 1.7.3 - 10th April 2019 =
220
+ * Added: New Notification - 'User Email Changed - For Admin'. This is sent to an admin after a user has successfully changed and confirmed a new email address.
221
+ * Added: New Notification - 'User Email Changed Confirmation - For User'. This is sent to a user in order for them to confirm a change to their email address.
222
+ * Added: You can now Enable or Disable a notification by hovering over it on the 'All Notifications' screen as well as enabling or disabling notifications in bulk from the Bulk Actions dropdown menu.
223
+ * Fixed: The 'User Email Changed - For User' and 'User Password Changed' notifications were no longer being disabled when attempting to override it since WordPress 5.0.
224
+ * Fixed: An issue where the new Block Editor (Gutenberg) caused double notifications upon publishing a post. Better support for Gutenberg will be coming this year. For now, it is recommended to use the [Classic Editor](https://wordpress.org/plugins/classic-editor/) plugin.
225
+ * Fixed: The 'New User Registration - For Admin' and 'New User Registration - For User' notifications should work better now after the changes that were made in 1.7.
226
+ * Fixed: The 'Send this Notification to the Author' checkbox was missing from the 'New Comment' notification.
227
+ * Fixed: The `[comment_moderation_link]` shortcode was outputting blank when used on the 'Post – New Comment Awaiting Moderation' notification and sent to non-Administrator user roles.
228
+ * Fixed: The `[edit_post]` shortcode was escaping ampersands in the URL.
229
+
230
  = 1.7.2 - 21st November 2018 =
231
  * Fixed: WYSIWYG editor and meta box compatibility for Gutenberg. After the public release of WordPress 5.0 BNFW will continue to use the Classic Editor, as opposed to the new block editor.
232
  * Fixed: New Comment Awaiting Moderation notifications weren't being sent to the Post Author, where selected.
assets/js/bnfw.js CHANGED
@@ -59,7 +59,7 @@ jQuery(document).ready(function($) {
59
 
60
  if ( 'reply-comment' === notification || notification.startsWith( 'commentreply-' ) ||
61
  'new-user' === notification || 'welcome-email' === notification || 'user-password' === notification ||
62
- 'password-changed' === notification || 'email-changed' === notification || 'user-role' === notification ||
63
  'ca-export-data' === notification || 'ca-erase-data' === notification ||
64
  'uc-export-data' === notification || 'uc-erase-data' === notification ||
65
  'data-export' === notification || 'data-erased' === notification ||
@@ -76,19 +76,24 @@ jQuery(document).ready(function($) {
76
  if ( 'multisite-new-user-created' === notification || 'multisite-site-created' === notification || 'multisite-site-deleted' === notification ||
77
  'multisite-site-admin-email-change-attempted' === notification || 'multisite-network-admin-email-change-attempted' === notification ||
78
  'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
79
- 'ca-export-data' === notification || 'ca-erase-data' === notification ) {
80
 
81
  $( '#subject-wrapper' ).hide();
82
  }
83
  } else if ( 'new-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ||
84
  'admin-password' === notification || 'admin-user' === notification || 'admin-role' === notification ) {
85
 
86
- $('#post-author').hide();
 
 
 
 
 
87
  $('#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop, #current-user').show();
88
  toggle_fields();
89
  toggle_users();
90
  $( '#user-password-msg' ).hide();
91
- } else if ( 'admin-password-changed' === notification || 'core-updated' === notification ) {
92
  $( '#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop' ).show();
93
  toggle_fields();
94
  toggle_users();
@@ -123,7 +128,7 @@ jQuery(document).ready(function($) {
123
 
124
  if ( 'reply-comment' === notification || notification.startsWith( 'commentreply-' ) ||
125
  'new-user' === notification || 'welcome-email' === notification || 'user-password' === notification ||
126
- 'password-changed' === notification || 'email-changed' === notification || 'user-role' === notification ||
127
  'ca-export-data' === notification || 'ca-erase-data' === notification ||
128
  'uc-export-data' === notification || 'uc-erase-data' === notification ||
129
  'data-export' === notification || 'data-erased' === notification ||
@@ -140,18 +145,24 @@ jQuery(document).ready(function($) {
140
  if ( 'multisite-new-user-created' === notification || 'multisite-site-created' === notification || 'multisite-site-deleted' === notification ||
141
  'multisite-site-admin-email-change-attempted' === notification || 'multisite-network-admin-email-change-attempted' === notification ||
142
  'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
143
- 'ca-export-data' === notification || 'ca-erase-data' === notification ) {
144
 
145
  $( '#subject-wrapper' ).hide();
146
  }
147
  } else if ( 'new-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ||
148
  'admin-password' === notification || 'admin-user' === notification || 'admin-role' === notification ) {
149
- $('#post-author').hide();
 
 
 
 
 
 
150
  $('#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop, #current-user').show();
151
  $('#user-password-msg').hide();
152
  toggle_fields();
153
  toggle_users();
154
- } else if ( 'admin-password-changed' === notification || 'core-updated' === notification ) {
155
  $( '#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop' ).show();
156
  toggle_fields();
157
  toggle_users();
@@ -197,8 +208,6 @@ jQuery(document).ready(function($) {
197
 
198
  switch( notification ) {
199
  case 'new-comment':
200
- case 'moderate-comment':
201
- case 'moderate-post-comment':
202
  case 'new-trackback':
203
  case 'new-pingback':
204
  case 'reply-comment':
@@ -206,8 +215,10 @@ jQuery(document).ready(function($) {
206
  case 'user-password':
207
  case 'admin-password':
208
  case 'admin-password-changed':
 
209
  case 'password-changed':
210
  case 'email-changed':
 
211
  case 'new-user':
212
  case 'welcome-email':
213
  case 'user-role':
@@ -248,7 +259,7 @@ jQuery(document).ready(function($) {
248
  notification_slug = 'moderate-comment';
249
  break;
250
  case 'commentreply':
251
- notification_slug = splited[0] + '-post';
252
  break;
253
  case 'newterm':
254
  notification_slug = 'newterm-category';
@@ -338,6 +349,25 @@ jQuery(document).ready(function($) {
338
  '[global_site_url]';
339
  break;
340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
  case 'email-changed':
342
  subject = '[[global_site_title]] Notice of Email Change';
343
  body = 'Hi [user_nicename], <br>' +
59
 
60
  if ( 'reply-comment' === notification || notification.startsWith( 'commentreply-' ) ||
61
  'new-user' === notification || 'welcome-email' === notification || 'user-password' === notification ||
62
+ 'password-changed' === notification || 'email-changed' === notification || 'email-changing' === notification || 'user-role' === notification ||
63
  'ca-export-data' === notification || 'ca-erase-data' === notification ||
64
  'uc-export-data' === notification || 'uc-erase-data' === notification ||
65
  'data-export' === notification || 'data-erased' === notification ||
76
  if ( 'multisite-new-user-created' === notification || 'multisite-site-created' === notification || 'multisite-site-deleted' === notification ||
77
  'multisite-site-admin-email-change-attempted' === notification || 'multisite-network-admin-email-change-attempted' === notification ||
78
  'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
79
+ 'ca-export-data' === notification || 'ca-erase-data' === notification || 'email-changing' === notification ) {
80
 
81
  $( '#subject-wrapper' ).hide();
82
  }
83
  } else if ( 'new-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ||
84
  'admin-password' === notification || 'admin-user' === notification || 'admin-role' === notification ) {
85
 
86
+ if ( 'new-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ) {
87
+ $('#post-author').show();
88
+ } else {
89
+ $('#post-author').hide();
90
+ }
91
+
92
  $('#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop, #current-user').show();
93
  toggle_fields();
94
  toggle_users();
95
  $( '#user-password-msg' ).hide();
96
+ } else if ( 'admin-password-changed' === notification || 'admin-email-changed' === notification || 'core-updated' === notification ) {
97
  $( '#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop' ).show();
98
  toggle_fields();
99
  toggle_users();
128
 
129
  if ( 'reply-comment' === notification || notification.startsWith( 'commentreply-' ) ||
130
  'new-user' === notification || 'welcome-email' === notification || 'user-password' === notification ||
131
+ 'password-changed' === notification || 'email-changed' === notification || 'email-changing' === notification || 'user-role' === notification ||
132
  'ca-export-data' === notification || 'ca-erase-data' === notification ||
133
  'uc-export-data' === notification || 'uc-erase-data' === notification ||
134
  'data-export' === notification || 'data-erased' === notification ||
145
  if ( 'multisite-new-user-created' === notification || 'multisite-site-created' === notification || 'multisite-site-deleted' === notification ||
146
  'multisite-site-admin-email-change-attempted' === notification || 'multisite-network-admin-email-change-attempted' === notification ||
147
  'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
148
+ 'ca-export-data' === notification || 'ca-erase-data' === notification || 'email-changing' === notification ) {
149
 
150
  $( '#subject-wrapper' ).hide();
151
  }
152
  } else if ( 'new-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ||
153
  'admin-password' === notification || 'admin-user' === notification || 'admin-role' === notification ) {
154
+
155
+ if ( 'new-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ) {
156
+ $('#post-author').show();
157
+ } else {
158
+ $('#post-author').hide();
159
+ }
160
+
161
  $('#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop, #current-user').show();
162
  $('#user-password-msg').hide();
163
  toggle_fields();
164
  toggle_users();
165
+ } else if ( 'admin-password-changed' === notification || 'admin-email-changed' === notification || 'core-updated' === notification ) {
166
  $( '#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop' ).show();
167
  toggle_fields();
168
  toggle_users();
208
 
209
  switch( notification ) {
210
  case 'new-comment':
 
 
211
  case 'new-trackback':
212
  case 'new-pingback':
213
  case 'reply-comment':
215
  case 'user-password':
216
  case 'admin-password':
217
  case 'admin-password-changed':
218
+ case 'admin-email-changed':
219
  case 'password-changed':
220
  case 'email-changed':
221
+ case 'email-changing':
222
  case 'new-user':
223
  case 'welcome-email':
224
  case 'user-role':
259
  notification_slug = 'moderate-comment';
260
  break;
261
  case 'commentreply':
262
+ notification_slug = 'reply-comment';
263
  break;
264
  case 'newterm':
265
  notification_slug = 'newterm-category';
349
  '[global_site_url]';
350
  break;
351
 
352
+ case 'email-changing':
353
+ subject = '[[global_site_title]] New Email Address';
354
+ body = 'Hi [user_nicename], <br>' +
355
+ '<br>' +
356
+ 'You recently requested to have the email address on your account changed.' +
357
+ '<br>' +
358
+ 'If this is correct, please click on the following link to change it:' +
359
+ '<br>' +
360
+ '[global_site_url]/wp-admin/profile.php' +
361
+ '<br>' +
362
+ 'You can safely ignore and delete this email if you do not want to take this action.' +
363
+ '<br>' +
364
+ 'This email has been sent to [global_user_email]' +
365
+ '<br>' +
366
+ 'Regards, <br>' +
367
+ 'All at [global_site_title] <br>' +
368
+ '[global_site_url]';
369
+ break;
370
+
371
  case 'email-changed':
372
  subject = '[[global_site_title]] Notice of Email Change';
373
  body = 'Hi [user_nicename], <br>' +
bnfw.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Better Notifications for WordPress
4
  * Plugin URI: https://wordpress.org/plugins/bnfw/
5
  * Description: Supercharge your WordPress notifications using a WYSIWYG editor and shortcodes. Default and new notifications available. Add more power with Add-ons.
6
- * Version: 1.7.2
7
  * Author: Made with Fuel
8
  * Author URI: https://betternotificationsforwp.com/
9
  * Author Email: hello@betternotificationsforwp.com
@@ -14,7 +14,7 @@
14
  */
15
 
16
  /**
17
- * Copyright © 2018 Made with Fuel Ltd. (hello@betternotificationsforwp.com)
18
  * This program is free software; you can redistribute it and/or modify
19
  * it under the terms of the GNU General Public License, version 2, as
20
  * published by the Free Software Foundation.
@@ -139,7 +139,7 @@ class BNFW {
139
  add_action( 'future_to_publish' , array( $this, 'publish_post' ) );
140
  add_action( 'pending_to_publish' , array( $this, 'publish_post' ) );
141
  add_action( 'private_to_publish' , array( $this, 'publish_post' ) );
142
- add_action( 'acf/submit_form' , array( $this, 'acf_submit_form' ), 10, 2 );
143
 
144
  add_action( 'publish_to_publish' , array( $this, 'update_post' ) );
145
  add_action( 'private_to_private' , array( $this, 'update_post' ) );
@@ -151,7 +151,7 @@ class BNFW {
151
  add_action( 'trackback_post' , array( $this, 'trackback_post' ) );
152
  add_action( 'pingback_post' , array( $this, 'pingback_post' ) );
153
 
154
- add_filter( 'wp_new_user_notification_email_admin', array( $this, 'handle_user_registered_admin_email' ), 10, 3 );
155
 
156
  add_action( 'user_register' , array( $this, 'welcome_email' ) );
157
  add_action( 'set_user_role' , array( $this, 'user_role_changed' ), 10, 3 );
@@ -165,8 +165,13 @@ class BNFW {
165
  add_filter( 'retrieve_password_message' , array( $this, 'change_password_email_message' ), 10, 4 );
166
 
167
  add_action( 'after_password_reset' , array( $this, 'on_password_reset' ) );
 
 
168
  add_filter( 'password_change_email' , array( $this, 'on_password_changed' ), 10, 2 );
 
 
169
  add_filter( 'email_change_email' , array( $this, 'on_email_changed' ), 10, 2 );
 
170
 
171
  add_filter( 'auto_core_update_email' , array( $this, 'on_core_updated' ), 10, 4 );
172
 
@@ -352,6 +357,11 @@ class BNFW {
352
  * @param unknown $post
353
  */
354
  function update_post( $post ) {
 
 
 
 
 
355
  $post_id = $post->ID;
356
  $post_type = $post->post_type;
357
 
@@ -551,6 +561,25 @@ class BNFW {
551
  }
552
  }
553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
  /**
555
  * On Password Changed.
556
  *
@@ -565,6 +594,35 @@ class BNFW {
565
  return $this->handle_filtered_data_notification( 'password-changed', $email_data, $user['ID'] );
566
  }
567
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
  /**
569
  * On Email Changed.
570
  *
@@ -579,6 +637,24 @@ class BNFW {
579
  return $this->handle_filtered_data_notification( 'email-changed', $email_data, $user['ID'] );
580
  }
581
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
582
  /**
583
  * Send notification on core updated event.
584
  *
3
  * Plugin Name: Better Notifications for WordPress
4
  * Plugin URI: https://wordpress.org/plugins/bnfw/
5
  * Description: Supercharge your WordPress notifications using a WYSIWYG editor and shortcodes. Default and new notifications available. Add more power with Add-ons.
6
+ * Version: 1.7.3
7
  * Author: Made with Fuel
8
  * Author URI: https://betternotificationsforwp.com/
9
  * Author Email: hello@betternotificationsforwp.com
14
  */
15
 
16
  /**
17
+ * Copyright © 2019 Made with Fuel Ltd. (hello@betternotificationsforwp.com)
18
  * This program is free software; you can redistribute it and/or modify
19
  * it under the terms of the GNU General Public License, version 2, as
20
  * published by the Free Software Foundation.
139
  add_action( 'future_to_publish' , array( $this, 'publish_post' ) );
140
  add_action( 'pending_to_publish' , array( $this, 'publish_post' ) );
141
  add_action( 'private_to_publish' , array( $this, 'publish_post' ) );
142
+ // add_action( 'acf/submit_form' , array( $this, 'acf_submit_form' ), 10, 2 );
143
 
144
  add_action( 'publish_to_publish' , array( $this, 'update_post' ) );
145
  add_action( 'private_to_private' , array( $this, 'update_post' ) );
151
  add_action( 'trackback_post' , array( $this, 'trackback_post' ) );
152
  add_action( 'pingback_post' , array( $this, 'pingback_post' ) );
153
 
154
+ add_action( 'user_register', array( $this, 'user_register' ) );
155
 
156
  add_action( 'user_register' , array( $this, 'welcome_email' ) );
157
  add_action( 'set_user_role' , array( $this, 'user_role_changed' ), 10, 3 );
165
  add_filter( 'retrieve_password_message' , array( $this, 'change_password_email_message' ), 10, 4 );
166
 
167
  add_action( 'after_password_reset' , array( $this, 'on_password_reset' ) );
168
+
169
+ add_filter( 'send_password_change_email', array( $this, 'should_password_changed_email_be_sent' ), 10, 3 );
170
  add_filter( 'password_change_email' , array( $this, 'on_password_changed' ), 10, 2 );
171
+
172
+ add_filter( 'send_email_change_email', array( $this, 'should_email_changed_email_be_sent' ), 10, 3 );
173
  add_filter( 'email_change_email' , array( $this, 'on_email_changed' ), 10, 2 );
174
+ add_filter( 'new_user_email_content', array( $this, 'on_email_changing' ), 10, 2 );
175
 
176
  add_filter( 'auto_core_update_email' , array( $this, 'on_core_updated' ), 10, 4 );
177
 
357
  * @param unknown $post
358
  */
359
  function update_post( $post ) {
360
+ // Block editor sends duplicate requests on post update.
361
+ if ( ( isset( $_GET['meta-box-loader'] ) || isset( $_GET['meta_box'] ) ) ) {
362
+ return;
363
+ }
364
+
365
  $post_id = $post->ID;
366
  $post_type = $post->post_type;
367
 
561
  }
562
  }
563
 
564
+ /**
565
+ * Should the password changed email be sent?
566
+ *
567
+ * @param $send
568
+ * @param $user
569
+ * @param $userdata
570
+ *
571
+ * @return bool
572
+ */
573
+ public function should_password_changed_email_be_sent( $send, $user, $userdata ) {
574
+ $bnfw = BNFW::factory();
575
+
576
+ if ( ! $send ) {
577
+ return $send;
578
+ }
579
+
580
+ return ! $bnfw->notifier->is_notification_disabled( 'password-changed' );
581
+ }
582
+
583
  /**
584
  * On Password Changed.
585
  *
594
  return $this->handle_filtered_data_notification( 'password-changed', $email_data, $user['ID'] );
595
  }
596
 
597
+ /**
598
+ * Should the email changed email be sent?
599
+ *
600
+ * @param $send
601
+ * @param $user
602
+ * @param $userdata
603
+ *
604
+ * @return bool
605
+ */
606
+ public function should_email_changed_email_be_sent( $send, $user, $userdata ) {
607
+ $bnfw = BNFW::factory();
608
+
609
+ if ( $bnfw->notifier->notification_exists( 'admin-email-changed', false ) ) {
610
+ $notifications = $bnfw->notifier->get_notifications( 'admin-email-changed' );
611
+
612
+ if ( count( $notifications ) > 0 ) {
613
+ // Ideally there should be only one notification for this type.
614
+ // If there are multiple notification then we will read data about only the last one
615
+ $bnfw->engine->send_notification( $bnfw->notifier->read_settings( end( $notifications )->ID ), $user['ID'] );
616
+ }
617
+ }
618
+
619
+ if ( ! $send ) {
620
+ return $send;
621
+ }
622
+
623
+ return ! $bnfw->notifier->is_notification_disabled( 'email-changed' );
624
+ }
625
+
626
  /**
627
  * On Email Changed.
628
  *
637
  return $this->handle_filtered_data_notification( 'email-changed', $email_data, $user['ID'] );
638
  }
639
 
640
+ public function on_email_changing( $email_text, $new_user_details ) {
641
+ $notification_name = 'email-changing';
642
+
643
+ $notifications = $this->notifier->get_notifications( $notification_name );
644
+ if ( count( $notifications ) > 0 ) {
645
+ // Ideally there should be only one notification for this type.
646
+ // If there are multiple notification then we will read data about only the last one
647
+ $setting = $this->notifier->read_settings( end( $notifications )->ID );
648
+
649
+ $email_text = $this->engine->handle_shortcodes( $setting['message'], $setting['notification'], $new_user_details['newemail'] );
650
+ $email_text = $this->engine->handle_global_user_shortcodes( $email_text, $new_user_details['newemail'] );
651
+ $email_text = str_replace( '[email_change_confirmation_link]', esc_url( admin_url( 'profile.php?newuseremail=' . $new_user_details['hash'] ) ), $email_text );
652
+
653
+ }
654
+
655
+ return $email_text;
656
+ }
657
+
658
  /**
659
  * Send notification on core updated event.
660
  *
includes/admin/class-bnfw-notification.php CHANGED
@@ -24,8 +24,12 @@ class BNFW_Notification {
24
 
25
  add_filter( 'use_block_editor_for_post_type', array( $this, 'disable_gutenberg_for_notification' ), 10, 2 );
26
 
 
 
 
27
  // Custom row actions.
28
  add_filter( 'post_row_actions', array( $this, 'custom_row_actions' ), 10, 2 );
 
29
 
30
  // Custom columns
31
  add_filter( sprintf( 'manage_%s_posts_columns', self::POST_TYPE ), array( $this, 'columns_header' ) );
@@ -186,6 +190,8 @@ class BNFW_Notification {
186
  value="admin-password" <?php selected( 'admin-password', $setting['notification'] ); ?>><?php esc_html_e( 'User Lost Password - For Admin', 'bnfw' ); ?></option>
187
  <option
188
  value="admin-password-changed" <?php selected( 'admin-password-changed', $setting['notification'] ); ?>><?php esc_html_e( 'Password Changed - For Admin', 'bnfw' ); ?></option>
 
 
189
  <option
190
  value="admin-role" <?php selected( 'admin-role', $setting['notification'] ); ?>><?php esc_html_e( 'User Role Changed - For Admin', 'bnfw' ); ?></option>
191
  <option
@@ -214,6 +220,9 @@ class BNFW_Notification {
214
  value="user-password" <?php selected( 'user-password', $setting['notification'] ); ?>><?php esc_html_e( 'User Lost Password - For User', 'bnfw' ); ?></option>
215
  <option
216
  value="password-changed" <?php selected( 'password-changed', $setting['notification'] ); ?>><?php esc_html_e( 'Password Changed - For User', 'bnfw' ); ?></option>
 
 
 
217
  <option
218
  value="email-changed" <?php selected( 'email-changed', $setting['notification'] ); ?>><?php esc_html_e( 'User Email Changed - For User', 'bnfw' ); ?></option>
219
  <option
@@ -415,7 +424,7 @@ foreach ( $taxs as $tax ) {
415
  <td>
416
  <input type="text" name="from-name" value="<?php echo esc_attr( $setting['from-name'] ); ?>"
417
  placeholder="Site Name" style="width: 37.35%">
418
- <input type="email" name="from-email" value="<?php echo esc_attr( $setting['from-email'] ); ?>"
419
  placeholder="Site Email" style="width: 37.3%">
420
  </td>
421
  </tr>
@@ -429,7 +438,7 @@ foreach ( $taxs as $tax ) {
429
  <td>
430
  <input type="text" name="reply-name" value="<?php echo esc_attr( $setting['reply-name'] ); ?>"
431
  placeholder="Name" style="width: 37.35%">
432
- <input type="email" name="reply-email" value="<?php echo esc_attr( $setting['reply-email'] ); ?>"
433
  placeholder="Email" style="width: 37.3%">
434
  </td>
435
  </tr>
@@ -726,9 +735,9 @@ foreach ( $taxs as $tax ) {
726
  if ( isset( $_POST['show-fields'] ) && 'true' == $_POST['show-fields'] ) {
727
  $setting['show-fields'] = 'true';
728
  $setting['from-name'] = sanitize_text_field( $_POST['from-name'] );
729
- $setting['from-email'] = sanitize_email( $_POST['from-email'] );
730
  $setting['reply-name'] = sanitize_text_field( $_POST['reply-name'] );
731
- $setting['reply-email'] = sanitize_email( $_POST['reply-email'] );
732
  $setting['cc'] = isset( $_POST['cc'] ) ? array_map( 'sanitize_text_field', $_POST['cc'] ) : '';
733
  $setting['bcc'] = isset( $_POST['bcc'] ) ? array_map( 'sanitize_text_field', $_POST['bcc'] ) : '';
734
  } else {
@@ -999,6 +1008,37 @@ foreach ( $taxs as $tax ) {
999
  return $posts;
1000
  }
1001
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1002
  /**
1003
  * Does a particular type of notification exists or not.
1004
  *
@@ -1156,9 +1196,15 @@ foreach ( $taxs as $tax ) {
1156
  case 'admin-password-changed':
1157
  $name = esc_html__( 'Password Changed - For Admin', 'bnfw' );
1158
  break;
 
 
 
1159
  case 'password-changed':
1160
  $name = esc_html__( 'Password Changed - For User', 'bnfw' );
1161
  break;
 
 
 
1162
  case 'email-changed':
1163
  $name = esc_html__( 'User Email Changed - For User', 'bnfw' );
1164
  break;
@@ -1273,27 +1319,115 @@ foreach ( $taxs as $tax ) {
1273
  return $name;
1274
  }
1275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1276
  /**
1277
  * Custom row actions for this post type.
1278
  *
1279
  * @since 1.0
1280
  * @filter post_row_actions
1281
  *
1282
- * @param array $actions
 
1283
  *
1284
  * @return array
1285
  */
1286
- public function custom_row_actions( $actions ) {
1287
- $post = get_post();
1288
-
1289
  if ( self::POST_TYPE === get_post_type( $post ) ) {
1290
  unset( $actions['inline hide-if-no-js'] );
1291
  unset( $actions['view'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1292
  }
1293
 
1294
  return $actions;
1295
  }
1296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1297
  /**
1298
  * Find if a string starts with another string.
1299
  *
@@ -1320,6 +1454,34 @@ foreach ( $taxs as $tax ) {
1320
  return;
1321
  }
1322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1323
  if ( ! PAnD::is_admin_notice_active( 'disable-bnfw-help-notice-forever' ) ) {
1324
  return;
1325
  }
24
 
25
  add_filter( 'use_block_editor_for_post_type', array( $this, 'disable_gutenberg_for_notification' ), 10, 2 );
26
 
27
+ add_filter( 'bulk_actions-edit-bnfw_notification', array( $this, 'add_custom_edit_action' ) );
28
+ add_filter( 'handle_bulk_actions-edit-bnfw_notification', array( $this, 'handle_custom_edit_action' ), 10, 3 );
29
+
30
  // Custom row actions.
31
  add_filter( 'post_row_actions', array( $this, 'custom_row_actions' ), 10, 2 );
32
+ add_action( 'admin_init', array( $this, 'handle_actions' ) );
33
 
34
  // Custom columns
35
  add_filter( sprintf( 'manage_%s_posts_columns', self::POST_TYPE ), array( $this, 'columns_header' ) );
190
  value="admin-password" <?php selected( 'admin-password', $setting['notification'] ); ?>><?php esc_html_e( 'User Lost Password - For Admin', 'bnfw' ); ?></option>
191
  <option
192
  value="admin-password-changed" <?php selected( 'admin-password-changed', $setting['notification'] ); ?>><?php esc_html_e( 'Password Changed - For Admin', 'bnfw' ); ?></option>
193
+ <option
194
+ value="admin-email-changed" <?php selected( 'admin-email-changed', $setting['notification'] ); ?>><?php esc_html_e( 'User Email Changed - For Admin', 'bnfw' ); ?></option>
195
  <option
196
  value="admin-role" <?php selected( 'admin-role', $setting['notification'] ); ?>><?php esc_html_e( 'User Role Changed - For Admin', 'bnfw' ); ?></option>
197
  <option
220
  value="user-password" <?php selected( 'user-password', $setting['notification'] ); ?>><?php esc_html_e( 'User Lost Password - For User', 'bnfw' ); ?></option>
221
  <option
222
  value="password-changed" <?php selected( 'password-changed', $setting['notification'] ); ?>><?php esc_html_e( 'Password Changed - For User', 'bnfw' ); ?></option>
223
+ <option value="email-changing" <?php selected( 'email-changing', $setting['notification'] ); ?>>
224
+ <?php esc_html_e( 'User Email Changed Confirmation - For User', 'bnfw' ); ?>
225
+ </option>
226
  <option
227
  value="email-changed" <?php selected( 'email-changed', $setting['notification'] ); ?>><?php esc_html_e( 'User Email Changed - For User', 'bnfw' ); ?></option>
228
  <option
424
  <td>
425
  <input type="text" name="from-name" value="<?php echo esc_attr( $setting['from-name'] ); ?>"
426
  placeholder="Site Name" style="width: 37.35%">
427
+ <input type="text" name="from-email" value="<?php echo esc_attr( $setting['from-email'] ); ?>"
428
  placeholder="Site Email" style="width: 37.3%">
429
  </td>
430
  </tr>
438
  <td>
439
  <input type="text" name="reply-name" value="<?php echo esc_attr( $setting['reply-name'] ); ?>"
440
  placeholder="Name" style="width: 37.35%">
441
+ <input type="text" name="reply-email" value="<?php echo esc_attr( $setting['reply-email'] ); ?>"
442
  placeholder="Email" style="width: 37.3%">
443
  </td>
444
  </tr>
735
  if ( isset( $_POST['show-fields'] ) && 'true' == $_POST['show-fields'] ) {
736
  $setting['show-fields'] = 'true';
737
  $setting['from-name'] = sanitize_text_field( $_POST['from-name'] );
738
+ $setting['from-email'] = sanitize_text_field( $_POST['from-email'] );
739
  $setting['reply-name'] = sanitize_text_field( $_POST['reply-name'] );
740
+ $setting['reply-email'] = sanitize_text_field( $_POST['reply-email'] );
741
  $setting['cc'] = isset( $_POST['cc'] ) ? array_map( 'sanitize_text_field', $_POST['cc'] ) : '';
742
  $setting['bcc'] = isset( $_POST['bcc'] ) ? array_map( 'sanitize_text_field', $_POST['bcc'] ) : '';
743
  } else {
1008
  return $posts;
1009
  }
1010
 
1011
+ /**
1012
+ * Are there any disabled notifications for a particular notification type.
1013
+ *
1014
+ * @param string $type Notification type.
1015
+ *
1016
+ * @return bool True if disabled, False otherwise.
1017
+ */
1018
+ public function is_notification_disabled( $type ) {
1019
+ $args = array(
1020
+ 'post_type' => self::POST_TYPE,
1021
+ 'posts_per_page' => - 1,
1022
+ 'nopagging' => true,
1023
+ 'fields' => 'ids',
1024
+ 'meta_query' => array(
1025
+ array(
1026
+ 'key' => self::META_KEY_PREFIX . 'notification',
1027
+ 'value' => $type,
1028
+ ),
1029
+ array(
1030
+ 'key' => self::META_KEY_PREFIX . 'disabled',
1031
+ 'value' => 'true',
1032
+ ),
1033
+ )
1034
+ );
1035
+
1036
+ $wp_query = new WP_Query();
1037
+ $posts = $wp_query->query( $args );
1038
+
1039
+ return count( $posts ) > 0;
1040
+ }
1041
+
1042
  /**
1043
  * Does a particular type of notification exists or not.
1044
  *
1196
  case 'admin-password-changed':
1197
  $name = esc_html__( 'Password Changed - For Admin', 'bnfw' );
1198
  break;
1199
+ case 'admin-email-changed':
1200
+ $name = esc_html__( 'User Email Changed - For Admin', 'bnfw' );
1201
+ break;
1202
  case 'password-changed':
1203
  $name = esc_html__( 'Password Changed - For User', 'bnfw' );
1204
  break;
1205
+ case 'email-changing':
1206
+ $name = esc_html__( 'User Email Changed Confirmation - For User', 'bnfw' );
1207
+ break;
1208
  case 'email-changed':
1209
  $name = esc_html__( 'User Email Changed - For User', 'bnfw' );
1210
  break;
1319
  return $name;
1320
  }
1321
 
1322
+ /**
1323
+ * Add additional custom edit actions for enabling and disabling notifications in bulk.
1324
+ *
1325
+ * @param array $bulk_actions Bulk Actions.
1326
+ *
1327
+ * @return array Modified list of Bulk Actions.
1328
+ */
1329
+ public function add_custom_edit_action( $bulk_actions ) {
1330
+ $bulk_actions['enable_notifications'] = __( 'Enable Notifications', 'bnfw' );
1331
+ $bulk_actions['disable_notifications'] = __( 'Disable Notifications', 'bnfw' );
1332
+
1333
+ return $bulk_actions;
1334
+ }
1335
+
1336
+ /**
1337
+ * Handle custom edit actions.
1338
+ *
1339
+ * @param $redirect_to
1340
+ * @param $doaction
1341
+ * @param $post_ids
1342
+ *
1343
+ * @return string
1344
+ */
1345
+ public function handle_custom_edit_action( $redirect_to, $doaction, $post_ids ) {
1346
+ if ( 'enable_notifications' !== $doaction && 'disable_notifications' !== $doaction ) {
1347
+ return $redirect_to;
1348
+ }
1349
+
1350
+ $redirect_to = remove_query_arg( array( 'bulk_enable_notifications', 'bulk_disable_notifications', 'bnfw_action' ), $redirect_to );
1351
+
1352
+ $meta_value = 'true';
1353
+
1354
+ if ( 'enable_notifications' === $doaction ) {
1355
+ $meta_value = 'false';
1356
+ }
1357
+
1358
+ foreach ( $post_ids as $post_id ) {
1359
+ update_post_meta( $post_id, self::META_KEY_PREFIX . 'disabled', $meta_value );
1360
+ }
1361
+
1362
+ $redirect_to = add_query_arg( 'bulk_' . $doaction, count( $post_ids ), $redirect_to );
1363
+
1364
+ return $redirect_to;
1365
+ }
1366
+
1367
  /**
1368
  * Custom row actions for this post type.
1369
  *
1370
  * @since 1.0
1371
  * @filter post_row_actions
1372
  *
1373
+ * @param array $actions
1374
+ * @param \WP_Post $post
1375
  *
1376
  * @return array
1377
  */
1378
+ public function custom_row_actions( $actions, $post ) {
 
 
1379
  if ( self::POST_TYPE === get_post_type( $post ) ) {
1380
  unset( $actions['inline hide-if-no-js'] );
1381
  unset( $actions['view'] );
1382
+
1383
+ $notification_disabled = get_post_meta( $post->ID, self::META_KEY_PREFIX . 'disabled', true );
1384
+
1385
+ if ( 'true' === $notification_disabled ) {
1386
+ $url = add_query_arg(
1387
+ array(
1388
+ 'notification_id' => $post->ID,
1389
+ 'bnfw_action' => 'enable_notification',
1390
+ )
1391
+ );
1392
+ $actions['enable_notification'] = '<a href="' . esc_url( $url ) . '">' . __( 'Enable Notification', 'bnfw' ) . '</a>';
1393
+ } else {
1394
+ $url = add_query_arg(
1395
+ array(
1396
+ 'notification_id' => $post->ID,
1397
+ 'bnfw_action' => 'disable_notification',
1398
+ )
1399
+ );
1400
+ $actions['disable_notification'] = '<a href="' . esc_url( $url ) . '">' . __( 'Disable Notification', 'bnfw' ) . '</a>';
1401
+ }
1402
  }
1403
 
1404
  return $actions;
1405
  }
1406
 
1407
+ /**
1408
+ * Handle custom actions.
1409
+ */
1410
+ public function handle_actions() {
1411
+ if ( ! isset( $_GET['bnfw_action'] ) || ! isset( $_GET['notification_id'] ) ) {
1412
+ return;
1413
+ }
1414
+
1415
+ $post_id = absint( $_GET['notification_id'] );
1416
+ if ( 0 === $post_id ) {
1417
+ return;
1418
+ }
1419
+
1420
+ $action = sanitize_text_field( $_GET['bnfw_action'] );
1421
+
1422
+ if ( 'enable_notification' === $action ) {
1423
+ update_post_meta( $post_id, self::META_KEY_PREFIX . 'disabled', 'false' );
1424
+ }
1425
+
1426
+ if ( 'disable_notification' === $action ) {
1427
+ update_post_meta( $post_id, self::META_KEY_PREFIX . 'disabled', 'true' );
1428
+ }
1429
+ }
1430
+
1431
  /**
1432
  * Find if a string starts with another string.
1433
  *
1454
  return;
1455
  }
1456
 
1457
+ if ( ! empty( $_REQUEST['bnfw_action'] ) && 'enable_notification' === $_REQUEST['bnfw_action'] ) {
1458
+ echo '<div id="message" class="updated fade"><p>' . __( 'Enabled 1 Notification.', 'bnfw' ) . '</p></div>';
1459
+ }
1460
+
1461
+ if ( ! empty( $_REQUEST['bnfw_action'] ) && 'disable_notification' === $_REQUEST['bnfw_action'] ) {
1462
+ echo '<div id="message" class="updated fade"><p>' . __( 'Disabled 1 Notification.', 'bnfw' ) . '</p></div>';
1463
+ }
1464
+
1465
+ if ( ! empty( $_REQUEST['bulk_enable_notifications'] ) ) {
1466
+ $enabled_count = intval( $_REQUEST['bulk_enable_notifications'] );
1467
+ printf( '<div id="message" class="updated fade"><p>' .
1468
+ _n( 'Enabled %s Notification.',
1469
+ 'Enabled %s Notifications.',
1470
+ $enabled_count,
1471
+ 'bnfw'
1472
+ ) . '</p></div>', $enabled_count );
1473
+ }
1474
+
1475
+ if ( ! empty( $_REQUEST['bulk_disable_notifications'] ) ) {
1476
+ $disabled_count = intval( $_REQUEST['bulk_disable_notifications'] );
1477
+ printf( '<div id="message" class="updated fade"><p>' .
1478
+ _n( 'Disabled %s Notification.',
1479
+ 'Disabled %s Notifications.',
1480
+ $disabled_count,
1481
+ 'bnfw'
1482
+ ) . '</p></div>', $disabled_count );
1483
+ }
1484
+
1485
  if ( ! PAnD::is_admin_notice_active( 'disable-bnfw-help-notice-forever' ) ) {
1486
  return;
1487
  }
includes/engine/class-bnfw-engine.php CHANGED
@@ -377,6 +377,7 @@ class BNFW_Engine {
377
 
378
  case 'admin-password':
379
  case 'admin-password-changed':
 
380
  case 'user-password':
381
  case 'admin-user':
382
  case 'welcome-email':
@@ -432,7 +433,9 @@ class BNFW_Engine {
432
  if ( in_array( $type[1], $post_types ) ) {
433
  $message = $this->post_shortcodes( $message, $extra_data );
434
  $post = get_post( $extra_data );
435
- $message = $this->user_shortcodes( $message, $post->post_author );
 
 
436
  }
437
  } elseif ( 'comment' == $type[0] || 'moderate' == $type[0] || 'commentreply' == $type[0] ) {
438
  $message = $this->comment_shortcodes( $message, $extra_data );
@@ -517,6 +520,10 @@ class BNFW_Engine {
517
  public function post_shortcodes( $message, $post_id ) {
518
  $post = get_post( $post_id );
519
 
 
 
 
 
520
  $post_content = $this->may_be_strip_shortcode( $post->post_content );
521
  $post_content = apply_filters( 'the_content', $post_content );
522
  $post_content = str_replace( ']]>', ']]&gt;', $post_content );
@@ -548,7 +555,7 @@ class BNFW_Engine {
548
  $message = str_replace( '[permalink]', get_permalink( $post->ID ), $message );
549
  $message = str_replace( '[post_type_archive]', get_post_type_archive_link($post->post_type), $message );
550
 
551
- $message = str_replace( '[edit_post]', $this->get_edit_post_link( $post->ID ), $message );
552
 
553
  $featured_image = '';
554
  if ( has_post_thumbnail( $post->ID ) ) {
@@ -720,7 +727,7 @@ class BNFW_Engine {
720
  $message = str_replace( '[comment_parent]', $comment->comment_parent, $message );
721
  $message = str_replace( '[user_id]', $comment->user_id, $message );
722
  $message = str_replace( '[permalink]', get_comment_link( $comment->comment_ID ), $message );
723
- $message = str_replace( '[comment_moderation_link]', str_replace( "&amp;", "&", get_edit_comment_link( $comment->comment_ID ) ), $message );
724
  $message = str_replace( '[comment_moderation_approve]', '<a href="' . wp_nonce_url(admin_url("comment.php?action=approve&c={$comment->comment_ID}#wpbody-content")) . '">Approve</a>', $message );
725
  $message = str_replace( '[comment_moderation_spam]', '<a href="' . wp_nonce_url(admin_url("comment.php?action=spam&c={$comment->comment_ID}#wpbody-content")) . '">Spam</a>', $message );
726
  $message = str_replace( '[comment_moderation_delete]', '<a href="' . wp_nonce_url(admin_url("comment.php?action=trash&c={$comment->comment_ID}#wpbody-content")) . '">Delete</a>', $message );
@@ -830,16 +837,17 @@ class BNFW_Engine {
830
  * @param array $setting Notification settings
831
  * @param int $id
832
  * @param bool $process_post_authors
 
833
  *
834
  * @return array Emails
835
  */
836
- public function get_emails( $setting, $id, $process_post_authors = true ) {
837
  global $current_user;
838
 
839
  $emails = array();
840
 
841
  $exclude = null;
842
- if ( 'true' == $setting['disable-current-user'] ) {
843
  if ( isset( $current_user->ID ) ) {
844
  $exclude = $current_user->ID;
845
  }
@@ -875,17 +883,31 @@ class BNFW_Engine {
875
 
876
  if ( 'true' == $setting['show-fields'] ) {
877
  if ( ! empty( $setting['from-name'] ) && ! empty( $setting['from-email'] ) ) {
878
- $emails['from'] = $setting['from-name'] . ' <' . $setting['from-email'] . '>' ;
 
 
 
 
 
 
 
 
 
879
  } else {
880
- $emails['from'] = get_option( 'blogname' ) . ' <' . get_option( 'admin_email' ) . '>' ;
881
  }
882
 
883
  if ( ! empty( $setting['reply-name'] ) ) {
884
- $emails['reply-name'] = $setting['reply-name'];
885
  }
886
 
887
  if ( ! empty( $setting['reply-email'] ) ) {
888
- $emails['reply-email'] = $setting['reply-email'];
 
 
 
 
 
889
  }
890
 
891
  if ( ! empty( $setting['cc'] ) ) {
@@ -1185,4 +1207,43 @@ class BNFW_Engine {
1185
 
1186
  return $message;
1187
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1188
  }
377
 
378
  case 'admin-password':
379
  case 'admin-password-changed':
380
+ case 'admin-email-changed':
381
  case 'user-password':
382
  case 'admin-user':
383
  case 'welcome-email':
433
  if ( in_array( $type[1], $post_types ) ) {
434
  $message = $this->post_shortcodes( $message, $extra_data );
435
  $post = get_post( $extra_data );
436
+ if ( $post instanceof WP_Post ) {
437
+ $message = $this->user_shortcodes( $message, $post->post_author );
438
+ }
439
  }
440
  } elseif ( 'comment' == $type[0] || 'moderate' == $type[0] || 'commentreply' == $type[0] ) {
441
  $message = $this->comment_shortcodes( $message, $extra_data );
520
  public function post_shortcodes( $message, $post_id ) {
521
  $post = get_post( $post_id );
522
 
523
+ if ( ! $post instanceof WP_Post ) {
524
+ return $message;
525
+ }
526
+
527
  $post_content = $this->may_be_strip_shortcode( $post->post_content );
528
  $post_content = apply_filters( 'the_content', $post_content );
529
  $post_content = str_replace( ']]>', ']]&gt;', $post_content );
555
  $message = str_replace( '[permalink]', get_permalink( $post->ID ), $message );
556
  $message = str_replace( '[post_type_archive]', get_post_type_archive_link($post->post_type), $message );
557
 
558
+ $message = str_replace( '[edit_post]', $this->get_edit_post_link( $post->ID, 'return' ), $message );
559
 
560
  $featured_image = '';
561
  if ( has_post_thumbnail( $post->ID ) ) {
727
  $message = str_replace( '[comment_parent]', $comment->comment_parent, $message );
728
  $message = str_replace( '[user_id]', $comment->user_id, $message );
729
  $message = str_replace( '[permalink]', get_comment_link( $comment->comment_ID ), $message );
730
+ $message = str_replace( '[comment_moderation_link]', admin_url( 'comment.php?action=editcomment&c=' ) . $comment->comment_ID, $message );
731
  $message = str_replace( '[comment_moderation_approve]', '<a href="' . wp_nonce_url(admin_url("comment.php?action=approve&c={$comment->comment_ID}#wpbody-content")) . '">Approve</a>', $message );
732
  $message = str_replace( '[comment_moderation_spam]', '<a href="' . wp_nonce_url(admin_url("comment.php?action=spam&c={$comment->comment_ID}#wpbody-content")) . '">Spam</a>', $message );
733
  $message = str_replace( '[comment_moderation_delete]', '<a href="' . wp_nonce_url(admin_url("comment.php?action=trash&c={$comment->comment_ID}#wpbody-content")) . '">Delete</a>', $message );
837
  * @param array $setting Notification settings
838
  * @param int $id
839
  * @param bool $process_post_authors
840
+ * @param bool $process_exclude_current_user
841
  *
842
  * @return array Emails
843
  */
844
+ public function get_emails( $setting, $id, $process_post_authors = true, $process_exclude_current_user = true ) {
845
  global $current_user;
846
 
847
  $emails = array();
848
 
849
  $exclude = null;
850
+ if ( $process_exclude_current_user && 'true' == $setting['disable-current-user'] ) {
851
  if ( isset( $current_user->ID ) ) {
852
  $exclude = $current_user->ID;
853
  }
883
 
884
  if ( 'true' == $setting['show-fields'] ) {
885
  if ( ! empty( $setting['from-name'] ) && ! empty( $setting['from-email'] ) ) {
886
+ $from_email = $setting['from-email'];
887
+ if ( ! is_email( $from_email ) ) {
888
+ $from_email = $this->process_shortcodes_in_email( $from_email, $id, $setting, $emails['to'] );
889
+ }
890
+
891
+ $from_name = $this->handle_shortcodes( $setting['from-name'], $setting['notification'], $id );
892
+
893
+ if ( is_email( $from_email ) ) {
894
+ $emails['from'] = $from_name . ' <' . $from_email . '>';
895
+ }
896
  } else {
897
+ $emails['from'] = get_option( 'blogname' ) . ' <' . get_option( 'admin_email' ) . '>';
898
  }
899
 
900
  if ( ! empty( $setting['reply-name'] ) ) {
901
+ $emails['reply-name'] = $this->handle_shortcodes( $setting['reply-name'], $setting['notification'], $id );
902
  }
903
 
904
  if ( ! empty( $setting['reply-email'] ) ) {
905
+ $reply_to_email = $setting['reply-email'];
906
+ if ( ! is_email( $setting['reply-email'] ) ) {
907
+ $reply_to_email = $this->process_shortcodes_in_email( $reply_to_email, $id, $setting, $emails['to'] );
908
+ }
909
+
910
+ $emails['reply-email'] = $reply_to_email;
911
  }
912
 
913
  if ( ! empty( $setting['cc'] ) ) {
1207
 
1208
  return $message;
1209
  }
1210
+
1211
+ /**
1212
+ * Process shortcodes in email.
1213
+ *
1214
+ * @param $email
1215
+ * @param $post_id
1216
+ * @param $setting
1217
+ *
1218
+ * @return string
1219
+ */
1220
+ protected function process_shortcodes_in_email( $email, $post_id, $setting, $to_emails ) {
1221
+ if ( ! empty( $setting ) ) {
1222
+ if ( $this->starts_with( $setting['notification'], 'comment-' ) || $this->starts_with( $setting['notification'], 'moderate-' ) ) {
1223
+ // for new comment notifications, we need to use post id instead of comment id.
1224
+ $post_id = bnfw_get_post_id_from_comment( $post_id );
1225
+ }
1226
+ }
1227
+
1228
+ $email = $this->handle_shortcodes( $email, $setting['notification'], $post_id );
1229
+
1230
+ if ( is_array( $to_emails ) && ! empty( $to_emails ) ) {
1231
+ $to_email = $to_emails[0];
1232
+
1233
+ $email = $this->handle_global_user_shortcodes( $email, $to_email );
1234
+ }
1235
+
1236
+ $processed_emails = array();
1237
+ if ( is_email( $email ) ) {
1238
+ $processed_emails[] = $email;
1239
+ }
1240
+
1241
+ $emails = apply_filters( 'bnfw_non_wp_emails', $processed_emails, array( $email ), $post_id );
1242
+
1243
+ if ( empty( $emails ) ) {
1244
+ return '';
1245
+ }
1246
+
1247
+ return $emails[0];
1248
+ }
1249
  }
includes/helpers/helpers.php CHANGED
@@ -15,7 +15,7 @@ defined( 'ABSPATH' ) || exit; // Exit if accessed directly
15
  function bnfw_get_user_select_class() {
16
  $user_count = count_users();
17
 
18
- if ( $user_count['total_users'] > 100 ) {
19
  return 'user-ajax-select2';
20
  } else {
21
  return 'user-select2';
15
  function bnfw_get_user_select_class() {
16
  $user_count = count_users();
17
 
18
+ if ( $user_count['total_users'] > 200 ) {
19
  return 'user-ajax-select2';
20
  } else {
21
  return 'user-select2';