Skip to:
Content

BuddyPress.org

Changeset 10832


Ignore:
Timestamp:
05/31/2016 06:49:07 AM (4 years ago)
Author:
r-a-y
Message:

Activity: Improve bp_activity_truncate_entry().

  • Added $args parameter, which uses the same arguments as `bp_create_excerpt() (see r10830)
  • Better excerpt length truncation by checking string length.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-filters.php

    r10825 r10832  
    388388 *
    389389 * @since 1.5.0
     390 * @since 2.6.0 Added $args parameter.
    390391 *
    391392 * @param string $text The original activity entry text.
     393 * @param array  $args {
     394 *     Optional parameters. See $options argument of {@link bp_create_excerpt()}
     395 *     for all available parameters.
     396 * }
    392397 * @return string $excerpt The truncated text.
    393398 */
    394 function bp_activity_truncate_entry( $text ) {
     399function bp_activity_truncate_entry( $text, $args = array() ) {
    395400    global $activities_template;
    396401
     
    408413
    409414    // The full text of the activity update should always show on the single activity screen.
    410     if ( ! $maybe_truncate_text || bp_is_single_activity() ) {
     415    if ( empty( $args['force_truncate'] ) && ( ! $maybe_truncate_text || bp_is_single_activity() ) ) {
    411416        return $text;
    412417    }
     
    430435    $excerpt_length = apply_filters( 'bp_activity_excerpt_length', 358 );
    431436
     437    $args = wp_parse_args( $args, array( 'ending' => __( '…', 'buddypress' ) ) );
     438
    432439    // Run the text through the excerpt function. If it's too short, the original text will be returned.
    433     $excerpt        = bp_create_excerpt( $text, $excerpt_length, array( 'ending' => __( '…', 'buddypress' ) ) );
     440    $excerpt        = bp_create_excerpt( $text, $excerpt_length, $args );
    434441
    435442    /*
     
    438445     * shortcodes, so we have strip them from the $text before the comparison.
    439446     */
    440     if ( $excerpt != strip_shortcodes( $text ) ) {
     447    if ( strlen( $excerpt ) > strlen( strip_shortcodes( $text ) ) ) {
    441448        $id = !empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id();
    442449
Note: See TracChangeset for help on using the changeset viewer.