<!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" />
<title>[BuddyPress][8575] trunk/src/bp-groups/bp-groups-notifications.php: Phpdoc and code clean-up to `bp-groups-notifications.php`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/8575">8575</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2014-07-09 20:19:59 +0000 (Wed, 09 Jul 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Phpdoc and code clean-up to `bp-groups-notifications.php`.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpgroupsbpgroupsnotificationsphp">trunk/src/bp-groups/bp-groups-notifications.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpgroupsbpgroupsnotificationsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/bp-groups/bp-groups-notifications.php (8574 => 8575)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/bp-groups/bp-groups-notifications.php  2014-07-09 20:16:16 UTC (rev 8574)
+++ trunk/src/bp-groups/bp-groups-notifications.php     2014-07-09 20:19:59 UTC (rev 8575)
</span><span class="lines">@@ -15,15 +15,26 @@
</span><span class="cx"> 
</span><span class="cx"> /** Emails ********************************************************************/
</span><span class="cx"> 
</span><del>-function groups_notification_group_updated( $group_id ) {
</del><ins>+/**
+ * Send an email to all group members when a group is updated
+ *
+ * @since BuddyPress (1.0.0)
+ *
+ * @param int $group_id
+ */
+function groups_notification_group_updated( $group_id = 0 ) {
</ins><span class="cx"> 
</span><span class="cx">  $group    = groups_get_group( array( 'group_id' => $group_id ) );
</span><span class="cx">  $subject  = bp_get_email_subject( array( 'text' => __( 'Group Details Updated', 'buddypress' ) ) );
</span><span class="cx">  $user_ids = BP_Groups_Member::get_group_member_ids( $group->id );
</span><span class="cx"> 
</span><span class="cx">  foreach ( (array) $user_ids as $user_id ) {
</span><del>-               if ( 'no' == bp_get_user_meta( $user_id, 'notification_groups_group_updated', true ) ) continue;
</del><span class="cx"> 
</span><ins>+               // Continue if member opted out of receiving this email
+               if ( 'no' === bp_get_user_meta( $user_id, 'notification_groups_group_updated', true ) ) {
+                       continue;
+               }
+
</ins><span class="cx">           $ud = bp_core_get_core_userdata( $user_id );
</span><span class="cx"> 
</span><span class="cx">          // Set up and send the message
</span><span class="lines">@@ -56,8 +67,20 @@
</span><span class="cx">  do_action( 'bp_groups_sent_updated_email', $user_ids, $subject, '', $group_id );
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function groups_notification_new_membership_request( $requesting_user_id, $admin_id, $group_id, $membership_id ) {
</del><ins>+/**
+ * Send email to group admin about membership request
+ *
+ * @since BuddyPress (1.0.0)
+ *
+ * @param int $requesting_user_id
+ * @param int $admin_id
+ * @param int $group_id
+ * @param int $membership_id
+ * @return boolean
+ */
+function groups_notification_new_membership_request( $requesting_user_id = 0, $admin_id = 0, $group_id = 0, $membership_id = 0 ) {
</ins><span class="cx"> 
</span><ins>+       // Trigger a BuddyPress Notification
</ins><span class="cx">   if ( bp_is_active( 'notifications' ) ) {
</span><span class="cx">          bp_notifications_add_notification( array(
</span><span class="cx">                  'user_id'           => $admin_id,
</span><span class="lines">@@ -68,8 +91,10 @@
</span><span class="cx">          ) );
</span><span class="cx">  }
</span><span class="cx"> 
</span><del>-       if ( 'no' == bp_get_user_meta( $admin_id, 'notification_groups_membership_request', true ) )
</del><ins>+        // Bail if member opted out of receiving this email
+       if ( 'no' === bp_get_user_meta( $admin_id, 'notification_groups_membership_request', true ) ) {
</ins><span class="cx">           return false;
</span><ins>+       }
</ins><span class="cx"> 
</span><span class="cx">  // Username of the user requesting a membership: %1$s in mail
</span><span class="cx">  $requesting_user_name = bp_core_get_user_displayname( $requesting_user_id );
</span><span class="lines">@@ -108,7 +133,7 @@
</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><span class="cx"> 
</span><del>-       /* Send the message */
</del><ins>+        // Send the message
</ins><span class="cx">   $to      = apply_filters( 'groups_notification_new_membership_request_to', $to );
</span><span class="cx">  $subject = apply_filters_ref_array( 'groups_notification_new_membership_request_subject', array( $subject, &$group ) );
</span><span class="cx">  $message = apply_filters_ref_array( 'groups_notification_new_membership_request_message', array( $message, &$group, $requesting_user_name, $profile_link, $group_requests, $settings_link ) );
</span><span class="lines">@@ -118,12 +143,25 @@
</span><span class="cx">  do_action( 'bp_groups_sent_membership_request_email', $admin_id, $subject, $message, $requesting_user_id, $group_id, $membership_id );
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function groups_notification_membership_request_completed( $requesting_user_id, $group_id, $accepted = true ) {
</del><ins>+/**
+ * Send email to member about their group membership request
+ *
+ * @since BuddyPress (1.0.0)
+ *
+ * @param type $requesting_user_id
+ * @param type $group_id
+ * @param type $accepted
+ * @return boolean
+ */
+function groups_notification_membership_request_completed( $requesting_user_id = 0, $group_id = 0, $accepted = true ) {
</ins><span class="cx"> 
</span><del>-       // Post a screen notification first.
</del><ins>+        // Trigger a BuddyPress Notification
</ins><span class="cx">   if ( bp_is_active( 'notifications' ) ) {
</span><span class="cx"> 
</span><del>-               $type = ! empty( $accepted ) ? 'membership_request_accepted' : 'membership_request_rejected' ;
</del><ins>+                // What type of acknowledgement
+               $type = ! empty( $accepted )
+                       ? 'membership_request_accepted'
+                       : 'membership_request_rejected';
</ins><span class="cx"> 
</span><span class="cx">          bp_notifications_add_notification( array(
</span><span class="cx">                  'user_id'           => $requesting_user_id,
</span><span class="lines">@@ -133,21 +171,20 @@
</span><span class="cx">          ) );
</span><span class="cx">  }
</span><span class="cx"> 
</span><del>-       if ( 'no' == bp_get_user_meta( $requesting_user_id, 'notification_membership_request_completed', true ) )
</del><ins>+        // Bail if member opted out of receiving this email
+       if ( 'no' === bp_get_user_meta( $requesting_user_id, 'notification_membership_request_completed', true ) ) {
</ins><span class="cx">           return false;
</span><ins>+       }
</ins><span class="cx"> 
</span><del>-       $group = groups_get_group( array( 'group_id' => $group_id ) );
-
-       $ud = bp_core_get_core_userdata($requesting_user_id);
-
-       $group_link   = bp_get_group_permalink( $group );
</del><ins>+        $group         = groups_get_group( array( 'group_id' => $group_id ) );
+       $ud            = bp_core_get_core_userdata( $requesting_user_id );
+       $group_link    = bp_get_group_permalink( $group );
</ins><span class="cx">   $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
</span><span class="cx">  $settings_link = bp_core_get_user_domain( $requesting_user_id ) . $settings_slug . '/notifications/';
</span><ins>+       $to            = $ud->user_email;
</ins><span class="cx"> 
</span><span class="cx">  // Set up and send the message
</span><del>-       $to       = $ud->user_email;
-
-       if ( $accepted ) {
</del><ins>+        if ( ! empty( $accepted ) ) {
</ins><span class="cx">           $subject = bp_get_email_subject( array( 'text' => sprintf( __( 'Membership request for group "%s" accepted', 'buddypress' ), $group->name ) ) );
</span><span class="cx">          $message = sprintf( __(
</span><span class="cx"> 'Your membership request for the group "%1$s" has been accepted.
</span><span class="lines">@@ -173,7 +210,7 @@
</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><span class="cx"> 
</span><del>-       /* Send the message */
</del><ins>+        // Send the message
</ins><span class="cx">   $to      = apply_filters( 'groups_notification_membership_request_completed_to', $to );
</span><span class="cx">  $subject = apply_filters_ref_array( 'groups_notification_membership_request_completed_subject', array( $subject, &$group ) );
</span><span class="cx">  $message = apply_filters_ref_array( 'groups_notification_membership_request_completed_message', array( $message, &$group, $group_link, $settings_link ) );
</span><span class="lines">@@ -185,30 +222,39 @@
</span><span class="cx"> add_action( 'groups_membership_accepted', 'groups_notification_membership_request_completed', 10, 3 );
</span><span class="cx"> add_action( 'groups_membership_rejected', 'groups_notification_membership_request_completed', 10, 3 );
</span><span class="cx"> 
</span><del>-function groups_notification_promoted_member( $user_id, $group_id ) {
</del><ins>+/**
+ * 
+ * @since BuddyPress (1.0.0)
+ *
+ * @param int $user_id
+ * @param int $group_id
+ * @return boolean
+ */
+function groups_notification_promoted_member( $user_id = 0, $group_id = 0 ) {
</ins><span class="cx"> 
</span><ins>+       // What type of promotion is this?
</ins><span class="cx">   if ( groups_is_user_admin( $user_id, $group_id ) ) {
</span><span class="cx">          $promoted_to = __( 'an administrator', 'buddypress' );
</span><del>-               $type = 'member_promoted_to_admin';
</del><ins>+                $type        = 'member_promoted_to_admin';
</ins><span class="cx">   } else {
</span><span class="cx">          $promoted_to = __( 'a moderator', 'buddypress' );
</span><del>-               $type = 'member_promoted_to_mod';
</del><ins>+                $type        = 'member_promoted_to_mod';
</ins><span class="cx">   }
</span><span class="cx"> 
</span><del>-       // Post a screen notification first.
</del><ins>+        // Trigger a BuddyPress Notification
</ins><span class="cx">   if ( bp_is_active( 'notifications' ) ) {
</span><span class="cx">          bp_notifications_add_notification( array(
</span><span class="cx">                  'user_id'           => $user_id,
</span><span class="cx">                  'item_id'           => $group_id,
</span><span class="cx">                  'component_name'    => buddypress()->groups->id,
</span><del>-                       'component_action'  => $type,
-                       'date_notified'     => bp_core_current_time(),
-                       'is_new'            => 1,
</del><ins>+                        'component_action'  => $type
</ins><span class="cx">           ) );
</span><span class="cx">  }
</span><span class="cx"> 
</span><del>-       if ( 'no' == bp_get_user_meta( $user_id, 'notification_groups_admin_promotion', true ) )
</del><ins>+        // Bail if admin opted out of receiving this email
+       if ( 'no' === bp_get_user_meta( $user_id, 'notification_groups_admin_promotion', true ) ) {
</ins><span class="cx">           return false;
</span><ins>+       }
</ins><span class="cx"> 
</span><span class="cx">  $group         = groups_get_group( array( 'group_id' => $group_id ) );
</span><span class="cx">  $ud            = bp_core_get_core_userdata($user_id);
</span><span class="lines">@@ -232,7 +278,7 @@
</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><span class="cx"> 
</span><del>-       /* Send the message */
</del><ins>+        // Send the message
</ins><span class="cx">   $to      = apply_filters( 'groups_notification_promoted_member_to', $to );
</span><span class="cx">  $subject = apply_filters_ref_array( 'groups_notification_promoted_member_subject', array( $subject, &$group ) );
</span><span class="cx">  $message = apply_filters_ref_array( 'groups_notification_promoted_member_message', array( $message, &$group, $promoted_to, $group_link, $settings_link ) );
</span><span class="lines">@@ -243,42 +289,56 @@
</span><span class="cx"> }
</span><span class="cx"> add_action( 'groups_promoted_member', 'groups_notification_promoted_member', 10, 2 );
</span><span class="cx"> 
</span><ins>+/**
+ * 
+ * @since BuddyPress (1.0.0)
+ *
+ * @param object $group
+ * @param object $member
+ * @param int $inviter_user_id
+ * @return boolean
+ */
</ins><span class="cx"> function groups_notification_group_invites( &$group, &$member, $inviter_user_id ) {
</span><span class="cx"> 
</span><del>-       // @todo $inviter_up may be used for caching, test without it
</del><ins>+        // Bail if member has already been invited
+       if ( ! empty( $member->invite_sent ) ) {
+               return;
+       }
+
+       // @todo $inviter_ud may be used for caching, test without it
</ins><span class="cx">   $inviter_ud   = bp_core_get_core_userdata( $inviter_user_id );
</span><span class="cx">  $inviter_name = bp_core_get_userlink( $inviter_user_id, true, false, true );
</span><span class="cx">  $inviter_link = bp_core_get_user_domain( $inviter_user_id );
</span><ins>+       $group_link   = bp_get_group_permalink( $group );
</ins><span class="cx"> 
</span><del>-       $group_link = bp_get_group_permalink( $group );
</del><ins>+        // Setup the ID for the invited user
+       $invited_user_id = $member->user_id;
</ins><span class="cx"> 
</span><del>-       if ( !$member->invite_sent ) {
-               $invited_user_id = $member->user_id;
</del><ins>+        // Trigger a BuddyPress Notification
+       if ( bp_is_active( 'notifications' ) ) {
+               bp_notifications_add_notification( array(
+                       'user_id'          => $invited_user_id,
+                       'item_id'          => $group->id,
+                       'component_name'   => buddypress()->groups->id,
+                       'component_action' => 'group_invite'
+               ) );
+       }
</ins><span class="cx"> 
</span><del>-               // Post a screen notification first.
-               if ( bp_is_active( 'notifications' ) ) {
-                       bp_notifications_add_notification( array(
-                               'user_id'           => $invited_user_id,
-                               'item_id'           => $group->id,
-                               'component_name'    => buddypress()->groups->id,
-                               'component_action'  => 'group_invite'
-                       ) );
-               }
</del><ins>+        // Bail if member opted out of receiving this email
+       if ( 'no' === bp_get_user_meta( $invited_user_id, 'notification_groups_invite', true ) ) {
+               return false;
+       }
</ins><span class="cx"> 
</span><del>-               if ( 'no' == bp_get_user_meta( $invited_user_id, 'notification_groups_invite', true ) )
-                       return false;
</del><ins>+        $invited_ud    = bp_core_get_core_userdata( $invited_user_id );
+       $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
+       $settings_link = bp_core_get_user_domain( $invited_user_id ) . $settings_slug . '/notifications/';
+       $invited_link  = bp_core_get_user_domain( $invited_user_id );
+       $invites_link  = trailingslashit( $invited_link . bp_get_groups_slug() . '/invites' );
</ins><span class="cx"> 
</span><del>-               $invited_ud    = bp_core_get_core_userdata($invited_user_id);
-               $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
-               $settings_link = bp_core_get_user_domain( $invited_user_id ) . $settings_slug . '/notifications/';
-               $invited_link  = bp_core_get_user_domain( $invited_user_id );
-               $invites_link  = trailingslashit( $invited_link . bp_get_groups_slug() . '/invites' );
-
-               // Set up and send the message
-               $to       = $invited_ud->user_email;
-               $subject  = bp_get_email_subject( array( 'text' => sprintf( __( 'You have an invitation to the group: "%s"', 'buddypress' ), $group->name ) ) );
-
-               $message = sprintf( __(
</del><ins>+        // Set up and send the message
+       $to       = $invited_ud->user_email;
+       $subject  = bp_get_email_subject( array( 'text' => sprintf( __( 'You have an invitation to the group: "%s"', 'buddypress' ), $group->name ) ) );
+       $message  = sprintf( __(
</ins><span class="cx"> 'One of your friends %1$s has invited you to the group: "%2$s".
</span><span class="cx"> 
</span><span class="cx"> To view your group invites visit: %3$s
</span><span class="lines">@@ -290,20 +350,19 @@
</span><span class="cx"> ---------------------
</span><span class="cx"> ', 'buddypress' ), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_link );
</span><span class="cx"> 
</span><del>-               // Only show the disable notifications line if the settings component is enabled
-               if ( bp_is_active( 'settings' ) ) {
-                       $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
-               }
</del><ins>+        // Only show the disable notifications line if the settings component is enabled
+       if ( bp_is_active( 'settings' ) ) {
+               $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
+       }
</ins><span class="cx"> 
</span><del>-               /* Send the message */
-               $to      = apply_filters( 'groups_notification_group_invites_to', $to );
-               $subject = apply_filters_ref_array( 'groups_notification_group_invites_subject', array( $subject, &$group ) );
-               $message = apply_filters_ref_array( 'groups_notification_group_invites_message', array( $message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link ) );
</del><ins>+        // Send the message
+       $to      = apply_filters( 'groups_notification_group_invites_to', $to );
+       $subject = apply_filters_ref_array( 'groups_notification_group_invites_subject', array( $subject, &$group ) );
+       $message = apply_filters_ref_array( 'groups_notification_group_invites_message', array( $message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link ) );
</ins><span class="cx"> 
</span><del>-               wp_mail( $to, $subject, $message );
</del><ins>+        wp_mail( $to, $subject, $message );
</ins><span class="cx"> 
</span><del>-               do_action( 'bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group );
-       }
</del><ins>+        do_action( 'bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /** Notifications *************************************************************/
</span><span class="lines">@@ -629,9 +688,8 @@
</span><span class="cx">  * administration area.
</span><span class="cx">  *
</span><span class="cx">  * @since BuddyPress (1.9.0)
</span><del>- * @param int $group_id
</del><span class="cx">  */
</span><del>-function bp_groups_screen_group_admin_requests_mark_notifications( $group_id ) {
</del><ins>+function bp_groups_screen_group_admin_requests_mark_notifications() {
</ins><span class="cx">   if ( bp_is_active( 'notifications' ) ) {
</span><span class="cx">          bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->groups->id, 'new_membership_request' );
</span><span class="cx">  }
</span></span></pre>
</div>
</div>

</body>
</html>