Skip to:
Content

bbPress.org

Ticket #2797: 2797.01.patch

File 2797.01.patch, 23.9 KB (added by mechter, 6 years ago)

A first patch, tested and works for me

  • includes/common/classes.php

     
    538538        }
    539539}
    540540endif; // class_exists check
     541
     542if ( !class_exists( 'BBP_Subscriber_Notification' ) ) :
     543/**
     544 * Send subscription notification emails via WP Cron
     545 *
     546 * @package bbPress
     547 * @subpackage Classes
     548 *
     549 * @since bbPress (r)
     550 */
     551class BBP_Subscriber_Notification {
     552        public $subject;
     553        public $message;
     554        public $headers;
     555        public $recipients = array();
     556
     557        public function __construct() {
     558                $from = array(
     559                        'name' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ),
     560                        'address' => get_bloginfo( 'admin_email' )
     561                );
     562                $from = apply_filters( 'bbp_subscription_email_from', $from );
     563                $from_string = empty( $from['name'] ) ? $from['address'] : "{$from['name']} <{$from['address']}>";
     564                $this->headers = "From: $from_string\r\n"; // string version $headers needs proper line ending, see wp codex on wp_mail()
     565        }
     566       
     567        /**
     568         * WP Cron callback to send notification emails to subscribers
     569         */
     570        public static function send( $notification ) {
     571                do_action( 'bbp_pre_notify_subscribers' );
     572       
     573                add_action( 'phpmailer_init', array( 'BBP_Subscriber_Notification', 'set_bounce_address' ), 10, 1 );
     574       
     575                foreach ( $notification->recipients as $to ) {
     576                        $to_string = empty( $to['name'] ) ? $to['address'] : "{$to['name']} <{$to['address']}>";
     577                        wp_mail( $to_string, $notification->subject, $notification->message, $notification->headers );
     578                }
     579       
     580                remove_action( 'phpmailer_init', array( 'BBP_Subscriber_Notification', 'set_bounce_address' ), 10, 1 );
     581       
     582                do_action( 'bbp_post_notify_subscribers' );
     583        }
     584       
     585        /**
     586         * Sets PHPMailer::Sender to bounce address, configurable via filter
     587         * Invoke via 'phpmailer_init' action hook
     588         */
     589        public static function set_bounce_address( $phpmailer ) {
     590                $bounce_address = apply_filters( 'bbp_bounce_address', false );
     591                if ( $bounce_address ) {
     592                        $phpmailer->Sender = $bounce_address;
     593                }
     594        }
     595       
     596        /**
     597         * Schedules a sending event with WP Cron
     598         */
     599        public function schedule_sending() {
     600                if ( empty( $this->recipients ) ) {
     601                        return;
     602                }
     603                wp_schedule_single_event( time(), 'bbp_subscription_email_cron', array( $this ) );
     604        }
     605       
     606        /**
     607         * Initializes recipients array from array of recipient user ids
     608         */
     609        protected function init_recipients( $user_ids ) {
     610                if ( empty( $user_ids ) || !is_array( $user_ids ) ) {
     611                        return;
     612                }
     613               
     614                global $wpdb;
     615                $ids_substitution = substr( str_repeat( ',%d', count( $user_ids ) ), 1 );
     616                $params = array_merge( array( "select user_email as address, display_name as name from {$wpdb->users} where ID in ($ids_substitution)" ), $user_ids );
     617                $recipients = $wpdb->get_results( call_user_func_array( array( $wpdb, 'prepare' ), $params ), ARRAY_A );
     618               
     619                $filtered_recipients = apply_filters( 'bbp_subscription_email_recipients', $recipients );
     620               
     621                if ( empty( $filtered_recipients ) || !is_array( $filtered_recipients ) ) {
     622                        return;
     623                }
     624               
     625                $this->recipients = $filtered_recipients;
     626        }
     627}
     628/**
     629 * Forum subscription notification
     630 *
     631 * @package bbPress
     632 * @subpackage Classes
     633 *
     634 * @since bbPress (r)
     635 *
     636 * @uses BBP_Subscriber_Notification
     637 */
     638class BBP_Forum_Subscriber_Notification extends BBP_Subscriber_Notification {
     639
     640        public function __construct( $forum_id, $topic_id ) {
     641                parent::__construct();
     642       
     643                // validation   
     644                $forum_id = bbp_get_forum_id( $forum_id );
     645                $topic_id = bbp_get_topic_id( $topic_id );
     646       
     647                // Remove filters from reply content and topic title to prevent content
     648                // from being encoded with HTML entities, wrapped in paragraph tags, etc...
     649                remove_all_filters( 'bbp_get_topic_content' );
     650                remove_all_filters( 'bbp_get_topic_title'   );
     651       
     652                // collect various pieces of information
     653                $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     654                $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) );
     655                $topic_author_id = bbp_get_topic_author_id( $topic_id );
     656                $topic_author_display_name = bbp_get_topic_author_display_name( $topic_id );
     657                $topic_url = get_permalink( $topic_id );
     658                $topic_content = strip_tags( bbp_get_topic_content( $topic_id ) );
     659               
     660                // subject
     661                $subject = sprintf( __( "[%s Forums] New topic: \"%s\"", 'bbpress' ), $blog_name, $topic_title );
     662                $this->subject = apply_filters( 'bbp_forum_subscription_email_subject', $subject, $forum_id, $topic_id );
     663
     664                // message
     665                $message = sprintf( __( "%s wrote:\r\n\r\n%s\r\n\r\n\r\n-----------------------------------------\r\nRead this post online: %s\r\n\r\nIf you don't want to receive any more email notifications for this forum, please visit the above link and click \"Unsubscribe\" at the top of the page.", 'bbpress' ), $topic_author_display_name, $topic_content, $topic_url );         
     666                $this->message = apply_filters( 'bbp_forum_subscription_email_message', $message, $forum_id, $topic_id );
     667               
     668                // recipients
     669                $user_ids = bbp_get_forum_subscribers( $forum_id, true );
     670                $user_ids = array_diff( $user_ids, array( $topic_author_id ) );
     671                $user_ids = apply_filters( 'bbp_forum_subscription_user_ids', $user_ids );
     672                $this->init_recipients( $user_ids );
     673        }
     674}
     675/**
     676 * Topic subscription notification
     677 *
     678 * @package bbPress
     679 * @subpackage Classes
     680 *
     681 * @since bbPress (r)
     682 *
     683 * @uses BBP_Subscriber_Notification
     684 */
     685class BBP_Topic_Subscriber_Notification extends BBP_Subscriber_Notification {
     686
     687        public function __construct( $forum_id, $topic_id, $reply_id ) {
     688                parent::__construct();
     689               
     690                // validation
     691                $forum_id = bbp_get_forum_id( $forum_id );
     692                $topic_id = bbp_get_topic_id( $topic_id );
     693                $reply_id = bbp_get_reply_id( $reply_id );
     694               
     695                // Remove filters from reply content and topic title to prevent content
     696                // from being encoded with HTML entities, wrapped in paragraph tags, etc...
     697                remove_all_filters( 'bbp_get_reply_content' );
     698                remove_all_filters( 'bbp_get_topic_title'   );
     699               
     700                // collect various pieces of information
     701                $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     702                $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) );
     703                $reply_author_id = bbp_get_reply_author_id( $reply_id );
     704                $reply_author_display_name = bbp_get_reply_author_display_name( $reply_id );
     705                $reply_url = bbp_get_reply_url( $reply_id );
     706                $reply_content = strip_tags( bbp_get_reply_content( $reply_id ) );
     707               
     708                // subject
     709                $subject = sprintf( __( "[%s Forums] New reply to: \"%s\"", 'bbpress' ), $blog_name, $topic_title );
     710                $this->subject = apply_filters( 'bbp_topic_subscription_email_subject', $subject, $forum_id, $topic_id, $reply_id );
     711
     712                // message
     713                $message = sprintf( __( "%s replied:\r\n\r\n%s\r\n\r\n\r\n-----------------------------------------\r\nRead this post online: %s\r\n\r\nIf you don't want to receive any more email notifications for this topic, please visit the above link and click \"Unsubscribe\" at the top of the page.", 'bbpress' ), $reply_author_display_name, $reply_content, $reply_url );
     714                $this->message = apply_filters( 'bbp_topic_subscription_email_message', $message, $forum_id, $topic_id, $reply_id );
     715               
     716                // recipients
     717                $user_ids = bbp_get_topic_subscribers( $topic_id, true );
     718                $user_ids = array_diff( $user_ids, array( $reply_author_id ) );
     719                $user_ids = apply_filters( 'bbp_topic_subscription_user_ids', $user_ids );
     720                $this->init_recipients( $user_ids );
     721        }
     722}
     723endif; // class_exists check
  • includes/common/functions.php

     
    10001000/** Subscriptions *************************************************************/
    10011001
    10021002/**
    1003  * Get the "Do Not Reply" email address to use when sending subscription emails.
    1004  *
    1005  * We make some educated guesses here based on the home URL. Filters are
    1006  * available to customize this address further. In the future, we may consider
    1007  * using `admin_email` instead, though this is not normally publicized.
    1008  *
    1009  * We use `$_SERVER['SERVER_NAME']` here to mimic similar functionality in
    1010  * WordPress core. Previously, we used `get_home_url()` to use already validated
    1011  * user input, but it was causing issues in some installations.
    1012  *
    1013  * @since bbPress (r5409)
    1014  *
    1015  * @see  wp_mail
    1016  * @see  wp_notify_postauthor
    1017  * @link https://bbpress.trac.wordpress.org/ticket/2618
    1018  *
    1019  * @return string
    1020  */
    1021 function bbp_get_do_not_reply_address() {
    1022         $sitename = strtolower( $_SERVER['SERVER_NAME'] );
    1023         if ( substr( $sitename, 0, 4 ) === 'www.' ) {
    1024                 $sitename = substr( $sitename, 4 );
    1025         }
    1026         return apply_filters( 'bbp_get_do_not_reply_address', 'noreply@' . $sitename );
    1027 }
    1028 
    1029 /**
    1030  * Sends notification emails for new replies to subscribed topics
    1031  *
    1032  * Gets new post's ID and check if there are subscribed users to that topic, and
    1033  * if there are, send notifications
    1034  *
    1035  * Note: in bbPress 2.6, we've moved away from 1 email per subscriber to 1 email
    1036  * with everyone BCC'd. This may have negative repercussions for email services
    1037  * that limit the number of addresses in a BCC field (often to around 500.) In
    1038  * those cases, we recommend unhooking this function and creating your own
    1039  * custom emailer script.
    1040  *
    1041  * @since bbPress (r5413)
    1042  *
    1043  * @param int $reply_id ID of the newly made reply
    1044  * @param int $topic_id ID of the topic of the reply
    1045  * @param int $forum_id ID of the forum of the reply
    1046  * @param mixed $anonymous_data Array of anonymous user data
    1047  * @param int $reply_author ID of the topic author ID
    1048  *
    1049  * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
    1050  * @uses bbp_get_reply_id() To validate the reply ID
    1051  * @uses bbp_get_topic_id() To validate the topic ID
    1052  * @uses bbp_get_forum_id() To validate the forum ID
    1053  * @uses bbp_get_reply() To get the reply
    1054  * @uses bbp_is_reply_published() To make sure the reply is published
    1055  * @uses bbp_get_topic_id() To validate the topic ID
    1056  * @uses bbp_get_topic() To get the reply's topic
    1057  * @uses bbp_is_topic_published() To make sure the topic is published
    1058  * @uses bbp_get_reply_author_display_name() To get the reply author's display name
    1059  * @uses do_action() Calls 'bbp_pre_notify_subscribers' with the reply id,
    1060  *                    topic id and user id
    1061  * @uses bbp_get_topic_subscribers() To get the topic subscribers
    1062  * @uses apply_filters() Calls 'bbp_subscription_mail_message' with the
    1063  *                    message, reply id, topic id and user id
    1064  * @uses apply_filters() Calls 'bbp_subscription_mail_title' with the
    1065  *                    topic title, reply id, topic id and user id
    1066  * @uses apply_filters() Calls 'bbp_subscription_mail_headers'
    1067  * @uses get_userdata() To get the user data
    1068  * @uses wp_mail() To send the mail
    1069  * @uses do_action() Calls 'bbp_post_notify_subscribers' with the reply id,
    1070  *                    topic id and user id
    1071  * @return bool True on success, false on failure
    1072  */
    1073 function bbp_notify_topic_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0 ) {
    1074 
    1075         // Bail if subscriptions are turned off
    1076         if ( !bbp_is_subscriptions_active() ) {
    1077                 return false;
    1078         }
    1079 
    1080         /** Validation ************************************************************/
    1081 
    1082         $reply_id = bbp_get_reply_id( $reply_id );
    1083         $topic_id = bbp_get_topic_id( $topic_id );
    1084         $forum_id = bbp_get_forum_id( $forum_id );
    1085 
    1086         /** Topic *****************************************************************/
    1087 
    1088         // Bail if topic is not published
    1089         if ( !bbp_is_topic_published( $topic_id ) ) {
    1090                 return false;
    1091         }
    1092 
    1093         /** Reply *****************************************************************/
    1094 
    1095         // Bail if reply is not published
    1096         if ( !bbp_is_reply_published( $reply_id ) ) {
    1097                 return false;
    1098         }
    1099 
    1100         // Poster name
    1101         $reply_author_name = bbp_get_reply_author_display_name( $reply_id );
    1102 
    1103         /** Mail ******************************************************************/
    1104 
    1105         // Remove filters from reply content and topic title to prevent content
    1106         // from being encoded with HTML entities, wrapped in paragraph tags, etc...
    1107         remove_all_filters( 'bbp_get_reply_content' );
    1108         remove_all_filters( 'bbp_get_topic_title'   );
    1109 
    1110         // Strip tags from text and setup mail data
    1111         $topic_title   = strip_tags( bbp_get_topic_title( $topic_id ) );
    1112         $reply_content = strip_tags( bbp_get_reply_content( $reply_id ) );
    1113         $reply_url     = bbp_get_reply_url( $reply_id );
    1114         $blog_name     = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    1115 
    1116         // For plugins to filter messages per reply/topic/user
    1117         $message = sprintf( __( '%1$s wrote:
    1118 
    1119 %2$s
    1120 
    1121 Post Link: %3$s
    1122 
    1123 -----------
    1124 
    1125 You are receiving this email because you subscribed to a forum topic.
    1126 
    1127 Login and visit the topic to unsubscribe from these emails.', 'bbpress' ),
    1128 
    1129                 $reply_author_name,
    1130                 $reply_content,
    1131                 $reply_url
    1132         );
    1133 
    1134         $message = apply_filters( 'bbp_subscription_mail_message', $message, $reply_id, $topic_id );
    1135         if ( empty( $message ) ) {
    1136                 return;
    1137         }
    1138 
    1139         // For plugins to filter titles per reply/topic/user
    1140         $subject = apply_filters( 'bbp_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $reply_id, $topic_id );
    1141         if ( empty( $subject ) ) {
    1142                 return;
    1143         }
    1144 
    1145         /** Users *****************************************************************/
    1146 
    1147         // Get the noreply@ address
    1148         $no_reply   = bbp_get_do_not_reply_address();
    1149 
    1150         // Setup "From" email address
    1151         $from_email = apply_filters( 'bbp_subscription_from_email', $no_reply );
    1152 
    1153         // Setup the From header
    1154         $headers = array( 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>' );
    1155 
    1156         // Get topic subscribers and bail if empty
    1157         $user_ids = bbp_get_topic_subscribers( $topic_id, true );
    1158 
    1159         // Dedicated filter to manipulate user ID's to send emails to
    1160         $user_ids = apply_filters( 'bbp_topic_subscription_user_ids', $user_ids );
    1161         if ( empty( $user_ids ) ) {
    1162                 return false;
    1163         }
    1164 
    1165         // Loop through users
    1166         foreach ( (array) $user_ids as $user_id ) {
    1167 
    1168                 // Don't send notifications to the person who made the post
    1169                 if ( !empty( $reply_author ) && (int) $user_id === (int) $reply_author ) {
    1170                         continue;
    1171                 }
    1172 
    1173                 // Get email address of subscribed user
    1174                 $headers[] = 'Bcc: ' . get_userdata( $user_id )->user_email;
    1175         }
    1176 
    1177         /** Send it ***************************************************************/
    1178 
    1179         // Custom headers
    1180         $headers  = apply_filters( 'bbp_subscription_mail_headers', $headers  );
    1181         $to_email = apply_filters( 'bbp_subscription_to_email',     $no_reply );
    1182 
    1183         do_action( 'bbp_pre_notify_subscribers', $reply_id, $topic_id, $user_ids );
    1184 
    1185         // Send notification email
    1186         wp_mail( $to_email, $subject, $message, $headers );
    1187 
    1188         do_action( 'bbp_post_notify_subscribers', $reply_id, $topic_id, $user_ids );
    1189 
    1190         return true;
    1191 }
    1192 
    1193 /**
    11941003 * Sends notification emails for new topics to subscribed forums
    11951004 *
    11961005 * Gets new post's ID and check if there are subscribed users to that forum, and
    11971006 * if there are, send notifications
    11981007 *
    1199  * Note: in bbPress 2.6, we've moved away from 1 email per subscriber to 1 email
    1200  * with everyone BCC'd. This may have negative repercussions for email services
    1201  * that limit the number of addresses in a BCC field (often to around 500.) In
    1202  * those cases, we recommend unhooking this function and creating your own
    1203  * custom emailer script.
    1204  *
    12051008 * @since bbPress (r5156)
    12061009 *
    12071010 * @param int $topic_id ID of the newly made reply
     
    12101013 * @param int $topic_author ID of the topic author ID
    12111014 *
    12121015 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
    1213  * @uses bbp_get_topic_id() To validate the topic ID
    1214  * @uses bbp_get_forum_id() To validate the forum ID
    12151016 * @uses bbp_is_topic_published() To make sure the topic is published
    1216  * @uses bbp_get_forum_subscribers() To get the forum subscribers
    1217  * @uses bbp_get_topic_author_display_name() To get the topic author's display name
    1218  * @uses do_action() Calls 'bbp_pre_notify_forum_subscribers' with the topic id,
    1219  *                    forum id and user id
    1220  * @uses apply_filters() Calls 'bbp_forum_subscription_mail_message' with the
    1221  *                    message, topic id, forum id and user id
    1222  * @uses apply_filters() Calls 'bbp_forum_subscription_mail_title' with the
    1223  *                    topic title, topic id, forum id and user id
    1224  * @uses apply_filters() Calls 'bbp_forum_subscription_mail_headers'
    1225  * @uses get_userdata() To get the user data
    1226  * @uses wp_mail() To send the mail
    1227  * @uses do_action() Calls 'bbp_post_notify_forum_subscribers' with the topic,
    1228  *                    id, forum id and user id
     1017 * @uses BBP_Topic_Subscriber_Notification to notify subscribers
     1018 *
    12291019 * @return bool True on success, false on failure
    12301020 */
    12311021function bbp_notify_forum_subscribers( $topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0 ) {
     
    12351025                return false;
    12361026        }
    12371027
    1238         /** Validation ************************************************************/
    1239 
    1240         $topic_id = bbp_get_topic_id( $topic_id );
    1241         $forum_id = bbp_get_forum_id( $forum_id );
    1242 
    1243         /**
    1244          * Necessary for backwards compatibility
    1245          *
    1246          * @see https://bbpress.trac.wordpress.org/ticket/2620
    1247          */
    1248         $user_id  = 0;
    1249 
    1250         /** Topic *****************************************************************/
    1251 
    12521028        // Bail if topic is not published
    12531029        if ( ! bbp_is_topic_published( $topic_id ) ) {
    12541030                return false;
    12551031        }
    12561032
    1257         // Poster name
    1258         $topic_author_name = bbp_get_topic_author_display_name( $topic_id );
     1033        // Schedule new notification in WP Cron
     1034        $notification = new BBP_Forum_Subscriber_Notification( $forum_id, $topic_id );
     1035        $notification->schedule_sending();
    12591036
    1260         /** Mail ******************************************************************/
    1261 
    1262         // Remove filters from reply content and topic title to prevent content
    1263         // from being encoded with HTML entities, wrapped in paragraph tags, etc...
    1264         remove_all_filters( 'bbp_get_topic_content' );
    1265         remove_all_filters( 'bbp_get_topic_title'   );
    1266 
    1267         // Strip tags from text and setup mail data
    1268         $topic_title   = strip_tags( bbp_get_topic_title( $topic_id ) );
    1269         $topic_content = strip_tags( bbp_get_topic_content( $topic_id ) );
    1270         $topic_url     = get_permalink( $topic_id );
    1271         $blog_name     = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    1272 
    1273         // For plugins to filter messages per reply/topic/user
    1274         $message = sprintf( __( '%1$s wrote:
    1275 
    1276 %2$s
    1277 
    1278 Topic Link: %3$s
    1279 
    1280 -----------
    1281 
    1282 You are receiving this email because you subscribed to a forum.
    1283 
    1284 Login and visit the topic to unsubscribe from these emails.', 'bbpress' ),
    1285 
    1286                 $topic_author_name,
    1287                 $topic_content,
    1288                 $topic_url
    1289         );
    1290 
    1291         $message = apply_filters( 'bbp_forum_subscription_mail_message', $message, $topic_id, $forum_id, $user_id );
    1292         if ( empty( $message ) ) {
    1293                 return;
    1294         }
    1295 
    1296         // For plugins to filter titles per reply/topic/user
    1297         $subject = apply_filters( 'bbp_forum_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $topic_id, $forum_id, $user_id );
    1298         if ( empty( $subject ) ) {
    1299                 return;
    1300         }
    1301 
    1302         /** User ******************************************************************/
    1303 
    1304         // Get the noreply@ address
    1305         $no_reply   = bbp_get_do_not_reply_address();
    1306 
    1307         // Setup "From" email address
    1308         $from_email = apply_filters( 'bbp_subscription_from_email', $no_reply );
    1309 
    1310         // Setup the From header
    1311         $headers = array( 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>' );
    1312 
    1313         // Get topic subscribers and bail if empty
    1314         $user_ids = bbp_get_forum_subscribers( $forum_id, true );
    1315 
    1316         // Dedicated filter to manipulate user ID's to send emails to
    1317         $user_ids = apply_filters( 'bbp_forum_subscription_user_ids', $user_ids );
    1318         if ( empty( $user_ids ) ) {
    1319                 return false;
    1320         }
    1321 
    1322         // Loop through users
    1323         foreach ( (array) $user_ids as $user_id ) {
    1324 
    1325                 // Don't send notifications to the person who made the post
    1326                 if ( !empty( $topic_author ) && (int) $user_id === (int) $topic_author ) {
    1327                         continue;
    1328                 }
    1329 
    1330                 // Get email address of subscribed user
    1331                 $headers[] = 'Bcc: ' . get_userdata( $user_id )->user_email;
    1332         }
    1333 
    1334         /** Send it ***************************************************************/
    1335 
    1336         // Custom headers
    1337         $headers  = apply_filters( 'bbp_subscription_mail_headers', $headers  );
    1338         $to_email = apply_filters( 'bbp_subscription_to_email',     $no_reply );
    1339 
    1340         do_action( 'bbp_pre_notify_forum_subscribers', $topic_id, $forum_id, $user_ids );
    1341 
    1342         // Send notification email
    1343         wp_mail( $to_email, $subject, $message, $headers );
    1344 
    1345         do_action( 'bbp_post_notify_forum_subscribers', $topic_id, $forum_id, $user_ids );
    1346 
    13471037        return true;
    13481038}
    13491039
     
    13671057        return bbp_notify_topic_subscribers( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author );
    13681058}
    13691059
     1060/**
     1061 * Sends notification emails for new replies to subscribed topics
     1062 *
     1063 * Gets new post's ID and check if there are subscribed users to that topic, and
     1064 * if there are, send notifications
     1065 *
     1066 * @since bbPress (r5413)
     1067 *
     1068 * @param int $reply_id ID of the newly made reply
     1069 * @param int $topic_id ID of the topic of the reply
     1070 * @param int $forum_id ID of the forum of the reply
     1071 * @param mixed $anonymous_data Array of anonymous user data
     1072 * @param int $reply_author ID of the topic author ID
     1073 *
     1074 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
     1075 * @uses bbp_is_reply_published() To make sure the reply is published
     1076 * @uses BBP_Topic_Subscriber_Notification to notify subscribers
     1077 *
     1078 * @return bool True on success, false on failure
     1079 */
     1080function bbp_notify_topic_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0 ) {
     1081
     1082        // Bail if subscriptions are turned off
     1083        if ( !bbp_is_subscriptions_active() ) {
     1084                return false;
     1085        }
     1086
     1087        // Bail if topic is not published
     1088        if ( !bbp_is_topic_published( $topic_id ) ) {
     1089                return false;
     1090        }
     1091
     1092        // Bail if reply is not published
     1093        if ( !bbp_is_reply_published( $reply_id ) ) {
     1094                return false;
     1095        }
     1096
     1097        // Schedule new notification in WP Cron
     1098        $notification = new BBP_Topic_Subscriber_Notification( $forum_id, $topic_id, $reply_id );
     1099        $notification->schedule_sending();
     1100
     1101        return true;
     1102}
     1103
    13701104/** Login *********************************************************************/
    13711105
    13721106/**
  • includes/core/actions.php

     
    224224add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_favorites' );
    225225
    226226// Subscriptions
    227 add_action( 'bbp_spam_topic',   'bbp_remove_topic_from_all_subscriptions'       );
    228 add_action( 'bbp_trash_topic',  'bbp_remove_topic_from_all_subscriptions'       );
    229 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions'       );
    230 add_action( 'bbp_trash_forum',  'bbp_remove_forum_from_all_subscriptions'       );
    231 add_action( 'bbp_delete_forum', 'bbp_remove_forum_from_all_subscriptions'       );
    232 add_action( 'bbp_new_reply',    'bbp_notify_subscribers',                 11, 5 );
    233 add_action( 'bbp_new_topic',    'bbp_notify_forum_subscribers',           11, 4 );
     227add_action( 'bbp_subscription_email_cron', array( 'BBP_Subscriber_Notification', 'send' ), 10, 1 );
     228add_action( 'bbp_spam_topic',              'bbp_remove_topic_from_all_subscriptions'             );
     229add_action( 'bbp_trash_topic',             'bbp_remove_topic_from_all_subscriptions'             );
     230add_action( 'bbp_delete_topic',            'bbp_remove_topic_from_all_subscriptions'             );
     231add_action( 'bbp_trash_forum',             'bbp_remove_forum_from_all_subscriptions'             );
     232add_action( 'bbp_delete_forum',            'bbp_remove_forum_from_all_subscriptions'             );
     233add_action( 'bbp_new_reply',               'bbp_notify_subscribers',                       11, 5 );
     234add_action( 'bbp_new_topic',               'bbp_notify_forum_subscribers',                 11, 4 );
    234235
    235236// Sticky
    236237add_action( 'bbp_spam_topic',   'bbp_unstick_topic' );
     
    338339// Maybe convert the users password
    339340add_action( 'bbp_login_form_login', 'bbp_user_maybe_convert_pass' );
    340341
    341 add_action( 'bbp_activation', 'bbp_add_activation_redirect' );
    342  No newline at end of file
     342add_action( 'bbp_activation', 'bbp_add_activation_redirect' );