Better Notifications for WordPress - Version 1.7.6

Version Description

  • 30th January 2020 =
  • New Notification: New Comment Approved. This is sent after the comment has been approved.
  • New: You can now output the description for the first available category in any new Post/Page/Custom Post Type notification, as well as to New Comment, Comment Awaiting Moderation, and Comment Reply notifications using the shortcode [post_category_description]. You can also use the [post_category_slug] notification to output the first available category slug.
  • Added: Merged two pull requests that came in via the GitHub clone of this plugin relating to filters - (#1 and #2).
  • Added: $update as 3rd parameter to bnfw_trigger_insert_post filter.
  • Added: Additional translatable strings.
  • Improved: 'Post Pending Review' notifications are now only sent for the first update to a post that is pending review. Subsequent updates will not trigger another notification.
  • Fixed: Advanced Custom Fields (ACF) was triggering incorrect notifications when post/page/custom post types were submitted via a front-end form.
  • Fixed: The [post_excerpt] shortcode now conforms to the excerpt_length filter.
  • Fixed: Post Pending Review notifications were being sent in duplicate in certain situations.
  • Fixed: Added an additional check to ensure a Multisite doesn't crash when BNFW is enabled on a site with no Administrator users.
  • Fixed: Multisite notifications were showing the HTMl/Text options for notifications that could only support text.
Download this release

Release Info

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

Code changes from version 1.7.5 to 1.7.6

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.2.3
7
  Requires PHP: 5.6
8
- Stable tag: 1.7.5
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -26,7 +26,9 @@ You want all the users in the Editor role to be notified via email when a new po
26
  = Premium Add-ons =
27
  Power-up your notifications using add-ons:
28
 
29
- [Subscriptions (GDPR Compliancy)](https://betternotificationsforwp.com/downloads/subscriptions-gdpr/) - Allow users to manage their subscriptions for BNFW notifications.
 
 
30
 
31
  [Conditional Notifications](https://betternotificationsforwp.com/downloads/conditional-notifications/) - Limit certain notifications depending on which categories, tags, post formats, or terms you choose.
32
 
@@ -89,6 +91,7 @@ The notifications that are currently available to use are:
89
  * Post Scheduled
90
  * New Comment
91
  * New Comment Awaiting Moderation
 
92
  * Post - Custom Field Updated ([Custom Fields Add-on](https://betternotificationsforwp.com/downloads/custom-fields/))
93
  * Post - Update Reminder ([Reminders Add-on](https://betternotificationsforwp.com/downloads/update-reminder/))
94
  * New Trackback
@@ -218,6 +221,19 @@ Yes, of course! The plugin is completely translation-friendly and if you send me
218
 
219
  == Changelog ==
220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  = 1.7.5 - 23rd September 2019 =
222
  * Added: Support for the new [Digest add-on](https://betternotificationsforwp.com/downloads/digest/)!
223
  * Added: Support for some big changes coming to the [Custom Fields add-on](https://betternotificationsforwp.com/downloads/custom-fields/).
@@ -250,7 +266,7 @@ Yes, of course! The plugin is completely translation-friendly and if you send me
250
  * Fixed: New Comment Awaiting Moderation notifications weren't being sent to the Post Author, where selected.
251
 
252
  = 1.7.1 - 5th November 2018 =
253
- * New: Full support for the new [Subscriptions (GDPR Compliancy)](https://betternotificationsforwp.com/downloads/subscriptions-gdpr/) add-on.
254
  * Fixed: Comments marked as SPAM were triggering the 'New Comment Awaiting Moderation' notification.
255
  * Fixed: An issue relating to the 'New Comment Awaiting Moderation' notification not saving when used in conjunction with the Send To Any Email and Custom Fields add-ons.
256
  * Fixed: A couple of minor javascript errors relating to BNFW add-ons.
@@ -277,7 +293,7 @@ Yes, of course! The plugin is completely translation-friendly and if you send me
277
  * Fixed: The SVG icon on WordPress.org wasn't exported correctly.
278
 
279
  = 1.6.14 - 25th May 2018 =
280
- * New: As part of my plans for implementing GDPR compliancy within BNFW, you can now exclude users and/or roles from your notifications in the new 'Except For' box.
281
  * New: You can now include the post/page author in addition to the list of users and user roles in your notifications (not either/or).
282
  * New: You can now enable the output of shortcodes again when using the `[post_content]` shortcode in your notifications via a new checkbox in the Settings screen.
283
  * New: A list of available actions and filters in BNFW is now available in the [website documentation](https://betternotificationsforwp.com/documentation/actions-and-filters/).
@@ -306,7 +322,7 @@ Yes, of course! The plugin is completely translation-friendly and if you send me
306
  * New: If you want to allow other user roles to create or edit notifications, you can now grant them the 'bnfw' capability using a role editor.
307
  * Added: A new notice will display at the top of all Notification screens explaining how you can improve email deliverability. You can dismiss this permanently at any time.
308
  * Added: Inline help tips are now available when creating or editing a notification. Handy if you want to remember how something works but don't want to sift through the documentation.
309
- * Added: Merged two pull request that came in via the GitHub clone of this plugin - ([#1](https://github.com/jackmcconnell/bnfw/pull/1) and [#2](https://github.com/jackmcconnell/bnfw/pull/2)).
310
  * Added: For faster support, there is now a Priority Support menu item in the BNFW Notifications menu. Priority Support is available to customers with an active subscription to an add-on.
311
  * Improved: All date related shortcodes now output in the date and time format set in Settings > General in the WordPress Admin.
312
  * Improved: The list of available notifications has been re-ordered to make more sense.
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.3.2
7
  Requires PHP: 5.6
8
+ Stable tag: 1.7.6
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
26
  = Premium Add-ons =
27
  Power-up your notifications using add-ons:
28
 
29
+ [Notification Add-on Bundles](https://betternotificationsforwp.com/add-on-bundles/) - Everything you need for your WordPress notifications. Save big when you buy an add-on bundle. Instant access.
30
+
31
+ [Subscriptions (GDPR)](https://betternotificationsforwp.com/downloads/subscriptions-gdpr/) - Allow users to manage their subscriptions for BNFW notifications.
32
 
33
  [Conditional Notifications](https://betternotificationsforwp.com/downloads/conditional-notifications/) - Limit certain notifications depending on which categories, tags, post formats, or terms you choose.
34
 
91
  * Post Scheduled
92
  * New Comment
93
  * New Comment Awaiting Moderation
94
+ * Comment Approved
95
  * Post - Custom Field Updated ([Custom Fields Add-on](https://betternotificationsforwp.com/downloads/custom-fields/))
96
  * Post - Update Reminder ([Reminders Add-on](https://betternotificationsforwp.com/downloads/update-reminder/))
97
  * New Trackback
221
 
222
  == Changelog ==
223
 
224
+ = 1.7.6 - 30th January 2020 =
225
+ * New Notification: New Comment Approved. This is sent after the comment has been approved.
226
+ * New: You can now output the description for the first available category in any new Post/Page/Custom Post Type notification, as well as to New Comment, Comment Awaiting Moderation, and Comment Reply notifications using the shortcode `[post_category_description]`. You can also use the `[post_category_slug]` notification to output the first available category slug.
227
+ * Added: Merged two pull requests that came in via the GitHub clone of this plugin relating to filters - ([#1](https://github.com/jackmcconnell/bnfw/pull/4/commits/501d7cdcb9855ad5aa08e4510f752f9ff319567f) and [#2](https://github.com/jackmcconnell/bnfw/pull/5)).
228
+ * Added: `$update` as 3rd parameter to `bnfw_trigger_insert_post` filter.
229
+ * Added: Additional translatable strings.
230
+ * Improved: 'Post Pending Review' notifications are now only sent for the first update to a post that is pending review. Subsequent updates will not trigger another notification.
231
+ * Fixed: Advanced Custom Fields (ACF) was triggering incorrect notifications when post/page/custom post types were submitted via a front-end form.
232
+ * Fixed: The `[post_excerpt]` shortcode now conforms to the `excerpt_length` filter.
233
+ * Fixed: Post Pending Review notifications were being sent in duplicate in certain situations.
234
+ * Fixed: Added an additional check to ensure a Multisite doesn't crash when BNFW is enabled on a site with no Administrator users.
235
+ * Fixed: Multisite notifications were showing the HTMl/Text options for notifications that could only support text.
236
+
237
  = 1.7.5 - 23rd September 2019 =
238
  * Added: Support for the new [Digest add-on](https://betternotificationsforwp.com/downloads/digest/)!
239
  * Added: Support for some big changes coming to the [Custom Fields add-on](https://betternotificationsforwp.com/downloads/custom-fields/).
266
  * Fixed: New Comment Awaiting Moderation notifications weren't being sent to the Post Author, where selected.
267
 
268
  = 1.7.1 - 5th November 2018 =
269
+ * New: Full support for the new [Subscriptions (GDPR)](https://betternotificationsforwp.com/downloads/subscriptions-gdpr/) add-on.
270
  * Fixed: Comments marked as SPAM were triggering the 'New Comment Awaiting Moderation' notification.
271
  * Fixed: An issue relating to the 'New Comment Awaiting Moderation' notification not saving when used in conjunction with the Send To Any Email and Custom Fields add-ons.
272
  * Fixed: A couple of minor javascript errors relating to BNFW add-ons.
293
  * Fixed: The SVG icon on WordPress.org wasn't exported correctly.
294
 
295
  = 1.6.14 - 25th May 2018 =
296
+ * New: As part of my plans for implementing GDPR within BNFW, you can now exclude users and/or roles from your notifications in the new 'Except For' box.
297
  * New: You can now include the post/page author in addition to the list of users and user roles in your notifications (not either/or).
298
  * New: You can now enable the output of shortcodes again when using the `[post_content]` shortcode in your notifications via a new checkbox in the Settings screen.
299
  * New: A list of available actions and filters in BNFW is now available in the [website documentation](https://betternotificationsforwp.com/documentation/actions-and-filters/).
322
  * New: If you want to allow other user roles to create or edit notifications, you can now grant them the 'bnfw' capability using a role editor.
323
  * Added: A new notice will display at the top of all Notification screens explaining how you can improve email deliverability. You can dismiss this permanently at any time.
324
  * Added: Inline help tips are now available when creating or editing a notification. Handy if you want to remember how something works but don't want to sift through the documentation.
325
+ * Added: Merged two pull requests that came in via the GitHub clone of this plugin - ([#1](https://github.com/jackmcconnell/bnfw/pull/1) and [#2](https://github.com/jackmcconnell/bnfw/pull/2)).
326
  * Added: For faster support, there is now a Priority Support menu item in the BNFW Notifications menu. Priority Support is available to customers with an active subscription to an add-on.
327
  * Improved: All date related shortcodes now output in the date and time format set in Settings > General in the WordPress Admin.
328
  * Improved: The list of available notifications has been re-ordered to make more sense.
assets/css/bnfw.css CHANGED
@@ -83,11 +83,13 @@ body.post-type-bnfw_notification #poststuff td,
83
  }
84
 
85
  /* Left Align Elements on Right of Screen */
 
86
  #bnfw_submitdiv .bnfw-help-tip p {
87
  left: auto;
88
  right: -8px;
89
  }
90
 
 
91
  #bnfw_submitdiv .bnfw-help-tip p:before {
92
  left: auto;
93
  right: 10px;
83
  }
84
 
85
  /* Left Align Elements on Right of Screen */
86
+ #bnfw_override_optout .bnfw-help-tip p,
87
  #bnfw_submitdiv .bnfw-help-tip p {
88
  left: auto;
89
  right: -8px;
90
  }
91
 
92
+ #bnfw_override_optout .bnfw-help-tip p:before,
93
  #bnfw_submitdiv .bnfw-help-tip p:before {
94
  left: auto;
95
  right: 10px;
assets/img/icon-256x256.png CHANGED
Binary file
assets/js/bnfw.js CHANGED
@@ -1,4 +1,18 @@
1
  jQuery(document).ready(function($) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  function toggle_fields() {
3
  var show_fields = $('#show-fields').is(":checked");
4
 
@@ -18,7 +32,9 @@ jQuery(document).ready(function($) {
18
  $( '#current-user' ).show();
19
  }
20
 
21
- if ( 'new-comment' === $( '#notification' ).val() || 'moderate-comment' === $( '#notification' ).val() ) {
 
 
22
  $( '#current-user' ).show();
23
  }
24
  }
@@ -82,14 +98,14 @@ jQuery(document).ready(function($) {
82
  }
83
 
84
  if ( 'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
85
- 'ca-export-data' === notification || 'ca-erase-data' === notification || 'data-erased' === notification ) {
86
 
87
  $( '#email-formatting' ).hide();
88
  }
89
- } else if ( 'new-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ||
90
  'admin-password' === notification || 'admin-user' === notification || 'admin-role' === notification ) {
91
 
92
- if ( 'new-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ) {
93
  $('#post-author').show();
94
  } else {
95
  $('#post-author').hide();
@@ -157,14 +173,15 @@ jQuery(document).ready(function($) {
157
  }
158
 
159
  if ( 'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
160
- 'ca-export-data' === notification || 'ca-erase-data' === notification || 'data-erased' === notification ) {
161
 
162
  $( '#email-formatting' ).hide();
163
  }
164
- } else if ( 'new-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ||
165
- 'admin-password' === notification || 'admin-user' === notification || 'admin-role' === notification ) {
 
166
 
167
- if ( 'new-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ) {
168
  $('#post-author').show();
169
  } else {
170
  $('#post-author').hide();
@@ -219,6 +236,7 @@ jQuery(document).ready(function($) {
219
  splited;
220
 
221
  switch( notification ) {
 
222
  case 'new-comment':
223
  case 'new-trackback':
224
  case 'new-pingback':
1
  jQuery(document).ready(function($) {
2
+ var multisiteNotifications = [
3
+ 'multisite-site-created',
4
+ 'multisite-new-user-created',
5
+ 'multisite-network-admin-email-change-attempted',
6
+ 'multisite-network-admin-email-changed',
7
+ 'multisite-site-welcome',
8
+ 'multisite-site-deleted',
9
+ 'multisite-site-admin-email-change-attempted',
10
+ 'multisite-site-admin-email-changed',
11
+ 'multisite-site-registered',
12
+ 'multisite-new-user-welcome',
13
+ 'multisite-new-user-invited'
14
+ ];
15
+
16
  function toggle_fields() {
17
  var show_fields = $('#show-fields').is(":checked");
18
 
32
  $( '#current-user' ).show();
33
  }
34
 
35
+ var notification = $( '#notification' ).val();
36
+
37
+ if ( 'new-comment' === notification || 'approve-comment' === notification || 'moderate-comment' === notification ) {
38
  $( '#current-user' ).show();
39
  }
40
  }
98
  }
99
 
100
  if ( 'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
101
+ 'ca-export-data' === notification || 'ca-erase-data' === notification || 'data-erased' === notification || ( -1 !== multisiteNotifications.indexOf( notification ) ) ) {
102
 
103
  $( '#email-formatting' ).hide();
104
  }
105
+ } else if ( 'new-comment' === notification || 'approve-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ||
106
  'admin-password' === notification || 'admin-user' === notification || 'admin-role' === notification ) {
107
 
108
+ if ( 'new-comment' === notification || 'approve-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ) {
109
  $('#post-author').show();
110
  } else {
111
  $('#post-author').hide();
173
  }
174
 
175
  if ( 'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
176
+ 'ca-export-data' === notification || 'ca-erase-data' === notification || 'data-erased' === notification || ( -1 !== multisiteNotifications.indexOf( notification ) ) ) {
177
 
178
  $( '#email-formatting' ).hide();
179
  }
180
+ } else if ( 'new-comment' === notification || 'approve-comment' === notification ||
181
+ notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ||
182
+ 'admin-password' === notification || 'admin-user' === notification || 'admin-role' === notification ) {
183
 
184
+ if ( 'new-comment' === notification || 'approve-comment' === notification || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ) {
185
  $('#post-author').show();
186
  } else {
187
  $('#post-author').hide();
236
  splited;
237
 
238
  switch( notification ) {
239
+ case 'approve-comment':
240
  case 'new-comment':
241
  case 'new-trackback':
242
  case 'new-pingback':
bnfw.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Better Notifications for WP
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.5
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 © 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.
@@ -133,7 +133,7 @@ class BNFW {
133
  add_action( 'pending_to_private' , array( $this, 'private_post' ) );
134
  add_action( 'publish_to_private' , array( $this, 'private_post' ) );
135
 
136
- add_action( 'wp_insert_post' , array( $this, 'insert_post' ), 10, 2 );
137
 
138
  add_action( 'auto-draft_to_publish' , array( $this, 'publish_post' ) );
139
  add_action( 'draft_to_publish' , array( $this, 'publish_post' ) );
@@ -145,9 +145,12 @@ class BNFW {
145
  add_action( 'publish_to_publish' , array( $this, 'update_post' ) );
146
  add_action( 'private_to_private' , array( $this, 'update_post' ) );
147
 
 
 
148
  add_action( 'init' , array( $this, 'custom_post_type_hooks' ), 100 );
149
  add_action( 'create_term' , array( $this, 'create_term' ), 10, 3 );
150
 
 
151
  add_action( 'comment_post' , array( $this, 'comment_post' ) );
152
  add_action( 'trackback_post' , array( $this, 'trackback_post' ) );
153
  add_action( 'pingback_post' , array( $this, 'pingback_post' ) );
@@ -196,11 +199,38 @@ class BNFW {
196
  public function add_capability_to_admin() {
197
  $admins = get_role( 'administrator' );
198
 
 
 
 
 
199
  if ( ! $admins->has_cap( 'bnfw' ) ) {
200
  $admins->add_cap( 'bnfw' );
201
  }
202
  }
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  /**
205
  * Setup hooks for custom post types.
206
  *
@@ -211,7 +241,6 @@ class BNFW {
211
  $post_types = array_diff( $post_types, array( BNFW_Notification::POST_TYPE ) );
212
 
213
  foreach ( $post_types as $post_type ) {
214
- add_action( 'pending_' . $post_type, array( $this, 'on_post_pending' ), 10, 2 );
215
  add_action( 'future_' . $post_type, array( $this, 'on_post_scheduled' ), 10, 2 );
216
  }
217
  }
@@ -257,11 +286,13 @@ class BNFW {
257
  /**
258
  * Fires when a post is created for the first time.
259
  *
 
 
 
 
260
  * @since 1.3.1
261
- * @param int $post_id Post ID
262
- * @param object $post Post object
263
  */
264
- public function insert_post( $post_id, $post ) {
265
  // Some themes like P2, directly insert posts into DB.
266
  $insert_post_themes = apply_filters( 'bnfw_insert_post_themes', array( 'P2', 'Syncope' ) );
267
  $current_theme = wp_get_theme();
@@ -271,10 +302,10 @@ class BNFW {
271
  *
272
  * @since 1.4
273
  */
274
- $trigger_insert_post = apply_filters( 'bnfw_trigger_insert_post', false, $post_id );
275
 
276
  if ( in_array( $current_theme->get( 'Name' ), $insert_post_themes ) || $trigger_insert_post ) {
277
- $this->handle_inserted_post( $post_id );
278
  }
279
  }
280
 
@@ -291,11 +322,12 @@ class BNFW {
291
  /**
292
  * Trigger correct notifications for inserted posts.
293
  *
294
- * @since 1.6.7
295
- *
296
  * @param int $post_id Post id.
 
 
 
297
  */
298
- private function handle_inserted_post( $post_id ) {
299
  $post = get_post( $post_id );
300
 
301
  if ( ! is_a( $post, 'WP_Post' ) ) {
@@ -304,7 +336,11 @@ class BNFW {
304
 
305
  switch ( $post->post_status ) {
306
  case 'publish':
307
- $this->publish_post( $post );
 
 
 
 
308
  break;
309
 
310
  case 'private':
@@ -357,9 +393,8 @@ class BNFW {
357
  * @since 1.0
358
  * @param unknown $post
359
  */
360
- function update_post( $post ) {
361
- // Block editor sends duplicate requests on post update.
362
- if ( ( isset( $_GET['meta-box-loader'] ) || isset( $_GET['meta_box'] ) ) ) {
363
  return;
364
  }
365
 
@@ -378,7 +413,11 @@ class BNFW {
378
  * @param int $post_id Post ID
379
  * @param object $post Post object
380
  */
381
- function on_post_pending( $post_id, $post ) {
 
 
 
 
382
  $post_type = $post->post_type;
383
 
384
  if ( BNFW_Notification::POST_TYPE != $post_type ) {
@@ -406,6 +445,21 @@ class BNFW {
406
  }
407
  }
408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
  /**
410
  * Send notification for new comments
411
  *
@@ -1061,6 +1115,17 @@ class BNFW {
1061
 
1062
  return '';
1063
  }
 
 
 
 
 
 
 
 
 
 
 
1064
  }
1065
 
1066
  /* ------------------------------------------------------------------------ *
3
  * Plugin Name: Better Notifications for WP
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.6
7
  * Author: Made with Fuel
8
  * Author URI: https://betternotificationsforwp.com/
9
  * Author Email: hello@betternotificationsforwp.com
14
  */
15
 
16
  /**
17
+ * Copyright © 2020 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.
133
  add_action( 'pending_to_private' , array( $this, 'private_post' ) );
134
  add_action( 'publish_to_private' , array( $this, 'private_post' ) );
135
 
136
+ add_action( 'wp_insert_post' , array( $this, 'insert_post' ), 10, 3 );
137
 
138
  add_action( 'auto-draft_to_publish' , array( $this, 'publish_post' ) );
139
  add_action( 'draft_to_publish' , array( $this, 'publish_post' ) );
145
  add_action( 'publish_to_publish' , array( $this, 'update_post' ) );
146
  add_action( 'private_to_private' , array( $this, 'update_post' ) );
147
 
148
+ add_action( 'transition_post_status', array( $this, 'on_post_transition' ), 10, 3 );
149
+
150
  add_action( 'init' , array( $this, 'custom_post_type_hooks' ), 100 );
151
  add_action( 'create_term' , array( $this, 'create_term' ), 10, 3 );
152
 
153
+ add_action( 'transition_comment_status', array( $this, 'on_comment_status_change' ), 10, 3 );
154
  add_action( 'comment_post' , array( $this, 'comment_post' ) );
155
  add_action( 'trackback_post' , array( $this, 'trackback_post' ) );
156
  add_action( 'pingback_post' , array( $this, 'pingback_post' ) );
199
  public function add_capability_to_admin() {
200
  $admins = get_role( 'administrator' );
201
 
202
+ if ( is_null( $admins ) ) {
203
+ return;
204
+ }
205
+
206
  if ( ! $admins->has_cap( 'bnfw' ) ) {
207
  $admins->add_cap( 'bnfw' );
208
  }
209
  }
210
 
211
+ /**
212
+ * On post transition.
213
+ *
214
+ * @param string $new_status New post status.
215
+ * @param string $old_status Old post status.
216
+ * @param \WP_Post $post Post object.
217
+ */
218
+ public function on_post_transition( $new_status, $old_status, $post ) {
219
+ if ( ! is_a( $post, 'WP_Post' ) ) {
220
+ return;
221
+ }
222
+
223
+ if ( 'pending' === $old_status ) {
224
+ return;
225
+ }
226
+
227
+ if ( 'pending' !== $new_status ) {
228
+ return;
229
+ }
230
+
231
+ $this->on_post_pending( $post->ID, $post );
232
+ }
233
+
234
  /**
235
  * Setup hooks for custom post types.
236
  *
241
  $post_types = array_diff( $post_types, array( BNFW_Notification::POST_TYPE ) );
242
 
243
  foreach ( $post_types as $post_type ) {
 
244
  add_action( 'future_' . $post_type, array( $this, 'on_post_scheduled' ), 10, 2 );
245
  }
246
  }
286
  /**
287
  * Fires when a post is created for the first time.
288
  *
289
+ * @param int $post_id Post ID
290
+ * @param object $post Post object
291
+ * @param bool $update Whether this is an existing post being updated or not.
292
+ *
293
  * @since 1.3.1
 
 
294
  */
295
+ public function insert_post( $post_id, $post, $update ) {
296
  // Some themes like P2, directly insert posts into DB.
297
  $insert_post_themes = apply_filters( 'bnfw_insert_post_themes', array( 'P2', 'Syncope' ) );
298
  $current_theme = wp_get_theme();
302
  *
303
  * @since 1.4
304
  */
305
+ $trigger_insert_post = apply_filters( 'bnfw_trigger_insert_post', false, $post_id, $update );
306
 
307
  if ( in_array( $current_theme->get( 'Name' ), $insert_post_themes ) || $trigger_insert_post ) {
308
+ $this->handle_inserted_post( $post_id, $update );
309
  }
310
  }
311
 
322
  /**
323
  * Trigger correct notifications for inserted posts.
324
  *
 
 
325
  * @param int $post_id Post id.
326
+ * @param bool $update Whether the post was updated.
327
+ *
328
+ * @since 1.6.7
329
  */
330
+ private function handle_inserted_post( $post_id, $update ) {
331
  $post = get_post( $post_id );
332
 
333
  if ( ! is_a( $post, 'WP_Post' ) ) {
336
 
337
  switch ( $post->post_status ) {
338
  case 'publish':
339
+ if ( $update ) {
340
+ $this->update_post( $post );
341
+ } else {
342
+ $this->publish_post( $post );
343
+ }
344
  break;
345
 
346
  case 'private':
393
  * @since 1.0
394
  * @param unknown $post
395
  */
396
+ public function update_post( $post ) {
397
+ if ( $this->is_metabox_request() ) {
 
398
  return;
399
  }
400
 
413
  * @param int $post_id Post ID
414
  * @param object $post Post object
415
  */
416
+ public function on_post_pending( $post_id, $post ) {
417
+ if ( $this->is_metabox_request() ) {
418
+ return;
419
+ }
420
+
421
  $post_type = $post->post_type;
422
 
423
  if ( BNFW_Notification::POST_TYPE != $post_type ) {
445
  }
446
  }
447
 
448
+ /**
449
+ * When the status of a comment is changed.
450
+ *
451
+ * @param string $new_status New status.
452
+ * @param string $old_status Old status.
453
+ * @param \WP_Comment $comment Comment.
454
+ */
455
+ public function on_comment_status_change( $new_status, $old_status, $comment ) {
456
+ if ( 'approved' !== $new_status ) {
457
+ return;
458
+ }
459
+
460
+ $this->send_notification( 'approve-comment', $comment->comment_ID );
461
+ }
462
+
463
  /**
464
  * Send notification for new comments
465
  *
1115
 
1116
  return '';
1117
  }
1118
+
1119
+ /**
1120
+ * Is this a metabox request?
1121
+ *
1122
+ * Block editor sends duplicate requests on post update.
1123
+ *
1124
+ * @return bool True if metabox request, False otherwise.
1125
+ */
1126
+ protected function is_metabox_request() {
1127
+ return ( isset( $_GET['meta-box-loader'] ) || isset( $_GET['meta_box'] ) );
1128
+ }
1129
  }
1130
 
1131
  /* ------------------------------------------------------------------------ *
includes/admin/bnfw-settings.php CHANGED
@@ -43,7 +43,7 @@ function bnfw_settings_page() {
43
  settings_fields( 'bnfw-settings' );
44
  do_settings_sections( 'bnfw-settings' );
45
 
46
- submit_button( 'Save Settings' );
47
  ?>
48
  </form>
49
  </div>
@@ -70,21 +70,21 @@ function bnfw_menu_item_links() {
70
 
71
  // Documentation Link
72
  $submenu['edit.php?post_type=bnfw_notification'][500] = array(
73
- '<div id="bnfw-menu-item-documentation" style="color: #73daeb;">Documentation</div>',
74
  'bnfw',
75
  $doc_url,
76
  );
77
 
78
  // Add-ons Link
79
  $submenu['edit.php?post_type=bnfw_notification'][600] = array(
80
- '<div id="bnfw-menu-item-addons" style="color: #ff6f59;">Premium Add-ons</div>',
81
  'bnfw',
82
  $store_url,
83
  );
84
 
85
  // Add-ons Link
86
  $submenu['edit.php?post_type=bnfw_notification'][700] = array(
87
- '<div id="bnfw-menu-item-support" style="color: #f00001;">Priority Support</div>',
88
  'bnfw',
89
  $support_url,
90
  );
43
  settings_fields( 'bnfw-settings' );
44
  do_settings_sections( 'bnfw-settings' );
45
 
46
+ submit_button( __( 'Save Settings', 'bnfw' ) );
47
  ?>
48
  </form>
49
  </div>
70
 
71
  // Documentation Link
72
  $submenu['edit.php?post_type=bnfw_notification'][500] = array(
73
+ '<div id="bnfw-menu-item-documentation" style="color: #73daeb;">' . __( 'Documentation', 'bnfw' ) . '</div>',
74
  'bnfw',
75
  $doc_url,
76
  );
77
 
78
  // Add-ons Link
79
  $submenu['edit.php?post_type=bnfw_notification'][600] = array(
80
+ '<div id="bnfw-menu-item-addons" style="color: #ff6f59;">' . __( 'Premium Add-ons', 'bnfw' ) . '</div>',
81
  'bnfw',
82
  $store_url,
83
  );
84
 
85
  // Add-ons Link
86
  $submenu['edit.php?post_type=bnfw_notification'][700] = array(
87
+ '<div id="bnfw-menu-item-support" style="color: #f00001;">' . __( 'Priority Support', 'bnfw' ) . '</div>',
88
  'bnfw',
89
  $support_url,
90
  );
includes/admin/class-bnfw-notification.php CHANGED
@@ -122,6 +122,8 @@ class BNFW_Notification {
122
  * @since 1.0
123
  */
124
  public function add_meta_boxes() {
 
 
125
  add_meta_box(
126
  'bnfw-post-notification', // Unique ID
127
  esc_html__( 'Notification Settings', 'bnfw' ), // Title
@@ -139,6 +141,12 @@ class BNFW_Notification {
139
  'side',
140
  'core'
141
  );
 
 
 
 
 
 
142
  }
143
 
144
  /**
@@ -180,7 +188,7 @@ class BNFW_Notification {
180
  </th>
181
  <td>
182
  <select name="notification" id="notification" class="select2"
183
- data-placeholder="Select the notification type" style="width:75%">
184
  <optgroup label="<?php _e( 'Admin', 'bnfw' ); ?>">
185
  <option
186
  value="admin-user" <?php selected( 'admin-user', $setting['notification'] ); ?>><?php esc_html_e( 'New User Registration - For Admin', 'bnfw' ); ?></option>
@@ -209,7 +217,7 @@ class BNFW_Notification {
209
  </optgroup>
210
  <?php do_action( 'bnfw_after_default_notifications_optgroup', $setting ); ?>
211
 
212
- <optgroup label="Transactional">
213
  <option
214
  value="new-user" <?php selected( 'new-user', $setting['notification'] ); ?>><?php esc_html_e( 'New User Registration - For User', 'bnfw' ); ?></option>
215
  <option
@@ -267,6 +275,9 @@ class BNFW_Notification {
267
  <option value="moderate-post-comment" <?php selected( 'moderate-post-comment', $setting['notification'] ); ?>>
268
  <?php esc_html_e( 'New Comment Awaiting Moderation', 'bnfw' ); ?>
269
  </option>
 
 
 
270
  <option
271
  value="newterm-category" <?php selected( 'newterm-category', $setting['notification'] ); ?>><?php esc_html_e( 'New Category', 'bnfw' ); ?></option>
272
  <option
@@ -421,9 +432,9 @@ foreach ( $taxs as $tax ) {
421
  </th>
422
  <td>
423
  <input type="text" name="from-name" value="<?php echo esc_attr( $setting['from-name'] ); ?>"
424
- placeholder="Site Name" style="width: 37.35%">
425
  <input type="text" name="from-email" value="<?php echo esc_attr( $setting['from-email'] ); ?>"
426
- placeholder="Site Email" style="width: 37.3%">
427
  </td>
428
  </tr>
429
 
@@ -435,9 +446,9 @@ foreach ( $taxs as $tax ) {
435
  </th>
436
  <td>
437
  <input type="text" name="reply-name" value="<?php echo esc_attr( $setting['reply-name'] ); ?>"
438
- placeholder="Name" style="width: 37.35%">
439
  <input type="text" name="reply-email" value="<?php echo esc_attr( $setting['reply-email'] ); ?>"
440
- placeholder="Email" style="width: 37.3%">
441
  </td>
442
  </tr>
443
 
@@ -449,7 +460,7 @@ foreach ( $taxs as $tax ) {
449
 
450
  <td>
451
  <select multiple name="cc[]" class="<?php echo sanitize_html_class( bnfw_get_user_select_class() ); ?>"
452
- data-placeholder="<?php echo apply_filters( 'bnfw_email_dropdown_placeholder', 'Select User Roles / Users' ); ?>" style="width:75%">
453
  <?php bnfw_render_users_dropdown( $setting['cc'] ); ?>
454
  </select>
455
  </td>
@@ -463,7 +474,7 @@ foreach ( $taxs as $tax ) {
463
 
464
  <td>
465
  <select multiple name="bcc[]" class="<?php echo sanitize_html_class( bnfw_get_user_select_class() ); ?>"
466
- data-placeholder="<?php echo apply_filters( 'bnfw_email_dropdown_placeholder', 'Select User Roles / Users' ); ?>" style="width:75%">
467
  <?php bnfw_render_users_dropdown( $setting['bcc'] ); ?>
468
  </select>
469
  </td>
@@ -474,7 +485,7 @@ foreach ( $taxs as $tax ) {
474
  <tr valign="top" id="post-author">
475
  <th>
476
  <?php esc_html_e( 'Send to Author', 'bnfw' ); ?>
477
- <div class="bnfw-help-tip"><p><?php esc_html_e( 'E.g. If you want a new comment notification to go to the author of the post that was commented on, tick this box. Doing so will hide the "Send To" box below.', 'bnfw' ); ?></p></div>
478
  </th>
479
 
480
  <td>
@@ -512,7 +523,7 @@ foreach ( $taxs as $tax ) {
512
  <td>
513
  <select multiple id="users-select" name="users[]"
514
  class="<?php echo sanitize_html_class( bnfw_get_user_select_class() ); ?>"
515
- data-placeholder="<?php echo apply_filters( 'bnfw_email_dropdown_placeholder', 'Select User Roles / Users' ); ?>" style="width:75%">
516
  <?php bnfw_render_users_dropdown( $setting['users'] ); ?>
517
  </select>
518
  </td>
@@ -530,7 +541,7 @@ foreach ( $taxs as $tax ) {
530
  <td>
531
  <select multiple id="exclude-users-select" name="exclude-users[]"
532
  class="<?php echo sanitize_html_class( bnfw_get_user_select_class() ); ?>"
533
- data-placeholder="<?php echo apply_filters( 'bnfw_email_dropdown_placeholder', 'Select User Roles / Users' ); ?>" style="width:75%">
534
  <?php bnfw_render_users_dropdown( $setting['exclude-users'] ); ?>
535
  </select>
536
  </td>
@@ -742,7 +753,7 @@ foreach ( $taxs as $tax ) {
742
  $setting['show-fields'] = 'false';
743
  }
744
 
745
- $setting = apply_filters( 'bnfw_notification_setting', $setting );
746
 
747
  $this->save_settings( $post_id, $setting );
748
 
@@ -883,7 +894,7 @@ foreach ( $taxs as $tax ) {
883
 
884
  <?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?>
885
  <div style="display:none;">
886
- <?php submit_button( esc_html__( 'Save' ), 'button', 'save' ); ?>
887
  </div>
888
 
889
  <?php // Always publish. ?>
@@ -1000,9 +1011,13 @@ foreach ( $taxs as $tax ) {
1000
  $args['posts_per_page'] = -1;
1001
  $args['nopagging'] = true;
1002
 
 
 
1003
  $wp_query = new WP_Query();
1004
  $posts = $wp_query->query( $args );
1005
 
 
 
1006
  return $posts;
1007
  }
1008
 
@@ -1031,9 +1046,13 @@ foreach ( $taxs as $tax ) {
1031
  )
1032
  );
1033
 
 
 
1034
  $wp_query = new WP_Query();
1035
  $posts = $wp_query->query( $args );
1036
 
 
 
1037
  return count( $posts ) > 0;
1038
  }
1039
 
@@ -1173,6 +1192,9 @@ foreach ( $taxs as $tax ) {
1173
  case 'new-comment':
1174
  $name = esc_html__( 'New Comment', 'bnfw' );
1175
  break;
 
 
 
1176
  case 'moderate-comment':
1177
  $name = esc_html__( 'New Comment Awaiting Moderation', 'bnfw' );
1178
  break;
122
  * @since 1.0
123
  */
124
  public function add_meta_boxes() {
125
+ global $post;
126
+
127
  add_meta_box(
128
  'bnfw-post-notification', // Unique ID
129
  esc_html__( 'Notification Settings', 'bnfw' ), // Title
141
  'side',
142
  'core'
143
  );
144
+
145
+ if ( self::POST_TYPE !== get_post_type( $post ) ) {
146
+ return;
147
+ }
148
+
149
+ do_action( 'bnfw_after_metaboxes', $this->read_settings( $post->ID ) );
150
  }
151
 
152
  /**
188
  </th>
189
  <td>
190
  <select name="notification" id="notification" class="select2"
191
+ data-placeholder="<?php _e( 'Select the notification type', 'bnfw' ); ?>" style="width:75%">
192
  <optgroup label="<?php _e( 'Admin', 'bnfw' ); ?>">
193
  <option
194
  value="admin-user" <?php selected( 'admin-user', $setting['notification'] ); ?>><?php esc_html_e( 'New User Registration - For Admin', 'bnfw' ); ?></option>
217
  </optgroup>
218
  <?php do_action( 'bnfw_after_default_notifications_optgroup', $setting ); ?>
219
 
220
+ <optgroup label="<?php _e( 'Transactional', 'bnfw' ); ?>">
221
  <option
222
  value="new-user" <?php selected( 'new-user', $setting['notification'] ); ?>><?php esc_html_e( 'New User Registration - For User', 'bnfw' ); ?></option>
223
  <option
275
  <option value="moderate-post-comment" <?php selected( 'moderate-post-comment', $setting['notification'] ); ?>>
276
  <?php esc_html_e( 'New Comment Awaiting Moderation', 'bnfw' ); ?>
277
  </option>
278
+ <option value="approve-comment" <?php selected( 'approve-comment', $setting['notification'] ); ?>>
279
+ <?php esc_html_e( 'Comment Approved', 'bnfw' ); ?>
280
+ </option>
281
  <option
282
  value="newterm-category" <?php selected( 'newterm-category', $setting['notification'] ); ?>><?php esc_html_e( 'New Category', 'bnfw' ); ?></option>
283
  <option
432
  </th>
433
  <td>
434
  <input type="text" name="from-name" value="<?php echo esc_attr( $setting['from-name'] ); ?>"
435
+ placeholder="<?php _e( 'Site Name', 'bnfw' ); ?>" style="width: 37.35%">
436
  <input type="text" name="from-email" value="<?php echo esc_attr( $setting['from-email'] ); ?>"
437
+ placeholder="<?php _e( 'Site Email', 'bnfw' ); ?>" style="width: 37.3%">
438
  </td>
439
  </tr>
440
 
446
  </th>
447
  <td>
448
  <input type="text" name="reply-name" value="<?php echo esc_attr( $setting['reply-name'] ); ?>"
449
+ placeholder="<?php _e( 'Name', 'bnfw' ); ?>" style="width: 37.35%">
450
  <input type="text" name="reply-email" value="<?php echo esc_attr( $setting['reply-email'] ); ?>"
451
+ placeholder="<?php _e( 'Email', 'bnfw' ); ?>" style="width: 37.3%">
452
  </td>
453
  </tr>
454
 
460
 
461
  <td>
462
  <select multiple name="cc[]" class="<?php echo sanitize_html_class( bnfw_get_user_select_class() ); ?>"
463
+ data-placeholder="<?php echo apply_filters( 'bnfw_email_dropdown_placeholder', __( 'Select User Roles / Users', 'bnfw' ) ); ?>" style="width:75%">
464
  <?php bnfw_render_users_dropdown( $setting['cc'] ); ?>
465
  </select>
466
  </td>
474
 
475
  <td>
476
  <select multiple name="bcc[]" class="<?php echo sanitize_html_class( bnfw_get_user_select_class() ); ?>"
477
+ data-placeholder="<?php echo apply_filters( 'bnfw_email_dropdown_placeholder', __( 'Select User Roles / Users', 'bnfw' ) ); ?>" style="width:75%">
478
  <?php bnfw_render_users_dropdown( $setting['bcc'] ); ?>
479
  </select>
480
  </td>
485
  <tr valign="top" id="post-author">
486
  <th>
487
  <?php esc_html_e( 'Send to Author', 'bnfw' ); ?>
488
+ <div class="bnfw-help-tip"><p><?php esc_html_e( 'E.g. If you want a new comment notification to go to the author of the post that was commented on, tick this box.', 'bnfw' ); ?></p></div>
489
  </th>
490
 
491
  <td>
523
  <td>
524
  <select multiple id="users-select" name="users[]"
525
  class="<?php echo sanitize_html_class( bnfw_get_user_select_class() ); ?>"
526
+ data-placeholder="<?php echo apply_filters( 'bnfw_email_dropdown_placeholder', __( 'Select User Roles / Users', 'bnfw' ) ); ?>" style="width:75%">
527
  <?php bnfw_render_users_dropdown( $setting['users'] ); ?>
528
  </select>
529
  </td>
541
  <td>
542
  <select multiple id="exclude-users-select" name="exclude-users[]"
543
  class="<?php echo sanitize_html_class( bnfw_get_user_select_class() ); ?>"
544
+ data-placeholder="<?php echo apply_filters( 'bnfw_email_dropdown_placeholder', __( 'Select User Roles / Users', 'bnfw' ) ); ?>" style="width:75%">
545
  <?php bnfw_render_users_dropdown( $setting['exclude-users'] ); ?>
546
  </select>
547
  </td>
753
  $setting['show-fields'] = 'false';
754
  }
755
 
756
+ $setting = apply_filters( 'bnfw_notification_setting', $setting, $_POST );
757
 
758
  $this->save_settings( $post_id, $setting );
759
 
894
 
895
  <?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?>
896
  <div style="display:none;">
897
+ <?php submit_button( esc_html__( 'Save', 'bnfw' ), 'button', 'save' ); ?>
898
  </div>
899
 
900
  <?php // Always publish. ?>
1011
  $args['posts_per_page'] = -1;
1012
  $args['nopagging'] = true;
1013
 
1014
+ $args = apply_filters( 'bnfw_get_notifications_args', $args, $types, $exclude_disabled );
1015
+
1016
  $wp_query = new WP_Query();
1017
  $posts = $wp_query->query( $args );
1018
 
1019
+ $posts = apply_filters( 'bnfw_get_notifications_posts', $posts, $args, $types, $exclude_disabled );
1020
+
1021
  return $posts;
1022
  }
1023
 
1046
  )
1047
  );
1048
 
1049
+ $args = apply_filters( 'bnfw_is_notification_disabled_args', $args, $type );
1050
+
1051
  $wp_query = new WP_Query();
1052
  $posts = $wp_query->query( $args );
1053
 
1054
+ $posts = apply_filters( 'bnfw_is_notification_disabled_posts', $posts, $args, $type );
1055
+
1056
  return count( $posts ) > 0;
1057
  }
1058
 
1192
  case 'new-comment':
1193
  $name = esc_html__( 'New Comment', 'bnfw' );
1194
  break;
1195
+ case 'approve-comment':
1196
+ $name = esc_html__( 'Comment Approved', 'bnfw' );
1197
+ break;
1198
  case 'moderate-comment':
1199
  $name = esc_html__( 'New Comment Awaiting Moderation', 'bnfw' );
1200
  break;
includes/engine/class-bnfw-engine.php CHANGED
@@ -15,8 +15,8 @@ class BNFW_Engine {
15
  * @param array $setting
16
  */
17
  public function send_test_email( $setting ) {
18
- $subject = 'Test Email: ' . $setting['subject'];
19
- $message = '<p><strong>This is a test email. All shortcodes below will show in place but not be replaced with content.</strong></p>' . stripslashes( $setting['message'] );
20
 
21
  if ( 'true' != $setting['disable-autop'] && 'html' == $setting['email-formatting'] ) {
22
  $message = wpautop( $message );
@@ -66,7 +66,7 @@ class BNFW_Engine {
66
  $headers[] = 'Content-type: text/plain';
67
  }
68
 
69
- $emails = apply_filters( 'bnfw_emails', $emails, $setting );
70
 
71
  $send = apply_filters( 'bnfw_can_send_email', true, $setting, $emails, $subject, $message, $headers );
72
 
@@ -369,6 +369,7 @@ class BNFW_Engine {
369
  public function handle_shortcodes( $message, $notification, $extra_data ) {
370
  switch ( $notification ) {
371
  case 'new-comment':
 
372
  case 'new-trackback':
373
  case 'new-pingback':
374
  case 'reply-comment':
@@ -553,7 +554,7 @@ class BNFW_Engine {
553
  $message = str_replace( '[post_date_gmt]', bnfw_format_date( $post->post_date_gmt ), $message );
554
  $message = str_replace( '[post_content]', $post_content, $message );
555
  $message = str_replace( '[post_title]', $post->post_title, $message );
556
- $message = str_replace( '[post_excerpt]', ( $this->may_be_strip_shortcode( $post->post_excerpt ? $post->post_excerpt : wp_trim_words( $post_content ) ) ), $message );
557
  $message = str_replace( '[post_status]', $post->post_status, $message );
558
  $message = str_replace( '[comment_status]', $post->comment_status, $message );
559
  $message = str_replace( '[ping_status]', $post->ping_status, $message );
@@ -596,14 +597,22 @@ class BNFW_Engine {
596
  $message = str_replace( '[post_scheduled_date_gmt]', 'Published', $message );
597
  }
598
 
599
- $category_list = implode( ', ', wp_get_post_categories( $post_id, array( 'fields' => 'names' ) ) );
600
- $message = str_replace( '[post_category]', $category_list, $message );
601
 
602
- $category_slugs = wp_get_post_categories( $post_id, array( 'fields' => 'id=>slug' ) );
603
- $category_slugs = array_values( $category_slugs );
604
 
605
- if ( count( $category_slugs ) > 0 ) {
606
- $message = str_replace( '[post_category_slug]', $category_slugs[0], $message );
 
 
 
 
 
 
 
 
 
 
607
  }
608
 
609
  $tag_list = implode( ', ', wp_get_post_tags( $post_id, array( 'fields' => 'names' ) ) );
15
  * @param array $setting
16
  */
17
  public function send_test_email( $setting ) {
18
+ $subject = __( 'Test Email:', 'bnfw' ) . ' ' . $setting['subject'];
19
+ $message = '<p><strong>' . __( 'This is a test email. All shortcodes below will show in place but not be replaced with content.', 'bnfw' ) . '</strong></p>' . stripslashes( $setting['message'] );
20
 
21
  if ( 'true' != $setting['disable-autop'] && 'html' == $setting['email-formatting'] ) {
22
  $message = wpautop( $message );
66
  $headers[] = 'Content-type: text/plain';
67
  }
68
 
69
+ $emails = apply_filters( 'bnfw_emails', $emails, $setting, $id );
70
 
71
  $send = apply_filters( 'bnfw_can_send_email', true, $setting, $emails, $subject, $message, $headers );
72
 
369
  public function handle_shortcodes( $message, $notification, $extra_data ) {
370
  switch ( $notification ) {
371
  case 'new-comment':
372
+ case 'approve-comment':
373
  case 'new-trackback':
374
  case 'new-pingback':
375
  case 'reply-comment':
554
  $message = str_replace( '[post_date_gmt]', bnfw_format_date( $post->post_date_gmt ), $message );
555
  $message = str_replace( '[post_content]', $post_content, $message );
556
  $message = str_replace( '[post_title]', $post->post_title, $message );
557
+ $message = str_replace( '[post_excerpt]', $this->may_be_strip_shortcode( get_the_excerpt( $post ) ), $message );
558
  $message = str_replace( '[post_status]', $post->post_status, $message );
559
  $message = str_replace( '[comment_status]', $post->comment_status, $message );
560
  $message = str_replace( '[ping_status]', $post->ping_status, $message );
597
  $message = str_replace( '[post_scheduled_date_gmt]', 'Published', $message );
598
  }
599
 
600
+ $categories = wp_get_post_categories( $post_id, array( 'fields' => 'all' ) );
 
601
 
602
+ $message = str_replace( '[post_category]', implode( ', ', wp_list_pluck( $categories, 'name' ) ), $message );
 
603
 
604
+ if ( count( $categories ) > 0 ) {
605
+ $message = str_replace(
606
+ array(
607
+ '[post_category_slug]',
608
+ '[post_category_description]',
609
+ ),
610
+ array(
611
+ $categories[0]->slug,
612
+ $categories[0]->description,
613
+ ),
614
+ $message
615
+ );
616
  }
617
 
618
  $tag_list = implode( ', ', wp_get_post_tags( $post_id, array( 'fields' => 'names' ) ) );
includes/helpers/helpers.php CHANGED
@@ -35,7 +35,7 @@ function bnfw_render_users_dropdown( $selected_users ) {
35
  $non_wp_users = $selected_users;
36
  $user_count = count_users();
37
  ?>
38
- <optgroup label="User Roles">
39
  <?php
40
  $roles = $wp_roles->get_names();
41
 
@@ -56,12 +56,12 @@ function bnfw_render_users_dropdown( $selected_users ) {
56
  if ( isset( $user_count['avail_roles'][ $role_slug ] ) ) {
57
  $count = $user_count['avail_roles'][ $role_slug ];
58
  }
59
- echo '<option value="role-', esc_attr( $role_slug ), '" ', $selected, '>', esc_html( $role_name ), ' (', $count, ' Users)', '</option>';
60
  }
61
  ?>
62
  </optgroup>
63
 
64
- <optgroup label="Users">
65
  <?php
66
  $args = array(
67
  'order_by' => 'email',
@@ -100,7 +100,7 @@ function bnfw_render_users_dropdown( $selected_users ) {
100
  </optgroup>
101
 
102
  <?php if ( ! empty( $non_wp_users ) ) { ?>
103
- <optgroup label="Non WordPress Users">
104
  <?php foreach ( $non_wp_users as $non_wp_user ) {
105
  echo '<option value="', esc_attr( $non_wp_user ), '" selected >', esc_html( $non_wp_user ), '</option>';
106
  }
@@ -124,6 +124,7 @@ function bnfw_is_comment_notification( $notification_name ) {
124
  case 'new-trackback':
125
  case 'new-pingback':
126
  case 'reply-comment':
 
127
  $is_comment_notification = true;
128
  break;
129
 
35
  $non_wp_users = $selected_users;
36
  $user_count = count_users();
37
  ?>
38
+ <optgroup label="<?php _e( 'User Roles', 'bnfw' ); ?>">
39
  <?php
40
  $roles = $wp_roles->get_names();
41
 
56
  if ( isset( $user_count['avail_roles'][ $role_slug ] ) ) {
57
  $count = $user_count['avail_roles'][ $role_slug ];
58
  }
59
+ echo '<option value="role-', esc_attr( $role_slug ), '" ', $selected, '>', esc_html( $role_name ), ' (', $count, ' ' . __( 'Users', 'bnfw' ) . ')', '</option>';
60
  }
61
  ?>
62
  </optgroup>
63
 
64
+ <optgroup label="<?php _e( 'Users', 'bnfw' ); ?>">
65
  <?php
66
  $args = array(
67
  'order_by' => 'email',
100
  </optgroup>
101
 
102
  <?php if ( ! empty( $non_wp_users ) ) { ?>
103
+ <optgroup label="<?php _e( 'Non WordPress Users', 'bnfw' ); ?>">
104
  <?php foreach ( $non_wp_users as $non_wp_user ) {
105
  echo '<option value="', esc_attr( $non_wp_user ), '" selected >', esc_html( $non_wp_user ), '</option>';
106
  }
124
  case 'new-trackback':
125
  case 'new-pingback':
126
  case 'reply-comment':
127
+ case 'approve-comment':
128
  $is_comment_notification = true;
129
  break;
130