Better Notifications for WordPress - Version 1.4

Version Description

  • 8th April 2016 =
  • New: Shortcode [post_slug]. Output the post slug.
  • New: Shortcode [edit_post]. Outputs the link to edit the post / page / custom post.
  • New: Shortcode [post_parent_permalink]. Outputs a permalink to the post / page / custom post's parent item.
  • New: Shortcode [author_link]. Outputs a link to the post / page / custom post's author archive.
  • New: You can now add the collection of User Shortcodes to the 'Lost Password - For User' email.
  • New: Support for the 'O2' plugin, when used in conjunction with the 'P2' Theme via a filter. Please see the documentation for details.
  • Improved: Users were getting confused with the 'Welcome Email', thinking it operated like that in the 'SB Welcome Email Editor' plugin. The name of this notification has been changed from 'New User - Welcome Email' to 'New User - Post-registration Email' to help differentiate its functionality in BNFW.
  • Improved: The screen where you add your license(s) after purchasing any BNFW add-on(s) is now called 'Add-on Licenses', instead of going to 'Settings' and adding them there.
  • Improved: Setting a notification to send to 'the author only' now shows a label in the 'User Roles / Users' column in the 'All Notifications' screen.
  • Improved: 'New Comment / Awaiting Moderation', 'New Trackback', and 'New Pingback' notifications now show the 'Send this notification to the Author only' checkbox.
  • Improved: If a notification is present but disabled, the default WordPress notification (if there is one), will not be sent.
  • Fixed: New Post Published notifications weren't being sent if you had the Per-post Override add-on installed.
Download this release

Release Info

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

Code changes from version 1.3.9.5 to 1.4

README.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: voltronik
3
  Donate link: https://betternotificationsforwp.com/donate/
4
  Tags: notifications, email, mail, alerts, roles, user, users, admin, HTML, plain, wp_mail, shortcode, customize, post, page, updated, pending review, scheduled, category, tag, term, custom post type, comment, akismet, trackback, pingback, lost password, welcome, new user, bulk, notice, trigger, CC, BCC, from, author
5
  Requires at least: 3.5
6
- Tested up to: 4.4.2
7
- Stable tag: 1.3.9.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -37,9 +37,9 @@ Notifications that are currently available to use are:
37
 
38
  **Transactional**
39
 
40
- * Lost Password (For User)
41
- * New User Registration (For User)
42
- * New User - Welcome Email
43
  * User Role Changed
44
  * Comment Reply
45
 
@@ -190,6 +190,20 @@ An older version might work but this is untested. A lot of the newer features re
190
 
191
  == Changelog ==
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  = 1.3.9.5 - 26th February 2016 =
194
  * Fixed: New Post Published notifications were triggering multiple times due to `auto_draft_to_publish`.
195
 
3
  Donate link: https://betternotificationsforwp.com/donate/
4
  Tags: notifications, email, mail, alerts, roles, user, users, admin, HTML, plain, wp_mail, shortcode, customize, post, page, updated, pending review, scheduled, category, tag, term, custom post type, comment, akismet, trackback, pingback, lost password, welcome, new user, bulk, notice, trigger, CC, BCC, from, author
5
  Requires at least: 3.5
6
+ Tested up to: 4.5
7
+ Stable tag: 1.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
37
 
38
  **Transactional**
39
 
40
+ * Lost Password - For User
41
+ * New User Registration - For User
42
+ * New User - Post-registration Email
43
  * User Role Changed
44
  * Comment Reply
45
 
190
 
191
  == Changelog ==
192
 
