bbp_open_topic

Opens a topic.

Description

bbp_open_topic( (int) $topic_id = 0 ); 

Parameters (1)

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

Usage

  1. if ( !function_exists( 'bbp_open_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_open_topic($topic_id); 
  9.  

Defined (1)

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

/includes/topics/functions.php  
  1. function bbp_open_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 open 
  9. if ( bbp_get_closed_status_id() !== $topic->post_status ) 
  10. return false; 
  11.  
  12. // Execute pre open code 
  13. do_action( 'bbp_open_topic', $topic_id ); 
  14.  
  15. // Get previous status 
  16. $topic_status = get_post_meta( $topic_id, '_bbp_status', true ); 
  17.  
  18. // Set previous status 
  19. $topic->post_status = $topic_status; 
  20.  
  21. // Remove old status meta 
  22. delete_post_meta( $topic_id, '_bbp_status' ); 
  23.  
  24. // No revisions 
  25. remove_action( 'pre_post_update', 'wp_save_post_revision' ); 
  26.  
  27. // Update topic 
  28. $topic_id = wp_update_post( $topic ); 
  29.  
  30. // Execute post open code 
  31. do_action( 'bbp_opened_topic', $topic_id ); 
  32.  
  33. // Return topic_id 
  34. return $topic_id;