Changeset 6725
- Timestamp:
- 10/11/2017 06:55:03 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/common/functions.php
r6711 r6725 1060 1060 $user_ids = bbp_get_subscribers( $topic_id ); 1061 1061 1062 // Dedicated filter to manipulate user ID's to send emails to1063 $user_ids = (array) apply_filters( 'bbp_topic_subscription_user_ids', $user_ids );1064 if ( empty( $user_ids ) ) {1065 return false;1066 }1067 1068 1062 // Remove the reply author from the list. 1069 1063 $reply_author_key = array_search( (int) $reply_author, $user_ids, true ); 1070 1064 if ( false !== $reply_author_key ) { 1071 unset( $user_ids[ $reply_author_key ] ); 1072 } 1065 //unset( $user_ids[ $reply_author_key ] ); 1066 } 1067 1068 // Dedicated filter to manipulate user ID's to send emails to 1069 $user_ids = (array) apply_filters( 'bbp_topic_subscription_user_ids', $user_ids ); 1073 1070 1074 1071 // Bail of the reply author was the only one subscribed. 1075 1072 if ( empty( $user_ids ) ) { 1073 return false; 1074 } 1075 1076 // Get email addresses, bail if empty 1077 $email_addresses = bbp_get_email_addresses_from_user_ids( $user_ids ); 1078 if ( empty( $email_addresses ) ) { 1076 1079 return false; 1077 1080 } … … 1131 1134 $headers = array( 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>' ); 1132 1135 1133 // Loop through users1134 foreach ( (array) $ user_ids as $user_id) {1135 $headers[] = 'Bcc: ' . get_userdata( $user_id )->user_email;1136 // Loop through addresses 1137 foreach ( (array) $email_addresses as $address ) { 1138 $headers[] = 'Bcc: ' . $address; 1136 1139 } 1137 1140 … … 1213 1216 $user_ids = bbp_get_subscribers( $forum_id ); 1214 1217 1215 // Dedicated filter to manipulate user ID's to send emails to1216 $user_ids = (array) apply_filters( 'bbp_forum_subscription_user_ids', $user_ids );1217 if ( empty( $user_ids ) ) {1218 return false;1219 }1220 1221 1218 // Remove the topic author from the list. 1222 1219 $topic_author_key = array_search( (int) $topic_author, $user_ids, true ); … … 1225 1222 } 1226 1223 1227 // Bail of the topic author was the only one subscribed. 1224 // Dedicated filter to manipulate user ID's to send emails to 1225 $user_ids = (array) apply_filters( 'bbp_forum_subscription_user_ids', $user_ids ); 1226 1227 // Bail of the reply author was the only one subscribed. 1228 1228 if ( empty( $user_ids ) ) { 1229 return false; 1230 } 1231 1232 // Get email addresses, bail if empty 1233 $email_addresses = bbp_get_email_addresses_from_user_ids( $user_ids ); 1234 if ( empty( $email_addresses ) ) { 1229 1235 return false; 1230 1236 } … … 1284 1290 $headers = array( 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>' ); 1285 1291 1286 // Loop through users1287 foreach ( (array) $ user_ids as $user_id) {1288 $headers[] = 'Bcc: ' . get_userdata( $user_id )->user_email;1292 // Loop through addresses 1293 foreach ( (array) $email_addresses as $address ) { 1294 $headers[] = 'Bcc: ' . $address; 1289 1295 } 1290 1296 … … 1331 1337 function bbp_notify_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $reply_author = 0 ) { 1332 1338 return bbp_notify_topic_subscribers( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author ); 1339 } 1340 1341 /** 1342 * Return an array of user email addresses from an array of user IDs 1343 * 1344 * @since 2.6.0 bbPress (r6722) 1345 * 1346 * @param array $user_ids 1347 * @return array 1348 */ 1349 function bbp_get_email_addresses_from_user_ids( $user_ids = array() ) { 1350 1351 // Default return value 1352 $retval = array(); 1353 1354 // Maximum number of users to get per database query 1355 $limit = apply_filters( 'bbp_get_users_chunk_limit', 100 ); 1356 1357 // Only do the work if there are user IDs to query for 1358 if ( ! empty( $user_ids ) ) { 1359 1360 // Get total number of sets 1361 $steps = ceil( count( $user_ids ) / $limit ); 1362 1363 // Loop through users 1364 foreach ( range( 1, $steps ) as $loop ) { 1365 1366 // Initial loop has no offset 1367 $offset = ( 1 === $loop ) 1368 ? 1 1369 : $limit * $loop; 1370 1371 // Calculate user IDs to include 1372 $loop_ids = array_slice( $user_ids, $offset, $limit ); 1373 1374 // Call get_users() in a way that users are cached 1375 $loop_users = get_users( array( 1376 'blog_id' => 0, 1377 'fields' => 'all_with_meta', 1378 'include' => $loop_ids 1379 ) ); 1380 1381 // Pluck emails from users 1382 $loop_emails = wp_list_pluck( $loop_users, 'user_email' ); 1383 1384 // Clean-up memory, for big user sets 1385 unset( $loop_users ); 1386 1387 // Merge users into return value 1388 if ( ! empty( $loop_emails ) ) { 1389 $retval = array_merge( $retval, $loop_emails ); 1390 } 1391 } 1392 1393 // No duplicates 1394 $retval = bbp_get_unique_array_values( $retval ); 1395 } 1396 1397 // Filter & return 1398 return apply_filters( 'bbp_get_email_addresses_from_user_ids', $retval, $user_ids, $limit ); 1333 1399 } 1334 1400
Note: See TracChangeset
for help on using the changeset viewer.