Skip to:
Content

bbPress.org

Ticket #2797: 2797.04.patch

File 2797.04.patch, 24.3 KB (added by mechter, 10 years ago)

re-added check for empty user id array before performing query

  • 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;
     556
     557        protected function __construct( $recipients ) {
     558                $this->recipients = $recipients;
     559                $from = array(
     560                        'name' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ),
     561                        'address' => get_bloginfo( 'admin_email' )
     562                );
     563                $from = apply_filters( 'bbp_subscription_email_from', $from );
     564                $from_string = empty( $from['name'] ) ? $from['address'] : "{$from['name']} <{$from['address']}>";
     565                $this->headers = "From: $from_string\r\n"; // string version $headers needs proper line ending, see wp codex on wp_mail()
     566        }
     567       
     568        /**
     569         * WP Cron callback to send notification emails to subscribers
     570         */
     571        public static function send( $notification ) {
     572                do_action( 'bbp_pre_notify_subscribers' );
     573       
     574                add_action( 'phpmailer_init', array( 'BBP_Subscriber_Notification', 'set_bounce_address' ), 10, 1 );
     575       
     576                foreach ( $notification->recipients as $to ) {
     577                        $to_string = empty( $to['name'] ) ? $to['address'] : "{$to['name']} <{$to['address']}>";
     578                        wp_mail( $to_string, $notification->subject, $notification->message, $notification->headers );
     579                }
     580       
     581                remove_action( 'phpmailer_init', array( 'BBP_Subscriber_Notification', 'set_bounce_address' ), 10, 1 );
     582       
     583                do_action( 'bbp_post_notify_subscribers' );
     584        }
     585       
     586        /**
     587         * Sets PHPMailer::Sender to bounce address, configurable via filter
     588         * Invoke via 'phpmailer_init' action hook
     589         */
     590        public static function set_bounce_address( $phpmailer ) {
     591                $bounce_address = apply_filters( 'bbp_bounce_address', false );
     592                if ( $bounce_address ) {
     593                        $phpmailer->Sender = $bounce_address;
     594                }
     595        }
     596       
     597        /**
     598         * Initializes recipients array from array of recipient user ids
     599         */
     600        protected static function get_recipients( $user_ids ) {
     601                if ( !$user_ids ) {
     602                        return array();
     603                }
     604
     605                global $wpdb;
     606                $ids_substitution = substr( str_repeat( ',%d', count( $user_ids ) ), 1 );
     607                $params = array_merge( array( "select user_email as address, display_name as name from {$wpdb->users} where ID in ($ids_substitution)" ), $user_ids );
     608                $recipients = $wpdb->get_results( call_user_func_array( array( $wpdb, 'prepare' ), $params ), ARRAY_A );
     609               
     610                return apply_filters( 'bbp_subscription_email_recipients', $recipients );
     611        }
     612       
     613        /**
     614         * Schedules a sending event with WP Cron
     615         */
     616        protected static function schedule_wp_cron_event( $notification ) {
     617                wp_schedule_single_event( time(), 'bbp_subscription_email_cron', array( $notification ) );
     618        }
     619}
     620/**
     621 * Forum subscription notification
     622 *
     623 * @package bbPress
     624 * @subpackage Classes
     625 *
     626 * @since bbPress (r)
     627 *
     628 * @uses BBP_Subscriber_Notification
     629 */
     630class BBP_Forum_Subscriber_Notification extends BBP_Subscriber_Notification {
     631
     632        protected function __construct( $recipients, $forum_id, $topic_id ) {
     633                parent::__construct( $recipients );
     634       
     635                // Remove filters from reply content and topic title to prevent content
     636                // from being encoded with HTML entities, wrapped in paragraph tags, etc...
     637                remove_all_filters( 'bbp_get_topic_content' );
     638                remove_all_filters( 'bbp_get_topic_title'   );
     639       
     640                // collect various pieces of information
     641                $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     642                $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) );
     643                $topic_author_display_name = bbp_get_topic_author_display_name( $topic_id );
     644                $topic_url = get_permalink( $topic_id );
     645                $topic_content = strip_tags( bbp_get_topic_content( $topic_id ) );
     646               
     647                // subject
     648                $subject = sprintf( __( "[%s Forums] New topic: \"%s\"", 'bbpress' ), $blog_name, $topic_title );
     649                $this->subject = apply_filters( 'bbp_forum_subscription_email_subject', $subject, $forum_id, $topic_id );
     650
     651                // message
     652                $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 );         
     653                $this->message = apply_filters( 'bbp_forum_subscription_email_message', $message, $forum_id, $topic_id );
     654        }
     655       
     656        /**
     657         * Factory
     658         *
     659         * @return true on success, false on failure
     660         */
     661        public static function schedule_sending( $forum_id, $topic_id ) {
     662
     663                // general checks and parameter validation
     664                if ( !bbp_is_subscriptions_active() ||
     665                                !bbp_get_forum_id( $forum_id ) ||
     666                                !bbp_is_topic_published( $topic_id ) ) {
     667                        return false;
     668                }
     669               
     670                // recipients
     671                $user_ids = bbp_get_forum_subscribers( $forum_id, true );
     672                $user_ids = array_diff( $user_ids, array( bbp_get_topic_author_id( $topic_id ) ) );
     673                $user_ids = apply_filters( 'bbp_forum_subscription_user_ids', $user_ids );
     674                $recipients = parent::get_recipients( $user_ids );
     675                if ( !$recipients ) {
     676                        return false;
     677                }
     678               
     679                $notification = new BBP_Forum_Subscriber_Notification( $recipients, $forum_id, $topic_id );
     680                parent::schedule_wp_cron_event( $notification );
     681               
     682                return true;
     683        }
     684}
     685/**
     686 * Topic subscription notification
     687 *
     688 * @package bbPress
     689 * @subpackage Classes
     690 *
     691 * @since bbPress (r)
     692 *
     693 * @uses BBP_Subscriber_Notification
     694 */
     695class BBP_Topic_Subscriber_Notification extends BBP_Subscriber_Notification {
     696
     697        protected function __construct( $recipients, $forum_id, $topic_id, $reply_id ) {
     698                parent::__construct( $recipients );
     699               
     700                // Remove filters from reply content and topic title to prevent content
     701                // from being encoded with HTML entities, wrapped in paragraph tags, etc...
     702                remove_all_filters( 'bbp_get_reply_content' );
     703                remove_all_filters( 'bbp_get_topic_title'   );
     704               
     705                // collect various pieces of information
     706                $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     707                $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) );
     708                $reply_author_display_name = bbp_get_reply_author_display_name( $reply_id );
     709                $reply_url = bbp_get_reply_url( $reply_id );
     710                $reply_content = strip_tags( bbp_get_reply_content( $reply_id ) );
     711               
     712                // subject
     713                $subject = sprintf( __( "[%s Forums] New reply to: \"%s\"", 'bbpress' ), $blog_name, $topic_title );
     714                $this->subject = apply_filters( 'bbp_topic_subscription_email_subject', $subject, $forum_id, $topic_id, $reply_id );
     715
     716                // message
     717                $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 );
     718                $this->message = apply_filters( 'bbp_topic_subscription_email_message', $message, $forum_id, $topic_id, $reply_id );
     719        }
     720       
     721        /**
     722         * Factory
     723         *
     724         * @return true on success, false on failure
     725         */
     726        public static function schedule_sending( $forum_id, $topic_id, $reply_id ) {
     727               
     728                // general checks and parameter validation
     729                if ( !bbp_is_subscriptions_active() ||
     730                                !bbp_get_forum_id( $forum_id ) ||
     731                                !bbp_is_topic_published( $topic_id ) ||
     732                                !bbp_is_reply_published( $reply_id ) ) {
     733                        return false;
     734                }
     735                               
     736                // recipients
     737                $user_ids = bbp_get_topic_subscribers( $topic_id, true );
     738                $user_ids = array_diff( $user_ids, array( bbp_get_reply_author_id( $reply_id ) ) );
     739                $user_ids = apply_filters( 'bbp_topic_subscription_user_ids', $user_ids );
     740                $recipients = parent::get_recipients( $user_ids );
     741                if ( !$recipients ) {
     742                        return false;
     743                }
     744               
     745                $notification = new BBP_Topic_Subscriber_Notification( $recipients, $forum_id, $topic_id, $reply_id );
     746                parent::schedule_wp_cron_event( $notification );
     747               
     748                return true;
     749        }
     750}
     751endif; // 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 ) {
    1232 
    1233         // Bail if subscriptions are turned off
    1234         if ( !bbp_is_subscriptions_active() ) {
    1235                 return false;
    1236         }
    1237 
    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 
    1252         // Bail if topic is not published
    1253         if ( ! bbp_is_topic_published( $topic_id ) ) {
    1254                 return false;
    1255         }
    1256 
    1257         // Poster name
    1258         $topic_author_name = bbp_get_topic_author_display_name( $topic_id );
    1259 
    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 
    1347         return true;
     1022        return BBP_Forum_Subscriber_Notification::schedule_sending( $forum_id, $topic_id );
    13481023}
    13491024
    13501025/**
     
    13671042        return bbp_notify_topic_subscribers( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author );
    13681043}
    13691044
     1045/**
     1046 * Sends notification emails for new replies to subscribed topics
     1047 *
     1048 * Gets new post's ID and check if there are subscribed users to that topic, and
     1049 * if there are, send notifications
     1050 *
     1051 * @since bbPress (r5413)
     1052 *
     1053 * @param int $reply_id ID of the newly made reply
     1054 * @param int $topic_id ID of the topic of the reply
     1055 * @param int $forum_id ID of the forum of the reply
     1056 * @param mixed $anonymous_data Array of anonymous user data
     1057 * @param int $reply_author ID of the topic author ID
     1058 *
     1059 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
     1060 * @uses bbp_is_reply_published() To make sure the reply is published
     1061 * @uses BBP_Topic_Subscriber_Notification to notify subscribers
     1062 *
     1063 * @return bool True on success, false on failure
     1064 */
     1065function bbp_notify_topic_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0 ) {
     1066        return BBP_Topic_Subscriber_Notification::schedule_sending( $forum_id, $topic_id, $reply_id );
     1067}
     1068
    13701069/** Login *********************************************************************/
    13711070
    13721071/**
  • 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' );