bb_move_forum_topics

Topics.

Description

bb_move_forum_topics( $from_forum_id, $to_forum_id ); 

Parameters (2)

0. $from_forum_id
The from forum id.
1. $to_forum_id
The to forum id.

Usage

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

Defined (1)

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

/bp-forums/bbpress/bb-admin/includes/functions.bb-admin.php  
  1. function bb_move_forum_topics( $from_forum_id, $to_forum_id ) { 
  2. global $bbdb; 
  3.  
  4. $from_forum_id = (int) $from_forum_id ; 
  5. $to_forum_id = (int) $to_forum_id; 
  6.  
  7. add_filter('get_forum_where', 'bb_no_where'); // Just in case 
  8.  
  9. $from_forum = bb_get_forum( $from_forum_id ); 
  10. if ( !$to_forum = bb_get_forum( $to_forum_id ) ) 
  11. return false; 
  12.  
  13. $posts = $to_forum->posts + ( $from_forum ? $from_forum->posts : 0 ); 
  14. $topics = $to_forum->topics + ( $from_forum ? $from_forum->topics : 0 ); 
  15.  
  16. $bbdb->update( $bbdb->forums, compact( 'topics', 'posts' ), array( 'forum_id' => $to_forum_id ) ); 
  17. $bbdb->update( $bbdb->forums, array( 'topics' => 0, 'posts' => 0 ), array( 'forum_id' => $from_forum_id ) ); 
  18. $bbdb->update( $bbdb->posts, array( 'forum_id' => $to_forum_id ), array( 'forum_id' => $from_forum_id ) ); 
  19. $topic_ids = $bbdb->get_col( $bbdb->prepare( "SELECT topic_id FROM $bbdb->topics WHERE forum_id = %d", $from_forum_id ) ); 
  20. $return = $bbdb->update( $bbdb->topics, array( 'forum_id' => $to_forum_id ), array( 'forum_id' => $from_forum_id ) ); 
  21.  
  22. wp_cache_flush( 'bb_post' ); 
  23.  
  24. if ( $topic_ids ) 
  25. foreach ( $topic_ids as $topic_id ) { 
  26. // should maybe just flush these groups 
  27. wp_cache_delete( $topic_id, 'bb_topic' ); 
  28. wp_cache_delete( $topic_id, 'bb_thread' ); 
  29.  
  30. wp_cache_delete( $from_forum_id, 'bb_forum' ); 
  31. wp_cache_delete( $to_forum_id, 'bb_forum' ); 
  32.  
  33. return $return;