bbp_remove_topic_from_all_favorites

Remove a deleted topic from all users' favorites.

Description

bbp_remove_topic_from_all_favorites( (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_favorites' ) ) { 
  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_favorites($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_favorites( $topic_id = 0 ) { 
  2. $topic_id = bbp_get_topic_id( $topic_id ); 
  3.  
  4. // Bail if no topic 
  5. if ( empty( $topic_id ) ) 
  6. return; 
  7.  
  8. // Get users 
  9. $users = (array) bbp_get_topic_favoriters( $topic_id ); 
  10.  
  11. // Users exist 
  12. if ( !empty( $users ) ) { 
  13.  
  14. // Loop through users 
  15. foreach ( $users as $user ) { 
  16.  
  17. // Remove each user 
  18. bbp_remove_user_favorite( $user, $topic_id );