Changeset 5156 for trunk/includes/common/functions.php
- Timestamp:
- 11/20/2013 07:50:55 PM (12 years ago)
- File:
-
- 1 edited
-
trunk/includes/common/functions.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/common/functions.php
r5134 r5156 983 983 984 984 /** 985 * Sends notification emails for new posts985 * Sends notification emails for new replies to subscribed topics 986 986 * 987 987 * Gets new post's ID and check if there are subscribed users to that topic, and … … 993 993 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 994 994 * @uses bbp_get_reply_id() To validate the reply ID 995 * @uses bbp_get_topic_id() To validate the topic ID 996 * @uses bbp_get_forum_id() To validate the forum ID 995 997 * @uses bbp_get_reply() To get the reply 996 * @uses bbp_get_reply_topic_id() To get the topic ID of the reply997 998 * @uses bbp_is_reply_published() To make sure the reply is published 998 999 * @uses bbp_get_topic_id() To validate the topic ID 999 1000 * @uses bbp_get_topic() To get the reply's topic 1000 1001 * @uses bbp_is_topic_published() To make sure the topic is published 1001 * @uses get_the_author_meta() To get theauthor's display name1002 * @uses do_action() Calls 'bbp_pre_notify_subscribers' with the reply id and1003 * topic id 1002 * @uses bbp_get_reply_author_display_name() To get the reply author's display name 1003 * @uses do_action() Calls 'bbp_pre_notify_subscribers' with the reply id, 1004 * topic id and user id 1004 1005 * @uses bbp_get_topic_subscribers() To get the topic subscribers 1005 1006 * @uses apply_filters() Calls 'bbp_subscription_mail_message' with the 1006 * message, reply id, topic id and user id 1007 * message, reply id, topic id and user id 1008 * @uses apply_filters() Calls 'bbp_subscription_mail_title' with the 1009 * topic title, reply id, topic id and user id 1010 * @uses apply_filters() Calls 'bbp_subscription_mail_headers' 1007 1011 * @uses get_userdata() To get the user data 1008 1012 * @uses wp_mail() To send the mail 1009 * @uses do_action() Calls 'bbp_post_notify_subscribers' with the reply id 1010 * and topicid1013 * @uses do_action() Calls 'bbp_post_notify_subscribers' with the reply id, 1014 * topic id and user id 1011 1015 * @return bool True on success, false on failure 1012 1016 */ … … 1037 1041 /** User ******************************************************************/ 1038 1042 1039 // Get subscribers and bail if empty1043 // Get topic subscribers and bail if empty 1040 1044 $user_ids = bbp_get_topic_subscribers( $topic_id, true ); 1041 1045 if ( empty( $user_ids ) ) … … 1105 1109 1106 1110 do_action( 'bbp_post_notify_subscribers', $reply_id, $topic_id, $user_ids ); 1111 1112 return true; 1113 } 1114 1115 /** 1116 * Sends notification emails for new topics to subscribed forums 1117 * 1118 * Gets new post's ID and check if there are subscribed users to that topic, and 1119 * if there are, send notifications 1120 * 1121 * @since bbPress (rxxxx) 1122 * 1123 * @param int $topic_id ID of the newly made reply 1124 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 1125 * @uses bbp_get_topic_id() To validate the topic ID 1126 * @uses bbp_get_forum_id() To validate the forum ID 1127 * @uses bbp_is_topic_published() To make sure the topic is published 1128 * @uses bbp_get_forum_subscribers() To get the forum subscribers 1129 * @uses bbp_get_topic_author_display_name() To get the topic author's display name 1130 * @uses do_action() Calls 'bbp_pre_notify_forum_subscribers' with the topic id, 1131 * forum id and user id 1132 * @uses apply_filters() Calls 'bbp_forum_subscription_mail_message' with the 1133 * message, topic id, forum id and user id 1134 * @uses apply_filters() Calls 'bbp_forum_subscription_mail_title' with the 1135 * topic title, topic id, forum id and user id 1136 * @uses apply_filters() Calls 'bbp_forum_subscription_mail_headers' 1137 * @uses get_userdata() To get the user data 1138 * @uses wp_mail() To send the mail 1139 * @uses do_action() Calls 'bbp_post_notify_forum_subscribers' with the topic, 1140 * id, forum id and user id 1141 * @return bool True on success, false on failure 1142 */ 1143 function bbp_notify_forum_subscribers( $topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0 ) { 1144 1145 // Bail if subscriptions are turned off 1146 if ( !bbp_is_subscriptions_active() ) 1147 return false; 1148 1149 /** Validation ************************************************************/ 1150 1151 $topic_id = bbp_get_topic_id( $topic_id ); 1152 $forum_id = bbp_get_forum_id( $forum_id ); 1153 1154 /** Topic *****************************************************************/ 1155 1156 // Bail if topic is not published 1157 if ( ! bbp_is_topic_published( $topic_id ) ) 1158 return false; 1159 1160 /** User ******************************************************************/ 1161 1162 // Get forum subscribers and bail if empty 1163 $user_ids = bbp_get_forum_subscribers( $forum_id, true ); 1164 if ( empty( $user_ids ) ) 1165 return false; 1166 1167 // Poster name 1168 $topic_author_name = bbp_get_topic_author_display_name( $topic_id ); 1169 1170 /** Mail ******************************************************************/ 1171 1172 do_action( 'bbp_pre_notify_forum_subscribers', $topic_id, $forum_id, $user_ids ); 1173 1174 // Remove filters from reply content and topic title to prevent content 1175 // from being encoded with HTML entities, wrapped in paragraph tags, etc... 1176 remove_all_filters( 'bbp_get_topic_content' ); 1177 remove_all_filters( 'bbp_get_topic_title' ); 1178 1179 // Strip tags from text 1180 $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) ); 1181 $topic_content = strip_tags( bbp_get_topic_content( $topic_id ) ); 1182 $topic_url = get_permalink( $topic_id ); 1183 $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 1184 1185 // Loop through users 1186 foreach ( (array) $user_ids as $user_id ) { 1187 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 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 } 1227 1228 do_action( 'bbp_post_notify_forum_subscribers', $topic_id, $forum_id, $user_ids ); 1107 1229 1108 1230 return true;
Note: See TracChangeset
for help on using the changeset viewer.