<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [2697] trunk: Adding filters to all BuddyPress wp_mail() calls
 .</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>2697</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2010-02-12 13:01:19 +0000 (Fri, 12 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Adding filters to all BuddyPress wp_mail() calls.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivitynotificationsphp">trunk/bp-activity/bp-activity-notifications.php</a></li>
<li><a href="#trunkbpcorebpcoreactivationphp">trunk/bp-core/bp-core-activation.php</a></li>
<li><a href="#trunkbpfriendsbpfriendsnotificationsphp">trunk/bp-friends/bp-friends-notifications.php</a></li>
<li><a href="#trunkbpgroupsbpgroupsnotificationsphp">trunk/bp-groups/bp-groups-notifications.php</a></li>
<li><a href="#trunkbpmessagesbpmessagesnotificationsphp">trunk/bp-messages/bp-messages-notifications.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivitynotificationsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-notifications.php (2696 => 2697)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-notifications.php        2010-02-12 12:48:30 UTC (rev 2696)
+++ trunk/bp-activity/bp-activity-notifications.php        2010-02-12 13:01:19 UTC (rev 2697)
</span><span class="lines">@@ -39,7 +39,11 @@
</span><span class="cx"> 
</span><span class="cx">                         $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
</span><span class="cx"> 
</span><del>-                        // Send it
</del><ins>+                        /* Send the message */
+                        $to = apply_filters( 'bp_activity_at_message_notification_to', $to );
+                        $subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject );
+                        $message = apply_filters( 'bp_activity_at_message_notification_message', $message );
+
</ins><span class="cx">                         wp_mail( $to, $subject, $message );
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="lines">@@ -75,7 +79,11 @@
</span><span class="cx"> 
</span><span class="cx">                 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
</span><span class="cx"> 
</span><del>-                // Send it
</del><ins>+                /* Send the message */
+                $to = apply_filters( 'bp_activity_new_comment_notification_to', $to );
+                $subject = apply_filters( 'bp_activity_new_comment_notification_subject', $subject );
+                $message = apply_filters( 'bp_activity_new_comment_notification_message', $message );
+
</ins><span class="cx">                 wp_mail( $to, $subject, $message );
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -110,7 +118,11 @@
</span><span class="cx"> 
</span><span class="cx">                 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
</span><span class="cx"> 
</span><del>-                // Send it
</del><ins>+                /* Send the message */
+                $to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $to );
+                $subject = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', $subject );
+                $message = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', $message );
+
</ins><span class="cx">                 wp_mail( $to, $subject, $message );
</span><span class="cx">         }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkbpcorebpcoreactivationphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-activation.php (2696 => 2697)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-activation.php        2010-02-12 12:48:30 UTC (rev 2696)
+++ trunk/bp-core/bp-core-activation.php        2010-02-12 13:01:19 UTC (rev 2697)
</span><span class="lines">@@ -113,8 +113,13 @@
</span><span class="cx">         $message = sprintf(__(&quot;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&quot;, 'buddypress' ), $activate_url, clean_url(&quot;http://{$domain}{$path}&quot; ) );
</span><span class="cx">         $subject = '[' . $from_name . '] ' . sprintf(__('Activate %s', 'buddypress' ), clean_url('http://' . $domain . $path));
</span><span class="cx"> 
</span><del>-        wp_mail( $user_email, $subject, $message, $message_headers );
</del><ins>+        /* Send the message */
+        $to = apply_filters( 'bp_core_activation_signup_blog_notification_to', $user_email );
+        $subject = apply_filters( 'bp_core_activation_signup_blog_notification_subject', $subject );
+        $message = apply_filters( 'bp_core_activation_signup_blog_notification_message', $message );
</ins><span class="cx"> 
</span><ins>+        wp_mail( $to, $subject, $message, $message_headers );
+
</ins><span class="cx">         // Return false to stop the original WPMU function from continuing
</span><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="lines">@@ -140,8 +145,13 @@
</span><span class="cx">         $message = sprintf( __( &quot;Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n&quot;, 'buddypress' ), $activate_url . $email, clean_url(&quot;http://{$domain}{$path}&quot; ) );
</span><span class="cx">         $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
</span><span class="cx"> 
</span><del>-        wp_mail( $user_email, $subject, $message, $message_headers );
</del><ins>+        /* Send the message */
+        $to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email );
+        $subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject );
+        $message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message );
</ins><span class="cx"> 
</span><ins>+        wp_mail( $to, $subject, $message, $message_headers );
+
</ins><span class="cx">         // Return false to stop the original WPMU function from continuing
</span><span class="cx">         return false;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkbpfriendsbpfriendsnotificationsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends/bp-friends-notifications.php (2696 => 2697)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends/bp-friends-notifications.php        2010-02-12 12:48:30 UTC (rev 2696)
+++ trunk/bp-friends/bp-friends-notifications.php        2010-02-12 13:01:19 UTC (rev 2697)
</span><span class="lines">@@ -32,11 +32,14 @@
</span><span class="cx"> 
</span><span class="cx">         $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
</span><span class="cx"> 
</span><del>-        // Send it
</del><ins>+        /* Send the message */
+        $to = apply_filters( 'friends_notification_new_request_to', $to );
+        $subject = apply_filters( 'friends_notification_new_request_subject', $subject );
+        $message = apply_filters( 'friends_notification_new_request_message', $message );
+
</ins><span class="cx">         wp_mail( $to, $subject, $message );
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> function friends_notification_accepted_request( $friendship_id, $initiator_id, $friend_id ) {
</span><span class="cx">         global $bp;
</span><span class="cx"> 
</span><span class="lines">@@ -66,9 +69,12 @@
</span><span class="cx"> 
</span><span class="cx">         $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
</span><span class="cx"> 
</span><del>-        // Send it
</del><ins>+        /* Send the message */
+        $to = apply_filters( 'friends_notification_accepted_request_to', $to );
+        $subject = apply_filters( 'friends_notification_accepted_request_subject', $subject );
+        $message = apply_filters( 'friends_notification_accepted_request_message', $message );
+
</ins><span class="cx">         wp_mail( $to, $subject, $message );
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> ?&gt;
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupsnotificationsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-notifications.php (2696 => 2697)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-notifications.php        2010-02-12 12:48:30 UTC (rev 2696)
+++ trunk/bp-groups/bp-groups-notifications.php        2010-02-12 13:01:19 UTC (rev 2697)
</span><span class="lines">@@ -28,7 +28,11 @@
</span><span class="cx"> 
</span><span class="cx">                 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
</span><span class="cx"> 
</span><del>-                // Send it
</del><ins>+                /* Send the message */
+                $to = apply_filters( 'groups_notification_group_updated_to', $to );
+                $subject = apply_filters( 'groups_notification_group_updated_subject', $subject );
+                $message = apply_filters( 'groups_notification_group_updated_message', $message );
+
</ins><span class="cx">                 wp_mail( $to, $subject, $message );
</span><span class="cx"> 
</span><span class="cx">                 unset( $message, $to );
</span><span class="lines">@@ -72,7 +76,11 @@
</span><span class="cx"> 
</span><span class="cx">         $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
</span><span class="cx"> 
</span><del>-        // Send it
</del><ins>+        /* Send the message */
+        $to = apply_filters( 'groups_notification_new_membership_request_to', $to );
+        $subject = apply_filters( 'groups_notification_new_membership_request_subject', $subject );
+        $message = apply_filters( 'groups_notification_new_membership_request_message', $message );
+
</ins><span class="cx">         wp_mail( $to, $subject, $message );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -121,7 +129,11 @@
</span><span class="cx"> 
</span><span class="cx">         $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
</span><span class="cx"> 
</span><del>-        // Send it
</del><ins>+        /* Send the message */
+        $to = apply_filters( 'groups_notification_membership_request_completed_to', $to );
+        $subject = apply_filters( 'groups_notification_membership_request_completed_subject', $subject );
+        $message = apply_filters( 'groups_notification_membership_request_completed_message', $message );
+
</ins><span class="cx">         wp_mail( $to, $subject, $message );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -163,7 +175,11 @@
</span><span class="cx"> 
</span><span class="cx">         $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
</span><span class="cx"> 
</span><del>-        // Send it
</del><ins>+        /* Send the message */
+        $to = apply_filters( 'groups_notification_promoted_member_to', $to );
+        $subject = apply_filters( 'groups_notification_promoted_member_subject', $subject );
+        $message = apply_filters( 'groups_notification_promoted_member_message', $message );
+
</ins><span class="cx">         wp_mail( $to, $subject, $message );
</span><span class="cx"> }
</span><span class="cx"> add_action( 'groups_promoted_member', 'groups_notification_promoted_member', 10, 2 );
</span><span class="lines">@@ -211,7 +227,11 @@
</span><span class="cx"> 
</span><span class="cx">                 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
</span><span class="cx"> 
</span><del>-                // Send it
</del><ins>+                /* Send the message */
+                $to = apply_filters( 'groups_notification_group_invites_to', $to );
+                $subject = apply_filters( 'groups_notification_group_invites_subject', $subject );
+                $message = apply_filters( 'groups_notification_group_invites_message', $message );
+
</ins><span class="cx">                 wp_mail( $to, $subject, $message );
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="lines">@@ -261,7 +281,11 @@
</span><span class="cx"> 
</span><span class="cx">                         $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
</span><span class="cx"> 
</span><del>-                        // Send it
</del><ins>+                        /* Send the message */
+                        $to = apply_filters( 'groups_at_message_notification_to', $to );
+                        $subject = apply_filters( 'groups_at_message_notification_subject', $subject );
+                        $message = apply_filters( 'groups_at_message_notification_message', $message );
+
</ins><span class="cx">                         wp_mail( $to, $subject, $message );
</span><span class="cx">                 }
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkbpmessagesbpmessagesnotificationsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-messages/bp-messages-notifications.php (2696 => 2697)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-messages/bp-messages-notifications.php        2010-02-12 12:48:30 UTC (rev 2696)
+++ trunk/bp-messages/bp-messages-notifications.php        2010-02-12 13:01:19 UTC (rev 2697)
</span><span class="lines">@@ -14,7 +14,7 @@
</span><span class="cx">                 $settings_link = bp_core_get_user_domain( $recipient-&gt;user_id ) . 'settings/notifications/';
</span><span class="cx"> 
</span><span class="cx">                 // Set up and send the message
</span><del>-                $to = $ud-&gt;user_email;
</del><ins>+                $email_to = $ud-&gt;user_email;
</ins><span class="cx">                 $email_subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'New message from %s', 'buddypress' ), stripslashes( $sender_name ) );
</span><span class="cx"> 
</span><span class="cx">                 $email_content = sprintf( __(
</span><span class="lines">@@ -31,48 +31,13 @@
</span><span class="cx"> 
</span><span class="cx">                 $content .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
</span><span class="cx"> 
</span><del>-                // Send it
-                wp_mail( $to, $email_subject, $email_content );
-        }
-}
</del><ins>+                /* Send the message */
+                $email_to = apply_filters( 'messages_notification_new_message_to', $email_to );
+                $email_subject = apply_filters( 'messages_notification_new_message_subject', $email_subject );
+                $email_content = apply_filters( 'messages_notification_new_message_message', $email_content );
</ins><span class="cx"> 
</span><del>-/* This is too expensive to send on normal servers uncomment action at your own risk. */
-function messages_notification_new_notice( $message_subject, $message ) {
-        global $bp, $wpdb;
-
-        $status_sql = bp_core_get_status_sql( 'u.' );
-        $users = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT ID as user_id, user_email, user_login FROM {$wpdb-&gt;base_prefix}users WHERE {$status_sql}&quot; ) );
-
-        for ( $i = 0; $i &lt; count($users); $i++ ) {
-                if ( get_usermeta( $users[$i]-&gt;user_id, 'notification_messages_new_notice' ) == 'no' ) continue;
-
-                $message_link = bp_core_get_user_domain( $users[$i]-&gt;user_id ) . 'messages';
-                $settings_link = bp_core_get_user_domain( $users[$i]-&gt;user_id ) . 'settings/notifications';
-
-                // Set up and send the message
-                $to = $users[$i]-&gt;user_email;
-                $subject = __( 'New Site Notice', 'buddypress' );
-
-                $message = sprintf( __(
-'A new site notice has been posted on %s:
-
-&quot;%s: %s&quot;
-
-To view the notice: %s
-
----------------------
-', 'buddypress' ), get_blog_option( BP_ROOT_BLOG, 'blogname' ), stripslashes( wp_filter_kses( $message_subject ) ), stripslashes( wp_filter_kses( $message ) ), $message_link );
-
-                $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
-
-                // Send it
-                wp_mail( $to, $subject, $message );
-
-                unset($message);
-                unset($subject);
-                unset($to);
</del><ins>+                wp_mail( $email_to, $email_subject, $email_content );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><del>-// add_action( 'bp_messages_notice_sent', 'messages_notification_new_notice', 10, 2 );
</del><span class="cx"> 
</span><span class="cx"> ?&gt;
</span><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>

</body>
</html>