Changeset 6919
- Timestamp:
- 11/06/2019 12:02:53 AM (4 years ago)
- Location:
- trunk/src/includes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/common/functions.php
r6917 r6919 1132 1132 /** Headers ***************************************************************/ 1133 1133 1134 // Default bbPress X-header 1135 $headers = array( bbp_get_email_header() ); 1136 1134 1137 // Get the noreply@ address 1135 1138 $no_reply = bbp_get_do_not_reply_address(); … … 1139 1142 1140 1143 // Setup the From header 1141 $headers = array( 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>' );1144 $headers[] = 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>'; 1142 1145 1143 1146 // Loop through addresses … … 1152 1155 $to_email = apply_filters( 'bbp_subscription_to_email', $no_reply ); 1153 1156 1157 // Before 1154 1158 do_action( 'bbp_pre_notify_subscribers', $reply_id, $topic_id, $user_ids ); 1155 1159 … … 1157 1161 wp_mail( $to_email, $subject, $message, $headers ); 1158 1162 1163 // After 1159 1164 do_action( 'bbp_post_notify_subscribers', $reply_id, $topic_id, $user_ids ); 1160 1165 … … 1294 1299 /** Headers ***************************************************************/ 1295 1300 1301 // Default bbPress X-header 1302 $headers = array( bbp_get_email_header() ); 1303 1296 1304 // Get the noreply@ address 1297 1305 $no_reply = bbp_get_do_not_reply_address(); … … 1301 1309 1302 1310 // Setup the From header 1303 $headers = array( 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>' );1311 $headers[] = 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>'; 1304 1312 1305 1313 // Loop through addresses … … 1314 1322 $to_email = apply_filters( 'bbp_subscription_to_email', $no_reply ); 1315 1323 1324 // Before 1316 1325 do_action( 'bbp_pre_notify_forum_subscribers', $topic_id, $forum_id, $user_ids ); 1317 1326 … … 1319 1328 wp_mail( $to_email, $subject, $message, $headers ); 1320 1329 1330 // After 1321 1331 do_action( 'bbp_post_notify_forum_subscribers', $topic_id, $forum_id, $user_ids ); 1322 1332 … … 1416 1426 // Filter & return 1417 1427 return apply_filters( 'bbp_get_email_addresses_from_user_ids', $retval, $user_ids, $limit ); 1428 } 1429 1430 /** 1431 * Automatically splits bbPress emails with many Bcc recipients into chunks. 1432 * 1433 * This middleware is useful because topics and forums with many subscribers 1434 * run into problems with Bcc limits, and many hosting companies & third-party 1435 * services limit the size of a Bcc audience to prevent spamming. 1436 * 1437 * The default "chunk" size is 40 users per iteration, and can be filtered if 1438 * desired. A future version of bbPress will introduce a setting to more easily 1439 * tune this. 1440 * 1441 * @since 2.6.0 (r6918) 1442 * 1443 * @param array $args Original arguments passed to wp_mail(). 1444 * @return array 1445 */ 1446 function bbp_chunk_emails( $args = array() ) { 1447 1448 // Get the maximum number of Bcc's per chunk 1449 $max_num = apply_filters( 'bbp_get_bcc_chunk_limit', 40, $args ); 1450 1451 // Look for "bcc: " in a case-insensitive way, and split into 2 sets 1452 $match = '/^bcc: (\w+)/i'; 1453 $old_headers = preg_grep( $match, $args['headers'], PREG_GREP_INVERT ); 1454 $bcc_headers = preg_grep( $match, $args['headers'] ); 1455 1456 // Bail if less than $max_num recipients 1457 if ( empty( $bcc_headers ) || ( count( $bcc_headers ) < $max_num ) ) { 1458 return $args; 1459 } 1460 1461 // Reindex the headers arrays 1462 $old_headers = array_values( $old_headers ); 1463 $bcc_headers = array_values( $bcc_headers ); 1464 1465 // Break the Bcc emails into chunks 1466 foreach ( array_chunk( $bcc_headers, $max_num ) as $i => $chunk ) { 1467 1468 // Skip the first chunk (it will get used in the original wp_mail() call) 1469 if ( 0 === $i ) { 1470 $first_chunk = $chunk; 1471 continue; 1472 } 1473 1474 // Send out the chunk 1475 $chunk_headers = array_merge( $old_headers, $chunk ); 1476 1477 // Recursion alert, but should be OK! 1478 wp_mail( 1479 $args['to'], 1480 $args['subject'], 1481 $args['message'], 1482 $chunk_headers, 1483 $args['attachments'] 1484 ); 1485 } 1486 1487 // Set headers to old headers + the $first_chunk of Bcc's 1488 $args['headers'] = array_merge( $old_headers, $first_chunk ); 1489 1490 // Return the reduced args, with the first chunk of Bcc's 1491 return $args; 1492 } 1493 1494 /** 1495 * Return the string used for the bbPress specific X-header. 1496 * 1497 * @since 2.6.0 (r6919) 1498 * 1499 * @return string 1500 */ 1501 function bbp_get_email_header() { 1502 return apply_filters( 'bbp_get_email_header', 'X-bbPress: ' . bbp_get_version() ); 1418 1503 } 1419 1504 -
trunk/src/includes/core/filters.php
r6719 r6919 40 40 add_filter( 'request', 'bbp_request', 10 ); 41 41 add_filter( 'template_include', 'bbp_template_include', 10 ); 42 add_filter( 'wp_mail', 'bbp_mail', 10, 3 ); 42 43 add_filter( 'wp_title', 'bbp_title', 10, 3 ); 43 44 add_filter( 'body_class', 'bbp_body_class', 10, 2 ); … … 69 70 70 71 /** 72 * Emails 73 * 74 * bbPress sends emails for a few different reasons, largely related to user 75 * notifications or account changes. Because the `wp_mail` filter can be a 76 * crowded space, the `bbp_mail` subfilter should be used in conjunction with 77 * bbp_get_email_header() to narrow the results to only bbPress emails. 78 */ 79 add_filter( 'bbp_mail', 'bbp_chunk_emails' ); 80 81 /** 71 82 * Feeds 72 83 * … … 84 95 * bbp_template_include() works and do something similar. :) 85 96 */ 86 add_filter( 'bbp_template_include', 87 add_filter( 'bbp_template_include', 97 add_filter( 'bbp_template_include', 'bbp_template_include_theme_supports', 2, 1 ); 98 add_filter( 'bbp_template_include', 'bbp_template_include_theme_compat', 4, 2 ); 88 99 89 100 // Filter bbPress template locations 90 add_filter( 'bbp_get_template_stack', 'bbp_add_template_stack_locations' 101 add_filter( 'bbp_get_template_stack', 'bbp_add_template_stack_locations' ); 91 102 92 103 // Links … … 97 108 98 109 // wp_filter_kses on new/edit forum/topic/reply title 99 add_filter( 'bbp_new_forum_pre_title', 'wp_filter_kses' 100 add_filter( 'bbp_new_reply_pre_title', 'wp_filter_kses' 101 add_filter( 'bbp_new_topic_pre_title', 'wp_filter_kses' 102 add_filter( 'bbp_edit_forum_pre_title', 'wp_filter_kses' 103 add_filter( 'bbp_edit_reply_pre_title', 'wp_filter_kses' 104 add_filter( 'bbp_edit_topic_pre_title', 'wp_filter_kses' 110 add_filter( 'bbp_new_forum_pre_title', 'wp_filter_kses' ); 111 add_filter( 'bbp_new_reply_pre_title', 'wp_filter_kses' ); 112 add_filter( 'bbp_new_topic_pre_title', 'wp_filter_kses' ); 113 add_filter( 'bbp_edit_forum_pre_title', 'wp_filter_kses' ); 114 add_filter( 'bbp_edit_reply_pre_title', 'wp_filter_kses' ); 115 add_filter( 'bbp_edit_topic_pre_title', 'wp_filter_kses' ); 105 116 106 117 // Prevent posting malicious or malformed content on new/edit topic/reply -
trunk/src/includes/core/sub-actions.php
r6876 r6919 524 524 return (array) apply_filters( 'bbp_map_meta_caps', $caps, $cap, $user_id, $args ); 525 525 } 526 527 /** 528 * Filter the arguments used by wp_mail for bbPress specific emails 529 * 530 * @since 2.6.0 bbPress (r6918) 531 * 532 * @param array $args A compacted array of wp_mail() arguments, including the "to" email, 533 * subject, message, headers, and attachments values. 534 * 535 * @return array Array of capabilities 536 */ 537 function bbp_mail( $args = array() ) { 538 539 // Bail if headers are missing/malformed 540 if ( empty( $args['headers'] ) || ! is_array( $args['headers'] ) ) { 541 return $args; 542 } 543 544 // Header to search all headers for 545 $bbp_header = bbp_get_email_header(); 546 547 // Bail if no bbPress header found 548 if ( false === array_search( $bbp_header, $args['headers'], true ) ) { 549 return $args; 550 } 551 552 // Filter & return 553 return (array) apply_filters( 'bbp_mail', $args ); 554 }
Note: See TracChangeset
for help on using the changeset viewer.