Changeset 5260
- Timestamp:
- 01/16/2014 08:39:12 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/common/functions.php
r5239 r5260 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 * … … 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 ************************************************************/ … … 1027 1034 $forum_id = bbp_get_forum_id( $forum_id ); 1028 1035 1036 /** Topic *****************************************************************/ 1037 1038 // Bail if topic is not published 1039 if ( !bbp_is_topic_published( $topic_id ) ) { 1040 return false; 1041 } 1042 1029 1043 /** Reply *****************************************************************/ 1030 1044 1031 1045 // Bail if reply is not published 1032 if ( !bbp_is_reply_published( $reply_id ) ) 1046 if ( !bbp_is_reply_published( $reply_id ) ) { 1033 1047 return false; 1034 1035 /** Topic *****************************************************************/ 1036 1037 // Bail if topic is not published 1038 if ( !bbp_is_topic_published( $topic_id ) ) 1039 return false; 1040 1041 /** User ******************************************************************/ 1042 1043 // Get topic subscribers and bail if empty 1044 $user_ids = bbp_get_topic_subscribers( $topic_id ); 1045 if ( empty( $user_ids ) ) 1046 return false; 1048 } 1047 1049 1048 1050 // Poster name … … 1050 1052 1051 1053 /** Mail ******************************************************************/ 1052 1053 do_action( 'bbp_pre_notify_subscribers', $reply_id, $topic_id, $user_ids );1054 1054 1055 1055 // Remove filters from reply content and topic title to prevent 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)://' ) . '>'; 1066 1067 // For plugins to filter messages per reply/topic/user 1068 $message = sprintf( __( '%1$s wrote: 1069 1070 %2$s 1071 1072 Post Link: %3$s 1073 1074 ----------- 1075 1076 You are receiving this email because you subscribed to a forum topic. 1077 1078 Login and visit the topic to unsubscribe from these emails.', 'bbpress' ), 1079 1080 $reply_author_name, 1081 $reply_content, 1082 $reply_url 1083 ); 1084 1085 $message = apply_filters( 'bbp_subscription_mail_message', $message, $reply_id, $topic_id ); 1086 if ( empty( $message ) ) { 1087 return; 1088 } 1089 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 } 1095 1096 /** Users *****************************************************************/ 1097 1098 // Array to hold BCC's 1099 $headers = array(); 1100 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 } 1065 1109 1066 1110 // Loop through users … … 1068 1112 1069 1113 // Don't send notifications to the person who made the post 1070 if ( !empty( $reply_author ) && (int) $user_id === (int) $reply_author ) 1114 if ( !empty( $reply_author ) && (int) $user_id === (int) $reply_author ) { 1071 1115 continue; 1072 1073 // For plugins to filter messages per reply/topic/user 1074 $message = sprintf( __( '%1$s wrote: 1075 1076 %2$s 1077 1078 Post Link: %3$s 1079 1080 ----------- 1081 1082 You are receiving this email because you subscribed to a forum topic. 1083 1084 Login and visit the topic to unsubscribe from these emails.', 'bbpress' ), 1085 1086 $reply_author_name, 1087 $reply_content, 1088 $reply_url 1089 ); 1090 1091 $message = apply_filters( 'bbp_subscription_mail_message', $message, $reply_id, $topic_id, $user_id ); 1092 if ( empty( $message ) ) 1093 continue; 1094 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; 1099 1100 // Custom headers 1101 $headers = apply_filters( 'bbp_subscription_mail_headers', array() ); 1102 1103 // Get user data of this user 1104 $user = get_userdata( $user_id ); 1105 1106 // Send notification email 1107 wp_mail( $user->user_email, $subject, $message, $headers ); 1108 } 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 ); 1109 1131 1110 1132 do_action( 'bbp_post_notify_subscribers', $reply_id, $topic_id, $user_ids ); … … 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 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. 1120 1148 * 1121 1149 * @since bbPress (r5156) … … 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 ************************************************************/ … … 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; 1159 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; 1188 } 1166 1189 1167 1190 // Poster name … … 1169 1192 1170 1193 /** Mail ******************************************************************/ 1171 1172 do_action( 'bbp_pre_notify_forum_subscribers', $topic_id, $forum_id, $user_ids );1173 1194 1174 1195 // Remove filters from reply content and topic title to prevent 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)://' ) . '>'; 1206 1207 // For plugins to filter messages per reply/topic/user 1208 $message = sprintf( __( '%1$s wrote: 1209 1210 %2$s 1211 1212 Topic Link: %3$s 1213 1214 ----------- 1215 1216 You are receiving this email because you subscribed to a forum. 1217 1218 Login and visit the topic to unsubscribe from these emails.', 'bbpress' ), 1219 1220 $topic_author_name, 1221 $topic_content, 1222 $topic_url 1223 ); 1224 1225 $message = apply_filters( 'bbp_forum_subscription_mail_message', $message, $topic_id, $forum_id, $user_id ); 1226 if ( empty( $message ) ) { 1227 return; 1228 } 1229 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 } 1235 1236 /** User ******************************************************************/ 1237 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; 1248 } 1184 1249 1185 1250 // Loop through users … … 1187 1252 1188 1253 // Don't send notifications to the person who made the post 1189 if ( !empty( $topic_author ) && (int) $user_id === (int) $topic_author ) 1254 if ( !empty( $topic_author ) && (int) $user_id === (int) $topic_author ) { 1190 1255 continue; 1191 1192 // For plugins to filter messages per reply/topic/user 1193 $message = sprintf( __( '%1$s wrote: 1194 1195 %2$s 1196 1197 Topic Link: %3$s 1198 1199 ----------- 1200 1201 You are receiving this email because you subscribed to a forum. 1202 1203 Login and visit the topic to unsubscribe from these emails.', 'bbpress' ), 1204 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; 1212 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; 1217 1218 // Custom headers 1219 $headers = apply_filters( 'bbp_forum_subscription_mail_headers', array() ); 1220 1221 // Get user data of this user 1222 $user = get_userdata( $user_id ); 1223 1224 // Send notification email 1225 wp_mail( $user->user_email, $subject, $message, $headers ); 1226 } 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 ); 1227 1271 1228 1272 do_action( 'bbp_post_notify_forum_subscribers', $topic_id, $forum_id, $user_ids );
Note: See TracChangeset
for help on using the changeset viewer.