Ticket #2797: 2797.09.patch
File 2797.09.patch, 25.7 KB (added by , 9 years ago) |
---|
-
includes/common/classes.php
543 543 } 544 544 } 545 545 endif; // class_exists check 546 547 if ( !class_exists( 'BBP_Subscriber_Notification' ) ) : 548 /** 549 * Send subscription notification emails via WP Cron 550 * 551 * @package bbPress 552 * @subpackage Classes 553 * 554 * @since bbPress (r) 555 */ 556 class BBP_Subscriber_Notification { 557 public $subject; 558 public $message; 559 public $headers; 560 public $recipients; 561 562 protected function __construct( $recipients ) { 563 $this->recipients = $recipients; 564 $from = array( 565 'name' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), 566 'address' => get_bloginfo( 'admin_email' ) 567 ); 568 $from = apply_filters( 'bbp_subscription_email_from', $from ); 569 $from_string = empty( $from['name'] ) ? $from['address'] : "{$from['name']} <{$from['address']}>"; 570 $from_string = apply_filters( 'bbp_subscription_from_email', $from_string ); // backwards compatibility 571 $this->headers []= "From: $from_string"; // array version $headers does not require proper line ending, see wp codex on wp_mail() 572 $this->headers = apply_filters( 'bbp_subscription_email_headers', $this->headers ); 573 $this->headers = apply_filters( 'bbp_subscription_mail_headers', $this->headers ); // backwards compatiobility 574 } 575 576 /** 577 * WP Cron callback to send notification emails to subscribers 578 */ 579 public static function send( $notification ) { 580 do_action( 'bbp_pre_notify_subscribers' ); 581 582 add_action( 'phpmailer_init', array( 'BBP_Subscriber_Notification', 'set_bounce_address' ), 10, 1 ); 583 584 foreach ( $notification->recipients as $to ) { 585 $to_string = empty( $to['name'] ) ? $to['address'] : "{$to['name']} <{$to['address']}>"; 586 wp_mail( $to_string, $notification->subject, $notification->message, $notification->headers ); 587 } 588 589 remove_action( 'phpmailer_init', array( 'BBP_Subscriber_Notification', 'set_bounce_address' ), 10, 1 ); 590 591 do_action( 'bbp_post_notify_subscribers' ); 592 } 593 594 /** 595 * Sets PHPMailer::Sender to bounce address, configurable via filter 596 * Invoke via 'phpmailer_init' action hook 597 */ 598 public static function set_bounce_address( $phpmailer ) { 599 $bounce_address = apply_filters( 'bbp_bounce_address', false ); 600 $bounce_address = apply_filters( 'bbp_get_do_not_reply_address', $bounce_address ); // backwards compatibility 601 if ( $bounce_address ) { 602 $phpmailer->Sender = $bounce_address; 603 } 604 } 605 606 /** 607 * Initializes recipients array from array of recipient user ids 608 */ 609 protected static function get_recipients( $user_ids ) { 610 if ( !$user_ids ) { 611 return apply_filters( 'bbp_subscription_email_recipients', array() ); 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 if ( !is_array( $recipients ) ) { 619 $recipients = array(); 620 } 621 622 return apply_filters( 'bbp_subscription_email_recipients', $recipients ); 623 } 624 625 /** 626 * Schedules a sending event with WP Cron 627 */ 628 protected static function schedule_wp_cron_event( $notification ) { 629 wp_schedule_single_event( time(), 'bbp_subscription_email_cron', array( $notification ) ); 630 } 631 } 632 /** 633 * Forum subscription notification 634 * 635 * @package bbPress 636 * @subpackage Classes 637 * 638 * @since bbPress (r) 639 * 640 * @uses BBP_Subscriber_Notification 641 */ 642 class BBP_Forum_Subscriber_Notification extends BBP_Subscriber_Notification { 643 644 protected function __construct( $recipients, $forum_id, $topic_id ) { 645 parent::__construct( $recipients ); 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_display_name = bbp_get_topic_author_display_name( $topic_id ); 656 $topic_url = get_permalink( $topic_id ); 657 $topic_content = strip_tags( bbp_get_topic_content( $topic_id ) ); 658 $user_id = bbp_get_topic_author_id( $topic_id ); // for backwards compatible filters below 659 660 // subject 661 $this->subject = sprintf( __( "[%s Forums] New topic: \"%s\"", 'bbpress' ), $blog_name, $topic_title ); 662 $this->subject = apply_filters( 'bbp_forum_subscription_email_subject', $this->subject, $forum_id, $topic_id ); 663 $this->subject = apply_filters( 'bbp_forum_subscription_mail_title', $this->subject, $topic_id, $forum_id, $user_id ); // backwards compatibility 664 665 // message 666 $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 ); 667 $this->message = apply_filters( 'bbp_forum_subscription_email_message', $this->message, $forum_id, $topic_id ); 668 $this->message = apply_filters( 'bbp_forum_subscription_mail_message', $this->message, $topic_id, $forum_id, $user_id ); // backwards compatibility 669 } 670 671 /** 672 * Factory 673 * 674 * @return true on success, false on failure 675 */ 676 public static function schedule_sending( $forum_id, $topic_id ) { 677 678 // general checks and parameter validation 679 if ( !bbp_is_subscriptions_active() || 680 !bbp_get_forum_id( $forum_id ) || 681 !bbp_is_topic_published( $topic_id ) ) { 682 return false; 683 } 684 685 // recipients 686 $user_ids = bbp_get_forum_subscribers( $forum_id, true ); 687 $user_ids = array_diff( $user_ids, array( bbp_get_topic_author_id( $topic_id ) ) ); 688 $user_ids = apply_filters( 'bbp_forum_subscription_user_ids', $user_ids ); 689 $recipients = parent::get_recipients( $user_ids ); 690 if ( !$recipients ) { 691 return false; 692 } 693 694 $notification = new ABBPS_Forum_Subscriber_Notification( $recipients, $forum_id, $topic_id ); 695 696 if ( apply_filters( 'bbp_subscription_disable_async', false ) || 697 apply_filters( 'bbp_forum_subscription_disable_async', false ) ) { 698 parent::send( $notification ); 699 return false; 700 } 701 702 parent::schedule_wp_cron_event( $notification ); 703 704 return true; 705 } 706 } 707 /** 708 * Topic subscription notification 709 * 710 * @package bbPress 711 * @subpackage Classes 712 * 713 * @since bbPress (r) 714 * 715 * @uses BBP_Subscriber_Notification 716 */ 717 class BBP_Topic_Subscriber_Notification extends BBP_Subscriber_Notification { 718 719 protected function __construct( $recipients, $forum_id, $topic_id, $reply_id ) { 720 parent::__construct( $recipients ); 721 722 // Remove filters from reply content and topic title to prevent content 723 // from being encoded with HTML entities, wrapped in paragraph tags, etc... 724 remove_all_filters( 'bbp_get_reply_content' ); 725 remove_all_filters( 'bbp_get_topic_title' ); 726 727 // collect various pieces of information 728 $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 729 $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) ); 730 $reply_author_display_name = bbp_get_reply_author_display_name( $reply_id ); 731 $reply_url = bbp_get_reply_url( $reply_id ); 732 $reply_content = strip_tags( bbp_get_reply_content( $reply_id ) ); 733 734 // subject 735 $this->subject = sprintf( __( "[%s Forums] New reply to: \"%s\"", 'bbpress' ), $blog_name, $topic_title ); 736 $this->subject = apply_filters( 'bbp_topic_subscription_email_subject', $this->subject, $forum_id, $topic_id, $reply_id ); 737 $this->subject = apply_filters( 'bbp_subscription_mail_title', $this->subject, $reply_id, $topic_id ); // backwards compatibility 738 739 // message 740 $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 ); 741 $this->message = apply_filters( 'bbp_topic_subscription_email_message', $this->message, $forum_id, $topic_id, $reply_id ); 742 $this->message = apply_filters( 'bbp_subscription_mail_message', $this->message, $reply_id, $topic_id ); // backwards compatibility 743 } 744 745 /** 746 * Factory 747 * 748 * @return true on success, false on failure 749 */ 750 public static function schedule_sending( $forum_id, $topic_id, $reply_id ) { 751 752 // general checks and parameter validation 753 if ( !bbp_is_subscriptions_active() || 754 !bbp_get_forum_id( $forum_id ) || 755 !bbp_is_topic_published( $topic_id ) || 756 !bbp_is_reply_published( $reply_id ) ) { 757 return false; 758 } 759 760 // recipients 761 $user_ids = bbp_get_topic_subscribers( $topic_id, true ); 762 $user_ids = array_diff( $user_ids, array( bbp_get_reply_author_id( $reply_id ) ) ); 763 $user_ids = apply_filters( 'bbp_topic_subscription_user_ids', $user_ids ); 764 $recipients = parent::get_recipients( $user_ids ); 765 if ( !$recipients ) { 766 return false; 767 } 768 769 $notification = new ABBPS_Topic_Subscriber_Notification( $recipients, $forum_id, $topic_id, $reply_id ); 770 771 if ( apply_filters( 'bbp_subscription_disable_async', false ) || 772 apply_filters( 'bbp_topic_subscription_disable_async', false ) ) { 773 parent::send( $notification ); 774 return false; 775 } 776 777 parent::schedule_wp_cron_event( $notification ); 778 779 return true; 780 } 781 } 782 endif; // class_exists check -
includes/common/functions.php
1001 1001 /** Subscriptions *************************************************************/ 1002 1002 1003 1003 /** 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 are1007 * available to customize this address further. In the future, we may consider1008 * using `admin_email` instead, though this is not normally publicized.1009 *1010 * We use `$_SERVER['SERVER_NAME']` here to mimic similar functionality in1011 * WordPress core. Previously, we used `get_home_url()` to use already validated1012 * user input, but it was causing issues in some installations.1013 *1014 * @since 2.6.0 bbPress (r5409)1015 *1016 * @see wp_mail1017 * @see wp_notify_postauthor1018 * @link https://bbpress.trac.wordpress.org/ticket/26181019 *1020 * @return string1021 */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 topics1032 *1033 * Gets new post's ID and check if there are subscribed users to that topic, and1034 * if there are, send notifications1035 *1036 * Note: in bbPress 2.6, we've moved away from 1 email per subscriber to 1 email1037 * with everyone BCC'd. This may have negative repercussions for email services1038 * that limit the number of addresses in a BCC field (often to around 500.) In1039 * those cases, we recommend unhooking this function and creating your own1040 * custom emailer script.1041 *1042 * @since 2.6.0 bbPress (r5413)1043 *1044 * @param int $reply_id ID of the newly made reply1045 * @param int $topic_id ID of the topic of the reply1046 * @param int $forum_id ID of the forum of the reply1047 * @param mixed $anonymous_data Array of anonymous user data1048 * @param int $reply_author ID of the topic author ID1049 *1050 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active1051 * @uses bbp_get_reply_id() To validate the reply ID1052 * @uses bbp_get_topic_id() To validate the topic ID1053 * @uses bbp_get_forum_id() To validate the forum ID1054 * @uses bbp_get_reply() To get the reply1055 * @uses bbp_is_reply_published() To make sure the reply is published1056 * @uses bbp_get_topic_id() To validate the topic ID1057 * @uses bbp_get_topic() To get the reply's topic1058 * @uses bbp_is_topic_published() To make sure the topic is published1059 * @uses bbp_get_reply_author_display_name() To get the reply author's display name1060 * @uses do_action() Calls 'bbp_pre_notify_subscribers' with the reply id,1061 * topic id and user id1062 * @uses bbp_get_topic_subscribers() To get the topic subscribers1063 * @uses apply_filters() Calls 'bbp_subscription_mail_message' with the1064 * message, reply id, topic id and user id1065 * @uses apply_filters() Calls 'bbp_subscription_mail_title' with the1066 * topic title, reply id, topic id and user id1067 * @uses apply_filters() Calls 'bbp_subscription_mail_headers'1068 * @uses get_userdata() To get the user data1069 * @uses wp_mail() To send the mail1070 * @uses do_action() Calls 'bbp_post_notify_subscribers' with the reply id,1071 * topic id and user id1072 * @return bool True on success, false on failure1073 */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 off1077 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 published1090 if ( ! bbp_is_topic_published( $topic_id ) ) {1091 return false;1092 }1093 1094 /** Reply *****************************************************************/1095 1096 // Bail if reply is not published1097 if ( ! bbp_is_reply_published( $reply_id ) ) {1098 return false;1099 }1100 1101 // Poster name1102 $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 content1107 // 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 data1112 $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/user1118 $message = sprintf( __( '%1$s wrote:1119 1120 %2$s1121 1122 Post Link: %3$s1123 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_url1133 );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/user1141 $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@ address1149 $no_reply = bbp_get_do_not_reply_address();1150 1151 // Setup "From" email address1152 $from_email = apply_filters( 'bbp_subscription_from_email', $no_reply );1153 1154 // Setup the From header1155 $headers = array( 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>' );1156 1157 // Get topic subscribers and bail if empty1158 $user_ids = bbp_get_topic_subscribers( $topic_id, true );1159 1160 // Dedicated filter to manipulate user ID's to send emails to1161 $user_ids = apply_filters( 'bbp_topic_subscription_user_ids', $user_ids );1162 if ( empty( $user_ids ) ) {1163 return false;1164 }1165 1166 // Loop through users1167 foreach ( (array) $user_ids as $user_id ) {1168 1169 // Don't send notifications to the person who made the post1170 if ( ! empty( $reply_author ) && (int) $user_id === (int) $reply_author ) {1171 continue;1172 }1173 1174 // Get email address of subscribed user1175 $headers[] = 'Bcc: ' . get_userdata( $user_id )->user_email;1176 }1177 1178 /** Send it ***************************************************************/1179 1180 // Custom headers1181 $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 email1187 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 /**1195 1004 * Sends notification emails for new topics to subscribed forums 1005 * Sends notification emails for new topics to subscribed forums 1196 1006 * 1197 1007 * Gets new post's ID and check if there are subscribed users to that forum, and 1198 1008 * if there are, send notifications 1199 1009 * 1200 * Note: in bbPress 2.6, we've moved away from 1 email per subscriber to 1 email1201 * with everyone BCC'd. This may have negative repercussions for email services1202 * that limit the number of addresses in a BCC field (often to around 500.) In1203 * those cases, we recommend unhooking this function and creating your own1204 * custom emailer script.1205 *1206 1010 * @since 2.5.0 bbPress (r5156) 1207 1011 * 1208 1012 * @param int $topic_id ID of the newly made reply … … 1211 1015 * @param int $topic_author ID of the topic author ID 1212 1016 * 1213 1017 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 1214 * @uses bbp_get_topic_id() To validate the topic ID1215 * @uses bbp_get_forum_id() To validate the forum ID1216 1018 * @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 1019 * @uses BBP_Topic_Subscriber_Notification to notify subscribers 1020 * 1230 1021 * @return bool True on success, false on failure 1231 1022 */ 1232 1023 function 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; 1024 return BBP_Forum_Subscriber_Notification::schedule_sending( $forum_id, $topic_id ); 1349 1025 } 1350 1026 1351 1027 /** … … 1369 1045 return bbp_notify_topic_subscribers( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author ); 1370 1046 } 1371 1047 1048 /** 1049 * Sends notification emails for new replies to subscribed topics 1050 * 1051 * Gets new post's ID and check if there are subscribed users to that topic, and 1052 * if there are, send notifications 1053 * 1054 * @since bbPress (r5413) 1055 * 1056 * @param int $reply_id ID of the newly made reply 1057 * @param int $topic_id ID of the topic of the reply 1058 * @param int $forum_id ID of the forum of the reply 1059 * @param mixed $anonymous_data Array of anonymous user data 1060 * @param int $reply_author ID of the topic author ID 1061 * 1062 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 1063 * @uses bbp_is_reply_published() To make sure the reply is published 1064 * @uses BBP_Topic_Subscriber_Notification to notify subscribers 1065 * 1066 * @return bool True on success, false on failure 1067 */ 1068 function bbp_notify_topic_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0 ) { 1069 return BBP_Topic_Subscriber_Notification::schedule_sending( $forum_id, $topic_id, $reply_id ); 1070 } 1071 1372 1072 /** Login *********************************************************************/ 1373 1073 1374 1074 /** -
includes/core/actions.php
224 224 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_favorites' ); 225 225 226 226 // 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 ); 227 add_action( 'bbp_subscription_email_cron', array( 'BBP_Subscriber_Notification', 'send' ), 10, 1 ); 228 add_action( 'bbp_spam_topic', 'bbp_remove_topic_from_all_subscriptions' ); 229 add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_subscriptions' ); 230 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions' ); 231 add_action( 'bbp_trash_forum', 'bbp_remove_forum_from_all_subscriptions' ); 232 add_action( 'bbp_delete_forum', 'bbp_remove_forum_from_all_subscriptions' ); 233 add_action( 'bbp_new_reply', 'bbp_notify_subscribers', 11, 5 ); 234 add_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4 ); 234 235 235 236 // Sticky 236 237 add_action( 'bbp_spam_topic', 'bbp_unstick_topic' );