bp_activity_truncate_entry( string $text, array $args = array() )
Truncate long activity entries when viewed in activity feeds.
Description
This method can only be used inside the Activity loop.
Parameters
- $text
-
(Required) The original activity entry text.
- $args
-
(Optional) Optional parameters. See $options argument of bp_create_excerpt() for all available parameters. }
Default value: array()
Return
(string) $excerpt The truncated text.
Source
File: bp-activity/bp-activity-filters.php
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | function bp_activity_truncate_entry( $text , $args = array () ) { global $activities_template ; /** * Provides a filter that lets you choose whether to skip this filter on a per-activity basis. * * @since BuddyPress 2.3.0 * * @param bool $value If true, text should be checked to see if it needs truncating. */ $maybe_truncate_text = apply_filters( 'bp_activity_maybe_truncate_entry' , isset( $activities_template ->activity->type ) && ! in_array( $activities_template ->activity->type, array ( 'new_blog_post' , ), true ) ); // The full text of the activity update should always show on the single activity screen. if ( empty ( $args [ 'force_truncate' ] ) && ( ! $maybe_truncate_text || bp_is_single_activity() ) ) { return $text ; } /** * Filters the appended text for the activity excerpt. * * @since BuddyPress 1.5.0 * * @param string $value Internationalized "Read more" text. */ $append_text = apply_filters( 'bp_activity_excerpt_append_text' , __( '[Read more]' , 'buddyboss' ) ); $excerpt_length = bp_activity_get_excerpt_length(); $args = wp_parse_args( $args , array ( 'ending' => __( '…' , 'buddyboss' ) ) ); // Run the text through the excerpt function. If it's too short, the original text will be returned. $excerpt = bp_create_excerpt( $text , $excerpt_length , $args ); /* * If the text returned by bp_create_excerpt() is different from the original text (ie it's * been truncated), add the "Read More" link. Note that bp_create_excerpt() is stripping * shortcodes, so we have strip them from the $text before the comparison. */ if ( strlen ( $excerpt ) < strlen ( strip_shortcodes( $text ) ) ) { $id = ! empty ( $activities_template ->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template ->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id(); $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 ); } /** * Filters the composite activity excerpt entry. * * @since BuddyPress 1.5.0 * * @param string $excerpt Excerpt text and markup to be displayed. * @param string $text The original activity entry text. * @param string $append_text The final append text applied. */ return apply_filters( 'bp_activity_truncate_entry' , $excerpt , $text , $append_text ); } |
Changelog
Version | Description |
---|---|
BuddyPress 2.6.0 Added $args parameter. | BuddyPress 2.6.0 Added $args parameter. |
BuddyPress 1.5.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.