Better Notifications for WordPress - Version 1.8.5

Version Description

  • 18th December 2020 =
  • New: Shortcode - [user_old_email] and [user_new_email] can now be used in 'User Email Changed - For User' and 'User Email Changed - For Admin' notifications.
  • Fixed: 'User Role Changed' notifications weren't being sent out when editing users using bulk edit when plugins that allowed multiple user roles were being used.
  • Fixed: Numerous issues with Privacy notifications, including emails not sending and shortcodes not working.
  • Fixed: Conditional Notifications fields were showing on incorrect notifications if that add-on was being used.
  • Fixed: POT file regenerated to account for missing translatable strings.
  • Have a Merry Christmas and a happy New Year. Thanks for using BNFW :)
Download this release

Release Info

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

Code changes from version 1.8.4 to 1.8.5

README.txt CHANGED
@@ -3,9 +3,9 @@ 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.5.1
7
  Requires PHP: 5.6
8
- Stable tag: 1.8.4
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -241,6 +241,14 @@ Yes, of course! The plugin is completely translation-friendly and if you send me
241
 
242
  == Changelog ==
243
 
 
 
 
 
 
 
 
 
244
  = 1.8.4 - 12th August 2020 =
245
  * Fixed: In certain situations, the password reset key would get modified when using the User Lost Password - For User notification.
246
  * Fixed: An issue in the Custom Fields add-on where the Send to Author checkbox did not send a User Custom Field Updated notification to the user.
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.6
7
  Requires PHP: 5.6
8
+ Stable tag: 1.8.5
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
241
 
242
  == Changelog ==
243
 
244
+ = 1.8.5 - 18th December 2020 =
245
+ * New: Shortcode - [user_old_email] and [user_new_email] can now be used in 'User Email Changed - For User' and 'User Email Changed - For Admin' notifications.
246
+ * Fixed: 'User Role Changed' notifications weren't being sent out when editing users using bulk edit when plugins that allowed multiple user roles were being used.
247
+ * Fixed: Numerous issues with Privacy notifications, including emails not sending and shortcodes not working.
248
+ * Fixed: Conditional Notifications fields were showing on incorrect notifications if that add-on was being used.
249
+ * Fixed: POT file regenerated to account for missing translatable strings.
250
+ * Have a Merry Christmas and a happy New Year. Thanks for using BNFW :)
251
+
252
  = 1.8.4 - 12th August 2020 =
253
  * Fixed: In certain situations, the password reset key would get modified when using the User Lost Password - For User notification.
254
  * Fixed: An issue in the Custom Fields add-on where the Send to Author checkbox did not send a User Custom Field Updated notification to the user.
bnfw.php CHANGED
@@ -4,7 +4,7 @@
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.4
8
  * Requires at least: 4.8
9
  * Requires PHP: 5.6
10
  * Author: Made with Fuel
@@ -16,7 +16,7 @@
16
  */
17
 
