bb_delete_forum

The BuddyPress bb delete forum function.

Description

bb_delete_forum( $forum_id ); 

Parameters (1)

0. $forum_id
The forum id.

Usage

  1. if ( !function_exists( 'bb_delete_forum' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-admin/includes/functions.bb-admin.php'; 
  3.  
  4. // The forum id. 
  5. $forum_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bb_delete_forum($forum_id); 
  9.  

Defined (1)

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

/bp-forums/bbpress/bb-admin/includes/functions.bb-admin.php  
  1. function bb_delete_forum( $forum_id ) { 
  2. global $bbdb; 
  3. if ( !bb_current_user_can( 'delete_forum', $forum_id ) ) 
  4. return false; 
  5. if ( !$forum_id = (int) $forum_id ) 
  6. return false; 
  7.  
  8. if ( !$forum = bb_get_forum( $forum_id ) ) 
  9. return false; 
  10.  
  11. if ( $topic_ids = $bbdb->get_col( $bbdb->prepare( "SELECT topic_id FROM $bbdb->topics WHERE forum_id = %d", $forum_id ) ) ) { 
  12. foreach ($topic_ids as $topic_id) { 
  13. bb_remove_topic_tags( $topic_id ); 
  14. $_topic_ids = join(', ', array_map('intval', $topic_ids)); 
  15. $bbdb->query("DELETE FROM $bbdb->posts WHERE topic_id IN ($_topic_ids) AND topic_id != 0"); 
  16. $bbdb->query("DELETE FROM $bbdb->meta WHERE object_type = 'bb_topic' AND object_id IN ($_topic_ids)"); 
  17. $bbdb->query( $bbdb->prepare( "DELETE FROM $bbdb->topics WHERE forum_id = %d", $forum_id ) ); 
  18.  
  19. $bbdb->update( $bbdb->forums, array( 'forum_parent' => $forum->forum_parent ), array( 'forum_parent' => $forum_id ) ); 
  20.  
  21. $return = $bbdb->query( $bbdb->prepare( "DELETE FROM $bbdb->forums WHERE forum_id = %d", $forum_id ) ); 
  22.  
  23. wp_cache_flush( 'bb_post' ); 
  24.  
  25. if ( $topic_ids ) 
  26. foreach ( $topic_ids as $topic_id ) { 
  27. // should maybe just flush these groups instead 
  28. wp_cache_delete( $topic_id, 'bb_topic' ); 
  29. wp_cache_delete( $topic_id, 'bb_thread' ); 
  30.  
  31. wp_cache_delete( $forum_id, 'bb_forum' ); 
  32.  
  33. return $return;