bbp_close_topic

Closes a topic.

Description

bbp_close_topic( (int) $topic_id = 0 ); 

Parameters (1)

0. $topic_id — Optional. (int)
The topic id.

Usage

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

Defined (1)

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

/includes/topics/functions.php  
  1. function bbp_close_topic( $topic_id = 0 ) { 
  2.  
  3. // Get topic 
  4. $topic = bbp_get_topic( $topic_id ); 
  5. if ( empty( $topic ) ) 
  6. return $topic; 
  7.  
  8. // Bail if already closed 
  9. if ( bbp_get_closed_status_id() === $topic->post_status ) 
  10. return false; 
  11.  
  12. // Execute pre close code 
  13. do_action( 'bbp_close_topic', $topic_id ); 
  14.  
  15. // Add pre close status 
  16. add_post_meta( $topic_id, '_bbp_status', $topic->post_status ); 
  17.  
  18. // Set closed status 
  19. $topic->post_status = bbp_get_closed_status_id(); 
  20.  
  21. // No revisions 
  22. remove_action( 'pre_post_update', 'wp_save_post_revision' ); 
  23.  
  24. // Update topic 
  25. $topic_id = wp_update_post( $topic ); 
  26.  
  27. // Execute post close code 
  28. do_action( 'bbp_closed_topic', $topic_id ); 
  29.  
  30. // Return topic_id 
  31. return $topic_id;