Skip to:
Content

bbPress.org

Ticket #2162: 2162.2.diff

File 2162.2.diff, 11.1 KB (added by netweb, 11 years ago)
  • includes/common/functions.php

     
    987987 * Gets new post's ID and check if there are subscribed users to that topic, and
    988988 * if there are, send notifications
    989989 *
     990 * Note: in bbPress 2.6, we've moved away from 1 email per subscriber to 1 email
     991 * with everyone BCC'd. This may have negative repercussions for email services
     992 * that limit the number of addresses in a BCC field (often to around 500.) In
     993 * those cases, we recommend unhooking this function and creating your own
     994 * custom emailer script.
     995 *
    990996 * @since bbPress (r2668)
    991997 *
    992998 * @param int $reply_id ID of the newly made reply
     
    10171023function bbp_notify_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0 ) {
    10181024
    10191025        // Bail if subscriptions are turned off
    1020         if ( !bbp_is_subscriptions_active() )
     1026        if ( !bbp_is_subscriptions_active() ) {
    10211027                return false;
     1028        }
    10221029
    10231030        /** Validation ************************************************************/
    10241031
     
    10261033        $topic_id = bbp_get_topic_id( $topic_id );
    10271034        $forum_id = bbp_get_forum_id( $forum_id );
    10281035
    1029         /** Reply *****************************************************************/
    1030 
    1031         // Bail if reply is not published
    1032         if ( !bbp_is_reply_published( $reply_id ) )
    1033                 return false;
    1034 
    10351036        /** Topic *****************************************************************/
    10361037
    10371038        // Bail if topic is not published
    1038         if ( !bbp_is_topic_published( $topic_id ) )
     1039        if ( !bbp_is_topic_published( $topic_id ) ) {
    10391040                return false;
     1041        }
    10401042
    1041         /** User ******************************************************************/
     1043        /** Reply *****************************************************************/
    10421044
    1043         // Get topic subscribers and bail if empty
    1044         $user_ids = bbp_get_topic_subscribers( $topic_id );
    1045         if ( empty( $user_ids ) )
     1045        // Bail if reply is not published
     1046        if ( !bbp_is_reply_published( $reply_id ) ) {
    10461047                return false;
     1048        }
    10471049
    10481050        // Poster name
    10491051        $reply_author_name = bbp_get_reply_author_display_name( $reply_id );
     
    10501052
    10511053        /** Mail ******************************************************************/
    10521054
    1053         do_action( 'bbp_pre_notify_subscribers', $reply_id, $topic_id, $user_ids );
    1054 
    10551055        // Remove filters from reply content and topic title to prevent content
    10561056        // from being encoded with HTML entities, wrapped in paragraph tags, etc...
    10571057        remove_all_filters( 'bbp_get_reply_content' );
    10581058        remove_all_filters( 'bbp_get_topic_title'   );
    10591059
    1060         // Strip tags from text
     1060        // Strip tags from text and setup mail data
    10611061        $topic_title   = strip_tags( bbp_get_topic_title( $topic_id ) );
    10621062        $reply_content = strip_tags( bbp_get_reply_content( $reply_id ) );
    10631063        $reply_url     = bbp_get_reply_url( $reply_id );
    10641064        $blog_name     = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     1065        $do_not_reply = '<noreply@' . ltrim( get_home_url(), '^(http|https)://' ) . '>';
    10651066
    1066         // Loop through users
    1067         foreach ( (array) $user_ids as $user_id ) {
     1067        // For plugins to filter messages per reply/topic/user
     1068        $message = sprintf( __( '%1$s wrote:
    10681069
    1069                 // Don't send notifications to the person who made the post
    1070                 if ( !empty( $reply_author ) && (int) $user_id === (int) $reply_author )
    1071                         continue;
    1072 
    1073                 // For plugins to filter messages per reply/topic/user
    1074                 $message = sprintf( __( '%1$s wrote:
    1075 
    10761070%2$s
    10771071
    10781072Post Link: %3$s
     
    10831077
    10841078Login and visit the topic to unsubscribe from these emails.', 'bbpress' ),
    10851079
    1086                         $reply_author_name,
    1087                         $reply_content,
    1088                         $reply_url
    1089                 );
     1080                $reply_author_name,
     1081                $reply_content,
     1082                $reply_url
     1083        );
    10901084
    1091                 $message = apply_filters( 'bbp_subscription_mail_message', $message, $reply_id, $topic_id, $user_id );
    1092                 if ( empty( $message ) )
    1093                         continue;
     1085        $message = apply_filters( 'bbp_subscription_mail_message', $message, $reply_id, $topic_id );
     1086        if ( empty( $message ) ) {
     1087                return;
     1088        }
    10941089
    1095                 // For plugins to filter titles per reply/topic/user
    1096                 $subject = apply_filters( 'bbp_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $reply_id, $topic_id, $user_id );
    1097                 if ( empty( $subject ) )
    1098                         continue;
     1090        // For plugins to filter titles per reply/topic/user
     1091        $subject = apply_filters( 'bbp_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $reply_id, $topic_id );
     1092        if ( empty( $subject ) ) {
     1093                return;
     1094        }
    10991095
    1100                 // Custom headers
    1101                 $headers = apply_filters( 'bbp_subscription_mail_headers', array() );
     1096        /** Users *****************************************************************/
    11021097
    1103                 // Get user data of this user
    1104                 $user = get_userdata( $user_id );
     1098        // Array to hold BCC's
     1099        $headers = array();
    11051100
    1106                 // Send notification email
    1107                 wp_mail( $user->user_email, $subject, $message, $headers );
     1101        // Setup the From header
     1102        $headers[] = 'From: ' . get_bloginfo( 'name' ) . ' ' . $do_not_reply;
     1103
     1104        // Get topic subscribers and bail if empty
     1105        $user_ids = bbp_get_topic_subscribers( $topic_id, true );
     1106        if ( empty( $user_ids ) ) {
     1107                return false;
    11081108        }
    11091109
     1110        // Loop through users
     1111        foreach ( (array) $user_ids as $user_id ) {
     1112
     1113                // Don't send notifications to the person who made the post
     1114                if ( !empty( $reply_author ) && (int) $user_id === (int) $reply_author ) {
     1115                        continue;
     1116                }
     1117
     1118                // Get email address of subscribed user
     1119                $headers[] = 'Bcc: ' . get_userdata( $user_id )->user_email;
     1120        }
     1121
     1122        /** Send it ***************************************************************/
     1123
     1124        // Custom headers
     1125        $headers = apply_filters( 'bbp_subscription_mail_headers', $headers );
     1126
     1127        do_action( 'bbp_pre_notify_subscribers', $reply_id, $topic_id, $user_ids );
     1128
     1129        // Send notification email
     1130        wp_mail( $do_not_reply, $subject, $message, $headers );
     1131
    11101132        do_action( 'bbp_post_notify_subscribers', $reply_id, $topic_id, $user_ids );
    11111133
    11121134        return true;
     
    11151137/**
    11161138 * Sends notification emails for new topics to subscribed forums
    11171139 *
    1118  * Gets new post's ID and check if there are subscribed users to that topic, and
     1140 * Gets new post's ID and check if there are subscribed users to that forum, and
    11191141 * if there are, send notifications
    11201142 *
     1143 * Note: in bbPress 2.6, we've moved away from 1 email per subscriber to 1 email
     1144 * with everyone BCC'd. This may have negative repercussions for email services
     1145 * that limit the number of addresses in a BCC field (often to around 500.) In
     1146 * those cases, we recommend unhooking this function and creating your own
     1147 * custom emailer script.
     1148 *
    11211149 * @since bbPress (r5156)
    11221150 *
    11231151 * @param int $topic_id ID of the newly made reply
     
    11431171function bbp_notify_forum_subscribers( $topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0 ) {
    11441172
    11451173        // Bail if subscriptions are turned off
    1146         if ( !bbp_is_subscriptions_active() )
     1174        if ( !bbp_is_subscriptions_active() ) {
    11471175                return false;
     1176        }
    11481177
    11491178        /** Validation ************************************************************/
    11501179
     
    11541183        /** Topic *****************************************************************/
    11551184
    11561185        // Bail if topic is not published
    1157         if ( ! bbp_is_topic_published( $topic_id ) )
     1186        if ( ! bbp_is_topic_published( $topic_id ) ) {
    11581187                return false;
     1188        }
    11591189
    1160         /** User ******************************************************************/
    1161 
    1162         // Get forum subscribers and bail if empty
    1163         $user_ids = bbp_get_forum_subscribers( $forum_id );
    1164         if ( empty( $user_ids ) )
    1165                 return false;
    1166 
    11671190        // Poster name
    11681191        $topic_author_name = bbp_get_topic_author_display_name( $topic_id );
    11691192
    11701193        /** Mail ******************************************************************/
    11711194
    1172         do_action( 'bbp_pre_notify_forum_subscribers', $topic_id, $forum_id, $user_ids );
    1173 
    11741195        // Remove filters from reply content and topic title to prevent content
    11751196        // from being encoded with HTML entities, wrapped in paragraph tags, etc...
    11761197        remove_all_filters( 'bbp_get_topic_content' );
    11771198        remove_all_filters( 'bbp_get_topic_title'   );
    11781199
    1179         // Strip tags from text
     1200        // Strip tags from text and setup mail data
    11801201        $topic_title   = strip_tags( bbp_get_topic_title( $topic_id ) );
    11811202        $topic_content = strip_tags( bbp_get_topic_content( $topic_id ) );
    11821203        $topic_url     = get_permalink( $topic_id );
    11831204        $blog_name     = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     1205        $do_not_reply = '<noreply@' . ltrim( get_home_url(), '^(http|https)://' ) . '>';
    11841206
    1185         // Loop through users
    1186         foreach ( (array) $user_ids as $user_id ) {
     1207        // For plugins to filter messages per reply/topic/user
     1208        $message = sprintf( __( '%1$s wrote:
    11871209
    1188                 // Don't send notifications to the person who made the post
    1189                 if ( !empty( $topic_author ) && (int) $user_id === (int) $topic_author )
    1190                         continue;
    1191 
    1192                 // For plugins to filter messages per reply/topic/user
    1193                 $message = sprintf( __( '%1$s wrote:
    1194 
    11951210%2$s
    11961211
    11971212Topic Link: %3$s
     
    12021217
    12031218Login and visit the topic to unsubscribe from these emails.', 'bbpress' ),
    12041219
    1205                         $topic_author_name,
    1206                         $topic_content,
    1207                         $topic_url
    1208                 );
    1209                 $message = apply_filters( 'bbp_forum_subscription_mail_message', $message, $topic_id, $forum_id, $user_id );
    1210                 if ( empty( $message ) )
    1211                         continue;
     1220                $topic_author_name,
     1221                $topic_content,
     1222                $topic_url
     1223        );
    12121224
    1213                 // For plugins to filter titles per reply/topic/user
    1214                 $subject = apply_filters( 'bbp_forum_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $topic_id, $forum_id, $user_id );
    1215                 if ( empty( $subject ) )
    1216                         continue;
     1225        $message = apply_filters( 'bbp_forum_subscription_mail_message', $message, $topic_id, $forum_id, $user_id );
     1226        if ( empty( $message ) ) {
     1227                return;
     1228        }
    12171229
    1218                 // Custom headers
    1219                 $headers = apply_filters( 'bbp_forum_subscription_mail_headers', array() );
     1230        // For plugins to filter titles per reply/topic/user
     1231        $subject = apply_filters( 'bbp_forum_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $topic_id, $forum_id, $user_id );
     1232        if ( empty( $subject ) ) {
     1233                return;
     1234        }
    12201235
    1221                 // Get user data of this user
    1222                 $user = get_userdata( $user_id );
     1236        /** User ******************************************************************/
    12231237
    1224                 // Send notification email
    1225                 wp_mail( $user->user_email, $subject, $message, $headers );
     1238        // Array to hold BCC's
     1239        $headers = array();
     1240
     1241        // Setup the From header
     1242        $headers[] = 'From: ' . get_bloginfo( 'name' ) . ' ' . $do_not_reply;
     1243
     1244        // Get topic subscribers and bail if empty
     1245        $user_ids = bbp_get_forum_subscribers( $forum_id, true );
     1246        if ( empty( $user_ids ) ) {
     1247                return false;
    12261248        }
    12271249
     1250        // Loop through users
     1251        foreach ( (array) $user_ids as $user_id ) {
     1252
     1253                // Don't send notifications to the person who made the post
     1254                if ( !empty( $topic_author ) && (int) $user_id === (int) $topic_author ) {
     1255                        continue;
     1256                }
     1257
     1258                // Get email address of subscribed user
     1259                $headers[] = 'Bcc: ' . get_userdata( $user_id )->user_email;
     1260        }
     1261
     1262        /** Send it ***************************************************************/
     1263
     1264        // Custom headers
     1265        $headers = apply_filters( 'bbp_subscription_mail_headers', $headers );
     1266
     1267        do_action( 'bbp_pre_notify_forum_subscribers', $topic_id, $forum_id, $user_ids );
     1268
     1269        // Send notification email
     1270        wp_mail( $do_not_reply, $subject, $message, $headers );
     1271
    12281272        do_action( 'bbp_post_notify_forum_subscribers', $topic_id, $forum_id, $user_ids );
    12291273
    12301274        return true;