Ticket #2162: 2162.2.diff
File 2162.2.diff, 11.1 KB (added by , 11 years ago) |
---|
-
includes/common/functions.php
987 987 * Gets new post's ID and check if there are subscribed users to that topic, and 988 988 * if there are, send notifications 989 989 * 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 * 990 996 * @since bbPress (r2668) 991 997 * 992 998 * @param int $reply_id ID of the newly made reply … … 1017 1023 function bbp_notify_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0 ) { 1018 1024 1019 1025 // Bail if subscriptions are turned off 1020 if ( !bbp_is_subscriptions_active() ) 1026 if ( !bbp_is_subscriptions_active() ) { 1021 1027 return false; 1028 } 1022 1029 1023 1030 /** Validation ************************************************************/ 1024 1031 … … 1026 1033 $topic_id = bbp_get_topic_id( $topic_id ); 1027 1034 $forum_id = bbp_get_forum_id( $forum_id ); 1028 1035 1029 /** Reply *****************************************************************/1030 1031 // Bail if reply is not published1032 if ( !bbp_is_reply_published( $reply_id ) )1033 return false;1034 1035 1036 /** Topic *****************************************************************/ 1036 1037 1037 1038 // Bail if topic is not published 1038 if ( !bbp_is_topic_published( $topic_id ) ) 1039 if ( !bbp_is_topic_published( $topic_id ) ) { 1039 1040 return false; 1041 } 1040 1042 1041 /** User ******************************************************************/1043 /** Reply *****************************************************************/ 1042 1044 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 ) ) { 1046 1047 return false; 1048 } 1047 1049 1048 1050 // Poster name 1049 1051 $reply_author_name = bbp_get_reply_author_display_name( $reply_id ); … … 1050 1052 1051 1053 /** Mail ******************************************************************/ 1052 1054 1053 do_action( 'bbp_pre_notify_subscribers', $reply_id, $topic_id, $user_ids );1054 1055 1055 // Remove filters from reply content and topic title to prevent content 1056 1056 // from being encoded with HTML entities, wrapped in paragraph tags, etc... 1057 1057 remove_all_filters( 'bbp_get_reply_content' ); 1058 1058 remove_all_filters( 'bbp_get_topic_title' ); 1059 1059 1060 // Strip tags from text 1060 // Strip tags from text and setup mail data 1061 1061 $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) ); 1062 1062 $reply_content = strip_tags( bbp_get_reply_content( $reply_id ) ); 1063 1063 $reply_url = bbp_get_reply_url( $reply_id ); 1064 1064 $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 1065 $do_not_reply = '<noreply@' . ltrim( get_home_url(), '^(http|https)://' ) . '>'; 1065 1066 1066 // Loop through users1067 foreach ( (array) $user_ids as $user_id ) {1067 // For plugins to filter messages per reply/topic/user 1068 $message = sprintf( __( '%1$s wrote: 1068 1069 1069 // Don't send notifications to the person who made the post1070 if ( !empty( $reply_author ) && (int) $user_id === (int) $reply_author )1071 continue;1072 1073 // For plugins to filter messages per reply/topic/user1074 $message = sprintf( __( '%1$s wrote:1075 1076 1070 %2$s 1077 1071 1078 1072 Post Link: %3$s … … 1083 1077 1084 1078 Login and visit the topic to unsubscribe from these emails.', 'bbpress' ), 1085 1079 1086 1087 1088 1089 1080 $reply_author_name, 1081 $reply_content, 1082 $reply_url 1083 ); 1090 1084 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 } 1094 1089 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 } 1099 1095 1100 // Custom headers 1101 $headers = apply_filters( 'bbp_subscription_mail_headers', array() ); 1096 /** Users *****************************************************************/ 1102 1097 1103 // Get user data of this user1104 $user = get_userdata( $user_id);1098 // Array to hold BCC's 1099 $headers = array(); 1105 1100 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; 1108 1108 } 1109 1109 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 1110 1132 do_action( 'bbp_post_notify_subscribers', $reply_id, $topic_id, $user_ids ); 1111 1133 1112 1134 return true; … … 1115 1137 /** 1116 1138 * Sends notification emails for new topics to subscribed forums 1117 1139 * 1118 * Gets new post's ID and check if there are subscribed users to that topic, and1140 * Gets new post's ID and check if there are subscribed users to that forum, and 1119 1141 * if there are, send notifications 1120 1142 * 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 * 1121 1149 * @since bbPress (r5156) 1122 1150 * 1123 1151 * @param int $topic_id ID of the newly made reply … … 1143 1171 function bbp_notify_forum_subscribers( $topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0 ) { 1144 1172 1145 1173 // Bail if subscriptions are turned off 1146 if ( !bbp_is_subscriptions_active() ) 1174 if ( !bbp_is_subscriptions_active() ) { 1147 1175 return false; 1176 } 1148 1177 1149 1178 /** Validation ************************************************************/ 1150 1179 … … 1154 1183 /** Topic *****************************************************************/ 1155 1184 1156 1185 // Bail if topic is not published 1157 if ( ! bbp_is_topic_published( $topic_id ) ) 1186 if ( ! bbp_is_topic_published( $topic_id ) ) { 1158 1187 return false; 1188 } 1159 1189 1160 /** User ******************************************************************/1161 1162 // Get forum subscribers and bail if empty1163 $user_ids = bbp_get_forum_subscribers( $forum_id );1164 if ( empty( $user_ids ) )1165 return false;1166 1167 1190 // Poster name 1168 1191 $topic_author_name = bbp_get_topic_author_display_name( $topic_id ); 1169 1192 1170 1193 /** Mail ******************************************************************/ 1171 1194 1172 do_action( 'bbp_pre_notify_forum_subscribers', $topic_id, $forum_id, $user_ids );1173 1174 1195 // Remove filters from reply content and topic title to prevent content 1175 1196 // from being encoded with HTML entities, wrapped in paragraph tags, etc... 1176 1197 remove_all_filters( 'bbp_get_topic_content' ); 1177 1198 remove_all_filters( 'bbp_get_topic_title' ); 1178 1199 1179 // Strip tags from text 1200 // Strip tags from text and setup mail data 1180 1201 $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) ); 1181 1202 $topic_content = strip_tags( bbp_get_topic_content( $topic_id ) ); 1182 1203 $topic_url = get_permalink( $topic_id ); 1183 1204 $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 1205 $do_not_reply = '<noreply@' . ltrim( get_home_url(), '^(http|https)://' ) . '>'; 1184 1206 1185 // Loop through users1186 foreach ( (array) $user_ids as $user_id ) {1207 // For plugins to filter messages per reply/topic/user 1208 $message = sprintf( __( '%1$s wrote: 1187 1209 1188 // Don't send notifications to the person who made the post1189 if ( !empty( $topic_author ) && (int) $user_id === (int) $topic_author )1190 continue;1191 1192 // For plugins to filter messages per reply/topic/user1193 $message = sprintf( __( '%1$s wrote:1194 1195 1210 %2$s 1196 1211 1197 1212 Topic Link: %3$s … … 1202 1217 1203 1218 Login and visit the topic to unsubscribe from these emails.', 'bbpress' ), 1204 1219 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 ); 1212 1224 1213 // For plugins to filter titles per reply/topic/user1214 $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 } 1217 1229 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 } 1220 1235 1221 // Get user data of this user 1222 $user = get_userdata( $user_id ); 1236 /** User ******************************************************************/ 1223 1237 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; 1226 1248 } 1227 1249 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 1228 1272 do_action( 'bbp_post_notify_forum_subscribers', $topic_id, $forum_id, $user_ids ); 1229 1273 1230 1274 return true;