Skip to:
Content
Pages
Categories
Search
Top
Bottom

[New Hack] Bumping Activity to the top when a reply comment is made

  • standard disclaimer – i don’t plan on releasing this as a plugin (better suited as a core thing – created a trac ticket already and don’t want to support messing around with the dates outside of the normal scope)

    warning: there is no way to auto-revert back the date_recorded for the activity but this will store the date_recorded in the activity meta table for safe keeping (on your own if you want to revert back and moving that date back)

    function etiviti_bp_activity_bump_denied_activity_type_check( $type ) {
    return in_array($type, array( 'tweet', 'bp_link_comment', 'bp_link_vote', 'joined_group', 'created_group', 'friendship_created', 'friendship_accepted', 'new_member' ) );
    }

    function etiviti_bp_activity_bump( $comment_id, $params ) {
    global $bp, $wpdb;

    extract( $params, EXTR_SKIP );

    $activity_parent = bp_activity_get_specific( array( 'activity_ids' => $activity_id ) );

    //make sure we have something
    if ( !$activity_parent = $activity_parent['activities'][0] )
    return;

    //don't update if certain activity types - remove this if you don't care
    if ( etiviti_bp_activity_bump_denied_activity_type_check( $activity_parent->type ) )
    return;

    //be nice and save the date_recorded
    if ( !bp_activity_get_meta( $activity_id, 'bump_date_recorded') )
    bp_activity_update_meta( $activity_id, 'bump_date_recorded', $activity_parent->date_recorded );

    //naughty but some bug using BP_Activity_Activity and save() :P - set the "new" date in order to bump this activity_parent wrap to the top
    $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET date_recorded = %s WHERE id = %d", gmdate( "Y-m-d H:i:s" ), $activity_id ) );

    }
    add_action( 'bp_activity_comment_posted', 'etiviti_bp_activity_bump', 1, 2 );

    the etiviti_bp_activity_bump_denied_activity_type_check is purely optional – i like to restrict certain activity functions.

    i have it working on my test site

    http://etivite.com/ (just view the activity stream)

    http://etivite.com/groups/buddypress/forum/topic/hack-bump-activity-to-the-top-when-a-comment-reply-is-made/

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

  • Tore
    Participant

    @toregus

    Extremely interesting but I’m a bit hesitant to do modding that needs to be at core. I’m hoping that Andy_P will see this! This have to get to core if it work! I’ll check the trac.

    I’ve tried to sign up for your test website but I’m not getting any activation email.


    Tore
    Participant

    @toregus

    check your spam folder – that site is on a shared host (dreamhost) – so emails typically get junked easily.

    yep, that is the ticket :P (i’m a fan of having a date_modified col in db – so hopefully that could happen here and then a site admin could have a choice on what to sort on)

    but this hack (while you do not have to touch any core files) will mess with intention of the date_recorded value (but saves the original in the activity meta table)


    Gene53
    Participant

    @gene53

    Where would I insert that code, in my child theme’s bp_custom.php or functions.php file?

    Thanks,

    Gene


    Mike Pratt
    Participant

    @mikepratt

    Rich – I have had this on the back burner for some time. Glad you took the time to get it going. Tested and works as promised. I noticed an interesting by product of the process. By virtue of the way you had to go about this hack (via date_recorded) we are left with a constantly updating time recorded on the original thread (as opposed to just the reply. I wonder if it would be possible to go about it a different way:

    Getting the original post’s time stamp to stay at the original value and show the most recent time stamp on the latest reply, all the while having it bump. It’d be even cooler to have the reply only up top with an “in reply to” ref to the entire thread but that might introduce unnecessary splits of the stream (eg Do you put the reply in both locations?)

    Getting the original post’s time stamp to stay at the original value and show the most recent time stamp on the latest reply, all the while having it bump.

    might be possible… if anyone wants to try running something on this filter:

    apply_filters( 'bp_activity_time_since', '<span class="time-since">' . sprintf( __( '%s ago', 'buddypress' ), bp_core_time_since( $activities_template->activity->date_recorded ) ) . '</span>', &$activities_template->activity );

    check if the activity meta key ‘bump_date_recorded’ exists and swap it in for the time_since

    (i’m not sure about the second question)

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[New Hack] Bumping Activity to the top when a reply comment is made’ is closed to new replies.
Skip to toolbar