193
+ = 1.4 - 8th April 2016 =
194
+ * New: Shortcode `[post_slug]`. Output the post slug.
195
+ * New: Shortcode `[edit_post]`. Outputs the link to edit the post / page / custom post.
196
+ * New: Shortcode `[post_parent_permalink]`. Outputs a permalink to the post / page / custom post's parent item.
197
+ * New: Shortcode `[author_link]`. Outputs a link to the post / page / custom post's author archive.
198
+ * New: You can now add the collection of User Shortcodes to the 'Lost Password - For User' email.
199
+ * New: Support for the 'O2' plugin, when used in conjunction with the 'P2' Theme via a filter. Please see the [documentation](https://betternotificationsforwp.com/documentation/) for details.
200
+ * Improved: Users were getting confused with the 'Welcome Email', thinking it operated like that in the 'SB Welcome Email Editor' plugin. The name of this notification has been changed from 'New User - Welcome Email' to 'New User - Post-registration Email' to help differentiate its functionality in BNFW.
201
+ * Improved: The screen where you add your license(s) after purchasing any BNFW add-on(s) is now called 'Add-on Licenses', instead of going to 'Settings' and adding them there.
202
+ * Improved: Setting a notification to send to 'the author only' now shows a label in the 'User Roles / Users' column in the 'All Notifications' screen.
203
+ * Improved: 'New Comment / Awaiting Moderation', 'New Trackback', and 'New Pingback' notifications now show the 'Send this notification to the Author only' checkbox.
204
+ * Improved: If a notification is present but disabled, the default WordPress notification (if there is one), will not be sent.
205
+ * Fixed: New Post Published notifications weren't being sent if you had the Per-post Override add-on installed.
206
+
207
  = 1.3.9.5 - 26th February 2016 =
208
  * Fixed: New Post Published notifications were triggering multiple times due to `auto_draft_to_publish`.
209
 
assets/js/bnfw.js CHANGED
@@ -50,10 +50,9 @@ jQuery(document).ready(function($) {
50
  $('#toggle-fields, #email, #cc, #bcc, #users, #disable-autop, #current-user, #post-author').hide();
51
  $('#user-password-msg, #email-formatting').show();
52
  } else if ( 'new-comment' === $('#notification').val() || 'new-trackback' === $('#notification').val() || 'new-pingback' === $('#notification').val() || 'admin-password' === $('#notification').val() || 'admin-user' === $('#notification').val() ) {
53
- $('#toggle-fields, #users, #email-formatting, #disable-autop, #current-user').show();
54
- $('#only-post-author').prop( 'checked', false );
55
- $('#post-author').hide();
56
  toggle_fields();
 
57
  $('#user-password-msg').hide();
58
  } else {
59
  $('#toggle-fields, #users, #email-formatting, #disable-autop, #current-user, #post-author').show();
@@ -74,15 +73,17 @@ jQuery(document).ready(function($) {
74
  } else if ( 'user-password' === $this.val() || 'user-role' === notification ) {
75
  $('#toggle-fields, #email, #cc, #bcc, #users, #disable-autop, #current-user, #post-author').hide();
76
  $('#user-password-msg, #email-formatting').show();
77
- } else if ( 'new-comment' === $('#notification').val() || 'new-trackback' === $('#notification').val() || 'new-pingback' === $('#notification').val() || 'admin-password' === $('#notification').val() || 'admin-user' === $('#notification').val() ) {
78
  $('#post-author').hide();
79
  $('#toggle-fields, #users, #email-formatting, #disable-autop, #current-user').show();
80
  $('#user-password-msg').hide();
81
  toggle_fields();
 
82
  } else {
83
  $('#toggle-fields, #users, #email-formatting, #disable-autop, #current-user, #post-author').show();
84
  $('#user-password-msg').hide();
85
  toggle_fields();
 
86
  }
87
  });
88
 
50
  $('#toggle-fields, #email, #cc, #bcc, #users, #disable-autop, #current-user, #post-author').hide();
51
  $('#user-password-msg, #email-formatting').show();
52
  } else if ( 'new-comment' === $('#notification').val() || 'new-trackback' === $('#notification').val() || 'new-pingback' === $('#notification').val() || 'admin-password' === $('#notification').val() || 'admin-user' === $('#notification').val() ) {
53
+ $('#toggle-fields, #users, #email-formatting, #disable-autop, #current-user, #post-author').show();
 
 
54
  toggle_fields();
55
+ toggle_users();
56
  $('#user-password-msg').hide();
57
  } else {
58
  $('#toggle-fields, #users, #email-formatting, #disable-autop, #current-user, #post-author').show();
73
  } else if ( 'user-password' === $this.val() || 'user-role' === notification ) {
74
  $('#toggle-fields, #email, #cc, #bcc, #users, #disable-autop, #current-user, #post-author').hide();
75
  $('#user-password-msg, #email-formatting').show();
76
+ } else if ( 'admin-password' === $('#notification').val() || 'admin-user' === $('#notification').val() ) {
77
  $('#post-author').hide();
78
  $('#toggle-fields, #users, #email-formatting, #disable-autop, #current-user').show();
79
  $('#user-password-msg').hide();
80
  toggle_fields();
81
+ toggle_users();
82
  } else {
83
  $('#toggle-fields, #users, #email-formatting, #disable-autop, #current-user, #post-author').show();
84
  $('#user-password-msg').hide();
85
  toggle_fields();
86
+ toggle_users();
87
  }
88
  });
89
 
bnfw.php CHANGED
@@ -3,10 +3,10 @@
3
  * Plugin Name: Better Notifications for WordPress
4
  * Plugin URI: http://wordpress.org/plugins/bnfw/
5
  * Description: Send customisable emails to your users for different WordPress notifications.
6
- * Version: 1.3.9.5
7
  * Author: Voltronik
8
  * Author URI: https://betternotificationsforwp.com/
9
- * Author Email: plugins@voltronik.co.uk
10
  * License: GPLv2 or later
11
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
  * Text Domain: bnfw
