notify_new_topic

The bbPress Notify notify new topic function.

Description

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

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( 'notify_new_topic' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress-notify/bbpress-notify.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 = notify_new_topic($topic_id, $forum_id, $anonymous_data, $topic_author); 
  18.  

Defined (1)

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

/bbpress-notify.php  
  1. function notify_new_topic($topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0) 
  2. global $wpdb; 
  3. $opt_recipients = get_option('bbpress_notify_newtopic_recipients'); 
  4. $recipients = array(); 
  5. foreach ($opt_recipients as $opt_recipient) 
  6. switch($opt_recipient) 
  7. case 'blogadmin': 
  8. $recipients[] = -1; 
  9. break; 
  10.  
  11. case 'admins': 
  12. $users = get_users(array('role' => 'administrator', 'orderby' => 'login', 'fields' => 'all')); 
  13. foreach ($users as $user) 
  14. $user = get_object_vars($user); 
  15. $recipients[] = $user['ID']; 
  16. break; 
  17.  
  18. case 'editors': 
  19. $users = get_users(array('role' => 'editor', 'orderby' => 'login', 'fields' => 'all')); 
  20. foreach ($users as $user) 
  21. $user = get_object_vars($user); 
  22. $recipients[] = $user['ID']; 
  23. break; 
  24.  
  25. case 'authors': 
  26. $users = get_users(array('role' => 'author', 'orderby' => 'login', 'fields' => 'all')); 
  27. foreach ($users as $user) 
  28. $user = get_object_vars($user); 
  29. $recipients[] = $user['ID']; 
  30. break; 
  31.  
  32. case 'contributors': 
  33. $users = get_users(array('role' => 'contributor', 'orderby' => 'login', 'fields' => 'all')); 
  34. foreach ($users as $user) 
  35. $user = get_object_vars($user); 
  36. $recipients[] = $user['ID']; 
  37. break; 
  38.  
  39. case 'subscribers': 
  40. $users = get_users(array('role' => 'subscriber', 'orderby' => 'login', 'fields' => 'all')); 
  41. foreach ($users as $user) 
  42. $user = get_object_vars($user); 
  43. $recipients[] = $user['ID']; 
  44. break; 
  45.  
  46. case 'all': 
  47. $users = get_users(array('orderby' => 'login', 'fields' => 'all')); 
  48. foreach ($users as $user) 
  49. $user = get_object_vars($user); 
  50. $recipients[] = $user['ID']; 
  51. break; 
  52.  
  53. case 'none': 
  54. break; 
  55. $email_subject = get_option('bbpress_notify_newtopic_email_subject'); 
  56. $email_body = get_option('bbpress_notify_newtopic_email_body'); 
  57.  
  58. // Replace shortcodes 
  59. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 
  60. $topic_title = html_entity_decode(strip_tags(bbp_get_topic_title($topic_id)), ENT_NOQUOTES, 'UTF-8'); 
  61. $topic_content = html_entity_decode(strip_tags(bbp_get_topic_content($topic_id)), ENT_NOQUOTES, 'UTF-8'); 
  62. $topic_excerpt = html_entity_decode(strip_tags(bbp_get_topic_excerpt($topic_id, 100)), ENT_NOQUOTES, 'UTF-8'); 
  63. $topic_author = bbp_get_topic_author($topic_id); 
  64. $topic_url = bbp_get_topic_permalink($topic_id); 
  65. $topic_reply = bbp_get_reply_url($topic_id); 
  66.  
  67. $email_subject = str_replace('[blogname]', $blogname, $email_subject); 
  68. $email_subject = str_replace('[topic-title]', $topic_title, $email_subject); 
  69. $email_subject = str_replace('[topic-content]', $topic_content, $email_subject); 
  70. $email_subject = str_replace('[topic-excerpt]', $topic_excerpt, $email_subject); 
  71. $email_subject = str_replace('[topic-author]', $topic_author, $email_subject); 
  72. $email_subject = str_replace('[topic-url]', $topic_url, $email_subject); 
  73. $email_subject = str_replace('[topic-replyurl]', $topic_reply, $email_subject); 
  74.  
  75. $email_body = str_replace('[blogname]', $blogname, $email_body); 
  76. $email_body = str_replace('[topic-title]', $topic_title, $email_body); 
  77. $email_body = str_replace('[topic-content]', $topic_content, $email_body); 
  78. $email_body = str_replace('[topic-excerpt]', $topic_excerpt, $email_body); 
  79. $email_body = str_replace('[topic-author]', $topic_author, $email_body); 
  80. $email_body = str_replace('[topic-url]', $topic_url, $email_body); 
  81. $email_body = str_replace('[topic-replyurl]', $topic_reply, $email_body); 
  82.  
  83. send_notification($recipients, $email_subject, $email_body);