bbp_unstick_topic

Unsticks a topic both from front and it's forum.

Description

bbp_unstick_topic( (int) $topic_id = 0 ); 

Parameters (1)

0. $topic_id — Optional. (int)
Topic id

Usage

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

Defined (1)

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

/includes/topics/functions.php  
  1. function bbp_unstick_topic( $topic_id = 0 ) { 
  2. $topic_id = bbp_get_topic_id( $topic_id ); 
  3. $super = bbp_is_topic_super_sticky( $topic_id ); 
  4. $forum_id = empty( $super ) ? bbp_get_topic_forum_id( $topic_id ) : 0; 
  5. $stickies = bbp_get_stickies( $forum_id ); 
  6. $offset = array_search( $topic_id, $stickies ); 
  7.  
  8. do_action( 'bbp_unstick_topic', $topic_id ); 
  9.  
  10. if ( empty( $stickies ) ) { 
  11. $success = true; 
  12. } elseif ( !in_array( $topic_id, $stickies ) ) { 
  13. $success = true; 
  14. } elseif ( false === $offset ) { 
  15. $success = true; 
  16. } else { 
  17. array_splice( $stickies, $offset, 1 ); 
  18. if ( empty( $stickies ) ) { 
  19. $success = !empty( $super ) ? delete_option( '_bbp_super_sticky_topics' ) : delete_post_meta( $forum_id, '_bbp_sticky_topics' ); 
  20. } else { 
  21. $success = !empty( $super ) ? update_option( '_bbp_super_sticky_topics', $stickies ) : update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies ); 
  22.  
  23. do_action( 'bbp_unsticked_topic', $topic_id, $success ); 
  24.  
  25. return (bool) $success;