Skip to:
Content

bbPress.org

Changeset 6264


Ignore:
Timestamp:
01/27/2017 06:04:37 AM (8 years ago)
Author:
johnjamesjacoby
Message:

Subscriptions: Do not send emails when $user_ids is empty.

Also reorder some logic to optimize the users loop.

Fixes #2863. Props thebrandonallen.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/common/functions.php

    r6227 r6264  
    11511151    $reply_author_name = bbp_get_reply_author_display_name( $reply_id );
    11521152
     1153    /** Users *****************************************************************/
     1154
     1155    // Get topic subscribers and bail if empty
     1156    $user_ids = bbp_get_topic_subscribers( $topic_id, true );
     1157
     1158    // Dedicated filter to manipulate user ID's to send emails to
     1159    $user_ids = (array) apply_filters( 'bbp_topic_subscription_user_ids', $user_ids );
     1160    $user_ids = array_filter( array_map( 'intval', $user_ids ) );
     1161    if ( empty( $user_ids ) ) {
     1162        return false;
     1163    }
     1164
     1165    // Remove the reply author from the list.
     1166    $reply_author_key = array_search( (int) $reply_author, $user_ids, true );
     1167    if ( false !== $reply_author_key ) {
     1168        unset( $user_ids[ $reply_author_key ] );
     1169    }
     1170
     1171    // Bail of the reply author was the only one subscribed.
     1172    if ( empty( $user_ids ) ) {
     1173        return false;
     1174    }
     1175
    11531176    /** Mail ******************************************************************/
    11541177
     
    11931216    }
    11941217
    1195     /** Users *****************************************************************/
     1218    /** Headers ***************************************************************/
    11961219
    11971220    // Get the noreply@ address
     
    12041227    $headers = array( 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>' );
    12051228
    1206     // Get topic subscribers and bail if empty
    1207     $user_ids = bbp_get_topic_subscribers( $topic_id, true );
    1208 
    1209     // Dedicated filter to manipulate user ID's to send emails to
    1210     $user_ids = apply_filters( 'bbp_topic_subscription_user_ids', $user_ids );
    1211     if ( empty( $user_ids ) ) {
    1212         return false;
    1213     }
    1214 
    12151229    // Loop through users
    12161230    foreach ( (array) $user_ids as $user_id ) {
    1217 
    1218         // Don't send notifications to the person who made the post
    1219         if ( ! empty( $reply_author ) && (int) $user_id === (int) $reply_author ) {
    1220             continue;
    1221         }
    1222 
    1223         // Get email address of subscribed user
    12241231        $headers[] = 'Bcc: ' . get_userdata( $user_id )->user_email;
    12251232    }
     
    13081315    $topic_author_name = bbp_get_topic_author_display_name( $topic_id );
    13091316
     1317    /** Users *****************************************************************/
     1318
     1319    // Get topic subscribers and bail if empty
     1320    $user_ids = bbp_get_forum_subscribers( $forum_id, true );
     1321
     1322    // Dedicated filter to manipulate user ID's to send emails to
     1323    $user_ids = (array) apply_filters( 'bbp_forum_subscription_user_ids', $user_ids );
     1324    $user_ids = array_filter( array_map( 'intval', $user_ids ) );
     1325    if ( empty( $user_ids ) ) {
     1326        return false;
     1327    }
     1328
     1329    // Remove the topic author from the list.
     1330    $topic_author_key = array_search( (int) $topic_author, $user_ids, true );
     1331    if ( false !== $topic_author_key ) {
     1332        unset( $user_ids[ $topic_author_key ] );
     1333    }
     1334
     1335    // Bail of the topic author was the only one subscribed.
     1336    if ( empty( $user_ids ) ) {
     1337        return false;
     1338    }
     1339
    13101340    /** Mail ******************************************************************/
    13111341
     
    13501380    }
    13511381
    1352     /** User ******************************************************************/
     1382    /** Headers ***************************************************************/
    13531383
    13541384    // Get the noreply@ address
     
    13611391    $headers = array( 'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>' );
    13621392
    1363     // Get topic subscribers and bail if empty
    1364     $user_ids = bbp_get_forum_subscribers( $forum_id, true );
    1365 
    1366     // Dedicated filter to manipulate user ID's to send emails to
    1367     $user_ids = apply_filters( 'bbp_forum_subscription_user_ids', $user_ids );
    1368     if ( empty( $user_ids ) ) {
    1369         return false;
    1370     }
    1371 
    13721393    // Loop through users
    13731394    foreach ( (array) $user_ids as $user_id ) {
    1374 
    1375         // Don't send notifications to the person who made the post
    1376         if ( ! empty( $topic_author ) && (int) $user_id === (int) $topic_author ) {
    1377             continue;
    1378         }
    1379 
    1380         // Get email address of subscribed user
    13811395        $headers[] = 'Bcc: ' . get_userdata( $user_id )->user_email;
    13821396    }
Note: See TracChangeset for help on using the changeset viewer.