Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of hnla

Replace Activity Stream blog excerpt with the_excerpt (42 posts)

Started 1 year, 7 months ago by: Mika Epstein (Ipstenu)

  • Profile picture of Mika Epstein (Ipstenu) Ipstenu said 1 year, 7 months ago:

    I custom craft my excerpts, and I’d like to have the sitewide activity stream show my excerpt and not the bp excerpt. Can this be done?

  • Profile picture of rich! @ etiviti rich! @ etiviti said 1 year, 7 months ago:

    hmm, well i was going to suggest using the filter…

    in bp_blogs_record_post
    'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink )

    which calls bp_blogs_record_activity but it does not pass the untouched content to tweak to your liking.
    $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ) ;

  • Profile picture of Mika Epstein (Ipstenu) Ipstenu said 1 year, 7 months ago:

    It’s bp_create_excerpt() that’s killing me.

    If I could replace (or change) that to check for the existence of an excerpt and, if found, spit THAT back, it’d be perfection.

  • Profile picture of r-a-y r-a-y said 1 year, 7 months ago:

    Isn’t it possible to grab the excerpt based on &$post?
    $post->post_excerpt.

    Sample code:

    http://pastebin.com/s9PajKjU

    Disclaimer: Untested ;)

    [EDIT]
    I see what you guys are talking about now with bp_create_excerpt()!

    You can either request an additional parameter for unfiltered text in the “bp_blogs_record_activity_content” filter or in the “bp_create_excerpt” filter.
    Definitely a good idea for a patch!

  • Profile picture of rich! @ etiviti rich! @ etiviti said 1 year, 7 months ago:

    a crazy idea – the BP_Activity class on the save method has another set of filters.

    $this->content = apply_filters( 'bp_activity_content_before_save', $this->content, &$this );

    Using $this
    check for the activity type (new_blog_post),
    grab the secondary_item_id which is the post_id (item_id is the blog_id here)
    then lookup your custom excerpt in wp with the post_id and replace?

  • Profile picture of Mika Epstein (Ipstenu) Ipstenu said 1 year, 7 months ago:

    Thank you both of you! Now I have a better start point!

  • Profile picture of r-a-y r-a-y said 1 year, 7 months ago:

    That would work as well!
    Though, you’d have to grab the excerpt either through a DB query or some WP functions (I suggest the DB query only if you’re using Multisite).

  • Profile picture of Mika Epstein (Ipstenu) Ipstenu said 1 year, 6 months ago:

    Some free time returned.

    You can either request an additional parameter for unfiltered text in the “bp_blogs_record_activity_content” filter or in the “bp_create_excerpt” filter.

    So that now exists thanks to @r-a-y ( http://trac.buddypress.org/ticket/2481 )

    I’m assuming I need to tell bp_blogs_record_activity_content to use the excerpt, but would that just be using the code r-a-y already made here: http://pastebin.com/s9PajKjU or something else.

  • Profile picture of r-a-y r-a-y said 1 year, 6 months ago:

    @ipstenu – Take the code I posted and then you’ll also need to apply a filter so BP doesn’t create its own excerpt.

    This can be done with:

    http://pastebin.com/adaQBSTz

    Untested, give it a shot and report back.

  • Profile picture of Mika Epstein (Ipstenu) Ipstenu said 1 year, 6 months ago:

    Okay, we’ll see how that goes (I have a scheduled post for 1am every day ;) )

    Oy. The fun!

  • Profile picture of Mika Epstein (Ipstenu) Ipstenu said 1 year, 5 months ago:

    Brilliant!

    For posts without a crafted excerpt, it’s the same as always. For posts WITH one, it’s the excerpt! Now to trick it into pulling featured post images ;) ….

  • Profile picture of cmscritic cmscritic said 1 year, 5 months ago:

    Any luck getting it to pull in the first image of the blog post as well?

  • Profile picture of Roger Coathup Roger Coathup said 1 year, 5 months ago:

    Some pointers, but not a solution:
    @ipstenu

    The featured image is referenced by _thumbnail_id . It’s not stored in the $post data structure, instead it’s held in the postmeta table.

    There are look up functions to get the featured image from the post_id of course, but not sure how efficient these would be… I guess you still have to have to switch to the correct blog (switch_to_blog()), before using the post_id in the 3.0 multisite world?

    Maybe I’m taking it off track here

  • Profile picture of Mika Epstein (Ipstenu) Ipstenu said 1 year, 5 months ago:

    Yeah, switch to blog is why I’ve not gotten any further, alas :) I do wish this worked like FaceBook, somewhat, but unless I had it pulled in on bp_blogs_record_activity_content, maybe tell that ‘and get post_thumbnail_id’ but right now I’m happy with the excerpt!

  • Profile picture of Roger Coathup Roger Coathup said 1 year, 5 months ago:

    @ipstenu:

    We came up with a solution to include the featured image (post_thumbnail) in the activity stream. The solution avoids the need to use switch_to_blog

    It isn’t simple, but it might help:

    We removed the action bp_blogs_record_post and replaced it with our own version that populates the content field with the post_thumbnail (you could also add the excerpt), i.e. $activity_content = get_the_post_thumbnail( $post_id );

    Unfortunately, bp_blogs_record_activity then takes the image and mangles it. To get around this we had to implement our own version of bp_blogs_record_activity, and call that instead from our blogs_record_post function.

    You can see the whole set of code here:

    http://pastebin.com/jKdQ2kLu

    Then in your activity loop, just use bp_activity_content_body() to display the thumbnail / excerpt, etc.

    IMHO – bp_blogs_record_activity() needs a rework in the core to give theme designers much more control.