Skip to:
Content

bbPress.org

Ticket #2797: 2797.08.patch

File 2797.08.patch, 25.2 KB (added by mechter, 6 years ago)

missed one

  • 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                $from_string = apply_filters( 'bbp_subscription_from_email', $from_string ); // backwards compatibility
     566                $this->headers []= "From: $from_string"; // array version $headers does not require proper line ending, see wp codex on wp_mail()
     567                $this->headers = apply_filters( 'bbp_subscription_email_headers', $this->headers  );
     568                $this->headers = apply_filters( 'bbp_subscription_mail_headers', $this->headers  ); // backwards compatiobility
     569        }
     570       
     571        /**
     572         * WP Cron callback to send notification emails to subscribers
     573         */
     574        public static function send( $notification ) {
     575                do_action( 'bbp_pre_notify_subscribers' );
     576       
     577                add_action( 'phpmailer_init', array( 'BBP_Subscriber_Notification', 'set_bounce_address' ), 10, 1 );
     578       
     579                foreach ( $notification->recipients as $to ) {
     580                        $to_string = empty( $to['name'] ) ? $to['address'] : "{$to['name']} <{$to['address']}>";
     581                        wp_mail( $to_string, $notification->subject, $notification->message, $notification->headers );
     582                }
     583       
     584                remove_action( 'phpmailer_init', array( 'BBP_Subscriber_Notification', 'set_bounce_address' ), 10, 1 );
     585       
     586                do_action( 'bbp_post_notify_subscribers' );
     587        }
     588       
     589        /**
     590         * Sets PHPMailer::Sender to bounce address, configurable via filter
     591         * Invoke via 'phpmailer_init' action hook
     592         */
     593        public static function set_bounce_address( $phpmailer ) {
     594                $bounce_address = apply_filters( 'bbp_bounce_address', false );
     595                $bounce_address = apply_filters( 'bbp_get_do_not_reply_address', $bounce_address ); // backwards compatibility
     596                if ( $bounce_address ) {
     597                        $phpmailer->Sender = $bounce_address;
     598                }
     599        }
     600       
     601        /**
     602         * Initializes recipients array from array of recipient user ids
     603         */
     604        protected static function get_recipients( $user_ids ) {
     605                if ( !$user_ids ) {
     606                        return apply_filters( 'bbp_subscription_email_recipients', array() );
     607                }
     608
     609                global $wpdb;
     610                $ids_substitution = substr( str_repeat( ',%d', count( $user_ids ) ), 1 );
     611                $params = array_merge( array( "select user_email as address, display_name as name from {$wpdb->users} where ID in ($ids_substitution)" ), $user_ids );
     612                $recipients = $wpdb->get_results( call_user_func_array( array( $wpdb, 'prepare' ), $params ), ARRAY_A );
     613                if ( !is_array( $recipients ) ) {
     614                        $recipients = array();
     615                }
     616               
     617                return apply_filters( 'bbp_subscription_email_recipients', $recipients );
     618        }
     619       
     620        /**
     621         * Schedules a sending event with WP Cron
     622         */
     623        protected static function schedule_wp_cron_event( $notification ) {
     624                wp_schedule_single_event( time(), 'bbp_subscription_email_cron', array( $notification ) );
     625        }
     626}
     627/**
     628 * Forum subscription notification
     629 *
     630 * @package bbPress
     631 * @subpackage Classes
     632 *
     633 * @since bbPress (r)
     634 *
     635 * @uses BBP_Subscriber_Notification
     636 */
     637class BBP_Forum_Subscriber_Notification extends BBP_Subscriber_Notification {
     638
     639        protected function __construct( $recipients, $forum_id, $topic_id ) {
     640                parent::__construct( $recipients );
     641       
     642                // Remove filters from reply content and topic title to prevent content
     643                // from being encoded with HTML entities, wrapped in paragraph tags, etc...
     644                remove_all_filters( 'bbp_get_topic_content' );
     645                remove_all_filters( 'bbp_get_topic_title'   );
     646       
     647                // collect various pieces of information
     648                $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     649                $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) );
     650                $topic_author_display_name = bbp_get_topic_author_display_name( $topic_id );
     651                $topic_url = get_permalink( $topic_id );
     652                $topic_content = strip_tags( bbp_get_topic_content( $topic_id ) );
     653                $user_id = bbp_get_topic_author_id( $topic_id ); // for backwards compatible filters below
     654               
     655                // subject
     656                $this->subject = sprintf( __( "[%s Forums] New topic: \"%s\"", 'bbpress' ), $blog_name, $topic_title );
     657                $this->subject = apply_filters( 'bbp_forum_subscription_email_subject', $this->subject, $forum_id, $topic_id );
     658                $this->subject = apply_filters( 'bbp_forum_subscription_mail_title', $this->subject, $topic_id, $forum_id, $user_id ); // backwards compatibility
     659
     660                // message
     661                $this->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 );
     662                $this->message = apply_filters( 'bbp_forum_subscription_email_message', $this->message, $forum_id, $topic_id );
     663                $this->message = apply_filters( 'bbp_forum_subscription_mail_message', $this->message, $topic_id, $forum_id, $user_id ); // backwards compatibility
     664        }
     665       
     666        /**
     667         * Factory
     668         *
     669         * @return true on success, false on failure
     670         */
     671        public static function schedule_sending( $forum_id, $topic_id ) {
     672
     673                // general checks and parameter validation
     674                if ( !bbp_is_subscriptions_active() ||
     675                                !bbp_get_forum_id( $forum_id ) ||
     676                                !bbp_is_topic_published( $topic_id ) ) {
     677                        return false;
     678                }
     679               
     680                // recipients
     681                $user_ids = bbp_get_forum_subscribers( $forum_id, true );
     682                $user_ids = array_diff( $user_ids, array( bbp_get_topic_author_id( $topic_id ) ) );
     683                $user_ids = apply_filters( 'bbp_forum_subscription_user_ids', $user_ids );
     684                $recipients = parent::get_recipients( $user_ids );
     685                if ( !$recipients ) {
     686                        return false;
     687                }
     688               
     689                $notification = new BBP_Forum_Subscriber_Notification( $recipients, $forum_id, $topic_id );
     690                parent::schedule_wp_cron_event( $notification );
     691               
     692                return true;
     693        }
     694}
     695/**
     696 * Topic subscription notification
     697 *
     698 * @package bbPress
     699 * @subpackage Classes
     700 *
     701 * @since bbPress (r)
     702 *
     703 * @uses BBP_Subscriber_Notification
     704 */
     705class BBP_Topic_Subscriber_Notification extends BBP_Subscriber_Notification {
     706
     707        protected function __construct( $recipients, $forum_id, $topic_id, $reply_id ) {
     708                parent::__construct( $recipients );
     709               
     710                // Remove filters from reply content and topic title to prevent content
     711                // from being encoded with HTML entities, wrapped in paragraph tags, etc...
     712                remove_all_filters( 'bbp_get_reply_content' );
     713                remove_all_filters( 'bbp_get_topic_title'   );
     714               
     715                // collect various pieces of information
     716                $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     717                $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) );
     718                $reply_author_display_name = bbp_get_reply_author_display_name( $reply_id );
     719                $reply_url = bbp_get_reply_url( $reply_id );
     720                $reply_content = strip_tags( bbp_get_reply_content( $reply_id ) );
     721
     722                // subject
     723                $this->subject = sprintf( __( "[%s Forums] New reply to: \"%s\"", 'bbpress' ), $blog_name, $topic_title );
     724                $this->subject = apply_filters( 'bbp_topic_subscription_email_subject', $this->subject, $forum_id, $topic_id, $reply_id );
     725                $this->subject = apply_filters( 'bbp_subscription_mail_title', $this->subject, $reply_id, $topic_id ); // backwards compatibility
     726
     727                // message
     728                $this->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 );
     729                $this->message = apply_filters( 'bbp_topic_subscription_email_message', $this->message, $forum_id, $topic_id, $reply_id );
     730                $this->message = apply_filters( 'bbp_subscription_mail_message', $this->message, $reply_id, $topic_id ); // backwards compatibility
     731        }
     732       
     733        /**
     734         * Factory
     735         *
     736         * @return true on success, false on failure
     737         */
     738        public static function schedule_sending( $forum_id, $topic_id, $reply_id ) {
     739               
     740                // general checks and parameter validation
     741                if ( !bbp_is_subscriptions_active() ||
     742                                !bbp_get_forum_id( $forum_id ) ||
     743                                !bbp_is_topic_published( $topic_id ) ||
     744                                !bbp_is_reply_published( $reply_id ) ) {
     745                        return false;
     746                }
     747                               
     748                // recipients
     749                $user_ids = bbp_get_topic_subscribers( $topic_id, true );
     750                $user_ids = array_diff( $user_ids, array( bbp_get_reply_author_id( $reply_id ) ) );
     751                $user_ids = apply_filters( 'bbp_topic_subscription_user_ids', $user_ids );
     752                $recipients = parent::get_recipients( $user_ids );
     753                if ( !$recipients ) {
     754                        return false;
     755                }
     756               
     757                $notification = new BBP_Topic_Subscriber_Notification( $recipients, $forum_id, $topic_id, $reply_id );
     758                parent::schedule_wp_cron_event( $notification );
     759               
     760                return true;
     761        }
     762}
     763endif; // class_exists check
  • includes/common/functions.php

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