bp_activity_link_preview( $content, $activity )
Embed link preview in activity content
Description
Parameters
- $content
-
(Required)
- $activity
-
(Required)
Return
(string)
Source
File: bp-activity/bp-activity-filters.php
function bp_activity_link_preview( $content, $activity ) { $activity_id = $activity->id; $preview_data = bp_activity_get_meta( $activity_id, '_link_preview_data', true ); if ( empty( $preview_data['url'] ) ) { return $content; } $preview_data = bp_parse_args( $preview_data, [ 'title' => '', 'description' => '', ] ); $description = $preview_data['description']; $read_more = ' <a href="' . esc_url( $preview_data['url'] ) . '" target="_blank" rel="nofollow">' . __( 'Read more', 'buddyboss' ) . '...</a>'; $description = wp_trim_words( $description, 40, $read_more ); $content = make_clickable( $content ); $content .= '<div class="activity-link-preview-container">'; if ( ! empty( $preview_data['attachment_id'] ) ) { $image_url = wp_get_attachment_image_url( $preview_data['attachment_id'], 'full' ); $content .= '<div class="activity-link-preview-image-wrap"><div class="activity-link-preview-image">'; $content .= '<a href="' . esc_url( $preview_data['url'] ) . '" target="_blank"><img src="' . $image_url . '" /></a>'; $content .= '</div></div>'; } $content .= '<div class="activity-link-preview-content">'; $content .= '<div class="activity-link-preview-title"><a href="' . esc_url( $preview_data['url'] ) . '" target="_blank" rel="nofollow">' . addslashes( $preview_data['title'] ) . '</a></div>'; $content .= '<div class="activity-link-preview-body">' . $description . '</div>'; $content .= '</div>'; $content .= '</div>'; return $content; }
Changelog
Version | Description |
---|---|
BuddyBoss 1.0.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.