bp_activity_new_comment_notification

Send email and BP notifications when an activity item receives a comment.

Description

bp_activity_new_comment_notification( (int) $comment_id = 0, (int) $commenter_id = 0, (array) $params = array() ); 

Parameters (3)

0. $comment_id — Optional. (int)
The comment id.
1. $commenter_id — Optional. (int)
The ID of the user who posted the comment.
2. $params — Optional. (array) => array()
The params.

Options

  • (bp_activity_new_comment()}.) => null
array(
    '' => null
);        


Usage

  1. if ( !function_exists( 'bp_activity_new_comment_notification' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3.  
  4. // The comment id. 
  5. $comment_id = -1; 
  6.  
  7. // The ID of the user who posted the comment. 
  8. $commenter_id = -1; 
  9.  
  10. // The params. 
  11. $params = array( 
  12. '' => null 
  13. ); 
  14.  
  15. // NOTICE! Understand what this does before running. 
  16. $result = bp_activity_new_comment_notification($comment_id, $commenter_id, $params); 
  17.  

Defined (1)

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

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 0, $params = array() ) { 
  2. $original_activity = new BP_Activity_Activity( $params['activity_id'] ); 
  3. $poster_name = bp_core_get_user_displayname( $commenter_id ); 
  4. $thread_link = bp_activity_get_permalink( $params['activity_id'] ); 
  5.  
  6.  
  7. /** This filter is documented in bp-activity/bp-activity-template.php */ 
  8. $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $params['content'], &$original_activity ) ); 
  9.  
  10. add_filter( 'bp_get_activity_content_body', 'convert_smilies' ); 
  11.  
  12. if ( $original_activity->user_id != $commenter_id ) { 
  13.  
  14. // Send an email if the user hasn't opted-out. 
  15. if ( 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) { 
  16.  
  17. $unsubscribe_args = array( 
  18. 'user_id' => $original_activity->user_id,  
  19. 'notification_type' => 'activity-comment',  
  20. ); 
  21.  
  22. $args = array( 
  23. 'tokens' => array( 
  24. 'comment.id' => $comment_id,  
  25. 'commenter.id' => $commenter_id,  
  26. 'usermessage' => wp_strip_all_tags( $content ),  
  27. 'original_activity.user_id' => $original_activity->user_id,  
  28. 'poster.name' => $poster_name,  
  29. 'thread.url' => esc_url( $thread_link ),  
  30. 'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),  
  31. ),  
  32. ); 
  33.  
  34. bp_send_email( 'activity-comment', $original_activity->user_id, $args ); 
  35.  
  36. /** 
  37. * Fires at the point that notifications should be sent for activity comments. 
  38. * @since 2.6.0 
  39. * @param BP_Activity_Activity $original_activity The original activity. 
  40. * @param int $comment_id ID for the newly received comment. 
  41. * @param int $commenter_id ID of the user who made the comment. 
  42. * @param array $params Arguments used with the original activity comment. 
  43. */ 
  44. do_action( 'bp_activity_sent_reply_to_update_notification', $original_activity, $comment_id, $commenter_id, $params ); 
  45.  
  46.  
  47. /** 
  48. * If this is a reply to another comment, send an email notification to the 
  49. * author of the immediate parent comment. 
  50. */ 
  51. if ( empty( $params['parent_id'] ) || ( $params['activity_id'] == $params['parent_id'] ) ) { 
  52. return; 
  53.  
  54. $parent_comment = new BP_Activity_Activity( $params['parent_id'] ); 
  55.  
  56. if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id ) { 
  57.  
  58. // Send an email if the user hasn't opted-out. 
  59. if ( 'no' != bp_get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) { 
  60.  
  61. $unsubscribe_args = array( 
  62. 'user_id' => $parent_comment->user_id,  
  63. 'notification_type' => 'activity-comment-author',  
  64. ); 
  65.  
  66. $args = array( 
  67. 'tokens' => array( 
  68. 'comment.id' => $comment_id,  
  69. 'commenter.id' => $commenter_id,  
  70. 'usermessage' => wp_strip_all_tags( $content ),  
  71. 'parent-comment-user.id' => $parent_comment->user_id,  
  72. 'poster.name' => $poster_name,  
  73. 'thread.url' => esc_url( $thread_link ),  
  74. 'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),  
  75. ),  
  76. ); 
  77.  
  78. bp_send_email( 'activity-comment-author', $parent_comment->user_id, $args ); 
  79.  
  80. /** 
  81. * Fires at the point that notifications should be sent for comments on activity replies. 
  82. * @since 2.6.0 
  83. * @param BP_Activity_Activity $parent_comment The parent activity. 
  84. * @param int $comment_id ID for the newly received comment. 
  85. * @param int $commenter_id ID of the user who made the comment. 
  86. * @param array $params Arguments used with the original activity comment. 
  87. */ 
  88. do_action( 'bp_activity_sent_reply_to_reply_notification', $parent_comment, $comment_id, $commenter_id, $params );