bp_activity_truncate_entry

Truncate long activity entries when viewed in activity streams.

Description

(string) bp_activity_truncate_entry( (string) $text, (array) $args = array() ); 

This method can only be used inside the Activity loop.

Returns (string)

$excerpt The truncated text.

Parameters (2)

0. $text (string)
The original activity entry text.
1. $args — Optional. (array) => array()
The args.

Options

    ;        


    Usage

    1. if ( !function_exists( 'bp_activity_truncate_entry' ) ) { 
    2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-filters.php'; 
    3.  
    4. // The original activity entry text. 
    5. $text = ''; 
    6.  
    7. // The args. 
    8. $args = array(); 
    9.  
    10. // NOTICE! Understand what this does before running. 
    11. $result = bp_activity_truncate_entry($text, $args); 
    12.  

    Defined (1)

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

    /bp-activity/bp-activity-filters.php  
    1. function bp_activity_truncate_entry( $text, $args = array() ) { 
    2. global $activities_template; 
    3.  
    4. /** 
    5. * Provides a filter that lets you choose whether to skip this filter on a per-activity basis. 
    6. * @since 2.3.0 
    7. * @param bool $value If true, text should be checked to see if it needs truncating. 
    8. */ 
    9. $maybe_truncate_text = apply_filters
    10. 'bp_activity_maybe_truncate_entry',  
    11. isset( $activities_template->activity->type ) && ! in_array( $activities_template->activity->type, array( 'new_blog_post', ), true ) 
    12. ); 
    13.  
    14. // The full text of the activity update should always show on the single activity screen. 
    15. if ( empty( $args['force_truncate'] ) && ( ! $maybe_truncate_text || bp_is_single_activity() ) ) { 
    16. return $text; 
    17.  
    18. /** 
    19. * Filters the appended text for the activity excerpt. 
    20. * @since 1.5.0 
    21. * @param string $value Internationalized "Read more" text. 
    22. */ 
    23. $append_text = apply_filters( 'bp_activity_excerpt_append_text', __( '[Read more]', buddypress ) ); 
    24.  
    25. $excerpt_length = bp_activity_get_excerpt_length(); 
    26.  
    27. $args = wp_parse_args( $args, array( 'ending' => __( '…', buddypress ) ) ); 
    28.  
    29. // Run the text through the excerpt function. If it's too short, the original text will be returned. 
    30. $excerpt = bp_create_excerpt( $text, $excerpt_length, $args ); 
    31.  
    32. /** 
    33. * If the text returned by bp_create_excerpt() is different from the original text (ie it's 
    34. * been truncated), add the "Read More" link. Note that bp_create_excerpt() is stripping 
    35. * shortcodes, so we have strip them from the $text before the comparison. 
    36. */ 
    37. if ( strlen( $excerpt ) < strlen( strip_shortcodes( $text ) ) ) { 
    38. $id = !empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id(); 
    39.  
    40. $excerpt = sprintf( '%1$s<span class="activity-read-more" id="%2$s"><a href="%3$s" rel="nofollow">%4$s</a></span>', $excerpt, $id, bp_get_activity_thread_permalink(), $append_text ); 
    41.  
    42. /** 
    43. * Filters the composite activity excerpt entry. 
    44. * @since 1.5.0 
    45. * @param string $excerpt Excerpt text and markup to be displayed. 
    46. * @param string $text The original activity entry text. 
    47. * @param string $append_text The final append text applied. 
    48. */ 
    49. return apply_filters( 'bp_activity_truncate_entry', $excerpt, $text, $append_text );