Better Notifications for WordPress - Version 1.8.7

Version Description

  • 27th January 2022 =
  • IMPORTANT! It is recommended that you update this plugin to the latest version.
  • Fixed: A security issue affecting select2 fields when searching for a user or user role.
Download this release

Release Info

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

Code changes from version 1.8.6 to 1.8.7

README.txt CHANGED
@@ -3,11 +3,12 @@ Contributors: voltronik
3
  Donate link: https://betternotificationsforwp.com/donate/
4
  Tags: notification, email, alert, message, notify, send, HTML, customize, bulk, trigger, CC, BCC
5
  Requires at least: 4.8
6
- Tested up to: 5.7.2
7
- Requires PHP: 5.6
8
- Stable tag: 1.8.6
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
 
11
 
12
  Supercharge your WordPress email notifications using a WYSIWYG editor and shortcodes. Default and new notifications available. Increase power with Add-ons.
13
 
@@ -21,7 +22,7 @@ Here's a quick walkthrough of the plugin in action:
21
  = An Example: =
22
  You want all the users in the Editor role to be notified via email when a new post is published and you'd like to customise it to include your logo along with the author's name and date / time it was published - with this plugin, that's easy.
23
 
24
- > A handy list of shortcodes you can use is available [here](https://betternotificationsforwp.com/shortcodes/ "Shortcodes for use in Better Notifications for WP").
25
 
26
  = Premium Add-ons =
27
  Power-up your notifications using add-ons:
@@ -163,8 +164,8 @@ If you want to let users create their own email notifications, check out my othe
163
  1. Upload the 'bnfw' plugin folder to the '/wp-content/plugins/' directory or install it via your WordPress Admin.
164
  2. Activate the plugin through the 'Plugins' menu in WordPress.
165
  3. Use the settings in the new 'Notifications' Menu item in the sidebar to configure the plugin.
166
- 4. (Optional) Install a plugin to use SMTP instead of `wp_mail()`. I recommend [Post SMTP Mailer/Email Log](https://wordpress.org/plugins/post-smtp/).
167
- 5. Test by creating a notification with some [shortcodes](https://betternotificationsforwp.com/shortcodes/ "Shortcodes for use in Better Notifications for WP").
168
 
169
 
170
 
@@ -182,7 +183,7 @@ Shortcodes are text in square brackets that output content of some kind. For exa
182
 
183
  Shortcodes can be used in the 'Subject' and 'Message Body' of your notifications, except for a select few (due to a restriction in WordPress).
184
 
185
- > A handy list of shortcodes you can use is available [here](https://betternotificationsforwp.com/shortcodes/ "Shortcodes for use in Better Notifications for WP").
186
 
187
  = What are some scenarios this plugin could be used for? =
188
 
@@ -241,6 +242,10 @@ Yes, of course! The plugin is completely translation-friendly and if you send me
241
 
242
  == Changelog ==
243
 
 
 
 
 
244
  = 1.8.6 - 26th April 2021 =
245
  * Fixed: Post Author and Update Author shortcodes now work as expected again following an issue introduced in WordPress 5.7.
246
  * Fixed: User Lost Password notifications now work correctly if users only log in with their email address.
3
  Donate link: https://betternotificationsforwp.com/donate/
4
  Tags: notification, email, alert, message, notify, send, HTML, customize, bulk, trigger, CC, BCC
5
  Requires at least: 4.8
6
+ Tested up to: 5.9
7
+ Requires PHP: 7.0
8
+ Stable tag: 1.8.7
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
+ Update URI: https://wordpress.org/plugins/bnfw/
12
 
13
  Supercharge your WordPress email notifications using a WYSIWYG editor and shortcodes. Default and new notifications available. Increase power with Add-ons.
14
 
22
  = An Example: =
23
  You want all the users in the Editor role to be notified via email when a new post is published and you'd like to customise it to include your logo along with the author's name and date / time it was published - with this plugin, that's easy.
24
 
25
+ > A handy list of shortcodes you can use is available [here](https://betternotificationsforwp.com/documentation/notifications/shortcodes/ "Shortcodes for use in Better Notifications for WP").
26
 
27
  = Premium Add-ons =
28
  Power-up your notifications using add-ons:
164
  1. Upload the 'bnfw' plugin folder to the '/wp-content/plugins/' directory or install it via your WordPress Admin.
165
  2. Activate the plugin through the 'Plugins' menu in WordPress.
166
  3. Use the settings in the new 'Notifications' Menu item in the sidebar to configure the plugin.
167
+ 4. (Optional) Read our article on [how to improve email delivery in WordPress](https://betternotificationsforwp.com/guides/how-to-improve-email-delivery-wordpress/).
168
+ 5. Test by creating a notification with some [shortcodes](https://betternotificationsforwp.com/documentation/notifications/shortcodes/ "Shortcodes for use in Better Notifications for WP").
169
 
170
 
171
 
183
 
184
  Shortcodes can be used in the 'Subject' and 'Message Body' of your notifications, except for a select few (due to a restriction in WordPress).
185
 
186
+ > A handy list of shortcodes you can use is available [here](https://betternotificationsforwp.com/documentation/notifications/shortcodes/ "Shortcodes for use in Better Notifications for WP").
187
 
188
  = What are some scenarios this plugin could be used for? =
189
 
242
 
243
  == Changelog ==
244
 
245
+ = 1.8.7 - 27th January 2022 =
246
+ * IMPORTANT! It is recommended that you update this plugin to the latest version.
247
+ * Fixed: A security issue affecting select2 fields when searching for a user or user role.
248
+
249
  = 1.8.6 - 26th April 2021 =
250
  * Fixed: Post Author and Update Author shortcodes now work as expected again following an issue introduced in WordPress 5.7.
251
  * Fixed: User Lost Password notifications now work correctly if users only log in with their email address.
assets/css/bnfw.css CHANGED
@@ -1,180 +1,180 @@
1
- /* Generic classes */
2
- .hidden {
3
- display: none;
4
- }
5
-
6
- .show {
7
- display: block;
8
- }
9
-
10
- #user-password-msg {
11
- display: none;
12
- }
13
-
14
- #user-password-msg div {
15
- background: #FFFFE1;
16
- padding: 15px;
17
- }
18
-
19
- #users-count-msg div {
20
- background: #F79C2D;
21
- padding: 15px;
22
- }
23
-
24
- #users-count-msg div p {
25
- margin-top: 0;
26
- }
27
-
28
- .manage-column.column-disabled {
29
- width: 8% !important;
30
- }
31
-
32
- /* Fix 'jump' when hovering over 'x' in select2 box */
33
- /*ul.select2-choices li.select2-search-choice a {
34
- -webkit-transition-property: none;
35
- transition-property: none;
36
- -webkit-transition-duration: 0s;
37
- transition-duration: 0s;
38
- -webkit-transition-timing-function: initial;
39
- transition-timing-function: initial;
40
- }*/
41
-
42
- /* Select2 4.0 */
43
- .select2-container--default .select2-selection--multiple {
44
- line-height: 0;
45
- }
46
-
47
- ul.select2-selection__rendered {
48
- line-height: 1.3;
49
- }
50
-
51
-
52
- /* Help Tip Positioning */
53
- .bnfw-help-tip-container,
54
- body.post-type-bnfw_notification #poststuff th,
55
- body.post-type-bnfw_notification #poststuff td,
56
- .bnfw-form th,
57
- .bnfw-form td {
58
- position: relative;
59
- }
60
-
61
- #bnfw-post-notification th[scope="row"],
62
- .bnfw-form th[scope="row"] {
63
- padding-right: 24px;
64
- }
65
-
66
- /* Inline Help Tips */
67
- .bnfw-help-tip {
68
- position: absolute;
69
- top: 22px;
70
- right: 8px;
71
- background-color: #73daeb;
72
- border-radius: 50%;
73
- width: 15px;
74
- height: 15px;
75
- font-size: 12px;
76
- line-height: 16px;
77
- text-align: center;
78
- cursor: default;
79
- }
80
-
81
- .bnfw-help-tip-container .bnfw-help-tip {
82
- top: 8px;
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;
96
- top: -12px;
97
- }
98
-
99
-
100
- .bnfw-help-tip:hover:before {
101
- color: #444;
102
- }
103
-
104
- .bnfw-help-tip:before {
105
- content: '?';
106
- font-weight: bold;
107
- color: #fff;
108
- }
109
-
110
- .bnfw-help-tip:hover p {
111
- display: block;
112
- transform-origin: 100% 0%;
113
- -webkit-animation: fadeIn 0.3s ease-in-out;
114
- animation: fadeIn 0.3s ease-in-out;
115
- }
116
-
117
- .bnfw-help-tip p {
118
- display: none;
119
- position: absolute;
120
- left: -8px;
121
- z-index: 9991;
122
- width: 300px;
123
- box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
124
- border-radius: 3px;
125
- background-color: #1E2021;
126
- padding: 20px;
127
- font-size: 13px;
128
- line-height: 1.4;
129
- color: #FFF;
130
- text-align: left;
131
- }
132
-
133
- .bnfw-help-tip p:before {
134
- position: absolute;
135
- content: '';
136
- width: 0;
137
- height: 0;
138
- border: 6px solid transparent;
139
- border-bottom-color: #1E2021;
140
- left: 10px;
141
- top: -12px;
142
- }
143
-
144
- .bnfw-help-tip p:after {
145
- content: '';
146
- position: absolute;
147
- top: -40px;
148
- left: 0;
149
- width: 100%;
150
- height: 40px;
151
- }
152
-
153
- .bnfw-help-tip p a {
154
- color: #73daeb;
155
- }
156
-
157
- .bnfw-help-tip p a:hover {
158
- color: #a0e6f1;
159
- }
160
-
161
- .bnfw-help-tip + .wp-ui-text-highlight {
162
- color: #1fbfd9;
163
- }
164
-
165
- @-webkit-keyframes fadeIn {
166
- 0% {
167
- opacity: 0;
168
- transform: scale(0.6);
169
- }
170
-
171
- 100% {
172
- opacity:1 00%;
173
- transform: scale(1);
174
- }
175
- }
176
-
177
- @keyframes fadeIn {
178
- 0% { opacity: 0; }
179
- 100% { opacity: 100%; }
180
  }
1
+ /* Generic classes */
2
+ .hidden {
3
+ display: none;
4
+ }
5
+
6
+ .show {
7
+ display: block;
8
+ }
9
+
10
+ #user-password-msg {
11
+ display: none;
12
+ }
13
+
14
+ #user-password-msg div {
15
+ background: #FFFFE1;
16
+ padding: 15px;
17
+ }
18
+
19
+ #users-count-msg div {
20
+ background: #F79C2D;
21
+ padding: 15px;
22
+ }
23
+
24
+ #users-count-msg div p {
25
+ margin-top: 0;
26
+ }
27
+
28
+ .manage-column.column-disabled {
29
+ width: 8% !important;
30
+ }
31
+
32
+ /* Fix 'jump' when hovering over 'x' in select2 box */
33
+ /*ul.select2-choices li.select2-search-choice a {
34
+ -webkit-transition-property: none;
35
+ transition-property: none;
36
+ -webkit-transition-duration: 0s;
37
+ transition-duration: 0s;
38
+ -webkit-transition-timing-function: initial;
39
+ transition-timing-function: initial;
40
+ }*/
41
+
42
+ /* Select2 4.0 */
43
+ .select2-container--default .select2-selection--multiple {
44
+ line-height: 0;
45
+ }
46
+
47
+ ul.select2-selection__rendered {
48
+ line-height: 1.3;
49
+ }
50
+
51
+
52
+ /* Help Tip Positioning */
53
+ .bnfw-help-tip-container,
54
+ body.post-type-bnfw_notification #poststuff th,
55
+ body.post-type-bnfw_notification #poststuff td,
56
+ .bnfw-form th,
57
+ .bnfw-form td {
58
+ position: relative;
59
+ }
60
+
61
+ #bnfw-post-notification th[scope="row"],
62
+ .bnfw-form th[scope="row"] {
63
+ padding-right: 24px;
64
+ }
65
+
66
+ /* Inline Help Tips */
67
+ .bnfw-help-tip {
68
+ position: absolute;
69
+ top: 22px;
70
+ right: 8px;
71
+ background-color: #73daeb;
72
+ border-radius: 50%;
73
+ width: 15px;
74
+ height: 15px;
75
+ font-size: 12px;
76
+ line-height: 16px;
77
+ text-align: center;
78
+ cursor: default;
79
+ }
80
+
81
+ .bnfw-help-tip-container .bnfw-help-tip {
82
+ top: 8px;
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;
96
+ top: -12px;
97
+ }
98
+
99
+
100
+ .bnfw-help-tip:hover:before {
101
+ color: #444;
102
+ }
103
+
104
+ .bnfw-help-tip:before {
105
+ content: '?';
106
+ font-weight: bold;
107
+ color: #fff;
108
+ }
109
+
110
+ .bnfw-help-tip:hover p {
111
+ display: block;
112
+ transform-origin: 100% 0%;
113
+ -webkit-animation: fadeIn 0.3s ease-in-out;
114
+ animation: fadeIn 0.3s ease-in-out;
115
+ }
116
+
117
+ .bnfw-help-tip p {
118
+ display: none;
119
+ position: absolute;
120
+ left: -8px;
121
+ z-index: 9991;
122
+ width: 300px;
123
+ box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
124
+ border-radius: 3px;
125
+ background-color: #1E2021;
126
+ padding: 20px;
127
+ font-size: 13px;
128
+ line-height: 1.4;
129
+ color: #FFF;
130
+ text-align: left;
131
+ }
132
+
133
+ .bnfw-help-tip p:before {
134
+ position: absolute;
135
+ content: '';
136
+ width: 0;
137
+ height: 0;
138
+ border: 6px solid transparent;
139
+ border-bottom-color: #1E2021;
140
+ left: 10px;
141
+ top: -12px;
142
+ }
143
+
144
+ .bnfw-help-tip p:after {
145
+ content: '';
146
+ position: absolute;
147
+ top: -40px;
148
+ left: 0;
149
+ width: 100%;
150
+ height: 40px;
151
+ }
152
+
153
+ .bnfw-help-tip p a {
154
+ color: #73daeb;
155
+ }
156
+
157
+ .bnfw-help-tip p a:hover {
158
+ color: #a0e6f1;
159
+ }
160
+
161
+ .bnfw-help-tip + .wp-ui-text-highlight {
162
+ color: #1fbfd9;
163
+ }
164
+
165
+ @-webkit-keyframes fadeIn {
166
+ 0% {
167
+ opacity: 0;
168
+ transform: scale(0.6);
169
+ }
170
+
171
+ 100% {
172
+ opacity:1 00%;
173
+ transform: scale(1);
174
+ }
175
+ }
176
+
177
+ @keyframes fadeIn {
178
+ 0% { opacity: 0; }
179
+ 100% { opacity: 100%; }
180
  }
