Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/09/2014 08:19:59 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Phpdoc and code clean-up to bp-groups-notifications.php.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-notifications.php

    r8568 r8575  
    1616/** Emails ********************************************************************/
    1717
    18 function groups_notification_group_updated( $group_id ) {
     18/**
     19 * Send an email to all group members when a group is updated
     20 *
     21 * @since BuddyPress (1.0.0)
     22 *
     23 * @param int $group_id
     24 */
     25function groups_notification_group_updated( $group_id = 0 ) {
    1926
    2027        $group    = groups_get_group( array( 'group_id' => $group_id ) );
     
    2330
    2431        foreach ( (array) $user_ids as $user_id ) {
    25                 if ( 'no' == bp_get_user_meta( $user_id, 'notification_groups_group_updated', true ) ) continue;
     32
     33                // Continue if member opted out of receiving this email
     34                if ( 'no' === bp_get_user_meta( $user_id, 'notification_groups_group_updated', true ) ) {
     35                        continue;
     36                }
    2637
    2738                $ud = bp_core_get_core_userdata( $user_id );
     
    5768}
    5869
    59 function groups_notification_new_membership_request( $requesting_user_id, $admin_id, $group_id, $membership_id ) {
    60 
     70/**
     71 * Send email to group admin about membership request
     72 *
     73 * @since BuddyPress (1.0.0)
     74 *
     75 * @param int $requesting_user_id
     76 * @param int $admin_id
     77 * @param int $group_id
     78 * @param int $membership_id
     79 * @return boolean
     80 */
     81function groups_notification_new_membership_request( $requesting_user_id = 0, $admin_id = 0, $group_id = 0, $membership_id = 0 ) {
     82
     83        // Trigger a BuddyPress Notification
    6184        if ( bp_is_active( 'notifications' ) ) {
    6285                bp_notifications_add_notification( array(
     
    6992        }
    7093
    71         if ( 'no' == bp_get_user_meta( $admin_id, 'notification_groups_membership_request', true ) )
     94        // Bail if member opted out of receiving this email
     95        if ( 'no' === bp_get_user_meta( $admin_id, 'notification_groups_membership_request', true ) ) {
    7296                return false;
     97        }
    7398
    7499        // Username of the user requesting a membership: %1$s in mail
     
    109134        }
    110135
    111         /* Send the message */
     136        // Send the message
    112137        $to      = apply_filters( 'groups_notification_new_membership_request_to', $to );
    113138        $subject = apply_filters_ref_array( 'groups_notification_new_membership_request_subject', array( $subject, &$group ) );
     
    119144}
    120145
    121 function groups_notification_membership_request_completed( $requesting_user_id, $group_id, $accepted = true ) {
    122 
    123         // Post a screen notification first.
    124         if ( bp_is_active( 'notifications' ) ) {
    125 
    126                 $type = ! empty( $accepted ) ? 'membership_request_accepted' : 'membership_request_rejected' ;
     146/**
     147 * Send email to member about their group membership request
     148 *
     149 * @since BuddyPress (1.0.0)
     150 *
     151 * @param type $requesting_user_id
     152 * @param type $group_id
     153 * @param type $accepted
     154 * @return boolean
     155 */
     156function groups_notification_membership_request_completed( $requesting_user_id = 0, $group_id = 0, $accepted = true ) {
     157
     158        // Trigger a BuddyPress Notification
     159        if ( bp_is_active( 'notifications' ) ) {
     160
     161                // What type of acknowledgement
     162                $type = ! empty( $accepted )
     163                        ? 'membership_request_accepted'
     164                        : 'membership_request_rejected';
    127165
    128166                bp_notifications_add_notification( array(
     
    134172        }
    135173
    136         if ( 'no' == bp_get_user_meta( $requesting_user_id, 'notification_membership_request_completed', true ) )
     174        // Bail if member opted out of receiving this email
     175        if ( 'no' === bp_get_user_meta( $requesting_user_id, 'notification_membership_request_completed', true ) ) {
    137176                return false;
    138 
    139         $group = groups_get_group( array( 'group_id' => $group_id ) );
    140 
    141         $ud = bp_core_get_core_userdata($requesting_user_id);
    142 
    143         $group_link   = bp_get_group_permalink( $group );
     177        }
     178
     179        $group         = groups_get_group( array( 'group_id' => $group_id ) );
     180        $ud            = bp_core_get_core_userdata( $requesting_user_id );
     181        $group_link    = bp_get_group_permalink( $group );
    144182        $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    145183        $settings_link = bp_core_get_user_domain( $requesting_user_id ) . $settings_slug . '/notifications/';
     184        $to            = $ud->user_email;
    146185
    147186        // Set up and send the message
    148         $to       = $ud->user_email;
    149 
    150         if ( $accepted ) {
     187        if ( ! empty( $accepted ) ) {
    151188                $subject = bp_get_email_subject( array( 'text' => sprintf( __( 'Membership request for group "%s" accepted', 'buddypress' ), $group->name ) ) );
    152189                $message = sprintf( __(
     
    174211        }
    175212
    176         /* Send the message */
     213        // Send the message
    177214        $to      = apply_filters( 'groups_notification_membership_request_completed_to', $to );
    178215        $subject = apply_filters_ref_array( 'groups_notification_membership_request_completed_subject', array( $subject, &$group ) );
     
    186223add_action( 'groups_membership_rejected', 'groups_notification_membership_request_completed', 10, 3 );
    187224
    188 function groups_notification_promoted_member( $user_id, $group_id ) {
    189 
     225/**
     226 *
     227 * @since BuddyPress (1.0.0)
     228 *
     229 * @param int $user_id
     230 * @param int $group_id
     231 * @return boolean
     232 */
     233function groups_notification_promoted_member( $user_id = 0, $group_id = 0 ) {
     234
     235        // What type of promotion is this?
    190236        if ( groups_is_user_admin( $user_id, $group_id ) ) {
    191237                $promoted_to = __( 'an administrator', 'buddypress' );
    192                 $type = 'member_promoted_to_admin';
     238                $type        = 'member_promoted_to_admin';
    193239        } else {
    194240                $promoted_to = __( 'a moderator', 'buddypress' );
    195                 $type = 'member_promoted_to_mod';
    196         }
    197 
    198         // Post a screen notification first.
     241                $type        = 'member_promoted_to_mod';
     242        }
     243
     244        // Trigger a BuddyPress Notification
    199245        if ( bp_is_active( 'notifications' ) ) {
    200246                bp_notifications_add_notification( array(
     
    202248                        'item_id'           => $group_id,
    203249                        'component_name'    => buddypress()->groups->id,
    204                         'component_action'  => $type,
    205                         'date_notified'     => bp_core_current_time(),
    206                         'is_new'            => 1,
     250                        'component_action'  => $type
    207251                ) );
    208252        }
    209253
    210         if ( 'no' == bp_get_user_meta( $user_id, 'notification_groups_admin_promotion', true ) )
     254        // Bail if admin opted out of receiving this email
     255        if ( 'no' === bp_get_user_meta( $user_id, 'notification_groups_admin_promotion', true ) ) {
    211256                return false;
     257        }
    212258
    213259        $group         = groups_get_group( array( 'group_id' => $group_id ) );
     
    233279        }
    234280
    235         /* Send the message */
     281        // Send the message
    236282        $to      = apply_filters( 'groups_notification_promoted_member_to', $to );
    237283        $subject = apply_filters_ref_array( 'groups_notification_promoted_member_subject', array( $subject, &$group ) );
     
    244290add_action( 'groups_promoted_member', 'groups_notification_promoted_member', 10, 2 );
    245291
     292/**
     293 *
     294 * @since BuddyPress (1.0.0)
     295 *
     296 * @param object $group
     297 * @param object $member
     298 * @param int $inviter_user_id
     299 * @return boolean
     300 */
    246301function groups_notification_group_invites( &$group, &$member, $inviter_user_id ) {
    247302
    248         // @todo $inviter_up may be used for caching, test without it
     303        // Bail if member has already been invited
     304        if ( ! empty( $member->invite_sent ) ) {
     305                return;
     306        }
     307
     308        // @todo $inviter_ud may be used for caching, test without it
    249309        $inviter_ud   = bp_core_get_core_userdata( $inviter_user_id );
    250310        $inviter_name = bp_core_get_userlink( $inviter_user_id, true, false, true );
    251311        $inviter_link = bp_core_get_user_domain( $inviter_user_id );
    252 
    253         $group_link = bp_get_group_permalink( $group );
    254 
    255         if ( !$member->invite_sent ) {
    256                 $invited_user_id = $member->user_id;
    257 
    258                 // Post a screen notification first.
    259                 if ( bp_is_active( 'notifications' ) ) {
    260                         bp_notifications_add_notification( array(
    261                                 'user_id'           => $invited_user_id,
    262                                 'item_id'           => $group->id,
    263                                 'component_name'    => buddypress()->groups->id,
    264                                 'component_action'  => 'group_invite'
    265                         ) );
    266                 }
    267 
    268                 if ( 'no' == bp_get_user_meta( $invited_user_id, 'notification_groups_invite', true ) )
    269                         return false;
    270 
    271                 $invited_ud    = bp_core_get_core_userdata($invited_user_id);
    272                 $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    273                 $settings_link = bp_core_get_user_domain( $invited_user_id ) . $settings_slug . '/notifications/';
    274                 $invited_link  = bp_core_get_user_domain( $invited_user_id );
    275                 $invites_link  = trailingslashit( $invited_link . bp_get_groups_slug() . '/invites' );
    276 
    277                 // Set up and send the message
    278                 $to       = $invited_ud->user_email;
    279                 $subject  = bp_get_email_subject( array( 'text' => sprintf( __( 'You have an invitation to the group: "%s"', 'buddypress' ), $group->name ) ) );
    280 
    281                 $message = sprintf( __(
     312        $group_link   = bp_get_group_permalink( $group );
     313
     314        // Setup the ID for the invited user
     315        $invited_user_id = $member->user_id;
     316
     317        // Trigger a BuddyPress Notification
     318        if ( bp_is_active( 'notifications' ) ) {
     319                bp_notifications_add_notification( array(
     320                        'user_id'          => $invited_user_id,
     321                        'item_id'          => $group->id,
     322                        'component_name'   => buddypress()->groups->id,
     323                        'component_action' => 'group_invite'
     324                ) );
     325        }
     326
     327        // Bail if member opted out of receiving this email
     328        if ( 'no' === bp_get_user_meta( $invited_user_id, 'notification_groups_invite', true ) ) {
     329                return false;
     330        }
     331
     332        $invited_ud    = bp_core_get_core_userdata( $invited_user_id );
     333        $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
     334        $settings_link = bp_core_get_user_domain( $invited_user_id ) . $settings_slug . '/notifications/';
     335        $invited_link  = bp_core_get_user_domain( $invited_user_id );
     336        $invites_link  = trailingslashit( $invited_link . bp_get_groups_slug() . '/invites' );
     337
     338        // Set up and send the message
     339        $to       = $invited_ud->user_email;
     340        $subject  = bp_get_email_subject( array( 'text' => sprintf( __( 'You have an invitation to the group: "%s"', 'buddypress' ), $group->name ) ) );
     341        $message = sprintf( __(
    282342'One of your friends %1$s has invited you to the group: "%2$s".
    283343
     
    291351', 'buddypress' ), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_link );
    292352
    293                 // Only show the disable notifications line if the settings component is enabled
    294                 if ( bp_is_active( 'settings' ) ) {
    295                         $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    296                 }
    297 
    298                 /* Send the message */
    299                 $to      = apply_filters( 'groups_notification_group_invites_to', $to );
    300                 $subject = apply_filters_ref_array( 'groups_notification_group_invites_subject', array( $subject, &$group ) );
    301                 $message = apply_filters_ref_array( 'groups_notification_group_invites_message', array( $message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link ) );
    302 
    303                 wp_mail( $to, $subject, $message );
    304 
    305                 do_action( 'bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group );
    306         }
     353        // Only show the disable notifications line if the settings component is enabled
     354        if ( bp_is_active( 'settings' ) ) {
     355                $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
     356        }
     357
     358        // Send the message
     359        $to      = apply_filters( 'groups_notification_group_invites_to', $to );
     360        $subject = apply_filters_ref_array( 'groups_notification_group_invites_subject', array( $subject, &$group ) );
     361        $message = apply_filters_ref_array( 'groups_notification_group_invites_message', array( $message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link ) );
     362
     363        wp_mail( $to, $subject, $message );
     364
     365        do_action( 'bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group );
    307366}
    308367
     
    630689 *
    631690 * @since BuddyPress (1.9.0)
    632  * @param int $group_id
    633  */
    634 function bp_groups_screen_group_admin_requests_mark_notifications( $group_id ) {
     691 */
     692function bp_groups_screen_group_admin_requests_mark_notifications() {
    635693        if ( bp_is_active( 'notifications' ) ) {
    636694                bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->groups->id, 'new_membership_request' );
Note: See TracChangeset for help on using the changeset viewer.