bbp_stick_topic

Sticks a topic to a forum or front.

Description

bbp_stick_topic( (int) $topic_id = 0, (bool) $super = false ); 

Parameters (2)

0. $topic_id — Optional. (int)
Topic id
1. $super — Optional. (bool) => false
Should we make the topic a super sticky?

Usage

  1. if ( !function_exists( 'bbp_stick_topic' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/topics/functions.php'; 
  3.  
  4. // Optional. Topic id 
  5. $topic_id = -1; 
  6.  
  7. // Should we make the topic a super sticky? 
  8. $super = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_stick_topic($topic_id, $super); 
  12.  

Defined (1)

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

/includes/topics/functions.php  
  1. function bbp_stick_topic( $topic_id = 0, $super = false ) { 
  2. $topic_id = bbp_get_topic_id( $topic_id ); 
  3.  
  4. // Bail if a topic is not a topic (prevents revisions as stickies) 
  5. if ( ! bbp_is_topic( $topic_id ) ) 
  6. return false; 
  7.  
  8. // We may have a super sticky to which we want to convert into a normal 
  9. // sticky and vice versa; unstick the topic first to avoid any possible error. 
  10. bbp_unstick_topic( $topic_id ); 
  11.  
  12. $forum_id = empty( $super ) ? bbp_get_topic_forum_id( $topic_id ) : 0; 
  13. $stickies = bbp_get_stickies( $forum_id ); 
  14.  
  15. do_action( 'bbp_stick_topic', $topic_id, $super ); 
  16.  
  17. if ( !is_array( $stickies ) ) { 
  18. $stickies = array( $topic_id ); 
  19. } else { 
  20. $stickies[] = $topic_id; 
  21.  
  22. // Pull out duplicates and empties 
  23. $stickies = array_unique( array_filter( $stickies ) ); 
  24.  
  25. // Unset incorrectly stuck revisions 
  26. foreach ( (array) $stickies as $key => $id ) { 
  27. if ( ! bbp_is_topic( $id ) ) { 
  28. unset( $stickies[$key] ); 
  29.  
  30. // Reset keys 
  31. $stickies = array_values( $stickies ); 
  32. $success = !empty( $super ) ? update_option( '_bbp_super_sticky_topics', $stickies ) : update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies ); 
  33.  
  34. do_action( 'bbp_sticked_topic', $topic_id, $super, $success ); 
  35.  
  36. return (bool) $success;