/** * Return the activity latest update link. * * @since 1.2.0 * * * @param int $user_id If empty, will fall back on displayed user. * @return string|bool $latest_update The activity latest update link. * False on failure. */ function bp_get_activity_latest_update($user_id = 0) { if (empty($user_id)) { $user_id = bp_displayed_user_id(); } if (bp_is_user_inactive($user_id)) { return false; } if (!($update = bp_get_user_meta($user_id, 'bp_latest_update', true))) { return false; } /** * Filters the latest update excerpt. * * @since 1.2.10 * @since 2.6.0 Added the `$user_id` parameter. * * @param string $value The excerpt for the latest update. * @param int $user_id ID of the queried user. */ $latest_update = apply_filters('bp_get_activity_latest_update_excerpt', trim(strip_tags(bp_create_excerpt($update['content'], bp_activity_get_excerpt_length()))), $user_id); $latest_update = sprintf('%s <a href="%s">%s</a>', $latest_update, esc_url_raw(bp_activity_get_permalink($update['id'])), esc_attr__('View', 'buddypress')); /** * Filters the latest update excerpt with view link appended to the end. * * @since 1.2.0 * @since 2.6.0 Added the `$user_id` parameter. * * @param string $latest_update The latest update with "view" link appended to it. * @param int $user_id ID of the queried user. */ return apply_filters('bp_get_activity_latest_update', $latest_update, $user_id); }
/** * Truncate long activity entries when viewed in activity streams. * * This method can only be used inside the Activity loop. * * @since 1.5.0 * @since 2.6.0 Added $args parameter. * * @param string $text The original activity entry text. * @param array $args { * Optional parameters. See $options argument of {@link bp_create_excerpt()} * for all available parameters. * } * @return string $excerpt The truncated text. */ 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 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 1.5.0 * * @param string $value Internationalized "Read more" text. */ $append_text = apply_filters('bp_activity_excerpt_append_text', __('[Read more]', 'buddypress')); $excerpt_length = bp_activity_get_excerpt_length(); $args = wp_parse_args($args, array('ending' => __('…', 'buddypress'))); // 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 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); }