Skip to:
Content

bbPress.org


Ignore:
Timestamp:
03/17/2015 03:38:20 AM (10 years ago)
Author:
johnjamesjacoby
Message:

Backport do_not_reply email address code from trunk to 2.5 branch (for what will be 2.5.6.) See #2618, r5642.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.5/includes/common/functions.php

    r5639 r5643  
    983983
    984984/**
     985 * Get the "Do Not Reply" email address to use when sending subscription emails.
     986 *
     987 * We make some educated guesses here based on the home URL. Filters are
     988 * available to customize this address further. In the future, we may consider
     989 * using `admin_email` instead, though this is not normally publicized.
     990 *
     991 * We use `$_SERVER['SERVER_NAME']` here to mimic similar functionality in
     992 * WordPress core. Previously, we used `get_home_url()` to use already validated
     993 * user input, but it was causing issues in some installations.
     994 *
     995 * @since bbPress (r5409)
     996 *
     997 * @see  wp_mail
     998 * @see  wp_notify_postauthor
     999 * @link https://bbpress.trac.wordpress.org/ticket/2618
     1000 *
     1001 * @return string
     1002 */
     1003function bbp_get_do_not_reply_address() {
     1004    $sitename = strtolower( $_SERVER['SERVER_NAME'] );
     1005    if ( substr( $sitename, 0, 4 ) === 'www.' ) {
     1006        $sitename = substr( $sitename, 4 );
     1007    }
     1008    return apply_filters( 'bbp_get_do_not_reply_address', 'noreply@' . $sitename );
     1009}
     1010
     1011/**
    9851012 * Sends notification emails for new replies to subscribed topics
    9861013 *
     
    9941021 * custom emailer script.
    9951022 *
    996  * @since bbPress (r2668)
     1023 * @since bbPress (r5413)
    9971024 *
    9981025 * @param int $reply_id ID of the newly made reply
     1026 * @param int $topic_id ID of the topic of the reply
     1027 * @param int $forum_id ID of the forum of the reply
     1028 * @param mixed $anonymous_data Array of anonymous user data
     1029 * @param int $reply_author ID of the topic author ID
     1030 *
    9991031 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
    10001032 * @uses bbp_get_reply_id() To validate the reply ID
     
    10211053 * @return bool True on success, false on failure
    10221054 */
    1023 function bbp_notify_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0 ) {
     1055function bbp_notify_topic_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0 ) {
    10241056
    10251057    // Bail if subscriptions are turned off
     
    10631095    $reply_url     = bbp_get_reply_url( $reply_id );
    10641096    $blog_name     = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    1065     $do_not_reply  = '<noreply@' . preg_replace( '@^https?://(www\.)?@i', '', get_home_url() ) . '>';
    10661097
    10671098    // For plugins to filter messages per reply/topic/user
     
    10961127    /** Users *****************************************************************/
    10971128
    1098     // Array to hold BCC's
    1099     $headers = array();
     1129    // Get the noreply@ address
     1130    $no_reply   = bbp_get_do_not_reply_address();
     1131
     1132    // Setup "From" email address
     1133    $from_email = apply_filters( 'bbp_subscription_from_email', $no_reply );
    11001134
    11011135    // Setup the From header
    1102     $headers[] = 'From: ' . get_bloginfo( 'name' ) . ' ' . $do_not_reply;
     1136    $headers = array( 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>' );
    11031137
    11041138    // Get topic subscribers and bail if empty
    11051139    $user_ids = bbp_get_topic_subscribers( $topic_id, true );
     1140
     1141    // Dedicated filter to manipulate user ID's to send emails to
     1142    $user_ids = apply_filters( 'bbp_topic_subscription_user_ids', $user_ids );
    11061143    if ( empty( $user_ids ) ) {
    11071144        return false;
     
    11231160
    11241161    // Custom headers
    1125     $headers = apply_filters( 'bbp_subscription_mail_headers', $headers );
     1162    $headers  = apply_filters( 'bbp_subscription_mail_headers', $headers  );
     1163    $to_email = apply_filters( 'bbp_subscription_to_email',     $no_reply );
    11261164
    11271165    do_action( 'bbp_pre_notify_subscribers', $reply_id, $topic_id, $user_ids );
    11281166
    11291167    // Send notification email
    1130     wp_mail( $do_not_reply, $subject, $message, $headers );
     1168    wp_mail( $to_email, $subject, $message, $headers );
    11311169
    11321170    do_action( 'bbp_post_notify_subscribers', $reply_id, $topic_id, $user_ids );
     
    11501188 *
    11511189 * @param int $topic_id ID of the newly made reply
     1190 * @param int $forum_id ID of the forum for the topic
     1191 * @param mixed $anonymous_data Array of anonymous user data
     1192 * @param int $topic_author ID of the topic author ID
     1193 *
    11521194 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
    11531195 * @uses bbp_get_topic_id() To validate the topic ID
     
    11811223    $forum_id = bbp_get_forum_id( $forum_id );
    11821224
     1225    /**
     1226     * Necessary for backwards compatibility
     1227     *
     1228     * @see https://bbpress.trac.wordpress.org/ticket/2620
     1229     */
     1230    $user_id  = 0;
     1231
    11831232    /** Topic *****************************************************************/
    11841233
     
    12031252    $topic_url     = get_permalink( $topic_id );
    12041253    $blog_name     = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    1205     $do_not_reply  = '<noreply@' . preg_replace( '@^https?://(www\.)?@i', '', get_home_url() ) . '>';
    12061254
    12071255    // For plugins to filter messages per reply/topic/user
     
    12361284    /** User ******************************************************************/
    12371285
    1238     // Array to hold BCC's
    1239     $headers = array();
     1286    // Get the noreply@ address
     1287    $no_reply   = bbp_get_do_not_reply_address();
     1288
     1289    // Setup "From" email address
     1290    $from_email = apply_filters( 'bbp_subscription_from_email', $no_reply );
    12401291
    12411292    // Setup the From header
    1242     $headers[] = 'From: ' . get_bloginfo( 'name' ) . ' ' . $do_not_reply;
     1293    $headers = array( 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>' );
    12431294
    12441295    // Get topic subscribers and bail if empty
    12451296    $user_ids = bbp_get_forum_subscribers( $forum_id, true );
     1297
     1298    // Dedicated filter to manipulate user ID's to send emails to
     1299    $user_ids = apply_filters( 'bbp_forum_subscription_user_ids', $user_ids );
    12461300    if ( empty( $user_ids ) ) {
    12471301        return false;
     
    12631317
    12641318    // Custom headers
    1265     $headers = apply_filters( 'bbp_subscription_mail_headers', $headers );
     1319    $headers  = apply_filters( 'bbp_subscription_mail_headers', $headers  );
     1320    $to_email = apply_filters( 'bbp_subscription_to_email',     $no_reply );
    12661321
    12671322    do_action( 'bbp_pre_notify_forum_subscribers', $topic_id, $forum_id, $user_ids );
    12681323
    12691324    // Send notification email
    1270     wp_mail( $do_not_reply, $subject, $message, $headers );
     1325    wp_mail( $to_email, $subject, $message, $headers );
    12711326
    12721327    do_action( 'bbp_post_notify_forum_subscribers', $topic_id, $forum_id, $user_ids );
    12731328
    12741329    return true;
     1330}
     1331
     1332/**
     1333 * Sends notification emails for new replies to subscribed topics
     1334 *
     1335 * This function is deprecated. Please use: bbp_notify_topic_subscribers()
     1336 *
     1337 * @since bbPress (r2668)
     1338 * @deprecated bbPress (r5412)
     1339 *
     1340 * @param int $reply_id ID of the newly made reply
     1341 * @param int $topic_id ID of the topic of the reply
     1342 * @param int $forum_id ID of the forum of the reply
     1343 * @param mixed $anonymous_data Array of anonymous user data
     1344 * @param int $reply_author ID of the topic author ID
     1345 *
     1346 * @return bool True on success, false on failure
     1347 */
     1348function bbp_notify_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0 ) {
     1349    return bbp_notify_topic_subscribers( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author );
    12751350}
    12761351
Note: See TracChangeset for help on using the changeset viewer.