assets/img/icon-256x256.png CHANGED
File without changes
assets/js/bnfw.js CHANGED
@@ -1,642 +1,643 @@
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
- var notification = $( "#notification" ).val();
19
- if('user-login' === notification){
20
- if ( show_fields ) {
21
- $('#email, #reply').show();
22
- } else {
23
- $('#email, #reply').hide();
24
- }
25
- }else{
26
- if ( show_fields ) {
27
- $('#email, #cc, #bcc, #reply').show();
28
- } else {
29
- $('#email, #cc, #bcc, #reply').hide();
30
- }
31
- }
32
- $( '#subject-wrapper' ).show();
33
- }
34
-
35
- function toggle_users() {
36
- if ( $( '#only-post-author' ).is( ':checked' ) ) {
37
- $( '#current-user' ).hide();
38
- } else {
39
- $( '#current-user' ).show();
40
- }
41
-
42
- var notification = $( '#notification' ).val();
43
- var check_comment = notification.split('-');
44
- if ( 'new-comment' === notification || 'approve' === check_comment[0] || 'moderate-comment' === notification ) {
45
- $( '#current-user' ).show();
46
- }
47
- }
48
-
49
- function init() {
50
- var notification = $('#notification').val();
51
-
52
- $("#notification, .bnfw-select2").select2();
53
-
54
- $(".user-select2").select2({
55
- tags: BNFW.enableTags,
56
- tokenSeparators: BNFW.enabletokenSeparators
57
- } );
58
-
59
- $(".user-ajax-select2").select2( {
60
- ajax: {
61
- url: ajaxurl,
62
- dataType: 'json',
63
- data: function( params ) {
64
- return {
65
- action: 'bnfw_search_users',
66
- query: params.term,
67
- page: params.page
68
- };
69
- },
70
- processResults: function( data, page ) {
71
- return {
72
- results: data
73
- };
74
- }
75
- },
76
- minimumInputLength: 1,
77
- tags: BNFW.enableTags
78
- } );
79
-
80
- if ( ! $( '#notification' ).length ) {
81
- return;
82
- }
83
-
84
- toggle_fields();
85
-
86
- var check_comment = notification.split('-');
87
-
88
- if ( 'reply-comment' === notification || notification.startsWith( 'commentreply-' ) ||
89
- 'new-user' === notification || 'welcome-email' === notification || 'user-password' === notification ||
90
- 'password-changed' === notification || 'email-changed' === notification || 'email-changing' === notification || 'user-role' === notification ||
91
- 'ca-export-data' === notification || 'ca-erase-data' === notification ||
92
- 'uc-export-data' === notification || 'uc-erase-data' === notification ||
93
- 'data-export' === notification || 'data-erased' === notification ||
94
- 'multisite-new-user-invited' === notification || 'multisite-new-user-created' === notification || 'multisite-new-user-welcome' === notification ||
95
- 'multisite-site-registered' === notification || 'multisite-site-welcome' === notification ||
96
- 'multisite-site-created' === notification || 'multisite-site-deleted' === notification ||
97
- 'multisite-site-admin-email-change-attempted' === notification || 'multisite-site-admin-email-changed' === notification ||
98
- 'multisite-network-admin-email-change-attempted' === notification || 'multisite-network-admin-email-changed' === notification) {
99
-
100
- $('#toggle-fields, #email, #cc, #bcc, #reply, #users, #exclude-users, #current-user, #post-author').hide();
101
- $('#user-password-msg, #disable-autop, #email-formatting').show();
102
-
103
- $( '#subject-wrapper' ).show();
104
- if ( 'multisite-new-user-created' === notification || 'multisite-site-created' === notification || 'multisite-site-deleted' === notification ||
105
- 'multisite-site-admin-email-change-attempted' === notification || 'multisite-network-admin-email-change-attempted' === notification ||
106
- 'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
107
- 'ca-export-data' === notification || 'ca-erase-data' === notification || 'email-changing' === notification ) {
108
-
109
- $( '#subject-wrapper' ).hide();
110
- }
111
-
112
- if ( 'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
113
- 'ca-export-data' === notification || 'ca-erase-data' === notification || 'data-erased' === notification || ( -1 !== multisiteNotifications.indexOf( notification ) ) ) {
114
-
115
- $( '#email-formatting' ).hide();
116
- }
117
- } else if ( 'new-comment' === notification || 'approve' === check_comment[0] || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ||
118
- 'admin-password' === notification || 'admin-user' === notification || 'admin-role' === notification ) {
119
-
120
- if ( 'new-comment' === notification || 'approve' === check_comment[0] || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ) {
121
- $('#post-author').show();
122
- } else {
123
- $('#post-author').hide();
124
- }
125
-
126
- $('#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop, #current-user').show();
127
- toggle_fields();
128
- toggle_users();
129
- $( '#user-password-msg' ).hide();
130
- } else if ( 'admin-password-changed' === notification || 'admin-email-changed' === notification || 'core-updated' === notification ) {
131
- $( '#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop' ).show();
132
- toggle_fields();
133
- toggle_users();
134
- $( '#user-password-msg, #current-user, #post-author' ).hide();
135
- } else if ('user-login' === notification){
136
- $('#cc, #bcc, #users, #exclude-users, #current-user, #post-author').hide();
137
- $('#toggle-fields').show();
138
- } else {
139
- $('#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop, #current-user, #post-author').show();
140
- toggle_fields();
141
- toggle_users();
142
- $('#user-password-msg').hide();
143
- }
144
- }
145
-
146
- init();
147
-
148
- /**
149
- * Show a warning message if a notification is configured for more than 200 emails.
150
- */
151
- $( '#users-select' ).on( 'change', function () {
152
- var emailCount = $( '#users-select' ).find( ':selected' ).length,
153
- $msg = $( '#users-count-msg' );
154
-
155
- if ( emailCount > 200 ) {
156
- $msg.show();
157
- } else {
158
- $msg.hide();
159
- }
160
- } );
161
-
162
- $('#notification').on('change', function() {
163
- var $this = $(this),
164
- notification = $this.val();
165
-
166
- var check_comment = notification.split('-');
167
-
168
- if ( 'reply-comment' === notification || notification.startsWith( 'commentreply-' ) ||
169
- 'new-user' === notification || 'welcome-email' === notification || 'user-password' === notification ||
170
- 'password-changed' === notification || 'email-changed' === notification || 'email-changing' === notification || 'user-role' === notification ||
171
- 'ca-export-data' === notification || 'ca-erase-data' === notification ||
172
- 'uc-export-data' === notification || 'uc-erase-data' === notification ||
173
- 'data-export' === notification || 'data-erased' === notification ||
174
- 'multisite-new-user-invited' === notification || 'multisite-new-user-created' === notification || 'multisite-new-user-welcome' === notification ||
175
- 'multisite-site-registered' === notification || 'multisite-site-welcome' === notification ||
176
- 'multisite-site-created' === notification || 'multisite-site-deleted' === notification ||
177
- 'multisite-site-admin-email-change-attempted' === notification || 'multisite-site-admin-email-changed' === notification ||
178
- 'multisite-network-admin-email-change-attempted' === notification || 'multisite-network-admin-email-changed' === notification) {
179
-
180
- $('#toggle-fields, #email, #cc, #bcc, #reply, #users, #exclude-users, #current-user, #post-author').hide();
181
- $('#user-password-msg, #disable-autop, #email-formatting').show();
182
-
183
- $( '#subject-wrapper' ).show();
184
- if ( 'multisite-new-user-created' === notification || 'multisite-site-created' === notification || 'multisite-site-deleted' === notification ||
185
- 'multisite-site-admin-email-change-attempted' === notification || 'multisite-network-admin-email-change-attempted' === notification ||
186
- 'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
187
- 'ca-export-data' === notification || 'ca-erase-data' === notification || 'email-changing' === notification ) {
188
-
189
- $( '#subject-wrapper' ).hide();
190
- }
191
-
192
- if ( 'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
193
- 'ca-export-data' === notification || 'ca-erase-data' === notification || 'data-erased' === notification || ( -1 !== multisiteNotifications.indexOf( notification ) ) ) {
194
-
195
- $( '#email-formatting' ).hide();
196
- }
197
- } else if ( 'new-comment' === notification || 'approve' === check_comment[0] ||
198
- notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ||
199
- 'admin-password' === notification || 'admin-user' === notification || 'admin-role' === notification ) {
200
-
201
- if ( 'new-comment' === notification || 'approve' === check_comment[0] || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ) {
202
- $('#post-author').show();
203
- } else {
204
- $('#post-author').hide();
205
- }
206
-
207
- $('#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop, #current-user').show();
208
- $('#user-password-msg').hide();
209
- toggle_fields();
210
- toggle_users();
211
- } else if ( 'admin-password-changed' === notification || 'admin-email-changed' === notification || 'core-updated' === notification ) {
212
- $( '#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop' ).show();
213
- toggle_fields();
214
- toggle_users();
215
- $( '#user-password-msg, #current-user, #post-author' ).hide();
216
- } else if ('user-login' === notification){
217
- $('#cc, #bcc, #users, #exclude-users, #current-user, #post-author').hide();
218
- $('#toggle-fields').show();
219
- } else {
220
- $('#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop, #current-user, #post-author').show();
221
- $('#user-password-msg').hide();
222
- toggle_fields();
223
- toggle_users();
224
- }
225
- });
226
-
227
- $('#show-fields').change(function() {
228
- toggle_fields();
229
- });
230
-
231
- $( '#only-post-author' ).change(function() {
232
- toggle_users();
233
- } );
234
-
235
- // send test email
236
- $( '#test-email' ).click(function() {
237
- $( '#send-test-email' ).val( 'true' );
238
- });
239
-
240
- // Validate before saving notification
241
- $( '#publish' ).click(function() {
242
- if ( $('#users').is(':visible') ) {
243
- if ( null === $(BNFW.validation_element).val() && $('#only-post-author:checked').length <= 0 ) {
244
- $('#bnfw_error').remove();
245
- $('.wrap h1').after('<div class="error" id="bnfw_error"><p>' + BNFW.empty_user + '</p></div>');
246
- return false;
247
- }
248
- }
249
-
250
- return true;
251
- });
252
-
253
- $( '#shortcode-help' ).on( 'click', function() {
254
- var notification = $( '#notification' ).val(),
255
- notification_slug = '',
256
- splited;
257
-
258
- switch( notification ) {
259
- case 'new-comment':
260
- case 'new-trackback':
261
- case 'new-pingback':
262
- case 'reply-comment':
263
- case 'commentreply-page':
264
- case 'user-password':
265
- case 'admin-password':
266
- case 'admin-password-changed':
267
- case 'admin-email-changed':
268
- case 'password-changed':
269
- case 'email-changed':
270
- case 'email-changing':
271
- case 'new-user':
272
- case 'user-login':
273
- case 'admin-user-login':
274
- case 'welcome-email':
275
- case 'user-role':
276
- case 'admin-role':
277
- case 'admin-user':
278
- case 'new-post':
279
- case 'core-updated':
280
- case 'update-post':
281
- case 'pending-post':
282
- case 'future-post':
283
- case 'newterm-category':
284
- case 'new-media':
285
- case 'comment-attachment':
286
- case 'update-media':
287
- case 'newterm-post_tag':
288
- notification_slug = notification;
289
- break;
290
-
291
- default:
292
- splited = notification.split( '-' );
293
- switch( splited[0] ) {
294
- case 'new':
295
- notification_slug = 'new-post';
296
- break;
297
- case 'update':
298
- notification_slug = 'update-post';
299
- break;
300
- case 'pending':
301
- notification_slug = 'pending-post';
302
- break;
303
- case 'private':
304
- notification_slug = 'private-post';
305
- break;
306
- case 'future':
307
- notification_slug = 'future-post';
308
- break;
309
- case 'comment':
310
- notification_slug = 'new-comment';
311
- break;
312
- case 'approve':
313
- notification_slug = 'approve-comment';
314
- break;
315
- case 'moderate':
316
- notification_slug = 'moderate-comment';
317
- break;
318
- case 'commentreply':
319
- notification_slug = 'reply-comment';
320
- break;
321
- case 'newterm':
322
- notification_slug = 'newterm-category';
323
- break;
324
- // ideally these should be in the add-ons. But hardcoding them here for now
325
- case 'customfield':
326
- notification_slug = 'customfield-post';
327
- break;
328
- case 'updatereminder':
329
- notification_slug = 'updatereminder-post';
330
- break;
331
-
332
- default:
333
- notification_slug = notification;
334
- break;
335
- }
336
-
337
- break;
338
- }
339
-
340
- $(this).attr( 'href', 'https://betternotificationsforwp.com/documentation/notifications/shortcodes/?notification=' + notification_slug + '&utm_source=WP%20Admin%20Notification%20Editor%20-%20"Shortcode%20Help"&utm_medium=referral' );
341
- });
342
-
343
- /**
344
- * Insert Default Message for notification.
345
- */
346
- $( '#insert-default-msg' ).on( 'click', function() {
347
- var notification = $( '#notification' ).val(),
348
- subject = '',
349
- body = '';
350
-
351
- switch ( notification ) {
352
- case 'new-comment':
353
- case 'moderate-comment':
354
- case 'new-trackback':
355
- case 'new-pingback':
356
- case 'reply-comment':
357
- subject = '[[global_site_title]] Comment: "[post_title]"';
358
- body = 'New comment on your post "[post_title]"<br>' +
359
- 'Author: [comment_author] (IP address: [comment_author_IP]) <br>' +
360
- 'Email: [comment_author_email] <br>' +
361
- 'URL: [comment_author_url] <br>' +
362
- 'Comment: <br> ' +
363
- '[comment_content] <br>' +
364
- '<br>' +
365
- 'You can see all comments on this post here: <br>' +
366
- '[permalink]#comments';
367
-
368
- break;
369
-
370
- case 'admin-user':
371
- subject = '[[global_site_title]] New User Registration';
372
- body = 'New user registration on your site [global_site_title]: <br>' +
373
- 'Username: [user_login] <br>' +
374
- 'E-mail: [user_email]';
375
-
376
- break;
377
-
378
- case 'admin-password-changed':
379
- subject = '[[global_site_title]] Password Changed';
380
- body = 'Password changed for user: [user_login] <br>';
381
-
382
- break;
383
-
384
- case 'user-password':
385
- subject = '[[global_site_title]] Password Reset';
386
- body = 'Someone has requested a password reset for the following account: <br>' +
387
- 'Site Name: [global_site_title] <br>' +
388
- 'Username: [email_user_login] <br>' +
389
- 'If this was a mistake, just ignore this email and nothing will happen. <br>' +
390
- 'To reset your password, visit the following address: [password_reset_link]';
391
-
392
- break;
393
-
394
- case 'password-changed':
395
- subject = '[[global_site_title]] Notice of Password Change';
396
- body = 'Hi [email_user_login], <br>' +
397
- '<br>' +
398
- 'This notice confirms that your password was changed on [global_site_title].' +
399
- '<br><br>' +
400
- 'If you did not change your password, please contact the Site Administrator at [admin_email] <br>' +
401
- '<br>' +
402
- 'This email has been sent to [global_user_email]' +
403
- '<br>' +
404
- 'Regards, <br>' +
405
- 'All at [global_site_title] <br>' +
406
- '[global_site_url]';
407
- break;
408
-
409
- case 'email-changing':
410
- subject = '[[global_site_title]] New Email Address';
411
- body = 'Hi [user_nicename], <br>' +
412
- '<br>' +
413
- 'You recently requested to have the email address on your account changed.' +
414
- '<br>' +
415
- 'If this is correct, please click on the following link to change it:' +
416
- '<br>' +
417
- '[global_site_url]/wp-admin/profile.php' +
418
- '<br>' +
419
- 'You can safely ignore and delete this email if you do not want to take this action.' +
420
- '<br>' +
421
- 'This email has been sent to [global_user_email]' +
422
- '<br>' +
423
- 'Regards, <br>' +
424
- 'All at [global_site_title] <br>' +
425
- '[global_site_url]';
426
- break;
427
-
428
- case 'email-changed':
429
- subject = '[[global_site_title]] Notice of Email Change';
430
- body = 'Hi [user_nicename], <br>' +
431
- '<br>' +
432
- 'This notice confirms that your email address on [global_site_title] was changed to [user_email].' +
433
- '<br>' +
434
- 'If you did not change your email, please contact the Site Administrator at [admin_email] <br>' +
435
- '<br>' +
436
- 'This email has been sent to [global_user_email]' +
437
- '<br>' +
438
- 'Regards, <br>' +
439
- 'All at [global_site_title] <br>' +
440
- '[global_site_url]';
441
- break;
442
-
443
- case 'new-user':
444
- subject = '[[global_site_title]] Your username and password info';
445
- body = 'Username: [user_login] <br>' +
446
- 'To set your password, visit the following address: [password_url]';
447
-
448
- break;
449
-
450
- case 'multisite-new-user-invited':
451
- subject = '[[network_name] Activate [user_login]';
452
- body = 'To activate your user, please click the following link:' +
453
- '<br>' +
454
- '[activation_link]' +
455
- '<br>' +
456
- 'After you activate, you will receive *another email* with your login.';
457
-
458
- break;
459
-
460
- case 'ca-export-data':
461
- subject = '[[global_site_title]] Confirm Action: Export Personal Data';
462
- body = 'Howdy,' +
463
- '<br>' +
464
- '<br>' +
465
- 'A request has been made to perform the following action on your account:' +
466
- '<br>' +
467
- '<br>' +
468
- '[data_request_type]' +
469
- '<br>' +
470
- '<br>' +
471
- 'To confirm this, please click on the following link:' +
472
- '<br>' +
473
- '<br>' +
474
- '[request_confirmation_link]' +
475
- '<br>' +
476
- '<br>' +
477
- 'You can safely ignore and delete this email if you do not want to' +
478
- '<br>' +
479
- 'take this action.' +
480
- '<br>' +
481
- '<br>' +
482
- 'This email has been sent to [global_user_email].' +
483
- '<br>' +
484
- '<br>' +
485
- 'Regards,' +
486
- '<br>' +
487
- 'All at [global_site_title]' +
488
- '<br>' +
489
- '[global_site_url]';
490
-
491
- break;
492
-
493
- case 'ca-erase-data':
494
- subject = '[[global_site_title]] Confirm Action: Erase Personal Data';
495
- body = 'Howdy,' +
496
- '<br>' +
497
- '<br>' +
498
- 'A request has been made to perform the following action on your account:' +
499
- '<br>' +
500
- '<br>' +
501
- '[data_request_type]' +
502
- '<br>' +
503
- '<br>' +
504
- 'To confirm this, please click on the following link:' +
505
- '<br>' +
506
- '<br>' +
507
- '[request_confirmation_link]' +
508
- '<br>' +
509
- '<br>' +
510
- 'You can safely ignore and delete this email if you do not want to' +
511
- '<br>' +
512
- 'take this action.' +
513
- '<br>' +
514
- '<br>' +
515
- 'This email has been sent to [global_user_email].' +
516
- '<br>' +
517
- '<br>' +
518
- 'Regards,' +
519
- '<br>' +
520
- 'All at [global_site_title]' +
521
- '<br>' +
522
- '[global_site_url]';
523
-
524
- break;
525
-
526
- case 'uc-export-data':
527
- subject = 'Action Confirmed';
528
-
529
- body = 'Howdy,' +
530
- '<br>' +
531
- '<br>' +
532
- 'A user data privacy request has been confirmed on [global_site_title]:' +
533
- '<br>' +
534
- '<br>' +
535
- 'User: [email_user_email]' +
536
- '<br>' +
537
- 'Request: [data_request_type]' +
538
- '<br>' +
539
- '<br>' +
540
- 'You can view and manage these data privacy requests here:' +
541
- '<br>' +
542
- '<br>' +
543
- '[data_privacy_requests_url]' +
544
- '<br>' +
545
- '<br>' +
546
- 'Regards,' +
547
- '<br>' +
548
- 'All at [global_site_title]' +
549
- '<br>' +
550
- '[global_site_url]';
551
- break;
552
-
553
- case 'uc-erase-data':
554
- subject = 'Action Confirmed';
555
-
556
- body = 'Howdy,' +
557
- '<br>' +
558
- '<br>' +
559
- 'A user data privacy request has been confirmed on [global_site_title]:' +
560
- '<br>' +
561
- '<br>' +
562
- 'User: [email_user_email]' +
563
- '<br>' +
564
- 'Request: [data_request_type]' +
565
- '<br>' +
566
- '<br>' +
567
- 'You can view and manage these data privacy requests here:' +
568
- '<br>' +
569
- '<br>' +
570
- '[data_privacy_requests_url]' +
571
- '<br>' +
572
- '<br>' +
573
- 'Regards,' +
574
- '<br>' +
575
- 'All at [global_site_title]' +
576
- '<br>' +
577
- '[global_site_title]';
578
- break;
579
-
580
- case 'data-export':
581
- subject = 'Personal Data Export';
582
-
583
- body = 'Howdy,' +
584
- '<br>' +
585
- '<br>' +
586
- 'Your request for an export of personal data has been completed. You may' +
587
- '<br>' +
588
- 'download your personal data by clicking on the link below. For privacy' +
589
- '<br>' +
590
- 'and security, we will automatically delete the file on [data_privacy_download_expiry],' +
591
- '<br>' +
592
- 'so please download it before then.' +
593
- '<br>' +
594
- '<br>' +
595
- '[data_privacy_download_url]' +
596
- '<br>' +
597
- '<br>' +
598
- 'This email has been sent to [global_user_email].' +
599
- '<br>' +
600
- '<br>' +
601
- 'Regards,' +
602
- '<br>' +
603
- 'All at [global_site_title]' +
604
- '<br>' +
605
- '[global_site_url]';
606
- break;
607
-
608
- case 'data-erased':
609
- subject = '[sitename] Erasure Request Fulfilled';
610
-
611
- body = 'Howdy,' +
612
- '<br>' +
613
- '<br>' +
614
- 'Your request to erase your personal data on [sitename] has been completed.' +
615
- '<br>' +
616
- 'If you have any follow-up questions or concerns, please contact the site administrator.' +
617
- '<br>' +
618
- '<br>' +
619
- 'Regards,' +
620
- '<br>' +
621
- 'All at [global_site_title]' +
622
- '<br>' +
623
- '[global_site_url]';
624
- break;
625
- default:
626
- alert( "This is a new notification that is not available in WordPress by default and has been added by Better Notifications for WP. As such, it doesn't have any default content." );
627
- break;
628
- }
629
-
630
- if ( subject !== '' ) {
631
- $( '#subject' ).val( subject );
632
- }
633
-
634
- if ( body !== '' ) {
635
- if ( tinyMCE && tinyMCE.editors && tinyMCE.editors['notification_message'] ) {
636
- tinyMCE.editors['notification_message'].selection.setContent( body );
637
- }
638
- }
639
-
640
- return false;
641
- } );
642
- });
 
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
+ var notification = $( "#notification" ).val();
19
+ if('user-login' === notification){
20
+ if ( show_fields ) {
21
+ $('#email, #reply').show();
22
+ } else {
23
+ $('#email, #reply').hide();
24
+ }
25
+ }else{
26
+ if ( show_fields ) {
27
+ $('#email, #cc, #bcc, #reply').show();
28
+ } else {
29
+ $('#email, #cc, #bcc, #reply').hide();
30
+ }
31
+ }
32
+ $( '#subject-wrapper' ).show();
33
+ }
34
+
35
+ function toggle_users() {
36
+ if ( $( '#only-post-author' ).is( ':checked' ) ) {
37
+ $( '#current-user' ).hide();
38
+ } else {
39
+ $( '#current-user' ).show();
40
+ }
41
+
42
+ var notification = $( '#notification' ).val();
43
+ var check_comment = notification.split('-');
44
+ if ( 'new-comment' === notification || 'approve' === check_comment[0] || 'moderate-comment' === notification ) {
45
+ $( '#current-user' ).show();
46
+ }
47
+ }
48
+
49
+ function init() {
50
+ var notification = $('#notification').val();
51
+
52
+ $("#notification, .bnfw-select2").select2();
53
+
54
+ $(".user-select2").select2({
55
+ tags: BNFW.enableTags,
56
+ tokenSeparators: BNFW.enabletokenSeparators
57
+ } );
58
+
59
+ $(".user-ajax-select2").select2( {
60
+ ajax: {
61
+ url: ajaxurl,
62
+ dataType: 'json',
63
+ data: function( params ) {
64
+ return {
65
+ action: 'bnfw_search_users',
66
+ query: params.term,
67
+ bnfw_security: BNFW.bnfw_users_search_ajax_nonce,
68
+ page: params.page
69
+ };
70
+ },
71
+ processResults: function( data, page ) {
72
+ return {
73
+ results: data
74
+ };
75
+ }
76
+ },
77
+ minimumInputLength: 1,
78
+ tags: BNFW.enableTags
79
+ } );
80
+
81
+ if ( ! $( '#notification' ).length ) {
82
+ return;
83
+ }
84
+
85
+ toggle_fields();
86
+
87
+ var check_comment = notification.split('-');
88
+
89
+ if ( 'reply-comment' === notification || notification.startsWith( 'commentreply-' ) ||
90
+ 'new-user' === notification || 'welcome-email' === notification || 'user-password' === notification ||
91
+ 'password-changed' === notification || 'email-changed' === notification || 'email-changing' === notification || 'user-role' === notification ||
92
+ 'ca-export-data' === notification || 'ca-erase-data' === notification ||
93
+ 'uc-export-data' === notification || 'uc-erase-data' === notification ||
94
+ 'data-export' === notification || 'data-erased' === notification ||
95
+ 'multisite-new-user-invited' === notification || 'multisite-new-user-created' === notification || 'multisite-new-user-welcome' === notification ||
96
+ 'multisite-site-registered' === notification || 'multisite-site-welcome' === notification ||
97
+ 'multisite-site-created' === notification || 'multisite-site-deleted' === notification ||
98
+ 'multisite-site-admin-email-change-attempted' === notification || 'multisite-site-admin-email-changed' === notification ||
99
+ 'multisite-network-admin-email-change-attempted' === notification || 'multisite-network-admin-email-changed' === notification) {
100
+
101
+ $('#toggle-fields, #email, #cc, #bcc, #reply, #users, #exclude-users, #current-user, #post-author').hide();
102
+ $('#user-password-msg, #disable-autop, #email-formatting').show();
103
+
104
+ $( '#subject-wrapper' ).show();
105
+ if ( 'multisite-new-user-created' === notification || 'multisite-site-created' === notification || 'multisite-site-deleted' === notification ||
106
+ 'multisite-site-admin-email-change-attempted' === notification || 'multisite-network-admin-email-change-attempted' === notification ||
107
+ 'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
108
+ 'ca-export-data' === notification || 'ca-erase-data' === notification || 'email-changing' === notification ) {
109
+
110
+ $( '#subject-wrapper' ).hide();
111
+ }
112
+
113
+ if ( 'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
114
+ 'ca-export-data' === notification || 'ca-erase-data' === notification || 'data-erased' === notification || ( -1 !== multisiteNotifications.indexOf( notification ) ) ) {
115
+
116
+ $( '#email-formatting' ).hide();
117
+ }
118
+ } else if ( 'new-comment' === notification || 'approve' === check_comment[0] || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ||
119
+ 'admin-password' === notification || 'admin-user' === notification || 'admin-role' === notification ) {
120
+
121
+ if ( 'new-comment' === notification || 'approve' === check_comment[0] || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ) {
122
+ $('#post-author').show();
123
+ } else {
124
+ $('#post-author').hide();
125
+ }
126
+
127
+ $('#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop, #current-user').show();
128
+ toggle_fields();
129
+ toggle_users();
130
+ $( '#user-password-msg' ).hide();
131
+ } else if ( 'admin-password-changed' === notification || 'admin-email-changed' === notification || 'core-updated' === notification ) {
132
+ $( '#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop' ).show();
133
+ toggle_fields();
134
+ toggle_users();
135
+ $( '#user-password-msg, #current-user, #post-author' ).hide();
136
+ } else if ('user-login' === notification){
137
+ $('#cc, #bcc, #users, #exclude-users, #current-user, #post-author').hide();
138
+ $('#toggle-fields').show();
139
+ } else {
140
+ $('#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop, #current-user, #post-author').show();
141
+ toggle_fields();
142
+ toggle_users();
143
+ $('#user-password-msg').hide();
144
+ }
145
+ }
146
+
147
+ init();
148
+
149
+ /**
150
+ * Show a warning message if a notification is configured for more than 200 emails.
151
+ */
152
+ $( '#users-select' ).on( 'change', function () {
153
+ var emailCount = $( '#users-select' ).find( ':selected' ).length,
154
+ $msg = $( '#users-count-msg' );
155
+
156
+ if ( emailCount > 200 ) {
157
+ $msg.show();
158
+ } else {
159
+ $msg.hide();
160
+ }
161
+ } );
162
+
163
+ $('#notification').on('change', function() {
164
+ var $this = $(this),
165
+ notification = $this.val();
166
+
167
+ var check_comment = notification.split('-');
168
+
169
+ if ( 'reply-comment' === notification || notification.startsWith( 'commentreply-' ) ||
170
+ 'new-user' === notification || 'welcome-email' === notification || 'user-password' === notification ||
171
+ 'password-changed' === notification || 'email-changed' === notification || 'email-changing' === notification || 'user-role' === notification ||
172
+ 'ca-export-data' === notification || 'ca-erase-data' === notification ||
173
+ 'uc-export-data' === notification || 'uc-erase-data' === notification ||
174
+ 'data-export' === notification || 'data-erased' === notification ||
175
+ 'multisite-new-user-invited' === notification || 'multisite-new-user-created' === notification || 'multisite-new-user-welcome' === notification ||
176
+ 'multisite-site-registered' === notification || 'multisite-site-welcome' === notification ||
177
+ 'multisite-site-created' === notification || 'multisite-site-deleted' === notification ||
178
+ 'multisite-site-admin-email-change-attempted' === notification || 'multisite-site-admin-email-changed' === notification ||
179
+ 'multisite-network-admin-email-change-attempted' === notification || 'multisite-network-admin-email-changed' === notification) {
180
+
181
+ $('#toggle-fields, #email, #cc, #bcc, #reply, #users, #exclude-users, #current-user, #post-author').hide();
182
+ $('#user-password-msg, #disable-autop, #email-formatting').show();
183
+
184
+ $( '#subject-wrapper' ).show();
185
+ if ( 'multisite-new-user-created' === notification || 'multisite-site-created' === notification || 'multisite-site-deleted' === notification ||
186
+ 'multisite-site-admin-email-change-attempted' === notification || 'multisite-network-admin-email-change-attempted' === notification ||
187
+ 'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
188
+ 'ca-export-data' === notification || 'ca-erase-data' === notification || 'email-changing' === notification ) {
189
+
190
+ $( '#subject-wrapper' ).hide();
191
+ }
192
+
193
+ if ( 'uc-export-data' === notification || 'uc-erase-data' === notification || 'data-export' === notification ||
194
+ 'ca-export-data' === notification || 'ca-erase-data' === notification || 'data-erased' === notification || ( -1 !== multisiteNotifications.indexOf( notification ) ) ) {
195
+
196
+ $( '#email-formatting' ).hide();
197
+ }
198
+ } else if ( 'new-comment' === notification || 'approve' === check_comment[0] ||
199
+ notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ||
200
+ 'admin-password' === notification || 'admin-user' === notification || 'admin-role' === notification ) {
201
+
202
+ if ( 'new-comment' === notification || 'approve' === check_comment[0] || notification.startsWith( 'moderate-comment-' ) || 'new-trackback' === notification || 'new-pingback' === notification ) {
203
+ $('#post-author').show();
204
+ } else {
205
+ $('#post-author').hide();
206
+ }
207
+
208
+ $('#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop, #current-user').show();
209
+ $('#user-password-msg').hide();
210
+ toggle_fields();
211
+ toggle_users();
212
+ } else if ( 'admin-password-changed' === notification || 'admin-email-changed' === notification || 'core-updated' === notification ) {
213
+ $( '#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop' ).show();
214
+ toggle_fields();
215
+ toggle_users();
216
+ $( '#user-password-msg, #current-user, #post-author' ).hide();
217
+ } else if ('user-login' === notification){
218
+ $('#cc, #bcc, #users, #exclude-users, #current-user, #post-author').hide();
219
+ $('#toggle-fields').show();
220
+ } else {
221
+ $('#toggle-fields, #users, #exclude-users, #email-formatting, #disable-autop, #current-user, #post-author').show();
222
+ $('#user-password-msg').hide();
223
+ toggle_fields();
224
+ toggle_users();
225
+ }
226
+ });
227
+
228
+ $('#show-fields').change(function() {
229
+ toggle_fields();
230
+ });
231
+
232
+ $( '#only-post-author' ).change(function() {
233
+ toggle_users();
234
+ } );
235
+
236
+ // send test email
237
+ $( '#test-email' ).click(function() {
238
+ $( '#send-test-email' ).val( 'true' );
239
+ });
240
+
241
+ // Validate before saving notification
242
+ $( '#publish' ).click(function() {
243
+ if ( $('#users').is(':visible') ) {
244
+ if ( null === $(BNFW.validation_element).val() && $('#only-post-author:checked').length <= 0 ) {
245
+ $('#bnfw_error').remove();
246
+ $('.wrap h1').after('<div class="error" id="bnfw_error"><p>' + BNFW.empty_user + '</p></div>');
247
+ return false;
248
+ }
249
+ }
250
+
251
+ return true;
252
+ });
253
+
254
+ $( '#shortcode-help' ).on( 'click', function() {
255
+ var notification = $( '#notification' ).val(),
256
+ notification_slug = '',
257
+ splited;
258
+
259
+ switch( notification ) {
260
+ case 'new-comment':
261
+ case 'new-trackback':
262
+ case 'new-pingback':
263
+ case 'reply-comment':
264
+ case 'commentreply-page':
265
+ case 'user-password':
266
+ case 'admin-password':
267
+ case 'admin-password-changed':
268
+ case 'admin-email-changed':
269
+ case 'password-changed':
270
+ case 'email-changed':
271
+ case 'email-changing':
272
+ case 'new-user':
273
+ case 'user-login':
274
+ case 'admin-user-login':
275
+ case 'welcome-email':
276
+ case 'user-role':
277
+ case 'admin-role':
278
+ case 'admin-user':
279
+ case 'new-post':
280
+ case 'core-updated':
281
+ case 'update-post':
282
+ case 'pending-post':
283
+ case 'future-post':
284
+ case 'newterm-category':
285
+ case 'new-media':
286
+ case 'comment-attachment':
287
+ case 'update-media':
288
+ case 'newterm-post_tag':
289
+ notification_slug = notification;
290
+ break;
291
+
292
+ default:
293
+ splited = notification.split( '-' );
294
+ switch( splited[0] ) {
295
+ case 'new':
296
+ notification_slug = 'new-post';
297
+ break;
298
+ case 'update':
299
+ notification_slug = 'update-post';
300
+ break;
301
+ case 'pending':
302
+ notification_slug = 'pending-post';
303
+ break;
304
+ case 'private':
305
+ notification_slug = 'private-post';
306
+ break;
307
+ case 'future':
308
+ notification_slug = 'future-post';
309
+ break;
310
+ case 'comment':
311
+ notification_slug = 'new-comment';
312
+ break;
313
+ case 'approve':
314
+ notification_slug = 'approve-comment';
315
+ break;
316
+ case 'moderate':
317
+ notification_slug = 'moderate-comment';
318
+ break;
319
+ case 'commentreply':
320
+ notification_slug = 'reply-comment';
321
+ break;
322
+ case 'newterm':
323
+ notification_slug = 'newterm-category';
324
+ break;
325
+ // ideally these should be in the add-ons. But hardcoding them here for now
326
+ case 'customfield':
327
+ notification_slug = 'customfield-post';
328
+ break;
329
+ case 'updatereminder':
330
+ notification_slug = 'updatereminder-post';
331
+ break;
332
+
333
+ default:
334
+ notification_slug = notification;
335
+ break;
336
+ }
337
+
338
+ break;
339
+ }
340
+
341
+ $(this).attr( 'href', 'https://betternotificationsforwp.com/documentation/notifications/shortcodes/?notification=' + notification_slug + '&utm_source=WP%20Admin%20Notification%20Editor%20-%20"Shortcode%20Help"&utm_medium=referral' );
342
+ });
343
+
344
+ /**
345
+ * Insert Default Message for notification.
346
+ */
347
+ $( '#insert-default-msg' ).on( 'click', function() {
348
+ var notification = $( '#notification' ).val(),
349
+ subject = '',
350
+ body = '';
351
+
352
+ switch ( notification ) {
353
+ case 'new-comment':
354
+ case 'moderate-comment':
355
+ case 'new-trackback':
356
+ case 'new-pingback':
357
+ case 'reply-comment':
358
+ subject = '[[global_site_title]] Comment: "[post_title]"';
359
+ body = 'New comment on your post "[post_title]"<br>' +
360
+ 'Author: [comment_author] (IP address: [comment_author_IP]) <br>' +
361
+ 'Email: [comment_author_email] <br>' +
362
+ 'URL: [comment_author_url] <br>' +
363
+ 'Comment: <br> ' +
364
+ '[comment_content] <br>' +
365
+ '<br>' +
366
+ 'You can see all comments on this post here: <br>' +
367
+ '[permalink]#comments';
368
+
369
+ break;
370
+
371
+ case 'admin-user':
372
+ subject = '[[global_site_title]] New User Registration';
373
+ body = 'New user registration on your site [global_site_title]: <br>' +
374
+ 'Username: [user_login] <br>' +
375
+ 'E-mail: [user_email]';
376
+
377
+ break;
378
+
379
+ case 'admin-password-changed':
380
+ subject = '[[global_site_title]] Password Changed';
381
+ body = 'Password changed for user: [user_login] <br>';
382
+
383
+ break;
384
+
385
+ case 'user-password':
386
+ subject = '[[global_site_title]] Password Reset';
387
+ body = 'Someone has requested a password reset for the following account: <br>' +
388
+ 'Site Name: [global_site_title] <br>' +
389
+ 'Username: [email_user_login] <br>' +
390
+ 'If this was a mistake, just ignore this email and nothing will happen. <br>' +
391
+ 'To reset your password, visit the following address: [password_reset_link]';
392
+
393
+ break;
394
+
395
+ case 'password-changed':
396
+ subject = '[[global_site_title]] Notice of Password Change';
397
+ body = 'Hi [email_user_login], <br>' +
398
+ '<br>' +
399
+ 'This notice confirms that your password was changed on [global_site_title].' +
400
+ '<br><br>' +
401
+ 'If you did not change your password, please contact the Site Administrator at [admin_email] <br>' +
402
+ '<br>' +
403
+ 'This email has been sent to [global_user_email]' +
404
+ '<br>' +
405
+ 'Regards, <br>' +
406
+ 'All at [global_site_title] <br>' +
407
+ '[global_site_url]';
408
+ break;
409
+
410
+ case 'email-changing':
411
+ subject = '[[global_site_title]] New Email Address';
412
+ body = 'Hi [user_nicename], <br>' +
413
+ '<br>' +
414
+ 'You recently requested to have the email address on your account changed.' +
415
+ '<br>' +
416
+ 'If this is correct, please click on the following link to change it:' +
417
+ '<br>' +
418
+ '[global_site_url]/wp-admin/profile.php' +
419
+ '<br>' +
420
+ 'You can safely ignore and delete this email if you do not want to take this action.' +
421
+ '<br>' +
422
+ 'This email has been sent to [global_user_email]' +
423
+ '<br>' +
424
+ 'Regards, <br>' +
425
+ 'All at [global_site_title] <br>' +
426
+ '[global_site_url]';
427
+ break;
428
+
429
+ case 'email-changed':
430
+ subject = '[[global_site_title]] Notice of Email Change';
431
+ body = 'Hi [user_nicename], <br>' +
432
+ '<br>' +
433
+ 'This notice confirms that your email address on [global_site_title] was changed to [user_email].' +
434
+ '<br>' +
435
+ 'If you did not change your email, please contact the Site Administrator at [admin_email] <br>' +
436
+ '<br>' +
437
+ 'This email has been sent to [global_user_email]' +
438
+ '<br>' +
439
+ 'Regards, <br>' +
440
+ 'All at [global_site_title] <br>' +
441
+ '[global_site_url]';
442
+ break;
443
+
444
+ case 'new-user':
445
+ subject = '[[global_site_title]] Your username and password info';
446
+ body = 'Username: [user_login] <br>' +
447
+ 'To set your password, visit the following address: [password_url]';
448
+
449
+ break;
450
+
451
+ case 'multisite-new-user-invited':
452
+ subject = '[[network_name] Activate [user_login]';
453
+ body = 'To activate your user, please click the following link:' +
454
+ '<br>' +
455
+ '[activation_link]' +
456
+ '<br>' +
457
+ 'After you activate, you will receive *another email* with your login.';
458
+
459
+ break;
460
+
461
+ case 'ca-export-data':
462
+ subject = '[[global_site_title]] Confirm Action: Export Personal Data';
463
+ body = 'Howdy,' +
464
+ '<br>' +
465
+ '<br>' +
466
+ 'A request has been made to perform the following action on your account:' +
467
+ '<br>' +
468
+ '<br>' +
469
+ '[data_request_type]' +
470
+ '<br>' +
471
+ '<br>' +
472
+ 'To confirm this, please click on the following link:' +
473
+ '<br>' +
474
+ '<br>' +
475
+ '[request_confirmation_link]' +
476
+ '<br>' +
477
+ '<br>' +
478
+ 'You can safely ignore and delete this email if you do not want to' +
479
+ '<br>' +
480
+ 'take this action.' +
481
+ '<br>' +
482
+ '<br>' +
483
+ 'This email has been sent to [global_user_email].' +
484
+ '<br>' +
485
+ '<br>' +
486
+ 'Regards,' +
487
+ '<br>' +
488
+ 'All at [global_site_title]' +
489
+ '<br>' +
490
+ '[global_site_url]';
491
+
492
+ break;
493
+
494
+ case 'ca-erase-data':
495
+ subject = '[[global_site_title]] Confirm Action: Erase Personal Data';
496
+ body = 'Howdy,' +
497
+ '<br>' +
498
+ '<br>' +
499
+ 'A request has been made to perform the following action on your account:' +
500
+ '<br>' +
501
+ '<br>' +
502
+ '[data_request_type]' +
503
+ '<br>' +
504
+ '<br>' +
505
+ 'To confirm this, please click on the following link:' +
506
+ '<br>' +
507
+ '<br>' +
508
+ '[request_confirmation_link]' +
509
+ '<br>' +
510
+ '<br>' +
511
+ 'You can safely ignore and delete this email if you do not want to' +
512
+ '<br>' +
513
+ 'take this action.' +
514
+ '<br>' +
515
+ '<br>' +
516
+ 'This email has been sent to [global_user_email].' +
517
+ '<br>' +
518
+ '<br>' +
519
+ 'Regards,' +
520
+ '<br>' +
521
+ 'All at [global_site_title]' +
522
+ '<br>' +
523
+ '[global_site_url]';
524
+
525
+ break;
526
+
527
+ case 'uc-export-data':
528
+ subject = 'Action Confirmed';
529
+
530
+ body = 'Howdy,' +
531
+ '<br>' +
532
+ '<br>' +
533
+ 'A user data privacy request has been confirmed on [global_site_title]:' +
534
+ '<br>' +
535
+ '<br>' +
536
+ 'User: [email_user_email]' +
537
+ '<br>' +
538
+ 'Request: [data_request_type]' +
539
+ '<br>' +
540
+ '<br>' +
541
+ 'You can view and manage these data privacy requests here:' +
542
+ '<br>' +
543
+ '<br>' +
544
+ '[data_privacy_requests_url]' +
545
+ '<br>' +
546
+ '<br>' +
547
+ 'Regards,' +
548
+ '<br>' +
549
+ 'All at [global_site_title]' +
550
+ '<br>' +
551
+ '[global_site_url]';
552
+ break;
553
+
554
+ case 'uc-erase-data':
555
+ subject = 'Action Confirmed';
556
+
557
+ body = 'Howdy,' +
558
+ '<br>' +
559
+ '<br>' +
560
+ 'A user data privacy request has been confirmed on [global_site_title]:' +
561
+ '<br>' +
562
+ '<br>' +
563
+ 'User: [email_user_email]' +
564
+ '<br>' +
565
+ 'Request: [data_request_type]' +
566
+ '<br>' +
567
+ '<br>' +
568
+ 'You can view and manage these data privacy requests here:' +
569
+ '<br>' +
570
+ '<br>' +
571
+ '[data_privacy_requests_url]' +
572
+ '<br>' +
573
+ '<br>' +
574
+ 'Regards,' +
575
+ '<br>' +
576
+ 'All at [global_site_title]' +
577
+ '<br>' +
578
+ '[global_site_title]';
579
+ break;
580
+
581
+ case 'data-export':
582
+ subject = 'Personal Data Export';
583
+
584
+ body = 'Howdy,' +
585
+ '<br>' +
586
+ '<br>' +
587
+ 'Your request for an export of personal data has been completed. You may' +
588
+ '<br>' +
589
+ 'download your personal data by clicking on the link below. For privacy' +
590
+ '<br>' +
591
+ 'and security, we will automatically delete the file on [data_privacy_download_expiry],' +
592
+ '<br>' +
593
+ 'so please download it before then.' +
594
+ '<br>' +
595
+ '<br>' +
596
+ '[data_privacy_download_url]' +
597
+ '<br>' +
598
+ '<br>' +
599
+ 'This email has been sent to [global_user_email].' +
600
+ '<br>' +
601
+ '<br>' +
602
+ 'Regards,' +
603
+ '<br>' +
604
+ 'All at [global_site_title]' +
605
+ '<br>' +
606
+ '[global_site_url]';
607
+ break;
608
+
609
+ case 'data-erased':
610
+ subject = '[sitename] Erasure Request Fulfilled';
611
+
612
+ body = 'Howdy,' +
613
+ '<br>' +
614
+ '<br>' +
615
+ 'Your request to erase your personal data on [sitename] has been completed.' +
616
+ '<br>' +
617
+ 'If you have any follow-up questions or concerns, please contact the site administrator.' +
618
+ '<br>' +
619
+ '<br>' +
620
+ 'Regards,' +
621
+ '<br>' +
622
+ 'All at [global_site_title]' +
623
+ '<br>' +
624
+ '[global_site_url]';
625
+ break;
626
+ default:
627
+ alert( "This is a new notification that is not available in WordPress by default and has been added by Better Notifications for WP. As such, it doesn't have any default content." );
628
+ break;
629
+ }
630
+
631
+ if ( subject !== '' ) {
632
+ $( '#subject' ).val( subject );
633
+ }
634
+
635
+ if ( body !== '' ) {
636
+ if ( tinyMCE && tinyMCE.editors && tinyMCE.editors['notification_message'] ) {
637
+ tinyMCE.editors['notification_message'].selection.setContent( body );
638
+ }
639
+ }
640
+
641
+ return false;
642
+ } );
643
+ });
bnfw.php CHANGED
@@ -1,1519 +1,1519 @@
1
- <?php
2
-
3
- /**
4
- * Plugin Name: Better Notifications for WP
5
- * Plugin URI: https://wordpress.org/plugins/bnfw/
6
- * Description: Supercharge your WordPress notifications using a WYSIWYG editor and shortcodes. Default and new notifications available. Add more power with Add-ons.
7
- * Version: 1.8.6
8
- * Requires at least: 4.8
9
- * Requires PHP: 5.6
10
- * Author: Made with Fuel
11
- * Author URI: https://madewithfuel.com/
12
- * License: GPLv2 or later
13
- * License URI: http://www.gnu.org/licenses/gpl-2.0.html
14
- * Text Domain: bnfw
15
- * Domain Path: /languages
16
- */
17
-
18
- /**
19
- * Copyright © 2021 Made with Fuel Ltd. (hello@betternotificationsforwp.com)
20
- * This program is free software; you can redistribute it and/or modify
21
- * it under the terms of the GNU General Public License, version 2, as
22
- * published by the Free Software Foundation.
23
- * This program is distributed in the hope that it will be useful,
24
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
- * GNU General Public License for more details.
27
- * You should have received a copy of the GNU General Public License
28
- * along with this program; if not, write to the Free Software
29
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
- */
31
- class BNFW {
32
-
33
- /**
34
- * Constructor.
35
- *
36
- * @since 1.0
37
- */
38
- function __construct() {
39
- $this->load_textdomain();
40
- $this->includes();
41
- $this->hooks();
42
-
43
- /**
44
- * BNFW Notification.
45
- *
46
- * @var \BNFW_Notification
47
- */
48
- $this->notifier = new BNFW_Notification;
49
-
50
- /**
51
- * BNFW Engine.
52
- *
53
- * @var \BNFW_Engine
54
- */
55
- $this->engine = new BNFW_Engine;
56
- }
57
-
58
- /**
59
- * Factory method to return the instance of the class.
60
- *
61
- * Makes sure that only one instance is created.
62
- *
63
- * @return \BNFW Instance of the class.
64
- */
65
- public static function factory() {
66
- static $instance = false;
67
- if ( ! $instance ) {
68
- $instance = new self();
69
- }
70
- return $instance;
71
- }
72
-
73
- /**
74
- * Loads the plugin language files
75
- *
76
- * @since 1.0
77
- */
78
- public function load_textdomain() {
79
- // Load localization domain
80
- $this->translations = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
81
- load_plugin_textdomain( 'bnfw', false, $this->translations );
82
- }
83
-
84
- /**
85
- * Include required files.
86
- *
87
- * @since 1.0
88
- */
89
- public function includes() {
90
-
91
- // Load license related classes
92
- if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
93
- require_once 'includes/libraries/EDD_SL_Plugin_Updater.php';
94
- }
95
-
96
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
97
-
98
- require_once 'vendor/persist-admin-notices-dismissal/persist-admin-notices-dismissal.php';
99
-
100
- require_once 'includes/license/class-bnfw-license.php';
101
- require_once 'includes/license/class-bnfw-license-setting.php';
102
-
103
- // Load Engine
104
- require_once 'includes/engine/class-bnfw-engine.php';
105
- require_once 'includes/overrides.php';
106
-
107
- // Load notification post type and notification helpers
108
- require_once 'includes/admin/class-bnfw-notification.php';
109
- require_once 'includes/notification/post-notification.php';
110
-
111
- // Helpers
112
- require_once 'includes/helpers/helpers.php';
113
- require_once 'includes/helpers/ajax-helpers.php';
114
-
115
- // Load Admin Pages
116
- if ( is_admin() ) {
117
- require_once 'includes/admin/bnfw-settings.php';
118
- }
119
- }
120
-
121
- /**
122
- * Register Hooks.
123
- *
124
- * @since 1.0
125
- */
126
- public function hooks() {
127
- global $wp_version;
128
-
129
- register_activation_hook( __FILE__, array( $this, 'activate' ) );
130
-
131
- add_action( 'admin_init', array( 'PAnD', 'init' ) );
132
- add_action( 'admin_init', array( $this, 'add_capability_to_admin' ) );
133
-
134
- add_action( 'draft_to_private', array( $this, 'private_post' ) );
135
- add_action( 'future_to_private', array( $this, 'private_post' ) );
136
- add_action( 'pending_to_private', array( $this, 'private_post' ) );
137
- add_action( 'publish_to_private', array( $this, 'private_post' ) );
138
-
139
- add_action( 'wp_insert_post', array( $this, 'insert_post' ), 10, 3 );
140
-
141
- add_action( 'publish_to_trash', array( $this, 'trash_post' ) );
142
-
143
- add_action( 'auto-draft_to_publish', array( $this, 'publish_post' ) );
144
- add_action( 'draft_to_publish', array( $this, 'publish_post' ) );
145
- add_action( 'future_to_publish', array( $this, 'publish_post' ) );
146
- add_action( 'pending_to_publish', array( $this, 'publish_post' ) );
147
- add_action( 'private_to_publish', array( $this, 'publish_post' ) );
148
- // add_action( 'acf/submit_form' , array( $this, 'acf_submit_form' ), 10, 2 );
149
-
150
- add_action( 'publish_to_publish', array( $this, 'update_post' ) );
151
- add_action( 'private_to_private', array( $this, 'update_post' ) );
152
-
153
- add_action( 'add_attachment', array( $this, 'new_publish_media_notification' ), 10, 1 );
154
- add_action( 'edit_attachment', array( $this, 'media_attachment_data_update_notification' ), 10 );
155
-
156
- add_action( 'transition_post_status', array( $this, 'on_post_transition' ), 10, 3 );
157
-
158
- add_action( 'init', array( $this, 'custom_post_type_hooks' ), 100 );
159
- add_action( 'create_term', array( $this, 'create_term' ), 10, 3 );
160
-
161
- add_action( 'transition_comment_status', array( $this, 'on_comment_status_change' ), 10, 3 );
162
- add_action( 'comment_post', array( $this, 'comment_post' ) );
163
- add_action( 'trackback_post', array( $this, 'trackback_post' ) );
164
- add_action( 'pingback_post', array( $this, 'pingback_post' ) );
165
-
166
- add_action( 'user_register', array( $this, 'user_register' ) );
167
-
168
- add_action( 'user_register', array( $this, 'welcome_email' ) );
169
-
170
- if ( is_plugin_active( 'members/members.php' ) ) {
171
-
172
- add_action('add_user_role', array($this,'user_role_added_from_member_plugin'), 10, 2);
173
- add_action('remove_user_role', array($this,'user_role_removed_from_member_plugin'), 10, 2);
174
- add_action('set_user_role', array( $this, 'user_role_changed' ), 10, 3 );
175
-
176
- add_action( 'profile_update', array( $this, 'user_role_added' ), 10, 2 );
177
- } else {
178
- add_action( 'set_user_role', array( $this, 'user_role_changed' ), 10, 3 );
179
- }
180
-
181
-
182
-
183
- add_action( 'wp_login', array( $this, 'user_login' ), 10, 2 );
184
-
185
- if ( version_compare( $wp_version, '4.4', '>=' ) ) {
186
- add_filter( 'retrieve_password_title', array( $this, 'change_password_email_title' ), 10, 3 );
187
- } else {
188
- add_filter( 'retrieve_password_title', array( $this, 'change_password_email_title' ) );
189
- }
190
- add_action( 'lostpassword_post', array( $this, 'on_lost_password' ) );
191
- add_filter( 'retrieve_password_message', array( $this, 'change_password_email_message' ), 10, 4 );
192
-
193
- add_action( 'after_password_reset', array( $this, 'on_password_reset' ) );
194
-
195
- add_filter( 'send_password_change_email', array( $this, 'should_password_changed_email_be_sent' ), 10, 3 );
196
- add_filter( 'password_change_email', array( $this, 'on_password_changed' ), 10, 2 );
197
-
198
- add_filter( 'send_email_change_email', array( $this, 'should_email_changed_email_be_sent' ), 10, 3 );
199
- add_filter( 'email_change_email', array( $this, 'on_email_changed' ), 10, 3 );
200
- add_filter( 'new_user_email_content', array( $this, 'on_email_changing' ), 10, 2 );
201
-
202
- add_filter( 'auto_core_update_email', array( $this, 'on_core_updated' ), 10, 4 );
203
-
204
- add_filter( 'user_request_action_email_content', array( $this, 'handle_user_request_email_content' ), 10, 2 );
205
- add_filter( 'user_request_action_email_subject', array( $this, 'handle_user_request_email_subject' ), 10, 3 );
206
-
207
- add_filter( 'user_confirmed_action_email_content', array( $this, 'handle_user_confirmed_action_email_content' ), 10, 2 );
208
-
209
- add_filter( 'wp_privacy_personal_data_email_content', array( $this, 'handle_data_export_email_content' ), 10, 3 );
210
-
211
- add_filter( 'user_erasure_complete_email_subject', array( $this, 'handle_erasure_complete_email_subject' ), 10, 3 );
212
- add_filter( 'user_confirmed_action_email_content', array( $this, 'handle_erasure_complete_email_content' ), 10, 2 );
213
-
214
- add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 4 );
215
- add_action( 'shutdown', array( $this, 'on_shutdown' ) );
216
- }
217
-
218
- /**
219
- * Add 'bnfw' capability to admin.
220
- */
221
- public function add_capability_to_admin() {
222
- $admins = get_role( 'administrator' );
223
-
224
- if ( is_null( $admins ) ) {
225
- return;
226
- }
227
-
228
- if ( ! $admins->has_cap( 'bnfw' ) ) {
229
- $admins->add_cap( 'bnfw' );
230
- }
231
- }
232
-
233
- /**
234
- * On post transition.
235
- *
236
- * @param string $new_status New post status.
237
- * @param string $old_status Old post status.
238
- * @param \WP_Post $post Post object.
239
- */
240
- public function on_post_transition( $new_status, $old_status, $post ) {
241
- if ( ! is_a( $post, 'WP_Post' ) ) {
242
- return;
243
- }
244
-
245
- if ( 'pending' === $old_status ) {
246
- return;
247
- }
248
-
249
- if ( 'pending' !== $new_status ) {
250
- return;
251
- }
252
-
253
- $this->on_post_pending( $post->ID, $post );
254
- }
255
-
256
- /**
257
- * Setup hooks for custom post types.
258
- *
259
- * @since 1.2
260
- */
261
- function custom_post_type_hooks() {
262
- $post_types = get_post_types( array( 'public' => true ), 'names' );
263
- $post_types = array_diff( $post_types, array( BNFW_Notification::POST_TYPE ) );
264
-
265
- foreach ( $post_types as $post_type ) {
266
- add_action( 'future_' . $post_type, array( $this, 'on_post_scheduled' ), 10, 2 );
267
- }
268
- }
269
-
270
- /**
271
- * importer
272
- */
273
- public function activate() {
274
- require_once dirname( __FILE__ ) . '/includes/import.php';
275
- $importer = new BNFW_Import;
276
- $importer->import();
277
- }
278
-
279
- /**
280
- * Add 'Settings' link below BNFW in Plugins list.
281
- *
282
- * @since 1.0
283
- * @param unknown $links
284
- * @param unknown $file
285
- * @return unknown
286
- */
287
- public function plugin_action_links( $links, $file ) {
288
- $plugin_file = 'bnfw/bnfw.php';
289
- if ( $file == $plugin_file ) {
290
- $settings_link = '<a href="' . esc_url( admin_url( 'edit.php?post_type=bnfw_notification&page=bnfw-settings' ) ) . '">' . esc_html__( 'Settings', 'bnfw' ) . '</a>';
291
- array_unshift( $links, $settings_link );
292
- }
293
- return $links;
294
- }
295
-
296
- /**
297
- * When a new term is created.
298
- *
299
- * @since 1.0
300
- * @param int $term_id
301
- * @param int $tt_id
302
- * @param string $taxonomy
303
- */
304
- public function create_term( $term_id, $tt_id, $taxonomy ) {
305
- $this->send_notification( 'newterm-' . $taxonomy, $term_id );
306
- }
307
-
308
- /**
309
- * Fires when a post is created for the first time.
310
- *
311
- * @param int $post_id Post ID
312
- * @param object $post Post object
313
- * @param bool $update Whether this is an existing post being updated or not.
314
- *
315
- * @since 1.3.1
316
- */
317
- public function insert_post( $post_id, $post, $update ) {
318
- // Some themes like P2, directly insert posts into DB.
319
- $insert_post_themes = apply_filters( 'bnfw_insert_post_themes', array( 'P2', 'Syncope' ) );
320
- $current_theme = wp_get_theme();
321
-
322
- /**
323
- * Whether to trigger insert post hook.
324
- *
325
- * @since 1.4
326
- */
327
- $trigger_insert_post = apply_filters( 'bnfw_trigger_insert_post', false, $post_id, $update );
328
-
329
- if ( in_array( $current_theme->get( 'Name' ), $insert_post_themes ) || $trigger_insert_post ) {
330
- $this->handle_inserted_post( $post_id, $update );
331
- }
332
- }
333
-
334
- /**
335
- * Trigger New Post published notification for ACF forms.
336
- *
337
- * @param string $form ACF Form.
338
- * @param int $post_id Post ID.
339
- */
340
- public function acf_submit_form( $form, $post_id ) {
341
- $this->handle_inserted_post( $post_id );
342
- }
343
-
344
- /**
345
- * Trigger correct notifications for inserted posts.
346
- *
347
- * @param int $post_id Post id.
348
- * @param bool $update Whether the post was updated.
349
- *
350
- * @since 1.6.7
351
- */
352
- private function handle_inserted_post( $post_id, $update ) {
353
- $post = get_post( $post_id );
354
-
355
- if ( ! is_a( $post, 'WP_Post' ) ) {
356
- return;
357
- }
358
-
359
- switch ( $post->post_status ) {
360
- case 'publish':
361
- if ( $update ) {
362
- $this->update_post( $post );
363
- } else {
364
- $this->publish_post( $post );
365
- }
366
- break;
367
-
368
- case 'private':
369
- $this->private_post( $post );
370
- break;
371
-
372
- case 'pending':
373
- $this->on_post_pending( $post_id, $post );
374
- break;
375
-
376
- case 'future':
377
- $this->on_post_scheduled( $post_id, $post );
378
- break;
379
- }
380
- }
381
-
382
- /**
383
- * Fires when a post is created for the first time.
384
- *
385
- * @since 1.0
386
- * @param object $post Post Object
387
- */
388
- function publish_post( $post ) {
389
- $post_id = $post->ID;
390
- $post_type = $post->post_type;
391
-
392
- if ( BNFW_Notification::POST_TYPE != $post_type ) {
393
- $this->send_notification_async( 'new-' . $post_type, $post_id );
394
- }
395
- }
396
-
397
- /**
398
- * Fires when a private post is created.
399
- *
400
- * @since 1.6
401
- * @param object $post Post Object
402
- */
403
- public function private_post( $post ) {
404
- $post_id = $post->ID;
405
- $post_type = $post->post_type;
406
-
407
- if ( BNFW_Notification::POST_TYPE != $post_type ) {
408
- $this->send_notification_async( 'private-' . $post_type, $post_id );
409
- }
410
- }
411
-
412
- /**
413
- * Fires when a post is updated.
414
- *
415
- * @since 1.0
416
- * @param unknown $post
417
- */
418
- public function update_post( $post ) {
419
- if ( $this->is_metabox_request() ) {
420
- return;
421
- }
422
-
423
- $post_id = $post->ID;
424
- $post_type = $post->post_type;
425
-
426
- if ( BNFW_Notification::POST_TYPE != $post_type ) {
427
- $this->send_notification_async( 'update-' . $post_type, $post_id );
428
- }
429
- }
430
-
431
- /**
432
- * Fires when a post is moved publish to trash.
433
- *
434
- */
435
- public function trash_post( $post ) {
436
- if ( $this->is_metabox_request() ) {
437
- return;
438
- }
439
- $post_id = $post->ID;
440
- $post_type = $post->post_type;
441
-
442
- if ( BNFW_Notification::POST_TYPE != $post_type ) {
443
- $this->send_notification_async( 'trash-' . $post_type, $post_id );
444
- }
445
- }
446
-
447
- /**
448
- * Fires when a post is pending for review.
449
- *
450
- * @since 1.1
451
- * @param int $post_id Post ID
452
- * @param object $post Post object
453
- */
454
- public function on_post_pending( $post_id, $post ) {
455
- if ( $this->is_metabox_request() ) {
456
- return;
457
- }
458
-
459
- $post_type = $post->post_type;
460
-
461
- if ( BNFW_Notification::POST_TYPE != $post_type ) {
462
- $this->send_notification_async( 'pending-' . $post_type, $post_id );
463
- }
464
- }
465
-
466
- /**
467
- * On Media Published.
468
- *
469
- * @param int $post_id Attachment post id.
470
- */
471
- public function new_publish_media_notification( $post_id ) {
472
- $post_type = get_post_type( $post_id );
473
-
474
- if ( BNFW_Notification::POST_TYPE != $post_type && $post_type == 'attachment' ) {
475
- $this->send_notification_async( 'new-media', $post_id );
476
- }
477
- }
478
-
479
- /**
480
- * On Media Attachment Data Update.
481
- *
482
- * @param int $post_id Attachment post id.
483
- */
484
- public function media_attachment_data_update_notification( $post_id ) {
485
- $post_type = get_post_type( $post_id );
486
- if ( BNFW_Notification::POST_TYPE != $post_type && $post_type == 'attachment' ) {
487
- $this->send_notification_async( 'update-media', $post_id );
488
- }
489
- }
490
-
491
- /**
492
- * Fires when a post is scheduled.
493
- *
494
- * @since 1.1.5
495
- * @param int $post_id Post ID
496
- * @param object $post Post object
497
- */
498
- function on_post_scheduled( $post_id, $post ) {
499
- // Rest request also triggers the same hook. We can ignore it.
500
- if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
501
- return;
502
- }
503
-
504
- $post_type = $post->post_type;
505
-
506
- if ( BNFW_Notification::POST_TYPE != $post_type ) {
507
- $this->send_notification_async( 'future-' . $post_type, $post_id );
508
- }
509
- }
510
-
511
- /**
512
- * When the status of a comment is changed.
513
- *
514
- * @param string $new_status New status.
515
- * @param string $old_status Old status.
516
- * @param \WP_Comment $comment Comment.
517
- */
518
- public function on_comment_status_change( $new_status, $old_status, $comment ) {
519
- if ( 'approved' !== $new_status ) {
520
- return;
521
- }
522
-
523
- $post = get_post( $comment->comment_post_ID );
524
-
525
- $notification_type = 'approve-' . $post->post_type . '-comment';
526
-
527
- $this->send_notification( $notification_type, $comment->comment_ID, false );
528
-
529
- // Send new comment notification after comment approve
530
- $notification_type = 'new-comment'; // old notification name
531
-
532
- if ( 'post' != $post->post_type ) {
533
- $notification_type = 'comment-' . $post->post_type;
534
- }
535
-
536
- $this->send_notification( $notification_type, $comment->comment_ID );
537
-
538
- // Send comment reply notification after comment approve.
539
- $this->commentsReply( $comment->comment_ID );
540
- }
541
-
542
- /**
543
- * Send notification for new comments
544
- *
545
- * @since 1.0
546
- * @param int $comment_id
547
- */
548
- public function comment_post( $comment_id ) {
549
- $the_comment = get_comment( $comment_id );
550
- $post = get_post( $the_comment->comment_post_ID );
551
-
552
- if ( '1' !== $the_comment->comment_approved ) {
553
- if ( $this->can_send_comment_notification( $the_comment ) ) {
554
- $notification_type = 'moderate-' . $post->post_type . '-comment';
555
- $this->send_notification( $notification_type, $comment_id );
556
- }
557
- } else {
558
- $notification_type = 'new-comment'; // old notification name
559
-
560
- if ( 'post' != $post->post_type ) {
561
- $notification_type = 'comment-' . $post->post_type;
562
- }
563
-
564
- $this->send_notification( $notification_type, $comment_id );
565
-
566
- // comment reply notification.
567
- $this->commentsReply( $comment_id );
568
- }
569
- }
570
-
571
- /**
572
- * Send notification for comments reply
573
- *
574
- * @since 1.0
575
- * @param int $comment_id
576
- */
577
- public function commentsReply( $comment_id ) {
578
- $the_comment = get_comment( $comment_id );
579
- $post = get_post( $the_comment->comment_post_ID );
580
-
581
- // comment reply notification.
582
- if ( $this->can_send_comment_notification( $the_comment ) ) {
583
- if ( $the_comment->comment_parent > 0 ) {
584
- $notification_type = 'reply-comment'; // old notification name
585
- if ( 'post' != $post->post_type ) {
586
- $notification_type = 'commentreply-' . $post->post_type;
587
- }
588
- $notifications = $this->notifier->get_notifications( $notification_type );
589
- if ( count( $notifications ) > 0 ) {
590
- $parent = get_comment( $the_comment->comment_parent );
591
- if ( $parent->comment_author_email != $the_comment->comment_author_email ) {
592
- foreach ( $notifications as $notification ) {
593
- $this->engine->send_comment_reply_email( $this->notifier->read_settings( $notification->ID ), $the_comment, $parent );
594
- }
595
- }
596
- }
597
- }
598
- }
599
- }
600
-
601
- /**
602
- * Send notification for new trackback
603
- *
604
- * @since 1.0
605
- * @param unknown $comment_id
606
- */
607
- function trackback_post( $comment_id ) {
608
- $the_comment = get_comment( $comment_id );
609
- if ( $this->can_send_comment_notification( $the_comment ) ) {
610
- $this->send_notification( 'new-trackback', $comment_id );
611
- }
612
- }
613
-
614
- /**
615
- * Send notification for new pingbacks
616
- *
617
- * @since 1.0
618
- * @param unknown $comment_id
619
- */
620
- function pingback_post( $comment_id ) {
621
- $the_comment = get_comment( $comment_id );
622
- if ( $this->can_send_comment_notification( $the_comment ) ) {
623
- $this->send_notification( 'new-pingback', $comment_id );
624
- }
625
- }
626
-
627
- /**
628
- * Send notification for lost password.
629
- *
630
- * @since 1.0
631
- */
632
- function on_lost_password() {
633
- $user_login = sanitize_text_field( $_POST[ 'user_login' ] );
634
- $user = get_user_by( 'login', $user_login ) ?: get_user_by( 'email', $user_login );
635
- if ( $user ) {
636
- $this->send_notification( 'admin-password', $user->ID );
637
- }
638
- }
639
-
640
- /**
641
- * Change the title of the password reset email that is sent to the user.
642
- *
643
- * @since 1.1
644
- *
645
- * @param string $title
646
- * @param string $user_login
647
- * @param string $user_data
648
- *
649
- * @return string
650
- */
651
- public function change_password_email_title( $title, $user_login = '',
652
- $user_data = '' ) {
653
- $notifications = $this->notifier->get_notifications( 'user-password' );
654
- if ( count( $notifications ) > 0 ) {
655
- // Ideally there should be only one notification for this type.
656
- // If there are multiple notification then we will read data about only the last one
657
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
658
-
659
- if ( '' === $user_data ) {
660
- return $this->engine->handle_shortcodes( $setting[ 'subject' ], 'user-password', $user_data->ID );
661
- } else {
662
- return $this->engine->handle_shortcodes( $setting[ 'subject' ], 'user-password', $user_data->ID );
663
- }
664
- }
665
-
666
- return $title;
667
- }
668
-
669
- /**
670
- * Change the message of the password reset email.
671
- *
672
- * @since 1.1
673
- *
674
- * @param string $message
675
- * @param string $key
676
- * @param string $user_login
677
- * @param string $user_data
678
- *
679
- * @return string
680
- */
681
- public function change_password_email_message( $message, $key,
682
- $user_login = '',
683
- $user_data = '' ) {
684
- $notifications = $this->notifier->get_notifications( 'user-password' );
685
- if ( count( $notifications ) > 0 ) {
686
- // Ideally there should be only one notification for this type.
687
- // If there are multiple notification then we will read data about only the last one
688
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
689
-
690
- $message = $this->engine->handle_password_reset_shortcodes( $setting, $key, $user_login, $user_data );
691
-
692
- if ( 'html' == $setting[ 'email-formatting' ] ) {
693
- add_filter( 'wp_mail_content_type', array( $this, 'set_html_content_type' ) );
694
- if ( 'true' !== $setting[ 'disable-autop' ] ) {
695
- $message = wpautop( $message );
696
- }
697
- } else {
698
- add_filter( 'wp_mail_content_type', array( $this, 'set_text_content_type' ) );
699
- if ( 'text' == $setting[ 'email-formatting' ] ) {
700
- $message = strip_tags( $message );
701
- }
702
- }
703
- } else {
704
- if ( $this->notifier->notification_exists( 'user-password', false ) ) {
705
- // disabled notification exists, so disable the email by returning empty string.
706
- return '';
707
- }
708
- }
709
-
710
- return $message;
711
- }
712
-
713
- /**
714
- * On Password reset.
715
- *
716
- * @param WP_User $user User who's password was changed.
717
- */
718
- public function on_password_reset( $user ) {
719
- $notifications = $this->notifier->get_notifications( 'password-changed' );
720
- foreach ( $notifications as $notification ) {
721
- $this->engine->send_password_changed_email( $this->notifier->read_settings( $notification->ID ), $user );
722
- }
723
- }
724
-
725
- /**
726
- * Should the password changed email be sent?
727
- *
728
- * @param $send
729
- * @param $user
730
- * @param $userdata
731
- *
732
- * @return bool
733
- */
734
- public function should_password_changed_email_be_sent( $send, $user,
735
- $userdata ) {
736
- $bnfw = BNFW::factory();
737
-
738
- if ( ! $send ) {
739
- return $send;
740
- }
741
-
742
- return ! $bnfw->notifier->is_notification_disabled( 'password-changed' );
743
- }
744
-
745
- /**
746
- * On Password Changed.
747
- *
748
- * @since 1.6
749
- *
750
- * @param array $email_data Email Data.
751
- * @param array $user User data.
752
- *
753
- * @return array Modified Email Data
754
- */
755
- public function on_password_changed( $email_data, $user ) {
756
- return $this->handle_filtered_data_notification( 'password-changed', $email_data, $user[ 'ID' ] );
757
- }
758
-
759
- /**
760
- * Should the email changed email be sent?
761
- *
762
- * @param $send
763
- * @param $user
764
- * @param $userdata
765
- *
766
- * @return bool
767
- */
768
- public function should_email_changed_email_be_sent( $send, $user_old_data,
769
- $user_new_data ) {
770
- $bnfw = BNFW::factory();
771
-
772
- if ( $bnfw->notifier->notification_exists( 'admin-email-changed', false ) ) {
773
- $notifications = $bnfw->notifier->get_notifications( 'admin-email-changed' );
774
-
775
- if ( count( $notifications ) > 0 ) {
776
- // Ideally there should be only one notification for this type.
777
- // If there are multiple notification then we will read data about only the last one
778
- $setting = $bnfw->notifier->read_settings( end( $notifications )->ID );
779
- $notification_disabled = apply_filters( 'bnfw_notification_disabled', ( 'true' === $setting[ 'disabled' ] ), $id, $setting );
780
-
781
- if ( ! $notification_disabled ) {
782
-
783
- $setting[ 'message' ] = str_replace( '[user_old_email]', $user_old_data[ 'user_email' ], $setting[ 'message' ] );
784
- $setting[ 'message' ] = str_replace( '[user_new_email]', $user_new_data[ 'user_email' ], $setting[ 'message' ] );
785
- $bnfw->engine->send_notification( $setting, $user_old_data[ 'ID' ] );
786
- }
787
- }
788
- }
789
-
790
- if ( ! $send ) {
791
- return $send;
792
- }
793
-
794
- return ! $bnfw->notifier->is_notification_disabled( 'email-changed' );
795
- }
796
-
797
- /**
798
- * On Email Changed.
799
- *
800
- * @since 1.6
801
- *
802
- * @param array $email_data Email Data.
803
- * @param array $user User data.
804
- *
805
- * @return array Modified Email Data
806
- */
807
- public function on_email_changed( $email_data, $user_old_data,
808
- $user_new_data ) {
809
-
810
- $email = $this->handle_filtered_data_notification( 'email-changed', $email_data, $user_old_data[ 'ID' ] );
811
- $email[ 'message' ] = str_replace( '[user_old_email]', $user_old_data[ 'user_email' ], $email[ 'message' ] );
812
- $email[ 'message' ] = str_replace( '[user_new_email]', $user_new_data[ 'user_email' ], $email[ 'message' ] );
813
- return $email;
814
- }
815
-
816
- public function on_email_changing( $email_text, $new_user_details ) {
817
- $notification_name = 'email-changing';
818
-
819
- $notifications = $this->notifier->get_notifications( $notification_name );
820
- if ( count( $notifications ) > 0 ) {
821
- // Ideally there should be only one notification for this type.
822
- // If there are multiple notification then we will read data about only the last one
823
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
824
-
825
- $email_text = $this->engine->handle_shortcodes( $setting[ 'message' ], $setting[ 'notification' ], $new_user_details[ 'newemail' ] );
826
- $email_text = $this->engine->handle_global_user_shortcodes( $email_text, $new_user_details[ 'newemail' ] );
827
- $email_text = str_replace( '[email_change_confirmation_link]', esc_url( admin_url( 'profile.php?newuseremail=' . $new_user_details[ 'hash' ] ) ), $email_text );
828
- }
829
-
830
- return $email_text;
831
- }
832
-
833
- /**
834
- * Send notification on core updated event.
835
- *
836
- * @since 1.6
837
- *
838
- * @param array $email_data Email Data.
839
- * @param string $type The type of email being sent. Can be one of
840
- * 'success', 'fail', 'manual', 'critical'.
841
- * @param object $core_update The update offer that was attempted.
842
- * @param mixed $result The result for the core update. Can be WP_Error.
843
- *
844
- * @return array Modified Email Data.
845
- */
846
- public function on_core_updated( $email_data, $type, $core_update, $result ) {
847
- $notifications = $this->notifier->get_notifications( 'core-updated' );
848
- if ( count( $notifications ) > 0 ) {
849
- // Ideally there should be only one notification for this type.
850
- // If there are multiple notification then we will read data about only the last one
851
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
852
-
853
- $email_data = $this->engine->handle_core_updated_notification( $email_data, $setting, $type );
854
- }
855
-
856
- return $email_data;
857
- }
858
-
859
- /**
860
- * Process User update notifications.
861
- *
862
- * @since 1.6
863
- *
864
- * @param string $notification_name Notification Name.
865
- * @param array $email_data Email Data.
866
- * @param string|int $extra_data User Id.
867
- *
868
- * @return array Modified Email Data.
869
- */
870
- private function handle_filtered_data_notification( $notification_name,
871
- $email_data, $extra_data ) {
872
- $notifications = $this->notifier->get_notifications( $notification_name );
873
- if ( count( $notifications ) > 0 ) {
874
- // Ideally there should be only one notification for this type.
875
- // If there are multiple notification then we will read data about only the last one
876
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
877
-
878
- $email_data = $this->engine->handle_filtered_data_notification( $email_data, $setting, $extra_data );
879
- }
880
-
881
- return $email_data;
882
- }
883
-
884
- /**
885
- * Set the email formatting to HTML.
886
- *
887
- * @since 1.4
888
- */
889
- public function set_html_content_type() {
890
- return 'text/html';
891
- }
892
-
893
- /**
894
- * Set the email formatting to text.
895
- *
896
- * @since 1.4
897
- */
898
- public function set_text_content_type() {
899
- return 'text/plain';
900
- }
901
-
902
- /**
903
- * Send notification for new users.
904
- *
905
- * @since 1.0
906
- * @param int $user_id
907
- */
908
- public function user_register( $user_id ) {
909
- $this->send_notification( 'admin-user', $user_id );
910
- }
911
-
912
- /**
913
- * Send notification for user when user login.
914
- *
915
- * @since 1.0
916
- * @param string $user_name
917
- * @param object $user_data User object.
918
- */
919
- public function user_login( $user_name, $user_data ) {
920
- $user_id = $user_data->ID;
921
- $notifications = $this->notifier->get_notifications( 'user-login' );
922
-
923
- foreach ( $notifications as $notification ) {
924
- $this->engine->send_user_login_email( $this->notifier->read_settings( $notification->ID ), get_userdata( $user_id ) );
925
- }
926
-
927
- $this->user_login_admin_notification( $user_id );
928
- }
929
-
930
- /**
931
- * Send notification for admin when user login.
932
- *
933
- * @since 1.0
934
- * @param int $user_id
935
- */
936
- public function user_login_admin_notification( $user_id ) {
937
- $notifications = $this->notifier->get_notifications( 'admin-user-login' );
938
-
939
- foreach ( $notifications as $notification ) {
940
- $this->engine->send_user_login_email_for_admin( $this->notifier->read_settings( $notification->ID ), get_userdata( $user_id ) );
941
- }
942
- }
943
-
944
- /**
945
- * Send notification about new users to site admin.
946
- *
947
- * @since 1.7.1
948
- *
949
- * @param array $email_data Email details.
950
- * @param WP_User $user User object.
951
- * @param string $blogname Blog name.
952
- *
953
- * @return array Modified email details.
954
- */
955
- public function handle_user_registered_admin_email( $email_data, $user,
956
- $blogname ) {
957
- return $this->handle_filtered_data_notification( 'admin-user', $email_data, $user->ID );
958
- }
959
-
960
- /**
961
- * New User - Post-registration Email
962
- *
963
- * @since 1.1
964
- * @param int $user_id New user id
965
- */
966
- public function welcome_email( $user_id ) {
967
- $notifications = $this->notifier->get_notifications( 'welcome-email' );
968
- foreach ( $notifications as $notification ) {
969
- $this->engine->send_registration_email( $this->notifier->read_settings( $notification->ID ), get_userdata( $user_id ) );
970
- }
971
- }
972
-
973
- /**
974
- * Send notification when a user role changes.
975
- *
976
- * @since 1.3.9
977
- *
978
- * @param int $user_id User ID
979
- * @param string $new_role New User role
980
- * @param array $old_roles Old User role
981
- */
982
- public function user_role_changed( $user_id, $new_role, $old_roles ) {
983
- if ( ! empty( $old_roles ) ) {
984
- $notifications = $this->notifier->get_notifications( 'user-role' );
985
- foreach ( $notifications as $notification ) {
986
-
987
- /**
988
- * Trigger User Role Changed - For User notification.
989
- *
990
- * @since 1.6.5
991
- */
992
- if ( apply_filters( 'bnfw_trigger_user-role_notification', true, $notification, $new_role, $old_roles ) ) {
993
- $this->engine->send_user_role_changed_email(
994
- $this->notifier->read_settings( $notification->ID ),
995
- $user_id,
996
- $old_roles[ 0 ],
997
- $new_role
998
- );
999
- }
1000
- }
1001
-
1002
- $notifications = $this->notifier->get_notifications( 'admin-role' );
1003
- foreach ( $notifications as $notification ) {
1004
-
1005
- /**
1006
- * Trigger User Role Changed - For User notification.
1007
- *
1008
- * @since 1.6.5
1009
- */
1010
- if ( apply_filters( 'bnfw_trigger_admin-role_notification', true, $notification, $new_role, $old_roles ) ) {
1011
- $setting = $this->notifier->read_settings( $notification->ID );
1012
- $setting[ 'message' ] = $this->engine->handle_user_role_shortcodes( $setting[ 'message' ], $old_roles[ 0 ], $new_role );
1013
- $setting[ 'subject' ] = $this->engine->handle_user_role_shortcodes( $setting[ 'subject' ], $old_roles[ 0 ], $new_role );
1014
-
1015
- $this->engine->send_notification( $setting, $user_id );
1016
- }
1017
- }
1018
- }
1019
- }
1020
-
1021
- /**
1022
- * Send notification when a user role added through Members Plugin.
1023
- *
1024
- * @since 1.8.4
1025
- *
1026
- * @param int $user_id User ID
1027
- * @param string $new_role New User role
1028
- *
1029
- */
1030
- public function user_role_added_from_member_plugin($user_id, $new_role){
1031
-
1032
- global $pagenow;
1033
-
1034
- if($pagenow != 'users.php')
1035
- return;
1036
-
1037
- if(!$user_id)
1038
- return;
1039
-
1040
- $notifications = $this->notifier->get_notifications( 'user-role' );
1041
-
1042
- foreach ( $notifications as $notification ) {
1043
-
1044
- if ( apply_filters( 'bnfw_trigger_user-role_notification', true, $notification, $new_role, null ) ) {
1045
- $this->engine->send_user_role_changed_email(
1046
- $this->notifier->read_settings( $notification->ID ),
1047
- $user_id,
1048
- null,