bbp_remove_topic_from_all_subscriptions

Remove a deleted topic from all users' subscriptions.

Description

bbp_remove_topic_from_all_subscriptions( (int) $topic_id = 0 ); 

Parameters (1)

0. $topic_id — Optional. (int)
Get the topic id to remove

Usage

  1. if ( !function_exists( 'bbp_remove_topic_from_all_subscriptions' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/topics/functions.php'; 
  3.  
  4. // Get the topic id to remove 
  5. $topic_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_remove_topic_from_all_subscriptions($topic_id); 
  9.  

Defined (1)

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

/includes/topics/functions.php  
  1. function bbp_remove_topic_from_all_subscriptions( $topic_id = 0 ) { 
  2.  
  3. // Subscriptions are not active 
  4. if ( !bbp_is_subscriptions_active() ) 
  5. return; 
  6.  
  7. $topic_id = bbp_get_topic_id( $topic_id ); 
  8.  
  9. // Bail if no topic 
  10. if ( empty( $topic_id ) ) 
  11. return; 
  12.  
  13. // Get users 
  14. $users = (array) bbp_get_topic_subscribers( $topic_id ); 
  15.  
  16. // Users exist 
  17. if ( !empty( $users ) ) { 
  18.  
  19. // Loop through users 
  20. foreach ( $users as $user ) { 
  21.  
  22. // Remove each user 
  23. bbp_remove_user_subscription( $user, $topic_id );