bbp_get_single_topic_description

Return a fancy description of the current topic, including total topics, total replies, and last activity.

Description

(string) bbp_get_single_topic_description( (string) $args = '' ); 

Returns (string)

Filtered topic description

Parameters (1)

0. $args — Optional. (string) => ''
This function supports these arguments: - topic_id: Topic id - before: Before the text - after: After the text - size: Size of the avatar

Usage

  1. if ( !function_exists( 'bbp_get_single_topic_description' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/topics/template.php'; 
  3. $args = ''; 
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bbp_get_single_topic_description($args); 
  7.  

Defined (1)

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

/includes/topics/template.php  
  1. function bbp_get_single_topic_description( $args = '' ) { 
  2.  
  3. // Parse arguments against default values 
  4. $r = bbp_parse_args( $args, array( 
  5. 'topic_id' => 0,  
  6. 'before' => '<div class="bbp-template-notice info"><p class="bbp-topic-description">',  
  7. 'after' => '</p></div>',  
  8. 'size' => 14 
  9. ), 'get_single_topic_description' ); 
  10.  
  11. // Validate topic_id 
  12. $topic_id = bbp_get_topic_id( $r['topic_id'] ); 
  13.  
  14. // Unhook the 'view all' query var adder 
  15.  
  16. // Build the topic description 
  17. $vc_int = bbp_get_topic_voice_count ( $topic_id, true ); 
  18. $voice_count = bbp_get_topic_voice_count ( $topic_id, false ); 
  19. $reply_count = bbp_get_topic_replies_link ( $topic_id ); 
  20. $time_since = bbp_get_topic_freshness_link( $topic_id ); 
  21.  
  22. // Singular/Plural 
  23. $voice_count = sprintf( _n( '%s voice', '%s voices', $vc_int, bbpress ), $voice_count ); 
  24.  
  25. // Topic has replies 
  26. $last_reply = bbp_get_topic_last_reply_id( $topic_id ); 
  27. if ( !empty( $last_reply ) ) { 
  28. $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_reply, 'size' => $r['size'] ) ); 
  29. $retstr = sprintf( esc_html__( 'This topic contains %1$s, has %2$s, and was last updated by %3$s %4$s.', bbpress ), $reply_count, $voice_count, $last_updated_by, $time_since ); 
  30.  
  31. // Topic has no replies 
  32. } elseif ( ! empty( $voice_count ) && ! empty( $reply_count ) ) { 
  33. $retstr = sprintf( esc_html__( 'This topic contains %1$s and has %2$s.', bbpress ), $voice_count, $reply_count ); 
  34.  
  35. // Topic has no replies and no voices 
  36. } elseif ( empty( $voice_count ) && empty( $reply_count ) ) { 
  37. $retstr = sprintf( esc_html__( 'This topic has no replies.', bbpress ), $voice_count, $reply_count ); 
  38.  
  39. // Add the 'view all' filter back 
  40.  
  41. // Combine the elements together 
  42. $retstr = $r['before'] . $retstr . $r['after']; 
  43.  
  44. // Return filtered result 
  45. return apply_filters( 'bbp_get_single_topic_description', $retstr, $r );