PluginProbe
Customize WordPress Emails and Alerts – Better Notifications for WP / 1.6.12
Customize WordPress Emails and Alerts – Better Notifications for WP v1.6.12
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.6.12, at bnfw.php

777 lines 22.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Better Notifications for WordPress
4 * Plugin URI: https://wordpress.org/plugins/bnfw/
5 * Description: Supercharge your WordPress notifications using a WYSIWYG editor and shortcodes. Default and new notifications available. Add more power with Add-ons.
6 * Version: 1.6.12
7 * Author: Made with Fuel
8 * Author URI: https://betternotificationsforwp.com/
9 * Author Email: hello@betternotificationsforwp.com
10 * License: GPLv2 or later
11 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
12 * Text Domain: bnfw
13 * Domain Path: /languages
14 */
15
16 /**
17 * Copyright © 2018 Made with Fuel Ltd. (hello@betternotificationsforwp.com)
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License, version 2, as
20 * published by the Free Software Foundation.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30 class BNFW {
31
32 /**
33 * Constructor.
34 *
35 * @since 1.0
36 */
37 function __construct() {
38 $this->load_textdomain();
39 $this->includes();
40 $this->hooks();
41
42 /**
43 * BNFW Notification.
44 *
45 * @var \BNFW_Notification
46 */
47 $this->notifier = new BNFW_Notification;
48
49 /**
50 * BNFW Engine.
51 *
52 * @var \BNFW_Engine
53 */
54 $this->engine = new BNFW_Engine;
55 }
56
57 /**
58 * Factory method to return the instance of the class.
59 *
60 * Makes sure that only one instance is created.
61 *
62 * @return \BNFW Instance of the class.
63 */
64 public static function factory() {
65 static $instance = false;
66 if ( ! $instance ) {
67 $instance = new self();
68 }
69 return $instance;
70 }
71
72 /**
73 * Loads the plugin language files
74 *
75 * @since 1.0
76 */
77 public function load_textdomain() {
78 // Load localization domain
79 $this->translations = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
80 load_plugin_textdomain( 'bnfw', false, $this->translations );
81 }
82
83 /**
84 * Include required files.
85 *
86 * @since 1.0
87 */
88 public function includes() {
89
90 // Load license related classes
91 if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
92 require_once 'includes/libraries/EDD_SL_Plugin_Updater.php';
93 }
94
95 require_once 'vendor/persist-admin-notices-dismissal/persist-admin-notices-dismissal.php';
96
97 require_once 'includes/license/class-bnfw-license.php';
98 require_once 'includes/license/class-bnfw-license-setting.php';
99
100 // Load Engine
101 require_once 'includes/engine/class-bnfw-engine.php';
102 require_once 'includes/overrides.php';
103
104 // Load notification post type and notification helpers
105 require_once 'includes/admin/class-bnfw-notification.php';
106 require_once 'includes/notification/post-notification.php';
107
108 // Helpers
109 require_once 'includes/helpers/helpers.php';
110 require_once 'includes/helpers/ajax-helpers.php';
111
112 // Load Admin Pages
113 if ( is_admin() ) {
114 require_once 'includes/admin/bnfw-settings.php';
115 }
116 }
117
118 /**
119 * Register Hooks.
120 *
121 * @since 1.0
122 */
123 public function hooks() {
124 global $wp_version;
125
126 register_activation_hook( __FILE__, array( $this, 'activate' ) );
127
128 add_action( 'admin_init', array( 'PAnD', 'init' ) );
129 add_action( 'admin_init', array( $this, 'add_capability_to_admin' ) );
130
131 add_action( 'draft_to_private' , array( $this, 'private_post' ) );
132 add_action( 'future_to_private' , array( $this, 'private_post' ) );
133 add_action( 'pending_to_private' , array( $this, 'private_post' ) );
134 add_action( 'publish_to_private' , array( $this, 'private_post' ) );
135
136 add_action( 'wp_insert_post' , array( $this, 'insert_post' ), 10, 2 );
137
138 add_action( 'draft_to_publish' , array( $this, 'publish_post' ) );
139 add_action( 'future_to_publish' , array( $this, 'publish_post' ) );
140 add_action( 'pending_to_publish' , array( $this, 'publish_post' ) );
141 add_action( 'private_to_publish' , array( $this, 'publish_post' ) );
142 add_action( 'acf/submit_form' , array( $this, 'acf_submit_form' ), 10, 2 );
143
144 add_action( 'publish_to_publish' , array( $this, 'update_post' ) );
145 add_action( 'private_to_private' , array( $this, 'update_post' ) );
146
147 add_action( 'init' , array( $this, 'custom_post_type_hooks' ), 100 );
148 add_action( 'create_term' , array( $this, 'create_term' ), 10, 3 );
149
150 add_action( 'comment_post' , array( $this, 'comment_post' ) );
151 add_action( 'trackback_post' , array( $this, 'trackback_post' ) );
152 add_action( 'pingback_post' , array( $this, 'pingback_post' ) );
153
154 add_action( 'user_register' , array( $this, 'user_register' ) );
155 add_action( 'user_register' , array( $this, 'welcome_email' ) );
156 add_action( 'set_user_role' , array( $this, 'user_role_changed' ), 10, 3 );
157
158 if ( version_compare( $wp_version, '4.4', '>=' ) ) {
159 add_filter( 'retrieve_password_title', array( $this, 'change_password_email_title' ), 10, 3 );
160 } else {
161 add_filter( 'retrieve_password_title', array( $this, 'change_password_email_title' ) );
162 }
163 add_action( 'lostpassword_post' , array( $this, 'on_lost_password' ) );
164 add_filter( 'retrieve_password_message' , array( $this, 'change_password_email_message' ), 10, 4 );
165
166 add_action( 'after_password_reset' , array( $this, 'on_password_reset' ) );
167 add_filter( 'password_change_email' , array( $this, 'on_password_changed' ), 10, 2 );
168 add_filter( 'email_change_email' , array( $this, 'on_email_changed' ), 10, 2 );
169
170 add_filter( 'auto_core_update_email' , array( $this, 'on_core_updated' ), 10, 4 );
171
172 add_filter( 'plugin_action_links' , array( $this, 'plugin_action_links' ), 10, 4 );
173 add_action( 'shutdown' , array( $this, 'on_shutdown' ) );
174 }
175
176 /**
177 * Add 'bnfw' capability to admin.
178 */
179 public function add_capability_to_admin() {
180 $admins = get_role( 'administrator' );
181
182 if ( ! $admins->has_cap( 'bnfw' ) ) {
183 $admins->add_cap( 'bnfw' );
184 }
185 }
186
187 /**
188 * Setup hooks for custom post types.
189 *
190 * @since 1.2
191 */
192 function custom_post_type_hooks() {
193 $post_types = get_post_types( array( 'public' => true ), 'names' );
194 $post_types = array_diff( $post_types, array( BNFW_Notification::POST_TYPE ) );
195
196 foreach ( $post_types as $post_type ) {
197 add_action( 'pending_' . $post_type, array( $this, 'on_post_pending' ), 10, 2 );
198 add_action( 'future_' . $post_type, array( $this, 'on_post_scheduled' ), 10, 2 );
199 }
200 }
201
202 /**
203 * importer
204 */
205 public function activate() {
206 require_once dirname( __FILE__ ) . '/includes/import.php';
207 $importer = new BNFW_Import;
208 $importer->import();
209 }
210
211 /**
212 * Add 'Settings' link below BNFW in Plugins list.
213 *
214 * @since 1.0
215 * @param unknown $links
216 * @param unknown $file
217 * @return unknown
218 */
219 public function plugin_action_links( $links, $file ) {
220 $plugin_file = 'bnfw/bnfw.php';
221 if ( $file == $plugin_file ) {
222 $settings_link = '<a href="' . esc_url( admin_url( 'edit.php?post_type=bnfw_notification&page=bnfw-settings' ) ) . '">' . esc_html__( 'Settings', 'bnfw' ) . '</a>';
223 array_unshift( $links, $settings_link );
224 }
225 return $links;
226 }
227
228 /**
229 * When a new term is created.
230 *
231 * @since 1.0
232 * @param int $term_id
233 * @param int $tt_id
234 * @param string $taxonomy
235 */
236 public function create_term( $term_id, $tt_id, $taxonomy ) {
237 $this->send_notification( 'newterm-' . $taxonomy, $term_id );
238 }
239
240 /**
241 * Fires when a post is created for the first time.
242 *
243 * @since 1.3.1
244 * @param int $post_id Post ID
245 * @param object $post Post object
246 */
247 public function insert_post( $post_id, $post ) {
248 // Some themes like P2, directly insert posts into DB.
249 $insert_post_themes = apply_filters( 'bnfw_insert_post_themes', array( 'P2', 'Syncope' ) );
250 $current_theme = wp_get_theme();
251
252 /**
253 * Whether to trigger insert post hook.
254 *
255 * @since 1.4
256 */
257 $trigger_insert_post = apply_filters( 'bnfw_trigger_insert_post', false );
258
259 if ( in_array( $current_theme->get( 'Name' ), $insert_post_themes ) || $trigger_insert_post ) {
260 $this->handle_inserted_post( $post_id );
261 }
262 }
263
264 /**
265 * Trigger New Post published notification for ACF forms.
266 *
267 * @param string $form ACF Form.
268 * @param int $post_id Post ID.
269 */
270 public function acf_submit_form( $form, $post_id ) {
271 $this->handle_inserted_post( $post_id );
272 }
273
274 /**
275 * Trigger correct notifications for inserted posts.
276 *
277 * @since 1.6.7
278 *
279 * @param int $post_id Post id.
280 */
281 private function handle_inserted_post( $post_id ) {
282 $post = get_post( $post_id );
283
284 if ( ! is_a( $post, 'WP_Post' ) ) {
285 return;
286 }
287
288 switch ( $post->post_status ) {
289 case 'publish':
290 $this->publish_post( $post );
291 break;
292
293 case 'private':
294 $this->private_post( $post );
295 break;
296
297 case 'pending':
298 $this->on_post_pending( $post_id, $post );
299 break;
300
301 case 'future':
302 $this->on_post_scheduled( $post_id, $post );
303 break;
304 }
305 }
306
307 /**
308 * Fires when a post is created for the first time.
309 *
310 * @since 1.0
311 * @param object $post Post Object
312 */
313 function publish_post( $post ) {
314 $post_id = $post->ID;
315 $post_type = $post->post_type;
316
317 if ( BNFW_Notification::POST_TYPE != $post_type ) {
318 $this->send_notification_async( 'new-' . $post_type, $post_id );
319 }
320 }
321
322 /**
323 * Fires when a private post is created.
324 *
325 * @since 1.6
326 * @param object $post Post Object
327 */
328 public function private_post( $post ) {
329 $post_id = $post->ID;
330 $post_type = $post->post_type;
331
332 if ( BNFW_Notification::POST_TYPE != $post_type ) {
333 $this->send_notification_async( 'private-' . $post_type, $post_id );
334 }
335 }
336
337 /**
338 * Fires when a post is updated.
339 *
340 * @since 1.0
341 * @param unknown $post
342 */
343 function update_post( $post ) {
344 $post_id = $post->ID;
345 $post_type = $post->post_type;
346
347 if ( BNFW_Notification::POST_TYPE != $post_type ) {
348 $this->send_notification_async( 'update-' . $post_type, $post_id );
349 }
350 }
351
352 /**
353 * Fires when a post is pending for review.
354 *
355 * @since 1.1
356 * @param int $post_id Post ID
357 * @param object $post Post object
358 */
359 function on_post_pending( $post_id, $post ) {
360 $post_type = $post->post_type;
361
362 if ( BNFW_Notification::POST_TYPE != $post_type ) {
363 $this->send_notification_async( 'pending-' . $post_type, $post_id );
364 }
365 }
366
367 /**
368 * Fires when a post is scheduled.
369 *
370 * @since 1.1.5
371 * @param int $post_id Post ID
372 * @param object $post Post object
373 */
374 function on_post_scheduled( $post_id, $post ) {
375 $post_type = $post->post_type;
376
377 if ( BNFW_Notification::POST_TYPE != $post_type ) {
378 $this->send_notification_async( 'future-' . $post_type, $post_id );
379 }
380 }
381
382 /**
383 * Send notification for new comments
384 *
385 * @since 1.0
386 * @param int $comment_id
387 */
388 function comment_post( $comment_id ) {
389 $the_comment = get_comment( $comment_id );
390 if ( $this->can_send_comment_notification( $the_comment ) ) {
391 $post = get_post( $the_comment->comment_post_ID );
392 $notification_type = 'new-comment'; // old notification name
393 if ( 'post' != $post->post_type ) {
394 $notification_type = 'comment-' . $post->post_type;
395 }
396 $this->send_notification( $notification_type, $comment_id );
397
398 // comment reply notification.
399 if ( $the_comment->comment_parent > 0 ) {
400 $notification_type = 'reply-comment'; // old notification name
401 if ( 'post' != $post->post_type ) {
402 $notification_type = 'commentreply-' . $post->post_type;
403 }
404 $notifications = $this->notifier->get_notifications( $notification_type );
405 if ( count( $notifications ) > 0 ) {
406 $parent = get_comment( $the_comment->comment_parent );
407 if ( $parent->comment_author_email != $the_comment->comment_author_email ) {
408 foreach ( $notifications as $notification ) {
409 $this->engine->send_comment_reply_email( $this->notifier->read_settings( $notification->ID ), $the_comment, $parent );
410 }
411 }
412 }
413 }
414 }
415 }
416
417 /**
418 * Send notification for new trackback
419 *
420 * @since 1.0
421 * @param unknown $comment_id
422 */
423 function trackback_post( $comment_id ) {
424 $the_comment = get_comment( $comment_id );
425 if ( $this->can_send_comment_notification( $the_comment ) ) {
426 $this->send_notification( 'new-trackback', $comment_id );
427 }
428 }
429
430 /**
431 * Send notification for new pingbacks
432 *
433 * @since 1.0
434 * @param unknown $comment_id
435 */
436 function pingback_post( $comment_id ) {
437 $the_comment = get_comment( $comment_id );
438 if ( $this->can_send_comment_notification( $the_comment ) ) {
439 $this->send_notification( 'new-pingback', $comment_id );
440 }
441 }
442
443 /**
444 * Send notification for lost password.
445 *
446 * @since 1.0
447 */
448 function on_lost_password() {
449 $user_login = sanitize_text_field( $_POST['user_login'] );
450 $user = get_user_by( 'login', $user_login );
451 if ( $user ) {
452 $this->send_notification( 'admin-password', $user->ID );
453 }
454 }
455
456 /**
457 * Change the title of the password reset email that is sent to the user.
458 *
459 * @since 1.1
460 *
461 * @param string $title
462 * @param string $user_login
463 * @param string $user_data
464 *
465 * @return string
466 */
467 public function change_password_email_title( $title, $user_login = '', $user_data = '' ) {
468 $notifications = $this->notifier->get_notifications( 'user-password' );
469 if ( count( $notifications ) > 0 ) {
470 // Ideally there should be only one notification for this type.
471 // If there are multiple notification then we will read data about only the last one
472 $setting = $this->notifier->read_settings( end( $notifications )->ID );
473
474 if ( '' === $user_data ) {
475 return $this->engine->handle_shortcodes( $setting['subject'], 'user-password', $user_data->ID );
476 } else {
477 return $setting['subject'];
478 }
479 }
480
481 return $title;
482 }
483
484 /**
485 * Change the message of the password reset email.
486 *
487 * @since 1.1
488 *
489 * @param string $message
490 * @param string $key
491 * @param string $user_login
492 * @param string $user_data
493 *
494 * @return string
495 */
496 public function change_password_email_message( $message, $key, $user_login = '', $user_data = '' ) {
497 $notifications = $this->notifier->get_notifications( 'user-password' );
498 if ( count( $notifications ) > 0 ) {
499 // Ideally there should be only one notification for this type.
500 // If there are multiple notification then we will read data about only the last one
501 $setting = $this->notifier->read_settings( end( $notifications )->ID );
502
503 $message = $this->engine->handle_password_reset_shortcodes( $setting, $key, $user_login, $user_data );
504
505 if ( 'html' == $setting['email-formatting'] ) {
506 add_filter( 'wp_mail_content_type', array( $this, 'set_html_content_type' ) );
507 $message = wpautop( $message );
508 } else {
509 add_filter( 'wp_mail_content_type', array( $this, 'set_text_content_type' ) );
510 }
511 } else {
512 if ( $this->notifier->notification_exists( 'user-password', false ) ) {
513 // disabled notification exists, so disable the email by returning empty string.
514 return '';
515 }
516 }
517
518 return $message;
519 }
520
521 /**
522 * On Password reset.
523 *
524 * @param WP_User $user User who's password was changed.
525 */
526 public function on_password_reset( $user ) {
527 $notifications = $this->notifier->get_notifications( 'password-changed' );
528 foreach ( $notifications as $notification ) {
529 $this->engine->send_password_changed_email( $this->notifier->read_settings( $notification->ID ), $user );
530 }
531 }
532
533 /**
534 * On Password Changed.
535 *
536 * @since 1.6
537 *
538 * @param array $email_data Email Data.
539 * @param array $user User data.
540 *
541 * @return array Modified Email Data
542 */
543 public function on_password_changed( $email_data, $user ) {
544 return $this->handle_filtered_data_notification( 'password-changed', $email_data, $user['ID'] );
545 }
546
547 /**
548 * On Email Changed.
549 *
550 * @since 1.6
551 *
552 * @param array $email_data Email Data.
553 * @param array $user User data.
554 *
555 * @return array Modified Email Data
556 */
557 public function on_email_changed( $email_data, $user ) {
558 return $this->handle_filtered_data_notification( 'email-changed', $email_data, $user['ID'] );
559 }
560
561 /**
562 * Send notification on core updated event.
563 *
564 * @since 1.6
565 *
566 * @param array $email_data Email Data.
567 * @param string $type The type of email being sent. Can be one of
568 * 'success', 'fail', 'manual', 'critical'.
569 * @param object $core_update The update offer that was attempted.
570 * @param mixed $result The result for the core update. Can be WP_Error.
571 *
572 * @return array Modified Email Data.
573 */
574 public function on_core_updated( $email_data, $type, $core_update, $result ) {
575 $notifications = $this->notifier->get_notifications( 'core-updated' );
576 if ( count( $notifications ) > 0 ) {
577 // Ideally there should be only one notification for this type.
578 // If there are multiple notification then we will read data about only the last one
579 $setting = $this->notifier->read_settings( end( $notifications )->ID );
580
581 $email_data = $this->engine->handle_core_updated_notification( $email_data, $setting, $type );
582 }
583
584 return $email_data;
585 }
586
587 /**
588 * Process User update notifications.
589 *
590 * @since 1.6
591 *
592 * @param string $notification_name Notification Name.
593 * @param array $email_data Email Data.
594 * @param string|int $extra_data User Id.
595 *
596 * @return array Modified Email Data.
597 */
598 private function handle_filtered_data_notification( $notification_name, $email_data, $extra_data ) {
599 $notifications = $this->notifier->get_notifications( $notification_name );
600 if ( count( $notifications ) > 0 ) {
601 // Ideally there should be only one notification for this type.
602 // If there are multiple notification then we will read data about only the last one
603 $setting = $this->notifier->read_settings( end( $notifications )->ID );
604
605 $email_data = $this->engine->handle_filtered_data_notification( $email_data, $setting, $extra_data );
606 }
607
608 return $email_data;
609 }
610
611 /**
612 * Set the email formatting to HTML.
613 *
614 * @since 1.4
615 */
616 public function set_html_content_type() {
617 return 'text/html';
618 }
619
620 /**
621 * Set the email formatting to text.
622 *
623 * @since 1.4
624 */
625 public function set_text_content_type() {
626 return 'text/plain';
627 }
628
629 /**
630 * Send notification for new users.
631 *
632 * @since 1.0
633 * @param int $user_id
634 */
635 function user_register( $user_id ) {
636 $this->send_notification( 'admin-user', $user_id );
637 }
638
639 /**
640 * New User - Post-registration Email
641 *
642 * @since 1.1
643 * @param int $user_id New user id
644 */
645 public function welcome_email( $user_id ) {
646 $notifications = $this->notifier->get_notifications( 'welcome-email' );
647 foreach ( $notifications as $notification ) {
648 $this->engine->send_registration_email( $this->notifier->read_settings( $notification->ID ), get_userdata( $user_id ) );
649 }
650 }
651
652 /**
653 * Send notification when a user role changes.
654 *
655 * @since 1.3.9
656 *
657 * @param int $user_id User ID
658 * @param string $new_role New User role
659 * @param array $old_roles Old User role
660 */
661 public function user_role_changed( $user_id, $new_role, $old_roles ) {
662 if ( ! empty( $old_roles ) ) {
663 $notifications = $this->notifier->get_notifications( 'user-role' );
664 foreach ( $notifications as $notification ) {
665
666 /**
667 * Trigger User Role Changed - For User notification.
668 *
669 * @since 1.6.5
670 */
671 if ( apply_filters( 'bnfw_trigger_user-role_notification', true, $notification, $new_role, $old_roles ) ) {
672 $this->engine->send_user_role_changed_email(
673 $this->notifier->read_settings( $notification->ID ),
674 $user_id,
675 $old_roles[0],
676 $new_role
677 );
678 }
679 }
680
681 $notifications = $this->notifier->get_notifications( 'admin-role' );
682 foreach ( $notifications as $notification ) {
683
684 /**
685 * Trigger User Role Changed - For User notification.
686 *
687 * @since 1.6.5
688 */
689 if ( apply_filters( 'bnfw_trigger_admin-role_notification', true, $notification, $new_role, $old_roles ) ) {
690 $setting = $this->notifier->read_settings( $notification->ID );
691 $setting['message'] = $this->engine->handle_user_role_shortcodes( $setting['message'], $old_roles[0], $new_role );
692 $setting['subject'] = $this->engine->handle_user_role_shortcodes( $setting['subject'], $old_roles[0], $new_role );
693
694 $this->engine->send_notification( $setting, $user_id );
695 }
696 }
697 }
698 }
699
700 /**
701 * Send notification based on type and ref id
702 *
703 * @access private
704 * @since 1.0
705 * @param string $type Notification type.
706 * @param int $ref_id Reference id.
707 */
708 private function send_notification( $type, $ref_id ) {
709 $notifications = $this->notifier->get_notifications( $type );
710 foreach ( $notifications as $notification ) {
711 $this->engine->send_notification( $this->notifier->read_settings( $notification->ID ), $ref_id );
712 }
713 }
714
715 /**
716 * Send notification async based on type and ref id.
717 *
718 * @access private
719 * @param string $type Notification type.
720 * @param int $ref_id Reference id.
721 */
722 private function send_notification_async( $type, $ref_id ) {
723 $notifications = $this->notifier->get_notifications( $type, false );
724 foreach ( $notifications as $notification ) {
725 $transient = get_transient( 'bnfw-async-notifications' );
726 if ( ! is_array( $transient ) ) {
727 $transient = array();
728 }
729
730 $transient[] = array( 'ref_id' => $ref_id, 'notification_id' => $notification->ID, 'notification_type' => $type );
731 set_transient( 'bnfw-async-notifications', $transient, 600 );
732 }
733 }
734
735 /**
736 * Can send comment notification or not
737 *
738 * @since 1.0
739 * @param unknown $comment
740 * @return unknown
741 */
742 private function can_send_comment_notification( $comment ) {
743 // Returns false if the comment is marked as spam AND admin has enabled suppression of spam
744 $suppress_spam = get_option( 'bnfw_suppress_spam' );
745 if ( '1' === $suppress_spam && ( 0 === strcmp( $comment->comment_approved, 'spam' ) ) ) {
746 return false;
747 }
748 return true;
749 }
750
751 /**
752 * Send notification emails on shutdown.
753 */
754 public function on_shutdown() {
755 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
756 return;
757 }
758
759 $transient = get_transient( 'bnfw-async-notifications' );
760 if ( is_array( $transient ) ) {
761 delete_transient( 'bnfw-async-notifications' );
762 foreach ( $transient as $id_pairs ) {
763 $this->engine->send_notification( $this->notifier->read_settings( $id_pairs['notification_id'] ), $id_pairs['ref_id'] );
764 }
765 }
766 }
767 }
768
769 if ( ! is_multisite() ) {
770 require_once 'includes/freemius.php';
771 }
772
773 /* ------------------------------------------------------------------------ *
774 * Fire up the plugin
775 * ------------------------------------------------------------------------ */
776 BNFW::factory();
777