PluginProbe
Customize WordPress Emails and Alerts – Better Notifications for WP / 1.8.7
Customize WordPress Emails and Alerts – Better Notifications for WP v1.8.7
1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.8 1.8.1 1.8.10 1.8.11 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 All 81 releases
bnfw / bnfw.php

bnfw.php in Customize WordPress Emails and Alerts – Better Notifications for WP 1.8.7, at bnfw.php

1,520 lines 54.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.7
8 * Requires at least: 4.8
9 * Requires PHP: 7.0
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 © 2022 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,
1049 $new_role
1050 );
1051 }
1052 }
1053
1054 $notifications_admin = $this->notifier->get_notifications( 'admin-role' );
1055 foreach ( $notifications_admin as $notification ) {
1056 if ( apply_filters( 'bnfw_trigger_admin-role_notification', true, $notification, $new_role, null ) ) {
1057 $setting = $this->notifier->read_settings( $notification->ID );
1058 $setting[ 'message' ] = $this->engine->handle_user_role_shortcodes( $setting[ 'message' ], null, $new_role );
1059 $setting[ 'subject' ] = $this->engine->handle_user_role_shortcodes( $setting[ 'subject' ], null, $new_role );
1060
1061 $this->engine->send_notification( $setting, $user_id );
1062 }
1063 }
1064
1065 }
1066
1067 /**
1068 * Send notification when a user role removed through Members Plugin.
1069 *
1070 * @since 1.8.4
1071 *
1072 * @param int $user_id User ID
1073 * @param string $old_role New User role
1074 *
1075 */
1076 public function user_role_removed_from_member_plugin($user_id, $old_role){
1077 global $pagenow;
1078
1079 if($pagenow != 'users.php')
1080 return;
1081
1082 if(!$user_id)
1083 return;
1084
1085 $notifications = $this->notifier->get_notifications( 'user-role' );
1086
1087 foreach ( $notifications as $notification ) {
1088 if ( apply_filters( 'bnfw_trigger_user-role_notification', true, $notification, null, array($old_role) ) ) {
1089 $this->engine->send_user_role_changed_email(
1090 $this->notifier->read_settings( $notification->ID ),
1091 $user_id,
1092 $old_role,
1093 null
1094 );
1095 }
1096 }
1097
1098 $notifications_admin = $this->notifier->get_notifications( 'admin-role' );
1099 foreach ( $notifications_admin as $notification ) {
1100 if ( apply_filters( 'bnfw_trigger_admin-role_notification', true, $notification, null, array($old_role) ) ) {
1101 $setting = $this->notifier->read_settings( $notification->ID );
1102 $setting[ 'message' ] = $this->engine->handle_user_role_shortcodes( $setting[ 'message' ], $old_role, null );
1103 $setting[ 'subject' ] = $this->engine->handle_user_role_shortcodes( $setting[ 'subject' ], $old_role, null );
1104
1105
1106
1107 $this->engine->send_notification( $setting, $user_id );
1108 }
1109 }
1110
1111 }
1112
1113 /**
1114 * Send notification when a user role added support User Role Editor by Members Plugin.
1115 *
1116 * @since 1.3.9
1117 *
1118 * @param int $user_id User ID
1119 * @param string $new_role New User role
1120 * @param array $old_roles Old User role
1121 */
1122 public function user_role_added( $user_id, $old_user_data ) {
1123
1124 if ( isset( $_POST[ 'members_user_roles' ] ) && ! empty( $_POST[ 'members_user_roles' ] ) ) {
1125 // Get the current user roles.
1126 $old_roles = (array) $old_user_data->roles;
1127
1128 // Sanitize the posted roles.
1129 $new_roles = array_map( 'members_sanitize_role', $_POST[ 'members_user_roles' ] );
1130
1131 sort( $old_roles );
1132 sort( $new_roles );
1133 $old_roles_str = implode( '', $old_roles );
1134 $new_roles_str = implode( '', $new_roles );
1135 if ( ! empty( $old_roles ) && $old_roles_str !== $new_roles_str ) {
1136 $notifications = $this->notifier->get_notifications( 'user-role' );
1137 foreach ( $notifications as $notification ) {
1138
1139 /**
1140 * Trigger User Role Changed - For User notification.
1141 *
1142 * @since 1.6.5
1143 */
1144 if ( apply_filters( 'bnfw_trigger_user-role-added_notification', true, $notification, $new_roles, $old_roles ) ) {
1145 $this->engine->send_user_role_added_email(
1146 $this->notifier->read_settings( $notification->ID ),
1147 $user_id,
1148 $old_roles,
1149 $new_roles
1150 );
1151 }
1152 }
1153
1154 $notifications = $this->notifier->get_notifications( 'admin-role' );
1155 foreach ( $notifications as $notification ) {
1156
1157 /**
1158 * Trigger User Role Changed - For User notification.
1159 *
1160 * @since 1.6.5
1161 */
1162 if ( apply_filters( 'bnfw_trigger_user-role-added_notification', true, $notification, $new_roles, $old_roles ) ) {
1163 $setting = $this->notifier->read_settings( $notification->ID );
1164 $setting[ 'message' ] = $this->engine->handle_user_added_role_shortcodes( $setting[ 'message' ], $old_roles, $new_roles );
1165 $setting[ 'subject' ] = $this->engine->handle_user_added_role_shortcodes( $setting[ 'subject' ], $old_roles, $new_roles );
1166
1167 $this->engine->send_notification( $setting, $user_id );
1168 }
1169 }
1170 }
1171 }
1172 }
1173
1174 /**
1175 * Sanitizes a role name. This is a wrapper for the `sanitize_key()` WordPress function. Only
1176 * alphanumeric characters and underscores are allowed. Hyphens are also replaced with underscores.
1177 *
1178 * @since 1.0.0
1179 * @access public
1180 * @return int
1181 */
1182 function members_sanitize_role( $role ) {
1183
1184 $_role = strtolower( $role );
1185 $_role = preg_replace( '/[^a-z0-9_\-\s]/', '', $_role );
1186
1187 return apply_filters( 'members_sanitize_role', str_replace( ' ', '_', $_role ), $role );
1188 }
1189
1190 /**
1191 * Send notification based on type and ref id
1192 *
1193 * @since 1.0
1194 * @param string $type Notification type.
1195 * @param mixed $ref_id Reference data.
1196 */
1197 public function send_notification( $type, $ref_id, $include_disabled = true ) {
1198 $notifications = $this->notifier->get_notifications( $type , $include_disabled);
1199 foreach ( $notifications as $notification ) {
1200 $this->engine->send_notification( $this->notifier->read_settings( $notification->ID ), $ref_id );
1201 }
1202 }
1203
1204 /**
1205 * Send notification async based on type and ref id.
1206 *
1207 * @param string $type Notification type.
1208 * @param mixed $ref_id Reference data.
1209 */
1210 public function send_notification_async( $type, $ref_id ) {
1211 $notifications = $this->notifier->get_notifications( $type, false );
1212 foreach ( $notifications as $notification ) {
1213 $transient = get_transient( 'bnfw-async-notifications' );
1214 if ( ! is_array( $transient ) ) {
1215 $transient = array();
1216 }
1217
1218 $notification_data = array(
1219 'ref_id' => $ref_id,
1220 'notification_id' => $notification->ID,
1221 'notification_type' => $type,
1222 );
1223
1224 if ( ! in_array( $notification_data, $transient ) ) {
1225 $transient[] = $notification_data;
1226 set_transient( 'bnfw-async-notifications', $transient, 600 );
1227 }
1228 }
1229 }
1230
1231 /**
1232 * Can send comment notification or not
1233 *
1234 * @since 1.0
1235 * @param unknown $comment
1236 * @return unknown
1237 */
1238 private function can_send_comment_notification( $comment ) {
1239 // Returns false if the comment is marked as spam AND admin has enabled suppression of spam
1240 $suppress_spam = get_option( 'bnfw_suppress_spam' );
1241 if ( '1' === $suppress_spam && ( 0 === strcmp( $comment->comment_approved, 'spam' ) ) ) {
1242 return false;
1243 }
1244 return true;
1245 }
1246
1247 /**
1248 * Handle user request email content.
1249 *
1250 * @param string $content Content.
1251 * @param array $email_data Email data.
1252 *
1253 * @return string Modified content.
1254 */
1255 public function handle_user_request_email_content( $content, $email_data ) {
1256 $field = 'message';
1257 $new_content = '';
1258
1259 switch ( $email_data[ 'description' ] ) {
1260 case 'Export Personal Data':
1261 $notification_name = 'ca-export-data';
1262 $new_content = $this->handle_user_request_notification( $notification_name, $field, $email_data );
1263 break;
1264 case 'Erase Personal Data':
1265 $notification_name = 'ca-erase-data';
1266 $new_content = $this->handle_user_request_notification( $notification_name, $field, $email_data );
1267 break;
1268 }
1269
1270 if ( ! empty( $new_content ) ) {
1271 return $new_content;
1272 } else {
1273 return $content;
1274 }
1275 }
1276
1277 /**
1278 * Handle user request email subject.
1279 *
1280 * @param string $subject Subject
1281 * @param string $blogname Blog name
1282 * @param array $email_data Email data.
1283 *
1284 * @return string Modified subject.
1285 */
1286 public function handle_user_request_email_subject( $subject, $blogname,
1287 $email_data ) {
1288 $field = 'subject';
1289 $new_subject = '';
1290
1291 switch ( $email_data[ 'description' ] ) {
1292 case 'Export Personal Data':
1293 $notification_name = 'ca-export-data';
1294 $new_subject = $this->handle_user_request_notification( $notification_name, $field, $email_data );
1295 break;
1296 case 'Erase Personal Data':
1297 $notification_name = 'ca-erase-data';
1298 $new_subject = $this->handle_user_request_notification( $notification_name, $field, $email_data );
1299 break;
1300 }
1301 if ( ! empty( $new_subject ) ) {
1302 return $new_subject;
1303 } else {
1304 return $subject;
1305 }
1306 }
1307
1308 /**
1309 * Handle user confirmed action email content.
1310 *
1311 * @param string $content Content.
1312 * @param array $email_data Email data.
1313 *
1314 * @return string Modified content.
1315 */
1316 public function handle_user_confirmed_action_email_content( $content,
1317 $email_data ) {
1318 $field = 'message';
1319 $new_content = '';
1320
1321 switch ( $email_data[ 'description' ] ) {
1322 case 'Export Personal Data':
1323 $notification_name = 'uc-export-data';
1324 $new_content = $this->handle_user_confirmed_action_notification( $notification_name, $field, $email_data );
1325 break;
1326 case 'Erase Personal Data':
1327 $notification_name = 'uc-erase-data';
1328 $new_content = $this->handle_user_confirmed_action_notification( $notification_name, $field, $email_data );
1329 break;
1330 }
1331
1332 if ( ! empty( $new_content ) ) {
1333 return $new_content;
1334 } else {
1335 return $content;
1336 }
1337 }
1338
1339 /**
1340 * Handle data exported email content.
1341 *
1342 * @param string $content Content.
1343 * @param int $request_id
1344 *
1345 * @return string Modified content.
1346 */
1347 public function handle_data_export_email_content( $content, $request_id,$email_data ) {
1348
1349 $field = 'message';
1350 $notification_name = 'data-export';
1351 $new_content = '';
1352
1353 $notifications = $this->notifier->get_notifications( $notification_name );
1354 if ( count( $notifications ) > 0 ) {
1355 // Ideally there should be only one notification for this type.
1356 // If there are multiple notification then we will read data about only the last one
1357 $setting = $this->notifier->read_settings( end( $notifications )->ID );
1358
1359 $new_content = $this->engine->handle_data_export_email_shortcodes( $setting[ $field ], $setting, $request_id );
1360 $new_content = $this->engine->handle_global_user_shortcodes( $new_content, $email_data['message_recipient'] );
1361 }
1362
1363 if ( ! empty( $new_content ) ) {
1364 return $new_content;
1365 } else {
1366 return $content;
1367 }
1368 }
1369
1370 public function handle_erasure_complete_email_subject( $subject, $sitename,
1371 $email_data ) {
1372 return $this->handle_erasure_complete_email_notification( 'subject', $subject, $email_data );
1373 }
1374
1375 public function handle_erasure_complete_email_content( $content, $email_data ) {
1376 if ( isset( $email_data[ 'privacy_policy_url' ] ) ) {
1377 return $this->handle_erasure_complete_email_notification( 'message', $content, $email_data );
1378 }
1379
1380 return $content;
1381 }
1382
1383 protected function handle_erasure_complete_email_notification( $field,
1384 $content,
1385 $email_data ) {
1386 $notification_name = 'data-erased';
1387 $new_content = '';
1388 $notifications = $this->notifier->get_notifications( $notification_name );
1389 if ( count( $notifications ) > 0 ) {
1390 // Ideally there should be only one notification for this type.
1391 // If there are multiple notification then we will read data about only the last one
1392 $setting = $this->notifier->read_settings( end( $notifications )->ID );
1393 $new_content = $this->engine->handle_shortcodes( $setting[ $field ], $notification_name, $email_data );
1394 }
1395 if ( ! empty( $new_content ) ) {
1396 return $new_content;
1397 } else {
1398 return $content;
1399 }
1400 }
1401
1402 /**
1403 * Send notification emails on shutdown.
1404 */
1405 public function on_shutdown() {
1406 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
1407 return;
1408 }
1409
1410 $transient = get_transient( 'bnfw-async-notifications' );
1411 if ( is_array( $transient ) ) {
1412 delete_transient( 'bnfw-async-notifications' );
1413 foreach ( $transient as $id_pairs ) {
1414 $this->engine->send_notification( $this->notifier->read_settings( $id_pairs[ 'notification_id' ] ), $id_pairs[ 'ref_id' ] );
1415 }
1416 }
1417 }
1418
1419 /**
1420 * Handle user request notification.
1421 *
1422 * @param string $notification_name Notification name.
1423 * @param string $field Field name.
1424 * @param array $email_data Email data.
1425 *
1426 * @return string Content.
1427 */
1428 protected function handle_user_request_notification( $notification_name,
1429 $field, $email_data ) {
1430 $notifications = $this->notifier->get_notifications( $notification_name );
1431 if ( count( $notifications ) > 0 ) {
1432 // Ideally there should be only one notification for this type.
1433 // If there are multiple notification then we will read data about only the last one
1434 $setting = $this->notifier->read_settings( end( $notifications )->ID );
1435
1436 return $this->engine->handle_user_request_email_shortcodes( $setting[ $field ], $setting, $email_data );
1437 }
1438
1439 return '';
1440 }
1441
1442 /**
1443 * Handle user confirmed action notification.
1444 *
1445 * @param string $notification_name Notification name.
1446 * @param string $field Field name.
1447 * @param array $email_data Email data.
1448 *
1449 * @return string Content.
1450 */
1451 protected function handle_user_confirmed_action_notification( $notification_name,
1452 $field,
1453 $email_data ) {
1454 $notifications = $this->notifier->get_notifications( $notification_name );
1455 if ( count( $notifications ) > 0 ) {
1456 // Ideally there should be only one notification for this type.
1457 // If there are multiple notification then we will read data about only the last one
1458 $setting = $this->notifier->read_settings( end( $notifications )->ID );
1459
1460 return $this->engine->handle_user_confirmed_action_email_shortcodes( $setting[ $field ], $setting, $email_data );
1461 }
1462
1463 return '';
1464 }
1465
1466 /**
1467 * Is this a metabox request?
1468 *
1469 * Block editor sends duplicate requests on post update.
1470 *
1471 * @return bool True if metabox request, False otherwise.
1472 */
1473 protected function is_metabox_request() {
1474 return ( isset( $_GET[ 'meta-box-loader' ] ) || isset( $_GET[ 'meta_box' ] ) );
1475 }
1476
1477
1478 /**
1479 * Check if Gutenberg is active.
1480 *
1481 *
1482 * @return bool
1483 * @since 1.3
1484 */
1485 public function is_gutenberg_active() {
1486 $gutenberg = false;
1487 $block_editor = false;
1488
1489 if ( has_filter( 'replace_editor', 'gutenberg_init' ) ) {
1490 // Gutenberg is installed and activated.
1491 $gutenberg = true;
1492 }
1493
1494 if ( version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' ) ) {
1495 // Block editor.
1496 $block_editor = true;
1497 }
1498
1499 if ( ! $gutenberg && ! $block_editor ) {
1500 return false;
1501 }
1502
1503 include_once ABSPATH . 'wp-admin/includes/plugin.php';
1504
1505 if ( ! is_plugin_active( 'classic-editor/classic-editor.php' ) ) {
1506 return true;
1507 }
1508
1509 $use_block_editor = ( get_option( 'classic-editor-replace' ) === 'no-replace' );
1510
1511 return $use_block_editor;
1512 }
1513
1514 }
1515
1516 /* ------------------------------------------------------------------------ *
1517 * Fire up the plugin
1518 * ------------------------------------------------------------------------ */
1519 BNFW::factory();
1520