18
  /**
19
- * Copyright © 2020 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.
@@ -28,1328 +28,1452 @@
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
-
32
  class BNFW {
33
 
34
- /**
35
- * Constructor.
36
- *
37
- * @since 1.0
38
- */
39
- function __construct() {
40
- $this->load_textdomain();
41
- $this->includes();
42
- $this->hooks();
43
-
44
- /**
45
- * BNFW Notification.
46
- *
47
- * @var \BNFW_Notification
48
- */
49
- $this->notifier = new BNFW_Notification;
50
-
51
- /**
52
- * BNFW Engine.
53
- *
54
- * @var \BNFW_Engine
55
- */
56
- $this->engine = new BNFW_Engine;
57
- }
58
-
59
- /**
60
- * Factory method to return the instance of the class.
61
- *
62
- * Makes sure that only one instance is created.
63
- *
64
- * @return \BNFW Instance of the class.
65
- */
66
- public static function factory() {
67
- static $instance = false;
68
- if ( ! $instance ) {
69
- $instance = new self();
70
- }
71
- return $instance;
72
- }
73
-
74
- /**
75
- * Loads the plugin language files
76
- *
77
- * @since 1.0
78
- */
79
- public function load_textdomain() {
80
- // Load localization domain
81
- $this->translations = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
82
- load_plugin_textdomain( 'bnfw', false, $this->translations );
83
- }
84
-
85
- /**
86
- * Include required files.
87
- *
88
- * @since 1.0
89
- */
90
- public function includes() {
91
-
92
- // Load license related classes
93
- if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
94
- require_once 'includes/libraries/EDD_SL_Plugin_Updater.php';
95
- }
96
-
97
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
98
-
99
- require_once 'vendor/persist-admin-notices-dismissal/persist-admin-notices-dismissal.php';
100
-
101
- require_once 'includes/license/class-bnfw-license.php';
102
- require_once 'includes/license/class-bnfw-license-setting.php';
103
-
104
- // Load Engine
105
- require_once 'includes/engine/class-bnfw-engine.php';
106
- require_once 'includes/overrides.php';
107
-
108
- // Load notification post type and notification helpers
109
- require_once 'includes/admin/class-bnfw-notification.php';
110
- require_once 'includes/notification/post-notification.php';
111
-
112
- // Helpers
113
- require_once 'includes/helpers/helpers.php';
114
- require_once 'includes/helpers/ajax-helpers.php';
115
-
116
- // Load Admin Pages
117
- if ( is_admin() ) {
118
- require_once 'includes/admin/bnfw-settings.php';
119
- }
120
- }
121
-
122
- /**
123
- * Register Hooks.
124
- *
125
- * @since 1.0
126
- */
127
- public function hooks() {
128
- global $wp_version;
129
-
130
- register_activation_hook( __FILE__, array( $this, 'activate' ) );
131
-
132
- add_action( 'admin_init', array( 'PAnD', 'init' ) );
133
- add_action( 'admin_init', array( $this, 'add_capability_to_admin' ) );
134
-
135
- add_action( 'draft_to_private' , array( $this, 'private_post' ) );
136
- add_action( 'future_to_private' , array( $this, 'private_post' ) );
137
- add_action( 'pending_to_private' , array( $this, 'private_post' ) );
138
- add_action( 'publish_to_private' , array( $this, 'private_post' ) );
139
-
140
- add_action( 'wp_insert_post' , array( $this, 'insert_post' ), 10, 3 );
141
-
142
- add_action( 'publish_to_trash' , array( $this, 'trash_post' ));
143
-
144
- add_action( 'auto-draft_to_publish' , array( $this, 'publish_post' ) );
145
- add_action( 'draft_to_publish' , array( $this, 'publish_post' ) );
146
- add_action( 'future_to_publish' , array( $this, 'publish_post' ) );
147
- add_action( 'pending_to_publish' , array( $this, 'publish_post' ) );
148
- add_action( 'private_to_publish' , array( $this, 'publish_post' ) );
149
  // add_action( 'acf/submit_form' , array( $this, 'acf_submit_form' ), 10, 2 );
150
 
151
- add_action( 'publish_to_publish' , array( $this, 'update_post' ) );
152
- add_action( 'private_to_private' , array( $this, 'update_post' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
- add_action( 'add_attachment' , array( $this, 'new_publish_media_notification' ), 10, 1 );
155
- add_action( 'edit_attachment' , array( $this, 'media_attachment_data_update_notification' ), 10 );
 
156
 
157
- add_action( 'transition_post_status' , array( $this, 'on_post_transition' ), 10, 3 );
 
 
158
 
159
- add_action( 'init' , array( $this, 'custom_post_type_hooks' ), 100 );
160
- add_action( 'create_term' , array( $this, 'create_term' ), 10, 3 );
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
- add_action( 'transition_comment_status' , array( $this, 'on_comment_status_change' ), 10, 3 );
163
- add_action( 'comment_post' , array( $this, 'comment_post' ) );
164
- add_action( 'trackback_post' , array( $this, 'trackback_post' ) );
165
- add_action( 'pingback_post' , array( $this, 'pingback_post' ) );
166
 
167
- add_action( 'user_register' , array( $this, 'user_register' ) );
 
 
 
 
 
 
 
 
168
 
169
- add_action( 'user_register' , array( $this, 'welcome_email' ) );
 
 
 
170
 
171
- if ( is_plugin_active('members/members.php') ) {
172
- add_action( 'profile_update' , array( $this, 'user_role_added' ), 10, 2 );
173
- }else{
174
- add_action( 'set_user_role' , array( $this, 'user_role_changed' ), 10, 3 );
 
 
 
 
 
175
  }
176
 
177
- add_action( 'wp_login' , array( $this, 'user_login' ),10,2);
178
-
179
- if ( version_compare( $wp_version, '4.4', '>=' ) ) {
180
- add_filter( 'retrieve_password_title', array( $this, 'change_password_email_title' ), 10, 3 );
181
- } else {
182
- add_filter( 'retrieve_password_title', array( $this, 'change_password_email_title' ) );
183
- }
184
- add_action( 'lostpassword_post' , array( $this, 'on_lost_password' ) );
185
- add_filter( 'retrieve_password_message' , array( $this, 'change_password_email_message' ), 10, 4 );
186
-
187
- add_action( 'after_password_reset' , array( $this, 'on_password_reset' ) );
188
-
189
- add_filter( 'send_password_change_email', array( $this, 'should_password_changed_email_be_sent' ), 10, 3 );
190
- add_filter( 'password_change_email' , array( $this, 'on_password_changed' ), 10, 2 );
191
-
192
- add_filter( 'send_email_change_email' , array( $this, 'should_email_changed_email_be_sent' ), 10, 3 );
193
- add_filter( 'email_change_email' , array( $this, 'on_email_changed' ), 10, 2 );
194
- add_filter( 'new_user_email_content' , array( $this, 'on_email_changing' ), 10, 2 );
195
-
196
- add_filter( 'auto_core_update_email' , array( $this, 'on_core_updated' ), 10, 4 );
197
-
198
- add_filter( 'user_request_action_email_content', array( $this, 'handle_user_request_email_content' ), 10, 2 );
199
- add_filter( 'user_request_action_email_subject', array( $this, 'handle_user_request_email_subject' ), 10, 3 );
200
-
201
- add_filter( 'user_confirmed_action_email_content', array( $this, 'handle_user_confirmed_action_email_content' ), 10, 2 );
202
-
203
- add_filter( 'wp_privacy_personal_data_email_content', array( $this, 'handle_data_export_email_content' ), 10, 2 );
204
-
205
- add_filter( 'user_erasure_complete_email_subject', array( $this, 'handle_erasure_complete_email_subject' ), 10, 3 );
206
- add_filter( 'user_confirmed_action_email_content', array( $this, 'handle_erasure_complete_email_content' ), 10, 2 );
207
-
208
- add_filter( 'plugin_action_links' , array( $this, 'plugin_action_links' ), 10, 4 );
209
- add_action( 'shutdown' , array( $this, 'on_shutdown' ) );
210
- }
211
-
212
- /**
213
- * Add 'bnfw' capability to admin.
214
- */
215
- public function add_capability_to_admin() {
216
- $admins = get_role( 'administrator' );
217
-
218
- if ( is_null( $admins ) ) {
219
- return;
220
- }
221
-
222
- if ( ! $admins->has_cap( 'bnfw' ) ) {
223
- $admins->add_cap( 'bnfw' );
224
- }
225
- }
226
-
227
- /**
228
- * On post transition.
229
- *
230
- * @param string $new_status New post status.
231
- * @param string $old_status Old post status.
232
- * @param \WP_Post $post Post object.
233
- */
234
- public function on_post_transition( $new_status, $old_status, $post ) {
235
- if ( ! is_a( $post, 'WP_Post' ) ) {
236
- return;
237
- }
238
-
239
- if ( 'pending' === $old_status ) {
240
- return;
241
- }
242
-
243
- if ( 'pending' !== $new_status ) {
244
- return;
245
- }
246
-
247
- $this->on_post_pending( $post->ID, $post );
248
- }
249
-
250
- /**
251
- * Setup hooks for custom post types.
252
- *
253
- * @since 1.2
254
- */
255
- function custom_post_type_hooks() {
256
- $post_types = get_post_types( array( 'public' => true ), 'names' );
257
- $post_types = array_diff( $post_types, array( BNFW_Notification::POST_TYPE ) );
258
-
259
- foreach ( $post_types as $post_type ) {
260
- add_action( 'future_' . $post_type, array( $this, 'on_post_scheduled' ), 10, 2 );
261
- }
262
- }
263
-
264
- /**
265
- * importer
266
- */
267
- public function activate() {
268
- require_once dirname( __FILE__ ) . '/includes/import.php';
269
- $importer = new BNFW_Import;
270
- $importer->import();
271
- }
272
-
273
- /**
274
- * Add 'Settings' link below BNFW in Plugins list.
275
- *
276
- * @since 1.0
277
- * @param unknown $links
278
- * @param unknown $file
279
- * @return unknown
280
- */
281
- public function plugin_action_links( $links, $file ) {
282
- $plugin_file = 'bnfw/bnfw.php';
283
- if ( $file == $plugin_file ) {
284
- $settings_link = '<a href="' . esc_url( admin_url( 'edit.php?post_type=bnfw_notification&page=bnfw-settings' ) ) . '">' . esc_html__( 'Settings', 'bnfw' ) . '</a>';
285
- array_unshift( $links, $settings_link );
286
- }
287
- return $links;
288
- }
289
-
290
- /**
291
- * When a new term is created.
292
- *
293
- * @since 1.0
294
- * @param int $term_id
295
- * @param int $tt_id
296
- * @param string $taxonomy
297
- */
298
- public function create_term( $term_id, $tt_id, $taxonomy ) {
299
- $this->send_notification( 'newterm-' . $taxonomy, $term_id );
300
- }
301
-
302
- /**
303
- * Fires when a post is created for the first time.
304
- *
305
- * @param int $post_id Post ID
306
- * @param object $post Post object
307
- * @param bool $update Whether this is an existing post being updated or not.
308
- *
309
- * @since 1.3.1
310
- */
311
- public function insert_post( $post_id, $post, $update ) {
312
- // Some themes like P2, directly insert posts into DB.
313
- $insert_post_themes = apply_filters( 'bnfw_insert_post_themes', array( 'P2', 'Syncope' ) );
314
- $current_theme = wp_get_theme();
315
-
316
- /**
317
- * Whether to trigger insert post hook.
318
- *
319
- * @since 1.4
320
- */
321
- $trigger_insert_post = apply_filters( 'bnfw_trigger_insert_post', false, $post_id, $update );
322
-
323
- if ( in_array( $current_theme->get( 'Name' ), $insert_post_themes ) || $trigger_insert_post ) {
324
- $this->handle_inserted_post( $post_id, $update );
325
- }
326
- }
327
-
328
- /**
329
- * Trigger New Post published notification for ACF forms.
330
- *
331
- * @param string $form ACF Form.
332
- * @param int $post_id Post ID.
333
- */
334
- public function acf_submit_form( $form, $post_id ) {
335
- $this->handle_inserted_post( $post_id );
336
- }
337
-
338
- /**
339
- * Trigger correct notifications for inserted posts.
340
- *
341
- * @param int $post_id Post id.
342
- * @param bool $update Whether the post was updated.
343
- *
344
- * @since 1.6.7
345
- */
346
- private function handle_inserted_post( $post_id, $update ) {
347
- $post = get_post( $post_id );
348
-
349
- if ( ! is_a( $post, 'WP_Post' ) ) {
350
- return;
351
- }
352
-
353
- switch ( $post->post_status ) {
354
- case 'publish':
355
- if ( $update ) {
356
- $this->update_post( $post );
357
- } else {
358
- $this->publish_post( $post );
359
- }
360
- break;
361
-
362
- case 'private':
363
- $this->private_post( $post );
364
- break;
365
-
366
- case 'pending':
367
- $this->on_post_pending( $post_id, $post );
368
- break;
369
-
370
- case 'future':
371
- $this->on_post_scheduled( $post_id, $post );
372
- break;
373
- }
374
- }
375
-
376
- /**
377
- * Fires when a post is created for the first time.
378
- *
379
- * @since 1.0
380
- * @param object $post Post Object
381
- */
382
- function publish_post( $post ) {
383
- $post_id = $post->ID;
384
- $post_type = $post->post_type;
385
-
386
- if ( BNFW_Notification::POST_TYPE != $post_type ) {
387
- $this->send_notification_async( 'new-' . $post_type, $post_id );
388
- }
389
- }
390
-
391
- /**
392
- * Fires when a private post is created.
393
- *
394
- * @since 1.6
395
- * @param object $post Post Object
396
- */
397
- public function private_post( $post ) {
398
- $post_id = $post->ID;
399
- $post_type = $post->post_type;
400
-
401
- if ( BNFW_Notification::POST_TYPE != $post_type ) {
402
- $this->send_notification_async( 'private-' . $post_type, $post_id );
403
- }
404
- }
405
-
406
- /**
407
- * Fires when a post is updated.
408
- *
409
- * @since 1.0
410
- * @param unknown $post
411
- */
412
- public function update_post( $post ) {
413
- if ( $this->is_metabox_request() ) {
414
- return;
415
- }
416
-
417
- $post_id = $post->ID;
418
- $post_type = $post->post_type;
419
-
420
- if ( BNFW_Notification::POST_TYPE != $post_type ) {
421
- $this->send_notification_async( 'update-' . $post_type, $post_id );
422
- }
423
- }
424
 
 
 
 
 
425
 
426
  /**
427
  * Fires when a post is moved publish to trash.
428
  *
429
  */
430
- public function trash_post($post) {
431
- if ($this->is_metabox_request()) {
432
  return;
433
  }
434
- $post_id = $post->ID;
435
  $post_type = $post->post_type;
436
 
437
- if (BNFW_Notification::POST_TYPE != $post_type) {
438
- $this->send_notification_async('trash-' . $post_type, $post_id);
439
  }
440
  }
441
 
442
- /**
443
- * Fires when a post is pending for review.
444
- *
445
- * @since 1.1
446
- * @param int $post_id Post ID
447
- * @param object $post Post object
448
- */
449
- public function on_post_pending( $post_id, $post ) {
450
- if ( $this->is_metabox_request() ) {
451
- return;
452
- }
 
 
453
 
454
- $post_type = $post->post_type;
 
 
 
455
 
456
- if ( BNFW_Notification::POST_TYPE != $post_type ) {
457
- $this->send_notification_async( 'pending-' . $post_type, $post_id );
458
- }
459
- }
 
 
 
460
 
 
 
 
 
461
 
462
- /**
463
- * On Media Published.
464
- *
465
- * @param int $post_id Attachment post id.
466
- */
 
 
 
 
 
 
467
 
468
- public function new_publish_media_notification( $post_id ) {
469
- $post_type = get_post_type($post_id);
 
 
 
 
 
 
 
 
 
 
470
 
471
- if (BNFW_Notification::POST_TYPE != $post_type && $post_type == 'attachment') {
472
- $this->send_notification_async( 'new-media', $post_id );
473
- }
474
- }
475
 
476
- /**
477
- * On Media Attachment Data Update.
478
- *
479
- * @param int $post_id Attachment post id.
480
- */
481
-
482
- public function media_attachment_data_update_notification($post_id ) {
483
- $post_type = get_post_type($post_id);
484
- if (BNFW_Notification::POST_TYPE != $post_type && $post_type == 'attachment') {
485
- $this->send_notification_async( 'update-media', $post_id );
486
- }
487
- }
488
-
489
- /**
490
- * Fires when a post is scheduled.
491
- *
492
- * @since 1.1.5
493
- * @param int $post_id Post ID
494
- * @param object $post Post object
495
- */
496
- function on_post_scheduled( $post_id, $post ) {
497
- // Rest request also triggers the same hook. We can ignore it.
498
- if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
499
- return;
500
- }
501
-
502
- $post_type = $post->post_type;
503
-
504
- if ( BNFW_Notification::POST_TYPE != $post_type ) {
505
- $this->send_notification_async( 'future-' . $post_type, $post_id );
506
- }
507
- }
508
-
509
- /**
510
- * When the status of a comment is changed.
511
- *
512
- * @param string $new_status New status.
513
- * @param string $old_status Old status.
514
- * @param \WP_Comment $comment Comment.
515
- */
516
- public function on_comment_status_change( $new_status, $old_status, $comment ) {
517
- if ( 'approved' !== $new_status ) {
518
- return;
519
- }
520
-
521
- $post = get_post( $comment->comment_post_ID );
522
-
523
- $notification_type = 'approve-'.$post->post_type.'-comment';
524
-
525
- $this->send_notification( $notification_type, $comment->comment_ID );
526
-
527
- // Send new comment notification after comment approve
528
- $notification_type = 'new-comment'; // old notification name
529
-
530
- if ( 'post' != $post->post_type ) {
531
- $notification_type = 'comment-' . $post->post_type;
532
- }
533
-
534
- $this->send_notification( $notification_type, $comment->comment_ID );
535
-
536
- // Send comment reply notification after comment approve.
537
- $this->commentsReply($comment->comment_ID);
538
- }
539
-
540
- /**
541
- * Send notification for new comments
542
- *
543
- * @since 1.0
544
- * @param int $comment_id
545
- */
546
- public function comment_post( $comment_id ) {
547
- $the_comment = get_comment( $comment_id );
548
- $post = get_post( $the_comment->comment_post_ID );
549
-
550
- if ( '1' !== $the_comment->comment_approved ) {
551
- if ( $this->can_send_comment_notification( $the_comment ) ) {
552
- $notification_type = 'moderate-' . $post->post_type . '-comment';
553
- $this->send_notification( $notification_type, $comment_id );
554
- }
555
- } else {
556
- $notification_type = 'new-comment'; // old notification name
557
-
558
- if ( 'post' != $post->post_type ) {
559
- $notification_type = 'comment-' . $post->post_type;
560
- }
561
-
562
- $this->send_notification( $notification_type, $comment_id );
563
-
564
- // comment reply notification.
565
- $this->commentsReply($comment_id);
566
- }
567
- }
568
 
569
- /**
570
- * Send notification for comments reply
571
- *
572
- * @since 1.0
573
- * @param int $comment_id
574
- */
575
- public function commentsReply($comment_id) {
576
- $the_comment = get_comment( $comment_id );
577
- $post = get_post( $the_comment->comment_post_ID );
578
-
579
- // comment reply notification.
580
- if ( $this->can_send_comment_notification( $the_comment ) ) {
581
- if ( $the_comment->comment_parent > 0 ) {
582
- $notification_type = 'reply-comment'; // old notification name
583
- if ( 'post' != $post->post_type ) {
584
- $notification_type = 'commentreply-' . $post->post_type;
585
- }
586
- $notifications = $this->notifier->get_notifications( $notification_type );
587
- if ( count( $notifications ) > 0 ) {
588
- $parent = get_comment( $the_comment->comment_parent );
589
- if ( $parent->comment_author_email != $the_comment->comment_author_email ) {
590
- foreach ( $notifications as $notification ) {
591
- $this->engine->send_comment_reply_email( $this->notifier->read_settings( $notification->ID ), $the_comment, $parent );
592
- }
593
- }
594
- }
595
- }
596
- }
597
- }
598
-
599
- /**
600
- * Send notification for new trackback
601
- *
602
- * @since 1.0
603
- * @param unknown $comment_id
604
- */
605
- function trackback_post( $comment_id ) {
606
- $the_comment = get_comment( $comment_id );
607
- if ( $this->can_send_comment_notification( $the_comment ) ) {
608
- $this->send_notification( 'new-trackback', $comment_id );
609
- }
610
- }
611
-
612
- /**
613
- * Send notification for new pingbacks
614
- *
615
- * @since 1.0
616
- * @param unknown $comment_id
617
- */
618
- function pingback_post( $comment_id ) {
619
- $the_comment = get_comment( $comment_id );
620
- if ( $this->can_send_comment_notification( $the_comment ) ) {
621
- $this->send_notification( 'new-pingback', $comment_id );
622
- }
623
- }
624
-
625
- /**
626
- * Send notification for lost password.
627
- *
628
- * @since 1.0
629
- */
630
- function on_lost_password() {
631
- $user_login = sanitize_text_field( $_POST['user_login'] );
632
- $user = get_user_by( 'login', $user_login );
633
- if ( $user ) {
634
- $this->send_notification( 'admin-password', $user->ID );
635
- }
636
- }
637
-
638
- /**
639
- * Change the title of the password reset email that is sent to the user.
640
- *
641
- * @since 1.1
642
- *
643
- * @param string $title
644
- * @param string $user_login
645
- * @param string $user_data
646
- *
647
- * @return string
648
- */
649
- public function change_password_email_title( $title, $user_login = '', $user_data = '' ) {
650
- $notifications = $this->notifier->get_notifications( 'user-password' );
651
- if ( count( $notifications ) > 0 ) {
652
- // Ideally there should be only one notification for this type.
653
- // If there are multiple notification then we will read data about only the last one
654
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
655
-
656
- if ( '' === $user_data ) {
657
- return $this->engine->handle_shortcodes( $setting['subject'], 'user-password', $user_data->ID );
658
- } else {
659
- return $this->engine->handle_shortcodes( $setting['subject'], 'user-password', $user_data->ID );
660
- }
661
- }
662
-
663
- return $title;
664
- }
665
-
666
- /**
667
- * Change the message of the password reset email.
668
- *
669
- * @since 1.1
670
- *
671
- * @param string $message
672
- * @param string $key
673
- * @param string $user_login
674
- * @param string $user_data
675
- *
676
- * @return string
677
- */
678
- public function change_password_email_message( $message, $key, $user_login = '', $user_data = '' ) {
679
- $notifications = $this->notifier->get_notifications( 'user-password' );
680
- if ( count( $notifications ) > 0 ) {
681
- // Ideally there should be only one notification for this type.
682
- // If there are multiple notification then we will read data about only the last one
683
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
684
-
685
- $message = $this->engine->handle_password_reset_shortcodes( $setting, $key, $user_login, $user_data );
686
-
687
- if ( 'html' == $setting['email-formatting'] ) {
688
- add_filter( 'wp_mail_content_type', array( $this, 'set_html_content_type' ) );
689
- if ( 'true' !== $setting['disable-autop'] ) {
690
- $message = wpautop( $message );
691
- }
692
- } else {
693
- add_filter( 'wp_mail_content_type', array( $this, 'set_text_content_type' ) );
694
- if('text' == $setting['email-formatting'] ){
695
- $message = strip_tags($message);
696
- }
697
- }
698
- } else {
699
- if ( $this->notifier->notification_exists( 'user-password', false ) ) {
700
- // disabled notification exists, so disable the email by returning empty string.
701
- return '';
702
- }
703
- }
704
-
705
- return $message;
706
- }
707
-
708
- /**
709
- * On Password reset.
710
- *
711
- * @param WP_User $user User who's password was changed.
712
- */
713
- public function on_password_reset( $user ) {
714
- $notifications = $this->notifier->get_notifications( 'password-changed' );
715
- foreach ( $notifications as $notification ) {
716
- $this->engine->send_password_changed_email( $this->notifier->read_settings( $notification->ID ), $user );
717
- }
718
- }
719
-
720
- /**
721
- * Should the password changed email be sent?
722
- *
723
- * @param $send
724
- * @param $user
725
- * @param $userdata
726
- *
727
- * @return bool
728
- */
729
- public function should_password_changed_email_be_sent( $send, $user, $userdata ) {
730
- $bnfw = BNFW::factory();
731
-
732
- if ( ! $send ) {
733
- return $send;
734
- }
735
-
736
- return ! $bnfw->notifier->is_notification_disabled( 'password-changed' );
737
- }
738
-
739
- /**
740
- * On Password Changed.
741
- *
742
- * @since 1.6
743
- *
744
- * @param array $email_data Email Data.
745
- * @param array $user User data.
746
- *
747
- * @return array Modified Email Data
748
- */
749
- public function on_password_changed( $email_data, $user ) {
750
- return $this->handle_filtered_data_notification( 'password-changed', $email_data, $user['ID'] );
751
- }
752
-
753
- /**
754
- * Should the email changed email be sent?
755
- *
756
- * @param $send
757
- * @param $user
758
- * @param $userdata
759
- *
760
- * @return bool
761
- */
762
- public function should_email_changed_email_be_sent( $send, $user, $userdata ) {
763
- $bnfw = BNFW::factory();
764
-
765
- if ( $bnfw->notifier->notification_exists( 'admin-email-changed', false ) ) {
766
- $notifications = $bnfw->notifier->get_notifications( 'admin-email-changed' );
767
-
768
- if ( count( $notifications ) > 0 ) {
769
- // Ideally there should be only one notification for this type.
770
- // If there are multiple notification then we will read data about only the last one
771
- $bnfw->engine->send_notification( $bnfw->notifier->read_settings( end( $notifications )->ID ), $user['ID'] );
772
- }
773
- }
774
-
775
- if ( ! $send ) {
776
- return $send;
777
- }
778
-
779
- return ! $bnfw->notifier->is_notification_disabled( 'email-changed' );
780
- }
781
-
782
- /**
783
- * On Email Changed.
784
- *
785
- * @since 1.6
786
- *
787
- * @param array $email_data Email Data.
788
- * @param array $user User data.
789
- *
790
- * @return array Modified Email Data
791
- */
792
- public function on_email_changed( $email_data, $user ) {
793
- return $this->handle_filtered_data_notification( 'email-changed', $email_data, $user['ID'] );
794
- }
795
-
796
- public function on_email_changing( $email_text, $new_user_details ) {
797
- $notification_name = 'email-changing';
798
-
799
- $notifications = $this->notifier->get_notifications( $notification_name );
800
- if ( count( $notifications ) > 0 ) {
801
- // Ideally there should be only one notification for this type.
802
- // If there are multiple notification then we will read data about only the last one
803
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
804
-
805
- $email_text = $this->engine->handle_shortcodes( $setting['message'], $setting['notification'], $new_user_details['newemail'] );
806
- $email_text = $this->engine->handle_global_user_shortcodes( $email_text, $new_user_details['newemail'] );
807
- $email_text = str_replace( '[email_change_confirmation_link]', esc_url( admin_url( 'profile.php?newuseremail=' . $new_user_details['hash'] ) ), $email_text );
808
-
809
- }
810
-
811
- return $email_text;
812
- }
813
-
814
- /**
815
- * Send notification on core updated event.
816
- *
817
- * @since 1.6
818
- *
819
- * @param array $email_data Email Data.
820
- * @param string $type The type of email being sent. Can be one of
821
- * 'success', 'fail', 'manual', 'critical'.
822
- * @param object $core_update The update offer that was attempted.
823
- * @param mixed $result The result for the core update. Can be WP_Error.
824
- *
825
- * @return array Modified Email Data.
826
- */
827
- public function on_core_updated( $email_data, $type, $core_update, $result ) {
828
- $notifications = $this->notifier->get_notifications( 'core-updated' );
829
- if ( count( $notifications ) > 0 ) {
830
- // Ideally there should be only one notification for this type.
831
- // If there are multiple notification then we will read data about only the last one
832
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
833
-
834
- $email_data = $this->engine->handle_core_updated_notification( $email_data, $setting, $type );
835
- }
836
-
837
- return $email_data;
838
- }
839
-
840
- /**
841
- * Process User update notifications.
842
- *
843
- * @since 1.6
844
- *
845
- * @param string $notification_name Notification Name.
846
- * @param array $email_data Email Data.
847
- * @param string|int $extra_data User Id.
848
- *
849
- * @return array Modified Email Data.
850
- */
851
- private function handle_filtered_data_notification( $notification_name, $email_data, $extra_data ) {
852
- $notifications = $this->notifier->get_notifications( $notification_name );
853
- if ( count( $notifications ) > 0 ) {
854
- // Ideally there should be only one notification for this type.
855
- // If there are multiple notification then we will read data about only the last one
856
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
857
-
858
- $email_data = $this->engine->handle_filtered_data_notification( $email_data, $setting, $extra_data );
859
- }
860
-
861
- return $email_data;
862
- }
863
-
864
- /**
865
- * Set the email formatting to HTML.
866
- *
867
- * @since 1.4
868
- */
869
- public function set_html_content_type() {
870
- return 'text/html';
871
- }
872
-
873
- /**
874
- * Set the email formatting to text.
875
- *
876
- * @since 1.4
877
- */
878
- public function set_text_content_type() {
879
- return 'text/plain';
880
- }
881
-
882
- /**
883
- * Send notification for new users.
884
- *
885
- * @since 1.0
886
- * @param int $user_id
887
- */
888
- public function user_register( $user_id ) {
889
- $this->send_notification( 'admin-user', $user_id );
890
- }
891
-
892
- /**
893
- * Send notification for user when user login.
894
- *
895
- * @since 1.0
896
- * @param string $user_name
897
- * @param object $user_data User object.
898
- */
899
- public function user_login( $user_name, $user_data ) {
900
- $user_id = $user_data->ID;
901
- $notifications = $this->notifier->get_notifications( 'user-login' );
902
 
903
- foreach ( $notifications as $notification ) {
904
- $this->engine->send_user_login_email( $this->notifier->read_settings( $notification->ID ), get_userdata( $user_id ) );
905
- }
906
 
907
- $this->user_login_admin_notification($user_id);
908
- }
909
 
910
- /**
911
- * Send notification for admin when user login.
912
- *
913
- * @since 1.0
914
- * @param int $user_id
915
- */
916
- public function user_login_admin_notification( $user_id ) {
917
- $notifications = $this->notifier->get_notifications( 'admin-user-login' );
918
 
919
- foreach ( $notifications as $notification ) {
920
- $this->engine->send_user_login_email_for_admin( $this->notifier->read_settings( $notification->ID ), get_userdata( $user_id ) );
921
- }
922
- }
923
-
924
- /**
925
- * Send notification about new users to site admin.
926
- *
927
- * @since 1.7.1
928
- *
929
- * @param array $email_data Email details.
930
- * @param WP_User $user User object.
931
- * @param string $blogname Blog name.
932
- *
933
- * @return array Modified email details.
934
- */
935
- public function handle_user_registered_admin_email( $email_data, $user, $blogname ) {
936
- return $this->handle_filtered_data_notification( 'admin-user', $email_data, $user->ID );
937
- }
938
-
939
- /**
940
- * New User - Post-registration Email
941
- *
942
- * @since 1.1
943
- * @param int $user_id New user id
944
- */
945
- public function welcome_email( $user_id ) {
946
- $notifications = $this->notifier->get_notifications( 'welcome-email' );
947
- foreach ( $notifications as $notification ) {
948
- $this->engine->send_registration_email( $this->notifier->read_settings( $notification->ID ), get_userdata( $user_id ) );
949
- }
950
- }
951
-
952
- /**
953
- * Send notification when a user role changes.
954
- *
955
- * @since 1.3.9
956
- *
957
- * @param int $user_id User ID
958
- * @param string $new_role New User role
959
- * @param array $old_roles Old User role
960
- */
961
- public function user_role_changed( $user_id, $new_role, $old_roles ) {
962
- if ( ! empty( $old_roles ) ) {
963
- $notifications = $this->notifier->get_notifications( 'user-role' );
964
- foreach ( $notifications as $notification ) {
965
-
966
- /**
967
- * Trigger User Role Changed - For User notification.
968
- *
969
- * @since 1.6.5
970
- */
971
- if ( apply_filters( 'bnfw_trigger_user-role_notification', true, $notification, $new_role, $old_roles ) ) {
972
- $this->engine->send_user_role_changed_email(
973
- $this->notifier->read_settings( $notification->ID ),
974
- $user_id,
975
- $old_roles[0],
976
- $new_role
977
- );
978
- }
979
- }
980
-
981
- $notifications = $this->notifier->get_notifications( 'admin-role' );
982
- foreach ( $notifications as $notification ) {
983
-
984
- /**
985
- * Trigger User Role Changed - For User notification.
986
- *
987
- * @since 1.6.5
988
- */
989
- if ( apply_filters( 'bnfw_trigger_admin-role_notification', true, $notification, $new_role, $old_roles ) ) {
990
- $setting = $this->notifier->read_settings( $notification->ID );
991
- $setting['message'] = $this->engine->handle_user_role_shortcodes( $setting['message'], $old_roles[0], $new_role );
992
- $setting['subject'] = $this->engine->handle_user_role_shortcodes( $setting['subject'], $old_roles[0], $new_role );
993
-
994
- $this->engine->send_notification( $setting, $user_id );
995
- }
996
- }
997
- }
998
- }
999
-
1000
- /**
1001
- * Send notification when a user role added support User Role Editor by Members Plugin.
1002
- *
1003
- * @since 1.3.9
1004
- *
1005
- * @param int $user_id User ID
1006
- * @param string $new_role New User role
1007
- * @param array $old_roles Old User role
1008
- */
1009
- public function user_role_added( $user_id, $old_user_data ) {
1010
-
1011
- if(isset($_POST['members_user_roles']) && !empty($_POST['members_user_roles'])){
1012
- // Get the current user roles.
1013
- $old_roles = (array) $old_user_data->roles;
1014
-
1015
- // Sanitize the posted roles.
1016
- $new_roles = array_map( 'members_sanitize_role', $_POST['members_user_roles'] );
1017
-
1018
- sort($old_roles);
1019
- sort($new_roles);
1020
- $old_roles_str = implode('', $old_roles);
1021
- $new_roles_str = implode('', $new_roles);
1022
- if ( ! empty( $old_roles ) && $old_roles_str !== $new_roles_str) {
1023
- $notifications = $this->notifier->get_notifications( 'user-role' );
1024
- foreach ( $notifications as $notification ) {
1025
-
1026
- /**
1027
- * Trigger User Role Changed - For User notification.
1028
- *
1029
- * @since 1.6.5
1030
- */
1031
- if ( apply_filters( 'bnfw_trigger_user-role-added_notification', true, $notification, $new_roles, $old_roles ) ) {
1032
- $this->engine->send_user_role_added_email(
1033
- $this->notifier->read_settings( $notification->ID ),
1034
- $user_id,
1035
- $old_roles,
1036
- $new_roles
1037
- );
1038
- }
1039
- }
1040
-
1041
- $notifications = $this->notifier->get_notifications( 'admin-role' );
1042
- foreach ( $notifications as $notification ) {
1043
-
1044
- /**
1045
- * Trigger User Role Changed - For User notification.
1046
- *
1047
- * @since 1.6.5
1048
- */
1049
- if ( apply_filters( 'bnfw_trigger_user-role-added_notification', true, $notification, $new_roles, $old_roles ) ) {
1050
- $setting = $this->notifier->read_settings( $notification->ID );
1051
- $setting['message'] = $this->engine->handle_user_added_role_shortcodes( $setting['message'], $old_roles, $new_roles );
1052
- $setting['subject'] = $this->engine->handle_user_added_role_shortcodes( $setting['subject'], $old_roles, $new_roles );
1053
-
1054
- $this->engine->send_notification( $setting, $user_id );
1055
- }
1056
- }
1057
- }
1058
- }
1059
- }
1060
 
1061
- /**
1062
- * Sanitizes a role name. This is a wrapper for the `sanitize_key()` WordPress function. Only
1063
- * alphanumeric characters and underscores are allowed. Hyphens are also replaced with underscores.
1064
- *
1065
- * @since 1.0.0
1066
- * @access public
1067
- * @return int
1068
- */
1069
- function members_sanitize_role( $role ) {
1070
-
1071
- $_role = strtolower( $role );
1072
- $_role = preg_replace( '/[^a-z0-9_\-\s]/', '', $_role );
1073
-
1074
- return apply_filters( 'members_sanitize_role', str_replace( ' ', '_', $_role ), $role );
1075
- }
1076
-
1077
- /**
1078
- * Send notification based on type and ref id
1079
- *
1080
- * @since 1.0
1081
- * @param string $type Notification type.
1082
- * @param mixed $ref_id Reference data.
1083
- */
1084
- public function send_notification( $type, $ref_id ) {
1085
- $notifications = $this->notifier->get_notifications( $type );
1086
- foreach ( $notifications as $notification ) {
1087
- $this->engine->send_notification( $this->notifier->read_settings( $notification->ID ), $ref_id );
1088
- }
1089
- }
1090
-
1091
- /**
1092
- * Send notification async based on type and ref id.
1093
- *
1094
- * @param string $type Notification type.
1095
- * @param mixed $ref_id Reference data.
1096
- */
1097
- public function send_notification_async( $type, $ref_id ) {
1098
- $notifications = $this->notifier->get_notifications( $type, false );
1099
- foreach ( $notifications as $notification ) {
1100
- $transient = get_transient( 'bnfw-async-notifications' );
1101
- if ( ! is_array( $transient ) ) {
1102
- $transient = array();
1103
- }
1104
-
1105
- $notification_data = array(
1106
- 'ref_id' => $ref_id,
1107
- 'notification_id' => $notification->ID,
1108
- 'notification_type' => $type,
1109
- );
1110
-
1111
- if ( ! in_array( $notification_data, $transient ) ) {
1112
- $transient[] = $notification_data;
1113
- set_transient( 'bnfw-async-notifications', $transient, 600 );
1114
- }
1115
- }
1116
- }
1117
-
1118
- /**
1119
- * Can send comment notification or not
1120
- *
1121
- * @since 1.0
1122
- * @param unknown $comment
1123
- * @return unknown
1124
- */
1125
- private function can_send_comment_notification( $comment ) {
1126
- // Returns false if the comment is marked as spam AND admin has enabled suppression of spam
1127
- $suppress_spam = get_option( 'bnfw_suppress_spam' );
1128
- if ( '1' === $suppress_spam && ( 0 === strcmp( $comment->comment_approved, 'spam' ) ) ) {
1129
- return false;
1130
- }
1131
- return true;
1132
- }
1133
-
1134
- /**
1135
- * Handle user request email content.
1136
- *
1137
- * @param string $content Content.
1138
- * @param array $email_data Email data.
1139
- *
1140
- * @return string Modified content.
1141
- */
1142
- public function handle_user_request_email_content( $content, $email_data ) {
1143
- $field = 'message';
1144
- $new_content = '';
1145
-
1146
- switch ( $email_data['description'] ) {
1147
- case 'Export Personal Data':
1148
- $notification_name = 'ca-export-data';
1149
- $new_content = $this->handle_user_request_notification( $notification_name, $field, $email_data );
1150
- break;
1151
- case 'Erase Personal Data':
1152
- $notification_name = 'ca-erase-data';
1153
- $new_content = $this->handle_user_request_notification( $notification_name, $field, $email_data );
1154
- break;
1155
- }
1156
-
1157
- if(!empty($new_content)){
1158
- return $new_content;
1159
- }else{
1160
- return $content;
1161
- }
1162
- }
1163
-
1164
- /**
1165
- * Handle user request email subject.
1166
- *
1167
- * @param string $subject Subject
1168
- * @param string $blogname Blog name
1169
- * @param array $email_data Email data.
1170
- *
1171
- * @return string Modified subject.
1172
- */
1173
- public function handle_user_request_email_subject( $subject, $blogname, $email_data ) {
1174
- $field = 'subject';
1175
- $new_subject = '';
1176
-
1177
- switch ( $email_data['description'] ) {
1178
- case 'Export Personal Data':
1179
- $notification_name = 'ca-export-data';
1180
- $new_subject = $this->handle_user_request_notification( $notification_name, $field, $email_data );
1181
- break;
1182
- case 'Erase Personal Data':
1183
- $notification_name = 'ca-erase-data';
1184
- $new_subject = $this->handle_user_request_notification( $notification_name, $field, $email_data );
1185
- break;
1186
- }
1187
- if(!empty($new_subject)){
1188
- return $new_subject;
1189
- }else{
1190
- return $subject;
1191
  }
1192
- }
1193
-
1194
- /**
1195
- * Handle user confirmed action email content.
1196
- *
1197
- * @param string $content Content.
1198
- * @param array $email_data Email data.
1199
- *
1200
- * @return string Modified content.
1201
- */
1202
- public function handle_user_confirmed_action_email_content( $content, $email_data ) {
1203
- $field = 'message';
1204
- $new_content = '';
1205
-
1206
- switch ( $email_data['description'] ) {
1207
- case 'Export Personal Data':
1208
- $notification_name = 'uc-export-data';
1209
- $new_content = $this->handle_user_confirmed_action_notification( $notification_name, $field, $email_data );
1210
- break;
1211
- case 'Erase Personal Data':
1212
- $notification_name = 'uc-erase-data';
1213
- $new_content = $this->handle_user_confirmed_action_notification( $notification_name, $field, $email_data );
1214
- break;
1215
- }
1216
-
1217
- if(!empty($new_content)){
1218
- return $new_content;
1219
- }else{
1220
- return $content;
1221
  }
1222
- }
1223
-
1224
- /**
1225
- * Handle data exported email content.
1226
- *
1227
- * @param string $content Content.
1228
- * @param int $request_id
1229
- *
1230
- * @return string Modified content.
1231
- */
1232
- public function handle_data_export_email_content( $content, $request_id ) {
1233
- $field = 'message';
1234
- $notification_name = 'data-export';
1235
- $new_content = '';
1236
-
1237
- $notifications = $this->notifier->get_notifications( $notification_name );
1238
- if ( count( $notifications ) > 0 ) {
1239
- // Ideally there should be only one notification for this type.
1240
- // If there are multiple notification then we will read data about only the last one
1241
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
1242
-
1243
- $new_content = $this->engine->handle_data_export_email_shortcodes( $setting[ $field ], $setting, $request_id );
1244
- }
1245
-
1246
- if(!empty($new_content)){
1247
- return $new_content;
1248
- }else{
1249
- return $content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1250
  }
1251
- }
1252
-
1253
- public function handle_erasure_complete_email_subject( $subject, $sitename, $email_data ) {
1254
- return $this->handle_erasure_complete_email_notification( 'subject', $subject, $email_data );
1255
- }
1256
-
1257
- public function handle_erasure_complete_email_content( $content, $email_data ) {
1258
- if ( isset( $email_data['privacy_policy_url'] ) ) {
1259
- return $this->handle_erasure_complete_email_notification( 'message', $content, $email_data );
1260
- }
1261
-
1262
- return $content;
1263
- }
1264
-
1265
- protected function handle_erasure_complete_email_notification( $field, $content, $email_data ) {
1266
- $notification_name = 'data-erased';
1267
- $new_content = '';
1268
- $notifications = $this->notifier->get_notifications( $notification_name );
1269
- if ( count( $notifications ) > 0 ) {
1270
- // Ideally there should be only one notification for this type.
1271
- // If there are multiple notification then we will read data about only the last one
1272
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
1273
- $new_content = $this->engine->handle_shortcodes( $setting[ $field ], $notification_name, $email_data );
1274
- }
1275
- if(!empty($new_content)){
1276
- return $new_content;
1277
- }else{
1278
- return $content;
1279
  }
1280
- }
1281
-
1282
- /**
1283
- * Send notification emails on shutdown.
1284
- */
1285
- public function on_shutdown() {
1286
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
1287
- return;
1288
- }
1289
-
1290
- $transient = get_transient( 'bnfw-async-notifications' );
1291
- if ( is_array( $transient ) ) {
1292
- delete_transient( 'bnfw-async-notifications' );
1293
- foreach ( $transient as $id_pairs ) {
1294
- $this->engine->send_notification( $this->notifier->read_settings( $id_pairs['notification_id'] ), $id_pairs['ref_id'] );
1295
- }
1296
- }
1297
- }
1298
-
1299
- /**
1300
- * Handle user request notification.
1301
- *
1302
- * @param string $notification_name Notification name.
1303
- * @param string $field Field name.
1304
- * @param array $email_data Email data.
1305
- *
1306
- * @return string Content.
1307
- */
1308
- protected function handle_user_request_notification( $notification_name, $field, $email_data ) {
1309
- $notifications = $this->notifier->get_notifications( $notification_name );
1310
- if ( count( $notifications ) > 0 ) {
1311
- // Ideally there should be only one notification for this type.
1312
- // If there are multiple notification then we will read data about only the last one
1313
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
1314
-
1315
- return $this->engine->handle_user_request_email_shortcodes( $setting[ $field ], $setting, $email_data );
1316
- }
1317
-
1318
- return '';
1319
- }
1320
-
1321
- /**
1322
- * Handle user confirmed action notification.
1323
- *
1324
- * @param string $notification_name Notification name.
1325
- * @param string $field Field name.
1326
- * @param array $email_data Email data.
1327
- *
1328
- * @return string Content.
1329
- */
1330
- protected function handle_user_confirmed_action_notification( $notification_name, $field, $email_data ) {
1331
- $notifications = $this->notifier->get_notifications( $notification_name );
1332
- if ( count( $notifications ) > 0 ) {
1333
- // Ideally there should be only one notification for this type.
1334
- // If there are multiple notification then we will read data about only the last one
1335
- $setting = $this->notifier->read_settings( end( $notifications )->ID );
1336
-
1337
- return $this->engine->handle_user_confirmed_action_email_shortcodes( $setting[ $field ], $setting, $email_data );
1338
- }
1339
-
1340
- return '';
1341
- }
1342
-
1343
- /**
1344
- * Is this a metabox request?
1345
- *
1346
- * Block editor sends duplicate requests on post update.
1347
- *
1348
- * @return bool True if metabox request, False otherwise.
1349
- */
1350
- protected function is_metabox_request() {
1351
- return ( isset( $_GET['meta-box-loader'] ) || isset( $_GET['meta_box'] ) );
1352
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1353
  }
1354
 
1355
  /* ------------------------------------------------------------------------ *
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.5
8
  * Requires at least: 4.8
9
  * Requires PHP: 5.6
10
  * Author: Made with Fuel
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.
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 ) {
</