Skip to:
Content

BuddyPress.org

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#5060 closed enhancement (fixed)

Add $args parameter to bp_activity_thumbnail_content_images()

Reported by: dcowgill's profile dcowgill Owned by: boonebgorges's profile boonebgorges
Milestone: 1.8 Priority: normal
Severity: normal Version:
Component: Activity Keywords: has-patch
Cc:

Description

It would be very nice if the args from the bp_blogs_record_activity() request were passed into the bp_activity_thumbnail_content_images() function and filter.

This would give developers the opportunity to easily override the prepended BuddyPress (first img found in post) thumbnail.

Here's a use case:

function at_add_custom_thumbnail( $content, $matches, $args ) {

    // we don't want images for blog comments
    if ( 'new_blog_comment' == $args['type'] )
        return $content;

    $post_id = $args['secondary_item_id'];

    $attachments = get_posts( array( 'post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'order'=> 'DESC', 'post_mime_type' => 'image', 'post_parent' => $post_id ) );

    // post has thumbnail so use that
    if ( has_post_thumbnail( $post_id ) )
        $image_url = get_the_post_thumbnail( $post_id, 'activity-stream' );
    elseif ( $attachments )
        $image_url = wp_get_attachment_image( $attachments[0]->ID, 'activity-stream' );
    else
        return $content;
    
    $image = '<a href="' . get_permalink( $post_id ) . '">' . $image_url . '</a>';

    // strip out the img bp uses & other html tags    
    $content = strip_tags( $content );
    
    // prepend our thumbnail to the content
    $content = $image . $content;
    
    return $content;

}
add_filter( 'bp_activity_thumbnail_content_images', 'at_add_custom_thumbnail', 10, 3 );

Proposed patch has been attached. Thank you.

Attachments (1)

activity_thumbnail_new_param.patch (1.8 KB) - added by dcowgill 11 years ago.

Download all attachments as: .zip

Change History (4)

#1 @boonebgorges
11 years ago

  • Milestone changed from Awaiting Review to 1.8

Looks legit. We're into the 1.8 beta period, which generally means no new enhancement requests for this release, but this is pretty harmless.

#2 @boonebgorges
11 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 7222:

Pass activity arguments through to bp_activity_thumbnail_content_images()

This allows plugin authors greater flexibility when modifying a post's
thumbnail image as it'll appear in the blog activity stream, by filtering
'bp_activity_thumbnail_content_images'.

Fixes #5060

Props dcowgill

#3 @dcowgill
11 years ago

Awesome! Thanks Boone.

Note: See TracTickets for help on using tickets.