bb_subscription_management

Updates user's subscription status in database.

Description

bb_subscription_management( (int) $topic_id, (string) $new_status, (string) $user_id = '' ); 

Gets user's new subscription status for topic and adds new status to database.

Parameters (3)

0. $topic_id (int)
ID of topic for subscription
1. $new_status (string)
New subscription status
2. $user_id — Optional. (string) => ''
ID of user for subscription

Usage

  1. if ( !function_exists( 'bb_subscription_management' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-posts.php'; 
  3.  
  4. // ID of topic for subscription 
  5. $topic_id = -1; 
  6.  
  7. // New subscription status 
  8. $new_status = ''; 
  9.  
  10. // Optional. ID of user for subscription 
  11. $user_id = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bb_subscription_management($topic_id, $new_status, $user_id); 
  15.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-posts.php  
  1. function bb_subscription_management( $topic_id, $new_status, $user_id = '' ) { 
  2. global $bbdb, $wp_taxonomy_object; 
  3.  
  4. $topic = get_topic( $topic_id ); 
  5. if (!$user_id) { 
  6. $user_id = bb_get_current_user_info( 'id' ); 
  7.  
  8. do_action( 'bb_subscripton_management', $topic_id, $new_status, $user_id ); 
  9.  
  10. switch ( $new_status ) { 
  11. case 'add': 
  12. $tt_ids = $wp_taxonomy_object->set_object_terms( $user_id, 'topic-' . $topic->topic_id, 'bb_subscribe', array( 'append' => true, 'user_id' => $user_id ) ); 
  13. break; 
  14. case 'remove': 
  15. // I hate this with the passion of a thousand suns 
  16. $term_id = $bbdb->get_var( "SELECT term_id FROM $bbdb->terms WHERE slug = 'topic-$topic->topic_id'" ); 
  17. $term_taxonomy_id = $bbdb->get_var( "SELECT term_taxonomy_id FROM $bbdb->term_taxonomy WHERE term_id = $term_id AND taxonomy = 'bb_subscribe'" ); 
  18. $bbdb->query( "DELETE FROM $bbdb->term_relationships WHERE object_id = $user_id AND term_taxonomy_id = $term_taxonomy_id" ); 
  19. $bbdb->query( "DELETE FROM $bbdb->term_taxonomy WHERE term_id = $term_id AND taxonomy = 'bb_subscribe'" ); 
  20. break; 
  21.