Better Notifications for WordPress - Version 1.6.6

Version Description

  • 28th June 2017 =
  • Fixed: New Comments on Custom Post Types weren't always sending notifications.
  • Fixed: An issue where using the bnfw_trigger_insert_post() filter wasn't always working correctly.
  • Fixed: An issue where checking a notification was disabled wasn't always working correctly.
  • Added: Support for limiting 'New User Registration - For User' notifications to specific user roles in the recently updated Conditional Notifications add-on.
  • Added: Support for huge logic enhancements to the soon to be updated Global Override add-on.
  • Added: Support for the new 'User Login Reminder' notification in the soon to be updated Reminders add-on.
Download this release

Release Info

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

Code changes from version 1.6.5 to 1.6.6

README.txt CHANGED
@@ -3,8 +3,8 @@ 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: 3.5
6
- Tested up to: 4.7.5
7
- Stable tag: 1.6.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -200,6 +200,14 @@ An older version might work but this is untested. A lot of the newer features re
200
 
201
  == Changelog ==
202
 
 
 
 
 
 
 
 
 
203
  = 1.6.5 - 18th May 2017 =
204
  * New: ACF Form compatibility has now been re-added! Props to @elliotcondon for the help.
205
  * Remember to subscribe to the [mailing list](http://voltronik.us2.list-manage2.com/subscribe?u=57c012217219b2d81dda0085f&id=28eebdab28) if you want to be notified of new add-ons for BNFW and receive 10% off your first add-on purchase.
3
  Donate link: https://betternotificationsforwp.com/donate/
4
  Tags: notification, email, push, sms, alert, HTML, customize, bulk, trigger, CC, BCC
5
  Requires at least: 3.5
6
+ Tested up to: 4.8
7
+ Stable tag: 1.6.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
200
 
201
  == Changelog ==
202
 
203
+ = 1.6.6 - 28th June 2017 =
204
+ * Fixed: New Comments on Custom Post Types weren't always sending notifications.
205
+ * Fixed: An issue where using the `bnfw_trigger_insert_post()` filter wasn't always working correctly.
206
+ * Fixed: An issue where checking a notification was disabled wasn't always working correctly.
207
+ * Added: Support for limiting 'New User Registration - For User' notifications to specific user roles in the recently updated [Conditional Notifications add-on](https://betternotificationsforwp.com/downloads/conditional-notifications/).
208
+ * Added: Support for huge logic enhancements to the soon to be updated [Global Override add-on](https://betternotificationsforwp.com/downloads/per-post-override/).
209
+ * Added: Support for the new 'User Login Reminder' notification in the soon to be updated [Reminders add-on](https://betternotificationsforwp.com/downloads/update-reminder/).
210
+
211
  = 1.6.5 - 18th May 2017 =
212
  * New: ACF Form compatibility has now been re-added! Props to @elliotcondon for the help.
213
  * Remember to subscribe to the [mailing list](http://voltronik.us2.list-manage2.com/subscribe?u=57c012217219b2d81dda0085f&id=28eebdab28) if you want to be notified of new add-ons for BNFW and receive 10% off your first add-on purchase.
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.6.5
7
  * Author: Made with Fuel
8
  * Author URI: https://betternotificationsforwp.com/
9
  * Author Email: hello@betternotificationsforwp.com
@@ -38,7 +38,18 @@ class BNFW {
38
  $this->includes();
39
  $this->hooks();
40
 
 
 
 
 
 
41
  $this->notifier = new BNFW_Notification;
 
 
 
 
 
 
42
  $this->engine = new BNFW_Engine;
43
  }
44
 
@@ -47,7 +58,7 @@ class BNFW {
47
  *
48
  * Makes sure that only one instance is created.
49
  *
50
- * @return object Instance of the class
51
  */
52
  public static function factory() {
53
  static $instance = false;
@@ -110,26 +121,13 @@ class BNFW {
110
 
111
  register_activation_hook( __FILE__, array( $this, 'activate' ) );
112
 
113
- // Some themes like P2, directly insert posts into DB.
114
- $insert_post_themes = apply_filters( 'bnfw_insert_post_themes', array( 'P2', 'Syncope' ) );
115
- $current_theme = wp_get_theme();
116
-
117
- /**
118
- * Whether to trigger insert post hook.
119
- *
120
- * @since 1.4
121
- */
122
- $trigger_insert_post = apply_filters( 'bnfw_trigger_insert_post', false );
123
-
124
- if ( in_array( $current_theme->get( 'Name' ), $insert_post_themes ) || $trigger_insert_post ) {
125
- add_action( 'wp_insert_post' , array( $this, 'insert_post' ), 10, 3 );
126
- }
127
-
128
  add_action( 'draft_to_private' , array( $this, 'private_post' ) );
129
  add_action( 'future_to_private' , array( $this, 'private_post' ) );
130
  add_action( 'pending_to_private' , array( $this, 'private_post' ) );
131
  add_action( 'publish_to_private' , array( $this, 'private_post' ) );
132
 
 
 
133
  add_action( 'draft_to_publish' , array( $this, 'publish_post' ) );
134
  add_action( 'future_to_publish' , array( $this, 'publish_post' ) );
135
  add_action( 'pending_to_publish' , array( $this, 'publish_post' ) );
@@ -226,10 +224,22 @@ class BNFW {
226
  * @since 1.3.1
227
  * @param int $post_id Post ID
228
  * @param object $post Post object
229
- * @param bool $update Whether it was an update
230
  */
231
- public function insert_post( $post_id, $post, $update ) {
232
- $this->publish_post( $post );
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  }
234
 
235
  /**
@@ -580,7 +590,7 @@ class BNFW {
580
  * @since 1.1
581
  * @param int $user_id New user id
582
  */
583
- function welcome_email( $user_id ) {
584
  $notifications = $this->notifier->get_notifications( 'welcome-email' );
585
  foreach ( $notifications as $notification ) {
586
  $this->engine->send_registration_email( $this->notifier->read_settings( $notification->ID ), get_userdata( $user_id ) );
@@ -658,7 +668,7 @@ class BNFW {
658
  * @param int $ref_id Reference id.
659
  */
660
  private function send_notification_async( $type, $ref_id ) {
661
- $notifications = $this->notifier->get_notifications( $type );
662
  foreach ( $notifications as $notification ) {
663
  $transient = get_transient( 'bnfw-async-notifications' );
664
  if ( ! is_array( $transient ) ) {
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.6.6
7
  * Author: Made with Fuel
8
  * Author URI: https://betternotificationsforwp.com/
9
  * Author Email: hello@betternotificationsforwp.com
38
  $this->includes();
39
  $this->hooks();
40
 
41
+ /**
42
+ * BNFW Notification.
43
+ *
44
+ * @var \BNFW_Notification
45
+ */
46
  $this->notifier = new BNFW_Notification;
47
+
48
+ /**
49
+ * BNFW Engine.
50
+ *
51
+ * @var \BNFW_Engine
52
+ */
53
  $this->engine = new BNFW_Engine;
54
  }
55
 
58
  *
59
  * Makes sure that only one instance is created.
60
  *
61
+ * @return \BNFW Instance of the class.
62
  */
63
  public static function factory() {
64
  static $instance = false;
121
 
122
  register_activation_hook( __FILE__, array( $this, 'activate' ) );
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  add_action( 'draft_to_private' , array( $this, 'private_post' ) );
125
  add_action( 'future_to_private' , array( $this, 'private_post' ) );
126
  add_action( 'pending_to_private' , array( $this, 'private_post' ) );
127
  add_action( 'publish_to_private' , array( $this, 'private_post' ) );
128
 
129
+ add_action( 'wp_insert_post' , array( $this, 'insert_post' ), 10, 2 );
130
+
131
  add_action( 'draft_to_publish' , array( $this, 'publish_post' ) );
132
  add_action( 'future_to_publish' , array( $this, 'publish_post' ) );
133
  add_action( 'pending_to_publish' , array( $this, 'publish_post' ) );
224
  * @since 1.3.1
225
  * @param int $post_id Post ID
226
  * @param object $post Post object
 
227
  */
228
+ public function insert_post( $post_id, $post ) {
229
+ // Some themes like P2, directly insert posts into DB.
230
+ $insert_post_themes = apply_filters( 'bnfw_insert_post_themes', array( 'P2', 'Syncope' ) );
231
+ $current_theme = wp_get_theme();
232
+
233
+ /**
234
+ * Whether to trigger insert post hook.
235
+ *
236
+ * @since 1.4
237
+ */
238
+ $trigger_insert_post = apply_filters( 'bnfw_trigger_insert_post', false );
239
+
240
+ if ( in_array( $current_theme->get( 'Name' ), $insert_post_themes ) || $trigger_insert_post ) {
241
+ $this->publish_post( $post );
242
+ }
243
  }
244
 
245
  /**
590
  * @since 1.1
591
  * @param int $user_id New user id
592
  */
593
+ public function welcome_email( $user_id ) {
594
  $notifications = $this->notifier->get_notifications( 'welcome-email' );
595
  foreach ( $notifications as $notification ) {
596
  $this->engine->send_registration_email( $this->notifier->read_settings( $notification->ID ), get_userdata( $user_id ) );
668
  * @param int $ref_id Reference id.
669
  */
670
  private function send_notification_async( $type, $ref_id ) {
671
+ $notifications = $this->notifier->get_notifications( $type, false );
672
  foreach ( $notifications as $notification ) {
673
  $transient = get_transient( 'bnfw-async-notifications' );
674
  if ( ! is_array( $transient ) ) {
includes/admin/class-bnfw-notification.php CHANGED
@@ -170,6 +170,8 @@ class BNFW_Notification {
170
  value="admin-role" <?php selected( 'admin-role', $setting['notification'] ); ?>><?php esc_html_e( 'User Role Changed - For Admin', 'bnfw' ); ?></option>
171
  <option
172
  value="core-updated" <?php selected( 'core-updated', $setting['notification'] ); ?>><?php esc_html_e( 'WordPress Core Automatic Background Updates', 'bnfw' ); ?></option>
 
 
173
  </optgroup>
174
  <optgroup label="Transactional">
175
  <option
@@ -186,6 +188,8 @@ class BNFW_Notification {
186
  value="user-role" <?php selected( 'user-role', $setting['notification'] ); ?>><?php esc_html_e( 'User Role Changed - For User', 'bnfw' ); ?></option>
187
  <option
188
  value="reply-comment" <?php selected( 'reply-comment', $setting['notification'] ); ?>><?php esc_html_e( 'Comment Reply', 'bnfw' ); ?></option>
 
 
189
  </optgroup>
190
  <optgroup label="Posts">
191
  <option
170
  value="admin-role" <?php selected( 'admin-role', $setting['notification'] ); ?>><?php esc_html_e( 'User Role Changed - For Admin', 'bnfw' ); ?></option>
171
  <option
172
  value="core-updated" <?php selected( 'core-updated', $setting['notification'] ); ?>><?php esc_html_e( 'WordPress Core Automatic Background Updates', 'bnfw' ); ?></option>
173
+
174
+ <?php do_action( 'bnfw_after_default_notifications', $setting ); ?>
175
  </optgroup>
176
  <optgroup label="Transactional">
177
  <option
188
  value="user-role" <?php selected( 'user-role', $setting['notification'] ); ?>><?php esc_html_e( 'User Role Changed - For User', 'bnfw' ); ?></option>
189
  <option
190
  value="reply-comment" <?php selected( 'reply-comment', $setting['notification'] ); ?>><?php esc_html_e( 'Comment Reply', 'bnfw' ); ?></option>
191
+
192
+ <?php do_action( 'bnfw_after_transactional_notifications', $setting ); ?>
193
  </optgroup>
194
  <optgroup label="Posts">
195
  <option
includes/engine/class-bnfw-engine.php CHANGED
@@ -46,7 +46,7 @@ class BNFW_Engine {
46
  *
47
  * @since 1.3.6
48
  */
49
- $notification_disabled = apply_filters( 'bnfw_notification_disabled', false, $id, $setting );
50
 
51
  if ( ! $notification_disabled ) {
52
  $subject = $this->handle_shortcodes( $setting['subject'], $setting['notification'], $id );
@@ -81,6 +81,17 @@ class BNFW_Engine {
81
  * @param string $password_url Plain text password in WP < 4.3 and password url in WP > 4.3
82
  */
83
  public function send_registration_email( $setting, $user, $password_url = '' ) {
 
 
 
 
 
 
 
 
 
 
 
84
  $user_id = $user->ID;
85
 
86
  $subject = $this->handle_shortcodes( $setting['subject'], $setting['notification'], $user_id );
@@ -444,7 +455,7 @@ class BNFW_Engine {
444
  *
445
  * @return string Processed string.
446
  */
447
- private function handle_global_user_shortcodes( $message, $email ) {
448
  $user = get_user_by( 'email', $email );
449
 
450
  if ( false === $user ) {
@@ -678,7 +689,7 @@ class BNFW_Engine {
678
  * @param int $id
679
  * @return array Emails
680
  */
681
- private function get_emails( $setting, $id ) {
682
  global $current_user;
683
 
684
  $emails = array();
@@ -707,7 +718,7 @@ class BNFW_Engine {
707
  $to_emails = array();
708
 
709
  if ( ! empty( $setting['users'] ) ) {
710
- $to_emails = $this->get_emails_from_users( $setting['users'], $exclude, $id );
711
  }
712
 
713
  /**
@@ -732,11 +743,11 @@ class BNFW_Engine {
732
  }
733
 
734
  if ( ! empty( $setting['cc'] ) ) {
735
- $emails['cc'] = $this->get_emails_from_users( $setting['cc'], $exclude, $id );
736
  }
737
 
738
  if ( ! empty( $setting['bcc'] ) ) {
739
- $emails['bcc'] = $this->get_emails_from_users( $setting['bcc'], $exclude, $id );
740
  }
741
  }
742
 
@@ -746,15 +757,16 @@ class BNFW_Engine {
746
  /**
747
  * Get emails from users.
748
  *
749
- * @since 1.2
750
  *
751
  * @param array $users Users Array
752
  * @param int $exclude User id to exclude
753
  * @param int $post_id Post id.
 
754
  *
755
  * @return array
756
  */
757
- public function get_emails_from_users( $users, $exclude = null, $post_id = 0 ) {
758
  $user_ids = array();
759
  $user_roles = array();
760
  $non_wp_users = array();
@@ -779,6 +791,14 @@ class BNFW_Engine {
779
 
780
  $emails_from_user_ids = $this->get_emails_from_id( $user_ids );
781
  $emails_from_user_roles = $this->get_emails_from_role( $user_roles, $exclude );
 
 
 
 
 
 
 
 
782
  $non_wp_emails = apply_filters( 'bnfw_non_wp_emails', array(), $non_wp_users, $post_id );
783
 
784
  return array_merge( $emails_from_user_roles, $emails_from_user_ids, $non_wp_emails );
@@ -884,7 +904,7 @@ class BNFW_Engine {
884
  * @param array $emails
885
  * @return array
886
  */
887
- private function get_headers( $emails ) {
888
  $headers = array();
889
 
890
  if ( ! empty( $emails['from'] ) ) {
46
  *
47
  * @since 1.3.6
48
  */
49
+ $notification_disabled = apply_filters( 'bnfw_notification_disabled', ( 'true' === $setting['disabled'] ), $id, $setting );
50
 
51
  if ( ! $notification_disabled ) {
52
  $subject = $this->handle_shortcodes( $setting['subject'], $setting['notification'], $id );
81
  * @param string $password_url Plain text password in WP < 4.3 and password url in WP > 4.3
82
  */
83
  public function send_registration_email( $setting, $user, $password_url = '' ) {
84
+ /**
85
+ * Whether to trigger welcome email notification or not.
86
+ *
87
+ * @since 1.7
88
+ */
89
+ $trigger_notification = apply_filters( 'bnfw_trigger_welcome-email_notification', true, $setting, $user );
90
+
91
+ if ( ! $trigger_notification ) {
92
+ return;
93
+ }
94
+
95
  $user_id = $user->ID;
96
 
97
  $subject = $this->handle_shortcodes( $setting['subject'], $setting['notification'], $user_id );
455
  *
456
  * @return string Processed string.
457
  */
458
+ public function handle_global_user_shortcodes( $message, $email ) {
459
  $user = get_user_by( 'email', $email );
460
 
461
  if ( false === $user ) {
689
  * @param int $id
690
  * @return array Emails
691
  */
692
+ public function get_emails( $setting, $id ) {
693
  global $current_user;
694
 
695
  $emails = array();
718
  $to_emails = array();
719
 
720
  if ( ! empty( $setting['users'] ) ) {
721
+ $to_emails = $this->get_emails_from_users( $setting['users'], $exclude, $id, $setting );
722
  }
723
 
724
  /**
743
  }
744
 
745
  if ( ! empty( $setting['cc'] ) ) {
746
+ $emails['cc'] = $this->get_emails_from_users( $setting['cc'], $exclude, $id, $setting );
747
  }
748
 
749
  if ( ! empty( $setting['bcc'] ) ) {
750
+ $emails['bcc'] = $this->get_emails_from_users( $setting['bcc'], $exclude, $id, $setting );
751
  }
752
  }
753
 
757
  /**
758
  * Get emails from users.
759
  *
760
+ * @since 1.2
761
  *
762
  * @param array $users Users Array
763
  * @param int $exclude User id to exclude
764
  * @param int $post_id Post id.
765
+ * @param array $setting Notification setting.
766
  *
767
  * @return array
768
  */
769
+ public function get_emails_from_users( $users, $exclude = null, $post_id = 0, $setting = array() ) {
770
  $user_ids = array();
771
  $user_roles = array();
772
  $non_wp_users = array();
791
 
792
  $emails_from_user_ids = $this->get_emails_from_id( $user_ids );
793
  $emails_from_user_roles = $this->get_emails_from_role( $user_roles, $exclude );
794
+
795
+ if ( ! empty( $setting ) ) {
796
+ if ( $this->starts_with( $setting['notification'], 'comment-' ) ) {
797
+ // for new comment notifications, we need to use post id instead of comment id.
798
+ $post_id = bnfw_get_post_id_from_comment( $post_id );
799
+ }
800
+ }
801
+
802
  $non_wp_emails = apply_filters( 'bnfw_non_wp_emails', array(), $non_wp_users, $post_id );
803
 
804
  return array_merge( $emails_from_user_roles, $emails_from_user_ids, $non_wp_emails );
904
  * @param array $emails
905
  * @return array
906
  */
907
+ public function get_headers( $emails ) {
908
  $headers = array();
909
 
910
  if ( ! empty( $emails['from'] ) ) {
includes/helpers/helpers.php CHANGED
@@ -173,3 +173,19 @@ function bnfw_is_tracking_allowed() {
173
 
174
  return $tracking_allowed;
175
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  return $tracking_allowed;
175
  }
176
+
177
+ /**
178
+ * Get post id from comment id.
179
+ *
180
+ * @param int $comment_id Comment ID for which we need Post ID.
181
+ * @return int Post ID. 0 if invalid comment id.
182
+ */
183
+ function bnfw_get_post_id_from_comment( $comment_id ) {
184
+ $comment = get_comment( $comment_id );
185
+
186
+ if ( null !== $comment ) {
187
+ return $comment->comment_post_ID;
188
+ }
189
+
190
+ return 0;
191
+ }
includes/overrides.php CHANGED
@@ -67,8 +67,14 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) {
67
  if ( $bnfw->notifier->notification_exists( 'new-user', false ) ) {
68
  $notifications = $bnfw->notifier->get_notifications( 'new-user' );
69
  $password_url = network_site_url( 'wp-login.php?action=rp&key=' . $key . '&login=' . rawurlencode( $user->user_login ), 'login' );
 
70
  foreach ( $notifications as $notification ) {
71
- $bnfw->engine->send_registration_email( $bnfw->notifier->read_settings( $notification->ID ), $user, $password_url );
 
 
 
 
 
72
  }
73
  } else {
74
  $message = sprintf( esc_html__( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";
67
  if ( $bnfw->notifier->notification_exists( 'new-user', false ) ) {
68
  $notifications = $bnfw->notifier->get_notifications( 'new-user' );
69
  $password_url = network_site_url( 'wp-login.php?action=rp&key=' . $key . '&login=' . rawurlencode( $user->user_login ), 'login' );
70
+
71
  foreach ( $notifications as $notification ) {
72
+ $setting = $bnfw->notifier->read_settings( $notification->ID );
73
+ $trigger_notification = apply_filters( 'bnfw_trigger_new-user_notification', true, $setting, $user );
74
+
75
+ if ( $trigger_notification ) {
76
+ $bnfw->engine->send_registration_email( $setting, $user, $password_url );
77
+ }
78
  }
79
  } else {
80
  $message = sprintf( esc_html__( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";