bpbbpst_notify_moderators

Sends a notification to bbPress moderators and eventually BP Groups one.

Description

(boolean) bpbbpst_notify_moderators( (int) $topic_id = 0, (int) $forum_id = 0, (constant) $anonymous_data = false, (int) $topic_author = 0 ); 

Inpired by : bbPress bbp_notify_subscribers() function

Returns (boolean)

true

Parameters (4)

0. $topic_id — Optional. (int)
The topic id.
1. $forum_id — Optional. (int)
The forum id.
2. $anonymous_data — Optional. (constant) => false
The anonymous data.
3. $topic_author — Optional. (int)
The topic author.

Usage

  1. if ( !function_exists( 'bpbbpst_notify_moderators' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddy-bbpress-support-topic/includes/functions.php'; 
  3.  
  4. // The topic id. 
  5. $topic_id = -1; 
  6.  
  7. // The forum id. 
  8. $forum_id = -1; 
  9.  
  10. // The anonymous data. 
  11. $anonymous_data = false; 
  12.  
  13. // The topic author. 
  14. $topic_author = -1; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = bpbbpst_notify_moderators($topic_id, $forum_id, $anonymous_data, $topic_author); 
  18.  

Defined (1)

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

/includes/functions.php  
  1. function bpbbpst_notify_moderators( $topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0 ) { 
  2.  
  3. /** Validation ************************************************************/ 
  4. $topic_id = bbp_get_topic_id( $topic_id ); 
  5. $forum_id = bbp_get_forum_id( $forum_id ); 
  6.  
  7. $recipients = bpbbpst_list_recipients( $forum_id, 'notify' ); 
  8.  
  9. if ( empty( $recipients ) || ! is_array( $recipients ) || count( $recipients ) < 1 ) { 
  10. return; 
  11.  
  12. /** Topic *****************************************************************/ 
  13.  
  14. // Bail if topic is not published 
  15. if ( ! bbp_is_topic_published( $topic_id ) ) { 
  16. return false; 
  17.  
  18. // Poster name 
  19. $topic_author_name = bbp_get_topic_author_display_name( $topic_id ); 
  20.  
  21. // Remove filters from reply content and topic title to prevent content 
  22. // from being encoded with HTML entities, wrapped in paragraph tags, etc... 
  23. remove_all_filters( 'bbp_get_topic_content' ); 
  24. remove_all_filters( 'bbp_get_topic_title' ); 
  25.  
  26. // Strip tags from text 
  27. $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) ); 
  28. $topic_content = strip_tags( bbp_get_topic_content( $topic_id ) ); 
  29. $topic_url = bbp_get_topic_permalink( $topic_id ); 
  30. $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 
  31. $forum_name = wp_specialchars_decode( bbp_get_forum_title( $forum_id ), ENT_QUOTES ); 
  32.  
  33. // Loop through users 
  34. foreach ( (array) $recipients as $user_id ) { 
  35.  
  36. /** Don't send notifications to the moderator if he is the one who made the post */ 
  37. if ( ! empty( $topic_author ) && (int) $user_id == (int) $topic_author ) { 
  38. continue; 
  39.  
  40. // For plugins to filter messages per reply/topic/user 
  41. $message = sprintf( __( '%1$s wrote a new support topic: %2$s 
  42.  
  43. %3$s 
  44.  
  45. Topic Link: %4$s 
  46.  
  47. ----------- 
  48.  
  49. You are receiving this email because a forum admin made you subscribe to new support topic of %5$s forum. 
  50.  
  51. Please ask the admin to unsubscribe from these emails.', 'buddy-bbpress-support-topic' ),  
  52.  
  53. $topic_author_name,  
  54. $topic_title,  
  55. $topic_content,  
  56. $topic_url,  
  57. $forum_name 
  58. ); 
  59.  
  60. $message = apply_filters( 'bpbbpst_notify_moderators_mail_message', $message, $topic_id, $forum_id, $user_id ); 
  61.  
  62. if ( empty( $message ) ) { 
  63. continue; 
  64.  
  65. // For plugins to filter titles per reply/topic/user 
  66. $subject = apply_filters( 'bpbbpst_notify_moderators_mail_title', '[' . $blog_name . '] New support topic on : ' . $forum_name, $topic_id, $forum_id, $user_id ); 
  67.  
  68. if ( empty( $subject ) ) { 
  69. continue; 
  70.  
  71. // Custom headers 
  72. $headers = apply_filters( 'bpbbpst_notify_moderators_mail_headers', array() ); 
  73.  
  74. // Get user data of this user 
  75. $user = get_userdata( $user_id ); 
  76.  
  77. // Send notification email 
  78. wp_mail( $user->user_email, $subject, $message, $headers ); 
  79.  
  80. do_action( 'bpbbpst_notify_moderators', $topic_id, $forum_id, $recipients ); 
  81.  
  82. return true;