bbp_buddypress_add_notification

Hooked into the new reply function, this notification action is responsible for notifying topic and hierarchical reply authors of topic replies.

Description

bbp_buddypress_add_notification( (int) $reply_id = 0, (int) $topic_id = 0, (int) $forum_id = 0, (constant) $anonymous_data = false, (int) $author_id = 0, (constant) $is_edit = false, (int) $reply_to = 0 ); 

Parameters (7)

0. $reply_id — Optional. (int)
The reply id.
1. $topic_id — Optional. (int)
The topic id.
2. $forum_id — Optional. (int)
The forum id.
3. $anonymous_data — Optional. (constant) => false
The anonymous data.
4. $author_id — Optional. (int)
The author id.
5. $is_edit — Optional. (constant) => false
Used to bail if this gets hooked to an edit action
6. $reply_to — Optional. (int)
The reply to.

Usage

  1. if ( !function_exists( 'bbp_buddypress_add_notification' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/extend/buddypress/notifications.php'; 
  3.  
  4. // The reply id. 
  5. $reply_id = -1; 
  6.  
  7. // The topic id. 
  8. $topic_id = -1; 
  9.  
  10. // The forum id. 
  11. $forum_id = -1; 
  12.  
  13. // The anonymous data. 
  14. $anonymous_data = false; 
  15.  
  16. // The author id. 
  17. $author_id = -1; 
  18.  
  19. // Used to bail if this gets hooked to an edit action 
  20. $is_edit = false; 
  21.  
  22. // The reply to. 
  23. $reply_to = -1; 
  24.  
  25. // NOTICE! Understand what this does before running. 
  26. $result = bbp_buddypress_add_notification($reply_id, $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit, $reply_to); 
  27.  

Defined (1)

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

/includes/extend/buddypress/notifications.php  
  1. function bbp_buddypress_add_notification( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0 ) { 
  2.  
  3. // Bail if somehow this is hooked to an edit action 
  4. if ( !empty( $is_edit ) ) { 
  5. return; 
  6.  
  7. // Get autohr information 
  8. $topic_author_id = bbp_get_topic_author_id( $topic_id ); 
  9. $secondary_item_id = $author_id; 
  10.  
  11. // Hierarchical replies 
  12. if ( !empty( $reply_to ) ) { 
  13. $reply_to_item_id = bbp_get_topic_author_id( $reply_to ); 
  14.  
  15. // Get some reply information 
  16. $args = array( 
  17. 'user_id' => $topic_author_id,  
  18. 'item_id' => $topic_id,  
  19. 'component_name' => bbp_get_component_name(),  
  20. 'component_action' => 'bbp_new_reply',  
  21. 'date_notified' => get_post( $reply_id )->post_date,  
  22. ); 
  23.  
  24. // Notify the topic author if not the current reply author 
  25. if ( $author_id !== $topic_author_id ) { 
  26. $args['secondary_item_id'] = $secondary_item_id ; 
  27.  
  28. bp_notifications_add_notification( $args ); 
  29.  
  30. // Notify the immediate reply author if not the current reply author 
  31. if ( !empty( $reply_to ) && ( $author_id !== $reply_to_item_id ) ) { 
  32. $args['secondary_item_id'] = $reply_to_item_id ; 
  33.  
  34. bp_notifications_add_notification( $args );