buddyboss_global_search_reply_intro

Returns a trimmed reply content string.

Description

buddyboss_global_search_reply_intro( (int) $character_limit = 50 ); 

Works for replies as well as topics. Must be used while inside the loop

Parameters (1)

0. $character_limit — Optional. (int) => 50
The character limit.

Usage

  1. if ( !function_exists( 'buddyboss_global_search_reply_intro' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-global-search/includes/functions.php'; 
  3.  
  4. // The character limit. 
  5. $character_limit = 50; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = buddyboss_global_search_reply_intro($character_limit); 
  9.  

Defined (1)

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

/includes/functions.php  
  1. function buddyboss_global_search_reply_intro( $character_limit=50 ) { 
  2. $content = ''; 
  3.  
  4. switch( get_post_type( get_the_ID() ) ) { 
  5. case 'topic': 
  6. $reply_content = bbp_get_topic_content(get_the_ID()); 
  7. break; 
  8. case 'reply': 
  9. $reply_content = bbp_get_reply_content(get_the_ID()); 
  10. break; 
  11. default: 
  12. $reply_content = get_the_content(); 
  13. break; 
  14.  
  15. if( $reply_content ) { 
  16. $content = wp_strip_all_tags( $reply_content, true ); 
  17. $search_term = buddyboss_global_search()->search->get_search_term(); 
  18.  
  19. $search_term_position = stripos( $content, $search_term ); 
  20. if( $search_term_position !== false ) { 
  21. $shortened_content = buddyboss_global_search_result_match( $content, $search_term ); 
  22.  
  23. //highlight search keyword 
  24.  
  25. $shortened_content = str_ireplace( $search_term, "<strong>" . $search_term . "</strong>", $shortened_content ); 
  26. } else { 
  27. $shortened_content = substr( $content, 0, $character_limit ); 
  28.  
  29. if( strlen($content)> $character_limit ) 
  30. $shortened_content .= '...'; 
  31.  
  32. $content = $shortened_content; 
  33.  
  34. return apply_filters( 'buddyboss_global_search_reply_intro', $content );