Skip to:
Content

BuddyPress.org

Ticket #1949: wp_mail_filter_refactor_for_r2697.patch

File wp_mail_filter_refactor_for_r2697.patch, 39.5 KB (added by johnjamesjacoby, 15 years ago)

What you gonna do with all this patch? All this patch inside this ticket?

  • bp-activity/bp-activity-notifications.php

     
    1515                if ( !$receiver_user_id = bp_core_get_userid($username) )
    1616                        continue;
    1717
    18                 // Now email the user with the contents of the message (if they have enabled email notifications)
     18                /* Now email the user with the contents of the message (if they have enabled email notifications) */
    1919                if ( 'no' != get_usermeta( $user_id, 'notification_activity_new_mention' ) ) {
    2020                        $poster_name = bp_core_get_user_displayname( $poster_user_id );
    21 
    2221                        $message_link = bp_activity_get_permalink( $activity_id );
    2322                        $settings_link = bp_core_get_user_domain( $receiver_user_id ) . 'settings/notifications/';
    2423
    25                         // Set up and send the message
     24                        /* Get email recipient data */
    2625                        $ud = bp_core_get_core_userdata( $receiver_user_id );
    27                         $to = $ud->user_email;
    28                         $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), stripslashes($poster_name) );
     26                        $to = apply_filters( 'bp_activity_at_message_notification_to', $ud->user_email );
    2927
    30 $message = sprintf( __(
    31 '%s mentioned you in an update:
     28                        /* Get blog name */
     29                        $blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
    3230
    33 "%s"
     31                        /* Filter content of comment */
     32                        $content = bp_activity_filter_kses( stripslashes( $content ) );
    3433
    35 To view and respond to the message, log in and visit: %s
     34                        /* Allow filtering of email subject and body */
     35                        $subject_text = apply_filters( 'bp_activity_at_message_notification_subject', __( '[%1$s] %2$s mentioned you in an update', 'buddypress' ), $blog_name, $poster_name );
     36                        $message_text = apply_filters( 'bp_activity_at_message_notification_message', __(
     37'%1$s mentioned you in an update:
    3638
     39"%2$s"
     40
     41To view and respond to the message, log in and visit: %3$s
     42
    3743---------------------
    38 ', 'buddypress' ), $poster_name, bp_activity_filter_kses( stripslashes($content) ), $message_link );
     44', 'buddypress' ), $poster_name, $content, $message_link );
    3945
     46                        /* Prepare the email */
     47                        $subject = sprintf( $subject_text, $blog_name, $poster_name );
     48                        $message = sprintf( $message_text, $poster_name, $content, $message_link );
     49
     50                        /* Add link for user to turn off this notification */
    4051                        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    4152
    42                         /* Send the message */
    43                         $to = apply_filters( 'bp_activity_at_message_notification_to', $to );
    44                         $subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject );
    45                         $message = apply_filters( 'bp_activity_at_message_notification_message', $message );
    46 
     53                        /* Send the email */
    4754                        wp_mail( $to, $subject, $message );
    4855                }
    4956        }
     
    5966
    6067        if ( $original_activity->user_id != $commenter_id && 'no' != get_usermeta( $original_activity->user_id, 'notification_activity_new_reply' ) ) {
    6168                $poster_name = bp_core_get_user_displayname( $commenter_id );
     69                $poster_name = stripslashes_deep( $poster_name );
    6270                $thread_link = bp_activity_get_permalink( $activity_id );
    6371                $settings_link = bp_core_get_user_domain( $original_activity->user_id ) . 'settings/notifications/';
    6472
    65                 // Set up and send the message
     73                /* Get email recipient data */
    6674                $ud = bp_core_get_core_userdata( $original_activity->user_id );
    67                 $to = $ud->user_email;
    68                 $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s replied to one of your updates', 'buddypress' ), stripslashes_deep( $poster_name ) );
     75                $to = apply_filters( 'bp_activity_new_comment_notification_to', $ud->user_email );
    6976
    70 $message = sprintf( __(
    71 '%s replied to one of your updates:
     77                /* Get blog name */
     78                $blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
    7279
    73 "%s"
     80                /* Filter content of comment */
     81                $content = bp_activity_filter_kses( stripslashes( $content ) );
    7482
    75 To view your original update and all comments, log in and visit: %s
     83                /* Allow filtering of email subject and body */
     84                $subject_text = apply_filters( 'bp_activity_new_comment_notification_subject', __( '[%1$s] %2$s replied to one of your updates', 'buddypress' ), $blog_name, $poster_name );
     85                $message_text = apply_filters( 'bp_activity_new_comment_notification_message', __(
     86'%1$s replied to one of your updates:
    7687
     88"%2$s"
     89
     90To view your original update and all comments, log in and visit: %3$s
     91
    7792---------------------
    78 ', 'buddypress' ), $poster_name, bp_activity_filter_kses( stripslashes( $content ) ), $thread_link );
     93', 'buddypress' ), $poster_name, $content, $thread_link );
    7994
     95                /* Prepare the email */
     96                $subject = sprintf( $subject_text, $blog_name, $poster_name );
     97                $message = sprintf( $message_text, $poster_name, $content, $thread_link );
     98
     99                /* Add link for user to turn off this notification */
    80100                $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    81101
    82                 /* Send the message */
    83                 $to = apply_filters( 'bp_activity_new_comment_notification_to', $to );
    84                 $subject = apply_filters( 'bp_activity_new_comment_notification_subject', $subject );
    85                 $message = apply_filters( 'bp_activity_new_comment_notification_message', $message );
    86 
     102                /* Send the email */
    87103                wp_mail( $to, $subject, $message );
    88104        }
    89105
     
    101117                $thread_link = bp_activity_get_permalink( $activity_id );
    102118                $settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . 'settings/notifications/';
    103119
    104                 // Set up and send the message
     120                /* Get email recipient data */
    105121                $ud = bp_core_get_core_userdata( $parent_comment->user_id );
    106                 $to = $ud->user_email;
    107                 $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s replied to one of your comments', 'buddypress' ), stripslashes_deep( $poster_name ) );
     122                $to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $ud->user_email );
    108123
    109 $message = sprintf( __(
    110 '%s replied to one of your comments:
     124                /* Get blog name */
     125                $blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
    111126
    112 "%s"
     127                /* Filter content of comment */
     128                $content = bp_activity_filter_kses( stripslashes( $content ) );
    113129
    114 To view the original activity, your comment and all replies, log in and visit: %s
     130                /* Allow filtering of email subject and body */
     131                $subject_text = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', __( '[%1$s] %2$s replied to one of your comments', 'buddypress' ), $blog_name, $poster_name );
     132                $message_text = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', __(
    115133
     134'%1$s replied to one of your comments:
     135
     136"%2$s"
     137
     138To view the original activity, your comment and all replies, log in and visit: %3$s
     139
    116140---------------------
    117 ', 'buddypress' ), $poster_name, bp_activity_filter_kses( stripslashes( $content ) ), $thread_link );
     141', 'buddypress' ), $poster_name, $content, $thread_link );
    118142
    119143                $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    120144
    121                 /* Send the message */
    122                 $to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $to );
    123                 $subject = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', $subject );
    124                 $message = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', $message );
     145                /* Prepare the email */
     146                $subject = sprintf( $subject_text, $blog_name, $poster_name );
     147                $message = sprintf( $message_text, $poster_name, $content, $thread_link );
    125148
     149                /* Add link for user to turn off this notification */
     150                $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
     151
     152                /* Send the email */
    126153                wp_mail( $to, $subject, $message );
    127154        }
    128155}
  • bp-core/bp-core-activation.php

     
    9595if ( !is_admin() && empty( $_GET['e'] ) )
    9696        add_filter( 'wpmu_welcome_user_notification', 'bp_core_disable_welcome_email' );
    9797
    98 // Notify user of signup success.
     98/* Notify user of signup success. */
    9999function bp_core_activation_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta ) {
    100100        global $current_site;
    101101
    102         // Send email with activation link.
    103         $activate_url = bp_get_activation_page() ."?key=$key";
    104         $activate_url = clean_url($activate_url);
     102        /* Send email with activation link. */
     103        $activate_url = bp_get_activation_page() . "?key=$key";
     104        $activate_url = clean_url( $activate_url );
    105105
    106         $admin_email = get_site_option( "admin_email" );
     106        /* Get admin email */
     107        $admin_email = get_site_option( 'admin_email' );
    107108
    108109        if ( empty( $admin_email ) )
    109110                $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
    110111
    111         $from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
    112         $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
    113         $message = sprintf(__("Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%s", 'buddypress' ), $activate_url, clean_url("http://{$domain}{$path}" ) );
    114         $subject = '[' . $from_name . '] ' . sprintf(__('Activate %s', 'buddypress' ), clean_url('http://' . $domain . $path));
     112        $from_name = ( '' == get_site_option( 'site_name' ) ) ? 'WordPress' : wp_specialchars( get_site_option( 'site_name' ) );
     113        $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
     114        $site = clean_url( 'http://' . $domain . $path );
    115115
    116         /* Send the message */
     116        /* Allow filtering of email recipient, subject, and body */
    117117        $to = apply_filters( 'bp_core_activation_signup_blog_notification_to', $user_email );
    118         $subject = apply_filters( 'bp_core_activation_signup_blog_notification_subject', $subject );
    119         $message = apply_filters( 'bp_core_activation_signup_blog_notification_message', $message );
     118        $subject_text = apply_filters( 'bp_core_activation_signup_blog_notification_subject', __( '[%1$s] Activate %2$s', 'buddypress' ), $from_name, $site );
     119        $message_text = apply_filters( 'bp_core_activation_signup_blog_notification_message', __( 'Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%1$s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%2$s', 'buddypress' ), $activate_url, $site );
    120120
     121        /* Prepare the email */
     122        $subject = sprintf( $subject_text, $from_name, $site );
     123        $message = sprintf( $message_text, $activate_url, $site );
     124
     125        /* Send the email */
    121126        wp_mail( $to, $subject, $message, $message_headers );
    122127
    123         // Return false to stop the original WPMU function from continuing
     128        /* Return false to stop the original WPMU function from continuing */
    124129        return false;
    125130}
    126131if ( !is_admin() )
     
    129134function bp_core_activation_signup_user_notification( $user, $user_email, $key, $meta ) {
    130135        global $current_site;
    131136
    132         $activate_url = bp_get_activation_page() ."?key=$key";
     137        $activate_url = bp_get_activation_page() . "?key=$key";
    133138        $activate_url = clean_url($activate_url);
    134         $admin_email = get_site_option( "admin_email" );
     139        $admin_email = get_site_option( 'admin_email' );
    135140
    136141        if ( empty( $admin_email ) )
    137142                $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
     
    140145        if ( is_admin() )
    141146                $email = '&e=1';
    142147
    143         $from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
    144         $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
    145         $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url . $email, clean_url("http://{$domain}{$path}" ) );
    146         $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
     148        $from_name = ( '' == get_site_option( 'site_name' ) ) ? 'WordPress' : wp_specialchars( get_site_option( 'site_name' ) );
     149        $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
    147150
    148         /* Send the message */
     151        /* Allow filtering of email recipient, subject, and body */
    149152        $to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email );
    150         $subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject );
    151         $message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message );
     153        $subject_text = apply_filters( 'bp_core_activation_signup_user_notification_subject', __( '[%1$s] Activate Your Account', 'buddypress' ), $from_name );
     154        $message_text = apply_filters( 'bp_core_activation_signup_user_notification_message', __( 'Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n', 'buddypress' ), $activate_url );
    152155
     156        /* Prepare the email */
     157        $subject = sprintf( $subject_text, $from_name );
     158        $message = sprintf( $message_text, $activate_url );
     159
     160        /* Send the email */
    153161        wp_mail( $to, $subject, $message, $message_headers );
    154162
    155         // Return false to stop the original WPMU function from continuing
     163        /* Return false to stop the original WPMU function from continuing */
    156164        return false;
    157165}
    158166if ( !is_admin() || ( is_admin() && empty( $_POST['noconfirmation'] ) ) )
  • bp-friends/bp-friends-notifications.php

     
    33function friends_notification_new_request( $friendship_id, $initiator_id, $friend_id ) {
    44        global $bp;
    55
    6         $initiator_name = bp_core_get_user_displayname( $initiator_id );
    7 
    86        if ( 'no' == get_usermeta( (int)$friend_id, 'notification_friends_friendship_request' ) )
    97                return false;
    108
     9        /* Get blog name */
     10        $blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
     11
     12        /* Get email recipient data */
    1113        $ud = get_userdata( $friend_id );
    12         $initiator_ud = get_userdata( $initiator_id );
    13 
    1414        $all_requests_link = bp_core_get_user_domain( $friend_id ) . BP_FRIENDS_SLUG . '/requests/';
    1515        $settings_link = bp_core_get_user_domain( $friend_id ) . 'settings/notifications';
     16        $to = apply_filters( 'friends_notification_new_request_to', $ud->user_email );
    1617
     18        /* Get intiator data */
     19        $initiator_ud = get_userdata( $initiator_id );
     20        $initiator_name = bp_core_get_user_displayname( $initiator_id );
    1721        $initiator_link = bp_core_get_user_domain( $initiator_id );
    1822
    19         // Set up and send the message
    20         $to = $ud->user_email;
    21         $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'New friendship request from %s', 'buddypress' ), $initiator_name );
     23        /* Allow filtering of email subject and body */
     24        $subject_text = apply_filters( 'friends_notification_new_request_subject', __( '[%1$s] New friendship request from %s', 'buddypress' ), $blog_name, $initiator_name );
     25        $message_text = apply_filters( 'friends_notification_new_request_message', __(
     26'%1$s wants to add you as a friend.
    2227
    23         $message = sprintf( __(
    24 "%s wants to add you as a friend.
     28To view %1$s\'s profile: %3$s
    2529
    26 To view all of your pending friendship requests: %s
     30To view all of your pending friendship requests: %2$s
    2731
    28 To view %s's profile: %s
    29 
    3032---------------------
    31 ", 'buddypress' ), $initiator_name, $all_requests_link, $initiator_name, $initiator_link );
     33', 'buddypress' ), $initiator_name, $initiator_link, $all_requests_link );
    3234
     35        /* Prepare the email */
     36        $subject = sprintf( $subject_text, $blog_name, $initiator_name );
     37        $message = sprintf( $message_text, $initiator_name, $initiator_link, $all_requests_link );
     38
     39        /* Add link for user to turn off this notification */
    3340        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    3441
    35         /* Send the message */
    36         $to = apply_filters( 'friends_notification_new_request_to', $to );
    37         $subject = apply_filters( 'friends_notification_new_request_subject', $subject );
    38         $message = apply_filters( 'friends_notification_new_request_message', $message );
    39 
     42        /* Send the email */
    4043        wp_mail( $to, $subject, $message );
    4144}
    4245
    4346function friends_notification_accepted_request( $friendship_id, $initiator_id, $friend_id ) {
    4447        global $bp;
    4548
     49        /* Create friendship */
    4650        $friendship = new BP_Friends_Friendship( $friendship_id, false, false );
    4751
    48         $friend_name = bp_core_get_user_displayname( $friend_id );
    49 
    5052        if ( 'no' == get_usermeta( (int)$initiator_id, 'notification_friends_friendship_accepted' ) )
    5153                return false;
    5254
     55        /* Get blog name */
     56        $blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
     57
     58        /* Get email recipient data */
    5359        $ud = get_userdata( $initiator_id );
     60        $to = apply_filters( 'friends_notification_accepted_request_to', $ud->user_email );
     61        $settings_link = bp_core_get_user_domain( $initiator_id ) . 'settings/notifications';
    5462
     63        /* Get friend data */
     64        $friend_name = bp_core_get_user_displayname( $friend_id );
    5565        $friend_link = bp_core_get_user_domain( $friend_id );
    56         $settings_link = bp_core_get_user_domain( $initiator_id ) . 'settings/notifications';
    5766
    58         // Set up and send the message
    59         $to = $ud->user_email;
    60         $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s accepted your friendship request', 'buddypress' ), $friend_name );
    6167
    62         $message = sprintf( __(
    63 '%s accepted your friend request.
     68        /* Allow filtering of email subject and body */
     69        $subject_text = apply_filters( 'friends_notification_accepted_request_subject', __( '[%1$s] %2$s accepted your friendship request', 'buddypress' ), $blog_name, $friend_name );
     70        $message_text = apply_filters( 'friends_notification_accepted_request_message', __(
     71'%1$s accepted your friend request.
    6472
    65 To view %s\'s profile: %s
     73To view %1$s\'s profile: %2$s
    6674
    6775---------------------
    68 ', 'buddypress' ), $friend_name, $friend_name, $friend_link );
     76', 'buddypress' ), $friend_name, $friend_link );
    6977
     78        /* Prepare the email */
     79        $subject = sprintf( $subject_text, $blog_name, $friend_name );
     80        $message = sprintf( $message_text, $friend_name, $friend_link );
     81
     82        /* Add link for user to turn off this notification */
    7083        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    7184
    72         /* Send the message */
    73         $to = apply_filters( 'friends_notification_accepted_request_to', $to );
    74         $subject = apply_filters( 'friends_notification_accepted_request_subject', $subject );
    75         $message = apply_filters( 'friends_notification_accepted_request_message', $message );
    76 
     85        /* Send the email */
    7786        wp_mail( $to, $subject, $message );
    7887}
    7988
  • bp-groups/bp-groups-notifications.php

     
    33function groups_notification_group_updated( $group_id ) {
    44        global $bp;
    55
     6        /* Get group data */
    67        $group = new BP_Groups_Group( $group_id );
    7         $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . __( 'Group Details Updated', 'buddypress' );
     8        $group_link = site_url( $bp->groups->slug . '/' . $group->slug );
     9        $user_ids = BP_Groups_Member::get_group_member_ids( $group->id );
    810
    9         $user_ids = BP_Groups_Member::get_group_member_ids( $group->id );
     11        /* Get blog name */
     12        $blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
     13
     14        /* Email subject */
     15        $subject_text = apply_filters( 'groups_notification_group_updated_subject', __( '[%s] Group Details Updated', 'buddypress' ), $blog_name );
     16
    1017        foreach ( (array)$user_ids as $user_id ) {
    1118                if ( 'no' == get_usermeta( $user_id, 'notification_groups_group_updated' ) ) continue;
    1219
     20                /* Get email recipient data */
    1321                $ud = bp_core_get_core_userdata( $user_id );
    14 
    15                 // Set up and send the message
    16                 $to = $ud->user_email;
    17 
    18                 $group_link = site_url( $bp->groups->slug . '/' . $group->slug );
    1922                $settings_link = bp_core_get_user_domain( $user_id ) . 'settings/notifications/';
     23                $to = apply_filters( 'groups_notification_group_updated_to', $ud->user_email );
    2024
    21                 $message = sprintf( __(
    22 'Group details for the group "%s" were updated:
     25                /* Email text */
     26                $message_text = apply_filters( 'groups_notification_group_updated_message', __(
     27'Group details for the group "%1$s" were updated:
    2328
    24 To view the group: %s
     29To view the group: %2$s
    2530
    2631---------------------
    2732', 'buddypress' ), $group->name, $group_link );
    2833
     34                /* Prepare the email */
     35                $subject = sprintf( $subject_text, $blog_name );
     36                $message = sprintf( $message_text, $group->name, $group_link );
     37
     38                /* Add link for user to turn off this notification */
    2939                $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    3040
    31                 /* Send the message */
    32                 $to = apply_filters( 'groups_notification_group_updated_to', $to );
    33                 $subject = apply_filters( 'groups_notification_group_updated_subject', $subject );
    34                 $message = apply_filters( 'groups_notification_group_updated_message', $message );
    35 
     41                /* Send the email */
    3642                wp_mail( $to, $subject, $message );
    3743
     44                /* Unset specific user data to avoid duplicate emails */
    3845                unset( $message, $to );
    3946        }
    4047}
     
    4754        if ( 'no' == get_usermeta( $admin_id, 'notification_groups_membership_request' ) )
    4855                return false;
    4956
    50         $requesting_user_name = bp_core_get_user_displayname( $requesting_user_id );
     57        /* Get group data */
    5158        $group = new BP_Groups_Group( $group_id );
     59        $group_requests = bp_get_group_permalink( $group ) . 'admin/membership-requests';
    5260
    53         $ud = bp_core_get_core_userdata($admin_id);
    54         $requesting_ud = bp_core_get_core_userdata($requesting_user_id);
     61        /* Get email recipient data */
     62        $ud = bp_core_get_core_userdata( $admin_id );
     63        $to = apply_filters( 'groups_notification_new_membership_request_to', $ud->user_email );
    5564
    56         $group_requests = bp_get_group_permalink( $group ) . 'admin/membership-requests';
     65        /* Get requester data */
     66        $requesting_ud = bp_core_get_core_userdata( $requesting_user_id );
     67        $requesting_user_name = bp_core_get_user_displayname( $requesting_user_id );
    5768        $profile_link = bp_core_get_user_domain( $requesting_user_id );
    5869        $settings_link = bp_core_get_user_domain( $requesting_user_id ) . 'settings/notifications/';
    5970
    60         // Set up and send the message
    61         $to = $ud->user_email;
    62         $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'Membership request for group: %s', 'buddypress' ), $group->name );
     71        /* Get blog name */
     72        $blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
    6373
    64 $message = sprintf( __(
    65 '%s wants to join the group "%s".
     74        /* Allow filtering of email subject and body */
     75        $subject_text = apply_filters( 'groups_notification_new_membership_request_subject', __( '[%1$s] Membership request for group: %2$s', 'buddypress' ), $blog_name, $group->name );
     76        $message_text = apply_filters( 'groups_notification_new_membership_request_message', __(
     77'%1$s wants to join the group "%2$s".
    6678
    6779Because you are the administrator of this group, you must either accept or reject the membership request.
    6880
    6981To view all pending membership requests for this group, please visit:
    70 %s
     82%3$s
    7183
    72 To view %s\'s profile: %s
     84To view %1$s\'s profile: %4$s
    7385
    7486---------------------
    75 ', 'buddypress' ), $requesting_user_name, $group->name, $group_requests, $requesting_user_name, $profile_link );
     87', 'buddypress' ), $requesting_user_name, $group->name, $group_requests, $profile_link );
    7688
     89        /* Prepare the email */
     90        $subject = sprintf( $subject_text, $blog_name, $group->name );
     91        $message = sprintf( $message_text, $requesting_user_name, $group->name, $group_requests, $profile_link );
     92
     93        /* Add link for user to turn off this notification */
    7794        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    7895
    79         /* Send the message */
    80         $to = apply_filters( 'groups_notification_new_membership_request_to', $to );
    81         $subject = apply_filters( 'groups_notification_new_membership_request_subject', $subject );
    82         $message = apply_filters( 'groups_notification_new_membership_request_message', $message );
    83 
     96        /* Send the email */
    8497        wp_mail( $to, $subject, $message );
    8598}
    8699
    87100function groups_notification_membership_request_completed( $requesting_user_id, $group_id, $accepted = true ) {
    88101        global $bp;
    89102
    90         // Post a screen notification first.
     103        /* Post a screen notification first. */
    91104        if ( $accepted )
    92105                bp_core_add_notification( $group_id, $requesting_user_id, 'groups', 'membership_request_accepted' );
    93106        else
     
    96109        if ( 'no' == get_usermeta( $requesting_user_id, 'notification_membership_request_completed' ) )
    97110                return false;
    98111
     112        /* Get group data */
    99113        $group = new BP_Groups_Group( $group_id );
     114        $group_link = bp_get_group_permalink( $group );
    100115
    101         $ud = bp_core_get_core_userdata($requesting_user_id);
    102 
    103         $group_link = bp_get_group_permalink( $group );
     116        /* Get email recipient data */
     117        $ud = bp_core_get_core_userdata( $requesting_user_id );
    104118        $settings_link = bp_core_get_user_domain( $requesting_user_id ) . 'settings/notifications/';
     119        $to = apply_filters( 'groups_notification_membership_request_completed_to', $ud->user_email );
    105120
    106         // Set up and send the message
    107         $to = $ud->user_email;
     121        /* Get blog name */
     122        $blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
    108123
     124        /* Allow filtering of email subject and body */
    109125        if ( $accepted ) {
    110                 $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'Membership request for group "%s" accepted', 'buddypress' ), $group->name );
    111                 $message = sprintf( __(
    112 'Your membership request for the group "%s" has been accepted.
     126                $subject_text = apply_filters( 'groups_notification_new_membership_request_subject', __( '[%1$s] Membership request for group "%2$s" accepted', 'buddypress' ), $blog_name, $group->name );
     127                $message_text = sprintf( __(
     128'Your membership request for the group "%1$s" has been accepted.
    113129
    114 To view the group please login and visit: %s
     130To view the group please login and visit: %2$s
    115131
    116132---------------------
    117133', 'buddypress' ), $group->name, $group_link );
    118134
    119135        } else {
    120                 $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'Membership request for group "%s" rejected', 'buddypress' ), $group->name );
    121                 $message = sprintf( __(
    122 'Your membership request for the group "%s" has been rejected.
     136                $subject_text = apply_filters( 'groups_notification_new_membership_request_subject', __( '[%1$s] Membership request for group "%2$s" rejected', 'buddypress' ), $blog_name, $group->name );
     137                $message_text = sprintf( __(
     138'Your membership request for the group "%1$s" has been rejected.
    123139
    124 To submit another request please log in and visit: %s
     140To submit another request please log in and visit: %2$s
    125141
    126142---------------------
    127143', 'buddypress' ), $group->name, $group_link );
    128144        }
    129145
     146        /* Prepare the email */
     147        $subject = sprintf( $subject_text, $blog_name, $group->name );
     148        $message = sprintf( $message_text, $group->name, $group_link );
     149
     150        /* Add link for user to turn off this notification */
    130151        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    131152
    132         /* Send the message */
    133         $to = apply_filters( 'groups_notification_membership_request_completed_to', $to );
    134         $subject = apply_filters( 'groups_notification_membership_request_completed_subject', $subject );
    135         $message = apply_filters( 'groups_notification_membership_request_completed_message', $message );
    136 
     153        /* Send the email */
    137154        wp_mail( $to, $subject, $message );
    138155}
    139156
     
    148165                $type = 'member_promoted_to_mod';
    149166        }
    150167
    151         // Post a screen notification first.
     168        /* Post a screen notification first. */
    152169        bp_core_add_notification( $group_id, $user_id, 'groups', $type );
    153170
    154171        if ( 'no' == get_usermeta( $user_id, 'notification_groups_admin_promotion' ) )
    155172                return false;
    156173
     174        /* Get group data */
    157175        $group = new BP_Groups_Group( $group_id );
    158         $ud = bp_core_get_core_userdata($user_id);
     176        $group_link = bp_get_group_permalink( $group );
    159177
    160         $group_link = bp_get_group_permalink( $group );
     178        /* Get email recipient data */
     179        $ud = bp_core_get_core_userdata( $user_id );
    161180        $settings_link = bp_core_get_user_domain( $user_id ) . 'settings/notifications/';
     181        $to = apply_filters( 'groups_notification_promoted_member_to', $ud->user_email );
    162182
    163         // Set up and send the message
    164         $to = $ud->user_email;
     183        /* Get blog name */
     184        $blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
    165185
    166         $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'You have been promoted in the group: "%s"', 'buddypress' ), $group->name );
     186        /* Allow filtering of email subject and body */
     187        $subject_text = apply_filters( 'groups_notification_promoted_member_subject', __( '[%1$s] You have been promoted in the group: "%s"', 'buddypress' ), $blog_name, $group->name );
     188        $message_text = apply_filters( 'groups_notification_promoted_member_message', __(
     189'You have been promoted to %1$s for the group: "%2$s".
    167190
    168         $message = sprintf( __(
    169 'You have been promoted to %s for the group: "%s".
     191To view the group please visit: %3$s
    170192
    171 To view the group please visit: %s
    172 
    173193---------------------
    174194', 'buddypress' ), $promoted_to, $group->name, $group_link );
    175195
     196        /* Prepare the email */
     197        $subject = sprintf( $subject_text, $blog_name, $group->name );
     198        $message = sprintf( $message_text, $promoted_to, $group->name, $group_link );
     199
     200        /* Add link for user to turn off this notification */
    176201        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    177202
    178         /* Send the message */
    179         $to = apply_filters( 'groups_notification_promoted_member_to', $to );
    180         $subject = apply_filters( 'groups_notification_promoted_member_subject', $subject );
    181         $message = apply_filters( 'groups_notification_promoted_member_message', $message );
    182 
     203        /* Send the email */
    183204        wp_mail( $to, $subject, $message );
    184205}
    185206add_action( 'groups_promoted_member', 'groups_notification_promoted_member', 10, 2 );
     
    187208function groups_notification_group_invites( &$group, &$member, $inviter_user_id ) {
    188209        global $bp;
    189210
     211        /* Get inviter data */
    190212        $inviter_ud = bp_core_get_core_userdata( $inviter_user_id );
    191213        $inviter_name = bp_core_get_userlink( $inviter_user_id, true, false, true );
    192214        $inviter_link = bp_core_get_user_domain( $inviter_user_id );
    193215
     216        /* Get group data */
    194217        $group_link = bp_get_group_permalink( $group );
    195218
    196219        if ( !$member->invite_sent ) {
    197220                $invited_user_id = $member->user_id;
    198221
    199                 // Post a screen notification first.
     222                /* Post a screen notification first. */
    200223                bp_core_add_notification( $group->id, $invited_user_id, 'groups', 'group_invite' );
    201224
    202225                if ( 'no' == get_usermeta( $invited_user_id, 'notification_groups_invite' ) )
    203226                        return false;
    204227
     228                /* Get invited data */
    205229                $invited_ud = bp_core_get_core_userdata($invited_user_id);
    206 
    207230                $settings_link = bp_core_get_user_domain( $invited_user_id ) . 'settings/notifications/';
    208231                $invited_link = bp_core_get_user_domain( $invited_user_id );
    209232                $invites_link = $invited_link . $bp->groups->slug . '/invites';
     233                $to = apply_filters( 'groups_notification_group_invites_to', $invited_ud->user_email );
    210234
    211                 // Set up and send the message
    212                 $to = $invited_ud->user_email;
     235                /* Allow filtering of email subject and body */
     236                $subject_text = apply_filters( 'groups_notification_group_invites_subject', __( '[%1$s] You have an invitation to the group: "%s"', 'buddypress' ), $blog_name, $group->name );
     237                $message_text = apply_filters( 'groups_notification_group_invites_message', __(
     238'One of your friends (%1$s) has invited you to the group "%2$s".
    213239
    214                 $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'You have an invitation to the group: "%s"', 'buddypress' ), $group->name );
     240To view your group invites visit: %3$s
    215241
    216                 $message = sprintf( __(
    217 'One of your friends %s has invited you to the group: "%s".
     242To view the group visit: %4$s
    218243
    219 To view your group invites visit: %s
     244To view %1$s\'s profile visit: %5$s
    220245
    221 To view the group visit: %s
     246---------------------
     247', 'buddypress' ), $inviter_name, $group->name, $invites_link, $group_link, $inviter_link );
    222248
    223 To view %s\'s profile visit: %s
     249                /* Prepare the email */
     250                $subject = sprintf( $subject_text, $blog_name, $group->name );
     251                $message = sprintf( $message_text, $inviter_name, $group->name, $invites_link, $group_link, $inviter_link );
    224252
    225 ---------------------
    226 ', 'buddypress' ), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_link );
    227 
     253                /* Add link for user to turn off this notification */
    228254                $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    229255
    230                 /* Send the message */
    231                 $to = apply_filters( 'groups_notification_group_invites_to', $to );
    232                 $subject = apply_filters( 'groups_notification_group_invites_subject', $subject );
    233                 $message = apply_filters( 'groups_notification_group_invites_message', $message );
    234 
     256                /* Send the email */
    235257                wp_mail( $to, $subject, $message );
    236258        }
    237259}
     
    247269        if ( !$usernames = array_unique( $usernames[1] ) )
    248270                return false;
    249271
     272        /* Get group data */
    250273        $group = new BP_Groups_Group( $group_id );
    251274
    252275        foreach( (array)$usernames as $username ) {
    253                 if ( !$receiver_user_id = bp_core_get_userid($username) )
    254                         continue;
     276                if ( !$receiver_user_id = bp_core_get_userid( $username ) ) continue;
    255277
    256278                /* Check the user is a member of the group before sending the update. */
    257                 if ( !groups_is_user_member( $receiver_user_id, $group_id ) )
    258                         continue;
     279                if ( !groups_is_user_member( $receiver_user_id, $group_id ) ) continue;
    259280
    260                 // Now email the user with the contents of the message (if they have enabled email notifications)
     281                /* Now email the user with the contents of the message (if they have enabled email notifications) */
    261282                if ( 'no' != get_usermeta( $user_id, 'notification_activity_new_mention' ) ) {
     283                        /* Get poster name */
    262284                        $poster_name = bp_core_get_user_displayname( $poster_user_id );
     285                        $poster_name = stripslashes( $poster_name );
    263286
     287                        /* Get activity data */
    264288                        $message_link = bp_activity_get_permalink( $activity_id );
     289                        $content = bp_groups_filter_kses( stripslashes( $content ) );
     290                       
     291                        /* Get email recipient data */
     292                        $ud = bp_core_get_core_userdata( $receiver_user_id );
    265293                        $settings_link = bp_core_get_user_domain( $receiver_user_id ) . 'settings/notifications/';
     294                        $to = apply_filters( 'groups_at_message_notification_to', $ud->user_email );
    266295
    267                         // Set up and send the message
    268                         $ud = bp_core_get_core_userdata( $receiver_user_id );
    269                         $to = $ud->user_email;
    270                         $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s mentioned you in the group "%s"', 'buddypress' ), stripslashes( $poster_name ), $group->name );
     296                        /* Allow filtering of email subject and body */
     297                        $subject_text = apply_filters( 'groups_at_message_notification_subject', __( '[%1$s] %s mentioned you in the group "%s"', 'buddypress' ), $blog_name, $poster_name, $group->name );
     298                        $message_text = apply_filters( 'groups_at_message_notification_message', __(
     299'%1$s mentioned you in the group "%2$s":
    271300
    272 $message = sprintf( __(
    273 '%s mentioned you in the group "%s":
     301"%3$s"
    274302
    275 "%s"
     303To view and/or respond to the message, log in and visit: %4$s
    276304
    277 To view and respond to the message, log in and visit: %s
    278 
    279305---------------------
    280 ', 'buddypress' ), $poster_name, $group->name, bp_groups_filter_kses( stripslashes( $content ) ), $message_link );
     306', 'buddypress' ), $poster_name, $group->name, $content, $message_link );
    281307
     308                        /* Prepare the email */
     309                        $subject = sprintf( $subject_text, $blog_name, $poster_name, $group->name );
     310                        $message = sprintf( $message_text, $poster_name, $group->name, $content, $message_link );
     311
     312                        /* Add link for user to turn off this notification */
    282313                        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    283314
    284                         /* Send the message */
    285                         $to = apply_filters( 'groups_at_message_notification_to', $to );
    286                         $subject = apply_filters( 'groups_at_message_notification_subject', $subject );
    287                         $message = apply_filters( 'groups_at_message_notification_message', $message );
    288 
     315                        /* Send the email */
    289316                        wp_mail( $to, $subject, $message );
    290317                }
    291318        }
    292319}
    293320add_action( 'bp_groups_posted_update', 'groups_at_message_notification', 10, 4 );
    294321
    295 
    296322?>
    297  No newline at end of file
  • bp-messages/bp-messages-notifications.php

     
    44        global $bp;
    55        extract($args);
    66
     7        /* Email sender */
    78        $sender_name = bp_core_get_user_displayname( $sender_id );
     9        $sender_name = stripslashes( $sender_name );
    810
     11        /* Get blog name */
     12        $blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
     13
     14        /* Message subject */
     15        $subject = stripslashes( wp_filter_kses( $subject ) );
     16        $subject_text = apply_filters( 'messages_notification_new_message_subject', __( '[%1$s] New message from %2$s', 'buddypress' ), $blog_name, $sender_name );
     17
    918        foreach( $recipients as $recipient ) {
    1019                if ( $sender_id == $recipient->user_id || 'no' == get_usermeta( $recipient->user_id, 'notification_messages_new_message' ) ) continue;
    1120
     21                /* Get email recipient data */
    1222                $ud = get_userdata( $recipient->user_id );
    1323                $message_link = bp_core_get_user_domain( $recipient->user_id ) . BP_MESSAGES_SLUG .'/';
    1424                $settings_link = bp_core_get_user_domain( $recipient->user_id ) . 'settings/notifications/';
     25                $to = apply_filters( 'messages_notification_new_message_to', $ud->user_email );
    1526
    16                 // Set up and send the message
    17                 $email_to = $ud->user_email;
    18                 $email_subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'New message from %s', 'buddypress' ), stripslashes( $sender_name ) );
     27                /* Message body */
     28                $content = stripslashes( wp_filter_kses( $content ) );
     29                $message_text = apply_filters( 'messages_notification_new_message_message', __(
     30'%1$s sent you a new message:
    1931
    20                 $email_content = sprintf( __(
    21 '%s sent you a new message:
     32Subject: %2$s
    2233
    23 Subject: %s
     34"%3$s"
    2435
    25 "%s"
     36To view and read your messages please log in and visit: %4$s
    2637
    27 To view and read your messages please log in and visit: %s
    28 
    2938---------------------
    30 ', 'buddypress' ), $sender_name, stripslashes( wp_filter_kses( $subject ) ), stripslashes( wp_filter_kses( $content ) ), $message_link );
     39', 'buddypress' ), $sender_name, $subject, $content, $message_link );
    3140
    32                 $content .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
     41                /* Prepare the email */
     42                $subject = sprintf( $subject_text, $blog_name, $sender_name );
     43                $message = sprintf( $message_text, $sender_name, $subject, $content, $message_link );
    3344
    34                 /* Send the message */
    35                 $email_to = apply_filters( 'messages_notification_new_message_to', $email_to );
    36                 $email_subject = apply_filters( 'messages_notification_new_message_subject', $email_subject );
    37                 $email_content = apply_filters( 'messages_notification_new_message_message', $email_content );
     45                /* Add link for user to turn off this notification */
     46                $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    3847
    39                 wp_mail( $email_to, $email_subject, $email_content );
     48                /* Send the email */
     49                wp_mail( $to, $subject, $message );
     50
     51                /* Unset specific user data to avoid duplicate emails */
     52                unset( $message, $to );
    4053        }
    4154}
    4255