@@ -74,13 +74,14 @@ class BNFW {
74
  * @since 1.0
75
  */
76
  public function includes() {
 
77
  // Load license related classes
78
  if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
79
  require_once 'includes/libraries/EDD_SL_Plugin_Updater.php';
80
  }
81
  require_once 'includes/license/class-bnfw-license.php';
82
  require_once 'includes/license/class-bnfw-license-setting.php';
83
-
84
  // Load Engine
85
  require_once 'includes/engine/class-bnfw-engine.php';
86
  require_once 'includes/overrides.php';
@@ -89,7 +90,7 @@ class BNFW {
89
  require_once 'includes/admin/class-bnfw-notification.php';
90
  require_once 'includes/notification/post-notification.php';
91
 
92
- // helpers
93
  require_once 'includes/helpers/helpers.php';
94
  require_once 'includes/helpers/ajax-helpers.php';
95
 
@@ -105,13 +106,22 @@ class BNFW {
105
  * @since 1.0
106
  */
107
  public function hooks() {
 
 
108
  register_activation_hook( __FILE__ , array( $this, 'activate' ) );
109
 
110
- // some themes like P2, directly insert posts into DB.
111
  $insert_post_themes = apply_filters( 'bnfw_insert_post_themes', array( 'P2', 'Syncope' ) );
112
  $current_theme = wp_get_theme();
113
 
114
- if ( in_array( $current_theme, $insert_post_themes ) ) {
 
 
 
 
 
 
 
115
  add_action( 'wp_insert_post' , array( $this, 'insert_post' ), 10, 3 );
116
  }
117
 
@@ -131,8 +141,12 @@ class BNFW {
131
  add_action( 'user_register' , array( $this, 'welcome_email' ) );
132
  add_action( 'set_user_role' , array( $this, 'user_role_changed' ), 10, 3 );
133
 
 
 
 
 
 
134
  add_action( 'lostpassword_post' , array( $this, 'on_lost_password' ) );
135
- add_filter( 'retrieve_password_title' , array( $this, 'change_password_email_title' ) );
136
  add_filter( 'retrieve_password_message' , array( $this, 'change_password_email_message' ), 10, 4 );
137
 
138
  add_filter( 'plugin_action_links' , array( $this, 'plugin_action_links' ), 10, 4 );
@@ -338,13 +352,19 @@ class BNFW {
338
  *
339
  * @since 1.1
340
  */
341
- public function change_password_email_title( $title ) {
342
  $notifications = $this->notifier->get_notifications( 'user-password' );
343
  if ( count( $notifications ) > 0 ) {
344
  // Ideally there should be only one notification for this type.
345
  // If there are multiple notification then we will read data about only the last one
346
  $setting = $this->notifier->read_settings( end( $notifications )->ID );
347
- return $setting['subject'];
 
 
 
 
 
 
348
  }
349
 
350
  return $title;
@@ -393,7 +413,7 @@ class BNFW {
393
  }
394
 
395
  /**
396
- * Send notification for new uses.
397
  *
398
  * @since 1.0
399
  * @param int $user_id
@@ -403,7 +423,7 @@ class BNFW {
403
  }
404
 
405
  /**
406
- * New User - Welcome email
407
  *
408
  * @since 1.1
409
  * @param int $user_id New user id
3
  * Plugin Name: Better Notifications for WordPress
4
  * Plugin URI: http://wordpress.org/plugins/bnfw/
5
  * Description: Send customisable emails to your users for different WordPress notifications.
6
+ * Version: 1.4
7
  * Author: Voltronik
8
  * Author URI: https://betternotificationsforwp.com/
9
+ * Author Email: hello@betternotificationsforwp.com
10
  * License: GPLv2 or later
11
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
  * Text Domain: bnfw
74
  * @since 1.0
75
  */
76
  public function includes() {
77
+
78
  // Load license related classes
79
  if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
80
  require_once 'includes/libraries/EDD_SL_Plugin_Updater.php';
81
  }
82
  require_once 'includes/license/class-bnfw-license.php';
83
  require_once 'includes/license/class-bnfw-license-setting.php';
84
+
85
  // Load Engine
86
  require_once 'includes/engine/class-bnfw-engine.php';
87
  require_once 'includes/overrides.php';
90
  require_once 'includes/admin/class-bnfw-notification.php';
91
  require_once 'includes/notification/post-notification.php';
92
 
93
+ // Helpers
94
  require_once 'includes/helpers/helpers.php';
95
  require_once 'includes/helpers/ajax-helpers.php';
96
 
106
  * @since 1.0
107
  */
108
  public function hooks() {
109
+ global $wp_version;
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, $insert_post_themes ) || $trigger_insert_post ) {
125
  add_action( 'wp_insert_post' , array( $this, 'insert_post' ), 10, 3 );
126
  }
127
 
141
  add_action( 'user_register' , array( $this, 'welcome_email' ) );
142
  add_action( 'set_user_role' , array( $this, 'user_role_changed' ), 10, 3 );
143
 
144
+ if ( version_compare( $wp_version, '4.4', '>=' ) ) {
145
+ add_filter( 'retrieve_password_title', array( $this, 'change_password_email_title' ), 10, 3 );
146
+ } else {
147
+ add_filter( 'retrieve_password_title', array( $this, 'change_password_email_title' ) );
148
+ }
149
  add_action( 'lostpassword_post' , array( $this, 'on_lost_password' ) );
 
150
  add_filter( 'retrieve_password_message' , array( $this, 'change_password_email_message' ), 10, 4 );
151
 
152
  add_filter( 'plugin_action_links' , array( $this, 'plugin_action_links' ), 10, 4 );
352
  *
353
  * @since 1.1
354
  */
355
+ public function change_password_email_title( $title, $user_login = '', $user_data = '' ) {
356
  $notifications = $this->notifier->get_notifications( 'user-password' );
357
  if ( count( $notifications ) > 0 ) {
358
  // Ideally there should be only one notification for this type.
359
  // If there are multiple notification then we will read data about only the last one
360
  $setting = $this->notifier->read_settings( end( $notifications )->ID );
361
+
362
+ if ( '' === $user_data ) {
363
+ return $this->engine->user_shortcodes( $setting['subject'], $user_data->ID );
364
+
365
+ } else {
366
+ return $setting['subject'];
367
+ }
368
  }
369
 
370
  return $title;
413
  }
414
 
415
  /**
416
+ * Send notification for new users.
417
  *
418
  * @since 1.0
419
  * @param int $user_id
423
  }
424
 
425
  /**
426
+ * New User - Post-registration Email
427
  *
428
  * @since 1.1
429
  * @param int $user_id New user id
includes/admin/bnfw-settings.php CHANGED
@@ -20,7 +20,7 @@ function bnfw_admin_menu() {
20
  }
21
  // Add the Admin pages to the WordPress menu
22
  add_action( 'admin_menu', 'bnfw_admin_menu' );
23
- add_action( 'admin_menu', 'bnfw_menu_item_links' );
24
  add_action( 'admin_head', 'bnfw_menu_item_link_targets' );
25
 
26
  /* ------------------------------------------------------------------------ *
@@ -58,14 +58,14 @@ function bnfw_menu_item_links() {
58
  global $submenu;
59
 
60
  // Documentation Link
61
- $submenu['edit.php?post_type=bnfw_notification'][400] = array(
62
- '<div id="bnfw-menu-item-documentation">Documentation</div>',
63
  'manage_options',
64
  'https://betternotificationsforwp.com/documentation/?utm_source=WP%20Admin%20Submenu%20Item%20-%20"Documentation"&amp;utm_medium=referral',
65
  );
66
 
67
  // Add-ons Link
68
- $submenu['edit.php?post_type=bnfw_notification'][500] = array(
69
  '<div id="bnfw-menu-item-addons" style="color: #ff6f59;">Add-ons</div>',
70
  'manage_options',
71
  'https://betternotificationsforwp.com/store/?utm_source=WP%20Admin%20Submenu%20Item%20-%20"Add-on"&amp;utm_medium=referral',
@@ -74,20 +74,21 @@ function bnfw_menu_item_links() {
74
 
75
  function bnfw_menu_item_link_targets() {
76
  ?>
77
-
78
- <!-- Documentation Link -->
79
  <script type="text/javascript">
80
  jQuery(document).ready(function($) {
 
81
  $('#bnfw-menu-item-documentation').parent().attr('target', '_blank');
82
- });
83
- </script>
 
 
 
84
 
85
- <!-- Add-ons Link -->
86
- <script type="text/javascript">
87
- jQuery(document).ready(function($) {
88
  $('#bnfw-menu-item-addons').parent().attr('target', '_blank');
89
  $('#bnfw-menu-item-addons').hover(function() {
90
- $(this).css('color', '#ffaa9d');
91
  }, function() {
92
  $(this).css('color', '#ff6f59');
93
  });
20
  }
21
  // Add the Admin pages to the WordPress menu
22
  add_action( 'admin_menu', 'bnfw_admin_menu' );
23
+ add_action( 'admin_menu', 'bnfw_menu_item_links', 12 );
24
  add_action( 'admin_head', 'bnfw_menu_item_link_targets' );
25
 
26
  /* ------------------------------------------------------------------------ *
58
  global $submenu;
59
 
60
  // Documentation Link
61
+ $submenu['edit.php?post_type=bnfw_notification'][500] = array(
62
+ '<div id="bnfw-menu-item-documentation" style="color: #73daeb;">Documentation</div>',
63
  'manage_options',
64
  'https://betternotificationsforwp.com/documentation/?utm_source=WP%20Admin%20Submenu%20Item%20-%20"Documentation"&amp;utm_medium=referral',
65
  );
66
 
67
  // Add-ons Link
68
+ $submenu['edit.php?post_type=bnfw_notification'][600] = array(
69
  '<div id="bnfw-menu-item-addons" style="color: #ff6f59;">Add-ons</div>',
70
  'manage_options',
71
  'https://betternotificationsforwp.com/store/?utm_source=WP%20Admin%20Submenu%20Item%20-%20"Add-on"&amp;utm_medium=referral',
74
 
75
  function bnfw_menu_item_link_targets() {
76
  ?>
77
+
 
78
  <script type="text/javascript">
79
  jQuery(document).ready(function($) {
80
+ // Documentation Link
81
  $('#bnfw-menu-item-documentation').parent().attr('target', '_blank');
82
+ $('#bnfw-menu-item-documentation').hover(function() {
83
+ $(this).css('color', '#a0e6f1');
84
+ }, function() {
85
+ $(this).css('color', '#73daeb');
86
+ });
87
 
88
+ // Add-ons Link
 
 
89
  $('#bnfw-menu-item-addons').parent().attr('target', '_blank');
90
  $('#bnfw-menu-item-addons').hover(function() {
91
+ $(this).css('color', '#ff9b8c');
92
  }, function() {
93
  $(this).css('color', '#ff6f59');
94
  });
includes/admin/class-bnfw-notification.php CHANGED
@@ -167,7 +167,7 @@ class BNFW_Notification {
167
  <optgroup label="Transactional">
168
  <option value="user-password" <?php selected( 'user-password', $setting['notification'] );?>><?php _e( 'Lost Password - For User', 'bnfw' );?></option>
169
  <option value="new-user" <?php selected( 'new-user', $setting['notification'] );?>><?php _e( 'New User Registration - For User', 'bnfw' );?></option>
170
- <option value="welcome-email" <?php selected( 'welcome-email', $setting['notification'] );?>><?php _e( 'New User - Welcome Email', 'bnfw' );?></option>
171
  <option value="user-role" <?php selected( 'user-role', $setting['notification'] );?>><?php _e( 'User Role Changed', 'bnfw' );?></option>
172
  <option value="reply-comment" <?php selected( 'reply-comment', $setting['notification'] );?>><?php _e( 'Comment Reply', 'bnfw' );?></option>
173
  </optgroup>
@@ -389,6 +389,9 @@ class BNFW_Notification {
389
  */
390
  public function is_assets_needed() {
391
  if ( self::POST_TYPE === get_post_type() ) {
 
 
 
392
  $this->enqueue_assets();
393
  do_action( 'bnfw_after_enqueue_scripts' );
394
  }
@@ -400,8 +403,6 @@ class BNFW_Notification {
400
  * @since 1.4
401
  */
402
  public function enqueue_assets() {
403
- wp_dequeue_script( 'autosave' );
404
-
405
  wp_deregister_script( 'select2' );
406
  wp_dequeue_script( 'select2' );
407
  wp_deregister_style( 'select2' );
@@ -670,9 +671,10 @@ class BNFW_Notification {
670
  *
671
  * @since 1.0
672
  * @param array|string $types
 
673
  * @return array WP_Post objects
674
  */
675
- public function get_notifications( $types ) {
676
  if ( ! is_array( $types ) ) {
677
  $types = array( $types );
678
  }
@@ -685,14 +687,17 @@ class BNFW_Notification {
685
  'value' => $types,
686
  'compare' => 'IN',
687
  ),
688
- array(
689
- 'key' => self::META_KEY_PREFIX . 'disabled',
690
- 'value' => 'true',
691
- 'compare' => '!=',
692
- ),
693
  ),
694
  );
695
 
 
 
 
 
 
 
 
 
696
  $wp_query = new WP_Query();
697
  $posts = $wp_query->query( $args );
698
  return $posts;
@@ -704,10 +709,11 @@ class BNFW_Notification {
704
  * @since 1.1
705
  *
706
  * @param string $type Notification Type.
 
707
  * @return bool True if present, False otherwise
708
  */
709
- public function notification_exists( $type ) {
710
- $notifications = $this->get_notifications( $type );
711
 
712
  if ( count( $notifications ) > 0 ) {
713
  return true;
@@ -736,7 +742,6 @@ class BNFW_Notification {
736
  /**
737
  * Custom column appears in each row.
738
  *
739
- *
740
  * @since 1.0
741
  * @action manage_{post_type}_posts_custom_column
742
  * @param string $column Column name
@@ -757,8 +762,12 @@ class BNFW_Notification {
757
  echo ! empty( $setting['subject'] ) ? $setting['subject'] : '';
758
  break;
759
  case 'users':
760
- $users = $this->get_names_from_users( $setting['users'] );
761
- echo implode( ', ', $users );
 
 
 
 
762
  break;
763
  }
764
 
@@ -830,13 +839,13 @@ class BNFW_Notification {
830
  $name = __( 'Lost Password - For Admin', 'bnfw' );
831
  break;
832
  case 'new-user':
833
- $name = __( 'User Registration - For User', 'bnfw' );
834
  break;
835
  case 'welcome-email':
836
- $name = __( 'New User - Welcome Email', 'bnfw' );
837
  break;
838
  case 'admin-user':
839
- $name = __( 'User Registration - For Admin', 'bnfw' );
840
  break;
841
  case 'user-role':
842
  $name = __( 'User Role Changed', 'bnfw' );
167
  <optgroup label="Transactional">
168
  <option value="user-password" <?php selected( 'user-password', $setting['notification'] );?>><?php _e( 'Lost Password - For User', 'bnfw' );?></option>
169
  <option value="new-user" <?php selected( 'new-user', $setting['notification'] );?>><?php _e( 'New User Registration - For User', 'bnfw' );?></option>
170
+ <option value="welcome-email" <?php selected( 'welcome-email', $setting['notification'] );?>><?php _e( 'New User - Post-registration Email', 'bnfw' );?></option>
171
  <option value="user-role" <?php selected( 'user-role', $setting['notification'] );?>><?php _e( 'User Role Changed', 'bnfw' );?></option>
172
  <option value="reply-comment" <?php selected( 'reply-comment', $setting['notification'] );?>><?php _e( 'Comment Reply', 'bnfw' );?></option>
173
  </optgroup>
389
  */
390
  public function is_assets_needed() {
391
  if ( self::POST_TYPE === get_post_type() ) {
392
+ // The enqueue assets function may be included from addons.
393
+ // We want to disable autosave only for notifications
394
+ wp_dequeue_script( 'autosave' );
395
  $this->enqueue_assets();
396
  do_action( 'bnfw_after_enqueue_scripts' );
397
  }
403
  * @since 1.4
404
  */
405
  public function enqueue_assets() {
 
 
406
  wp_deregister_script( 'select2' );
407
  wp_dequeue_script( 'select2' );
408
  wp_deregister_style( 'select2' );
671
  *
672
  * @since 1.0
673
  * @param array|string $types
674
+ * @param bool $exclude_disabled (optional) Whether to exclude disabled notifications or not. True by default.
675
  * @return array WP_Post objects
676
  */
677
+ public function get_notifications( $types, $exclude_disabled = true ) {
678
  if ( ! is_array( $types ) ) {
679
  $types = array( $types );
680
  }
687
  'value' => $types,
688
  'compare' => 'IN',
689
  ),
 
 
 
 
 
690
  ),
691
  );
692
 
693
+ if ( $exclude_disabled ) {
694
+ $args['meta_query'][] = array(
695
+ 'key' => self::META_KEY_PREFIX . 'disabled',
696
+ 'value' => 'true',
697
+ 'compare' => '!=',
698
+ );
699
+ }
700
+
701
  $wp_query = new WP_Query();
702
  $posts = $wp_query->query( $args );
703
  return $posts;
709
  * @since 1.1
710
  *
711
  * @param string $type Notification Type.
712
+ * @param bool $exclude_disabled (optional) Whether to exclude disabled notifications or not. True by default.
713
  * @return bool True if present, False otherwise
714
  */
715
+ public function notification_exists( $type, $exclude_disabled = true ) {
716
+ $notifications = $this->get_notifications( $type, $exclude_disabled );
717
 
718
  if ( count( $notifications ) > 0 ) {
719
  return true;
742
  /**
743
  * Custom column appears in each row.
744
  *
 
745
  * @since 1.0
746
  * @action manage_{post_type}_posts_custom_column
747
  * @param string $column Column name
762
  echo ! empty( $setting['subject'] ) ? $setting['subject'] : '';
763
  break;
764
  case 'users':
765
+ if ( 'true' === $setting['only-post-author'] ) {
766
+ echo __( 'Author only', 'bnfw' );
767
+ } else {
768
+ $users = $this->get_names_from_users( $setting['users'] );
769
+ echo implode( ', ', $users );
770
+ }
771
  break;
772
  }
773
 
839
  $name = __( 'Lost Password - For Admin', 'bnfw' );
840
  break;
841
  case 'new-user':
842
+ $name = __( 'New User Registration - For User', 'bnfw' );
843
  break;
844
  case 'welcome-email':
845
+ $name = __( 'New User - Post-registration Email', 'bnfw' );
846
  break;
847
  case 'admin-user':
848
+ $name = __( 'New User Registration - For Admin', 'bnfw' );
849
  break;
850
  case 'user-role':
851
  $name = __( 'User Role Changed', 'bnfw' );
includes/engine/class-bnfw-engine.php CHANGED
@@ -62,7 +62,7 @@ class BNFW_Engine {
62
  $headers[] = 'Content-type: text/plain';
63
  }
64
 
65
- if ( is_array( $emails['to'] ) ) {
66
  foreach ( $emails['to'] as $email ) {
67
  wp_mail( $email, stripslashes( $subject ), $message, $headers );
68
  }
@@ -192,6 +192,9 @@ class BNFW_Engine {
192
  $message = $this->comment_shortcodes( $message, $id );
193
  $comment = get_comment( $id );
194
  $message = $this->post_shortcodes( $message, $comment->comment_post_ID );
 
 
 
195
  break;
196
 
197
  case 'admin-password':
@@ -267,18 +270,21 @@ class BNFW_Engine {
267
  $message = str_replace( '[ping_status]', $post->ping_status, $message );
268
  $message = str_replace( '[post_password]', $post->post_password, $message );
269
  $message = str_replace( '[post_name]', $post->post_name, $message );
 
270
  $message = str_replace( '[to_ping]', $post->to_ping, $message );
271
  $message = str_replace( '[pinged]', $post->pinged, $message );
272
  $message = str_replace( '[post_modified]', $post->post_modified, $message );
273
  $message = str_replace( '[post_modified_gmt]', $post->post_modified_gmt, $message );
274
  $message = str_replace( '[post_content_filtered]', $post->post_content_filtered, $message );
275
  $message = str_replace( '[post_parent]', $post->post_parent, $message );
 
276
  $message = str_replace( '[guid]', $post->guid, $message );
277
  $message = str_replace( '[menu_order]', $post->menu_order, $message );
278
  $message = str_replace( '[post_type]', $post->post_type, $message );
279
  $message = str_replace( '[post_mime_type]', $post->post_mime_type, $message );
280
  $message = str_replace( '[comment_count]', $post->comment_count, $message );
281
  $message = str_replace( '[permalink]', get_permalink( $post->ID ), $message );
 
282
 
283
  if ( 'future' == $post->post_status ) {
284
  $message = str_replace( '[post_scheduled_date]', $post->post_date, $message );
@@ -297,6 +303,8 @@ class BNFW_Engine {
297
  $user_info = get_userdata( $post->post_author );
298
  $message = str_replace( '[post_author]', $user_info->display_name, $message );
299
 
 
 
300
  if ( $last_id = get_post_meta( $post->ID, '_edit_last', true ) ) {
301
  if ( $post->post_author != $last_id ) {
302
  $last_user_info = get_userdata( $last_id );
@@ -416,7 +424,14 @@ class BNFW_Engine {
416
  }
417
 
418
  if ( 'true' === $setting['only-post-author'] ) {
419
- $author = get_user_by( 'id', get_post_field( 'post_author', $id ) );
 
 
 
 
 
 
 
420
  if ( false !== $author ) {
421
  $emails['to'] = array( $author->user_email );
422
  }
62
  $headers[] = 'Content-type: text/plain';
63
  }
64
 
65
+ if ( isset( $emails['to'] ) && is_array( $emails['to'] ) ) {
66
  foreach ( $emails['to'] as $email ) {
67
  wp_mail( $email, stripslashes( $subject ), $message, $headers );
68
  }
192
  $message = $this->comment_shortcodes( $message, $id );
193
  $comment = get_comment( $id );
194
  $message = $this->post_shortcodes( $message, $comment->comment_post_ID );
195
+ if ( 0 != $comment->user_id ) {
196
+ $message = $this->user_shortcodes( $message, $comment->user_id );
197
+ }
198
  break;
199
 
200
  case 'admin-password':
270
  $message = str_replace( '[ping_status]', $post->ping_status, $message );
271
  $message = str_replace( '[post_password]', $post->post_password, $message );
272
  $message = str_replace( '[post_name]', $post->post_name, $message );
273
+ $message = str_replace( '[post_slug]', $post->post_name, $message );
274
  $message = str_replace( '[to_ping]', $post->to_ping, $message );
275
  $message = str_replace( '[pinged]', $post->pinged, $message );
276
  $message = str_replace( '[post_modified]', $post->post_modified, $message );
277
  $message = str_replace( '[post_modified_gmt]', $post->post_modified_gmt, $message );
278
  $message = str_replace( '[post_content_filtered]', $post->post_content_filtered, $message );
279
  $message = str_replace( '[post_parent]', $post->post_parent, $message );
280
+ $message = str_replace( '[post_parent_permalink]', get_permalink( $post->post_parent ), $message );
281
  $message = str_replace( '[guid]', $post->guid, $message );
282
  $message = str_replace( '[menu_order]', $post->menu_order, $message );
283
  $message = str_replace( '[post_type]', $post->post_type, $message );
284
  $message = str_replace( '[post_mime_type]', $post->post_mime_type, $message );
285
  $message = str_replace( '[comment_count]', $post->comment_count, $message );
286
  $message = str_replace( '[permalink]', get_permalink( $post->ID ), $message );
287
+ $message = str_replace( '[edit_post]', get_edit_post_link( $post->ID ), $message );
288
 
289
  if ( 'future' == $post->post_status ) {
290
  $message = str_replace( '[post_scheduled_date]', $post->post_date, $message );
303
  $user_info = get_userdata( $post->post_author );
304
  $message = str_replace( '[post_author]', $user_info->display_name, $message );
305
 
306
+ $message = str_replace( '[author_link]', get_author_posts_url( $post->post_author ), $message );
307
+
308
  if ( $last_id = get_post_meta( $post->ID, '_edit_last', true ) ) {
309
  if ( $post->post_author != $last_id ) {
310
  $last_user_info = get_userdata( $last_id );
424
  }
425
 
426
  if ( 'true' === $setting['only-post-author'] ) {
427
+
428
+ $post_id = $id;
429
+ if ( bnfw_is_comment_notification( $setting['notification'] ) ) {
430
+ $comment = get_comment( $id );
431
+ $post_id = $comment->comment_post_ID;
432
+ }
433
+
434
+ $author = get_user_by( 'id', get_post_field( 'post_author', $post_id ) );
435
  if ( false !== $author ) {
436
  $emails['to'] = array( $author->user_email );
437
  }
includes/helpers/helpers.php CHANGED
@@ -65,3 +65,31 @@ function bnfw_render_users_dropdown( $selected_users ) {
65
  echo '<option value="', $user->ID, '" ', $selected, '>', $user->user_login, '</option>';
66
  }
67
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  echo '<option value="', $user->ID, '" ', $selected, '>', $user->user_login, '</option>';
66
  }
67
  }
68
+
69
+ /**
70
+ * Find whether the notification name is a comment notification.
71
+ *
72
+ * @param string $notification_name Notification Name.
73
+ * @return bool True if it is a comment notification, False otherwise.
74
+ */
75
+ function bnfw_is_comment_notification( $notification_name ) {
76
+ $is_comment_notification = false;
77
+
78
+ switch ( $notification_name ) {
79
+ case 'new-comment':
80
+ case 'new-trackback':
81
+ case 'new-pingback':
82
+ case 'reply-comment':
83
+ $is_comment_notification = true;
84
+ break;
85
+
86
+ default:
87
+ $type = explode( '-', $notification_name, 2 );
88
+ if ( 'comment' == $type[0] ) {
89
+ $is_comment_notification = true;
90
+ }
91
+ break;
92
+ }
93
+
94
+ return $is_comment_notification;
95
+ }
includes/license/class-bnfw-license-setting.php CHANGED
@@ -7,17 +7,64 @@
7
 
8
  defined( 'ABSPATH' ) || exit; // Exit if accessed directly
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  function bnfw_license_settings() {
11
  $settings = apply_filters( 'bnfw_settings_licenses', array() );
12
 
13
  if ( ! empty( $settings ) ) {
14
 
15
- // Set-up - General Options Section
16
  add_settings_section(
17
- 'bnfw_license_section', // Section ID
18
- __( 'Addon Licenses', 'bnfw' ), // Title above settings section
19
- '__return_false', // Name of function that renders a description of the settings section
20
- 'bnfw-settings' // Page to show on
21
  );
22
 
23
  foreach ( $settings as $option ) {
@@ -26,7 +73,7 @@ function bnfw_license_settings() {
26
  'bnfw_licenses[' . $option['id'] . ']',
27
  $name,
28
  'bnfw_license_key_callback',
29
- 'bnfw-settings',
30
  'bnfw_license_section',
31
  array(
32
  'id' => isset( $option['id'] ) ? $option['id'] : null,
@@ -48,7 +95,7 @@ function bnfw_license_settings() {
48
  }
49
 
50
  register_setting(
51
- 'bnfw-settings',
52
  'bnfw_licenses'
53
  );
54
  }
7
 
8
  defined( 'ABSPATH' ) || exit; // Exit if accessed directly
9
 
10
+ /**
11
+ * Add License page.
12
+ *
13
+ * @since 1.4
14
+ */
15
+ function bnfw_add_license_page() {
16
+ add_submenu_page(
17
+ 'edit.php?post_type=bnfw_notification',
18
+ __( 'Add-on Licenses', 'bnfw' ),
19
+ __( 'Add-on Licenses', 'bnfw' ),
20
+ 'manage_options',
21
+ 'bnfw-license',
22
+ 'bnfw_render_license_page'
23
+ );
24
+ }
25
+ add_action( 'admin_menu', 'bnfw_add_license_page', 11 );
26
+
27
+ /**
28
+ * Render license page.
29
+ *
30
+ * @since 1.4
31
+ */
32
+ function bnfw_render_license_page() {
33
+ $settings = apply_filters( 'bnfw_settings_licenses', array() );
34
+ ob_start(); ?>
35
+
36
+ <div class="wrap">
37
+ <?php screen_icon(); ?>
38
+ <h2><?php _e( 'BNFW Add-on Licenses', 'bnfw' ); ?></h2>
39
+
40
+ <form method="post" action="options.php" class="bnfw-form">
41
+ <?php
42
+ settings_errors();
43
+ settings_fields( 'bnfw-license-settings' );
44
+ do_settings_sections( 'bnfw-license' );
45
+
46
+ if ( ! empty( $settings ) ) {
47
+ submit_button( __( 'Save License', 'bnfw' ) );
48
+ } else {
49
+ _e( '<br>You have no BNFW Add-ons installed yet. You can buy add-ons from the <a href="https://betternotificationsforwp.com/store/?utm_source=WP%20Admin%20Submenu%20Item%20-%20"Add-on%20Licenses"&amp;utm_medium=referral" target="_blank">Store</a>.', 'bnfw' );
50
+ }
51
+ ?>
52
+ </form>
53
+ </div>
54
+
55
+ <?php echo ob_get_clean();
56
+ }
57
+
58
  function bnfw_license_settings() {
59
  $settings = apply_filters( 'bnfw_settings_licenses', array() );
60
 
61
  if ( ! empty( $settings ) ) {
62
 
 
63
  add_settings_section(
64
+ 'bnfw_license_section', // Section ID
65
+ __( '', 'bnfw' ), // Title above settings section
66
+ '__return_false', // Name of function that renders a description of the settings section
67
+ 'bnfw-license' // Page to show on
68
  );
69
 
70
  foreach ( $settings as $option ) {
73
  'bnfw_licenses[' . $option['id'] . ']',
74
  $name,
75
  'bnfw_license_key_callback',
76
+ 'bnfw-license',
77
  'bnfw_license_section',
78
  array(
79
  'id' => isset( $option['id'] ) ? $option['id'] : null,
95
  }
96
 
97
  register_setting(
98
+ 'bnfw-license-settings',
99
  'bnfw_licenses'
100
  );
101
  }
includes/overrides.php CHANGED
@@ -38,7 +38,7 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) {
38
  // we want to reverse this for the plain text arena of emails.
39
  $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
40
 
41
- if ( ! $bnfw->notifier->notification_exists( 'admin-user' ) ) {
42
  $message = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
43
  $message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
44
  $message .= sprintf(__('E-mail: %s'), $user->user_email) . "\r\n";
@@ -64,7 +64,7 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) {
64
  $hashed = time() . ':' . $wp_hasher->HashPassword( $key );
65
  $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) );
66
 
67
- if ( $bnfw->notifier->notification_exists( 'new-user' ) ) {
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 ) {
@@ -88,7 +88,7 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) {
88
  // we want to reverse this for the plain text arena of emails.
89
  $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
90
 
91
- if ( ! $bnfw->notifier->notification_exists( 'admin-user' ) ) {
92
  $message = sprintf( __( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n";
93
  $message .= sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";
94
  $message .= sprintf( __( 'E-mail: %s' ), $user->user_email ) . "\r\n";
@@ -100,7 +100,7 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) {
100
  return;
101
  }
102
 
103
- if ( $bnfw->notifier->notification_exists( 'new-user' ) ) {
104
  $notifications = $bnfw->notifier->get_notifications( 'new-user' );
105
  foreach ( $notifications as $notification ) {
106
  $bnfw->engine->send_registration_email( $bnfw->notifier->read_settings( $notification->ID ), $user, $plaintext_pass );
38
  // we want to reverse this for the plain text arena of emails.
39
  $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
40
 
41
+ if ( ! $bnfw->notifier->notification_exists( 'admin-user', false ) ) {
42
  $message = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
43
  $message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
44
  $message .= sprintf(__('E-mail: %s'), $user->user_email) . "\r\n";
64
  $hashed = time() . ':' . $wp_hasher->HashPassword( $key );
65
  $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) );
66
 
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 ) {
88
  // we want to reverse this for the plain text arena of emails.
89
  $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
90
 
91
+ if ( ! $bnfw->notifier->notification_exists( 'admin-user', false ) ) {
92
  $message = sprintf( __( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n";
93
  $message .= sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";
94
  $message .= sprintf( __( 'E-mail: %s' ), $user->user_email ) . "\r\n";
100
  return;
101
  }
102
 
103
+ if ( $bnfw->notifier->notification_exists( 'new-user', false ) ) {
104
  $notifications = $bnfw->notifier->get_notifications( 'new-user' );
105
  foreach ( $notifications as $notification ) {
106
  $bnfw->engine->send_registration_email( $bnfw->notifier->read_settings( $notification->ID ), $user, $plaintext_pass );