bp_activity_at_message_notification

Send email and BP notifications when a user is mentioned in an update.

Description

bp_activity_at_message_notification( (int) $activity_id, (int) $receiver_user_id ); 

Parameters (2)

0. $activity_id (int)
The ID of the activity update.
1. $receiver_user_id (int)
The ID of the user who is receiving the update.

Usage

  1. if ( !function_exists( 'bp_activity_at_message_notification' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3.  
  4. // The ID of the activity update. 
  5. $activity_id = -1; 
  6.  
  7. // The ID of the user who is receiving the update. 
  8. $receiver_user_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_activity_at_message_notification($activity_id, $receiver_user_id); 
  12.  

Defined (1)

The function is defined in the following location(s).

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) { 
  2. $notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' ); 
  3.  
  4. // Don't leave multiple notifications for the same activity item. 
  5. foreach( $notifications as $notification ) { 
  6. if ( $activity_id == $notification->item_id ) { 
  7. return; 
  8.  
  9. $activity = new BP_Activity_Activity( $activity_id ); 
  10. $email_type = 'activity-at-message'; 
  11. $group_name = ''; 
  12. $message_link = bp_activity_get_permalink( $activity_id ); 
  13. $poster_name = bp_core_get_user_displayname( $activity->user_id ); 
  14.  
  15.  
  16. /** This filter is documented in bp-activity/bp-activity-template.php */ 
  17. $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $activity->content, &$activity ) ); 
  18.  
  19. add_filter( 'bp_get_activity_content_body', 'convert_smilies' ); 
  20.  
  21. // Now email the user with the contents of the message (if they have enabled email notifications). 
  22. if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) { 
  23. if ( bp_is_active( 'groups' ) && bp_is_group() ) { 
  24. $email_type = 'groups-at-message'; 
  25. $group_name = bp_get_current_group_name(); 
  26.  
  27. $unsubscribe_args = array( 
  28. 'user_id' => $receiver_user_id,  
  29. 'notification_type' => $email_type,  
  30. ); 
  31.  
  32. $args = array( 
  33. 'tokens' => array( 
  34. 'activity' => $activity,  
  35. 'usermessage' => wp_strip_all_tags( $content ),  
  36. 'group.name' => $group_name,  
  37. 'mentioned.url' => $message_link,  
  38. 'poster.name' => $poster_name,  
  39. 'receiver-user.id' => $receiver_user_id,  
  40. 'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),  
  41. ),  
  42. ); 
  43.  
  44. bp_send_email( $email_type, $receiver_user_id, $args ); 
  45.  
  46. /** 
  47. * Fires after the sending of an @mention email notification. 
  48. * @since 1.5.0 
  49. * @since 2.5.0 $subject, $message, $content arguments unset and deprecated. 
  50. * @param BP_Activity_Activity $activity Activity Item object. 
  51. * @param string $deprecated Removed in 2.5; now an empty string. 
  52. * @param string $deprecated Removed in 2.5; now an empty string. 
  53. * @param string $deprecated Removed in 2.5; now an empty string. 
  54. * @param int $receiver_user_id The ID of the user who is receiving the update. 
  55. */ 
  56. do_action( 'bp_activity_sent_mention_email', $activity, '', '', '', $receiver_user_id );