Changeset 8575
- Timestamp:
- 07/09/2014 08:19:59 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-notifications.php
r8568 r8575 16 16 /** Emails ********************************************************************/ 17 17 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 */ 25 function groups_notification_group_updated( $group_id = 0 ) { 19 26 20 27 $group = groups_get_group( array( 'group_id' => $group_id ) ); … … 23 30 24 31 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 } 26 37 27 38 $ud = bp_core_get_core_userdata( $user_id ); … … 57 68 } 58 69 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 */ 81 function groups_notification_new_membership_request( $requesting_user_id = 0, $admin_id = 0, $group_id = 0, $membership_id = 0 ) { 82 83 // Trigger a BuddyPress Notification 61 84 if ( bp_is_active( 'notifications' ) ) { 62 85 bp_notifications_add_notification( array( … … 69 92 } 70 93 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 ) ) { 72 96 return false; 97 } 73 98 74 99 // Username of the user requesting a membership: %1$s in mail … … 109 134 } 110 135 111 / * Send the message */136 // Send the message 112 137 $to = apply_filters( 'groups_notification_new_membership_request_to', $to ); 113 138 $subject = apply_filters_ref_array( 'groups_notification_new_membership_request_subject', array( $subject, &$group ) ); … … 119 144 } 120 145 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 */ 156 function 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'; 127 165 128 166 bp_notifications_add_notification( array( … … 134 172 } 135 173 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 ) ) { 137 176 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 ); 144 182 $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings'; 145 183 $settings_link = bp_core_get_user_domain( $requesting_user_id ) . $settings_slug . '/notifications/'; 184 $to = $ud->user_email; 146 185 147 186 // Set up and send the message 148 $to = $ud->user_email; 149 150 if ( $accepted ) { 187 if ( ! empty( $accepted ) ) { 151 188 $subject = bp_get_email_subject( array( 'text' => sprintf( __( 'Membership request for group "%s" accepted', 'buddypress' ), $group->name ) ) ); 152 189 $message = sprintf( __( … … 174 211 } 175 212 176 / * Send the message */213 // Send the message 177 214 $to = apply_filters( 'groups_notification_membership_request_completed_to', $to ); 178 215 $subject = apply_filters_ref_array( 'groups_notification_membership_request_completed_subject', array( $subject, &$group ) ); … … 186 223 add_action( 'groups_membership_rejected', 'groups_notification_membership_request_completed', 10, 3 ); 187 224 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 */ 233 function groups_notification_promoted_member( $user_id = 0, $group_id = 0 ) { 234 235 // What type of promotion is this? 190 236 if ( groups_is_user_admin( $user_id, $group_id ) ) { 191 237 $promoted_to = __( 'an administrator', 'buddypress' ); 192 $type = 'member_promoted_to_admin';238 $type = 'member_promoted_to_admin'; 193 239 } else { 194 240 $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 199 245 if ( bp_is_active( 'notifications' ) ) { 200 246 bp_notifications_add_notification( array( … … 202 248 'item_id' => $group_id, 203 249 'component_name' => buddypress()->groups->id, 204 'component_action' => $type, 205 'date_notified' => bp_core_current_time(), 206 'is_new' => 1, 250 'component_action' => $type 207 251 ) ); 208 252 } 209 253 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 ) ) { 211 256 return false; 257 } 212 258 213 259 $group = groups_get_group( array( 'group_id' => $group_id ) ); … … 233 279 } 234 280 235 / * Send the message */281 // Send the message 236 282 $to = apply_filters( 'groups_notification_promoted_member_to', $to ); 237 283 $subject = apply_filters_ref_array( 'groups_notification_promoted_member_subject', array( $subject, &$group ) ); … … 244 290 add_action( 'groups_promoted_member', 'groups_notification_promoted_member', 10, 2 ); 245 291 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 */ 246 301 function groups_notification_group_invites( &$group, &$member, $inviter_user_id ) { 247 302 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 249 309 $inviter_ud = bp_core_get_core_userdata( $inviter_user_id ); 250 310 $inviter_name = bp_core_get_userlink( $inviter_user_id, true, false, true ); 251 311 $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 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( __( 282 342 'One of your friends %1$s has invited you to the group: "%2$s". 283 343 … … 291 351 ', 'buddypress' ), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_link ); 292 352 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 ); 307 366 } 308 367 … … 630 689 * 631 690 * @since BuddyPress (1.9.0) 632 * @param int $group_id 633 */ 634 function bp_groups_screen_group_admin_requests_mark_notifications( $group_id ) { 691 */ 692 function bp_groups_screen_group_admin_requests_mark_notifications() { 635 693 if ( bp_is_active( 'notifications' ) ) { 636 694 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.