bb_notify_subscribers

Sends notification emails for new posts.

Description

bb_notify_subscribers( (int) $post_id ); 

Gets new post's ID and check if there are subscribed user to that topic, and if there are, send notifications

Parameters (1)

0. $post_id (int)
ID of new post

Usage

  1. if ( !function_exists( 'bb_notify_subscribers' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-posts.php'; 
  3.  
  4. // ID of new post 
  5. $post_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bb_notify_subscribers($post_id); 
  9.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-posts.php  
  1. function bb_notify_subscribers( $post_id ) { 
  2. global $bbdb; 
  3.  
  4. if ( !$post = bb_get_post( $post_id ) ) 
  5. return false; 
  6.  
  7. // bozo or spam 
  8. if ( 2 == $post->post_status ) 
  9. return false; 
  10.  
  11. if ( !$topic = get_topic( $post->topic_id ) ) 
  12. return false; 
  13.  
  14. $post_id = $post->post_id; 
  15. $topic_id = $topic->topic_id; 
  16.  
  17. if ( !$poster_name = get_post_author( $post_id ) ) 
  18. return false; 
  19.  
  20. do_action( 'bb_pre_notify_subscribers', $post_id, $topic_id ); 
  21.  
  22. if ( !$user_ids = $bbdb->get_col( $bbdb->prepare( "SELECT `$bbdb->term_relationships`.`object_id` 
  23. FROM $bbdb->term_relationships, $bbdb->term_taxonomy, $bbdb->terms 
  24. WHERE `$bbdb->term_relationships`.`term_taxonomy_id` = `$bbdb->term_taxonomy`.`term_taxonomy_id` 
  25. AND `$bbdb->term_taxonomy`.`term_id` = `$bbdb->terms`.`term_id` 
  26. AND `$bbdb->term_taxonomy`.`taxonomy` = 'bb_subscribe' 
  27. AND `$bbdb->terms`.`slug` = 'topic-%d'",  
  28. $topic_id ) ) ) 
  29. return false; 
  30.  
  31. foreach ( (array) $user_ids as $user_id ) { 
  32. if ( $user_id == $post->poster_id ) 
  33. continue; // don't send notifications to the person who made the post 
  34.  
  35. $user = bb_get_user( $user_id ); 
  36.  
  37. if ( !$message = apply_filters( 'bb_subscription_mail_message', __( "%1\$s wrote:\n\n%2\$s\n\nRead this post on the forums: %3\$s\n\nYou're getting this email because you subscribed to '%4\$s.'\nPlease click the link above, login, and click 'Unsubscribe' at the top of the page to stop receiving emails from this topic." ), $post_id, $topic_id ) ) 
  38. continue; /** For plugins */ 
  39.  
  40. $user->user_email,  
  41. apply_filters( 'bb_subscription_mail_title', '[' . bb_get_option( 'name' ) . '] ' . $topic->topic_title, $post_id, $topic_id ),  
  42. sprintf( $message, $poster_name, strip_tags( $post->post_text ), get_post_link( $post_id ), strip_tags( $topic->topic_title ) ) 
  43. ); 
  44.  
  45. do_action( 'bb_post_notify_subscribers', $post_id, $topic_id );