Skip to:
Content
Pages
Categories
Search
Top
Bottom

Excluding blog post comments from activity stream page?


  • pollycoke :)
    Participant

    @pollycoke

    I’m not able to apply a filter to the activity loop, as described here: http://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-activity-stream-loop/ What I’d like to do is:

    1) Exclude blog post comments from the activity stream

    OR

    2) Show only status updates in the activity stream

    3) Have that reflected in the RSS feed for the activity stream page

    I’m using regular WP 2.9.2 with BP 1.2.2 and a simple custom child of the default theme. I tried with this:

    <?php if ( bp_has_activities( ‘object=status’ ) ) : ?>

    But once I do this, the activity stream doesn’t show anything at all.

    Any hints very appreciated.

    Thank you!

Viewing 14 replies - 1 through 14 (of 14 total)

  • pollycoke :)
    Participant

    @pollycoke

    Here’s how: in your /plugins/ directory, create a file called bp-custom.php with this content:

    <?php

    function bp_remove_comment_ac() { remove_action( ‘comment_post’, ‘bp_blogs_record_comment’, 10, 2 ); } add_action( ‘bp_init’, ‘bp_remove_comment_ac’ );

    ?>

    It works on blog comments posted after you do this.

    Many thanks to apeatling for the solution!


    Reezo
    Participant

    @reezolution

    is this method exclude all blog post and comments? How about if I just want to filter post and comment from certain blog? I want the blog appear to public and search engine, but I just don’t want its activity to shown on activity stream..


    3sixty
    Participant

    @3sixty

    this works great – how do you also exclude forum replies?

    (… searching code …)

    UPDATE: Well, I tried this code but it doesn’t work. Posting it here in case I’m on to something that somebody else can fix:

    function bp_remove_forum_topic_post() { remove_action( ‘groups_new_forum_topic_post’, ‘groups_update_last_activity’, 10, 2 ); } add_action( ‘bp_init’, ‘bp_remove_forum_topic_post’ );


    3sixty
    Participant

    @3sixty

    While this is an elegant hack, it just occurred to me that this is not optimal if you want to preserve an individual user’s ability to check blog comments in an activity stream. If I read the code correctly, it prevents blog comments from triggering an activity update in the database, so blog comments never get recorded as an activity.

    If that’s true, then it would be preferable to still RECORD the activity, but simply not DISPLAY it in the activity loop. Unfortunately, from this codex tutorial, it seems like the “filter” options only allow you to SHOW one type of activity (rather than filtering OUT one type of activity):

    https://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-activity-stream-loop/


    Boone Gorges
    Keymaster

    @boonebgorges

    You can filter the activity stream on a certain page with something like this:

    function bp_no_blog_comment_filter( $a, $activities ) {
    global $bp;

    /* Only run the filter on activity streams where you want blog comments filtered out. For example, the following will only filter them on the sitewide activity tab: */
    if ( $bp->current_component != $bp->activity->slug )
    return $activities;

    /* Then filter out all the blog comments */
    foreach( $activities->activities as $key => $activity ) {
    if ( $activity->type == 'new_blog_comment' ) {
    unset( $activities->activities[$key] );
    $activities->total_activity_count = $activities->total_activity_count - 1;
    $activities->activity_count = $activities->activity_count - 1;
    }
    }

    /* Renumber the array keys to account for missing items */
    $activities_new = array_values( $activities->activities );
    $activities->activities = $activities_new;
    return $activities;
    }
    add_action( 'bp_has_activities', 'bp_no_blog_comment_filter', 10, 2 );

    Obviously you may want to tweak some of the details, but that’s the basic idea – the comments are still recorded to the stream, and still appear on the individual member streams.


    3sixty
    Participant

    @3sixty

    Thank you! This is very powerful.

    I customized it to exclude blog comments and forum comments:

    if ( $activity->type == ‘new_blog_comment’ || $activity->type == ‘new_forum_post’) {


    3sixty
    Participant

    @3sixty

    Please don’t use my customization of Boone’s code above. It seems to be causing a failure of the Activity Stream, at least for me. Have not figured out why yet.


    3sixty
    Participant

    @3sixty

    So I think Boone’s code works for filtering blog comments but has an unintended side effect of causing the “Load More” box to disappear. We may be discussing this in another thread at the moment…


    3sixty
    Participant

    @3sixty

    The achilles heel of @boonebgorges otherwise excellent approach is that you are essentially just removing items from the array, which causes activity stream atrophy. If you have a 20-item activity stream and 11 of those are blog comments, then you only have 9 items in the page before we get to “load more”, whereas you have a slow comment period, there may be 18 items on the page.

    One a clean way to exclude blog post comments and/or forum replies from the main activity stream, but still preserve the activity stream length, would be by passing an additional WHERE != item to the database query. I couldn’t figure out a way to pass it, so as a proof-of-concept, I did this to exclude forum comments from the main page activity stream (on a BP install set up to display activity on the front page):

    Go to Line 123 in bp-activity-classes.php:
    $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );

    Add this line below it:
    if ( $bp->current_component == "") { $where_sql .= " AND a.type != 'new_forum_post' "; }

    This is just a proof-of-concept. I WOULD NOT take this approach for your site, because it will get overwritten when you upgrade your BP files.

    Is anyone able to suggest a way to do this without messing with the BP core files?


    Boone Gorges
    Keymaster

    @boonebgorges

    @3sixty – Yes, I am aware of this Achilles’s heel, and I have toyed with a solution like yours.

    It would be really nice if bp_has_activities (and bp_has_members, etc) had some sort of exclude or exclude_by argument. I might try writing a realistic patch for the core that would make something like this more than just a hack.


    3sixty
    Participant

    @3sixty

    It would be really nice if bp_has_activities (and bp_has_members, etc) had some sort of exclude or exclude_by argument. I might try writing a realistic patch for the core that would make something like this more than just a hack.

    YES… PLEASE! I have made this exact point before. That would be awesome.

    Also, not to litter these threads with circular references, but Jeff Sayre just said that his Privacy plugin component is going to allow fine-grained control over display of any activity stream. I think he’s anticipating having that ready in about 10 days or so.

    But for tweakers, having the ability to directly interact with the streams via bp_has_activities() would be ideal, so if you’re able to do a core patch that allows exclude or exclude_by, I think it would be a huge help.


    chouxpastry2002
    Participant

    @chouxpastry2002

    Hello guys,
    I think i have arrived at right thread to post my query at.

    I am looking to filter Group creation and member joining activity from Group activities.

    I dont want to display “Member has joined this group” And “Member has created this group” in group activity stream.

    Please tell me how to do it using custom-bp.php file or themes function.php file. I am ok with both the types.

    Regards,
    Sam.

    Old threads are never really the ‘Right Place’ they’re there as archive material to be read. Generally the correct form is to start a new post for your issue.

    Have you not already asked this question a couple of times today in threads?

    Please keep to this thread you started on the issue,
    https://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/editing-group-activity-stream/

    if no response by the morning give the post a bump, in the meantime keep searching and reading old posts as the solution might well have been covered already.


    chouxpastry2002
    Participant

    @chouxpastry2002

    i am sorry sir i dint saw the date of this post i thought its been such a long discussion so i thought i would get faster response over here. I will follow that in my new thread :)!!!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Excluding blog post comments from activity stream page?’ is closed to new replies.
Skip to toolbar